public void Start() { Time timePerUpdate = Time.FromSeconds(1.0f / (float)TPS); uint ticks = 0; Clock timer = new Clock(); // Timing variables Time lastTime = Time.Zero; // Set to time of last frame Time lag = Time.Zero; // For FixedUpdate() Time time = Time.Zero; // Time of current frame Time deltaTime = Time.Zero; // Delta time of frame // Initialize the current state at least once currentState.Init(window); while (window.IsOpen && currentState != null) { // We shouldn't handle draw queue clearing, the StateBase should. // drawBuffer.Clear(); if (currentState.GetID() != newState.GetID()) { SwapState(); } time = timer.ElapsedTime; deltaTime = time - lastTime; lastTime = time; lag += deltaTime; CheckCommand(); // Dispatch window events window.DispatchEvents(); if (currentState.WantsExtendedUpdate()) { currentState.ExtendedUpdate(deltaTime, this); } // Update for set amount of time while (lag >= timePerUpdate) { ticks++; lag -= timePerUpdate; Update(deltaTime); } // TODO: Add comment that makes sense FixedUpdate(deltaTime); CheckEvents(deltaTime); window.Clear(clearColor); staticDrawBuffer = currentState.Render(); // Draw our framebuffer staticDrawBuffer.Draw(window); LateUpdate(deltaTime); // Display the screen window.Display(); } }