Changeset 4780 in orxonox.OLD for orxonox/trunk/src/lib/event/event_handler.cc
- Timestamp:
- Jul 2, 2005, 10:55:47 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/event/event_handler.cc
r4519 r4780 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 11 11 ### File Specific: 12 12 main-programmer: Patrick Boenzli 13 co-programmer: 13 co-programmer: 14 14 */ 15 15 … … 31 31 \brief standard constructor 32 32 */ 33 EventHandler::EventHandler () 34 { 35 this->setClassID(CL_EVENT_HANDLER, "EventHandler"); 33 EventHandler::EventHandler () 34 { 35 this->setClassID(CL_EVENT_HANDLER, "EventHandler"); 36 36 37 37 this->listeners = new EventListener**[ES_NUMBER]; … … 43 43 { 44 44 for(int j = 0; j < SDLK_LAST; ++j) 45 46 47 45 { 46 this->listeners[i][j] = NULL; 47 } 48 48 } 49 49 this->state = ES_GAME; … … 61 61 62 62 */ 63 EventHandler::~EventHandler () 63 EventHandler::~EventHandler () 64 64 { 65 65 EventHandler::singletonRef = NULL; … … 99 99 than one state, you have to subscribe for each state again. If you want to subscribe for all states, use 100 100 state = ES_ALL, which will subscribe your listener for all states together. 101 * 102 * \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 101 103 */ 102 104 void EventHandler::subscribe(EventListener* el, elState state, int eventType) … … 106 108 { 107 109 for(int i = 0; i < ES_NUMBER; ++i) 108 109 110 111 PRINTF(1)("Someone tried to subscribe to event %i @ state %i but this event has already been subscribed\n", eventType, state);112 } 113 else 110 if( likely(this->listeners[state][eventType] == NULL)) 111 this->listeners[i][eventType] = el; 112 else 113 PRINTF(1)("%s of class %s tried to subscribe to event %i @ state %i but this event has already been subscribed\n", el->getName(), el->getClassName(), eventType, state); 114 } 115 else 114 116 if( likely(this->listeners[state][eventType] == NULL)) 115 117 { 116 118 this->listeners[state][eventType] = el; 117 119 } 118 120 else 119 PRINTF(1)(" Someone tried to subscribe to event %i @ state %i but this event has already been subscribed\n", eventType, state);121 PRINTF(1)("% of class %s tried to subscribe to event %i @ state %i but this event has already been subscribed\n", el->getName(), el->getClassName(), eventType, state); 120 122 } 121 123 … … 126 128 \param eventType: the event, that shall be unsubscribed 127 129 128 if you want to unsubscribe an event listener from all subscribed events, just use the 130 if you want to unsubscribe an event listener from all subscribed events, just use the 129 131 unsubscribe(EventListener* el, elState state) function 130 132 */ … … 140 142 \param el: the listener that wants to unsubscribe itself 141 143 \param state: the state in which the events shall be unsubscribed 142 144 143 145 */ 144 146 void EventHandler::unsubscribe(EventListener* el, elState state) … … 147 149 { 148 150 for(int i = 0; i < ES_NUMBER; ++i) 149 150 151 152 153 154 155 151 { 152 for(int j = 0; j < EV_NUMBER; ++j) 153 { 154 if( this->listeners[i][j] == el ) 155 this->listeners[i][j] = NULL; 156 } 157 } 156 158 } 157 159 else 158 160 { 159 161 for(int j = 0; j < EV_NUMBER; ++j) 160 161 162 163 162 { 163 if( this->listeners[state][j] == el ) 164 this->listeners[state][j] = NULL; 165 } 164 166 } 165 167 } … … 175 177 { 176 178 for(int i = 0; i < ES_NUMBER; ++i) 177 178 179 180 181 182 179 { 180 for(int j = 0; j < EV_NUMBER; ++j) 181 { 182 this->listeners[i][j] = NULL; 183 } 184 } 183 185 } 184 186 else 185 187 { 186 188 for(int j = 0; j < EV_NUMBER; ++j) 187 188 189 190 } 191 } 192 193 194 /** 195 \brief core function of event handler: receives all events from SDL 189 { 190 this->listeners[state][j] = NULL; 191 } 192 } 193 } 194 195 196 /** 197 \brief core function of event handler: receives all events from SDL 196 198 197 199 The event from the SDL framework are collected here and distributed to all listeners. … … 205 207 { 206 208 switch( event.type) 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 /* small debug routine: shows all eevents dispatched by the event handler */209 { 210 case SDL_KEYDOWN: 211 ev.bPressed = true; 212 ev.type = event.key.keysym.sym; 213 break; 214 case SDL_KEYUP: 215 ev.bPressed = false; 216 ev.type = event.key.keysym.sym; 217 break; 218 case SDL_MOUSEMOTION: 219 ev.bPressed = false; 220 ev.type = EV_MOUSE_MOTION; 221 ev.x = event.motion.x; 222 ev.y = event.motion.y; 223 ev.xRel = event.motion.xrel; 224 ev.yRel = event.motion.yrel; 225 break; 226 case SDL_MOUSEBUTTONUP: 227 ev.bPressed = false; 228 ev.type = event.button.button + SDLK_LAST; 229 break; 230 case SDL_MOUSEBUTTONDOWN: 231 ev.bPressed = true; 232 ev.type = event.button.button + SDLK_LAST; 233 break; 234 case SDL_JOYAXISMOTION: 235 ev.bPressed = false; 236 ev.type = EV_JOY_AXIS_MOTION; 237 break; 238 case SDL_JOYBALLMOTION: 239 ev.bPressed = false; 240 ev.type = EV_JOY_BALL_MOTION; 241 break; 242 case SDL_JOYHATMOTION: 243 ev.bPressed = false; 244 ev.type = EV_JOY_HAT_MOTION; 245 break; 246 case SDL_JOYBUTTONDOWN: 247 ev.bPressed = true; 248 ev.type = EV_JOY_BUTTON; 249 break; 250 case SDL_JOYBUTTONUP: 251 ev.bPressed = true; 252 ev.type = EV_JOY_BUTTON; 253 break; 254 default: 255 ev.type = EV_UNKNOWN; 256 break; 257 } 258 259 /* small debug routine: shows all events dispatched by the event handler */ 258 260 PRINT(4)("\n==========================| EventHandler::process () |===\n"); 259 PRINT(4)("= Got Event nr %i, for state %i", ev.type, this->state); 260 261 PRINT(4)("= Got Event nr %i, for state %i", ev.type, this->state); 262 261 263 listener = this->listeners[this->state][ev.type]; 262 264 if( listener != NULL) 263 264 265 PRINT(4)("=======================================================\n"); 266 267 265 { 266 PRINT(4)("= Event dispatcher msg: This event has been consumed\n"); 267 PRINT(4)("=======================================================\n"); 268 listener->process(ev); 269 } 268 270 else 269 { 270 PRINT(4)("= Event dispatcher msg: This event has NOT been consumed\n"); 271 PRINT(4)("=======================================================\n"); 272 } 273 274 275 } 276 } 277 271 { 272 PRINT(4)("= Event dispatcher msg: This event has NOT been consumed\n"); 273 PRINT(4)("=======================================================\n"); 274 } 275 } 276 } 277
Note: See TracChangeset
for help on using the changeset viewer.