Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


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

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

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

Legend:

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

    r5291 r5388  
    4040typedef enum elState
    4141  {
    42     ES_GAME,           //!< the state during the game plays
    43     ES_GAME_MENU,      //!< state when the menu is called during game
    44     ES_MENU,           //!< orxonox menu state
    45     ES_SHELL,          //!< if we are in shell Modus
     42    ES_NULL         = -1,
     43    ES_GAME         = 0,       //!< the state during the game plays
     44    ES_GAME_MENU    = 1,       //!< state when the menu is called during game
     45    ES_MENU         = 2,       //!< orxonox menu state
     46    ES_SHELL        = 3,       //!< if we are in shell Modus
    4647
    47     ES_ALL,            //!< you want to register events for all states
     48    ES_ALL          = 4,       //!< you want to register events for all states
    4849
    49     ES_NUMBER       //!< the number of states
     50    ES_NUMBER       = 5,       //!< the number of states
    5051  };
    5152
  • 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/**
  • trunk/src/lib/event/event_handler.h

    r5309 r5388  
    1414// FORWARD DECLARATION
    1515class EventListener;
    16 template <class T> class tList;
     16template<class T> class tList;
     17template<class T> class tStack;
    1718class IniParser;
    1819
     
    3031  /** @returns the current state */
    3132  inline elState getState() const { return this->state; };
     33
     34  void pushState(elState state);
     35  elState popState();
    3236
    3337  void subscribe(EventListener* el, elState state, int eventType);
     
    5054  static EventHandler*       singletonRef;                    //!< the singleton reference
    5155
    52   EventListener*             listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners
    53   elState                    state;                           //!< the state of the event handlder
    54   KeyMapper*                 keyMapper;                       //!< reference to the key mapper
     56  EventListener*             listeners[ES_NUMBER][EV_NUMBER]; //!< a list of registered listeners.
     57  elState                    state;                           //!< the state of the event handlder.
     58  tStack<short>*             stateStack;                      //!< a stack for the States we are in.
     59  KeyMapper*                 keyMapper;                       //!< reference to the key mapper.
     60
    5561};
    5662
Note: See TracChangeset for help on using the changeset viewer.