Exemplo n.º 1
0
        public void MoveEntity(NodeType entity, ref RectangleF oldBounds, ref RectangleF newBounds)
        {
            var oldPoints = GetPointRange(ref oldBounds);
            var newPoints = GetPointRange(ref newBounds);

            if (oldPoints.p == newPoints.p && oldPoints.pEnd == newPoints.pEnd)
            {
                return;
            }

            RemoveEntity(entity, ref oldBounds);
            InsertEntity(entity, ref newBounds);
        }
Exemplo n.º 2
0
        public void RemoveEntity(NodeType entity, ref RectangleF bounds)
        {
            var p    = new Point2(bounds.X / CELL_SIZE, bounds.Y / CELL_SIZE);
            var pEnd = new Point2((bounds.X + bounds.Width) / CELL_SIZE, (bounds.Y + bounds.Height) / CELL_SIZE);

            for (; p.X <= pEnd.X; p.X++)
            {
                for (; p.Y <= pEnd.Y; p.Y++)
                {
                    if (nodes.TryGetValue(p, out var node))
                    {
                        node.Remove(entity);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void InsertEntity(NodeType entity, ref RectangleF bounds)
        {
            var p    = new Point2(bounds.X / CELL_SIZE, bounds.Y / CELL_SIZE);
            var pEnd = new Point2((bounds.X + bounds.Width) / CELL_SIZE, (bounds.Y + bounds.Height) / CELL_SIZE);

            for (; p.X <= pEnd.X; p.X++)
            {
                for (; p.Y <= pEnd.Y; p.Y++)
                {
                    GridNode <NodeType> gridNode;
                    if (nodes.ContainsKey(p))
                    {
                        gridNode = nodes[p];
                    }
                    else
                    {
                        gridNode = new GridNode <NodeType>();
                        nodes.Add(p, gridNode);
                    }

                    gridNode.Insert(entity);
                }
            }
        }
 public EntityInitializer BuildEntity(EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable <object> implementors = null)
 {
     return(_enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors));
 }
Exemplo n.º 5
0
 public void RemoveEntityFromFilter <T>(int filtersID, EGID egid) where T : struct, IEntityComponent
 {
     ref var filter = ref GetFilterForGroup <T>(filtersID, egid.groupID);
        public static ref T QueryEntity <T>(this EntitiesDB entitiesDb, EGID entityGID) where T : unmanaged, IEntityComponent
        {
            var array = entitiesDb.QueryEntitiesAndIndex <T>(entityGID, out var index);

            return(ref array[(int)index]);
 public EntityInitializer BuildEntity <T>
     (EGID egid, T entityDescriptor, IEnumerable <object> implementors) where T : IEntityDescriptor
 {
     return(_enginesRoot.Target.BuildEntity(egid, entityDescriptor.componentsToBuild, TypeCache <T> .type, implementors));
 }
 public void SwapEntityGroup <T>(EGID fromID, ExclusiveGroup.ExclusiveGroupStruct toGroupID)
     where T : IEntityDescriptor, new()
 {
     SwapEntityGroup <T>(fromID, new EGID(fromID.entityID, (uint)toGroupID));
 }
Exemplo n.º 9
0
 public ref T Entity(EGID entity)
 {
     ref var sveltoDictionary = ref _dic.GetValueByRef(entity.groupID);
Exemplo n.º 10
0
 public EntityComponentInitializer(EGID id, FasterDictionary <RefWrapperType, ITypeSafeDictionary> group)
 {
     _group = group;
     _ID    = id;
 }
Exemplo n.º 11
0
 void QueueRemoveEntityOperation(EGID entityEGID, IComponentBuilder[] componentBuilders, string caller)
 {
     _entitiesOperations.AddRemoveOperation(entityEGID, componentBuilders, caller);
 }
Exemplo n.º 12
0
 public EntityStructInitializer(EGID id, Dictionary <Type, ITypeSafeDictionary> current)
 {
     _current = current;
     _id      = id;
 }
Exemplo n.º 13
0
        ///--------------------------------------------
        ///
        void MoveEntity(IEntityBuilder[] entityBuilders, EGID fromEntityGID, Type originalDescriptorType, EGID?toEntityGID)
        {
            var profiler = new PlatformProfiler();

            using (profiler.StartNewSession("Move Entity"))
            {
                //for each entity view generated by the entity descriptor
                if (_groupEntityDB.TryGetValue(fromEntityGID.groupID, out var fromGroup) == false)
                {
                    throw new ECSException("from group not found eid: ".FastConcat(fromEntityGID.entityID)
                                           .FastConcat(" group: ").FastConcat(fromEntityGID.groupID));
                }

                //Check if there is an EntityInfoView linked to this entity, if so it's a DynamicEntityDescriptor!
                bool correctEntityDescriptorFound = true;

                EntityStructInfoView entityInfoView = default;
                if (fromGroup.TryGetValue(ENTITY_INFO_VIEW_TYPE, out var entityInfoViewDic) &&
                    (entityInfoViewDic as TypeSafeDictionary <EntityStructInfoView>).TryGetValue(
                        fromEntityGID.entityID, out entityInfoView) && (correctEntityDescriptorFound =
                                                                            entityInfoView.type == originalDescriptorType))
                {
                    var entitiesToMove = entityInfoView.entitiesToBuild;

                    Dictionary <Type, ITypeSafeDictionary> toGroup = null;

                    if (toEntityGID != null)
                    {
                        var toGroupID = toEntityGID.Value.groupID;

                        if (_groupEntityDB.TryGetValue(toGroupID, out toGroup) == false)
                        {
                            toGroup = _groupEntityDB[toGroupID] = new Dictionary <Type, ITypeSafeDictionary>();
                        }
                    }

                    for (int i = 0; i < entitiesToMove.Length; i++)
                    {
                        MoveEntityView(fromEntityGID, toEntityGID, toGroup, ref fromGroup,
                                       entitiesToMove[i].GetEntityType(), profiler);
                    }
                }
                //otherwise it's a normal static entity descriptor
                else
                {
#if DEBUG && !PROFILER
                    if (correctEntityDescriptorFound == false)
                    {
                        throw new ECSException(INVALID_DYNAMIC_DESCRIPTOR_ERROR.FastConcat(" ID ").FastConcat(fromEntityGID.entityID)
                                               .FastConcat(" group ID ").FastConcat(fromEntityGID.groupID).FastConcat(
                                                   " descriptor found: ", entityInfoView.type.Name, " descriptor Excepted ",
                                                   originalDescriptorType.Name));
                    }
#endif

                    Dictionary <Type, ITypeSafeDictionary> toGroup = null;
                    if (toEntityGID != null)
                    {
                        var toGroupID = toEntityGID.Value.groupID;

                        if (_groupEntityDB.TryGetValue(toGroupID, out toGroup) == false)
                        {
                            toGroup = _groupEntityDB[toGroupID] = new Dictionary <Type, ITypeSafeDictionary>();
                        }
                    }

                    for (var i = 0; i < entityBuilders.Length; i++)
                    {
                        MoveEntityView(fromEntityGID, toEntityGID, toGroup, ref fromGroup,
                                       entityBuilders[i].GetEntityType(), profiler);
                    }
                }
            }
        }
Exemplo n.º 14
0
 internal static void BuildEntityView(EGID ID, out T entityView)
 {
     entityView = new T {
         ID = ID
     };
 }
Exemplo n.º 15
0
 public void PublishEntityChange <T>(EGID egid) where T : unmanaged, IEntityComponent
 {
     _entityStream.PublishEntity(ref this.QueryEntity <T>(egid), egid);
 }
Exemplo n.º 16
0
 public void SwapEntityGroup <T>
     (EGID fromEGID, ExclusiveBuildGroup toGroupID, [CallerMemberName] string caller = null)
     where T : IEntityDescriptor, new()
 {
     SwapEntityGroup <T>(fromEGID, new EGID(fromEGID.entityID, toGroupID), caller);
 }
Exemplo n.º 17
0
 public bool IsEqualTo(EGID otherGID)
 {
     return(otherGID._GID == _GID);
 }
 public EGID SwapEntityGroup <T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
 {
     return(_weakReference.Target.SwapEntityGroup <T>(id.entityID, id.groupID, (int)toGroupID));
 }
Exemplo n.º 19
0
        ///--------------------------------------------
        void SwapEntityGroup(IEntityBuilder[] builders, Type originalEntityDescriptor, EGID fromEntityID,
                             EGID toEntityID)
        {
            DBC.ECS.Check.Require(fromEntityID.groupID != toEntityID.groupID,
                                  "entity group is the same of the destination group");

            MoveEntity(builders, fromEntityID, originalEntityDescriptor, toEntityID);
        }
Exemplo n.º 20
0
 void QueueSwapEntityOperation
     (EGID fromID, EGID toID, IComponentBuilder[] componentBuilders, string caller)
 {
     _entitiesOperations.AddSwapOperation(fromID, toID, componentBuilders, caller);
 }
Exemplo n.º 21
0
 EntityStructInitializer BuildEntity <T>(EGID entityID, object[] implementors) where T : IEntityDescriptor, new()
 {
     return(BuildEntity(entityID, EntityDescriptorTemplate <T> .descriptor, implementors));
 }
 public void RemoveEntity <T>(EGID entityEGID) where T : IEntityDescriptor, new()
 {
     _weakReference.Target.MoveEntity <T>(entityEGID);
 }