add UncheckedGet for world component

This commit is contained in:
Mikhail 2023-07-02 16:17:13 +08:00
parent b04756c03d
commit aad94da19d
2 changed files with 4 additions and 1 deletions

View File

@ -116,6 +116,8 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Get<T>() where T : struct => ref WorldComponentPool<T>.GetForWorld(id); public ref T Get<T>() where T : struct => ref WorldComponentPool<T>.GetForWorld(id);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T UncheckedGet<T>() where T : struct => ref WorldComponentPool<T>.UncheckedGetForWorld(id);
#endregion #endregion
#region Where Query #region Where Query

View File

@ -57,6 +57,8 @@ namespace DCFApixels.DragonECS
public static ref T Get(int itemIndex) => ref _items[itemIndex]; public static ref T Get(int itemIndex) => ref _items[itemIndex];
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T GetForWorld(int worldID) => ref _items[GetItemIndex(worldID)]; public static ref T GetForWorld(int worldID) => ref _items[GetItemIndex(worldID)];
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T UncheckedGetForWorld(int worldID) => ref _items[_mapping[worldID]];
public static int GetItemIndex(int worldID) public static int GetItemIndex(int worldID)
{ {
if (_mapping.Length < Worlds.Length) if (_mapping.Length < Worlds.Length)
@ -79,7 +81,6 @@ namespace DCFApixels.DragonECS
} }
return itemIndex; return itemIndex;
} }
private static void Release(int worldID) private static void Release(int worldID)
{ {
ref short itemIndex = ref _mapping[worldID]; ref short itemIndex = ref _mapping[worldID];