mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
Optimization
This commit is contained in:
parent
de7762861c
commit
fd653dc06f
@ -198,21 +198,22 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region AddGroup/RemoveGroup
|
#region AddGroup/RemoveGroup
|
||||||
public void AddGroup(EcsReadonlyGroup group)
|
public void AddGroup(EcsReadonlyGroup group)
|
||||||
{
|
{ foreach (var item in group) Add(item.id); }
|
||||||
foreach (var item in group) UncheckedAdd(item.id);
|
|
||||||
}
|
|
||||||
public void RemoveGroup(EcsReadonlyGroup group)
|
public void RemoveGroup(EcsReadonlyGroup group)
|
||||||
{
|
{ foreach (var item in group) Remove(item.id); }
|
||||||
foreach (var item in group) UncheckedRemove(item.id);
|
|
||||||
}
|
|
||||||
public void AddGroup(EcsGroup group)
|
public void AddGroup(EcsGroup group)
|
||||||
{
|
{ foreach (var item in group) Add(item.id); }
|
||||||
foreach (var item in group) UncheckedAdd(item.id);
|
|
||||||
}
|
|
||||||
public void RemoveGroup(EcsGroup group)
|
public void RemoveGroup(EcsGroup group)
|
||||||
{
|
{ foreach (var item in group) Remove(item.id); }
|
||||||
foreach (var item in group) UncheckedRemove(item.id);
|
|
||||||
}
|
public void UncheckedAddGroup(EcsReadonlyGroup group)
|
||||||
|
{ foreach (var item in group) AddInternal(item.id); }
|
||||||
|
public void UncheckedRemoveGroup(EcsReadonlyGroup group)
|
||||||
|
{ foreach (var item in group) RemoveInternal(item.id); }
|
||||||
|
public void UncheckedAddGroup(EcsGroup group)
|
||||||
|
{ foreach (var item in group) AddInternal(item.id); }
|
||||||
|
public void UncheckedRemoveGroup(EcsGroup group)
|
||||||
|
{ foreach (var item in group) RemoveInternal(item.id); }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetEnumerator
|
#region GetEnumerator
|
||||||
@ -231,13 +232,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
delayedOp op = _delayedOps[i];
|
delayedOp op = _delayedOps[i];
|
||||||
if (op >= 0) //delayedOp.IsAdded
|
if (op >= 0) //delayedOp.IsAdded
|
||||||
{
|
|
||||||
UncheckedAdd(op & int.MaxValue); //delayedOp.Entity
|
UncheckedAdd(op & int.MaxValue); //delayedOp.Entity
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
UncheckedRemove(op & int.MaxValue); //delayedOp.Entity
|
UncheckedRemove(op & int.MaxValue); //delayedOp.Entity
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,31 +250,29 @@ namespace DCFApixels.DragonECS
|
|||||||
public struct Enumerator : IDisposable
|
public struct Enumerator : IDisposable
|
||||||
{
|
{
|
||||||
private readonly EcsGroup _source;
|
private readonly EcsGroup _source;
|
||||||
|
private readonly int[] _dense;
|
||||||
|
private readonly int _count;
|
||||||
private int _pointer;
|
private int _pointer;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public Enumerator(EcsGroup group)
|
public Enumerator(EcsGroup group)
|
||||||
{
|
{
|
||||||
_source = group;
|
_source = group;
|
||||||
|
_dense = group._dense;
|
||||||
|
_count = group.Count;
|
||||||
_pointer = 0;
|
_pointer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EcsProfilerMarker _marker = new EcsProfilerMarker("EcsGroup.Enumerator.Current");
|
|
||||||
|
|
||||||
public ent Current
|
public ent Current
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get
|
get => _source.World.GetEntity(_dense[_pointer]);
|
||||||
{
|
|
||||||
using (_marker.Auto())
|
|
||||||
return _source.World.GetEntity(_source._dense[_pointer]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
{
|
{
|
||||||
return ++_pointer <= _source.Count;
|
return ++_pointer <= _count && _count < _dense.Length; //_count < _dense.Length дает среде понять что проверки на выход за границы не нужны
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -287,10 +282,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Reset()
|
public void Reset() { }
|
||||||
{
|
|
||||||
_pointer = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ namespace DCFApixels.DragonECS
|
|||||||
public IEcsWorld World { get; }
|
public IEcsWorld World { get; }
|
||||||
public Type DataType { get; }
|
public Type DataType { get; }
|
||||||
public int ID { get; }
|
public int ID { get; }
|
||||||
public bool Has(int index);
|
public bool Has(int entityID);
|
||||||
public void Write(int index);
|
public void Write(int entityID);
|
||||||
public void Del(int index);
|
public void Del(int entityID);
|
||||||
|
|
||||||
internal void OnWorldResize(int newSize);
|
internal void OnWorldResize(int newSize);
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
private readonly int _id;
|
private readonly int _id;
|
||||||
private readonly IEcsWorld _source;
|
private readonly IEcsWorld _source;
|
||||||
// private readonly EcsGroup _entities;
|
// private readonly EcsGroup _entities;
|
||||||
|
|
||||||
private int[] _mapping;// index = entity / value = itemIndex;/ value = 0 = no entity
|
private int[] _mapping;// index = entity / value = itemIndex;/ value = 0 = no entity
|
||||||
private T[] _items; //dense
|
private T[] _items; //dense
|
||||||
@ -86,7 +86,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_mapping = new int[source.EntitesCapacity];
|
_mapping = new int[source.EntitesCapacity];
|
||||||
_recycledItems = new int[128];
|
_recycledItems = new int[128];
|
||||||
_recycledItemsCount = 0;
|
_recycledItemsCount = 0;
|
||||||
_items =new T[capacity];
|
_items = new T[capacity];
|
||||||
_itemsCount = 0;
|
_itemsCount = 0;
|
||||||
|
|
||||||
_componentResetHandler = ComponentResetHandler.New<T>();
|
_componentResetHandler = ComponentResetHandler.New<T>();
|
||||||
@ -102,8 +102,8 @@ namespace DCFApixels.DragonECS
|
|||||||
private ProfilerMarker _delMark = new ProfilerMarker("EcsPoo.Del");
|
private ProfilerMarker _delMark = new ProfilerMarker("EcsPoo.Del");
|
||||||
public ref T Write(int entityID)
|
public ref T Write(int entityID)
|
||||||
{
|
{
|
||||||
//using (_writeMark.Auto())
|
// using (_writeMark.Auto())
|
||||||
//{
|
// {
|
||||||
ref int itemIndex = ref _mapping[entityID];
|
ref int itemIndex = ref _mapping[entityID];
|
||||||
if (itemIndex <= 0) //åñëè 0 òî íàäî äîáàâèòü
|
if (itemIndex <= 0) //åñëè 0 òî íàäî äîáàâèòü
|
||||||
{
|
{
|
||||||
@ -131,35 +131,34 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref readonly T Read(int entityID)
|
public ref readonly T Read(int entityID)
|
||||||
{
|
{
|
||||||
//using (_readMark.Auto())
|
// using (_readMark.Auto())
|
||||||
return ref _items[_mapping[entityID]];
|
return ref _items[_mapping[entityID]];
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(int entityID)
|
public bool Has(int entityID)
|
||||||
{
|
{
|
||||||
//using (_hasMark.Auto())
|
// using (_hasMark.Auto())
|
||||||
return _mapping[entityID] > 0;
|
return _mapping[entityID] > 0;
|
||||||
}
|
}
|
||||||
public void Del(int entityID)
|
public void Del(int entityID)
|
||||||
{
|
{
|
||||||
//using (_delMark.Auto())
|
//using (_delMark.Auto())
|
||||||
//{
|
// {
|
||||||
if(_recycledItemsCount >= _recycledItems.Length)
|
if (_recycledItemsCount >= _recycledItems.Length)
|
||||||
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
Array.Resize(ref _recycledItems, _recycledItems.Length << 1);
|
||||||
_recycledItems[_recycledItemsCount++] = _mapping[entityID];
|
_recycledItems[_recycledItemsCount++] = _mapping[entityID];
|
||||||
_mapping[entityID] = 0;
|
_mapping[entityID] = 0;
|
||||||
_itemsCount--;
|
_itemsCount--;
|
||||||
//_entities.UncheckedRemove(entityID);
|
|
||||||
_source.OnEntityComponentRemoved(entityID, _id);
|
_source.OnEntityComponentRemoved(entityID, _id);
|
||||||
_poolRunnres.del.OnComponentDel<T>(entityID);
|
_poolRunnres.del.OnComponentDel<T>(entityID);
|
||||||
//}
|
// }
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEcsPool
|
#region IEcsPool
|
||||||
void IEcsPool.Write(int index)
|
void IEcsPool.Write(int entityID)
|
||||||
{
|
{
|
||||||
Write(index);
|
Write(entityID);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user