Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4450 in orxonox.OLD


Ignore:
Timestamp:
Jun 1, 2005, 11:05:23 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: commented the event handler and event class

Location:
orxonox/trunk/src/util/event
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/util/event/event.cc

    r4346 r4450  
    2323/**
    2424   \brief standard constructor
    25    \todo this constructor is not jet implemented - do it
    2625*/
    2726Event::Event ()
  • orxonox/trunk/src/util/event/event_def.h

    r4417 r4450  
    1717#define DEFAULT_KEYBIND_FILE "~/.orxonox/orxonox.conf"
    1818
     19
    1920#define EVENT_QUEUE_LENGTH 32
    2021
    21 
     22//! these are the extended event types, that are not included in SDL_keysym
    2223typedef enum extEventTyes
    2324  {
     
    3839  };
    3940
    40 
    41 
     41//! this is an enumeration of all states of the event_handler/game
    4242typedef enum elState
    4343  {
    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
    4747
    48     ES_ALL,
     48    ES_ALL,            //!< you want to register events for all states
    4949
    50     ES_NUMBER,
     50    ES_NUMBER,         //!< the number of states
    5151  };
    5252
  • orxonox/trunk/src/util/event/event_handler.cc

    r4420 r4450  
    7979
    8080
    81 
     81/**
     82   \brief initializes the event handler
     83
     84   this has to be called before the use of the event handler
     85*/
    8286void EventHandler::init()
    8387{
     
    8791
    8892
    89 
     93/**
     94   \brief set the state of the event handler
     95   \param state to which the event handler shall change
     96*/
    9097void EventHandler::setState(elState state)
    9198{
     
    94101
    95102
     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*/
    96113void EventHandler::subscribe(EventListener* el, elState state, int eventType)
    97114{
    98   PRINTF(0)("Subscribing event type: %i\n", eventType);
     115  PRINTF(4)("Subscribing event type: %i\n", eventType);
    99116  if( state == ES_ALL )
    100117    {
     
    103120          this->listeners[i][eventType] = el;
    104121        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);
    106123    }
    107124  else
     
    111128      }
    112129    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*/
    117142void EventHandler::unsubscribe(elState state, int eventType)
    118143{
    119   PRINTF(0)("Unsubscribing event type nr: %i\n", eventType);
     144  PRINTF(4)("Unsubscribing event type nr: %i\n", eventType);
    120145  this->listeners[state][eventType] = NULL;
    121146}
    122147
    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*/
    144155void EventHandler::unsubscribe(EventListener* el, elState state)
    145156{
     
    166177
    167178
    168 
     179/**
     180   \brief flush all registered events
     181   \param in a specific state
     182*/
     183void 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*/
    169210void EventHandler::process()
    170211{
     
    226267
    227268      /* 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); 
    230271     
    231272      listener = this->listeners[this->state][ev.type];
    232273      if( listener != NULL)
    233274        {
    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");     
    235277          listener->process(ev);
    236278        }
    237279      else
    238280        {
    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  
    2121  static EventHandler* getInstance(void);
    2222  virtual ~EventHandler(void);
    23 
    2423  void init();
    2524
     
    2928  void unsubscribe(elState state, int eventType);
    3029  void unsubscribe(EventListener* el, elState state = ES_ALL);
    31 
    3230  void flush(elState state);
    3331
    34   void tick(float t);
    3532  void process();
    36 
    37   void test();
    3833
    3934 private:
     
    4237
    4338 private:
    44   static EventHandler* singletonRef;
     39  static EventHandler* singletonRef;                  //!< the singleton reference
    4540  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
    4843};
    4944
Note: See TracChangeset for help on using the changeset viewer.