Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7868 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
May 26, 2006, 1:21:32 PM (19 years ago)
Author:
bensch
Message:

trunk: merge Check in the Event-changes:
r7867 | bensch | 2006-05-26 13:19:46 +0200 (Fri, 26 May 2006) | 1 line

Events better subscribed


r7866 | bensch | 2006-05-26 13:11:10 +0200 (Fri, 26 May 2006) | 1 line

Events are subscribed at the EventListener, and not the EventHandler

Location:
trunk/src
Files:
24 edited

Legend:

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

    r5553 r7868  
    1212#include "SDL/SDL_keysym.h"
    1313#endif
    14 #include "stdincl.h"
    1514
    1615
  • trunk/src/lib/event/event_handler.cc

    r7756 r7868  
    171171   unsubscribe(EventListener* el, elState state) function
    172172*/
    173 void EventHandler::unsubscribe(elState state, int eventType)
     173void EventHandler::unsubscribe(EventListener* el, elState state, int eventType)
    174174{
    175175  PRINTF(4)("Unsubscribing event type nr: %i\n", eventType);
    176176  if (state == ES_ALL)
    177177    for (unsigned int i = 0; i < ES_NUMBER; i++)
    178       this->listeners[i][eventType].clear();
    179   else
    180     this->listeners[state][eventType].clear();
    181 }
    182 
    183 
    184 /**
    185  * unsubscribe all events from a specific listener
     178    {
     179      std::vector<EventListener*>::iterator listener =
     180         std::find(this->listeners[i][eventType].begin(),
     181                   this->listeners[i][eventType].end(),
     182                   el);
     183      if (listener != this->listeners[i][eventType].end())
     184        this->listeners[i][eventType].erase(listener);
     185    }
     186  else
     187  {
     188    std::vector<EventListener*>::iterator listener =
     189        std::find(this->listeners[state][eventType].begin(),
     190                  this->listeners[state][eventType].end(),
     191                  el);
     192    if (listener != this->listeners[state][eventType].end())
     193      this->listeners[state][eventType].erase(listener);
     194  }
     195}
     196
     197
     198/**
     199 * @brief unsubscribe all events from a specific listener
    186200 * @param el: the listener that wants to unsubscribe itself
    187201 * @param state: the state in which the events shall be unsubscribed
    188 
    189 */
     202 */
    190203void EventHandler::unsubscribe(EventListener* el, elState state)
    191204{
  • trunk/src/lib/event/event_handler.h

    r7756 r7868  
    3535
    3636  void subscribe(EventListener* el, elState state, int eventType);
    37   void unsubscribe(elState state, int eventType);
     37  void unsubscribe(EventListener* el, elState state, int eventType);
    3838  void unsubscribe(EventListener* el, elState state = ES_ALL);
    3939  void flush(elState state);
  • trunk/src/lib/event/event_listener.cc

    r4866 r7868  
    1919#include "event_handler.h"
    2020
    21 using namespace std;
    22 
    23 
    2421/**
    25  * standard constructor
    26 */
     22 * @brief standard constructor
     23 */
    2724EventListener::EventListener ()
    2825{
     
    3229
    3330/**
    34  *  standard deconstructor
    35 */
     31 * @brief standard deconstructor
     32 *
     33 * Unsubscribes all Subscribed Events, of this EventListener.
     34 */
    3635EventListener::~EventListener ()
    3736{
     
    3938  EventHandler::getInstance()->unsubscribe(this, ES_ALL);
    4039}
     40
     41bool EventListener::isEventSubscribed(elState state, int eventType) const
     42{
     43  return EventHandler::getInstance()->isSubscribed(state, eventType);
     44}
     45
     46
     47/**
     48 * @brief Subscribes an Events to this EventListener.
     49 * @param state the state to subscribe to.
     50 * @param eventType the Type of Event to subscribe.
     51 */
     52void EventListener::subscribeEvent(elState state, int eventType)
     53{
     54  EventHandler::getInstance()->subscribe(this, state, eventType);
     55}
     56
     57
     58/**
     59 * @brief Unubscribes an Event from this EventListener.
     60 * @param state the state to unsubscribe from.
     61 * @param eventType the Type of Event to unsubscribe.
     62 */
     63void EventListener::unsubscribeEvent(elState state, int eventType)
     64{
     65  EventHandler::getInstance()->unsubscribe(this, state, eventType);
     66}
     67
     68void EventListener::unsubscribeEvents(elState state)
     69{
     70  EventHandler::getInstance()->unsubscribe(this, state);
     71}
     72
  • trunk/src/lib/event/event_listener.h

    r5291 r7868  
    99#include "base_object.h"
    1010#include "event.h"
     11#include "event_def.h"
    1112
    1213//! A class for event listener
     
    1718  virtual ~EventListener();
    1819
     20  bool isEventSubscribed(elState state, int eventType) const;
     21
     22  void subscribeEvent(elState state, int eventType);
     23  void unsubscribeEvent(elState state, int eventType);
     24  void unsubscribeEvents(elState state = ES_ALL);
     25
    1926  /**
    20    * abstract function that processes events from the handler
     27   * @brief abstract function that processes events from the handler
    2128   * @param event: the event
    2229   */
    2330  virtual void process(const Event &event) = 0;
     31
    2432};
    2533
  • trunk/src/lib/graphics/graphics_engine.cc

    r7840 r7868  
    1818#include "graphics_engine.h"
    1919#include "util/loading/resource_manager.h"
    20 #include "event_handler.h"
    2120#include "state.h"
    2221
  • trunk/src/lib/gui/gl_gui/glgui_handler.cc

    r7840 r7868  
    3131    this->setClassID(CL_GLGUI_HANDLER, "GLGuiHandler");
    3232    this->setName("GLGuiHandler");
     33
     34    //this->subscribeEvent()
    3335
    3436  }
  • trunk/src/lib/gui/gl_gui/glgui_widget.h

    r7855 r7868  
    5656    bool focusOverWidget(float x, float y);
    5757
    58     // if something was clickt on the GUI-widget.
     58
     59    virtual void update() {};
     60    virtual void draw() const;
     61
     62    Material& backMaterial() { return this->backMat; };
     63    const Material& backMaterial() const { return this->backMat; };
     64
     65    Material& frontMaterial() { return this->frontMat; };
     66    const Material& frontMaterial() const { return this->frontMat; };
     67
     68  protected:
     69        // if something was clickt on the GUI-widget.
    5970    virtual void clicked(const Event& event) {};
    6071    virtual void released(const Event& event) {};
     
    6576    virtual void destroyed() {};
    6677
    67     virtual void update() {};
    68     virtual void draw() const;
    6978
    70     Material& backMaterial() { return this->backMat; };
    71     Material& frontMaterial() { return this->frontMat; };
    72 
    73   protected:
    7479    inline void startDraw() const { glPushMatrix(); glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0); };
    7580    inline void endDraw() const { glPopMatrix(); };
  • trunk/src/lib/shell/shell.cc

    r7764 r7868  
    6565
    6666    // EVENT-Handler subscription of '`' to all States.
    67     EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_BACKQUOTE);
    68     EventHandler::getInstance()->subscribe(this, ES_ALL, SDLK_F12);
    69     EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEUP);
    70     EventHandler::getInstance()->subscribe(this, ES_SHELL, SDLK_PAGEDOWN);
    71     EventHandler::getInstance()->subscribe(this, ES_SHELL, EV_VIDEO_RESIZE);
     67    this->subscribeEvent(ES_ALL, SDLK_BACKQUOTE);
     68    this->subscribeEvent(ES_ALL, SDLK_F12);
     69    this->subscribeEvent(ES_SHELL, SDLK_PAGEUP);
     70    this->subscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
     71    this->subscribeEvent(ES_SHELL, EV_VIDEO_RESIZE);
    7272
    7373    // BUFFER
  • trunk/src/lib/shell/shell_input.cc

    r7858 r7868  
    2020#include "shell_command.h"
    2121#include "shell_command_class.h"
    22 #include "event_handler.h"
    2322
    2423#include "debug.h"
     
    5049    this->setRepeatDelay(.3, .05);
    5150
    52     // subscribe all keyboard commands to ES_SEHLL
    53     EventHandler* evh = EventHandler::getInstance();
     51    // subscribe all keyboard commands to ES_SHELL
    5452    for (int i = 1; i < SDLK_LAST; i++)
    5553    {
    56       if (!evh->isSubscribed(ES_SHELL, i))
    57         evh->subscribe(this, ES_SHELL, i);
     54      if (!this->isEventSubscribed(ES_SHELL, i))
     55        this->subscribeEvent(ES_SHELL, i);
    5856    }
    5957    // unsubscribe unused TODO improve.
    60     evh->unsubscribe(ES_SHELL, SDLK_BACKQUOTE);
    61     evh->unsubscribe(ES_SHELL, SDLK_F12);
    62     evh->unsubscribe(ES_SHELL, SDLK_PAGEUP);
    63     evh->unsubscribe(ES_SHELL, SDLK_PAGEDOWN);
     58    this->unsubscribeEvent(ES_SHELL, SDLK_BACKQUOTE);
     59    this->unsubscribeEvent(ES_SHELL, SDLK_F12);
     60    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEUP);
     61    this->unsubscribeEvent(ES_SHELL, SDLK_PAGEDOWN);
    6462
    6563  }
  • trunk/src/lib/util/loading/game_loader.cc

    r7374 r7868  
    2626#include "util/loading/resource_manager.h"
    2727
    28 #include "event_handler.h"
    29 
    30 
    31 namespace OrxShell
    32 {
    33 
    34   SHELL_COMMAND(quit, GameLoader, stop)
    35   ->describe("quits the game")
    36   ->setAlias("orxoquit");
    37 
    38 
    39   GameLoader* GameLoader::singletonRef = NULL;
    40 
    41 
    42   /**
    43    *  simple constructor
    44    */
    45   GameLoader::GameLoader ()
    46   {
    47     this->setClassID(CL_GAME_LOADER, "GameLoader");
    48     this->setName("GameLoader");
    49     this->bRun = true;
    50   }
    51 
    52 
    53   /**
    54    *  simple deconstructor
    55    */
    56   GameLoader::~GameLoader ()
    57   {
    58     if( this->currentCampaign)
    59       delete this->currentCampaign;
    60     this->currentCampaign = NULL;
    61   }
    62 
    63 
    64   /**
    65    *  initializes the GameLoader
    66    */
    67   ErrorMessage GameLoader::init()
    68   {
    69     if(this->currentCampaign != NULL)
    70       this->currentCampaign->init();
    71 
    72     this->eventHandler = EventHandler::getInstance();
    73     this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_PAUSE);
    74     this->eventHandler->subscribe(this, ES_ALL, EV_MAIN_QUIT);          //< External Quit Event
    75     this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_QUIT);
    76     this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_NEXT_WORLD);
    77     this->eventHandler->subscribe(this, ES_GAME, KeyMapper::PEV_PREVIOUS_WORLD);
    78   }
    79 
    80 
    81   /**
    82    *  reads a campaign definition file into a campaign class
    83    * @param fileName to be loaded
    84    * @returns the loaded campaign
    85    *
    86    * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    87    */
    88   ErrorMessage GameLoader::loadCampaign(const std::string& fileName)
    89   {
    90     ErrorMessage errorCode;
    91     std::string campaignName = ResourceManager::getFullName(fileName);
    92     if (!campaignName.empty())
     28#include "key_mapper.h"
     29
     30
     31
     32SHELL_COMMAND(quit, GameLoader, stop)
     33->describe("quits the game")
     34->setAlias("orxoquit");
     35
     36
     37GameLoader* GameLoader::singletonRef = NULL;
     38
     39
     40/**
     41 *  simple constructor
     42 */
     43GameLoader::GameLoader ()
     44{
     45  this->setClassID(CL_GAME_LOADER, "GameLoader");
     46  this->setName("GameLoader");
     47  this->bRun = true;
     48}
     49
     50
     51/**
     52 *  simple deconstructor
     53 */
     54GameLoader::~GameLoader ()
     55{
     56  if( this->currentCampaign)
     57    delete this->currentCampaign;
     58  this->currentCampaign = NULL;
     59}
     60
     61
     62/**
     63 *  initializes the GameLoader
     64 */
     65ErrorMessage GameLoader::init()
     66{
     67  if(this->currentCampaign != NULL)
     68    this->currentCampaign->init();
     69
     70  this->subscribeEvent(ES_GAME, KeyMapper::PEV_PAUSE);
     71  this->subscribeEvent(ES_ALL, EV_MAIN_QUIT);          //< External Quit Event
     72  this->subscribeEvent(ES_GAME, KeyMapper::PEV_QUIT);
     73  this->subscribeEvent(ES_GAME, KeyMapper::PEV_NEXT_WORLD);
     74  this->subscribeEvent(ES_GAME, KeyMapper::PEV_PREVIOUS_WORLD);
     75}
     76
     77
     78/**
     79 *  reads a campaign definition file into a campaign class
     80 * @param fileName to be loaded
     81 * @returns the loaded campaign
     82 *
     83 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     84 */
     85ErrorMessage GameLoader::loadCampaign(const std::string& fileName)
     86{
     87  ErrorMessage errorCode;
     88  std::string campaignName = ResourceManager::getFullName(fileName);
     89  if (!campaignName.empty())
     90  {
     91    this->currentCampaign = this->fileToCampaign(campaignName);
     92  }
     93}
     94
     95
     96/**
     97 *  reads a campaign definition file into a campaign class
     98 * @param fileName to be loaded
     99 * @returns the loaded campaign
     100 *
     101 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     102 */
     103ErrorMessage GameLoader::loadNetworkCampaign(const std::string& fileName)
     104{
     105  ErrorMessage errorCode;
     106  std::string campaignName = ResourceManager::getFullName(fileName);
     107  if (!campaignName.empty())
     108  {
     109    this->currentCampaign = this->fileToCampaign(campaignName);
     110  }
     111}
     112
     113
     114/**
     115 *  loads a debug campaign for test purposes only.
     116 * @param campaignID the identifier of the campaign.
     117 * @returns error message if not able to do so.
     118 */
     119ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
     120{
     121  switch(campaignID)
     122  {
     123      /*
     124         Debug Level 0: Debug level used to test the base frame work.
     125         As you can see, all storyentity data is allocated before game
     126         start. the storyentity will load themselfs shortly before start
     127         through the StoryEntity::init() funtion.
     128      */
     129    case DEBUG_CAMPAIGN_0:
     130      {
     131        /*        Campaign* debugCampaign = new Campaign();
     132
     133                World* world0 = new World(DEBUG_WORLD_0);
     134                world0->setNextStoryID(WORLD_ID_1);
     135                debugCampaign->addEntity(world0, WORLD_ID_0);
     136
     137                World* world1 = new World(DEBUG_WORLD_1);
     138                world1->setNextStoryID(WORLD_ID_2);
     139                debugCampaign->addEntity(world1, WORLD_ID_1);
     140
     141                World* world2 = new World(DEBUG_WORLD_2);
     142                world2->setNextStoryID(WORLD_ID_GAMEEND);
     143                debugCampaign->addEntity(world2, WORLD_ID_2);
     144
     145                this->currentCampaign = debugCampaign;
     146                break;*/
     147      }
     148  }
     149}
     150
     151
     152/**
     153 *  starts the current entity
     154 * @returns error code if this action has caused a error
     155 */
     156ErrorMessage GameLoader::start()
     157{
     158  if(this->currentCampaign != NULL)
     159  {
     160    this->currentCampaign->start();
     161  }
     162}
     163
     164
     165/**
     166 *  stops the current entity
     167 * @returns error code if this action has caused a error
     168 *
     169 *  ATTENTION: this function shouldn't call other functions, or if so, they must return
     170 *  after finishing. If you ignore or forget to do so, the current entity is not able to
     171 *  terminate and it will run in the background or the ressources can't be freed or even
     172 *  worse: are freed and the program will end in a segmentation fault!
     173 *  hehehe, have ya seen it... :)
     174 */
     175void GameLoader::stop()
     176{
     177  if(this->currentCampaign != NULL)
     178    this->currentCampaign->stop();
     179}
     180
     181
     182/**
     183 *  pause the current entity
     184 * @returns error code if this action has caused a error
     185 *
     186 * this pauses the current entity or passes this call forth to the running entity.
     187 */
     188ErrorMessage GameLoader::pause()
     189{
     190  this->isPaused = true;
     191  if(this->currentCampaign != NULL)
     192    this->currentCampaign->pause();
     193}
     194
     195
     196/**
     197 *  resumes a pause
     198 * @returns error code if this action has caused a error
     199 *
     200 *  this resumess the current entity or passes this call forth to the running entity.
     201 */
     202ErrorMessage GameLoader::resume()
     203{
     204  this->isPaused = false;
     205  if(this->currentCampaign != NULL)
     206    this->currentCampaign->resume();
     207}
     208
     209
     210/**
     211 *  reads a campaign definition file into a campaign class
     212 * @param fileName to be loaded
     213 * @returns the loaded campaign
     214 *
     215 * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
     216 */
     217Campaign* GameLoader::fileToCampaign(const std::string& fileName)
     218{
     219  /* do not entirely load the campaign. just the current world
     220     before start of each world, it has to be initialized so it
     221     can load everything it needs into memory then.
     222  */
     223
     224  if( fileName.empty())
     225  {
     226    PRINTF(2)("No filename specified for loading");
     227    return NULL;
     228  }
     229
     230  TiXmlDocument XMLDoc(fileName);
     231  // load the campaign document
     232  if( !XMLDoc.LoadFile(fileName))
     233  {
     234    // report an error
     235    PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
     236    return NULL;
     237  }
     238
     239  // check basic validity
     240  TiXmlElement* root = XMLDoc.RootElement();
     241  assert( root != NULL);
     242
     243  if( strcmp( root->Value(), "Campaign"))
     244  {
     245    // report an error
     246    PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
     247    return NULL;
     248  }
     249
     250  // construct campaign
     251  return new Campaign( root);
     252}
     253
     254
     255
     256/**
     257 *  handle keyboard commands
     258 * @param event the event to handle
     259 */
     260void GameLoader::process(const Event& event)
     261{
     262  if( event.type == KeyMapper::PEV_NEXT_WORLD)
     263  {
     264    if( likely(event.bPressed))
    93265    {
    94       this->currentCampaign = this->fileToCampaign(campaignName);
     266      this->switchToNextLevel();
    95267    }
    96268  }
    97 
    98 
    99   /**
    100    *  reads a campaign definition file into a campaign class
    101    * @param fileName to be loaded
    102    * @returns the loaded campaign
    103    *
    104    * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    105    */
    106   ErrorMessage GameLoader::loadNetworkCampaign(const std::string& fileName)
    107   {
    108     ErrorMessage errorCode;
    109     std::string campaignName = ResourceManager::getFullName(fileName);
    110     if (!campaignName.empty())
     269  else if( event.type == KeyMapper::PEV_PAUSE)
     270  {
     271    if( likely(event.bPressed))
    111272    {
    112       this->currentCampaign = this->fileToCampaign(campaignName);
     273      if(this->isPaused)
     274        this->resume();
     275      else
     276        this->pause();
    113277    }
    114278  }
    115 
    116 
    117   /**
    118    *  loads a debug campaign for test purposes only.
    119    * @param campaignID the identifier of the campaign.
    120    * @returns error message if not able to do so.
    121    */
    122   ErrorMessage GameLoader::loadDebugCampaign(Uint32 campaignID)
    123   {
    124     switch(campaignID)
    125     {
    126         /*
    127            Debug Level 0: Debug level used to test the base frame work.
    128            As you can see, all storyentity data is allocated before game
    129            start. the storyentity will load themselfs shortly before start
    130            through the StoryEntity::init() funtion.
    131         */
    132       case DEBUG_CAMPAIGN_0:
    133         {
    134           /*        Campaign* debugCampaign = new Campaign();
    135 
    136                   World* world0 = new World(DEBUG_WORLD_0);
    137                   world0->setNextStoryID(WORLD_ID_1);
    138                   debugCampaign->addEntity(world0, WORLD_ID_0);
    139 
    140                   World* world1 = new World(DEBUG_WORLD_1);
    141                   world1->setNextStoryID(WORLD_ID_2);
    142                   debugCampaign->addEntity(world1, WORLD_ID_1);
    143 
    144                   World* world2 = new World(DEBUG_WORLD_2);
    145                   world2->setNextStoryID(WORLD_ID_GAMEEND);
    146                   debugCampaign->addEntity(world2, WORLD_ID_2);
    147 
    148                   this->currentCampaign = debugCampaign;
    149                   break;*/
    150         }
    151     }
    152   }
    153 
    154 
    155   /**
    156    *  starts the current entity
    157    * @returns error code if this action has caused a error
    158    */
    159   ErrorMessage GameLoader::start()
    160   {
    161     if(this->currentCampaign != NULL)
    162     {
    163       this->currentCampaign->start();
    164     }
    165   }
    166 
    167 
    168   /**
    169    *  stops the current entity
    170    * @returns error code if this action has caused a error
    171    *
    172    *  ATTENTION: this function shouldn't call other functions, or if so, they must return
    173    *  after finishing. If you ignore or forget to do so, the current entity is not able to
    174    *  terminate and it will run in the background or the ressources can't be freed or even
    175    *  worse: are freed and the program will end in a segmentation fault!
    176    *  hehehe, have ya seen it... :)
    177    */
    178   void GameLoader::stop()
    179   {
    180     if(this->currentCampaign != NULL)
    181       this->currentCampaign->stop();
    182   }
    183 
    184 
    185   /**
    186    *  pause the current entity
    187    * @returns error code if this action has caused a error
    188    *
    189    * this pauses the current entity or passes this call forth to the running entity.
    190    */
    191   ErrorMessage GameLoader::pause()
    192   {
    193     this->isPaused = true;
    194     if(this->currentCampaign != NULL)
    195       this->currentCampaign->pause();
    196   }
    197 
    198 
    199   /**
    200    *  resumes a pause
    201    * @returns error code if this action has caused a error
    202    *
    203    *  this resumess the current entity or passes this call forth to the running entity.
    204    */
    205   ErrorMessage GameLoader::resume()
    206   {
    207     this->isPaused = false;
    208     if(this->currentCampaign != NULL)
    209       this->currentCampaign->resume();
    210   }
    211 
    212 
    213   /**
    214    *  reads a campaign definition file into a campaign class
    215    * @param fileName to be loaded
    216    * @returns the loaded campaign
    217    *
    218    * this will interprete the map/campaign files and recursivly load a tree of worlds/campaigns
    219    */
    220   Campaign* GameLoader::fileToCampaign(const std::string& fileName)
    221   {
    222     /* do not entirely load the campaign. just the current world
    223        before start of each world, it has to be initialized so it
    224        can load everything it needs into memory then.
    225     */
    226 
    227     if( fileName.empty())
    228     {
    229       PRINTF(2)("No filename specified for loading");
    230       return NULL;
    231     }
    232 
    233     TiXmlDocument XMLDoc(fileName);
    234     // load the campaign document
    235     if( !XMLDoc.LoadFile(fileName))
    236     {
    237       // report an error
    238       PRINTF(1)("Could not load XML File %s: %s @ %d:%d\n", fileName.c_str(), XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol());
    239       return NULL;
    240     }
    241 
    242     // check basic validity
    243     TiXmlElement* root = XMLDoc.RootElement();
    244     assert( root != NULL);
    245 
    246     if( strcmp( root->Value(), "Campaign"))
    247     {
    248       // report an error
    249       PRINTF(2)("Specified XML File is not an orxonox campaign file (Campaign element missing)\n");
    250       return NULL;
    251     }
    252 
    253     // construct campaign
    254     return new Campaign( root);
    255   }
    256 
    257 
    258 
    259   /**
    260    *  handle keyboard commands
    261    * @param event the event to handle
    262    */
    263   void GameLoader::process(const Event& event)
    264   {
    265     if( event.type == KeyMapper::PEV_NEXT_WORLD)
    266     {
    267       if( likely(event.bPressed))
    268       {
    269         this->switchToNextLevel();
    270       }
    271     }
    272     else if( event.type == KeyMapper::PEV_PAUSE)
    273     {
    274       if( likely(event.bPressed))
    275       {
    276         if(this->isPaused)
    277           this->resume();
    278         else
    279           this->pause();
    280       }
    281     }
    282     else if( event.type == KeyMapper::PEV_QUIT)
    283     {
    284       if( event.bPressed) this->stop();
    285     }
    286     else if (event.type == EV_MAIN_QUIT)
    287       this->stop();
    288   }
    289 
    290 
    291   /**
    292    *  this changes to the next level
    293    */
    294   void GameLoader::switchToNextLevel()
    295   {
    296     if(this->currentCampaign != NULL)
    297       this->currentCampaign->switchToNextLevel();
    298   }
    299 
    300 }
     279  else if( event.type == KeyMapper::PEV_QUIT)
     280  {
     281    if( event.bPressed) this->stop();
     282  }
     283  else if (event.type == EV_MAIN_QUIT)
     284    this->stop();
     285}
     286
     287
     288/**
     289 *  this changes to the next level
     290 */
     291void GameLoader::switchToNextLevel()
     292{
     293  if(this->currentCampaign != NULL)
     294    this->currentCampaign->switchToNextLevel();
     295}
     296
  • trunk/src/lib/util/loading/game_loader.h

    r7221 r7868  
    2323class BaseObject;
    2424class Event;
    25 class EventHandler;
    2625
    2726//! The GameLoader
     
    7372
    7473  Campaign*              currentCampaign;      //!< reference to the current campaign playing
    75 
    76   EventHandler*          eventHandler;         //!< reference to the eventHandler
    7774};
    7875
  • trunk/src/story_entities/movie_loader.cc

    r7283 r7868  
    7070ErrorMessage MovieLoader::unloadData()
    7171{
    72   EventHandler::getInstance()->unsubscribe(this, ES_GAME);
     72  this->unsubscribeEvents(ES_GAME);
    7373}
    7474
  • trunk/src/story_entities/simple_game_menu.cc

    r7765 r7868  
    1818
    1919#include "simple_game_menu.h"
     20
     21#include "event_handler.h"
    2022
    2123#include "state.h"
     
    3234#include "camera.h"
    3335
    34 #include "event_handler.h"
    3536#include "graphics_engine.h"
    3637#include "object_manager.h"
     
    112113  GameWorld::init();
    113114
    114   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_UP);
    115   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_DOWN);
    116   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_RETURN);
    117   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_SPACE);
    118   EventHandler::getInstance()->subscribe(this, ES_MENU, SDLK_ESCAPE);
     115  this->subscribeEvent(ES_MENU, SDLK_UP);
     116  this->subscribeEvent(ES_MENU, SDLK_DOWN);
     117  this->subscribeEvent(ES_MENU, SDLK_RETURN);
     118  this->subscribeEvent(ES_MENU, SDLK_SPACE);
     119  this->subscribeEvent(ES_MENU, SDLK_ESCAPE);
    119120
    120121  this->dataTank->localCamera->setRelCoor(this->cameraVector);
     
    253254ErrorMessage SimpleGameMenu::unloadData()
    254255{
    255   EventHandler::getInstance()->unsubscribe(this, ES_MENU);
     256  this->unsubscribeEvents(ES_MENU);
    256257
    257258  std::vector<MenuLayer>::iterator mit;
  • trunk/src/util/track/pilot_node.cc

    r6997 r7868  
    2020
    2121#include "pilot_node.h"
    22 #include "event_handler.h"
    2322#include "event.h"
     23#include "key_mapper.h"
    2424
    25 using namespace std;
    2625
    2726/**
  • trunk/src/world_entities/camera.cc

    r7347 r7868  
    1616
    1717#include "camera.h"
    18 
    19 #include "event_handler.h"
    20 
    21 using namespace std;
    22 
     18#include "key_mapper.h"
    2319
    2420/**
     
    3127  this->target = new CameraTarget();
    3228
    33   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW0);
    34   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW1);
    35   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW2);
    36   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW3);
    37   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW4);
    38   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_VIEW5);
     29  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW0);
     30  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW1);
     31  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW2);
     32  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW3);
     33  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW4);
     34  this->subscribeEvent(ES_GAME, KeyMapper::PEV_VIEW5);
    3935
    4036  this->setFovy(90);
  • trunk/src/world_entities/creatures/md2_creature.cc

    r7337 r7868  
    3232#include "util/loading/factory.h"
    3333#include "key_mapper.h"
    34 #include "event_handler.h"
    3534
    3635#include "graphics_engine.h"
  • trunk/src/world_entities/playable.cc

    r7713 r7868  
    1616
    1717#include "playable.h"
    18 #include "event_handler.h"
     18
     19#include "key_mapper.h"
    1920
    2021#include "player.h"
     
    225226
    226227    // unsubscibe all events.
    227     EventHandler* evh = EventHandler::getInstance();
    228228    std::vector<int>::iterator ev;
    229229    for (ev = this->events.begin(); ev != events.end(); ev++)
    230       evh->unsubscribe( ES_GAME, (*ev));
     230      player->unsubscribeEvent(ES_GAME, (*ev));
    231231
    232232    // leave the entity
     
    251251
    252252    /*EventHandler*/
    253     EventHandler* evh = EventHandler::getInstance();
    254253    std::vector<int>::iterator ev;
    255254    for (ev = this->events.begin(); ev != events.end(); ev++)
    256       evh->subscribe(player, ES_GAME, (*ev));
     255      player->subscribeEvent(ES_GAME, (*ev));
    257256
    258257    this->enter();
     
    440439
    441440  if (this->currentPlayer != NULL)
    442     EventHandler::getInstance()->subscribe(this->currentPlayer, ES_GAME, eventType);
     441    this->currentPlayer->subscribeEvent(ES_GAME, eventType);
    443442}
    444443
     
    453452
    454453  if (this->currentPlayer != NULL)
    455     EventHandler::getInstance()->unsubscribe(ES_GAME, eventType);
     454    this->currentPlayer->unsubscribeEvent(ES_GAME, eventType);
    456455}
    457456
  • trunk/src/world_entities/player.cc

    r7337 r7868  
    4040  this->hud.show();
    4141
    42   EventHandler::getInstance()->subscribe(this, ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
     42  this->subscribeEvent(ES_GAME, KeyMapper::PEV_CHANGE_SHIP);
    4343}
    4444
  • trunk/src/world_entities/space_ships/helicopter.cc

    r7810 r7868  
    2828
    2929#include "key_mapper.h"
    30 #include "event_handler.h"
    3130#include "state.h"
    3231
  • trunk/src/world_entities/space_ships/hover.cc

    r7337 r7868  
    2626#include "util/loading/factory.h"
    2727#include "key_mapper.h"
    28 #include "event_handler.h"
    2928#include "state.h"
    3029
  • trunk/src/world_entities/space_ships/space_ship.cc

    r7346 r7868  
    3131#include "util/loading/factory.h"
    3232#include "key_mapper.h"
    33 #include "event_handler.h"
    3433
    3534#include "network_game_manager.h"
  • trunk/src/world_entities/space_ships/turbine_hover.cc

    r7348 r7868  
    2626#include "util/loading/factory.h"
    2727#include "key_mapper.h"
    28 #include "event_handler.h"
    2928#include "state.h"
    3029
     
    3231#include "dot_emitter.h"
    3332#include "sprite_particles.h"
    34 
    35 using namespace std;
    3633
    3734CREATE_FACTORY(TurbineHover, CL_TURBINE_HOVER);
     
    176173
    177174
    178   //add events to the eventlist
    179   registerEvent(KeyMapper::PEV_FORWARD);
    180   registerEvent(KeyMapper::PEV_BACKWARD);
    181   registerEvent(KeyMapper::PEV_LEFT);
    182   registerEvent(KeyMapper::PEV_RIGHT);
    183   registerEvent(KeyMapper::PEV_UP);
    184   registerEvent(KeyMapper::PEV_DOWN);
    185   registerEvent(KeyMapper::PEV_FIRE1);
    186   registerEvent(KeyMapper::PEV_NEXT_WEAPON);
    187   registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
    188   registerEvent(EV_MOUSE_MOTION);
     175  //add events to the eventlist of the Playable
     176  this->registerEvent(KeyMapper::PEV_FORWARD);
     177  this->registerEvent(KeyMapper::PEV_BACKWARD);
     178  this->registerEvent(KeyMapper::PEV_LEFT);
     179  this->registerEvent(KeyMapper::PEV_RIGHT);
     180  this->registerEvent(KeyMapper::PEV_UP);
     181  this->registerEvent(KeyMapper::PEV_DOWN);
     182  this->registerEvent(KeyMapper::PEV_FIRE1);
     183  this->registerEvent(KeyMapper::PEV_NEXT_WEAPON);
     184  this->registerEvent(KeyMapper::PEV_PREVIOUS_WEAPON);
     185  this->registerEvent(EV_MOUSE_MOTION);
    189186
    190187  dynamic_cast<Element2D*>(this->getWeaponManager().getFixedTarget())->setVisibility( false);
  • trunk/src/world_entities/weapons/crosshair.cc

    r7221 r7868  
    1717
    1818#include "crosshair.h"
    19 #include "event_handler.h"
    2019
    2120#include "util/loading/load_param.h"
     
    6564  this->material = new Material;
    6665
    67   //EventHandler::getInstance()->subscribe(this, ES_GAME, EV_MOUSE_MOTION);
     66  //this->subscribeEvent(ES_GAME, EV_MOUSE_MOTION);
    6867
    6968  // center the mouse on the screen, and also hide the cursors
Note: See TracChangeset for help on using the changeset viewer.