bbuck/dragon-mud

Address the "1 Emitter per State" policy and work to get one event emitter per stage of scripting.

Closed this issue · 1 comments

bbuck commented

I'm hijacking the "make engines thread safe" issue and completely changing it. Not even going to bother explaining what my goal was with the old ticket. Here's my concerns for the new issue:

  1. Right now, each engine gets it's own event emitter associated with it.
  2. Engine pools (like server level) have 10 emitters then
  3. Currently one emitter is targeted (at random basically)

This works. Mostly. So event handlers associated to that emitter are fired off accordingly. Again, this works. If that engine associated it's once handlers they get dropped off from that emitter after being fired, everything just works (kind of). Okay, so what's with the "kind of" here? Well.... there are now 9 other engines with 9 other emitters with 9 instances of "one time handlers" on them. If the event is fired again and of those 9 are selected (a 9/10 chance) then those "one time handlers" are fired for a second time. Rinse and repeat for 10 attempts.

Also, having a pool of 10 engines with 10 emitters leads to the need for the third point. Another layer has to be implemented to "randomly select" an engine/emitter to fire events too. So this is practically impossible when you introduce a game world with (potentially) thousands of engines floating around that might need to fire events for each other. What kind of system is not very complex that can be handle receiving and emitting events to thousands of receivers?!

Well. To simply, this is to address any concerns with having all engines in a certain tier share an emitter. So the system will have one server emitter for 10 engines (the default pool size), one client emitter for client level engines, and one emitter for game entities. This provides one point of entry for event handling on each level which allows the server level to freely emit events up and down (so the server handler can emit tick events, etc...) to client and all listening entities.

bbuck commented

Try replacing the engine in a Lua handler for the engine pool instead. Then allow handlers to cmpare to each other, replace the current Off implementation with Purge and change Off to remove all handlers that match a given string or some identifier.