Skip to content

Commit

Permalink
room: make struct for sector floor and ceiling
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 committed Aug 6, 2024
1 parent 6c67520 commit ccbf337
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/game/carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static void Carrier_AnimateDrop(CARRIED_ITEM *item)
pickup->rot.y += in_water ? DROP_SLOW_TURN : DROP_FAST_TURN;

if (sector->pit_room != NO_ROOM
&& pickup->pos.y > (sector->floor << 8)) {
&& pickup->pos.y > (sector->floor.height << 8)) {
room_num = sector->pit_room;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/game/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,15 @@ static void Inject_RoomShift(INJECTION *injection, int16_t room_num)

// Update the sector floor and ceiling clicks to match.
const int8_t click_shift = y_shift / STEP_L;
const int8_t wall_height = NO_HEIGHT / STEP_L;
for (int i = 0; i < room->z_size * room->x_size; i++) {
SECTOR_INFO *sector = &room->sectors[i];
if (sector->floor == wall_height || sector->ceiling == wall_height) {
if (sector->floor.height == WALL_CLICKS
|| sector->ceiling.height == WALL_CLICKS) {
continue;
}

sector->floor += click_shift;
sector->ceiling += click_shift;
sector->floor.height += click_shift;
sector->ceiling.height += click_shift;
}

// Update vertex Y values to match; x and z are room-relative.
Expand Down
2 changes: 1 addition & 1 deletion src/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void Item_Initialise(int16_t item_num)
const int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT;
const SECTOR_INFO *const sector =
&r->sectors[z_sector + x_sector * r->z_size];
item->floor = sector->floor << 8;
item->floor = sector->floor.height << 8;

if (g_GameInfo.bonus_flag & GBF_NGPLUS) {
item->hit_points *= 2;
Expand Down
4 changes: 2 additions & 2 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ static bool Level_LoadRooms(MYFILE *fp)
File_Read(&sector->index, sizeof(uint16_t), 1, fp);
File_Read(&sector->box, sizeof(int16_t), 1, fp);
File_Read(&sector->pit_room, sizeof(uint8_t), 1, fp);
File_Read(&sector->floor, sizeof(int8_t), 1, fp);
File_Read(&sector->floor.height, sizeof(int8_t), 1, fp);
File_Read(&sector->sky_room, sizeof(uint8_t), 1, fp);
File_Read(&sector->ceiling, sizeof(int8_t), 1, fp);
File_Read(&sector->ceiling.height, sizeof(int8_t), 1, fp);
}

// Room lights
Expand Down
4 changes: 2 additions & 2 deletions src/game/objects/general/door.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ static void Door_Shut(DOORPOS_DATA *const d)

sector->index = 0;
sector->box = NO_BOX;
sector->floor = NO_HEIGHT / STEP_L;
sector->ceiling = NO_HEIGHT / STEP_L;
sector->floor.height = WALL_CLICKS;
sector->ceiling.height = WALL_CLICKS;
sector->sky_room = NO_ROOM;
sector->pit_room = NO_ROOM;

Expand Down
30 changes: 15 additions & 15 deletions src/game/room.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ int16_t Room_GetTiltType(
+ ((x - r->x) >> WALL_SHIFT) * r->z_size];
}

if (y + 512 < ((int32_t)sector->floor << 8)) {
if (y + 512 < ((int32_t)sector->floor.height << 8)) {
return 0;
}

Expand Down Expand Up @@ -275,7 +275,7 @@ SECTOR_INFO *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num)
}
} while (data != NO_ROOM);

