mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-19 02:24:37 +08:00
fix
This commit is contained in:
parent
2fff79439e
commit
ab444859d3
@ -93,6 +93,12 @@
|
|||||||
true;
|
true;
|
||||||
#else
|
#else
|
||||||
false;
|
false;
|
||||||
|
#endif
|
||||||
|
public const bool DRAGONECS_DEEP_DEBUG =
|
||||||
|
#if DRAGONECS_DEV_MODE
|
||||||
|
true;
|
||||||
|
#else
|
||||||
|
false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -869,7 +869,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new Enumerator(_span.Slice(0, 0), _iterator);
|
return new Enumerator(_span.Slice(0, 0), _iterator);
|
||||||
}
|
}
|
||||||
if (_iterator.TryGetEntityStorage(out IEntityStorage storage))
|
if (_span.IsSourceEntities && _iterator.TryGetEntityStorage(out IEntityStorage storage))
|
||||||
{
|
{
|
||||||
return new Enumerator(storage.ToSpan(), _iterator);
|
return new Enumerator(storage.ToSpan(), _iterator);
|
||||||
}
|
}
|
||||||
|
@ -127,11 +127,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsSpan Entities
|
public EcsSpan Entities
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get { return ToSpan(); }
|
||||||
{
|
|
||||||
ReleaseDelEntityBufferAll();
|
|
||||||
return GetCurrentEntities_Internal();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public int PoolsCount
|
public int PoolsCount
|
||||||
{
|
{
|
||||||
@ -397,7 +393,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
ReleaseDelEntityBufferAll();
|
ReleaseDelEntityBufferAll();
|
||||||
}
|
}
|
||||||
return _entityDispenser.UsedToEcsSpan(ID);
|
return GetCurrentEntities_Internal();
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public unsafe entlong GetEntityLong(int entityID)
|
public unsafe entlong GetEntityLong(int entityID)
|
||||||
|
@ -69,7 +69,7 @@ namespace DCFApixels.DragonECS.Internal
|
|||||||
//TODO потестить
|
//TODO потестить
|
||||||
public static void ResizeOrCreate<T>(ref T[] array, int newSize)
|
public static void ResizeOrCreate<T>(ref T[] array, int newSize)
|
||||||
{
|
{
|
||||||
if(array == null)
|
if (array == null)
|
||||||
{
|
{
|
||||||
array = new T[newSize];
|
array = new T[newSize];
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using DCFApixels.DragonECS.Core;
|
using DCFApixels.DragonECS.Core;
|
||||||
using DCFApixels.DragonECS.Internal;
|
using DCFApixels.DragonECS.Internal;
|
||||||
using DCFApixels.DragonECS.PoolsCore;
|
using DCFApixels.DragonECS.PoolsCore;
|
||||||
|
using DCFApixels.DragonECS.UncheckedCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -105,6 +106,14 @@ namespace DCFApixels.DragonECS
|
|||||||
#if !DISABLE_POOLS_EVENTS
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
|
if (_mediator.GetComponentCount(_componentTypeID) != _itemsCount)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return ref result;
|
return ref result;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -128,24 +137,43 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public ref T TryAddOrGet(int entityID)
|
public ref T TryAddOrGet(int entityID)
|
||||||
{
|
{
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
if (Has(entityID))
|
||||||
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
|
{
|
||||||
#endif
|
return ref Get(entityID);
|
||||||
ref int itemIndex = ref _mapping[entityID];
|
}
|
||||||
if (itemIndex <= 0)
|
else
|
||||||
{ //Add block
|
{
|
||||||
itemIndex = GetFreeItemIndex(entityID);
|
return ref Add(entityID);
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
}
|
||||||
_sparseEntities[itemIndex] = entityID;
|
|
||||||
EnableComponent(ref _items[itemIndex]);
|
|
||||||
#if !DISABLE_POOLS_EVENTS
|
|
||||||
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
//#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
#endif
|
// if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
|
||||||
} //Add block end
|
//#endif
|
||||||
#if !DISABLE_POOLS_EVENTS
|
// ref int itemIndex = ref _mapping[entityID];
|
||||||
_listeners.InvokeOnGet(entityID, _listenersCachedCount);
|
// if (itemIndex <= 0)
|
||||||
#endif
|
// { //Add block
|
||||||
return ref _items[itemIndex];
|
// itemIndex = GetFreeItemIndex(entityID);
|
||||||
|
// _mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
|
// _sparseEntities[itemIndex] = entityID;
|
||||||
|
// EnableComponent(ref _items[itemIndex]);
|
||||||
|
//#if !DISABLE_POOLS_EVENTS
|
||||||
|
// _listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
||||||
|
//#endif
|
||||||
|
// } //Add block end
|
||||||
|
//#if !DISABLE_POOLS_EVENTS
|
||||||
|
// _listeners.InvokeOnGet(entityID, _listenersCachedCount);
|
||||||
|
//#endif
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//#if DRAGONECS_DEEP_DEBUG
|
||||||
|
// if (_mediator.GetComponentCount(_componentTypeID) != _itemsCount)
|
||||||
|
// {
|
||||||
|
// Throw.UndefinedException();
|
||||||
|
// }
|
||||||
|
//#endif
|
||||||
|
// return ref _items[itemIndex];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(int entityID)
|
public bool Has(int entityID)
|
||||||
@ -170,6 +198,13 @@ namespace DCFApixels.DragonECS
|
|||||||
#if !DISABLE_POOLS_EVENTS
|
#if !DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
_listeners.InvokeOnDel(entityID, _listenersCachedCount);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
|
if (_mediator.GetComponentCount(_componentTypeID) != _itemsCount)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
public void TryDel(int entityID)
|
public void TryDel(int entityID)
|
||||||
{
|
{
|
||||||
@ -268,11 +303,22 @@ namespace DCFApixels.DragonECS
|
|||||||
Get(entityID) = dataRaw == null ? default : (T)dataRaw;
|
Get(entityID) = dataRaw == null ? default : (T)dataRaw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _lockToSpan = false;
|
||||||
public EcsSpan ToSpan()
|
public EcsSpan ToSpan()
|
||||||
{
|
{
|
||||||
|
if (_lockToSpan)
|
||||||
|
{
|
||||||
|
return _source.Entities;
|
||||||
|
}
|
||||||
UpdateDenseEntities();
|
UpdateDenseEntities();
|
||||||
return new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
var span = new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
||||||
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
|
if (UncheckedCoreUtility.CheckSpanValideDebug(span) == false)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return span;
|
||||||
}
|
}
|
||||||
private bool IsDenseEntitiesDelayedValid()
|
private bool IsDenseEntitiesDelayedValid()
|
||||||
{
|
{
|
||||||
@ -294,6 +340,40 @@ namespace DCFApixels.DragonECS
|
|||||||
_denseEntitiesDelayed[_denseEntitiesDelayedCount++] = _sparseEntities[i];
|
_denseEntitiesDelayed[_denseEntitiesDelayedCount++] = _sparseEntities[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
|
_lockToSpan = true;
|
||||||
|
if (_denseEntitiesDelayed[0] != 0)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
if (_denseEntitiesDelayedCount != _itemsCount + 1)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
int coreCount = _mediator.GetComponentCount(_componentTypeID);
|
||||||
|
if (coreCount != _itemsCount)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
using (_source.DisableAutoReleaseDelEntBuffer()) using (var group = EcsGroup.New(_source))
|
||||||
|
{
|
||||||
|
EcsStaticMask.Inc<T>().Build().ToMask(_source).GetIterator().IterateTo(World.Entities, group);
|
||||||
|
var span = new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
||||||
|
if (group.SetEquals(span) == false)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_lockToSpan = false;
|
||||||
|
for (int i = _denseEntitiesDelayedCount; i < _capacity; i++)
|
||||||
|
{
|
||||||
|
var index = _denseEntitiesDelayed[i];
|
||||||
|
if (_sparseEntities[index] != 0)
|
||||||
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
_isDenseEntitiesDelayedValid = true;
|
_isDenseEntitiesDelayedValid = true;
|
||||||
}
|
}
|
||||||
private int GetFreeItemIndex(int entityID)
|
private int GetFreeItemIndex(int entityID)
|
||||||
@ -312,10 +392,12 @@ namespace DCFApixels.DragonECS
|
|||||||
_denseEntitiesDelayed[_denseEntitiesDelayedCount] = entityID;
|
_denseEntitiesDelayed[_denseEntitiesDelayedCount] = entityID;
|
||||||
_itemsCount++;
|
_itemsCount++;
|
||||||
_denseEntitiesDelayedCount++;
|
_denseEntitiesDelayedCount++;
|
||||||
if(result == 0)
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
|
if (result == 0)
|
||||||
{
|
{
|
||||||
|
Throw.UndefinedException();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private void CheckOrUpsize()
|
private void CheckOrUpsize()
|
||||||
@ -352,7 +434,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Enable/Disable/Copy
|
#region Enable/Disable/Copy
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
Loading…
Reference in New Issue
Block a user