Browse Source

Send normal logs to Unity again, but for the Update loop collect all logs and flush the contents only once per frame

console
Nico de Poel 5 years ago
parent
commit
1a5ff9b64b
  1. 2
      Assets/Scripts/Modules/SystemModule.cs
  2. 35
      Assets/Scripts/UniQuake.cs

2
Assets/Scripts/Modules/SystemModule.cs

@ -30,7 +30,7 @@ public partial class SystemModule
private void Print(string message) 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) private void Error(string message)

35
Assets/Scripts/UniQuake.cs

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using UnityEngine; using UnityEngine;
public class UniQuake: MonoBehaviour public class UniQuake: MonoBehaviour
@ -35,8 +36,12 @@ public class UniQuake: MonoBehaviour
/// </summary> /// </summary>
public double CurrentTime => Time.timeAsDouble - startTime; public double CurrentTime => Time.timeAsDouble - startTime;
private Action<string> logHandler;
void Start() void Start()
{ {
logHandler = PrintLog; // Send each log statement to Unity immediately during startup
systemModule = new SystemModule(this); systemModule = new SystemModule(this);
renderModule = new RenderModule(this); renderModule = new RenderModule(this);
@ -109,6 +114,8 @@ public class UniQuake: MonoBehaviour
if (!initialized) if (!initialized)
return; return;
logHandler = CollectLog; // Collect and dump logs to Unity once per frame
try try
{ {
UniQuake_Update(Time.deltaTime); UniQuake_Update(Time.deltaTime);
@ -127,6 +134,8 @@ public class UniQuake: MonoBehaviour
Debug.LogException(ex); Debug.LogException(ex);
Shutdown(); Shutdown();
} }
FlushLog();
} }
private void Shutdown() private void Shutdown()
@ -150,6 +159,32 @@ public class UniQuake: MonoBehaviour
FreeLibrary(); 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)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void UniQuake_InitFunc(IntPtr parms, IntPtr sysCalls, IntPtr glCalls); private delegate void UniQuake_InitFunc(IntPtr parms, IntPtr sysCalls, IntPtr glCalls);
private UniQuake_InitFunc UniQuake_Init; private UniQuake_InitFunc UniQuake_Init;

Loading…
Cancel
Save