Update() private method

private Update ( ) : void
return void
Example #1
0
 /// <summary>
 /// Primary game loop.
 /// </summary>
 public void GameLoop()
 {
     while (Running)
     {
         _resetEvent.WaitOne(1);
         FCounter.Update();
         try {
             if (WorldLoaded && GameTime != null)
             {
                 Users.Frame();
                 if (GameTime.Update())                          // every second
                 {
                     if (GameTime.TickIncrease)                  // update when enough seconds pass to increase tick.
                     {
                         Logger.Log("Updating world. Tick: {0}", GameTime.Tick.ToString());
                         Users.TickUpdate();
                         Structures.TickUpdate();
                         _taskQueue.Update();
                         Save();
                         SockServ.Broadcast("tick", GameTime.Tick.ToString());
                     }
                 }
             }
             //Net.Update();
             _taskQueue.Update();                 // run items queued during frame.
             Logger.Update();                     // print items sent to log during frame.
         }
         catch (Exception e) {
             Logger.LogError("{0}: {1}\n{2}", e.GetType(), e.Message, e.StackTrace);
         }
     }
 }
        public void Run()
        {
            LoadContent();
            Initialize(GameTime);

            float totalTimeBeforeUpdate = 0f;
            float previousTimeElapsed   = 0f;
            float deltaTime             = 0f;
            float totalTimeElapsed      = 0f;

            Clock clock = new Clock();

            while (Window.IsOpen)
            {
                Window.DispatchEvents();

                totalTimeElapsed    = clock.ElapsedTime.AsSeconds();
                deltaTime           = totalTimeElapsed - previousTimeElapsed;
                previousTimeElapsed = totalTimeElapsed;

                totalTimeBeforeUpdate += deltaTime;

                if (totalTimeBeforeUpdate >= TIME_UNTIL_UPDATE)
                {
                    GameTime.Update(totalTimeBeforeUpdate, totalTimeElapsed);
                    totalTimeBeforeUpdate = 0f;

                    Update(GameTime);

                    Window.Clear(WindowClearColor);
                    Draw(GameTime);
                    Window.Display();
                }
            }
        }
Example #3
0
        private void UpdateValueTime()
        {
            var deltaTime      = (float)GameTime.Update(ref _valueTime).Seconds;
            var animationSpeed = AnimationSpeed?.Value ?? 0;
            var targetValue    = TargetValue?.Value ?? 0;

            if (!(animationSpeed > 0))
            {
                return;
            }

            var deltaValue         = targetValue - _value;
            var deltaValueAbs      = Math.Abs(deltaValue);
            var deltaValueSign     = Math.Sign(deltaValue);
            var possibleDeltaValue = deltaTime * animationSpeed;

            if (possibleDeltaValue >= deltaValueAbs)
            {
                _value = targetValue;
            }
            else
            {
                _value += deltaValueSign * possibleDeltaValue;
            }
        }
Example #4
0
        private long Update(long id)
        {
            lock (_locker)
            {
                DateTime utcNow = DateTime.UtcNow;

                try
                {
                    _gameTime.Update(utcNow);

                    GameHandler.Update(_gameTime);

                    if (_actualFPS <= _drawFPS || (++_drawCount) % DRAW_AFTER == 0)
                    {
                        Draw();
                        _drawCount = 0;
                    }
                }
                catch (Exception e)
                {
                    // ErrorLog.Instance.Log(e);
                }

                return(id);
            }
        }
Example #5
0
        public DrawingSurfaceSIS(IRenderer renderer1, IRenderer renderer2)
        {
            gameTime                 = new GameTime();
            totalGameTime            = new TimeSpan();
            timer                    = new TimerTick();
            IsFixedTimeStep          = true;
            maximumElapsedTime       = TimeSpan.FromMilliseconds(500.0);
            TargetElapsedTime        = TimeSpan.FromTicks(10000000 / 60); // target elapsed time is by default 60Hz
            lastUpdateCount          = new int[4];
            nextLastUpdateCountIndex = 0;

            // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 )
            // Example for a moving average of 4:
            // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f
            const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates)
            var       maxLastCount       = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length);

            updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length;

            timer.Reset();
            gameTime.Update(totalGameTime, TimeSpan.Zero, false);

            //gameTime.FrameCount = 0;



            Init(renderer1, renderer2);
        }
