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 | insert_final_newline = true | ||||||
| max_line_length = 120 | max_line_length = 120 | ||||||
| tab_width = 4 | 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; |         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) |     private int GetIndex(ushort x, ushort y) | ||||||
|     { |     { | ||||||
|         Debug.Assert(x < Width); |         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 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 bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is ByteGrid other && Equals(other)); | ||||||
|  | 
 | ||||||
|     public override int GetHashCode() => HashCode.Combine(Height, Width, Data); |     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); | ||||||
|  | 
 | ||||||
|     public static bool operator !=(ByteGrid? left, ByteGrid? right) => !Equals(left, right); |     public static bool operator !=(ByteGrid? left, ByteGrid? right) => !Equals(left, right); | ||||||
| } | } | ||||||
|  | @ -16,12 +16,12 @@ | ||||||
|     </PropertyGroup> |     </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|     <ItemGroup> |     <ItemGroup> | ||||||
|         <PackageReference Include="Microsoft.Extensions.DependencyInjection" 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" Version="8.0.2"/> | ||||||
|         <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" /> |         <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0"/> | ||||||
|         <PackageReference Include="System.Text.Encoding.CodePages" 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.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> |     </ItemGroup> | ||||||
| 
 | 
 | ||||||
| </Project> | </Project> | ||||||
|  |  | ||||||
|  | @ -13,5 +13,5 @@ internal enum DisplayCommand : ushort | ||||||
|     BitmapLinearWin = 0x0013, |     BitmapLinearWin = 0x0013, | ||||||
|     BitmapLinearAnd = 0x0014, |     BitmapLinearAnd = 0x0014, | ||||||
|     BitmapLinearOr = 0x0015, |     BitmapLinearOr = 0x0015, | ||||||
|     BitmapLinearXor = 0x0016, |     BitmapLinearXor = 0x0016 | ||||||
| } | } | ||||||
|  | @ -9,8 +9,8 @@ namespace DisplayCommands.Internals; | ||||||
| 
 | 
 | ||||||
| internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options) : IDisplayConnection, IDisposable | 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 ArrayPool<byte> _arrayPool = ArrayPool<byte>.Shared; | ||||||
|  |     private readonly UdpClient _udpClient = new(options.Value.Hostname, options.Value.Port); | ||||||
| 
 | 
 | ||||||
