views:

325

answers:

1

I'm in the research stage of a project that will require the development of a custom event manager for computer game events.

In the past, the routing code for polling the correct pieces of code for event consumption has been placed entirely within the Event Manager's ProcessEvents() function. Example: The UI needs to be provided the opportunity to consume a Mouse-Click Event, but a player object does not.

The size of the upcoming project is pretty big, and I can see it becoming rather annoying having to put this type of routing in the ProcessEvents() function.

During my reading last night, I read about the concept of registering & unregistering listeners.

This sounds like a great idea, but I'm at a complete loss as to exactly how this works or how I would implement it in VB.NET. I suppose the concept is this. If I create new Monster object, I would somehow register it as a listener for event types such as GunShoot, BombExplode, etc. During the processing of events by the Event Manager, if it comes across a BombExplode event, it would poll each registered listener if they can consume the event.

How could this be implemented efficiently in VB.NET?

Thanks.

+1  A: 

This seems like the perfect scenario for the built in WeakEvent Pattern in .NET.

If you made your subscribers implement IWeakEventListener appropriately, and created the appropriate WeakEventManager classes, you could have listeners that listened to the "event manager" events (which could be implemented in numerous ways), without having to worry about lifetime issues causing memory "leaks".

Reed Copsey