From 8cdd55acbb13ca378500a70ea55acfac2396618d Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:33:15 -0300 Subject: [PATCH 1/7] fix: Raylib Graphics Engine logger was always null --- Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs b/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs index 960d958..dbeca43 100644 --- a/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs +++ b/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs @@ -24,7 +24,7 @@ public class RaylibGraphicsEngine : IGraphicsEngine public string PostProcessingShaderCacheKey { get; set; } = string.Empty; private readonly WindowInitParams config; - private readonly ILogger? logger; + private ILogger? logger; internal static RaylibGraphicsEngine instance = new(new()); private EntityManager entityManager; @@ -53,12 +53,13 @@ public unsafe void Initialize() inputSystem = Engine.Instance.GetEngineComponent(); eventBus = Engine.Instance.GetEngineComponent()!; entityManager = Engine.Instance.EntityManager; + logger = Engine.Instance.Logger; enablePostProcessing = config.PostProcessing; instance = this; - SetTraceLogCallback(&LogCustom); + SetTraceLogCallback(&LogToLogger); SetTraceLogLevel(TraceLogLevel.All); if (config.Borderless) SetConfigFlags(ConfigFlags.UndecoratedWindow); @@ -191,10 +192,6 @@ public unsafe void Render() BeginMode3D(control.camera); -#if DEBUG - DrawGrid(100, 1.0f); -#endif - eventBus?.NotifyRender(); @@ -228,7 +225,7 @@ public unsafe void Render() } [UnmanagedCallersOnly(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })] - private static unsafe void LogCustom(int logLevel, sbyte* text, sbyte* args) + private static unsafe void LogToLogger(int logLevel, sbyte* text, sbyte* args) { var message = Logging.GetLogMessage(new IntPtr(text), new IntPtr(args)); switch ((TraceLogLevel)logLevel) From d03d6502fa1896d2712af0b4c05991eebfe9e6ef Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:38:55 -0300 Subject: [PATCH 2/7] fix: Raylib Graphics Engine always rendered info boxes --- Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs b/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs index dbeca43..4d20267 100644 --- a/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs +++ b/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs @@ -207,15 +207,6 @@ public unsafe void Render() } - - // Draw info boxes - DrawRectangle(5, 5, 330, 100, ColorAlpha(Color.SkyBlue, 0.5f)); - DrawRectangleLines(10, 10, 330, 100, Color.Blue); - - DrawText($"Physics Elapsed time: {Time.PhysicsDeltaTime}s - Expected: 0.016s", 15, 30, 10, Color.White); - DrawText($"Update Elapsed time: {Time.DeltaTime}s - Expected: 0.00833s", 15, 45, 10, Color.White); - DrawFPS(15, 105); - EndDrawing(); //---------------------------------------------------------------------------------- } From e0f1ce08e3b544ffd07b10e1809656eb94e1a11b Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:49:57 -0300 Subject: [PATCH 3/7] fix: No longer throws random exceptions for tightly timed entity instantiation --- Basalt/Common/Physics/Grid.cs | 16 ++++++++++++++-- Basalt/Common/Physics/IChunkingMechanism.cs | 1 + Basalt/Common/Physics/PhysicsEngine.cs | 8 ++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Basalt/Common/Physics/Grid.cs b/Basalt/Common/Physics/Grid.cs index 79d07fa..bea1c16 100644 --- a/Basalt/Common/Physics/Grid.cs +++ b/Basalt/Common/Physics/Grid.cs @@ -5,7 +5,9 @@ namespace Basalt.Common.Physics { public class Grid : IChunkingMechanism { - public List Entities = new List(); + private List Entities = new List(); + private List entityAddQueue = new List(); + private List entityRemoveQueue = new List(); Dictionary> chunks = new Dictionary>(); @@ -17,12 +19,22 @@ public Grid(int sideLength) public void AddEntity(Entity entity) { - Entities.Add(entity); + entityAddQueue.Add(entity); + } + + public void RemoveEntity(Entity entity) + { + entityRemoveQueue.Add(entity); } public void Update() { chunks.Clear(); + Entities.AddRange(entityAddQueue); + foreach(var entity in entityRemoveQueue) + { + Entities.Remove(entity); + } foreach (var entity in Entities) { diff --git a/Basalt/Common/Physics/IChunkingMechanism.cs b/Basalt/Common/Physics/IChunkingMechanism.cs index 65b3ac3..17550a4 100644 --- a/Basalt/Common/Physics/IChunkingMechanism.cs +++ b/Basalt/Common/Physics/IChunkingMechanism.cs @@ -6,6 +6,7 @@ namespace Basalt.Common.Physics public interface IChunkingMechanism { void AddEntity(Entity entity); + void RemoveEntity(Entity entity); List> GetEntitiesChunked(); List GetEntitiesNearPoint(Vector3 point); void Update(); diff --git a/Basalt/Common/Physics/PhysicsEngine.cs b/Basalt/Common/Physics/PhysicsEngine.cs index 997d8c5..e593a89 100644 --- a/Basalt/Common/Physics/PhysicsEngine.cs +++ b/Basalt/Common/Physics/PhysicsEngine.cs @@ -131,5 +131,13 @@ public void AddEntityToSimulation(object entity) } } + public void RemoveEntityFromSimulation(object entity) + { + if (entity is Entity e) + { + chunking.RemoveEntity(e); + } + } + } } From e793eba484f1c517217dfaff2528fdf089544006 Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:52:23 -0300 Subject: [PATCH 4/7] fix: Physics Delta Time was not consistent --- Basalt/Common/Physics/PhysicsEngine.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Basalt/Common/Physics/PhysicsEngine.cs b/Basalt/Common/Physics/PhysicsEngine.cs index e593a89..acaa4ee 100644 --- a/Basalt/Common/Physics/PhysicsEngine.cs +++ b/Basalt/Common/Physics/PhysicsEngine.cs @@ -12,6 +12,7 @@ public class PhysicsEngine : IPhysicsEngine public long startTime, elapsedTime; + const float targetDeltaTime = 0.016f; const int targetFrameTimeMs = 16; private IChunkingMechanism chunking; @@ -19,7 +20,6 @@ public class PhysicsEngine : IPhysicsEngine private ILogger? logger; private bool ShouldRun = true; - /// /// Gets or sets the gravity value for the physics engine. /// @@ -114,11 +114,14 @@ public void Simulate() if (elapsedTime > targetFrameTimeMs) { logger?.LogWarning($"Physics engine is running behind. Elapsed time: {elapsedTime}ms"); + Time.PhysicsDeltaTime = elapsedTime / 1000f; + continue; } if (elapsedTime < targetFrameTimeMs) { Task.Delay((int)(targetFrameTimeMs - elapsedTime)).Wait(); + Time.PhysicsDeltaTime = targetDeltaTime; } } } From 3811cc279058ac851168b7de7ac2004be9785209 Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:52:43 -0300 Subject: [PATCH 5/7] chore(release): 1.0.0 --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..384b60b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [versionize](https://github.com/versionize/versionize) for commit guidelines. + + +## [1.0.0](https://www.github.com/thiagomvas/Basalt/releases/tag/v1.0.0) (2024-05-15) + +### Features + +* Add SingletonComponentAttribute for single instance per entity components. ([73e2b88](https://www.github.com/thiagomvas/Basalt/commit/73e2b88d88ffe8a9d4a3733f3b63538016387565)) + +### Bug Fixes + +* entities started as disabled ([f2c5260](https://www.github.com/thiagomvas/Basalt/commit/f2c52600036aa3c78f50197e8ff7565bce4f09bc)) +* if Entity.Id is not found, generate a random ID ([2bb9d53](https://www.github.com/thiagomvas/Basalt/commit/2bb9d532bb6754803bb08fc9e52d173813ae17fd)) +* No longer throws random exceptions for tightly timed entity instantiation ([e0f1ce0](https://www.github.com/thiagomvas/Basalt/commit/e0f1ce08e3b544ffd07b10e1809656eb94e1a11b)) +* Physics Delta Time was not consistent ([e793eba](https://www.github.com/thiagomvas/Basalt/commit/e793eba484f1c517217dfaff2528fdf089544006)) +* Raylib Graphics Engine always rendered info boxes ([d03d650](https://www.github.com/thiagomvas/Basalt/commit/d03d6502fa1896d2712af0b4c05991eebfe9e6ef)) +* Raylib Graphics Engine logger was always null ([8cdd55a](https://www.github.com/thiagomvas/Basalt/commit/8cdd55acbb13ca378500a70ea55acfac2396618d)) + From 2ea5283c978416a869f12d72658750d6b2b87db4 Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:53:23 -0300 Subject: [PATCH 6/7] chore(release): 1.0.1 --- Basalt.Core/Basalt.Core.csproj | 4 ++-- Basalt.Raylib/Basalt.Raylib.csproj | 4 ++-- Basalt/Basalt.csproj | 4 ++-- CHANGELOG.md | 3 +++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Basalt.Core/Basalt.Core.csproj b/Basalt.Core/Basalt.Core.csproj index 59a7883..8b9b2fe 100644 --- a/Basalt.Core/Basalt.Core.csproj +++ b/Basalt.Core/Basalt.Core.csproj @@ -1,10 +1,10 @@ - + net8.0 enable enable - 1.0.0 + 1.0.1 True BasaltLogoBg.png README.md diff --git a/Basalt.Raylib/Basalt.Raylib.csproj b/Basalt.Raylib/Basalt.Raylib.csproj index 94f0185..093441a 100644 --- a/Basalt.Raylib/Basalt.Raylib.csproj +++ b/Basalt.Raylib/Basalt.Raylib.csproj @@ -1,11 +1,11 @@ - + net8.0 enable enable true - 1.0.0 + 1.0.1 True BasaltLogoBg.png README.md diff --git a/Basalt/Basalt.csproj b/Basalt/Basalt.csproj index dd3f2ba..1940f0c 100644 --- a/Basalt/Basalt.csproj +++ b/Basalt/Basalt.csproj @@ -1,11 +1,11 @@ - + net8.0 enable enable true - 1.0.0 + 1.0.1 True Basalt BasaltLogoBg.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 384b60b..e90ddfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. See [versionize](https://github.com/versionize/versionize) for commit guidelines. + +## [1.0.1](https://www.github.com/thiagomvas/Basalt/releases/tag/v1.0.1) (2024-05-15) + ## [1.0.0](https://www.github.com/thiagomvas/Basalt/releases/tag/v1.0.0) (2024-05-15) From 117e7ea8a5d7fbf6dbd3345cf0b4240804c79118 Mon Sep 17 00:00:00 2001 From: Thiago Menezes Date: Wed, 15 May 2024 15:55:26 -0300 Subject: [PATCH 7/7] Fix changelog --- CHANGELOG.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e90ddfd..58067af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,19 +5,8 @@ All notable changes to this project will be documented in this file. See [versio ## [1.0.1](https://www.github.com/thiagomvas/Basalt/releases/tag/v1.0.1) (2024-05-15) - -## [1.0.0](https://www.github.com/thiagomvas/Basalt/releases/tag/v1.0.0) (2024-05-15) - -### Features - -* Add SingletonComponentAttribute for single instance per entity components. ([73e2b88](https://www.github.com/thiagomvas/Basalt/commit/73e2b88d88ffe8a9d4a3733f3b63538016387565)) - ### Bug Fixes - -* entities started as disabled ([f2c5260](https://www.github.com/thiagomvas/Basalt/commit/f2c52600036aa3c78f50197e8ff7565bce4f09bc)) -* if Entity.Id is not found, generate a random ID ([2bb9d53](https://www.github.com/thiagomvas/Basalt/commit/2bb9d532bb6754803bb08fc9e52d173813ae17fd)) * No longer throws random exceptions for tightly timed entity instantiation ([e0f1ce0](https://www.github.com/thiagomvas/Basalt/commit/e0f1ce08e3b544ffd07b10e1809656eb94e1a11b)) * Physics Delta Time was not consistent ([e793eba](https://www.github.com/thiagomvas/Basalt/commit/e793eba484f1c517217dfaff2528fdf089544006)) * Raylib Graphics Engine always rendered info boxes ([d03d650](https://www.github.com/thiagomvas/Basalt/commit/d03d6502fa1896d2712af0b4c05991eebfe9e6ef)) -* Raylib Graphics Engine logger was always null ([8cdd55a](https://www.github.com/thiagomvas/Basalt/commit/8cdd55acbb13ca378500a70ea55acfac2396618d)) - +* Raylib Graphics Engine logger was always null ([8cdd55a](https://www.github.com/thiagomvas/Basalt/commit/8cdd55acbb13ca378500a70ea55acfac2396618d)) \ No newline at end of file