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.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<float> pts = new();
private readonly List<int> 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)
{
}
}

View File

@ -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)
{

View File

@ -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";
}
}

View File

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

View File

@ -32,12 +32,24 @@ namespace DotRecast.Recast.Demo.Tools;
public class JumpLinkBuilderTool : IRcTool
{
private readonly JumpLinkBuilderToolImpl _impl;
private readonly List<JumpLink> 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)
{

View File

@ -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)
{
}
}

View File

@ -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()
{

View File

@ -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();

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";
}
}
}