add singleton getter
parent
9eb4b947f0
commit
0ddc89ddea
|
@ -50,6 +50,11 @@ internal class ComponentDepot
|
|||
return ref Lookup<TComponent>().Get(entityID);
|
||||
}
|
||||
|
||||
public ref readonly TComponent Get<TComponent>() where TComponent : struct
|
||||
{
|
||||
return ref Lookup<TComponent>().Get();
|
||||
}
|
||||
|
||||
public void Set<TComponent>(int entityID, in TComponent component) where TComponent : struct
|
||||
{
|
||||
Lookup<TComponent>().Set(entityID, component);
|
||||
|
@ -74,6 +79,11 @@ internal class ComponentDepot
|
|||
}
|
||||
}
|
||||
|
||||
public ref readonly Entity GetEntity<TComponent>() where TComponent : struct
|
||||
{
|
||||
return ref Lookup<TComponent>().FirstEntity();
|
||||
}
|
||||
|
||||
public ReadOnlySpan<Entity> ReadEntities<TComponent>() where TComponent : struct
|
||||
{
|
||||
return Lookup<TComponent>().AllEntities();
|
||||
|
|
|
@ -29,6 +29,17 @@ internal class ComponentStorage<TComponent> : ComponentStorage where TComponent
|
|||
return ref components[entityIDToStorageIndex[entityID]];
|
||||
}
|
||||
|
||||
public ref readonly TComponent Get()
|
||||
{
|
||||
#if DEBUG
|
||||
if (nextID == 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Component storage is empty!");
|
||||
}
|
||||
#endif
|
||||
return ref components[0];
|
||||
}
|
||||
|
||||
public void Set(int entityID, in TComponent component)
|
||||
{
|
||||
if (!entityIDToStorageIndex.ContainsKey(entityID))
|
||||
|
@ -87,4 +98,9 @@ internal class ComponentStorage<TComponent> : ComponentStorage where TComponent
|
|||
{
|
||||
return new ReadOnlySpan<TComponent>(components, 0, nextID);
|
||||
}
|
||||
|
||||
public ref readonly Entity FirstEntity()
|
||||
{
|
||||
return ref storageIndexToEntities[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,8 +37,18 @@ public abstract class EntityComponentReader
|
|||
return ComponentDepot.Some<TComponent>();
|
||||
}
|
||||
|
||||
protected TComponent Get<TComponent>(in Entity entity) where TComponent : struct
|
||||
protected ref readonly TComponent Get<TComponent>(in Entity entity) where TComponent : struct
|
||||
{
|
||||
return ComponentDepot.Get<TComponent>(entity.ID);
|
||||
return ref ComponentDepot.Get<TComponent>(entity.ID);
|
||||
}
|
||||
|
||||
protected ref readonly TComponent Get<TComponent>() where TComponent : struct
|
||||
{
|
||||
return ref ComponentDepot.Get<TComponent>();
|
||||
}
|
||||
|
||||
protected ref readonly Entity GetEntity<TComponent>() where TComponent : struct
|
||||
{
|
||||
return ref ComponentDepot.GetEntity<TComponent>();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue