예제 #1
0
        /// <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);
        }
예제 #2
0
        public WaitForEntitiesInGroupEnumerator(ExclusiveGroupStruct group, EntitiesDB entitiesDB)
        {
            var groups = new FasterList <ExclusiveGroupStruct>(new [] { group });

            _groups     = new FasterReadOnlyList <ExclusiveGroupStruct>(groups);
            _entitiesDB = entitiesDB;
        }
예제 #3
0
        public QueryGroups Except(FasterReadOnlyList <ExclusiveGroupStruct> groupsToIgnore)
        {
            var groupsValue = groups.Value;

            groupsValue.Exclude(groupsToIgnore.ToArrayFast(out var count), count);

            return(this);
        }
예제 #4
0
        IEnumerator WaitToEnableButtons()
        {
            yield return(_waitToEnableButtons);

            FasterReadOnlyList <ButtonEntityView> buttonEntityViews = entityViewsDB.QueryEntityViews <ButtonEntityView>();

            for (int i = 0; i < buttonEntityViews.Count; ++i)
            {
                buttonEntityViews[i].UserMovementButtonComponent.IsInteractable = true;
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        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);
        }
예제 #7
0
 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);
        }
예제 #9
0
        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
        }
예제 #10
0
 public GroupsEnumerable(EntitiesDB db, FasterReadOnlyList <ExclusiveGroupStruct> groups)
 {
     _db     = db;
     _groups = groups;
 }
예제 #11
0
 public WaitForEntitiesInGroupEnumerator(FasterReadOnlyList <ExclusiveGroupStruct> groups, EntitiesDB entitiesDB)
 {
     _groups     = groups;
     _entitiesDB = entitiesDB;
 }
 public EnginesExecutionOrderGroup(FasterReadOnlyList <IJobifiedEngine> engines) : base(engines)
 {
 }
예제 #13
0
 public QueryResult(FasterList <ExclusiveGroupStruct> @group)
 {
     _group = @group;
 }
예제 #14
0
 protected SortedJobifedEnginesGroup(FasterReadOnlyList <Interface> engines)
 {
     _instancedSequence = new Sequence <Interface, SequenceOrder>(engines);
 }
예제 #15
0
 public QueryResult Except(FasterReadOnlyList <ExclusiveGroupStruct> groupsToIgnore)
 {
     return(QueryResult(groupsToIgnore.ToArrayFast(out var count), (int)count));
 }
예제 #16
0
 public GroupsIterator(EntitiesDB db, FasterReadOnlyList <ExclusiveGroupStruct> groups) : this()
 {
     _groups     = groups;
     _indexGroup = -1;
     _entitiesDB = db;
 }
예제 #17
0
 protected JobifedEnginesGroup(FasterReadOnlyList <Interface> engines, bool completeEachJob = false)
 {
     _engines         = engines;
     _completeEachJob = completeEachJob;
 }