2024-04-15 20:34:23 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
namespace TanksServer.Graphics;
|
|
|
|
|
|
|
|
internal sealed class GamePixelGrid : IEnumerable<GamePixel>
|
|
|
|
{
|
2024-11-12 18:27:04 +01:00
|
|
|
public ulong Width { get; }
|
|
|
|
public ulong Height { get; }
|
2024-04-15 20:34:23 +02:00
|
|
|
|
|
|
|
private readonly GamePixel[,] _pixels;
|
|
|
|
|
2024-11-12 18:27:04 +01:00
|
|
|
public GamePixelGrid(ulong width, ulong height)
|
2024-04-15 20:34:23 +02:00
|
|
|
{
|
|
|
|
Width = width;
|
|
|
|
Height = height;
|
|
|
|
|
2024-04-16 00:07:44 +02:00
|
|
|
_pixels = new GamePixel[width, height];
|
2024-11-12 18:27:04 +01:00
|
|
|
for (ulong y = 0; y < height; y++)
|
|
|
|
for (ulong x = 0; x < width; x++)
|
|
|
|
this[x, y] = new GamePixel();
|
2024-04-15 20:34:23 +02:00
|
|
|
}
|
|
|
|
|
2024-11-12 18:27:04 +01:00
|
|
|
public GamePixel this[ulong x, ulong y]
|
2024-04-15 20:34:23 +02:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2024-11-12 18:27:04 +01:00
|
|
|
Debug.Assert(y * Width + x < (ulong)_pixels.Length);
|
2024-04-16 00:07:44 +02:00
|
|
|
return _pixels[x, y];
|
2024-04-15 20:34:23 +02:00
|
|
|
}
|
2024-04-16 00:07:44 +02:00
|
|
|
set => _pixels[x, y] = value;
|
2024-04-15 20:34:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
{
|
|
|
|
foreach (var pixel in _pixels)
|
|
|
|
pixel.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
|
|
|
|
public IEnumerator<GamePixel> GetEnumerator()
|
|
|
|
{
|
2024-11-12 18:27:04 +01:00
|
|
|
for (ulong y = 0; y < Height; y++)
|
|
|
|
for (ulong x = 0; x < Width; x++)
|
|
|
|
yield return this[x, y];
|
2024-04-15 20:34:23 +02:00
|
|
|
}
|
|
|
|
}
|