move IRcTool.SetSample to ISampleTool.SetSample

This commit is contained in:
ikpil 2023-06-13 01:19:05 +09:00
parent a8aafc8491
commit ca51085826
15 changed files with 141 additions and 74 deletions

View File

@ -35,7 +35,6 @@ 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;
private float boxHeight = 6f;
@ -54,14 +53,14 @@ public class ConvexVolumeTool : IRcTool
return _impl;
}
public void SetSample(Sample sample)
public void OnSampleChanged()
{
_sample = sample;
// ..
}
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{
DemoInputGeomProvider geom = _sample.GetInputGeom();
DemoInputGeomProvider geom = _impl.GetSample().GetInputGeom();
if (geom == null)
{
return;
@ -229,7 +228,7 @@ public class ConvexVolumeTool : IRcTool
hull.Clear();
pts.Clear();
DemoInputGeomProvider geom = _sample.GetInputGeom();
DemoInputGeomProvider geom = _impl.GetSample().GetInputGeom();
if (geom != null)
{
geom.ClearConvexVolumes();

View File

@ -39,7 +39,6 @@ public class CrowdTool : IRcTool
{
private readonly CrowdToolImpl _impl;
private readonly CrowdToolParams toolParams = new CrowdToolParams();
private Sample _sample;
private DtNavMesh m_nav;
private DtCrowd crowd;
private readonly CrowdProfilingTool profilingTool;
@ -64,16 +63,15 @@ public class CrowdTool : IRcTool
return _impl;
}
public void SetSample(Sample sample)
public void OnSampleChanged()
{
_sample = sample;
DtNavMesh nav = _sample.GetNavMesh();
DtNavMesh nav = _impl.GetSample().GetNavMesh();
if (nav != null && m_nav != nav)
{
m_nav = nav;
DtCrowdConfig config = new DtCrowdConfig(_sample.GetSettings().agentRadius);
DtCrowdConfig config = new DtCrowdConfig(_impl.GetSample().GetSettings().agentRadius);
crowd = new DtCrowd(config, nav, __ => new DtQueryDefaultFilter(SampleAreaModifications.SAMPLE_POLYFLAGS_ALL,
SampleAreaModifications.SAMPLE_POLYFLAGS_DISABLED, new float[] { 1f, 10f, 1f, 1f, 2f, 1.5f }));
@ -111,7 +109,7 @@ public class CrowdTool : IRcTool
crowd.SetObstacleAvoidanceParams(3, option);
profilingTool.Setup(_sample.GetSettings().agentRadius, m_nav);
profilingTool.Setup(_impl.GetSample().GetSettings().agentRadius, m_nav);
}
}
@ -156,8 +154,8 @@ public class CrowdTool : IRcTool
}
else if (m_mode == CrowdToolMode.TOGGLE_POLYS)
{
DtNavMesh nav = _sample.GetNavMesh();
DtNavMeshQuery navquery = _sample.GetNavMeshQuery();
DtNavMesh nav = _impl.GetSample().GetNavMesh();
DtNavMeshQuery navquery = _impl.GetSample().GetNavMeshQuery();
if (nav != null && navquery != null)
{
IDtQueryFilter filter = new DtQueryDefaultFilter();
@ -214,8 +212,8 @@ public class CrowdTool : IRcTool
private DtCrowdAgentParams GetAgentParams()
{
DtCrowdAgentParams ap = new DtCrowdAgentParams();
ap.radius = _sample.GetSettings().agentRadius;
ap.height = _sample.GetSettings().agentHeight;
ap.radius = _impl.GetSample().GetSettings().agentRadius;
ap.height = _impl.GetSample().GetSettings().agentHeight;
ap.maxAcceleration = 8.0f;
ap.maxSpeed = 3.5f;
ap.collisionQueryRange = ap.radius * 12.0f;
@ -264,11 +262,11 @@ public class CrowdTool : IRcTool
private void SetMoveTarget(RcVec3f p, bool adjust)
{
if (_sample == null || crowd == null)
if (_impl.GetSample() == null || crowd == null)
return;
// Find nearest point on navmesh and set move request to that location.
DtNavMeshQuery navquery = _sample.GetNavMeshQuery();
DtNavMeshQuery navquery = _impl.GetSample().GetNavMeshQuery();
IDtQueryFilter filter = crowd.GetFilter(0);
RcVec3f halfExtents = crowd.GetQueryExtents();
@ -323,8 +321,8 @@ public class CrowdTool : IRcTool
}
RecastDebugDraw dd = renderer.GetDebugDraw();
float rad = _sample.GetSettings().agentRadius;
DtNavMesh nav = _sample.GetNavMesh();
float rad = _impl.GetSample().GetSettings().agentRadius;
DtNavMesh nav = _impl.GetSample().GetNavMesh();
if (nav == null || crowd == null)
return;
@ -636,7 +634,7 @@ public class CrowdTool : IRcTool
if (crowd == null)
return;
DtNavMesh nav = _sample.GetNavMesh();
DtNavMesh nav = _impl.GetSample().GetNavMesh();
if (nav == null)
return;

View File

@ -41,7 +41,6 @@ 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;
private float cellSize = 0.3f;
@ -99,12 +98,13 @@ public class DynamicUpdateTool : IRcTool
{
return _impl;
}
public void SetSample(Sample sample)
public void OnSampleChanged()
{
_sample = sample;
// ..
}
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{
if (mode == DynamicUpdateToolMode.COLLIDERS)
@ -439,9 +439,9 @@ public class DynamicUpdateTool : IRcTool
private void DrawAgent(RecastDebugDraw dd, RcVec3f pos, int col)
{
float r = _sample.GetSettings().agentRadius;
float h = _sample.GetSettings().agentHeight;
float c = _sample.GetSettings().agentMaxClimb;
float r = _impl.GetSample().GetSettings().agentRadius;
float h = _impl.GetSample().GetSettings().agentHeight;
float c = _impl.GetSample().GetSettings().agentMaxClimb;
dd.DepthMask(false);
// Agent dimensions.
dd.DebugDrawCylinderWire(pos.x - r, pos.y + 0.02f, pos.z - r, pos.x + r, pos.y + h, pos.z + r, col, 2.0f);
@ -475,8 +475,8 @@ public class DynamicUpdateTool : IRcTool
if (updated)
{
buildTime = (RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond;
_sample.Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
_sample.SetChanged(false);
_impl.GetSample().Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
_impl.GetSample().SetChanged(false);
}
}
catch (Exception e)
@ -607,7 +607,7 @@ public class DynamicUpdateTool : IRcTool
if (dynaMesh != null)
{
BuildDynaMesh();
_sample.SetChanged(false);
_impl.GetSample().SetChanged(false);
}
}
}
@ -708,7 +708,7 @@ public class DynamicUpdateTool : IRcTool
}
buildTime = (RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond;
_sample.Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
_impl.GetSample().Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
}
private void ConfigDynaMesh()

View File

@ -27,10 +27,10 @@ namespace DotRecast.Recast.Demo.Tools;
public interface IRcTool
{
ISampleTool GetTool();
void OnSampleChanged();
void Layout();
void SetSample(Sample sample);
void HandleClick(RcVec3f s, RcVec3f p, bool shift);
void HandleRender(NavMeshRenderer renderer);

View File

@ -34,7 +34,6 @@ 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();
@ -50,9 +49,8 @@ public class JumpLinkBuilderTool : IRcTool
return _impl;
}
public void SetSample(Sample sample)
public void OnSampleChanged()
{
_sample = sample;
annotationBuilder = null;
}
@ -337,7 +335,7 @@ public class JumpLinkBuilderTool : IRcTool
public void Layout()
{
if (0 >= _sample.GetRecastResults().Count)
if (0 >= _impl.GetSample().GetRecastResults().Count)
return;
ImGui.Text("Options");
@ -382,16 +380,16 @@ public class JumpLinkBuilderTool : IRcTool
{
if (annotationBuilder == null)
{
if (_sample != null && 0 < _sample.GetRecastResults().Count)
if (_impl.GetSample() != null && 0 < _impl.GetSample().GetRecastResults().Count)
{
annotationBuilder = new JumpLinkBuilder(_sample.GetRecastResults());
annotationBuilder = new JumpLinkBuilder(_impl.GetSample().GetRecastResults());
}
}
links.Clear();
if (annotationBuilder != null)
{
var settings = _sample.GetSettings();
var settings = _impl.GetSample().GetSettings();
float cellSize = settings.cellSize;
float agentHeight = settings.agentHeight;
float agentRadius = settings.agentRadius;
@ -418,7 +416,7 @@ public class JumpLinkBuilderTool : IRcTool
if (buildOffMeshConnections)
{
DemoInputGeomProvider geom = _sample.GetInputGeom();
DemoInputGeomProvider geom = _impl.GetSample().GetInputGeom();
if (geom != null)
{
int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP_AUTO;

View File

@ -33,7 +33,6 @@ 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;
@ -47,15 +46,15 @@ public class OffMeshConnectionTool : IRcTool
{
return _impl;
}
public void SetSample(Sample sample)
public void OnSampleChanged()
{
_sample = sample;
// ..
}
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{
DemoInputGeomProvider geom = _sample.GetInputGeom();
DemoInputGeomProvider geom = _impl.GetSample().GetInputGeom();
if (geom == null)
{
return;
@ -70,7 +69,7 @@ public class OffMeshConnectionTool : IRcTool
foreach (DemoOffMeshConnection offMeshCon in geom.GetOffMeshConnections())
{
float d = Math.Min(RcVec3f.DistSqr(p, offMeshCon.verts, 0), RcVec3f.DistSqr(p, offMeshCon.verts, 3));
if (d < nearestDist && Math.Sqrt(d) < _sample.GetSettings().agentRadius)
if (d < nearestDist && Math.Sqrt(d) < _impl.GetSample().GetSettings().agentRadius)
{
nearestDist = d;
nearestConnection = offMeshCon;
@ -94,7 +93,7 @@ public class OffMeshConnectionTool : IRcTool
{
int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP;
int flags = SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP;
geom.AddOffMeshConnection(hitPos, p, _sample.GetSettings().agentRadius, 0 == bidir, area, flags);
geom.AddOffMeshConnection(hitPos, p, _impl.GetSample().GetSettings().agentRadius, 0 == bidir, area, flags);
hitPosSet = false;
}
}
@ -102,20 +101,20 @@ public class OffMeshConnectionTool : IRcTool
public void HandleRender(NavMeshRenderer renderer)
{
if (_sample == null)
if (_impl.GetSample() == null)
{
return;
}
RecastDebugDraw dd = renderer.GetDebugDraw();
float s = _sample.GetSettings().agentRadius;
float s = _impl.GetSample().GetSettings().agentRadius;
if (hitPosSet)
{
dd.DebugDrawCross(hitPos.x, hitPos.y + 0.1f, hitPos.z, s, DuRGBA(0, 0, 0, 128), 2.0f);
}
DemoInputGeomProvider geom = _sample.GetInputGeom();
DemoInputGeomProvider geom = _impl.GetSample().GetInputGeom();
if (geom != null)
{
renderer.DrawOffMeshConnections(geom, true);

View File

@ -13,15 +13,12 @@ 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;
private TestNavmeshToolMode m_toolMode => TestNavmeshToolMode.Values[m_toolModeIdx];
@ -66,12 +63,13 @@ public class TestNavmeshTool : IRcTool
{
return _impl;
}
public void SetSample(Sample sample)
public void OnSampleChanged()
{
_sample = sample;
// ..
}
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
{
if (shift)
@ -169,12 +167,12 @@ public class TestNavmeshTool : IRcTool
private void Recalc()
{
if (_sample.GetNavMesh() == null)
if (_impl.GetSample().GetNavMesh() == null)
{
return;
}
DtNavMeshQuery m_navQuery = _sample.GetNavMeshQuery();
DtNavMeshQuery m_navQuery = _impl.GetSample().GetNavMeshQuery();
if (m_sposSet)
{
m_navQuery.FindNearestPoly(m_spos, m_polyPickExt, m_filter, out m_startRef, out var _, out var _);
@ -193,7 +191,7 @@ public class TestNavmeshTool : IRcTool
m_endRef = 0;
}
DtNavMesh m_navMesh = _sample.GetNavMesh();
DtNavMesh m_navMesh = _impl.GetSample().GetNavMesh();
if (m_toolMode == TestNavmeshToolMode.PATHFIND_FOLLOW)
{
if (m_sposSet && m_eposSet && m_startRef != 0 && m_endRef != 0)
@ -443,7 +441,7 @@ public class TestNavmeshTool : IRcTool
{
float nx = (m_epos.z - m_spos.z) * 0.25f;
float nz = -(m_epos.x - m_spos.x) * 0.25f;
float agentHeight = _sample != null ? _sample.GetSettings().agentHeight : 0;
float agentHeight = _impl.GetSample() != null ? _impl.GetSample().GetSettings().agentHeight : 0;
m_queryPoly[0] = m_spos.x + nx * 1.2f;
m_queryPoly[1] = m_spos.y + agentHeight / 2;
@ -473,7 +471,7 @@ public class TestNavmeshTool : IRcTool
{
if (m_sposSet && m_startRef != 0)
{
m_neighbourhoodRadius = _sample.GetSettings().agentRadius * 20.0f;
m_neighbourhoodRadius = _impl.GetSample().GetSettings().agentRadius * 20.0f;
Result<FindLocalNeighbourhoodResult> result = m_navQuery.FindLocalNeighbourhood(m_startRef, m_spos,
m_neighbourhoodRadius, m_filter);
if (result.Succeeded())
@ -510,7 +508,7 @@ public class TestNavmeshTool : IRcTool
public void HandleRender(NavMeshRenderer renderer)
{
if (_sample == null)
if (_impl.GetSample() == null)
{
return;
}
@ -520,9 +518,9 @@ public class TestNavmeshTool : IRcTool
int endCol = DuRGBA(51, 102, 0, 129);
int pathCol = DuRGBA(0, 0, 0, 64);
float agentRadius = _sample.GetSettings().agentRadius;
float agentHeight = _sample.GetSettings().agentHeight;
float agentClimb = _sample.GetSettings().agentMaxClimb;
float agentRadius = _impl.GetSample().GetSettings().agentRadius;
float agentHeight = _impl.GetSample().GetSettings().agentHeight;
float agentClimb = _impl.GetSample().GetSettings().agentMaxClimb;
if (m_sposSet)
{
@ -536,7 +534,7 @@ public class TestNavmeshTool : IRcTool
dd.DepthMask(true);
DtNavMesh m_navMesh = _sample.GetNavMesh();
DtNavMesh m_navMesh = _impl.GetSample().GetNavMesh();
if (m_navMesh == null)
{
return;
@ -839,9 +837,9 @@ public class TestNavmeshTool : IRcTool
}
dd.DepthMask(true);
if (_sample.GetNavMeshQuery() != null)
if (_impl.GetSample().GetNavMeshQuery() != null)
{
Result<GetPolyWallSegmentsResult> result = _sample.GetNavMeshQuery()
Result<GetPolyWallSegmentsResult> result = _impl.GetSample().GetNavMeshQuery()
.GetPolyWallSegments(m_polys[i], false, m_filter);
if (result.Succeeded())
{
@ -931,9 +929,9 @@ public class TestNavmeshTool : IRcTool
private void DrawAgent(RecastDebugDraw dd, RcVec3f pos, int col)
{
float r = _sample.GetSettings().agentRadius;
float h = _sample.GetSettings().agentHeight;
float c = _sample.GetSettings().agentMaxClimb;
float r = _impl.GetSample().GetSettings().agentRadius;
float h = _impl.GetSample().GetSettings().agentHeight;
float c = _impl.GetSample().GetSettings().agentMaxClimb;
dd.DepthMask(false);
// Agent dimensions.
dd.DebugDrawCylinderWire(pos.x - r, pos.y + 0.02f, pos.z - r, pos.x + r, pos.y + h, pos.z + r, col, 2.0f);
@ -979,7 +977,7 @@ public class TestNavmeshTool : IRcTool
// TODO Auto-generated method stub
if (m_toolMode == TestNavmeshToolMode.PATHFIND_SLICED)
{
DtNavMeshQuery m_navQuery = _sample.GetNavMeshQuery();
DtNavMeshQuery m_navQuery = _impl.GetSample().GetNavMeshQuery();
if (m_pathFindStatus.InProgress())
{
m_pathFindStatus = m_navQuery.UpdateSlicedFindPath(1).status;

View File

@ -95,7 +95,8 @@ public class RcToolsetView : IRcView
public void SetSample(Sample sample)
{
tools.ForEach(t => t.SetSample(sample));
tools.ForEach(t => t.GetTool().SetSample(sample));
tools.ForEach(t => t.OnSampleChanged());
}
public void HandleUpdate(float dt)

View File

@ -3,5 +3,7 @@
public interface ISampleTool
{
string GetName();
void SetSample(Sample sample);
Sample GetSample();
}
}

View File

@ -2,9 +2,22 @@
{
public class ConvexVolumeToolImpl : ISampleTool
{
public string GetName()
{
return "Create Convex Volumes";
}
private Sample _sample;
public void SetSample(Sample sample)
{
_sample = sample;
}
public Sample GetSample()
{
return _sample;
}
}
}

View File

@ -6,5 +6,16 @@
{
return "Crowd";
}
private Sample _sample;
public void SetSample(Sample sample)
{
_sample = sample;
}
public Sample GetSample()
{
return _sample;
}
}
}

View File

@ -6,5 +6,17 @@
{
return "Dynamic Updates";
}
private Sample _sample;
public void SetSample(Sample sample)
{
_sample = sample;
}
public Sample GetSample()
{
return _sample;
}
}
}

View File

@ -6,5 +6,17 @@
{
return "Annotation Builder";
}
private Sample _sample;
public void SetSample(Sample sample)
{
_sample = sample;
}
public Sample GetSample()
{
return _sample;
}
}
}

View File

@ -6,5 +6,17 @@
{
return "Create Off-Mesh Links";
}
private Sample _sample;
public void SetSample(Sample sample)
{
_sample = sample;
}
public Sample GetSample()
{
return _sample;
}
}
}

View File

@ -6,5 +6,17 @@
{
return "Test Navmesh";
}
private Sample _sample;
public void SetSample(Sample sample)
{
_sample = sample;
}
public Sample GetSample()
{
return _sample;
}
}
}