5 ms·
Years ago a good friend and I wrote a zombie outbreak simulator, and ran into a similar problem. Our solution was to have "move" and "think" phases for all ent
by angersock 13y ago
Years ago a good friend and I wrote a zombie outbreak simulator, and ran into a similar problem.
Our solution was to have "move" and "think" phases for all entities (usually run think->move->think because a movement could result in a collision with somebody else who had wanted to move), and to use a messaging system to have entities announce their intentions ("attack entity X", "open door", etc.). The messaging system also let us filter messages and do other clever things--a later evolution of this same architecture became a double-buffered entity simulation framework with green threads for handling updates.
It's a hell of a lot simpler to write a simulation with objects who can understand certain types of messages--the code is simpler, the mental model is tons simpler, and in general it seems to be just easier.
- TillE 13y ago> Our solution was to have "move" and "think" phases for all entities Oh good, that was my really simple solution for multithreading a large agent-based simulation on the order of 100k entities. Each step has a read-only phase (decide) followed by a write-only phase (act). I figure that's good enough (if not quite optimal) for maximizing CPU usage on a simulation running on one computer.
- _random_ 13y agoIt's the way to go. Just don't forget to decompose entities into components.
- angersock 13y agoComponents are a thing--depending on the language, even a good thing.
- seanmcdirmid 13y agoRepinning proposed anti-objects to solve this problem, which uses collaborative diffusion to take the logic out of the actor and place it into the environment: http://www.cs.colorado.edu/~ralex/papers/PDF/OOPSLA06antiobjects.pdf http://www.cs.colorado.edu/~ralex/papers/PDF/OOPSLA06antiobj...
- lloeki 13y ago> "because a movement could result in a collision with somebody else who had wanted to move" Similarly useful when simulating physics: evaluate forces effecting entities, then evaluate movement for the next step regardless of collisions and then resolve the collisions by applying a virtual repulsive force moving the objects out of the "impossible superpositions".
- jjoonathan 13y agoHow do you address the problem where you get impossible superpositions that are difficult to resolve via repulsive forces, leading to a massive deposition of energy in the objects? http://i.imgur.com/ZgMNXpS.gif http://i.imgur.com/ZgMNXpS.gif
- lloeki 13y agoCap the forces and/or trigger a more refined resolution mechanism, and maybe also force set the objects in a plausible {position, velocity}. This kind of simulation is by definition an approximation. You can detect impossible superpositions because they result in impossible forces. This is of course not applicable to the general case, so it depends if you want realism racing or massive unit count RTS physics.