"L. Spiro Engine"
Public Member Functions | Protected Attributes | Friends

lse::CState Class Reference

A state in the game. More...

#include <LSEState.h>

List of all members.

Public Member Functions

virtual LSVOID LSE_CALL Init (CGame *_pgGame, LSINT32 _ui32State, LSINT32 _ui32PrevState, LSUINTPTR _uptrUser)
virtual LSVOID LSE_CALL Destroy (CGame *_pgGame, LSINT32 _ui32NextState)
virtual LSBOOL LSE_CALL Tick (CGame *_pgGame)
virtual LSBOOL LSE_CALL Draw (CGame *_pgGame)
virtual LSBOOL LSE_CALL Interruptable () const
virtual LSA_SIZE LSE_CALL GetHeapSize (CGame *_pgGame, LSINT32 _ui32State, LSUINTPTR _uptrUser) const
const CTime &LSE_CALL GetTimeMan () const
virtual LSVOID LSE_CALL EventSound (CGame *_pgGame, CSoundSource *_pssSource, LSUINT32 _ui32EventType, CSoundManagerEx *_psmManager)
virtual LSVOID LSE_CALL EventTouch (const CVector2 &_vPos)

Protected Attributes

CTime m_tLocalTime
CTime m_tRenderTime
CStdAllocator * m_psaAllocator
LSUINT32 m_ui32StateId

Friends

class CStateMachine

Detailed Description

A state in the game.

Class CState Description: The base class for all states. A state is any modular portion of the game, such as the main menu, options menu, credits screen, gameplay area, bonus stages, stage-select screen, etc. When created, Init() is called. When destroyed, Destroy() is called. Each frame the state is in focus, Tick() is called followed by Draw(). It keeps its own local time which it may use as it pleases. The local time counts starting from the time the state was created. Since it is local time, the state can reset it, tick it twice as fast, or whatever it pleases. DO NOT LOAD RESOURCES VIA THE CONSTRUCTOR. #1: Its local memory manager will not be initialized yet. #2: Resources frequently rely on data provided by the game class, which you will not have until Init() is called.


Member Function Documentation

virtual LSVOID LSE_CALL lse::CState::Destroy ( CGame *  _pgGame,
LSINT32  _ui32NextState 
) [virtual]

Called when it is time for the state to die. Free resources here.

Parameters:
_pgGamePointer to the game class which allows access to game-specific resources.
_ui32NextStateThe identifier of the next state.
virtual LSBOOL LSE_CALL lse::CState::Draw ( CGame *  _pgGame) [virtual]

Called once every frame the state has focus to allow the state to render itself. If the state is in the background, this is not called. Return false to exit the game.

Parameters:
_pgGamePointer to the custom game class which can be used to access game-specific resources.
Returns:
Return false if the game should close.
virtual LSVOID LSE_CALL lse::CState::EventSound ( CGame *  _pgGame,
CSoundSource *  _pssSource,
LSUINT32  _ui32EventType,
CSoundManagerEx *  _psmManager 
) [virtual]

Handler for sound events.

Parameters:
_pgGameThe game class.
_pssSourceThe sound source that caused the event.
_ui32EventTypeThe type of event. Can be CSoundManager::LSS_ET_SOUND_JUST_STARTED or CSoundManager::LSS_ET_SOUND_JUST_ENDED.
_psmManagerThe sound manager.
virtual LSVOID LSE_CALL lse::CState::EventTouch ( const CVector2 &  _vPos) [virtual]

Handler for touch events.

Parameters:
_vPosThe 2D position of the touch in view space.
virtual LSA_SIZE LSE_CALL lse::CState::GetHeapSize ( CGame *  _pgGame,
LSINT32  _ui32State,
LSUINTPTR  _uptrUser 
) const [virtual]

Get the size of the heap to be allocated for this state, or 0 for none.

Parameters:
_pgGameThe game pointer.
_ui32StateThe ID of the current state.
_uptrUserUser data passed to the state upon initialization. Same value as what is passed in Init().
Returns:
Return a non-zero value to indicate the size of the heap to be allocated for this class.
const CTime& LSE_CALL lse::CState::GetTimeMan ( ) const

Get our time manager.

Returns:
Returns the time manager for this state.
virtual LSVOID LSE_CALL lse::CState::Init ( CGame *  _pgGame,
LSINT32  _ui32State,
LSINT32  _ui32PrevState,
LSUINTPTR  _uptrUser 
) [virtual]

Called when the state is just created. Use this to initialize resources.

Parameters:
_pgGameCan be accessed for whatever game-specific information needs to be obtained.
_ui32StateThe current state identifier (the same class could then be used for multiple states if they are similar enough).
_ui32PrevStateThe identifier of the previous state.
_uptrUserUser-defined data passed to the state. How this is used is entirely defined by the state. Examples of use: #1: Which map to load in a game state. #2: Which tutorial page to show in a tutorial state. #3: Used as a pointer to data containing a lot of state-specific information such as map file to load, previous state of the player, etc.
virtual LSBOOL LSE_CALL lse::CState::Interruptable ( ) const [virtual]

If a state is not on top of the state stack, it is not ticked normally. If the state flags itself as non-interruptable, however, it will be ticked every frame regardless of whether it is on top or not.

Returns:
Return true to make this state interruptable. The default behavior is true. States that need to run online or continuously in the background for any reason should return false.
virtual LSBOOL LSE_CALL lse::CState::Tick ( CGame *  _pgGame) [virtual]

Called once every frame the state has focus (or if it is in the background but is non-interruptable). Do the state-specific processing here. This can be anything, but usually means ticking the menu manager, distributing input, running physics, and all other game logic.

Parameters:
_pgGamePointer to the custom game class which can be used to access game-specific resources.
Returns:
Return false if the game should close.

Member Data Documentation

CStdAllocator* lse::CState::m_psaAllocator [protected]

Its own heap. It is encouraged, but not required, that this be used for allocations related to the state. This is created and destroyed by the state machine. It is created before Init() is called and destroyed after Destroy() is called. This design helps reduce (or eliminate if used strictly) fragmentation and helps the system track memory leaks.

CTime lse::CState::m_tLocalTime [protected]

Local time which keeps track of time since the start of this state. The state should never update the time; it will automatically be updated by the engine, so manually updating it would cause it to tick twice per frame instead of once. However, it is perfectly acceptible for a state to reset its own time counter at any time. This helps a great deal when breaking a state into multiple parts, each of timed length (for example, a count-down before a match; after the count-down, the timer can be reset, so that it correctly reports the actual length of the match from that point forward).

CTime lse::CState::m_tRenderTime [protected]

Local time that keeps track of the render time, which may not be the same as the logical time stored in m_tLocalTime. This should be used in Draw().

LSUINT32 lse::CState::m_ui32StateId [protected]

This state ID.


The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator