formatting
This commit is contained in:
		
							parent
							
								
									d4d0abd013
								
							
						
					
					
						commit
						1f0e6ba8fa
					
				
					 19 changed files with 88 additions and 79 deletions
				
			
		|  | @ -8,3 +8,24 @@ indent_style = space | |||
| insert_final_newline = true | ||||
| max_line_length = 120 | ||||
| tab_width = 4 | ||||
| trim_trailing_whitespace = true | ||||
| 
 | ||||
| csharp_style_expression_bodied_methods = when_on_single_line:warning | ||||
| csharp_style_expression_bodied_lambdas = when_on_single_line:warning | ||||
| csharp_style_expression_bodied_properties = when_on_single_line:warning | ||||
| 
 | ||||
| dotnet_style_collection_initializer = true:warning | ||||
| 
 | ||||
| dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none | ||||
| dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:none | ||||
| dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none | ||||
| 
 | ||||
| dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion | ||||
| dotnet_style_predefined_type_for_member_access = true:suggestion | ||||
| 
 | ||||
| dotnet_style_qualification_for_event = false:suggestion | ||||
| dotnet_style_qualification_for_field = false:suggestion | ||||
| dotnet_style_qualification_for_method = false:suggestion | ||||
| dotnet_style_qualification_for_property = false:suggestion | ||||
| 
 | ||||
| dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning | ||||
|  |  | |||
|  | @ -16,6 +16,13 @@ public sealed class ByteGrid(ushort width, ushort height) : IEquatable<ByteGrid> | |||
|         set => Data.Span[GetIndex(x, y)] = value; | ||||
|     } | ||||
| 
 | ||||
|     public bool Equals(ByteGrid? other) | ||||
|     { | ||||
|         if (ReferenceEquals(null, other)) return false; | ||||
|         if (ReferenceEquals(this, other)) return true; | ||||
|         return Height == other.Height && Width == other.Width && Data.Span.SequenceEqual(other.Data.Span); | ||||
|     } | ||||
| 
 | ||||
|     private int GetIndex(ushort x, ushort y) | ||||
|     { | ||||
|         Debug.Assert(x < Width); | ||||
|  | @ -25,15 +32,11 @@ public sealed class ByteGrid(ushort width, ushort height) : IEquatable<ByteGrid> | |||
| 
 | ||||
|     public void Clear() => Data.Span.Clear(); | ||||
| 
 | ||||
|     public bool Equals(ByteGrid? other) | ||||
|     { | ||||
|         if (ReferenceEquals(null, other)) return false; | ||||
|         if (ReferenceEquals(this, other)) return true; | ||||
|         return Height == other.Height && Width == other.Width && Data.Span.SequenceEqual(other.Data.Span); | ||||
|     } | ||||
| 
 | ||||
|     public override bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is ByteGrid other && Equals(other)); | ||||
| 
 | ||||
|     public override int GetHashCode() => HashCode.Combine(Height, Width, Data); | ||||
| 
 | ||||
|     public static bool operator ==(ByteGrid? left, ByteGrid? right) => Equals(left, right); | ||||
| 
 | ||||
|     public static bool operator !=(ByteGrid? left, ByteGrid? right) => !Equals(left, right); | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -14,14 +14,14 @@ | |||
|         <TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||||
|         <NoWarn>CA1805,CA1848</NoWarn> | ||||
|     </PropertyGroup> | ||||
|      | ||||
| 
 | ||||
|     <ItemGroup> | ||||
|         <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | ||||
|         <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" /> | ||||
|         <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" /> | ||||
|         <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0"/> | ||||
|         <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2"/> | ||||
|         <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0"/> | ||||
|         <PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0"/> | ||||
|         <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1"/> | ||||
|         <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" /> | ||||
|         <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1"/> | ||||
|     </ItemGroup> | ||||
|      | ||||
| 
 | ||||
| </Project> | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ public interface IDisplayConnection | |||
|     ValueTask SendCp437DataAsync(ushort x, ushort y, Cp437Grid grid); | ||||
| 
 | ||||
