public void UpdateSeenBoids() { SeenBoids.Clear(); //System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); List <GameObject> boids = new List <GameObject>(); if (useFastHashCheck) { boids = hash.GetNRandom(transform.position, maxSeenBoidsToStore); } else { //boids = hash.GetNByRadius(transform.position, overlapSphereRadius, maxSeenBoidsToStore); boids = hash.GetByRadius(transform.position, overlapSphereRadius); } foreach (GameObject boid in boids) { if (boid != this.gameObject && IsWithinVisionAngle(boid.transform.position)) { SeenBoids.Add(boid); } } /* * int n = (maxSeenBoidsToStore <= 0) ? boids.Count : Mathf.Min(boids.Count, maxSeenBoidsToStore); * for (int i = 0; i < n; i++) * { * if (boids[i] != this.gameObject && IsWithinVisionAngle(boids[i].transform.position)) * { * SeenBoids.Add(boids[i]); * } * } */ //watch.Stop(); //if(Random.Range(0f, 1f) >= 0.9f) Debug.Log("time to get seen boids (fast hash check = " + useFastHashCheck + "): " + watch.ElapsedMilliseconds + " ms"); //ADAPTIVE OVERLAP SPHERE: if current pass didn't find enough boids, increase overlap sphere size; if it did, reduce it if (useAdaptiveOverlapSphere) { if (SeenBoids.Count < maxSeenBoidsToStore && overlapSphereRadius < maxAdaptiveOverlapRadius) { overlapSphereRadius += adaptiveOverlapSphereInc; } else if (overlapSphereRadius > minAdaptiveOverlapRadius) { overlapSphereRadius -= adaptiveOverlapSphereInc; } } }