mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 18:14:37 +08:00
Update WIP
This commit is contained in:
parent
796a555cbc
commit
d64d4407c9
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: f88c761abb374574fba2ac5aa2d5e41a
|
guid: 0404e70f4ccc54a41b3da9268ff287ad
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
228
src/EcsFilter.cs
228
src/EcsFilter.cs
@ -19,7 +19,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID
|
ComponentType<T0>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,8 +29,8 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID
|
ComponentType<T1>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,9 +40,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID
|
ComponentType<T2>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -52,10 +52,10 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID
|
ComponentType<T3>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,11 +65,11 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID
|
ComponentType<T4>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,12 +79,12 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID
|
ComponentType<T5>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,13 +94,13 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID
|
ComponentType<T6>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,14 +110,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID,
|
ComponentType<T6>.globalID,
|
||||||
ComponentType<T7>.uniqueID
|
ComponentType<T7>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,15 +127,15 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID,
|
ComponentType<T6>.globalID,
|
||||||
ComponentType<T7>.uniqueID,
|
ComponentType<T7>.globalID,
|
||||||
ComponentType<T8>.uniqueID
|
ComponentType<T8>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -145,16 +145,16 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID,
|
ComponentType<T6>.globalID,
|
||||||
ComponentType<T7>.uniqueID,
|
ComponentType<T7>.globalID,
|
||||||
ComponentType<T8>.uniqueID,
|
ComponentType<T8>.globalID,
|
||||||
ComponentType<T9>.uniqueID
|
ComponentType<T9>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -164,17 +164,17 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID,
|
ComponentType<T6>.globalID,
|
||||||
ComponentType<T7>.uniqueID,
|
ComponentType<T7>.globalID,
|
||||||
ComponentType<T8>.uniqueID,
|
ComponentType<T8>.globalID,
|
||||||
ComponentType<T9>.uniqueID,
|
ComponentType<T9>.globalID,
|
||||||
ComponentType<T10>.uniqueID
|
ComponentType<T10>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,18 +184,18 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID,
|
ComponentType<T6>.globalID,
|
||||||
ComponentType<T7>.uniqueID,
|
ComponentType<T7>.globalID,
|
||||||
ComponentType<T8>.uniqueID,
|
ComponentType<T8>.globalID,
|
||||||
ComponentType<T9>.uniqueID,
|
ComponentType<T9>.globalID,
|
||||||
ComponentType<T10>.uniqueID,
|
ComponentType<T10>.globalID,
|
||||||
ComponentType<T11>.uniqueID
|
ComponentType<T11>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID
|
ComponentType<T0>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,8 +220,8 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID
|
ComponentType<T1>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -231,9 +231,9 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID
|
ComponentType<T2>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,10 +243,10 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID
|
ComponentType<T3>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -256,11 +256,11 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID
|
ComponentType<T4>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,12 +270,12 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID
|
ComponentType<T5>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,13 +285,13 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID
|
ComponentType<T6>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -301,14 +301,14 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return new int[]
|
return new int[]
|
||||||
{
|
{
|
||||||
ComponentType<T0>.uniqueID,
|
ComponentType<T0>.globalID,
|
||||||
ComponentType<T1>.uniqueID,
|
ComponentType<T1>.globalID,
|
||||||
ComponentType<T2>.uniqueID,
|
ComponentType<T2>.globalID,
|
||||||
ComponentType<T3>.uniqueID,
|
ComponentType<T3>.globalID,
|
||||||
ComponentType<T4>.uniqueID,
|
ComponentType<T4>.globalID,
|
||||||
ComponentType<T5>.uniqueID,
|
ComponentType<T5>.globalID,
|
||||||
ComponentType<T6>.uniqueID,
|
ComponentType<T6>.globalID,
|
||||||
ComponentType<T7>.uniqueID
|
ComponentType<T7>.globalID
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsWorld World { get; }
|
public EcsWorld World { get; }
|
||||||
public int ID { get; }
|
public int ID { get; }
|
||||||
public bool Has(int index);
|
public bool Has(int index);
|
||||||
public void Add(int index);
|
public void Write(int index);
|
||||||
public void Del(int index);
|
public void Del(int index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,34 +48,35 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public ref T Write(int index)
|
public ref T Write(int index)
|
||||||
|
{
|
||||||
|
if (_sparseSet.Contains(index))
|
||||||
{
|
{
|
||||||
return ref _denseItems[_sparseSet[index]];
|
return ref _denseItems[_sparseSet[index]];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public ref T Add(int index)
|
|
||||||
{
|
{
|
||||||
_sparseSet.Add(index);
|
_sparseSet.Add(index);
|
||||||
_sparseSet.Normalize(ref _denseItems);
|
_sparseSet.Normalize(ref _denseItems);
|
||||||
return ref _denseItems[_sparseSet.IndexOf(index)];
|
return ref _denseItems[_sparseSet.IndexOf(index)];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(int index)
|
public bool Has(int index)
|
||||||
{
|
{
|
||||||
return _sparseSet.Contains(index);
|
return _sparseSet.IndexOf(index) > 0;
|
||||||
}
|
}
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Del(int index)
|
public void Del(int index)
|
||||||
{
|
{
|
||||||
_sparseSet.Remove(index);
|
_sparseSet.RemoveAt(index);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEcsFieldPool
|
#region IEcsFieldPool
|
||||||
void IEcsPool.Add(int index)
|
void IEcsPool.Write(int index)
|
||||||
{
|
{
|
||||||
Add(index);
|
Write(index);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -87,4 +88,28 @@ namespace DCFApixels.DragonECS
|
|||||||
public override int GetHashCode() => _source.GetHashCode() + ID;
|
public override int GetHashCode() => _source.GetHashCode() + ID;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static partial class EntityExtensions
|
||||||
|
{
|
||||||
|
public static ref readonly T Read<T>(this in Entity self)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
return ref self.world.GetPool<T>().Read(self.id);
|
||||||
|
}
|
||||||
|
public static ref T Write<T>(this in Entity self)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
return ref self.world.GetPool<T>().Write(self.id);
|
||||||
|
}
|
||||||
|
public static bool Has<T>(this in Entity self)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
return self.world.GetPool<T>().Has(self.id);
|
||||||
|
}
|
||||||
|
public static void Del<T>(this in Entity self)
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
self.world.GetPool<T>().Del(self.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,9 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public class EcsSession
|
public class EcsSession
|
||||||
{
|
{
|
||||||
|
private int _id;
|
||||||
|
|
||||||
|
|
||||||
private List<IEcsProcessor> _allProcessors;
|
private List<IEcsProcessor> _allProcessors;
|
||||||
private ReadOnlyCollection<IEcsProcessor> _allProcessorsSealed;
|
private ReadOnlyCollection<IEcsProcessor> _allProcessorsSealed;
|
||||||
|
|
||||||
@ -151,5 +154,9 @@ namespace DCFApixels.DragonECS
|
|||||||
// return new ent(target.id, target.world._gens[target.id], -1000);
|
// return new ent(target.id, target.world._gens[target.id], -1000);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public class EcsWorldMap
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
public class EcsWorld
|
public class EcsWorld
|
||||||
{
|
{
|
||||||
public const int MAX_WORLDS = byte.MaxValue; //Номер последнего мира 254
|
public const int MAX_WORLDS = byte.MaxValue; //Номер последнего мира 254
|
||||||
@ -14,7 +19,7 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private byte _id = DEAD_WORLD_ID;
|
private byte _id = DEAD_WORLD_ID;
|
||||||
|
|
||||||
private float _timeScale;//TODO реализовать собсвенныйтайм склей для разных миров
|
//private float _timeScale;//TODO реализовать собсвенныйтайм склей для разных миров
|
||||||
|
|
||||||
private IEcsPool[] _pools;
|
private IEcsPool[] _pools;
|
||||||
private SparseSet _componentIDToPoolID;
|
private SparseSet _componentIDToPoolID;
|
||||||
@ -45,27 +50,11 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Filters
|
#region Pools
|
||||||
public EcsFilter GetFilter<TMask>(TMask mask) where TMask : Mask
|
|
||||||
{
|
|
||||||
if (_maskIDToFilterID.TryAdd(mask.ID, ref _filters))
|
|
||||||
{
|
|
||||||
EcsFilter filter = new EcsFilter(this, mask, 512);
|
|
||||||
_filters[_maskIDToFilterID.IndexOf(mask.ID)] = filter;
|
|
||||||
return filter;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return _filters[_maskIDToFilterID.IndexOf(mask.ID)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GetPool
|
|
||||||
public EcsPool<T> GetPool<T>()
|
public EcsPool<T> GetPool<T>()
|
||||||
where T : struct
|
where T : struct
|
||||||
{
|
{
|
||||||
int uniqueID = ComponentType<T>.uniqueID;
|
int uniqueID = ComponentType<T>.globalID;
|
||||||
int poolIndex = _componentIDToPoolID.IndexOf(uniqueID);
|
int poolIndex = _componentIDToPoolID.IndexOf(uniqueID);
|
||||||
if (poolIndex >= 0)
|
if (poolIndex >= 0)
|
||||||
{
|
{
|
||||||
@ -88,6 +77,22 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Filters
|
||||||
|
public EcsFilter GetFilter<TMask>(TMask mask) where TMask : Mask
|
||||||
|
{
|
||||||
|
if (_maskIDToFilterID.TryAdd(mask.ID, ref _filters))
|
||||||
|
{
|
||||||
|
EcsFilter filter = new EcsFilter(this, mask, 512);
|
||||||
|
_filters[_maskIDToFilterID.IndexOf(mask.ID)] = filter;
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _filters[_maskIDToFilterID.IndexOf(mask.ID)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region NewEntity
|
#region NewEntity
|
||||||
public ent NewEntity()
|
public ent NewEntity()
|
||||||
{
|
{
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public class EcsWorldMap
|
|
||||||
{
|
|
||||||
private EcsWorld[] _worlds = new EcsWorld[8];
|
|
||||||
private SparseSet _sparceSet = new SparseSet(8);
|
|
||||||
|
|
||||||
public EcsWorld this[int index]
|
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => _worlds[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void InsertWorld(EcsWorld world)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void RemoveWorld(EcsWorld world)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: c53ca292f39cf9d48a0bb60a65fc1232
|
guid: b4766bca23373eb4cb95ecae89f45c3f
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
11
src/Exceptions/Exceptions.cs.meta
Normal file
11
src/Exceptions/Exceptions.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f04087406e09f6042a341cf8fc41fabf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
11
src/Interfaces/IEcsComponentReset.cs.meta
Normal file
11
src/Interfaces/IEcsComponentReset.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8e4f5b9d0612fde4997b44362501d498
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -110,11 +110,6 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return self == ent.NULL;
|
return self == ent.NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entity UseIn(in ent self, EcsSession session)
|
|
||||||
{
|
|
||||||
session.GetWorld()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ref struct Entity
|
public ref struct Entity
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
internal abstract class ComponentType
|
|
||||||
{
|
|
||||||
protected static int _increment = 0;
|
|
||||||
}
|
|
||||||
internal sealed class ComponentType<T> : ComponentType
|
|
||||||
{
|
|
||||||
internal static int uniqueID = _increment++;
|
|
||||||
}
|
|
||||||
}
|
|
98
src/Utils/ComponentTypeMap.cs
Normal file
98
src/Utils/ComponentTypeMap.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
internal abstract class ComponentType
|
||||||
|
{
|
||||||
|
internal static int increment = 1;
|
||||||
|
internal static int capacity = 512;
|
||||||
|
}
|
||||||
|
internal sealed class ComponentType<T> : ComponentType
|
||||||
|
{
|
||||||
|
internal static int globalID;
|
||||||
|
|
||||||
|
static ComponentType()
|
||||||
|
{
|
||||||
|
globalID = increment++;
|
||||||
|
if (increment > capacity)
|
||||||
|
{
|
||||||
|
capacity <<= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ComponentTypeMap
|
||||||
|
{
|
||||||
|
private int[] _dense;
|
||||||
|
private int[] _sparse;
|
||||||
|
|
||||||
|
private int _count;
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
public int Count
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _count;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constrcutors
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public ComponentTypeMap(int denseCapacity = 64)
|
||||||
|
{
|
||||||
|
_dense = new int[denseCapacity];
|
||||||
|
_sparse = new int[ComponentType.capacity];
|
||||||
|
|
||||||
|
_count = 0;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Contains
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool Contains<T>() => Contains(ComponentType<T>.globalID);
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
private bool Contains(int globalID)
|
||||||
|
{
|
||||||
|
return globalID > 0 && globalID < _sparse.Length && _sparse[globalID] > 0;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetID
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public int GetID<T>()
|
||||||
|
{
|
||||||
|
int globalID = ComponentType<T>.globalID;
|
||||||
|
|
||||||
|
if (!Contains(globalID))
|
||||||
|
{
|
||||||
|
Add(globalID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _dense[globalID];
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Add
|
||||||
|
private void Add(int entityID)
|
||||||
|
{
|
||||||
|
if (Contains(entityID))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (++_count >= _dense.Length)
|
||||||
|
Array.Resize(ref _dense, _dense.Length << 1);
|
||||||
|
|
||||||
|
if (entityID > _sparse.Length)
|
||||||
|
{
|
||||||
|
int neadedSpace = _sparse.Length;
|
||||||
|
while (entityID >= neadedSpace)
|
||||||
|
neadedSpace <<= 1;
|
||||||
|
Array.Resize(ref _sparse, neadedSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
_dense[_count] = entityID;
|
||||||
|
_sparse[entityID] = _count;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -1,64 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public class CompressedBitMask
|
|
||||||
{
|
|
||||||
private const int CHUNK = 32; //int bits
|
|
||||||
|
|
||||||
private int[] _fullChunkIndexes; // индексы чанков с полным заполнением
|
|
||||||
private int[] _sparseIndexes;
|
|
||||||
private int[] _denseMasks;
|
|
||||||
|
|
||||||
private int _highBit = 0;
|
|
||||||
|
|
||||||
public int HightBit => _highBit;
|
|
||||||
|
|
||||||
public void Set(int[] indexes, int count)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public ref struct EqualsRequest
|
|
||||||
{
|
|
||||||
private CompressedBitMask _source;
|
|
||||||
private CompressedBitMask _other;
|
|
||||||
public void GetEnumerator() =>
|
|
||||||
}
|
|
||||||
public ref struct Enumerator
|
|
||||||
{
|
|
||||||
private readonly int[] _indexes;
|
|
||||||
private readonly int[] _masks;
|
|
||||||
private int _index;
|
|
||||||
|
|
||||||
public Enumerator(int[] indexes, int[] masks)
|
|
||||||
|
|
||||||
{
|
|
||||||
_indexes = indexes;
|
|
||||||
_masks = masks;
|
|
||||||
_index = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Current
|
|
||||||
{
|
|
||||||
get => 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() { }
|
|
||||||
|
|
||||||
public bool MoveNext()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
_index = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
11
test/SharedData.cs.meta
Normal file
11
test/SharedData.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ea74209e58692b3428f531e27d577cd7
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue
Block a user