From 46c0eb00455791baa1b50a4d844062cc2e2e2b36 Mon Sep 17 00:00:00 2001 From: cherrynik Date: Tue, 31 Oct 2023 15:50:51 +0300 Subject: [PATCH] chore: imguinet is ran only on debug --- .../DebugRootFeatureCompositionRoot.cs | 3 +++ .../CompositionRoots/GameCompositionRoot.cs | 1 + src/Apps/GameDesktop/Game.cs | 15 ++++++++++++--- src/Libs/Systems.Debugging/EntitiesList.cs | 1 + .../Systems.Debugging/Systems.Debugging.csproj | 1 + 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs index 79f105d..a813c63 100644 --- a/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs +++ b/src/Apps/GameDesktop/CompositionRoots/DebugFeatures/DebugRootFeatureCompositionRoot.cs @@ -1,5 +1,6 @@ // using Features.Debugging; using LightInject; +using MonoGame.ImGuiNet; namespace GameDesktop.CompositionRoots.DebugFeatures; @@ -13,6 +14,8 @@ public void Compose(IServiceRegistry serviceRegistry) private static void RegisterSystems(IServiceRegistry serviceRegistry) { + serviceRegistry.RegisterSingleton(factory => new ImGuiRenderer(factory.GetInstance())); + // serviceRegistry.RegisterSingleton(factory => // { // return new DrawRectangleCollisionComponentsSystem(factory.GetInstance()); diff --git a/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs index 64067dd..384c014 100644 --- a/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs +++ b/src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs @@ -1,6 +1,7 @@ using GameDesktop.Resources.Internal; using LightInject; using Microsoft.Xna.Framework; +using MonoGame.ImGuiNet; using Serilog; namespace GameDesktop.CompositionRoots; diff --git a/src/Apps/GameDesktop/Game.cs b/src/Apps/GameDesktop/Game.cs index 7e91dbf..09ce3ad 100644 --- a/src/Apps/GameDesktop/Game.cs +++ b/src/Apps/GameDesktop/Game.cs @@ -4,6 +4,8 @@ using Components.Tags; using Entities; using GameDesktop.CompositionRoots.Features; +using ImGuiNET; +using MonoGame.ImGuiNet; using LightInject; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -17,9 +19,11 @@ public class Game : Microsoft.Xna.Framework.Game private readonly ILogger _logger; private readonly IServiceContainer _container; + private ImGuiRenderer _guiRenderer; private SpriteBatch _spriteBatch; // TODO: Frames updating + // https://gafferongames.com/post/fix_your_timestep/ // https://lajbert.wordpress.com/2021/05/02/fix-your-timestep-in-monogame/ @@ -64,9 +68,6 @@ protected override void LoadContent() var dummy = _container.GetInstance(); dummy.Create(@in: world); - // _logger.ForContext().Verbose(e.ToString()!); - // _logger.ForContext().Verbose(e2.ToString()!); - _logger.ForContext().Verbose("LoadContent(): end"); } @@ -110,6 +111,14 @@ protected override void Draw(GameTime gameTime) GraphicsDevice.Clear(Color.CornflowerBlue); base.Draw(gameTime); + +#if DEBUG + _guiRenderer.BeginLayout(gameTime); + + ImGui.Text("Hi!"); + + _guiRenderer.EndLayout(); +#endif } protected override void Dispose(bool disposing) diff --git a/src/Libs/Systems.Debugging/EntitiesList.cs b/src/Libs/Systems.Debugging/EntitiesList.cs index 530664d..41575bc 100644 --- a/src/Libs/Systems.Debugging/EntitiesList.cs +++ b/src/Libs/Systems.Debugging/EntitiesList.cs @@ -1,4 +1,5 @@ using Components.Data; +using ImGuiNET; using Scellecs.Morpeh; namespace Systems.Debugging; diff --git a/src/Libs/Systems.Debugging/Systems.Debugging.csproj b/src/Libs/Systems.Debugging/Systems.Debugging.csproj index 49dd10b..c6b8e3f 100644 --- a/src/Libs/Systems.Debugging/Systems.Debugging.csproj +++ b/src/Libs/Systems.Debugging/Systems.Debugging.csproj @@ -18,6 +18,7 @@ +