enable and disable big screen at runtime

This commit is contained in:
Vinzenz Schroeter 2024-05-08 01:00:11 +02:00
parent a4aab442e5
commit b47901313b
2 changed files with 10 additions and 12 deletions

View file

@ -18,6 +18,7 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer
private readonly PlayerServer _players; private readonly PlayerServer _players;
private readonly Cp437Grid _scoresBuffer; private readonly Cp437Grid _scoresBuffer;
private readonly TimeSpan _minFrameTime; private readonly TimeSpan _minFrameTime;
private readonly IOptionsMonitor<HostConfiguration> _options;
private DateTime _nextFailLogAfter = DateTime.Now; private DateTime _nextFailLogAfter = DateTime.Now;
private DateTime _nextFrameAfter = DateTime.Now; private DateTime _nextFrameAfter = DateTime.Now;
@ -27,7 +28,8 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer
ILogger<SendToServicePointDisplay> logger, ILogger<SendToServicePointDisplay> logger,
IDisplayConnection displayConnection, IDisplayConnection displayConnection,
IOptions<HostConfiguration> hostOptions, IOptions<HostConfiguration> hostOptions,
MapService mapService MapService mapService,
IOptionsMonitor<HostConfiguration> options
) )
{ {
_players = players; _players = players;
@ -35,6 +37,7 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer
_displayConnection = displayConnection; _displayConnection = displayConnection;
_mapService = mapService; _mapService = mapService;
_minFrameTime = TimeSpan.FromMilliseconds(hostOptions.Value.ServicePointDisplayMinFrameTimeMs); _minFrameTime = TimeSpan.FromMilliseconds(hostOptions.Value.ServicePointDisplayMinFrameTimeMs);
_options = options;
var localIp = _displayConnection.GetLocalIPv4().Split('.'); var localIp = _displayConnection.GetLocalIPv4().Split('.');
Debug.Assert(localIp.Length == 4); Debug.Assert(localIp.Length == 4);
@ -50,6 +53,9 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer
public async Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels) public async Task OnFrameDoneAsync(GamePixelGrid gamePixelGrid, PixelGrid observerPixels)
{ {
if (!_options.CurrentValue.EnableServicePointDisplay)
return;
if (DateTime.Now < _nextFrameAfter) if (DateTime.Now < _nextFrameAfter)
return; return;

View file

@ -1,7 +1,6 @@
using System.IO; using System.IO;
using DisplayCommands; using DisplayCommands;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using TanksServer.GameLogic; using TanksServer.GameLogic;
@ -54,11 +53,6 @@ public static class Program
var healthCheckBuilder = builder.Services.AddHealthChecks(); var healthCheckBuilder = builder.Services.AddHealthChecks();
healthCheckBuilder.AddCheck<UpdatesPerSecondCounter>("updates check"); healthCheckBuilder.AddCheck<UpdatesPerSecondCounter>("updates check");
builder.Services.Configure<HostConfiguration>(builder.Configuration.GetSection("Host"));
var hostConfiguration = builder.Configuration.GetSection("Host").Get<HostConfiguration>();
if (hostConfiguration == null)
throw new InvalidOperationException("'Host' configuration missing");
builder.Services.AddSingleton<MapService>(); builder.Services.AddSingleton<MapService>();
builder.Services.AddSingleton<MapEntityManager>(); builder.Services.AddSingleton<MapEntityManager>();
builder.Services.AddSingleton<ControlsServer>(); builder.Services.AddSingleton<ControlsServer>();
@ -99,12 +93,10 @@ public static class Program
sp.GetRequiredService<ClientScreenServer>()); sp.GetRequiredService<ClientScreenServer>());
builder.Services.Configure<GameRules>(builder.Configuration.GetSection("GameRules")); builder.Services.Configure<GameRules>(builder.Configuration.GetSection("GameRules"));
builder.Services.Configure<HostConfiguration>(builder.Configuration.GetSection("Host"));
if (hostConfiguration.EnableServicePointDisplay) builder.Services.AddSingleton<IFrameConsumer, SendToServicePointDisplay>();
{ builder.Services.AddDisplay(builder.Configuration.GetSection("ServicePointDisplay"));
builder.Services.AddSingleton<IFrameConsumer, SendToServicePointDisplay>();
builder.Services.AddDisplay(builder.Configuration.GetSection("ServicePointDisplay"));
}
var app = builder.Build(); var app = builder.Build();