more commands, change display communication to new lib
This commit is contained in:
parent
38463ac109
commit
7213318838
31 changed files with 240 additions and 417 deletions
|
@ -1,13 +1,16 @@
|
|||
using DisplayCommands;
|
||||
using TanksServer.GameLogic;
|
||||
using TanksServer.ServicePointDisplay;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
internal sealed class BulletDrawer(BulletManager bullets): IDrawStep
|
||||
internal sealed class BulletDrawer(BulletManager bullets) : IDrawStep
|
||||
{
|
||||
public void Draw(PixelDisplayBufferView buffer)
|
||||
public void Draw(PixelGrid buffer)
|
||||
{
|
||||
foreach (var bullet in bullets.GetAll())
|
||||
buffer.Pixels[bullet.Position.ToPixelPosition()] = true;
|
||||
{
|
||||
var pos = bullet.Position.ToPixelPosition();
|
||||
buffer[pos.X, pos.Y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
using DisplayCommands;
|
||||
using TanksServer.GameLogic;
|
||||
using TanksServer.ServicePointDisplay;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
|
@ -8,13 +8,14 @@ internal sealed class DrawStateToFrame(
|
|||
) : ITickStep
|
||||
{
|
||||
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();
|
||||
private readonly PixelGrid _drawGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||
|
||||
public Task TickAsync()
|
||||
{
|
||||
var buffer = PixelDisplayBufferView.New(0, 0, MapService.TilesPerRow, MapService.PixelsPerColumn);
|
||||
_drawGrid.Clear();
|
||||
foreach (var step in _drawSteps)
|
||||
step.Draw(buffer);
|
||||
lastFrameProvider.LastFrame = buffer;
|
||||
step.Draw(_drawGrid);
|
||||
lastFrameProvider.LastFrame = _drawGrid;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using TanksServer.ServicePointDisplay;
|
||||
using DisplayCommands;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
internal interface IDrawStep
|
||||
{
|
||||
void Draw(PixelDisplayBufferView buffer);
|
||||
void Draw(PixelGrid buffer);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using TanksServer.ServicePointDisplay;
|
||||
using DisplayCommands;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
internal sealed class LastFinishedFrameProvider
|
||||
{
|
||||
private PixelDisplayBufferView? _lastFrame;
|
||||
private PixelGrid? _lastFrame;
|
||||
|
||||
public PixelDisplayBufferView LastFrame
|
||||
public PixelGrid LastFrame
|
||||
{
|
||||
get => _lastFrame ?? throw new InvalidOperationException("first frame not yet drawn");
|
||||
set => _lastFrame = value;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
using DisplayCommands;
|
||||
using TanksServer.GameLogic;
|
||||
using TanksServer.ServicePointDisplay;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
internal sealed class MapDrawer(MapService map) : IDrawStep
|
||||
{
|
||||
public void Draw(PixelDisplayBufferView buffer)
|
||||
public void Draw(PixelGrid buffer)
|
||||
{
|
||||
for (var tileY = 0; tileY < MapService.TilesPerColumn; tileY++)
|
||||
for (var tileX = 0; tileX < MapService.TilesPerRow; tileX++)
|
||||
|
@ -18,8 +18,8 @@ internal sealed class MapDrawer(MapService map) : IDrawStep
|
|||
for (byte pixelInTileX = 0; pixelInTileX < MapService.TileSize; pixelInTileX++)
|
||||
{
|
||||
var position = tile.GetPixelRelative(pixelInTileX, pixelInTileY);
|
||||
buffer.Pixels[position] = pixelInTileX % 2 == pixelInTileY % 2;
|
||||
buffer[position.X, position.Y] = pixelInTileX % 2 == pixelInTileY % 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
using DisplayCommands;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using TanksServer.GameLogic;
|
||||
using TanksServer.ServicePointDisplay;
|
||||
|
||||
namespace TanksServer.Graphics;
|
||||
|
||||
|
@ -29,21 +29,21 @@ internal sealed class TankDrawer : IDrawStep
|
|||
_tankSpriteWidth = tankImage.Width;
|
||||
}
|
||||
|
||||
public void Draw(PixelDisplayBufferView buffer)
|
||||
public void Draw(PixelGrid buffer)
|
||||
{
|
||||
foreach (var tank in _tanks)
|
||||
{
|
||||
var pos = tank.Position.ToPixelPosition();
|
||||
var rotationVariant = (int)Math.Round(tank.Rotation) % 16;
|
||||
|
||||
|
||||
for (var dy = 0; dy < MapService.TileSize; dy++)
|
||||
for (var dx = 0; dx < MapService.TileSize; dx++)
|
||||
{
|
||||
if (!TankSpriteAt(dx, dy, rotationVariant))
|
||||
continue;
|
||||
|
||||
var position = new PixelPosition(pos.X + dx, pos.Y + dy);
|
||||
buffer.Pixels[position] = true;
|
||||
var position = new PixelPosition((ushort)(pos.X + dx), (ushort)(pos.Y + dy));
|
||||
buffer[position.X, position.Y] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue