mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-11-14 01:35:54 +08:00
Merge branch 'dev'
This commit is contained in:
commit
f282e1344e
23
package.json
Normal file
23
package.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "com.dcfa_pixels.dragonecs",
|
||||||
|
"author":
|
||||||
|
{
|
||||||
|
"name": "DCFApixels",
|
||||||
|
"url": "https://github.com/DCFApixels"
|
||||||
|
},
|
||||||
|
"displayName": "DragonECS",
|
||||||
|
"description": "C# Entity Component System Framework",
|
||||||
|
"unity": "2020.3",
|
||||||
|
"version": "0.7.0",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/DCFApixels/DragonECS.git"
|
||||||
|
},
|
||||||
|
"keywords":
|
||||||
|
[
|
||||||
|
"ecs",
|
||||||
|
"performance",
|
||||||
|
"dragonecs",
|
||||||
|
"framework"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -27,8 +27,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[DebugHide, DebugColor(DebugColor.Grey)]
|
[DebugHide, DebugColor(DebugColor.Grey)]
|
||||||
public class DeleteOneFrameComponentSystem<TWorld, TComponent> : IEcsRunProcess, IEcsInject<TWorld>
|
public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsPreInject
|
||||||
where TWorld : EcsWorld<TWorld>
|
|
||||||
where TComponent : struct, IEcsComponent
|
where TComponent : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
private sealed class Subject : EcsSubject
|
private sealed class Subject : EcsSubject
|
||||||
@ -36,32 +35,35 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsPool<TComponent> pool;
|
public EcsPool<TComponent> pool;
|
||||||
public Subject(Builder b) => pool = b.Include<TComponent>();
|
public Subject(Builder b) => pool = b.Include<TComponent>();
|
||||||
}
|
}
|
||||||
private TWorld _world;
|
List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||||
public void Inject(TWorld obj) => _world = obj;
|
public void PreInject(object obj)
|
||||||
|
{
|
||||||
|
if (obj is EcsWorld world)
|
||||||
|
_worlds.Add(world);
|
||||||
|
}
|
||||||
public void Run(EcsPipeline pipeline)
|
public void Run(EcsPipeline pipeline)
|
||||||
{
|
{
|
||||||
foreach (var e in _world.Where(out Subject s))
|
for (int i = 0, iMax = _worlds.Count; i < iMax; i++)
|
||||||
|
{
|
||||||
|
EcsWorld world = _worlds[i];
|
||||||
|
if (world.IsComponentTypeDeclared<TComponent>())
|
||||||
|
{
|
||||||
|
foreach (var e in world.Where(out Subject s))
|
||||||
s.pool.Del(e);
|
s.pool.Del(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
public static class DeleteOneFrameComponentSystemExtensions
|
public static class DeleteOneFrameComponentSystemExtensions
|
||||||
{
|
{
|
||||||
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
|
||||||
public static EcsPipeline.Builder AutoDel<TWorld, TComponent>(this EcsPipeline.Builder b)
|
public static EcsPipeline.Builder AutoDel<TComponent>(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER)
|
||||||
where TWorld : EcsWorld<TWorld>
|
|
||||||
where TComponent : struct, IEcsComponent
|
where TComponent : struct, IEcsComponent
|
||||||
{
|
{
|
||||||
|
if(AUTO_DEL_LAYER == layerName)
|
||||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
||||||
b.AddUnique(new DeleteOneFrameComponentSystem<TWorld, TComponent>(), AUTO_DEL_LAYER);
|
b.AddUnique(new DeleteOneFrameComponentSystem<TComponent>(), layerName);
|
||||||
return b;
|
|
||||||
}
|
|
||||||
/// <summary>for EcsDefaultWorld</summary>
|
|
||||||
public static EcsPipeline.Builder AutoDel<TComponent>(this EcsPipeline.Builder b)
|
|
||||||
where TComponent : struct, IEcsComponent
|
|
||||||
{
|
|
||||||
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
|
|
||||||
b.AddUnique(new DeleteOneFrameComponentSystem<EcsDefaultWorld, TComponent>(), AUTO_DEL_LAYER);
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -189,7 +189,7 @@ namespace DCFApixels.DragonECS
|
|||||||
List<IEcsSystem> basicBlockList = _systems[_basicLayer];
|
List<IEcsSystem> basicBlockList = _systems[_basicLayer];
|
||||||
foreach (var item in _systems)
|
foreach (var item in _systems)
|
||||||
{
|
{
|
||||||
if (!Layers.Has(item.Key))
|
if (!Layers.Contains(item.Key))
|
||||||
basicBlockList.AddRange(item.Value);
|
basicBlockList.AddRange(item.Value);
|
||||||
}
|
}
|
||||||
foreach (var item in Layers)
|
foreach (var item in Layers)
|
||||||
@ -217,7 +217,7 @@ namespace DCFApixels.DragonECS
|
|||||||
public Builder Add(string newLayer) => Insert(ADD_LAYER, newLayer);
|
public Builder Add(string newLayer) => Insert(ADD_LAYER, newLayer);
|
||||||
public Builder Insert(string targetLayer, string newLayer)
|
public Builder Insert(string targetLayer, string newLayer)
|
||||||
{
|
{
|
||||||
if (Has(newLayer)) return _source;
|
if (Contains(newLayer)) return _source;
|
||||||
|
|
||||||
int index = _layers.IndexOf(targetLayer);
|
int index = _layers.IndexOf(targetLayer);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
@ -227,7 +227,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public Builder InsertAfter(string targetLayer, string newLayer)
|
public Builder InsertAfter(string targetLayer, string newLayer)
|
||||||
{
|
{
|
||||||
if (Has(newLayer)) return _source;
|
if (Contains(newLayer)) return _source;
|
||||||
|
|
||||||
if (targetLayer == _basicLayerName) // нужно чтобы метод Add работал правильно. _basicLayerName и ADD_LAYER считается одним слоем, поэтому Before = _basicLayerName After = ADD_LAYER
|
if (targetLayer == _basicLayerName) // нужно чтобы метод Add работал правильно. _basicLayerName и ADD_LAYER считается одним слоем, поэтому Before = _basicLayerName After = ADD_LAYER
|
||||||
targetLayer = ADD_LAYER;
|
targetLayer = ADD_LAYER;
|
||||||
@ -262,7 +262,7 @@ namespace DCFApixels.DragonECS
|
|||||||
int index = _layers.IndexOf(targetLayer);
|
int index = _layers.IndexOf(targetLayer);
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
throw new KeyNotFoundException($"Layer {targetLayer} not found");
|
throw new KeyNotFoundException($"Layer {targetLayer} not found");
|
||||||
_layers.InsertRange(index, newLayers.Where(o => !Has(o)));
|
_layers.InsertRange(index, newLayers.Where(o => !Contains(o)));
|
||||||
return _source;
|
return _source;
|
||||||
}
|
}
|
||||||
public Builder InsertAfter(string targetLayer, params string[] newLayers)
|
public Builder InsertAfter(string targetLayer, params string[] newLayers)
|
||||||
@ -275,9 +275,9 @@ namespace DCFApixels.DragonECS
|
|||||||
targetLayer = ADD_LAYER;
|
targetLayer = ADD_LAYER;
|
||||||
|
|
||||||
if (++index >= _layers.Count)
|
if (++index >= _layers.Count)
|
||||||
_layers.AddRange(newLayers.Where(o => !Has(o)));
|
_layers.AddRange(newLayers.Where(o => !Contains(o)));
|
||||||
else
|
else
|
||||||
_layers.InsertRange(index, newLayers.Where(o => !Has(o)));
|
_layers.InsertRange(index, newLayers.Where(o => !Contains(o)));
|
||||||
return _source;
|
return _source;
|
||||||
}
|
}
|
||||||
public Builder Move(string targetLayer, params string[] movingLayers)
|
public Builder Move(string targetLayer, params string[] movingLayers)
|
||||||
@ -296,7 +296,7 @@ namespace DCFApixels.DragonECS
|
|||||||
return InsertAfter(targetLayer, movingLayers);
|
return InsertAfter(targetLayer, movingLayers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Has(string layer) => _layers.Contains(layer);
|
public bool Contains(string layer) => _layers.Contains(layer);
|
||||||
|
|
||||||
public List<string>.Enumerator GetEnumerator() => _layers.GetEnumerator();
|
public List<string>.Enumerator GetEnumerator() => _layers.GetEnumerator();
|
||||||
IEnumerator<string> IEnumerable<string>.GetEnumerator() => _layers.GetEnumerator();
|
IEnumerator<string> IEnumerable<string>.GetEnumerator() => _layers.GetEnumerator();
|
||||||
|
|||||||
@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS
|
|||||||
{
|
{
|
||||||
return _world.GetPool<TComponent, TPool>();
|
return _world.GetPool<TComponent, TPool>();
|
||||||
}
|
}
|
||||||
public void IncludeImplicit<TComponent>()
|
private void IncludeImplicit<TComponent>()
|
||||||
{
|
{
|
||||||
int id = _world.GetComponentID<TComponent>();
|
int id = _world.GetComponentID<TComponent>();
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
@ -90,7 +90,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endif
|
#endif
|
||||||
_inc.Add(_world.GetComponentID<TComponent>());
|
_inc.Add(_world.GetComponentID<TComponent>());
|
||||||
}
|
}
|
||||||
public void ExcludeImplicit<TComponent>()
|
private void ExcludeImplicit<TComponent>()
|
||||||
{
|
{
|
||||||
int id = _world.GetComponentID<TComponent>();
|
int id = _world.GetComponentID<TComponent>();
|
||||||
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
|
||||||
|
|||||||
@ -108,7 +108,8 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetComponentID
|
#region GetComponentID
|
||||||
public int GetComponentID<T>() => WorldMetaStorage.GetComponentId<T>(_worldTypeID);////ComponentType<TWorldArchetype>.uniqueID;
|
public int GetComponentID<T>() => WorldMetaStorage.GetComponentId<T>(_worldTypeID);
|
||||||
|
public bool IsComponentTypeDeclared<T>() => WorldMetaStorage.IsComponentTypeDeclared<T>(_worldTypeID);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -380,7 +381,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region WorldMetaStorage
|
#region WorldMetaStorage
|
||||||
public static class WorldMetaStorage
|
internal static class WorldMetaStorage
|
||||||
{
|
{
|
||||||
private static List<Resizer> _resizer = new List<Resizer>();
|
private static List<Resizer> _resizer = new List<Resizer>();
|
||||||
private static int _tokenCount = 0;
|
private static int _tokenCount = 0;
|
||||||
@ -421,6 +422,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static int GetExecutorId<T>(int worldID) => Executor<T>.Get(worldID);
|
public static int GetExecutorId<T>(int worldID) => Executor<T>.Get(worldID);
|
||||||
|
|
||||||
|
public static bool IsComponentTypeDeclared<TComponent>(int worldID) => IsComponentTypeDeclared(worldID, typeof(TComponent));
|
||||||
public static bool IsComponentTypeDeclared(int worldID, Type type) => _metas[worldID].IsDeclaredType(type);
|
public static bool IsComponentTypeDeclared(int worldID, Type type) => _metas[worldID].IsDeclaredType(type);
|
||||||
public static Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID);
|
public static Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user