#include <C:/Work/specialnumbers_svn/NumberLib/NumbersLib/BufferedState.h>
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.
n | The number of states. |
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... |
BufferedState | ( | unsigned int | initialState, | |
float | stateValues[], | |||
float | thresholds[], | |||
float | increment | |||
) | [inline] |
Initialises a new BufferedState.
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.
Definition at line 145 of file BufferedState.h.
References BufferedState::mStateValues, and BufferedState::mThresholds.
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.
unsigned int mState [private] |
Definition at line 64 of file BufferedState.h.
Referenced by BufferedState::forceValue(), BufferedState::getValue(), and BufferedState::setValue().
DefaultClampedFloat mStateValues[n] [private] |
Definition at line 62 of file BufferedState.h.
Referenced by BufferedState::BufferedState(), BufferedState::forceValue(), and BufferedState::setValue().
float mThresholds[n] [private] |
Definition at line 63 of file BufferedState.h.
Referenced by BufferedState::BufferedState(), and BufferedState::setValue().