public void RemoveRoom(ProceduralRoom room)
 {
     m_rooms.Remove(room.RoomID);
     m_roomTree.RemoveProxy(room.m_aabbProxyID);
     if (m_roomsSafeOrder[m_roomsSafeOrder.Count - 1] == room)
     {
         m_roomsSafeOrder.RemoveAt(m_roomsSafeOrder.Count - 1);
     }
     else
     {
         m_roomsSafeOrder.Remove(room);
         Logger.Warning("Possibly unsafe removal of room not at end of safe list");
     }
     foreach (var k in room.MountPoints)
     {
         foreach (var p in k.MountLocations)
         {
             if (!m_mountPoints.Remove(p))
             {
                 Logger.Warning("Failed to remove room; mount point wasn't registered");
             }
         }
     }
     room.Orphan();
     using (room.Part.LockSharedUsing())
         BlockSetInfo.SubtractFromSelf(room.Part.BlockSetInfo);
     RoomRemoved?.Invoke(room);
 }
        public void AddRoom(ProceduralRoom room)
        {
            if (m_rooms.ContainsKey(room.RoomID))
            {
                throw new ArgumentException("Room ID already used");
            }
            m_rooms[room.RoomID] = room;
            var aabb = room.BoundingBoxBoth;

            room.m_aabbProxyID = m_roomTree.AddProxy(ref aabb, room, 0);
            m_roomsSafeOrder.Add(room);
            foreach (var k in room.MountPoints)
            {
                foreach (var p in k.MountLocations)
                {
                    if (m_mountPoints.ContainsKey(p))
                    {
                        Logger.Warning("Room {0} at {1} has mount point {4}:{5} that intersect with mount point {6}:{7} of room {2} at {3}", m_mountPoints[p].Owner.Part.Name, m_mountPoints[p].Owner.Transform.Translation,
                                       room.Part.Name, room.Transform.Translation, m_mountPoints[p].MountPoint.MountType, m_mountPoints[p].MountPoint.MountName,
                                       k.MountPoint.MountType, k.MountPoint.MountName);
                    }
                    else
                    {
                        m_mountPoints.Add(p, k);
                    }
                }
            }
            room.TakeOwnership(this);
            using (room.Part.LockSharedUsing())
                BlockSetInfo.AddToSelf(room.Part.BlockSetInfo);
            RoomAdded?.Invoke(room);
        }
        public bool Intersects(ProceduralRoom room, bool testOptional, bool testQuick = false)
        {
            var bb     = room.BoundingBoxBoth;
            var result = false;

            m_roomTree.Query((x) =>
            {
                var test = m_roomTree.GetUserData <ProceduralRoom>(x);
                var res  = test != room && test.Intersects(room, testOptional, testQuick);
                result   = res;
                return(!res);
            }, ref bb);
            return(result);
        }
 public bool Init(PartManager manager, Ob_ProceduralConstruction ob)
 {
     if (ob.Rooms.Any(x => manager.LoadNullable(x.PrefabID) == null))
     {
         return(false);
     }
     Clear();
     foreach (var room in ob.Rooms)
     {
         var data = new ProceduralRoom();
         data.Init(room.Transform, manager.LoadNullable(room.PrefabID));
         AddRoom(data);
     }
     return(true);
 }
        public ProceduralRoom GetRoomAt(Vector3I pos)
        {
            ProceduralRoom result = null;
            var            aabb   = new BoundingBox(pos, pos + 1);

            m_roomTree.Query((id) =>
            {
                var room = m_roomTree.GetUserData <ProceduralRoom>(id);
                if (!room.CubeExists(pos))
                {
                    return(true);
                }
                result = room;
                return(false);
            }, ref aabb);
            return(result);
        }
        public bool Intersects(PartFromPrefab other, MatrixI otherTransform, MatrixI otherITransform, bool testOptional, bool testQuick = false, ProceduralRoom ignore = null)
        {
            var bb     = Utilities.TransformBoundingBox(other.BoundingBoxBoth, otherTransform);
            var result = false;

            m_roomTree.Query((x) =>
            {
                var test = m_roomTree.GetUserData <ProceduralRoom>(x);
                var res  = test != ignore && test.Intersects(other, otherTransform, otherITransform, testOptional, testQuick);
                result   = res;
                return(!res);
            }, ref bb);
            return(result);
        }
 public IDisposable RegisterRoomUsing(ProceduralRoom room)
 {
     return(new RoomRegisterToken(this, room));
 }
 public RoomRegisterToken(ProceduralConstruction c, ProceduralRoom r)
 {
     m_construction = c;
     m_room         = r;
     c.AddRoom(r);
 }
Beispiel #9
0
 internal void Init(PartMount mount, ProceduralRoom parent)
 {
     MountPoint = mount;
     TakeOwnership(parent);
 }
Beispiel #10
0
 private void TakeOwnership(ProceduralRoom parent)
 {
     Orphan();
     Owner = parent;
 }
 public bool Intersects(ProceduralRoom other, bool testOptional, bool testQuick = false)
 {
     return(other.BoundingBoxBoth.Intersects(BoundingBoxBoth) &&
            (other.BoundingBox.Intersects(BoundingBox) || other.ReservedSpace.Intersects(ReservedSpace)) &&
            PartMetadata.Intersects(ref m_part, ref m_transform, ref m_invTransform, ref other.m_part, ref other.m_transform, ref other.m_invTransform, testOptional, testQuick));
 }