From 5e1d4cd02a585ddcfb7fddb6ec2ecd390658d9a5 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sun, 11 Jun 2023 14:58:37 +0900 Subject: [PATCH] prepare tool <- control < view --- src/DotRecast.Recast.Demo/RecastDemo.cs | 96 +++++++++---------- .../Tools/ConvexVolumeTool.cs | 2 +- src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 2 +- .../Tools/DynamicUpdateTool.cs | 2 +- .../Tools/{ITool.cs => IRcTool.cs} | 2 +- .../Tools/JumpLinkBuilderTool.cs | 2 +- .../Tools/OffMeshConnectionTool.cs | 2 +- .../Tools/TestNavmeshTool.cs | 2 +- src/DotRecast.Recast.Demo/UI/IRcView.cs | 2 +- .../UI/{RecastDemoCanvas.cs => RcCanvas.cs} | 4 +- src/DotRecast.Recast.Demo/UI/RcLogView.cs | 4 +- .../UI/RcSettingsView.cs | 6 +- .../UI/{ToolsView.cs => RcToolsetView.cs} | 14 +-- 13 files changed, 69 insertions(+), 71 deletions(-) rename src/DotRecast.Recast.Demo/Tools/{ITool.cs => IRcTool.cs} (98%) rename src/DotRecast.Recast.Demo/UI/{RecastDemoCanvas.cs => RcCanvas.cs} (97%) rename src/DotRecast.Recast.Demo/UI/{ToolsView.cs => RcToolsetView.cs} (91%) diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 787131a..7a897ec 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -54,7 +54,7 @@ public class RecastDemo private GL _gl; private IInputContext _input; private ImGuiController _imgui; - private RecastDemoCanvas _canvas; + private RcCanvas _canvas; private int width = 1000; private int height = 900; @@ -109,9 +109,9 @@ public class RecastDemo private bool markerPositionSet; private RcVec3f markerPosition = new RcVec3f(); - private ToolsView toolsUI; - private RcSettingsView settingsUI; - private RcLogView logUI; + private RcToolsetView toolsetView; + private RcSettingsView settingsView; + private RcLogView logView; private long prevFrameTime; private RecastDebugDraw dd; @@ -300,8 +300,8 @@ public class RecastDemo private DemoInputGeomProvider LoadInputMesh(byte[] stream) { DemoInputGeomProvider geom = DemoObjImporter.Load(stream); - sample = new Sample(geom, ImmutableArray.Empty, null, settingsUI, dd); - toolsUI.SetEnabled(true); + sample = new Sample(geom, ImmutableArray.Empty, null, settingsView, dd); + toolsetView.SetEnabled(true); return geom; } @@ -325,7 +325,7 @@ public class RecastDemo if (mesh != null) { //sample = new Sample(null, ImmutableArray.Empty, mesh, settingsUI, dd); - toolsUI.SetEnabled(true); + toolsetView.SetEnabled(true); } } @@ -368,8 +368,8 @@ public class RecastDemo _imgui = new ImGuiController(_gl, window, _input); - settingsUI = new RcSettingsView(); - toolsUI = new ToolsView( + settingsView = new RcSettingsView(); + toolsetView = new RcToolsetView( new TestNavmeshTool(), new OffMeshConnectionTool(), new ConvexVolumeTool(), @@ -377,9 +377,9 @@ public class RecastDemo new JumpLinkBuilderTool(), new DynamicUpdateTool() ); - logUI = new RcLogView(); + logView = new RcLogView(); - _canvas = new RecastDemoCanvas(window, settingsUI, toolsUI, logUI); + _canvas = new RcCanvas(window, settingsView, toolsetView, logView); var vendor = _gl.GetStringS(GLEnum.Vendor); var version = _gl.GetStringS(GLEnum.Version); @@ -395,7 +395,7 @@ public class RecastDemo DemoInputGeomProvider geom = LoadInputMesh(Loader.ToBytes("nav_test.obj")); - sample = new Sample(geom, ImmutableArray.Empty, null, settingsUI, dd); + sample = new Sample(geom, ImmutableArray.Empty, null, settingsView, dd); } private void UpdateKeyboard(float dt) @@ -432,11 +432,11 @@ public class RecastDemo { RcVec3f bmin = sample.GetInputGeom().GetMeshBoundsMin(); RcVec3f bmax = sample.GetInputGeom().GetMeshBoundsMax(); - Recast.CalcGridSize(bmin, bmax, settingsUI.GetCellSize(), out var gw, out var gh); - settingsUI.SetVoxels(gw, gh); - settingsUI.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); - settingsUI.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); - settingsUI.SetMaxPolys(tileNavMeshBuilder.GetMaxPolysPerTile(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); + Recast.CalcGridSize(bmin, bmax, settingsView.GetCellSize(), out var gw, out var gh); + settingsView.SetVoxels(gw, gh); + settingsView.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsView.GetCellSize(), settingsView.GetTileSize())); + settingsView.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(sample.GetInputGeom(), settingsView.GetCellSize(), settingsView.GetTileSize())); + settingsView.SetMaxPolys(tileNavMeshBuilder.GetMaxPolysPerTile(sample.GetInputGeom(), settingsView.GetCellSize(), settingsView.GetTileSize())); } UpdateKeyboard((float)dt); @@ -475,18 +475,18 @@ public class RecastDemo timeAcc -= DELTA_TIME; if (simIter < 5 && sample != null) { - toolsUI.HandleUpdate(DELTA_TIME); + toolsetView.HandleUpdate(DELTA_TIME); } simIter++; } - if (settingsUI.IsMeshInputTrigerred()) + if (settingsView.IsMeshInputTrigerred()) { - var bytes = Loader.ToBytes(settingsUI.GetMeshInputFilePath()); + var bytes = Loader.ToBytes(settingsView.GetMeshInputFilePath()); sample.Update(LoadInputMesh(bytes), null, null); } - else if (settingsUI.IsNavMeshInputTrigerred()) + else if (settingsView.IsNavMeshInputTrigerred()) { // try (MemoryStack stack = StackPush()) { // PointerBuffer aFilterPatterns = stack.MallocPointer(4); @@ -511,51 +511,51 @@ public class RecastDemo // } } - if (settingsUI.IsBuildTriggered() && sample.GetInputGeom() != null) + if (settingsView.IsBuildTriggered() && sample.GetInputGeom() != null) { if (!building) { - float m_cellSize = settingsUI.GetCellSize(); - float m_cellHeight = settingsUI.GetCellHeight(); - float m_agentHeight = settingsUI.GetAgentHeight(); - float m_agentRadius = settingsUI.GetAgentRadius(); - float m_agentMaxClimb = settingsUI.GetAgentMaxClimb(); - float m_agentMaxSlope = settingsUI.GetAgentMaxSlope(); - int m_regionMinSize = settingsUI.GetMinRegionSize(); - int m_regionMergeSize = settingsUI.GetMergedRegionSize(); - float m_edgeMaxLen = settingsUI.GetEdgeMaxLen(); - float m_edgeMaxError = settingsUI.GetEdgeMaxError(); - int m_vertsPerPoly = settingsUI.GetVertsPerPoly(); - float m_detailSampleDist = settingsUI.GetDetailSampleDist(); - float m_detailSampleMaxError = settingsUI.GetDetailSampleMaxError(); - int m_tileSize = settingsUI.GetTileSize(); + float m_cellSize = settingsView.GetCellSize(); + float m_cellHeight = settingsView.GetCellHeight(); + float m_agentHeight = settingsView.GetAgentHeight(); + float m_agentRadius = settingsView.GetAgentRadius(); + float m_agentMaxClimb = settingsView.GetAgentMaxClimb(); + float m_agentMaxSlope = settingsView.GetAgentMaxSlope(); + int m_regionMinSize = settingsView.GetMinRegionSize(); + int m_regionMergeSize = settingsView.GetMergedRegionSize(); + float m_edgeMaxLen = settingsView.GetEdgeMaxLen(); + float m_edgeMaxError = settingsView.GetEdgeMaxError(); + int m_vertsPerPoly = settingsView.GetVertsPerPoly(); + float m_detailSampleDist = settingsView.GetDetailSampleDist(); + float m_detailSampleMaxError = settingsView.GetDetailSampleMaxError(); + int m_tileSize = settingsView.GetTileSize(); long t = RcFrequency.Ticks; Logger.Information($"build"); Tuple, DtNavMesh> buildResult; - if (settingsUI.IsTiled()) + if (settingsView.IsTiled()) { - buildResult = tileNavMeshBuilder.Build(sample.GetInputGeom(), settingsUI.GetPartitioning(), m_cellSize, + buildResult = tileNavMeshBuilder.Build(sample.GetInputGeom(), settingsView.GetPartitioning(), m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist, - m_detailSampleMaxError, settingsUI.IsFilterLowHangingObstacles(), settingsUI.IsFilterLedgeSpans(), - settingsUI.IsFilterWalkableLowHeightSpans(), m_tileSize); + m_detailSampleMaxError, settingsView.IsFilterLowHangingObstacles(), settingsView.IsFilterLedgeSpans(), + settingsView.IsFilterWalkableLowHeightSpans(), m_tileSize); } else { - buildResult = soloNavMeshBuilder.Build(sample.GetInputGeom(), settingsUI.GetPartitioning(), m_cellSize, + buildResult = soloNavMeshBuilder.Build(sample.GetInputGeom(), settingsView.GetPartitioning(), m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist, - m_detailSampleMaxError, settingsUI.IsFilterLowHangingObstacles(), settingsUI.IsFilterLedgeSpans(), - settingsUI.IsFilterWalkableLowHeightSpans()); + m_detailSampleMaxError, settingsView.IsFilterLowHangingObstacles(), settingsView.IsFilterLedgeSpans(), + settingsView.IsFilterWalkableLowHeightSpans()); } sample.Update(sample.GetInputGeom(), buildResult.Item1, buildResult.Item2); sample.SetChanged(false); - settingsUI.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond); + settingsView.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond); //settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList()); - toolsUI.SetSample(sample); + toolsetView.SetSample(sample); Logger.Information($"build times"); Logger.Information($"-----------------------------------------"); @@ -602,7 +602,7 @@ public class RecastDemo } RcVec3f rayDir = RcVec3f.Of(rayEnd.x - rayStart.x, rayEnd.y - rayStart.y, rayEnd.z - rayStart.z); - ITool rayTool = toolsUI.GetTool(); + IRcTool rayTool = toolsetView.GetTool(); rayDir.Normalize(); if (rayTool != null) { @@ -704,7 +704,7 @@ public class RecastDemo } sample.SetChanged(false); - toolsUI.SetSample(sample); + toolsetView.SetSample(sample); } @@ -727,7 +727,7 @@ public class RecastDemo dd.Fog(camr * 0.1f, camr * 1.25f); renderer.Render(sample); - ITool tool = toolsUI.GetTool(); + IRcTool tool = toolsetView.GetTool(); if (tool != null) { tool.HandleRender(renderer); diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs index d4cde1f..2c00a68 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs @@ -30,7 +30,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; -public class ConvexVolumeTool : ITool +public class ConvexVolumeTool : IRcTool { private Sample sample; private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value; diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index a4a903e..e0cb046 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -34,7 +34,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; -public class CrowdTool : ITool +public class CrowdTool : IRcTool { private readonly CrowdToolParams toolParams = new CrowdToolParams(); private Sample sample; diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index 4ad7202..0845ad0 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -37,7 +37,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; -public class DynamicUpdateTool : ITool +public class DynamicUpdateTool : IRcTool { private Sample sample; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx; diff --git a/src/DotRecast.Recast.Demo/Tools/ITool.cs b/src/DotRecast.Recast.Demo/Tools/IRcTool.cs similarity index 98% rename from src/DotRecast.Recast.Demo/Tools/ITool.cs rename to src/DotRecast.Recast.Demo/Tools/IRcTool.cs index 27b4f58..fef856a 100644 --- a/src/DotRecast.Recast.Demo/Tools/ITool.cs +++ b/src/DotRecast.Recast.Demo/Tools/IRcTool.cs @@ -23,7 +23,7 @@ using DotRecast.Recast.Demo.Draw; namespace DotRecast.Recast.Demo.Tools; -public interface ITool +public interface IRcTool { string GetName(); void Layout(); diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs index d3dead0..0b3de1a 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs @@ -29,7 +29,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; -public class JumpLinkBuilderTool : ITool +public class JumpLinkBuilderTool : IRcTool { private readonly List links = new(); private Sample sample; diff --git a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs index 266ff10..a084993 100644 --- a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs @@ -28,7 +28,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDraw; namespace DotRecast.Recast.Demo.Tools; -public class OffMeshConnectionTool : ITool +public class OffMeshConnectionTool : IRcTool { private Sample sample; private bool hitPosSet; diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index e0a9448..46c0f7f 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -12,7 +12,7 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; -public class TestNavmeshTool : ITool +public class TestNavmeshTool : IRcTool { private const int MAX_POLYS = 256; private const int MAX_SMOOTH = 2048; diff --git a/src/DotRecast.Recast.Demo/UI/IRcView.cs b/src/DotRecast.Recast.Demo/UI/IRcView.cs index c413026..94a2f03 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(RecastDemoCanvas canvas); + void Bind(RcCanvas canvas); bool IsMouseInside(); void Update(double dt); void Draw(double dt); diff --git a/src/DotRecast.Recast.Demo/UI/RecastDemoCanvas.cs b/src/DotRecast.Recast.Demo/UI/RcCanvas.cs similarity index 97% rename from src/DotRecast.Recast.Demo/UI/RecastDemoCanvas.cs rename to src/DotRecast.Recast.Demo/UI/RcCanvas.cs index e37395b..fec796d 100644 --- a/src/DotRecast.Recast.Demo/UI/RecastDemoCanvas.cs +++ b/src/DotRecast.Recast.Demo/UI/RcCanvas.cs @@ -27,7 +27,7 @@ using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.UI; -public class RecastDemoCanvas +public class RcCanvas { private static readonly ILogger Logger = Log.ForContext(); @@ -38,7 +38,7 @@ public class RecastDemoCanvas public Vector2D Size => _window.Size; - public RecastDemoCanvas(IWindow window, params IRcView[] views) + public RcCanvas(IWindow window, params IRcView[] views) { _window = window; _views = views; diff --git a/src/DotRecast.Recast.Demo/UI/RcLogView.cs b/src/DotRecast.Recast.Demo/UI/RcLogView.cs index bfebcd9..30a2652 100644 --- a/src/DotRecast.Recast.Demo/UI/RcLogView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcLogView.cs @@ -13,7 +13,7 @@ namespace DotRecast.Recast.Demo.UI; public class RcLogView : IRcView { - private RecastDemoCanvas _canvas; + private RcCanvas _canvas; private bool _mouseInside; private readonly List _lines; @@ -42,7 +42,7 @@ public class RcLogView : IRcView _lines.Clear(); } - public void Bind(RecastDemoCanvas canvas) + public void Bind(RcCanvas canvas) { _canvas = canvas; } diff --git a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs index 8628dc5..e2162a7 100644 --- a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs @@ -23,9 +23,7 @@ using System.Linq; using System.Numerics; using DotRecast.Core; using DotRecast.Recast.Demo.Draw; -using DotRecast.Recast.Demo.UI; using ImGuiNET; -using Silk.NET.Windowing; namespace DotRecast.Recast.Demo.UI; @@ -78,9 +76,9 @@ public class RcSettingsView : IRcView private bool _mouseInside; public bool IsMouseInside() => _mouseInside; - private RecastDemoCanvas _canvas; + private RcCanvas _canvas; - public void Bind(RecastDemoCanvas canvas) + public void Bind(RcCanvas canvas) { _canvas = canvas; } diff --git a/src/DotRecast.Recast.Demo/UI/ToolsView.cs b/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs similarity index 91% rename from src/DotRecast.Recast.Demo/UI/ToolsView.cs rename to src/DotRecast.Recast.Demo/UI/RcToolsetView.cs index 1bae479..d0d7015 100644 --- a/src/DotRecast.Recast.Demo/UI/ToolsView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs @@ -26,24 +26,24 @@ using ImGuiNET; namespace DotRecast.Recast.Demo.UI; -public class ToolsView : IRcView +public class RcToolsetView : IRcView { //private readonly NkColor white = NkColor.Create(); private int _currentToolIdx = 0; - private ITool currentTool; + private IRcTool currentTool; private bool enabled; - private readonly ITool[] tools; + private readonly IRcTool[] tools; private bool _mouseInside; public bool IsMouseInside() => _mouseInside; - private RecastDemoCanvas _canvas; + private RcCanvas _canvas; - public ToolsView(params ITool[] tools) + public RcToolsetView(params IRcTool[] tools) { this.tools = tools; } - public void Bind(RecastDemoCanvas canvas) + public void Bind(RcCanvas canvas) { _canvas = canvas; } @@ -87,7 +87,7 @@ public class ToolsView : IRcView this.enabled = enabled; } - public ITool GetTool() + public IRcTool GetTool() { return currentTool; }