From b565510a69e304a3a7955b520958cf8fea27bae3 Mon Sep 17 00:00:00 2001 From: Mikhail <99481254+DCFApixels@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:50:31 +0800 Subject: [PATCH] fix changes --- src/EcsRelationTable.cs | 57 ++++++++++++++++++++++ src/Interfaces/IEcsEntityComponentTable.cs | 50 +++++++++++++++++++ src/rel.cs | 29 +++++++++++ 3 files changed, 136 insertions(+) create mode 100644 src/EcsRelationTable.cs create mode 100644 src/Interfaces/IEcsEntityComponentTable.cs create mode 100644 src/rel.cs diff --git a/src/EcsRelationTable.cs b/src/EcsRelationTable.cs new file mode 100644 index 0000000..457980c --- /dev/null +++ b/src/EcsRelationTable.cs @@ -0,0 +1,57 @@ +using DCFApixels.DragonECS; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEditorInternal; + +namespace DCFApixels.Assets.DragonECS.src +{ + public class EcsRelationTable + { + public readonly IEcsWorld leftWorld; + public readonly IEcsWorld rightWorld; + + + private int[] _relationEntities; //dense + private int[] _leftMapping; + private int[] _rgihtMapping; + + private int _relationsCount; + + + #region Properties + public int RelationsCount + { + get => _relationsCount; + } + #endregion + + + internal EcsRelationTable(IEcsWorld leftWorld, IEcsWorld rightWorld) + { + this.leftWorld = leftWorld; + this.rightWorld = rightWorld; + + _relationEntities = new int[512]; + _leftMapping = new int[512]; + _rgihtMapping = new int[512]; + + _relationsCount = 0; + } + + public void AddRelation(int leftEnttiyID, int rightEntityID) + { + + } + public void RemoveRelationLeft(int entityID) + { + + } + public void RemoveRelationRight(int entityID) + { + + } + } +} diff --git a/src/Interfaces/IEcsEntityComponentTable.cs b/src/Interfaces/IEcsEntityComponentTable.cs new file mode 100644 index 0000000..d119050 --- /dev/null +++ b/src/Interfaces/IEcsEntityComponentTable.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DCFApixels.DragonECS +{ + public interface IEcsEntityComponentTable + { + #region Properties + public bool IsEmpty { get; } + public Type ArchetypeType { get; } + //public int ID { get; } + public int EntitesCount { get; } + public int EntitesCapacity { get; } + #endregion + + #region GetterMethods + public ReadOnlySpan GetAllPools(); + + #endregion + + #region Methods + public EcsPool GetPool() where T : struct; + public EcsPool UncheckedGetPool() where T : struct; + + public EcsFilter Entities() where TComponent : struct; + public EcsFilter Filter() where TInc : struct, IInc; + public EcsFilter Filter() where TInc : struct, IInc where TExc : struct, IExc; + + public ent NewEntity(); + public void DelEntity(ent entity); + public bool EntityIsAlive(int entityID, short gen); + public ent GetEntity(int entityID); + public void Destroy(); + + public bool IsMaskCompatible(int entity) where TInc : struct, IInc; + public bool IsMaskCompatible(int entity) where TInc : struct, IInc where TExc : struct, IExc; + public bool IsMaskCompatible(EcsMask mask, int entity); + public bool IsMaskCompatibleWithout(EcsMask mask, int entity, int otherPoolID); + + internal void OnEntityComponentAdded(int entityID, int changedPoolID); + internal void OnEntityComponentRemoved(int entityID, int changedPoolID); + + public int GetComponentID(); + internal void RegisterGroup(EcsGroup group); + #endregion + } +} diff --git a/src/rel.cs b/src/rel.cs new file mode 100644 index 0000000..be53451 --- /dev/null +++ b/src/rel.cs @@ -0,0 +1,29 @@ +using System; +using System.ComponentModel; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +namespace DCFApixels.DragonECS.TODO +{ + //TODO реализовать систему отношений. + //идея есть миры-коннекторы, они являются наборами сущьностей-отношений + //сущьности отношения, это теже сущьности но их полный идентификатор - это 32 бита - одна сущьность и 32 - другая + //айди миров левой и правой части записываются в мир-коннектор и для конвертации айди сущьности в полный идентификатор, надо взять данные из него. + //Проблема: если хранить айди мира для левой части отношения в одном месте, а для правого в другом и только раграничивать на лево и право будет проблема с тем что связи работают только в одном направлении + //в этом мире вообще не будет вестиь учет гена, потому что для отношений он не нужен + + //миры коннекторы можно назвать Relations или RealtionTable + + + + // left entity id - 32 bits + // right entity id - 32 bits + [StructLayout(LayoutKind.Explicit, Pack = 4, Size = 8)] + public struct rel + { + [FieldOffset(0)] + public int l; + [FieldOffset(1)] + public int r; + } +}