Exemplo n.º 1
0
 public AWGame(GraphicsDeviceService graphicsDeviceService)
 {
     GraphicsDeviceService = graphicsDeviceService;
     Services = new GameServiceContainer();
     if (graphicsDeviceService != null) Services.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService);
     Components = new AWGameComponentCollection();
     GameTime = new AWGameTime();
     _framerateTimer = new AWTimer(() => GameTime.TotalRealTime, TimeSpan.FromSeconds(1)) { SkipPastIntervals = true };
     _frameDrawTimes = new RunningSequenceTimeSpan(TimeSpan.FromSeconds(1));
     _frameDrawStopwatch = new Stopwatch();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Called when the game has determined that game logic needs to be processed.
 /// </summary>
 public void Update(AWGameTime gameTime)
 {
     GameTime = gameTime;
     foreach (var item in Components)
         if (item.Enabled) item.Update();
     UpdateImpl();
 }
Exemplo n.º 3
0
 private void GameUpdateAndDrawLoopImpl()
 {
     _invoker(() =>
     {
         try
         {
             _game.Initialize();
             _game.BeginRun();
         }
         catch (Exception e)
         {
             _exceptionHandler(e);
         }
     });
     var totalGameTime = TimeSpan.Zero;
     _timer.Start();
     if (Initialized != null)
     {
         Initialized();
         Initialized = null;
     }
     _readyForNextUpdateAndDraw = true;
     while (!_exiting)
     {
         lock (_timer)
         {
             var now = _timer.Elapsed;
             if (!IsTimeForNextUpdate)
             {
                 // It's not yet time for update.
                 Waiter.Instance.Sleep(_nextUpdate - now);
             }
             else if (now > _nextUpdate + TimeSpan.FromSeconds(10))
             {
                 // Update is lagging a lot; skip over the missed updates.
                 _nextUpdate = now;
             }
             else if (_readyForNextUpdateAndDraw)
             {
                 var updateInterval = AssaultWingCore.TargetElapsedTime;
                 var gameTime = new AWGameTime(totalGameTime, updateInterval, now);
                 _nextUpdate += updateInterval;
                 totalGameTime += updateInterval;
                 _readyForNextUpdateAndDraw = false;
                 _updateAndDraw(gameTime);
             }
             else
             {
                 // We didn't make it in time for a frame update. Wait for a while and try again.
                 Waiter.Instance.Sleep(TimeSpan.FromMilliseconds(5));
             }
         }
     }
 }