-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ removed EcsID as struct. Use ulong extention
+ improved deferred op
- Loading branch information
1 parent
66926b3
commit deb2b7a
Showing
12 changed files
with
125 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,84 @@ | ||
namespace TinyEcs; | ||
|
||
/// <summary> | ||
/// The ecs entity rappresentation which is a wrapper around an ulong | ||
/// </summary> | ||
[StructLayout(LayoutKind.Explicit)] | ||
public readonly struct EcsID : IEquatable<ulong>, IComparable<ulong>, IEquatable<EcsID>, IComparable<EcsID> | ||
public static class EcsIdEx | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal EcsID(ulong value) => Value = value; | ||
|
||
|
||
/// <summary> | ||
/// ID + Generation | ||
/// </summary> | ||
[FieldOffset(0)] | ||
public readonly ulong Value; | ||
|
||
/// <summary> | ||
/// ID only | ||
/// </summary> | ||
[FieldOffset(0)] | ||
internal readonly int ID; | ||
|
||
/// <summary> | ||
/// Generation count.<br/> | ||
/// This number rappresent how many times the real ID has been recycled. | ||
/// </summary> | ||
[FieldOffset(4)] | ||
internal readonly int Generation; | ||
public static bool IsPair(this ref readonly EcsID id) | ||
=> IDOp.IsPair(id); | ||
|
||
public static EcsID First(this ref readonly EcsID id) | ||
=> id.IsPair() ? IDOp.GetPairFirst(id) : 0; | ||
|
||
public readonly bool IsValid => Value != 0; | ||
public readonly bool IsPair => IDOp.IsPair(Value); | ||
public readonly EcsID First => IsPair ? IDOp.GetPairFirst(Value) : 0; | ||
public readonly EcsID Second => IsPair ? IDOp.GetPairSecond(Value) : 0; | ||
public readonly (EcsID, EcsID) Pair => (First, Second); | ||
public static EcsID Second(this ref readonly EcsID id) | ||
=> id.IsPair() ? IDOp.GetPairSecond(id) : 0; | ||
|
||
public static (EcsID, EcsID) Pair(this ref readonly EcsID id) | ||
=> (id.First(), id.Second()); | ||
|
||
public readonly int CompareTo(ulong other) => Value.CompareTo(other); | ||
public readonly int CompareTo(EcsID other) => Value.CompareTo(other.Value); | ||
public readonly bool Equals(ulong other) => Value == other; | ||
public readonly bool Equals(EcsID other) => Value == other.Value; | ||
public static bool IsValid(this ref readonly EcsID id) | ||
=> id != 0; | ||
|
||
public static EcsID RealId(this ref readonly EcsID id) | ||
=> IDOp.RealID(id); | ||
|
||
public static implicit operator ulong(EcsID id) => id.Value; | ||
public static implicit operator EcsID(ulong value) => new (value); | ||
public static bool operator ==(EcsID id, EcsID other) => id.Value.Equals(other.Value); | ||
public static bool operator !=(EcsID id, EcsID other) => !id.Value.Equals(other.Value); | ||
|
||
|
||
public readonly override bool Equals(object? obj) => obj is EcsID ent && Equals(ent); | ||
public readonly override int GetHashCode() => Value.GetHashCode(); | ||
public readonly override string ToString() | ||
{ | ||
if (IsPair) | ||
return $"({First}, {Second}) | {Value}"; | ||
return $"[{ID} - @{Generation} | {Value}]"; | ||
} | ||
public static int Generation(this ref readonly EcsID id) | ||
=> (int) IDOp.GetGeneration(id); | ||
} | ||
|
||
/// <summary> | ||
/// The ecs entity rappresentation which is a wrapper around an ulong | ||
/// </summary> | ||
// [StructLayout(LayoutKind.Explicit)] | ||
// public readonly struct EcsID : IEquatable<ulong>, IComparable<ulong>, IEquatable<EcsID>, IComparable<EcsID> | ||
// { | ||
// [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
// internal EcsID(ulong value) => Value = value; | ||
// | ||
// | ||
// /// <summary> | ||
// /// ID + Generation | ||
// /// </summary> | ||
// [FieldOffset(0)] | ||
// public readonly ulong Value; | ||
// | ||
// /// <summary> | ||
// /// ID only | ||
// /// </summary> | ||
// [FieldOffset(0)] | ||
// internal readonly int ID; | ||
// | ||
// /// <summary> | ||
// /// Generation count.<br/> | ||
// /// This number rappresent how many times the real ID has been recycled. | ||
// /// </summary> | ||
// [FieldOffset(4)] | ||
// internal readonly int Generation; | ||
// | ||
// | ||
// public readonly bool IsValid => Value != 0; | ||
// public readonly bool IsPair => IDOp.IsPair(Value); | ||
// public readonly EcsID First => IsPair ? IDOp.GetPairFirst(Value) : 0; | ||
// public readonly EcsID Second => IsPair ? IDOp.GetPairSecond(Value) : 0; | ||
// public readonly (EcsID, EcsID) Pair => (First, Second); | ||
// | ||
// | ||
// public readonly int CompareTo(ulong other) => Value.CompareTo(other); | ||
// public readonly int CompareTo(EcsID other) => Value.CompareTo(other.Value); | ||
// public readonly bool Equals(ulong other) => Value == other; | ||
// public readonly bool Equals(EcsID other) => Value == other.Value; | ||
// | ||
// | ||
// // public static implicit operator ulong(EcsID id) => id.Value; | ||
// // public static implicit operator EcsID(ulong value) => new (value); | ||
// public static bool operator ==(EcsID id, EcsID other) => id.Value.Equals(other.Value); | ||
// public static bool operator !=(EcsID id, EcsID other) => !id.Value.Equals(other.Value); | ||
// | ||
// | ||
// public readonly override bool Equals(object? obj) => obj is EcsID ent && Equals(ent); | ||
// public readonly override int GetHashCode() => Value.GetHashCode(); | ||
// public readonly override string ToString() | ||
// { | ||
// if (IsPair) | ||
// return $"({First}, {Second}) | {Value}"; | ||
// return $"[{ID} - @{Generation} | {Value}]"; | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.