Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jan 26, 2006, 2:39:31 PM (19 years ago)
Author:
bensch
Message:

Water is better now (but still quite Bad)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/event/event_handler.cc

    r6769 r6771  
    156156  PRINTF(4)("Subscribing event type: %i\n", eventType);
    157157  if( state == ES_ALL )
    158     {
    159       for(unsigned int i = 0; i < ES_NUMBER; i++)
    160         if( likely(this->listeners[i][eventType] == NULL))
    161           this->listeners[i][eventType] = el;
    162         else
    163           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);
    164     }
     158  {
     159    for(unsigned int i = 0; i < ES_NUMBER; i++)
     160      if( likely(this->listeners[i][eventType] == NULL))
     161        this->listeners[i][eventType] = el;
     162      else
     163        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);
     164  }
    165165  else
    166166    if( likely(this->listeners[state][eventType] == NULL))
    167       {
    168         this->listeners[state][eventType] = el;
    169       }
     167    {
     168      this->listeners[state][eventType] = el;
     169    }
    170170    else
    171171      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);
     
    203203    return;
    204204  if( state == ES_ALL)
    205     {
    206       for(unsigned int i = 0; i < ES_NUMBER; i++)
    207         {
    208           for(unsigned int j = 0; j < EV_NUMBER; j++)
    209             {
    210               if( this->listeners[i][j] == el )
    211                 this->listeners[i][j] = NULL;
    212             }
    213         }
    214     }
    215   else
    216     {
    217       for(int j = 0; j < EV_NUMBER; j++)
    218         {
    219           if( this->listeners[state][j] == el )
    220             this->listeners[state][j] = NULL;
    221         }
    222     }
     205  {
     206    for(unsigned int i = 0; i < ES_NUMBER; i++)
     207    {
     208      for(unsigned int j = 0; j < EV_NUMBER; j++)
     209      {
     210        if( this->listeners[i][j] == el )
     211          this->listeners[i][j] = NULL;
     212      }
     213    }
     214  }
     215  else
     216  {
     217    for(int j = 0; j < EV_NUMBER; j++)
     218    {
     219      if( this->listeners[state][j] == el )
     220        this->listeners[state][j] = NULL;
     221    }
     222  }
    223223}
    224224
     
    231231{
    232232  if( state == ES_ALL)
    233     {
    234       for(int i = 0; i < ES_NUMBER; ++i)
    235         {
    236           for(int j = 0; j < EV_NUMBER; ++j)
    237             {
    238               this->listeners[i][j] = NULL;
    239             }
    240         }
    241     }
    242   else
     233  {
     234    for(int i = 0; i < ES_NUMBER; ++i)
    243235    {
    244236      for(int j = 0; j < EV_NUMBER; ++j)
    245         {
    246           this->listeners[state][j] = NULL;
    247         }
    248     }
     237      {
     238        this->listeners[i][j] = NULL;
     239      }
     240    }
     241  }
     242  else
     243  {
     244    for(int j = 0; j < EV_NUMBER; ++j)
     245    {
     246      this->listeners[state][j] = NULL;
     247    }
     248  }
    249249}
    250250
     
    262262    SDL_WM_GrabInput(SDL_GRAB_OFF);
    263263  else
    264     ;//    SDL_WM_GrabInput(SDL_GRAB_ON);
     264    SDL_WM_GrabInput(SDL_GRAB_ON);
    265265}
    266266
     
    276276  EventListener* listener = NULL;
    277277  while( SDL_PollEvent (&event))
    278     {
    279       switch( event.type)
    280         {
    281         case SDL_KEYDOWN:
    282           ev.bPressed = true;
    283           ev.type = event.key.keysym.sym;
    284           if (unlikely(this->bUNICODE))
    285               ev.x = event.key.keysym.unicode;
    286           break;
    287         case SDL_KEYUP:
    288           ev.bPressed = false;
    289           ev.type = event.key.keysym.sym;
    290           if (unlikely(this->bUNICODE))
    291             ev.x = event.key.keysym.unicode;
    292           break;
    293         case SDL_MOUSEMOTION:
    294           ev.bPressed = false;
    295           ev.type = EV_MOUSE_MOTION;
    296           ev.x = event.motion.x;
    297           ev.y = event.motion.y;
    298           ev.xRel = event.motion.xrel;
    299           ev.yRel = event.motion.yrel;
    300           break;
    301         case SDL_MOUSEBUTTONUP:
    302           ev.bPressed = false;
    303           ev.type = event.button.button + SDLK_LAST;
    304           break;
    305         case SDL_MOUSEBUTTONDOWN:
    306           ev.bPressed = true;
    307           ev.type = event.button.button + SDLK_LAST;
    308           break;
    309         case SDL_JOYAXISMOTION:
    310           ev.bPressed = false;
    311           ev.type = EV_JOY_AXIS_MOTION;
    312           break;
    313         case SDL_JOYBALLMOTION:
    314           ev.bPressed = false;
    315           ev.type = EV_JOY_BALL_MOTION;
    316           break;
    317         case SDL_JOYHATMOTION:
    318           ev.bPressed = false;
    319           ev.type = EV_JOY_HAT_MOTION;
    320           break;
    321         case SDL_JOYBUTTONDOWN:
    322           ev.bPressed = true;
    323           ev.type = EV_JOY_BUTTON;
    324           break;
    325         case SDL_JOYBUTTONUP:
    326           ev.bPressed = true;
    327           ev.type = EV_JOY_BUTTON;
    328           break;
    329         case SDL_VIDEORESIZE:
    330           ev.resize = event.resize;
    331           ev.type = EV_VIDEO_RESIZE;
    332           break;
    333         case SDL_QUIT:
    334           ev.type = EV_MAIN_QUIT;
    335           break;
    336         default:
    337           ev.type = EV_UNKNOWN;
    338           break;
    339         }
    340 
    341       /* small debug routine: shows all events dispatched by the event handler */
    342       PRINT(4)("\n==========================| EventHandler::process () |===\n");
    343       PRINT(4)("=  Got Event nr %i, for state %i", ev.type, this->state);
    344 
    345       listener = this->listeners[this->state][ev.type];
    346       if( listener != NULL)
    347         {
    348           PRINT(4)("=  Event dispatcher msg: This event has been consumed\n");
    349           PRINT(4)("=======================================================\n");
    350           listener->process(ev);
    351         }
    352       else
    353         {
    354           PRINT(4)("=  Event dispatcher msg: This event has NOT been consumed\n");
    355           PRINT(4)("=======================================================\n");
    356         }
    357     }
     278  {
     279    switch( event.type)
     280    {
     281      case SDL_KEYDOWN:
     282        ev.bPressed = true;
     283        ev.type = event.key.keysym.sym;
     284        if (unlikely(this->bUNICODE))
     285          ev.x = event.key.keysym.unicode;
     286        break;
     287      case SDL_KEYUP:
     288        ev.bPressed = false;
     289        ev.type = event.key.keysym.sym;
     290        if (unlikely(this->bUNICODE))
     291          ev.x = event.key.keysym.unicode;
     292        break;
     293      case SDL_MOUSEMOTION:
     294        ev.bPressed = false;
     295        ev.type = EV_MOUSE_MOTION;
     296        ev.x = event.motion.x;
     297        ev.y = event.motion.y;
     298        ev.xRel = event.motion.xrel;
     299        ev.yRel = event.motion.yrel;
     300        break;
     301      case SDL_MOUSEBUTTONUP:
     302        ev.bPressed = false;
     303        ev.type = event.button.button + SDLK_LAST;
     304        break;
     305      case SDL_MOUSEBUTTONDOWN:
     306        ev.bPressed = true;
     307        ev.type = event.button.button + SDLK_LAST;
     308        break;
     309      case SDL_JOYAXISMOTION:
     310        ev.bPressed = false;
     311        ev.type = EV_JOY_AXIS_MOTION;
     312        break;
     313      case SDL_JOYBALLMOTION:
     314        ev.bPressed = false;
     315        ev.type = EV_JOY_BALL_MOTION;
     316        break;
     317      case SDL_JOYHATMOTION:
     318        ev.bPressed = false;
     319        ev.type = EV_JOY_HAT_MOTION;
     320        break;
     321      case SDL_JOYBUTTONDOWN:
     322        ev.bPressed = true;
     323        ev.type = EV_JOY_BUTTON;
     324        break;
     325      case SDL_JOYBUTTONUP:
     326        ev.bPressed = true;
     327        ev.type = EV_JOY_BUTTON;
     328        break;
     329      case SDL_VIDEORESIZE:
     330        ev.resize = event.resize;
     331        ev.type = EV_VIDEO_RESIZE;
     332        break;
     333      case SDL_QUIT:
     334        ev.type = EV_MAIN_QUIT;
     335        break;
     336      default:
     337        ev.type = EV_UNKNOWN;
     338        break;
     339    }
     340
     341    /* small debug routine: shows all events dispatched by the event handler */
     342    PRINT(4)("\n==========================| EventHandler::process () |===\n");
     343    PRINT(4)("=  Got Event nr %i, for state %i", ev.type, this->state);
     344
     345    listener = this->listeners[this->state][ev.type];
     346    if( listener != NULL)
     347    {
     348      PRINT(4)("=  Event dispatcher msg: This event has been consumed\n");
     349      PRINT(4)("=======================================================\n");
     350      listener->process(ev);
     351    }
     352    else
     353    {
     354      PRINT(4)("=  Event dispatcher msg: This event has NOT been consumed\n");
     355      PRINT(4)("=======================================================\n");
     356    }
     357  }
    358358}
    359359
Note: See TracChangeset for help on using the changeset viewer.