mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-18 09:54:35 +08:00
Update WIP
This commit is contained in:
parent
b97f409671
commit
980ed316e1
@ -1,84 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public class EcsEntityTableManager
|
|
||||||
{
|
|
||||||
private int _count;
|
|
||||||
private IEcsPool[] _fieldPools;
|
|
||||||
|
|
||||||
private int _idIncrement;
|
|
||||||
private Dictionary<IDKey, int> _ids;
|
|
||||||
|
|
||||||
public EcsEntityTableManager(int capacity)
|
|
||||||
{
|
|
||||||
_fieldPools = new IEcsPool[capacity];
|
|
||||||
_ids = new Dictionary<IDKey, int>(capacity);
|
|
||||||
_count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EcsPool<T> GetFieldPool<T>(int id)
|
|
||||||
{
|
|
||||||
if(id < _count)
|
|
||||||
return (EcsPool<T>)_fieldPools[id];
|
|
||||||
|
|
||||||
_count++;
|
|
||||||
if(_fieldPools.Length < _count)
|
|
||||||
{
|
|
||||||
Array.Resize(ref _fieldPools, _fieldPools.Length << 1);
|
|
||||||
}
|
|
||||||
EcsPool<T> newPool = null;// new EcsFieldPool<T>(7);
|
|
||||||
_fieldPools[id] = newPool;
|
|
||||||
return newPool;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ResizeFieldPool(int id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int GetFieldID(string name, int index)
|
|
||||||
{
|
|
||||||
IDKey key = new IDKey(name, index);
|
|
||||||
if (_ids.TryGetValue(key, out int id))
|
|
||||||
return id;
|
|
||||||
|
|
||||||
id = _idIncrement++;
|
|
||||||
_ids.Add(key, id);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
private struct IDKey
|
|
||||||
{
|
|
||||||
public string name;
|
|
||||||
public int index;
|
|
||||||
|
|
||||||
public IDKey(string name, int index)
|
|
||||||
{
|
|
||||||
this.name = name;
|
|
||||||
this.index = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
return obj is IDKey key &&
|
|
||||||
name == key.name &&
|
|
||||||
index == key.index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int GetHashCode()
|
|
||||||
{
|
|
||||||
return HashCode.Combine(name, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
return name + "_" + index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: f568bc9f583414c4188526dfade20358
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -1,22 +1,22 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using DCFApixels.DragonECS.Reflection;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS.Reflection
|
||||||
{
|
|
||||||
namespace Reflection
|
|
||||||
{
|
{
|
||||||
public static class MemberDeclarator
|
public static class MemberDeclarator
|
||||||
{
|
{
|
||||||
private static Dictionary<string, EcsMemberBase> _nameMembersPairs = new Dictionary<string, EcsMemberBase>(1024);
|
private static Dictionary<string, EcsMemberBase> _nameMembersPairs = new Dictionary<string, EcsMemberBase>(1024);
|
||||||
private static EcsMemberBase[] _members = new EcsMemberBase[1024];
|
private static EcsMemberBase[] _members = new EcsMemberBase[1024];
|
||||||
private static int _typesCount = 0;
|
private static int _increment = 1; // 0 индекс всегда пустой, так как он используется в mem<T> для обозначения NULL mem<T>
|
||||||
|
|
||||||
|
public static int MembersCount => _increment - 1;
|
||||||
public static EcsMember<T> Declare<T>(string name)
|
public static EcsMember<T> Declare<T>(string name)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
name = $"{typeof(T).FullName}__{name}";
|
name = $"{typeof(T).FullName}__{name}";
|
||||||
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||||
if (_typesCount < 0)
|
if (_increment < 0)
|
||||||
{
|
{
|
||||||
throw new EcsFrameworkException($"Maximum available members exceeded. The member of \"{name}\" was not declared");
|
throw new EcsFrameworkException($"Maximum available members exceeded. The member of \"{name}\" was not declared");
|
||||||
}
|
}
|
||||||
@ -25,19 +25,20 @@ namespace DCFApixels.DragonECS
|
|||||||
throw new EcsFrameworkException($"The node with the name \"{name}\" has already been declared");
|
throw new EcsFrameworkException($"The node with the name \"{name}\" has already been declared");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (_typesCount >= _members.Length)
|
if (_increment >= _members.Length)
|
||||||
{
|
{
|
||||||
Array.Resize(ref _members, _members.Length << 1);
|
Array.Resize(ref _members, _members.Length << 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
EcsMember<T> member = new EcsMember<T>(name, _typesCount);
|
EcsMember<T> member = new EcsMember<T>(name, _increment);
|
||||||
_nameMembersPairs.Add(name, member);
|
_nameMembersPairs.Add(name, member);
|
||||||
_members[_typesCount++] = member;
|
_members[_increment++] = member;
|
||||||
|
|
||||||
return member;
|
return member;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EcsMember<T> GetOrDeclareMember<T>(string name)
|
public static EcsMember<T> GetOrDeclareMember<T>(string name)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
if (_nameMembersPairs.TryGetValue(name, out EcsMemberBase memberBase))
|
if (_nameMembersPairs.TryGetValue(name, out EcsMemberBase memberBase))
|
||||||
{
|
{
|
||||||
@ -48,6 +49,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static EcsMember<T> GetMemberInfo<T>(mem<T> member)
|
public static EcsMember<T> GetMemberInfo<T>(mem<T> member)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||||
if (member.HasValue == false)
|
if (member.HasValue == false)
|
||||||
@ -56,7 +58,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return (EcsMember<T>)_members[member.UniqueID];
|
return (EcsMember<T>)_members[member.uniqueID];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,6 +109,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
public class EcsMember<T> : EcsMemberBase, IEquatable<EcsMember<T>>
|
public class EcsMember<T> : EcsMemberBase, IEquatable<EcsMember<T>>
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
#region Constructors
|
#region Constructors
|
||||||
private EcsMember() { }
|
private EcsMember() { }
|
||||||
@ -147,5 +150,3 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
@ -4,6 +4,8 @@ using DCFApixels.DragonECS.Reflection;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
@ -12,12 +14,14 @@ namespace DCFApixels.DragonECS
|
|||||||
public EcsWorld World { get; }
|
public EcsWorld World { get; }
|
||||||
public int ID { get; }
|
public int ID { get; }
|
||||||
public EcsMemberBase Type { get; }
|
public EcsMemberBase Type { get; }
|
||||||
|
public bool IsTagsPool { get; }
|
||||||
public bool Has(int index);
|
public bool Has(int index);
|
||||||
public void Add(int index);
|
public void Add(int index);
|
||||||
public void Del(int index);
|
public void Del(int index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EcsPool<T> : IEcsPool
|
public class EcsPool<T> : IEcsPool
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
private int _id;
|
private int _id;
|
||||||
private readonly EcsWorld _source;
|
private readonly EcsWorld _source;
|
||||||
@ -25,25 +29,40 @@ namespace DCFApixels.DragonECS
|
|||||||
private readonly SparseSet _sparseSet;
|
private readonly SparseSet _sparseSet;
|
||||||
private T[] _denseItems;
|
private T[] _denseItems;
|
||||||
|
|
||||||
|
private int _isTagsPoolMask;
|
||||||
|
|
||||||
#region Properites
|
#region Properites
|
||||||
public EcsWorld World => _source;
|
public EcsWorld World => _source;
|
||||||
public int ID => _id;
|
|
||||||
public EcsMemberBase Type => _type;
|
public EcsMemberBase Type => _type;
|
||||||
|
|
||||||
|
public int ID
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _id;
|
||||||
|
}
|
||||||
|
public bool IsTagsPool
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => _isTagsPoolMask < 0;
|
||||||
|
}
|
||||||
|
|
||||||
public ref T this[int index]
|
public ref T this[int index]
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => ref _denseItems[_sparseSet[index]];
|
get => ref _denseItems[_sparseSet[index] | _isTagsPoolMask];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public EcsPool(EcsWorld source, EcsMember<T> type, int capacity)
|
public EcsPool(EcsWorld source, mem<T> type, int capacity)
|
||||||
{
|
{
|
||||||
_source = source;
|
_source = source;
|
||||||
_type = type;
|
_type = MemberDeclarator.GetMemberInfo(type);
|
||||||
_denseItems = new T[capacity];
|
|
||||||
_sparseSet = new SparseSet(capacity);
|
_sparseSet = new SparseSet(capacity);
|
||||||
|
|
||||||
|
_isTagsPoolMask = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Length <= 0 ? -1 : 0;
|
||||||
|
|
||||||
|
_denseItems = IsTagsPool ? new T[1] : new T[capacity];
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -52,9 +71,13 @@ namespace DCFApixels.DragonECS
|
|||||||
public ref T Add(int index)
|
public ref T Add(int index)
|
||||||
{
|
{
|
||||||
_sparseSet.Add(index);
|
_sparseSet.Add(index);
|
||||||
|
if(IsTagsPool)
|
||||||
|
{
|
||||||
_sparseSet.Normalize(ref _denseItems);
|
_sparseSet.Normalize(ref _denseItems);
|
||||||
return ref _denseItems[_sparseSet.IndexOf(index)];
|
return ref _denseItems[_sparseSet.IndexOf(index)];
|
||||||
}
|
}
|
||||||
|
return ref _denseItems[0];
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Has(int index)
|
public bool Has(int index)
|
||||||
@ -65,6 +88,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Del(int index)
|
public void Del(int index)
|
||||||
{
|
{
|
||||||
|
if (!IsTagsPool) { this[index] = default; }
|
||||||
_sparseSet.Remove(index);
|
_sparseSet.Remove(index);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
@ -20,6 +18,8 @@ namespace DCFApixels.DragonECS
|
|||||||
private Dictionary<string, EcsWorld> _worldsDict = new Dictionary<string, EcsWorld>();
|
private Dictionary<string, EcsWorld> _worldsDict = new Dictionary<string, EcsWorld>();
|
||||||
private List<EcsWorld> _worlds = new List<EcsWorld>();
|
private List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Dictionary<Type, IEcsProcessorsRunner> _runners;
|
private Dictionary<Type, IEcsProcessorsRunner> _runners;
|
||||||
private Dictionary<Type, IEcsProcessorsMessenger> _messengers;
|
private Dictionary<Type, IEcsProcessorsMessenger> _messengers;
|
||||||
private EcsProcessorsRunner<_Run> _runRunnerCache;
|
private EcsProcessorsRunner<_Run> _runRunnerCache;
|
||||||
|
@ -14,25 +14,28 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private byte _id = DEAD_WORLD_ID;
|
private byte _id = DEAD_WORLD_ID;
|
||||||
|
|
||||||
private Dictionary<Type, IEcsPool> _pools;
|
private IEcsPool[] _pools;
|
||||||
|
private SparseSet _memToPoolIDSet;
|
||||||
|
|
||||||
|
|
||||||
private SparseSet _entities = new SparseSet();
|
private SparseSet _entities = new SparseSet();
|
||||||
private short[] _gens;
|
private short[] _gens;
|
||||||
|
|
||||||
private List<EcsFilter>[] _filtersByIncludedComponents;
|
private List<EcsFilter>[] _filtersByIncludedComponents;
|
||||||
private List<EcsFilter>[] _filtersByExcludedComponents;
|
private List<EcsFilter>[] _filtersByExcludedComponents;
|
||||||
|
|
||||||
//private Dictionary<Type, IEcsEntityTable> _tables;
|
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public int ID => _id;
|
public int ID => _id;
|
||||||
public bool IsAlive => _id != DEAD_WORLD_ID;
|
public bool IsAlive => _id != DEAD_WORLD_ID;
|
||||||
|
public bool IsEmpty => _entities.Count < 0;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public EcsWorld()
|
public EcsWorld()
|
||||||
{
|
{
|
||||||
_pools = new Dictionary<Type, IEcsPool>();
|
_pools = new IEcsPool[512];
|
||||||
_entities = new SparseSet();
|
_entities = new SparseSet();
|
||||||
|
_memToPoolIDSet = new SparseSet(512);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -45,14 +48,16 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
#region GetPool
|
#region GetPool
|
||||||
public EcsPool<T> GetPool<T>(mem<T> member)
|
public EcsPool<T> GetPool<T>(mem<T> member)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
if(_memToPoolIDSet.Contains(member.uniqueID))
|
||||||
|
|
||||||
if (_pools.TryGetValue(type, out IEcsPool pool))
|
if (_pools.TryGetValue(type, out IEcsPool pool))
|
||||||
{
|
{
|
||||||
return (EcsPool<T>)pool;
|
return (EcsPool<T>)pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
//pool = new EcsPool<T>();
|
pool = new EcsPool<T>(this, member, 512);//TODO сделать чтоб объем можно было указывать через конфиг
|
||||||
_pools.Add(type, pool);
|
_pools.Add(type, pool);
|
||||||
return (EcsPool<T>)pool;
|
return (EcsPool<T>)pool;
|
||||||
}
|
}
|
||||||
@ -92,11 +97,11 @@ namespace DCFApixels.DragonECS
|
|||||||
public class Mask
|
public class Mask
|
||||||
{
|
{
|
||||||
private readonly EcsWorld _world;
|
private readonly EcsWorld _world;
|
||||||
internal int[] Include;
|
internal int[] include;
|
||||||
internal int[] Exclude;
|
internal int[] exclude;
|
||||||
internal int IncludeCount;
|
internal int includeCount;
|
||||||
internal int ExcludeCount;
|
internal int excludeCount;
|
||||||
internal int Hash;
|
internal int hash;
|
||||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||||
bool _built;
|
bool _built;
|
||||||
#endif
|
#endif
|
||||||
@ -104,17 +109,17 @@ namespace DCFApixels.DragonECS
|
|||||||
internal Mask(EcsWorld world)
|
internal Mask(EcsWorld world)
|
||||||
{
|
{
|
||||||
_world = world;
|
_world = world;
|
||||||
Include = new int[8];
|
include = new int[8];
|
||||||
Exclude = new int[2];
|
exclude = new int[2];
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
void Reset()
|
void Reset()
|
||||||
{
|
{
|
||||||
IncludeCount = 0;
|
includeCount = 0;
|
||||||
ExcludeCount = 0;
|
excludeCount = 0;
|
||||||
Hash = 0;
|
hash = 0;
|
||||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||||
_built = false;
|
_built = false;
|
||||||
#endif
|
#endif
|
||||||
@ -126,11 +131,11 @@ namespace DCFApixels.DragonECS
|
|||||||
var poolId = _world.GetPool(member).ID;
|
var poolId = _world.GetPool(member).ID;
|
||||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||||
if (_built) { throw new Exception("Cant change built mask."); }
|
if (_built) { throw new Exception("Cant change built mask."); }
|
||||||
if (Array.IndexOf(Include, poolId, 0, IncludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
if (Array.IndexOf(include, poolId, 0, includeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
||||||
if (Array.IndexOf(Exclude, poolId, 0, ExcludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
if (Array.IndexOf(exclude, poolId, 0, excludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
||||||
#endif
|
#endif
|
||||||
if (IncludeCount == Include.Length) { Array.Resize(ref Include, IncludeCount << 1); }
|
if (includeCount == include.Length) { Array.Resize(ref include, includeCount << 1); }
|
||||||
Include[IncludeCount++] = poolId;
|
include[includeCount++] = poolId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,11 +145,11 @@ namespace DCFApixels.DragonECS
|
|||||||
var poolId = _world.GetPool(member).ID;
|
var poolId = _world.GetPool(member).ID;
|
||||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||||
if (_built) { throw new Exception("Cant change built mask."); }
|
if (_built) { throw new Exception("Cant change built mask."); }
|
||||||
if (Array.IndexOf(Include, poolId, 0, IncludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
if (Array.IndexOf(include, poolId, 0, includeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
||||||
if (Array.IndexOf(Exclude, poolId, 0, ExcludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
if (Array.IndexOf(exclude, poolId, 0, excludeCount) != -1) { throw new Exception($"{typeof(T).Name} already in constraints list."); }
|
||||||
#endif
|
#endif
|
||||||
if (ExcludeCount == Exclude.Length) { Array.Resize(ref Exclude, ExcludeCount << 1); }
|
if (excludeCount == exclude.Length) { Array.Resize(ref exclude, excludeCount << 1); }
|
||||||
Exclude[ExcludeCount++] = poolId;
|
exclude[excludeCount++] = poolId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/EcsWorldMap.cs
Normal file
33
src/EcsWorldMap.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -30,8 +30,16 @@
|
|||||||
{
|
{
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public readonly struct _OnNewEntityGenRecycled : IEcsMessage
|
||||||
|
{
|
||||||
|
public readonly ent entity;
|
||||||
|
public _OnNewEntityGenRecycled(ent entity)
|
||||||
|
{
|
||||||
|
this.entity = entity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface IEcsDoMessege<TMessage> : IEcsProcessor
|
public interface IEcsDoMessege<TMessage> : IEcsProcessor
|
||||||
where TMessage : IEcsMessage
|
where TMessage : IEcsMessage
|
||||||
{
|
{
|
||||||
|
7
src/Primitives/Ref.cs
Normal file
7
src/Primitives/Ref.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public readonly struct Ref<T> where T : class
|
||||||
|
{
|
||||||
|
public readonly T target;
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,6 @@ namespace DCFApixels.DragonECS
|
|||||||
get => (short)((_full << 32) >> 48);
|
get => (short)((_full << 32) >> 48);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 255 = однозначно указывает что сущьность мертва или NULL
|
// 255 = однозначно указывает что сущьность мертва или NULL
|
||||||
// но чтобы значене default было NULL сульностью, мир хранится в виде ID + 1
|
// но чтобы значене default было NULL сульностью, мир хранится в виде ID + 1
|
||||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||||
|
@ -5,43 +5,37 @@ using DCFApixels.DragonECS.Reflection;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public readonly struct mem<T> : IEquatable<mem<T>>, IEquatable<int>
|
public readonly struct mem<T> : IEquatable<mem<T>>, IEquatable<int>
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
public static readonly mem<T> NULL = new mem<T>(-1);
|
public static readonly mem<T> NULL = default;
|
||||||
|
|
||||||
internal readonly int offsetedUniqueID;
|
internal readonly int uniqueID;
|
||||||
|
|
||||||
#region Properties
|
#region Properties
|
||||||
public int UniqueID
|
|
||||||
{
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
get => offsetedUniqueID - 1;
|
|
||||||
}
|
|
||||||
public bool HasValue
|
public bool HasValue
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
get => offsetedUniqueID != 0;
|
get => uniqueID != 0;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
private mem(int uniqueID)
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
{
|
private mem(int uniqueID) => this.uniqueID = uniqueID;
|
||||||
offsetedUniqueID = uniqueID + 1;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Equals
|
#region Equals
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override bool Equals(object obj) => obj is mem<T> key && offsetedUniqueID == key.offsetedUniqueID;
|
public override bool Equals(object obj) => obj is mem<T> key && uniqueID == key.uniqueID;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Equals(mem<T> other) => offsetedUniqueID == other.offsetedUniqueID;
|
public bool Equals(mem<T> other) => uniqueID == other.uniqueID;
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Equals(int other) => offsetedUniqueID == (other + 1);
|
public bool Equals(int other) => uniqueID == other;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetHashCode/ToString
|
#region GetHashCode/ToString
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override int GetHashCode() => offsetedUniqueID - 1;
|
public override int GetHashCode() => uniqueID;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public override string ToString() => HasValue ? MemberDeclarator.GetMemberInfo(this).ToString() : "NULL";
|
public override string ToString() => HasValue ? MemberDeclarator.GetMemberInfo(this).ToString() : "NULL";
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
namespace DCFApixels.DragonECS
|
using System;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public struct tag { }
|
public struct tag { }
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.Assets.DragonECS.src.React
|
namespace DCFApixels.Assets.DragonECS.src.React
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
||||||
sealed class WorldFilterAttribute : Attribute
|
sealed class WorldFilterAttribute : Attribute //TODO
|
||||||
{
|
{
|
||||||
public readonly string[] worlds;
|
public readonly string[] worlds;
|
||||||
|
|
||||||
|
@ -1,26 +1,32 @@
|
|||||||
using System;
|
namespace DCFApixels.DragonECS
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
{
|
||||||
public readonly ref struct TableBuilder
|
public readonly ref struct TableBuilder
|
||||||
{
|
{
|
||||||
private readonly EcsWorld _world;
|
private readonly EcsWorld _world;
|
||||||
|
private readonly EcsWorld.Mask _mask;
|
||||||
|
|
||||||
|
public TableBuilder(EcsWorld world, EcsWorld.Mask mask)
|
||||||
|
{
|
||||||
|
_world = world;
|
||||||
|
_mask = mask;
|
||||||
|
}
|
||||||
|
|
||||||
public EcsPool<T> Cache<T>(mem<T> member)
|
public EcsPool<T> Cache<T>(mem<T> member)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return _world.GetPool(member);
|
||||||
}
|
}
|
||||||
public EcsPool<T> Inc<T>(mem<T> member)
|
public EcsPool<T> Inc<T>(mem<T> member)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_mask.Inc(member);
|
||||||
|
return _world.GetPool(member);
|
||||||
}
|
}
|
||||||
public EcsPool<T> Exc<T>(mem<T> member)
|
public EcsPool<T> Exc<T>(mem<T> member)
|
||||||
|
where T : struct
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_mask.Exc(member);
|
||||||
|
return _world.GetPool(member);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public class EntityArraysPool
|
|
||||||
{
|
|
||||||
//public int[]
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 50cf3219cac6cc84faf71a80230f8539
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public readonly struct EcsField<T> : IEcsMemberCachePool<EcsField<T>, T>
|
public readonly struct EcsField<T> : IEcsMemberCachePool<EcsField<T>, T>
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
private readonly EcsPool<T> _pool;
|
private readonly EcsPool<T> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
@ -57,6 +58,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
public readonly struct EcsIncField<T> : IEcsMemberCachePool<EcsIncField<T>, T>
|
public readonly struct EcsIncField<T> : IEcsMemberCachePool<EcsIncField<T>, T>
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
private readonly EcsPool<T> _pool;
|
private readonly EcsPool<T> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
@ -98,6 +100,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct EcsExcField<T> : IEcsMemberCachePool<EcsExcField<T>, T>
|
public struct EcsExcField<T> : IEcsMemberCachePool<EcsExcField<T>, T>
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
private readonly EcsPool<T> _pool;
|
private readonly EcsPool<T> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
|
|||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public readonly struct EcsTag : IEcsMemberCachePool<EcsTag, tag>
|
public readonly struct EcsTag : IEcsMemberCachePool<EcsTag, tag>
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
private readonly EcsPool<tag> _pool;
|
private readonly EcsPool<tag> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
@ -38,6 +39,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public readonly struct EcsIncTag : IEcsMemberCachePool<EcsIncTag, tag>
|
public readonly struct EcsIncTag : IEcsMemberCachePool<EcsIncTag, tag>
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
private readonly EcsPool<tag> _pool;
|
private readonly EcsPool<tag> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
@ -65,6 +67,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public readonly struct EcsExcTag : IEcsMemberCachePool<EcsExcTag, tag>
|
public readonly struct EcsExcTag : IEcsMemberCachePool<EcsExcTag, tag>
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
private readonly EcsPool<tag> _pool;
|
private readonly EcsPool<tag> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
@ -9,6 +9,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
public interface IEcsMemberCachePool<TSelf, T> : IEcsTableMember
|
public interface IEcsMemberCachePool<TSelf, T> : IEcsTableMember
|
||||||
where TSelf: struct, IEcsTableMember
|
where TSelf: struct, IEcsTableMember
|
||||||
|
where T :struct
|
||||||
{
|
{
|
||||||
public EcsPool<T> Pool { get; }
|
public EcsPool<T> Pool { get; }
|
||||||
public void Inject(out TSelf self, EcsPool<T> pool);
|
public void Inject(out TSelf self, EcsPool<T> pool);
|
Loading…
Reference in New Issue
Block a user