mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +08:00
update configs
This commit is contained in:
parent
53911d4f25
commit
ef0f13850f
@ -2,10 +2,12 @@
|
||||
{
|
||||
public sealed class EcsDefaultWorld : EcsWorld
|
||||
{
|
||||
public EcsDefaultWorld(IEcsWorldConfigContainer config = null, short worldID = -1) : base(config, worldID) { }
|
||||
public EcsDefaultWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { }
|
||||
public EcsDefaultWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { }
|
||||
}
|
||||
public sealed class EcsEventWorld : EcsWorld
|
||||
{
|
||||
public EcsEventWorld(IEcsWorldConfigContainer config = null, short worldID = -1) : base(config, worldID) { }
|
||||
public EcsEventWorld(EcsWorldConfig config, short worldID = -1) : base(config, worldID) { }
|
||||
public EcsEventWorld(IConfigContainer configs = null, short worldID = -1) : base(configs, worldID) { }
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 180397e9b3d73d143a3239dd05b2a84b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public interface IEcsPipelineConfigContainer : IConfigContainer { }
|
||||
public interface IEcsPipelineConfigContainerWriter : IConfigContainerWriter
|
||||
{
|
||||
IEcsPipelineConfigContainer GetPipelineConfigs();
|
||||
}
|
||||
[Serializable]
|
||||
public class EcsPipelineConfigContainer : DefaultConfigContainerBase, IEcsPipelineConfigContainerWriter, IEcsPipelineConfigContainer, IEnumerable<object>
|
||||
{
|
||||
public static readonly IEcsPipelineConfigContainer Defaut;
|
||||
static EcsPipelineConfigContainer()
|
||||
{
|
||||
var container = new EcsPipelineConfigContainer();
|
||||
Defaut = container;
|
||||
}
|
||||
public EcsPipelineConfigContainer Set<T>(T value)
|
||||
{
|
||||
SetInternal(value);
|
||||
return this;
|
||||
}
|
||||
public IEcsPipelineConfigContainer GetPipelineConfigs()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3699ffd374c5074ebd5240c20ae5ba5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public class EcsWorldConfig
|
||||
{
|
||||
public readonly int EntitiesCapacity;
|
||||
public readonly int GroupCapacity;
|
||||
public readonly int PoolsCapacity;
|
||||
public readonly int PoolComponentsCapacity;
|
||||
public readonly int PoolRecycledComponentsCapacity;
|
||||
public EcsWorldConfig(int entitiesCapacity = 512, int groupCapacity = 512, int poolsCapacity = 512, int poolComponentsCapacity = 512, int poolRecycledComponentsCapacity = 512 / 2)
|
||||
{
|
||||
EntitiesCapacity = entitiesCapacity;
|
||||
GroupCapacity = groupCapacity;
|
||||
PoolsCapacity = poolsCapacity;
|
||||
PoolComponentsCapacity = poolComponentsCapacity;
|
||||
PoolRecycledComponentsCapacity = poolRecycledComponentsCapacity;
|
||||
}
|
||||
}
|
||||
public interface IEcsWorldConfigContainer : IConfigContainer { }
|
||||
public interface IEcsWorldConfigContainerWriter : IConfigContainerWriter
|
||||
{
|
||||
IEcsWorldConfigContainer GetWorldConfigs();
|
||||
}
|
||||
[Serializable]
|
||||
public class EcsWorldConfigContainer : DefaultConfigContainerBase, IEcsWorldConfigContainerWriter, IEcsWorldConfigContainer, IEnumerable<object>
|
||||
{
|
||||
public static readonly IEcsWorldConfigContainer Defaut;
|
||||
static EcsWorldConfigContainer()
|
||||
{
|
||||
var container = new EcsWorldConfigContainer();
|
||||
container.Set(new EcsWorldConfig());
|
||||
Defaut = container;
|
||||
}
|
||||
public EcsWorldConfigContainer Set<T>(T value)
|
||||
{
|
||||
SetInternal(value);
|
||||
return this;
|
||||
}
|
||||
public IEcsWorldConfigContainer GetWorldConfigs()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
public static class EcsWorldConfigExtensions
|
||||
{
|
||||
public static T GetOrDefault<T>(this IEcsWorldConfigContainer self, T defaultValue)
|
||||
{
|
||||
if (self.TryGet(out T value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bd5947405343044b9e716c787ad4945
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -14,7 +14,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public sealed class EcsPipeline
|
||||
{
|
||||
private readonly IEcsPipelineConfigContainer _config;
|
||||
private readonly IConfigContainer _configs;
|
||||
private Injector.Builder _injectorBuilder;
|
||||
private Injector _injector;
|
||||
|
||||
@ -31,9 +31,9 @@ namespace DCFApixels.DragonECS
|
||||
#endif
|
||||
|
||||
#region Properties
|
||||
public IEcsPipelineConfigContainer Config
|
||||
public IConfigContainer Configs
|
||||
{
|
||||
get { return _config; }
|
||||
get { return _configs; }
|
||||
}
|
||||
public Injector Injector
|
||||
{
|
||||
@ -58,9 +58,9 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
private EcsPipeline(IEcsPipelineConfigContainer config, Injector.Builder injectorBuilder, IEcsProcess[] systems)
|
||||
private EcsPipeline(IConfigContainer configs, Injector.Builder injectorBuilder, IEcsProcess[] systems)
|
||||
{
|
||||
_config = config;
|
||||
_configs = configs;
|
||||
_allSystems = systems;
|
||||
_injectorBuilder = injectorBuilder;
|
||||
_injectorBuilder.Inject(this);
|
||||
@ -186,7 +186,7 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Builder
|
||||
public static Builder New(IEcsPipelineConfigContainerWriter config = null)
|
||||
public static Builder New(IConfigContainerWriter config = null)
|
||||
{
|
||||
return new Builder(config);
|
||||
}
|
||||
@ -197,28 +197,28 @@ namespace DCFApixels.DragonECS
|
||||
private readonly Dictionary<string, List<IEcsProcess>> _systems;
|
||||
private readonly string _basicLayer;
|
||||
public readonly LayerList Layers;
|
||||
private readonly IEcsPipelineConfigContainerWriter _config;
|
||||
private readonly IConfigContainerWriter _configs;
|
||||
private readonly Injector.Builder _injector;
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
private EcsProfilerMarker _buildBarker = new EcsProfilerMarker("EcsPipeline.Build");
|
||||
#endif
|
||||
private List<InitDeclaredRunner> _initDeclaredRunners = new List<InitDeclaredRunner>(4);
|
||||
|
||||
public IEcsPipelineConfigContainerWriter Config
|
||||
public IConfigContainerWriter Configs
|
||||
{
|
||||
get { return _config; }
|
||||
get { return _configs; }
|
||||
}
|
||||
public Injector.Builder Injector
|
||||
{
|
||||
get { return _injector; }
|
||||
}
|
||||
public Builder(IEcsPipelineConfigContainerWriter config = null)
|
||||
public Builder(IConfigContainerWriter config = null)
|
||||
{
|
||||
#if (DEBUG && !DISABLE_DEBUG) || ENABLE_DRAGONECS_ASSERT_CHEKS
|
||||
_buildBarker.Begin();
|
||||
#endif
|
||||
if (config == null) { config = new EcsPipelineConfigContainer(); }
|
||||
_config = config;
|
||||
if (config == null) { config = ConfigContainer.Empty; }
|
||||
_configs = config;
|
||||
|
||||
_injector = new Injector.Builder(this);
|
||||
_injector.AddNode<object>();
|
||||
@ -293,7 +293,7 @@ namespace DCFApixels.DragonECS
|
||||
if (_systems.TryGetValue(item, out var list))
|
||||
result.AddRange(list);
|
||||
}
|
||||
EcsPipeline pipeline = new EcsPipeline(_config.GetPipelineConfigs(), _injector, result.ToArray());
|
||||
EcsPipeline pipeline = new EcsPipeline(_configs.GetContainer(), _injector, result.ToArray());
|
||||
foreach (var item in _initDeclaredRunners)
|
||||
{
|
||||
item.Declare(pipeline);
|
||||
|
@ -6,10 +6,27 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public class EcsWorldConfig
|
||||
{
|
||||
public static readonly EcsWorldConfig Default = new EcsWorldConfig();
|
||||
public readonly int EntitiesCapacity;
|
||||
public readonly int GroupCapacity;
|
||||
public readonly int PoolsCapacity;
|
||||
public readonly int PoolComponentsCapacity;
|
||||
public readonly int PoolRecycledComponentsCapacity;
|
||||
public EcsWorldConfig(int entitiesCapacity = 512, int groupCapacity = 512, int poolsCapacity = 512, int poolComponentsCapacity = 512, int poolRecycledComponentsCapacity = 512 / 2)
|
||||
{
|
||||
EntitiesCapacity = entitiesCapacity;
|
||||
GroupCapacity = groupCapacity;
|
||||
PoolsCapacity = poolsCapacity;
|
||||
PoolComponentsCapacity = poolComponentsCapacity;
|
||||
PoolRecycledComponentsCapacity = poolRecycledComponentsCapacity;
|
||||
}
|
||||
}
|
||||
public partial class EcsWorld : IEntityStorage
|
||||
{
|
||||
public readonly short id;
|
||||
private IEcsWorldConfigContainer _configs;
|
||||
private IConfigContainer _configs;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
@ -38,7 +55,7 @@ namespace DCFApixels.DragonECS
|
||||
private List<IEcsEntityEventListener> _entityListeners = new List<IEcsEntityEventListener>();
|
||||
|
||||
#region Properties
|
||||
public IEcsWorldConfigContainer Configs
|
||||
public IConfigContainer Configs
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get { return _configs; }
|
||||
@ -95,19 +112,17 @@ namespace DCFApixels.DragonECS
|
||||
#endregion
|
||||
|
||||
#region Constructors/Destroy
|
||||
public EcsWorld(IEcsWorldConfigContainer configs = null, short worldID = -1)
|
||||
public EcsWorld(EcsWorldConfig config, short worldID = -1) : this(config == null ? ConfigContainer.Empty : new ConfigContainer().Set(config), worldID) { }
|
||||
public EcsWorld(IConfigContainer configs = null, short worldID = -1)
|
||||
{
|
||||
if (configs == null)
|
||||
{
|
||||
configs = EcsWorldConfigContainer.Defaut;
|
||||
}
|
||||
if (configs == null) { configs = ConfigContainer.Empty; }
|
||||
bool nullWorld = this is NullWorld;
|
||||
if(nullWorld == false && worldID == NULL_WORLD_ID)
|
||||
{
|
||||
EcsDebug.PrintWarning($"The world identifier cannot be {NULL_WORLD_ID}");
|
||||
}
|
||||
_configs = configs;
|
||||
EcsWorldConfig config = configs.Get<EcsWorldConfig>();
|
||||
EcsWorldConfig config = configs.GetWorldConfigOrDefault();
|
||||
|
||||
if (worldID < 0 || (worldID == NULL_WORLD_ID && nullWorld == false))
|
||||
{
|
||||
@ -554,7 +569,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
internal EcsGroup GetFreeGroup()
|
||||
{
|
||||
EcsGroup result = _groupsPool.Count <= 0 ? new EcsGroup(this, _configs.Get<EcsWorldConfig>().GroupCapacity) : _groupsPool.Pop();
|
||||
EcsGroup result = _groupsPool.Count <= 0 ? new EcsGroup(this, _configs.GetWorldConfigOrDefault().GroupCapacity) : _groupsPool.Pop();
|
||||
result._isReleased = false;
|
||||
return result;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
private sealed class NullWorld : EcsWorld
|
||||
{
|
||||
internal NullWorld() : base(EcsWorldConfigContainer.Defaut, 0) { }
|
||||
internal NullWorld() : base(ConfigContainer.Empty, 0) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ namespace DCFApixels.DragonECS
|
||||
_maskBit = EcsMaskChunck.FromID(componentTypeID);
|
||||
|
||||
_mapping = new int[world.Capacity];
|
||||
_items = new T[ArrayUtility.NormalizeSizeToPowerOfTwo(world.Configs.Get<EcsWorldConfig>().PoolComponentsCapacity)];
|
||||
_recycledItems = new int[world.Configs.Get<EcsWorldConfig>().PoolRecycledComponentsCapacity];
|
||||
_items = new T[ArrayUtility.NormalizeSizeToPowerOfTwo(world.Configs.GetWorldConfigOrDefault().PoolComponentsCapacity)];
|
||||
_recycledItems = new int[world.Configs.GetWorldConfigOrDefault().PoolRecycledComponentsCapacity];
|
||||
}
|
||||
void IEcsPoolImplementation.OnWorldResize(int newSize)
|
||||
{
|
||||
|
@ -21,32 +21,23 @@ namespace DCFApixels.DragonECS
|
||||
bool TryGet<T>(out T value);
|
||||
void Remove<T>();
|
||||
IEnumerable<object> GetAllConfigs();
|
||||
IConfigContainer GetContainer();
|
||||
}
|
||||
public static class ConfigContainerExtensions
|
||||
public sealed class ConfigContainer : IConfigContainer, IConfigContainerWriter, IEnumerable<object>
|
||||
{
|
||||
public static T GetOrDefault<T>(this IConfigContainer self, T defaultValue)
|
||||
{
|
||||
if (self.TryGet(out T value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
public static readonly ConfigContainer Empty = new ConfigContainer();
|
||||
|
||||
public class DefaultConfigContainerBase : IConfigContainer, IConfigContainerWriter, IEnumerable<object>
|
||||
{
|
||||
private Dictionary<Type, object> _storage = new Dictionary<Type, object>();
|
||||
|
||||
public DefaultConfigContainerBase() { }
|
||||
public DefaultConfigContainerBase(IEnumerable<object> range)
|
||||
public ConfigContainer() { }
|
||||
public ConfigContainer(IEnumerable<object> range)
|
||||
{
|
||||
foreach (var item in range)
|
||||
{
|
||||
_storage.Add(item.GetType(), item);
|
||||
}
|
||||
}
|
||||
public DefaultConfigContainerBase(params object[] range)
|
||||
public ConfigContainer(params object[] range)
|
||||
{
|
||||
foreach (var item in range)
|
||||
{
|
||||
@ -70,13 +61,14 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
_storage.Remove(typeof(T));
|
||||
}
|
||||
protected void SetInternal<T>(T value)
|
||||
public ConfigContainer Set<T>(T value)
|
||||
{
|
||||
_storage[typeof(T)] = value;
|
||||
return this;
|
||||
}
|
||||
void IConfigContainerWriter.Set<T>(T value)
|
||||
{
|
||||
SetInternal(value);
|
||||
Set(value);
|
||||
}
|
||||
public bool TryGet<T>(out T value)
|
||||
{
|
||||
@ -84,6 +76,10 @@ namespace DCFApixels.DragonECS
|
||||
value = rawValue == null ? default : (T)rawValue;
|
||||
return result;
|
||||
}
|
||||
public IConfigContainer GetContainer()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
public IEnumerable<object> GetAllConfigs()
|
||||
{
|
||||
return _storage.Values;
|
||||
@ -97,14 +93,19 @@ namespace DCFApixels.DragonECS
|
||||
return GetAllConfigs().GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
public static class DefaultConfigContainerBaseExtensions
|
||||
public static class ConfigContainerExtensions
|
||||
{
|
||||
public static TContainer Set<TContainer, T>(this TContainer self, T value)
|
||||
where TContainer : IConfigContainerWriter
|
||||
public static T GetOrDefault<T>(this IConfigContainer self, T defaultValue)
|
||||
{
|
||||
self.Set(value);
|
||||
return self;
|
||||
if (self.TryGet(out T value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
public static EcsWorldConfig GetWorldConfigOrDefault(this IConfigContainer self)
|
||||
{
|
||||
return self.GetOrDefault(EcsWorldConfig.Default);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user