Changeset 5388 in orxonox.OLD for trunk/src/lib/event
- Timestamp:
- Oct 16, 2005, 2:05:26 AM (19 years ago)
- Location:
- trunk/src/lib/event
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/event_def.h
r5291 r5388 40 40 typedef enum elState 41 41 { 42 ES_GAME, //!< the state during the game plays 43 ES_GAME_MENU, //!< state when the menu is called during game 44 ES_MENU, //!< orxonox menu state 45 ES_SHELL, //!< if we are in shell Modus 42 ES_NULL = -1, 43 ES_GAME = 0, //!< the state during the game plays 44 ES_GAME_MENU = 1, //!< state when the menu is called during game 45 ES_MENU = 2, //!< orxonox menu state 46 ES_SHELL = 3, //!< if we are in shell Modus 46 47 47 ES_ALL ,//!< you want to register events for all states48 ES_ALL = 4, //!< you want to register events for all states 48 49 49 ES_NUMBER ,//!< the number of states50 ES_NUMBER = 5, //!< the number of states 50 51 }; 51 52 -
trunk/src/lib/event/event_handler.cc
r5371 r5388 26 26 #include "class_list.h" 27 27 28 #include "t_stack.h" 29 28 30 using namespace std; 29 31 … … 47 49 this->state = ES_GAME; 48 50 this->keyMapper = NULL; 51 this->stateStack = NULL; 49 52 } 50 53 … … 72 75 } 73 76 } 77 delete this->stateStack; 74 78 delete this->keyMapper; 75 79 … … 87 91 void EventHandler::init(IniParser* iniParser) 88 92 { 89 this->keyMapper = new KeyMapper(); 90 this->keyMapper->loadKeyBindings(iniParser); 91 } 93 if (this->keyMapper == NULL) 94 { 95 this->keyMapper = new KeyMapper(); 96 this->keyMapper->loadKeyBindings(iniParser); 97 } 98 if (this->stateStack == NULL) 99 this->stateStack = new tStack<short>; 100 } 101 102 /** 103 * pushes the current State in the State-stack, and selects state 104 * @param state the new State to set 105 */ 106 void EventHandler::pushState(elState state) 107 { 108 if (likely(state != ES_NULL && state != ES_ALL && this->stateStack != NULL)) 109 { 110 this->stateStack->push(this->state); 111 this->setState(state); 112 } 113 else 114 { 115 PRINTF(2)("unable to push State\n"); 116 } 117 } 118 119 /** 120 * this removes the topmost stack-entry and select the underlying one 121 * @returns the next stack-entry 122 */ 123 elState EventHandler::popState() 124 { 125 if (unlikely(this->stateStack == NULL)) 126 return ES_NULL; 127 elState state = (elState)this->stateStack->pop(); 128 if (state == ES_NULL) 129 { 130 PRINTF(2)("No more states availiable. (unable to pop state)\n"); 131 return ES_NULL; 132 } 133 else 134 { 135 this->setState(state); 136 return state; 137 } 138 } 139 92 140 93 141 /** -
trunk/src/lib/event/event_handler.h
r5309 r5388 14 14 // FORWARD DECLARATION 15 15 class EventListener; 16 template <class T> class tList; 16 template<class T> class tList; 17 template<class T> class tStack; 17 18 class IniParser; 18 19 … … 30 31 /** @returns the current state */ 31 32 inline elState getState() const { return this->state; }; 33 34 void pushState(elState state); 35 elState popState(); 32 36 33 37 void subscribe(EventListener* el, elState state, int eventType); … … 50 54 static EventHandler* singletonRef; //!< the singleton reference 51 55 52 EventListener* listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners 53 elState state; //!< the state of the event handlder 54 KeyMapper* keyMapper; //!< reference to the key mapper 56 EventListener* listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners. 57 elState state; //!< the state of the event handlder. 58 tStack<short>* stateStack; //!< a stack for the States we are in. 59 KeyMapper* keyMapper; //!< reference to the key mapper. 60 55 61 }; 56 62
Note: See TracChangeset
for help on using the changeset viewer.