/// <summary> /// Start running the engine loop. Can be blocking depending on the host. /// </summary> public static void Run() { // If the debugger is attached, don't wrap in a try-catch so that exceptions can be traced easier. if (System.Diagnostics.Debugger.IsAttached) { InternalRun(); return; } // If no debugger is attached, wrap in a try-catch so that exception logs are generated. try { InternalRun(); } catch (Exception ex) { File.WriteAllText($"Logs{Path.DirectorySeparatorChar}FatalCrash_{DateTime.Now.ToFileTime()}", ex.ToString()); Debugger.Log(MessageType.Error, MessageSource.Engine, $"Emotion engine has encountered a crash.\n{ex}"); // Flush logs. while (Debugger.LogInProgress()) { Task.Delay(1).Wait(); } // Close. Environment.Exit(1); } }
/// <summary> /// Prepare the Emotion engine. /// </summary> /// <param name="config">A function to apply initial settings.</param> public static void Setup(Action <Settings> config = null) { // Check if it was already setup. if (IsSetup) { throw new Exception("Context is already setup."); } IsSetup = true; // Initialize debugger so we have access to logging afterward. Debugger.Initialize(); Debugger.Log(MessageType.Info, MessageSource.Engine, $"Starting Emotion v{Meta.Version}"); // If the debugger is attached, don't wrap in a try-catch so that exceptions can be traced easier. if (Debugger.DebugMode) { InternalSetup(config); return; } // If no debugger is attached, wrap in a try-catch so that exception logs are generated. try { InternalSetup(config); } catch (Exception ex) { File.WriteAllText($"Logs{Path.DirectorySeparatorChar}InitCrash_{DateTime.Now.ToFileTime()}", ex.ToString()); Debugger.Log(MessageType.Error, MessageSource.Engine, $"Emotion engine was unable to initialize.\n{ex}"); // Flush logs. while (Debugger.LogInProgress()) { Task.Delay(1).Wait(); } // Close. Environment.Exit(1); } }