Example #6
0
 protected override void Update()
 {
     GameTime.Update();
     Flags.Update(GameTime);
     Shots.Update(GameTime);
     Players.Update(GameTime);
 }
Example #7
0
 public void Update()
 {
     if (cycleEnabled)
     {
         GameTime.Update(Time.deltaTime);
         ChangeTime();
     }
 }
Example #8
0
        static void Main(string[] args)
        {
            // initialize window and view
            win  = new RenderWindow(new VideoMode((uint)windowSize.X, (uint)windowSize.Y), "Hadoken!!!");
            view = new View();
            ResetView();
            gui = new GUI(win, view);

            // prevent window resizing
            win.Resized += (sender, e) => { (sender as Window).Size = windowSize; };

            // exit Program, when window is being closed
            //win.Closed += new EventHandler(closeWindow);
            win.Closed += (sender, e) => { (sender as Window).Close(); };

            // initialize GameState
            HandleNewGameState();

            // initialize GameTime
            GameTime = new GameTime();
            GameTime.Start();

            // debug Text
            Text debugText = new Text("debug Text", new Font("Fonts/calibri.ttf"));

            while (running && win.IsOpen())
            {
                KeyboardInputManager.Update();

                // update GameTime
                GameTime.Update();
                float deltaTime = (float)GameTime.EllapsedTime.TotalSeconds;

                currentGameState = state.Update(deltaTime);

                if (currentGameState != prevGameState)
                {
                    HandleNewGameState();
                }

                // gather drawStuff from State
                win.Clear(new Color(100, 149, 237));    //cornflowerblue ftw!!! 1337
                state.Draw(win, view, deltaTime);
                state.DrawGUI(gui, deltaTime);

                // some DebugText
                debugText.DisplayedString = "fps: " + (1.0F / deltaTime);
                win.Draw(debugText);

                // do the actual drawing
                win.SetView(view);
                win.Display();

                // check for window-events. e.g. window closed
                win.DispatchEvents();
                Update_view();
            }
        }
Example #9
0
        public static string rootPath = "../../"; // path for development version
        //public static string rootPath = ""; // path for shipping version

        static void Main(string[] args)
        {
            // initialize window and view
            win  = new RenderWindow(new VideoMode(800, 600), "2D Game Project");
            view = new View();
            resetView();
            gui = new GUI(win, view);

            Text debugText = new Text("", calibriFont);

            debugText.Color = new Color(252, 143, 80);

            // exit Program, when window is being closed
            //win.Closed += new EventHandler(closeWindow);
            win.Closed += (sender, e) => { (sender as Window).Close(); };

            // initialize GamePadInputManager, in case, there are GamePads connected
            gamePadInputManager = new GamePadInputManager();

            // initialize GameState
            handleNewGameState();

            // initialize GameTime
            gameTime = new GameTime();
            gameTime.Start();

            while (running && win.IsOpen())
            {
                gamePadInputManager.update();
                // TODO: reevaluate gamepads every once in a while

                currentGameState = state.update();

                if (currentGameState != prevGameState)
                {
                    handleNewGameState();
                }

                // draw current frame
                win.Clear(new Color(100, 149, 237));    //cornflowerblue ftw!!! 1337
                state.draw(win, view);
                state.drawGUI(gui);
                {   //HACK
                    debugText.DisplayedString  = "fps:" + (1.0 / gameTime.EllapsedTime.TotalSeconds);
                    debugText.DisplayedString += "\ntest";
                    gui.draw(debugText);
                }
                win.SetView(view);
                win.Display();

                // check for window-events. e.g. window closed
                win.DispatchEvents();

                // update GameTime
                gameTime.Update();
            }
        }
