/// <summary> /// Called every frame. /// This may be called during FixedUpdate or Update depending on if a rigidbody is attached to the GameObject. /// </summary> static void OnUpdate(AIBase[] components, int count, BatchedEvents.Event ev) { float dt = ev == BatchedEvents.Event.FixedUpdate ? Time.fixedDeltaTime : Time.deltaTime; if (RVOSimulator.active != null) { int agentsWithRVOControllers = 0; for (int i = 0; i < count; i++) { agentsWithRVOControllers += (components[i].rvoController != null && components[i].rvoController.enabled ? 1 : 0); } RVODestinationCrowdedBehavior.JobDensityCheck densityJobData = new RVODestinationCrowdedBehavior.JobDensityCheck(agentsWithRVOControllers, dt); for (int i = 0, j = 0; i < count; i++) { var agent = components[i]; if (agent.rvoController != null && agent.rvoController.enabled) { densityJobData.Set(j, agent.rvoController.rvoAgent.AgentIndex, agent.endOfPath, agent.rvoDensityBehavior.densityThreshold, agent.rvoDensityBehavior.progressAverage); j++; } } var densityJob = densityJobData.ScheduleBatch(agentsWithRVOControllers, agentsWithRVOControllers / 16); densityJob.Complete(); for (int i = 0, j = 0; i < count; i++) { var agent = components[i]; if (agent.rvoController != null && agent.rvoController.enabled) { agent.rvoDensityBehavior.ReadJobResult(ref densityJobData, j); j++; } } densityJobData.Dispose(); } for (int i = 0; i < count; i++) { var agent = components[i]; agent.OnUpdate(dt); } }
/// <summary> /// Called every frame. /// This may be called during FixedUpdate or Update depending on if a rigidbody is attached to the GameObject. /// </summary> static void OnUpdate(AIBase[] components, int count, BatchedEvents.Event ev) { float dt = ev == BatchedEvents.Event.FixedUpdate ? Time.fixedDeltaTime : Time.deltaTime; if (RVOSimulator.active != null) { RVODestinationCrowdedBehavior.JobDensityCheck densityJobData = new RVODestinationCrowdedBehavior.JobDensityCheck(count, dt); for (int i = 0; i < count; i++) { var agent = components[i]; // Exponentially decaying average of // dot(desired direction, rvo velocity) / radius // isStopped = v < 0.1f && density > threshold if (agent.rvoController != null) { densityJobData.Set(i, agent.rvoController.rvoAgent.AgentIndex, agent.destination, agent.rvoDensityBehavior.densityThreshold, agent.rvoDensityBehavior.progressAverage); } } var densityJob = densityJobData.ScheduleBatch(count, count / 16); densityJob.Complete(); for (int i = 0; i < count; i++) { var agent = components[i]; agent.rvoDensityBehavior.ReadJobResult(ref densityJobData, i); } densityJobData.Dispose(); } for (int i = 0; i < count; i++) { var agent = components[i]; agent.OnUpdate(dt); } }