Skip to content

Commit

Permalink
room: rename floor info (LostArtefacts#1428)
Browse files Browse the repository at this point in the history
This renames FLOOR_INFO to SECTOR_INFO to help distinguish it in cases
where floor is used in reference to height. The naming is more in line
with Tomb Editor, the TRosettaStone documentation and so forth.

Part of LostArtefacts#941.
  • Loading branch information
lahm86 authored Aug 5, 2024
1 parent 0fdb842 commit 0a24856
Show file tree
Hide file tree
Showing 47 changed files with 573 additions and 554 deletions.
8 changes: 4 additions & 4 deletions src/game/box.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,16 +426,16 @@ bool Box_BadFloor(
int32_t x, int32_t y, int32_t z, int16_t box_height, int16_t next_height,
int16_t room_number, LOT_INFO *LOT)
{
FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_number);
if (floor->box == NO_BOX) {
const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_number);
if (sector->box == NO_BOX) {
return true;
}

if (g_Boxes[floor->box].overlap_index & LOT->block_mask) {
if (g_Boxes[sector->box].overlap_index & LOT->block_mask) {
return true;
}

int32_t height = g_Boxes[floor->box].height;
const int32_t height = g_Boxes[sector->box].height;
if (box_height - height > LOT->step || box_height - height < LOT->drop) {
return true;
}
Expand Down
53 changes: 27 additions & 26 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ static void Camera_EnsureEnvironment(void);
static bool Camera_BadPosition(
int32_t x, int32_t y, int32_t z, int16_t room_num)
{
FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num);
return y >= Room_GetHeight(floor, x, y, z)
|| y <= Room_GetCeiling(floor, x, y, z);
const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num);
return y >= Room_GetHeight(sector, x, y, z)
|| y <= Room_GetCeiling(sector, x, y, z);
}

static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp)
Expand All @@ -58,9 +58,10 @@ static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp)
int32_t y = pos->y;
int32_t z = pos->z;

FLOOR_INFO *floor = Room_GetFloor(x, y, z, &pos->room_number);
const SECTOR_INFO *const sector =
Room_GetSector(x, y, z, &pos->room_number);

BOX_INFO *box = &g_Boxes[floor->box];
const BOX_INFO *const box = &g_Boxes[sector->box];
if (z < box->left + clamp
&& Camera_BadPosition(x, y, z - clamp, pos->room_number)) {
pos->z = box->left + clamp;
Expand All @@ -79,8 +80,8 @@ static int32_t Camera_ShiftClamp(GAME_VECTOR *pos, int32_t clamp)
pos->x = box->bottom - clamp;
}

int32_t height = Room_GetHeight(floor, x, y, z) - clamp;
int32_t ceiling = Room_GetCeiling(floor, x, y, z) + clamp;
int32_t height = Room_GetHeight(sector, x, y, z) - clamp;
int32_t ceiling = Room_GetCeiling(sector, x, y, z) + clamp;

