Exemplo n.º 1
0
    public void StoreCommand(int tick)
    {
        if (m_LocalPlayer.playerState == null)
        {
            return;
        }

        m_LocalPlayer.command.checkTick = tick;

        var lastBufferTick = m_LocalPlayer.commandBuffer.LastTick();

        if (tick != lastBufferTick && tick != lastBufferTick + 1)
        {
            m_LocalPlayer.commandBuffer.Clear();
            GameDebug.Log(string.Format("Trying to store tick:{0} but last buffer tick is:{1}. Clearing buffer", tick, lastBufferTick));
        }

        if (tick == lastBufferTick)
        {
            m_LocalPlayer.commandBuffer.Set(ref m_LocalPlayer.command, tick);
        }
        else
        {
            m_LocalPlayer.commandBuffer.Add(ref m_LocalPlayer.command, tick);
        }

#if UNITY_EDITOR
        StateHistory.SetCommand(tick, ref m_LocalPlayer.command);
#endif
    }
Exemplo n.º 2
0
    public void ShowHistory(GameWorld world)
    {
        StateHistory.Enabled = true;
        var state = new CharacterPredictedState.StateData();
        var count = DebugOverlay.Height - 4;

        for (var iEntry = 0; iEntry < count; iEntry++)
        {
            var tick = world.worldTime.tick - count + 1 + iEntry;

            StateHistory.GetPredictedState(this, tick, ref state);

            var y = 2 + iEntry;

            {
                var color    = (Color32)Color.HSVToRGB(0.21f * (int)state.locoState, 1, 1);
                var colorRGB = ((color.r >> 4) << 8) | ((color.g >> 4) << 4) | (color.b >> 4);
                DebugOverlay.Write(2, y, "^{0}{1}", colorRGB.ToString("X3"), state.locoState.ToString());
            }
            DebugOverlay.Write(14, y, state.sprinting ? "Sprint" : "no-sprint");

            {
                var color    = (Color32)Color.HSVToRGB(0.21f * (int)state.action, 1, 1);
                var colorRGB = ((color.r >> 4) << 8) | ((color.g >> 4) << 4) | (color.b >> 4);
                DebugOverlay.Write(26, y, "^{0}{1}", colorRGB.ToString("X3"), state.action.ToString());
            }
        }
    }
Exemplo n.º 3
0
        void UpdateChampions(double dt)
        {
            // Use the time elapsed since our last snapshot as a delta time
            double time = StateHistory.IsEmpty() ? dt :
                          Server.Instance.GetTime().TotalSeconds - StateHistory.GetLast().Key;

            foreach (ServerClient client in Clients.Values)
            {
                if (time > 0.0)
                {
                    Match.CurrentState.ApplyPhysicsUpdate(client.Champion.ID, (float)time);
                }

                UpdateChampionHealth(client);

                // Check to go out of combat
                if (client.ChampStats.ShouldGoOutOfCombat())
                {
                    client.ChampStats.GoOutOfCombat();
                }

                client.Champion.Animation = client.Champion.GetAnim(!client.ChampStats.Alive,                 //TODO: replace with actual HP
                                                                    Match.CurrentState.IsOnGround(client.Champion.ID),
                                                                    client.ChampStats.IsCastingSpell(client.Champion.Type, PlayerActionType.Spell1),
                                                                    client.ChampStats.IsCastingSpell(client.Champion.Type, PlayerActionType.Spell2),
                                                                    client.ChampStats.IsCastingSpell(client.Champion.Type, PlayerActionType.Spell3),
                                                                    client.ChampStats.IsCastingSpell(client.Champion.Type, PlayerActionType.Spell4),
                                                                    client.AnimData.Movement,
                                                                    client.AnimData.Idle,
                                                                    client.Champion.Animation);
            }
        }
Exemplo n.º 4
0
 public override void AuthoritativeChangePosition(StateUpdateData data, double time)
 {
     ServerPosition = data.Position;
     StateHistory.AddSnapshot(
         data,
         GetCurrentTimeSeconds());
 }
Exemplo n.º 5
0
            public void UpdateForChangedVoxel(VoxelCell changedVoxel)
            {
                SolutionState state = FirstState.GetWithChangedCell(changedVoxel);

                StateHistory.Clear();
                StateHistory.Add(state);
            }
