Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Oct 16, 2005, 2:05:26 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: implemented a t-Stack, for dynamic stacks, and integrated it into the Shell.

File:
1 edited

Legend:

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

    r5371 r5388  
    2626#include "class_list.h"
    2727
     28#include "t_stack.h"
     29
    2830using namespace std;
    2931
     
    4749  this->state = ES_GAME;
    4850  this->keyMapper = NULL;
     51  this->stateStack = NULL;
    4952}
    5053
     
    7275    }
    7376  }
     77  delete this->stateStack;
    7478  delete this->keyMapper;
    7579
     
    8791void EventHandler::init(IniParser* iniParser)
    8892{
    89   this->keyMapper = new KeyMapper();
    90   this->keyMapper->loadKeyBindings(iniParser);
    91 }
     93  if (this->keyMapper == NULL)
     94  {
     95    this->keyMapper = new KeyMapper();
     96    this->keyMapper->loadKeyBindings(iniParser);
     97  }
     98  if (this->stateStack == NULL)
     99    this->stateStack = new tStack<short>;
     100}
     101
     102/**
     103 * pushes the current State in the State-stack, and selects state
     104 * @param state the new State to set
     105 */
     106void EventHandler::pushState(elState state)
     107{
     108  if (likely(state != ES_NULL && state != ES_ALL && this->stateStack != NULL))
     109  {
     110    this->stateStack->push(this->state);
     111    this->setState(state);
     112  }
     113  else
     114  {
     115    PRINTF(2)("unable to push State\n");
     116  }
     117}
     118
     119/**
     120 * this removes the topmost stack-entry and select the underlying one
     121 * @returns the next stack-entry
     122 */
     123elState EventHandler::popState()
     124{
     125  if (unlikely(this->stateStack == NULL))
     126    return ES_NULL;
     127  elState state = (elState)this->stateStack->pop();
     128  if (state == ES_NULL)
     129  {
     130    PRINTF(2)("No more states availiable. (unable to pop state)\n");
     131    return ES_NULL;
     132  }
     133  else
     134  {
     135    this->setState(state);
     136    return state;
     137  }
     138}
     139
    92140
    93141/**
Note: See TracChangeset for help on using the changeset viewer.