/* Copyright (C) Eric Dybsand, 2000. * All rights reserved worldwide. * * This software is provided "as is" without express or implied * warranties. You may freely copy and compile this source into * applications you distribute provided that the copyright text * below is included in the resulting source code, for example: * "Portions Copyright (C) Eric Dybsand, 2000" */ // FSMstate.cpp: implementation of the FSMstate class. Unoptimized. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GameGems.h" #include "FSMstate.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // AddTransition() - accept an input transition threshhold and the // output state ID to associate with it ////////////////////////////////////////////////////////////////////// void FSMstate::AddTransition( int iInput, int iOutputID ) { // the m_piInputs[] and m_piOutputState[] are not sorted // so find the first non-zero offset in m_piOutputState[] // and use that offset to store the input and OutputID // within the m_piInputs[] and m_piOutputState[] for( int i=0; i= m_usNumberOfTransistions ) return; // remove this output ID and its input transition value m_piInputs[i] = 0; m_piOutputState[i] = 0; // since the m_piInputs[] and m_piOutputState[] are not // sorted, then we need to shift the remaining contents for( ; i<(m_usNumberOfTransistions-1); ++i ) { if( !m_piOutputState[i] ) break; m_piInputs[i] = m_piInputs[i+1]; m_piOutputState[i] = m_piOutputState[i+1]; } // and make sure the last used offset is cleared m_piInputs[i] = 0; m_piOutputState[i] = 0; } ////////////////////////////////////////////////////////////////////// // FSMstate() - create a new instance and allocate arrays ////////////////////////////////////////////////////////////////////// FSMstate::FSMstate( int iStateID, unsigned usTransitions ) { // don't allow 0 transitions if( !usTransitions ) m_usNumberOfTransistions = 1; else m_usNumberOfTransistions = usTransitions; // save off id and number of transitions m_iStateID = iStateID; // now allocate each array try { m_piInputs = new int[m_usNumberOfTransistions]; for( int i=0; i