mirror of
https://github.com/DCFApixels/DragonECS.git
synced 2025-09-17 09:24:37 +08:00
Update WIP, add table members
This commit is contained in:
parent
491e8069c3
commit
2c6fac98fb
@ -4,7 +4,7 @@
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
|
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public struct EcsField<T>
|
||||
{
|
||||
private EcsFieldPool<T> _pool;
|
||||
public ref T this[int index]
|
||||
{
|
||||
get => ref _pool[index];
|
||||
}
|
||||
}
|
||||
}
|
@ -12,14 +12,11 @@ namespace DCFApixels.DragonECS
|
||||
}
|
||||
public class EcsFieldPool<T> : IEcsFieldPool
|
||||
{
|
||||
private int _id;
|
||||
private SparseSet _sparseSet;
|
||||
private T[] _denseItems;
|
||||
|
||||
public EcsFieldPool(int capacity)
|
||||
{
|
||||
_denseItems = new T[capacity];
|
||||
_sparseSet = new SparseSet(capacity);
|
||||
}
|
||||
public int ID => _id;
|
||||
|
||||
public ref T this[int index]
|
||||
{
|
||||
@ -27,6 +24,12 @@ namespace DCFApixels.DragonECS
|
||||
get => ref _denseItems[_sparseSet[index]];
|
||||
}
|
||||
|
||||
public EcsFieldPool(int capacity)
|
||||
{
|
||||
_denseItems = new T[capacity];
|
||||
_sparseSet = new SparseSet(capacity);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref T Add(int index)
|
||||
{
|
||||
|
68
src/EcsTableCore.cs
Normal file
68
src/EcsTableCore.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public abstract class EcsTableCore
|
||||
{
|
||||
internal EcsWorld _source;
|
||||
internal ent entity;
|
||||
|
||||
private bool _enabled = false;
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ent Entity
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => entity;
|
||||
}
|
||||
|
||||
internal void Enable()
|
||||
{
|
||||
_enabled = true;
|
||||
}
|
||||
|
||||
internal void Disable()
|
||||
{
|
||||
_enabled = false;
|
||||
entity = ent.NULL;
|
||||
}
|
||||
|
||||
internal void MoveToNextEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Enumerator GetEnumerator()
|
||||
{
|
||||
return new Enumerator(this);
|
||||
}
|
||||
|
||||
|
||||
public ref struct Enumerator
|
||||
{
|
||||
private readonly EcsTableCore _source;
|
||||
|
||||
public Enumerator(EcsTableCore source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
public EcsTableCore Current => _source;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -71,7 +71,7 @@ namespace DCFApixels.DragonECS
|
||||
#region Destroy
|
||||
public void Destroy()
|
||||
{
|
||||
_id = Consts.DEAD_WORLD_ID;
|
||||
_id = DEAD_WORLD_ID;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -6,8 +6,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public interface IEcsEntityTable
|
||||
{
|
||||
|
||||
}
|
||||
public interface IEcsTable { }
|
||||
}
|
||||
|
11
src/Interfaces/IEcsTable.cs.meta
Normal file
11
src/Interfaces/IEcsTable.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce8e0e17f18931e4284946bddba80e02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
src/TableMembers.meta
Normal file
8
src/TableMembers.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35dbc0eb7d0449242a40ddcb8cbdbc06
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
103
src/TableMembers/EcsField.cs
Normal file
103
src/TableMembers/EcsField.cs
Normal file
@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public readonly struct EcsField<T> : IEcsMemberCachePool<EcsField<T>, T>
|
||||
{
|
||||
private readonly EcsFieldPool<T> _pool;
|
||||
private readonly int _poolID;
|
||||
|
||||
public EcsFieldPool<T> Pool => _pool;
|
||||
public int PoolID => _poolID;
|
||||
|
||||
private EcsField(int poolID)
|
||||
{
|
||||
_pool = null;
|
||||
_poolID = poolID;
|
||||
}
|
||||
internal EcsField(EcsFieldPool<T> pool)
|
||||
{
|
||||
_pool = pool;
|
||||
_poolID = pool.ID;
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ref T this[int entityID]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref _pool[entityID];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool HasValue(int entityID)
|
||||
{
|
||||
return _pool.Has(entityID);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ref T New(int entityID)
|
||||
{
|
||||
return ref _pool.Add(entityID);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsField<T>(in int poolID) => new EcsField<T>(poolID);
|
||||
|
||||
void IEcsMemberCachePool<EcsField<T>, T>.Inject(out EcsField<T> self, EcsFieldPool<T> pool)
|
||||
{
|
||||
self = new EcsField<T>(pool);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct EcsIncField<T> : IEcsMemberCachePool<EcsIncField<T>, T>
|
||||
{
|
||||
private readonly EcsFieldPool<T> _pool;
|
||||
private readonly int _poolID;
|
||||
|
||||
public EcsFieldPool<T> Pool => _pool;
|
||||
public int PoolID => _poolID;
|
||||
|
||||
private EcsIncField(int poolID)
|
||||
{
|
||||
_pool = null;
|
||||
_poolID = poolID;
|
||||
}
|
||||
internal EcsIncField(EcsFieldPool<T> pool)
|
||||
{
|
||||
_pool = pool;
|
||||
_poolID = pool.ID;
|
||||
}
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public ref T this[int entityID]
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => ref _pool[entityID];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsIncField<T>(in int poolID) => new EcsIncField<T>(poolID);
|
||||
|
||||
void IEcsMemberCachePool<EcsIncField<T>, T>.Inject(out EcsIncField<T> self, EcsFieldPool<T> pool)
|
||||
{
|
||||
self = new EcsIncField<T>(pool);
|
||||
}
|
||||
}
|
||||
|
||||
public struct EcsExcField<T> : IEcsTableMember
|
||||
{
|
||||
private readonly int _poolID;
|
||||
public int PoolID => _poolID;
|
||||
|
||||
private EcsExcField(int poolID)
|
||||
{
|
||||
_poolID = poolID;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsExcField<T>(in int poolID) => new EcsExcField<T>(poolID);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2fa97ad86c494a40939307a2cfaca36
|
||||
guid: 93de2f9d4ed4cd849a2b4fca39174c37
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
66
src/TableMembers/EcsTag.cs
Normal file
66
src/TableMembers/EcsTag.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public readonly struct EcsTag<T> : IEcsMemberCachePool<EcsTag<T>, T>
|
||||
{
|
||||
private readonly EcsFieldPool<T> _pool;
|
||||
private readonly int _poolID;
|
||||
|
||||
public EcsFieldPool<T> Pool => _pool;
|
||||
public int PoolID => _poolID;
|
||||
|
||||
private EcsTag(int poolID)
|
||||
{
|
||||
_pool = null;
|
||||
_poolID = poolID;
|
||||
}
|
||||
internal EcsTag(EcsFieldPool<T> pool)
|
||||
{
|
||||
_pool = pool;
|
||||
_poolID = pool.ID;
|
||||
}
|
||||
|
||||
public void Add(int entityID)
|
||||
{
|
||||
_pool.Add(entityID);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsTag<T>(in int poolID) => new EcsTag<T>(poolID);
|
||||
|
||||
void IEcsMemberCachePool<EcsTag<T>, T>.Inject(out EcsTag<T> self, EcsFieldPool<T> pool)
|
||||
{
|
||||
self = new EcsTag<T>(pool);
|
||||
}
|
||||
}
|
||||
public readonly struct EcsIncTag<T> : IEcsTableMember
|
||||
{
|
||||
private readonly int _poolID;
|
||||
public int PoolID => _poolID;
|
||||
|
||||
private EcsIncTag(int poolID)
|
||||
{
|
||||
_poolID = poolID;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsIncTag<T>(in int poolID) => new EcsIncTag<T>(poolID);
|
||||
}
|
||||
public readonly struct EcsExcTag<T> : IEcsTableMember
|
||||
{
|
||||
private readonly int _poolID;
|
||||
public int PoolID => _poolID;
|
||||
|
||||
private EcsExcTag(int poolID)
|
||||
{
|
||||
_poolID = poolID;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator EcsExcTag<T>(in int poolID) => new EcsExcTag<T>(poolID);
|
||||
}
|
||||
}
|
11
src/TableMembers/EcsTag.cs.meta
Normal file
11
src/TableMembers/EcsTag.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 524f71e4e46e94a44b302e2242150817
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
src/TableMembers/IEcsTableMember.cs
Normal file
16
src/TableMembers/IEcsTableMember.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DCFApixels.DragonECS
|
||||
{
|
||||
public interface IEcsTableMember
|
||||
{
|
||||
public int PoolID { get; }
|
||||
}
|
||||
public interface IEcsMemberCachePool<TSelf, T> : IEcsTableMember
|
||||
where TSelf: struct, IEcsTableMember
|
||||
{
|
||||
public EcsFieldPool<T> Pool { get; }
|
||||
public void Inject(out TSelf self, EcsFieldPool<T> pool);
|
||||
}
|
||||
}
|
11
src/TableMembers/IEcsTableMember.cs.meta
Normal file
11
src/TableMembers/IEcsTableMember.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e765044f6e73f5847aa432da56a1ec9d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
35
src/ent.cs
35
src/ent.cs
@ -9,12 +9,12 @@ namespace DCFApixels.DragonECS
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 0, Size = 8)]
|
||||
public readonly struct ent : IEquatable<long>, IEquatable<ent>
|
||||
{
|
||||
//private const int ID_BITS = 32;
|
||||
//private const int GEN_BITS = 16;
|
||||
//private const int WORLD_BITS = 8;
|
||||
//private const int COM_BITS = 8;
|
||||
public static readonly long NULL = 0;
|
||||
|
||||
public readonly long _full;
|
||||
// id - 32 bits
|
||||
// gen - 16 bits
|
||||
// world - 8 bits
|
||||
public readonly long _full;
|
||||
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public int id
|
||||
@ -29,15 +29,18 @@ 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);
|
||||
get => (byte)(((_full << 48) >> 56) - 1);
|
||||
|
||||
}
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public byte com
|
||||
public byte type
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => (byte)((_full << 56) >> 56);
|
||||
@ -49,7 +52,7 @@ namespace DCFApixels.DragonECS
|
||||
{
|
||||
_full = ((long)id) << 32;
|
||||
_full += ((long)gen) << 16;
|
||||
_full += ((long)world) << 8;
|
||||
_full += ((long)(++world)) << 8; // сдвиг айдишников + 1
|
||||
_full += com;
|
||||
}
|
||||
|
||||
@ -59,12 +62,6 @@ namespace DCFApixels.DragonECS
|
||||
_full = value;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public TypeCode GetTypeCode()
|
||||
{
|
||||
return TypeCode.Int64;
|
||||
}
|
||||
|
||||
#region GetHashCode
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode()
|
||||
@ -110,4 +107,12 @@ namespace DCFApixels.DragonECS
|
||||
public static implicit operator ent(in long value) => new ent(value);
|
||||
#endregion
|
||||
}
|
||||
|
||||
public static class entExtensions
|
||||
{
|
||||
public static bool IsNull(this in ent self)
|
||||
{
|
||||
return self == ent.NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user