2024-04-12 16:05:24 +02:00
|
|
|
using DisplayCommands;
|
2024-04-10 19:25:45 +02:00
|
|
|
using TanksServer.GameLogic;
|
2024-04-07 13:02:49 +02:00
|
|
|
|
2024-04-10 19:25:45 +02:00
|
|
|
namespace TanksServer.Graphics;
|
2024-04-07 13:02:49 +02:00
|
|
|
|
2024-04-13 14:07:14 +02:00
|
|
|
internal sealed class GeneratePixelsTickStep(
|
|
|
|
IEnumerable<IDrawStep> drawSteps,
|
2024-04-15 20:34:23 +02:00
|
|
|
IEnumerable<IFrameConsumer> consumers
|
2024-04-07 20:16:22 +02:00
|
|
|
) : ITickStep
|
2024-04-07 13:02:49 +02:00
|
|
|
{
|
2024-04-07 19:05:50 +02:00
|
|
|
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();
|
2024-04-15 20:34:23 +02:00
|
|
|
private readonly List<IFrameConsumer> _consumers = consumers.ToList();
|
2024-04-07 13:02:49 +02:00
|
|
|
|
2024-04-15 20:34:23 +02:00
|
|
|
private readonly PixelGrid _observerPixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
|
|
|
private readonly GamePixelGrid _gamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
|
|
|
|
2024-04-16 19:40:08 +02:00
|
|
|
public async Task TickAsync(TimeSpan _)
|
2024-04-07 13:02:49 +02:00
|
|
|
{
|
2024-04-15 20:34:23 +02:00
|
|
|
_gamePixelGrid.Clear();
|
2024-04-07 20:16:22 +02:00
|
|
|
foreach (var step in _drawSteps)
|
2024-04-15 20:34:23 +02:00
|
|
|
step.Draw(_gamePixelGrid);
|
|
|
|
|
|
|
|
_observerPixelGrid.Clear();
|
|
|
|
for (var y = 0; y < MapService.PixelsPerColumn; y++)
|
|
|
|
for (var x = 0; x < MapService.PixelsPerRow; x++)
|
|
|
|
{
|
|
|
|
if (_gamePixelGrid[x, y].EntityType.HasValue)
|
|
|
|
_observerPixelGrid[(ushort)x, (ushort)y] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var consumer in _consumers)
|
|
|
|
await consumer.OnFrameDoneAsync(_gamePixelGrid, _observerPixelGrid);
|
2024-04-07 13:02:49 +02:00
|
|
|
}
|
|
|
|
}
|