From a8aafc8491b3ee88e758c2b9e83b1eb9e9c4a99c Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 13 Jun 2023 01:04:14 +0900 Subject: [PATCH] add ISampleTool Idiom --- .../Tools/ConvexVolumeTool.cs | 21 ++++++++++++------- src/DotRecast.Recast.Demo/Tools/CrowdTool.cs | 11 ++++++---- .../Tools/DynamicUpdateTool.cs | 12 ++++++----- src/DotRecast.Recast.Demo/Tools/IRcTool.cs | 2 +- .../Tools/JumpLinkBuilderTool.cs | 18 +++++++++++----- .../Tools/OffMeshConnectionTool.cs | 20 +++++++++++------- .../Tools/TestNavmeshTool.cs | 13 ++++++++---- src/DotRecast.Recast.Demo/UI/RcToolsetView.cs | 4 ++-- src/DotRecast.Recast.DemoTool/ISampleTool.cs | 7 +++++++ .../Tools/ConvexVolumeToolImpl.cs | 10 +++++++++ .../Tools/CrowdToolImpl.cs | 10 +++++++++ .../Tools/DynamicUpdateToolImpl.cs | 10 +++++++++ .../Tools/JumpLinkBuilderToolImpl.cs | 10 +++++++++ .../Tools/OffMeshConnectionToolImpl.cs | 10 +++++++++ .../Tools/TestNavmeshToolImpl.cs | 10 +++++++++ 15 files changed, 132 insertions(+), 36 deletions(-) create mode 100644 src/DotRecast.Recast.DemoTool/ISampleTool.cs create mode 100644 src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs create mode 100644 src/DotRecast.Recast.DemoTool/Tools/CrowdToolImpl.cs create mode 100644 src/DotRecast.Recast.DemoTool/Tools/DynamicUpdateToolImpl.cs create mode 100644 src/DotRecast.Recast.DemoTool/Tools/JumpLinkBuilderToolImpl.cs create mode 100644 src/DotRecast.Recast.DemoTool/Tools/OffMeshConnectionToolImpl.cs create mode 100644 src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs index dddc834..bc15bb0 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeTool.cs @@ -25,6 +25,7 @@ using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool.Geom; +using DotRecast.Recast.DemoTool.Tools; using ImGuiNET; using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; @@ -33,6 +34,7 @@ namespace DotRecast.Recast.Demo.Tools; public class ConvexVolumeTool : IRcTool { + private readonly ConvexVolumeToolImpl _impl; private Sample _sample; private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value; private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS; @@ -42,6 +44,16 @@ public class ConvexVolumeTool : IRcTool private readonly List pts = new(); private readonly List hull = new(); + public ConvexVolumeTool() + { + _impl = new ConvexVolumeToolImpl(); + } + + public ISampleTool GetTool() + { + return _impl; + } + public void SetSample(Sample sample) { _sample = sample; @@ -225,19 +237,12 @@ public class ConvexVolumeTool : IRcTool } } - public string GetName() - { - return "Create Convex Volumes"; - } - public void HandleUpdate(float dt) { // TODO Auto-generated method stub } - + public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) { - } - } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index 5080fc1..1ed0ddb 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -37,6 +37,7 @@ namespace DotRecast.Recast.Demo.Tools; public class CrowdTool : IRcTool { + private readonly CrowdToolImpl _impl; private readonly CrowdToolParams toolParams = new CrowdToolParams(); private Sample _sample; private DtNavMesh m_nav; @@ -55,6 +56,12 @@ public class CrowdTool : IRcTool { m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048); profilingTool = new CrowdProfilingTool(GetAgentParams); + _impl = new(); + } + + public ISampleTool GetTool() + { + return _impl; } public void SetSample(Sample sample) @@ -788,10 +795,6 @@ public class CrowdTool : IRcTool return updateFlags; } - public string GetName() - { - return "Crowd"; - } public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) { diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index 968cae8..6b7bd19 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -40,6 +40,7 @@ namespace DotRecast.Recast.Demo.Tools; public class DynamicUpdateTool : IRcTool { + private readonly DynamicUpdateToolImpl _impl; private Sample _sample; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx; private DynamicUpdateToolMode mode = DynamicUpdateToolMode.BUILD; @@ -87,12 +88,18 @@ public class DynamicUpdateTool : IRcTool public DynamicUpdateTool() { + _impl = new(); executor = Task.Factory; bridgeGeom = DemoObjImporter.Load(Loader.ToBytes("bridge.obj")); houseGeom = DemoObjImporter.Load(Loader.ToBytes("house.obj")); convexGeom = DemoObjImporter.Load(Loader.ToBytes("convex.obj")); } + public ISampleTool GetTool() + { + return _impl; + } + public void SetSample(Sample sample) { _sample = sample; @@ -744,9 +751,4 @@ public class DynamicUpdateTool : IRcTool filterLedgeSpans = dynaMesh.config.filterLedgeSpans; filterWalkableLowHeightSpans = dynaMesh.config.filterWalkableLowHeightSpans; } - - public string GetName() - { - return "Dynamic Updates"; - } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/IRcTool.cs b/src/DotRecast.Recast.Demo/Tools/IRcTool.cs index 60072b6..e86c0ec 100644 --- a/src/DotRecast.Recast.Demo/Tools/IRcTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/IRcTool.cs @@ -26,7 +26,7 @@ namespace DotRecast.Recast.Demo.Tools; public interface IRcTool { - string GetName(); + ISampleTool GetTool(); void Layout(); void SetSample(Sample sample); diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs index df06c4b..67d0875 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderTool.cs @@ -32,12 +32,24 @@ namespace DotRecast.Recast.Demo.Tools; public class JumpLinkBuilderTool : IRcTool { + private readonly JumpLinkBuilderToolImpl _impl; private readonly List links = new(); private Sample _sample; private JumpLinkBuilder annotationBuilder; private readonly int selEdge = -1; private readonly JumpLinkBuilderToolParams option = new JumpLinkBuilderToolParams(); + + public JumpLinkBuilderTool() + { + _impl = new(); + } + + public ISampleTool GetTool() + { + return _impl; + } + public void SetSample(Sample sample) { _sample = sample; @@ -385,7 +397,7 @@ public class JumpLinkBuilderTool : IRcTool float agentRadius = settings.agentRadius; float agentClimb = settings.agentMaxClimb; float cellHeight = settings.cellHeight; - + if ((option.buildTypes & JumpLinkType.EDGE_CLIMB_DOWN.Bit) != 0) { JumpLinkBuilderConfig config = new JumpLinkBuilderConfig(cellSize, cellHeight, agentRadius, @@ -445,10 +457,6 @@ public class JumpLinkBuilderTool : IRcTool } } - public string GetName() - { - return "Annotation Builder"; - } public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) { diff --git a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs index 1c0837b..7f27b27 100644 --- a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionTool.cs @@ -24,6 +24,7 @@ using DotRecast.Recast.DemoTool.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool.Geom; +using DotRecast.Recast.DemoTool.Tools; using ImGuiNET; using static DotRecast.Recast.Demo.Draw.DebugDraw; @@ -31,11 +32,22 @@ namespace DotRecast.Recast.Demo.Tools; public class OffMeshConnectionTool : IRcTool { + private readonly OffMeshConnectionToolImpl _impl; private Sample _sample; private bool hitPosSet; private RcVec3f hitPos; private int bidir; + public OffMeshConnectionTool() + { + _impl = new(); + } + + public ISampleTool GetTool() + { + return _impl; + } + public void SetSample(Sample sample) { _sample = sample; @@ -116,19 +128,13 @@ public class OffMeshConnectionTool : IRcTool ImGui.RadioButton("Bidirectional", ref bidir, 1); } - public string GetName() - { - return "Create Off-Mesh Links"; - } public void HandleUpdate(float dt) { // TODO Auto-generated method stub } - + public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) { - } - } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index cf4dde3..1a5c696 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -13,11 +13,14 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; namespace DotRecast.Recast.Demo.Tools; + + public class TestNavmeshTool : IRcTool { private const int MAX_POLYS = 256; private const int MAX_SMOOTH = 2048; + private readonly TestNavmeshToolImpl _impl; private Sample _sample; private int m_toolModeIdx = TestNavmeshToolMode.PATHFIND_FOLLOW.Idx; @@ -51,6 +54,7 @@ public class TestNavmeshTool : IRcTool public TestNavmeshTool() { + _impl = new(); m_filter = new DtQueryDefaultFilter( SampleAreaModifications.SAMPLE_POLYFLAGS_ALL, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, @@ -58,6 +62,11 @@ public class TestNavmeshTool : IRcTool ); } + public ISampleTool GetTool() + { + return _impl; + } + public void SetSample(Sample sample) { _sample = sample; @@ -157,10 +166,6 @@ public class TestNavmeshTool : IRcTool } } - public string GetName() - { - return "Test Navmesh"; - } private void Recalc() { diff --git a/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs b/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs index a4103ba..db29c08 100644 --- a/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcToolsetView.cs @@ -64,7 +64,7 @@ public class RcToolsetView : IRcView for (int i = 0; i < tools.Length; ++i) { var tool = tools[i]; - ImGui.RadioButton(tool.GetName(), ref _currentToolIdx, i); + ImGui.RadioButton(tool.GetTool().GetName(), ref _currentToolIdx, i); } ImGui.NewLine(); @@ -76,7 +76,7 @@ public class RcToolsetView : IRcView } currentTool = tools[_currentToolIdx]; - ImGui.Text(currentTool.GetName()); + ImGui.Text(currentTool.GetTool().GetName()); ImGui.Separator(); currentTool.Layout(); diff --git a/src/DotRecast.Recast.DemoTool/ISampleTool.cs b/src/DotRecast.Recast.DemoTool/ISampleTool.cs new file mode 100644 index 0000000..143cbbb --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/ISampleTool.cs @@ -0,0 +1,7 @@ +namespace DotRecast.Recast.DemoTool +{ + public interface ISampleTool + { + string GetName(); + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs new file mode 100644 index 0000000..52a714f --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/Tools/ConvexVolumeToolImpl.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.DemoTool.Tools +{ + public class ConvexVolumeToolImpl : ISampleTool + { + public string GetName() + { + return "Create Convex Volumes"; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/CrowdToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/CrowdToolImpl.cs new file mode 100644 index 0000000..6ee73a7 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/Tools/CrowdToolImpl.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.DemoTool.Tools +{ + public class CrowdToolImpl : ISampleTool + { + public string GetName() + { + return "Crowd"; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/DynamicUpdateToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/DynamicUpdateToolImpl.cs new file mode 100644 index 0000000..309c467 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/Tools/DynamicUpdateToolImpl.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.DemoTool.Tools +{ + public class DynamicUpdateToolImpl : ISampleTool + { + public string GetName() + { + return "Dynamic Updates"; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/JumpLinkBuilderToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/JumpLinkBuilderToolImpl.cs new file mode 100644 index 0000000..7261c8b --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/Tools/JumpLinkBuilderToolImpl.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.DemoTool.Tools +{ + public class JumpLinkBuilderToolImpl : ISampleTool + { + public string GetName() + { + return "Annotation Builder"; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/OffMeshConnectionToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/OffMeshConnectionToolImpl.cs new file mode 100644 index 0000000..8754108 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/Tools/OffMeshConnectionToolImpl.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.DemoTool.Tools +{ + public class OffMeshConnectionToolImpl : ISampleTool + { + public string GetName() + { + return "Create Off-Mesh Links"; + } + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs new file mode 100644 index 0000000..0b1d2d0 --- /dev/null +++ b/src/DotRecast.Recast.DemoTool/Tools/TestNavmeshToolImpl.cs @@ -0,0 +1,10 @@ +namespace DotRecast.Recast.DemoTool.Tools +{ + public class TestNavmeshToolImpl : ISampleTool + { + public string GetName() + { + return "Test Navmesh"; + } + } +} \ No newline at end of file