/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { base.Draw(gameTime); _framesAccum++; var elapsed = gameTime.TotalGameTime.TotalSeconds - _lastFPSUpdateSeconds; if (elapsed >= 1.0) { _lastFPS = _framesAccum.ToString(); _lastFPSUpdateSeconds = gameTime.TotalGameTime.TotalSeconds - (elapsed - 1.0); _framesAccum = 0; } HandmadeCore.RenderVideo(gameState, _drawBuffer, _viewport.Width, _viewport.Height); // Suuuuuper slow // TODO Try drawing pixel-sized colored textures directly? _backBuffer.SetData <UInt32>(_drawBuffer); _spriteBatch.Begin(blendState: BlendState.NonPremultiplied); _spriteBatch.Draw(_backBuffer, position: Vector2.Zero); _spriteBatch.DrawString(_monoFont, _lastFPS, _cfg.DebugPanelPos, Color.White); Vector2 consolePos = new Vector2(0f, _viewport.Height) + _cfg.DebugConsolePos; Color consoleCol = Color.White; for (int i = 0; i < 5; i++) { if (_logStrings.Count == i) { break; } consoleCol.A = (byte)(255 - (byte)(255f / 6 * i)); _spriteBatch.DrawString(_monoFont, _logStrings[i], consolePos, consoleCol); consolePos.Y += -20f; } _spriteBatch.End(); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (isPaused) { return; } base.Update(gameTime); // TODO Do proper input handling (key down/up events) if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } if (Keyboard.GetState().IsKeyDown(Keys.RightControl)) { if (Keyboard.GetState().IsKeyDown(Keys.D1)) { SaveGameStateToSlot(1); } } if (Keyboard.GetState().IsKeyDown(Keys.RightShift)) { if (Keyboard.GetState().IsKeyDown(Keys.D1)) { ReadGameStateFromSlot(1); } } HandmadeCore.Update(gameState, gameTime); while (_audioInstance.PendingBufferCount < DynamicSoundEffectInstance.BufferCount) { HandmadeCore.RenderAudio(gameState, _cfg, _audioBuffer); _audioInstance.SubmitBuffer(_audioBuffer); } }