update servicepoint to branch with better codegen
This commit is contained in:
parent
4fad4612b7
commit
416c8f2165
|
@ -42,7 +42,7 @@ internal sealed class MapService
|
||||||
if (!_mapPrototypes.TryGetValue(name, out var prototype))
|
if (!_mapPrototypes.TryGetValue(name, out var prototype))
|
||||||
return false; // name not found
|
return false; // name not found
|
||||||
|
|
||||||
pixelGrid = Bitmap.New(PixelsPerRow, PixelsPerColumn);
|
pixelGrid = new Bitmap(PixelsPerRow, PixelsPerColumn);
|
||||||
DrawMapStep.Draw(pixelGrid, prototype.CreateInstance());
|
DrawMapStep.Draw(pixelGrid, prototype.CreateInstance());
|
||||||
|
|
||||||
_mapPreviews.TryAdd(name, pixelGrid); // another thread may have added the map already
|
_mapPreviews.TryAdd(name, pixelGrid); // another thread may have added the map already
|
||||||
|
|
|
@ -7,12 +7,12 @@ namespace TanksServer.Graphics;
|
||||||
internal sealed class GeneratePixelsTickStep(
|
internal sealed class GeneratePixelsTickStep(
|
||||||
IEnumerable<IDrawStep> drawSteps,
|
IEnumerable<IDrawStep> drawSteps,
|
||||||
IEnumerable<IFrameConsumer> consumers
|
IEnumerable<IFrameConsumer> consumers
|
||||||
) : ITickStep
|
) : ITickStep, IDisposable
|
||||||
{
|
{
|
||||||
private GamePixelGrid _lastGamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
private GamePixelGrid _lastGamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||||
private Bitmap _lastObserverPixelGrid = Bitmap.New(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
private Bitmap _lastObserverPixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||||
private GamePixelGrid _gamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
private GamePixelGrid _gamePixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||||
private Bitmap _observerPixelGrid = Bitmap.New(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
private Bitmap _observerPixelGrid = new(MapService.PixelsPerRow, MapService.PixelsPerColumn);
|
||||||
|
|
||||||
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();
|
private readonly List<IDrawStep> _drawSteps = drawSteps.ToList();
|
||||||
private readonly List<IFrameConsumer> _consumers = consumers.ToList();
|
private readonly List<IFrameConsumer> _consumers = consumers.ToList();
|
||||||
|
@ -44,4 +44,10 @@ internal sealed class GeneratePixelsTickStep(
|
||||||
observerPixelGrid[(ushort)x, (ushort)y] = true;
|
observerPixelGrid[(ushort)x, (ushort)y] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_lastObserverPixelGrid.Dispose();
|
||||||
|
_observerPixelGrid.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,11 +4,10 @@ using System.Net.Sockets;
|
||||||
using ServicePoint;
|
using ServicePoint;
|
||||||
using TanksServer.GameLogic;
|
using TanksServer.GameLogic;
|
||||||
using TanksServer.Graphics;
|
using TanksServer.Graphics;
|
||||||
using CompressionCode = ServicePoint.BindGen.CompressionCode;
|
|
||||||
|
|
||||||
namespace TanksServer.Interactivity;
|
namespace TanksServer.Interactivity;
|
||||||
|
|
||||||
internal sealed class SendToServicePointDisplay : IFrameConsumer
|
internal sealed class SendToServicePointDisplay : IFrameConsumer, IDisposable
|
||||||
{
|
{
|
||||||
private const int ScoresWidth = 12;
|
private const int ScoresWidth = 12;
|
||||||
private const int ScoresHeight = 20;
|
private const int ScoresHeight = 20;
|
||||||
|
@ -43,7 +42,7 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer
|
||||||
|
|
||||||
var localIp = GetLocalIPv4(displayConfig.Value).Split('.');
|
var localIp = GetLocalIPv4(displayConfig.Value).Split('.');
|
||||||
Debug.Assert(localIp.Length == 4);
|
Debug.Assert(localIp.Length == 4);
|
||||||
_scoresBuffer = Cp437Grid.New(12, 20);
|
_scoresBuffer = new Cp437Grid(12, 20);
|
||||||
|
|
||||||
_scoresBuffer[00] = "== TANKS! ==";
|
_scoresBuffer[00] = "== TANKS! ==";
|
||||||
_scoresBuffer[01] = "-- scores --";
|
_scoresBuffer[01] = "-- scores --";
|
||||||
|
@ -113,4 +112,10 @@ internal sealed class SendToServicePointDisplay : IFrameConsumer
|
||||||
var endPoint = socket.LocalEndPoint as IPEndPoint ?? throw new NotSupportedException();
|
var endPoint = socket.LocalEndPoint as IPEndPoint ?? throw new NotSupportedException();
|
||||||
return endPoint.Address.ToString();
|
return endPoint.Address.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_displayConnection.Dispose();
|
||||||
|
_scoresBuffer.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using ServicePoint;
|
using ServicePoint;
|
||||||
using SixLabors.ImageSharp;
|
|
||||||
using TanksServer.GameLogic;
|
using TanksServer.GameLogic;
|
||||||
using TanksServer.Graphics;
|
using TanksServer.Graphics;
|
||||||
using TanksServer.Interactivity;
|
using TanksServer.Interactivity;
|
||||||
|
@ -101,7 +100,11 @@ public static class Program
|
||||||
builder.Services.AddSingleton<Connection>(sp =>
|
builder.Services.AddSingleton<Connection>(sp =>
|
||||||
{
|
{
|
||||||
var config = sp.GetRequiredService<IOptions<DisplayConfiguration>>().Value;
|
var config = sp.GetRequiredService<IOptions<DisplayConfiguration>>().Value;
|
||||||
return Connection.Open($"{config.Hostname}:{config.Port}");
|
var connection = Connection.Open($"{config.Hostname}:{config.Port}");
|
||||||
|
if (connection == null)
|
||||||
|
throw new IOException($"Could not open connection to {config.Hostname}:{config.Port}");
|
||||||
|
|
||||||
|
return connection;
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9193cfec10c72d99ad01b1ae09a935007588d7d9
|
Subproject commit f968f929173c6646acb7d9a3ed19112e626732b3
|
Loading…
Reference in a new issue