diff --git a/src/DotRecast.Recast.Demo/Program.cs b/src/DotRecast.Recast.Demo/Program.cs index 6428385..74c5f3b 100644 --- a/src/DotRecast.Recast.Demo/Program.cs +++ b/src/DotRecast.Recast.Demo/Program.cs @@ -33,7 +33,12 @@ public static class Program outputTemplate: format) .CreateLogger(); + Run(); + } + + public static void Run() + { var demo = new RecastDemo(); - demo.start(); + demo.Run(); } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 876df68..8b3c957 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -38,7 +38,6 @@ using DotRecast.Detour.Io; using DotRecast.Recast.Demo.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Geom; - using DotRecast.Recast.Demo.Tools; using DotRecast.Recast.Demo.UI; using static DotRecast.Core.RecastMath; @@ -50,11 +49,12 @@ public class RecastDemo { private static readonly ILogger Logger = Log.ForContext(); - private RcCanvas _canvas; private IWindow window; + private GL _gl; private IInputContext _input; private ImGuiController _imgui; - private GL _gl; + private RecastDemoCanvas _canvas; + private int width = 1000; private int height = 900; @@ -107,11 +107,11 @@ public class RecastDemo private int[] viewport; private bool markerPositionSet; private Vector3f markerPosition = new Vector3f(); - + private ToolsView toolsUI; private RcSettingsView settingsUI; private RcLogView logUI; - + private long prevFrameTime; private RecastDebugDraw dd; @@ -119,7 +119,7 @@ public class RecastDemo { } - public void start() + public void Run() { window = CreateWindow(); window.Run(); @@ -266,7 +266,7 @@ public class RecastDemo options.Title = title; options.Size = new Vector2D(width, height); options.Position = new Vector2D((resolution.X - width) / 2, (resolution.Y - height) / 2); - options.VSync = false; + options.VSync = true; options.ShouldSwapAutomatically = false; options.PreferredDepthBufferBits = 24; window = Window.Create(options); @@ -280,8 +280,8 @@ public class RecastDemo window.Load += OnWindowOnLoad; window.Resize += OnWindowResize; window.FramebufferResize += OnWindowFramebufferSizeChanged; - window.Update += OnWindowOnUpdate; - window.Render += OnWindowOnRender; + window.Update += OnWindowUpdate; + window.Render += OnWindowRender; // // -- move somewhere else: @@ -366,7 +366,7 @@ public class RecastDemo dd.init(camr); _imgui = new ImGuiController(_gl, window, _input); - + settingsUI = new RcSettingsView(); toolsUI = new ToolsView( new TestNavmeshTool(), @@ -378,13 +378,13 @@ public class RecastDemo ); logUI = new RcLogView(); - _canvas = new RcCanvas(window, settingsUI, toolsUI, logUI); - + _canvas = new RecastDemoCanvas(window, settingsUI, toolsUI, logUI); + var vendor = _gl.GetStringS(GLEnum.Vendor); var version = _gl.GetStringS(GLEnum.Version); var renderGl = _gl.GetStringS(GLEnum.Renderer); var glslString = _gl.GetStringS(GLEnum.ShadingLanguageVersion); - + Logger.Debug(vendor); Logger.Debug(version); Logger.Debug(renderGl); @@ -419,7 +419,7 @@ public class RecastDemo } } - private void OnWindowOnUpdate(double dt) + private void OnWindowUpdate(double dt) { /* * try (MemoryStack stack = stackPush()) { int[] w = stack.mallocInt(1); int[] h = @@ -483,9 +483,8 @@ public class RecastDemo var bytes = Loader.ToBytes(settingsUI.GetMeshInputFilePath()); sample.update(loadInputMesh(bytes), null, null); } - - // else if (settingsUI.isNavMeshInputTrigerred()) - // { + else if (settingsUI.isNavMeshInputTrigerred()) + { // try (MemoryStack stack = stackPush()) { // PointerBuffer aFilterPatterns = stack.mallocPointer(4); // aFilterPatterns.put(stack.UTF8("*.bin")); @@ -507,7 +506,7 @@ public class RecastDemo // } // } // } - // } + } if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null) { if (!building) @@ -527,7 +526,7 @@ public class RecastDemo float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError(); int m_tileSize = settingsUI.getTileSize(); long t = FrequencyWatch.Ticks; - + Logger.Information($"build"); Tuple, NavMesh> buildResult; @@ -553,7 +552,7 @@ public class RecastDemo settingsUI.setBuildTime((FrequencyWatch.Ticks - t) / TimeSpan.TicksPerMillisecond); //settingsUI.setBuildTelemetry(buildResult.Item1.Select(x => x.getTelemetry()).ToList()); toolsUI.setSample(sample); - + Logger.Information($"build times"); Logger.Information($"-----------------------------------------"); var telemetries = buildResult.Item1 @@ -561,12 +560,11 @@ public class RecastDemo .SelectMany(x => x.ToList()) .GroupBy(x => x.Item1) .ToImmutableSortedDictionary(x => x.Key, x => x.Sum(y => y.Item2)); - + foreach (var (key, millis) in telemetries) { Logger.Information($"{key}: {millis} ms"); } - } } else @@ -716,7 +714,7 @@ public class RecastDemo _imgui.Update((float)dt); } - private unsafe void OnWindowOnRender(double dt) + private unsafe void OnWindowRender(double dt) { // _gl.ClearColor(Color.CadetBlue); // _gl.Clear(ClearBufferMask.ColorBufferBit); diff --git a/src/DotRecast.Recast.Demo/UI/IRcView.cs b/src/DotRecast.Recast.Demo/UI/IRcView.cs index 94a2f03..c413026 100644 --- a/src/DotRecast.Recast.Demo/UI/IRcView.cs +++ b/src/DotRecast.Recast.Demo/UI/IRcView.cs @@ -20,7 +20,7 @@ namespace DotRecast.Recast.Demo.UI; public interface IRcView { - void Bind(RcCanvas canvas); + void Bind(RecastDemoCanvas canvas); bool IsMouseInside(); void Update(double dt); void Draw(double dt); diff --git a/src/DotRecast.Recast.Demo/UI/RcLogView.cs b/src/DotRecast.Recast.Demo/UI/RcLogView.cs index c5a484f..8bba290 100644 --- a/src/DotRecast.Recast.Demo/UI/RcLogView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcLogView.cs @@ -10,7 +10,7 @@ namespace DotRecast.Recast.Demo.UI; public class RcLogView : IRcView { - private RcCanvas _canvas; + private RecastDemoCanvas _canvas; private bool _mouseInside; private List _lines = new(); @@ -60,7 +60,7 @@ public class RcLogView : IRcView } - public void Bind(RcCanvas canvas) + public void Bind(RecastDemoCanvas canvas) { _canvas = canvas; } diff --git a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs index 96f94b7..58bdbbb 100644 --- a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs @@ -78,9 +78,9 @@ public class RcSettingsView : IRcView private bool _mouseInside; public bool IsMouseInside() => _mouseInside; - private RcCanvas _canvas; + private RecastDemoCanvas _canvas; - public void Bind(RcCanvas canvas) + public void Bind(RecastDemoCanvas canvas) { _canvas = canvas; } diff --git a/src/DotRecast.Recast.Demo/UI/RcCanvas.cs b/src/DotRecast.Recast.Demo/UI/RecastDemoCanvas.cs similarity index 94% rename from src/DotRecast.Recast.Demo/UI/RcCanvas.cs rename to src/DotRecast.Recast.Demo/UI/RecastDemoCanvas.cs index bc97392..29de392 100644 --- a/src/DotRecast.Recast.Demo/UI/RcCanvas.cs +++ b/src/DotRecast.Recast.Demo/UI/RecastDemoCanvas.cs @@ -27,7 +27,7 @@ using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.UI; -public class RcCanvas +public class RecastDemoCanvas { private static readonly ILogger Logger = Log.ForContext(); @@ -38,7 +38,7 @@ public class RcCanvas public Vector2D Size => _window.Size; - public RcCanvas(IWindow window, params IRcView[] views) + public RecastDemoCanvas(IWindow window, params IRcView[] views) { _window = window; _views = views; @@ -112,10 +112,6 @@ public class RcCanvas { view.Draw(dt); _mouseOverUI |= view.IsMouseInside(); - // if (_mouseOverUI) - // { - // Logger.Information("mouse hover!"); - // } } } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/UI/ToolsView.cs b/src/DotRecast.Recast.Demo/UI/ToolsView.cs index b15d1ad..015cbbc 100644 --- a/src/DotRecast.Recast.Demo/UI/ToolsView.cs +++ b/src/DotRecast.Recast.Demo/UI/ToolsView.cs @@ -41,9 +41,9 @@ public class ToolsView : IRcView private bool _mouseInside; public bool IsMouseInside() => _mouseInside; - private RcCanvas _canvas; + private RecastDemoCanvas _canvas; - public void Bind(RcCanvas canvas) + public void Bind(RecastDemoCanvas canvas) { _canvas = canvas; }