diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 884cc28..207ca23 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using Silk.NET.Windowing; using DotRecast.Core; using DotRecast.Detour; using DotRecast.Recast.Demo.Builder; @@ -16,11 +15,11 @@ public class TestNavmeshTool : Tool { private const int MAX_POLYS = 256; private const int MAX_SMOOTH = 2048; - + private Sample m_sample; - private int toolModeIdx = -1; - private TestNavmeshToolMode m_toolMode = TestNavmeshToolMode.PATHFIND_FOLLOW; + private int m_toolModeIdx = TestNavmeshToolMode.PATHFIND_FOLLOW.Idx; + private TestNavmeshToolMode m_toolMode => TestNavmeshToolMode.Values[m_toolModeIdx]; private bool m_sposSet; private bool m_eposSet; private float[] m_spos; @@ -45,6 +44,8 @@ public class TestNavmeshTool : Tool private readonly List randomPoints = new(); private bool constrainByCircle; + private int includeFlags = SampleAreaModifications.SAMPLE_POLYFLAGS_ALL; + private int excludeFlags = 0; public TestNavmeshTool() { @@ -75,7 +76,7 @@ public class TestNavmeshTool : Tool public override void layout() { - TestNavmeshToolMode previousToolMode = m_toolMode; + var previousToolMode = m_toolMode; int previousStraightPathOptions = m_straightPathOptions; int previousIncludeFlags = m_filter.getIncludeFlags(); int previousExcludeFlags = m_filter.getExcludeFlags(); @@ -83,104 +84,71 @@ public class TestNavmeshTool : Tool ImGui.Text("Mode"); ImGui.Separator(); - ImGui.RadioButton("Pathfind Follow", ref toolModeIdx, (int)TestNavmeshToolMode.PATHFIND_FOLLOW); - ImGui.RadioButton("Pathfind Straight", ref toolModeIdx, (int)TestNavmeshToolMode.PATHFIND_STRAIGHT); - ImGui.RadioButton("Pathfind Sliced", ref toolModeIdx, (int)TestNavmeshToolMode.PATHFIND_SLICED); - ImGui.RadioButton("Distance to Wall", ref toolModeIdx, (int)TestNavmeshToolMode.DISTANCE_TO_WALL); - ImGui.RadioButton("Raycast", ref toolModeIdx, (int)TestNavmeshToolMode.RAYCAST); - ImGui.RadioButton("Find Polys in Circle", ref toolModeIdx, (int)TestNavmeshToolMode.FIND_POLYS_IN_CIRCLE); - ImGui.RadioButton("Find Polys in Shape", ref toolModeIdx, (int)TestNavmeshToolMode.FIND_POLYS_IN_SHAPE); - ImGui.RadioButton("Find Local Neighbourhood", ref toolModeIdx, (int)TestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD); - ImGui.RadioButton("Random Points in Circle", ref toolModeIdx, (int)TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE); + ImGui.RadioButton(TestNavmeshToolMode.PATHFIND_FOLLOW.Label, ref m_toolModeIdx, TestNavmeshToolMode.PATHFIND_FOLLOW.Idx); + ImGui.RadioButton(TestNavmeshToolMode.PATHFIND_STRAIGHT.Label, ref m_toolModeIdx, TestNavmeshToolMode.PATHFIND_STRAIGHT.Idx); + ImGui.RadioButton(TestNavmeshToolMode.PATHFIND_SLICED.Label, ref m_toolModeIdx, TestNavmeshToolMode.PATHFIND_SLICED.Idx); + ImGui.RadioButton(TestNavmeshToolMode.DISTANCE_TO_WALL.Label, ref m_toolModeIdx, TestNavmeshToolMode.DISTANCE_TO_WALL.Idx); + ImGui.RadioButton(TestNavmeshToolMode.RAYCAST.Label, ref m_toolModeIdx, TestNavmeshToolMode.RAYCAST.Idx); + ImGui.RadioButton(TestNavmeshToolMode.FIND_POLYS_IN_CIRCLE.Label, ref m_toolModeIdx, TestNavmeshToolMode.FIND_POLYS_IN_CIRCLE.Idx); + ImGui.RadioButton(TestNavmeshToolMode.FIND_POLYS_IN_SHAPE.Label, ref m_toolModeIdx, TestNavmeshToolMode.FIND_POLYS_IN_SHAPE.Idx); + ImGui.RadioButton(TestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD.Label, ref m_toolModeIdx, TestNavmeshToolMode.FIND_LOCAL_NEIGHBOURHOOD.Idx); + ImGui.RadioButton(TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE.Label, ref m_toolModeIdx, TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE.Idx); + ImGui.NewLine(); + + // selecting mode + ImGui.Text(m_toolMode.Label); + ImGui.Separator(); ImGui.NewLine(); - if (toolModeIdx == (int)TestNavmeshToolMode.PATHFIND_FOLLOW) + if (m_toolMode == TestNavmeshToolMode.PATHFIND_FOLLOW) { - } - if (toolModeIdx == (int)TestNavmeshToolMode.PATHFIND_STRAIGHT) + if (m_toolMode == TestNavmeshToolMode.PATHFIND_STRAIGHT) { - // m_toolMode = TestNavmeshToolMode.PATHFIND_STRAIGHT; - // nk_layout_row_dynamic(ctx, 20, 1); ImGui.Text("Vertices at crossings"); - // nk_layout_row_dynamic(ctx, 20, 1); - // if (nk_option_label(ctx, "None", m_straightPathOptions == 0)) { - // m_straightPathOptions = 0; - // } - // nk_layout_row_dynamic(ctx, 20, 1); - // if (nk_option_label(ctx, "Area", m_straightPathOptions == NavMeshQuery.DT_STRAIGHTPATH_AREA_CROSSINGS)) { - // m_straightPathOptions = NavMeshQuery.DT_STRAIGHTPATH_AREA_CROSSINGS; - // } - // nk_layout_row_dynamic(ctx, 20, 1); - // if (nk_option_label(ctx, "All", m_straightPathOptions == NavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS)) { - // m_straightPathOptions = NavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS; - // } - // nk_layout_row_dynamic(ctx, 5, 1); - // nk_spacing(ctx, 1); + ImGui.Separator(); + ImGui.RadioButton("None", ref m_straightPathOptions, 0); + ImGui.RadioButton("Area", ref m_straightPathOptions, NavMeshQuery.DT_STRAIGHTPATH_AREA_CROSSINGS); + ImGui.RadioButton("All", ref m_straightPathOptions, NavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS); } - if (toolModeIdx == (int)TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) + if (m_toolMode == TestNavmeshToolMode.RANDOM_POINTS_IN_CIRCLE) { - // constrainByCircle = nk_check_text(ctx, "Constrained", constrainByCircle); + ImGui.Checkbox("Constrained", ref constrainByCircle); } - // nk_layout_row_dynamic(ctx, 5, 1); - // nk_spacing(ctx, 1); - // nk_layout_row_dynamic(ctx, 20, 1); + + ImGui.Text("Common"); + ImGui.Separator(); + ImGui.Text("Include Flags"); - // nk_layout_row_dynamic(ctx, 20, 1); - // int includeFlags = 0; - // if (nk_option_label(ctx, "Walk", - // (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_WALK) != 0)) { - // includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_WALK; - // } - // if (nk_option_label(ctx, "Swim", - // (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM) != 0)) { - // includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM; - // } - // if (nk_option_label(ctx, "Door", - // (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR) != 0)) { - // includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR; - // } - // if (nk_option_label(ctx, "Jump", - // (m_filter.getIncludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP) != 0)) { - // includeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP; - // } - // m_filter.setIncludeFlags(includeFlags); - // - // nk_layout_row_dynamic(ctx, 5, 1); - // nk_spacing(ctx, 1); - // nk_layout_row_dynamic(ctx, 20, 1); + ImGui.Separator(); + ImGui.CheckboxFlags("Walk", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_WALK); + ImGui.CheckboxFlags("Swim", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM); + ImGui.CheckboxFlags("Door", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR); + ImGui.CheckboxFlags("Jump", ref includeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP); + ImGui.NewLine(); + + m_filter.setIncludeFlags(includeFlags); + ImGui.Text("Exclude Flags"); - // nk_layout_row_dynamic(ctx, 20, 1); - // int excludeFlags = 0; - // if (nk_option_label(ctx, "Walk", - // (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_WALK) != 0)) { - // excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_WALK; - // } - // if (nk_option_label(ctx, "Swim", - // (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM) != 0)) { - // excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM; - // } - // if (nk_option_label(ctx, "Door", - // (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR) != 0)) { - // excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR; - // } - // if (nk_option_label(ctx, "Jump", - // (m_filter.getExcludeFlags() & SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP) != 0)) { - // excludeFlags |= SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP; - // } - // m_filter.setExcludeFlags(excludeFlags); - // - // nk_layout_row_dynamic(ctx, 30, 1); - // bool previousEnableRaycast = enableRaycast; - // enableRaycast = nk_check_label(ctx, "Raycast shortcuts", enableRaycast); - // - // if (previousToolMode != m_toolMode || m_straightPathOptions != previousStraightPathOptions - // || previousIncludeFlags != includeFlags || previousExcludeFlags != excludeFlags - // || previousEnableRaycast != enableRaycast || previousConstrainByCircle != constrainByCircle) { - // recalc(); - // } + ImGui.Separator(); + ImGui.CheckboxFlags("Walk", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_WALK); + ImGui.CheckboxFlags("Swim", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM); + ImGui.CheckboxFlags("Door", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR); + ImGui.CheckboxFlags("Jump", ref excludeFlags, SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP); + ImGui.NewLine(); + + m_filter.setExcludeFlags(excludeFlags); + + bool previousEnableRaycast = enableRaycast; + ImGui.Checkbox("Raycast shortcuts", ref enableRaycast); + + if (previousToolMode != m_toolMode || m_straightPathOptions != previousStraightPathOptions + || previousIncludeFlags != includeFlags || previousExcludeFlags != excludeFlags + || previousEnableRaycast != enableRaycast || previousConstrainByCircle != constrainByCircle) { + recalc(); + } } public override string getName() diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs index be77e26..71bc62d 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshToolMode.cs @@ -1,14 +1,38 @@ -namespace DotRecast.Recast.Demo.Tools; +using System.Collections.Immutable; -public enum TestNavmeshToolMode +namespace DotRecast.Recast.Demo.Tools; + +public class TestNavmeshToolMode { - PATHFIND_FOLLOW, - PATHFIND_STRAIGHT, - PATHFIND_SLICED, - DISTANCE_TO_WALL, - RAYCAST, - FIND_POLYS_IN_CIRCLE, - FIND_POLYS_IN_SHAPE, - FIND_LOCAL_NEIGHBOURHOOD, - RANDOM_POINTS_IN_CIRCLE -} + public static readonly TestNavmeshToolMode PATHFIND_FOLLOW = new(0, "Pathfind Follow"); + public static readonly TestNavmeshToolMode PATHFIND_STRAIGHT = new(1, "Pathfind Straight"); + public static readonly TestNavmeshToolMode PATHFIND_SLICED = new(2, "Pathfind Sliced"); + public static readonly TestNavmeshToolMode DISTANCE_TO_WALL = new(3, "Distance to Wall"); + public static readonly TestNavmeshToolMode RAYCAST = new(4, "Raycast"); + public static readonly TestNavmeshToolMode FIND_POLYS_IN_CIRCLE = new(5, "Find Polys in Circle"); + public static readonly TestNavmeshToolMode FIND_POLYS_IN_SHAPE = new(6, "Find Polys in Shape"); + public static readonly TestNavmeshToolMode FIND_LOCAL_NEIGHBOURHOOD = new(7, "Find Local Neighbourhood"); + public static readonly TestNavmeshToolMode RANDOM_POINTS_IN_CIRCLE = new(8, "Random Points in Circle"); + + public static readonly ImmutableArray Values = ImmutableArray.Create( + PATHFIND_FOLLOW, + PATHFIND_STRAIGHT, + PATHFIND_SLICED, + DISTANCE_TO_WALL, + RAYCAST, + FIND_POLYS_IN_CIRCLE, + FIND_POLYS_IN_SHAPE, + FIND_LOCAL_NEIGHBOURHOOD, + RANDOM_POINTS_IN_CIRCLE + ); + + + public int Idx { get; } + public string Label { get; } + + private TestNavmeshToolMode(int idx, string label) + { + Idx = idx; + Label = label; + } +} \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/ToolsView.cs b/src/DotRecast.Recast.Demo/Tools/ToolsView.cs index 6c30067..4d6d31a 100644 --- a/src/DotRecast.Recast.Demo/Tools/ToolsView.cs +++ b/src/DotRecast.Recast.Demo/Tools/ToolsView.cs @@ -27,7 +27,7 @@ namespace DotRecast.Recast.Demo.Tools; public class ToolsView : IRcView { //private readonly NkColor white = NkColor.create(); - private int _currentToolIdx = -1; + private int _currentToolIdx = 0; private Tool currentTool; private bool enabled; private readonly Tool[] tools;