rename write methods to get

This commit is contained in:
Mikhail 2023-05-30 16:01:16 +08:00
parent b73101d18c
commit 8dc8236f7e
3 changed files with 18 additions and 18 deletions

View File

@ -74,18 +74,18 @@ namespace DCFApixels.DragonECS
Array.Resize(ref _items, _items.Length << 1);
}
this.IncrementEntityComponentCount(entityID);
_listeners.InvokeOnAddAndWrite(entityID);
_listeners.InvokeOnAddAndGet(entityID);
return ref _items[itemIndex];
// }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T Write(int entityID)
public ref T Get(int entityID)
{
// using (_writeMark.Auto())
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
if (!Has(entityID)) ThrowNotHaveComponent<T>(entityID);
#endif
_listeners.InvokeOnWrite(entityID);
_listeners.InvokeOnGet(entityID);
return ref _items[_mapping[entityID]];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -97,7 +97,7 @@ namespace DCFApixels.DragonECS
#endif
return ref _items[_mapping[entityID]];
}
public ref T TryAddOrWrite(int entityID)
public ref T TryAddOrGet(int entityID)
{
ref int itemIndex = ref _mapping[entityID];
if (itemIndex <= 0)
@ -116,7 +116,7 @@ namespace DCFApixels.DragonECS
this.IncrementEntityComponentCount(entityID);
_listeners.InvokeOnAdd(entityID);
}
_listeners.InvokeOnWrite(entityID);
_listeners.InvokeOnGet(entityID);
return ref _items[itemIndex];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -148,14 +148,14 @@ namespace DCFApixels.DragonECS
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
if (!Has(fromEntityID)) ThrowNotHaveComponent<T>(fromEntityID);
#endif
_componentCopyHandler.Copy(ref Write(fromEntityID), ref TryAddOrWrite(toEntityID));
_componentCopyHandler.Copy(ref Get(fromEntityID), ref TryAddOrGet(toEntityID));
}
public void Copy(int fromEntityID, EcsWorld toWorld, int toEntityID)
{
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
if (!Has(fromEntityID)) ThrowNotHaveComponent<T>(fromEntityID);
#endif
_componentCopyHandler.Copy(ref Write(fromEntityID), ref toWorld.GetPool<T>().TryAddOrWrite(toEntityID));
_componentCopyHandler.Copy(ref Get(fromEntityID), ref toWorld.GetPool<T>().TryAddOrGet(toEntityID));
}
#endregion
@ -175,9 +175,9 @@ namespace DCFApixels.DragonECS
#region Other
void IEcsPool.AddRaw(int entityID, object dataRaw) => Add(entityID) = (T)dataRaw;
object IEcsPool.GetRaw(int entityID) => Read(entityID);
void IEcsPool.SetRaw(int entityID, object dataRaw) => Write(entityID) = (T)dataRaw;
void IEcsPool.SetRaw(int entityID, object dataRaw) => Get(entityID) = (T)dataRaw;
ref readonly T IEcsPool<T>.Read(int entityID) => ref Read(entityID);
ref T IEcsPool<T>.Write(int entityID) => ref Write(entityID);
ref T IEcsPool<T>.Get(int entityID) => ref Get(entityID);
#endregion
#region Listeners

View File

@ -35,7 +35,7 @@ namespace DCFApixels.DragonECS
{
ref T Add(int entityID);
ref readonly T Read(int entityID);
ref T Write(int entityID);
ref T Get(int entityID);
}
/// <summary>Only used to implement a custom pool. In other contexts use IEcsPool or IEcsPool<T>.</summary>
public interface IEcsPoolImplementation : IEcsPool
@ -106,7 +106,7 @@ namespace DCFApixels.DragonECS
void IEcsPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) => throw new NotImplementedException();
ref NullComponent IEcsPool<NullComponent>.Add(int entityID) => throw new NotImplementedException();
ref readonly NullComponent IEcsPool<NullComponent>.Read(int entityID) => throw new NotImplementedException();
ref NullComponent IEcsPool<NullComponent>.Write(int entityID) => throw new NotImplementedException();
ref NullComponent IEcsPool<NullComponent>.Get(int entityID) => throw new NotImplementedException();
#endregion
#region Callbacks
@ -203,8 +203,8 @@ namespace DCFApixels.DragonECS
{
/// <summary>Called after adding an entity to the pool, but before changing values.</summary>
void OnAdd(int entityID);
/// <summary>Is called when EcsPool.Write or EcsPool.Add is called, but before changing values.</summary>
void OnWrite(int entityID);
/// <summary>Is called when EcsPool.Get or EcsPool.Add is called, but before changing values.</summary>
void OnGet(int entityID);
/// <summary>Called after deleting an entity from the pool</summary>
void OnDel(int entityID);
}
@ -216,18 +216,18 @@ namespace DCFApixels.DragonECS
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnAdd(entityID);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InvokeOnAddAndWrite(this List<IEcsPoolEventListener> self, int entityID)
public static void InvokeOnAddAndGet(this List<IEcsPoolEventListener> self, int entityID)
{
for (int i = 0, iMax = self.Count; i < iMax; i++)
{
self[i].OnAdd(entityID);
self[i].OnWrite(entityID);
self[i].OnGet(entityID);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InvokeOnWrite(this List<IEcsPoolEventListener> self, int entityID)
public static void InvokeOnGet(this List<IEcsPoolEventListener> self, int entityID)
{
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnWrite(entityID);
for (int i = 0, iMax = self.Count; i < iMax; i++) self[i].OnGet(entityID);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InvokeOnDel(this List<IEcsPoolEventListener> self, int entityID)

View File

@ -143,7 +143,7 @@ namespace DCFApixels.DragonECS
#endif
return ref _fakeComponent;
}
ref T IEcsPool<T>.Write(int entityID)
ref T IEcsPool<T>.Get(int entityID)
{
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
if (!Has(entityID)) ThrowNotHaveComponent<T>(entityID);