tailieunhanh - Object oriented Game Development -P13

Object oriented Game Development -P13: There’s a better than 50% chance that you have picked this title off the shelf in a bookshop and are wondering if it’s going to be another one of those ‘secrets of the inner circle’ type of titles. You know, the ones that promise to tell you unspoken truths on how to write really cool games but in reality offer up a rehash of a manual you may already have for free anyway. | 346 Object-oriented game development class evt_Event public virtual void Schedule evt_Scheduler pScheduler 0 include include class evt_TimedEvent public evt_Event public void Schedule evt_Scheduler pScheduler pScheduler- AddTimedEvent this class evt_StateEvent public evt_Event public void Schedule evt_Scheduler pScheduler pScheduler- AddStateEvent this class evt_Scheduler public void AddTimedEvent evt_TimedEvent pEvent void AddStateEvent evt_StateEvent pEvent and so we get to keep our encapsulation-preserving interface class evt_EventScheduler class evt_IsEventDriven public void AddEvent evt_Event pEvent Design-driven control 347 private evt_EventScheduler m_pScheduler void evt_IsEventDriven AddEvent evt_Event pEvent pEvent- Schedule m_pScheduler Language issues If I had a penny for every time I d seen a scripting system with a core loop looking like const char cToken MAX_TOKEN_NAME while cToken if strcmp cToken set_position float x y z x y z SetPosition x y z else if strcmp cToken message . . else Warning Unknown command s cToken then I d have enough for a cappuccino and a skinny breakfast muffin at my favourite multinational coffee bar. Leaving aside the horrors of case-sensitive comparisons and the hideous inefficiency of a large number of per-object-per-game-loop string comparisons the main problem with this sort of scripting is the lack of grammar. 348 Object-oriented game development For example the above set_position command can fall flat on its face if presented with set_position 10 15 2 sin t for a multitude of reasons. There are two alternatives for handling grammar An escalating series of special-case bodges in the scripting system. Use of a grammar definition language to generate the script toolset. The latter is in theory more appealing than the former. In practice