diff --git a/.gitignore b/.gitignore index cd42ee3..27c949c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin/ obj/ +client/.godot/ diff --git a/client/BadDay.Client.csproj b/client/BadDay.Client.csproj new file mode 100644 index 0000000..993a88e --- /dev/null +++ b/client/BadDay.Client.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + true + enable + BadDay.Client + BadDay.Client + + + + + diff --git a/client/NativeLibraries.cs b/client/NativeLibraries.cs new file mode 100644 index 0000000..b7f90da --- /dev/null +++ b/client/NativeLibraries.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using Godot; +using Ymir.Box3D; + +namespace BadDay.Client; + +/// +/// Finds ymir_box3d for Ymir.Box3D's DllImports. Godot loads game assemblies into its own load context, so the +/// default probing does not look beside them. A run from the editor or --path loads the library from the +/// project's build directory; an exported run from the data folder Godot puts beside the executable. +/// +internal static class NativeLibraries +{ + private const string Library = "ymir_box3d"; + +#pragma warning disable CA2255 // application code: the resolver must exist before the first DllImport + [ModuleInitializer] + internal static void Register() => + NativeLibrary.SetDllImportResolver(typeof(Box3DSoaWorld).Assembly, Resolve); + + private static IntPtr Resolve(string name, Assembly assembly, DllImportSearchPath? searchPath) + { + if (name != Library) return IntPtr.Zero; + string dir = OS.HasFeature("template") + ? Path.Combine(Path.GetDirectoryName(OS.GetExecutablePath())!, $"data_BadDay.Client_{Platform()}_{Arch()}") + : ProjectSettings.GlobalizePath("res://.godot/mono/temp/bin/Debug"); + string path = Path.Combine(dir, FileName()); + return File.Exists(path) && NativeLibrary.TryLoad(path, out var handle) ? handle : IntPtr.Zero; + } + + private static string FileName() => + OperatingSystem.IsWindows() ? "ymir_box3d.dll" : OperatingSystem.IsMacOS() ? "libymir_box3d.dylib" : "libymir_box3d.so"; + + private static string Platform() => + OperatingSystem.IsWindows() ? "windows" : OperatingSystem.IsMacOS() ? "macos" : "linuxbsd"; + + private static string Arch() => + RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.Arm64 ? "arm64" : "x86_64"; +} diff --git a/client/project.godot b/client/project.godot new file mode 100644 index 0000000..12b1c93 --- /dev/null +++ b/client/project.godot @@ -0,0 +1,33 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. + +config_version=5 + +[application] + +config/name="Bad Day Simulator" +run/main_scene="res://Main.tscn" +config/features=PackedStringArray("4.7", "C#") + +[display] + +window/size/viewport_width=1280 +window/size/viewport_height=720 +window/stretch/mode="canvas_items" + +[dotnet] + +project/assembly_name="BadDay.Client" + +[physics] + +; Godot's physics is switched off: Ymir is the only physics world. The client ticks BodyPainBoxSession at 120 Hz. +3d/physics_engine="Dummy" +common/physics_ticks_per_second=120 +common/physics_interpolation=true + +[rendering] + +renderer/rendering_method="gl_compatibility" +renderer/rendering_method.mobile="gl_compatibility"