Events Groups with Panda. Design question

Hello All,

I’m having a design questions because i’m refactoring mercilessly those day.

To solve this design issue, i need to know if there is a way in Messenger System to list all objects accepting one event?

The reason i need it is:
I have currently a Group system in place. I can assign my game object to several groups and then send “group” event and all objects respond to this group events.

ex: I’ve got soldierA, B and C.
Soldier A and B are in group “Assault”, soldier C in group “Support”
I can send event "Assault_Attack and soldier A and B will attack.

Today my implementation is the following.
each Game object have a method that expose his features to event.
Each feature is registered once for the object itself, then once for each group the object belong in.

Group is dynamic , there is a group_add and group_remove event that allow to each object to register or remove from a group.

So in my design, there is no “group” entity/object , group only exist because some object tag themself in Event System as belonging to a group.

But today i need to be able to:

  • list all groups members
  • list all objects that can react to a specific event.

So i’m challenging the need to create a central group management instead.

All your inputs are welcome, about the question but also about the design…

I believe most of your questions can be answered in the Messenger API reference.

http://panda3d.org/apiref.php?page=Messenger

messenger.whoAccepts(event) should return all objects accepting the given event.

You may have to make sure that the objects are constructed properly to register with this function, meaning they have a concise string representation. The whoAccepts method basically returns the values of an event key stored in a dictionary in messenger.

messenger.whoAccepts(“myMessage”) will list all DirectObjects that accept “myMessage.”

In terms of design, your overall methodology looks just fine :wink: Another way to do it might be to use arguments; instead of “Asssault_attack”, do

messenger.send("Assault",["Attack"])

In this model, Groups are now responsible for accepting messages sent to their name (with self.accept(“Assault”,self._handleMessage), for example), and they then dispatch the message to each of their members:

def _handleMessage(self,actionString):
    for member in self.allMembers():
        member.doAction(actionString)

This has the advantage of adding a layer of indirection (the group class could modify the actionString before passing it to its children). But the runtime efficiency is probably little better than the design you have now, so there’s no obvious performance gain I could see. Go with what you think is going to work best!

The only other change I would suggest is to prefix each message intended for groups with some common string, like “Group-Assault-attack” instead of “Assault-attack.” That way there’s room for other types of things that may behave like groups to have the same names as your groups.

Best of luck with the rest of your project!
-Mark

Thanks you, i’ll have a look once i’ve installed my vmware + Ubuntu system to be able to see panda working in linux and windows at the same time