mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 17:34:36 +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:
|
253
src/EcsMember.cs
253
src/EcsMember.cs
@ -1,151 +1,152 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 EcsMemberBase[] _members = new EcsMemberBase[1024];
|
||||
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)
|
||||
where T : struct
|
||||
{
|
||||
private static Dictionary<string, EcsMemberBase> _nameMembersPairs = new Dictionary<string, EcsMemberBase>(1024);
|
||||
private static EcsMemberBase[] _members = new EcsMemberBase[1024];
|
||||
private static int _typesCount = 0;
|
||||
public static EcsMember<T> Declare<T>(string name)
|
||||
{
|
||||
name = $"{typeof(T).FullName}__{name}";
|
||||
name = $"{typeof(T).FullName}__{name}";
|
||||
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||
if (_typesCount < 0)
|
||||
{
|
||||
throw new EcsFrameworkException($"Maximum available members exceeded. The member of \"{name}\" was not declared");
|
||||
}
|
||||
if (_nameMembersPairs.ContainsKey(name))
|
||||
{
|
||||
throw new EcsFrameworkException($"The node with the name \"{name}\" has already been declared");
|
||||
}
|
||||
#endif
|
||||
if (_typesCount >= _members.Length)
|
||||
{
|
||||
Array.Resize(ref _members, _members.Length << 1);
|
||||
}
|
||||
|
||||
EcsMember<T> member = new EcsMember<T>(name, _typesCount);
|
||||
_nameMembersPairs.Add(name, member);
|
||||
_members[_typesCount++] = member;
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
public static EcsMember<T> GetOrDeclareMember<T>(string name)
|
||||
if (_increment < 0)
|
||||
{
|
||||
if(_nameMembersPairs.TryGetValue(name,out EcsMemberBase memberBase))
|
||||
{
|
||||
return (EcsMember<T>)memberBase;
|
||||
}
|
||||
|
||||
return Declare<T>(name);
|
||||
throw new EcsFrameworkException($"Maximum available members exceeded. The member of \"{name}\" was not declared");
|
||||
}
|
||||
|
||||
public static EcsMember<T> GetMemberInfo<T>(mem<T> member)
|
||||
if (_nameMembersPairs.ContainsKey(name))
|
||||
{
|
||||
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||
if (member.HasValue == false)
|
||||
{
|
||||
throw new ArgumentException($"The mem<{typeof(T).Name}> argument is empty");
|
||||
}
|
||||
#endif
|
||||
|
||||
return (EcsMember<T>)_members[member.UniqueID];
|
||||
throw new EcsFrameworkException($"The node with the name \"{name}\" has already been declared");
|
||||
}
|
||||
#endif
|
||||
if (_increment >= _members.Length)
|
||||
{
|
||||
Array.Resize(ref _members, _members.Length << 1);
|
||||
}
|
||||
|
||||
EcsMember<T> member = new EcsMember<T>(name, _increment);
|
||||
_nameMembersPairs.Add(name, member);
|
||||
_members[_increment++] = member;
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
public abstract class EcsMemberBase : IEquatable<EcsMemberBase>
|
||||
public static EcsMember<T> GetOrDeclareMember<T>(string name)
|
||||
where T : struct
|
||||
{
|
||||
protected const string TO_STRING_HEADER = "EcsMember:";
|
||||
|
||||
protected string _name;
|
||||
protected int _uniqueID;
|
||||
protected Type _type;
|
||||
|
||||
#region Propertiees
|
||||
public int UniqueID
|
||||
if (_nameMembersPairs.TryGetValue(name, out EcsMemberBase memberBase))
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _uniqueID;
|
||||
return (EcsMember<T>)memberBase;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetHashCode/ToString
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => _uniqueID;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => TO_STRING_HEADER + _name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Equals
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is EcsMemberBase key && _name == key._name;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(EcsMemberBase other)
|
||||
{
|
||||
return _uniqueID == other._uniqueID;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region operators
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(in EcsMemberBase left, in EcsMemberBase right) => left.Equals(right);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(in EcsMemberBase left, in EcsMemberBase right) => !left.Equals(right);
|
||||
#endregion
|
||||
return Declare<T>(name);
|
||||
}
|
||||
public class EcsMember<T> : EcsMemberBase, IEquatable<EcsMember<T>>
|
||||
|
||||
public static EcsMember<T> GetMemberInfo<T>(mem<T> member)
|
||||
where T : struct
|
||||
{
|
||||
#region Constructors
|
||||
private EcsMember() { }
|
||||
internal EcsMember(string name, int uniqueID)
|
||||
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||
if (member.HasValue == false)
|
||||
{
|
||||
_name = name;
|
||||
_uniqueID = uniqueID;
|
||||
_type = typeof(T);
|
||||
throw new ArgumentException($"The mem<{typeof(T).Name}> argument is empty");
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
|
||||
#region Equals
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool Equals(object obj) => obj is EcsMember<T> key && _uniqueID == key._uniqueID;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(EcsMember<T> other) => _uniqueID == other._uniqueID;
|
||||
#endregion
|
||||
|
||||
#region GetHashCode/ToString
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => _uniqueID;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => TO_STRING_HEADER + _name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region operators
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(in EcsMember<T> left, in EcsMember<T> right) => left.Equals(right);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(in EcsMember<T> left, in EcsMember<T> right) => !left.Equals(right);
|
||||
|
||||
|
||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
//public static implicit operator EcsMember<T>(string name) => MemberDeclarator.Declare<T>(name);
|
||||
#endregion
|
||||
return (EcsMember<T>)_members[member.uniqueID];
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class EcsMemberBase : IEquatable<EcsMemberBase>
|
||||
{
|
||||
protected const string TO_STRING_HEADER = "EcsMember:";
|
||||
|
||||
protected string _name;
|
||||
protected int _uniqueID;
|
||||
protected Type _type;
|
||||
|
||||
#region Propertiees
|
||||
public int UniqueID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => _uniqueID;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region GetHashCode/ToString
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => _uniqueID;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => TO_STRING_HEADER + _name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Equals
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is EcsMemberBase key && _name == key._name;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(EcsMemberBase other)
|
||||
{
|
||||
return _uniqueID == other._uniqueID;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region operators
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(in EcsMemberBase left, in EcsMemberBase right) => left.Equals(right);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(in EcsMemberBase left, in EcsMemberBase right) => !left.Equals(right);
|
||||
#endregion
|
||||
}
|
||||
public class EcsMember<T> : EcsMemberBase, IEquatable<EcsMember<T>>
|
||||
where T : struct
|
||||
{
|
||||
#region Constructors
|
||||
private EcsMember() { }
|
||||
internal EcsMember(string name, int uniqueID)
|
||||
{
|
||||
_name = name;
|
||||
_uniqueID = uniqueID;
|
||||
_type = typeof(T);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Equals
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override bool Equals(object obj) => obj is EcsMember<T> key && _uniqueID == key._uniqueID;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(EcsMember<T> other) => _uniqueID == other._uniqueID;
|
||||
#endregion
|
||||
|
||||
#region GetHashCode/ToString
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => _uniqueID;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => TO_STRING_HEADER + _name;
|
||||
|
||||
#endregion
|
||||
|
||||
#region operators
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(in EcsMember<T> left, in EcsMember<T> right) => left.Equals(right);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(in EcsMember<T> left, in EcsMember<T> right) => !left.Equals(right);
|
||||
|
||||
|
||||
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
//public static implicit operator EcsMember<T>(string name) => MemberDeclarator.Declare<T>(name);
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -4,6 +4,8 @@ using DCFApixels.DragonECS.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -12,12 +14,14 @@ namespace DCFApixels.DragonECS
|
||||
public EcsWorld World { get; }
|
||||
public int ID { get; }
|
||||
public EcsMemberBase Type { get; }
|
||||
public bool IsTagsPool { get; }
|
||||
public bool Has(int index);
|
||||
public void Add(int index);
|
||||
public void Del(int index);
|
||||
}
|
||||
|
||||
public class EcsPool<T> : IEcsPool
|
||||
where T : struct
|
||||
{
|
||||
private int _id;
|
||||
private readonly EcsWorld _source;
|
||||
@ -25,25 +29,40 @@ namespace DCFApixels.DragonECS
|
||||
private readonly SparseSet _sparseSet;
|
||||
private T[] _denseItems;
|
||||
|
||||
private int _isTagsPoolMask;
|
||||
|
||||
#region Properites
|
||||
public EcsWorld World => _source;
|
||||
public int ID => _id;
|
||||
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]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref _denseItems[_sparseSet[index]];
|
||||
get => ref _denseItems[_sparseSet[index] | _isTagsPoolMask];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public EcsPool(EcsWorld source, EcsMember<T> type, int capacity)
|
||||
public EcsPool(EcsWorld source, mem<T> type, int capacity)
|
||||
{
|
||||
_source = source;
|
||||
_type = type;
|
||||
_denseItems = new T[capacity];
|
||||
_type = MemberDeclarator.GetMemberInfo(type);
|
||||
_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
|
||||
|
||||
@ -52,8 +71,12 @@ namespace DCFApixels.DragonECS
|
||||
public ref T Add(int index)
|
||||
{
|
||||
_sparseSet.Add(index);
|
||||
_sparseSet.Normalize(ref _denseItems);
|
||||
return ref _denseItems[_sparseSet.IndexOf(index)];
|
||||
if(IsTagsPool)
|
||||
{
|
||||
_sparseSet.Normalize(ref _denseItems);
|
||||
return ref _denseItems[_sparseSet.IndexOf(index)];
|
||||
}
|
||||
return ref _denseItems[0];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@ -65,6 +88,7 @@ namespace DCFApixels.DragonECS
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Del(int index)
|
||||
{
|
||||
if (!IsTagsPool) { this[index] = default; }
|
||||
_sparseSet.Remove(index);
|
||||
}
|
||||
#endregion
|
||||
|
@ -2,8 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
@ -20,6 +18,8 @@ namespace DCFApixels.DragonECS
|
||||
private Dictionary<string, EcsWorld> _worldsDict = new Dictionary<string, EcsWorld>();
|
||||
private List<EcsWorld> _worlds = new List<EcsWorld>();
|
||||
|
||||
|
||||
|
||||
private Dictionary<Type, IEcsProcessorsRunner> _runners;
|
||||
private Dictionary<Type, IEcsProcessorsMessenger> _messengers;
|
||||
private EcsProcessorsRunner<_Run> _runRunnerCache;
|
||||
|
@ -14,25 +14,28 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
private byte _id = DEAD_WORLD_ID;
|
||||
|
||||
private Dictionary<Type, IEcsPool> _pools;
|
||||
private IEcsPool[] _pools;
|
||||
private SparseSet _memToPoolIDSet;
|
||||
|
||||
|
||||
private SparseSet _entities = new SparseSet();
|
||||
private short[] _gens;
|
||||
|
||||
private List<EcsFilter>[] _filtersByIncludedComponents;
|
||||
private List<EcsFilter>[] _filtersByExcludedComponents;
|
||||
|
||||
//private Dictionary<Type, IEcsEntityTable> _tables;
|
||||
|
||||
#region Properties
|
||||
public int ID => _id;
|
||||
public bool IsAlive => _id != DEAD_WORLD_ID;
|
||||
public bool IsEmpty => _entities.Count < 0;
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
public EcsWorld()
|
||||
{
|
||||
_pools = new Dictionary<Type, IEcsPool>();
|
||||
_pools = new IEcsPool[512];
|
||||
_entities = new SparseSet();
|
||||
_memToPoolIDSet = new SparseSet(512);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -45,14 +48,16 @@ namespace DCFApixels.DragonECS
|
||||
|
||||
#region GetPool
|
||||
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))
|
||||
{
|
||||
return (EcsPool<T>)pool;
|
||||
}
|
||||
|
||||
//pool = new EcsPool<T>();
|
||||
pool = new EcsPool<T>(this, member, 512);//TODO сделать чтоб объем можно было указывать через конфиг
|
||||
_pools.Add(type, pool);
|
||||
return (EcsPool<T>)pool;
|
||||
}
|
||||
@ -92,11 +97,11 @@ namespace DCFApixels.DragonECS
|
||||
public class Mask
|
||||
{
|
||||
private readonly EcsWorld _world;
|
||||
internal int[] Include;
|
||||
internal int[] Exclude;
|
||||
internal int IncludeCount;
|
||||
internal int ExcludeCount;
|
||||
internal int Hash;
|
||||
internal int[] include;
|
||||
internal int[] exclude;
|
||||
internal int includeCount;
|
||||
internal int excludeCount;
|
||||
internal int hash;
|
||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||
bool _built;
|
||||
#endif
|
||||
@ -104,17 +109,17 @@ namespace DCFApixels.DragonECS
|
||||
internal Mask(EcsWorld world)
|
||||
{
|
||||
_world = world;
|
||||
Include = new int[8];
|
||||
Exclude = new int[2];
|
||||
include = new int[8];
|
||||
exclude = new int[2];
|
||||
Reset();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void Reset()
|
||||
{
|
||||
IncludeCount = 0;
|
||||
ExcludeCount = 0;
|
||||
Hash = 0;
|
||||
includeCount = 0;
|
||||
excludeCount = 0;
|
||||
hash = 0;
|
||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||
_built = false;
|
||||
#endif
|
||||
@ -126,11 +131,11 @@ namespace DCFApixels.DragonECS
|
||||
var poolId = _world.GetPool(member).ID;
|
||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||
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(Exclude, poolId, 0, ExcludeCount) != -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."); }
|
||||
#endif
|
||||
if (IncludeCount == Include.Length) { Array.Resize(ref Include, IncludeCount << 1); }
|
||||
Include[IncludeCount++] = poolId;
|
||||
if (includeCount == include.Length) { Array.Resize(ref include, includeCount << 1); }
|
||||
include[includeCount++] = poolId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -140,11 +145,11 @@ namespace DCFApixels.DragonECS
|
||||
var poolId = _world.GetPool(member).ID;
|
||||
#if DEBUG && !DCFAECS_NO_SANITIZE_CHECKS
|
||||
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(Exclude, poolId, 0, ExcludeCount) != -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."); }
|
||||
#endif
|
||||
if (ExcludeCount == Exclude.Length) { Array.Resize(ref Exclude, ExcludeCount << 1); }
|
||||
Exclude[ExcludeCount++] = poolId;
|
||||
if (excludeCount == exclude.Length) { Array.Resize(ref exclude, excludeCount << 1); }
|
||||
exclude[excludeCount++] = poolId;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
public readonly struct _OnNewEntityGenRecycled : IEcsMessage
|
||||
{
|
||||
public readonly ent entity;
|
||||
public _OnNewEntityGenRecycled(ent entity)
|
||||
{
|
||||
this.entity = entity;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IEcsDoMessege<TMessage> : IEcsProcessor
|
||||
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,11 +30,10 @@ namespace DCFApixels.DragonECS
|
||||
get => (short)((_full << 32) >> 48);
|
||||
|
||||
}
|
||||
|
||||
// 255 = однозначно указывает что сущьность мертва или NULL
|
||||
// но чтобы значене default было NULL сульностью, мир хранится в виде ID + 1
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public byte world
|
||||
public byte world
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (byte)(((_full << 48) >> 56) - 1);
|
||||
|
@ -5,43 +5,37 @@ using DCFApixels.DragonECS.Reflection;
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
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
|
||||
public int UniqueID
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => offsetedUniqueID - 1;
|
||||
}
|
||||
public bool HasValue
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => offsetedUniqueID != 0;
|
||||
get => uniqueID != 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
private mem(int uniqueID)
|
||||
{
|
||||
offsetedUniqueID = uniqueID + 1;
|
||||
}
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private mem(int uniqueID) => this.uniqueID = uniqueID;
|
||||
#endregion
|
||||
|
||||
#region Equals
|
||||
[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)]
|
||||
public bool Equals(mem<T> other) => offsetedUniqueID == other.offsetedUniqueID;
|
||||
public bool Equals(mem<T> other) => uniqueID == other.uniqueID;
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(int other) => offsetedUniqueID == (other + 1);
|
||||
public bool Equals(int other) => uniqueID == other;
|
||||
#endregion
|
||||
|
||||
#region GetHashCode/ToString
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => offsetedUniqueID - 1;
|
||||
public override int GetHashCode() => uniqueID;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
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 { }
|
||||
}
|
||||
|
@ -1,13 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DCFApixels.Assets.DragonECS.src.React
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
||||
sealed class WorldFilterAttribute : Attribute
|
||||
sealed class WorldFilterAttribute : Attribute //TODO
|
||||
{
|
||||
public readonly string[] worlds;
|
||||
|
||||
|
@ -1,26 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public readonly ref struct TableBuilder
|
||||
{
|
||||
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)
|
||||
where T : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return _world.GetPool(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)
|
||||
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
|
||||
{
|
||||
public readonly struct EcsField<T> : IEcsMemberCachePool<EcsField<T>, T>
|
||||
where T :struct
|
||||
{
|
||||
private readonly EcsPool<T> _pool;
|
||||
private readonly int _poolID;
|
||||
@ -57,6 +58,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
|
||||
public readonly struct EcsIncField<T> : IEcsMemberCachePool<EcsIncField<T>, T>
|
||||
where T :struct
|
||||
{
|
||||
private readonly EcsPool<T> _pool;
|
||||
private readonly int _poolID;
|
||||
@ -98,6 +100,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
|
||||
public struct EcsExcField<T> : IEcsMemberCachePool<EcsExcField<T>, T>
|
||||
where T :struct
|
||||
{
|
||||
private readonly EcsPool<T> _pool;
|
||||
private readonly int _poolID;
|
@ -6,6 +6,7 @@ using System.Runtime.CompilerServices;
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public readonly struct EcsTag : IEcsMemberCachePool<EcsTag, tag>
|
||||
where T :struct
|
||||
{
|
||||
private readonly EcsPool<tag> _pool;
|
||||
private readonly int _poolID;
|
||||
@ -38,6 +39,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
}
|
||||
public readonly struct EcsIncTag : IEcsMemberCachePool<EcsIncTag, tag>
|
||||
where T :struct
|
||||
{
|
||||
private readonly EcsPool<tag> _pool;
|
||||
private readonly int _poolID;
|
||||
@ -65,6 +67,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
}
|
||||
public readonly struct EcsExcTag : IEcsMemberCachePool<EcsExcTag, tag>
|
||||
where T :struct
|
||||
{
|
||||
private readonly EcsPool<tag> _pool;
|
||||
private readonly int _poolID;
|
@ -9,6 +9,7 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public interface IEcsMemberCachePool<TSelf, T> : IEcsTableMember
|
||||
where TSelf: struct, IEcsTableMember
|
||||
where T :struct
|
||||
{
|
||||
public EcsPool<T> Pool { get; }
|
||||
public void Inject(out TSelf self, EcsPool<T> pool);
|
Loading…
Reference in New Issue
Block a user