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.Raylib/Graphics/RaylibGraphicsEngine.cs b/Basalt.Raylib/Graphics/RaylibGraphicsEngine.cs index 960d958..4d20267 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(); @@ -210,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(); //---------------------------------------------------------------------------------- } @@ -228,7 +216,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) 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/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..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; } } } @@ -131,5 +134,13 @@ public void AddEntityToSimulation(object entity) } } + public void RemoveEntityFromSimulation(object entity) + { + if (entity is Entity e) + { + chunking.RemoveEntity(e); + } + } + } } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..58067af --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# 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.1](https://www.github.com/thiagomvas/Basalt/releases/tag/v1.0.1) (2024-05-15) + +### Bug Fixes +* 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)) \ No newline at end of file