Exemplo n.º 1
0
 public static void RunGameMaster(GameMaster.GameMaster gameMaster, int gameMasterSleepMs)
 {
     for (int i = 0; i < 400; i++)
     {
         gameMaster.Update(gameMasterSleepMs / 1000.0);
         Thread.Sleep(gameMasterSleepMs);
     }
 }
Exemplo n.º 2
0
        private void RunGameMasterThread()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            double frameTimer = 0;
            int    frameCount = 0;

            shouldCloseMutex.WaitOne();
            var close = shouldClose;

            shouldCloseMutex.ReleaseMutex();

            while (close == false)
            {
                stopwatch.Stop();
                var elapsed = (double)stopwatch.ElapsedMilliseconds / 1000.0;
                stopwatch.Reset();
                stopwatch.Start();

                frameTimer += elapsed;
                frameCount++;

                if (frameTimer >= 1)
                {
                    FPS        = frameCount;
                    frameTimer = 0;
                    frameCount = 0;
                }

                gameMasterMutex.WaitOne();
                gameMaster.Update(elapsed);
                var state = gameMaster.state;
                gameMasterMutex.ReleaseMutex();

                if (state == GameMaster.GameMasterState.CriticalError)
                {
                    OnCriticalError();
                }

                Thread.Sleep(3);

                shouldCloseMutex.WaitOne();
                close = shouldClose;
                shouldCloseMutex.ReleaseMutex();
            }

            gameMaster.OnDestroy();
        }