示例#1
0
文件: Game.cs 项目: zhuowp/ge
        public void NewSceneLoaded()
        {
            var systemEnumerator = SystemRegistry.GetSystemsEnumerator();

            while (systemEnumerator.MoveNext())
            {
                var kvp = systemEnumerator.Current;
                kvp.Value.OnNewSceneLoaded();
            }

            ResetDeltaTime();
        }
示例#2
0
文件: Game.cs 项目: zhuowp/ge
        private void RunMainLoopCore()
        {
            _running = true;

            _sw = Stopwatch.StartNew();
            while (_running)
            {
                double desiredFrameTime  = 1000.0 / DesiredFramerate;
                long   currentFrameTicks = _sw.ElapsedTicks;
                double deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0 / Stopwatch.Frequency);

                while (LimitFrameRate && deltaMilliseconds < desiredFrameTime)
                {
                    Thread.Sleep(0);
                    currentFrameTicks = _sw.ElapsedTicks;
                    deltaMilliseconds = (currentFrameTicks - _previousFrameTicks) * (1000.0 / Stopwatch.Frequency);
                }

                _previousFrameTicks = currentFrameTicks;

                FlushDeletedObjects();

                var systemEnumerator = SystemRegistry.GetSystemsEnumerator();
                while (systemEnumerator.MoveNext())
                {
                    var        kvp          = systemEnumerator.Current;
                    GameSystem system       = kvp.Value;
                    float      deltaSeconds = (float)deltaMilliseconds / 1000.0f;
                    system.Update(deltaSeconds * _timeSystem.TimeScale);
                }

                RunEndOfFrameActions();
            }

            var cleanupEnumerator = SystemRegistry.GetSystemsEnumerator();

            while (cleanupEnumerator.MoveNext())
            {
                var        kvp    = cleanupEnumerator.Current;
                GameSystem system = kvp.Value;
                if (system is IDisposable)
                {
                    ((IDisposable)system).Dispose();
                }
            }
        }