Example #1
0
 public void Extend(Box box)
 {
     X1 = Math.Min(X1, box.X1);
     X2 = Math.Max(X2, box.X2);
     Y1 = Math.Min(Y1, box.Y1);
     Y2 = Math.Max(Y2, box.Y2);
     Z1 = Math.Min(Z1, box.Z1);
     Z2 = Math.Max(Z2, box.Z2);
 }
Example #2
0
        public bool TryExtend(Box box)
        {
            if (Area.Contains(box))
                return true;

            // New area has to be within 1 tile
            var testBox = Area;
            testBox.Extend(1);

            if (!testBox.Contains(Area))
                return false;

            var newBox = Area;
            newBox.Extend(box);
            if (newBox.Size - Area.Size > 2)
                return false;

            Area = newBox;
            return true;
        }
Example #3
0
 public bool Contains(Box box)
 {
     return box.X1 >= X1 && box.X2 <= X2 &&
            box.Y1 >= Y1 && box.Y2 <= Y2 &&
            box.Z1 >= Z1 && box.Z2 <= Z2;
 }
Example #4
0
        public void ScheduleUpdate(LightType type, Box area)
        {
            int centerX = (area.X1 + area.X2) / 2;
            int centerY = (area.Y1 + area.Y2) / 2;

            if (!world.IsLoaded(centerX, centerY))
                return;

            // Try to merge this update in one of the more recent updates
            int checkUpdates = 4;

            foreach(var update in scheduledUpdates) {
                if (checkUpdates <= 0)
                    break;
                checkUpdates--;
                if (update.Type == type && update.TryExtend(area))
                    return;
            }

            var newUpdate = new LightingUpdate(this);
            newUpdate.Area = area;
            newUpdate.Type = type;
            scheduledUpdates.AddFirst(newUpdate);
        }