|     ValueTask SendBrightnessAsync(byte brightness); | ||||
|      | ||||
| 
 | ||||
|     ValueTask SendCharBrightnessAsync(ushort x, ushort y, ByteGrid luma); | ||||
| 
 | ||||
|     ValueTask SendHardResetAsync(); | ||||
|  | @ -17,8 +17,8 @@ public interface IDisplayConnection | |||
|     public ValueTask SendBitmapLinearWindowAsync(ushort x, ushort y, PixelGrid pixels); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Returns the IPv4 address that is associated with the interface with which the display is reachable. | ||||
|     ///     Returns the IPv4 address that is associated with the interface with which the display is reachable. | ||||
|     /// </summary> | ||||
|     /// <returns>IPv4 as text</returns> | ||||
|     public string GetLocalIPv4(); | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -13,5 +13,5 @@ internal enum DisplayCommand : ushort | |||
|     BitmapLinearWin = 0x0013, | ||||
|     BitmapLinearAnd = 0x0014, | ||||
|     BitmapLinearOr = 0x0015, | ||||
|     BitmapLinearXor = 0x0016, | ||||
| } | ||||
|     BitmapLinearXor = 0x0016 | ||||
| } | ||||
|  |  | |||
|  | @ -9,8 +9,8 @@ namespace DisplayCommands.Internals; | |||
| 
 | ||||
| internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options) : IDisplayConnection, IDisposable | ||||
| { | ||||
|     private readonly UdpClient _udpClient = new(options.Value.Hostname, options.Value.Port); | ||||
|     private readonly ArrayPool<byte> _arrayPool = ArrayPool<byte>.Shared; | ||||
|     private readonly UdpClient _udpClient = new(options.Value.Hostname, options.Value.Port); | ||||
| 
 | ||||
|     public ValueTask SendClearAsync() | ||||
|     { | ||||
|  | @ -119,8 +119,5 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options) | |||
|         _arrayPool.Return(buffer); | ||||
|     } | ||||
| 
 | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _udpClient.Dispose(); | ||||
|     } | ||||
| } | ||||
|     public void Dispose() => _udpClient.Dispose(); | ||||
| } | ||||
|  |  | |||
|  | @ -6,5 +6,5 @@ internal enum DisplaySubCommand : ushort | |||
|     BitmapCompressZ = 0x677a, | ||||
|     BitmapCompressBz = 0x627a, | ||||
|     BitmapCompressLz = 0x6c7a, | ||||
|     BitmapCompressZs = 0x7a73, | ||||
| } | ||||
|     BitmapCompressZs = 0x7a73 | ||||
| } | ||||
|  |  | |||
|  | @ -56,4 +56,4 @@ public sealed class PixelGrid(ushort width, ushort height) : IEquatable<PixelGri | |||
|         var bitInByteMask = (byte)(1 << bitInByteIndex); | ||||
|         return (byteIndex, bitInByteMask); | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -2,14 +2,11 @@ namespace TanksServer.GameLogic; | |||
| 
 | ||||
| internal sealed class BulletManager | ||||
| { | ||||
|     private readonly HashSet<Bullet> _bullets = new(); | ||||
|     private readonly HashSet<Bullet> _bullets = []; | ||||
| 
 | ||||
|     public void Spawn(Bullet bullet) => _bullets.Add(bullet); | ||||
| 
 | ||||
|     public IEnumerable<Bullet> GetAll() => _bullets; | ||||
| 
 | ||||
|     public void RemoveWhere(Predicate<Bullet> predicate) | ||||
|     { | ||||
|         _bullets.RemoveWhere(predicate); | ||||
|     } | ||||
|     public void RemoveWhere(Predicate<Bullet> predicate) => _bullets.RemoveWhere(predicate); | ||||
| } | ||||
|  |  | |||
|  | @ -8,8 +8,6 @@ internal sealed class CollideBulletsWithMap(BulletManager bullets, MapService ma | |||
|         return Task.CompletedTask; | ||||
|     } | ||||
| 
 | ||||
