On Thu, Sep 16, 2010 at 11:33 PM, Mike Wyatt <[email protected]>wrote:
> In my game, I store all my entities in an EntityManager object, which
references them in a couple different lists and dictionaries, for easy
> database-like look-ups. When a new entity is added, I dispatch the
> "on_entity_added" event. This event is handled by my Model object,
> which in turn initializes the entity's Box2D body and pyglet sprite
> objects.
>
> This works great, except for the situation where I immediately call
> the new entity's "start_moving" method. This method attempts to apply
> force to the uninitialized physics object, resulting in a thrown
> exception. This is because the event loop hasn't yet processes the
> new event.
With stock EventDispatcher s the messages are not queued, that is,
event_dispatcher.dispatch_event(msg, ...)
calls the listeners when this call is executed. (look at event.py, it is
clear)
quoting from pyglet.event docstrings:
"It is up to the specific event dispatcher to queue relevant events until
they
can be dispatched, at which point the handlers are called in the order the
events were originally generated."
I missing something here.
writing pseudocode describing what I parse from the description
class EntityManager(pyglet.event.EventDispatcher):
...
...def add(self, ...):
......# add to the tables
......# publish like
......self.dispatch_event('add_actor')
......return actor
...
# instantiate
entity_manager = EntityManager(...)
And in model something like
class WorldModel(...):
...def __init__(self, ...):
.......# initialize all things before enabling listeners
.......# attach listeners
.......entity_manager.push_handlers(self.on_add_actor,self.on_remove_actors,...)
...# define a handler for on_add_actor
...def on_add_actor(self,...):
.......#initializes associated box2D body and pyglet sprite object
#somewhere in code:
actor = entity_manager.add(...)
actor.start_moving() # ---> traceback here ?
Having no queue involved the traceback cant be.
So probably I misunderstood your description.
Can you give some more detail ?
--
claudio
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.