DragonECS/src/Entities/ent.cs

33 lines
1.2 KiB
C#
Raw Normal View History

2023-04-08 05:50:44 +08:00
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
2023-04-15 00:23:46 +08:00
using UnityEngine.Rendering;
2023-04-08 05:50:44 +08:00
namespace DCFApixels.DragonECS
{
2023-04-17 22:58:52 +08:00
#pragma warning disable CS0660, CS0661, IDE1006
/// <summary>Weak identifier/Single frame entity identifier</summary>
2023-04-08 05:50:44 +08:00
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 4)]
2023-04-09 02:52:39 +08:00
public readonly ref struct ent
2023-04-08 05:50:44 +08:00
{
internal readonly int id;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ent(int id) => this.id = id;
public static explicit operator ent(int id) => new ent(id);
public static explicit operator int(ent entityID) => entityID.id;
public static bool operator ==(ent a, ent b) => a.id == b.id;
public static bool operator !=(ent a, ent b) => a.id != b.id;
public static bool operator ==(ent a, Null? _) => a.id == 0;
public static bool operator ==(Null? _, ent b) => b.id == 0;
public static bool operator !=(ent a, Null? _) => a.id != 0;
public static bool operator !=(Null? _, ent b) => b.id != 0;
public struct Null { }
2023-04-17 22:58:52 +08:00
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public EcsEntity ToStrong(IEcsWorld world) => world.GetEntity(id);
2023-04-08 05:50:44 +08:00
}
}