|     private bool BulletHitsWall(Bullet bullet) | ||||
|     { | ||||
|         return map.IsCurrentlyWall(bullet.Position.ToPixelPosition().ToTilePosition()); | ||||
|     } | ||||
|     private bool BulletHitsWall(Bullet bullet) => | ||||
|         map.IsCurrentlyWall(bullet.Position.ToPixelPosition().ToTilePosition()); | ||||
| } | ||||
|  |  | |||
|  | @ -10,17 +10,29 @@ internal sealed class GameTickWorker( | |||
| ) : IHostedService, IDisposable | ||||
| { | ||||
|     private const int TicksPerSecond = 25; | ||||
|     private static readonly TimeSpan TickPacing = TimeSpan.FromMilliseconds((int)(1000 / TicksPerSecond)); | ||||
|     private static readonly TimeSpan TickPacing = TimeSpan.FromMilliseconds(1000 / TicksPerSecond); | ||||
|     private readonly CancellationTokenSource _cancellation = new(); | ||||
|     private readonly List<ITickStep> _steps = steps.ToList(); | ||||
|     private Task? _run; | ||||
| 
 | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _cancellation.Dispose(); | ||||
|         _run?.Dispose(); | ||||
|     } | ||||
| 
 | ||||
|     public Task StartAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         _run = RunAsync(); | ||||
|         return Task.CompletedTask; | ||||
|     } | ||||
| 
 | ||||
|     public async Task StopAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         await _cancellation.CancelAsync(); | ||||
|         if (_run != null) await _run; | ||||
|     } | ||||
| 
 | ||||
