Remove skyRoom/pitRoom

This commit is contained in:
Lwmte 2021-09-11 23:50:54 +03:00
parent c67290bc30
commit 0fd07f11dc
9 changed files with 70 additions and 85 deletions

View file

@ -151,9 +151,9 @@ int GetWaterDepth(int x, int y, int z, short roomNumber)
if (r->flags & (ENV_FLAG_WATER|ENV_FLAG_SWAMP))
{
while (floor->skyRoom != NO_ROOM)
while (floor->RoomAbove() != NO_ROOM)
{
r = &g_Level.Rooms[floor->skyRoom];
r = &g_Level.Rooms[floor->RoomAbove()];
if (!(r->flags & (ENV_FLAG_WATER|ENV_FLAG_SWAMP)))
{
int wh = floor->ceiling << 8;
@ -166,9 +166,9 @@ int GetWaterDepth(int x, int y, int z, short roomNumber)
}
else
{
while (floor->pitRoom != NO_ROOM)
while (floor->RoomBelow() != NO_ROOM)
{
r = &g_Level.Rooms[floor->pitRoom];
r = &g_Level.Rooms[floor->RoomBelow()];
if (r->flags & (ENV_FLAG_WATER|ENV_FLAG_SWAMP))
{
int wh = floor->floor << 8;

View file

@ -1247,11 +1247,11 @@ COLL_RESULT GetCollisionResult(FLOOR_INFO* floor, int x, int y, int z)
// Probe bottom block through portals.
// TODO: Check if it is really needed, as GetFloor should take care of it itself?
ROOM_INFO* r;
while (floor->pitRoom != NO_ROOM)
while (floor->RoomBelow() != NO_ROOM)
{
if (CheckNoColFloorTriangle(floor, x, z) == 1)
break;
r = &g_Level.Rooms[floor->pitRoom];
r = &g_Level.Rooms[floor->RoomBelow()];
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
}

View file

@ -875,9 +875,9 @@ int GetWaterSurface(int x, int y, int z, short roomNumber)
if (room->flags & ENV_FLAG_WATER)
{
while (floor->skyRoom != NO_ROOM)
while (floor->RoomAbove() != NO_ROOM)
{
room = &g_Level.Rooms[floor->skyRoom];
room = &g_Level.Rooms[floor->RoomAbove()];
if (!(room->flags & ENV_FLAG_WATER))
return (floor->ceiling << 8);
floor = XZ_GET_SECTOR(room, x - room->x, z - room->z);
@ -886,9 +886,9 @@ int GetWaterSurface(int x, int y, int z, short roomNumber)
}
else
{
while (floor->pitRoom != NO_ROOM)
while (floor->RoomBelow() != NO_ROOM)
{
room = &g_Level.Rooms[floor->pitRoom];
room = &g_Level.Rooms[floor->RoomBelow()];
if (room->flags & ENV_FLAG_WATER)
return (floor->floor << 8);
floor = XZ_GET_SECTOR(room, x - room->x, z - room->z);
@ -1016,56 +1016,24 @@ FLOOR_INFO *GetFloor(int x, int y, int z, short *roomNumber)
int CheckNoColFloorTriangle(FLOOR_INFO *floor, int x, int z)
{
if (floor->FloorIsSplit() &&
(floor->FloorCollision.Portals[0] != 0 || floor->FloorCollision.Portals[1] != 0))
{
int dx = x & 1023;
int dz = z & 1023;
// TODO: bring these checks back!
//if (type == NOCOLF1T && dx <= (SECTOR(1) - dz))
// return -1;
//else if (type == NOCOLF1B && dx > (SECTOR(1) - dz))
// return -1;
//else if (type == NOCOLF2T && dx <= dz)
// return -1;
//else if (type == NOCOLF2B && dx > dz)
// return -1;
//else
// return 1;
if (!floor->FloorIsSplit())
return 0;
if (floor->FloorCollision.Portals[floor->SectorPlane(x, z)] == NO_ROOM)
return 1;
}
return 0;
else
return -1;
}
int CheckNoColCeilingTriangle(FLOOR_INFO *floor, int x, int z)
{
if (floor->CeilingIsSplit() &&
(floor->CeilingCollision.Portals[0] != 0 || floor->CeilingCollision.Portals[1] != 0))
{
int dx = x & 1023;
int dz = z & 1023;
// TODO: bring these checks back!
//if (type == NOCOLC1T && dx <= (SECTOR(1) - dz))
// return -1;
//else if (type == NOCOLC1B && dx > (SECTOR(1) - dz))
// return -1;
//else if (type == NOCOLC2T && dx <= dz)
// return -1;
//else if (type == NOCOLC2B && dx > dz)
// return -1;
//else
// return 1;
if (!floor->CeilingIsSplit())
return 0;
if (floor->CeilingCollision.Portals[floor->SectorPlaneCeiling(x, z)] == NO_ROOM)
return 1;
}
return 0;
else
return -1;
}
int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z)
@ -2291,15 +2259,15 @@ int GetWaterHeight(int x, int y, int z, short roomNumber)
if (r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP))
{
while (floor->skyRoom != NO_ROOM)
while (floor->RoomAbove() != NO_ROOM)
{
if (CheckNoColCeilingTriangle(floor, x, z) == 1)
break;
r = &g_Level.Rooms[floor->skyRoom];
r = &g_Level.Rooms[floor->RoomAbove()];
if (!(r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP)))
return r->minfloor;
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
if (floor->skyRoom == NO_ROOM)
if (floor->RoomAbove() == NO_ROOM)
break;
}
@ -2307,15 +2275,15 @@ int GetWaterHeight(int x, int y, int z, short roomNumber)
}
else
{
while (floor->pitRoom != NO_ROOM)
while (floor->RoomBelow() != NO_ROOM)
{
if (CheckNoColFloorTriangle(floor, x, z) == 1)
break;
r = &g_Level.Rooms[floor->pitRoom];
r = &g_Level.Rooms[floor->RoomBelow()];
if (r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP))
return r->maxceiling;
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
if (floor->pitRoom == NO_ROOM)
if (floor->RoomBelow() == NO_ROOM)
break;
}
}

View file

@ -153,11 +153,11 @@ int SwitchTrigger(short itemNum, short timer)
short* GetTriggerIndex(FLOOR_INFO* floor, int x, int y, int z)
{
ROOM_INFO* r;
while (floor->pitRoom != NO_ROOM)
while (floor->RoomBelow() != NO_ROOM)
{
if (CheckNoColFloorTriangle(floor, x, z) == 1)
break;
r = &g_Level.Rooms[floor->pitRoom];
r = &g_Level.Rooms[floor->RoomBelow()];
floor = XZ_GET_SECTOR(r, x - r->x, z - r->z);
}

View file

@ -129,18 +129,18 @@ void UpdateDebris()
deb.angularVelocity *= deb.angularDrag;
roomNumber = deb.roomNumber;
floor = GetFloor(deb.worldPosition.x, deb.worldPosition.y, deb.worldPosition.z,&roomNumber);
floor = GetFloor(deb.worldPosition.x, deb.worldPosition.y, deb.worldPosition.z, &roomNumber);
if (deb.worldPosition.y < floor->ceiling*256)
{
if (floor->skyRoom != NO_ROOM)
deb.roomNumber = floor->skyRoom;
if (floor->RoomAbove() != NO_ROOM)
deb.roomNumber = floor->RoomAbove();
}
if (deb.worldPosition.y > floor->floor*256)
{
if (floor->pitRoom != NO_ROOM)
deb.roomNumber = floor->pitRoom;
if (floor->RoomBelow() != NO_ROOM)
deb.roomNumber = floor->RoomBelow();
if (deb.numBounces > 3)
{

View file

@ -7,6 +7,26 @@
using namespace TEN::Floordata;
int FLOOR_INFO::RoomBelow() const
{
if (FloorCollision.Portals[0] != NO_ROOM)
return FloorCollision.Portals[0];
else if (FloorCollision.Portals[1] != NO_ROOM)
return FloorCollision.Portals[1];
else
return NO_ROOM;
}
int FLOOR_INFO::RoomAbove() const
{
if (CeilingCollision.Portals[0] != NO_ROOM)
return CeilingCollision.Portals[0];
else if (CeilingCollision.Portals[1] != NO_ROOM)
return CeilingCollision.Portals[1];
else
return NO_ROOM;
}
int FLOOR_INFO::SectorPlane(int x, int z) const
{
const auto point = GetSectorPoint(x, z);
@ -52,16 +72,6 @@ bool FLOOR_INFO::CeilingIsSplit() const
return differentPlanes || differentPortals;
}
bool FLOOR_INFO::FloorIsDiagonalStep() const
{
return FloorCollision.Planes[0].z != FloorCollision.Planes[1].z;
}
bool FLOOR_INFO::CeilingIsDiagonalStep() const
{
return CeilingCollision.Planes[0].z != CeilingCollision.Planes[1].z;
}
std::optional<int> FLOOR_INFO::RoomBelow(int plane) const
{
const auto room = FloorCollision.Portals[plane];

View file

@ -31,9 +31,7 @@ class FLOOR_INFO
int box;
int fx;
int stopper;
int pitRoom;
int floor;
int skyRoom;
int ceiling;
SECTOR_COLLISION_INFO FloorCollision;
SECTOR_COLLISION_INFO CeilingCollision;
@ -42,13 +40,18 @@ class FLOOR_INFO
std::set<short> BridgeItem;
int Room;
// These two functions return single floor/ceiling portal for legacy code.
// Later, when there will be possible to make 2 separate portals in 2
// planes, these functions should be somehow resolved along with legacy code.
int RoomAbove() const;
int RoomBelow() const;
int SectorPlane(int x, int z) const;
int SectorPlaneCeiling(int x, int z) const;
std::pair<int, int> FLOOR_INFO::TiltXZ(int x, int z) const;
bool FloorIsSplit() const;
bool CeilingIsSplit() const;
bool FloorIsDiagonalStep() const;
bool CeilingIsDiagonalStep() const;
std::optional<int> RoomBelow(int plane) const;
std::optional<int> RoomBelow(int x, int z) const;
std::optional<int> RoomBelow(int x, int z, int y) const;

View file

@ -438,11 +438,17 @@ namespace TEN::Entities::Doors
if (floor)
{
floor->box = NO_BOX;
floor->ceiling = -127;
floor->floor = -127;
floor->index = 0;
floor->skyRoom = NO_ROOM;
floor->pitRoom = NO_ROOM;
// FIXME: HACK!!!!!!!
floor->FloorCollision.Portals[0] = NO_ROOM;
floor->FloorCollision.Portals[1] = NO_ROOM;
floor->CeilingCollision.Portals[0] = NO_ROOM;
floor->CeilingCollision.Portals[1] = NO_ROOM;
floor->FloorCollision.Planes[0].z = -127;
floor->FloorCollision.Planes[1].z = -127;
floor->CeilingCollision.Planes[0].z = -127;
floor->CeilingCollision.Planes[1].z = -127;
short boxIndex = doorPos->block;
if (boxIndex != NO_BOX)

View file

@ -648,9 +648,7 @@ void ReadRooms()
floor.box = ReadInt32();
floor.fx = ReadInt32();
floor.stopper = ReadInt32();
floor.pitRoom = ReadInt32();
floor.floor = ReadInt32();
floor.skyRoom = ReadInt32();
floor.ceiling = ReadInt32();
floor.FloorCollision.SplitAngle = ReadFloat();