add ISampleTool Idiom

This commit is contained in:
ikpil 2023-06-13 01:04:14 +09:00
parent 51de2c88f9
commit a8aafc8491
15 changed files with 132 additions and 36 deletions

View File

@ -25,6 +25,7 @@ using DotRecast.Recast.DemoTool.Builder;
using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool;
using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.DemoTool.Geom;
using DotRecast.Recast.DemoTool.Tools;
using ImGuiNET; using ImGuiNET;
using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDraw;
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives; using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
@ -33,6 +34,7 @@ namespace DotRecast.Recast.Demo.Tools;
public class ConvexVolumeTool : IRcTool public class ConvexVolumeTool : IRcTool
{ {
private readonly ConvexVolumeToolImpl _impl;
private Sample _sample; private Sample _sample;
private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value; private int areaTypeValue = SampleAreaModifications.SAMPLE_AREAMOD_GRASS.Value;
private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS; private AreaModification areaType = SampleAreaModifications.SAMPLE_AREAMOD_GRASS;
@ -42,6 +44,16 @@ public class ConvexVolumeTool : IRcTool
private readonly List<float> pts = new(); private readonly List<float> pts = new();
private readonly List<int> hull = new(); private readonly List<int> hull = new();
public ConvexVolumeTool()
{
_impl = new ConvexVolumeToolImpl();
}
public ISampleTool GetTool()
{
return _impl;
}
public void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
_sample = sample; _sample = sample;
@ -225,11 +237,6 @@ public class ConvexVolumeTool : IRcTool
} }
} }
public string GetName()
{
return "Create Convex Volumes";
}
public void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -237,7 +244,5 @@ public class ConvexVolumeTool : IRcTool
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{ {
} }
} }

View File

@ -37,6 +37,7 @@ namespace DotRecast.Recast.Demo.Tools;
public class CrowdTool : IRcTool public class CrowdTool : IRcTool
{ {
private readonly CrowdToolImpl _impl;
private readonly CrowdToolParams toolParams = new CrowdToolParams(); private readonly CrowdToolParams toolParams = new CrowdToolParams();
private Sample _sample; private Sample _sample;
private DtNavMesh m_nav; private DtNavMesh m_nav;
@ -55,6 +56,12 @@ public class CrowdTool : IRcTool
{ {
m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048); m_agentDebug.vod = new DtObstacleAvoidanceDebugData(2048);
profilingTool = new CrowdProfilingTool(GetAgentParams); profilingTool = new CrowdProfilingTool(GetAgentParams);
_impl = new();
}
public ISampleTool GetTool()
{
return _impl;
} }
public void SetSample(Sample sample) public void SetSample(Sample sample)
@ -788,10 +795,6 @@ public class CrowdTool : IRcTool
return updateFlags; return updateFlags;
} }
public string GetName()
{
return "Crowd";
}
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{ {

View File

@ -40,6 +40,7 @@ namespace DotRecast.Recast.Demo.Tools;
public class DynamicUpdateTool : IRcTool public class DynamicUpdateTool : IRcTool
{ {
private readonly DynamicUpdateToolImpl _impl;
private Sample _sample; private Sample _sample;
private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx; private int toolModeIdx = DynamicUpdateToolMode.BUILD.Idx;
private DynamicUpdateToolMode mode = DynamicUpdateToolMode.BUILD; private DynamicUpdateToolMode mode = DynamicUpdateToolMode.BUILD;
@ -87,12 +88,18 @@ public class DynamicUpdateTool : IRcTool
public DynamicUpdateTool() public DynamicUpdateTool()
{ {
_impl = new();
executor = Task.Factory; executor = Task.Factory;
bridgeGeom = DemoObjImporter.Load(Loader.ToBytes("bridge.obj")); bridgeGeom = DemoObjImporter.Load(Loader.ToBytes("bridge.obj"));
houseGeom = DemoObjImporter.Load(Loader.ToBytes("house.obj")); houseGeom = DemoObjImporter.Load(Loader.ToBytes("house.obj"));
convexGeom = DemoObjImporter.Load(Loader.ToBytes("convex.obj")); convexGeom = DemoObjImporter.Load(Loader.ToBytes("convex.obj"));
} }
public ISampleTool GetTool()
{
return _impl;
}
public void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
_sample = sample; _sample = sample;
@ -744,9 +751,4 @@ public class DynamicUpdateTool : IRcTool
filterLedgeSpans = dynaMesh.config.filterLedgeSpans; filterLedgeSpans = dynaMesh.config.filterLedgeSpans;
filterWalkableLowHeightSpans = dynaMesh.config.filterWalkableLowHeightSpans; filterWalkableLowHeightSpans = dynaMesh.config.filterWalkableLowHeightSpans;
} }
public string GetName()
{
return "Dynamic Updates";
}
} }

View File

