mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 01:44:35 +08:00
fix changes
This commit is contained in:
parent
0d4da6325c
commit
b26a255a90
16
src/EcsComponentMask.cs
Normal file
16
src/EcsComponentMask.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public class EcsComponentMask
|
||||
{
|
||||
internal Type WorldArchetypeType;
|
||||
internal int[] Inc;
|
||||
internal int[] Exc;
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Inc({string.Join(", ", Inc)}) Exc({string.Join(", ", Exc)})";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -264,7 +264,7 @@ namespace DCFApixels.DragonECS
|
||||
public void CopyFrom(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (group.World != _source) throw new ArgumentException("groupFilter.World != World");
|
||||
if (group.World != _source) throw new ArgumentException("groupFilter.WorldIndex != WorldIndex");
|
||||
#endif
|
||||
if(_count > 0)
|
||||
Clear();
|
||||
@ -287,7 +287,7 @@ namespace DCFApixels.DragonECS
|
||||
public void UnionWith(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (_source != group.World) throw new ArgumentException("World != groupFilter.World");
|
||||
if (_source != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex");
|
||||
#endif
|
||||
foreach (var item in group)
|
||||
if (!Contains(item.id))
|
||||
@ -301,7 +301,7 @@ namespace DCFApixels.DragonECS
|
||||
public void ExceptWith(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (_source != group.World) throw new ArgumentException("World != groupFilter.World");
|
||||
if (_source != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex");
|
||||
#endif
|
||||
foreach (var item in this)
|
||||
if (group.Contains(item.id))
|
||||
@ -315,7 +315,7 @@ namespace DCFApixels.DragonECS
|
||||
public void AndWith(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (World != group.World) throw new ArgumentException("World != groupFilter.World");
|
||||
if (World != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex");
|
||||
#endif
|
||||
foreach (var item in this)
|
||||
if (!group.Contains(item.id))
|
||||
@ -329,7 +329,7 @@ namespace DCFApixels.DragonECS
|
||||
public void XorWith(EcsGroup group)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (_source != group.World) throw new ArgumentException("World != groupFilter.World");
|
||||
if (_source != group.World) throw new ArgumentException("WorldIndex != groupFilter.WorldIndex");
|
||||
#endif
|
||||
foreach (var item in group)
|
||||
if (Contains(item.id))
|
||||
@ -345,7 +345,7 @@ namespace DCFApixels.DragonECS
|
||||
public static EcsGroup Except(EcsGroup a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (a._source != b._source) throw new ArgumentException("a.World != b.World");
|
||||
if (a._source != b._source) throw new ArgumentException("a.WorldIndex != b.WorldIndex");
|
||||
#endif
|
||||
EcsGroup result = a._source.GetGroupFromPool();
|
||||
foreach (var item in a)
|
||||
@ -359,7 +359,7 @@ namespace DCFApixels.DragonECS
|
||||
public static EcsGroup And(EcsGroup a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (a._source != b._source) throw new ArgumentException("a.World != b.World");
|
||||
if (a._source != b._source) throw new ArgumentException("a.WorldIndex != b.WorldIndex");
|
||||
#endif
|
||||
EcsGroup result = a._source.GetGroupFromPool();
|
||||
foreach (var item in a)
|
||||
@ -373,7 +373,7 @@ namespace DCFApixels.DragonECS
|
||||
public static EcsGroup Union(EcsGroup a, EcsGroup b)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (a._source != b._source) throw new ArgumentException("a.World != b.World");
|
||||
if (a._source != b._source) throw new ArgumentException("a.WorldIndex != b.WorldIndex");
|
||||
#endif
|
||||
EcsGroup result = a._source.GetGroupFromPool();
|
||||
foreach (var item in a)
|
||||
|
296
src/EcsMask.cs
296
src/EcsMask.cs
@ -23,7 +23,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -33,8 +33,8 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -44,9 +44,9 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -56,10 +56,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -69,11 +69,11 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -83,12 +83,12 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -98,13 +98,13 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T6>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -114,14 +114,14 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T6>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T7>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -131,15 +131,15 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T6>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T7>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T8>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -149,16 +149,16 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T9>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T6>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T7>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T8>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T9>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -168,17 +168,17 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T9>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T10>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T6>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T7>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T8>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T9>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T10>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -188,18 +188,18 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T6>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T7>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T8>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T9>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T10>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T11>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T6>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T7>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T8>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T9>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T10>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T11>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -217,7 +217,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -227,8 +227,8 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -238,9 +238,9 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -250,10 +250,10 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -263,11 +263,11 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -277,47 +277,23 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
return new int[]
|
||||
{
|
||||
ComponentIndexer.GetComponentId<T0>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T1>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T2>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T3>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T4>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
ComponentIndexer.GetComponentId<T5>(ComponentIndexer.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T0>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T1>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T2>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T3>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T4>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
WorldMetaStorage.GetComponentId<T5>(WorldMetaStorage.GetWorldId<TWorldArchetype>()),
|
||||
};
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region EcsMask
|
||||
public class EcsComponentMask
|
||||
{
|
||||
internal Type WorldArchetypeType;
|
||||
internal int[] Inc;
|
||||
internal int[] Exc;
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Inc({string.Join(", ", Inc)}) Exc({string.Join(", ", Exc)})";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public sealed class EcsMask : EcsComponentMask
|
||||
{
|
||||
// internal readonly Type WorldArchetypeType;
|
||||
internal readonly int UniqueID;
|
||||
//internal readonly int[] Inc;
|
||||
//internal readonly int[] Exc;
|
||||
|
||||
//internal int IncCount
|
||||
//{
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// get => Inc.Length;
|
||||
//}
|
||||
//internal int ExcCount
|
||||
//{
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// get => Exc.Length;
|
||||
//}
|
||||
internal EcsMask(Type worldArchetypeType, int uniqueID, int[] inc, int[] exc)
|
||||
{
|
||||
WorldArchetypeType = worldArchetypeType;
|
||||
@ -357,43 +333,43 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
static Activator()
|
||||
{
|
||||
// var inc_ = new TInc().GetComponentsIDs<TWorldArchetype>();
|
||||
// var exc_ = new TExc().GetComponentsIDs<TWorldArchetype>();
|
||||
// Array.Sort(inc_);
|
||||
// Array.Sort(exc_);
|
||||
//
|
||||
// Type thisType = typeof(Activator<TInc, TExc>);
|
||||
//
|
||||
// Type sortedIncType = typeof(TInc);
|
||||
// if (sortedIncType.IsGenericType)
|
||||
// {
|
||||
// Type[] sortedInc = new Type[inc_.Length];
|
||||
// for (int i = 0; i < sortedInc.Length; i++)
|
||||
// sortedInc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[inc_[i]];
|
||||
// sortedIncType = sortedIncType.GetGenericTypeDefinition().MakeGenericType(sortedInc);
|
||||
// }
|
||||
// Type sortedExcType = typeof(TExc);
|
||||
// if (sortedExcType.IsGenericType)
|
||||
// {
|
||||
// Type[] sortedExc = new Type[exc_.Length];
|
||||
// for (int i = 0; i < sortedExc.Length; i++)
|
||||
// sortedExc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[exc_[i]];
|
||||
// sortedExcType = sortedExcType.GetGenericTypeDefinition().MakeGenericType(sortedExc);
|
||||
// }
|
||||
//
|
||||
// Type targetType = typeof(Activator<,>).MakeGenericType(typeof(TWorldArchetype), sortedIncType, sortedExcType);
|
||||
//
|
||||
// if (targetType != thisType)
|
||||
// {
|
||||
// instance = (EcsMask)targetType.GetField(nameof(instance), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// var uniqueID = _count++;
|
||||
// if (_count >= _capacity)
|
||||
// _capacity <<= 1;
|
||||
//
|
||||
// instance = new EcsMask(typeof(TWorldArchetype), uniqueID, inc_, exc_);
|
||||
var inc_ = new TInc().GetComponentsIDs<TWorldArchetype>();
|
||||
var exc_ = new TExc().GetComponentsIDs<TWorldArchetype>();
|
||||
Array.Sort(inc_);
|
||||
Array.Sort(exc_);
|
||||
|
||||
Type thisType = typeof(Activator<TInc, TExc>);
|
||||
|
||||
Type sortedIncType = typeof(TInc);
|
||||
if (sortedIncType.IsGenericType)
|
||||
{
|
||||
Type[] sortedInc = new Type[inc_.Length];
|
||||
for (int i = 0; i < sortedInc.Length; i++)
|
||||
sortedInc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[inc_[i]];
|
||||
sortedIncType = sortedIncType.GetGenericTypeDefinition().MakeGenericType(sortedInc);
|
||||
}
|
||||
Type sortedExcType = typeof(TExc);
|
||||
if (sortedExcType.IsGenericType)
|
||||
{
|
||||
Type[] sortedExc = new Type[exc_.Length];
|
||||
for (int i = 0; i < sortedExc.Length; i++)
|
||||
sortedExc[i] = EcsWorld<TWorldArchetype>.ComponentType.types[exc_[i]];
|
||||
sortedExcType = sortedExcType.GetGenericTypeDefinition().MakeGenericType(sortedExc);
|
||||
}
|
||||
|
||||
Type targetType = typeof(Activator<,>).MakeGenericType(typeof(TWorldArchetype), sortedIncType, sortedExcType);
|
||||
|
||||
if (targetType != thisType)
|
||||
{
|
||||
instance = (EcsMask)targetType.GetField(nameof(instance), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
var uniqueID = _count++;
|
||||
if (_count >= _capacity)
|
||||
_capacity <<= 1;
|
||||
|
||||
instance = new EcsMask(typeof(TWorldArchetype), uniqueID, inc_, exc_);
|
||||
}
|
||||
|
||||
public readonly static EcsMask instance;
|
||||
|
@ -8,7 +8,6 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
#region Properties
|
||||
public Type ComponentType { get; }
|
||||
public int ComponentID { get; }
|
||||
public IEcsWorld World { get; }
|
||||
public int Count { get; }
|
||||
public int Capacity { get; }
|
||||
@ -19,6 +18,9 @@ namespace DCFApixels.DragonECS
|
||||
public void Write(int entityID);
|
||||
public bool Has(int entityID);
|
||||
public void Del(int entityID);
|
||||
#endregion
|
||||
|
||||
#region Internal
|
||||
internal void OnWorldResize(int newSize);
|
||||
#endregion
|
||||
}
|
||||
@ -30,7 +32,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
|
||||
public struct NullComponent { }
|
||||
public sealed class EcsNullPool : EcsPool, IEcsPool<NullComponent>
|
||||
public sealed class EcsNullPool : IEcsPool<NullComponent>
|
||||
{
|
||||
public static EcsNullPool instance => new EcsNullPool(null);
|
||||
private IEcsWorld _source;
|
||||
@ -47,25 +49,24 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#region Methods
|
||||
public ref NullComponent Add(int entity) => ref fakeComponent;
|
||||
public override bool Has(int index) => false;
|
||||
public bool Has(int index) => false;
|
||||
public ref NullComponent Read(int entity) => ref fakeComponent;
|
||||
public ref NullComponent Write(int entity) => ref fakeComponent;
|
||||
public void Del(int index) { }
|
||||
void IEcsPool.Write(int entityID) { }
|
||||
void IEcsPool.Add(int entityID) { }
|
||||
void IEcsPool.OnWorldResize(int newSize) { }
|
||||
internal override void OnWorldResize(int newSize) { }
|
||||
#endregion
|
||||
}
|
||||
public abstract class EcsPool
|
||||
{
|
||||
public abstract bool Has(int entityID);
|
||||
internal abstract void OnWorldResize(int newSize);
|
||||
}
|
||||
public sealed class EcsPool<T> : EcsPool, IEcsPool<T>
|
||||
|
||||
public sealed class EcsPool<T> : IEcsPool<T>
|
||||
where T : struct
|
||||
{
|
||||
private readonly int _componentID;
|
||||
public static EcsPool<T> Builder(IEcsWorld source)
|
||||
{
|
||||
return new EcsPool<T>(source, 512, default);
|
||||
}
|
||||
|
||||
private readonly IEcsWorld _source;
|
||||
|
||||
private int[] _mapping;// index = entityID / value = itemIndex;/ value = 0 = no entityID
|
||||
@ -75,21 +76,19 @@ namespace DCFApixels.DragonECS
|
||||
private int _recycledItemsCount;
|
||||
|
||||
private IEcsComponentReset<T> _componentResetHandler;
|
||||
private PoolRunnres _poolRunnres;
|
||||
private PoolRunners _poolRunners;
|
||||
|
||||
#region Properites
|
||||
public int Count => _itemsCount;
|
||||
public int Capacity => _items.Length;
|
||||
public IEcsWorld World => _source;
|
||||
public Type ComponentType => typeof(T);
|
||||
public int ComponentID => _componentID;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
internal EcsPool(IEcsWorld source, int id, int capacity, PoolRunnres poolRunnres)
|
||||
internal EcsPool(IEcsWorld source, int capacity, PoolRunners poolRunnres)
|
||||
{
|
||||
_source = source;
|
||||
_componentID = id;
|
||||
|
||||
_mapping = new int[source.Capacity];
|
||||
_recycledItems = new int[128];
|
||||
@ -97,8 +96,8 @@ namespace DCFApixels.DragonECS
|
||||
_items = new T[capacity];
|
||||
_itemsCount = 0;
|
||||
|
||||
_componentResetHandler = IEcsComponentReset<T>.Handler;
|
||||
_poolRunnres = poolRunnres;
|
||||
_componentResetHandler = EcsComponentResetHandler<T>.instance;
|
||||
_poolRunners = poolRunnres;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -128,9 +127,9 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
|
||||
_mapping[entityID] = itemIndex;
|
||||
_poolRunnres.add.OnComponentAdd<T>(entityID);
|
||||
_poolRunners.add.OnComponentAdd<T>(entityID);
|
||||
}
|
||||
_poolRunnres.write.OnComponentWrite<T>(entityID);
|
||||
_poolRunners.write.OnComponentWrite<T>(entityID);
|
||||
return ref _items[itemIndex];
|
||||
// }
|
||||
}
|
||||
@ -138,7 +137,7 @@ namespace DCFApixels.DragonECS
|
||||
public ref T Write(int entityID)
|
||||
{
|
||||
// using (_writeMark.Auto())
|
||||
_poolRunnres.write.OnComponentWrite<T>(entityID);
|
||||
_poolRunners.write.OnComponentWrite<T>(entityID);
|
||||
return ref _items[_mapping[entityID]];
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -148,7 +147,7 @@ namespace DCFApixels.DragonECS
|
||||
return ref _items[_mapping[entityID]];
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sealed override bool Has(int entityID)
|
||||
public bool Has(int entityID)
|
||||
{
|
||||
// using (_hasMark.Auto())
|
||||
return _mapping[entityID] > 0;
|
||||
@ -164,7 +163,7 @@ namespace DCFApixels.DragonECS
|
||||
_recycledItems[_recycledItemsCount++] = itemIndex;
|
||||
itemIndex = 0;
|
||||
_itemsCount--;
|
||||
_poolRunnres.del.OnComponentDel<T>(entityID);
|
||||
_poolRunners.del.OnComponentDel<T>(entityID);
|
||||
// }
|
||||
}
|
||||
#endregion
|
||||
@ -180,22 +179,12 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Object
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => _source.GetHashCode() ^ ~ComponentID;
|
||||
#endregion
|
||||
|
||||
#region Internal
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void IEcsPool.OnWorldResize(int newSize)
|
||||
{
|
||||
Array.Resize(ref _mapping, newSize);
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal sealed override void OnWorldResize(int newSize)
|
||||
{
|
||||
Array.Resize(ref _mapping, newSize);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -77,12 +77,20 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
public abstract class EcsHierarchyQuery : EcsQueryBase
|
||||
{
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsHierarchyQuery.Execute");
|
||||
|
||||
public abstract class EcsJoinQuery : EcsQueryBase
|
||||
protected override void OnBuildAfter() { }
|
||||
public override void Execute()
|
||||
{
|
||||
}
|
||||
}
|
||||
public abstract class EcsGraphQuery : EcsQueryBase
|
||||
{
|
||||
private EcsPool<Edge> attachPool;
|
||||
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where");
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsGraphQuery.Execute");
|
||||
protected sealed override void OnBuildAfter()
|
||||
{
|
||||
attachPool = World.GetPool<Edge>();
|
||||
@ -102,7 +110,7 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
public abstract class EcsQuery : EcsQueryBase
|
||||
{
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Where");
|
||||
private ProfilerMarker _getEnumerator = new ProfilerMarker("EcsQuery.Execute");
|
||||
protected sealed override void OnBuildAfter() { }
|
||||
public sealed override void Execute()
|
||||
{
|
||||
|
@ -84,54 +84,54 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
// #region select_readonly
|
||||
// [StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
||||
// public readonly struct inc_readonly_<TComponent> : IEcsQueryReadonlyField<TComponent>
|
||||
// where TComponent : struct
|
||||
// public readonly struct inc_readonly_<T> : IEcsQueryReadonlyField<T>
|
||||
// where T : struct
|
||||
// {
|
||||
// internal readonly EcsPool<TComponent> pool;
|
||||
// internal readonly EcsPool<T> pool;
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// internal inc_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
||||
// internal inc_readonly_(EcsPool<T> pool) => this.pool = pool;
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||
// public ref T Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
//
|
||||
// public static implicit operator inc_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Include<TComponent>();
|
||||
// public static implicit operator inc_readonly_<TComponent>(inc_<TComponent> o) => new inc_readonly_<TComponent>(o.pool);
|
||||
// public static implicit operator inc_readonly_<T>(EcsQueryBuilderBase buider) => buider.Include<T>();
|
||||
// public static implicit operator inc_readonly_<T>(inc_<T> o) => new inc_readonly_<T>(o.pool);
|
||||
// }
|
||||
//
|
||||
// [StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
||||
// public readonly struct exc_readonly_<TComponent> : IEcsQueryReadonlyField<TComponent>
|
||||
// where TComponent : struct
|
||||
// public readonly struct exc_readonly_<T> : IEcsQueryReadonlyField<T>
|
||||
// where T : struct
|
||||
// {
|
||||
// internal readonly EcsPool<TComponent> pool;
|
||||
// internal readonly EcsPool<T> pool;
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// internal exc_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
||||
// internal exc_readonly_(EcsPool<T> pool) => this.pool = pool;
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||
// public ref T Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
//
|
||||
// public static implicit operator exc_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Exclude<TComponent>();
|
||||
// public static implicit operator exc_readonly_<TComponent>(exc_<TComponent> o) => new exc_readonly_<TComponent>(o.pool);
|
||||
// public static implicit operator exc_readonly_<T>(EcsQueryBuilderBase buider) => buider.Exclude<T>();
|
||||
// public static implicit operator exc_readonly_<T>(exc_<T> o) => new exc_readonly_<T>(o.pool);
|
||||
// }
|
||||
//
|
||||
// [StructLayout(LayoutKind.Sequential, Pack = 8, Size = 8)]
|
||||
// public readonly struct opt_readonly_<TComponent> : IEcsQueryReadonlyField<TComponent>
|
||||
// where TComponent : struct
|
||||
// public readonly struct opt_readonly_<T> : IEcsQueryReadonlyField<T>
|
||||
// where T : struct
|
||||
// {
|
||||
// internal readonly EcsPool<TComponent> pool;
|
||||
// internal readonly EcsPool<T> pool;
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// internal opt_readonly_(EcsPool<TComponent> pool) => this.pool = pool;
|
||||
// internal opt_readonly_(EcsPool<T> pool) => this.pool = pool;
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public ref TComponent Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||
// public ref T Read(ent entityID) => ref pool.Read(entityID.uniqueID);
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public bool Has(ent entityID) => pool.Has(entityID.uniqueID);
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
//
|
||||
// public static implicit operator opt_readonly_<TComponent>(EcsQueryBuilderBase buider) => buider.Optional<TComponent>();
|
||||
// public static implicit operator opt_readonly_<TComponent>(opt_<TComponent> o) => new opt_readonly_<TComponent>(o.pool);
|
||||
// public static implicit operator opt_readonly_<T>(EcsQueryBuilderBase buider) => buider.Optional<T>();
|
||||
// public static implicit operator opt_readonly_<T>(opt_<T> o) => new opt_readonly_<T>(o.pool);
|
||||
// }
|
||||
// #endregion
|
||||
//
|
||||
|
105
src/EcsWorld.cs
105
src/EcsWorld.cs
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using static DCFApixels.DragonECS.WorldMetaStorage;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -43,7 +44,7 @@ namespace DCFApixels.DragonECS
|
||||
where TWorldArchetype : EcsWorld<TWorldArchetype>
|
||||
{
|
||||
private const int DEL_ENT_BUFFER_SIZE_OFFSET = 2;
|
||||
private readonly int _worldArchetypeID = ComponentIndexer.GetWorldId<TWorldArchetype>();
|
||||
private readonly int _worldArchetypeID = WorldMetaStorage.GetWorldId<TWorldArchetype>();
|
||||
|
||||
private IntDispenser _entityDispenser;
|
||||
private int _entitiesCount;
|
||||
@ -52,10 +53,12 @@ namespace DCFApixels.DragonECS
|
||||
//private short[] _componentCounts; //TODO
|
||||
private EcsGroup _allEntites;
|
||||
|
||||
private int[] _delEntBuffer; //буфер удаления нужен для того чтобы запускать некоторые процесыы связанные с удалением сущьности не по одному при каждом удалении, а пачкой
|
||||
//буфер удаления откладывает освобождение андишников сущьностей.
|
||||
//Нужен для того чтобы запускать некоторые процесыы связанные с удалением сущьности не по одному при каждом удалении, а пачкой
|
||||
private int[] _delEntBuffer;
|
||||
private int _delEntBufferCount;
|
||||
|
||||
private EcsPool[] _pools;
|
||||
private IEcsPool[] _pools;
|
||||
private EcsNullPool _nullPool;
|
||||
|
||||
private EcsQueryBase[] _queries;
|
||||
@ -65,13 +68,13 @@ namespace DCFApixels.DragonECS
|
||||
private List<WeakReference<EcsGroup>> _groups;
|
||||
private Stack<EcsGroup> _groupsPool = new Stack<EcsGroup>(64);
|
||||
|
||||
private PoolRunnres _poolRunnres;
|
||||
private PoolRunners _poolRunners;
|
||||
private IEcsEntityCreate _entityCreate;
|
||||
private IEcsEntityDestroy _entityDestry;
|
||||
|
||||
#region GetterMethods
|
||||
public ReadOnlySpan<EcsPool> GetAllPools() => new ReadOnlySpan<EcsPool>(_pools);
|
||||
public int GetComponentID<T>() => ComponentIndexer.GetComponentId<T>(_worldArchetypeID);////ComponentType<T>.uniqueID;
|
||||
public ReadOnlySpan<IEcsPool> GetAllPools() => new ReadOnlySpan<IEcsPool>(_pools);
|
||||
public int GetComponentID<T>() => WorldMetaStorage.GetComponentId<T>(_worldArchetypeID);////ComponentType<T>.uniqueID;
|
||||
|
||||
#endregion
|
||||
|
||||
@ -91,7 +94,7 @@ namespace DCFApixels.DragonECS
|
||||
if (!_pipeline.IsInit) pipline.Init();
|
||||
_entityDispenser = new IntDispenser(0);
|
||||
_nullPool = EcsNullPool.instance;
|
||||
_pools = new EcsPool[512];
|
||||
_pools = new IEcsPool[512];
|
||||
ArrayUtility.Fill(_pools, _nullPool);
|
||||
|
||||
_gens = new short[512];
|
||||
@ -102,9 +105,9 @@ namespace DCFApixels.DragonECS
|
||||
_groups = new List<WeakReference<EcsGroup>>();
|
||||
_allEntites = GetGroupFromPool();
|
||||
|
||||
_queries = new EcsQuery[QueryType.capacity];
|
||||
_queries = new EcsQuery[128];
|
||||
|
||||
_poolRunnres = new PoolRunnres(_pipeline);
|
||||
_poolRunners = new PoolRunners(_pipeline);
|
||||
_entityCreate = _pipeline.GetRunner<IEcsEntityCreate>();
|
||||
_entityDestry = _pipeline.GetRunner<IEcsEntityDestroy>();
|
||||
_pipeline.GetRunner<IEcsInject<TWorldArchetype>>().Inject((TWorldArchetype)this);
|
||||
@ -114,9 +117,10 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region GetPool
|
||||
public EcsPool<T> GetPool<T>() where T : struct
|
||||
public EcsPool<TComponent> GetPool<TComponent>()
|
||||
where TComponent : struct
|
||||
{
|
||||
int uniqueID = ComponentIndexer.GetComponentId<T>(_worldArchetypeID);
|
||||
int uniqueID = WorldMetaStorage.GetComponentId<TComponent>(_worldArchetypeID);
|
||||
|
||||
if (uniqueID >= _pools.Length)
|
||||
{
|
||||
@ -126,10 +130,9 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
|
||||
if (_pools[uniqueID] == _nullPool)
|
||||
{
|
||||
_pools[uniqueID] = new EcsPool<T>(this, uniqueID, 512, _poolRunnres);
|
||||
}
|
||||
return (EcsPool<T>)_pools[uniqueID];
|
||||
_pools[uniqueID] = new EcsPool<TComponent>(this, 512, _poolRunners);
|
||||
|
||||
return (EcsPool<TComponent>)_pools[uniqueID];
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -142,9 +145,9 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public TQuery Select<TQuery>() where TQuery : EcsQueryBase
|
||||
{
|
||||
int uniqueID = QueryType<TQuery>.uniqueID;
|
||||
if (_queries.Length < QueryType.capacity)
|
||||
Array.Resize(ref _queries, QueryType.capacity);
|
||||
int uniqueID = WorldMetaStorage.GetQueryId<TQuery>(_worldArchetypeID);
|
||||
if (uniqueID >= _queries.Length)
|
||||
Array.Resize(ref _queries, _queries.Length << 1);
|
||||
if (_queries[uniqueID] == null)
|
||||
_queries[uniqueID] = EcsQueryBase.Builder.Build<TQuery>(this);
|
||||
return (TQuery)_queries[uniqueID];
|
||||
@ -274,53 +277,37 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || !DRAGONECS_NO_SANITIZE_CHECKS
|
||||
if (group.World != this)
|
||||
throw new ArgumentException("groupFilter.World != this");
|
||||
throw new ArgumentException("groupFilter.WorldIndex != this");
|
||||
#endif
|
||||
group.Clear();
|
||||
_groupsPool.Push(group);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Utils
|
||||
internal static class QueryType
|
||||
{
|
||||
public static int increment = 0;
|
||||
public static int capacity = 128;
|
||||
}
|
||||
internal static class QueryType<TQuery>
|
||||
{
|
||||
public static int uniqueID;
|
||||
static QueryType()
|
||||
{
|
||||
uniqueID = QueryType.increment++;
|
||||
if (QueryType.increment > QueryType.capacity)
|
||||
QueryType.capacity <<= 1;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Utils
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 24)]
|
||||
internal readonly struct PoolRunnres
|
||||
internal readonly struct PoolRunners
|
||||
{
|
||||
public readonly IEcsComponentAdd add;
|
||||
public readonly IEcsComponentWrite write;
|
||||
public readonly IEcsComponentDel del;
|
||||
|
||||
public PoolRunnres(EcsPipeline pipeline)
|
||||
public PoolRunners(EcsPipeline pipeline)
|
||||
{
|
||||
add = pipeline.GetRunner<IEcsComponentAdd>();
|
||||
write = pipeline.GetRunner<IEcsComponentWrite>();
|
||||
del = pipeline.GetRunner<IEcsComponentDel>();
|
||||
}
|
||||
}
|
||||
public static class ComponentIndexer
|
||||
public static class WorldMetaStorage
|
||||
{
|
||||
private static List<Resizer> resizer = new List<Resizer>();
|
||||
private static int tokenCount = 0;
|
||||
private static int[] componentCounts = new int[0];
|
||||
private static class World<TWorldArchetype>
|
||||
private static int[] queryCounts = new int[0];
|
||||
|
||||
private static class WorldIndex<TWorldArchetype>
|
||||
{
|
||||
public static int id = GetToken();
|
||||
}
|
||||
@ -328,23 +315,30 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
tokenCount++;
|
||||
Array.Resize(ref componentCounts, tokenCount);
|
||||
Array.Resize(ref queryCounts, tokenCount);
|
||||
foreach (var item in resizer)
|
||||
item.Resize(tokenCount);
|
||||
return tokenCount - 1;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int GetWorldId<TWorldArchetype>() => World<TWorldArchetype>.id;
|
||||
public static int GetWorldId<TWorldArchetype>() => WorldIndex<TWorldArchetype>.id;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int GetComponentId<TComponent>(int worldID) => Component<TComponent>.Get(worldID);
|
||||
public static int GetComponentId<T>(int worldID) => Component<T>.Get(worldID);
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int GetQueryId<T>(int worldID) => Query<T>.Get(worldID);
|
||||
private abstract class Resizer
|
||||
{
|
||||
public abstract void Resize(int size);
|
||||
}
|
||||
private sealed class Resizer<T> : Resizer
|
||||
{
|
||||
public override void Resize(int size) => Array.Resize(ref Component<T>.ids, size);
|
||||
public override void Resize(int size)
|
||||
{
|
||||
Array.Resize(ref Component<T>.ids, size);
|
||||
Array.Resize(ref Query<T>.ids, size);
|
||||
}
|
||||
private static class Component<TComponent>
|
||||
}
|
||||
private static class Component<T>
|
||||
{
|
||||
public static int[] ids;
|
||||
static Component()
|
||||
@ -352,7 +346,7 @@ namespace DCFApixels.DragonECS
|
||||
ids = new int[tokenCount];
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
ids[i] = -1;
|
||||
resizer.Add(new Resizer<TComponent>());
|
||||
resizer.Add(new Resizer<T>());
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Get(int token)
|
||||
@ -363,6 +357,25 @@ namespace DCFApixels.DragonECS
|
||||
return id;
|
||||
}
|
||||
}
|
||||
private static class Query<T>
|
||||
{
|
||||
public static int[] ids;
|
||||
static Query()
|
||||
{
|
||||
ids = new int[tokenCount];
|
||||
for (int i = 0; i < ids.Length; i++)
|
||||
ids[i] = -1;
|
||||
resizer.Add(new Resizer<T>());
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int Get(int token)
|
||||
{
|
||||
ref int id = ref ids[token];
|
||||
if (id < 0)
|
||||
id = queryCounts[token]++;
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -1,34 +1,33 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public interface IEcsComponentReset<T>
|
||||
{
|
||||
public void Reset(ref T component);
|
||||
|
||||
|
||||
private static IEcsComponentReset<T> _handler;
|
||||
public static IEcsComponentReset<T> Handler
|
||||
}
|
||||
public static class EcsComponentResetHandler<T>
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
if(_handler == null)
|
||||
public static readonly IEcsComponentReset<T> instance;
|
||||
public static readonly bool isHasHandler;
|
||||
static EcsComponentResetHandler()
|
||||
{
|
||||
Type targetType = typeof(T);
|
||||
if (targetType.GetInterfaces().Contains(typeof(IEcsComponentReset<>).MakeGenericType(targetType)))
|
||||
_handler = (IEcsComponentReset<T>)Activator.CreateInstance(typeof(ComponentResetHandler<>).MakeGenericType(targetType));
|
||||
{
|
||||
instance = (IEcsComponentReset<T>)Activator.CreateInstance(typeof(ComponentResetHandler<>).MakeGenericType(targetType));
|
||||
isHasHandler = true;
|
||||
}
|
||||
else
|
||||
_handler = new ComponentResetDummy<T>();
|
||||
}
|
||||
return _handler;
|
||||
{
|
||||
instance = new ComponentResetDummyHandler<T>();
|
||||
isHasHandler = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ComponentResetDummy<T> : IEcsComponentReset<T>
|
||||
internal sealed class ComponentResetDummyHandler<T> : IEcsComponentReset<T>
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Reset(ref T component) => component = default;
|
||||
|
@ -16,7 +16,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Methods
|
||||
public int GetComponentID<T>();
|
||||
public EcsPool<T> GetPool<T>() where T : struct;
|
||||
public ReadOnlySpan<EcsPool> GetAllPools();
|
||||
public ReadOnlySpan<IEcsPool> GetAllPools();
|
||||
public TQuery Where<TQuery>(out TQuery query) where TQuery : EcsQueryBase;
|
||||
public TQuery Select<TQuery>() where TQuery : EcsQueryBase;
|
||||
|
||||
|
103
src/TestPool.cs
103
src/TestPool.cs
@ -12,6 +12,11 @@ namespace DCFApixels.DragonECS.Test
|
||||
{
|
||||
return new PoolToken(1);
|
||||
}
|
||||
|
||||
public IEcsPool GetPoolX()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct PoolToken
|
||||
@ -33,4 +38,102 @@ namespace DCFApixels.DragonECS.Test
|
||||
_token = world.RegisterPool<TComponent>();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPool { }
|
||||
public class Pool1<TComponent> : IEcsPool<TComponent>
|
||||
where TComponent : struct
|
||||
{
|
||||
public Type ComponentType => throw new NotImplementedException();
|
||||
|
||||
public IEcsWorld World => throw new NotImplementedException();
|
||||
|
||||
public int Count => throw new NotImplementedException();
|
||||
|
||||
public int Capacity => throw new NotImplementedException();
|
||||
|
||||
public ref TComponent Add(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Del(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Has(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ref TComponent Read(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ref TComponent Write(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IEcsPool.Add(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IEcsPool.OnWorldResize(int newSize)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
void IEcsPool.Write(int entityID)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IComponentPool<TPool, TComponent>
|
||||
where TPool : IEcsPool<TComponent>
|
||||
where TComponent : struct
|
||||
{ }
|
||||
|
||||
public interface IComponent1<TComponent> : IComponentPool<Pool1<TComponent>, TComponent>
|
||||
where TComponent : struct
|
||||
{ }
|
||||
public interface IComponent2<TComponent> : IComponentPool<EcsPool<TComponent>, TComponent>
|
||||
where TComponent : struct
|
||||
{ }
|
||||
|
||||
public struct ComponentX1 : IComponent1<ComponentX1> { }
|
||||
public struct ComponentX2 : IComponent2<ComponentX2> { }
|
||||
|
||||
public static class Pool1Ext
|
||||
{
|
||||
public static Pool1<TComponent> GetPool<TComponent>(this TestWorld self)
|
||||
where TComponent : struct, IComponent1<TComponent>
|
||||
{
|
||||
return (Pool1<TComponent>)self.GetPoolX();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Pool2Ext
|
||||
{
|
||||
public static EcsPool<TComponent> GetPool<TComponent>(this TestWorld self)
|
||||
where TComponent : struct, IComponent2<TComponent>
|
||||
{
|
||||
return (EcsPool<TComponent>)self.GetPoolX();
|
||||
}
|
||||
}
|
||||
|
||||
public class Foo
|
||||
{
|
||||
private TestWorld world;
|
||||
public void Do()
|
||||
{
|
||||
var poola = world.GetPool<ComponentX1>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user