From 90a632c4a4d3f4bb7805e57e2b7d168fd89edeaa Mon Sep 17 00:00:00 2001 From: Nik Date: Wed, 11 Oct 2023 12:29:56 +0300 Subject: [PATCH] chore: draw rect collision component & conditional debug --- .../Features/RootFeatureCompositionRoot.cs | 15 ++++------ .../DrawRectangleCollisionComponentsSystem.cs | 30 ++++++++++++++++++- src/Libs/Systems/DefaultDrawSystem.cs | 4 +++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs b/src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs index b391b2c..3edf6d1 100644 --- a/src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs +++ b/src/Apps/GameDesktop/CompositionRoots/Features/RootFeatureCompositionRoot.cs @@ -24,21 +24,18 @@ public void Compose(IServiceRegistry serviceRegistry) RegisterFeatures(serviceRegistry); - // Extra pre-entry point for debugging, might be safely excluded +#if DEBUG serviceRegistry.RegisterFrom(); +#endif RegisterEntryPoint(serviceRegistry); } - private static void RegisterFundamental(IServiceRegistry serviceRegistry) - { + private static void RegisterFundamental(IServiceRegistry serviceRegistry) => serviceRegistry.RegisterFrom(); - } - private static void RegisterComponents(IServiceRegistry serviceRegistry) - { + private static void RegisterComponents(IServiceRegistry serviceRegistry) => serviceRegistry.RegisterFrom(); - } private static void RegisterEntities(IServiceRegistry serviceRegistry) { @@ -54,8 +51,6 @@ private static void RegisterFeatures(IServiceRegistry serviceRegistry) serviceRegistry.RegisterFrom(); } - private static void RegisterEntryPoint(IServiceRegistry serviceRegistry) - { + private static void RegisterEntryPoint(IServiceRegistry serviceRegistry) => serviceRegistry.RegisterSingleton(); - } } diff --git a/src/Libs/Systems.Debugging/DrawRectangleCollisionComponentsSystem.cs b/src/Libs/Systems.Debugging/DrawRectangleCollisionComponentsSystem.cs index c322b10..f0ce73e 100644 --- a/src/Libs/Systems.Debugging/DrawRectangleCollisionComponentsSystem.cs +++ b/src/Libs/Systems.Debugging/DrawRectangleCollisionComponentsSystem.cs @@ -9,16 +9,44 @@ namespace Systems.Debugging; public class DrawRectangleCollisionComponentsSystem : IDrawSystem { private readonly Contexts _contexts; + private readonly IGroup _group; private readonly ILogger _logger; public DrawRectangleCollisionComponentsSystem(Contexts contexts, IGroup group, ILogger logger) { _contexts = contexts; + _group = group; _logger = logger; } public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { - _logger.ForContext().Verbose("Draw"); + GameEntity[] entities = _group.GetEntities(); + + + spriteBatch.Begin(samplerState: SamplerState.PointClamp); + + // temp start + Color[] colors = { Color.Black, Color.White }; + int i = 0; + // temp end + + foreach (var e in entities) + { + Vector2 at = e.transform.Position; + Rectangle rectangleSize = e.rectangleCollision.Size; + + // temp start + var texture = new Texture2D(spriteBatch.GraphicsDevice, 1, 1); + texture.SetData(new[] { colors[i] }); + ++i; + if (i is 2) + i = 0; + // temp end + + spriteBatch.Draw(texture, at, sourceRectangle: rectangleSize, Color.White); + } + + spriteBatch.End(); } } diff --git a/src/Libs/Systems/DefaultDrawSystem.cs b/src/Libs/Systems/DefaultDrawSystem.cs index c6531de..b57564a 100644 --- a/src/Libs/Systems/DefaultDrawSystem.cs +++ b/src/Libs/Systems/DefaultDrawSystem.cs @@ -38,4 +38,8 @@ public void Draw(GameTime gameTime, SpriteBatch spriteBatch) spriteBatch.End(); } + // TODO: When camera following feature is enabled, + // Make it working with other drawing systems, e.g. debug drawing. + // Thus, draw relatively to camera. + // Share rendering results with other systems (sorting, etc) }