Skip to content

Commit

Permalink
room: refactor tilt and portal interpretation (#1433)
Browse files Browse the repository at this point in the history
This introduces a floor data master parser to allow setting all
relevant properties for sectors once. This is applied initially to
floor and ceiling tilts, and horizontal portals. Related refactors
have been undertaken, such as combining all portal values into a struct
in the sector, and simplifying sector traversal.
  • Loading branch information
lahm86 authored Aug 8, 2024
1 parent 330a57d commit 3405e8c
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 195 deletions.
6 changes: 3 additions & 3 deletions src/game/carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static void Carrier_AnimateDrop(CARRIED_ITEM *item)
Room_GetHeight(sector, pickup->pos.x, pickup->pos.y, pickup->pos.z);
const bool in_water = g_RoomInfo[pickup->room_number].flags & RF_UNDERWATER;

if (sector->pit_room == NO_ROOM && pickup->pos.y >= height) {
if (sector->portal_room.pit == NO_ROOM && pickup->pos.y >= height) {
item->status = DS_DROPPED;
pickup->pos.y = height;
pickup->fall_speed = 0;
Expand All @@ -260,9 +260,9 @@ static void Carrier_AnimateDrop(CARRIED_ITEM *item)
pickup->pos.y += pickup->fall_speed;
pickup->rot.y += in_water ? DROP_SLOW_TURN : DROP_FAST_TURN;

if (sector->pit_room != NO_ROOM
if (sector->portal_room.pit != NO_ROOM
&& pickup->pos.y > sector->floor.height) {
room_num = sector->pit_room;
room_num = sector->portal_room.pit;
}
}

Expand Down
9 changes: 7 additions & 2 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ static bool Level_LoadRooms(MYFILE *fp)
SECTOR_INFO *const sector = &current_room_info->sectors[j];
sector->index = File_ReadU16(fp);
sector->box = File_ReadS16(fp);
sector->pit_room = File_ReadU8(fp);
sector->portal_room.pit = File_ReadU8(fp);
const int8_t floor_clicks = File_ReadS8(fp);
sector->sky_room = File_ReadU8(fp);
sector->portal_room.sky = File_ReadU8(fp);
const int8_t ceiling_clicks = File_ReadS8(fp);

sector->floor.height = floor_clicks * STEP_L;
Expand Down Expand Up @@ -853,6 +853,11 @@ static void Level_CompleteSetup(int32_t level_num)
{
Inject_AllInjections(&m_LevelInfo);

// Expand raw floor data into sectors
Room_ParseFloorData(g_FloorData);
// TODO: store raw FD temporarily in m_LevelInfo, release here and eliminate
// g_FloorData

// Must be called post-injection to allow for floor data changes.
Stats_ObserveRoomsLoad();

Expand Down
2 changes: 1 addition & 1 deletion src/game/objects/general/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void Bridge_FixEmbeddedPosition(int16_t item_num)

// Only move the bridge up if it's at floor level and there
// isn't a room portal below.
if (item->floor != floor_height || sector->pit_room != NO_ROOM) {
if (item->floor != floor_height || sector->portal_room.pit != NO_ROOM) {
return;
}

Expand Down
14 changes: 7 additions & 7 deletions src/game/objects/general/door.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ static void Door_Shut(DOORPOS_DATA *const d)
sector->box = NO_BOX;
sector->floor.height = NO_HEIGHT;
sector->ceiling.height = NO_HEIGHT;
sector->sky_room = NO_ROOM;
sector->pit_room = NO_ROOM;
sector->portal_room.sky = NO_ROOM;
sector->portal_room.pit = NO_ROOM;

const int16_t box_num = d->block;
if (box_num != NO_BOX) {
Expand Down Expand Up @@ -119,7 +119,7 @@ void Door_Initialise(int16_t item_num)
z_sector = ((item->pos.z - r->z) >> WALL_SHIFT) + dx;
x_sector = ((item->pos.x - r->x) >> WALL_SHIFT) + dy;
door->d1.sector = &r->sectors[z_sector + x_sector * r->z_size];
room_num = Room_GetDoor(door->d1.sector);
room_num = door->d1.sector->portal_room.wall;
if (room_num == NO_ROOM) {
box_num = door->d1.sector->box;
} else {
Expand All @@ -139,7 +139,7 @@ void Door_Initialise(int16_t item_num)
z_sector = ((item->pos.z - r->z) >> WALL_SHIFT) + dx;
x_sector = ((item->pos.x - r->x) >> WALL_SHIFT) + dy;
door->d1flip.sector = &r->sectors[z_sector + x_sector * r->z_size];
room_num = Room_GetDoor(door->d1flip.sector);
room_num = door->d1flip.sector->portal_room.wall;
if (room_num == NO_ROOM) {
box_num = door->d1flip.sector->box;
} else {
Expand All @@ -157,7 +157,7 @@ void Door_Initialise(int16_t item_num)
door->d1flip.sector = NULL;
}

room_num = Room_GetDoor(door->d1.sector);
room_num = door->d1.sector->portal_room.wall;
Door_Shut(&door->d1);
Door_Shut(&door->d1flip);

Expand All @@ -171,7 +171,7 @@ void Door_Initialise(int16_t item_num)
z_sector = (item->pos.z - r->z) >> WALL_SHIFT;
x_sector = (item->pos.x - r->x) >> WALL_SHIFT;
door->d2.sector = &r->sectors[z_sector + x_sector * r->z_size];
room_num = Room_GetDoor(door->d2.sector);
room_num = door->d2.sector->portal_room.wall;
if (room_num == NO_ROOM) {
box_num = door->d2.sector->box;
} else {
Expand All @@ -191,7 +191,7 @@ void Door_Initialise(int16_t item_num)
z_sector = (item->pos.z - r->z) >> WALL_SHIFT;
x_sector = (item->pos.x - r->x) >> WALL_SHIFT;
door->d2flip.sector = &r->sectors[z_sector + x_sector * r->z_size];
room_num = Room_GetDoor(door->d2flip.sector);
room_num = door->d2flip.sector->portal_room.wall;
if (room_num == NO_ROOM) {
box_num = door->d2flip.sector->box;
} else {
Expand Down
Loading

0 comments on commit 3405e8c

Please sign in to comment.