Changeset 7756 in orxonox.OLD for trunk/src/lib
- Timestamp:
- May 21, 2006, 6:42:09 PM (19 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/event_handler.cc
r7256 r7756 26 26 #include "class_list.h" 27 27 28 using namespace std; 29 28 #include <algorithm> 30 29 31 30 /** … … 43 42 44 43 /* now initialize them all to zero */ 45 this->flush(ES_ALL);46 44 this->withUNICODE(false); 47 45 this->grabEvents(false); 48 46 49 47 this->state = ES_GAME; 50 this->keyMapper = NULL;51 48 this->eventsGrabbed = false; 52 49 } … … 69 66 for(int j = 0; j < EV_NUMBER; ++j) 70 67 { 71 if( this->listeners[i][j] != NULL)68 if(!this->listeners[i][j].empty()) 72 69 { 73 70 PRINTF(2)("forgot to unsubscribe an EventListener!\n");// %s!\n", this->listeners[i][j]->getName()); … … 75 72 } 76 73 } 77 delete this->keyMapper;78 79 74 SDL_QuitSubSystem(SDL_INIT_JOYSTICK); 80 75 … … 90 85 void EventHandler::init() 91 86 { 92 if (this->keyMapper == NULL) 93 { 94 this->keyMapper = new KeyMapper(); 95 this->keyMapper->loadKeyBindings(); 96 } 87 this->keyMapper.loadKeyBindings(); 97 88 } 98 89 … … 138 129 139 130 /** 140 * subscribe to an event131 * @brief subscribe to an event 141 132 * @param el: the event listener that wants to subscribe itself, the listener that will be called when the evetn occures 142 133 * @param state: for which the listener wants to receive events … … 153 144 { 154 145 for(unsigned int i = 0; i < ES_NUMBER; i++) 155 if( likely(this->listeners[i][eventType] == NULL)) 156 this->listeners[i][eventType] = el; 157 else 158 PRINTF(2)("%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); 159 } 160 else 161 if( likely(this->listeners[state][eventType] == NULL)) 162 { 163 this->listeners[state][eventType] = el; 164 } 165 else 166 PRINTF(2)("% 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); 167 } 168 169 170 /** 171 * unsubscribe from the EventHandler 146 { 147 if( !likely(this->listeners[i][eventType].empty())) 148 { 149 PRINTF(2)("'%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); 150 } 151 this->listeners[i][eventType].push_back(el); 152 } 153 } 154 else 155 { 156 if( likely(!this->listeners[state][eventType].empty())) 157 { 158 PRINTF(2)("%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); 159 } 160 this->listeners[state][eventType].push_back(el); 161 } 162 } 163 164 165 /** 166 * @brief unsubscribe from the EventHandler 172 167 * @param state: the stat in which it has been subscribed 173 168 * @param eventType: the event, that shall be unsubscribed … … 181 176 if (state == ES_ALL) 182 177 for (unsigned int i = 0; i < ES_NUMBER; i++) 183 this->listeners[i][eventType] = NULL;184 else 185 this->listeners[state][eventType] = NULL;178 this->listeners[i][eventType].clear(); 179 else 180 this->listeners[state][eventType].clear(); 186 181 } 187 182 … … 203 198 for(unsigned int j = 0; j < EV_NUMBER; j++) 204 199 { 205 if( this->listeners[i][j] == el ) 206 this->listeners[i][j] = NULL; 200 std::vector<EventListener*>::iterator deller = std::find (this->listeners[i][j].begin(), this->listeners[i][j].end(), el); 201 if( deller != this->listeners[i][j].end()) 202 this->listeners[i][j].erase(deller); 207 203 } 208 204 } … … 212 208 for(int j = 0; j < EV_NUMBER; j++) 213 209 { 214 if( this->listeners[state][j] == el ) 215 this->listeners[state][j] = NULL; 216 } 217 } 218 } 210 std::vector<EventListener*>::iterator deller = std::find (this->listeners[state][j].begin(), this->listeners[state][j].end(), el); 211 if( deller != this->listeners[state][j].end()) 212 this->listeners[state][j].erase(deller); 213 } 214 } 215 } 216 217 bool EventHandler::isSubscribed(elState state, int eventType) 218 { 219 return(listeners[state][eventType].empty()) ? false : true; 220 }; 221 219 222 220 223 … … 231 234 for(int j = 0; j < EV_NUMBER; ++j) 232 235 { 233 this->listeners[i][j] = NULL;236 this->listeners[i][j].clear(); 234 237 } 235 238 } … … 239 242 for(int j = 0; j < EV_NUMBER; ++j) 240 243 { 241 this->listeners[state][j] = NULL;244 this->listeners[state][j].clear(); 242 245 } 243 246 } … … 344 347 PRINT(4)("= Got Event nr %i, for state %i", ev.type, this->state); 345 348 346 listener = this->listeners[this->state][ev.type]; 347 if( listener != NULL)349 350 for (unsigned int i = 0; i < this->listeners[this->state][ev.type].size(); i++) 348 351 { 349 352 PRINT(4)("= Event dispatcher msg: This event has been consumed\n"); 350 353 PRINT(4)("=======================================================\n"); 351 listener ->process(ev);352 } 353 else354 {355 PRINT(4)("= Event dispatcher msg: This event has NOT been consumed\n");356 PRINT(4)("=======================================================\n");357 }354 listeners[this->state][ev.type][i]->process(ev); 355 } 356 /* else 357 { 358 PRINT(4)("= Event dispatcher msg: This event has NOT been consumed\n"); 359 PRINT(4)("=======================================================\n"); 360 }*/ 358 361 } 359 362 } … … 393 396 for(int i = 0; i < ES_NUMBER; ++i) 394 397 for(int j = 0; j < EV_NUMBER; ++j) 395 if( this->listeners[i][j] != NULL)396 PRINT(0)("Event %d of State %d subscribed to %s (%p)\n", j, i, this->listeners[i][j] ->getName(), this->listeners[i][j]);398 for (unsigned int evl = 0; evl < this->listeners[i][j].size(); evl++) 399 PRINT(0)("Event %d of State %d subscribed to %s (%p)\n", j, i, this->listeners[i][j][evl]->getName(), this->listeners[i][j][evl]); 397 400 PRINT(0)("============================EH=\n"); 398 401 } -
trunk/src/lib/event/event_handler.h
r7256 r7756 12 12 #include "event_def.h" 13 13 #include <stack> 14 #include <vector> 14 15 15 16 // FORWARD DECLARATION … … 38 39 void flush(elState state); 39 40 /** @returns true, if the @param state has @param eventType subscribed?? */ 40 inline bool isSubscribed(elState state, int eventType) { return(listeners[state][eventType] == NULL)?false:true; };41 bool isSubscribed(elState state, int eventType); 41 42 42 43 … … 54 55 55 56 private: 56 static EventHandler* singletonRef; //!< the singleton reference57 static EventHandler* singletonRef; //!< the singleton reference 57 58 58 EventListener*listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners.59 elState state; //!< the state of the event handlder.60 std::stack<short> stateStack; //!< a stack for the States we are in.61 KeyMapper *keyMapper; //!< reference to the key mapper.59 std::vector<EventListener*> listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners. 60 elState state; //!< the state of the event handlder. 61 std::stack<short> stateStack; //!< a stack for the States we are in. 62 KeyMapper keyMapper; //!< reference to the key mapper. 62 63 63 bool bUNICODE; //!< If unicode should be enabled.64 bool eventsGrabbed; //!< If the events should be grabbed64 bool bUNICODE; //!< If unicode should be enabled. 65 bool eventsGrabbed; //!< If the events should be grabbed 65 66 }; 66 67 -
trunk/src/lib/graphics/text_engine/multi_line_text.cc
r7754 r7756 136 136 if (width > maxWidth || this->getText()[i] == '\n') 137 137 { 138 this->lineEnds.push_back(i); 139 width = 0.0f; 138 if (likely(i > 0)) 139 { 140 this->lineEnds.push_back( i -1 ); 141 width = this->getFont()->getGlyphArray()[this->getText()[i-1]]->advance; 142 } 143 else 144 width = 0.0f; 140 145 } 146 141 147 // Advance the Text. 142 148 if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
Note: See TracChangeset
for help on using the changeset viewer.