Skip to content

Commit

Permalink
feat: imguinet entities list debug menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrynik committed Oct 31, 2023
1 parent 46c0eb0 commit 10a559d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Apps/GameDesktop/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Xna.Framework.Graphics;
using Scellecs.Morpeh;
using Serilog;
using Systems.Debugging;

namespace GameDesktop;

Expand All @@ -22,6 +23,8 @@ public class Game : Microsoft.Xna.Framework.Game
private ImGuiRenderer _guiRenderer;
private SpriteBatch _spriteBatch;

private SystemsGroup _debugSystemsGroup;

// TODO: Frames updating

// https://gafferongames.com/post/fix_your_timestep/
Expand All @@ -45,6 +48,9 @@ protected override void Initialize()
_container.RegisterSingleton(_ => new SpriteBatch(GraphicsDevice));
_spriteBatch = _container.GetInstance<SpriteBatch>();

_guiRenderer = new(this);
_guiRenderer.RebuildFontAtlas();

_logger.ForContext<Game>().Verbose("SpriteBatch initialized");

base.Initialize();
Expand All @@ -68,6 +74,11 @@ protected override void LoadContent()
var dummy = _container.GetInstance<DummyEntity>();
dummy.Create(@in: world);

#if DEBUG
_debugSystemsGroup = world.CreateSystemsGroup();
_debugSystemsGroup.AddSystem(new EntitiesList(world));
#endif

_logger.ForContext<Game>().Verbose("LoadContent(): end");
}

Expand Down Expand Up @@ -108,14 +119,15 @@ private void LateUpdate(GameTime gameTime)

protected override void Draw(GameTime gameTime)
{
float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
GraphicsDevice.Clear(Color.CornflowerBlue);

base.Draw(gameTime);

#if DEBUG
_guiRenderer.BeginLayout(gameTime);

ImGui.Text("Hi!");
_debugSystemsGroup.Update(deltaTime);

_guiRenderer.EndLayout();
#endif
Expand Down
1 change: 1 addition & 0 deletions src/Libs/Systems.Debugging/EntitiesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void OnUpdate(float deltaTime)

foreach (Entity e in filter)
{
ImGui.Text(e.ToString());
}
}

Expand Down

0 comments on commit 10a559d

Please sign in to comment.