Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

GameState Class Reference

Inheritance diagram for GameState:

Inheritance graph
[legend]
Collaboration diagram for GameState:

Collaboration graph
[legend]

Detailed Description

Game state.

GameState installs own InputHandler in init phase.

To change state, use m_manager->pushState(topState) or m_manager->changeState(newState)

Definition at line 21 of file GameState.h.

Public Member Functions

 GameState ()
virtual ~GameState ()
virtual bool allowBg () const
bool isRunning () const
bool isOnBg () const
void setNextState (GameState *nextState)
void initState (StateManager *manager)
void updateState ()
 
Exceptions:
LogicException when state is not active

void pauseState ()
 
Exceptions:
LogicException when state is not active

void resumeState ()
 Reactivate state after pause.
void cleanState ()
 Clean state after run.
void quitState ()
void pushState (GameState *new_state)
void noteBg ()
void noteFg ()
void installHandlers ()
 Install own video and input handler.
void unHandlers ()
 Uninstall own video and input handler.
void receiveSimple (const SimpleMsg *msg)
 Handle incoming message.

Protected Member Functions

void takeHandler (InputHandler *new_handler)
 Obtain input handler.
const InputProvidergetInput ()
 Returns wrapped input.
virtual void own_initState ()=0
virtual void own_updateState ()=0
virtual void own_pauseState ()=0
virtual void own_resumeState ()=0
virtual void own_cleanState ()=0
virtual void own_noteBg ()
virtual void own_noteFg ()
void changeState (GameState *new_state)
void registerDrawable (Drawable *drawable)
 Add new drawable to drawers fifo.
void deregisterDrawable (const Drawable *drawable)


Constructor & Destructor Documentation

GameState::GameState  ) 
 

Definition at line 23 of file GameState.cpp.

00024 {
00025     m_nextState = NULL;
00026     m_handler = NULL;
00027     m_active = false;
00028     m_onBg = false;
00029     m_drawer = new MultiDrawer();
00030 }

GameState::~GameState  )  [virtual]
 

Definition at line 32 of file GameState.cpp.

00033 {
00034     if (m_handler) {
00035         delete m_handler;
00036     }
00037     delete m_drawer;
00038 }


Member Function Documentation

virtual bool GameState::allowBg  )  const [inline, virtual]
 

Reimplemented in MenuHelp, MenuOptions, KeyConsole, and PosterScroller.

Definition at line 48 of file GameState.h.

00048 { return false; }

void GameState::changeState GameState new_state  )  [protected]
 

Definition at line 158 of file GameState.cpp.

00159 {
00160     m_manager->changeState(this, new_state);
00161 }

void GameState::cleanState  ) 
 

Clean state after run.

Exceptions:
LogicException when state is not active

Definition at line 123 of file GameState.cpp.

00124 {
00125     LOG_DEBUG(ExInfo("cleanState").addInfo("name", getName()));
00126     if (!m_active) {
00127         throw LogicException(ExInfo("clean - state is not active")
00128                 .addInfo("name", getName()));
00129     }
00130     own_cleanState();
00131     unHandlers();
00132 
00133     m_active = false;
00134     m_onBg = false;
00135     m_manager = NULL;
00136     removeWatchers();
00137     MessagerAgent::agent()->removeListener(getName());
00138 }

void GameState::deregisterDrawable const Drawable drawable  )  [protected]
 

Definition at line 213 of file GameState.cpp.

00214 {
00215     m_drawer->removeDrawer(drawable);
00216 }

const InputProvider * GameState::getInput  )  [protected]
 

Returns wrapped input.

Definition at line 57 of file GameState.cpp.

00058 {
00059     return m_handler;
00060 }

void GameState::initState StateManager manager  ) 
 

Definition at line 63 of file GameState.cpp.

00064 {
00065     LOG_DEBUG(ExInfo("initState").addInfo("name", getName()));
00066     MessagerAgent::agent()->addListener(this);
00067     m_manager = manager;
00068     m_active = true;
00069     m_onBg = false;
00070     own_initState();
00071 }

void GameState::installHandlers  ) 
 

Install own video and input handler.

Definition at line 183 of file GameState.cpp.

00184 {
00185     LOG_DEBUG(ExInfo("installHandlers").addInfo("state", getName()));
00186     InputAgent::agent()->installHandler(m_handler);
00187     VideoAgent::agent()->acceptDrawer(m_drawer);
00188 }

bool GameState::isOnBg  )  const [inline]
 

Definition at line 50 of file GameState.h.

00050 { return m_onBg; }

bool GameState::isRunning  )  const [inline]
 

Definition at line 49 of file GameState.h.

00049 { return m_active; }

void GameState::noteBg  ) 
 

Definition at line 164 of file GameState.cpp.

00165 {
00166     LOG_DEBUG(ExInfo("noteBg").addInfo("name", getName()));
00167     own_noteBg();
00168     m_onBg = true;
00169 }

