IEnumerator PollForInput() { while (true) { while (_buttonConsumer.TryDequeue(out var entity)) { if (entity.message == ButtonEvents.SELECT) { IGuiViewIndex guiViewIndex = entitiesDB.QueryEntity <GuiViewIndexEntityViewComponent>(entity.ID).guiViewIndex; ExclusiveGroupStruct group = entity.ID.groupID; if (string.IsNullOrEmpty(guiViewIndex.groupName) == false) { group = ExclusiveGroup.Search(guiViewIndex.groupName); } var(entities, count) = entitiesDB.QueryEntities <GUIEntityViewComponent>(@group); for (int i = 0; i < count; i++) { entities[i].guiRoot.view = guiViewIndex.index; } } } yield return(null); } }
public void MovedTo(ref AiPath aiPath, ExclusiveGroupStruct previousGroup, EGID egid) { if (GroupTagExtensions.Contains <SUNK>(egid.groupID)) { aiPath.Waypoint = (uint)aiPath.Path.Count <uint>(); } }
public DebugGroup(ExclusiveGroupStruct key, FasterDictionary <RefWrapperType, ITypeSafeDictionary> val, DebugRoot debugRoot) { Id = key; GroupDB = val; Parent = debugRoot; Process(); }
internal static NativeEGIDMapper <T> ToNativeEGIDMapper <T>(this TypeSafeDictionary <T> dic, ExclusiveGroupStruct groupStructId) where T : unmanaged, IEntityComponent { var mapper = new NativeEGIDMapper <T>(groupStructId, dic.implUnmgd); return(mapper); }
JobHandle CreateJobForDoofusesAndFood (JobHandle inputDeps, FasterList <ExclusiveGroupStruct> doofusesGroups, ExclusiveGroupStruct swapGroup , ExclusiveGroupStruct foodGroup) { if (entitiesDB.TryQueryNativeMappedEntities <PositionEntityComponent>(foodGroup, out var foodPositionMapper) == false) { return(inputDeps); } var doofusesEntityGroups = entitiesDB .QueryEntities <PositionEntityComponent, VelocityEntityComponent, MealInfoComponent, EGIDComponent>(doofusesGroups); //against all the doofuses foreach (var doofusesBuffer in doofusesEntityGroups.groups) { var doofusesCount = doofusesBuffer.count; //schedule the job var deps = new ConsumingFoodJob(doofusesBuffer.ToFast(), foodPositionMapper, _nativeSwap, _nativeRemove, swapGroup) .ScheduleParallel(doofusesCount, inputDeps); inputDeps = JobHandle.CombineDependencies(deps, inputDeps); } return(inputDeps); }
internal static NativeEGIDMapper <T> ToNativeEGIDMapper <T>(this TypeSafeDictionary <T> dic, ExclusiveGroupStruct groupStructId) where T : unmanaged, IEntityStruct { var mapper = new NativeEGIDMapper <T>(groupStructId, dic.implementation.ToNative <uint, T>()); return(mapper); }
internal static EGIDMapper <T> ToEGIDMapper <T>(this ITypeSafeDictionary <T> dic, ExclusiveGroupStruct groupStructId) where T : struct, IBaseEntityComponent { var mapper = new EGIDMapper <T>(groupStructId, dic); return(mapper); }
public QueryGroups(ExclusiveGroupStruct group) { var groupsValue = groups.Value; groupsValue.Reset(); groupsValue.Add(group); }
public void MovedTo(ref ShipViewComponent shipView, ExclusiveGroupStruct previousGroup, EGID egid) { if (GroupTagExtensions.Contains <SUNK>(egid.groupID)) { Respawn(shipView, egid).Run(); } }
public WaitForEntitiesInGroupEnumerator(ExclusiveGroupStruct group, EntitiesDB entitiesDB) { var groups = new FasterList <ExclusiveGroupStruct>(new [] { group }); _groups = new FasterReadOnlyList <ExclusiveGroupStruct>(groups); _entitiesDB = entitiesDB; }
public void MovedTo(ref EnemyEntityViewComponent entityComponent, ExclusiveGroupStruct previousGroup, EGID egid) { if (previousGroup == ECSGroups.EnemiesDeadGroup) { _numberOfEnemyToSpawn++; } }
static uint InternalBuildAll(uint startIndex, IEntityDescriptorHolder descriptorHolder, IEntityFactory factory, ExclusiveGroup group, IImplementor[] implementors, string groupNamePostfix) { ExclusiveGroupStruct realGroup = group; if (string.IsNullOrEmpty(descriptorHolder.groupName) == false) { realGroup = ExclusiveGroup.Search(!string.IsNullOrEmpty(groupNamePostfix) ? $"{descriptorHolder.groupName}{groupNamePostfix}" : descriptorHolder.groupName); } EGID egid; var holderId = descriptorHolder.id; if (holderId == 0) { egid = new EGID(startIndex++, realGroup); } else { egid = new EGID(holderId, realGroup); } var init = factory.BuildEntity(egid, descriptorHolder.GetDescriptor(), implementors); init.Init(new EntityHierarchyComponent(group)); return(startIndex); }
JobHandle CreateJobForDoofusesAndFood (JobHandle inputDeps, FasterList <ExclusiveGroupStruct> foodGroups, FasterList <ExclusiveGroupStruct> doofusesGroups , ExclusiveGroupStruct swapDoofuseGroup, ExclusiveGroupStruct swapFoodGroup) { JobHandle deps = inputDeps; foreach (var foodgroup in entitiesDB.QueryEntities <EGIDComponent>(foodGroups).groups) { foreach (var doofusesGroup in entitiesDB.QueryEntities <MealInfoComponent, EGIDComponent>(doofusesGroups).groups) { var doofusesCount = doofusesGroup.count; var foodCount = foodgroup.count; if (foodCount == 0 || doofusesCount == 0) { return(inputDeps); } var willEatDoofuses = math.min(foodCount, doofusesCount); //schedule the job deps = new LookingForFoodDoofusesJob() { _doofuses = doofusesGroup.ToFast() , _food = foodgroup.ToFast() , _nativeDoofusesSwap = _nativeDoofusesSwap , _nativeFoodSwap = _nativeFoodSwap , _doofuseMealLockedGroup = swapDoofuseGroup , _lockedFood = swapFoodGroup }.ScheduleParallel(willEatDoofuses, deps); } } return(deps); }
public void MovedTo(ref CoinViewComponent view, ExclusiveGroupStruct previousGroup, EGID egid) { var mapper = entitiesDB.QueryMappedEntities <GridCellComponent>(GridGroups.GridWaterGroup); // Free the corresponding grid cell when a coin gets recycled. if (egid.groupID == CoinGroups.RecycledCoinsGroup) { var cellId = new EGID(_gridUtils.WorldToEnitityId(view.Transform.Position.xy), GridGroups.GridWaterGroup); if (entitiesDB.Exists <GridCellComponent>(cellId) == false) { return; } _freeCellFilter.Add(cellId.entityID, mapper); } else if (egid.groupID == CoinGroups.SpawnedCoinsGroup) { var cellId = new EGID(_gridUtils.WorldToEnitityId(view.Transform.Position.xy), GridGroups.GridWaterGroup); if (entitiesDB.Exists <GridCellComponent>(cellId) == false) { return; } _freeCellFilter.Remove(cellId.entityID); } }
public void MovedTo(ref CoinComponent coin, ExclusiveGroupStruct previousGroup, EGID egid) { if (egid.groupID == CoinGroups.SpawnedCoinsGroup) { coin.Picked = false; coin.TimeToRespawn = _coinDefinition.CoinsSpawnTime; } }
public void MovedTo(ref ShipLevelComponent level, ExclusiveGroupStruct previousGroup, EGID egid) { if (GroupTagExtensions.Contains <SUNK>(egid.groupID)) { level.Level = ShipLevel.Normal; level.NextLevel = ShipLevel.Normal; } }
public void MovedTo(ref UnityEcsEntityComponent entityComponent, ExclusiveGroupStruct previousGroup, EGID egid) { #if USE_ENTITY_MANAGER EntityManager.SetSharedComponentData(entityComponent.uecsEntity, new UECSSveltoGroupID(egid.groupID)); #else ECB.SetSharedComponent(entityComponent.uecsEntity, new UECSSveltoGroupID(egid.groupID)); #endif }
public QueryGroups(ExclusiveGroupStruct findGroups) { var groupsValue = groups.Value; var group = groupsValue.reference; group.FastClear(); group.Add(findGroups); }
protected EntityInitializer CreateTestEntity(uint entityId, ExclusiveGroupStruct group, int value = 1) { var initializer = _factory.BuildEntity <EntityDescriptorWithComponentAndViewComponent> (entityId, group, new object[] { new TestFloatValue(value), new TestIntValue(value) }); initializer.Init(new TestEntityComponent(value, value)); return(initializer); }
public QueryGroups Except(ExclusiveGroupStruct group) { var groupsValue = groups.Value; groupsValue.Exclude(group); return(this); }
public QueryGroups Union(ExclusiveGroupStruct group) { var groupsValue = groups.Value; groupsValue.Add(group); return(this); }
/// <summary> /// One of the available form of communication in Svelto.ECS: React On Swap allow to do what it says /// </summary> /// <param name="enemyView"></param> /// <param name="previousGroup"></param> /// <param name="egid"></param> public void MovedTo(ref EnemyEntityViewComponent enemyView, ExclusiveGroupStruct previousGroup, EGID egid) { if (egid.groupID == ECSGroups.EnemiesDeadGroup) { enemyView.layerComponent.layer = GAME_LAYERS.NOT_SHOOTABLE_MASK; enemyView.movementComponent.navMeshEnabled = false; enemyView.movementComponent.setCapsuleAsTrigger = true; } }
public NativeEGIDMapper (ExclusiveGroupStruct groupStructId , SveltoDictionary <uint, T, NativeStrategy <SveltoDictionaryNode <uint> >, NativeStrategy <T>, NativeStrategy <int> > toNative) : this() { groupID = groupStructId; _map = new SveltoDictionaryNative <uint, T>(); _map.UnsafeCast(toNative); }
static FasterDictionary <RefWrapperType, ITypeSafeDictionary> FetchEntityGroup (ExclusiveGroupStruct groupID, EnginesRoot.DoubleBufferedEntitiesToAdd groupEntityComponentsByType) { var group = groupEntityComponentsByType.current.GetOrCreate( groupID, () => new FasterDictionary <RefWrapperType, ITypeSafeDictionary>()); //track the number of entities created so far in the group. groupEntityComponentsByType.IncrementEntityCount(groupID); return(group); }
public void MovedTo(ref CoinViewComponent coinView, ExclusiveGroupStruct previousGroup, EGID egid) { if (egid.groupID == CoinGroups.RecycledCoinsGroup) { coinView.Renderer.Render = false; } else { EnableCoin(coinView).Run(); } }
/// <summary> /// MovedTo callbacks are enabled by the IReactOnSwap interface /// They are called on entity swap (when leaving a group and moving to the new one) /// </summary> /// <param name="entityViewComponent"></param> public void MovedTo (ref EnemyEntityViewComponent entityViewComponent, ExclusiveGroupStruct previousGroup, EGID egid) { if (egid.groupID == ECSGroups.EnemiesGroup) { entityViewComponent.targetTriggerComponent.hitChange.ResumeNotify(); } else { entityViewComponent.targetTriggerComponent.hitChange.PauseNotify(); } }
public static bool Contains <T>(ExclusiveGroupStruct target) where T : GroupTag <T> { var groups = GroupTag <T> .Groups; foreach (var group in groups) { if (group == target) { return(true); } } return(false); }
static FasterDictionary <RefWrapperType, ITypeSafeDictionary> FetchEntityGroup (ExclusiveGroupStruct groupID, EnginesRoot.DoubleBufferedEntitiesToAdd groupEntityComponentsByType) { if (groupEntityComponentsByType.current.TryGetValue((uint)groupID, out var group) == false) { group = new FasterDictionary <RefWrapperType, ITypeSafeDictionary>(); groupEntityComponentsByType.current.Add((uint)groupID, group); } //track the number of entities created so far in the group. groupEntityComponentsByType.IncrementEntityCount(groupID); return(group); }
public static ExclusiveGroupStruct AddTag <T>(this ExclusiveGroupStruct group) where T : GroupTag <T> { if (_addTransitions.TryGetValue(group, out var transitions)) { var type = new RefWrapper <Type>(typeof(T)); if (transitions.TryGetValue(type, out var result)) { return(result); } } throw new ECSException("No add transition found for type " .FastConcat(typeof(T).ToString()) .FastConcat(" in group ").FastConcat(group) ); }
public void MovedTo(ref ShipViewComponent entityComponent, ExclusiveGroupStruct previousGroup, EGID egid) { if (GroupTagExtensions.Contains <SUNK>(egid.groupID)) { entityComponent.Renderer.Render = false; entityComponent.Renderer.Sprite = (int)ShipLevel.Normal; entityComponent.Physics.Enable = false; entityComponent.Explosion.Play = true; entityComponent.Audio.PlayOneShot = ShipAudioType.Sink; entityComponent.CoinsHud.Visibility = false; } else { entityComponent.Explosion.Play = false; } }