//public System.Object lockObject; public void AddSpan(uint bottom, uint top, int area, int voxelWalkableClimb) { VoxelSpan span = new VoxelSpan(bottom, top, area); //lock (lockObject) { if (firstSpan == null) { firstSpan = span; return; } VoxelSpan prev = null; VoxelSpan cSpan = firstSpan; //for (VoxelSpan cSpan = firstSpan; cSpan != null; cSpan = cSpan.next) { while (cSpan != null) { if (cSpan.bottom > span.top) { break; } else if (cSpan.top < span.bottom) { prev = cSpan; cSpan = cSpan.next; } else { if (cSpan.bottom < bottom) { span.bottom = cSpan.bottom; } if (cSpan.top > top) { span.top = cSpan.top; } //1 is flagMergeDistance, when a walkable flag is favored before an unwalkable one if (Mathfx.Abs((int)span.top - (int)cSpan.top) <= voxelWalkableClimb) { span.area = Mathfx.Max(span.area, cSpan.area); } VoxelSpan next = cSpan.next; if (prev != null) { prev.next = next; } else { firstSpan = next; } cSpan = next; /*cSpan.bottom = cSpan.bottom < bottom ? cSpan.bottom : bottom; * cSpan.top = cSpan.top > top ? cSpan.top : top; * * if (cSpan.bottom < span.bottom) { * span.bottom = cSpan.bottom; * } * if (cSpan.top > span.top) { * span.top = cSpan.top; * } * * span.area = Mathfx.Min (span.area,cSpan.area); * VoxelSpan next = cSpan.next; * * if (prev != null) { * prev.next = next; * } else { * firstSpan = next; * } * cSpan = next;*/ } } if (prev != null) { span.next = prev.next; prev.next = span; } else { span.next = firstSpan; firstSpan = span; } //} }