void GameState::noteFg  ) 
 

Definition at line 172 of file GameState.cpp.

00173 {
00174     LOG_DEBUG(ExInfo("noteFg").addInfo("name", getName()));
00175     m_onBg = false;
00176     own_noteFg();
00177 }

virtual void GameState::own_cleanState  )  [protected, pure virtual]
 

Implemented in Level, Pedometer, WorldMap, MenuHelp, MenuOptions, KeyConsole, DemoMode, and PosterState.

virtual void GameState::own_initState  )  [protected, pure virtual]
 

Implemented in Level, Pedometer, WorldMap, MenuHelp, MenuOptions, KeyConsole, DemoMode, PosterScroller, and PosterState.

virtual void GameState::own_noteBg  )  [inline, protected, virtual]
 

Reimplemented in Level.

Definition at line 39 of file GameState.h.

00039 {}

virtual void GameState::own_noteFg  )  [inline, protected, virtual]
 

Reimplemented in Level.

Definition at line 40 of file GameState.h.

00040 {}

virtual void GameState::own_pauseState  )  [protected, pure virtual]
 

Implemented in Level, Pedometer, WorldMap, MenuHelp, MenuOptions, KeyConsole, DemoMode, and PosterState.

virtual void GameState::own_resumeState  )  [protected, pure virtual]
 

Implemented in Level, Pedometer, WorldMap, MenuHelp, MenuOptions, KeyConsole, DemoMode, and PosterState.

virtual void GameState::own_updateState  )  [protected, pure virtual]
 

Implemented in Level, Pedometer, WorldMap, MenuHelp, MenuOptions, KeyConsole, DemoMode, PosterScroller, and PosterState.

void GameState::pauseState  ) 
 

Exceptions:
LogicException when state is not active

Definition at line 91 of file GameState.cpp.

00092 {
00093     if (!m_active) {
00094         throw LogicException(ExInfo("pause - state is not active")
00095                 .addInfo("name", getName()));
00096     }
00097 
00098     own_pauseState();
00099     m_active = false;
00100     m_onBg = false;
00101 }

void GameState::pushState GameState new_state  ) 
 

Definition at line 152 of file GameState.cpp.

00153 {
00154     m_manager->pushState(this, new_state);
00155 }

void GameState::quitState  ) 
 

Definition at line 141 of file GameState.cpp.

00142 {
00143     if (m_nextState) {
00144         changeState(m_nextState);
00145     }
00146     else {
00147         m_manager->popState(this);
00148     }
00149 }

void GameState::receiveSimple const SimpleMsg msg  )  [virtual]
 

Handle incoming message.

Messages:

  • quit ... quit state

Reimplemented from BaseListener.

Definition at line 224 of file GameState.cpp.

00225 {
00226     if (msg->equalsName("quit")) {
00227         quitState();
00228     }
00229     else {
00230         LOG_WARNING(ExInfo("unknown msg")
00231                 .addInfo("msg", msg->toString()));
00232     }
00233 }

void GameState::registerDrawable Drawable drawable  )  [protected]
 

Add new drawable to drawers fifo.

NOTE: order is important, the first inserted drawer will be on background

Definition at line 207 of file GameState.cpp.

00208 {
00209     m_drawer->acceptDrawer(drawable);
00210 }

void GameState::resumeState  ) 
 

Reactivate state after pause.

Exceptions:
LogicException when state is already active

Definition at line 108 of file GameState.cpp.

00109 {
00110     if (m_active) {
00111         throw LogicException(ExInfo("resume - state is already active")
00112                 .addInfo("name", getName()));
00113     }
00114     m_active = true;
00115     own_resumeState();
00116 }

void GameState::setNextState GameState nextState  )  [inline]
 

Definition at line 51 of file GameState.h.

00051 { m_nextState = nextState; }

void GameState::takeHandler InputHandler new_handler  )  [protected]
 

Obtain input handler.

Parameters:
new_handler new input handler

Definition at line 45 of file GameState.cpp.

00046 {
00047     if (m_handler) {
00048         delete m_handler;
00049     }
00050     m_handler = new_handler;
00051 }

void GameState::unHandlers  ) 
 

Uninstall own video and input handler.

Definition at line 194 of file GameState.cpp.

00195 {
00196     InputAgent::agent()->installHandler(NULL);
00197     VideoAgent::agent()->removeDrawer(m_drawer);
00198 }

void GameState::updateState  ) 
 

Exceptions:
LogicException when state is not active

Definition at line 77 of file GameState.cpp.

00078 {
00079     if (!m_active) {
00080         throw LogicException(ExInfo("update - state is not active")
00081                 .addInfo("name", getName()));
00082     }
00083 
00084     own_updateState();
00085 }


The documentation for this class was generated from the following files:
Generated on Wed Jun 1 09:55:15 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2