Merge branch 'dev'

This commit is contained in:
Mikhail 2023-05-30 00:14:08 +08:00
commit f282e1344e
5 changed files with 56 additions and 29 deletions

23
package.json Normal file
View 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"
]
}

View File

@ -27,8 +27,7 @@ namespace DCFApixels.DragonECS
}
}
[DebugHide, DebugColor(DebugColor.Grey)]
public class DeleteOneFrameComponentSystem<TWorld, TComponent> : IEcsRunProcess, IEcsInject<TWorld>
where TWorld : EcsWorld<TWorld>
public class DeleteOneFrameComponentSystem<TComponent> : IEcsRunProcess, IEcsPreInject
where TComponent : struct, IEcsComponent
{
private sealed class Subject : EcsSubject
@ -36,32 +35,35 @@ namespace DCFApixels.DragonECS
public EcsPool<TComponent> pool;
public Subject(Builder b) => pool = b.Include<TComponent>();
}
private TWorld _world;
public void Inject(TWorld obj) => _world = obj;
List<EcsWorld> _worlds = new List<EcsWorld>();
public void PreInject(object obj)
{
if (obj is EcsWorld world)
_worlds.Add(world);
}
public void Run(EcsPipeline pipeline)
{
foreach (var e in _world.Where(out Subject s))
s.pool.Del(e);
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);
}
}
}
}
}
public static class DeleteOneFrameComponentSystemExtensions
{
private const string AUTO_DEL_LAYER = nameof(AUTO_DEL_LAYER);
public static EcsPipeline.Builder AutoDel<TWorld, TComponent>(this EcsPipeline.Builder b)
where TWorld : EcsWorld<TWorld>
public static EcsPipeline.Builder AutoDel<TComponent>(this EcsPipeline.Builder b, string layerName = AUTO_DEL_LAYER)
where TComponent : struct, IEcsComponent
{
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
b.AddUnique(new DeleteOneFrameComponentSystem<TWorld, TComponent>(), AUTO_DEL_LAYER);
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);
if(AUTO_DEL_LAYER == layerName)
b.Layers.Insert(EcsConsts.POST_END_LAYER, AUTO_DEL_LAYER);
b.AddUnique(new DeleteOneFrameComponentSystem<TComponent>(), layerName);
return b;
}
}

View File

@ -189,7 +189,7 @@ namespace DCFApixels.DragonECS
List<IEcsSystem> basicBlockList = _systems[_basicLayer];
foreach (var item in _systems)
{
if (!Layers.Has(item.Key))
if (!Layers.Contains(item.Key))
basicBlockList.AddRange(item.Value);
}
foreach (var item in Layers)
@ -217,7 +217,7 @@ namespace DCFApixels.DragonECS
public Builder Add(string newLayer) => Insert(ADD_LAYER, newLayer);
public Builder Insert(string targetLayer, string newLayer)
{
if (Has(newLayer)) return _source;
if (Contains(newLayer)) return _source;
int index = _layers.IndexOf(targetLayer);
if (index < 0)
@ -227,7 +227,7 @@ namespace DCFApixels.DragonECS
}
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
targetLayer = ADD_LAYER;
@ -262,7 +262,7 @@ namespace DCFApixels.DragonECS
int index = _layers.IndexOf(targetLayer);
if (index < 0)
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;
}
public Builder InsertAfter(string targetLayer, params string[] newLayers)
@ -275,9 +275,9 @@ namespace DCFApixels.DragonECS
targetLayer = ADD_LAYER;
if (++index >= _layers.Count)
_layers.AddRange(newLayers.Where(o => !Has(o)));
_layers.AddRange(newLayers.Where(o => !Contains(o)));
else
_layers.InsertRange(index, newLayers.Where(o => !Has(o)));
_layers.InsertRange(index, newLayers.Where(o => !Contains(o)));
return _source;
}
public Builder Move(string targetLayer, params string[] movingLayers)
@ -296,7 +296,7 @@ namespace DCFApixels.DragonECS
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();
IEnumerator<string> IEnumerable<string>.GetEnumerator() => _layers.GetEnumerator();

View File

@ -82,7 +82,7 @@ namespace DCFApixels.DragonECS
{
return _world.GetPool<TComponent, TPool>();
}
public void IncludeImplicit<TComponent>()
private void IncludeImplicit<TComponent>()
{
int id = _world.GetComponentID<TComponent>();
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS
@ -90,7 +90,7 @@ namespace DCFApixels.DragonECS
#endif
_inc.Add(_world.GetComponentID<TComponent>());
}
public void ExcludeImplicit<TComponent>()
private void ExcludeImplicit<TComponent>()
{
int id = _world.GetComponentID<TComponent>();
#if (DEBUG && !DISABLE_DEBUG) || !DISABLE_DRAGONECS_ASSERT_CHEKS

View File

@ -108,7 +108,8 @@ namespace DCFApixels.DragonECS
#endregion
#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
@ -380,7 +381,7 @@ namespace DCFApixels.DragonECS
}
#region WorldMetaStorage
public static class WorldMetaStorage
internal static class WorldMetaStorage
{
private static List<Resizer> _resizer = new List<Resizer>();
private static int _tokenCount = 0;
@ -421,6 +422,7 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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 Type GetComponentType(int worldID, int componentID) => _metas[worldID].GetComponentType(componentID);