This commit is contained in:
Mikhail 2024-03-13 17:41:33 +08:00
parent a83dacedcf
commit e56c7f94d7
5 changed files with 103 additions and 13 deletions

View File

@ -157,6 +157,8 @@ namespace DCFApixels.DragonECS
int entitiesCapacity = ArrayUtility.NormalizeSizeToPowerOfTwo(config.EntitiesCapacity); int entitiesCapacity = ArrayUtility.NormalizeSizeToPowerOfTwo(config.EntitiesCapacity);
_entityDispenser = new IdDispenser(entitiesCapacity, 0, OnEntityDispenserResized); _entityDispenser = new IdDispenser(entitiesCapacity, 0, OnEntityDispenserResized);
GetComponentTypeID<NullComponent>();
} }
public void Destroy() public void Destroy()
{ {

View File

@ -166,6 +166,21 @@ namespace DCFApixels.DragonECS
#endif #endif
CopyComponent(ref Get(fromEntityID), ref toWorld.GetPool<T>().TryAddOrGet(toEntityID)); CopyComponent(ref Get(fromEntityID), ref toWorld.GetPool<T>().TryAddOrGet(toEntityID));
} }
public void ClearAll()
{
var span = _source.Where(out SingleAspect<EcsPool<T>> _);
_itemsCount = 0;
_recycledItemsCount = 0;
foreach (var entityID in span)
{
ref int itemIndex = ref _mapping[entityID];
DisableComponent(ref _items[itemIndex]);
itemIndex = 0;
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
_listeners.InvokeOnDel(entityID);
}
}
#endregion #endregion
#region Callbacks #region Callbacks
@ -199,9 +214,15 @@ namespace DCFApixels.DragonECS
#endregion #endregion
#region Other #region Other
void IEcsPool.AddRaw(int entityID, object dataRaw) { Add(entityID) = (T)dataRaw; } void IEcsPool.AddRaw(int entityID, object dataRaw)
{
Add(entityID) = dataRaw == null ? default : (T)dataRaw;
}
object IEcsReadonlyPool.GetRaw(int entityID) { return Get(entityID); } object IEcsReadonlyPool.GetRaw(int entityID) { return Get(entityID); }
void IEcsPool.SetRaw(int entityID, object dataRaw) { Get(entityID) = (T)dataRaw; } void IEcsPool.SetRaw(int entityID, object dataRaw)
{
Get(entityID) = dataRaw == null ? default : (T)dataRaw;
}
#endregion #endregion
#region Listeners #region Listeners

View File

@ -33,6 +33,7 @@ namespace DCFApixels.DragonECS
void AddRaw(int entityID, object dataRaw); void AddRaw(int entityID, object dataRaw);
void SetRaw(int entityID, object dataRaw); void SetRaw(int entityID, object dataRaw);
void Del(int entityID); void Del(int entityID);
void ClearAll();
#endregion #endregion
} }
/// <summary>A pool for struct components.</summary> /// <summary>A pool for struct components.</summary>
@ -103,21 +104,68 @@ namespace DCFApixels.DragonECS
public static readonly EcsNullPool instance = new EcsNullPool(); public static readonly EcsNullPool instance = new EcsNullPool();
#region Properties #region Properties
int IEcsReadonlyPool.ComponentTypeID => -1; int IEcsReadonlyPool.ComponentTypeID { get { return 0; } }//TODO Првоерить что NullComponent всегда имеет id 0
Type IEcsReadonlyPool.ComponentType => typeof(NullComponent); Type IEcsReadonlyPool.ComponentType { get { return typeof(NullComponent); } }
EcsWorld IEcsReadonlyPool.World => throw new NotImplementedException(); EcsWorld IEcsReadonlyPool.World
public int Count => -1; {
get
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
}
public int Count { get { return 0; } }
public bool IsReadOnly { get { return true; } } public bool IsReadOnly { get { return true; } }
#endregion #endregion
#region Methods #region Methods
bool IEcsReadonlyPool.Has(int index) => false; bool IEcsReadonlyPool.Has(int index)
void IEcsPool.Del(int entityID) => throw new NotImplementedException(); {
void IEcsPool.AddRaw(int entityID, object dataRaw) => throw new NotImplementedException(); return false;
object IEcsReadonlyPool.GetRaw(int entityID) => throw new NotImplementedException(); }
void IEcsPool.SetRaw(int entity, object dataRaw) => throw new NotImplementedException(); void IEcsPool.Del(int entityID)
void IEcsReadonlyPool.Copy(int fromEntityID, int toEntityID) => throw new NotImplementedException(); {
void IEcsReadonlyPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID) => throw new NotImplementedException(); #if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
void IEcsPool.AddRaw(int entityID, object dataRaw)
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
object IEcsReadonlyPool.GetRaw(int entityID)
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
void IEcsPool.SetRaw(int entity, object dataRaw)
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
void IEcsReadonlyPool.Copy(int fromEntityID, int toEntityID)
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
void IEcsReadonlyPool.Copy(int fromEntityID, EcsWorld toWorld, int toEntityID)
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
void IEcsPool.ClearAll()
{
#if (DEBUG && !DISABLE_DEBUG)
throw new NullInstanceException();
#endif
}
#endregion #endregion
#region Callbacks #region Callbacks

View File

@ -145,6 +145,18 @@ namespace DCFApixels.DragonECS
Add(entityID); Add(entityID);
} }
} }
public void ClearAll()
{
var span = _source.Where(out SingleAspect<EcsTagPool<T>> _);
_count = 0;
foreach (var entityID in span)
{
_mapping[entityID] = false;
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
_listeners.InvokeOnDel(entityID);
}
}
#endregion #endregion
#region Callbacks #region Callbacks

View File

@ -11,6 +11,13 @@ namespace DCFApixels.DragonECS
public EcsFrameworkException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { } public EcsFrameworkException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
} }
[Serializable] [Serializable]
public class NullInstanceException : EcsFrameworkException
{
public NullInstanceException() { }
public NullInstanceException(string message) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message) { }
public NullInstanceException(string message, Exception inner) : base(EcsConsts.EXCEPTION_MESSAGE_PREFIX + message, inner) { }
}
[Serializable]
public class EcsRunnerImplementationException : EcsFrameworkException public class EcsRunnerImplementationException : EcsFrameworkException
{ {
public EcsRunnerImplementationException() { } public EcsRunnerImplementationException() { }