add EcsWorld.GetPoolInstanceMarker

This commit is contained in:
DCFApixels 2024-12-03 17:44:16 +08:00
parent 0182614819
commit dd5a81334c
3 changed files with 25 additions and 0 deletions

View File

@ -83,6 +83,11 @@ namespace DCFApixels.DragonECS
{
return GetUnchecked<PoolCache<TPool>>(worldID).Instance;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public GetPoolInstanceMarker GetPoolInstance()
{
return new GetPoolInstanceMarker(this);
}
#endregion
#region ComponentInfo
@ -418,6 +423,24 @@ namespace DCFApixels.DragonECS
public bool locked;
#endif
}
public readonly ref struct GetPoolInstanceMarker
{
public readonly EcsWorld World;
public GetPoolInstanceMarker(EcsWorld world)
{
World = world;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TPool GetInstance<TPool>() where TPool : IEcsPoolImplementation, new()
{
return World.GetPoolInstance<TPool>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public TPool GetInstanceUnchecked<TPool>() where TPool : IEcsPoolImplementation, new()
{
return World.GetPoolInstanceUnchecked<TPool>();
}
}
#endregion
}
}

View File

@ -340,6 +340,7 @@ namespace DCFApixels.DragonECS
public static implicit operator EcsPool<T>(IncludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
public static implicit operator EcsPool<T>(ExcludeMarker a) { return a.GetInstance<EcsPool<T>>(); }
public static implicit operator EcsPool<T>(OptionalMarker a) { return a.GetInstance<EcsPool<T>>(); }
public static implicit operator EcsPool<T>(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance<EcsPool<T>>(); }
#endregion
}
public static class EcsPoolExt

View File

@ -291,6 +291,7 @@ namespace DCFApixels.DragonECS
public static implicit operator EcsTagPool<T>(IncludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
public static implicit operator EcsTagPool<T>(ExcludeMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
public static implicit operator EcsTagPool<T>(OptionalMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
public static implicit operator EcsTagPool<T>(EcsWorld.GetPoolInstanceMarker a) { return a.GetInstance<EcsTagPool<T>>(); }
#endregion
}
public static class EcsTagPoolExt