Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5291 in orxonox.OLD for trunk/src/lib/event


Ignore:
Timestamp:
Oct 7, 2005, 12:00:46 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: minor bug-fixes in the Event_listener.
still have to find the 'even-level'-bug

Location:
trunk/src/lib/event
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/event_def.h

    r5069 r5291  
    4747    ES_ALL,            //!< you want to register events for all states
    4848
    49     ES_NUMBER,          //!< the number of states
     49    ES_NUMBER,         //!< the number of states
    5050  };
    5151
  • trunk/src/lib/event/event_handler.cc

    r5285 r5291  
    4343
    4444  /* 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
    5247  this->state = ES_GAME;
    5348  this->keyMapper = NULL;
     
    105100   than one state, you have to subscribe for each state again. If you want to subscribe for all states, use
    106101   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 */
    110103void EventHandler::subscribe(EventListener* el, elState state, int eventType)
    111104{
     
    113106  if( state == ES_ALL )
    114107    {
    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))
    117110          this->listeners[i][eventType] = el;
    118111        else
     
    140133{
    141134  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;
    143140}
    144141
     
    152149void EventHandler::unsubscribe(EventListener* el, elState state)
    153150{
    154   if( el == NULL)
     151  if( el == NULL || state >= ES_NUMBER)
    155152    return;
    156153  if( state == ES_ALL)
    157154    {
    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++)
    161158            {
    162159              if( this->listeners[i][j] == el )
     
    167164  else
    168165    {
    169       for(int j = 0; j < EV_NUMBER; ++j)
     166      for(int j = 0; j < EV_NUMBER; j++)
    170167        {
    171168          if( this->listeners[state][j] == el )
     
    319316  PRINT(0)("===============================\n");
    320317  for(int i = 0; i < ES_NUMBER; ++i)
    321   {
    322318    for(int j = 0; j < EV_NUMBER; ++j)
    323     {
    324319      if( this->listeners[i][j] != NULL)
    325       {
    326320        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   }
    330321  PRINT(0)("============================EH=\n");
    331322}
  • trunk/src/lib/event/event_listener.h

    r5279 r5291  
    1818
    1919  /**
    20    *  abstract function that processes events from the handler
     20   * abstract function that processes events from the handler
    2121   * @param event: the event
    22   */
     22   */
    2323  virtual void process(const Event &event) = 0;
    2424};
Note: See TracChangeset for help on using the changeset viewer.