/// <summary> /// 连续弹出多个状态 /// </summary> public void PopStates(int count) { if (count > _states.Count) count = _states.Count; if (count <= 0) return; if (_currentState != null) { _currentState.OnExit(); } IStackState state; while(count > 0) { state = _states.Pop(); if (state != null) state.OnPop(); count--; } state = _currentState; _currentState = (_states.Count > 0) ? _states.Peek() : null; _currentStateTime = 0f; if (_currentState != null) { _currentState.OnEnter(); } OnStateChanged(state, _currentState); }
/// <summary> /// 将新状态压入栈 /// </summary> public void PushState(IStackState newState) { if (_currentState != null) { _currentState.OnExit(); } Kit.Swap(ref _currentState, ref newState); _currentStateTime = 0; _states.Push(_currentState); if (_currentState != null) { _currentState.OnPush(); _currentState.OnEnter(); } OnStateChanged(newState, _currentState); }
/// <summary> /// Pulls the data sources from the provided stack state, and merges them with each stack slot. /// </summary> /// <param name="self">The state to modify.</param> /// <param name="other">A snapshot of the stack to pull the data sources from.</param> /// <returns><c>True</c> if the stack state has changed, <c>false</c> otherwise.</returns> /// <exception cref="StackImbalanceException">Occurs when the stack states are of different size.</exception> public static bool MergeWith <T>(this IStackState <SymbolicValue <T> > self, IStackState <SymbolicValue <T> > other) { if (self.Size != other.Size) { throw new StackImbalanceException(); } var zipped = self .GetAllStackSlots() .Zip(other.GetAllStackSlots(), (a, b) => (a, b)) #if DEBUG .ToArray() #endif ; bool changed = false; foreach (var(a, b) in zipped) { changed |= a.MergeWith(b); } return(changed); }
protected override void OnStateChanged(IStackState prevState, IStackState currentState) { focusTarget = (currentState as CustomStackState).rectTransform; }
/// <summary> /// Creates a new symbolic program state. /// </summary> /// <param name="programCounter">The value of the current program counter.</param> /// <param name="stack">A snapshot of the current state of the stack.</param> /// <param name="variables">A snapshot of the state of all variables.</param> public SymbolicProgramState(long programCounter, IStackState <SymbolicValue <TInstruction> > stack, IVariableState <SymbolicValue <TInstruction> > variables) { ProgramCounter = programCounter; Stack = stack ?? throw new ArgumentNullException(nameof(stack)); Variables = variables ?? throw new ArgumentNullException(nameof(variables)); }
/// <summary> /// 状态变化后触发的事件 /// </summary> protected virtual void OnStateChanged(IStackState prevState, IStackState currentState) { }