do not send frames when nothing changes

This commit is contained in:
Vinzenz Schroeter 2024-04-12 19:54:16 +02:00
commit de3d298475

View file

@ -3,16 +3,16 @@ using System.Text;
namespace DisplayCommands;
public sealed class Cp437Grid(ushort width, ushort height)
public sealed class Cp437Grid(ushort width, ushort height) : IEquatable<Cp437Grid>
{
private readonly ByteGrid _byteGrid = new(width, height);
public ushort Height { get; } = height;
public ushort Width { get; } = width;
internal Memory<byte> Data => _byteGrid.Data;
private readonly Encoding _encoding = Encoding.GetEncoding(437);
public char this[ushort x, ushort y]
@ -47,7 +47,6 @@ public sealed class Cp437Grid(ushort width, ushort height)
var consumed = _encoding.GetBytes(valuesStr, convertedStr);
Debug.Assert(consumed == 1);
return convertedStr[0];
}
private char ByteToChar(byte b)
@ -57,4 +56,16 @@ public sealed class Cp437Grid(ushort width, ushort height)
_encoding.GetChars(valueBytes, resultStr);
return resultStr[0];
}
public bool Equals(Cp437Grid? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Height == other.Height && Width == other.Width && _byteGrid.Equals(other._byteGrid);
}
public override bool Equals(object? obj) => ReferenceEquals(this, obj) || (obj is Cp437Grid other && Equals(other));
public override int GetHashCode() => HashCode.Combine(_byteGrid, Height, Width);
public static bool operator ==(Cp437Grid? left, Cp437Grid? right) => Equals(left, right);
public static bool operator !=(Cp437Grid? left, Cp437Grid? right) => !Equals(left, right);
}