diff --git a/Assets/Scripts/Modules/SystemModule.cs b/Assets/Scripts/Modules/SystemModule.cs index 4b24010..d5d71c4 100644 --- a/Assets/Scripts/Modules/SystemModule.cs +++ b/Assets/Scripts/Modules/SystemModule.cs @@ -30,7 +30,7 @@ public partial class SystemModule private void Print(string message) { - // Debug.Log(message); // TODO: collect logs per frame and print after each Update loop + uq.AddLog(message); } private void Error(string message) diff --git a/Assets/Scripts/UniQuake.cs b/Assets/Scripts/UniQuake.cs index b617ebb..869d02a 100644 --- a/Assets/Scripts/UniQuake.cs +++ b/Assets/Scripts/UniQuake.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; +using System.Text; using UnityEngine; public class UniQuake: MonoBehaviour @@ -35,8 +36,12 @@ public class UniQuake: MonoBehaviour /// public double CurrentTime => Time.timeAsDouble - startTime; + private Action logHandler; + void Start() { + logHandler = PrintLog; // Send each log statement to Unity immediately during startup + systemModule = new SystemModule(this); renderModule = new RenderModule(this); @@ -109,6 +114,8 @@ public class UniQuake: MonoBehaviour if (!initialized) return; + logHandler = CollectLog; // Collect and dump logs to Unity once per frame + try { UniQuake_Update(Time.deltaTime); @@ -127,6 +134,8 @@ public class UniQuake: MonoBehaviour Debug.LogException(ex); Shutdown(); } + + FlushLog(); } private void Shutdown() @@ -150,6 +159,32 @@ public class UniQuake: MonoBehaviour FreeLibrary(); } + public void AddLog(string log) + { + logHandler?.Invoke(log); + } + + private void PrintLog(string log) + { + Debug.Log(log); + } + + private StringBuilder logBuffer = new StringBuilder(); + + private void CollectLog(string log) + { + logBuffer.Append(log); + } + + private void FlushLog() + { + if (logBuffer.Length > 0) + { + Debug.Log(logBuffer.ToString()); + logBuffer.Clear(); + } + } + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void UniQuake_InitFunc(IntPtr parms, IntPtr sysCalls, IntPtr glCalls); private UniQuake_InitFunc UniQuake_Init;