2024-04-06 16:38:26 +02:00
|
|
|
using System.Net.WebSockets;
|
2024-04-12 16:05:24 +02:00
|
|
|
using DisplayCommands;
|
2024-04-15 20:34:23 +02:00
|
|
|
using TanksServer.Graphics;
|
2024-04-06 16:38:26 +02:00
|
|
|
|
2024-04-10 19:25:45 +02:00
|
|
|
namespace TanksServer.Interactivity;
|
2024-04-06 16:38:26 +02:00
|
|
|
|
2024-04-06 20:32:54 +02:00
|
|
|
internal sealed class ClientScreenServer(
|
|
|
|
ILogger<ClientScreenServer> logger,
|
2024-04-16 21:34:54 +02:00
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
IOptions<HostConfiguration> hostConfig
|
2024-04-21 23:00:44 +02:00
|
|
|
) : WebsocketServer<ClientScreenServerConnection>(logger), IFrameConsumer
|
2024-04-06 16:38:26 +02:00
|
|
|
{
|
2024-04-16 21:34:54 +02:00
|
|
|
private readonly TimeSpan _minFrameTime = TimeSpan.FromMilliseconds(hostConfig.Value.ClientDisplayMinFrameTimeMs);
|
2024-04-06 16:38:26 +02:00
|
|
|
|
2024-04-21 23:00:44 +02:00
|
|
|
public Task HandleClientAsync(WebSocket socket, Guid? playerGuid)
|
|
|
|
=> base.HandleClientAsync(new(
|
2024-04-16 00:07:44 +02:00
|
|
|
socket,
|
|
|
|
loggerFactory.CreateLogger<ClientScreenServerConnection>(),
|
2024-04-16 21:34:54 +02:00
|
|
|
_minFrameTime,
|
2024-04-21 23:00:44 +02:00
|
|
|
playerGuid
|
|
|
|
));
|
2024-04-15 20:34:23 +02:00
|
|
|
|
|
|
|
public Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels)
|
2024-04-21 23:00:44 +02:00
|
|
|
=> ParallelForEachConnectionAsync(c => c.SendAsync(observerPixels, gamePixelGrid));
|
2024-04-13 12:33:08 +02:00
|
|
|
}
|