// [4/22/2014 puos] Transition state public bool TransitionCommand(uint eCommand) { if (myState.ContainsKey(eCommand)) { if (m_CurrentCommandQueue.Count > 0) { m_CurrentCommandQueue.Dequeue(); } m_CurrentCommandQueue.Enqueue(eCommand); EAFSMCommand command = myState[eCommand]; m_nPrevState = m_nCurrState; m_nCurrState = eCommand; Init(m_nCurrState); // [11/22/2017 puos] prevent loop turning if (m_CurrentCommandQueue.Count == 1) { return(false); } else { return(true); } } return(false); }
void Init(uint eCommandType) { if (myState.ContainsKey(eCommandType)) { EAFSMCommand command = myState[eCommandType]; command.Init(); } }
/// <summary> /// Get the current fsm run state /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public EAFSMCommand.eFSMState GetCurrentFSMRunState() { EAFSMCommand.eFSMState eState = EAFSMCommand.eFSMState.eInit; EAFSMCommand command = GetStateCommand(m_nCurrState); if (command != null) { eState = command.m_efsmState; } return(eState); }
/// <summary> /// add fsm /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nState"></param> /// <param name="eCommand1"></param> /// <param name="eCommand2"></param> /// <param name="eCommand3"></param> /// <param name="eCommand4"></param> /// <param name="funcCommand"></param> private void AddFSM <T>(T nState, EACommanMethod funcCommand, T eCommand1, T eCommand2, T eCommand3, T eCommand4) { Type typeParameterType = typeof(T); if (typeParameterType.IsEnum == false) { Debug.Log("invalid type - type is not null"); return; } uint idx_1 = System.Convert.ToUInt32(eCommand1); uint idx_2 = System.Convert.ToUInt32(eCommand2); uint idx_3 = System.Convert.ToUInt32(eCommand3); uint idx_4 = System.Convert.ToUInt32(eCommand4); EAFSMCommand command = new EAFSMCommand(funcCommand, idx_1, idx_2, idx_3, idx_4); uint idx = System.Convert.ToUInt32(nState); AddState(idx, command); }
public void Update() { while (m_CurrentCommandQueue.Count > 0) { uint eCommandType = m_CurrentCommandQueue.Peek(); if (myState.ContainsKey(eCommandType)) { EAFSMCommand command = myState[eCommandType]; int nCheck = -1; if (command.m_funcCommand != null) { nCheck = command.m_funcCommand(command); // puos 20180830 Fixed bug where incorrectly referenced index would go to run without going through init Run(eCommandType); } if (nCheck >= 0 && command.m_eTransitionCommand.Length > nCheck) { bool bsearchCommand = TransitionCommand(command.m_eTransitionCommand[nCheck]); // puos 20140917 Fixed bug where infinite value could be found if command value could not be found if (bsearchCommand == false) { break; } } else { break; } } else { break; } } }
public void AddState(uint nState, EAFSMCommand command) { myState.Add(nState, command); }