From 540845cff3c374e1f9de80b349e10e377370449b Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 14 Mar 2023 23:56:10 +0900 Subject: [PATCH] Preparing for integration as ViewSystem --- .../Draw/NavMeshRenderer.cs | 8 ++--- src/DotRecast.Recast.Demo/Program.cs | 10 ++++++ src/DotRecast.Recast.Demo/RecastDemo.cs | 29 +++++++---------- src/DotRecast.Recast.Demo/Sample.cs | 10 +++--- .../{SettingsUI.cs => RcSettingsView.cs} | 31 ++++++------------- src/DotRecast.Recast.Demo/Tools/ToolsUI.cs | 4 +-- .../UI/{NuklearUIModule.cs => IRcView.cs} | 7 ++--- src/DotRecast.Recast.Demo/UI/NuklearGL.cs | 4 +-- .../UI/{NuklearUI.cs => RcViewSystem.cs} | 17 +++++----- src/DotRecast.Recast.Demo/imgui.ini | 5 --- 10 files changed, 54 insertions(+), 71 deletions(-) create mode 100644 src/DotRecast.Recast.Demo/Program.cs rename src/DotRecast.Recast.Demo/Settings/{SettingsUI.cs => RcSettingsView.cs} (95%) rename src/DotRecast.Recast.Demo/UI/{NuklearUIModule.cs => IRcView.cs} (90%) rename src/DotRecast.Recast.Demo/UI/{NuklearUI.cs => RcViewSystem.cs} (92%) delete mode 100644 src/DotRecast.Recast.Demo/imgui.ini diff --git a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs index c7633c3..aeacd5d 100644 --- a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs +++ b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs @@ -49,13 +49,13 @@ public class NavMeshRenderer { DemoInputGeomProvider geom = sample.getInputGeom(); IList rcBuilderResults = sample.getRecastResults(); NavMesh navMesh = sample.getNavMesh(); - SettingsUI settingsUI = sample.getSettingsUI(); + RcSettingsView rcSettingsView = sample.getSettingsUI(); debugDraw.fog(true); debugDraw.depthMask(true); - DrawMode drawMode = settingsUI.getDrawMode(); + DrawMode drawMode = rcSettingsView.getDrawMode(); - float texScale = 1.0f / (settingsUI.getCellSize() * 10.0f); - float m_agentMaxSlope = settingsUI.getAgentMaxSlope(); + float texScale = 1.0f / (rcSettingsView.getCellSize() * 10.0f); + float m_agentMaxSlope = rcSettingsView.getAgentMaxSlope(); if (drawMode != DrawMode.DRAWMODE_NAVMESH_TRANS) { // Draw mesh diff --git a/src/DotRecast.Recast.Demo/Program.cs b/src/DotRecast.Recast.Demo/Program.cs new file mode 100644 index 0000000..c0a24a0 --- /dev/null +++ b/src/DotRecast.Recast.Demo/Program.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.Demo; + +public static class Program +{ + public static void Main(string[] args) + { + var demo = new RecastDemo(); + demo.start(); + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 4eff934..c776f7d 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -51,7 +51,7 @@ namespace DotRecast.Recast.Demo; public class RecastDemo : MouseListener { private readonly ILogger logger = Log.ForContext(); - private NuklearUI nuklearUI; + private RcViewSystem _viewSys; private IWindow window; private IInputContext _input; private ImGuiController _imgui; @@ -95,7 +95,7 @@ public class RecastDemo : MouseListener private bool markerPositionSet; private readonly float[] markerPosition = new float[3]; private ToolsUI toolsUI; - private SettingsUI settingsUI; + private RcSettingsView _rcSettingsView; private long prevFrameTime; public RecastDemo() @@ -378,7 +378,7 @@ public class RecastDemo : MouseListener window.CreateInput(); - settingsUI = new SettingsUI(); + _rcSettingsView = new RcSettingsView(); toolsUI = new ToolsUI( new TestNavmeshTool(), new OffMeshConnectionTool(), @@ -387,7 +387,7 @@ public class RecastDemo : MouseListener new JumpLinkBuilderTool(), new DynamicUpdateTool()); - nuklearUI = new NuklearUI(window, _input, settingsUI, toolsUI); + _viewSys = new RcViewSystem(window, _input, _rcSettingsView, toolsUI); DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj")); //sample = new Sample(geom, ImmutableArray.Empty, null, settingsUI, dd); @@ -410,9 +410,9 @@ public class RecastDemo : MouseListener // settingsUI.setMaxPolys(tileNavMeshBuilder.getMaxPolysPerTile(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize())); // } - nuklearUI.inputBegin(); + _viewSys.inputBegin(); window.DoEvents(); - nuklearUI.inputEnd(window); + _viewSys.inputEnd(window); long time = Stopwatch.GetTimestamp() / 1000; //float dt = (time - prevFrameTime) / 1000000.0f; @@ -446,7 +446,7 @@ public class RecastDemo : MouseListener //mouseOverMenu = nuklearUI.layout(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); - if (settingsUI.isMeshInputTrigerred()) + if (_rcSettingsView.isMeshInputTrigerred()) { // aFilterPatterns.put(stack.UTF8("*.obj")); // aFilterPatterns.flip(); @@ -460,7 +460,7 @@ public class RecastDemo : MouseListener // } // } } - else if (settingsUI.isNavMeshInputTrigerred()) + else if (_rcSettingsView.isNavMeshInputTrigerred()) { // try (MemoryStack stack = stackPush()) { // PointerBuffer aFilterPatterns = stack.mallocPointer(4); @@ -664,9 +664,8 @@ public class RecastDemo : MouseListener private unsafe void OnWindowOnRender(double dt) { _gl.Clear(ClearBufferMask.ColorBufferBit); - // Render GUI - //mouseOverMenu = nuklearUI.layout(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); - //nuklearUI.render(); + + mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); ImGui.Button("hello"); ImGui.Button("world"); @@ -674,13 +673,7 @@ public class RecastDemo : MouseListener } - public static void Main(string[] args) - { - var demo = new RecastDemo(); - demo.start(); - } - - private static void ErrorCallback(Silk.NET.GLFW.ErrorCode code, string message) + private void ErrorCallback(Silk.NET.GLFW.ErrorCode code, string message) { Console.WriteLine($"GLFW error [{code}]: {message}"); } diff --git a/src/DotRecast.Recast.Demo/Sample.cs b/src/DotRecast.Recast.Demo/Sample.cs index c9e95bc..2b62280 100644 --- a/src/DotRecast.Recast.Demo/Sample.cs +++ b/src/DotRecast.Recast.Demo/Sample.cs @@ -30,16 +30,16 @@ public class Sample { private DemoInputGeomProvider inputGeom; private NavMesh navMesh; private NavMeshQuery navMeshQuery; - private readonly SettingsUI settingsUI; + private readonly RcSettingsView _rcSettingsView; private IList recastResults; private bool changed; public Sample(DemoInputGeomProvider inputGeom, IList recastResults, NavMesh navMesh, - SettingsUI settingsUI, RecastDebugDraw debugDraw) { + RcSettingsView rcSettingsView, RecastDebugDraw debugDraw) { this.inputGeom = inputGeom; this.recastResults = recastResults; this.navMesh = navMesh; - this.settingsUI = settingsUI; + this._rcSettingsView = rcSettingsView; setQuery(navMesh); changed = true; } @@ -60,8 +60,8 @@ public class Sample { return navMesh; } - public SettingsUI getSettingsUI() { - return settingsUI; + public RcSettingsView getSettingsUI() { + return _rcSettingsView; } public NavMeshQuery getNavMeshQuery() { diff --git a/src/DotRecast.Recast.Demo/Settings/SettingsUI.cs b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs similarity index 95% rename from src/DotRecast.Recast.Demo/Settings/SettingsUI.cs rename to src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs index 0c1f054..ddf9ae6 100644 --- a/src/DotRecast.Recast.Demo/Settings/SettingsUI.cs +++ b/src/DotRecast.Recast.Demo/Settings/RcSettingsView.cs @@ -16,16 +16,13 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ -using System; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.UI; -using ImGuiNET; -using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.Settings; -public class SettingsUI : NuklearUIModule { +public class RcSettingsView : IRcView { private readonly float[] cellSize = new[] { 0.3f }; private readonly float[] cellHeight = new[] { 0.2f }; @@ -68,7 +65,7 @@ public class SettingsUI : NuklearUIModule { private bool meshInputTrigerred; private bool navMeshInputTrigerred; - public bool layout(IWindow i, int x, int y, int width, int height, int mouseX, int mouseY) { + public bool render(IWindow i, int x, int y, int width, int height, int mouseX, int mouseY) { bool mouseInside = false; // nk_rgb(255, 255, 255, white); // nk_rgba(0, 0, 0, 192, background); @@ -212,43 +209,35 @@ public class SettingsUI : NuklearUIModule { } public float getCellSize() { - //return cellSize[0]; - return 0; + return cellSize[0]; } public float getCellHeight() { - //return cellHeight[0]; - return 0; + return cellHeight[0]; } public float getAgentHeight() { - //return agentHeight[0]; - return 0; + return agentHeight[0]; } public float getAgentRadius() { - //return agentRadius[0]; - return 0; + return agentRadius[0]; } public float getAgentMaxClimb() { - //return agentMaxClimb[0]; - return 0; + return agentMaxClimb[0]; } public float getAgentMaxSlope() { - //return agentMaxSlope[0]; - return 0; + return agentMaxSlope[0]; } public int getMinRegionSize() { - //return minRegionSize[0]; - return 0; + return minRegionSize[0]; } public int getMergedRegionSize() { - //return mergedRegionSize[0]; - return 0; + return mergedRegionSize[0]; } public PartitionType getPartitioning() { diff --git a/src/DotRecast.Recast.Demo/Tools/ToolsUI.cs b/src/DotRecast.Recast.Demo/Tools/ToolsUI.cs index 377d7b8..0a7b082 100644 --- a/src/DotRecast.Recast.Demo/Tools/ToolsUI.cs +++ b/src/DotRecast.Recast.Demo/Tools/ToolsUI.cs @@ -23,7 +23,7 @@ using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.Tools; -public class ToolsUI : NuklearUIModule { +public class ToolsUI : IRcView { //private readonly NkColor white = NkColor.create(); private Tool currentTool; @@ -34,7 +34,7 @@ public class ToolsUI : NuklearUIModule { this.tools = tools; } - public bool layout(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) { + public bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) { bool mouseInside = false; // nk_rgb(255, 255, 255, white); // try (MemoryStack stack = stackPush()) { diff --git a/src/DotRecast.Recast.Demo/UI/NuklearUIModule.cs b/src/DotRecast.Recast.Demo/UI/IRcView.cs similarity index 90% rename from src/DotRecast.Recast.Demo/UI/NuklearUIModule.cs rename to src/DotRecast.Recast.Demo/UI/IRcView.cs index 854c5f9..bca10b7 100644 --- a/src/DotRecast.Recast.Demo/UI/NuklearUIModule.cs +++ b/src/DotRecast.Recast.Demo/UI/IRcView.cs @@ -20,10 +20,7 @@ using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.UI; +public interface IRcView { - -public interface NuklearUIModule { - - bool layout(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY); - + bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY); } diff --git a/src/DotRecast.Recast.Demo/UI/NuklearGL.cs b/src/DotRecast.Recast.Demo/UI/NuklearGL.cs index d5cdd22..e0eb5d1 100644 --- a/src/DotRecast.Recast.Demo/UI/NuklearGL.cs +++ b/src/DotRecast.Recast.Demo/UI/NuklearGL.cs @@ -33,7 +33,7 @@ public class NuklearGL { private static readonly int FONT_BITMAP_H = 1024; private static readonly int FONT_HEIGHT = 15; - private readonly NuklearUI context; + private readonly RcViewSystem context; // private readonly NkDrawNullTexture null_texture = NkDrawNullTexture.create(); // private readonly NkBuffer cmds = NkBuffer.create(); // private readonly NkUserFont default_font; @@ -45,7 +45,7 @@ public class NuklearGL { private readonly int vao; //private readonly Buffer vertexLayout; - public NuklearGL(NuklearUI context) { + public NuklearGL(RcViewSystem context) { this.context = context; // nk_buffer_init(cmds, context.allocator, BUFFER_INITIAL_SIZE); // vertexLayout = NkDrawVertexLayoutElement.create(4)// diff --git a/src/DotRecast.Recast.Demo/UI/NuklearUI.cs b/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs similarity index 92% rename from src/DotRecast.Recast.Demo/UI/NuklearUI.cs rename to src/DotRecast.Recast.Demo/UI/RcViewSystem.cs index 6627804..91a4d27 100644 --- a/src/DotRecast.Recast.Demo/UI/NuklearUI.cs +++ b/src/DotRecast.Recast.Demo/UI/RcViewSystem.cs @@ -18,23 +18,22 @@ freely, subject to the following restrictions: using Silk.NET.Input; using Silk.NET.OpenGL; -using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.UI; -public class NuklearUI { +public class RcViewSystem { // readonly NkAllocator allocator; private readonly IWindow _window; private readonly GL _gl; // readonly NkColor background; // readonly NkColor white; - private readonly NuklearUIModule[] _modules; + private readonly IRcView[] _views; private readonly NuklearGL glContext; private bool mouseOverUI; - public NuklearUI(IWindow window, IInputContext input, params NuklearUIModule[] modules) + public RcViewSystem(IWindow window, IInputContext input, params IRcView[] views) { var mouse = new Mouse(input); _window = window; @@ -58,7 +57,7 @@ public class NuklearUI { // setupClipboard(window); // glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint)); // glContext = new NuklearGL(this); - _modules = modules; + _views = views; } private void setupMouse(Mouse mouse) { @@ -139,11 +138,11 @@ public class NuklearUI { // } // nk_input_end(ctx); } - - public bool layout(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) { + + public bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) { mouseOverUI = false; - foreach (NuklearUIModule m in _modules) { - mouseOverUI = m.layout(ctx, x, y, width, height, mouseX, mouseY) | mouseOverUI; + foreach (IRcView m in _views) { + mouseOverUI = m.render(ctx, x, y, width, height, mouseX, mouseY) | mouseOverUI; } return mouseOverUI; } diff --git a/src/DotRecast.Recast.Demo/imgui.ini b/src/DotRecast.Recast.Demo/imgui.ini deleted file mode 100644 index 7e8c982..0000000 --- a/src/DotRecast.Recast.Demo/imgui.ini +++ /dev/null @@ -1,5 +0,0 @@ -[Window][Debug##Default] -Pos=280,129 -Size=400,400 -Collapsed=0 -