public static int CountDuplicates <T>(this SCG.IEnumerable <T> enumerable, T item, SCG.IEqualityComparer <T> equalityComparer = null) { // Argument must be non-null Requires(enumerable != null, ArgumentMustBeNonNull); if (equalityComparer == null) { equalityComparer = SCG.EqualityComparer <T> .Default; } return(enumerable.Count(x => equalityComparer.Equals(x, item))); }
private void worldLoad() { processJobAdds(); /** * Load the world tiles around the camera and their objects */ int tileX = Mathf.FloorToInt(telaraWorldCamPos.x / 256.0f); int tileY = Mathf.FloorToInt(telaraWorldCamPos.z / 256.0f); int[][] v = { new int[] { -1, 1 }, new int[] { 0, 1 }, new int[] { 1, 1 }, new int[] { -1, 0 }, new int[] { 0, 0 }, new int[] { 1, 0 }, new int[] { -1, -1 }, new int[] { 0, -1 }, new int[] { 1, -1 }, }; int range = ProgramSettings.get("TERRAIN_VIS", 10); submitCDRJob(tileX, tileY); for (int txx = tileX - range; txx <= tileX + range; txx++) { for (int txy = tileY - range; txy <= tileY + range; txy++) { submitCDRJob(txx, txy); } } processCDRQueue(); if (availThreads() > 0) { Vector3 camPos = cameraWorldCamPos; //getWorldCamPos(); float[] camPosF = new float[] { camPos.x, camPos.z }; lock (terraintree) { lock (postree) { KdTreeNode <float, SCG.List <NifLoadJob> >[] tercandidates = this.terraintree.RadialSearch(camPosF, Math.Max(256, ProgramSettings.get("TERRAIN_VIS", 10) * 256), 200); KdTreeNode <float, SCG.List <NifLoadJob> >[] candidates = this.postree.RadialSearch(camPosF, ProgramSettings.get("OBJECT_VISIBLE", 500), 200); SCG.IEnumerable <NifLoadJob> terjobs = tercandidates.SelectMany(e => e.Value); // always have a terrain job running if (terjobs.Count() > 0) { lock (camPlaneLock) { terjobs = terjobs.OrderBy(n => Vector3.Distance(n.parentPos, camPos)); } SCG.List <NifLoadJob> jobs = terjobs.ToList(); lock (terrainRunningList) { if (terrainRunningList.Count <= 1) { startJob(jobs[0], terrainRunningList, tercandidates); } } } lock (terrainRunningList) { tListCountEstimate = terrainRunningList.Count; } foreach (KdTreeNode <float, SCG.List <NifLoadJob> > n in tercandidates) { if (n.Value.Count == 0) { terraintree.RemoveAt(n.Point); } } if (availThreads() > 0) { oListCountEstimate = objectRunningList.Count; SCG.IEnumerable <NifLoadJob> otherjobs = candidates.SelectMany(e => e.Value); lock (camPlaneLock) { otherjobs = otherjobs.OrderBy(n => !TestPlanesAABB(camPlanes, n.parentPos)).ThenBy(n => Vector3.Distance(n.parentPos, camPos)); } foreach (NifLoadJob job in otherjobs) { if (availThreads() > 0) { lock (objectRunningList) { startJob(job, objectRunningList, candidates); } } else { break; } } foreach (KdTreeNode <float, SCG.List <NifLoadJob> > n in candidates) { if (n.Value.Count == 0) { postree.RemoveAt(n.Point); } } } } } } }