Preparing for integration as ViewSystem

This commit is contained in:
ikpil 2023-03-14 23:56:10 +09:00
parent 85e74dad92
commit 540845cff3
10 changed files with 54 additions and 71 deletions

View File

@ -49,13 +49,13 @@ public class NavMeshRenderer {
DemoInputGeomProvider geom = sample.getInputGeom(); DemoInputGeomProvider geom = sample.getInputGeom();
IList<RecastBuilderResult> rcBuilderResults = sample.getRecastResults(); IList<RecastBuilderResult> rcBuilderResults = sample.getRecastResults();
NavMesh navMesh = sample.getNavMesh(); NavMesh navMesh = sample.getNavMesh();
SettingsUI settingsUI = sample.getSettingsUI(); RcSettingsView rcSettingsView = sample.getSettingsUI();
debugDraw.fog(true); debugDraw.fog(true);
debugDraw.depthMask(true); debugDraw.depthMask(true);
DrawMode drawMode = settingsUI.getDrawMode(); DrawMode drawMode = rcSettingsView.getDrawMode();
float texScale = 1.0f / (settingsUI.getCellSize() * 10.0f); float texScale = 1.0f / (rcSettingsView.getCellSize() * 10.0f);
float m_agentMaxSlope = settingsUI.getAgentMaxSlope(); float m_agentMaxSlope = rcSettingsView.getAgentMaxSlope();
if (drawMode != DrawMode.DRAWMODE_NAVMESH_TRANS) { if (drawMode != DrawMode.DRAWMODE_NAVMESH_TRANS) {
// Draw mesh // Draw mesh

View File

@ -0,0 +1,10 @@
namespace DotRecast.Recast.Demo;
public static class Program
{
public static void Main(string[] args)
{
var demo = new RecastDemo();
demo.start();
}
}

View File

@ -51,7 +51,7 @@ namespace DotRecast.Recast.Demo;
public class RecastDemo : MouseListener public class RecastDemo : MouseListener
{ {
private readonly ILogger logger = Log.ForContext<RecastDemo>(); private readonly ILogger logger = Log.ForContext<RecastDemo>();
private NuklearUI nuklearUI; private RcViewSystem _viewSys;
private IWindow window; private IWindow window;
private IInputContext _input; private IInputContext _input;
private ImGuiController _imgui; private ImGuiController _imgui;
@ -95,7 +95,7 @@ public class RecastDemo : MouseListener
private bool markerPositionSet; private bool markerPositionSet;
private readonly float[] markerPosition = new float[3]; private readonly float[] markerPosition = new float[3];
private ToolsUI toolsUI; private ToolsUI toolsUI;
private SettingsUI settingsUI; private RcSettingsView _rcSettingsView;
private long prevFrameTime; private long prevFrameTime;
public RecastDemo() public RecastDemo()
@ -378,7 +378,7 @@ public class RecastDemo : MouseListener
window.CreateInput(); window.CreateInput();
settingsUI = new SettingsUI(); _rcSettingsView = new RcSettingsView();
toolsUI = new ToolsUI( toolsUI = new ToolsUI(
new TestNavmeshTool(), new TestNavmeshTool(),
new OffMeshConnectionTool(), new OffMeshConnectionTool(),
@ -387,7 +387,7 @@ public class RecastDemo : MouseListener
new JumpLinkBuilderTool(), new JumpLinkBuilderTool(),
new DynamicUpdateTool()); new DynamicUpdateTool());
nuklearUI = new NuklearUI(window, _input, settingsUI, toolsUI); _viewSys = new RcViewSystem(window, _input, _rcSettingsView, toolsUI);
DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj")); DemoInputGeomProvider geom = loadInputMesh(Loader.ToBytes("nav_test.obj"));
//sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd); //sample = new Sample(geom, ImmutableArray<RecastBuilderResult>.Empty, null, settingsUI, dd);
@ -410,9 +410,9 @@ public class RecastDemo : MouseListener
// settingsUI.setMaxPolys(tileNavMeshBuilder.getMaxPolysPerTile(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize())); // settingsUI.setMaxPolys(tileNavMeshBuilder.getMaxPolysPerTile(sample.getInputGeom(), settingsUI.getCellSize(), settingsUI.getTileSize()));
// } // }
nuklearUI.inputBegin(); _viewSys.inputBegin();
window.DoEvents(); window.DoEvents();
nuklearUI.inputEnd(window); _viewSys.inputEnd(window);
long time = Stopwatch.GetTimestamp() / 1000; long time = Stopwatch.GetTimestamp() / 1000;
//float dt = (time - prevFrameTime) / 1000000.0f; //float dt = (time - prevFrameTime) / 1000000.0f;
@ -446,7 +446,7 @@ public class RecastDemo : MouseListener
//mouseOverMenu = nuklearUI.layout(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); //mouseOverMenu = nuklearUI.layout(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]);
if (settingsUI.isMeshInputTrigerred()) if (_rcSettingsView.isMeshInputTrigerred())
{ {
// aFilterPatterns.put(stack.UTF8("*.obj")); // aFilterPatterns.put(stack.UTF8("*.obj"));
// aFilterPatterns.flip(); // aFilterPatterns.flip();
@ -460,7 +460,7 @@ public class RecastDemo : MouseListener
// } // }
// } // }
} }
else if (settingsUI.isNavMeshInputTrigerred()) else if (_rcSettingsView.isNavMeshInputTrigerred())
{ {
// try (MemoryStack stack = stackPush()) { // try (MemoryStack stack = stackPush()) {
// PointerBuffer aFilterPatterns = stack.mallocPointer(4); // PointerBuffer aFilterPatterns = stack.mallocPointer(4);
@ -664,9 +664,8 @@ public class RecastDemo : MouseListener
private unsafe void OnWindowOnRender(double dt) private unsafe void OnWindowOnRender(double dt)
{ {
_gl.Clear(ClearBufferMask.ColorBufferBit); _gl.Clear(ClearBufferMask.ColorBufferBit);
// Render GUI
//mouseOverMenu = nuklearUI.layout(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]); mouseOverMenu = _viewSys.render(window, 0, 0, width, height, (int)mousePos[0], (int)mousePos[1]);
//nuklearUI.render();
ImGui.Button("hello"); ImGui.Button("hello");
ImGui.Button("world"); ImGui.Button("world");
@ -674,13 +673,7 @@ public class RecastDemo : MouseListener
} }
public static void Main(string[] args) private void ErrorCallback(Silk.NET.GLFW.ErrorCode code, string message)
{
var demo = new RecastDemo();
demo.start();
}
private static void ErrorCallback(Silk.NET.GLFW.ErrorCode code, string message)
{ {
Console.WriteLine($"GLFW error [{code}]: {message}"); Console.WriteLine($"GLFW error [{code}]: {message}");
} }

View File

@ -30,16 +30,16 @@ public class Sample {
private DemoInputGeomProvider inputGeom; private DemoInputGeomProvider inputGeom;
private NavMesh navMesh; private NavMesh navMesh;
private NavMeshQuery navMeshQuery; private NavMeshQuery navMeshQuery;
private readonly SettingsUI settingsUI; private readonly RcSettingsView _rcSettingsView;
private IList<RecastBuilderResult> recastResults; private IList<RecastBuilderResult> recastResults;
private bool changed; private bool changed;
public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, NavMesh navMesh, public Sample(DemoInputGeomProvider inputGeom, IList<RecastBuilderResult> recastResults, NavMesh navMesh,
SettingsUI settingsUI, RecastDebugDraw debugDraw) { RcSettingsView rcSettingsView, RecastDebugDraw debugDraw) {
this.inputGeom = inputGeom; this.inputGeom = inputGeom;
this.recastResults = recastResults; this.recastResults = recastResults;
this.navMesh = navMesh; this.navMesh = navMesh;
this.settingsUI = settingsUI; this._rcSettingsView = rcSettingsView;
setQuery(navMesh); setQuery(navMesh);
changed = true; changed = true;
} }
@ -60,8 +60,8 @@ public class Sample {
return navMesh; return navMesh;
} }
public SettingsUI getSettingsUI() { public RcSettingsView getSettingsUI() {
return settingsUI; return _rcSettingsView;
} }
public NavMeshQuery getNavMeshQuery() { public NavMeshQuery getNavMeshQuery() {

View File

@ -16,16 +16,13 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
using System;
using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.Draw;
using DotRecast.Recast.Demo.UI; using DotRecast.Recast.Demo.UI;
using ImGuiNET;
using Silk.NET.OpenGL.Extensions.ImGui;
using Silk.NET.Windowing; using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.Settings; namespace DotRecast.Recast.Demo.Settings;
public class SettingsUI : NuklearUIModule { public class RcSettingsView : IRcView {
private readonly float[] cellSize = new[] { 0.3f }; private readonly float[] cellSize = new[] { 0.3f };
private readonly float[] cellHeight = new[] { 0.2f }; private readonly float[] cellHeight = new[] { 0.2f };
@ -68,7 +65,7 @@ public class SettingsUI : NuklearUIModule {
private bool meshInputTrigerred; private bool meshInputTrigerred;
private bool navMeshInputTrigerred; private bool navMeshInputTrigerred;
public bool layout(IWindow i, int x, int y, int width, int height, int mouseX, int mouseY) { public bool render(IWindow i, int x, int y, int width, int height, int mouseX, int mouseY) {
bool mouseInside = false; bool mouseInside = false;
// nk_rgb(255, 255, 255, white); // nk_rgb(255, 255, 255, white);
// nk_rgba(0, 0, 0, 192, background); // nk_rgba(0, 0, 0, 192, background);
@ -212,43 +209,35 @@ public class SettingsUI : NuklearUIModule {
} }
public float getCellSize() { public float getCellSize() {
//return cellSize[0]; return cellSize[0];
return 0;
} }
public float getCellHeight() { public float getCellHeight() {
//return cellHeight[0]; return cellHeight[0];
return 0;
} }
public float getAgentHeight() { public float getAgentHeight() {
//return agentHeight[0]; return agentHeight[0];
return 0;
} }
public float getAgentRadius() { public float getAgentRadius() {
//return agentRadius[0]; return agentRadius[0];
return 0;
} }
public float getAgentMaxClimb() { public float getAgentMaxClimb() {
//return agentMaxClimb[0]; return agentMaxClimb[0];
return 0;
} }
public float getAgentMaxSlope() { public float getAgentMaxSlope() {
//return agentMaxSlope[0]; return agentMaxSlope[0];
return 0;
} }
public int getMinRegionSize() { public int getMinRegionSize() {
//return minRegionSize[0]; return minRegionSize[0];
return 0;
} }
public int getMergedRegionSize() { public int getMergedRegionSize() {
//return mergedRegionSize[0]; return mergedRegionSize[0];
return 0;
} }
public PartitionType getPartitioning() { public PartitionType getPartitioning() {

View File

@ -23,7 +23,7 @@ using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.Tools; namespace DotRecast.Recast.Demo.Tools;
public class ToolsUI : NuklearUIModule { public class ToolsUI : IRcView {
//private readonly NkColor white = NkColor.create(); //private readonly NkColor white = NkColor.create();
private Tool currentTool; private Tool currentTool;
@ -34,7 +34,7 @@ public class ToolsUI : NuklearUIModule {
this.tools = tools; this.tools = tools;
} }
public bool layout(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) { public bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) {
bool mouseInside = false; bool mouseInside = false;
// nk_rgb(255, 255, 255, white); // nk_rgb(255, 255, 255, white);
// try (MemoryStack stack = stackPush()) { // try (MemoryStack stack = stackPush()) {

View File

@ -20,10 +20,7 @@ using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.UI; namespace DotRecast.Recast.Demo.UI;
public interface IRcView {
bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY);
public interface NuklearUIModule {
bool layout(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY);
} }

View File

@ -33,7 +33,7 @@ public class NuklearGL {
private static readonly int FONT_BITMAP_H = 1024; private static readonly int FONT_BITMAP_H = 1024;
private static readonly int FONT_HEIGHT = 15; private static readonly int FONT_HEIGHT = 15;
private readonly NuklearUI context; private readonly RcViewSystem context;
// private readonly NkDrawNullTexture null_texture = NkDrawNullTexture.create(); // private readonly NkDrawNullTexture null_texture = NkDrawNullTexture.create();
// private readonly NkBuffer cmds = NkBuffer.create(); // private readonly NkBuffer cmds = NkBuffer.create();
// private readonly NkUserFont default_font; // private readonly NkUserFont default_font;
@ -45,7 +45,7 @@ public class NuklearGL {
private readonly int vao; private readonly int vao;
//private readonly Buffer vertexLayout; //private readonly Buffer vertexLayout;
public NuklearGL(NuklearUI context) { public NuklearGL(RcViewSystem context) {
this.context = context; this.context = context;
// nk_buffer_init(cmds, context.allocator, BUFFER_INITIAL_SIZE); // nk_buffer_init(cmds, context.allocator, BUFFER_INITIAL_SIZE);
// vertexLayout = NkDrawVertexLayoutElement.create(4)// // vertexLayout = NkDrawVertexLayoutElement.create(4)//

View File

@ -18,23 +18,22 @@ freely, subject to the following restrictions:
using Silk.NET.Input; using Silk.NET.Input;
using Silk.NET.OpenGL; using Silk.NET.OpenGL;
using Silk.NET.OpenGL.Extensions.ImGui;
using Silk.NET.Windowing; using Silk.NET.Windowing;
namespace DotRecast.Recast.Demo.UI; namespace DotRecast.Recast.Demo.UI;
public class NuklearUI { public class RcViewSystem {
// readonly NkAllocator allocator; // readonly NkAllocator allocator;
private readonly IWindow _window; private readonly IWindow _window;
private readonly GL _gl; private readonly GL _gl;
// readonly NkColor background; // readonly NkColor background;
// readonly NkColor white; // readonly NkColor white;
private readonly NuklearUIModule[] _modules; private readonly IRcView[] _views;
private readonly NuklearGL glContext; private readonly NuklearGL glContext;
private bool mouseOverUI; private bool mouseOverUI;
public NuklearUI(IWindow window, IInputContext input, params NuklearUIModule[] modules) public RcViewSystem(IWindow window, IInputContext input, params IRcView[] views)
{ {
var mouse = new Mouse(input); var mouse = new Mouse(input);
_window = window; _window = window;
@ -58,7 +57,7 @@ public class NuklearUI {
// setupClipboard(window); // setupClipboard(window);
// glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint)); // glfwSetCharCallback(window, (w, codepoint) => nk_input_unicode(ctx, codepoint));
// glContext = new NuklearGL(this); // glContext = new NuklearGL(this);
_modules = modules; _views = views;
} }
private void setupMouse(Mouse mouse) { private void setupMouse(Mouse mouse) {
@ -139,11 +138,11 @@ public class NuklearUI {
// } // }
// nk_input_end(ctx); // nk_input_end(ctx);
} }
public bool layout(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) { public bool render(IWindow ctx, int x, int y, int width, int height, int mouseX, int mouseY) {
mouseOverUI = false; mouseOverUI = false;
foreach (NuklearUIModule m in _modules) { foreach (IRcView m in _views) {
mouseOverUI = m.layout(ctx, x, y, width, height, mouseX, mouseY) | mouseOverUI; mouseOverUI = m.render(ctx, x, y, width, height, mouseX, mouseY) | mouseOverUI;
} }
return mouseOverUI; return mouseOverUI;
} }

View File

@ -1,5 +0,0 @@
[Window][Debug##Default]
Pos=280,129
Size=400,400
Collapsed=0