another data view
This commit is contained in:
parent
85ae3e302c
commit
91ab911f9c
9 changed files with 44 additions and 23 deletions
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++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue