private int?UpdateInLoop() { if (_first) { _first = false; OnResize(this, EventArgs.Empty); } int?timeSteps = 0; if (!Window.window.Exists) { return(null); } if (Window.window.WindowState == OpenTK.WindowState.Minimized) { return(timeSteps); } Input.Start(); if (DemoHarness != null) { //We'll let the delegate's logic handle the variable time steps. timeSteps = DemoHarness.Update(1 / 60f); // TODO //At the moment, rendering just follows sequentially. Later on we might want to distinguish it a bit more with fixed time stepping or something. Maybe. DemoHarness.Render(Renderer); } Renderer.Render(Camera); Surface.Present(); Input.End(); return(timeSteps); }
public void Run(DemoHarness harness) { DemoHarness = harness; if (!true) // TODO: Controls like F1 don't work in this case { Task.Run(Loop); Window.Run(() => { }); } else { Window.Run(Update); } }
private void OnResize(object sender, EventArgs args) { //Note that minimizing or resizing the window to invalid sizes don't result in actual resize attempts. Zero width rendering surfaces aren't allowed. if (Window.window.Width <= 0 || Window.window.Height <= 0) { return; } var resolution = new Int2(Window.window.Width, Window.window.Height); //We just don't support true fullscreen in the demos. Would be pretty pointless. Renderer.Surface.Resize(resolution, false); Camera.AspectRatio = resolution.X / (float)resolution.Y; DemoHarness?.OnResize(resolution); }
public void CheckForDemoSwap(DemoHarness harness) { if (harness.input.WasPushed(harness.controls.ChangeDemo.Key)) { TrackingInput = !TrackingInput; TargetDemoIndex = -1; } if (TrackingInput) { for (int i = 0; i < harness.input.TypedCharacters.Count; ++i) { var character = harness.input.TypedCharacters[i]; if (character == '\b') { //Backspace! if (TargetDemoIndex >= 10) { TargetDemoIndex /= 10; } else { TargetDemoIndex = -1; } } else { if (TargetDemoIndex < harness.demoSet.Count) { var digit = character - '0'; if (digit >= 0 && digit <= 9) { TargetDemoIndex = Math.Max(0, TargetDemoIndex) * 10 + digit; } } } } if (harness.input.WasPushed(OpenTK.Input.Key.Enter)) { //Done entering the index. Swap the demo if needed. TrackingInput = false; harness.TryChangeToDemo(TargetDemoIndex); } } }