메인 루프 구조

This commit is contained in:
2025-12-07 04:38:51 +09:00
parent 3261e85b33
commit 61d43ef61e

View File

@@ -1,4 +1,6 @@
using System.Diagnostics;
namespace WarhoundConsole namespace WarhoundConsole
{ {
public class Program public class Program
@@ -22,15 +24,38 @@ namespace WarhoundConsole
{ {
Singleton.I.Initialize(new()); Singleton.I.Initialize(new());
bool exitRequested = Singleton.I.ExitRequested; var sw = Stopwatch.StartNew();
while (!exitRequested) while (!Singleton.I.ExitRequested)
{
try
{
sw.Restart();
MainLoop();
sw.Stop();
const int targetFrameTimeMs = 10;
if (sw.Elapsed.Milliseconds < targetFrameTimeMs)
{
Thread.Sleep(targetFrameTimeMs - sw.Elapsed.Milliseconds);
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
Shutdown();
}
private static void MainLoop()
{ {
exitRequested = Singleton.I.ExitRequested;
} }
// Graceful shutdown private static void Shutdown()
{
// DO SOMETHING
} }
} }
} }