if (y >= ((int32_t)sector->floor << 8)) {
if (y >= ((int32_t)sector->floor.height << 8)) {
do {
if (sector->pit_room == NO_ROOM) {
break;
Expand All @@ -287,8 +287,8 @@ SECTOR_INFO *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num)
const int32_t z_sector = (z - r->z) >> WALL_SHIFT;
const int32_t x_sector = (x - r->x) >> WALL_SHIFT;
sector = &r->sectors[z_sector + x_sector * r->z_size];
} while (y >= ((int32_t)sector->floor << 8));
} else if (y < ((int32_t)sector->ceiling << 8)) {
} while (y >= ((int32_t)sector->floor.height << 8));
} else if (y < ((int32_t)sector->ceiling.height << 8)) {
do {
if (sector->sky_room == NO_ROOM) {
break;
Expand All @@ -300,7 +300,7 @@ SECTOR_INFO *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num)
const int32_t z_sector = (z - r->z) >> WALL_SHIFT;
const int32_t x_sector = (x - r->x) >> WALL_SHIFT;
sector = &r->sectors[z_sector + x_sector * r->z_size];
} while (y < ((int32_t)sector->ceiling << 8));
} while (y < ((int32_t)sector->ceiling.height << 8));
}

return sector;
Expand All @@ -322,7 +322,7 @@ int16_t Room_GetCeiling(
sky_sector = &r->sectors[z_sector + x_sector * r->z_size];
}

int16_t height = sky_sector->ceiling << 8;
int16_t height = sky_sector->ceiling.height << 8;

if (sky_sector->index) {
data = &g_FloorData[sky_sector->index];
Expand Down Expand Up @@ -447,7 +447,7 @@ int16_t Room_GetHeight(
sector = &r->sectors[z_sector + x_sector * r->z_size];
}

int16_t height = sector->floor << 8;
int16_t height = sector->floor.height << 8;

g_TriggerIndex = NULL;

Expand Down Expand Up @@ -583,12 +583,12 @@ int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num)
x_sector = (x - r->x) >> WALL_SHIFT;
sector = &r->sectors[z_sector + x_sector * r->z_size];
}
return sector->ceiling << 8;
return sector->ceiling.height << 8;
} else {
while (sector->pit_room != NO_ROOM) {
r = &g_RoomInfo[sector->pit_room];
if (r->flags & RF_UNDERWATER) {
return sector->floor << 8;
return sector->floor.height << 8;
}
z_sector = (z - r->z) >> WALL_SHIFT;
x_sector = (x - r->x) >> WALL_SHIFT;
Expand Down Expand Up @@ -661,13 +661,13 @@ void Room_AlterFloorHeight(ITEM_INFO *item, int32_t height)
sector = &r->sectors[z_sector + x_sector * r->z_size];
}

if (sector->floor != NO_HEIGHT / 256) {
sector->floor += height >> 8;
if (sector->floor == sky_sector->ceiling) {
sector->floor = NO_HEIGHT / 256;
if (sector->floor.height != WALL_CLICKS) {
sector->floor.height += height >> 8;
if (sector->floor.height == sky_sector->ceiling.height) {
sector->floor.height = WALL_CLICKS;
}
} else {
sector->floor = sky_sector->ceiling + (height >> 8);
sector->floor.height = sky_sector->ceiling.height + (height >> 8);
}

if (g_Boxes[sector->box].overlap_index & BLOCKABLE) {
Expand Down Expand Up @@ -993,7 +993,7 @@ bool Room_IsOnWalkable(
sector = &r->sectors[z_sector + x_sector * r->z_size];
}

int16_t height = sector->floor << 8;
int16_t height = sector->floor.height << 8;
bool object_found = false;

int16_t *floor_data = &g_FloorData[sector->index];
Expand Down
1 change: 1 addition & 0 deletions src/global/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
#define DONT_TARGET (-16384)
#define UNIT_SHADOW 256
#define NO_HEIGHT (-32512)
#define WALL_CLICKS (NO_HEIGHT / STEP_L)
#define NO_BAD_POS (-NO_HEIGHT)
#define NO_BAD_NEG NO_HEIGHT
#define BAD_JUMP_CEILING ((STEP_L * 3) / 4) // = 192
Expand Down
5 changes: 3 additions & 2 deletions src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,10 @@ typedef struct SECTOR_INFO {
uint16_t index;
int16_t box;
uint8_t pit_room;
int8_t floor;
uint8_t sky_room;
int8_t ceiling;
struct {
int8_t height;
} floor, ceiling;
} SECTOR_INFO;

typedef struct DOORPOS_DATA {
Expand Down

0 comments on commit ccbf337

Please sign in to comment.