public void ApplyTimeStamp(TimeStamp timeStamp, TimeSpan totalGameTime, int localID)
        {
            Queue<Command> localCommands = new Queue<Command>(gameStateManager.RollBack(timeStamp.time, localID));
            gameStateManager.TimeStampManager.SwapFirstTimeStamp(timeStamp);

            GameLoop gameLoop = new GameLoop(0);

            SimulationGameTime simulationGameTime = new SimulationGameTime(totalGameTime, totalGameTime.TotalMilliseconds - timeStamp.time);
            gameLoop.InputQueue = localCommands;

            while (simulationGameTime.SimulationTime > 0)
            {
                gameLoop.SimulationLoop(simulationGameTime, this.gameStateManager);
                simulationGameTime.SimulationTime -= 50;
            }
        }
Exemple #2
0
        public void SimulationLoop(IGameTime gameTime, GameStateManager gameStateManager)
        {
            switch (simulationState)
            {
                case SimulationState.Idling:
                    idleTimer -= gameTime.ElapsedGameTime.Milliseconds;
                    if(idleTimer <=0)
                    {
                        OnStartingSimulation();

                        if(inputQueue.Count > 0)
                        {
                            simulationStep = Convert.ToInt32(inputQueue.Peek().time);
                        } else
                        {
                            simulationStep = defaultSimulationStep;
                        }

                    }

                    break;
                case SimulationState.Simulating:
                    endIdling = gameTime.TotalGameTime.Milliseconds;

                    int simulationTime = endIdling - startSimulating;

                    simulationGameTime = new SimulationGameTime(gameTime.TotalGameTime, simulationTime);

                    if(inputQueue.Count > 0)
                    {
                        simulationStep = inputQueue.Peek().time;
                    }

                    startSimulating = gameTime.TotalGameTime.Milliseconds;

                    GamePlaySimulation(gameStateManager);

                    int i = 0;
                    OnFinishedSimulation(gameStateManager, gameTime);
                    idleTimer = defaultIdleTimer;
                    break;
            }
        }