mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
stash
This commit is contained in:
parent
5c80c13924
commit
48e02602c3
@ -247,7 +247,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Static Constructor
|
#region Static Constructor
|
||||||
static DebugService()
|
static DebugService()
|
||||||
{
|
{
|
||||||
#if !UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
Set(new NullDebugService());
|
Set(new NullDebugService());
|
||||||
#else
|
#else
|
||||||
Set(new DefaultDebugService());
|
Set(new DefaultDebugService());
|
||||||
|
@ -620,7 +620,7 @@ namespace DCFApixels.DragonECS
|
|||||||
// Поэтому исключающее ограничение игнорируется для maxEntites.
|
// Поэтому исключающее ограничение игнорируется для maxEntites.
|
||||||
return maxEntites;
|
return maxEntites;
|
||||||
}
|
}
|
||||||
private unsafe bool TryFindEntityStorage(out IEntityStorage storage)
|
private unsafe bool TryGetEntityStorage(out IEntityStorage storage)
|
||||||
{
|
{
|
||||||
if (_isHasAnyEntityStorage)
|
if (_isHasAnyEntityStorage)
|
||||||
{
|
{
|
||||||
@ -746,7 +746,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new Enumerator(_span.Slice(0, 0), _iterator);
|
return new Enumerator(_span.Slice(0, 0), _iterator);
|
||||||
}
|
}
|
||||||
if (_iterator.TryFindEntityStorage(out IEntityStorage storage))
|
if (_span.IsSourceEntities && _iterator.TryGetEntityStorage(out IEntityStorage storage))
|
||||||
{
|
{
|
||||||
return new Enumerator(storage.ToSpan(), _iterator);
|
return new Enumerator(storage.ToSpan(), _iterator);
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
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;
|
||||||
@ -45,8 +44,9 @@ namespace DCFApixels.DragonECS
|
|||||||
private int _itemsCount = 0;
|
private int _itemsCount = 0;
|
||||||
private int _capacity = 0;
|
private int _capacity = 0;
|
||||||
|
|
||||||
private int[] _sparseEntities;
|
//private int[] _sparseEntities;
|
||||||
private int[] _denseEntitiesDelayed;
|
//private int[] _denseEntitiesDelayed;
|
||||||
|
private int[] _table;
|
||||||
private int _denseEntitiesDelayedCount = 0;
|
private int _denseEntitiesDelayedCount = 0;
|
||||||
private bool _isDenseEntitiesDelayedValid = false;
|
private bool _isDenseEntitiesDelayedValid = false;
|
||||||
private int _recycledCount = 0;
|
private int _recycledCount = 0;
|
||||||
@ -111,7 +111,8 @@ namespace DCFApixels.DragonECS
|
|||||||
itemIndex = GetFreeItemIndex(entityID);
|
itemIndex = GetFreeItemIndex(entityID);
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
ref T result = ref _items[itemIndex];
|
ref T result = ref _items[itemIndex];
|
||||||
_sparseEntities[itemIndex] = entityID;
|
//_sparseEntities[itemIndex] = entityID;
|
||||||
|
_table[itemIndex] = entityID;
|
||||||
EnableComponent(ref result);
|
EnableComponent(ref result);
|
||||||
#if !DRAGONECS_DISABLE_POOLS_EVENTS
|
#if !DRAGONECS_DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
_listeners.InvokeOnAddAndGet(entityID, _listenersCachedCount);
|
||||||
@ -167,7 +168,8 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
itemIndex = GetFreeItemIndex(entityID);
|
itemIndex = GetFreeItemIndex(entityID);
|
||||||
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.RegisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
_sparseEntities[itemIndex] = entityID;
|
//_sparseEntities[itemIndex] = entityID;
|
||||||
|
_table[itemIndex] = entityID;
|
||||||
EnableComponent(ref _items[itemIndex]);
|
EnableComponent(ref _items[itemIndex]);
|
||||||
#if !DRAGONECS_DISABLE_POOLS_EVENTS
|
#if !DRAGONECS_DISABLE_POOLS_EVENTS
|
||||||
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
_listeners.InvokeOnAdd(entityID, _listenersCachedCount);
|
||||||
@ -202,7 +204,8 @@ namespace DCFApixels.DragonECS
|
|||||||
if (_isLocked) { return; }
|
if (_isLocked) { return; }
|
||||||
#endif
|
#endif
|
||||||
DisableComponent(ref _items[itemIndex]);
|
DisableComponent(ref _items[itemIndex]);
|
||||||
_sparseEntities[itemIndex] = 0;
|
//_sparseEntities[itemIndex] = 0;
|
||||||
|
_table[itemIndex] = 0;
|
||||||
itemIndex = 0;
|
itemIndex = 0;
|
||||||
_itemsCount--;
|
_itemsCount--;
|
||||||
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
_mediator.UnregisterComponent(entityID, _componentTypeID, _maskBit);
|
||||||
@ -325,37 +328,48 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
UpdateDenseEntities();
|
UpdateDenseEntities();
|
||||||
var span = new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
//var span = new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
||||||
|
var span = new EcsSpan(_source.ID, _table, 1 + _capacity, _itemsCount);
|
||||||
#if DRAGONECS_DEEP_DEBUG
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
if (UncheckedCoreUtility.CheckSpanValideDebug(span) == false)
|
if (DCFApixels.DragonECS.UncheckedCore.UncheckedCoreUtility.CheckSpanValideDebug(span) == false)
|
||||||
{
|
{
|
||||||
Throw.UndefinedException();
|
Throw.UndefinedException();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
private void UpdateDenseEntities()
|
private unsafe void UpdateDenseEntities()
|
||||||
{
|
{
|
||||||
if (_isDenseEntitiesDelayedValid) { return; }
|
if (_isDenseEntitiesDelayedValid) { return; }
|
||||||
_denseEntitiesDelayedCount = 1;
|
//_denseEntitiesDelayedCount = 1;
|
||||||
_denseEntitiesDelayed[0] = 0;
|
_denseEntitiesDelayedCount = 1 + _capacity;
|
||||||
|
//_denseEntitiesDelayed[0] = 0;
|
||||||
|
_table[_capacity] = 0;
|
||||||
_recycledCount = 0;
|
_recycledCount = 0;
|
||||||
for (int i = 1, jRight = _itemsCount + 1; _denseEntitiesDelayedCount <= _itemsCount; i++)
|
//for (int i = 1, jRight = _capacity + _itemsCount + 1; _denseEntitiesDelayedCount <= _itemsCount; i++)
|
||||||
|
for (int i = 1, jRight = _capacity + _itemsCount + 1, max = _itemsCount + _capacity; _denseEntitiesDelayedCount <= max; i++)
|
||||||
{
|
{
|
||||||
if (_sparseEntities[i] == 0)
|
//if (_sparseEntities[i] == 0)
|
||||||
|
if (_table[i] == 0)
|
||||||
{
|
{
|
||||||
_denseEntitiesDelayed[jRight] = i;
|
//_denseEntitiesDelayed[jRight] = i;
|
||||||
|
_table[jRight] = i;
|
||||||
jRight++;
|
jRight++;
|
||||||
_recycledCount++;
|
_recycledCount++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_denseEntitiesDelayed[_denseEntitiesDelayedCount++] = _sparseEntities[i];
|
//_denseEntitiesDelayed[_denseEntitiesDelayedCount++] = _sparseEntities[i];
|
||||||
|
//_table[_denseEntitiesDelayedCount++ + _capacity] = _table[i];
|
||||||
|
_table[_denseEntitiesDelayedCount++] = _table[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_denseEntitiesDelayedCount -= _capacity;
|
||||||
|
|
||||||
#if DRAGONECS_DEEP_DEBUG
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
_lockToSpan = true;
|
_lockToSpan = true;
|
||||||
if (_denseEntitiesDelayed[0] != 0)
|
//if (_denseEntitiesDelayed[0] != 0)
|
||||||
|
if (_table[_capacity] != 0)
|
||||||
{
|
{
|
||||||
Throw.UndefinedException();
|
Throw.UndefinedException();
|
||||||
}
|
}
|
||||||
@ -371,7 +385,8 @@ namespace DCFApixels.DragonECS
|
|||||||
using (_source.DisableAutoReleaseDelEntBuffer()) using (var group = EcsGroup.New(_source))
|
using (_source.DisableAutoReleaseDelEntBuffer()) using (var group = EcsGroup.New(_source))
|
||||||
{
|
{
|
||||||
EcsStaticMask.Inc<T>().Build().ToMask(_source).GetIterator().IterateTo(World.Entities, group);
|
EcsStaticMask.Inc<T>().Build().ToMask(_source).GetIterator().IterateTo(World.Entities, group);
|
||||||
var span = new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
//var span = new EcsSpan(_source.ID, _denseEntitiesDelayed, 1, _itemsCount);
|
||||||
|
var span = new EcsSpan(_source.ID, _table, 1 + _capacity, _itemsCount);
|
||||||
if (group.SetEquals(span) == false)
|
if (group.SetEquals(span) == false)
|
||||||
{
|
{
|
||||||
Throw.UndefinedException();
|
Throw.UndefinedException();
|
||||||
@ -380,8 +395,10 @@ namespace DCFApixels.DragonECS
|
|||||||
_lockToSpan = false;
|
_lockToSpan = false;
|
||||||
for (int i = _denseEntitiesDelayedCount; i < _denseEntitiesDelayedCount + _recycledCount; i++)
|
for (int i = _denseEntitiesDelayedCount; i < _denseEntitiesDelayedCount + _recycledCount; i++)
|
||||||
{
|
{
|
||||||
var index = _denseEntitiesDelayed[i];
|
//var index = _denseEntitiesDelayed[i];
|
||||||
if (_sparseEntities[index] != 0)
|
var index = _table[i + _capacity];
|
||||||
|
//if (_sparseEntities[index] != 0)
|
||||||
|
if (_table[index] != 0)
|
||||||
{
|
{
|
||||||
Throw.UndefinedException();
|
Throw.UndefinedException();
|
||||||
}
|
}
|
||||||
@ -392,12 +409,12 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private int GetFreeItemIndex(int entityID)
|
private int GetFreeItemIndex(int entityID)
|
||||||
{
|
{
|
||||||
if (_denseEntitiesDelayedCount >= _capacity)
|
if (_denseEntitiesDelayedCount >= _items.Length)
|
||||||
{
|
{
|
||||||
UpdateDenseEntities();
|
UpdateDenseEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_itemsCount + 1 >= _capacity)
|
if (_itemsCount + 1 >= _items.Length)
|
||||||
{
|
{
|
||||||
Resize(_items.Length << 1);
|
Resize(_items.Length << 1);
|
||||||
}
|
}
|
||||||
@ -405,18 +422,21 @@ namespace DCFApixels.DragonECS
|
|||||||
if(_recycledCount > 0)
|
if(_recycledCount > 0)
|
||||||
{
|
{
|
||||||
_recycledCount--;
|
_recycledCount--;
|
||||||
result = _denseEntitiesDelayed[_denseEntitiesDelayedCount];
|
//result = _denseEntitiesDelayed[_denseEntitiesDelayedCount];
|
||||||
|
result = _table[_denseEntitiesDelayedCount + _capacity];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = _denseEntitiesDelayedCount;
|
result = _denseEntitiesDelayedCount;
|
||||||
}
|
}
|
||||||
_denseEntitiesDelayed[_denseEntitiesDelayedCount] = entityID;
|
//_denseEntitiesDelayed[_denseEntitiesDelayedCount] = entityID;
|
||||||
|
_table[_denseEntitiesDelayedCount + _capacity] = entityID;
|
||||||
_itemsCount++;
|
_itemsCount++;
|
||||||
_denseEntitiesDelayedCount++;
|
_denseEntitiesDelayedCount++;
|
||||||
|
|
||||||
#if DRAGONECS_DEEP_DEBUG
|
#if DRAGONECS_DEEP_DEBUG
|
||||||
if (_sparseEntities[result] != 0)
|
//if (_sparseEntities[result] != 0)
|
||||||
|
if (_table[result] != 0)
|
||||||
{
|
{
|
||||||
Throw.UndefinedException();
|
Throw.UndefinedException();
|
||||||
}
|
}
|
||||||
@ -427,17 +447,27 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
private void CheckOrUpsize()
|
//private void CheckOrUpsize()
|
||||||
{
|
//{
|
||||||
if (_itemsCount < _capacity) { return; }
|
// if (_itemsCount < _capacity) { return; }
|
||||||
Resize(_items.Length << 1);
|
// Resize(_items.Length << 1);
|
||||||
}
|
//}
|
||||||
private void Resize(int newSize)
|
private void Resize(int newSize)
|
||||||
{
|
{
|
||||||
if (newSize <= _capacity) { return; }
|
if (newSize <= _capacity) { return; }
|
||||||
ArrayUtility.ResizeOrCreate(ref _sparseEntities, newSize);
|
|
||||||
|
//ArrayUtility.ResizeOrCreate(ref _sparseEntities, newSize);
|
||||||
|
//ArrayUtility.ResizeOrCreate(ref _items, newSize);
|
||||||
|
//_denseEntitiesDelayed = new int[newSize];
|
||||||
|
|
||||||
ArrayUtility.ResizeOrCreate(ref _items, newSize);
|
ArrayUtility.ResizeOrCreate(ref _items, newSize);
|
||||||
_denseEntitiesDelayed = new int[newSize];
|
var newTable = new int[newSize * 2];
|
||||||
|
if(_table != null)
|
||||||
|
{
|
||||||
|
Array.Copy(_table, newTable, _table.Length / 2);
|
||||||
|
}
|
||||||
|
_table = newTable;
|
||||||
|
|
||||||
_denseEntitiesDelayedCount = 0;
|
_denseEntitiesDelayedCount = 0;
|
||||||
_capacity = newSize;
|
_capacity = newSize;
|
||||||
_isDenseEntitiesDelayedValid = false;
|
_isDenseEntitiesDelayedValid = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user