if (height < ceiling) {
ceiling = (height + ceiling) >> 1;
Expand All @@ -104,18 +105,18 @@ static void Camera_SmartShift(
{
LOS_Check(&g_Camera.target, ideal);

ROOM_INFO *r = &g_RoomInfo[g_Camera.target.room_number];
int32_t x_floor = (g_Camera.target.z - r->z) >> WALL_SHIFT;
int32_t y_floor = (g_Camera.target.x - r->x) >> WALL_SHIFT;
const ROOM_INFO *r = &g_RoomInfo[g_Camera.target.room_number];
int32_t z_sector = (g_Camera.target.z - r->z) >> WALL_SHIFT;
int32_t x_sector = (g_Camera.target.x - r->x) >> WALL_SHIFT;

int16_t item_box = r->floor[x_floor + y_floor * r->x_size].box;
const int16_t item_box = r->sectors[z_sector + x_sector * r->z_size].box;
BOX_INFO *box = &g_Boxes[item_box];

r = &g_RoomInfo[ideal->room_number];
x_floor = (ideal->z - r->z) >> WALL_SHIFT;
y_floor = (ideal->x - r->x) >> WALL_SHIFT;
z_sector = (ideal->z - r->z) >> WALL_SHIFT;
x_sector = (ideal->x - r->x) >> WALL_SHIFT;

int16_t camera_box = r->floor[x_floor + y_floor * r->x_size].box;
int16_t camera_box = r->sectors[z_sector + x_sector * r->z_size].box;
if (camera_box != NO_BOX
&& (ideal->z < box->left || ideal->z > box->right || ideal->x < box->top
|| ideal->x > box->bottom)) {
Expand All @@ -131,7 +132,7 @@ static void Camera_SmartShift(
bool bad_left =
Camera_BadPosition(ideal->x, ideal->y, test, ideal->room_number);
if (!bad_left) {
camera_box = r->floor[x_floor - 1 + y_floor * r->x_size].box;
camera_box = r->sectors[z_sector - 1 + x_sector * r->z_size].box;
if (camera_box != NO_ITEM && g_Boxes[camera_box].left < left) {
left = g_Boxes[camera_box].left;
}
Expand All @@ -141,7 +142,7 @@ static void Camera_SmartShift(
bool bad_right =
Camera_BadPosition(ideal->x, ideal->y, test, ideal->room_number);
if (!bad_right) {
camera_box = r->floor[x_floor + 1 + y_floor * r->x_size].box;
camera_box = r->sectors[z_sector + 1 + x_sector * r->z_size].box;
if (camera_box != NO_ITEM && g_Boxes[camera_box].right > right) {
right = g_Boxes[camera_box].right;
}
Expand All @@ -151,7 +152,7 @@ static void Camera_SmartShift(
bool bad_top =
Camera_BadPosition(test, ideal->y, ideal->z, ideal->room_number);
if (!bad_top) {
camera_box = r->floor[x_floor + (y_floor - 1) * r->x_size].box;
camera_box = r->sectors[z_sector + (x_sector - 1) * r->z_size].box;
if (camera_box != NO_ITEM && g_Boxes[camera_box].top < top) {
top = g_Boxes[camera_box].top;
}
Expand All @@ -161,7 +162,7 @@ static void Camera_SmartShift(
bool bad_bottom =
Camera_BadPosition(test, ideal->y, ideal->z, ideal->room_number);
if (!bad_bottom) {
camera_box = r->floor[x_floor + (y_floor + 1) * r->x_size].box;
camera_box = r->sectors[z_sector + (x_sector + 1) * r->z_size].box;
if (camera_box != NO_ITEM && g_Boxes[camera_box].bottom > bottom) {
bottom = g_Boxes[camera_box].bottom;
}
Expand Down Expand Up @@ -224,7 +225,7 @@ static void Camera_SmartShift(
}

if (!noclip) {
Room_GetFloor(ideal->x, ideal->y, ideal->z, &ideal->room_number);
Room_GetSector(ideal->x, ideal->y, ideal->z, &ideal->room_number);
}
}

Expand Down Expand Up @@ -302,25 +303,25 @@ static void Camera_Move(GAME_VECTOR *ideal, int32_t speed)

g_ChunkyFlag = false;

FLOOR_INFO *floor = Room_GetFloor(
const SECTOR_INFO *sector = Room_GetSector(
g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z,
&g_Camera.pos.room_number);
int32_t height =
Room_GetHeight(floor, g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z)
Room_GetHeight(sector, g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z)
- GROUND_SHIFT;

if (g_Camera.pos.y >= height && ideal->y >= height) {
LOS_Check(&g_Camera.target, &g_Camera.pos);
floor = Room_GetFloor(
sector = Room_GetSector(
g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z,
&g_Camera.pos.room_number);
height = Room_GetHeight(
floor, g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z)
sector, g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z)
- GROUND_SHIFT;
}

int32_t ceiling =
Room_GetCeiling(floor, g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z)
Room_GetCeiling(sector, g_Camera.pos.x, g_Camera.pos.y, g_Camera.pos.z)
+ GROUND_SHIFT;
if (height < ceiling) {
ceiling = (height + ceiling) >> 1;
Expand Down Expand Up @@ -697,11 +698,11 @@ void Camera_Update(void)
g_Camera.fixed_camera = 0;
}

FLOOR_INFO *floor = Room_GetFloor(
const SECTOR_INFO *const sector = Room_GetSector(
g_Camera.target.x, g_Camera.target.y, g_Camera.target.z,
&g_Camera.target.room_number);
if (g_Camera.target.y > Room_GetHeight(
floor, g_Camera.target.x, g_Camera.target.y,
sector, g_Camera.target.x, g_Camera.target.y,
g_Camera.target.z)) {
g_ChunkyFlag = false;
}
Expand Down
19 changes: 10 additions & 9 deletions src/game/carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ static void Carrier_AnimateDrop(CARRIED_ITEM *item)
return;
}

ITEM_INFO *pickup = &g_Items[item->spawn_number];
ITEM_INFO *const pickup = &g_Items[item->spawn_number];
int16_t room_num = pickup->room_number;
FLOOR_INFO *floor =
Room_GetFloor(pickup->pos.x, pickup->pos.y, pickup->pos.z, &room_num);
int16_t height =
Room_GetHeight(floor, pickup->pos.x, pickup->pos.y, pickup->pos.z);
bool in_water = g_RoomInfo[pickup->room_number].flags & RF_UNDERWATER;
const SECTOR_INFO *const sector =
Room_GetSector(pickup->pos.x, pickup->pos.y, pickup->pos.z, &room_num);
const int16_t height =
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 (floor->pit_room == NO_ROOM && pickup->pos.y >= height) {
if (sector->pit_room == NO_ROOM && pickup->pos.y >= height) {
item->status = DS_DROPPED;
pickup->pos.y = height;
pickup->fall_speed = 0;
Expand All @@ -260,8 +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 (floor->pit_room != NO_ROOM && pickup->pos.y > (floor->floor << 8)) {
room_num = floor->pit_room;
if (sector->pit_room != NO_ROOM
&& pickup->pos.y > (sector->floor << 8)) {
room_num = sector->pit_room;
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/game/collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ void Collide_GetCollisionInfo(
int32_t z = zpos;
int32_t ytop = y - 160;

FLOOR_INFO *floor = Room_GetFloor(x, ytop, z, &room_num);
int32_t height = Room_GetHeight(floor, x, ytop, z);
const SECTOR_INFO *sector = Room_GetSector(x, ytop, z, &room_num);
int32_t height = Room_GetHeight(sector, x, ytop, z);
int32_t room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}

int32_t ceiling = Room_GetCeiling(floor, x, ytop, z);
int32_t ceiling = Room_GetCeiling(sector, x, ytop, z);
if (ceiling != NO_HEIGHT) {
ceiling -= y;
}
Expand All @@ -44,8 +44,8 @@ void Collide_GetCollisionInfo(
coll->trigger = g_TriggerIndex;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
int16_t tilt = Room_GetTiltType(floor, x, g_LaraItem->pos.y, z);
|| !Room_IsOnWalkable(sector, x, ytop, z, room_height)) {
const int16_t tilt = Room_GetTiltType(sector, x, g_LaraItem->pos.y, z);
coll->tilt_z = tilt >> 8;
coll->tilt_x = (int8_t)tilt;
} else {
Expand Down Expand Up @@ -109,14 +109,14 @@ void Collide_GetCollisionInfo(
// Front.
x = xpos + xfront;
z = zpos + zfront;
floor = Room_GetFloor(x, ytop, z, &room_num);
height = Room_GetHeight(floor, x, ytop, z);
sector = Room_GetSector(x, ytop, z, &room_num);
height = Room_GetHeight(sector, x, ytop, z);
room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}

ceiling = Room_GetCeiling(floor, x, ytop, z);
ceiling = Room_GetCeiling(sector, x, ytop, z);
if (ceiling != NO_HEIGHT) {
ceiling -= y;
}
Expand All @@ -126,7 +126,7 @@ void Collide_GetCollisionInfo(
coll->front_type = g_HeightType;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
|| !Room_IsOnWalkable(sector, x, ytop, z, room_height)) {
if (coll->slopes_are_walls && coll->front_type == HT_BIG_SLOPE
&& coll->front_floor < 0) {
coll->front_floor = -32767;
Expand All @@ -144,14 +144,14 @@ void Collide_GetCollisionInfo(
// Left.
x = xpos + xleft;
z = zpos + zleft;
floor = Room_GetFloor(x, ytop, z, &room_num);
height = Room_GetHeight(floor, x, ytop, z);
sector = Room_GetSector(x, ytop, z, &room_num);
height = Room_GetHeight(sector, x, ytop, z);
room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}

ceiling = Room_GetCeiling(floor, x, ytop, z);
ceiling = Room_GetCeiling(sector, x, ytop, z);
if (ceiling != NO_HEIGHT) {
ceiling -= y;
}
Expand All @@ -161,7 +161,7 @@ void Collide_GetCollisionInfo(
coll->left_type = g_HeightType;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
|| !Room_IsOnWalkable(sector, x, ytop, z, room_height)) {
if (coll->slopes_are_walls && coll->left_type == HT_BIG_SLOPE
&& coll->left_floor < 0) {
coll->left_floor = -32767;
Expand All @@ -179,14 +179,14 @@ void Collide_GetCollisionInfo(
// Right.
x = xpos + xright;
z = zpos + zright;
floor = Room_GetFloor(x, ytop, z, &room_num);
height = Room_GetHeight(floor, x, ytop, z);
sector = Room_GetSector(x, ytop, z, &room_num);
height = Room_GetHeight(sector, x, ytop, z);
room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}

ceiling = Room_GetCeiling(floor, x, ytop, z);
ceiling = Room_GetCeiling(sector, x, ytop, z);
if (ceiling != NO_HEIGHT) {
ceiling -= y;
}
Expand All @@ -196,7 +196,7 @@ void Collide_GetCollisionInfo(
coll->right_type = g_HeightType;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
|| !Room_IsOnWalkable(sector, x, ytop, z, room_height)) {
if (coll->slopes_are_walls && coll->right_type == HT_BIG_SLOPE
&& coll->right_floor < 0) {
coll->right_floor = -32767;
Expand All @@ -213,13 +213,13 @@ void Collide_GetCollisionInfo(

if (Collide_CollideStaticObjects(
coll, xpos, ypos, zpos, room_num, obj_height)) {
floor = Room_GetFloor(
sector = Room_GetSector(
xpos + coll->shift.x, ypos, zpos + coll->shift.z, &room_num);
if (Room_GetHeight(
floor, xpos + coll->shift.x, ypos, zpos + coll->shift.z)
sector, xpos + coll->shift.x, ypos, zpos + coll->shift.z)
< ypos - 512
|| Room_GetCeiling(
floor, xpos + coll->shift.x, ypos, zpos + coll->shift.z)
sector, xpos + coll->shift.x, ypos, zpos + coll->shift.z)
> y) {
coll->shift.x = -coll->shift.x;
coll->shift.z = -coll->shift.z;
Expand Down
4 changes: 2 additions & 2 deletions src/game/console_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ static COMMAND_RESULT Console_Cmd_Teleport(const char *const args)
const ROOM_INFO *const room = &g_RoomInfo[room_num];

const int32_t x1 = room->x + WALL_L;
const int32_t x2 = (room->y_size << WALL_SHIFT) + room->x - WALL_L;
const int32_t x2 = (room->x_size << WALL_SHIFT) + room->x - WALL_L;
const int32_t y1 = room->min_floor;
const int32_t y2 = room->max_ceiling;
const int32_t z1 = room->z + WALL_L;
const int32_t z2 = (room->x_size << WALL_SHIFT) + room->z - WALL_L;
const int32_t z2 = (room->z_size << WALL_SHIFT) + room->z - WALL_L;

for (int i = 0; i < 100; i++) {
int32_t x = x1 + Random_GetControl() * (x2 - x1) / 0x7FFF;
Expand Down
Loading

0 comments on commit 0a24856

Please sign in to comment.