Merge branch 'main' into ImGui

This commit is contained in:
max
2024-07-12 18:08:28 +02:00
45 changed files with 780 additions and 82 deletions

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Runtime ID" AfterTargets="Build">
<Message Text="Runtime ID: $(RuntimeIdentifier)" Importance="high"/>
</Target>
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))">
<Content Include="..\libs\x64\**\*.*" >
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))">
<Content Include="..\libs\lib64\**\*.*" >
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup Condition="$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))">
<Content Include="..\libs\osx\**\*.*" >
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

View File

@ -7,6 +7,11 @@ namespace Nerfed.Runtime;
public static class Engine
{
public static event Action OnInitialize;
public static event Action OnUpdate;
public static event Action OnRender;
public static event Action OnQuit;
public static TimeSpan MaxDeltaTime { get; set; } = TimeSpan.FromMilliseconds(100);
public static bool VSync { get; set; }
@ -19,6 +24,7 @@ public static class Engine
private static Stopwatch gameTimer;
private static long previousTicks = 0;
private static TimeSpan accumulatedUpdateTime = TimeSpan.Zero;
private static TimeSpan accumulatedDrawTime = TimeSpan.Zero;
// must be a power of 2 so we can do a bitmask optimization when checking worst case
@ -38,9 +44,7 @@ public static class Engine
private const string WindowTitle = "Nerfed";
//..
private static Gui.GuiController Controller;
internal static void Run(string[] args)
public static void Run(string[] args)
{
Timestep = TimeSpan.FromTicks(TimeSpan.TicksPerSecond / TargetTimestep);
gameTimer = Stopwatch.StartNew();
@ -55,7 +59,7 @@ public static class Engine
{
throw new Exception("Failed to init SDL");
}
GraphicsDevice = new GraphicsDevice(BackendFlags.All);
MainWindow = new Window(GraphicsDevice, new WindowCreateInfo(WindowTitle, WindowWidth, WindowHeight, ScreenMode.Windowed));
@ -64,23 +68,17 @@ public static class Engine
throw new Exception("Failed to claim window");
}
MainWindow.OnCloseEvent += (w) => {
Quit();
};
AudioDevice = new AudioDevice();
Controller = new Gui.GuiController(GraphicsDevice, MainWindow, Color.DarkOliveGreen);
Controller.OnGui += () => {
ImGuiNET.ImGui.ShowDemoWindow();
};
OnInitialize?.Invoke();
while (!quit)
{
Tick();
}
Controller.Dispose();
OnQuit?.Invoke();
GraphicsDevice.UnclaimWindow(MainWindow);
MainWindow.Dispose();
GraphicsDevice.Dispose();
@ -157,7 +155,7 @@ public static class Engine
ProcessSDLEvents();
// Tick game here...
Controller.Update((float)Timestep.TotalSeconds);
OnUpdate?.Invoke();
AudioDevice.WakeThread();
accumulatedUpdateTime -= Timestep;
@ -166,7 +164,7 @@ public static class Engine
double alpha = accumulatedUpdateTime / Timestep;
// Render here..
Controller.Render();
OnRender?.Invoke();
accumulatedDrawTime -= framerateCapTimeSpan;
}

View File

@ -1,33 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);Libraries\**\*</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<Compile Include="Libraries\SDL2CS\src\SDL2.cs" />
<Compile Include="Libraries\RefreshCS\RefreshCS.cs" />
<Compile Include="Libraries\FAudio\csharp\FAudio.cs" />
<Compile Include="Libraries\WellspringCS\WellspringCS.cs" />
<Compile Include="Libraries\dav1dfile\csharp\dav1dfile.cs" />
<Compile Include="Libraries\ImGui.NET\src\ImGui.NET\**\*.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\**\*.*">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<IsPackable>false</IsPackable>
<Configurations>Debug;Test;Release</Configurations>
<Platforms>x64</Platforms>
</PropertyGroup>
<Import Project=".\CopyLibs.targets" />
<PropertyGroup>
<DefaultItemExcludes>$(DefaultItemExcludes);Libraries\**\*</DefaultItemExcludes>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DefineConstants>TRACE;LOG_INFO;PROFILING</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Test|x64' ">
<DefineConstants>TRACE;LOG_ERROR;PROFILING</DefineConstants>
<Optimize>true</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<DefineConstants>TRACE;LOG_ERROR</DefineConstants>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="Libraries\SDL2CS\src\SDL2.cs"/>
<Compile Include="Libraries\RefreshCS\RefreshCS.cs"/>
<Compile Include="Libraries\FAudio\csharp\FAudio.cs"/>
<Compile Include="Libraries\WellspringCS\WellspringCS.cs"/>
<Compile Include="Libraries\dav1dfile\csharp\dav1dfile.cs"/>
<Compile Include="Libraries\ImGui.NET\src\ImGui.NET\**\*.cs"/>
</ItemGroup>
</Project>

View File

@ -17,12 +17,12 @@ public struct ProfilerScope : IDisposable
public static class Profiler
{
[Conditional("PROFILER")]
[Conditional("PROFILING")]
public static void BeginSample(string label) {
}
[Conditional("PROFILER")]
[Conditional("PROFILING")]
public static void EndSample() {
}

View File

@ -1,9 +0,0 @@
namespace Nerfed.Runtime;
internal class Program
{
private static void Main(string[] args)
{
Engine.Run(args);
}
}