Actor model and collision detection
Asked Answered
R

2

10

I'm just thinking about possibility of Erlang for game server. (oh I'm not Erlang expert, just considering stage) This means using Actor Model for game simulation. Of course, most biggest attraction is its concurrency distributed over multiple nodes.

My current huge question is how should I perform multi-actor interactions like collision detection. (this is just an example)

Though collision detection is essentially required in any game, but in the nature of Actor Model, it doesn't look efficient and even doesn't make sense, because it needs globally synchronized state query and update over all the targeting actors. And if I use any of synchronization, it overrides all benefits of Erlang's actor model.

Of course targeting actors at a time can be smaller if I use space partitioning correctly, but it's just an optimization, not a principal answer. Or is this a correct answer for this question? Decreasing range of synchronization by decreasing number of interacting actors?

Radical answered 29/4, 2012 at 8:18 Comment(0)
D
9

Split the map in smaller parts and let each part be its own process (you may even split it so much that each tile is its own process). A player trying to move will send a message to the tile/sub-map saying that it is going there, and the tile answers if it's okay or not. This avoids collisions since only one message is handled by the tile/sub-map at a time. Multiple sub-maps/tiles may handle messages concurrently, so it is still a concurrent program.

Desiderate answered 29/4, 2012 at 11:53 Comment(1)
Decreasing range of interaction look as the only way to go. Thanks.Radical
M
7

I have a space-based game doing the server in Erlang. The trick is that each location/node/etc is an actor, too. It runs the physics continuously and sends the information to each game entity actor on a regular basis.

The whole thing becomes much cleaner when you start thinking more abstractly about what an actor/entity is. For example, collisions can be full fledged actors. This makes the client side much easier-- tie the graphic and sound effects to the collision. On the server side, it does as well-- prevent multiple collision effects between two entities more than once in a given time.

Mathieu answered 30/4, 2012 at 12:11 Comment(2)
So are all the physics done in single actor? How did you make the physics done?Radical
Yes. I'm using Bullet to run the physics. The entity actors track their own game state, shoot each other, decide movement, etc. They send commands to the location, which runs the simulations. The location runs continuously and sends out "you are here" to the entities periodically and "you collided with X". Entities send queries to the location as well.Mathieu

© 2022 - 2024 — McMap. All rights reserved.