|     public ValueTask SendClearAsync() |     public ValueTask SendClearAsync() | ||||||
|     { |     { | ||||||
|  | @ -119,8 +119,5 @@ internal sealed class DisplayConnection(IOptions<DisplayConfiguration> options) | ||||||
|         _arrayPool.Return(buffer); |         _arrayPool.Return(buffer); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void Dispose() |     public void Dispose() => _udpClient.Dispose(); | ||||||
|     { |  | ||||||
|         _udpClient.Dispose(); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  | @ -6,5 +6,5 @@ internal enum DisplaySubCommand : ushort | ||||||
|     BitmapCompressZ = 0x677a, |     BitmapCompressZ = 0x677a, | ||||||
|     BitmapCompressBz = 0x627a, |     BitmapCompressBz = 0x627a, | ||||||
|     BitmapCompressLz = 0x6c7a, |     BitmapCompressLz = 0x6c7a, | ||||||
|     BitmapCompressZs = 0x7a73, |     BitmapCompressZs = 0x7a73 | ||||||
| } | } | ||||||
|  | @ -2,14 +2,11 @@ namespace TanksServer.GameLogic; | ||||||
| 
 | 
 | ||||||
| internal sealed class BulletManager | internal sealed class BulletManager | ||||||
| { | { | ||||||
|     private readonly HashSet<Bullet> _bullets = new(); |     private readonly HashSet<Bullet> _bullets = []; | ||||||
| 
 | 
 | ||||||
|     public void Spawn(Bullet bullet) => _bullets.Add(bullet); |     public void Spawn(Bullet bullet) => _bullets.Add(bullet); | ||||||
| 
 | 
 | ||||||
|     public IEnumerable<Bullet> GetAll() => _bullets; |     public IEnumerable<Bullet> GetAll() => _bullets; | ||||||
| 
 | 
 | ||||||
|     public void RemoveWhere(Predicate<Bullet> predicate) |     public void RemoveWhere(Predicate<Bullet> predicate) => _bullets.RemoveWhere(predicate); | ||||||
|     { |  | ||||||
|         _bullets.RemoveWhere(predicate); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,8 +8,6 @@ internal sealed class CollideBulletsWithMap(BulletManager bullets, MapService ma | ||||||
|         return Task.CompletedTask; |         return Task.CompletedTask; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private bool BulletHitsWall(Bullet bullet) |     private bool BulletHitsWall(Bullet bullet) => | ||||||
|     { |         map.IsCurrentlyWall(bullet.Position.ToPixelPosition().ToTilePosition()); | ||||||
|         return map.IsCurrentlyWall(bullet.Position.ToPixelPosition().ToTilePosition()); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -10,17 +10,29 @@ internal sealed class GameTickWorker( | ||||||
| ) : IHostedService, IDisposable | ) : IHostedService, IDisposable | ||||||
| { | { | ||||||
|     private const int TicksPerSecond = 25; |     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 CancellationTokenSource _cancellation = new(); | ||||||
|     private readonly List<ITickStep> _steps = steps.ToList(); |     private readonly List<ITickStep> _steps = steps.ToList(); | ||||||
|     private Task? _run; |     private Task? _run; | ||||||
| 
 | 
 | ||||||
|  |     public void Dispose() | ||||||
|  |     { | ||||||
|  |         _cancellation.Dispose(); | ||||||
|  |         _run?.Dispose(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     public Task StartAsync(CancellationToken cancellationToken) |     public Task StartAsync(CancellationToken cancellationToken) | ||||||
|     { |     { | ||||||
|         _run = RunAsync(); |         _run = RunAsync(); | ||||||
|         return Task.CompletedTask; |         return Task.CompletedTask; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public async Task StopAsync(CancellationToken cancellationToken) | ||||||
|  |     { | ||||||
|  |         await _cancellation.CancelAsync(); | ||||||
|  |         if (_run != null) await _run; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     private async Task RunAsync() |     private async Task RunAsync() | ||||||
|     { |     { | ||||||
|         try |         try | ||||||
|  | @ -45,16 +57,4 @@ internal sealed class GameTickWorker( | ||||||
|             lifetime.StopApplication(); |             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]; |     private char this[int tileX, int tileY] => _map[tileX + tileY * TilesPerRow]; | ||||||
| 
 | 
 | ||||||
|     public bool IsCurrentlyWall(TilePosition position) |     public bool IsCurrentlyWall(TilePosition position) => this[position.X, position.Y] == '#'; | ||||||
|     { |  | ||||||
|         return this[position.X, position.Y] == '#'; |  | ||||||
|     } |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -11,10 +11,7 @@ internal sealed class SpawnQueue( | ||||||
|     private readonly TimeSpan _spawnDelay = TimeSpan.FromMilliseconds(options.Value.SpawnDelayMs); |     private readonly TimeSpan _spawnDelay = TimeSpan.FromMilliseconds(options.Value.SpawnDelayMs); | ||||||
|     private readonly TimeSpan _idleTimeout = TimeSpan.FromMilliseconds(options.Value.IdleTimeoutMs); |     private readonly TimeSpan _idleTimeout = TimeSpan.FromMilliseconds(options.Value.IdleTimeoutMs); | ||||||
| 
 | 
 | ||||||
|     public void EnqueueForImmediateSpawn(Player player) |     public void EnqueueForImmediateSpawn(Player player) => _queue.Enqueue(player); | ||||||
|     { |  | ||||||
|         _queue.Enqueue(player); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     public void EnqueueForDelayedSpawn(Player player) |     public void EnqueueForDelayedSpawn(Player player) | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -3,4 +3,4 @@ using System.Text.Json.Serialization; | ||||||
| namespace TanksServer.Interactivity; | namespace TanksServer.Interactivity; | ||||||
| 
 | 
 | ||||||
| [JsonSerializable(typeof(Player))] | [JsonSerializable(typeof(Player))] | ||||||
| internal sealed partial class AppSerializerContext: JsonSerializerContext; | internal sealed partial class AppSerializerContext : JsonSerializerContext; | ||||||
|  |  | ||||||
|  | @ -8,19 +8,19 @@ namespace TanksServer.Interactivity; | ||||||
| 
 | 
 | ||||||
| internal sealed class SendToServicePointDisplay : ITickStep | 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 ScoresWidth = 12; | ||||||
|     private const int ScoresHeight = 20; |     private const int ScoresHeight = 20; | ||||||
|     private const int ScoresPlayerRows = ScoresHeight - 5; |     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( |     public SendToServicePointDisplay( | ||||||
|         LastFinishedFrameProvider lastFinishedFrameProvider, |         LastFinishedFrameProvider lastFinishedFrameProvider, | ||||||
|         PlayerServer players, |         PlayerServer players, | ||||||
|  |  | ||||||
|  | @ -8,8 +8,7 @@ internal sealed class Player(string name) | ||||||
| 
 | 
 | ||||||
|     public Guid Id { get; } = Guid.NewGuid(); |     public Guid Id { get; } = Guid.NewGuid(); | ||||||
| 
 | 
 | ||||||
|     [JsonIgnore] |     [JsonIgnore] public PlayerControls Controls { get; } = new(); | ||||||
|     public PlayerControls Controls { get; } = new(); |  | ||||||
| 
 | 
 | ||||||
|     public int Kills { get; set; } |     public int Kills { get; set; } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter