Updated Handle and Identifier that default is invalid

This commit is contained in:
2025-12-23 14:22:44 +09:00
parent aa3d9c749b
commit b8ce824292
21 changed files with 268 additions and 221 deletions

View File

@@ -129,7 +129,7 @@ internal static class ComponentRegistry
s_typeHandleToID[typeHandle] = newID;
s_nameToRuntimeID[stableName] = newID;
s_runtimeIDToType[newID.value] = typeof(T);
s_runtimeIDToType[newID.Value] = typeof(T);
return newID;
}
@@ -179,9 +179,9 @@ internal static class ComponentRegistry
var largestID = 0;
foreach (var id in componentTypeIDs)
{
if (id.value > largestID)
if (id.Value > largestID)
{
largestID = id.value;
largestID = id.Value;
}
}
@@ -192,7 +192,7 @@ internal static class ComponentRegistry
var bitSet = new SpanBitSet(bits);
foreach (var id in componentTypeIDs)
{
bitSet.SetBit(id.value);
bitSet.SetBit(id.Value);
}
return bitSet.GetHashCode();

View File

@@ -112,7 +112,7 @@ public readonly unsafe ref struct ChunkView
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Archetype.ComponentMemoryLayout GetLayout(Identifier<IComponent> id)
{
var layout = _layouts[id.value];
var layout = _layouts[id.Value];
if (layout.enableBitsOffset == -1)
{
throw new InvalidOperationException($"Component {id} is not exist in the archetype.");
@@ -502,7 +502,7 @@ public ref partial struct QueryBuilder
{
foreach (var id in list)
{
if (id.value > max) max = id.value;
if (id.Value > max) max = id.Value;
}
}

View File

@@ -58,7 +58,7 @@ public abstract class SystemBase : ISystem
protected void RequireQueryForUpdate(Identifier<EntityQuery> queryID)
{
_requiredQueries ??= new List<int>(4);
_requiredQueries.Add(queryID.value);
_requiredQueries.Add(queryID.Value);
}
void ISystem.Initialize(ref readonly SystemAPI systemAPI)

View File

@@ -1,4 +1,3 @@
namespace Ghost.Entities;
public unsafe partial struct EntityQuery
@@ -13,7 +12,7 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp0TypeID.Value,
};
var changedCompIDs = stackalloc int[1];
@@ -99,8 +98,8 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
};
var changedCompIDs = stackalloc int[2];
@@ -189,9 +188,9 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
};
var changedCompIDs = stackalloc int[3];
@@ -283,10 +282,10 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
};
var changedCompIDs = stackalloc int[4];
@@ -381,11 +380,11 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
};
var changedCompIDs = stackalloc int[5];
@@ -483,12 +482,12 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp5TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
comp5TypeID.Value,
};
var changedCompIDs = stackalloc int[6];
@@ -589,13 +588,13 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp5TypeID.value,
comp6TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
comp5TypeID.Value,
comp6TypeID.Value,
};
var changedCompIDs = stackalloc int[7];
@@ -699,14 +698,14 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp5TypeID.value,
comp6TypeID.value,
comp7TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
comp5TypeID.Value,
comp6TypeID.Value,
comp7TypeID.Value,
};
var changedCompIDs = stackalloc int[8];
@@ -797,7 +796,7 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp0TypeID.Value,
};
var changedCompIDs = stackalloc int[1];
@@ -884,8 +883,8 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
};
var changedCompIDs = stackalloc int[2];
@@ -975,9 +974,9 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
};
var changedCompIDs = stackalloc int[3];
@@ -1070,10 +1069,10 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
};
var changedCompIDs = stackalloc int[4];
@@ -1169,11 +1168,11 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
};
var changedCompIDs = stackalloc int[5];
@@ -1272,12 +1271,12 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp5TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
comp5TypeID.Value,
};
var changedCompIDs = stackalloc int[6];
@@ -1379,13 +1378,13 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp5TypeID.value,
comp6TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
comp5TypeID.Value,
comp6TypeID.Value,
};
var changedCompIDs = stackalloc int[7];
@@ -1490,14 +1489,14 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
comp0TypeID.value,
comp1TypeID.value,
comp2TypeID.value,
comp3TypeID.value,
comp4TypeID.value,
comp5TypeID.value,
comp6TypeID.value,
comp7TypeID.value,
comp0TypeID.Value,
comp1TypeID.Value,
comp2TypeID.Value,
comp3TypeID.Value,
comp4TypeID.Value,
comp5TypeID.Value,
comp6TypeID.Value,
comp7TypeID.Value,
};
var changedCompIDs = stackalloc int[8];

View File

@@ -32,7 +32,7 @@ public unsafe partial struct EntityQuery
var compTypeIDs = stackalloc int[]
{
<# for (var localIndex = 0; localIndex < i; localIndex++) { #>
comp<#= localIndex #>TypeID.value,
comp<#= localIndex #>TypeID.Value,
<# } #>
};

View File

@@ -21,7 +21,7 @@ public partial class World
{
if (s_freeWorldSlots.TryDequeue(out var index))
{
s_worlds[index.value] = new World(index, entityCapacity, jobScheduler);
s_worlds[index.Value] = new World(index, entityCapacity, jobScheduler);
}
else
{
@@ -29,7 +29,7 @@ public partial class World
s_worlds.Add(new World(index, entityCapacity, jobScheduler));
}
return s_worlds[index.value]!;
return s_worlds[index.Value]!;
}
}
@@ -37,12 +37,12 @@ public partial class World
{
lock (s_worlds)
{
if (id.value < 0 || id.value >= s_worlds.Count)
if (id.Value < 0 || id.Value >= s_worlds.Count)
{
return;
}
var world = s_worlds[id.value];
var world = s_worlds[id.Value];
world?.Dispose();
}
}
@@ -51,12 +51,12 @@ public partial class World
internal static World GetWorldUncheck(Identifier<World> id)
{
#if DEBUG || GHOST_EDITOR
if (id.value < 0 || id.value >= s_worlds.Count)
if (id.Value < 0 || id.Value >= s_worlds.Count)
{
throw new ArgumentOutOfRangeException(nameof(id), "World ID is out of range.");
}
var world = s_worlds[id.value];
var world = s_worlds[id.Value];
return world is null ? throw new InvalidOperationException("World not found.") : world;
#else
return s_worlds[id.value]!;
@@ -66,12 +66,12 @@ public partial class World
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Result<World, ErrorStatus> GetWorld(Identifier<World> id)
{
if (id.value < 0 || id.value >= s_worlds.Count)
if (id.Value < 0 || id.Value >= s_worlds.Count)
{
return ErrorStatus.InvalidArgument;
}
var world = s_worlds[id.value];
var world = s_worlds[id.Value];
return world is null ? ErrorStatus.NotFound : world;
}
}
@@ -175,7 +175,7 @@ public partial class World : IDisposable, IEquatable<World>
for (int i = 0; i < _entityQueries.Count; i++)
{
ref var query = ref _entityQueries[i];
query.AddArchetypeIfMatch(in _archetypes[arcID.value]);
query.AddArchetypeIfMatch(in _archetypes[arcID.Value]);
}
return arcID;
@@ -195,7 +195,7 @@ public partial class World : IDisposable, IEquatable<World>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal ref Archetype GetArchetypeReference(Identifier<Archetype> id)
{
return ref _archetypes[id.value];
return ref _archetypes[id.Value];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -205,7 +205,7 @@ public partial class World : IDisposable, IEquatable<World>
_entityQueries.Add(new EntityQuery(queryID, _id, mask));
_querieLookup.Add(maskHash, queryID);
ref var query = ref _entityQueries[queryID.value];
ref var query = ref _entityQueries[queryID.Value];
for (var i = 0; i < _archetypes.Count; i++)
{
query.AddArchetypeIfMatch(in _archetypes[i]);
@@ -251,7 +251,7 @@ public partial class World : IDisposable, IEquatable<World>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref EntityQuery GetEntityQueryReference(Identifier<EntityQuery> id)
{
return ref _entityQueries[id.value];
return ref _entityQueries[id.Value];
}
/// <summary>