/// <summary> /// LÖVE engine entrance function /// </summary> /// <param name="scene">The way to run LÖVE engine</param> /// <param name="bootConfig">LÖVE engine boot config</param> static public void Run(Scene scene = null, BootConfig bootConfig = null) { // config if (bootConfig == null) { bootConfig = new BootConfig(); } try { Init(bootConfig); Loop(bootConfig, scene != null ? scene : new Love2dNoGame()); } catch (Exception e) { Log.Error("----------------------------------------------------"); Log.Error("[Error]:"); Exception itException = e; while (itException != null) { Log.Error(itException.Message); itException = itException.InnerException; } Log.Error("[Stack trace]:"); Log.Error(e.StackTrace); Log.Error("----------------------------------------------------"); LoopErrorScene(scene, e); } }
static void Loop(BootConfig bootConfig, Scene scene) { scene.InvokeLoad(); Timer.Step(); // fix large delta on first frame while (!Boot.QuitFlag) { SystemStep(scene); scene.InvokeUpdate(Timer.GetDelta()); if (Graphics.IsActive()) { var c = Graphics.GetBackgroundColor(); Graphics.Clear(c.r, c.g, c.b, c.a); Graphics.Origin(); scene.InvokeDraw(); Graphics.Present(); } if (Timer.IsLimitMaxFPS()) { Timer.SleepByMaxFPS(); } else { Timer.Sleep(0.001f); // max 1000 fps. } } }
static public void Init(BootConfig bootConfig = null) { if (InitFlag == false) { InitFlag = true; // config if (bootConfig == null) { bootConfig = new BootConfig(); } // init to load native library InitNativeLibrary(); if (bootConfig.DefaultRandomSeed.HasValue) { Mathf.Init(bootConfig.DefaultRandomSeed.Value); } else { Mathf.Init(); } FileSystem.Init(""); Timer.Init(); Event.Init(); Keyboard.Init(); Joystick.Init(); Mouse.Init(); Touch.Init(); Sound.Init(); Audio.Init(); Font.Init(); Image.Init(); Video.Init(); Window.Init(); Graphics.Init(); Special.Init(); if (bootConfig.WindowTitle != null) { Window.SetTitle(bootConfig.WindowTitle); } WindowSettings settings = new WindowSettings(); settings.FullscreenType = bootConfig.WindowFullscreenType; settings.Fullscreen = bootConfig.WindowFullscreen; settings.Vsync = bootConfig.WindowVsync; settings.MSAA = bootConfig.WindowMSAA; settings.Resizable = bootConfig.WindowResizable; settings.MinWidth = bootConfig.WindowMinWidth; settings.MinHeight = bootConfig.WindowMinHeight; settings.Borderless = bootConfig.WindowBorderless; settings.Centered = bootConfig.WindowCentered; settings.Display = bootConfig.WindowDisplay; settings.HighDpi = bootConfig.WindowHighdpi; if (bootConfig.WindowX.HasValue) { settings.X = bootConfig.WindowX.Value; } if (bootConfig.WindowY.HasValue) { settings.Y = bootConfig.WindowY.Value; } Window.SetMode(bootConfig.WindowWidth, bootConfig.WindowHeight, settings); FileSystem.SetSource(Environment.CurrentDirectory); RecordWarningInfo = bootConfig.WarningInfo; Console.WriteLine($"FileSystem set source with path : {FileSystem.GetSource()}"); } }
static public void Init(BootConfig bootConfig = null) { if (InitFlag == false) { InitFlag = true; // output the version var versionInfo = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); Log.Info($"[Version: {versionInfo}]"); // config if (bootConfig == null) { bootConfig = new BootConfig(); } // init to load native library try { InitNativeLibrary(); Love2dDll.LoadInit(); } catch (Exception e) { Log.Error(e); throw e; } if (bootConfig.DefaultRandomSeed.HasValue) { Mathf.Init(bootConfig.DefaultRandomSeed.Value); } else { Mathf.Init(); } FileSystem.Init(""); Timer.Init(); Event.Init(); Keyboard.Init(); Joystick.Init(); Mouse.Init(); Touch.Init(); Sound.Init(); Audio.Init(); Font.Init(); Image.Init(); Video.Init(); Window.Init(); Graphics.Init(); Special.Init(); if (bootConfig.WindowTitle != null) { Window.SetTitle(bootConfig.WindowTitle); } WindowSettings settings = new WindowSettings(); settings.FullscreenType = bootConfig.WindowFullscreenType; settings.Fullscreen = bootConfig.WindowFullscreen; settings.Vsync = bootConfig.WindowVsync; settings.MSAA = bootConfig.WindowMSAA; settings.Resizable = bootConfig.WindowResizable; settings.MinWidth = bootConfig.WindowMinWidth; settings.MinHeight = bootConfig.WindowMinHeight; settings.Borderless = bootConfig.WindowBorderless; settings.Centered = bootConfig.WindowCentered; settings.Display = bootConfig.WindowDisplay; settings.HighDpi = bootConfig.WindowHighdpi; if (bootConfig.WindowX.HasValue) { settings.X = bootConfig.WindowX.Value; } if (bootConfig.WindowY.HasValue) { settings.Y = bootConfig.WindowY.Value; } Window.SetMode(bootConfig.WindowWidth, bootConfig.WindowHeight, settings); FileSystem.SetSource(Environment.CurrentDirectory); Log.Info($"FileSystem current work directory : {FileSystem.GetSource()}"); } }