Changeset 5291 in orxonox.OLD for trunk/src/lib/event
- Timestamp:
- Oct 7, 2005, 12:00:46 AM (19 years ago)
- Location:
- trunk/src/lib/event
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/event_def.h
r5069 r5291 47 47 ES_ALL, //!< you want to register events for all states 48 48 49 ES_NUMBER, 49 ES_NUMBER, //!< the number of states 50 50 }; 51 51 -
trunk/src/lib/event/event_handler.cc
r5285 r5291 43 43 44 44 /* now initialize them all to zero */ 45 for(int i = 0; i < ES_NUMBER; i++) 46 { 47 for(int j = 0; j < EV_NUMBER; j++) 48 { 49 this->listeners[i][j] = NULL; 50 } 51 } 45 this->flush(ES_ALL); 46 52 47 this->state = ES_GAME; 53 48 this->keyMapper = NULL; … … 105 100 than one state, you have to subscribe for each state again. If you want to subscribe for all states, use 106 101 state = ES_ALL, which will subscribe your listener for all states together. 107 * 108 * @todo this can also be done with the & operator, and checking for states, just set the esState to 1,2,4,8, and then 15 is equal to ES_ALL 109 */ 102 */ 110 103 void EventHandler::subscribe(EventListener* el, elState state, int eventType) 111 104 { … … 113 106 if( state == ES_ALL ) 114 107 { 115 for( int i = 0; i < ES_NUMBER; ++i)116 if( likely(this->listeners[ state][eventType] == NULL))108 for(unsigned int i = 0; i < ES_NUMBER; i++) 109 if( likely(this->listeners[i][eventType] == NULL)) 117 110 this->listeners[i][eventType] = el; 118 111 else … … 140 133 { 141 134 PRINTF(4)("Unsubscribing event type nr: %i\n", eventType); 142 this->listeners[state][eventType] = NULL; 135 if (state == ES_ALL) 136 for (unsigned int i = 0; i < ES_NUMBER; i++) 137 this->listeners[i][eventType] = NULL; 138 else 139 this->listeners[state][eventType] = NULL; 143 140 } 144 141 … … 152 149 void EventHandler::unsubscribe(EventListener* el, elState state) 153 150 { 154 if( el == NULL )151 if( el == NULL || state >= ES_NUMBER) 155 152 return; 156 153 if( state == ES_ALL) 157 154 { 158 for( int i = 0; i < ES_NUMBER; ++i)159 { 160 for( int j = 0; j < EV_NUMBER; ++j)155 for(unsigned int i = 0; i < ES_NUMBER; i++) 156 { 157 for(unsigned int j = 0; j < EV_NUMBER; j++) 161 158 { 162 159 if( this->listeners[i][j] == el ) … … 167 164 else 168 165 { 169 for(int j = 0; j < EV_NUMBER; ++j)166 for(int j = 0; j < EV_NUMBER; j++) 170 167 { 171 168 if( this->listeners[state][j] == el ) … … 319 316 PRINT(0)("===============================\n"); 320 317 for(int i = 0; i < ES_NUMBER; ++i) 321 {322 318 for(int j = 0; j < EV_NUMBER; ++j) 323 {324 319 if( this->listeners[i][j] != NULL) 325 {326 320 PRINT(0)("Event %d of State %d subscribed to %s (%p)\n", j, i, this->listeners[i][j]->getName(), this->listeners[i][j]); 327 }328 }329 }330 321 PRINT(0)("============================EH=\n"); 331 322 } -
trunk/src/lib/event/event_listener.h
r5279 r5291 18 18 19 19 /** 20 * 20 * abstract function that processes events from the handler 21 21 * @param event: the event 22 */22 */ 23 23 virtual void process(const Event &event) = 0; 24 24 };
Note: See TracChangeset
for help on using the changeset viewer.