using System; using System.Windows.Forms; using Azimuth; using Blacklight.Core; using Blacklight.Core.Cameras; namespace Konis.Testbed { public partial class Testbed : Form { private readonly WinFormsClipboard clipboard = new WinFormsClipboard(); private readonly TestbedWorld world; private readonly WinFormsFramePump pump; public Testbed() { InitializeComponent(); world = new TestbedWorld( viewport.DrawableSurface, viewport.Camera, viewport.Controller, viewport.InputRouter, pointerSource: viewport.Input, pointerLock: viewport.Input, textSource: viewport.Input, clipboard: clipboard, verticalSync: GraphicsAdapterManager.Singleton.CurrentModule.VerticalSync, random: new Rand((ulong)DateTime.UtcNow.Ticks)); pump = new WinFormsFramePump(this, elapsed => world.Tick(elapsed.ToTimeSpan())); } /// /// Gets or sets whether the form closes itself once it has drawn a frame. /// public bool ExitAfterFirstFrame { get => pump.CloseAfterFirstFrame; set => pump.CloseAfterFirstFrame = value; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); // A run that closes after one frame spawns every effect first, so that frame draws particles. if (ExitAfterFirstFrame) { world.SpawnEveryEffect(); } pump.Start(); } protected override void OnFormClosing(FormClosingEventArgs e) { pump.Stop(); world.Unbind(); clipboard.Dispose(); base.OnFormClosing(e); } } }