Exemplo n.º 6
0
        public void ChangeState(string stateName)
        {
            Form _cur = StateHistory.Peek();

            _cur.Hide();
            Form _new;

            if (stateName == "AddSales")
            {
                _new = new frmAddSales();
            }
            else if (stateName == "Stock")
            {
                _new = new frmStock();
            }
            else if (stateName == "Sales")
            {
                _new = new frmSales();
            }
            else
            {
                throw new System.NotImplementedException();
            }

            _new.Show();
            _new.Activate();
            _new.Closed += new EventHandler(OnFormClosed);
            StateHistory.Push(_new);
        }
Exemplo n.º 7
0
    public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick)
    {
        m_lastServerState.Deserialize(ref reader, refSerializer, tick);

#if UNITY_EDITOR
        StateHistory.SetState(this, tick, ref m_lastServerState);
#endif
    }
Exemplo n.º 8
0
        private void AddState(string state)
        {
            if (this.StateHistory == null)
            {
                this.StateHistory = new List <History>();
            }

            StateHistory.Add(new History(state));
        }
Exemplo n.º 9
0
 void StoreGameState(double dt)
 {
     if (TimeSinceLastGameHistory >= STORE_HISTORY_INTERVAL.TotalSeconds)
     {
         StateHistory.AddSnapshot(Match.CurrentState.Clone() as MatchState, Server.Instance.GetTime().TotalSeconds);
         TimeSinceLastGameHistory = 0.0;
     }
     TimeSinceLastGameHistory += dt;
 }
Exemplo n.º 10
0
 public void AdvanceOneStep()
 {
     if (StateHistory.Count < SolverLimit && !LastState.IsEverythingSolved)
     {
         SolutionState nextState = LastState.GetNextState();
         StateHistory.Add(nextState);
         Status = GetSolverStatus();
     }
 }
Exemplo n.º 11
0
        public void NextState()
        {
            var deadCount = 0;

            var currentBoard = StateHistory.Last();

            var ghosts = GhostMovement(currentBoard.Ghosts);

            var newPlayers = new List <PacManPlayer>();

            var coins = new List <Coin>(currentBoard.Coins);

            foreach (var player in currentBoard.Players)
            {
                var newPlayer = player.Copy();

                //Check if player is alive
                if (!newPlayer.Alive)
                {
                    continue;
                }

                PlayerMovement(newPlayer);

                var coin = CheckCoin(newPlayer, coins);

                if (coin != null)
                {
                    coins.Remove(coin);
                }

                if (CheckPlayerWallCollision(newPlayer))
                {
                    newPlayer.Alive = false;
                    deadCount++;
                    continue;
                }

                if (CheckPlayerGhostCollision(newPlayer, ghosts))
                {
                    deadCount++;
                    newPlayer.Alive = false;
                }

                newPlayers.Add(newPlayer);
            }

            if (deadCount == numberPlayers)
            {
                GameEnded = true;
            }

            NewMovements.Clear();

            StateHistory.Add(new Board(currentBoard.RoundID + 1, ghosts, newPlayers, coins));
        }
Exemplo n.º 12
0
    public void Deserialize(ref NetworkReader reader, IEntityReferenceSerializer refSerializer, int tick)
    {
        var state = new State();

        state.Deserialize(ref reader);

        stateHistory.Add(tick, state);

#if UNITY_EDITOR
        StateHistory.SetState(this, tick, ref state);
#endif
    }
Exemplo n.º 13
0
 private SolverStatus GetSolverStatus()
 {
     if (StateHistory.Any() && LastState.IsEverythingSolved)
     {
         return(SolverStatus.Solved);
     }
     if (StateHistory.Count >= SolverLimit)
     {
         return(SolverStatus.AtLimit);
     }
     return(SolverStatus.Solving);
 }
