From 53a1cdf5bee2955995dfbf441f5354d1dcfc1e0c Mon Sep 17 00:00:00 2001 From: Joel Stålnacke Date: Fri, 11 Oct 2024 13:31:44 +0300 Subject: Add Godot client --- client/.gitattributes | 2 ++ client/.gitignore | 3 ++ client/Djup.csproj | 15 ++++++++++ client/Djup.sln | 19 +++++++++++++ client/Root.cs | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ client/icon.svg | 1 + client/icon.svg.import | 37 +++++++++++++++++++++++++ client/project.godot | 24 ++++++++++++++++ client/root.tscn | 6 ++++ 9 files changed, 181 insertions(+) create mode 100644 client/.gitattributes create mode 100644 client/.gitignore create mode 100644 client/Djup.csproj create mode 100644 client/Djup.sln create mode 100644 client/Root.cs create mode 100644 client/icon.svg create mode 100644 client/icon.svg.import create mode 100644 client/project.godot create mode 100644 client/root.tscn (limited to 'client') diff --git a/client/.gitattributes b/client/.gitattributes new file mode 100644 index 0000000..8ad74f7 --- /dev/null +++ b/client/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/client/Djup.csproj b/client/Djup.csproj new file mode 100644 index 0000000..0e34542 --- /dev/null +++ b/client/Djup.csproj @@ -0,0 +1,15 @@ + + + net8.0 + net7.0 + net8.0 + true + true + + + + + + + + diff --git a/client/Djup.sln b/client/Djup.sln new file mode 100644 index 0000000..fc24000 --- /dev/null +++ b/client/Djup.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Djup", "Djup.csproj", "{77DE270B-0994-425F-9CA2-4E664136B608}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {77DE270B-0994-425F-9CA2-4E664136B608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77DE270B-0994-425F-9CA2-4E664136B608}.Debug|Any CPU.Build.0 = Debug|Any CPU + {77DE270B-0994-425F-9CA2-4E664136B608}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {77DE270B-0994-425F-9CA2-4E664136B608}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {77DE270B-0994-425F-9CA2-4E664136B608}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {77DE270B-0994-425F-9CA2-4E664136B608}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/client/Root.cs b/client/Root.cs new file mode 100644 index 0000000..e39a485 --- /dev/null +++ b/client/Root.cs @@ -0,0 +1,74 @@ +using Godot; +using System; +using Djup.Native; + +public partial class Root : Node2D +{ + private IntPtr native_world; + private int[] balls = new int[100]; + private Random rng = new(); + private const double Tps = 1d/60d; + + // Called when the node enters the scene tree for the first time. + public unsafe override void _Ready() + { + RenderingServer.SetDefaultClearColor(Colors.LightGray); + + native_world = LibDjup.world_create(); + for (int i = 0; i < balls.Length; i++) + { + int id = LibDjup.world_create_entity(native_world, EntityKind.Ball); + if (id < 0) + { + throw new Exception("Failed to create entity"); + } + balls[i] = id; + Entity *ent; + var pos = new Vec2(5f * rng.Next(10), 5f * rng.Next(20)); + var vel = new Vec2(50f + 5f * rng.Next(10), 50f); + ent = LibDjup.world_find_entity(native_world, balls[i]); + ent->ball.Position = pos; + ent->ball.Velocity = vel; + } + } + + public override void _ExitTree() + { + LibDjup.world_free(native_world); + } + + private void DrawBall(Ball ball) + { + //Color color = rng.Next(5) switch + //{ + //0 => Colors.Black, + //1 => Colors.Blue, + //2 => Colors.Red, + //3 => Colors.Green, + //4 => Colors.Pink + //}; + Color color = Colors.Blue; + this.DrawCircle(new Vector2(ball.Position.X, ball.Position.Y), 5f, color, antialiased: true); + } + + public unsafe override void _Draw() + { + for (int i = 0; i < balls.Length; i++) + { + DrawBall(LibDjup.world_find_entity(native_world, balls[i])->ball); + } + } + + public override void _Process(double delta) + { + this.QueueRedraw(); + } + + public override void _PhysicsProcess(double delta) + { + if (LibDjup.world_tick(native_world, Tps) != 0) + { + GD.Print("world_tick failed"); + } + } +} diff --git a/client/icon.svg b/client/icon.svg new file mode 100644 index 0000000..9d8b7fa --- /dev/null +++ b/client/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/client/icon.svg.import b/client/icon.svg.import new file mode 100644 index 0000000..57c75ba --- /dev/null +++ b/client/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cg5s4tfihtewl" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/client/project.godot b/client/project.godot new file mode 100644 index 0000000..6107d87 --- /dev/null +++ b/client/project.godot @@ -0,0 +1,24 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="Djup" +run/main_scene="res://root.tscn" +config/features=PackedStringArray("4.3", "C#", "Forward Plus") +config/icon="res://icon.svg" + +[display] + +window/stretch/mode="canvas_items" + +[dotnet] + +project/assembly_name="Djup" diff --git a/client/root.tscn b/client/root.tscn new file mode 100644 index 0000000..ded95a0 --- /dev/null +++ b/client/root.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://drdk1by1fun2q"] + +[ext_resource type="Script" path="res://Root.cs" id="1_p5oo0"] + +[node name="Root" type="Node2D"] +script = ExtResource("1_p5oo0") -- cgit v1.2.3