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
cab282ac43
commit
36b696777b
@ -19,6 +19,7 @@ namespace DCFApixels.DragonECS
|
|||||||
private readonly SparseSet _entities;
|
private readonly SparseSet _entities;
|
||||||
|
|
||||||
private DelayedOp[] _delayedOps;
|
private DelayedOp[] _delayedOps;
|
||||||
|
private int _delayedOpsCount;
|
||||||
|
|
||||||
private int _lockCount;
|
private int _lockCount;
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ namespace DCFApixels.DragonECS
|
|||||||
internal void Add(int entityID)
|
internal void Add(int entityID)
|
||||||
{
|
{
|
||||||
if (_lockCount > 0)
|
if (_lockCount > 0)
|
||||||
AddDelayedOp(entityID, false);
|
AddDelayedOp(entityID, true);
|
||||||
_entities.Add(entityID);
|
_entities.Add(entityID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,15 +63,32 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
private void AddDelayedOp(int entityID, bool isAdd)
|
private void AddDelayedOp(int entityID, bool isAdd)
|
||||||
{
|
{
|
||||||
|
if(_delayedOpsCount >= _delayedOps.Length)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _delayedOps, _delayedOps.Length << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
_delayedOps[_delayedOpsCount].Entity = entityID;
|
||||||
|
_delayedOps[_delayedOpsCount].Added = isAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region GetEnumerator
|
#region GetEnumerator
|
||||||
private void Unlock()
|
private void Unlock()
|
||||||
{
|
{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (_lockCount <= 0) { throw new Exception($"Invalid lock-unlock balance for {nameof(EcsFilter)}."); }
|
if (_lockCount <= 0)
|
||||||
|
{
|
||||||
|
throw new Exception($"Invalid lock-unlock balance for {nameof(EcsFilter)}.");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
_lockCount--;
|
_lockCount--;
|
||||||
|
if (_lockCount <= 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _delayedOpsCount; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public Enumerator GetEnumerator()
|
public Enumerator GetEnumerator()
|
||||||
{
|
{
|
||||||
@ -112,7 +130,7 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DelayedOp
|
private struct DelayedOp
|
||||||
{
|
{
|
||||||
public bool Added;
|
public bool Added;
|
||||||
public int Entity;
|
public int Entity;
|
||||||
|
@ -1,22 +1,33 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using DCFApixels.DragonECS.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
|
public interface IEcsPool
|
||||||
|
{
|
||||||
|
public EcsWorld World { get; }
|
||||||
|
public int ID { get; }
|
||||||
|
public EcsMemberBase Type { get; }
|
||||||
|
public bool Has(int index);
|
||||||
|
public void Add(int index);
|
||||||
|
public void Del(int index);
|
||||||
|
}
|
||||||
|
|
||||||
public class EcsPool<T> : IEcsPool
|
public class EcsPool<T> : IEcsPool
|
||||||
{
|
{
|
||||||
private int _id;
|
private int _id;
|
||||||
private readonly EcsWorld _source;
|
private readonly EcsWorld _source;
|
||||||
private readonly EcsType _type;
|
private readonly EcsMember<T> _type;
|
||||||
private readonly SparseSet _sparseSet;
|
private readonly SparseSet _sparseSet;
|
||||||
private T[] _denseItems;
|
private T[] _denseItems;
|
||||||
|
|
||||||
#region Properites
|
#region Properites
|
||||||
public EcsWorld World => _source;
|
public EcsWorld World => _source;
|
||||||
public int ID => _id;
|
public int ID => _id;
|
||||||
public EcsType Type => _type;
|
public EcsMemberBase Type => _type;
|
||||||
public ref T this[int index]
|
public ref T this[int index]
|
||||||
{
|
{
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
@ -26,7 +37,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
public EcsPool(EcsWorld source, EcsType type, int capacity)
|
public EcsPool(EcsWorld source, EcsMember<T> type, int capacity)
|
||||||
{
|
{
|
||||||
_source = source;
|
_source = source;
|
||||||
_type = type;
|
_type = type;
|
@ -7,10 +7,14 @@ namespace DCFApixels.DragonECS
|
|||||||
public abstract class EcsTable
|
public abstract class EcsTable
|
||||||
{
|
{
|
||||||
internal EcsFilter _filter;
|
internal EcsFilter _filter;
|
||||||
|
|
||||||
|
public EcsTable(ref TableBuilder tableBuilder) { }
|
||||||
|
|
||||||
public EcsFilter Filter
|
public EcsFilter Filter
|
||||||
{
|
{
|
||||||
get => _filter;
|
get => _filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ namespace DCFApixels.DragonECS
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetPool
|
#region GetPool
|
||||||
public EcsPool<T> GetPool<T>()
|
public EcsPool<T> GetPool<T>(mem<T> member)
|
||||||
{
|
{
|
||||||
Type type = typeof(T);
|
Type type = typeof(T);
|
||||||
if (_pools.TryGetValue(type, out IEcsPool pool))
|
if (_pools.TryGetValue(type, out IEcsPool pool))
|
||||||
@ -76,13 +77,13 @@ namespace DCFApixels.DragonECS
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
internal void OnEntityFieldAdd(int entityID, EcsType chaangedField)
|
internal void OnEntityFieldAdd(int entityID, mem<T> chaangedField)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal void OnEntityFieldDel(int entityID, EcsType chaangedField)
|
internal void OnEntityFieldDel(int entityID, EcsMember chaangedField)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -90,7 +91,65 @@ namespace DCFApixels.DragonECS
|
|||||||
|
|
||||||
public class Mask
|
public class Mask
|
||||||
{
|
{
|
||||||
|
private readonly EcsWorld _world;
|
||||||
|
internal int[] Include;
|
||||||
|
internal int[] Exclude;
|
||||||
|
internal int IncludeCount;
|
||||||
|
internal int ExcludeCount;
|
||||||
|
internal int Hash;
|
||||||
|
#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS
|
||||||
|
bool _built;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
internal Mask(EcsWorld world)
|
||||||
|
{
|
||||||
|
_world = world;
|
||||||
|
Include = new int[8];
|
||||||
|
Exclude = new int[2];
|
||||||
|
Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
void Reset()
|
||||||
|
{
|
||||||
|
IncludeCount = 0;
|
||||||
|
ExcludeCount = 0;
|
||||||
|
Hash = 0;
|
||||||
|
#if DEBUG && !LEOECSLITE_NO_SANITIZE_CHECKS
|
||||||
|
_built = false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Mask Inc<T>(EcsMember member) where T : struct
|
||||||
|
{
|
||||||
|
var poolId = _world.GetPool<T>().GetId();
|
||||||
|
#if DEBUG && !LEOECSLITE_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."); }
|
||||||
|
#endif
|
||||||
|
if (IncludeCount == Include.Length) { Array.Resize(ref Include, IncludeCount << 1); }
|
||||||
|
Include[IncludeCount++] = poolId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_2020_3_OR_NEWER
|
||||||
|
[UnityEngine.Scripting.Preserve]
|
||||||
|
#endif
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public Mask Exc<T>(EcsMember member) where T : struct
|
||||||
|
{
|
||||||
|
var poolId = _world.GetPool<T>().GetId();
|
||||||
|
#if DEBUG && !LEOECSLITE_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."); }
|
||||||
|
#endif
|
||||||
|
if (ExcludeCount == Exclude.Length) { Array.Resize(ref Exclude, ExcludeCount << 1); }
|
||||||
|
Exclude[ExcludeCount++] = poolId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,16 @@
|
|||||||
|
|
||||||
|
|
||||||
public interface IEcsMessage { }
|
public interface IEcsMessage { }
|
||||||
|
public readonly struct _OnNewEntityCreated : IEcsMessage
|
||||||
|
{
|
||||||
|
public readonly ent entity;
|
||||||
|
|
||||||
|
public _OnNewEntityCreated(ent entity)
|
||||||
|
{
|
||||||
|
this.entity = entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
public interface IEcsDoMessege<TMessage> : IEcsProcessor
|
public interface IEcsDoMessege<TMessage> : IEcsProcessor
|
||||||
where TMessage : IEcsMessage
|
where TMessage : IEcsMessage
|
||||||
{
|
{
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
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 EcsTagsPool : IEcsPool
|
|
||||||
{
|
|
||||||
private int _id;
|
|
||||||
private readonly EcsWorld _source;
|
|
||||||
private readonly EcsType _type;
|
|
||||||
private readonly SparseSet _sparseSet;
|
|
||||||
|
|
||||||
#region Properites
|
|
||||||
public EcsWorld World => _source;
|
|
||||||
public int ID => _id;
|
|
||||||
public EcsType Type => _type;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
public EcsTagsPool(EcsWorld source, EcsType type, int capacity)
|
|
||||||
{
|
|
||||||
_source = source;
|
|
||||||
_type = type;
|
|
||||||
_sparseSet = new SparseSet(capacity);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Add/Has/Del
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Add(int index)
|
|
||||||
{
|
|
||||||
_sparseSet.Add(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Del(int index)
|
|
||||||
{
|
|
||||||
_sparseSet.Add(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool Has(int index)
|
|
||||||
{
|
|
||||||
return _sparseSet.Contains(index);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public interface IEcsPool
|
|
||||||
{
|
|
||||||
public EcsWorld World { get; }
|
|
||||||
public int ID { get; }
|
|
||||||
public EcsType Type { get; }
|
|
||||||
public bool Has(int index);
|
|
||||||
public void Add(int index);
|
|
||||||
public void Del(int index);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 712e0669e3984c0479174a12942e4db6
|
guid: 7c2d964089dec3d439486d9a2c94dda2
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
62
src/Primitives/mem.cs
Normal file
62
src/Primitives/mem.cs
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using DCFApixels.DragonECS.Reflection;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public readonly struct mem<T> : IEquatable<mem<T>>, IEquatable<int>
|
||||||
|
{
|
||||||
|
public static readonly mem<T> NULL = new mem<T>(-1);
|
||||||
|
|
||||||
|
internal readonly int offsetedUniqueID;
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
public int UniqueID
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => offsetedUniqueID - 1;
|
||||||
|
}
|
||||||
|
public bool HasValue
|
||||||
|
{
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
get => offsetedUniqueID != 0;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
private mem(int uniqueID)
|
||||||
|
{
|
||||||
|
offsetedUniqueID = uniqueID + 1;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Equals
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public override bool Equals(object obj) => obj is mem<T> key && offsetedUniqueID == key.offsetedUniqueID;
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool Equals(mem<T> other) => offsetedUniqueID == other.offsetedUniqueID;
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public bool Equals(int other) => offsetedUniqueID == (other + 1);
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region GetHashCode/ToString
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public override int GetHashCode() => offsetedUniqueID - 1;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public override string ToString() => HasValue ? MemberDeclarator.GetMemberInfo(this).ToString() : "NULL";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region operators
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool operator ==(in mem<T> left, in mem<T> right) => left.Equals(right);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static bool operator !=(in mem<T> left, in mem<T> right) => !left.Equals(right);
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static implicit operator mem<T>(string name) => new mem<T>(MemberDeclarator.Declare<T>(name).UniqueID);
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 82d72237ee8aeb64c9e5455be807896a
|
guid: a21421fecdd5670448a3a10c804238f7
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
4
src/Primitives/tag.cs
Normal file
4
src/Primitives/tag.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public struct tag { }
|
||||||
|
}
|
19
src/React/WorldFilterAttribute.cs
Normal file
19
src/React/WorldFilterAttribute.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
|
{
|
||||||
|
public readonly string[] worlds;
|
||||||
|
|
||||||
|
public WorldFilterAttribute(params string[] worlds)
|
||||||
|
{
|
||||||
|
this.worlds = worlds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 01fdcaed7dcb78b4eb4560c068cb0b27
|
guid: 473f26450295507498d518fb452be90f
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
26
src/TableBuilder.cs
Normal file
26
src/TableBuilder.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public readonly ref struct TableBuilder
|
||||||
|
{
|
||||||
|
private readonly EcsWorld _world;
|
||||||
|
|
||||||
|
public EcsPool<T> Cache<T>(mem<T> member)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public EcsPool<T> Inc<T>(mem<T> member)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public EcsPool<T> Exc<T>(mem<T> member)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
src/TableBuilder.cs.meta
Normal file
11
src/TableBuilder.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3ae306a1fd41f78428c59018eeaf21f3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -5,12 +5,12 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public readonly struct EcsTag : IEcsMemberCachePool<EcsTag, TagType>
|
public readonly struct EcsTag : IEcsMemberCachePool<EcsTag, tag>
|
||||||
{
|
{
|
||||||
private readonly EcsPool<TagType> _pool;
|
private readonly EcsPool<tag> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
|
|
||||||
public EcsPool<TagType> Pool => _pool;
|
public EcsPool<tag> Pool => _pool;
|
||||||
public int PoolID => _poolID;
|
public int PoolID => _poolID;
|
||||||
|
|
||||||
private EcsTag(int poolID)
|
private EcsTag(int poolID)
|
||||||
@ -18,7 +18,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_pool = null;
|
_pool = null;
|
||||||
_poolID = poolID;
|
_poolID = poolID;
|
||||||
}
|
}
|
||||||
internal EcsTag(EcsPool<TagType> pool)
|
internal EcsTag(EcsPool<tag> pool)
|
||||||
{
|
{
|
||||||
_pool = pool;
|
_pool = pool;
|
||||||
_poolID = pool.ID;
|
_poolID = pool.ID;
|
||||||
@ -32,17 +32,17 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static implicit operator EcsTag(in int poolID) => new EcsTag(poolID);
|
public static implicit operator EcsTag(in int poolID) => new EcsTag(poolID);
|
||||||
|
|
||||||
void IEcsMemberCachePool<EcsTag, TagType>.Inject(out EcsTag self, EcsPool<TagType> pool)
|
void IEcsMemberCachePool<EcsTag, tag>.Inject(out EcsTag self, EcsPool<tag> pool)
|
||||||
{
|
{
|
||||||
self = new EcsTag(pool);
|
self = new EcsTag(pool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public readonly struct EcsIncTag : IEcsMemberCachePool<EcsIncTag, TagType>
|
public readonly struct EcsIncTag : IEcsMemberCachePool<EcsIncTag, tag>
|
||||||
{
|
{
|
||||||
private readonly EcsPool<TagType> _pool;
|
private readonly EcsPool<tag> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
|
|
||||||
public EcsPool<TagType> Pool => _pool;
|
public EcsPool<tag> Pool => _pool;
|
||||||
public int PoolID => _poolID;
|
public int PoolID => _poolID;
|
||||||
|
|
||||||
private EcsIncTag(int poolID)
|
private EcsIncTag(int poolID)
|
||||||
@ -50,7 +50,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_pool = null;
|
_pool = null;
|
||||||
_poolID = poolID;
|
_poolID = poolID;
|
||||||
}
|
}
|
||||||
internal EcsIncTag(EcsPool<TagType> pool)
|
internal EcsIncTag(EcsPool<tag> pool)
|
||||||
{
|
{
|
||||||
_pool = pool;
|
_pool = pool;
|
||||||
_poolID = pool.ID;
|
_poolID = pool.ID;
|
||||||
@ -59,17 +59,17 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static implicit operator EcsIncTag(in int poolID) => new EcsIncTag(poolID);
|
public static implicit operator EcsIncTag(in int poolID) => new EcsIncTag(poolID);
|
||||||
|
|
||||||
void IEcsMemberCachePool<EcsIncTag, TagType>.Inject(out EcsIncTag self, EcsPool<TagType> pool)
|
void IEcsMemberCachePool<EcsIncTag, tag>.Inject(out EcsIncTag self, EcsPool<tag> pool)
|
||||||
{
|
{
|
||||||
self = new EcsIncTag(pool);
|
self = new EcsIncTag(pool);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public readonly struct EcsExcTag : IEcsMemberCachePool<EcsExcTag, TagType>
|
public readonly struct EcsExcTag : IEcsMemberCachePool<EcsExcTag, tag>
|
||||||
{
|
{
|
||||||
private readonly EcsPool<TagType> _pool;
|
private readonly EcsPool<tag> _pool;
|
||||||
private readonly int _poolID;
|
private readonly int _poolID;
|
||||||
|
|
||||||
public EcsPool<TagType> Pool => _pool;
|
public EcsPool<tag> Pool => _pool;
|
||||||
public int PoolID => _poolID;
|
public int PoolID => _poolID;
|
||||||
|
|
||||||
private EcsExcTag(int poolID)
|
private EcsExcTag(int poolID)
|
||||||
@ -77,7 +77,7 @@ namespace DCFApixels.DragonECS
|
|||||||
_pool = null;
|
_pool = null;
|
||||||
_poolID = poolID;
|
_poolID = poolID;
|
||||||
}
|
}
|
||||||
internal EcsExcTag(EcsPool<TagType> pool)
|
internal EcsExcTag(EcsPool<tag> pool)
|
||||||
{
|
{
|
||||||
_pool = pool;
|
_pool = pool;
|
||||||
_poolID = pool.ID;
|
_poolID = pool.ID;
|
||||||
@ -86,7 +86,7 @@ namespace DCFApixels.DragonECS
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static implicit operator EcsExcTag(in int poolID) => new EcsExcTag(poolID);
|
public static implicit operator EcsExcTag(in int poolID) => new EcsExcTag(poolID);
|
||||||
|
|
||||||
void IEcsMemberCachePool<EcsExcTag, TagType>.Inject(out EcsExcTag self, EcsPool<TagType> pool)
|
void IEcsMemberCachePool<EcsExcTag, tag>.Inject(out EcsExcTag self, EcsPool<tag> pool)
|
||||||
{
|
{
|
||||||
self = new EcsExcTag(pool);
|
self = new EcsExcTag(pool);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
public struct TagType { }
|
|
||||||
}
|
|
143
src/Utils/EcsMember.cs
Normal file
143
src/Utils/EcsMember.cs
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using DCFApixels.DragonECS.Reflection;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
namespace Reflection
|
||||||
|
{
|
||||||
|
public static class MemberDeclarator
|
||||||
|
{
|
||||||
|
#if !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||||
|
private static HashSet<string> _usedNames = new HashSet<string>(1024);
|
||||||
|
#endif
|
||||||
|
private static EcsMemberBase[] _member = new EcsMemberBase[1024];
|
||||||
|
private static int _typesCount = 0;
|
||||||
|
public static EcsMember<T> Declare<T>(string 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 (_usedNames.Contains(name))
|
||||||
|
{
|
||||||
|
throw new EcsFrameworkException($"The node with the name \"{name}\" has already been declared");
|
||||||
|
}
|
||||||
|
_usedNames.Add(name);
|
||||||
|
#endif
|
||||||
|
if (_typesCount >= _member.Length)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _member, _member.Length << 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
EcsMember<T> member = new EcsMember<T>(name, _typesCount);
|
||||||
|
_member[_typesCount++] = member;
|
||||||
|
|
||||||
|
return member;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EcsMember<T> GetMemberInfo<T>(mem<T> member)
|
||||||
|
{
|
||||||
|
#if DEBUG && !DCFA_ECS_NO_SANITIZE_CHECKS
|
||||||
|
if (member.HasValue == false)
|
||||||
|
{
|
||||||
|
throw new ArgumentException($"The member argument is empty");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (EcsMember<T>)_member[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>>
|
||||||
|
{
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,77 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
|
||||||
{
|
|
||||||
|
|
||||||
public class EcsType : IEquatable<EcsType>
|
|
||||||
{
|
|
||||||
private static int _idIncrement = 0;
|
|
||||||
|
|
||||||
//свободно еще 4 байта, возможно можно выделить под айдишники
|
|
||||||
private string _name;
|
|
||||||
private int _uniqueID;
|
|
||||||
|
|
||||||
#region Constructors
|
|
||||||
internal EcsType(string name)
|
|
||||||
{
|
|
||||||
_name = name;
|
|
||||||
_uniqueID = _idIncrement++;
|
|
||||||
|
|
||||||
#if DEBUG
|
|
||||||
if (_idIncrement == 0)
|
|
||||||
{
|
|
||||||
throw new EcsFrameworkException($"The maximum number of identifiers is allocated. Max:{uint.MaxValue}");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Equals
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public override bool Equals(object obj)
|
|
||||||
{
|
|
||||||
return obj is EcsType key && _name == key._name;
|
|
||||||
}
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool Equals(EcsType other)
|
|
||||||
{
|
|
||||||
return _uniqueID == other._uniqueID;
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region GetHashCode/ToString
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public override int GetHashCode() => _uniqueID;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public override string ToString() => "EcsType." + _name;
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region operators
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static bool operator ==(in EcsType left, in EcsType right) => left.Equals(right);
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static bool operator !=(in EcsType left, in EcsType right) => !left.Equals(right);
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static class EcsTypeMap
|
|
||||||
{
|
|
||||||
private static Dictionary<string, EcsType> _types = new Dictionary<string, EcsType>(256);
|
|
||||||
|
|
||||||
public static EcsType GetEcsType(string name)
|
|
||||||
{
|
|
||||||
if (_types.TryGetValue(name, out EcsType type))
|
|
||||||
return type;
|
|
||||||
|
|
||||||
type = new EcsType(name);
|
|
||||||
_types.Add(name, type);
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public class entityArraysPool
|
public class EntityArraysPool
|
||||||
{
|
{
|
||||||
//public int[]
|
//public int[]
|
||||||
}
|
}
|
||||||
|
18
test/Mems.cs
Normal file
18
test/Mems.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public static class Mems
|
||||||
|
{
|
||||||
|
public static readonly mem<float> health = "health";
|
||||||
|
public static readonly mem<float> regeneration = "regeneration";
|
||||||
|
public static readonly mem<Vector3> position = "position";
|
||||||
|
public static readonly mem<Quaternion> rotation = "rotation";
|
||||||
|
public static readonly mem<Vector3> scale = "scale";
|
||||||
|
}
|
||||||
|
}
|
11
test/Mems.cs.meta
Normal file
11
test/Mems.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9478c808aeb8de24a883819991780c9b
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
31
test/Startup.cs
Normal file
31
test/Startup.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DCFApixels;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace DCFApixels.DragonECS
|
||||||
|
{
|
||||||
|
public class Startup : MonoBehaviour
|
||||||
|
{
|
||||||
|
|
||||||
|
private EcsSession _ecsSession;
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
_ecsSession
|
||||||
|
.AddWorld("")
|
||||||
|
.Add(new TestSystem())
|
||||||
|
.Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
_ecsSession.Run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
_ecsSession.Destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
test/Startup.cs.meta
Normal file
11
test/Startup.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8520d71f413c71442bd847f51820760e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,12 +1,63 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using DCFApixels;
|
||||||
using System.Text;
|
using UnityEngine;
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace DCFApixels.DragonECS
|
namespace DCFApixels.DragonECS
|
||||||
{
|
{
|
||||||
public struct TransformTable
|
public class TransformTable : EcsTable
|
||||||
{
|
{
|
||||||
|
public readonly EcsPool<Vector3> position;
|
||||||
|
public readonly EcsPool<Quaternion> rotation;
|
||||||
|
public readonly EcsPool<Vector3> scale;
|
||||||
|
|
||||||
|
public TransformTable(ref TableBuilder tableBuilder) : base(ref tableBuilder)
|
||||||
|
{
|
||||||
|
position = tableBuilder.Inc(Mems.position);
|
||||||
|
rotation = tableBuilder.Inc(Mems.rotation);
|
||||||
|
scale = tableBuilder.Inc(Mems.scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PositionTable : EcsTable
|
||||||
|
{
|
||||||
|
public readonly EcsPool<Vector3> position;
|
||||||
|
public readonly EcsPool<Quaternion> rotation;
|
||||||
|
public readonly EcsPool<Vector3> scale;
|
||||||
|
|
||||||
|
public PositionTable(ref TableBuilder tableBuilder) : base(ref tableBuilder)
|
||||||
|
{
|
||||||
|
position = tableBuilder.Inc(Mems.position);
|
||||||
|
rotation = tableBuilder.Cache(Mems.rotation);
|
||||||
|
scale = tableBuilder.Cache(Mems.scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RotationTable : EcsTable
|
||||||
|
{
|
||||||
|
public readonly EcsPool<Vector3> position;
|
||||||
|
public readonly EcsPool<Quaternion> rotation;
|
||||||
|
public readonly EcsPool<Vector3> scale;
|
||||||
|
|
||||||
|
public RotationTable(ref TableBuilder tableBuilder) : base(ref tableBuilder)
|
||||||
|
{
|
||||||
|
position = tableBuilder.Cache(Mems.position);
|
||||||
|
rotation = tableBuilder.Inc(Mems.rotation);
|
||||||
|
scale = tableBuilder.Cache(Mems.scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ScaleTable : EcsTable
|
||||||
|
{
|
||||||
|
public readonly EcsPool<Vector3> position;
|
||||||
|
public readonly EcsPool<Quaternion> rotation;
|
||||||
|
public readonly EcsPool<Vector3> scale;
|
||||||
|
|
||||||
|
public ScaleTable(ref TableBuilder tableBuilder) : base(ref tableBuilder)
|
||||||
|
{
|
||||||
|
position = tableBuilder.Cache(Mems.position);
|
||||||
|
rotation = tableBuilder.Cache(Mems.rotation);
|
||||||
|
scale = tableBuilder.Inc(Mems.scale);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user