Hacker News new | past | comments | ask | show | jobs | submit login
Simulation Islands (box2d.org)
261 points by AshleysBrain on Oct 10, 2023 | hide | past | favorite | 15 comments



Given how widespread the usage of Box2D has been over the last decade+, I truly hope the creator has seen some form of financial benefit from it. His work is awesome and has benefitted the gamedev community immensely.

He mentions Jolt physics in this blog. That’s another example of “holy shit look at what one person can do”. I’ve found myself wishing I had Unity source so I could performantly inject that engine instead of being stuck with PhysX.


Jolt physics is an amazing piece of work way above my level of understanding, but as someone who loves physics in video games I always enjoy learning a bit about how it all works:

https://github.com/jrouwe/JoltPhysics

http://jrouwe.nl/architectingjolt/ArchitectingJoltPhysics_Ro...

http://jrouwe.nl/architectingjolt/


Curious looking new setting in Unity alpha seems to suggest that swappable physics engines for GameObjects might be coming.[0]

Swapping physics engines for Unity's ECS world should already be very doable, but people understandably aren't leaping to it.

[0] https://forum.unity.com/threads/multiple-physics-options-for...


This left me wondering if there might be a deterministic parallel algorithm for union find :)

I did find this arxiv paper from April which claims to have one: https://arxiv.org/abs/2304.09331

My understanding is that they process batches of edges at a time. If they "conflict" (meaning they want to do different things to the data structure) then they're processed in serial, otherwise all edges in the batch are handled sequentially. They provide a bound on how often edges should conflict, and use that to show the complexity.


...ok change sequentially to in parallel, I was sleepy when I wrote this.


Software engineering at it's best. And surprisingly nicely written up.

One of my favourite reads! Would read again.


It's lovely to see active development on Box2D. Thank you for your efforts.


I'm the last one to shill specific styles or languages, but:

    class b2Island
    {
        b2Body** bodies;
        b2Contact** contacts;
        b2Joint** joints;
        int bodyCount;
        int contactCount;
        int jointCount;
    };
I understand that this is a physics engine and performance is paramount.

There is absolutely no real reason to use raw double pointers here, in my opinion there is likely a zero Overhead datastructure one could come up with to do exaftly the same thing, but unit-testable.

Further, why `int`? This isn't java, and this will cause any size comparisons to become unsigned-vs-signed comparisons, which likely will also be of different sizes. I'm saying those could and should be size_t, unless I'm missing something(?). Why would a count be negative? Why only allow a count up to int max, whatever that is on a given platform?

It just baffels me that people write serious business code in this style, still.

Edit: If the pointers are non-owning, there are references for that... Not that they're safer, but at least more idiomatic


How would you write the struct?


Why are the boxes always made of jelly in these physics simulations? Stacks/walls of boxes in real life are never that jiggly.


Sometimes it's just wrong parameters (e.g. too low density, too low gravity, ...), but the 'jelly-like' behaviour may also help to keep the simulation stable (sometimes in games you can see the physics simulation explode, e.g. stuff being catapulted with near-infinite speed into space, putting some dampening into the simulation and allowing some 'slack' for resolving object intersections can help to avoid that, but also makes everything feel more jelly-like).


It's due to using a Gauss–Seidel solver which iteratively solves each constraint rather than a global solver that solves all the constraints at once. The reason to use the iterative approach is that global solvers can end up with unbounded runtime or without a solution in some cases. The downside is that some constraints are left unsatisfied after you've run through your fixed set of iterations so it takes time to converge. With big stacks you have a lot of constraints and it can take even more time to converge as errors propagate energy through the stack. You can solve this as a sub-problem by itself and maybe the 'large islands' work will tackle that.

TLDR; with iterative methods stiffness of things depends on the physics timestep size and number of iterations of constraint solving.


Aka causality limitations through propagationspeed -aka lightspeed.


:) This was the same conclusion I came to when I first started researching this in video game design. No idea if there's actual merit to it, but the parallels are uncanny to be sure.


I haven't seen or heard of box2d in years.... awesome to see again :)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: