/// <summary> /// All the available doofuses will start to hunt for available food /// </summary> JobHandle CreateJobForDoofusesAndFood (JobHandle inputDeps, FasterReadOnlyList <ExclusiveGroupStruct> availableFood , FasterReadOnlyList <ExclusiveGroupStruct> availableDoofuses, ExclusiveBuildGroup eatingDoofusesGroup , ExclusiveBuildGroup eatenFoodGroup) { JobHandle combinedDeps = inputDeps; foreach (var((foodEntities, availableFoodCount), _) in entitiesDB.QueryEntities <EGIDComponent>( availableFood)) { foreach (var((doofuses, egids, doofusesCount), _) in entitiesDB .QueryEntities <MealInfoComponent, EGIDComponent>(availableDoofuses)) { var willEatDoofuses = math.min(availableFoodCount, doofusesCount); //schedule the job combinedDeps = JobHandle.CombineDependencies(combinedDeps, new LookingForFoodDoofusesJob() { _doofuses = doofuses , _doofusesegids = egids , _food = foodEntities , _nativeDoofusesSwap = _nativeDoofusesSwap , _nativeFoodSwap = _nativeFoodSwap , _doofuseMealLockedGroup = eatingDoofusesGroup , _lockedFood = eatenFoodGroup }.ScheduleParallel(willEatDoofuses, inputDeps)); } } return(combinedDeps); }
public WaitForEntitiesInGroupEnumerator(ExclusiveGroupStruct group, EntitiesDB entitiesDB) { var groups = new FasterList <ExclusiveGroupStruct>(new [] { group }); _groups = new FasterReadOnlyList <ExclusiveGroupStruct>(groups); _entitiesDB = entitiesDB; }
public QueryGroups Except(FasterReadOnlyList <ExclusiveGroupStruct> groupsToIgnore) { var groupsValue = groups.Value; groupsValue.Exclude(groupsToIgnore.ToArrayFast(out var count), count); return(this); }
IEnumerator WaitToEnableButtons() { yield return(_waitToEnableButtons); FasterReadOnlyList <ButtonEntityView> buttonEntityViews = entityViewsDB.QueryEntityViews <ButtonEntityView>(); for (int i = 0; i < buttonEntityViews.Count; ++i) { buttonEntityViews[i].UserMovementButtonComponent.IsInteractable = true; } }
IEnumerator CheckIfHittingEnemyTarget() { while (true) { FasterReadOnlyList <EnemyTargetEntityView> targetEntitiesView = entityViewsDB.QueryEntityViews <EnemyTargetEntityView>(); //there is a sneaky bug that can be caused by this routine. It can be solved in several //ways once it has been understood. //the targetDamageSequence.Next can trigger a sequence that could lead to the immediate //death of the player, this would mean that the inner loop should stop when the //enemytarget (the player) dies. However this engine doens't know when the player dies //We can solve this problem in several ways including //- iterating over the enemy target, if the entity has been removed because dead, the for will be skipped //(which is the solution I chose here) //- removing the entity the frame after and not immediatly (a bit hacky) //- add this engine in the sequencer to know when the player is death to stop //this taskroutine FasterReadOnlyList <EnemyEntityView> enemiesAttackList = entityViewsDB.QueryEntityViews <EnemyEntityView>(); for (int enemyIndex = enemiesAttackList.Count - 1; enemyIndex >= 0; --enemyIndex) { var enemyAttackEntityView = enemiesAttackList[enemyIndex]; EnemyCollisionData enemyCollisionData = enemyAttackEntityView.targetTriggerComponent.entityInRange; for (int enemyTargetIndex = 0; enemyTargetIndex < targetEntitiesView.Count; enemyTargetIndex++) { var targetEntityView = targetEntitiesView[enemyTargetIndex]; //the IEnemyTriggerComponent implementors sets a the collides boolean //whenever anything enters in the trigger range, but there is not more logic //we have to check here if the colliding entity is actually an EnemyTarget if (enemyCollisionData.collides == true && enemyCollisionData.otherEntityID == targetEntityView.ID) { var attackDamageComponent = enemyAttackEntityView.attackDamageComponent; attackDamageComponent.timer += _time.deltaTime; if (attackDamageComponent.timer >= attackDamageComponent.attackInterval) { attackDamageComponent.timer = 0.0f; var damageInfo = new DamageInfo(attackDamageComponent.damage, Vector3.zero, targetEntityView.ID, EntityDamagedType.EnemyTarget); _targetDamageSequence.Next(this, ref damageInfo); } } } } yield return(null); } }
private void OnPressed(int entity, UserMovementInfo userMovementInfo) { FasterReadOnlyList <ButtonEntityView> buttonEntityViews = entityViewsDB.QueryEntityViews <ButtonEntityView>(); userMovementInfo.entityID = entityViewsDB.QueryEntityViews <LocalUserView>()[0].ID; for (int i = 0; i < buttonEntityViews.Count; ++i) { buttonEntityViews[i].UserMovementButtonComponent.IsInteractable = false; } _localUserMovementSequence.Next(this, ref userMovementInfo); }
private IEnumerator Tick() { while (true) { _CameraTargetEntityViews = entityViewsDB.QueryEntityViews <CameraTargetEntityView>(); if (_CameraTargetEntityViews.Count > 0) { Move(); Zoom(); } yield return(null); } }
public static bool Exists <T>(this EntitiesDB db, uint entityId, FasterReadOnlyList <ExclusiveGroupStruct> groups) where T : struct, IEntityComponent { foreach (var group in groups) { if (db.Exists <T>(entityId, group)) { return(true); } } return(false); }
public Sequence(FasterReadOnlyList <T> itemsToSort) { _ordered = FasterList <T> .PreInit((uint)SequenceCache <En> .cachedEnum.Count); var counted = 0; var cachedEnum = SequenceCache <En> .cachedEnum; foreach (var item in itemsToSort) { var type = item.GetType(); Check.Require(type.IsDefined(typeof(SequencedAttribute)) , $"Sequenced item not tagged as Sequenced {type.Name}"); var typeName = type.GetCustomAttribute <SequencedAttribute>().name; Check.Require(cachedEnum.ContainsKey(typeName) , $"Sequenced item not contained in the sequence {typeof(En).Name}: {typeName}"); var index = cachedEnum[typeName]; counted++; Check.Require(_ordered[index] == null , $"Items to sequence contains duplicate, {typeName} (wrong sequenced attribute name?)"); _ordered[index] = item; } #if DEBUG && !PROFILE_SVELTO if (counted != cachedEnum.Count) { var debug = new HashSet <string>(); foreach (var debugItem in itemsToSort) { debug.Add(debugItem.GetType().GetCustomAttribute <SequencedAttribute>().name); } foreach (var debugSequence in cachedEnum.Keys) { if (debug.Contains(debugSequence) == false) { throw new Exception( $"The sequence {typeof(En).Name} wasn't fully satisfied, missing sequenced item {debugSequence}"); } } } #endif }
public GroupsEnumerable(EntitiesDB db, FasterReadOnlyList <ExclusiveGroupStruct> groups) { _db = db; _groups = groups; }
public WaitForEntitiesInGroupEnumerator(FasterReadOnlyList <ExclusiveGroupStruct> groups, EntitiesDB entitiesDB) { _groups = groups; _entitiesDB = entitiesDB; }
public EnginesExecutionOrderGroup(FasterReadOnlyList <IJobifiedEngine> engines) : base(engines) { }
public QueryResult(FasterList <ExclusiveGroupStruct> @group) { _group = @group; }
protected SortedJobifedEnginesGroup(FasterReadOnlyList <Interface> engines) { _instancedSequence = new Sequence <Interface, SequenceOrder>(engines); }
public QueryResult Except(FasterReadOnlyList <ExclusiveGroupStruct> groupsToIgnore) { return(QueryResult(groupsToIgnore.ToArrayFast(out var count), (int)count)); }
public GroupsIterator(EntitiesDB db, FasterReadOnlyList <ExclusiveGroupStruct> groups) : this() { _groups = groups; _indexGroup = -1; _entitiesDB = db; }
protected JobifedEnginesGroup(FasterReadOnlyList <Interface> engines, bool completeEachJob = false) { _engines = engines; _completeEachJob = completeEachJob; }