I'm not quite sure, but I may have run across a problem involving the Event Manager in Chapter 10. First, I suppose it would be important to note that when attempting to work with the Event Manager, I chose to opt with the version without scripting support. I wanted to start simple and then add on from there (one step at a time).
My trouble revolves around what seems to be a sort of chicken-and-egg problem, specifically with adding an event listener. Say you started off with an Event Manager devoid of any listeners - a clean slate. If you were to add a listener, such as your Event Snooper, passing in the wildcard character, it would first try to validate the event type (wild card). In the validation function, it passes the first two checks to filter out garbage, but the third check is where an issue arises. Because the event type list is empty (initial setting), the iterator will always hit the end of the list, and thus the assertion fails and the function evaluates as false. So as far as I understand, if you have an empty type list, you cannot add a listener. So my question is: How am I to add an Event Type?
In terms of how to fix this, my initial thoughts were:
My trouble revolves around what seems to be a sort of chicken-and-egg problem, specifically with adding an event listener. Say you started off with an Event Manager devoid of any listeners - a clean slate. If you were to add a listener, such as your Event Snooper, passing in the wildcard character, it would first try to validate the event type (wild card). In the validation function, it passes the first two checks to filter out garbage, but the third check is where an issue arises. Because the event type list is empty (initial setting), the iterator will always hit the end of the list, and thus the assertion fails and the function evaluates as false. So as far as I understand, if you have an empty type list, you cannot add a listener. So my question is: How am I to add an Event Type?
In terms of how to fix this, my initial thoughts were:
- One could hardcode the event types into the Event Manager's constructor, sacrificing a bit of flexibility for both speed and simplicity's sake.
- A function could be added to register event types with the Event Manager. This would require a few checks (to avoid collisions and/or duplicates), but would help make things a bit more autonomous.
- Lastly, I suppose the validation function itself could be altered such that it doesn't misinterpret a valid event type. The problem here is that 'valid' seems to differ somewhat with regard to context. By this I mean, an event's type may be valid in a hypothetical situation, but in a particular case it could cause a collision with the hash function, thus registering as invalid.
[/list=1]
Personally, assuming this is actually a problem, I feel inclined to choose option 2. From the source in the SVN, I believe you chose a similar solution with regard to the scripting stuff, but since I haven't read that far yet, I shouldn't make too many guesses there.
I'm perfectly willing to admit that I'm wrong here if you can show me what's what, but this has me a bit puzzled, especially considering I don't see much direction in Chapter 10 concerning the actual registration of event types. I only see it mentioned within the add listener function. I have the sinking feeling that I'm just missing something here, but I'll never know until I ask, right?
Aside from this problem I've had, and the occasional typo (code or otherwise), I really enjoy the book, and I look forward to finishing it!