public void Pause(ISMState <T> state) { if (ContainsState(state)) { state.Pause(); } }
public override void Execute() { if (mCurrentState != null) { if (mCurrentState.mStateFlag == ISMStateBase.StateFlag.BeforeEnter) { mCurrentState.Enter(); } else if (mCurrentState.mStateFlag == ISMStateBase.StateFlag.Executing) { mCurrentState.Execute(); } else if (mCurrentState.mStateFlag == ISMStateBase.StateFlag.BeforeExit) { mCurrentState.Exit(); } else if (mCurrentState.mStateFlag == ISMStateBase.StateFlag.AfterExit) { mCurrentState.ReInit(); mCurrentState = null; } } else { if (mStateQueue.Count > 0) { mCurrentState = mStateQueue.Dequeue(); } else { EndSelf(); } } }
public void AddState(ISMState state) { _states.Add(state.GetType(), state); var stateData = StateData.FirstOrDefault(s => s.GetStateType() == state.GetType()); state.SetData(stateData); }
/// <see cref="ISMState.AddInternalTrigger"/> public void AddInternalTrigger(ISMState targetState, StateMachineController.TransitionHandler handler, SMOperator stateOperator) { if (this.stateMachine.Commissioned) { throw new SMException("Unable to add trigger to a commissioned state machine"); } if (targetState == null) { throw new ArgumentNullException("targetState"); } if (stateOperator == null) { throw new ArgumentNullException("stateOperator"); } SMState target = this.stateMachine.GetState(targetState.Name); if (target != null) { SMInternalTrigger intTrigger = new SMInternalTrigger(this, target, handler, stateOperator); this.stateMachine.RegisterTrigger(intTrigger); } else { throw new SMException("State '" + targetState.Name + "' doesn't exist!"); } }
protected void Add2Dic(ISMState <T> state) { if (!m_statesDic.ContainsKey(state.mName)) { m_statesDic.Add(state.mName, state); } }
/// <summary> /// This function is called by the SMC framework when the guest session has to call the setup interface /// of the client module. /// </summary> /// <param name="state"></param> private void CallClientModuleSetupIface(ISMState state) { if (state == this.SendingSetupStepAW) { TraceManager.WriteAllTrace("Calling IDssGuestSetup.ExecuteNextStep on client module.", DssTraceFilters.SETUP_STAGE_INFO); CallNotificationMethods(this.guestRoot.Step.GuestsLeftDss, this.guestRoot.Step.GuestsLost); this.channelProxy.UnlockForClient(this.guestRoot.Step.StepPackageList, this.guestRoot.Step.ChannelStateList, this.guestRoot.IndexOfThisGuest); bool result = this.guestRoot.SetupIface.ExecuteNextStep(this.channelProxy); this.channelProxy.Lock(); if (result) { ContinueSetup(); } else { LeaveDss(); } } else { throw new DssException("Unexpected state!"); } }
public void Resume(ISMState <T> state) { if (ContainsState(state)) { state.Resume(); } }
public bool ShouldOverrideCurrentState(ISMState currentState) { var hearing = _entityContainer.GetEntity <HearingEntity>(); return(hearing.NoiseEntities.Count > 0 && currentState.GetType() != typeof(ChaseState) && currentState.GetType() != typeof(ClickerChaseState)); }
public void Pop(ISMState <T> state) { if (ContainsState(state)) { Remove(state); state.Exit(); } }
public void ClearAll() { ISMState <T>[] states = new ISMState <T> [m_states.Count]; m_states.CopyTo(states); foreach (ISMState <T> s in states) { Pop(s); } }
public TS GetState <TS>(string name) where TS : ISMState <T> { ISMState <T> state = GetState(name); if (state != null) { return((TS)state); } return(null); }
public override bool Enter() { base.Enter(); if (mStateQueue.Count > 0) { mCurrentState = mStateQueue.Dequeue(); } return(true); }
/// <summary> /// Gets the SMState object that implements the interface given in the parameter. /// </summary> /// <param name="iface">The interface of the object you want to get.</param> /// <returns>The implementor object or null if no such object exists in this map.</returns> public SMState GetStateObject(ISMState iface) { if (this.objectMap.ContainsKey(iface)) { return(this.objectMap[iface]); } else { return(null); } }
public void Pop(string name) { for (int i = 0; i < m_states.Count; i++) { ISMState <T> state = m_states[i]; if (state.mName == name) { Remove(state); state.Exit(); } } }
public void EnqueueState(ISMState <T> state) { foreach (ISMState <T> s in mStateQueue) { if (s.mName == state.mName) { Debug.LogError("ISMSequenceState :vState Already In Queue"); return; } } mStateQueueRest.Enqueue(state); }
/// <summary> /// This function is called when the SETUP_STEP_REQUEST_TIMEOUT clock has to be started. /// </summary> private void StartSetupStepReqTimeout(ISMState targetState, ISMState sourceState) { if (targetState == this.WaitingSetupStepRQ && sourceState == this.SendingSetupStepAW) { this.guestRoot.SetupStepReqTimeoutClock = this.guestRoot.AlarmClkMgr.SetAlarmClock( DssRoot.Time + DssConstants.SETUP_STEP_REQUEST_TIMEOUT, this.SetupStepReqTimeout); } else { throw new DssException("Illegal call to DssGuestSessionSM.StartSetupStepReqTimeout!"); } }
protected int SortStatePriorityCompare(ISMState <T> state1, ISMState <T> state2) { if (state1.PRIORITY > state2.PRIORITY) { return(-1); } else if (state1.PRIORITY < state2.PRIORITY) { return(1); } return(0); }
//states will all ended except the state param put in public void PopAll(ISMState <T> state = null) { foreach (ISMState <T> s in m_states) { if (state != null && s.mName == state.mName) { } else { s.EndSelf(); } } }
/// <summary> /// This function is called when the SETUP_STEP_ANSWER_TIMEOUT clock has to be started. /// </summary> private void StartSetupStepAwTimer(ISMState targetState, ISMState sourceState) { if (targetState == this.WaitingSetupStepAWs && sourceState == this.SendingSetupStepRQs) { this.hostRoot.SetupStepAwTimeoutClock = this.hostRoot.AlarmClkMgr.SetAlarmClock( DssRoot.Time + DssConstants.SETUP_STEP_ANSWER_TIMEOUT, this.SetupStepAwTimeout); } else { throw new DssException("Illegal call to DssManagerSM.StartSetupStepAwTimer"); } }
/// <summary> /// Internal function to initialize the simulation manager. /// </summary> /// <remarks> /// Called when the session-SM goes to the Simulating stage. /// </remarks> private void BeginSimulationStage(ISMState state) { if (state == this.Simulating) { /// Ask the root to execute the next frame immediately. this.guestRoot.SimulationMgr.Reset(this.opFlagsTmp); this.guestRoot.SimulationMgr.SetNextFrameExecutionTime(DssRoot.Time); } else { throw new DssException("Illegal call to DssGuestSessionSM.BeginSimulationStage!"); } }
/// <summary> /// This function is called when the CONNECTION_ACKNOWLEDGE_TIMEOUT clock has to be started. /// </summary> private void StartConnAckTimeout(ISMState targetState, ISMState sourceState) { if (targetState == this.WaitingConnectionACK && sourceState == this.Start) { this.guestRoot.ConnAckTimeoutClock = this.guestRoot.AlarmClkMgr.SetAlarmClock( DssRoot.Time + DssConstants.CONNECTION_ACKNOWLEDGE_TIMEOUT, this.ConnectionAckTimeout); } else { throw new DssException("Illegal call to DssGuestSessionSM.StartConnAckTimeout!"); } }
/// <summary> /// Internal function to start the setup step timer. /// </summary> private void StartSetupStepTimer(ISMState state) { if (state == this.SetupStepTimerRunning) { this.hostRoot.SetupStepClock = this.hostRoot.AlarmClkMgr.SetAlarmClock( DssRoot.Time + DssConstants.SETUP_STEP_CYCLE_TIME, this.SetupStepTimeout); } else { throw new DssException("Illegal call to DssManagerSM.StartSetupStepTimer"); } }
public void Push(ISMState <T> state) { if (state == null) { return; } List <ISMState <T> > CompatibleList = new List <ISMState <T> >(); List <ISMState <T> > IncompatibleList = new List <ISMState <T> >(); foreach (ISMState <T> s in m_states) { //can exist at same time if (ISMStateGroupMgr.Instance.IsTwoMaskCompatible(s.GroupMask, state.GroupMask)) { CompatibleList.Add(s); } else { IncompatibleList.Add(s); } } //CompatibleList.Sort(SortStatePriorityCompare); IncompatibleList.Sort(SortStatePriorityCompare); //if there some state incompatible if (IncompatibleList.Count > 0) { int highestpriority = IncompatibleList[0].PRIORITY; if (state.PRIORITY >= highestpriority) { foreach (ISMState <T> s in IncompatibleList) { Pop(s); } if (m_states.Count > 0) { Push(state); } else { PushOne(state); } } } else { PushOne(state); } }
public void ChangeState(Type stateType) { if (_currentState != null) { Debug.LogFormat("({1}) Exit [{0}]", _currentState.GetType().Name, gameObject.name); _currentState.OnStateExit(); StopCoroutine(_currentStateExecute); } _currentState = _states[stateType]; Debug.LogFormat("({1}) Enter [{0}]", _currentState.GetType().Name, gameObject.name); _currentState.OnStateEnter(); Debug.LogFormat("({1}) Execute [{0}]", _currentState.GetType().Name, gameObject.name); _currentStateExecute = StartCoroutine(_currentState.OnStateExecute(this)); }
/// <summary> /// This function is called when the CONNECTION_REQUEST_TIMEOUT clock has to be started. /// </summary> private void StartConnReqTimeout(ISMState targetState, ISMState sourceState) { if (sourceState == this.Opened && targetState == this.Engaging) { AlarmClock connReqTimeoutClk = this.manager.HostRoot.AlarmClkMgr.SetAlarmClock( DssRoot.Time + DssConstants.CONNECTION_REQUEST_TIMEOUT, this.ConnectionReqTimeout); this.manager.HostRoot.SetConnReqTimeoutClock(this.Index, connReqTimeoutClk); } else { throw new DssException("Illegal call to DssChannelSM.StartConnReqTimeout"); } }
public virtual void FixedUpdate() { for (int i = 0; i < m_states.Count; i++) { ISMState <T> state = m_states[i]; if (state.mStateFlag == ISMStateBase.StateFlag.Executing) { if (state.IsPause() == false) { state.FixedExecute(); } } } }
/// <summary> /// This function is called when the SETUP_STEP_ANSWER_TIMEOUT clock has to be stopped. /// </summary> private void StopSetupStepAwTimer(ISMState targetState, ISMState sourceState) { if (targetState == this.SendingSetupStepRQs && sourceState == this.WaitingSetupStepAWs) { if (this.hostRoot.SetupStepAwTimeoutClock != null) { this.hostRoot.SetupStepAwTimeoutClock.Cancel(); this.hostRoot.SetupStepAwTimeoutClock = null; } } else { throw new DssException("Illegal call to DssManagerSM.StopSetupStepAwTimer"); } }
/// <summary> /// This function is called when the SETUP_STEP_REQUEST_TIMEOUT clock has to be stopped. /// </summary> private void StopSetupStepReqTimeout(ISMState targetState, ISMState sourceState) { if (sourceState == this.WaitingSetupStepRQ && (targetState == this.SendingSetupStepAW || targetState == this.Simulating)) { if (this.guestRoot.SetupStepReqTimeoutClock != null) { this.guestRoot.SetupStepReqTimeoutClock.Cancel(); this.guestRoot.SetupStepReqTimeoutClock = null; } } else { throw new DssException("Illegal call to DssGuestSessionSM.StartSetupStepReqTimeout!"); } }
/// <summary> /// This function is called when the CONNECTION_REQUEST_TIMEOUT clock has to be stopped. /// </summary> private void StopConnReqTimeout(ISMState targetState, ISMState sourceState) { if (sourceState == this.Engaging && (targetState == this.Engaged || targetState == this.Terminating)) { AlarmClock connReqTimeoutClk = this.manager.HostRoot.GetConnReqTimeoutClock(this.Index); if (connReqTimeoutClk != null) { connReqTimeoutClk.Cancel(); this.manager.HostRoot.SetConnReqTimeoutClock(this.Index, null); } } else { throw new DssException("Illegal call to DssChannelSM.StopConnReqTimeout"); } }
/// <see cref="ISMState.AddInternalTrigger"/> public void AddInternalTrigger(ISMState targetState, StateMachineController.TransitionHandler handler, RCSet <ISMState> neededStates) { if (this.stateMachine.Commissioned) { throw new SMException("Unable to add trigger to a commissioned state machine"); } if (targetState == null) { throw new ArgumentNullException("targetState"); } if (neededStates == null || neededStates.Count == 0) { throw new ArgumentNullException("neededStates"); } SMState target = this.stateMachine.GetState(targetState.Name); if (target != null) { ISMState[] neededStatesArray = new ISMState[neededStates.Count]; int i = 0; foreach (ISMState st in neededStates) { neededStatesArray[i] = st; i++; } //RCSet<SMState> neededStateObjects = new RCSet<SMState>(); //foreach (ISMState s in neededStates) //{ // SMState sObj = this.stateMachine.StateObjectMap.GetStateObject(s); // if (null != sObj) // { // neededStateObjects.Add(sObj); // } // else { throw new SMException("State '" + s.Name + "' was not found in the object map!"); } //} SMInternalTrigger intTrigger = new SMInternalTrigger(this, target, handler, new SMOperator(SMOperatorType.AND, neededStatesArray)); this.stateMachine.RegisterTrigger(intTrigger); } else { throw new SMException("State '" + targetState.Name + "' doesn't exist!"); } }