Re: Issue 3 in pysage: Implement a way to queue message to all listeners

5 views
Skip to first unread message

John Yang

unread,
Apr 9, 2009, 3:10:02 AM4/9/09
to pys...@googlegroups.com
1. good question. From the initial implementation, only local
processes are called "groups" and they are associated with string
names. You could have a group called "GUI" and another one called
"worker_bee" for example. And you can call:

queue_message_to_group('GUI', msg)

whereas network nodes were meant to be more anonymous (especially in a
game), and not known until runtime, like ip addresses. However, I
think there is room to make this more generic. Maybe we could have a
unified "send_message" method for both IPC and network messages and
have this method figure out where to send underneath.

2. agreed. It makes sense to break this up into separate methods.
Users may not want to poll for network messages as often as the
actors' "update" method is called, for example. The "tick" does too
much right now. :) Thoughts on the API for this?

John

On Wed, Apr 8, 2009 at 11:37 PM, <codesite...@google.com> wrote:
>
> Comment #6 on issue 3 by arsch...@gmail.com: Implement a way to queue
> message to all listeners
> http://code.google.com/p/pysage/issues/detail?id=3
>
> makes sense. very cool. two more questions:
>
> (1) why are the network calls different from the IPC equivalents?
> (2) is it possible to make it opt-out to poll for messages on the receiving
> end (as opposed to opt-in, which it
> seems to be now)? it could be accomplished with a decorator perhaps.
>
> --
> You received this message because you are listed in the owner
> or CC fields of this issue, or because you starred this issue.
> You may adjust your issue notification preferences at:
> http://code.google.com/hosting/settings
>

arschles

unread,
Apr 9, 2009, 3:33:37 AM4/9/09
to pysage
1. I think that would be way cool. I know that Erlang gives this
abstraction - maybe we could follow that model?

2. I agree with you that actors might not want to poll for messages as
often as "update" is called, especially across a network. I need
another day to really understand this problem well, but my first
inkling is to have the process that kicks off the program implement a
kind of "main":

<code>
#this is a pysage library class
class PrimaryActor(Actor):
def __init__(self):
#do some startup bookkeeping, maybe call the parent's __init__
here?
main()
#listen for messages. there's probably a better way to do this
so it doesn't just spin-wait...
while True:
processed = mgr.tick()
time.sleep(.03)

#this is a user-defined class
class MainActor(PrimaryActor):
def main(self):
self.player1 = mgr.register_actor(Player(), 'player1')
self.player2 = mgr.register_actor(Player(), 'player2')
mgr.queue_message(BombMessage(damage=10))

ActorMgr.begin(MainActor())
</code>

this way, everyone's an actor, including the "user" (ie: the process
that starts everything up) and no user code executes in the "main"
process. and so as one benefit to this, users aren't forced to decide
how often to poll (although the could have the choice, of course)
Reply all
Reply to author
Forward
0 new messages