From cc220aae44bf71cf0895e2e859f7e469cd3996cb Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Thu, 4 Nov 2021 11:51:03 +0000 Subject: [PATCH] #219 TR3 Boxes, overlaps and zones Some tidying/refactoring for finding room sectors. --- TRFDControl/Utilities/FDUtilities.cs | 53 +++++----------------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/TRFDControl/Utilities/FDUtilities.cs b/TRFDControl/Utilities/FDUtilities.cs index eef40dec1..6440c5d35 100644 --- a/TRFDControl/Utilities/FDUtilities.cs +++ b/TRFDControl/Utilities/FDUtilities.cs @@ -130,7 +130,6 @@ public static void RemoveEntityTriggers(IEnumerable sectorList, in public static readonly short NO_ROOM = 0xff; public static readonly short WALL_SHIFT = 10; - // See Control.c line 516 public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, TR2Level level, FDControl floorData) { int xFloor, yFloor; @@ -140,11 +139,10 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, do { - // Clip position to edge of room (that way doorways are detected) + // Clip position to edge of tile xFloor = (z - room.Info.Z) >> WALL_SHIFT; yFloor = (x - room.Info.X) >> WALL_SHIFT; - // Ensure we don't test the corner of a room's floor data, as this can cause problems when 4 rooms join at a point if (xFloor <= 0) { xFloor = 0; @@ -178,7 +176,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, yFloor = room.NumXSectors - 1; } - // If doorway, go through and retest, else move onto next stage sector = room.SectorList[xFloor + yFloor * room.NumZSectors]; data = GetDoor(sector, floorData); if (data != NO_ROOM && data >= 0 && data < level.Rooms.Length - 1) @@ -188,7 +185,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, } while (data != NO_ROOM); - // If below floor and pit, go down if (y >= (sector.Floor << 8)) { do @@ -205,7 +201,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, } else if (y < (sector.Ceiling << 8)) { - // If above ceiling and skylight, go up do { if (sector.RoomAbove == NO_ROOM) @@ -222,7 +217,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, return sector; } - // See Control.c line 766 public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, TR3Level level, FDControl floorData) { int xFloor, yFloor; @@ -232,11 +226,10 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, do { - // Clip position to edge of room (that way doorways are detected) + // Clip position to edge of tile xFloor = (z - room.Info.Z) >> WALL_SHIFT; yFloor = (x - room.Info.X) >> WALL_SHIFT; - // Ensure we don't test the corner of a room's floor data, as this can cause problems when 4 rooms join at a point if (xFloor <= 0) { xFloor = 0; @@ -270,7 +263,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, yFloor = room.NumXSectors - 1; } - // If doorway, go through and retest, else move onto next stage sector = room.Sectors[xFloor + yFloor * room.NumZSectors]; data = GetDoor(sector, floorData); if (data != NO_ROOM && data >= 0 && data < level.Rooms.Length - 1) @@ -280,7 +272,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, } while (data != NO_ROOM); - // If below floor and pit, go down if (y >= (sector.Floor << 8)) { do @@ -290,8 +281,8 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, return sector; } - int triCheck = CheckNoColFloorTriangle(floorData, sector, x, z); - if (triCheck == 1) // If on collision side of a split quad then stop. + int triCheck = CheckFloorTriangle(floorData, sector, x, z); + if (triCheck == 1) { break; } @@ -307,7 +298,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, } else if (y < (sector.Ceiling << 8)) { - // If above ceiling and skylight, go up do { if (sector.RoomAbove == NO_ROOM) @@ -315,8 +305,8 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, return sector; } - int triCheck = CheckNoColCeilingTriangle(floorData, sector, x, z); - if (triCheck == 1) // If on collision side of a split quad then stop. + int triCheck = CheckCeilingTriangle(floorData, sector, x, z); + if (triCheck == 1) { break; } @@ -334,7 +324,6 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, return sector; } - // See Control.c line 1344 public static short GetDoor(TRRoomSector sector, FDControl floorData) { if (sector.FDIndex == 0) @@ -354,26 +343,13 @@ public static short GetDoor(TRRoomSector sector, FDControl floorData) return NO_ROOM; } - private static int CheckNoColFloorTriangle(FDControl floorData, TRRoomSector sector, int x, int z) + private static int CheckFloorTriangle(FDControl floorData, TRRoomSector sector, int x, int z) { if (sector.FDIndex == 0) { return 0; } - /* - * ------- - * | /| - * | T / | Split type 1 - * | / | - * | / B | - * |/ | - * ------- - * NOCOLF1T == FloorTriangulationNWSE_SW - * NOCOLF1B == FloorTriangulationNWSE_NE - * NOCOLF2T == FloorTriangulationNESW_SW - * NOCOLF2B == FloorTriangulationNESW_NW - */ if (floorData.Entries[sector.FDIndex].Find(e => e is TR3TriangulationEntry) is TR3TriangulationEntry triangulation) { FDFunctions func = (FDFunctions)triangulation.Setup.Value; @@ -403,26 +379,13 @@ private static int CheckNoColFloorTriangle(FDControl floorData, TRRoomSector sec return 0; } - private static int CheckNoColCeilingTriangle(FDControl floorData, TRRoomSector sector, int x, int z) + private static int CheckCeilingTriangle(FDControl floorData, TRRoomSector sector, int x, int z) { if (sector.FDIndex == 0) { return 0; } - /* - * ------- - * | /| - * | T / | Split type 3 - * | / | - * | / B | - * |/ | - * ------- - * NOCOLC1T == CeilingTriangulationNW_SW - * NOCOLC1B == CeilingTriangulationNW_NE - * NOCOLC2T == CeilingTriangulationNE_NW - * NOCOLC2B == CeilingTriangulationNE_SE - */ if (floorData.Entries[sector.FDIndex].Find(e => e is TR3TriangulationEntry) is TR3TriangulationEntry triangulation) { FDFunctions func = (FDFunctions)triangulation.Setup.Value;