move backend to subfolder
This commit is contained in:
parent
d4d1f2f981
commit
8d09663eff
1 changed files with 97 additions and 87 deletions
|
|
@ -1,39 +0,0 @@
|
|||
using System.Diagnostics;
|
||||
using TanksServer.GameLogic;
|
||||
using TanksServer.Graphics;
|
||||
|
||||
namespace TanksServer.Interactivity;
|
||||
|
||||
internal sealed class PlayerScreenData(ILogger logger)
|
||||
{
|
||||
private readonly Memory<byte> _data = new byte[MapService.PixelsPerRow * MapService.PixelsPerColumn / 2];
|
||||
private int _count = 0;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_count = 0;
|
||||
_data.Span.Clear();
|
||||
}
|
||||
|
||||
public ReadOnlyMemory<byte> GetPacket()
|
||||
{
|
||||
var index = _count / 2 + (_count % 2 == 0 ? 0 : 1);
|
||||
logger.LogTrace("packet length: {} (count={})", index, _count);
|
||||
return _data[..index];
|
||||
}
|
||||
|
||||
public void Add(GamePixelEntityType entityKind, bool isCurrentPlayer)
|
||||
{
|
||||
var result = (byte)(isCurrentPlayer ? 0x1 : 0x0);
|
||||
var kind = (byte)entityKind;
|
||||
Debug.Assert(kind <= 3);
|
||||
result += (byte)(kind << 2);
|
||||
|
||||
var index = _count / 2;
|
||||
if (_count % 2 != 0)
|
||||
_data.Span[index] |= (byte)(result << 4);
|
||||
else
|
||||
_data.Span[index] = result;
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
Reference in a new issue