|     private async Task RunAsync() | ||||
|     { | ||||
|         try | ||||
|  | @ -45,16 +57,4 @@ internal sealed class GameTickWorker( | |||
|             lifetime.StopApplication(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public async Task StopAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         await _cancellation.CancelAsync(); | ||||
|         if (_run != null) await _run; | ||||
|     } | ||||
| 
 | ||||
|     public void Dispose() | ||||
|     { | ||||
|         _cancellation.Dispose(); | ||||
|         _run?.Dispose(); | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -35,8 +35,5 @@ internal sealed class MapService | |||
| 
 | ||||
|     private char this[int tileX, int tileY] => _map[tileX + tileY * TilesPerRow]; | ||||
| 
 | ||||
|     public bool IsCurrentlyWall(TilePosition position) | ||||
|     { | ||||
|         return this[position.X, position.Y] == '#'; | ||||
|     } | ||||
|     public bool IsCurrentlyWall(TilePosition position) => this[position.X, position.Y] == '#'; | ||||
| } | ||||
|  |  | |||
|  | @ -18,4 +18,4 @@ internal sealed class MoveBullets(BulletManager bullets, IOptions<TanksConfigura | |||
|             bullet.Position.Y - Math.Cos(angle) * config.Value.BulletSpeed | ||||
|         ); | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -11,10 +11,7 @@ internal sealed class SpawnQueue( | |||
|     private readonly TimeSpan _spawnDelay = TimeSpan.FromMilliseconds(options.Value.SpawnDelayMs); | ||||
|     private readonly TimeSpan _idleTimeout = TimeSpan.FromMilliseconds(options.Value.IdleTimeoutMs); | ||||
| 
 | ||||
|     public void EnqueueForImmediateSpawn(Player player) | ||||
|     { | ||||
|         _queue.Enqueue(player); | ||||
|     } | ||||
|     public void EnqueueForImmediateSpawn(Player player) => _queue.Enqueue(player); | ||||
| 
 | ||||
|     public void EnqueueForDelayedSpawn(Player player) | ||||
|     { | ||||
|  | @ -33,7 +30,7 @@ internal sealed class SpawnQueue( | |||
|             _queue.Enqueue(player); | ||||
|             return false; | ||||
|         } | ||||
|          | ||||
| 
 | ||||
|         var now = DateTime.Now; | ||||
|         if (_spawnTimes.GetOrAdd(player, DateTime.MinValue) > now) | ||||
|         { | ||||
|  | @ -44,4 +41,4 @@ internal sealed class SpawnQueue( | |||
| 
 | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ namespace TanksServer.Graphics; | |||
| internal sealed class LastFinishedFrameProvider | ||||
| { | ||||
|     private PixelGrid? _lastFrame; | ||||
|      | ||||
| 
 | ||||
|     public PixelGrid LastFrame | ||||
|     { | ||||
|         get => _lastFrame ?? throw new InvalidOperationException("first frame not yet drawn"); | ||||
|  |  | |||
|  | @ -3,4 +3,4 @@ using System.Text.Json.Serialization; | |||
| namespace TanksServer.Interactivity; | ||||
| 
 | ||||
| [JsonSerializable(typeof(Player))] | ||||
| internal sealed partial class AppSerializerContext: JsonSerializerContext; | ||||
| internal sealed partial class AppSerializerContext : JsonSerializerContext; | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ internal sealed class PlayerServer(ILogger<PlayerServer> logger, SpawnQueue spaw | |||
|     } | ||||
| 
 | ||||
|     public IEnumerable<Player> GetAll() => _players.Values; | ||||
|      | ||||
| 
 | ||||
|     private Player AddAndSpawn(string name) | ||||
|     { | ||||
|         var player = new Player(name); | ||||
|  |  | |||
|  | @ -8,19 +8,19 @@ namespace TanksServer.Interactivity; | |||
| 
 | ||||
| internal sealed class SendToServicePointDisplay : ITickStep | ||||
| { | ||||
|     private readonly LastFinishedFrameProvider _lastFinishedFrameProvider; | ||||
|     private readonly Cp437Grid _scoresBuffer; | ||||
|     private readonly PlayerServer _players; | ||||
|     private readonly ILogger<SendToServicePointDisplay> _logger; | ||||
|     private readonly IDisplayConnection _displayConnection; | ||||
|     private PixelGrid? _lastSentFrame; | ||||
| 
 | ||||
|     private DateTime _nextFailLog = DateTime.Now; | ||||
| 
 | ||||
|     private const int ScoresWidth = 12; | ||||
|     private const int ScoresHeight = 20; | ||||
|     private const int ScoresPlayerRows = ScoresHeight - 5; | ||||
| 
 | ||||
|     private readonly IDisplayConnection _displayConnection; | ||||
|     private readonly LastFinishedFrameProvider _lastFinishedFrameProvider; | ||||
|     private readonly ILogger<SendToServicePointDisplay> _logger; | ||||
|     private readonly PlayerServer _players; | ||||
|     private readonly Cp437Grid _scoresBuffer; | ||||
| 
 | ||||
|     private PixelGrid? _lastSentFrame; | ||||
|     private DateTime _nextFailLog = DateTime.Now; | ||||
| 
 | ||||
|     public SendToServicePointDisplay( | ||||
|         LastFinishedFrameProvider lastFinishedFrameProvider, | ||||
|         PlayerServer players, | ||||
|  | @ -90,4 +90,4 @@ internal sealed class SendToServicePointDisplay : ITickStep | |||
|         for (; row < 17; row++) | ||||
|             _scoresBuffer[row] = string.Empty; | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -8,12 +8,11 @@ internal sealed class Player(string name) | |||
| 
 | ||||
|     public Guid Id { get; } = Guid.NewGuid(); | ||||
| 
 | ||||
|     [JsonIgnore] | ||||
|     public PlayerControls Controls { get; } = new(); | ||||
|     [JsonIgnore] public PlayerControls Controls { get; } = new(); | ||||
| 
 | ||||
|     public int Kills { get; set; } | ||||
|      | ||||
| 
 | ||||
|     public int Deaths { get; set; } | ||||
| 
 | ||||
|     public DateTime LastInput { get; set; } = DateTime.Now; | ||||
| } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter