Esempio n. 1
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (AgentMarkers.Capacity < agentGroup.Agents.Length * qtdMarkers * 4)
            {
                AgentMarkers.Dispose();
                AgentMarkers = new NativeMultiHashMap <int, float3>(agentGroup.Agents.Length * qtdMarkers * 4, Allocator.Persistent);
            }
            else
            {
                AgentMarkers.Clear();
            }


            if (!CellTagSystem.AgentIDToPos.IsCreated)
            {
                return(inputDeps);
            }



            if (createDict)
            {
                createDict = false;
                CreateCells();
            }

            //Get QuadTree quadrants that need to be schedueled
            var schedule = new NativeArray <int3>(qt.GetScheduled(), Allocator.Temp);
            //Debug.Log(schedule.Length);
            //list<quadrants> --> [[cell1, cell2, ..., celln], [celln+1, ...], ...]
            //[cell1, cell2, ..., celln] --> ComponentDataArray<Position>
            //Job <-- Position, MarkedCells { markerCell --> checkAgents }

            var job = new TakeMarkers
            {
                AgentMarkers = AgentMarkers.ToConcurrent(),
                Densities    = LocalDensities.ToConcurrent(),
                cellToAgent  = CellTagSystem.CellToMarkedAgents,
                cells        = schedule,
                AgentIDToPos = CellTagSystem.AgentIDToPos
            };

            var sq = job.Schedule(schedule.Length, Settings.BatchSize, inputDeps);

            sq.Complete();

            schedule.Dispose();
            frame++;
            return(sq);
        }
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            AgentMarkers.Clear();
            AgentStress.Clear();
            AgentToSubGoal.Clear();

            var SetGoals = new SetGoals
            {
                AgentToSubGoal = AgentToSubGoal.ToConcurrent(),
                AgentData      = agentGroup.AgentData,
                AgentGoal      = agentGroup.AgentGoal
            };

            var setGoalsHandle = SetGoals.Schedule(agentGroup.Length, Settings.BatchSize, inputDeps);

            setGoalsHandle.Complete();


            var SetStress = new StressHashMap
            {
                AgentData      = agentGroup.AgentData,
                NormalLifeData = agentGroup.NormalLifeData,
                AgentStress    = AgentStress.ToConcurrent()
            };

            var SetStressHandle = SetStress.Schedule(agentGroup.Length, Settings.BatchSize, setGoalsHandle);

            SetStressHandle.Complete();

            TakeMarkers takeMarkersJob = new TakeMarkers
            {
                AgentIDToPos   = CellTagSystem.AgentIDToPos,
                AgentMarkers   = AgentMarkers.ToConcurrent(),
                cellToAgent    = CellTagSystem.CellToMarkedAgents,
                MarkerCell     = markerGroup.MarkerCell,
                MarkerPos      = markerGroup.Position,
                MarkerData     = markerGroup.MarkerData,
                Counter        = agentGroup.Counter,
                AgentStress    = AgentStress,
                AgentToSubGoal = AgentToSubGoal,
                NormalLifeData = agentGroup.NormalLifeData
            };

            int qtdAgents        = Settings.agentQuantity;
            var takeMakersHandle = takeMarkersJob.Schedule(markerGroup.Length, qtdAgents / 4, inputDeps);

            takeMakersHandle.Complete();


            NativeMultiHashMap <int, float3> agtM = AgentMarkers;

            NativeMultiHashMapIterator <int> iter;
            float3 marker;

            for (int i = 0; i < agentGroup.Length; i++)
            {
                bool keepGoing = agtM.TryGetFirstValue(agentGroup.AgentData[i].ID, out marker, out iter);
                if (keepGoing)
                {
                    //Debug.Log(i);

                    Debug.DrawLine(agentGroup.Positions[i].Value, marker);
                    while (agtM.TryGetNextValue(out marker, ref iter))
                    {
                        Debug.DrawLine(agentGroup.Positions[i].Value, marker);
                    }
                }
            }

            return(takeMakersHandle);
        }
Esempio n. 3
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (AgentMarkers.Capacity < agentGroup.Agents.Length * qtdMarkers * 4)
            {
                AgentMarkers.Dispose();
                AgentMarkers = new NativeMultiHashMap <int, float3>(agentGroup.Agents.Length * qtdMarkers * 4, Allocator.Persistent);
            }
            else
            {
                AgentMarkers.Clear();
            }


            if (!CellTagSystem.AgentIDToPos.IsCreated)
            {
                return(inputDeps);
            }


            TakeMarkers takeMarkersJob = new TakeMarkers
            {
                AgentIDToPos = CellTagSystem.AgentIDToPos,
                AgentMarkers = AgentMarkers.ToConcurrent(),
                cellToAgent  = CellTagSystem.CellToMarkedAgents,
                MarkerCell   = markerGroup.MarkerCell,
                MarkerPos    = markerGroup.Position,
                Densities    = LocalDensities.ToConcurrent()
                               //Entities = markerGroup.Entities,
                               //CommandBuffer = m_SpawnerBarrier.CreateCommandBuffer().ToConcurrent()
            };

            //if (CellTagSystem.AgentIDToPos.IsCreated)
            // {
            JobHandle takeMakersHandle = takeMarkersJob.Schedule(markerGroup.Length, 64, inputDeps);

            takeMakersHandle.Complete();


            NativeMultiHashMap <int, float3> agtM = AgentMarkers;

            NativeMultiHashMapIterator <int> iter;
            float3 marker;

            for (int i = 0; i < agentGroup.Length; i++)
            {
                bool keepGoing = agtM.TryGetFirstValue(agentGroup.Agents[i].ID, out marker, out iter);
                if (keepGoing)
                {
                    //Debug.Log(i);

                    Debug.DrawLine(agentGroup.Positions[i].Value, marker);
                    while (agtM.TryGetNextValue(out marker, ref iter))
                    {
                        Debug.DrawLine(agentGroup.Positions[i].Value, marker);
                    }
                }
            }


            return(takeMakersHandle);
            // }

            // return inputDeps;
        }