separate folders per functionality

This commit is contained in:
Vinzenz Schroeter 2024-04-10 19:25:45 +02:00
parent 7f00160780
commit 0ca6a91a7e
33 changed files with 60 additions and 113 deletions

View file

@ -1,6 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
namespace TanksServer.Services;
internal sealed class BulletManager internal sealed class BulletManager
{ {

View file

@ -1,8 +1,4 @@
using TanksServer.Helpers; namespace TanksServer.GameLogic;
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class CollideBulletsWithMap(BulletManager bullets, MapService map) : ITickStep internal sealed class CollideBulletsWithMap(BulletManager bullets, MapService map) : ITickStep
{ {

View file

@ -1,7 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class CollideBulletsWithTanks( internal sealed class CollideBulletsWithTanks(
BulletManager bullets, TankManager tanks, SpawnQueueProvider spawnQueueProvider BulletManager bullets, TankManager tanks, SpawnQueueProvider spawnQueueProvider

View file

@ -1,9 +1,7 @@
using System.Diagnostics; using System.Diagnostics;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TanksServer.TickSteps;
namespace TanksServer.Services; namespace TanksServer.GameLogic;
internal sealed class GameTickWorker( internal sealed class GameTickWorker(
IEnumerable<ITickStep> steps, IEnumerable<ITickStep> steps,

View file

@ -1,4 +1,4 @@
namespace TanksServer.TickSteps; namespace TanksServer.GameLogic;
public interface ITickStep public interface ITickStep
{ {

View file

@ -1,6 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
namespace TanksServer.Services;
internal sealed class MapService internal sealed class MapService
{ {

View file

@ -1,7 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class MoveBullets(BulletManager bullets) : ITickStep internal sealed class MoveBullets(BulletManager bullets) : ITickStep
{ {

View file

@ -1,10 +1,9 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class MoveTanks( internal sealed class MoveTanks(
TankManager tanks, IOptions<TanksConfiguration> options, MapService map TankManager tanks,
IOptions<TanksConfiguration> options,
MapService map
) : ITickStep ) : ITickStep
{ {
private readonly TanksConfiguration _config = options.Value; private readonly TanksConfiguration _config = options.Value;

View file

@ -1,7 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class RotateTanks(TankManager tanks, IOptions<TanksConfiguration> options) : ITickStep internal sealed class RotateTanks(TankManager tanks, IOptions<TanksConfiguration> options) : ITickStep
{ {

View file

@ -1,7 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class ShootFromTanks( internal sealed class ShootFromTanks(
TankManager tanks, TankManager tanks,

View file

@ -1,7 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.TickSteps;
internal sealed class SpawnNewTanks(TankManager tanks, MapService map, SpawnQueueProvider queueProvider) : ITickStep internal sealed class SpawnNewTanks(TankManager tanks, MapService map, SpawnQueueProvider queueProvider) : ITickStep
{ {

View file

@ -1,6 +1,4 @@
using TanksServer.Models; namespace TanksServer.GameLogic;
namespace TanksServer.Services;
internal sealed class SpawnQueueProvider internal sealed class SpawnQueueProvider
{ {

View file

@ -1,8 +1,6 @@
using System.Collections; using System.Collections;
using Microsoft.Extensions.Logging;
using TanksServer.Models;
namespace TanksServer.Services; namespace TanksServer.GameLogic;
internal sealed class TankManager(ILogger<TankManager> logger) : IEnumerable<Tank> internal sealed class TankManager(ILogger<TankManager> logger) : IEnumerable<Tank>
{ {

View file

@ -4,4 +4,6 @@ global using System.Collections.Generic;
global using System.Linq; global using System.Linq;
global using System.Threading; global using System.Threading;
global using System.Threading.Tasks; global using System.Threading.Tasks;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options; global using Microsoft.Extensions.Options;
global using TanksServer.Models;

View file

@ -1,8 +1,7 @@
using TanksServer.Helpers; using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.DrawSteps; namespace TanksServer.Graphics;
internal sealed class BulletDrawer(BulletManager bullets): IDrawStep internal sealed class BulletDrawer(BulletManager bullets): IDrawStep
{ {

View file

@ -1,8 +1,7 @@
using TanksServer.DrawSteps; using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.TickSteps; namespace TanksServer.Graphics;
internal sealed class DrawStateToFrame( internal sealed class DrawStateToFrame(
IEnumerable<IDrawStep> drawSteps, LastFinishedFrameProvider lastFrameProvider IEnumerable<IDrawStep> drawSteps, LastFinishedFrameProvider lastFrameProvider

View file

@ -1,6 +1,6 @@
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
namespace TanksServer.DrawSteps; namespace TanksServer.Graphics;
internal interface IDrawStep internal interface IDrawStep
{ {

View file

@ -1,6 +1,6 @@
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
namespace TanksServer.Services; namespace TanksServer.Graphics;
internal sealed class LastFinishedFrameProvider internal sealed class LastFinishedFrameProvider
{ {

View file

@ -1,9 +1,7 @@
using TanksServer.Helpers; using TanksServer.GameLogic;
using TanksServer.Models;
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.DrawSteps; namespace TanksServer.Graphics;
internal sealed class MapDrawer(MapService map) : IDrawStep internal sealed class MapDrawer(MapService map) : IDrawStep
{ {

View file

@ -1,10 +1,9 @@
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using TanksServer.Helpers; using TanksServer.GameLogic;
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
using TanksServer.Services;
namespace TanksServer.DrawSteps; namespace TanksServer.Graphics;
internal sealed class TankDrawer : IDrawStep internal sealed class TankDrawer : IDrawStep
{ {

View file

@ -1,7 +1,6 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using TanksServer.Models;
namespace TanksServer.Helpers; namespace TanksServer.Interactivity;
[JsonSerializable(typeof(Player))] [JsonSerializable(typeof(Player))]
internal sealed partial class AppSerializerContext: JsonSerializerContext; internal sealed partial class AppSerializerContext: JsonSerializerContext;

View file

@ -1,9 +1,8 @@
using System.Diagnostics; using System.Diagnostics;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Threading.Channels; using System.Threading.Channels;
using Microsoft.Extensions.Logging;
namespace TanksServer.Helpers; namespace TanksServer.Interactivity;
/// <summary> /// <summary>
/// Hacky class for easier semantics /// Hacky class for easier semantics

View file

@ -2,11 +2,9 @@ using System.Diagnostics;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Threading.Channels; using System.Threading.Channels;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TanksServer.Helpers;
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
namespace TanksServer.Servers; namespace TanksServer.Interactivity;
internal sealed class ClientScreenServer( internal sealed class ClientScreenServer(
ILogger<ClientScreenServer> logger, ILogger<ClientScreenServer> logger,

View file

@ -1,15 +1,12 @@
using System.Net.WebSockets; using System.Net.WebSockets;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using TanksServer.Helpers;
using TanksServer.Models;
namespace TanksServer.Servers; namespace TanksServer.Interactivity;
internal sealed class ControlsServer(ILogger<ControlsServer> logger, ILoggerFactory loggerFactory) internal sealed class ControlsServer(ILogger<ControlsServer> logger, ILoggerFactory loggerFactory)
: IHostedLifecycleService : IHostedLifecycleService
{ {
private readonly List<ControlsServerConnection> _connections = new(); private readonly List<ControlsServerConnection> _connections = [];
public Task HandleClient(WebSocket ws, Player player) public Task HandleClient(WebSocket ws, Player player)
{ {

View file

@ -1,9 +1,7 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging; using TanksServer.GameLogic;
using TanksServer.Models;
using TanksServer.Services;
namespace TanksServer.Servers; namespace TanksServer.Interactivity;
internal sealed class PlayerServer(ILogger<PlayerServer> logger, SpawnQueueProvider spawnQueueProvider) internal sealed class PlayerServer(ILogger<PlayerServer> logger, SpawnQueueProvider spawnQueueProvider)
{ {

View file

@ -1,7 +1,7 @@
using TanksServer.Servers; using TanksServer.GameLogic;
using TanksServer.Services; using TanksServer.Graphics;
namespace TanksServer.TickSteps; namespace TanksServer.Interactivity;
internal sealed class SendToClientScreen( internal sealed class SendToClientScreen(
ClientScreenServer clientScreenServer, ClientScreenServer clientScreenServer,

View file

@ -1,15 +1,11 @@
using System.Diagnostics; using System.Diagnostics;
using TanksServer.Models; using TanksServer.GameLogic;
using TanksServer.Services;
namespace TanksServer.Helpers; namespace TanksServer.Models;
internal static class PositionHelpers internal static class PositionHelpers
{ {
public static int ToPixelIndex(this PixelPosition position) public static int ToPixelIndex(this PixelPosition position) => position.Y * MapService.PixelsPerRow + position.X;
{
return position.Y * MapService.PixelsPerRow + position.X;
}
public static PixelPosition GetPixelRelative(this TilePosition position, byte subX, byte subY) public static PixelPosition GetPixelRelative(this TilePosition position, byte subX, byte subY)
{ {
@ -31,4 +27,4 @@ internal static class PositionHelpers
X: position.X / MapService.TileSize, X: position.X / MapService.TileSize,
Y: position.Y / MapService.TileSize Y: position.Y / MapService.TileSize
); );
} }

View file

@ -1,4 +1,4 @@
using TanksServer.Services; using TanksServer.GameLogic;
namespace TanksServer.Models; namespace TanksServer.Models;

View file

@ -4,12 +4,10 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using TanksServer.DrawSteps; using TanksServer.GameLogic;
using TanksServer.Helpers; using TanksServer.Graphics;
using TanksServer.Servers; using TanksServer.Interactivity;
using TanksServer.ServicePointDisplay; using TanksServer.ServicePointDisplay;
using TanksServer.Services;
using TanksServer.TickSteps;
namespace TanksServer; namespace TanksServer;

View file

@ -1,5 +1,3 @@
using TanksServer.Models;
namespace TanksServer.ServicePointDisplay; namespace TanksServer.ServicePointDisplay;
internal class DisplayBufferView(byte[] data) internal class DisplayBufferView(byte[] data)

View file

@ -1,6 +1,3 @@
using TanksServer.Helpers;
using TanksServer.Services;
namespace TanksServer.ServicePointDisplay; namespace TanksServer.ServicePointDisplay;
internal sealed class PixelDisplayBufferView : DisplayBufferView internal sealed class PixelDisplayBufferView : DisplayBufferView

View file

@ -1,10 +1,9 @@
using System.Diagnostics; using System.Diagnostics;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using Microsoft.Extensions.Logging; using TanksServer.GameLogic;
using TanksServer.Servers; using TanksServer.Graphics;
using TanksServer.Services; using TanksServer.Interactivity;
using TanksServer.TickSteps;
namespace TanksServer.ServicePointDisplay; namespace TanksServer.ServicePointDisplay;
@ -34,16 +33,19 @@ internal sealed class SendToServicePointDisplay : ITickStep, IDisposable
? new UdpClient(options.Value.Hostname, options.Value.Port) ? new UdpClient(options.Value.Hostname, options.Value.Port)
: null; : null;
_scoresBuffer = new(new(MapService.TilesPerRow, 0), 12, 20);
_scoresBuffer.Rows[0] = "== TANKS! ==";
_scoresBuffer.Rows[1] = "-- scores --";
_scoresBuffer.Rows[17] = "-- join --";
var localIp = GetLocalIp(options.Value.Hostname, options.Value.Port).Split('.'); var localIp = GetLocalIp(options.Value.Hostname, options.Value.Port).Split('.');
Debug.Assert(localIp.Length == 4); // were talking legacy ip Debug.Assert(localIp.Length == 4); // were talking legacy ip
_scoresBuffer.Rows[18] = string.Join('.', localIp[..2]); _scoresBuffer = new TextDisplayBuffer(new TilePosition(MapService.TilesPerRow, 0), 12, 20)
_scoresBuffer.Rows[19] = string.Join('.', localIp[2..]); {
Rows =
{
[0] = "== TANKS! ==",
[1] = "-- scores --",
[17] = "-- join --",
[18] = string.Join('.', localIp[..2]),
[19] = string.Join('.', localIp[2..])
}
};
} }
private static string GetLocalIp(string host, int port) private static string GetLocalIp(string host, int port)

View file

@ -1,5 +1,3 @@
using TanksServer.Models;
namespace TanksServer.ServicePointDisplay; namespace TanksServer.ServicePointDisplay;
internal sealed class TextDisplayBuffer : DisplayBufferView internal sealed class TextDisplayBuffer : DisplayBufferView