Exemplo n.º 14
0
        public void Back()
        {
            Form _cur = StateHistory.Pop();

            _cur.Hide();
            _cur.Dispose();
            Form _new = StateHistory.Peek();

            _new.Show();
            _new.Activate();
            _new.Closed += new EventHandler(OnFormClosed);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Clears the state history and adds the "uninitialized" state
        /// </summary>
        private void SetUninitializedState()
        {
            StateHistory.Clear();

            PresentableMD5State uninitializedState = new PresentableMD5State();

            uninitializedState.State = MD5StateDescription.UNINITIALIZED;
            StateHistory.Add(uninitializedState);
            CurrentState = uninitializedState;

            CurrentStateNumber = 0;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Create entity.
        /// </summary>
        public StateHistory Create(StateHistory entity)
        {
            using (var connection = _dbConnectionFactory.CreateConnection())
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    var parameters = new DynamicParameters();

                    parameters.Add("@Name", entity.Name, DbType.String);

                    parameters.Add("@dpdOrderNr", entity.dpdOrderNr, DbType.String);
                    parameters.Add("@dpdParcelNr", entity.dpdParcelNr, DbType.String);

                    parameters.Add("@newState", entity.newState, DbType.String);
                    parameters.Add("@transitionTime", entity.transitionTime, DbType.DateTime2);
                    parameters.Add("@terminalCode", entity.terminalCode, DbType.String);
                    parameters.Add("@terminalCity", entity.terminalCity, DbType.String);
                    parameters.Add("@incidentCode", entity.incidentCode, DbType.String);
                    parameters.Add("@incidentName", entity.incidentName, DbType.String);
                    parameters.Add("@consignee ", entity.consignee, DbType.String);

                    // Configure outputs
                    parameters.Add("@EntityId", dbType: DbType.Int32, direction: ParameterDirection.Output);
                    parameters.Add("@ErrorMessage", dbType: DbType.String, size: 1000, direction: ParameterDirection.Output);

                    // Execute query
                    int result = connection.Execute(
                        sql: StateHistoryInsert_Proc,
                        commandType: CommandType.StoredProcedure,
                        transaction: transaction,
                        param: parameters
                        );

                    // Check for errors
                    string errorMessage = parameters.Get <string>("@ErrorMessage");

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        throw new RepositoryException(errorMessage);
                    }

                    // Set the id
                    entity.Id = parameters.Get <int>("@EntityId");

                    transaction.Commit();

                    return(entity);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Create states
        /// </summary>
        /// <param name="states">Pool of all states</param>
        public override void CreateStates(StatePool states)
        {
            if (states == null)
            {
                throw new ArgumentNullException(nameof(states));
            }

            // We just need a history without integration here
            StateChargeBe             = states.CreateDerivative();
            StateChargeBc             = states.CreateDerivative();
            StateChargeCs             = states.CreateDerivative();
            StateChargeBx             = states.CreateDerivative();
            StateExcessPhaseCurrentBc = states.CreateHistory();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Adds a new state to the history and sets it as the current state
        /// </summary>
        protected void AddNewState()
        {
            if (CurrentStateNumber == -1)
            {
                CurrentState = new PresentableMD5State();
            }
            else
            {
                CurrentState = new PresentableMD5State(StateHistory[CurrentStateNumber]);
            }

            StateHistory.Add(CurrentState);
            CurrentStateNumber = StateHistory.Count - 1;
        }
    protected override void OnUpdate()
    {
        Profiler.BeginSample("StoreStateHistory.Update");
        for (var i = 0; i < Group.characters.Length; i++)
        {
            // Only store data from full ticks
            if (m_world.worldTime.tickDuration != m_world.worldTime.tickInterval)
            {
                return;
            }

            StateHistory.SetPredictedState(Group.characters[i], m_world.worldTime.tick, ref Group.characters[i].State);
        }
        Profiler.EndSample();
    }
Exemplo n.º 20
0
        public LevelInfo()
        {
            Title      = "Untitled";
            MusicPath  = null;
            SkyPath    = null;
            ScriptPath = null;
            ItemPath   = null;
            RandomSeed = 0;
            InEditor   = false;
            InMenu     = false;

            TotalPlacements = 0;
            m_history       = new StateHistory <State>(0.0f);
            m_history.PushState(new State(0));
        }
Exemplo n.º 21
0
    private static void OnUpdateEvent()
    {
        if (m_captureRequested)
        {
            m_captureRequested = false;


            // Capture
            CaptureResult capture = new CaptureResult(StateHistory.HighestTick - StateHistory.BufferSize + 1, StateHistory.BufferSize);

            // Commands
            {
                for (int i = 0; i < capture.count; i++)
                {
                    int tick = i + capture.firstTick;
                    capture.commands[i] = StateHistory.GetCommand <UserCommand>(tick);
                }
            }

            // Components
            List <Component> components = StateHistory.GetComponents();
            foreach (var component in components)
            {
                if (component == null || component.gameObject == null)
                {
                    continue;
                }

                var data = StateHistory.GetComponentData(component);

                var componentData = new ComponentData(component, capture.count);
                capture.componentData.Add(componentData);
                for (int i = 0; i < StateHistory.BufferSize; i++)
                {
                    int tick = i + capture.firstTick;

                    componentData.states[i]          = data.GetState(tick);
                    componentData.predictedStates[i] = data.GetPredicted(tick);
                    componentData.predictionValid[i] = !data.mispredictedTicks.Contains(tick);
                }
            }

            // Sort componts by gameObject
            capture.componentData.Sort((a, b) => (a.component.gameObject.name.CompareTo(b.component.gameObject.name)));

            Capture?.Invoke(capture);
        }
    }
        /// <summary>
        /// Create states
        /// </summary>
        /// <param name="method"></param>
        public override void CreateStates(IntegrationMethod method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            // We just need a history without integration here
            StateChargeBe = method.CreateDerivative();
            StateChargeBc = method.CreateDerivative();
            StateChargeCs = method.CreateDerivative();

            // Spice 3f5 does not include this state for LTE calculations
            StateChargeBx = method.CreateDerivative(false);

            StateExcessPhaseCurrentBc = method.CreateHistory();
        }
        public void SetCurrentState(IState state)
        {
            if (state != null)
            {
                Definition.CheckState(state);
            }

            StateHistory.Add(CurrentStateId, state.id);
            PreviousStateId = CurrentStateId;

            CurrentState   = state;
            CurrentStateId = state.id;

            if (state.EndPoint)
            {
                Finished = true;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Create states
        /// </summary>
        /// <param name="method"></param>
        public override void CreateStates(IntegrationMethod method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            _vgs   = method.CreateHistory();
            _vds   = method.CreateHistory();
            _vbs   = method.CreateHistory();
            _capgs = method.CreateHistory();
            _capgd = method.CreateHistory();
            _capgb = method.CreateHistory();
            _qgs   = method.CreateDerivative();
            _qgd   = method.CreateDerivative();
            _qgb   = method.CreateDerivative();
            _qbd   = method.CreateDerivative();
            _qbs   = method.CreateDerivative();
        }
Exemplo n.º 25
0
        /// <summary>
        /// Create states
        /// </summary>
        /// <param name="states">States</param>
        public override void CreateStates(StatePool states)
        {
            if (states == null)
            {
                throw new ArgumentNullException(nameof(states));
            }

            _vgs   = states.CreateHistory();
            _vds   = states.CreateHistory();
            _vbs   = states.CreateHistory();
            _capgs = states.CreateHistory();
            _capgd = states.CreateHistory();
            _capgb = states.CreateHistory();
            _qgs   = states.CreateDerivative();
            _qgd   = states.CreateDerivative();
            _qgb   = states.CreateDerivative();
            _qbd   = states.CreateDerivative();
            _qbs   = states.CreateDerivative();
        }
Exemplo n.º 26
0
        /// <summary>
        /// Create states
        /// </summary>
        /// <param name="states">States</param>
        public override void CreateStates(StatePool states)
        {
            if (states == null)
            {
                throw new ArgumentNullException(nameof(states));
            }

            ChargeGs = states.CreateDerivative();
            ChargeGd = states.CreateDerivative();
            ChargeGb = states.CreateDerivative();
            ChargeBd = states.CreateDerivative();
            ChargeBs = states.CreateDerivative();

            CapGs     = states.CreateHistory();
            CapGd     = states.CreateHistory();
            CapGb     = states.CreateHistory();
            VoltageGs = states.CreateHistory();
            VoltageDs = states.CreateHistory();
            VoltageBs = states.CreateHistory();
        }
        /// <summary>
        /// Create states
        /// </summary>
        /// <param name="method"></param>
        public override void CreateStates(IntegrationMethod method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            ChargeGs = method.CreateDerivative();
            ChargeGd = method.CreateDerivative();
            ChargeGb = method.CreateDerivative();
            ChargeBd = method.CreateDerivative();
            ChargeBs = method.CreateDerivative();

            CapGs     = method.CreateHistory();
            CapGd     = method.CreateHistory();
            CapGb     = method.CreateHistory();
            VoltageGs = method.CreateHistory();
            VoltageDs = method.CreateHistory();
            VoltageBs = method.CreateHistory();
        }
Exemplo n.º 28
0
        void InterpolateInThePast()
        {
            double targetTime = GetCurrentTimeSeconds() - LERP_TIME_IN_THE_PAST.TotalSeconds;

            if (!StateHistory.IsEmpty())
            {
                KeyValuePair <double, StateUpdateData> before = StateHistory.GetSnapshotBefore(targetTime);
                KeyValuePair <double, StateUpdateData>?after  = StateHistory.GetNext(before);

                if (after.HasValue)
                {
                    Debug.Assert(targetTime <= after.Value.Key);
                    Debug.Assert(before.Key <= after.Value.Key);

                    if (targetTime < before.Key)                       // if we have a too small history
                    {
                        ILogger.Log(String.Format("Remote history too small. Snapping time {0} to {1}", targetTime, before.Key),
                                    LogPriority.High);
                        targetTime = before.Key;
                    }

                    double progress = (targetTime - before.Key) / (after.Value.Key - before.Key);
                    Debug.Assert(0.0 - double.Epsilon <= progress && progress <= 1.0 + double.Epsilon);

                    Position = Vec2.Lerp(before.Value.Position, after.Value.Value.Position, (float)progress);

                    // Take animation of closest state
                    var closestState = after.Value.Value;
                    Animation  = closestState.Animation;
                    FacingLeft = closestState.FacingLeft;
                }
                else
                {
                    Position = before.Value.Position;
                    //TODO: extrapolation here
                }
            }
        }
Exemplo n.º 29
0
        private void StateChanged(object sender, Events.StateChangedArgs e)
        {
            //todo: this should be pushed directly to a queue to minimize time in method. the queue can be picked up by a processor that does what this method is currently doing.
            Dispatcher.Invoke((state) =>
            {
                State = state as ITelloState;
                StateHistory.Add(state as ITelloState);
                if (StateHistory.Count > 500)
                {
                    StateHistory.RemoveAt(0);
                }
            },
                              e.State);


            var group = _repository.NewEntity <ObservationGroup>(_session);

            _repository.Insert(new StateObservation(group, e.State));
            _repository.Insert(new AirSpeedObservation(group, e.State));
            _repository.Insert(new AttitudeObservation(group, e.State));
            _repository.Insert(new BatteryObservation(group, e.State));
            _repository.Insert(new HobbsMeterObservation(group, e.State));
            _repository.Insert(new PositionObservation(group, e.State));
        }
Exemplo n.º 30
0
        void HandleMovementAction(ulong id, PlayerAction action)
        {
            double now  = Server.Instance.GetTime().TotalSeconds;
            double time = action.Time;

            // Make sure we're not using weird times
            time = ValidateActionTime(action, now);

            // Go to the given action time if we have a state history
            if (!StateHistory.IsEmpty())
            {
                // Go to the game snapshot before the action that we're simulating
                KeyValuePair <double, MatchState> stateBefore = StateHistory.GetSnapshotBefore(time);
                KeyValuePair <double, MatchState> state       = new KeyValuePair <double, MatchState>(
                    stateBefore.Key,
                    stateBefore.Value.Clone() as MatchState);

                // Simulate from our previous snapshot to our current action to be up-to-date
                if (state.Value.ContainsEntity(id))
                {
                    var   player = (ICharacter)state.Value.GetEntity(id);
                    float deltaT = (float)(time - state.Key);
                    if (deltaT > 0f)                       // if we have something to simulate...
                    {
                        state.Value.ApplyPhysicsUpdate(id, deltaT);
                    }

                    // Make sure we're not using hacked positions
                    player.Position = ValidateActionPosition(player, action);

                    // Actually execute the action on our currently simulated state
                    DoAction(state.Value, player, action);

                    // Store our intermediate state at the action time.
                    state = StateHistory.AddSnapshot(state.Value, time);
                }



                // Resimulate all the states up to now so that they are affected
                // by the player's action.
                var nextState = StateHistory.GetNext(state);
                while (nextState.HasValue)
                {
                    // get how much time we have to simulate for next state
                    float timeUntilNextState = (float)(nextState.Value.Key - time);
                    Debug.Assert(timeUntilNextState >= 0f);

                    // simulate the next state
                    if (nextState.Value.Value.ContainsEntity(id))
                    {
                        nextState.Value.Value.GetEntity(id).Clone(state.Value.GetEntity(id));
                        if (timeUntilNextState > 0f)
                        {
                            nextState.Value.Value.ApplyPhysicsUpdate(id, timeUntilNextState);
                        }
                    }

                    // switch to the next state
                    state     = nextState.Value;
                    time      = state.Key;
                    nextState = StateHistory.GetNext(state);
                }

                // Modify our current game state to apply our simulation modifications.
                var last = StateHistory.GetLast();
                if (Match.CurrentState.ContainsEntity(id) && last.Value.ContainsEntity(id))
                {
                    Match.CurrentState.GetEntity(id).Clone(last.Value.GetEntity(id));
                }
            }
        }