@ -26,7 +26,7 @@ namespace DotRecast.Recast.Demo.Tools;
public interface IRcTool public interface IRcTool
{ {
string GetName(); ISampleTool GetTool();
void Layout(); void Layout();
void SetSample(Sample sample); void SetSample(Sample sample);

View File

@ -32,12 +32,24 @@ namespace DotRecast.Recast.Demo.Tools;
public class JumpLinkBuilderTool : IRcTool public class JumpLinkBuilderTool : IRcTool
{ {
private readonly JumpLinkBuilderToolImpl _impl;
private readonly List<JumpLink> links = new(); private readonly List<JumpLink> links = new();
private Sample _sample; private Sample _sample;
private JumpLinkBuilder annotationBuilder; private JumpLinkBuilder annotationBuilder;
private readonly int selEdge = -1; private readonly int selEdge = -1;
private readonly JumpLinkBuilderToolParams option = new JumpLinkBuilderToolParams(); private readonly JumpLinkBuilderToolParams option = new JumpLinkBuilderToolParams();
public JumpLinkBuilderTool()
{
_impl = new();
}
public ISampleTool GetTool()
{
return _impl;
}
public void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
_sample = sample; _sample = sample;
@ -445,10 +457,6 @@ public class JumpLinkBuilderTool : IRcTool
} }
} }
public string GetName()
{
return "Annotation Builder";
}
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{ {

View File

@ -24,6 +24,7 @@ using DotRecast.Recast.DemoTool.Builder;
using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.DemoTool; using DotRecast.Recast.DemoTool;
using DotRecast.Recast.DemoTool.Geom; using DotRecast.Recast.DemoTool.Geom;
using DotRecast.Recast.DemoTool.Tools;
using ImGuiNET; using ImGuiNET;
using static DotRecast.Recast.Demo.Draw.DebugDraw; using static DotRecast.Recast.Demo.Draw.DebugDraw;
@ -31,11 +32,22 @@ namespace DotRecast.Recast.Demo.Tools;
public class OffMeshConnectionTool : IRcTool public class OffMeshConnectionTool : IRcTool
{ {
private readonly OffMeshConnectionToolImpl _impl;
private Sample _sample; private Sample _sample;
private bool hitPosSet; private bool hitPosSet;
private RcVec3f hitPos; private RcVec3f hitPos;
private int bidir; private int bidir;
public OffMeshConnectionTool()
{
_impl = new();
}
public ISampleTool GetTool()
{
return _impl;
}
public void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
_sample = sample; _sample = sample;
@ -116,10 +128,6 @@ public class OffMeshConnectionTool : IRcTool
ImGui.RadioButton("Bidirectional", ref bidir, 1); ImGui.RadioButton("Bidirectional", ref bidir, 1);
} }
public string GetName()
{
return "Create Off-Mesh Links";
}
public void HandleUpdate(float dt) public void HandleUpdate(float dt)
{ {
@ -128,7 +136,5 @@ public class OffMeshConnectionTool : IRcTool
public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift)
{ {
} }
} }

View File

@ -13,11 +13,14 @@ using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class TestNavmeshTool : IRcTool public class TestNavmeshTool : IRcTool
{ {
private const int MAX_POLYS = 256; private const int MAX_POLYS = 256;
private const int MAX_SMOOTH = 2048; private const int MAX_SMOOTH = 2048;
private readonly TestNavmeshToolImpl _impl;
private Sample _sample; private Sample _sample;
private int m_toolModeIdx = TestNavmeshToolMode.PATHFIND_FOLLOW.Idx; private int m_toolModeIdx = TestNavmeshToolMode.PATHFIND_FOLLOW.Idx;
@ -51,6 +54,7 @@ public class TestNavmeshTool : IRcTool
public TestNavmeshTool() public TestNavmeshTool()
{ {
_impl = new();
m_filter = new DtQueryDefaultFilter( m_filter = new DtQueryDefaultFilter(
SampleAreaModifications.SAMPLE_POLYFLAGS_ALL, SampleAreaModifications.SAMPLE_POLYFLAGS_ALL,
SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED,
@ -58,6 +62,11 @@ public class TestNavmeshTool : IRcTool
); );
} }
public ISampleTool GetTool()
{
return _impl;
}
public void SetSample(Sample sample) public void SetSample(Sample sample)
{ {
_sample = sample; _sample = sample;
@ -157,10 +166,6 @@ public class TestNavmeshTool : IRcTool
} }
} }
public string GetName()
{
return "Test Navmesh";
}
private void Recalc() private void Recalc()
{ {

View File

@ -64,7 +64,7 @@ public class RcToolsetView : IRcView
for (int i = 0; i < tools.Length; ++i) for (int i = 0; i < tools.Length; ++i)
{ {
var tool = tools[i]; var tool = tools[i];
ImGui.RadioButton(tool.GetName(), ref _currentToolIdx, i); ImGui.RadioButton(tool.GetTool().GetName(), ref _currentToolIdx, i);
} }
ImGui.NewLine(); ImGui.NewLine();
@ -76,7 +76,7 @@ public class RcToolsetView : IRcView
} }
currentTool = tools[_currentToolIdx]; currentTool = tools[_currentToolIdx];
ImGui.Text(currentTool.GetName()); ImGui.Text(currentTool.GetTool().GetName());
ImGui.Separator(); ImGui.Separator();
currentTool.Layout(); currentTool.Layout();

View File

@ -0,0 +1,7 @@
namespace DotRecast.Recast.DemoTool
{
public interface ISampleTool
{
string GetName();
}
}

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class ConvexVolumeToolImpl : ISampleTool
{
public string GetName()
{
return "Create Convex Volumes";
}
}
}

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class CrowdToolImpl : ISampleTool
{
public string GetName()
{
return "Crowd";
}
}
}

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class DynamicUpdateToolImpl : ISampleTool
{
public string GetName()
{
return "Dynamic Updates";
}
}
}

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class JumpLinkBuilderToolImpl : ISampleTool
{
public string GetName()
{
return "Annotation Builder";
}
}
}

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class OffMeshConnectionToolImpl : ISampleTool
{
public string GetName()
{
return "Create Off-Mesh Links";
}
}
}

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.DemoTool.Tools
{
public class TestNavmeshToolImpl : ISampleTool
{
public string GetName()
{
return "Test Navmesh";
}
}
}