Wrecked Games

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're just that awesome.

Author Topic: Messanging System  (Read 2357 times)

mysterycoder

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 447
    • View Profile
Messanging System
« on: April 30, 2006, 06:21:56 PM »

For a messanging system, maybe we can use PeerOS, that was posted by Occulis on the Ogre forums. http://www.ogre3d.org/phpBB2/viewtopic.php?t=20004
Logged

pjcast

  • Administrator
  • Veteran
  • *****
  • Karma: +1/-0
  • Posts: 2661
    • View Profile
    • http://www.wreckedgames.com
Messanging System
« Reply #1 on: April 30, 2006, 08:11:37 PM »

OvermindDL1 also posted in the main stickied WGE thread about his lib's messaging system. Might be worth taking a look at both and see which looks better. I still havn't had time to browse his lib ( I believe he said it was BSD or LGPL  license or something).

In either case, feel free to play around, and see which one works for you. Afterall, it can always be pulled out, refactored, removed entirely at this early stage.

I for one will be pretty light on the WGE for the next few weeks. But, i will still be around the forums often.
1) Ogre 1.2 Final Release is just around the corner.. Although, i have just about finished adding all the patches I can
2) Wedding coming up on the 20th :)
3) School Finals on the 22nd
4) Looking for fulltime work after these classes are over - gotta pay for this server somehow :) - I've been using the Navy College Fund & GI Bill to pay for school and bills
5) Stuff that always comes up unexpectedly :)
Logged

mysterycoder

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 447
    • View Profile
Messanging System
« Reply #2 on: May 01, 2006, 01:59:02 PM »

Very busy, I see :)

I'll start taking a look at the messanging systems. I'll be comparing OverMindDL1's messanging system and PeerOS.
Logged

OvermindDL1

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 288
    • View Profile
    • http://www.overminddl1.com/forum/
Messanging System
« Reply #3 on: May 01, 2006, 02:06:11 PM »

Mine is a more generic messaging system then PeerOS.  PeerOS uses a document/view model, mine is more like... I don't really know what model it would be called.  How about examples and descriptions instead:

Using PeerOS you have a 'document' class which has events that can be handled elsewhere.  You also define a message class for it, and listeners also subclass from something else as well and can register themselves to the document.

Mine was originally started for an input action-map, it just kept growing though.  There is one main class, a singleton, you treat it as this (I don't have the code in front of me right now so doing this from memory):

To register a new action:
Code: [Select]
ActionMap::getSingleton().addAction("quit");

You can link it to any amount of actions that are already defined (there are a few predefined ones as well, mostly input's):
Code: [Select]
ActionMap::getSingleton().addPersistantLink("KC_ESCAPE","quit");
If you use addLink() instead, it returns a connection object, when that object goes out of scope or you manually call Disconnect() on it or whatever, the link disappears.

Now this is good, if you hit escape (a prebuilt event), it calls quit, and anything else linked to it, and anything linked to quit or those anythings, you can also link between like "KC_Q" and "quit" if you want as well, it is a many-to-many relationship.  But say you have an action/event of your own, that you want to call, well, addAction both creates and returns, or returns if it already exists, an action/event object, so:
Code: [Select]
actionEventDontRecallTheTypeName aQuitAction = ActionMap::getSingleton().addAction("quit");
And you can pass that around, so if something wants to register to you, you can either give them the variable, or you can link it yourself if they pass an object.

To call an action/event, you do:
Code: [Select]
(*aQuitAction)(0.0f);
I have it take floats right now, as stated, was made for inputs originally, but if I find a need to pass other things, I'll probably change it to an Any, very simple change to make.

Now, making, linking, and causing events to happen is all well and good, but useless without something to listen to it, to register a function, member function, functor, etc... etc... then you do:
Code: [Select]
DontRecallTheLinkTypname aLink1 = ActionMap::getSingleton().addLink("quit", &aQuitStaticFunction);
DontRecallTheLinkTypname aLink2 = ActionMap::getSingleton().addLink("quit", bind(&aQuitMemberFunction,thisOrClassPointer,_1)); // Will make this into a function overload later so the bind junk will be unnecessary
DontRecallTheLinkTypname aLink3 = ActionMap::getSingleton().addLink("quit", aQuitFunctor);

Of course you could use addPersistentLink if you want it to persist until program exit.

There are a few other abilities of it like (un)serializing, but I need to go.
Logged

mysterycoder

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 447
    • View Profile
Messanging System
« Reply #4 on: May 01, 2006, 04:07:45 PM »

Sweet  :D, it sounds awesome!
Logged

OvermindDL1

  • Administrator
  • Veteran
  • *****
  • Karma: +0/-0
  • Posts: 288
    • View Profile
    • http://www.overminddl1.com/forum/
Messanging System
« Reply #5 on: May 01, 2006, 08:19:47 PM »

I certainly wouldn't call it production ready as I was designing it for myself and not for others, but it would be quite simple to get it done (adding things like the bind overload, changing the float call to Any, adding in a flag for what needs to be serialized and what doesn't, etc...).

EDIT:  If you are worried about timing, actually making a new action is a hashmap lookup and a hashmap insertion.  Getting back an already created action is just a hashmap lookup.  Creating a new link between two actions is two hashmap lookups.  Adding a link between an action and a function/method/functor is a single hashmap lookup.  When an event called it is very lightweight as I use the signal lib, about as lightweight as you can get, in other words, it is a couple asm instructions plus a function call of 3 asm instruction per link down the line.

In other words, creating and linking actions is costly, calling actions is not, so do the bulk of the creation early on if possible.  Although things like a message system between a trigger and a door or whatnot mid-game is fine, just not like 50 per frame. :P
Logged