Hey,

I got a question regarding a project I'm working on.

There are player actors that can be managed by a "player director" actor 
which belongs to a virtual room and supervises the players. A player 
maintains its current position and name as a mutable state.

The director looks like this:

class PlayerDirector extends Actor {
     ....
     private val players = mutable.Map[Int, ActorRef]() // Id, Player ref
     ....
     override def receive = {
          case SpawnPlayer(playerReference) => players += 
(incrementAndGetId() -> context.actorOf(Player.props(playerReference)))
          case RemovePlayer(id) => ...
     }
}


Now I'd like to execute some operations on all players which are positioned 
at x, y

My first attempt:

class PlayerDirector ...
   receive = {
          ....
          case ExecuteOnPlayersByPosition(position, callback) => {
                for ((id, player) <- players) {
                   player ! ExecuteIfPositionMatches(position, callback)
                }
          }
          ....


Then, the player would check its position and execute the callback from its 
context. I don't like this implementation because it forces me to have the 
callback executed on the player's actor, but It's the only way to guarantee 
synchronization (I guess).

Do you have any advice for me?

Cheers!

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to