Changeset 4450 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Jun 1, 2005, 11:05:23 PM (19 years ago)
- Location:
- orxonox/trunk/src/util/event
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/util/event/event.cc
r4346 r4450 23 23 /** 24 24 \brief standard constructor 25 \todo this constructor is not jet implemented - do it26 25 */ 27 26 Event::Event () -
orxonox/trunk/src/util/event/event_def.h
r4417 r4450 17 17 #define DEFAULT_KEYBIND_FILE "~/.orxonox/orxonox.conf" 18 18 19 19 20 #define EVENT_QUEUE_LENGTH 32 20 21 21 22 //! these are the extended event types, that are not included in SDL_keysym 22 23 typedef enum extEventTyes 23 24 { … … 38 39 }; 39 40 40 41 41 //! this is an enumeration of all states of the event_handler/game 42 42 typedef enum elState 43 43 { 44 ES_GAME, 45 ES_GAME_MENU, 46 ES_MENU, 44 ES_GAME, //!< the state during the game plays 45 ES_GAME_MENU, //!< state when the menu is called during game 46 ES_MENU, //!< orxonox menu state 47 47 48 ES_ALL, 48 ES_ALL, //!< you want to register events for all states 49 49 50 ES_NUMBER, 50 ES_NUMBER, //!< the number of states 51 51 }; 52 52 -
orxonox/trunk/src/util/event/event_handler.cc
r4420 r4450 79 79 80 80 81 81 /** 82 \brief initializes the event handler 83 84 this has to be called before the use of the event handler 85 */ 82 86 void EventHandler::init() 83 87 { … … 87 91 88 92 89 93 /** 94 \brief set the state of the event handler 95 \param state to which the event handler shall change 96 */ 90 97 void EventHandler::setState(elState state) 91 98 { … … 94 101 95 102 103 /** 104 \brief subscribe to an event 105 \param the event listener that wants to subscribe itself, the listener that will be called when the evetn occures 106 \param state for which the listener wants to receive events 107 \param the event type that wants to be listened for. 108 109 This is one of the most important function of the EventHandler. If you would like to subscribe for more 110 than one state, you have to subscribe for each state again. If you want to subscribe for all states, use 111 state = ES_ALL, which will subscribe your listener for all states together. 112 */ 96 113 void EventHandler::subscribe(EventListener* el, elState state, int eventType) 97 114 { 98 PRINTF( 0)("Subscribing event type: %i\n", eventType);115 PRINTF(4)("Subscribing event type: %i\n", eventType); 99 116 if( state == ES_ALL ) 100 117 { … … 103 120 this->listeners[i][eventType] = el; 104 121 else 105 PRINTF( 0)("Someone tried to subscribe to event %i @ state %i but this event has already been subscribed\n", eventType, state);122 PRINTF(1)("Someone tried to subscribe to event %i @ state %i but this event has already been subscribed\n", eventType, state); 106 123 } 107 124 else … … 111 128 } 112 129 else 113 PRINTF(0)("Someone tried to subscribe to event %i @ state %i but this event has already been subscribed\n", eventType, state); 114 } 115 116 130 PRINTF(1)("Someone tried to subscribe to event %i @ state %i but this event has already been subscribed\n", eventType, state); 131 } 132 133 134 /** 135 \brief unsubscribe from the EventHandler 136 \param the stat in which it has been subscribed 137 \param the event, that shall be unsubscribed 138 139 if you want to unsubscribe an event listener from all subscribed events, just use the 140 unsubscribe(EventListener* el, elState state) function 141 */ 117 142 void EventHandler::unsubscribe(elState state, int eventType) 118 143 { 119 PRINTF( 0)("Unsubscribing event type nr: %i\n", eventType);144 PRINTF(4)("Unsubscribing event type nr: %i\n", eventType); 120 145 this->listeners[state][eventType] = NULL; 121 146 } 122 147 123 void EventHandler::flush(elState state) 124 { 125 if( state == ES_ALL) 126 { 127 for(int i = 0; i < ES_NUMBER; ++i) 128 { 129 for(int j = 0; j < EV_NUMBER; ++j) 130 { 131 this->listeners[i][j] = NULL; 132 } 133 } 134 } 135 else 136 { 137 for(int j = 0; j < EV_NUMBER; ++j) 138 { 139 this->listeners[state][j] = NULL; 140 } 141 } 142 } 143 148 149 /** 150 \brief unsubscribe all events from a specific listener 151 \param the listener that wants to unsubscribe itself 152 \param the state in which the events shall be unsubscribed 153 154 */ 144 155 void EventHandler::unsubscribe(EventListener* el, elState state) 145 156 { … … 166 177 167 178 168 179 /** 180 \brief flush all registered events 181 \param in a specific state 182 */ 183 void EventHandler::flush(elState state) 184 { 185 if( state == ES_ALL) 186 { 187 for(int i = 0; i < ES_NUMBER; ++i) 188 { 189 for(int j = 0; j < EV_NUMBER; ++j) 190 { 191 this->listeners[i][j] = NULL; 192 } 193 } 194 } 195 else 196 { 197 for(int j = 0; j < EV_NUMBER; ++j) 198 { 199 this->listeners[state][j] = NULL; 200 } 201 } 202 } 203 204 205 /** 206 \brief core function of event handler: receives all events from SDL 207 208 The event from the SDL framework are collected here and distributed to all listeners. 209 */ 169 210 void EventHandler::process() 170 211 { … … 226 267 227 268 /* small debug routine: shows alle events dispatched by the event handler */ 228 PRINT( 0)("\n==========================| EventHandler::process () |===\n");229 PRINT( 0)("= Got Event nr %i, for state %i", ev.type, this->state);269 PRINT(4)("\n==========================| EventHandler::process () |===\n"); 270 PRINT(4)("= Got Event nr %i, for state %i", ev.type, this->state); 230 271 231 272 listener = this->listeners[this->state][ev.type]; 232 273 if( listener != NULL) 233 274 { 234 PRINTF(0)("= Event dispatcher msg: This event has been consumed\n"); 275 PRINT(4)("= Event dispatcher msg: This event has been consumed\n"); 276 PRINT(4)("=======================================================\n"); 235 277 listener->process(ev); 236 278 } 237 279 else 238 280 { 239 PRINTF(0)("= Event dispatcher msg: This event has NOT been consumed\n"); 240 } 241 242 PRINT(0)("=======================================================\n"); 243 } 244 } 245 246 247 void EventHandler::test() 248 { 249 PRINT(0)("\n==========================| EventHandler::test () |===\n"); 250 PRINT(0)("Eventhandler init successfuly\n"); 251 KeyMapper km; 252 PRINT(0)("KeyMapper loaded\n"); 253 km.loadKeyBindings(); 254 km.debug(); 255 256 PRINT(0)("=======================================================\n"); 257 } 281 PRINT(4)("= Event dispatcher msg: This event has NOT been consumed\n"); 282 PRINT(4)("=======================================================\n"); 283 } 284 285 286 } 287 } 288 -
orxonox/trunk/src/util/event/event_handler.h
r4420 r4450 21 21 static EventHandler* getInstance(void); 22 22 virtual ~EventHandler(void); 23 24 23 void init(); 25 24 … … 29 28 void unsubscribe(elState state, int eventType); 30 29 void unsubscribe(EventListener* el, elState state = ES_ALL); 31 32 30 void flush(elState state); 33 31 34 void tick(float t);35 32 void process(); 36 37 void test();38 33 39 34 private: … … 42 37 43 38 private: 44 static EventHandler* singletonRef; 39 static EventHandler* singletonRef; //!< the singleton reference 45 40 EventListener*** listeners; //!< a list of registered listeners 46 elState state; 47 KeyMapper* keyMapper; 41 elState state; //!< the state of the event handlder 42 KeyMapper* keyMapper; //!< reference to the key mapper 48 43 }; 49 44
Note: See TracChangeset
for help on using the changeset viewer.