Skip to content

Commit

Permalink
chore: draw rect collision component & conditional debug
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrynik committed Oct 11, 2023
1 parent 7ef5a50 commit 90a632c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<DebugRootFeatureCompositionRoot>();
#endif

RegisterEntryPoint(serviceRegistry);
}

private static void RegisterFundamental(IServiceRegistry serviceRegistry)
{
private static void RegisterFundamental(IServiceRegistry serviceRegistry) =>
serviceRegistry.RegisterFrom<FundamentalCompositionRoot>();
}

private static void RegisterComponents(IServiceRegistry serviceRegistry)
{
private static void RegisterComponents(IServiceRegistry serviceRegistry) =>
serviceRegistry.RegisterFrom<ComponentsCompositionRoot>();
}

private static void RegisterEntities(IServiceRegistry serviceRegistry)
{
Expand All @@ -54,8 +51,6 @@ private static void RegisterFeatures(IServiceRegistry serviceRegistry)
serviceRegistry.RegisterFrom<MovementFeatureCompositionRoot>();
}

private static void RegisterEntryPoint(IServiceRegistry serviceRegistry)
{
private static void RegisterEntryPoint(IServiceRegistry serviceRegistry) =>
serviceRegistry.RegisterSingleton<RootFeature>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,44 @@ namespace Systems.Debugging;
public class DrawRectangleCollisionComponentsSystem : IDrawSystem
{
private readonly Contexts _contexts;
private readonly IGroup<GameEntity> _group;
private readonly ILogger _logger;

public DrawRectangleCollisionComponentsSystem(Contexts contexts, IGroup<GameEntity> group, ILogger logger)
{
_contexts = contexts;
_group = group;
_logger = logger;
}

public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
{
_logger.ForContext<DrawRectangleCollisionComponentsSystem>().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();
}
}
4 changes: 4 additions & 0 deletions src/Libs/Systems/DefaultDrawSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 90a632c

Please sign in to comment.