From e053f57571481a1bec3c63bc64ef594e104b868c Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 1 Jul 2023 11:26:56 +0900 Subject: [PATCH] remove Tuple --- .../Tools/DynamicUpdateTool.cs | 64 +++++++++++-------- .../Tools/Gizmos/ColliderWithGizmo.cs | 15 +++++ 2 files changed, 51 insertions(+), 28 deletions(-) create mode 100644 src/DotRecast.Recast.Demo/Tools/Gizmos/ColliderWithGizmo.cs diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index 9a315c4..e54fd48 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -98,7 +98,7 @@ public class DynamicUpdateTool : IRcTool { return _impl; } - + public void OnSampleChanged() { // .. @@ -111,7 +111,7 @@ public class DynamicUpdateTool : IRcTool { if (!shift) { - Tuple colliderWithGizmo = null; + ColliderWithGizmo colliderWithGizmo = null; if (dynaMesh != null) { if (colliderShape == DynamicColliderShape.SPHERE) @@ -150,9 +150,9 @@ public class DynamicUpdateTool : IRcTool if (colliderWithGizmo != null) { - long id = dynaMesh.AddCollider(colliderWithGizmo.Item1); - colliders.Add(id, colliderWithGizmo.Item1); - colliderGizmos.Add(id, colliderWithGizmo.Item2); + long id = dynaMesh.AddCollider(colliderWithGizmo.Collider); + colliders.Add(id, colliderWithGizmo.Collider); + colliderGizmos.Add(id, colliderWithGizmo.Gizmo); } } } @@ -186,15 +186,16 @@ public class DynamicUpdateTool : IRcTool } } - private Tuple SphereCollider(RcVec3f p) + private ColliderWithGizmo SphereCollider(RcVec3f p) { float radius = 1 + (float)random.NextDouble() * 10; - return Tuple.Create( - new SphereCollider(p, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb), - GizmoFactory.Sphere(p, radius)); + var collider = new SphereCollider(p, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb); + var gizmo = GizmoFactory.Sphere(p, radius); + + return new ColliderWithGizmo(collider, gizmo); } - private Tuple CapsuleCollider(RcVec3f p) + private ColliderWithGizmo CapsuleCollider(RcVec3f p) { float radius = 0.4f + (float)random.NextDouble() * 4f; RcVec3f a = RcVec3f.Of( @@ -209,11 +210,12 @@ public class DynamicUpdateTool : IRcTool a.z *= len; RcVec3f start = RcVec3f.Of(p.x, p.y, p.z); RcVec3f end = RcVec3f.Of(p.x + a.x, p.y + a.y, p.z + a.z); - return Tuple.Create(new CapsuleCollider( - start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb), GizmoFactory.Capsule(start, end, radius)); + var collider = new CapsuleCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb); + var gizmo = GizmoFactory.Capsule(start, end, radius); + return new ColliderWithGizmo(collider, gizmo); } - private Tuple BoxCollider(RcVec3f p) + private ColliderWithGizmo BoxCollider(RcVec3f p) { RcVec3f extent = RcVec3f.Of( 0.5f + (float)random.NextDouble() * 6f, @@ -223,11 +225,12 @@ public class DynamicUpdateTool : IRcTool RcVec3f forward = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble())); RcVec3f up = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble())); RcVec3f[] halfEdges = Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(up, forward, extent); - return Tuple.Create( - new BoxCollider(p, halfEdges, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb), GizmoFactory.Box(p, halfEdges)); + var collider = new BoxCollider(p, halfEdges, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb); + var gizmo = GizmoFactory.Box(p, halfEdges); + return new ColliderWithGizmo(collider, gizmo); } - private Tuple CylinderCollider(RcVec3f p) + private ColliderWithGizmo CylinderCollider(RcVec3f p) { float radius = 0.7f + (float)random.NextDouble() * 4f; RcVec3f a = RcVec3f.Of(1f - 2 * (float)random.NextDouble(), 0.01f + (float)random.NextDouble(), 1f - 2 * (float)random.NextDouble()); @@ -238,11 +241,13 @@ public class DynamicUpdateTool : IRcTool a[2] *= len; RcVec3f start = RcVec3f.Of(p.x, p.y, p.z); RcVec3f end = RcVec3f.Of(p.x + a.x, p.y + a.y, p.z + a.z); - return Tuple.Create(new CylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, - dynaMesh.config.walkableClimb), GizmoFactory.Cylinder(start, end, radius)); + var collider = new CylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, dynaMesh.config.walkableClimb); + var gizmo = GizmoFactory.Cylinder(start, end, radius); + + return new ColliderWithGizmo(collider, gizmo); } - private Tuple CompositeCollider(RcVec3f p) + private ColliderWithGizmo CompositeCollider(RcVec3f p) { RcVec3f baseExtent = RcVec3f.Of(5, 3, 8); RcVec3f baseCenter = RcVec3f.Of(p.x, p.y + 3, p.z); @@ -279,33 +284,36 @@ public class DynamicUpdateTool : IRcTool IColliderGizmo trunkGizmo = GizmoFactory.Capsule(trunkStart, trunkEnd, 0.5f); IColliderGizmo crownGizmo = GizmoFactory.Sphere(crownCenter, 4f); IColliderGizmo gizmo = GizmoFactory.Composite(baseGizmo, roofGizmo, trunkGizmo, crownGizmo); - return Tuple.Create(collider, gizmo); + return new ColliderWithGizmo(collider, gizmo); } - private Tuple TrimeshBridge(RcVec3f p) + private ColliderWithGizmo TrimeshBridge(RcVec3f p) { return TrimeshCollider(p, bridgeGeom); } - private Tuple TrimeshHouse(RcVec3f p) + private ColliderWithGizmo TrimeshHouse(RcVec3f p) { return TrimeshCollider(p, houseGeom); } - private Tuple ConvexTrimesh(RcVec3f p) + private ColliderWithGizmo ConvexTrimesh(RcVec3f p) { float[] verts = TransformVertices(p, convexGeom, 360); - ConvexTrimeshCollider collider = new ConvexTrimeshCollider(verts, convexGeom.faces, + var collider = new ConvexTrimeshCollider(verts, convexGeom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, dynaMesh.config.walkableClimb * 10); - return Tuple.Create(collider, GizmoFactory.Trimesh(verts, convexGeom.faces)); + var gizmo = GizmoFactory.Trimesh(verts, convexGeom.faces); + return new ColliderWithGizmo(collider, gizmo); } - private Tuple TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom) + private ColliderWithGizmo TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom) { float[] verts = TransformVertices(p, geom, 0); - TrimeshCollider collider = new TrimeshCollider(verts, geom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, + var collider = new TrimeshCollider(verts, geom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, dynaMesh.config.walkableClimb * 10); - return Tuple.Create(collider, GizmoFactory.Trimesh(verts, geom.faces)); + var gizmo = GizmoFactory.Trimesh(verts, geom.faces); + + return new ColliderWithGizmo(collider, gizmo); } private float[] TransformVertices(RcVec3f p, DemoInputGeomProvider geom, float ax) diff --git a/src/DotRecast.Recast.Demo/Tools/Gizmos/ColliderWithGizmo.cs b/src/DotRecast.Recast.Demo/Tools/Gizmos/ColliderWithGizmo.cs new file mode 100644 index 0000000..96be8bd --- /dev/null +++ b/src/DotRecast.Recast.Demo/Tools/Gizmos/ColliderWithGizmo.cs @@ -0,0 +1,15 @@ +using DotRecast.Detour.Dynamic.Colliders; + +namespace DotRecast.Recast.Demo.Tools.Gizmos; + +public class ColliderWithGizmo +{ + public readonly ICollider Collider; + public readonly IColliderGizmo Gizmo; + + public ColliderWithGizmo(ICollider collider, IColliderGizmo gizmo) + { + Collider = collider; + Gizmo = gizmo; + } +} \ No newline at end of file