Example #1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var removeList      = new NativeQueue <RemoveItem>(Allocator.TempJob);
            var timerRemoveList = new NativeQueue <WakeItem>(Allocator.TempJob);
            var job             = new WakeJob()
            {
                NodeSleepings = GetArchetypeChunkBufferType <NodeSleeping>(),
                RemoveList    = removeList.AsParallelWriter(),
            };

            var jobTimer = new WakeWithTimerJob()
            {
                dt = Time.deltaTime,
                NodeTimeBufferType = GetArchetypeChunkBufferType <NodeTimer>(),
                ActionRunStateType = GetArchetypeChunkComponentType <ActionRunState>(),
                RemoveList         = timerRemoveList.AsParallelWriter(),
            };

            var handle      = job.Schedule(m_Group, inputDeps);
            var handleTimer = jobTimer.Schedule(m_GroupTimer, inputDeps);

            handle.Complete();
            handleTimer.Complete();

            if (removeList.Count > 0)
            {
                var actionRunStates = GetComponentDataFromEntity <ActionRunState>();
                while (removeList.TryDequeue(out var item))
                {
                    var states    = actionRunStates[item.Entity];
                    var container = ActionStateMapToAsset.Instance.GetContainer(states.InstanceID);
                    container.SetNodeCycle(new ActionStateIndex()
                    {
                        ChunkIndex = states.ChunkIndex, NodeIndex = item.NodeIndex
                    }, NodeCycle.Waking);
                }
            }

            if (timerRemoveList.Count > 0)
            {
                while (timerRemoveList.TryDequeue(out var item))
                {
                    var container = ActionStateMapToAsset.Instance.GetContainer(item.InstanceID);
                    container.SetNodeCycle(new ActionStateIndex()
                    {
                        ChunkIndex = item.ChunkIndex, NodeIndex = item.NodeIndex
                    }, NodeCycle.Waking);
                }
            }

            removeList.Dispose();
            timerRemoveList.Dispose();
            return(inputDeps);
        }
Example #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            var chunks = m_Group.CreateArchetypeChunkArray(Allocator.TempJob);
            NativeList <SleepingNode> WakeNodes = new NativeList <SleepingNode>(Allocator.TempJob);
            var job = new WakeJob()
            {
                sleepTypes      = _sleepTypes,
                EntityType      = GetArchetypeChunkEntityType(),
                ArchetypeChunks = chunks,
                sleepNodes      = _sleepNodes,
            };

            var job_B = new WakeJob_B()
            {
                sleepTypes = _sleepTypes,
                sleepNodes = _sleepNodes,
                EntityType = GetArchetypeChunkEntityType(),
                WakeNodes  = WakeNodes
            };

            var handle   = job.Schedule(inputDeps);
            var handle_B = job_B.Schedule(handle);

            handle_B.Complete();

            for (int i = 0; i < WakeNodes.Length; i++)
            {
                var nodeInfo = WakeNodes[i];
                var runState = EntityManager.GetComponentData <ActionRunState>(nodeInfo.Entity);
                var Index    = new ActionStateIndex()
                {
                    ChunkIndex = runState.ChunkIndex,
                    NodeIndex  = nodeInfo.NodeIndex
                };
                ActionStateMapToAsset.Instance.GetContainer(runState.InstanceID).SetNodeCycle(Index, NodeCycle.Waking);
            }

            chunks.Dispose();
            WakeNodes.Dispose();
            return(inputDeps);
        }