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); }
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); } } } }
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)); }
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)); }
public ref T Entity(EGID entity) { ref var sveltoDictionary = ref _dic.GetValueByRef(entity.groupID);
public EntityComponentInitializer(EGID id, FasterDictionary <RefWrapperType, ITypeSafeDictionary> group) { _group = group; _ID = id; }
void QueueRemoveEntityOperation(EGID entityEGID, IComponentBuilder[] componentBuilders, string caller) { _entitiesOperations.AddRemoveOperation(entityEGID, componentBuilders, caller); }
public EntityStructInitializer(EGID id, Dictionary <Type, ITypeSafeDictionary> current) { _current = current; _id = id; }
///-------------------------------------------- /// 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); } } } }
internal static void BuildEntityView(EGID ID, out T entityView) { entityView = new T { ID = ID }; }
public void PublishEntityChange <T>(EGID egid) where T : unmanaged, IEntityComponent { _entityStream.PublishEntity(ref this.QueryEntity <T>(egid), egid); }
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); }
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)); }
///-------------------------------------------- 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); }
void QueueSwapEntityOperation (EGID fromID, EGID toID, IComponentBuilder[] componentBuilders, string caller) { _entitiesOperations.AddSwapOperation(fromID, toID, componentBuilders, caller); }
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); }