Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8148 in orxonox.OLD for trunk/src/lib/event/event_handler.cc


Ignore:
Timestamp:
Jun 5, 2006, 12:46:02 PM (18 years ago)
Author:
bensch
Message:

trunk: output of EventListener Nicer

File:
1 edited

Legend:

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

    r8145 r8148  
    2121#include "event.h"
    2222#include "key_mapper.h"
     23#include "key_names.h"
    2324
    2425#include "compiler.h"
     
    6263EventHandler::~EventHandler ()
    6364{
     65  bool forgotToUnsubscribe = false;
     66
    6467  for(int i = 0; i < ES_NUMBER; ++i)
    6568  {
     
    6871      if(!this->listeners[i][j].empty())
    6972      {
    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        }
    7178      }
    7279    }
    7380  }
     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
    7490  SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
    7591
     
    485501}
    486502
     503
     504/**
     505 * @param state The State to get the Name of.
     506 * @returns the Name of the State.
     507 */
     508const 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 */
     520elState 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
     528const std::string  EventHandler::stateNames[] =
     529{
     530  "game",
     531  "game_menu",
     532  "menu",
     533  "shell",
     534  "all",
     535  "unknown",
     536};
     537
     538
    487539/**
    488540 * @brief outputs some nice information about the EventHandler
     
    497549    for(int j = 0; j < EV_NUMBER; ++j)
    498550      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]);
    500555  }
    501556  PRINT(0)("============================EH=\n");
Note: See TracChangeset for help on using the changeset viewer.