another data view
This commit is contained in:
parent
85ae3e302c
commit
91ab911f9c
|
@ -8,6 +8,6 @@ internal sealed class BulletDrawer(BulletManager bullets): IDrawStep
|
|||
public void Draw(PixelDisplayBufferView buffer)
|
||||
{
|
||||
foreach (var bullet in bullets.GetAll())
|
||||
buffer.Pixels[bullet.Position.ToPixelPosition().ToPixelIndex()] = true;
|
||||
buffer.Pixels[bullet.Position.ToPixelPosition()] = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ internal sealed class MapDrawer(MapService map) : IDrawStep
|
|||
for (byte pixelInTileY = 0; pixelInTileY < MapService.TileSize; pixelInTileY++)
|
||||
for (byte pixelInTileX = 0; pixelInTileX < MapService.TileSize; pixelInTileX++)
|
||||
{
|
||||
var index = tile.GetPixelRelative(pixelInTileX, pixelInTileY).ToPixelIndex();
|
||||
buffer.Pixels[index] = pixelInTileX % 2 == pixelInTileY % 2;
|
||||
var position = tile.GetPixelRelative(pixelInTileX, pixelInTileY);
|
||||
buffer.Pixels[position] = pixelInTileX % 2 == pixelInTileY % 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,18 +35,15 @@ internal sealed class TankDrawer : IDrawStep
|
|||
{
|
||||
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++)
|
||||
{
|
||||
var rowStartIndex = (pos.Y + dy) * MapService.PixelsPerRow;
|
||||
if (!TankSpriteAt(dx, dy, rotationVariant))
|
||||
continue;
|
||||
|
||||
for (var dx = 0; dx < MapService.TileSize; dx++)
|
||||
{
|
||||
if (!TankSpriteAt(dx, dy, rotationVariant))
|
||||
continue;
|
||||
|
||||
var i = rowStartIndex + pos.X + dx;
|
||||
buffer.Pixels[i] = true;
|
||||
}
|
||||
var position = new PixelPosition(pos.X + dx, pos.Y + dy);
|
||||
buffer.Pixels[position] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,4 +56,4 @@ internal sealed class TankDrawer : IDrawStep
|
|||
|
||||
return _tankSprite[index];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,8 +5,6 @@ namespace TanksServer.Models;
|
|||
|
||||
internal static class PositionHelpers
|
||||
{
|
||||
public static int ToPixelIndex(this PixelPosition position) => position.Y * MapService.PixelsPerRow + position.X;
|
||||
|
||||
public static PixelPosition GetPixelRelative(this TilePosition position, byte subX, byte subY)
|
||||
{
|
||||
Debug.Assert(subX < 8);
|
||||
|
|
23
TanksServer/ServicePointDisplay/FixedSizeBitGridView.cs
Normal file
23
TanksServer/ServicePointDisplay/FixedSizeBitGridView.cs
Normal file
|
@ -0,0 +1,23 @@
|
|||
using System.Diagnostics;
|
||||
|
||||
namespace TanksServer.ServicePointDisplay;
|
||||
|
||||
internal sealed class FixedSizeBitGridView(Memory<byte> data, int columns, int rows)
|
||||
{
|
||||
private readonly FixedSizeBitRowView _bits = new(data);
|
||||
|
||||
public bool this[PixelPosition position]
|
||||
{
|
||||
get => _bits[ToPixelIndex(position)];
|
||||
set => _bits[ToPixelIndex(position)] = value;
|
||||
}
|
||||
|
||||
private int ToPixelIndex(PixelPosition position)
|
||||
{
|
||||
Debug.Assert(position.X < columns);
|
||||
Debug.Assert(position.Y < rows);
|
||||
var index = position.Y * columns + position.X;
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(index, nameof(position));
|
||||
return index;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@ using System.Collections;
|
|||
|
||||
namespace TanksServer.ServicePointDisplay;
|
||||
|
||||
internal sealed class FixedSizeBitFieldView(Memory<byte> data) : IList<bool>
|
||||
internal sealed class FixedSizeBitRowView(Memory<byte> data) : IList<bool>
|
||||
{
|
||||
public int Count => data.Length * 8;
|
||||
public bool IsReadOnly => false;
|
|
@ -1,20 +1,22 @@
|
|||
using TanksServer.GameLogic;
|
||||
|
||||
namespace TanksServer.ServicePointDisplay;
|
||||
|
||||
internal sealed class PixelDisplayBufferView : DisplayBufferView
|
||||
{
|
||||
private PixelDisplayBufferView(byte[] data) : base(data)
|
||||
private PixelDisplayBufferView(byte[] data, int columns, int pixelRows) : base(data)
|
||||
{
|
||||
Pixels = new FixedSizeBitFieldView(Data.AsMemory(10));
|
||||
Pixels = new FixedSizeBitGridView(Data.AsMemory(10), columns, pixelRows);
|
||||
}
|
||||
|
||||
// ReSharper disable once CollectionNeverQueried.Global (setting values in collection updates underlying byte array)
|
||||
public FixedSizeBitFieldView Pixels { get; }
|
||||
public FixedSizeBitGridView Pixels { get; }
|
||||
|
||||
public static PixelDisplayBufferView New(ushort x, ushort y, ushort widthInTiles, ushort pixelRows)
|
||||
{
|
||||
// 10 bytes header, one byte per tile row (with one bit each pixel) after that
|
||||
var size = 10 + widthInTiles * pixelRows;
|
||||
return new PixelDisplayBufferView(new byte[size])
|
||||
return new PixelDisplayBufferView(new byte[size], widthInTiles * MapService.TileSize, pixelRows)
|
||||
{
|
||||
Mode = 19,
|
||||
TileX = x,
|
||||
|
|
|
@ -90,10 +90,10 @@ internal sealed class SendToServicePointDisplay : ITickStep, IDisposable
|
|||
foreach (var p in playersToDisplay)
|
||||
{
|
||||
var score = p.Kills.ToString();
|
||||
var nameLength = ScoresWidth - score.Length;
|
||||
var nameLength = Math.Min(p.Name.Length, ScoresWidth - score.Length - 1);
|
||||
|
||||
var name = p.Name[..nameLength];
|
||||
var spaces = new string(' ', nameLength - name.Length + 1);
|
||||
var spaces = new string(' ', ScoresWidth - score.Length - nameLength);
|
||||
|
||||
_scoresBuffer.Rows[row] = name + spaces + score;
|
||||
row++;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"TanksServer": "Debug"
|
||||
"TanksServer": "Debug",
|
||||
"Microsoft.AspNetCore.HttpLogging": "Debug"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
|
|
Loading…
Reference in a new issue