using System; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using Azimuth; using Blacklight.Core; using Blacklight.Core.Cameras; using Blacklight.WebGL2; using Foundations; using Glass.WebGL2; // [JSImport]/[JSExport] require the assembly to be marked browser-targeted, or they won't compile. [assembly: SupportedOSPlatform("browser")] namespace Konis.Testbed { public static class Program { // A trimmed build can silently lose the static defs that reflection reads, and then it reports zero of them // rather than failing. Checking at startup makes that fail at once. private static void CheckTrimmingKeptTheDefs() { int defs = Defs.ValidateStatics(typeof(TestbedSprites)); if (defs == 0) { throw new InvalidOperationException("The trimmer removed the testbed's static defs."); } Console.WriteLine($"Konis defs validated: {defs}"); } private static async Task Main() { if (!BrowserStartup.TryBegin(out _)) { return; } CheckTrimmingKeptTheDefs(); await GL.EnsureLoadedAsync(); WindowHandle window = WebGL2Backend.CreateWindowHandle(); var inputRouter = new InputRouter(); var input = new WebGL2Input(WebGL2Backend.DefaultCanvasElementId, inputRouter); var world = new TestbedWorld( window, new MicroscopeCamera(window), new MicroscopeController { Handle = window }, inputRouter, pointerSource: input, pointerLock: input, textSource: input, clipboard: new WebGL2Clipboard(), // requestAnimationFrame is paced off the display and the driver decides when. That is what Driver // means, and the browser offers nothing to turn it off with. verticalSync: VerticalSyncMode.Driver, random: new Rand((ulong)DateTime.UtcNow.Ticks)); await new WebGL2FramePump(elapsed => world.Tick(elapsed.ToTimeSpan())).RunForeverAsync(); } } }