//private GameObject[] roots; public void Initial(Contexts contexts) { this.contexts = contexts; Bin2DConfig config = new Bin2DConfig(-4000, -4000, 4000, 4000, 50, 50); map = new Map2D <GameObject>(config); smallMap = new Map2D <GameObject>(config); MidMap = new Map2D <GameObject>(config); InternalBounds bouds = map.GetInternalBounds(new Rect(-4000, -4000, 8000, 8000)); MaxLen = bouds.MaxX - bouds.MinX + 1; recSet = new BitArray(100); lastRecSet = new BitArray(100); countDic = new int[100]; lastSet = new BitArray(MaxLen * MaxLen); currentSet = new BitArray(MaxLen * MaxLen); lastSetS = new BitArray(MaxLen * MaxLen); currentSetS = new BitArray(MaxLen * MaxLen); lastSetM = new BitArray(MaxLen * MaxLen); currentSetM = new BitArray(MaxLen * MaxLen); //roots = new GameObject[MaxLen * MaxLen]; //for (int i = 0; i < MaxLen * MaxLen; i++) //{ // roots[i] = new GameObject(); // roots[i].name = "root" + i; // } }
public InternalBounds GetInternalBounds(Rect bounds) { var internalBounds = new InternalBounds { MinX = Mathf.Max(0, (int)((bounds.xMin - _bottomLeft.x) / CellWidth)), MinY = Mathf.Max(0, (int)((bounds.yMin - _bottomLeft.y) / CellHeight)), MaxX = Mathf.Min(Width - 1, (int)((bounds.xMax - _bottomLeft.x) / CellWidth)), MaxY = Mathf.Min(Height - 1, (int)((bounds.yMax - _bottomLeft.y) / CellHeight)) }; return(internalBounds); }
private void Culling(Map2D <GameObject> map, BitArray currentSet, BitArray lastSet, int range, string type) { long startTime = DateTime.Now.Ticks; showCount = 0; hideCount = 0; PlayerEntity player = contexts.player.flagSelfEntity; InternalBounds bounds = map.GetInternalBounds(new Rect(player.position.Value.x - range / 2, player.position.Value.z - range / 2, range, range)); currentSet.SetAll(false); for (int i = bounds.MinX; i <= bounds.MaxX; i++) { for (int j = bounds.MinY; j <= bounds.MaxY; j++) { currentSet.Set(GetIndex(i, j), true); } } //_logger.InfoFormat("culling all {4} rect {0}-{1},{2}-{3} at {5},{6}\nalready show:\n", bounds.MinX, bounds.MaxX, bounds.MinY, bounds.MaxY, MaxLen, player.position.Value.x, player.position.Value.z); //printNotEmpty(lastSet); for (int i = 0; i < currentSet.Length; i++) { if (currentSet.Get(i) && !lastSet.Get(i)) { ShowOne(map, i, true, type); } if (!currentSet.Get(i) && lastSet.Get(i)) { ShowOne(map, i, false, type); } } lastSet.SetAll(false); lastSet = lastSet.Or(currentSet); if (DateTime.Now.Ticks - startTime > 10000 && (showCount > 0 || hideCount > 0)) { _logger.InfoFormat("culling time {0}, show count={1}, hide count={2}, center={3},{4}", (DateTime.Now.Ticks - startTime) / 10000, showCount, hideCount, (bounds.MinX + bounds.MaxX) / 2, (bounds.MinY + bounds.MaxY) / 2); } }