BufferedState Class Template Reference

#include <C:/Work/specialnumbers_svn/NumberLib/NumbersLib/BufferedState.h>

Inheritance diagram for BufferedState:

UpdateableNumber< unsigned int >

List of all members.


Detailed Description

template<unsigned int n>
class luma::numbers::BufferedState< n >

This class handles buffered states transitions, that is, it can be used to reduce state flickering.

It is is useful in cases where transition checks should consistently indicate a state change before the actual state change takes place.

This class assumes all states lie in the range [0, n). The function setValue(i) is called to indicate the check for transition to state i has succeeded. Similarly, if getValue() returns i, the state should change to state i.

Note that this class is not a state machine - rather, it can be used with a state machine to gain buffered transitions.

Parameters:
n The number of states.
Author:
Herman Tulleken (herman.tulleken@gmail.com)

luma/games (http://www.luma.co.za/)

Definition at line 33 of file BufferedState.h.


Public Member Functions

 BufferedState (const BufferedState &other)
 Copy constructor.
 BufferedState (unsigned int initialState, float stateValues[], float thresholds[], float increment)
 Initialises a new BufferedState.
void forceValue (int state)
 Forces the state to the given state.
unsigned int getValue () const
 Returns the last triggered state.
void setValue (unsigned int state, float ellapsedTime=1)
 Sets the state of this buffered state.

Private Attributes

unsigned int mState
DefaultClampedFloat mStateValues [n]
float mThresholds [n]

Classes

class  DefaultClampedFloat
 This class is provided solely so that we can have a default constructor, and can hence use this class in an array. More...

Constructor & Destructor Documentation

BufferedState ( unsigned int  initialState,
float  stateValues[],
float  thresholds[],
float  increment 
) [inline]

Initialises a new BufferedState.

Parameters:
initialState the initial state
stateValues the initial state values. Usually, if initialState is i, then initialStates[i] = 1.0f and initialStates[j] = 0.0 if j != i.
thresholds the triggering thresholds for each state. Each of these should be greater than 0.5f, otherwise flickering might still occur. A state triggers if is stateValue is greater than this threshold.
increment this is the value added or subtracted from state values everytime the setValue function is called.

Definition at line 133 of file BufferedState.h.

References BufferedState::mStateValues, BufferedState::mThresholds, BufferedState::DefaultClampedFloat::setIncrement(), and RangedNumber::setValue().

BufferedState ( const BufferedState< n > &  other  )  [inline]

Copy constructor.

Note:
All internal vectors are copied, so that this data is not shared.

Definition at line 145 of file BufferedState.h.

References BufferedState::mStateValues, and BufferedState::mThresholds.


Member Function Documentation

void forceValue ( int  state  )  [inline]

Forces the state to the given state.

Definition at line 179 of file BufferedState.h.

References BufferedState::mState, and BufferedState::mStateValues.

unsigned int getValue (  )  const [inline, virtual]

Returns the last triggered state.

Implements UpdateableNumber< unsigned int >.

Definition at line 173 of file BufferedState.h.

References BufferedState::mState.

void setValue ( unsigned int  state,
float  ellapsedTime = 1 
) [inline, virtual]

Sets the state of this buffered state.

Note that setting the state does not mean that state will be returned next by getState(). This will only happen after a number of calls to setState, depending on the thresholds and increment.

Implements UpdateableNumber< unsigned int >.

Definition at line 156 of file BufferedState.h.

References ClampedNumber::dec(), ClampedNumber::inc(), BufferedState::mState, BufferedState::mStateValues, and BufferedState::mThresholds.


Member Data Documentation

unsigned int mState [private]

float mThresholds[n] [private]

Definition at line 63 of file BufferedState.h.

Referenced by BufferedState::BufferedState(), and BufferedState::setValue().


The documentation for this class was generated from the following file:

Generated on Sun Sep 21 20:49:08 2008 for Numbers by  doxygen 1.5.6