mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
tmp commit
This commit is contained in:
parent
b07256f020
commit
db863bf8bf
@ -142,7 +142,7 @@ namespace DCFApixels.DragonECS
|
|||||||
Dictionary<int, int> r = new Dictionary<int, int>();
|
Dictionary<int, int> r = new Dictionary<int, int>();
|
||||||
foreach (var id in maskInc)
|
foreach (var id in maskInc)
|
||||||
{
|
{
|
||||||
var bit = EcsMaskBit.FromPoolID(id);
|
var bit = EcsMaskBit.FromID(id);
|
||||||
if(!r.TryAdd(bit.chankIndex, bit.mask))
|
if(!r.TryAdd(bit.chankIndex, bit.mask))
|
||||||
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ namespace DCFApixels.DragonECS
|
|||||||
r.Clear();
|
r.Clear();
|
||||||
foreach (var id in maskExc)
|
foreach (var id in maskExc)
|
||||||
{
|
{
|
||||||
var bit = EcsMaskBit.FromPoolID(id);
|
var bit = EcsMaskBit.FromID(id);
|
||||||
if (!r.TryAdd(bit.chankIndex, bit.mask))
|
if (!r.TryAdd(bit.chankIndex, bit.mask))
|
||||||
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
r[bit.chankIndex] = r[bit.chankIndex] | bit.mask;
|
||||||
}
|
}
|
||||||
@ -218,6 +218,10 @@ namespace DCFApixels.DragonECS
|
|||||||
#region Mask
|
#region Mask
|
||||||
public readonly struct EcsMaskBit
|
public readonly struct EcsMaskBit
|
||||||
{
|
{
|
||||||
|
private const int BITS = 32;
|
||||||
|
private const int DIV_SHIFT = 5;
|
||||||
|
private const int MOD_MASK = BITS - 1;
|
||||||
|
|
||||||
public readonly int chankIndex;
|
public readonly int chankIndex;
|
||||||
public readonly int mask;
|
public readonly int mask;
|
||||||
public EcsMaskBit(int chankIndex, int mask)
|
public EcsMaskBit(int chankIndex, int mask)
|
||||||
@ -225,11 +229,10 @@ namespace DCFApixels.DragonECS
|
|||||||
this.chankIndex = chankIndex;
|
this.chankIndex = chankIndex;
|
||||||
this.mask = mask;
|
this.mask = mask;
|
||||||
}
|
}
|
||||||
public static EcsMaskBit FromPoolID(int id)
|
public static EcsMaskBit FromID(int id)
|
||||||
{
|
{
|
||||||
return new EcsMaskBit(id / 32, 1 << (id % 32));
|
return new EcsMaskBit(id >> DIV_SHIFT, 1 << (id & MOD_MASK)); //аналогично new EcsMaskBit(id / BITS, 1 << (id % BITS)) но быстрее
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"bit({chankIndex}, {mask})";
|
return $"bit({chankIndex}, {mask})";
|
||||||
|
@ -273,14 +273,14 @@ namespace DCFApixels.DragonECS
|
|||||||
internal void IncrementEntityComponentCount(int entityID, int componentID)
|
internal void IncrementEntityComponentCount(int entityID, int componentID)
|
||||||
{
|
{
|
||||||
_componentCounts[entityID]++;
|
_componentCounts[entityID]++;
|
||||||
EcsMaskBit bit = EcsMaskBit.FromPoolID(componentID);
|
EcsMaskBit bit = EcsMaskBit.FromID(componentID);
|
||||||
_entitiesComponentMasks[entityID][bit.chankIndex] |= bit.mask;
|
_entitiesComponentMasks[entityID][bit.chankIndex] |= bit.mask;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
internal void DecrementEntityComponentCount(int entityID, int componentID)
|
internal void DecrementEntityComponentCount(int entityID, int componentID)
|
||||||
{
|
{
|
||||||
var count = --_componentCounts[entityID];
|
var count = --_componentCounts[entityID];
|
||||||
EcsMaskBit bit = EcsMaskBit.FromPoolID(componentID);
|
EcsMaskBit bit = EcsMaskBit.FromID(componentID);
|
||||||
_entitiesComponentMasks[entityID][bit.chankIndex] &= ~bit.mask;
|
_entitiesComponentMasks[entityID][bit.chankIndex] &= ~bit.mask;
|
||||||
|
|
||||||
if (count == 0 && _allEntites.Has(entityID))
|
if (count == 0 && _allEntites.Has(entityID))
|
||||||
|
@ -140,7 +140,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_source = world;
|
_source = world;
|
||||||
_componentID = componentID;
|
_componentID = componentID;
|
||||||
|
|
||||||
_maskBit = EcsMaskBit.FromPoolID(componentID);
|
_maskBit = EcsMaskBit.FromID(componentID);
|
||||||
|
|
||||||
const int capacity = 512;
|
const int capacity = 512;
|
||||||
|
|
||||||
|
@ -187,7 +187,14 @@ namespace DCFApixels.DragonECS
|
|||||||
if (!Has(key: key)) EcsPoolThrowHalper.ThrowNotHaveComponent<T>(unchecked((int)key));
|
if (!Has(key: key)) EcsPoolThrowHalper.ThrowNotHaveComponent<T>(unchecked((int)key));
|
||||||
#endif
|
#endif
|
||||||
_listeners.InvokeOnGet(unchecked((int)key));
|
_listeners.InvokeOnGet(unchecked((int)key));
|
||||||
return ref _entries[FindEntry(key)].value;
|
//return ref _entries[FindEntry(key)].value;
|
||||||
|
|
||||||
|
for (int i = _buckets[unchecked((int)key & _modBitMask)]; i >= 0; i = _entries[i].next)
|
||||||
|
if (_entries[i].key == key) return ref _entries[i].value; // return i;
|
||||||
|
|
||||||
|
#pragma warning disable CS0251 // Èíäåêñàöèÿ ìàññèâà ñ îòðèöàòåëüíûì èíäåêñîì
|
||||||
|
return ref _entries[-1].value; //ïðè íîðìàëüíîé ðàáîòå ýòî íåäîñòèæèìûé êîä.
|
||||||
|
#pragma warning restore CS0251 // Èíäåêñàöèÿ ìàññèâà ñ îòðèöàòåëüíûì èíäåêñîì
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
@ -25,15 +25,15 @@ namespace DCFApixels.DragonECS.Utils
|
|||||||
private int _modBitMask;
|
private int _modBitMask;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public TValue this[long keyX, long keyY]
|
public ref TValue this[long keyX, long keyY]
|
||||||
{
|
{
|
||||||
get => _entries[FindEntry(keyX + (keyY << 32))].value;
|
get => ref _entries[FindEntry(keyX + (keyY << 32))].value;
|
||||||
set => Insert(keyX + (keyY << 32), value);
|
//set => Insert(keyX + (keyY << 32), value);
|
||||||
}
|
}
|
||||||
public TValue this[long key]
|
public ref TValue this[long key]
|
||||||
{
|
{
|
||||||
get => _entries[FindEntry(key)].value;
|
get => ref _entries[FindEntry(key)].value;
|
||||||
set => Insert(key, value);
|
//set => Insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count => _count;
|
public int Count => _count;
|
||||||
|
Loading…
Reference in New Issue
Block a user