forked from mirror/DotRecast
rename RecastDemoCanvas
This commit is contained in:
parent
98cdbd7d20
commit
f835a14563
|
@ -33,7 +33,12 @@ public static class Program
|
||||||
outputTemplate: format)
|
outputTemplate: format)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
|
|
||||||
|
Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Run()
|
||||||
|
{
|
||||||
var demo = new RecastDemo();
|
var demo = new RecastDemo();
|
||||||
demo.start();
|
demo.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,7 +38,6 @@ using DotRecast.Detour.Io;
|
||||||
using DotRecast.Recast.Demo.Builder;
|
using DotRecast.Recast.Demo.Builder;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using DotRecast.Recast.Demo.Geom;
|
using DotRecast.Recast.Demo.Geom;
|
||||||
|
|
||||||
using DotRecast.Recast.Demo.Tools;
|
using DotRecast.Recast.Demo.Tools;
|
||||||
using DotRecast.Recast.Demo.UI;
|
using DotRecast.Recast.Demo.UI;
|
||||||
using static DotRecast.Core.RecastMath;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
@ -50,11 +49,12 @@ public class RecastDemo
|
||||||
{
|
{
|
||||||
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
||||||
|
|
||||||
private RcCanvas _canvas;
|
|
||||||
private IWindow window;
|
private IWindow window;
|
||||||
|
private GL _gl;
|
||||||
private IInputContext _input;
|
private IInputContext _input;
|
||||||
private ImGuiController _imgui;
|
private ImGuiController _imgui;
|
||||||
private GL _gl;
|
private RecastDemoCanvas _canvas;
|
||||||
|
|
||||||
private int width = 1000;
|
private int width = 1000;
|
||||||
private int height = 900;
|
private int height = 900;
|
||||||
|
|
||||||
|
@ -107,11 +107,11 @@ public class RecastDemo
|
||||||
private int[] viewport;
|
private int[] viewport;
|
||||||
private bool markerPositionSet;
|
private bool markerPositionSet;
|
||||||
private Vector3f markerPosition = new Vector3f();
|
private Vector3f markerPosition = new Vector3f();
|
||||||
|
|
||||||
private ToolsView toolsUI;
|
private ToolsView toolsUI;
|
||||||
private RcSettingsView settingsUI;
|
private RcSettingsView settingsUI;
|
||||||
private RcLogView logUI;
|
private RcLogView logUI;
|
||||||
|
|
||||||
private long prevFrameTime;
|
private long prevFrameTime;
|
||||||
private RecastDebugDraw dd;
|
private RecastDebugDraw dd;
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ public class RecastDemo
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start()
|
public void Run()
|
||||||
{
|
{
|
||||||
window = CreateWindow();
|
window = CreateWindow();
|
||||||
window.Run();
|
window.Run();
|
||||||
|
@ -266,7 +266,7 @@ public class RecastDemo
|
||||||
options.Title = title;
|
options.Title = title;
|
||||||
options.Size = new Vector2D<int>(width, height);
|
options.Size = new Vector2D<int>(width, height);
|
||||||
options.Position = new Vector2D<int>((resolution.X - width) / 2, (resolution.Y - height) / 2);
|
options.Position = new Vector2D<int>((resolution.X - width) / 2, (resolution.Y - height) / 2);
|
||||||
options.VSync = false;
|
options.VSync = true;
|
||||||
options.ShouldSwapAutomatically = false;
|
options.ShouldSwapAutomatically = false;
|
||||||
options.PreferredDepthBufferBits = 24;
|
options.PreferredDepthBufferBits = 24;
|
||||||
window = Window.Create(options);
|
window = Window.Create(options);
|
||||||
|
@ -280,8 +280,8 @@ public class RecastDemo
|
||||||
window.Load += OnWindowOnLoad;
|
window.Load += OnWindowOnLoad;
|
||||||
window.Resize += OnWindowResize;
|
window.Resize += OnWindowResize;
|
||||||
window.FramebufferResize += OnWindowFramebufferSizeChanged;
|
window.FramebufferResize += OnWindowFramebufferSizeChanged;
|
||||||
window.Update += OnWindowOnUpdate;
|
window.Update += OnWindowUpdate;
|
||||||
window.Render += OnWindowOnRender;
|
window.Render += OnWindowRender;
|
||||||
|
|
||||||
|
|
||||||
// // -- move somewhere else:
|
// // -- move somewhere else:
|
||||||
|
@ -366,7 +366,7 @@ public class RecastDemo
|
||||||
dd.init(camr);
|
dd.init(camr);
|
||||||
|
|
||||||
_imgui = new ImGuiController(_gl, window, _input);
|
_imgui = new ImGuiController(_gl, window, _input);
|
||||||
|
|
||||||
settingsUI = new RcSettingsView();
|
settingsUI = new RcSettingsView();
|
||||||
toolsUI = new ToolsView(
|
toolsUI = new ToolsView(
|
||||||
new TestNavmeshTool(),
|
new TestNavmeshTool(),
|
||||||
|
@ -378,13 +378,13 @@ public class RecastDemo
|
||||||
);
|
);
|
||||||
logUI = new RcLogView();
|
logUI = new RcLogView();
|
||||||
|
|
||||||
_canvas = new RcCanvas(window, settingsUI, toolsUI, logUI);
|
_canvas = new RecastDemoCanvas(window, settingsUI, toolsUI, logUI);
|
||||||
|
|
||||||
var vendor = _gl.GetStringS(GLEnum.Vendor);
|
var vendor = _gl.GetStringS(GLEnum.Vendor);
|
||||||
var version = _gl.GetStringS(GLEnum.Version);
|
var version = _gl.GetStringS(GLEnum.Version);
|
||||||
var renderGl = _gl.GetStringS(GLEnum.Renderer);
|
var renderGl = _gl.GetStringS(GLEnum.Renderer);
|
||||||
var glslString = _gl.GetStringS(GLEnum.ShadingLanguageVersion);
|
var glslString = _gl.GetStringS(GLEnum.ShadingLanguageVersion);
|
||||||
|
|
||||||
Logger.Debug(vendor);
|
Logger.Debug(vendor);
|
||||||
Logger.Debug(version);
|
Logger.Debug(version);
|
||||||
Logger.Debug(renderGl);
|
Logger.Debug(renderGl);
|
||||||
|
@ -419,7 +419,7 @@ public class RecastDemo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnWindowOnUpdate(double dt)
|
private void OnWindowUpdate(double dt)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* try (MemoryStack stack = stackPush()) { int[] w = stack.mallocInt(1); int[] h =
|
* try (MemoryStack stack = stackPush()) { int[] w = stack.mallocInt(1); int[] h =
|
||||||
|
@ -483,9 +483,8 @@ public class RecastDemo
|
||||||
var bytes = Loader.ToBytes(settingsUI.GetMeshInputFilePath());
|
var bytes = Loader.ToBytes(settingsUI.GetMeshInputFilePath());
|
||||||
sample.update(loadInputMesh(bytes), null, null);
|
sample.update(loadInputMesh(bytes), null, null);
|
||||||
}
|
}
|
||||||
|
else if (settingsUI.isNavMeshInputTrigerred())
|
||||||
// else if (settingsUI.isNavMeshInputTrigerred())
|
{
|
||||||
// {
|
|
||||||
// try (MemoryStack stack = stackPush()) {
|
// try (MemoryStack stack = stackPush()) {
|
||||||
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
// PointerBuffer aFilterPatterns = stack.mallocPointer(4);
|
||||||
// aFilterPatterns.put(stack.UTF8("*.bin"));
|
// aFilterPatterns.put(stack.UTF8("*.bin"));
|
||||||
|
@ -507,7 +506,7 @@ public class RecastDemo
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
}
|
||||||
if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
|
if (settingsUI.isBuildTriggered() && sample.getInputGeom() != null)
|
||||||
{
|
{
|
||||||
if (!building)
|
if (!building)
|
||||||
|
@ -527,7 +526,7 @@ public class RecastDemo
|
||||||
float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
|
float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
|
||||||
int m_tileSize = settingsUI.getTileSize();
|
int m_tileSize = settingsUI.getTileSize();
|
||||||
long t = FrequencyWatch.Ticks;
|
long t = FrequencyWatch.Ticks;
|
||||||
|
|
||||||
Logger.Information($"build");
|
Logger.Information($"build");
|
||||||
|
|
||||||
Tuple<IList<RecastBuilderResult>, NavMesh> buildResult;
|
Tuple<IList<RecastBuilderResult>, NavMesh> buildResult;
|
||||||
|
@ -553,7 +552,7 @@ public class RecastDemo
|
||||||
settingsUI.setBuildTime((FrequencyWatch.Ticks - t) / TimeSpan.TicksPerMillisecond);
|
settingsUI.setBuildTime((FrequencyWatch.Ticks - t) / TimeSpan.TicksPerMillisecond);
|
||||||
//settingsUI.setBuildTelemetry(buildResult.Item1.Select(x => x.getTelemetry()).ToList());
|
//settingsUI.setBuildTelemetry(buildResult.Item1.Select(x => x.getTelemetry()).ToList());
|
||||||
toolsUI.setSample(sample);
|
toolsUI.setSample(sample);
|
||||||
|
|
||||||
Logger.Information($"build times");
|
Logger.Information($"build times");
|
||||||
Logger.Information($"-----------------------------------------");
|
Logger.Information($"-----------------------------------------");
|
||||||
var telemetries = buildResult.Item1
|
var telemetries = buildResult.Item1
|
||||||
|
@ -561,12 +560,11 @@ public class RecastDemo
|
||||||
.SelectMany(x => x.ToList())
|
.SelectMany(x => x.ToList())
|
||||||
.GroupBy(x => x.Item1)
|
.GroupBy(x => x.Item1)
|
||||||
.ToImmutableSortedDictionary(x => x.Key, x => x.Sum(y => y.Item2));
|
.ToImmutableSortedDictionary(x => x.Key, x => x.Sum(y => y.Item2));
|
||||||
|
|
||||||
foreach (var (key, millis) in telemetries)
|
foreach (var (key, millis) in telemetries)
|
||||||
{
|
{
|
||||||
Logger.Information($"{key}: {millis} ms");
|
Logger.Information($"{key}: {millis} ms");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -716,7 +714,7 @@ public class RecastDemo
|
||||||
_imgui.Update((float)dt);
|
_imgui.Update((float)dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe void OnWindowOnRender(double dt)
|
private unsafe void OnWindowRender(double dt)
|
||||||
{
|
{
|
||||||
// _gl.ClearColor(Color.CadetBlue);
|
// _gl.ClearColor(Color.CadetBlue);
|
||||||
// _gl.Clear(ClearBufferMask.ColorBufferBit);
|
// _gl.Clear(ClearBufferMask.ColorBufferBit);
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace DotRecast.Recast.Demo.UI;
|
||||||
|
|
||||||
public interface IRcView
|
public interface IRcView
|
||||||
{
|
{
|
||||||
void Bind(RcCanvas canvas);
|
void Bind(RecastDemoCanvas canvas);
|
||||||
bool IsMouseInside();
|
bool IsMouseInside();
|
||||||
void Update(double dt);
|
void Update(double dt);
|
||||||
void Draw(double dt);
|
void Draw(double dt);
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace DotRecast.Recast.Demo.UI;
|
||||||
|
|
||||||
public class RcLogView : IRcView
|
public class RcLogView : IRcView
|
||||||
{
|
{
|
||||||
private RcCanvas _canvas;
|
private RecastDemoCanvas _canvas;
|
||||||
private bool _mouseInside;
|
private bool _mouseInside;
|
||||||
|
|
||||||
private List<string> _lines = new();
|
private List<string> _lines = new();
|
||||||
|
@ -60,7 +60,7 @@ public class RcLogView : IRcView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Bind(RcCanvas canvas)
|
public void Bind(RecastDemoCanvas canvas)
|
||||||
{
|
{
|
||||||
_canvas = canvas;
|
_canvas = canvas;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,9 @@ public class RcSettingsView : IRcView
|
||||||
private bool _mouseInside;
|
private bool _mouseInside;
|
||||||
public bool IsMouseInside() => _mouseInside;
|
public bool IsMouseInside() => _mouseInside;
|
||||||
|
|
||||||
private RcCanvas _canvas;
|
private RecastDemoCanvas _canvas;
|
||||||
|
|
||||||
public void Bind(RcCanvas canvas)
|
public void Bind(RecastDemoCanvas canvas)
|
||||||
{
|
{
|
||||||
_canvas = canvas;
|
_canvas = canvas;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ using Silk.NET.Windowing;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.UI;
|
namespace DotRecast.Recast.Demo.UI;
|
||||||
|
|
||||||
public class RcCanvas
|
public class RecastDemoCanvas
|
||||||
{
|
{
|
||||||
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
private static readonly ILogger Logger = Log.ForContext<RecastDemo>();
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public class RcCanvas
|
||||||
|
|
||||||
public Vector2D<int> Size => _window.Size;
|
public Vector2D<int> Size => _window.Size;
|
||||||
|
|
||||||
public RcCanvas(IWindow window, params IRcView[] views)
|
public RecastDemoCanvas(IWindow window, params IRcView[] views)
|
||||||
{
|
{
|
||||||
_window = window;
|
_window = window;
|
||||||
_views = views;
|
_views = views;
|
||||||
|
@ -112,10 +112,6 @@ public class RcCanvas
|
||||||
{
|
{
|
||||||
view.Draw(dt);
|
view.Draw(dt);
|
||||||
_mouseOverUI |= view.IsMouseInside();
|
_mouseOverUI |= view.IsMouseInside();
|
||||||
// if (_mouseOverUI)
|
|
||||||
// {
|
|
||||||
// Logger.Information("mouse hover!");
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -41,9 +41,9 @@ public class ToolsView : IRcView
|
||||||
private bool _mouseInside;
|
private bool _mouseInside;
|
||||||
public bool IsMouseInside() => _mouseInside;
|
public bool IsMouseInside() => _mouseInside;
|
||||||
|
|
||||||
private RcCanvas _canvas;
|
private RecastDemoCanvas _canvas;
|
||||||
|
|
||||||
public void Bind(RcCanvas canvas)
|
public void Bind(RecastDemoCanvas canvas)
|
||||||
{
|
{
|
||||||
_canvas = canvas;
|
_canvas = canvas;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue