From 69fe2ec015237e8d00e34cb1344685bd122574f6 Mon Sep 17 00:00:00 2001 From: Tijmen van den Heuvel Date: Fri, 1 Mar 2024 09:19:16 +0100 Subject: [PATCH] Revert iquatable and method overrides on structs These caused more friction than intended. Only the `Invalid` readonly field remains, and a constructor that includes the index parameter are additions. --- bindings/cs/bgfx.cs | 156 ++++++++++------------------------------ scripts/bindings-cs.lua | 14 ++-- 2 files changed, 40 insertions(+), 130 deletions(-) diff --git a/bindings/cs/bgfx.cs b/bindings/cs/bgfx.cs index abbf6dd26..91dc67688 100644 --- a/bindings/cs/bgfx.cs +++ b/bindings/cs/bgfx.cs @@ -2520,172 +2520,88 @@ public static partial class bgfx { } - public readonly struct DynamicIndexBufferHandle : IEquatable - - { - public readonly ushort idx; + public struct DynamicIndexBufferHandle { + public ushort idx; public static readonly DynamicIndexBufferHandle Invalid = new DynamicIndexBufferHandle(ushort.MaxValue); public DynamicIndexBufferHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is DynamicIndexBufferHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(DynamicIndexBufferHandle other) => this.idx == other.idx; - public static bool operator ==(DynamicIndexBufferHandle left, DynamicIndexBufferHandle right) => left.Equals(right); - public static bool operator !=(DynamicIndexBufferHandle left, DynamicIndexBufferHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct DynamicVertexBufferHandle : IEquatable - - { - public readonly ushort idx; + public struct DynamicVertexBufferHandle { + public ushort idx; public static readonly DynamicVertexBufferHandle Invalid = new DynamicVertexBufferHandle(ushort.MaxValue); public DynamicVertexBufferHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is DynamicVertexBufferHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(DynamicVertexBufferHandle other) => this.idx == other.idx; - public static bool operator ==(DynamicVertexBufferHandle left, DynamicVertexBufferHandle right) => left.Equals(right); - public static bool operator !=(DynamicVertexBufferHandle left, DynamicVertexBufferHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct FrameBufferHandle : IEquatable - - { - public readonly ushort idx; + public struct FrameBufferHandle { + public ushort idx; public static readonly FrameBufferHandle Invalid = new FrameBufferHandle(ushort.MaxValue); public FrameBufferHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is FrameBufferHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(FrameBufferHandle other) => this.idx == other.idx; - public static bool operator ==(FrameBufferHandle left, FrameBufferHandle right) => left.Equals(right); - public static bool operator !=(FrameBufferHandle left, FrameBufferHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct IndexBufferHandle : IEquatable - - { - public readonly ushort idx; + public struct IndexBufferHandle { + public ushort idx; public static readonly IndexBufferHandle Invalid = new IndexBufferHandle(ushort.MaxValue); public IndexBufferHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is IndexBufferHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(IndexBufferHandle other) => this.idx == other.idx; - public static bool operator ==(IndexBufferHandle left, IndexBufferHandle right) => left.Equals(right); - public static bool operator !=(IndexBufferHandle left, IndexBufferHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct IndirectBufferHandle : IEquatable - - { - public readonly ushort idx; + public struct IndirectBufferHandle { + public ushort idx; public static readonly IndirectBufferHandle Invalid = new IndirectBufferHandle(ushort.MaxValue); public IndirectBufferHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is IndirectBufferHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(IndirectBufferHandle other) => this.idx == other.idx; - public static bool operator ==(IndirectBufferHandle left, IndirectBufferHandle right) => left.Equals(right); - public static bool operator !=(IndirectBufferHandle left, IndirectBufferHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct OcclusionQueryHandle : IEquatable - - { - public readonly ushort idx; + public struct OcclusionQueryHandle { + public ushort idx; public static readonly OcclusionQueryHandle Invalid = new OcclusionQueryHandle(ushort.MaxValue); public OcclusionQueryHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is OcclusionQueryHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(OcclusionQueryHandle other) => this.idx == other.idx; - public static bool operator ==(OcclusionQueryHandle left, OcclusionQueryHandle right) => left.Equals(right); - public static bool operator !=(OcclusionQueryHandle left, OcclusionQueryHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct ProgramHandle : IEquatable - - { - public readonly ushort idx; + public struct ProgramHandle { + public ushort idx; public static readonly ProgramHandle Invalid = new ProgramHandle(ushort.MaxValue); public ProgramHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is ProgramHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(ProgramHandle other) => this.idx == other.idx; - public static bool operator ==(ProgramHandle left, ProgramHandle right) => left.Equals(right); - public static bool operator !=(ProgramHandle left, ProgramHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct ShaderHandle : IEquatable - - { - public readonly ushort idx; + public struct ShaderHandle { + public ushort idx; public static readonly ShaderHandle Invalid = new ShaderHandle(ushort.MaxValue); public ShaderHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is ShaderHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(ShaderHandle other) => this.idx == other.idx; - public static bool operator ==(ShaderHandle left, ShaderHandle right) => left.Equals(right); - public static bool operator !=(ShaderHandle left, ShaderHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct TextureHandle : IEquatable - - { - public readonly ushort idx; + public struct TextureHandle { + public ushort idx; public static readonly TextureHandle Invalid = new TextureHandle(ushort.MaxValue); public TextureHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is TextureHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(TextureHandle other) => this.idx == other.idx; - public static bool operator ==(TextureHandle left, TextureHandle right) => left.Equals(right); - public static bool operator !=(TextureHandle left, TextureHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct UniformHandle : IEquatable - - { - public readonly ushort idx; + public struct UniformHandle { + public ushort idx; public static readonly UniformHandle Invalid = new UniformHandle(ushort.MaxValue); public UniformHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is UniformHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(UniformHandle other) => this.idx == other.idx; - public static bool operator ==(UniformHandle left, UniformHandle right) => left.Equals(right); - public static bool operator !=(UniformHandle left, UniformHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct VertexBufferHandle : IEquatable - - { - public readonly ushort idx; + public struct VertexBufferHandle { + public ushort idx; public static readonly VertexBufferHandle Invalid = new VertexBufferHandle(ushort.MaxValue); public VertexBufferHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is VertexBufferHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(VertexBufferHandle other) => this.idx == other.idx; - public static bool operator ==(VertexBufferHandle left, VertexBufferHandle right) => left.Equals(right); - public static bool operator !=(VertexBufferHandle left, VertexBufferHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } - public readonly struct VertexLayoutHandle : IEquatable - - { - public readonly ushort idx; + public struct VertexLayoutHandle { + public ushort idx; public static readonly VertexLayoutHandle Invalid = new VertexLayoutHandle(ushort.MaxValue); public VertexLayoutHandle(ushort index) => idx = index; - public bool Valid => this != Invalid; - public override bool Equals(object? obj) => obj is VertexLayoutHandle handle && handle == this; - public override int GetHashCode() => idx.GetHashCode(); - public bool Equals(VertexLayoutHandle other) => this.idx == other.idx; - public static bool operator ==(VertexLayoutHandle left, VertexLayoutHandle right) => left.Equals(right); - public static bool operator !=(VertexLayoutHandle left, VertexLayoutHandle right) => !(left == right); + public bool Valid => this.idx != Invalid.idx; } diff --git a/scripts/bindings-cs.lua b/scripts/bindings-cs.lua index 4e732866b..a538c22a1 100644 --- a/scripts/bindings-cs.lua +++ b/scripts/bindings-cs.lua @@ -299,18 +299,12 @@ function converter.types(typ) if typ.handle then lastCombinedFlagBlock() - yield("public readonly struct " .. typ.name .. " : IEquatable<"..typ.name..">\n") - yield("{") - yield(" public readonly ushort idx;") + yield("public struct " .. typ.name .. " {") + yield(" public ushort idx;") yield(" public static readonly " .. typ.name .. " Invalid = new " .. typ.name .. "(ushort.MaxValue);") yield(" public " .. typ.name .. "(ushort index) => idx = index;") - yield(" public bool Valid => this != Invalid;") - yield(" public override bool Equals(object? obj) => obj is " .. typ.name .. " handle && handle == this;") - yield(" public override int GetHashCode() => idx.GetHashCode();") - yield(" public bool Equals(" .. typ.name .. " other) => this.idx == other.idx;") - yield(" public static bool operator ==(" .. typ.name .. " left, " .. typ.name .. " right) => left.Equals(right);") - yield(" public static bool operator !=(" .. typ.name .. " left, " .. typ.name .. " right) => !(left == right);") - yield("}") + yield(" public bool Valid => this.idx != Invalid.idx;") + yield("}") elseif hasSuffix(typ.name, "::Enum") then lastCombinedFlagBlock()