wip move to new uniffi language binding

This commit is contained in:
Vinzenz Schroeter 2024-11-12 18:27:04 +01:00
parent f7a5d8f823
commit 53cbdd8440
30 changed files with 211 additions and 187 deletions

View file

@ -2,13 +2,13 @@ using System.Buffers;
namespace TanksServer.Interactivity;
internal sealed class BufferPool: MemoryPool<byte>
internal sealed class BufferPool : MemoryPool<byte>
{
private readonly MemoryPool<byte> _actualPool = Shared;
public override int MaxBufferSize => int.MaxValue;
protected override void Dispose(bool disposing) {}
protected override void Dispose(bool disposing) { }
public override IMemoryOwner<byte> Rent(int minBufferSize = -1)
{
@ -16,7 +16,7 @@ internal sealed class BufferPool: MemoryPool<byte>
return new BufferPoolMemoryOwner(_actualPool.Rent(minBufferSize), minBufferSize);
}
private sealed class BufferPoolMemoryOwner(IMemoryOwner<byte> actualOwner, int wantedSize): IMemoryOwner<byte>
private sealed class BufferPoolMemoryOwner(IMemoryOwner<byte> actualOwner, int wantedSize) : IMemoryOwner<byte>
{
public Memory<byte> Memory { get; } = actualOwner.Memory[..wantedSize];

View file

@ -36,7 +36,7 @@ internal sealed class ClientScreenServerConnection
private Package BuildNextPackage(Bitmap pixels, GamePixelGrid gamePixelGrid)
{
var pixelsData = pixels.Data;
var pixelsData = pixels.CopyRaw();
var nextPixels = _bufferPool.Rent(pixelsData.Length);
pixelsData.CopyTo(nextPixels.Memory.Span);

View file

@ -17,7 +17,7 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer, IDisposable
private readonly MapService _mapService;
private readonly ILogger<SendToServicePointDisplay> _logger;
private readonly PlayerServer _players;
private readonly Cp437Grid _scoresBuffer;
private readonly CharGrid _scoresBuffer;
private readonly TimeSpan _minFrameTime;
private readonly IOptionsMonitor<HostConfiguration> _options;
@ -42,13 +42,13 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer, IDisposable
var localIp = GetLocalIPv4(displayConfig.Value).Split('.');
Debug.Assert(localIp.Length == 4);
_scoresBuffer = new Cp437Grid(12, 20);
_scoresBuffer = new CharGrid(12, 20);
_scoresBuffer[00] = "== TANKS! ==";
_scoresBuffer[01] = "-- scores --";
_scoresBuffer[17] = "-- join --";
_scoresBuffer[18] = string.Join('.', localIp[..2]);
_scoresBuffer[19] = string.Join('.', localIp[2..]);
_scoresBuffer.SetRow(00, "== TANKS! ==");
_scoresBuffer.SetRow(01, "-- scores --");
_scoresBuffer.SetRow(17, "-- join --");
_scoresBuffer.SetRow(18, string.Join('.', localIp[..2]));
_scoresBuffer.SetRow(19, string.Join('.', localIp[2..]));
}
public async Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, Bitmap observerPixels)
@ -66,9 +66,8 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer, IDisposable
try
{
_displayConnection.Send(Command.BitmapLinearWin(0, 0, observerPixels.Clone(), CompressionCode.Lzma)
.IntoPacket());
_displayConnection.Send(Command.Cp437Data(MapService.TilesPerRow, 0, _scoresBuffer.Clone()).IntoPacket());
_displayConnection.Send(Command.BitmapLinearWin(0, 0, observerPixels, CompressionCode.Lzma));
_displayConnection.Send(Command.Cp437Data(MapService.TilesPerRow, 0, _scoresBuffer.ToCp437()));
}
catch (SocketException ex)
{
@ -95,14 +94,14 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer, IDisposable
var name = p.Name[..nameLength];
var spaces = new string(' ', ScoresWidth - score.Length - nameLength);
_scoresBuffer[row] = name + spaces + score;
_scoresBuffer.SetRow(row, name + spaces + score);
row++;
}
for (; row < 16; row++)
_scoresBuffer[row] = string.Empty;
_scoresBuffer.SetRow(row, new string(' ', ScoresWidth));
_scoresBuffer[16] = _mapService.Current.Name[..(Math.Min(ScoresWidth, _mapService.Current.Name.Length) - 1)];
_scoresBuffer.SetRow(16, _mapService.Current.Name[..(Math.Min(ScoresWidth, _mapService.Current.Name.Length) - 1)]);
}
private static string GetLocalIPv4(DisplayConfiguration configuration)

View file

@ -3,7 +3,7 @@ namespace TanksServer.Interactivity;
internal abstract class WebsocketServerConnection(
ILogger logger,
ByteChannelWebSocket socket
): IDisposable
) : IDisposable
{
protected readonly ByteChannelWebSocket Socket = socket;
protected readonly ILogger Logger = logger;