Пример #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 void SwapEntity(EGID from, ExclusiveBuildGroup to, int threadIndex)
        {
            var simpleNativeBag = _swapQueue.GetBuffer(threadIndex);

            simpleNativeBag.Enqueue(_indexSwap);
            simpleNativeBag.Enqueue(new DoubleEGID(from, new EGID(from.entityID, to)));
        }
Пример #3
0
        public NativeEntityInitializer BuildEntity
            (uint eindex, ExclusiveBuildGroup exclusiveBuildGroup, int threadIndex)
        {
            NativeBag unsafeBuffer = _addOperationQueue.GetBuffer(threadIndex + 1);

            unsafeBuffer.Enqueue(_index);
            unsafeBuffer.Enqueue(new EGID(eindex, exclusiveBuildGroup));
            unsafeBuffer.ReserveEnqueue <uint>(out var index) = 0;

            return(new NativeEntityInitializer(unsafeBuffer, index));
        }
Пример #4
0
        public NativeEntityInitializer BuildEntity
            (uint eindex, ExclusiveBuildGroup exclusiveBuildGroup, int threadIndex)
        {
            EntityReference reference    = _entityLocator.ClaimReference();
            NativeBag       unsafeBuffer = _addOperationQueue.GetBuffer(threadIndex + 1);

            unsafeBuffer.Enqueue(_index); //each native ECS native operation is stored in an array, each request to perform a native operation in a queue. _index is the index of the operation in the array that will be dequeued later
            unsafeBuffer.Enqueue(new EGID(eindex, exclusiveBuildGroup));
            unsafeBuffer.Enqueue(reference);

            //NativeEntityInitializer is quite a complex beast. It holds the starting values of the component set by the user. These components must be later dequeued and in order to know how many components
            //must be dequeued, a count must be used. The space to hold the count is then reserved in the queue and index will be used access the count later on through NativeEntityInitializer so it can increment it.
            unsafeBuffer.ReserveEnqueue <uint>(out var index) = 0;

            return(new NativeEntityInitializer(unsafeBuffer, index, reference));
        }