Are actors the right tool for implementing messaging between a simple multiplayer game?

I am thinking of using actors for a simple asteroid game written in Scala and Java2D that two players can play in cooperative mode.

Both players can control their own ship on a common playing field, where asteroids float in space.

I wonder if the actors are a suitable tool for realizing network elements between both players, such as updating a position or destroying an asteroid.

What is necessary for its implementation? What will be the hard parts? I'm afraid that I will have problems synchronizing them ...

Is there a better solution?

EDIT:

I do not plan to do any fancy things regarding firewalls or NAT ... I was thinking about having a small "server" to which both clients connect. (In fact, one client will simply start the server and run it on the same computer.)

Both clients will connect to it, preferably both with a remote actor, and for a special case in the particular case, no.

I have no problem switching to a P2P route, if that is easier. The requirements are fixed, and I never need to plan the case "we need a game with 64 players !!!".

+4
source share
3 answers

I recently participated in the development of a game that more or less used the same messaging approach. That is, having a remote server listening on a port somewhere, and then several clients connecting to it and sending messages back and forth.

However, this was done in Python, and since we did not want to rely on any external libraries, we wrote about our own actors and the remote messaging system on top of them. As it turned out, there were several performance issues, but I think that they were mainly related to Putin's Pythons method (and our lack of understanding of this). Tests for Scala Actors or Akka always did better numbers than what we could do in Python.

Synchronization was not a big problem for us, at least in the game itself. But then we did not have so much data to exchange, and it was a round-based game. Thus, each client was requested one after another, and if there was a timeout, then the next client will be requested. In our problem, clients only reacted to what the server presented to them. This may, however, not be the best solution in a more real game.

In real time, you can have an incoming queue (Actor) on the server to receive all client moves and, possibly, have a separate channel for the game state to avoid blocking. For synchronization, this would be much more complicated. It depends on how quickly you need updates.

+4
source

For whatever reason, some of Akka's early followers were multiplayer games, although I cannot provide a link for him.

In addition, the Call of Duty multi-user core is written in Erlang . This link to the presentation by the guys who did it, and this is very interesting material.

+3
source

Actors are definitely one way to go if there are many asynchronous messages (i.e. messages sent without any prior state)

I would do it as follows: each player will Actor receive messages from another player. Messages sent to actors will not be lost, so you will eventually reach a synchronized state after all messages have been delivered. Of course, you will have to write your own synchronization algorithm.

You can use the RemoteActor API to directly access remote RemoteActor or to use an intermediate means of communication (for example, Sockets) to send messages.

I assume that there is no central server for coordinating players.

+1
source

All Articles