コード例 #1
0
ファイル: SpatialGrid.cs プロジェクト: versus-fm/walker
        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);
        }
コード例 #2
0
ファイル: SpatialGrid.cs プロジェクト: versus-fm/walker
        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);
                    }
                }
            }
        }
コード例 #3
0
ファイル: SpatialGrid.cs プロジェクト: versus-fm/walker
        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);
                }
            }
        }
コード例 #4
0
 public EntityInitializer BuildEntity(EGID egid, IComponentBuilder[] componentsToBuild, Type type, IEnumerable <object> implementors = null)
 {
     return(_enginesRoot.Target.BuildEntity(egid, componentsToBuild, type, implementors));
 }
コード例 #5
0
 public void RemoveEntityFromFilter <T>(int filtersID, EGID egid) where T : struct, IEntityComponent
 {
     ref var filter = ref GetFilterForGroup <T>(filtersID, egid.groupID);
コード例 #6
0
        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]);
コード例 #7
0
 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));
 }
コード例 #8
0
 public void SwapEntityGroup <T>(EGID fromID, ExclusiveGroup.ExclusiveGroupStruct toGroupID)
     where T : IEntityDescriptor, new()
 {
     SwapEntityGroup <T>(fromID, new EGID(fromID.entityID, (uint)toGroupID));
 }
コード例 #9
0
 public ref T Entity(EGID entity)
 {
     ref var sveltoDictionary = ref _dic.GetValueByRef(entity.groupID);
コード例 #10
0
 public EntityComponentInitializer(EGID id, FasterDictionary <RefWrapperType, ITypeSafeDictionary> group)
 {
     _group = group;
     _ID    = id;
 }
コード例 #11
0
 void QueueRemoveEntityOperation(EGID entityEGID, IComponentBuilder[] componentBuilders, string caller)
 {
     _entitiesOperations.AddRemoveOperation(entityEGID, componentBuilders, caller);
 }
コード例 #12
0
 public EntityStructInitializer(EGID id, Dictionary <Type, ITypeSafeDictionary> current)
 {
     _current = current;
     _id      = id;
 }
コード例 #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);
                    }
                }
            }
        }
コード例 #14
0
ファイル: EntityView.cs プロジェクト: voidimage/Svelto.ECS
 internal static void BuildEntityView(EGID ID, out T entityView)
 {
     entityView = new T {
         ID = ID
     };
 }
コード例 #15
0
 public void PublishEntityChange <T>(EGID egid) where T : unmanaged, IEntityComponent
 {
     _entityStream.PublishEntity(ref this.QueryEntity <T>(egid), egid);
 }
コード例 #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);
 }
コード例 #17
0
ファイル: EGID.cs プロジェクト: MadBanny/Svelto.ECS-Tanks
 public bool IsEqualTo(EGID otherGID)
 {
     return(otherGID._GID == _GID);
 }
コード例 #18
0
 public EGID SwapEntityGroup <T>(EGID id, ExclusiveGroup toGroupID) where T : IEntityDescriptor, new()
 {
     return(_weakReference.Target.SwapEntityGroup <T>(id.entityID, id.groupID, (int)toGroupID));
 }
コード例 #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);
        }
コード例 #20
0
 void QueueSwapEntityOperation
     (EGID fromID, EGID toID, IComponentBuilder[] componentBuilders, string caller)
 {
     _entitiesOperations.AddSwapOperation(fromID, toID, componentBuilders, caller);
 }
コード例 #21
0
 EntityStructInitializer BuildEntity <T>(EGID entityID, object[] implementors) where T : IEntityDescriptor, new()
 {
     return(BuildEntity(entityID, EntityDescriptorTemplate <T> .descriptor, implementors));
 }
コード例 #22
0
 public void RemoveEntity <T>(EGID entityEGID) where T : IEntityDescriptor, new()
 {
     _weakReference.Target.MoveEntity <T>(entityEGID);
 }