Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actor model and collision detection

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?

like image 417
eonil Avatar asked Apr 29 '12 08:04

eonil


2 Answers

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.

like image 95
Emil Vikström Avatar answered Oct 03 '22 15:10

Emil Vikström


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.

like image 30
Nialscorva Avatar answered Oct 03 '22 17:10

Nialscorva