Changeset 8148 in orxonox.OLD for trunk/src/lib/event
- Timestamp:
- Jun 5, 2006, 12:46:02 PM (19 years ago)
- Location:
- trunk/src/lib/event
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/event/event_def.h
r7919 r8148 42 42 //! this is an enumeration of all states of the event_handler/game 43 43 typedef enum elState 44 45 46 47 48 49 44 { 45 ES_NULL = -1, 46 ES_GAME = 0, //!< the state during the game plays 47 ES_GAME_MENU = 1, //!< state when the menu is called during game 48 ES_MENU = 2, //!< orxonox menu state 49 ES_SHELL = 3, //!< if we are in shell Modus 50 50 51 51 ES_ALL = 4, //!< you want to register events for all states 52 52 53 ES_NUMBER = 5, //!< the number of states 54 }; 53 ES_NUMBER = 5, //!< the number of states 54 }; 55 56 55 57 56 58 -
trunk/src/lib/event/event_handler.cc
r8145 r8148 21 21 #include "event.h" 22 22 #include "key_mapper.h" 23 #include "key_names.h" 23 24 24 25 #include "compiler.h" … … 62 63 EventHandler::~EventHandler () 63 64 { 65 bool forgotToUnsubscribe = false; 66 64 67 for(int i = 0; i < ES_NUMBER; ++i) 65 68 { … … 68 71 if(!this->listeners[i][j].empty()) 69 72 { 70 PRINTF(2)("forgot to unsubscribe an EventListener!\n");// %s!\n", this->listeners[i][j]->getName()); 73 if (!forgotToUnsubscribe) 74 { 75 forgotToUnsubscribe = true; 76 PRINTF(2)("forgot to unsubscribe an EventListener!\n");// %s!\n", this->listeners[i][j]->getName()); 77 } 71 78 } 72 79 } 73 80 } 81 82 if (forgotToUnsubscribe) 83 { 84 PRINTF(2)("Listing still subscribed EventListeners\n"); 85 PRINTF(2)("========================================\n"); 86 this->debug(); 87 PRINTF(2)("========================================\n"); 88 } 89 74 90 SDL_QuitSubSystem(SDL_INIT_JOYSTICK); 75 91 … … 485 501 } 486 502 503 504 /** 505 * @param state The State to get the Name of. 506 * @returns the Name of the State. 507 */ 508 const std::string& EventHandler::ELStateToString(elState state) 509 { 510 if (state < ES_NUMBER) 511 return EventHandler::stateNames[state]; 512 else 513 return EventHandler::stateNames[5]; 514 } 515 516 /** 517 * @param stateName the Name of the State to retrieve. 518 * @return the State given by the name 519 */ 520 elState EventHandler::StringToELState(const std::string& stateName) 521 { 522 for (unsigned int i = 0 ; i < ES_NUMBER; i++) 523 if (stateName == EventHandler::stateNames[i]) 524 return (elState)i; 525 return ES_NULL; 526 } 527 528 const std::string EventHandler::stateNames[] = 529 { 530 "game", 531 "game_menu", 532 "menu", 533 "shell", 534 "all", 535 "unknown", 536 }; 537 538 487 539 /** 488 540 * @brief outputs some nice information about the EventHandler … … 497 549 for(int j = 0; j < EV_NUMBER; ++j) 498 550 for (unsigned int evl = 0; evl < this->listeners[i][j].size(); evl++) 499 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]); 551 PRINT(0)("Event %s(%d) of State %s(%d) subscribed to %s (%p)\n", 552 EVToKeyName(j).c_str(), j, 553 ELStateToString((elState)i).c_str(), i, 554 this->listeners[i][j][evl]->getName(), this->listeners[i][j][evl]); 500 555 } 501 556 PRINT(0)("============================EH=\n"); -
trunk/src/lib/event/event_handler.h
r7919 r8148 19 19 20 20 //! The one Event Handler from Orxonox 21 class EventHandler : public BaseObject { 21 class EventHandler : public BaseObject 22 { 22 23 23 24 public: 24 25 virtual ~EventHandler(); 25 26 /** @returns a Pointer to the only object of this Class */ … … 29 30 void setState(elState state); 30 31 /** @returns the current state */ 31 32 inline elState getState() const { return this->state; }; 32 33 33 34 void pushState(elState state); … … 52 53 void debug() const; 53 54 54 private: 55 static const std::string& ELStateToString(elState state); 56 static elState StringToELState(const std::string& stateName); 57 58 private: 55 59 EventHandler(); 56 60 57 61 bool findListener(std::vector<EventListener*>::iterator* it, elState state, int eventType, EventListener* listener); 58 62 59 private: 63 public: 64 static const std::string stateNames[]; 65 66 private: 60 67 static EventHandler* singletonRef; //!< the singleton reference 61 68 -
trunk/src/lib/event/key_names.h
r7661 r8148 52 52 std::string SDLKToKeyname( int key); 53 53 54 54 55 #endif /* _KEY_NAMES_H */
Note: See TracChangeset
for help on using the changeset viewer.