Game Development Reference
In-Depth Information
for(int i = 0; i < m_NumberStates;i++)
{
if(m_States[i].GetStateID() == Goal)
{
m_GoalState = m_States[i];
return true;
}
}
return false;
}
The UpdateMachine() function updates the finite state machine for the tank. (See Listing 8-42.)
Listing 8-42. Updating the Finite State Machine
void UpdateMachine()
{
if(m_NumberStates == 0)
{
return;
}
if(m_CurrentState == null)
{
m_CurrentState = m_DefaultState;
}
if(m_CurrentState == null)
{
return;
}
FSM_StatesTank OldStateID = m_CurrentState.GetStateID();
m_GoalID = m_CurrentState.CheckTransitions();
if(m_GoalID != OldStateID)
{
if(TransitionState(m_GoalID))
{
m_CurrentState.Exit();
m_CurrentState = m_GoalState;
m_CurrentState.Enter();
}
}
m_CurrentState.Update();
}
The function does the following:
1.
Returns, if there are no states in the machine.
2.
Sets the current state to the default state, if there is no current state.
3.
Returns, if the current state is still nonexistent.
4.
Gets the current state's id.
Checks the current state for a state transition by calling CheckTransitions() .
5.
 
Search WWH ::




Custom Search