Example #10
0
        static void RunOutgame(RegisterMemory rmem)
        {
            try
            {
                GameTime.Update();
                GUCTimer.Update(GameTime.Ticks);

                GameTime.Update();
                GameClient.Update();

                GameTime.Update();
                InputHandler.Update();

                if (!ShowConnectionAttempts())
                {
                    if (!outgameStarted)
                    {
                        outgameStarted = true;
                        VobRenderArgs.Init();
                        ScriptManager.Interface.StartOutgame();
                    }

                    GameTime.Update();
                    ScriptManager.Interface.Update(GameTime.Ticks);
                }

                #region Gothic

                WinApi.Process.CDECLCALL <WinApi.NullReturnCall>(0x5053E0); // void __cdecl sysEvent(void)

                using (zColor color = zColor.Create(0, 0, 0, 0))
                    zCRenderer.Vid_Clear(color, 3);

                zCRenderer.BeginFrame();
                zCView.GetScreen().Render();
                zCRenderer.EndFrame();
                zCRenderer.Vid_Blit(1, 0, 0);
                zCSndSys_MSS.DoSoundUpdate();

                #endregion

                if (fpsWatch.IsRunning)
                {
                    long diff = 8 * TimeSpan.TicksPerMillisecond - fpsWatch.Elapsed.Ticks;
                    if (diff > 0)
                    {
                        Thread.Sleep((int)(diff / TimeSpan.TicksPerMillisecond));
                    }
                }
                fpsWatch.Restart();
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Example #11
0
        private void BeginServerLoop()
        {
            _netThread = new Thread(() =>
            {
                float millisecondsPerUpdate = 1000f / Settings.TickRate;
                float nextUpdateTime        = 0;
                var gameTime = new GameTime();

                gameTime.Start();

                while (!Server.ShutDown)
                {
                    if (gameTime.TotalElapsedTime >= nextUpdateTime)
                    {
                        _netHandler.Update();

                        nextUpdateTime = gameTime.TotalElapsedTime + millisecondsPerUpdate;

                        gameTime.Update();
                    }
                }
            });

            _worldThread = new Thread(() =>
            {
                float millisecondsPerUpdate = 1000f / Settings.TickRate;
                float nextUpdateTime        = 0;
                var gameTime = new GameTime();

                gameTime.Start();

                while (!Server.ShutDown)
                {
                    if (gameTime.TotalElapsedTime >= nextUpdateTime)
                    {
                        Server.ServiceLocator.GetService <WorldManager>().Update(gameTime);

                        GameTimerManager.Instance.Update(gameTime);

                        nextUpdateTime = gameTime.TotalElapsedTime + millisecondsPerUpdate;

                        gameTime.Update();
                    }
                }

                // Save the game world
                Server.ServiceLocator.GetService <WorldManager>().Save();
            });

            _netThread.Start();
            _worldThread.Start();
        }
Example #12
0
        public void UpdateState()
        {
            var elapsedDuration = GameTime.Update(ref _frameTime);

            MovePlayer(elapsedDuration);

            foreach (var entityInfo in EntityInfos)
            {
                Movement.MoveEntity(PhysicsValues, World, entityInfo.PositionData, elapsedDuration, entityInfo.PositionData.Velocity);
            }

            UpdateBuildAction(elapsedDuration);
        }
Example #13
0
    public void Update(float dt)
    {
        //  *** 在逻辑更新之前这里会处理各种touch事件~  这里面处理的逻辑有:生成士兵 和 ForceBattleEnd(这个延迟到DelayManager进行调用)。***
        currentWorldMode.Update(dt);            //  REMARK:这个移动到录像之前,确保所有的士兵产生逻辑都在录像之前。方便帧数统一。

        GameRecord.Update(dt);                  //  REMARK:这个应该位于其他逻辑的最上层、但位于产生士兵的下面。
        GameTime.Update(dt);
        IsoMap.Instance.Update(dt);             //  REMARK:这里面可能导致战斗结束
        GameBulletManager.Instance.Update(dt);
        GameEffectManager.Instance.Update(dt);
        GameSkillManager.Instance.Update(dt);
        UpdateManager.Instance.Update(dt);
        DelayManager.Instance.Update(dt);       //  REMARK:这里面也可能导致战斗结束(因为从上面的touch事件延迟到这里面了)这样 战斗结束事件都在 Record 的后面方便帧数统一。
    }
Example #14
0
        /// <summary>
        /// Start your game with this method.
        /// Starts the gametime, keeps the window open, dispatches the window events.
        /// Updates the gametime and the derived class aswell. Calls the draw method of the derived class and displays the window.
        /// </summary>
        public void run()
        {
            gameTime.Start();

            while (window.IsOpen())
            {
                window.DispatchEvents();
                gameTime.Update();

                update(gameTime);
                draw(gameTime, window);

                wheelDelta = 0;
                window.Display();
            }
        }
Example #15
0
        public void Run()
        {
            //double timeBeforeUpdate = 0d;
            //float prevTimeElapsed = 0f, deltaTime = 0f, timeElapsed = 0f;

            Clock clock;

            LoadContent();
            Initialize();

            clock = new Clock();

            while (Window.IsOpen)
            {
                Window.DispatchEvents();

                //float timeElapsed, deltaTime, prevTimeElapsed = 0, timeBeforeUpdate = 0;

                //timeElapsed = clock.ElapsedTime.AsSeconds();
                //deltaTime = timeElapsed - prevTimeElapsed;
                //prevTimeElapsed = timeElapsed;

                //timeBeforeUpdate += deltaTime;

                //if (timeBeforeUpdate >= TimeUntilUpdate)
                //{
                //    GameTime.Update(TimeUntilUpdate, clock.ElapsedTime.AsSeconds());
                //    Update(GameTime);

                //    timeBeforeUpdate = 0;

                //    Window.Clear(ClearColor);
                //    Draw(GameTime);
                //    Window.Display();
                //}
                GameTime.Update(TimeUntilUpdate, clock.ElapsedTime.AsSeconds());
                Update(GameTime);

                Window.Clear(ClearColor);
                Draw(GameTime);
                Window.Display();
            }
        }
Example #16
0
        public void Run()
        {
            LoadContent();
            Initialize();

            var totalTimeBeforeUpdate = 0f;
            var previousTimeElapsed   = 0f;
            var deltaTime             = 0f;
            var totalTimeElapsed      = 0f;

            var clock = new Clock();

            while (Window.IsOpen)
            {
                Window.DispatchEvents();

                totalTimeElapsed    = clock.ElapsedTime.AsSeconds();
                deltaTime           = totalTimeElapsed - previousTimeElapsed;
                previousTimeElapsed = totalTimeElapsed;

                totalTimeBeforeUpdate += deltaTime;

                if (!(totalTimeBeforeUpdate >= TIME_UNTIL_UPDATE))
                {
                    continue;
                }

                GameTime.Update(totalTimeBeforeUpdate, clock.ElapsedTime.AsSeconds());
                totalTimeBeforeUpdate = 0f;
                if (!_isPaused)
                {
                    Update(GameTime);
                }

                Window.Clear(WindowClearColor);
                Draw(GameTime);
                Window.Display();
            }
        }
Example #17
0
        private void RunUniverse()
        {
            try
            {
                var frameTime = GameTime.Now();

                while (!_isDisposed)
                {
                    var startTime = DateTime.Now;

                    lock (_mutex)
                    {
                        foreach (var channel in _channels)
                        {
                            while (true)
                            {
                                var playerEvent = channel.TakePlayerEvent();
                                if (playerEvent == null)
                                {
                                    break;
                                }
                                HandlePlayerEvent(channel, playerEvent);
                            }
                        }

                        var elapsedDuration = GameTime.Update(ref frameTime);
                        foreach (var entity in Universe.GetEntitiesWithComponent <PositionComponent>())
                        {
                            if (entity.Has <AiComponent>())
                            {
                                Ai.Control(Mod.PhysicsValues, elapsedDuration, entity);
                            }

                            var position = entity.Get <PositionComponent>();

                            Movement.MoveEntity(
                                Mod.PhysicsValues,
                                Universe.StartWorld,
                                position,
                                elapsedDuration,
                                position.Velocity);

                            entity.Set(position);
                        }

                        foreach (var channel in _channels)
                        {
                            if (channel.NeedsGameEvent())
                            {
                                var gameEvent = GetCurrentGameEvent(channel);
                                if (!channel.HasSentInitialValues)
                                {
                                    channel.HasSentInitialValues = true;
                                    gameEvent.PhysicsValues      = Mod.PhysicsValues;
                                }

                                channel.QueueGameEvent(gameEvent);
                            }
                        }
                    }

                    var endTime = DateTime.Now;

                    double sleepMillis = 10 - (endTime - startTime).TotalMilliseconds;
                    if (sleepMillis > 0)
                    {
                        Thread.Sleep((int)Math.Ceiling(sleepMillis));
                    }
                }
            }
            catch
            {
            }
        }
Example #18
0
        static void Main(string[] args)
        {
            // init screen related constants
            Constants.windowSizeY = (int)VideoMode.DesktopMode.Height;
            Constants.windowSizeX = Constants.windowSizeY * 4 / 3;
            Constants.windowScaleFactor = Constants.windowSizeY / 600f;
            Constants.screenRatio = (float)Constants.windowSizeY / Constants.windowSizeX;
            Constants.worldToScreenRatio = Constants.windowSizeX / Constants.worldSizeX;
            Constants.worldSizeY = Constants.worldSizeX * Constants.screenRatio;

            // initialize window and view
            win = new RenderWindow(new VideoMode((uint)Constants.windowSizeX, (uint)Constants.windowSizeY), "Shøøp");
            view = new View();
            resetView();
            gui = new GUI(win, view);

            // exit Program, when window is being closed
            //win.Closed += new EventHandler(closeWindow);
            win.Closed += (sender, e) => { (sender as Window).Close(); };

            // initialize GameState
            handleNewGameState();

            // initialize GameTime
            gameTime = new GameTime();
            float deltaTime = 0f;
            gameTime.Start();
            while (running && win.IsOpen())
            {
            //		gameTime.Update();

                GamePadInputManager.update();
                KeyboardInputManager.update();

                if (currentGameState == GameState.InGame) { inGameFrameCount++; }
                currentGameState = state.update(deltaTime * Constants.gameSpeedFactor);

                if (currentGameState != prevGameState)
                {
                    handleNewGameState();
                }

                // draw current frame
                win.Clear(new Color(100, 149, 237));    //cornflowerblue ftw!!! 1337
                state.draw(win, view);
                state.drawGUI(gui);

                win.SetView(view);
                win.Display();

                // check for window-events. e.g. window closed
                win.DispatchEvents();

                System.Threading.Thread.Sleep(5);
                // update GameTime
                gameTime.Update();
                deltaTime = (float)gameTime.EllapsedTime.TotalSeconds;
            //	int waitTime = (int)(16.667f - gameTime.EllapsedTime.TotalMilliseconds);
            //	if (waitTime > 0) System.Threading.Thread.Sleep(waitTime);
            //	win.SetTitle(waitTime.ToString());
            //	win.SetTitle((count/60f).ToString("0.0") + " | " + gameTime.TotalTime.TotalSeconds.ToString("0.0"));
            }
        }
Example #19
0
        static void Main(string[] args)
        {
            // initialize window and view
            win  = new RenderWindow(new VideoMode((uint)windowSize.X, (uint)windowSize.Y), "RAMification!!!");
            view = new View();
            ResetView();
            gui = new GUI(win, view);

            // prevent window resizing
            win.Resized += (sender, e) => { (sender as Window).Size = windowSize; };

            // exit Program, when window is being closed
            //win.Closed += new EventHandler(closeWindow);
            win.Closed += (sender, e) => { (sender as Window).Close(); };

            // initialize GameState
            HandleNewGameState();

            // initialize GameTime
            GameTime = new GameTime();
            GameTime.Start();
            logger = Logger.Instance;
            // TODO: set level to 0 and writemodes to false
            logger.SetLevel(0);
            // writeToFile should be optional
            logger.SetWriteMode(false, false);

            // debug Text
            Text debugText = new Text("debug Text", new Font("Assets/Fonts/calibri.ttf"));

            win.SetMouseCursorVisible(false);

            while (running && win.IsOpen())
            {
                KeyboardInputManager.Update();

                // update GameTime
                GameTime.Update();
                float deltaTime = (float)GameTime.EllapsedTime.TotalSeconds;
                // logger needs Timespan for Timestamp!
                logger.UpdateTime(GameTime.TotalTime);
                currentGameState = state.Update(win, deltaTime);

                if (currentGameState != prevGameState)
                {
                    HandleNewGameState();
                }

                // gather drawStuff from State
                win.Clear(new Color(0, 0, 0));    //cornflowerblue ftw!!! 1337
                state.Draw(win, view, deltaTime);
                state.DrawGUI(gui, deltaTime);

                // some DebugText
                //debugText.DisplayedString = "fps: " + (1.0F / deltaTime);
                //gui.Draw(debugText);

                // do the actual drawing
                win.SetView(view);
                win.Display();

                // check for window-events. e.g. window closed
                win.DispatchEvents();
                Update_view();
            }
        }
Example #20
0
        public override void Alter(LTimerContext timer)
        {
            if (!IsOnLoadComplete())
            {
                return;
            }

            gameTime.Update(timer);

            if (!isInit)
            {
                LoadContent();
            }

            gameCollection.Update(gameTime);
            if (drawablesToUpdate.Count > 0)
            {
                CollectionUtils.Clear(drawablesToUpdate);
            }

            foreach (Drawable drawable in drawables)
            {
                CollectionUtils.Add(drawablesToUpdate, drawable);
            }

            bool otherScreenHasFocus  = false;
            bool coveredByOtherScreen = false;

            Drawable _drawable;
            int      screenIndex;

            for (; drawablesToUpdate.Count > 0;)
            {
                screenIndex = drawablesToUpdate.Count - 1;
                _drawable   = drawablesToUpdate[screenIndex];

                CollectionUtils.RemoveAt(drawablesToUpdate, screenIndex);

                if (_drawable._enabled)
                {
                    _drawable.Update(gameTime, otherScreenHasFocus,
                                     coveredByOtherScreen);

                    if (_drawable.GetDrawableState() == Painting.DrawableState.TransitionOn ||
                        _drawable.GetDrawableState() == Painting.DrawableState.Active)
                    {
                        if (!otherScreenHasFocus)
                        {
                            _drawable.HandleInput(this);
                            otherScreenHasFocus = true;
                        }
                        if (!_drawable.IsPopup)
                        {
                            coveredByOtherScreen = true;
                        }
                    }
                }
            }

            Update(gameTime);
        }
Example #21
0
        public void Tick()
        {
            if (timer == null)
            {
                return;
            }

            // Update the timer
            timer.Tick();

            var elapsedAdjustedTime = timer.ElapsedAdjustedTime;

            if (forceElapsedTimeToZero)
            {
                elapsedAdjustedTime    = TimeSpan.Zero;
                forceElapsedTimeToZero = false;
            }

            if (elapsedAdjustedTime > maximumElapsedTime)
            {
                elapsedAdjustedTime = maximumElapsedTime;
            }

            bool suppressNextDraw       = true;
            int  updateCount            = 1;
            var  singleFrameElapsedTime = elapsedAdjustedTime;

            if (IsFixedTimeStep)
            {
                // If the rounded TargetElapsedTime is equivalent to current ElapsedAdjustedTime
                // then make ElapsedAdjustedTime = TargetElapsedTime. We take the same internal rules as XNA
                if (Math.Abs(elapsedAdjustedTime.Ticks - TargetElapsedTime.Ticks) < (TargetElapsedTime.Ticks >> 6))
                {
                    elapsedAdjustedTime = TargetElapsedTime;
                }

                // Update the accumulated time
                accumulatedElapsedGameTime += elapsedAdjustedTime;

                // Calculate the number of update to issue
                updateCount = (int)(accumulatedElapsedGameTime.Ticks / TargetElapsedTime.Ticks);

                // If there is no need for update, then exit
                if (updateCount == 0)
                {
                    return;
                }

                // Calculate a moving average on updateCount
                lastUpdateCount[nextLastUpdateCountIndex] = updateCount;
                float updateCountMean = 0;
                for (int i = 0; i < lastUpdateCount.Length; i++)
                {
                    updateCountMean += lastUpdateCount[i];
                }

                updateCountMean         /= lastUpdateCount.Length;
                nextLastUpdateCountIndex = (nextLastUpdateCountIndex + 1) % lastUpdateCount.Length;

                // Test when we are running slowly
                drawRunningSlowly = updateCountMean > updateCountAverageSlowLimit;

                // We are going to call Update updateCount times, so we can substract this from accumulated elapsed game time
                accumulatedElapsedGameTime = new TimeSpan(accumulatedElapsedGameTime.Ticks - (updateCount * TargetElapsedTime.Ticks));
                singleFrameElapsedTime     = TargetElapsedTime;
            }
            else
            {
                Array.Clear(lastUpdateCount, 0, lastUpdateCount.Length);
                nextLastUpdateCountIndex = 0;
                drawRunningSlowly        = false;
            }

            // Reset the time of the next frame
            for (lastFrameElapsedGameTime = TimeSpan.Zero; updateCount > 0 && !isExiting; updateCount--)
            {
                gameTime.Update(totalGameTime, singleFrameElapsedTime, drawRunningSlowly);

                try
                {
                    //Update(gameTime);

                    // If there is no exception, then we can draw the frame
                    suppressNextDraw &= suppressDraw;
                    suppressDraw      = false;
                }
                finally
                {
                    lastFrameElapsedGameTime += singleFrameElapsedTime;
                    totalGameTime            += singleFrameElapsedTime;
                }
            }

            if (!suppressNextDraw)
            {
                //DrawFrame();
                gameTime.FrameCount++;
            }
        }
Example #22
0
 private void RpcUpdateGameTime(float time, bool forceUpdate)
 {
     GameTime.Update(time, forceUpdate);
 }
Example #23
0
        private void RunUniverse()
        {
            try
            {
                var frameTime = GameTime.Now();

                while (!_isDisposed)
                {
                    var startTime = DateTime.Now;

                    lock (_mutex)
                    {
                        foreach (var channel in _channels)
                        {
                            while (true)
                            {
                                var playerEvent = channel.TakePlayerEvent();
                                if (playerEvent == null)
                                {
                                    break;
                                }
                                HandlePlayerEvent(channel, playerEvent);
                            }
                        }

                        var elapsedDuration = GameTime.Update(ref frameTime);
                        foreach (var entity in _entities)
                        {
                            if (entity.PositionData == null)
                            {
                                continue;
                            }

                            if (entity.IsAiControlled)
                            {
                                Ai.Control(_mod.PhysicsValues, elapsedDuration, entity, _entities.FindAll(e => !e.Equals(entity)));
                            }

                            Movement.MoveEntity(
                                _mod.PhysicsValues,
                                _startWorld,
                                entity.PositionData,
                                elapsedDuration,
                                entity.PositionData.Velocity);
                        }

                        foreach (var channel in _channels)
                        {
                            if (channel.NeedsGameEvent())
                            {
                                var gameEvent = GetCurrentGameEvent(channel);
                                if (!channel.HasSentInitialValues)
                                {
                                    channel.HasSentInitialValues = true;
                                    gameEvent.PhysicsValues      = _mod.PhysicsValues;
                                }

                                channel.QueueGameEvent(gameEvent);
                            }
                        }
                    }

                    var endTime = DateTime.Now;

                    double sleepMillis = 10 - (endTime - startTime).TotalMilliseconds;
                    if (sleepMillis > 0)
                    {
                        Thread.Sleep((int)Math.Ceiling(sleepMillis));
                    }
                }
            }
            catch
            {
            }
        }
Example #24
0
        static void RunIngame(RegisterMemory rmem)
        {
            try
            {
                spikeWatch.Restart();
                // Update Timers
                GameTime.Update();
                GUCTimer.Update(GameTime.Ticks);

                // Do networking, read packets
                GameTime.Update();
                GameClient.Update();

                // handle peripherals' input
                GameTime.Update();
                InputHandler.Update();

                if (!ShowConnectionAttempts())
                {
                    if (!ingameStarted)
                    {
                        ingameStarted = true;
                        ScriptManager.Interface.StartIngame();
                    }

                    // ClientScripts update
                    GameTime.Update();
                    ScriptManager.Interface.Update(GameTime.Ticks);

                    if (GameClient.Client.IsIngame)
                    {
                        // Update worlds
                        GameTime.Update();
                        World.UpdateWorlds(GameTime.Ticks);
                    }

                    // Check spectator stuff
                    GameTime.Update();
                    GameClient.UpdateSpectator(GameTime.Ticks);

                    // check player hero
                    GameTime.Update();
                    NPC.UpdateHero(GameTime.Ticks);
                }

                // update guc sounds
                GameTime.Update();
                SoundHandler.Update3DSounds();

                spikeWatch.Stop();
                if (spikeTimer.IsReady)
                {
                    spikeLongest = 0;
                }
                if (spikeLongest < spikeWatch.Elapsed.Ticks)
                {
                    spikeLongest = spikeWatch.Elapsed.Ticks;
                }

                if (fpsWatch.IsRunning)
                {
                    long diff;
                    if ((diff = 8 * TimeSpan.TicksPerMillisecond - fpsWatch.Elapsed.Ticks) > 0)
                    {
                        Thread.Sleep((int)(diff / TimeSpan.TicksPerMillisecond));
                    }
                }
                lastElapsed = fpsWatch.Elapsed.Ticks;
                fpsWatch.Restart();
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Example #25
0
 // Update is called once per frame
 void Update()
 {
     gameTime.Update(Time.deltaTime);
 }
Example #26
0
 static void UpdateSubsystems()
 {
     GameTime.Update();
     Input.Update();
     Graphics.Update();
 }
 public void Update()
 {
     gameTime.Update();
 }