added menu bar in Demo

This commit is contained in:
ikpil 2024-02-11 15:39:34 +09:00
parent a65e5a3125
commit 73bb475ef7
4 changed files with 107 additions and 12 deletions

View File

@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added DtNodeQueue UnitTest [@ikpil](https://github.com/ikpil) - Added DtNodeQueue UnitTest [@ikpil](https://github.com/ikpil)
- Added RcSortedQueue UnitTest [@ikpil](https://github.com/ikpil) - Added RcSortedQueue UnitTest [@ikpil](https://github.com/ikpil)
- Added IComparable interface to RcAtomicLong [@ikpil](https://github.com/ikpil) - Added IComparable interface to RcAtomicLong [@ikpil](https://github.com/ikpil)
- Added Menu bar in Demo [@ikpil](https://github.com/ikpil)
### Fixed ### Fixed

View File

@ -0,0 +1,34 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DotRecast.Core
{
public static class RcProcess
{
public static void OpenUrl(string url)
{
try
{
// OS에 따라 다른 명령 실행
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var psi = new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true };
Process.Start(psi);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error opening web browser: {ex.Message}");
}
}
}
}

View File

@ -43,7 +43,6 @@ using DotRecast.Recast.Demo.Messages;
using DotRecast.Recast.Toolset.Geom; using DotRecast.Recast.Toolset.Geom;
using DotRecast.Recast.Demo.Tools; using DotRecast.Recast.Demo.Tools;
using DotRecast.Recast.Demo.UI; using DotRecast.Recast.Demo.UI;
using DotRecast.Recast.Toolset;
using MouseButton = Silk.NET.Input.MouseButton; using MouseButton = Silk.NET.Input.MouseButton;
using Window = Silk.NET.Windowing.Window; using Window = Silk.NET.Windowing.Window;
@ -111,7 +110,8 @@ public class RecastDemo : IRecastDemoChannel
private bool markerPositionSet; private bool markerPositionSet;
private RcVec3f markerPosition = new RcVec3f(); private RcVec3f markerPosition = new RcVec3f();
private RcToolsetView toolset; private RcMenuView _menuView;
private RcToolsetView _toolsetView;
private RcSettingsView settingsView; private RcSettingsView settingsView;
private RcLogView logView; private RcLogView logView;
@ -319,7 +319,7 @@ public class RecastDemo : IRecastDemoChannel
if (null != mesh) if (null != mesh)
{ {
_sample.Update(_sample.GetInputGeom(), ImmutableArray<RcBuilderResult>.Empty, mesh); _sample.Update(_sample.GetInputGeom(), ImmutableArray<RcBuilderResult>.Empty, mesh);
toolset.SetEnabled(true); _toolsetView.SetEnabled(true);
} }
} }
catch (Exception e) catch (Exception e)
@ -380,10 +380,11 @@ public class RecastDemo : IRecastDemoChannel
DemoInputGeomProvider geom = LoadInputMesh("nav_test.obj"); DemoInputGeomProvider geom = LoadInputMesh("nav_test.obj");
_sample = new DemoSample(geom, ImmutableArray<RcBuilderResult>.Empty, null); _sample = new DemoSample(geom, ImmutableArray<RcBuilderResult>.Empty, null);
_menuView = new RcMenuView();
settingsView = new RcSettingsView(this); settingsView = new RcSettingsView(this);
settingsView.SetSample(_sample); settingsView.SetSample(_sample);
toolset = new RcToolsetView( _toolsetView = new RcToolsetView(
new TestNavmeshSampleTool(), new TestNavmeshSampleTool(),
new TileSampleTool(), new TileSampleTool(),
new ObstacleSampleTool(), new ObstacleSampleTool(),
@ -394,10 +395,10 @@ public class RecastDemo : IRecastDemoChannel
new JumpLinkBuilderSampleTool(), new JumpLinkBuilderSampleTool(),
new DynamicUpdateSampleTool() new DynamicUpdateSampleTool()
); );
toolset.SetEnabled(true); _toolsetView.SetEnabled(true);
logView = new RcLogView(); logView = new RcLogView();
_canvas = new RcCanvas(window, settingsView, toolset, logView); _canvas = new RcCanvas(window, _menuView, settingsView, _toolsetView, logView);
var vendor = _gl.GetStringS(GLEnum.Vendor); var vendor = _gl.GetStringS(GLEnum.Vendor);
var version = _gl.GetStringS(GLEnum.Version); var version = _gl.GetStringS(GLEnum.Version);
@ -504,7 +505,7 @@ public class RecastDemo : IRecastDemoChannel
timeAcc -= DELTA_TIME; timeAcc -= DELTA_TIME;
if (simIter < 5 && _sample != null) if (simIter < 5 && _sample != null)
{ {
var tool = toolset.GetTool(); var tool = _toolsetView.GetTool();
if (null != tool) if (null != tool)
{ {
tool.HandleUpdate(DELTA_TIME); tool.HandleUpdate(DELTA_TIME);
@ -591,7 +592,7 @@ public class RecastDemo : IRecastDemoChannel
} }
_sample.SetChanged(false); _sample.SetChanged(false);
toolset.SetSample(_sample); _toolsetView.SetSample(_sample);
} }
if (_messages.TryDequeue(out var msg)) if (_messages.TryDequeue(out var msg))
@ -620,7 +621,7 @@ public class RecastDemo : IRecastDemoChannel
dd.Fog(camr * 0.1f, camr * 1.25f); dd.Fog(camr * 0.1f, camr * 1.25f);
renderer.Render(_sample, settingsView.GetDrawMode()); renderer.Render(_sample, settingsView.GetDrawMode());
ISampleTool sampleTool = toolset.GetTool(); ISampleTool sampleTool = _toolsetView.GetTool();
if (sampleTool != null) if (sampleTool != null)
{ {
sampleTool.HandleRender(renderer); sampleTool.HandleRender(renderer);
@ -707,7 +708,7 @@ public class RecastDemo : IRecastDemoChannel
_sample.SetChanged(false); _sample.SetChanged(false);
settingsView.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond); settingsView.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond);
//settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList()); //settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList());
toolset.SetSample(_sample); _toolsetView.SetSample(_sample);
Logger.Information($"build times"); Logger.Information($"build times");
Logger.Information($"-----------------------------------------"); Logger.Information($"-----------------------------------------");
@ -800,7 +801,7 @@ public class RecastDemo : IRecastDemoChannel
RcVec3f rayDir = new RcVec3f(rayEnd.X - rayStart.X, rayEnd.Y - rayStart.Y, rayEnd.Z - rayStart.Z); RcVec3f rayDir = new RcVec3f(rayEnd.X - rayStart.X, rayEnd.Y - rayStart.Y, rayEnd.Z - rayStart.Z);
rayDir = RcVec3f.Normalize(rayDir); rayDir = RcVec3f.Normalize(rayDir);
ISampleTool raySampleTool = toolset.GetTool(); ISampleTool raySampleTool = _toolsetView.GetTool();
if (raySampleTool != null) if (raySampleTool != null)
{ {

View File

@ -0,0 +1,59 @@
using DotRecast.Core;
using ImGuiNET;
namespace DotRecast.Recast.Demo.UI;
public class RcMenuView : IRcView
{
private RcCanvas _canvas;
public void Bind(RcCanvas canvas)
{
_canvas = canvas;
}
public bool IsHovered()
{
//throw new System.NotImplementedException();
return false;
}
public void Update(double dt)
{
//throw new System.NotImplementedException();
}
public void Draw(double dt)
{
if (ImGui.BeginMainMenuBar())
{
if (ImGui.BeginMenu("Help"))
{
if (ImGui.MenuItem("Repository"))
{
RcProcess.OpenUrl("https://github.com/ikpil/DotRecast");
}
if (ImGui.MenuItem("Nuget"))
{
RcProcess.OpenUrl("https://www.nuget.org/packages/DotRecast.Core/");
}
ImGui.Separator();
if (ImGui.MenuItem("Issue Tracker"))
{
RcProcess.OpenUrl("https://github.com/ikpil/DotRecast/issues");
}
if (ImGui.MenuItem("Release Notes"))
{
RcProcess.OpenUrl("https://github.com/ikpil/DotRecast/blob/main/CHANGELOG.md");
}
ImGui.EndMenu();
}
ImGui.EndMainMenuBar();
}
}
}