Event messaging system for B3D?

Blitz3D Forums/Blitz3D Programming/Event messaging system for B3D?

BulletMagnet(Posted 2004) [#1]
Anyone know of an event messaging system for Blitz3D?

I am looking for a system that can generate events and have game objects 'register' to listen only for certain event types. If no game object is currently registered for a given event type it is not sent out so no spamming of messages occurs.

For example a weapon listens for EVENT_fire or EVENT_altFire, but could care less about EVENT_mouseOver or EVENT_jumpLikeAMonkey.

If such a system is not already out there, got any slick ideas on how to proceed building one? Massive Select/Case statements are all that pop into my head right now but I haven't had my coffee yet...

Also, I have BVM and keep thinking this is the way to go to build such a system, but haven't really dug into it yet. So if you have an idea along those lines let me know.

Thanks,


jfk EO-11110(Posted 2004) [#2]
Personally I use an event system as a sideeffect. My app is not built around an event system, rather the event system is one part added to the engine. There are things that don't require event generators or handlers, things like toggle switches etc. It may or may not be useful to use a generic event system.


BulletMagnet(Posted 2004) [#3]
So...then...no ideas there JFK? (Just kidding.)

I am not sure I understand what you mean by 'side effect'.

I realize that not every object or action needs to have an event associated with it, that is why I mentioned that game objects should be able to register to receive events, only the ones they need. The event system should skip even creating an event message if there is no one to registered 'hear' it.

I have started tooling about and maybe I can come up with something useful.


martonic(Posted 2004) [#4]
Could be useful. You might use:
a) a type for events (field event$, for example)
b) a type for active events (also, field event$)
c) a type for event registrations (field event$, field callback ??? - see below)
d) a function to fire off an event (would create a new object of the active_event type)
e) a function allowing an object to register as a listener for an event (create a new object of the event_registration type)
f) an event manager, called in the main loop, that detects all events (loops "for each" on the active_event type), calls all event handlers registered for each active event and then deletes that event from the active_events queue.

The trouble seems to be the callbacks - does Blitz allow passing the name or address of a function as a parameter, storing it in a field of an "event_registration" type, and calling that function to pass the notification of an event to a registered object?

There's my two bits on theory. I don't know if Blitz allows passing a function as a parameter, or supports callbacks.