diff --git a/src/game/box.c b/src/game/box.c index f06c9bede..4745bcbcc 100644 --- a/src/game/box.c +++ b/src/game/box.c @@ -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; } diff --git a/src/game/camera.c b/src/game/camera.c index b5ee0d47e..42c679322 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -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) @@ -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; @@ -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; @@ -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)) { @@ -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; } @@ -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; } @@ -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; } @@ -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; } @@ -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); } } @@ -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; @@ -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; } diff --git a/src/game/carrier.c b/src/game/carrier.c index 7bf24c8b0..6efe2b594 100644 --- a/src/game/carrier.c +++ b/src/game/carrier.c @@ -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; @@ -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; } } diff --git a/src/game/collide.c b/src/game/collide.c index abe8577c5..bdf9b9478 100644 --- a/src/game/collide.c +++ b/src/game/collide.c @@ -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; } @@ -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 { @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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; diff --git a/src/game/console_cmd.c b/src/game/console_cmd.c index 77adeadfa..43a1e77cc 100644 --- a/src/game/console_cmd.c +++ b/src/game/console_cmd.c @@ -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; diff --git a/src/game/creature.c b/src/game/creature.c index f76b221f1..2dab826fb 100644 --- a/src/game/creature.c +++ b/src/game/creature.c @@ -49,16 +49,16 @@ void Creature_AIInfo(ITEM_INFO *item, AI_INFO *info) zone = g_GroundZone2[g_FlipStatus]; } - ROOM_INFO *r = &g_RoomInfo[item->room_number]; - int32_t x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - item->box_number = r->floor[x_floor + y_floor * r->x_size].box; + const ROOM_INFO *r = &g_RoomInfo[item->room_number]; + int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; + int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; + item->box_number = r->sectors[z_sector + x_sector * r->z_size].box; info->zone_number = zone[item->box_number]; r = &g_RoomInfo[g_LaraItem->room_number]; - x_floor = (g_LaraItem->pos.z - r->z) >> WALL_SHIFT; - y_floor = (g_LaraItem->pos.x - r->x) >> WALL_SHIFT; - g_LaraItem->box_number = r->floor[x_floor + y_floor * r->x_size].box; + z_sector = (g_LaraItem->pos.z - r->z) >> WALL_SHIFT; + x_sector = (g_LaraItem->pos.x - r->x) >> WALL_SHIFT; + g_LaraItem->box_number = r->sectors[z_sector + x_sector * r->z_size].box; info->enemy_zone = zone[g_LaraItem->box_number]; if (g_Boxes[g_LaraItem->box_number].overlap_index @@ -433,9 +433,10 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) int32_t y = item->pos.y + bounds->min.y; int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(item->pos.x, y, item->pos.z, &room_num); - int32_t height = g_Boxes[floor->box].height; - int16_t next_box = LOT->node[floor->box].exit_box; + const SECTOR_INFO *sector = + Room_GetSector(item->pos.x, y, item->pos.z, &room_num); + int32_t height = g_Boxes[sector->box].height; + int16_t next_box = LOT->node[sector->box].exit_box; int32_t next_height; if (next_box != NO_BOX) { next_height = g_Boxes[next_box].height; @@ -447,7 +448,7 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) int32_t pos_z; int32_t shift_x; int32_t shift_z; - if (floor->box == NO_BOX || zone[item->box_number] != zone[floor->box] + if (sector->box == NO_BOX || zone[item->box_number] != zone[sector->box] || box_height - height > LOT->step || box_height - height < LOT->drop) { pos_x = item->pos.x >> WALL_SHIFT; @@ -466,9 +467,9 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) item->pos.z = old.z | (WALL_L - 1); } - floor = Room_GetFloor(item->pos.x, y, item->pos.z, &room_num); - height = g_Boxes[floor->box].height; - next_box = LOT->node[floor->box].exit_box; + sector = Room_GetSector(item->pos.x, y, item->pos.z, &room_num); + height = g_Boxes[sector->box].height; + next_box = LOT->node[sector->box].exit_box; if (next_box != NO_BOX) { next_height = g_Boxes[next_box].height; } else { @@ -576,7 +577,7 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) item->pos.z += shift_z; if (shift_x || shift_z) { - floor = Room_GetFloor(item->pos.x, y, item->pos.z, &room_num); + sector = Room_GetSector(item->pos.x, y, item->pos.z, &room_num); item->rot.y += angle; Creature_Tilt(item, tilt * 2); @@ -597,7 +598,7 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) dy = -LOT->fly; } - height = Room_GetHeight(floor, item->pos.x, y, item->pos.z); + height = Room_GetHeight(sector, item->pos.x, y, item->pos.z); if (item->pos.y + dy > height) { if (item->pos.y > height) { item->pos.x = old.x; @@ -609,7 +610,7 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) } } else { int32_t ceiling = - Room_GetCeiling(floor, item->pos.x, y, item->pos.z); + Room_GetCeiling(sector, item->pos.x, y, item->pos.z); int32_t min_y = item->object_number == O_ALLIGATOR ? 0 : bounds->min.y; @@ -625,8 +626,8 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) } item->pos.y += dy; - floor = Room_GetFloor(item->pos.x, y, item->pos.z, &room_num); - item->floor = Room_GetHeight(floor, item->pos.x, y, item->pos.z); + sector = Room_GetSector(item->pos.x, y, item->pos.z, &room_num); + item->floor = Room_GetHeight(sector, item->pos.x, y, item->pos.z); angle = item->speed ? Math_Atan(item->speed, -dy) : 0; if (angle < item->rot.x - PHD_DEGREE) { @@ -637,9 +638,10 @@ bool Creature_Animate(int16_t item_num, int16_t angle, int16_t tilt) item->rot.x = angle; } } else { - floor = Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); item->floor = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); if (item->pos.y > item->floor) { item->pos.y = item->floor; @@ -781,10 +783,10 @@ static bool Creature_SwitchToLand( item->goal_anim_state = item->current_anim_state; int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); item->floor = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); item->pos.y = item->floor; if (item->room_number != room_num) { diff --git a/src/game/gamebuf.c b/src/game/gamebuf.c index 8c1a89c4f..0b767e632 100644 --- a/src/game/gamebuf.c +++ b/src/game/gamebuf.c @@ -28,7 +28,7 @@ static const char *GameBuf_GetBufferName(GAME_BUFFER buffer) case GBUF_ROOM_INFOS: return "Room information"; case GBUF_ROOM_MESH: return "Room meshes"; case GBUF_ROOM_DOOR: return "Room doors"; - case GBUF_ROOM_FLOOR: return "Room floor information"; + case GBUF_ROOM_SECTOR: return "Room sector information"; case GBUF_ROOM_LIGHTS: return "Room lights"; case GBUF_ROOM_STATIC_MESH_INFOS: return "Room static meshes"; case GBUF_FLOOR_DATA: return "Floor data"; diff --git a/src/game/gamebuf.h b/src/game/gamebuf.h index 611e679fa..83c4a29d2 100644 --- a/src/game/gamebuf.h +++ b/src/game/gamebuf.h @@ -22,7 +22,7 @@ typedef enum GAME_BUFFER { GBUF_ROOM_INFOS, GBUF_ROOM_MESH, GBUF_ROOM_DOOR, - GBUF_ROOM_FLOOR, + GBUF_ROOM_SECTOR, GBUF_ROOM_LIGHTS, GBUF_ROOM_STATIC_MESH_INFOS, GBUF_FLOOR_DATA, diff --git a/src/game/inject.c b/src/game/inject.c index cd2923aeb..4098912ac 100644 --- a/src/game/inject.c +++ b/src/game/inject.c @@ -135,10 +135,10 @@ static void Inject_TextureOverwrites( static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info); static void Inject_TriggerParameterChange( - INJECTION *injection, FLOOR_INFO *floor); -static void Inject_SetMusicOneShot(FLOOR_INFO *floor); + INJECTION *injection, SECTOR_INFO *sector); +static void Inject_SetMusicOneShot(SECTOR_INFO *sector); static void Inject_InsertFloorData( - INJECTION *injection, FLOOR_INFO *floor, LEVEL_INFO *level_info); + INJECTION *injection, SECTOR_INFO *sector, LEVEL_INFO *level_info); static void Inject_RoomShift(INJECTION *injection, int16_t room_num); static void Inject_TriggeredItem(INJECTION *injection, LEVEL_INFO *level_info); @@ -1130,26 +1130,26 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) int32_t fd_edit_count; FLOOR_EDIT_TYPE edit_type; int16_t room; - uint16_t y, x; + uint16_t x, z; for (int i = 0; i < inj_info->floor_edit_count; i++) { File_Read(&room, sizeof(int16_t), 1, fp); - File_Read(&y, sizeof(uint16_t), 1, fp); File_Read(&x, sizeof(uint16_t), 1, fp); + File_Read(&z, sizeof(uint16_t), 1, fp); File_Read(&fd_edit_count, sizeof(int32_t), 1, fp); // Verify that the given room and coordinates are accurate. - // Individual FD functions must check that floor is actually set. + // Individual FD functions must check that sector is actually set. ROOM_INFO *r = NULL; - FLOOR_INFO *floor = NULL; + SECTOR_INFO *sector = NULL; if (room < 0 || room >= g_RoomCount) { LOG_WARNING("Room index %d is invalid", room); } else { r = &g_RoomInfo[room]; - if (y >= r->y_size || x >= r->x_size) { + if (x >= r->x_size || z >= r->z_size) { LOG_WARNING( - "Sector [%d,%d] is invalid for room %d", y, x, room); + "Sector [%d,%d] is invalid for room %d", x, z, room); } else { - floor = &r->floor[r->x_size * y + x]; + sector = &r->sectors[r->z_size * x + z]; } } @@ -1157,13 +1157,13 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) File_Read(&edit_type, sizeof(int32_t), 1, fp); switch (edit_type) { case FET_TRIGGER_PARAM: - Inject_TriggerParameterChange(injection, floor); + Inject_TriggerParameterChange(injection, sector); break; case FET_MUSIC_ONESHOT: - Inject_SetMusicOneShot(floor); + Inject_SetMusicOneShot(sector); break; case FET_FD_INSERT: - Inject_InsertFloorData(injection, floor, level_info); + Inject_InsertFloorData(injection, sector, level_info); break; case FET_ROOM_SHIFT: Inject_RoomShift(injection, room); @@ -1180,7 +1180,7 @@ static void Inject_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) } static void Inject_TriggerParameterChange( - INJECTION *injection, FLOOR_INFO *floor) + INJECTION *injection, SECTOR_INFO *sector) { MYFILE *fp = injection->fp; @@ -1190,15 +1190,15 @@ static void Inject_TriggerParameterChange( File_Read(&old_param, sizeof(int16_t), 1, fp); File_Read(&new_param, sizeof(int16_t), 1, fp); - if (!floor) { + if (!sector) { return; } - // If we can find an action item for the given floor that matches + // If we can find an action item for the given sector that matches // the command type and old (current) parameter, change it to the // new parameter. - uint16_t fd_index = floor->index; + uint16_t fd_index = sector->index; if (!fd_index) { return; } @@ -1254,13 +1254,13 @@ static void Inject_TriggerParameterChange( } } -static void Inject_SetMusicOneShot(FLOOR_INFO *floor) +static void Inject_SetMusicOneShot(SECTOR_INFO *sector) { - if (!floor) { + if (!sector) { return; } - uint16_t fd_index = floor->index; + uint16_t fd_index = sector->index; if (!fd_index) { return; } @@ -1312,7 +1312,7 @@ static void Inject_SetMusicOneShot(FLOOR_INFO *floor) } static void Inject_InsertFloorData( - INJECTION *injection, FLOOR_INFO *floor, LEVEL_INFO *level_info) + INJECTION *injection, SECTOR_INFO *sector, LEVEL_INFO *level_info) { MYFILE *fp = injection->fp; @@ -1322,11 +1322,11 @@ static void Inject_InsertFloorData( int16_t data[data_length]; File_Read(&data, sizeof(int16_t), data_length, fp); - if (!floor) { + if (!sector) { return; } - floor->index = level_info->floor_data_size; + sector->index = level_info->floor_data_size; for (int i = 0; i < data_length; i++) { g_FloorData[level_info->floor_data_size + i] = data[i]; } @@ -1371,14 +1371,14 @@ 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->x_size * room->y_size; i++) { - FLOOR_INFO *floor = &room->floor[i]; - if (floor->floor == wall_height || floor->ceiling == wall_height) { + 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) { continue; } - floor->floor += click_shift; - floor->ceiling += click_shift; + sector->floor += click_shift; + sector->ceiling += click_shift; } // Update vertex Y values to match; x and z are room-relative. diff --git a/src/game/interpolation.c b/src/game/interpolation.c index 3d877b1a5..83fbf2fad 100644 --- a/src/game/interpolation.c +++ b/src/game/interpolation.c @@ -86,7 +86,7 @@ void Interpolation_Commit(void) INTERPOLATE(&g_Camera, target.z, ratio, 512); g_Camera.interp.room_num = g_Camera.pos.room_number; - Room_GetFloor( + Room_GetSector( g_Camera.interp.result.pos.x, g_Camera.interp.result.pos.y + g_Camera.interp.result.shift, g_Camera.interp.result.pos.z, &g_Camera.interp.room_num); diff --git a/src/game/items.c b/src/game/items.c index 32870d90f..135c83b4d 100644 --- a/src/game/items.c +++ b/src/game/items.c @@ -166,13 +166,14 @@ void Item_Initialise(int16_t item_num) item->status = IS_ACTIVE; } - ROOM_INFO *r = &g_RoomInfo[item->room_number]; + ROOM_INFO *const r = &g_RoomInfo[item->room_number]; item->next_item = r->item_number; r->item_number = item_num; - int32_t x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - FLOOR_INFO *floor = &r->floor[x_floor + y_floor * r->x_size]; - item->floor = floor->floor << 8; + const int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; + 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; if (g_GameInfo.bonus_flag & GBF_NGPLUS) { item->hit_points *= 2; @@ -271,8 +272,8 @@ bool Item_Teleport(ITEM_INFO *item, int32_t x, int32_t y, int32_t z) if (room_num == NO_ROOM) { return false; } - FLOOR_INFO *const floor = Room_GetFloor(x, y, z, &room_num); - const int16_t height = Room_GetHeight(floor, x, y, z); + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); + const int16_t height = Room_GetHeight(sector, x, y, z); if (height != NO_HEIGHT) { item->pos.x = x; item->pos.y = y; @@ -297,8 +298,8 @@ void Item_UpdateRoom(ITEM_INFO *item, int32_t height) int32_t y = item->pos.y + height; int32_t z = item->pos.z; int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); - item->floor = Room_GetHeight(floor, x, y, z); + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); + item->floor = Room_GetHeight(sector, x, y, z); if (item->room_number != room_num) { Item_NewRoom(g_Lara.item_number, room_num); } @@ -307,10 +308,10 @@ void Item_UpdateRoom(ITEM_INFO *item, int32_t height) int16_t Item_GetHeight(ITEM_INFO *item) { int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); - int32_t height = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); + const int32_t height = + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); return height; } diff --git a/src/game/lara/lara_control.c b/src/game/lara/lara_control.c index 301093fe3..30a2678db 100644 --- a/src/game/lara/lara_control.c +++ b/src/game/lara/lara_control.c @@ -33,13 +33,13 @@ static void Lara_WaterCurrent(COLL_INFO *coll) { XYZ_32 target; - ITEM_INFO *item = g_LaraItem; - ROOM_INFO *r = &g_RoomInfo[item->room_number]; - FLOOR_INFO *floor = - &r->floor + ITEM_INFO *const item = g_LaraItem; + const ROOM_INFO *const r = &g_RoomInfo[item->room_number]; + const SECTOR_INFO *const sector = + &r->sectors [((item->pos.z - r->z) >> WALL_SHIFT) - + ((item->pos.x - r->x) >> WALL_SHIFT) * r->x_size]; - item->box_number = floor->box; + + ((item->pos.x - r->x) >> WALL_SHIFT) * r->z_size]; + item->box_number = sector->box; if (Box_CalculateTarget(&target, item, &g_Lara.LOT) == TARGET_NONE) { return; diff --git a/src/game/lara/lara_hair.c b/src/game/lara/lara_hair.c index 599c2d468..e8c7e0994 100644 --- a/src/game/lara/lara_hair.c +++ b/src/game/lara/lara_hair.c @@ -77,7 +77,7 @@ void Lara_Hair_Control(void) FRAME_INFO *frmptr[2]; int16_t **mesh_base; XYZ_32 pos; - FLOOR_INFO *floor; + const SECTOR_INFO *sector; int32_t i; int32_t water_level; int32_t height; @@ -338,11 +338,11 @@ void Lara_Hair_Control(void) for (i = 1; i < HAIR_SEGMENTS + 1; i++, bone += 4) { m_HVel[0] = m_Hair[i].pos; - floor = Room_GetFloor( + sector = Room_GetSector( m_Hair[i].pos.x, m_Hair[i].pos.y, m_Hair[i].pos.z, &room_number); height = Room_GetHeight( - floor, m_Hair[i].pos.x, m_Hair[i].pos.y, m_Hair[i].pos.z); + sector, m_Hair[i].pos.x, m_Hair[i].pos.y, m_Hair[i].pos.z); m_Hair[i].pos.x += m_HVel[i].x * 3 / 4; m_Hair[i].pos.y += m_HVel[i].y * 3 / 4; diff --git a/src/game/lara/lara_misc.c b/src/game/lara/lara_misc.c index 6bc151a13..dc8f3c5f9 100644 --- a/src/game/lara/lara_misc.c +++ b/src/game/lara/lara_misc.c @@ -434,9 +434,9 @@ bool Lara_TestHangSwingIn(ITEM_INFO *item, PHD_ANGLE angle) break; } - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); - int h = Room_GetHeight(floor, x, y, z); - int c = Room_GetCeiling(floor, x, y, z); + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); + const int32_t h = Room_GetHeight(sector, x, y, z); + const int32_t c = Room_GetCeiling(sector, x, y, z); if (h != NO_HEIGHT) { if ((h - y) > 0 && (c - y) < -400) { @@ -547,17 +547,17 @@ bool Lara_LandedBad(ITEM_INFO *item, COLL_INFO *coll) { int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); - int oy = item->pos.y; - int height = Room_GetHeight( - floor, item->pos.x, item->pos.y - LARA_HEIGHT, item->pos.z); + const int32_t old_y = item->pos.y; + const int32_t height = Room_GetHeight( + sector, item->pos.x, item->pos.y - LARA_HEIGHT, item->pos.z); item->floor = height; item->pos.y = height; Room_TestTriggers(g_TriggerIndex, false); - item->pos.y = oy; + item->pos.y = old_y; int landspeed = item->fall_speed - DAMAGE_START; if (landspeed <= 0) { diff --git a/src/game/lara/lara_state.c b/src/game/lara/lara_state.c index da1c47d8d..ff7af4126 100644 --- a/src/game/lara/lara_state.c +++ b/src/game/lara/lara_state.c @@ -50,8 +50,8 @@ static int16_t Lara_FloorFront(ITEM_INFO *item, PHD_ANGLE ang, int32_t dist) int32_t y = item->pos.y - LARA_HEIGHT; int32_t z = item->pos.z + ((Math_Cos(ang) * dist) >> W2V_SHIFT); int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); - int32_t height = Room_GetHeight(floor, x, y, z); + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); + int32_t height = Room_GetHeight(sector, x, y, z); if (height != NO_HEIGHT) { height -= item->pos.y; } diff --git a/src/game/level.c b/src/game/level.c index 7756217b0..9936f4bfa 100644 --- a/src/game/level.c +++ b/src/game/level.c @@ -207,19 +207,19 @@ static bool Level_LoadRooms(MYFILE *fp) } // Room floor + File_Read(¤t_room_info->z_size, sizeof(uint16_t), 1, fp); File_Read(¤t_room_info->x_size, sizeof(uint16_t), 1, fp); - File_Read(¤t_room_info->y_size, sizeof(uint16_t), 1, fp); - count4 = current_room_info->y_size * current_room_info->x_size; - current_room_info->floor = - GameBuf_Alloc(sizeof(FLOOR_INFO) * count4, GBUF_ROOM_FLOOR); + count4 = current_room_info->x_size * current_room_info->z_size; + current_room_info->sectors = + GameBuf_Alloc(sizeof(SECTOR_INFO) * count4, GBUF_ROOM_SECTOR); for (int32_t j = 0; j < (signed)count4; j++) { - FLOOR_INFO *floor = ¤t_room_info->floor[j]; - File_Read(&floor->index, sizeof(uint16_t), 1, fp); - File_Read(&floor->box, sizeof(int16_t), 1, fp); - File_Read(&floor->pit_room, sizeof(uint8_t), 1, fp); - File_Read(&floor->floor, sizeof(int8_t), 1, fp); - File_Read(&floor->sky_room, sizeof(uint8_t), 1, fp); - File_Read(&floor->ceiling, sizeof(int8_t), 1, fp); + SECTOR_INFO *const sector = ¤t_room_info->sectors[j]; + File_Read(§or->index, sizeof(uint16_t), 1, fp); + File_Read(§or->box, sizeof(int16_t), 1, fp); + File_Read(§or->pit_room, sizeof(uint8_t), 1, fp); + File_Read(§or->floor, sizeof(int8_t), 1, fp); + File_Read(§or->sky_room, sizeof(uint8_t), 1, fp); + File_Read(§or->ceiling, sizeof(int8_t), 1, fp); } // Room lights diff --git a/src/game/los.c b/src/game/los.c index fbe5f10f0..7cadc9803 100644 --- a/src/game/los.c +++ b/src/game/los.c @@ -10,12 +10,12 @@ static int32_t LOS_CheckX(const GAME_VECTOR *start, GAME_VECTOR *target); static int32_t LOS_CheckZ(const GAME_VECTOR *start, GAME_VECTOR *target); static bool LOS_ClipTarget( - const GAME_VECTOR *start, GAME_VECTOR *target, const FLOOR_INFO *floor); + const GAME_VECTOR *start, GAME_VECTOR *target, const SECTOR_INFO *sector); static int32_t LOS_CheckX( const GAME_VECTOR *const start, GAME_VECTOR *const target) { - FLOOR_INFO *floor; + const SECTOR_INFO *sector; int32_t dx = target->x - start->x; if (dx == 0) { @@ -34,9 +34,9 @@ static int32_t LOS_CheckX( int32_t z = start->z + ((dz * (x - start->x)) >> WALL_SHIFT); while (x > target->x) { - floor = Room_GetFloor(x, y, z, &room_num); - if (y > Room_GetHeight(floor, x, y, z) - || y < Room_GetCeiling(floor, x, y, z)) { + sector = Room_GetSector(x, y, z, &room_num); + if (y > Room_GetHeight(sector, x, y, z) + || y < Room_GetCeiling(sector, x, y, z)) { target->x = x; target->y = y; target->z = z; @@ -46,9 +46,9 @@ static int32_t LOS_CheckX( last_room = room_num; - floor = Room_GetFloor(x - 1, y, z, &room_num); - if (y > Room_GetHeight(floor, x - 1, y, z) - || y < Room_GetCeiling(floor, x - 1, y, z)) { + sector = Room_GetSector(x - 1, y, z, &room_num); + if (y > Room_GetHeight(sector, x - 1, y, z) + || y < Room_GetCeiling(sector, x - 1, y, z)) { target->x = x; target->y = y; target->z = z; @@ -66,9 +66,9 @@ static int32_t LOS_CheckX( int32_t z = start->z + ((dz * (x - start->x)) >> WALL_SHIFT); while (x < target->x) { - floor = Room_GetFloor(x, y, z, &room_num); - if (y > Room_GetHeight(floor, x, y, z) - || y < Room_GetCeiling(floor, x, y, z)) { + sector = Room_GetSector(x, y, z, &room_num); + if (y > Room_GetHeight(sector, x, y, z) + || y < Room_GetCeiling(sector, x, y, z)) { target->x = x; target->y = y; target->z = z; @@ -78,9 +78,9 @@ static int32_t LOS_CheckX( last_room = room_num; - floor = Room_GetFloor(x + 1, y, z, &room_num); - if (y > Room_GetHeight(floor, x + 1, y, z) - || y < Room_GetCeiling(floor, x + 1, y, z)) { + sector = Room_GetSector(x + 1, y, z, &room_num); + if (y > Room_GetHeight(sector, x + 1, y, z) + || y < Room_GetCeiling(sector, x + 1, y, z)) { target->x = x; target->y = y; target->z = z; @@ -101,7 +101,7 @@ static int32_t LOS_CheckX( static int32_t LOS_CheckZ( const GAME_VECTOR *const start, GAME_VECTOR *const target) { - FLOOR_INFO *floor; + const SECTOR_INFO *sector; int32_t dz = target->z - start->z; if (dz == 0) { @@ -120,9 +120,9 @@ static int32_t LOS_CheckZ( int32_t y = start->y + ((dy * (z - start->z)) >> WALL_SHIFT); while (z > target->z) { - floor = Room_GetFloor(x, y, z, &room_num); - if (y > Room_GetHeight(floor, x, y, z) - || y < Room_GetCeiling(floor, x, y, z)) { + sector = Room_GetSector(x, y, z, &room_num); + if (y > Room_GetHeight(sector, x, y, z) + || y < Room_GetCeiling(sector, x, y, z)) { target->x = x; target->y = y; target->z = z; @@ -132,9 +132,9 @@ static int32_t LOS_CheckZ( last_room = room_num; - floor = Room_GetFloor(x, y, z - 1, &room_num); - if (y > Room_GetHeight(floor, x, y, z - 1) - || y < Room_GetCeiling(floor, x, y, z - 1)) { + sector = Room_GetSector(x, y, z - 1, &room_num); + if (y > Room_GetHeight(sector, x, y, z - 1) + || y < Room_GetCeiling(sector, x, y, z - 1)) { target->x = x; target->y = y; target->z = z; @@ -152,9 +152,9 @@ static int32_t LOS_CheckZ( int32_t y = start->y + ((dy * (z - start->z)) >> WALL_SHIFT); while (z < target->z) { - floor = Room_GetFloor(x, y, z, &room_num); - if (y > Room_GetHeight(floor, x, y, z) - || y < Room_GetCeiling(floor, x, y, z)) { + sector = Room_GetSector(x, y, z, &room_num); + if (y > Room_GetHeight(sector, x, y, z) + || y < Room_GetCeiling(sector, x, y, z)) { target->x = x; target->y = y; target->z = z; @@ -164,9 +164,9 @@ static int32_t LOS_CheckZ( last_room = room_num; - floor = Room_GetFloor(x, y, z + 1, &room_num); - if (y > Room_GetHeight(floor, x, y, z + 1) - || y < Room_GetCeiling(floor, x, y, z + 1)) { + sector = Room_GetSector(x, y, z + 1, &room_num); + if (y > Room_GetHeight(sector, x, y, z + 1) + || y < Room_GetCeiling(sector, x, y, z + 1)) { target->x = x; target->y = y; target->z = z; @@ -186,13 +186,14 @@ static int32_t LOS_CheckZ( static bool LOS_ClipTarget( const GAME_VECTOR *const start, GAME_VECTOR *const target, - const FLOOR_INFO *const floor) + const SECTOR_INFO *const sector) { int32_t dx = target->x - start->x; int32_t dy = target->y - start->y; int32_t dz = target->z - start->z; - int32_t height = Room_GetHeight(floor, target->x, target->y, target->z); + const int32_t height = + Room_GetHeight(sector, target->x, target->y, target->z); if (target->y > height && start->y < height) { target->y = height; target->x = start->x + dx * (height - start->y) / dy; @@ -200,7 +201,8 @@ static bool LOS_ClipTarget( return false; } - int32_t ceiling = Room_GetCeiling(floor, target->x, target->y, target->z); + const int32_t ceiling = + Room_GetCeiling(sector, target->x, target->y, target->z); if (target->y < ceiling && start->y > ceiling) { target->y = ceiling; target->x = start->x + dx * (ceiling - start->y) / dy; @@ -228,8 +230,8 @@ bool LOS_Check(const GAME_VECTOR *const start, GAME_VECTOR *const target) return false; } - FLOOR_INFO *floor = - Room_GetFloor(target->x, target->y, target->z, &target->room_number); + const SECTOR_INFO *const sector = + Room_GetSector(target->x, target->y, target->z, &target->room_number); - return LOS_ClipTarget(start, target, floor) && los1 == 1 && los2 == 1; + return LOS_ClipTarget(start, target, sector) && los1 == 1 && los2 == 1; } diff --git a/src/game/lot.c b/src/game/lot.c index 4191cf7b9..a51126898 100644 --- a/src/game/lot.c +++ b/src/game/lot.c @@ -158,10 +158,10 @@ void LOT_CreateZone(ITEM_INFO *item) flip = g_GroundZone2[1]; } - ROOM_INFO *r = &g_RoomInfo[item->room_number]; - int32_t x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - item->box_number = r->floor[x_floor + y_floor * r->x_size].box; + const ROOM_INFO *const r = &g_RoomInfo[item->room_number]; + const int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; + const int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; + item->box_number = r->sectors[z_sector + x_sector * r->z_size].box; int16_t zone_number = zone[item->box_number]; int16_t flip_number = flip[item->box_number]; diff --git a/src/game/objects/common.c b/src/game/objects/common.c index cd84d4f8d..984c15181 100644 --- a/src/game/objects/common.c +++ b/src/game/objects/common.c @@ -351,10 +351,10 @@ void Object_DrawPickupItem(ITEM_INFO *item) // This is mostly true, but for example the 4 items in the Obelisk of // Khamoon the 4 items are sitting on top of a static mesh which is not // floor. - FLOOR_INFO *floor = Room_GetFloor( + const SECTOR_INFO *const sector = Room_GetSector( item->pos.x, item->pos.y, item->pos.z, &item->room_number); - int16_t floor_height = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + const int16_t floor_height = + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); // Assume this is our offset. int16_t offset = floor_height; diff --git a/src/game/objects/creatures/bacon_lara.c b/src/game/objects/creatures/bacon_lara.c index 3be6f39e9..3fe35804c 100644 --- a/src/game/objects/creatures/bacon_lara.c +++ b/src/game/objects/creatures/bacon_lara.c @@ -44,8 +44,8 @@ bool BaconLara_InitialiseAnchor(int32_t room_index) } ROOM_INFO *r = &g_RoomInfo[room_index]; - m_AnchorX = r->x + r->y_size * (WALL_L >> 1); - m_AnchorZ = r->z + r->x_size * (WALL_L >> 1); + m_AnchorX = r->x + r->x_size * (WALL_L >> 1); + m_AnchorZ = r->z + r->z_size * (WALL_L >> 1); return true; } @@ -69,15 +69,15 @@ void BaconLara_Control(int16_t item_num) int32_t z = 2 * m_AnchorZ - g_LaraItem->pos.z; int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); - int32_t h = Room_GetHeight(floor, x, y, z); + const SECTOR_INFO *sector = Room_GetSector(x, y, z, &room_num); + const int32_t h = Room_GetHeight(sector, x, y, z); item->floor = h; room_num = g_LaraItem->room_number; - floor = Room_GetFloor( + sector = Room_GetSector( g_LaraItem->pos.x, g_LaraItem->pos.y, g_LaraItem->pos.z, &room_num); int32_t lh = Room_GetHeight( - floor, g_LaraItem->pos.x, g_LaraItem->pos.y, g_LaraItem->pos.z); + sector, g_LaraItem->pos.x, g_LaraItem->pos.y, g_LaraItem->pos.z); int16_t relative_anim = g_LaraItem->anim_number - g_Objects[g_LaraItem->object_number].anim_index; @@ -112,16 +112,16 @@ void BaconLara_Control(int16_t item_num) int32_t z = item->pos.z; int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); - int32_t h = Room_GetHeight(floor, x, y, z); + const SECTOR_INFO *sector = Room_GetSector(x, y, z, &room_num); + const int32_t h = Room_GetHeight(sector, x, y, z); item->floor = h; Room_TestTriggers(g_TriggerIndex, true); if (item->pos.y >= h) { item->floor = h; item->pos.y = h; - floor = Room_GetFloor(x, h, z, &room_num); - Room_GetHeight(floor, x, h, z); + sector = Room_GetSector(x, h, z, &room_num); + Room_GetHeight(sector, x, h, z); Room_TestTriggers(g_TriggerIndex, true); item->gravity_status = 0; item->fall_speed = 0; diff --git a/src/game/objects/creatures/bat.c b/src/game/objects/creatures/bat.c index dc9ba3f05..ada972152 100644 --- a/src/game/objects/creatures/bat.c +++ b/src/game/objects/creatures/bat.c @@ -44,9 +44,8 @@ static void Bat_FixEmbeddedPosition(int16_t item_num) const int32_t y = item->pos.y; const int32_t z = item->pos.z; int16_t room_number = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_number); - Room_GetHeight(floor, x, y, z); - const int16_t ceiling = Room_GetCeiling(floor, x, y, z); + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_number); + const int16_t ceiling = Room_GetCeiling(sector, x, y, z); // The bats animation and frame have to be changed to the hanging // one to properly measure them. Save it so it can be restored diff --git a/src/game/objects/creatures/crocodile.c b/src/game/objects/creatures/crocodile.c index 30145169f..acd033962 100644 --- a/src/game/objects/creatures/crocodile.c +++ b/src/game/objects/creatures/crocodile.c @@ -236,7 +236,7 @@ void Alligator_Control(int16_t item_num) } CREATURE_INFO *gator = item->data; - FLOOR_INFO *floor; + const SECTOR_INFO *sector; int16_t head = 0; int16_t angle = 0; int16_t room_num; @@ -266,9 +266,10 @@ void Alligator_Control(int16_t item_num) Item_Animate(item); room_num = item->room_number; - floor = Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); item->floor = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); if (room_num != item->room_number) { Item_NewRoom(item_num, room_num); } diff --git a/src/game/objects/creatures/natla.c b/src/game/objects/creatures/natla.c index e4d6b2464..c35e32c9a 100644 --- a/src/game/objects/creatures/natla.c +++ b/src/game/objects/creatures/natla.c @@ -342,10 +342,10 @@ void NatlaGun_Control(int16_t fx_num) int32_t x = fx->pos.x + ((fx->speed * Math_Sin(fx->rot.y)) >> W2V_SHIFT); int32_t y = fx->pos.y; int16_t room_num = fx->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); - if (y >= Room_GetHeight(floor, x, y, z) - || y <= Room_GetCeiling(floor, x, y, z)) { + if (y >= Room_GetHeight(sector, x, y, z) + || y <= Room_GetCeiling(sector, x, y, z)) { return; } diff --git a/src/game/objects/creatures/torso.c b/src/game/objects/creatures/torso.c index e169121bf..733913a5d 100644 --- a/src/game/objects/creatures/torso.c +++ b/src/game/objects/creatures/torso.c @@ -255,9 +255,9 @@ void Torso_Control(int16_t item_num) if (item->status == IS_DEACTIVATED) { Sound_Effect(SFX_ATLANTEAN_DEATH, &item->pos, SPM_NORMAL); Effect_ExplodingDeath(item_num, -1, TORSO_PART_DAMAGE); - FLOOR_INFO *floor = Room_GetFloor( + const SECTOR_INFO *const sector = Room_GetSector( item->pos.x, item->pos.y, item->pos.z, &item->room_number); - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); Room_TestTriggers(g_TriggerIndex, true); Item_Kill(item_num); diff --git a/src/game/objects/effects/body_part.c b/src/game/objects/effects/body_part.c index 2534ad2b3..a852c16fe 100644 --- a/src/game/objects/effects/body_part.c +++ b/src/game/objects/effects/body_part.c @@ -28,16 +28,18 @@ void BodyPart_Control(int16_t fx_num) fx->pos.y += fx->fall_speed; int16_t room_num = fx->room_number; - FLOOR_INFO *floor = - Room_GetFloor(fx->pos.x, fx->pos.y, fx->pos.z, &room_num); + const SECTOR_INFO *const sector = + Room_GetSector(fx->pos.x, fx->pos.y, fx->pos.z, &room_num); - int32_t ceiling = Room_GetCeiling(floor, fx->pos.x, fx->pos.y, fx->pos.z); + const int32_t ceiling = + Room_GetCeiling(sector, fx->pos.x, fx->pos.y, fx->pos.z); if (fx->pos.y < ceiling) { fx->fall_speed = -fx->fall_speed; fx->pos.y = ceiling; } - int32_t height = Room_GetHeight(floor, fx->pos.x, fx->pos.y, fx->pos.z); + const int32_t height = + Room_GetHeight(sector, fx->pos.x, fx->pos.y, fx->pos.z); if (fx->pos.y >= height) { if (fx->counter) { fx->speed = 0; diff --git a/src/game/objects/effects/bubble.c b/src/game/objects/effects/bubble.c index 273b4293a..37e98de06 100644 --- a/src/game/objects/effects/bubble.c +++ b/src/game/objects/effects/bubble.c @@ -22,13 +22,13 @@ void Bubble_Control(int16_t fx_num) int32_t z = fx->pos.z + ((Math_Cos(fx->rot.x) * 8) >> W2V_SHIFT); int16_t room_num = fx->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); - if (!floor || !(g_RoomInfo[room_num].flags & RF_UNDERWATER)) { + const SECTOR_INFO *const sector = Room_GetSector(x, y, z, &room_num); + if (!sector || !(g_RoomInfo[room_num].flags & RF_UNDERWATER)) { Effect_Kill(fx_num); return; } - int32_t height = Room_GetCeiling(floor, x, y, z); + const int32_t height = Room_GetCeiling(sector, x, y, z); if (height == NO_HEIGHT || y <= height) { Effect_Kill(fx_num); return; diff --git a/src/game/objects/effects/missile.c b/src/game/objects/effects/missile.c index f8a8f0109..d3972d726 100644 --- a/src/game/objects/effects/missile.c +++ b/src/game/objects/effects/missile.c @@ -34,10 +34,12 @@ void Missile_Control(int16_t fx_num) fx->pos.x += (speed * Math_Sin(fx->rot.y)) >> W2V_SHIFT; int16_t room_num = fx->room_number; - FLOOR_INFO *floor = - Room_GetFloor(fx->pos.x, fx->pos.y, fx->pos.z, &room_num); - int32_t height = Room_GetHeight(floor, fx->pos.x, fx->pos.y, fx->pos.z); - int32_t ceiling = Room_GetCeiling(floor, fx->pos.x, fx->pos.y, fx->pos.z); + const SECTOR_INFO *const sector = + Room_GetSector(fx->pos.x, fx->pos.y, fx->pos.z, &room_num); + const int32_t height = + Room_GetHeight(sector, fx->pos.x, fx->pos.y, fx->pos.z); + const int32_t ceiling = + Room_GetCeiling(sector, fx->pos.x, fx->pos.y, fx->pos.z); if (fx->pos.y >= height || fx->pos.y <= ceiling) { if (fx->object_number == O_MISSILE2) { diff --git a/src/game/objects/effects/splash.c b/src/game/objects/effects/splash.c index 5b90c15d9..ea215e2dc 100644 --- a/src/game/objects/effects/splash.c +++ b/src/game/objects/effects/splash.c @@ -31,7 +31,7 @@ void Splash_Spawn(ITEM_INFO *item) int16_t wh = Room_GetWaterHeight( item->pos.x, item->pos.y, item->pos.z, item->room_number); int16_t room_num = item->room_number; - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); Sound_Effect(SFX_LARA_SPLASH, &item->pos, SPM_NORMAL); diff --git a/src/game/objects/general/bridge.c b/src/game/objects/general/bridge.c index b84ed2bc0..1cdf050a3 100644 --- a/src/game/objects/general/bridge.c +++ b/src/game/objects/general/bridge.c @@ -105,14 +105,15 @@ static void Bridge_FixEmbeddedPosition(int16_t item_num) int16_t room_num = item->room_number; const BOUNDS_16 *const bounds = Item_GetBoundsAccurate(item); - int16_t bridge_height = ABS(bounds->max.y) - ABS(bounds->min.y); + const int16_t bridge_height = ABS(bounds->max.y) - ABS(bounds->min.y); - FLOOR_INFO *floor = Room_GetFloor(x, y - bridge_height, z, &room_num); - int16_t floor_height = Room_GetHeight(floor, x, y, z); + const SECTOR_INFO *const sector = + Room_GetSector(x, y - bridge_height, z, &room_num); + const int16_t floor_height = Room_GetHeight(sector, x, y, z); // Only move the bridge up if it's at floor level and there // isn't a room portal below. - if (item->floor != floor_height || floor->pit_room != NO_ROOM) { + if (item->floor != floor_height || sector->pit_room != NO_ROOM) { return; } diff --git a/src/game/objects/general/cog.c b/src/game/objects/general/cog.c index 9b35ac9e8..55afdef64 100644 --- a/src/game/objects/general/cog.c +++ b/src/game/objects/general/cog.c @@ -21,7 +21,7 @@ void Cog_Control(int16_t item_num) Item_Animate(item); int16_t room_num = item->room_number; - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); if (room_num != item->room_number) { Item_NewRoom(item_num, room_num); } diff --git a/src/game/objects/general/door.c b/src/game/objects/general/door.c index 23071461f..4ce3938cd 100644 --- a/src/game/objects/general/door.c +++ b/src/game/objects/general/door.c @@ -14,12 +14,12 @@ #include #include -static bool Door_LaraDoorCollision(const FLOOR_INFO *floor); +static bool Door_LaraDoorCollision(const SECTOR_INFO *sector); static void Door_Check(DOORPOS_DATA *d); static void Door_Open(DOORPOS_DATA *d); static void Door_Shut(DOORPOS_DATA *d); -static bool Door_LaraDoorCollision(const FLOOR_INFO *const floor) +static bool Door_LaraDoorCollision(const SECTOR_INFO *const sector) { // Check if Lara is on the same tile as the invisible block. if (g_LaraItem == NULL) { @@ -27,9 +27,9 @@ static bool Door_LaraDoorCollision(const FLOOR_INFO *const floor) } int16_t room_num = g_LaraItem->room_number; - const FLOOR_INFO *const lara_floor = Room_GetFloor( + const SECTOR_INFO *const lara_sector = Room_GetSector( g_LaraItem->pos.x, g_LaraItem->pos.y, g_LaraItem->pos.z, &room_num); - return lara_floor == floor; + return lara_sector == sector; } static void Door_Check(DOORPOS_DATA *const d) @@ -38,7 +38,7 @@ static void Door_Check(DOORPOS_DATA *const d) // tile. This ensures that Lara doesn't void if a timed door happens to // close right on her, or the player loads the game while standing on a // closed door's block tile. - if (Door_LaraDoorCollision(d->floor)) { + if (Door_LaraDoorCollision(d->sector)) { Door_Open(d); } } @@ -46,17 +46,17 @@ static void Door_Check(DOORPOS_DATA *const d) static void Door_Shut(DOORPOS_DATA *const d) { // Change the level geometry so that the door tile is impassable. - FLOOR_INFO *const floor = d->floor; - if (floor == NULL) { + SECTOR_INFO *const sector = d->sector; + if (sector == NULL) { return; } - floor->index = 0; - floor->box = NO_BOX; - floor->floor = NO_HEIGHT / STEP_L; - floor->ceiling = NO_HEIGHT / STEP_L; - floor->sky_room = NO_ROOM; - floor->pit_room = NO_ROOM; + sector->index = 0; + sector->box = NO_BOX; + sector->floor = NO_HEIGHT / STEP_L; + sector->ceiling = NO_HEIGHT / STEP_L; + sector->sky_room = NO_ROOM; + sector->pit_room = NO_ROOM; const int16_t box_num = d->block; if (box_num != NO_BOX) { @@ -67,12 +67,12 @@ static void Door_Shut(DOORPOS_DATA *const d) static void Door_Open(DOORPOS_DATA *const d) { // Restore the level geometry so that the door tile is passable. - FLOOR_INFO *const floor = d->floor; - if (!floor) { + SECTOR_INFO *const sector = d->sector; + if (!sector) { return; } - *floor = d->old_floor; + *sector = d->old_sector; const int16_t box_num = d->block; if (box_num != NO_BOX) { @@ -108,105 +108,105 @@ void Door_Initialise(int16_t item_num) dy++; } - ROOM_INFO *r; - ROOM_INFO *b; - int32_t x_floor; - int32_t y_floor; + const ROOM_INFO *r; + const ROOM_INFO *b; + int32_t z_sector; + int32_t x_sector; int16_t room_num; int16_t box_num; r = &g_RoomInfo[item->room_number]; - x_floor = ((item->pos.z - r->z) >> WALL_SHIFT) + dx; - y_floor = ((item->pos.x - r->x) >> WALL_SHIFT) + dy; - door->d1.floor = &r->floor[x_floor + y_floor * r->x_size]; - room_num = Room_GetDoor(door->d1.floor); + 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); if (room_num == NO_ROOM) { - box_num = door->d1.floor->box; + box_num = door->d1.sector->box; } else { b = &g_RoomInfo[room_num]; - x_floor = ((item->pos.z - b->z) >> WALL_SHIFT) + dx; - y_floor = ((item->pos.x - b->x) >> WALL_SHIFT) + dy; - box_num = b->floor[x_floor + y_floor * b->x_size].box; + z_sector = ((item->pos.z - b->z) >> WALL_SHIFT) + dx; + x_sector = ((item->pos.x - b->x) >> WALL_SHIFT) + dy; + box_num = b->sectors[z_sector + x_sector * b->z_size].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; } door->d1.block = box_num; - door->d1.old_floor = *door->d1.floor; + door->d1.old_sector = *door->d1.sector; if (r->flipped_room != -1) { r = &g_RoomInfo[r->flipped_room]; - x_floor = ((item->pos.z - r->z) >> WALL_SHIFT) + dx; - y_floor = ((item->pos.x - r->x) >> WALL_SHIFT) + dy; - door->d1flip.floor = &r->floor[x_floor + y_floor * r->x_size]; - room_num = Room_GetDoor(door->d1flip.floor); + 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); if (room_num == NO_ROOM) { - box_num = door->d1flip.floor->box; + box_num = door->d1flip.sector->box; } else { b = &g_RoomInfo[room_num]; - x_floor = ((item->pos.z - b->z) >> WALL_SHIFT) + dx; - y_floor = ((item->pos.x - b->x) >> WALL_SHIFT) + dy; - box_num = b->floor[x_floor + y_floor * b->x_size].box; + z_sector = ((item->pos.z - b->z) >> WALL_SHIFT) + dx; + x_sector = ((item->pos.x - b->x) >> WALL_SHIFT) + dy; + box_num = b->sectors[z_sector + x_sector * b->z_size].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; } door->d1flip.block = box_num; - door->d1flip.old_floor = *door->d1flip.floor; + door->d1flip.old_sector = *door->d1flip.sector; } else { - door->d1flip.floor = NULL; + door->d1flip.sector = NULL; } - room_num = Room_GetDoor(door->d1.floor); + room_num = Room_GetDoor(door->d1.sector); Door_Shut(&door->d1); Door_Shut(&door->d1flip); if (room_num == NO_ROOM) { - door->d2.floor = NULL; - door->d2flip.floor = NULL; + door->d2.sector = NULL; + door->d2flip.sector = NULL; return; } r = &g_RoomInfo[room_num]; - x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - door->d2.floor = &r->floor[x_floor + y_floor * r->x_size]; - room_num = Room_GetDoor(door->d2.floor); + 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); if (room_num == NO_ROOM) { - box_num = door->d2.floor->box; + box_num = door->d2.sector->box; } else { b = &g_RoomInfo[room_num]; - x_floor = (item->pos.z - b->z) >> WALL_SHIFT; - y_floor = (item->pos.x - b->x) >> WALL_SHIFT; - box_num = b->floor[x_floor + y_floor * b->x_size].box; + z_sector = (item->pos.z - b->z) >> WALL_SHIFT; + x_sector = (item->pos.x - b->x) >> WALL_SHIFT; + box_num = b->sectors[z_sector + x_sector * b->z_size].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; } door->d2.block = box_num; - door->d2.old_floor = *door->d2.floor; + door->d2.old_sector = *door->d2.sector; if (r->flipped_room != -1) { r = &g_RoomInfo[r->flipped_room]; - x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - door->d2flip.floor = &r->floor[x_floor + y_floor * r->x_size]; - room_num = Room_GetDoor(door->d2flip.floor); + 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); if (room_num == NO_ROOM) { - box_num = door->d2flip.floor->box; + box_num = door->d2flip.sector->box; } else { b = &g_RoomInfo[room_num]; - x_floor = (item->pos.z - b->z) >> WALL_SHIFT; - y_floor = (item->pos.x - b->x) >> WALL_SHIFT; - box_num = b->floor[x_floor + y_floor * b->x_size].box; + z_sector = (item->pos.z - b->z) >> WALL_SHIFT; + x_sector = (item->pos.x - b->x) >> WALL_SHIFT; + box_num = b->sectors[z_sector + x_sector * b->z_size].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; } door->d2flip.block = box_num; - door->d2flip.old_floor = *door->d2flip.floor; + door->d2flip.old_sector = *door->d2flip.sector; } else { - door->d2flip.floor = NULL; + door->d2flip.sector = NULL; } Door_Shut(&door->d2); diff --git a/src/game/objects/general/scion.c b/src/game/objects/general/scion.c index 6f793d009..b1515c7cc 100644 --- a/src/game/objects/general/scion.c +++ b/src/game/objects/general/scion.c @@ -117,9 +117,9 @@ void Scion_Control3(int16_t item_num) item->status = IS_INVISIBLE; item->hit_points = DONT_TARGET; int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); Room_TestTriggers(g_TriggerIndex, true); Item_RemoveDrawn(item_num); } diff --git a/src/game/objects/traps/dart.c b/src/game/objects/traps/dart.c index 340b6e2a3..4ad75d31d 100644 --- a/src/game/objects/traps/dart.c +++ b/src/game/objects/traps/dart.c @@ -43,13 +43,13 @@ void Dart_Control(int16_t item_num) Item_Animate(item); int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); if (item->room_number != room_num) { Item_NewRoom(item_num, room_num); } - item->floor = Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + item->floor = Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); if (item->pos.y >= item->floor) { Item_Kill(item_num); int16_t fx_num = Effect_Create(item->room_number); diff --git a/src/game/objects/traps/falling_block.c b/src/game/objects/traps/falling_block.c index bb0c667f1..9a6597e99 100644 --- a/src/game/objects/traps/falling_block.c +++ b/src/game/objects/traps/falling_block.c @@ -48,13 +48,13 @@ void FallingBlock_Control(int16_t item_num) } int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); if (item->room_number != room_num) { Item_NewRoom(item_num, room_num); } - item->floor = Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + item->floor = Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); if (item->current_anim_state == TRAP_WORKING && item->pos.y >= item->floor) { diff --git a/src/game/objects/traps/lava.c b/src/game/objects/traps/lava.c index f4c1c1822..54743fc50 100644 --- a/src/game/objects/traps/lava.c +++ b/src/game/objects/traps/lava.c @@ -24,10 +24,10 @@ bool Lava_TestFloor(ITEM_INFO *item) // OG fix: check if floor index has lava int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, 32000, item->pos.z, &room_num); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, 32000, item->pos.z, &room_num); - int16_t *data = &g_FloorData[floor->index]; + int16_t *data = &g_FloorData[sector->index]; int16_t type; do { type = *data++; @@ -69,9 +69,9 @@ void Lava_Burn(ITEM_INFO *item) } int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, 32000, item->pos.z, &room_num); - int16_t height = Room_GetHeight(floor, item->pos.x, 32000, item->pos.z); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, 32000, item->pos.z, &room_num); + int16_t height = Room_GetHeight(sector, item->pos.x, 32000, item->pos.z); if (item->floor != height) { return; @@ -109,11 +109,11 @@ void Lava_Control(int16_t fx_num) fx->pos.y += fx->fall_speed; int16_t room_num = fx->room_number; - FLOOR_INFO *floor = - Room_GetFloor(fx->pos.x, fx->pos.y, fx->pos.z, &room_num); - if (fx->pos.y >= Room_GetHeight(floor, fx->pos.x, fx->pos.y, fx->pos.z) + const SECTOR_INFO *const sector = + Room_GetSector(fx->pos.x, fx->pos.y, fx->pos.z, &room_num); + if (fx->pos.y >= Room_GetHeight(sector, fx->pos.x, fx->pos.y, fx->pos.z) || fx->pos.y - < Room_GetCeiling(floor, fx->pos.x, fx->pos.y, fx->pos.z)) { + < Room_GetCeiling(sector, fx->pos.x, fx->pos.y, fx->pos.z)) { Effect_Kill(fx_num); } else if (Lara_IsNearItem(&fx->pos, 200)) { Lara_TakeDamage(LAVA_EMBER_DAMAGE, true); @@ -163,7 +163,7 @@ void LavaWedge_Control(int16_t item_num) ITEM_INFO *item = &g_Items[item_num]; int16_t room_num = item->room_number; - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); if (room_num != item->room_number) { Item_NewRoom(item_num, room_num); } @@ -191,8 +191,9 @@ void LavaWedge_Control(int16_t item_num) break; } - FLOOR_INFO *floor = Room_GetFloor(x, item->pos.y, z, &room_num); - if (Room_GetHeight(floor, x, item->pos.y, z) != item->pos.y) { + const SECTOR_INFO *const sector = + Room_GetSector(x, item->pos.y, z, &room_num); + if (Room_GetHeight(sector, x, item->pos.y, z) != item->pos.y) { item->status = IS_DEACTIVATED; } } diff --git a/src/game/objects/traps/lightning_emitter.c b/src/game/objects/traps/lightning_emitter.c index e13553e11..bc8f1c6a5 100644 --- a/src/game/objects/traps/lightning_emitter.c +++ b/src/game/objects/traps/lightning_emitter.c @@ -111,10 +111,10 @@ void LightningEmitter_Control(int16_t item_num) l->zapped = true; } else if (l->no_target) { - FLOOR_INFO *floor = Room_GetFloor( + const SECTOR_INFO *const sector = Room_GetSector( item->pos.x, item->pos.y, item->pos.z, &item->room_number); - int32_t h = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + const int32_t h = + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); l->target.x = item->pos.x; l->target.y = h; l->target.z = item->pos.z; diff --git a/src/game/objects/traps/movable_block.c b/src/game/objects/traps/movable_block.c index c79bdac7f..343d61bca 100644 --- a/src/game/objects/traps/movable_block.c +++ b/src/game/objects/traps/movable_block.c @@ -78,14 +78,14 @@ static bool MovableBlock_TestDoor(ITEM_INFO *lara_item, COLL_INFO *coll) static bool MovableBlock_TestDestination(ITEM_INFO *item, int32_t block_height) { int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); - if (Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z) + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); + if (Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z) == NO_HEIGHT) { return true; } - if (Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z) + if (Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z) != item->pos.y - block_height) { return false; } @@ -120,7 +120,7 @@ static bool MovableBlock_TestPush( break; } - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); + const SECTOR_INFO *sector = Room_GetSector(x, y, z, &room_num); COLL_INFO coll; coll.quadrant = quadrant; coll.radius = 500; @@ -128,12 +128,12 @@ static bool MovableBlock_TestPush( return false; } - if (Room_GetHeight(floor, x, y, z) != y) { + if (Room_GetHeight(sector, x, y, z) != y) { return false; } - floor = Room_GetFloor(x, y - block_height, z, &room_num); - if (Room_GetCeiling(floor, x, y - block_height, z) > y - block_height) { + sector = Room_GetSector(x, y - block_height, z, &room_num); + if (Room_GetCeiling(sector, x, y - block_height, z) > y - block_height) { return false; } @@ -169,7 +169,7 @@ static bool MovableBlock_TestPull( int32_t z = item->pos.z + z_add; int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, y, z, &room_num); + const SECTOR_INFO *sector = Room_GetSector(x, y, z, &room_num); COLL_INFO coll; coll.quadrant = quadrant; coll.radius = 500; @@ -177,26 +177,26 @@ static bool MovableBlock_TestPull( return false; } - if (Room_GetHeight(floor, x, y, z) != y) { + if (Room_GetHeight(sector, x, y, z) != y) { return false; } - floor = Room_GetFloor(x, y - block_height, z, &room_num); - if (Room_GetCeiling(floor, x, y - block_height, z) > y - block_height) { + sector = Room_GetSector(x, y - block_height, z, &room_num); + if (Room_GetCeiling(sector, x, y - block_height, z) > y - block_height) { return false; } x += x_add; z += z_add; room_num = item->room_number; - floor = Room_GetFloor(x, y, z, &room_num); + sector = Room_GetSector(x, y, z, &room_num); - if (Room_GetHeight(floor, x, y, z) != y) { + if (Room_GetHeight(sector, x, y, z) != y) { return false; } - floor = Room_GetFloor(x, y - LARA_HEIGHT, z, &room_num); - if (Room_GetCeiling(floor, x, y - LARA_HEIGHT, z) > y - LARA_HEIGHT) { + sector = Room_GetSector(x, y - LARA_HEIGHT, z, &room_num); + if (Room_GetCeiling(sector, x, y - LARA_HEIGHT, z) > y - LARA_HEIGHT) { return false; } @@ -204,7 +204,7 @@ static bool MovableBlock_TestPull( y = g_LaraItem->pos.y; z = g_LaraItem->pos.z + z_add; room_num = g_LaraItem->room_number; - floor = Room_GetFloor(x, y, z, &room_num); + sector = Room_GetSector(x, y, z, &room_num); coll.radius = LARA_RAD; coll.quadrant = (quadrant + 2) & 3; if (Collide_CollideStaticObjects(&coll, x, y, z, room_num, LARA_HEIGHT)) { @@ -248,10 +248,10 @@ void MovableBlock_Control(int16_t item_num) Item_Animate(item); int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor( + const SECTOR_INFO *sector = Room_GetSector( item->pos.x, item->pos.y - STEP_L / 2, item->pos.z, &room_num); - int32_t height = Room_GetHeight( - floor, item->pos.x, item->pos.y - STEP_L / 2, item->pos.z); + const int32_t height = Room_GetHeight( + sector, item->pos.x, item->pos.y - STEP_L / 2, item->pos.z); if (item->pos.y < height) { item->gravity_status = 1; @@ -278,8 +278,9 @@ void MovableBlock_Control(int16_t item_num) Room_AlterFloorHeight(item, -WALL_L); room_num = item->room_number; - floor = Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); Room_TestTriggers(g_TriggerIndex, true); } } diff --git a/src/game/objects/traps/pendulum.c b/src/game/objects/traps/pendulum.c index 827ad95ff..4436ce55c 100644 --- a/src/game/objects/traps/pendulum.c +++ b/src/game/objects/traps/pendulum.c @@ -45,9 +45,9 @@ void Pendulum_Control(int16_t item_num) Effect_Blood(x, y, z, g_LaraItem->speed, d, g_LaraItem->room_number); } - FLOOR_INFO *floor = Room_GetFloor( + const SECTOR_INFO *const sector = Room_GetSector( item->pos.x, item->pos.y, item->pos.z, &item->room_number); - item->floor = Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + item->floor = Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); Item_Animate(item); } diff --git a/src/game/objects/traps/rolling_ball.c b/src/game/objects/traps/rolling_ball.c index 7b42b8e11..3006cd736 100644 --- a/src/game/objects/traps/rolling_ball.c +++ b/src/game/objects/traps/rolling_ball.c @@ -57,14 +57,14 @@ void RollingBall_Control(int16_t item_num) Item_Animate(item); int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + const SECTOR_INFO *sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); if (item->room_number != room_num) { Item_NewRoom(item_num, room_num); } item->floor = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); Room_TestTriggers(g_TriggerIndex, true); @@ -78,8 +78,8 @@ void RollingBall_Control(int16_t item_num) item->pos.x + (((WALL_L / 2) * Math_Sin(item->rot.y)) >> W2V_SHIFT); int32_t z = item->pos.z + (((WALL_L / 2) * Math_Cos(item->rot.y)) >> W2V_SHIFT); - floor = Room_GetFloor(x, item->pos.y, z, &room_num); - if (Room_GetHeight(floor, x, item->pos.y, z) < item->pos.y) { + sector = Room_GetSector(x, item->pos.y, z, &room_num); + if (Room_GetHeight(sector, x, item->pos.y, z) < item->pos.y) { item->status = IS_DEACTIVATED; item->pos.x = oldx; item->pos.y = item->floor; diff --git a/src/game/objects/traps/sliding_pillar.c b/src/game/objects/traps/sliding_pillar.c index 8e1f2c7b2..d02c61154 100644 --- a/src/game/objects/traps/sliding_pillar.c +++ b/src/game/objects/traps/sliding_pillar.c @@ -35,7 +35,7 @@ void SlidingPillar_Control(int16_t item_num) Item_Animate(item); int16_t room_num = item->room_number; - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); if (item->room_number != room_num) { Item_NewRoom(item_num, room_num); } diff --git a/src/game/objects/traps/thors_hammer.c b/src/game/objects/traps/thors_hammer.c index 8af2f8aa2..f4bb21869 100644 --- a/src/game/objects/traps/thors_hammer.c +++ b/src/game/objects/traps/thors_hammer.c @@ -114,8 +114,9 @@ void ThorsHandle_Control(int16_t item_num) int32_t old_z = z; int16_t room_num = item->room_number; - FLOOR_INFO *floor = Room_GetFloor(x, item->pos.y, z, &room_num); - Room_GetHeight(floor, x, item->pos.y, z); + const SECTOR_INFO *const sector = + Room_GetSector(x, item->pos.y, z, &room_num); + Room_GetHeight(sector, x, item->pos.y, z); Room_TestTriggers(g_TriggerIndex, true); switch (item->rot.y) { diff --git a/src/game/phase/phase_demo.c b/src/game/phase/phase_demo.c index 520421bcd..24ab609ef 100644 --- a/src/game/phase/phase_demo.c +++ b/src/game/phase/phase_demo.c @@ -188,9 +188,9 @@ static void Phase_Demo_Start(void *arg) Item_NewRoom(g_Lara.item_number, room_num); } - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); - item->floor = Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + const SECTOR_INFO *const sector = + Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num); + item->floor = Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); Random_SeedDraw(0xD371F947); Random_SeedControl(0xD371F947); diff --git a/src/game/room.c b/src/game/room.c index 197fdfa2f..9362289f0 100644 --- a/src/game/room.c +++ b/src/game/room.c @@ -159,23 +159,24 @@ static void Room_RemoveFlipItems(ROOM_INFO *r) } } -int16_t Room_GetTiltType(FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z) +int16_t Room_GetTiltType( + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z) { ROOM_INFO *r; - while (floor->pit_room != NO_ROOM) { - r = &g_RoomInfo[floor->pit_room]; - floor = &r->floor - [((z - r->z) >> WALL_SHIFT) - + ((x - r->x) >> WALL_SHIFT) * r->x_size]; + while (sector->pit_room != NO_ROOM) { + r = &g_RoomInfo[sector->pit_room]; + sector = &r->sectors + [((z - r->z) >> WALL_SHIFT) + + ((x - r->x) >> WALL_SHIFT) * r->z_size]; } - if (y + 512 < ((int32_t)floor->floor << 8)) { + if (y + 512 < ((int32_t)sector->floor << 8)) { return 0; } - if (floor->index) { - int16_t *data = &g_FloorData[floor->index]; + if (sector->index) { + int16_t *data = &g_FloorData[sector->index]; if ((data[0] & DATA_TYPE) == FT_TILT) { return data[1]; } @@ -219,7 +220,7 @@ void Room_GetNearByRooms( void Room_GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num) { - Room_GetFloor(x, y, z, &room_num); + Room_GetSector(x, y, z, &room_num); for (int i = 0; i < g_RoomsToDrawCount; i++) { int16_t drawn_room = g_RoomsToDraw[i]; @@ -233,98 +234,98 @@ void Room_GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num) } } -FLOOR_INFO *Room_GetFloor(int32_t x, int32_t y, int32_t z, int16_t *room_num) +SECTOR_INFO *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num) { int16_t data; - FLOOR_INFO *floor; - ROOM_INFO *r = &g_RoomInfo[*room_num]; + SECTOR_INFO *sector; + const ROOM_INFO *r = &g_RoomInfo[*room_num]; do { - int32_t x_floor = (z - r->z) >> WALL_SHIFT; - int32_t y_floor = (x - r->x) >> WALL_SHIFT; - - if (x_floor <= 0) { - x_floor = 0; - if (y_floor < 1) { - y_floor = 1; - } else if (y_floor > r->y_size - 2) { - y_floor = r->y_size - 2; + int32_t z_sector = (z - r->z) >> WALL_SHIFT; + int32_t x_sector = (x - r->x) >> WALL_SHIFT; + + if (z_sector <= 0) { + z_sector = 0; + if (x_sector < 1) { + x_sector = 1; + } else if (x_sector > r->x_size - 2) { + x_sector = r->x_size - 2; } - } else if (x_floor >= r->x_size - 1) { - x_floor = r->x_size - 1; - if (y_floor < 1) { - y_floor = 1; - } else if (y_floor > r->y_size - 2) { - y_floor = r->y_size - 2; + } else if (z_sector >= r->z_size - 1) { + z_sector = r->z_size - 1; + if (x_sector < 1) { + x_sector = 1; + } else if (x_sector > r->x_size - 2) { + x_sector = r->x_size - 2; } - } else if (y_floor < 0) { - y_floor = 0; - } else if (y_floor >= r->y_size) { - y_floor = r->y_size - 1; + } else if (x_sector < 0) { + x_sector = 0; + } else if (x_sector >= r->x_size) { + x_sector = r->x_size - 1; } - floor = &r->floor[x_floor + y_floor * r->x_size]; - if (!floor->index) { + sector = &r->sectors[z_sector + x_sector * r->z_size]; + if (!sector->index) { break; } - data = Room_GetDoor(floor); + data = Room_GetDoor(sector); if (data != NO_ROOM) { *room_num = data; r = &g_RoomInfo[data]; } } while (data != NO_ROOM); - if (y >= ((int32_t)floor->floor << 8)) { + if (y >= ((int32_t)sector->floor << 8)) { do { - if (floor->pit_room == NO_ROOM) { + if (sector->pit_room == NO_ROOM) { break; } - *room_num = floor->pit_room; + *room_num = sector->pit_room; - r = &g_RoomInfo[floor->pit_room]; - int32_t x_floor = (z - r->z) >> WALL_SHIFT; - int32_t y_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; - } while (y >= ((int32_t)floor->floor << 8)); - } else if (y < ((int32_t)floor->ceiling << 8)) { + r = &g_RoomInfo[sector->pit_room]; + 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)) { do { - if (floor->sky_room == NO_ROOM) { + if (sector->sky_room == NO_ROOM) { break; } - *room_num = floor->sky_room; + *room_num = sector->sky_room; - r = &g_RoomInfo[floor->sky_room]; - int32_t x_floor = (z - r->z) >> WALL_SHIFT; - int32_t y_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; - } while (y < ((int32_t)floor->ceiling << 8)); + r = &g_RoomInfo[sector->sky_room]; + 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)); } - return floor; + return sector; } int16_t Room_GetCeiling( - const FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z) + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z) { int16_t *data; int16_t type; int16_t ended; int16_t trigger; - const FLOOR_INFO *f = floor; - while (f->sky_room != NO_ROOM) { - ROOM_INFO *r = &g_RoomInfo[f->sky_room]; - int32_t x_floor = (z - r->z) >> WALL_SHIFT; - int32_t y_floor = (x - r->x) >> WALL_SHIFT; - f = &r->floor[x_floor + y_floor * r->x_size]; + const SECTOR_INFO *sky_sector = sector; + while (sky_sector->sky_room != NO_ROOM) { + const ROOM_INFO *const r = &g_RoomInfo[sky_sector->sky_room]; + const int32_t z_sector = (z - r->z) >> WALL_SHIFT; + const int32_t x_sector = (x - r->x) >> WALL_SHIFT; + sky_sector = &r->sectors[z_sector + x_sector * r->z_size]; } - int16_t height = f->ceiling << 8; + int16_t height = sky_sector->ceiling << 8; - if (f->index) { - data = &g_FloorData[f->index]; + if (sky_sector->index) { + data = &g_FloorData[sky_sector->index]; type = *data & DATA_TYPE; ended = *data++ & END_BIT; @@ -358,18 +359,18 @@ int16_t Room_GetCeiling( } } - while (floor->pit_room != NO_ROOM) { - ROOM_INFO *r = &g_RoomInfo[floor->pit_room]; - int32_t x_floor = (z - r->z) >> WALL_SHIFT; - int32_t y_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; + while (sector->pit_room != NO_ROOM) { + const ROOM_INFO *const r = &g_RoomInfo[sector->pit_room]; + 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]; } - if (!floor->index) { + if (!sector->index) { return height; } - data = &g_FloorData[floor->index]; + data = &g_FloorData[sector->index]; do { type = *data++; @@ -410,13 +411,13 @@ int16_t Room_GetCeiling( return height; } -int16_t Room_GetDoor(FLOOR_INFO *floor) +int16_t Room_GetDoor(const SECTOR_INFO *sector) { - if (!floor->index) { + if (!sector->index) { return NO_ROOM; } - int16_t *data = &g_FloorData[floor->index]; + int16_t *data = &g_FloorData[sector->index]; int16_t type = *data++; if (type == FT_TILT) { @@ -435,25 +436,26 @@ int16_t Room_GetDoor(FLOOR_INFO *floor) return NO_ROOM; } -int16_t Room_GetHeight(const FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z) +int16_t Room_GetHeight( + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z) { g_HeightType = HT_WALL; - while (floor->pit_room != NO_ROOM) { - ROOM_INFO *r = &g_RoomInfo[floor->pit_room]; - int32_t x_floor = (z - r->z) >> WALL_SHIFT; - int32_t y_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; + while (sector->pit_room != NO_ROOM) { + const ROOM_INFO *const r = &g_RoomInfo[sector->pit_room]; + 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]; } - int16_t height = floor->floor << 8; + int16_t height = sector->floor << 8; g_TriggerIndex = NULL; - if (!floor->index) { + if (!sector->index) { return height; } - int16_t *data = &g_FloorData[floor->index]; + int16_t *data = &g_FloorData[sector->index]; int16_t type; int16_t trigger; do { @@ -534,63 +536,63 @@ int16_t Room_GetHeight(const FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z) int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num) { - ROOM_INFO *r = &g_RoomInfo[room_num]; + const ROOM_INFO *r = &g_RoomInfo[room_num]; int16_t data; - FLOOR_INFO *floor; - int32_t x_floor, y_floor; + const SECTOR_INFO *sector; + int32_t z_sector, x_sector; do { - x_floor = (z - r->z) >> WALL_SHIFT; - y_floor = (x - r->x) >> WALL_SHIFT; - - if (x_floor <= 0) { - x_floor = 0; - if (y_floor < 1) { - y_floor = 1; - } else if (y_floor > r->y_size - 2) { - y_floor = r->y_size - 2; + z_sector = (z - r->z) >> WALL_SHIFT; + x_sector = (x - r->x) >> WALL_SHIFT; + + if (z_sector <= 0) { + z_sector = 0; + if (x_sector < 1) { + x_sector = 1; + } else if (x_sector > r->x_size - 2) { + x_sector = r->x_size - 2; } - } else if (x_floor >= r->x_size - 1) { - x_floor = r->x_size - 1; - if (y_floor < 1) { - y_floor = 1; - } else if (y_floor > r->y_size - 2) { - y_floor = r->y_size - 2; + } else if (z_sector >= r->z_size - 1) { + z_sector = r->z_size - 1; + if (x_sector < 1) { + x_sector = 1; + } else if (x_sector > r->x_size - 2) { + x_sector = r->x_size - 2; } - } else if (y_floor < 0) { - y_floor = 0; - } else if (y_floor >= r->y_size) { - y_floor = r->y_size - 1; + } else if (x_sector < 0) { + x_sector = 0; + } else if (x_sector >= r->x_size) { + x_sector = r->x_size - 1; } - floor = &r->floor[x_floor + y_floor * r->x_size]; - data = Room_GetDoor(floor); + sector = &r->sectors[z_sector + x_sector * r->z_size]; + data = Room_GetDoor(sector); if (data != NO_ROOM) { r = &g_RoomInfo[data]; } } while (data != NO_ROOM); if (r->flags & RF_UNDERWATER) { - while (floor->sky_room != NO_ROOM) { - r = &g_RoomInfo[floor->sky_room]; + while (sector->sky_room != NO_ROOM) { + r = &g_RoomInfo[sector->sky_room]; if (!(r->flags & RF_UNDERWATER)) { break; } - x_floor = (z - r->z) >> WALL_SHIFT; - y_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; + z_sector = (z - r->z) >> WALL_SHIFT; + x_sector = (x - r->x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->z_size]; } - return floor->ceiling << 8; + return sector->ceiling << 8; } else { - while (floor->pit_room != NO_ROOM) { - r = &g_RoomInfo[floor->pit_room]; + while (sector->pit_room != NO_ROOM) { + r = &g_RoomInfo[sector->pit_room]; if (r->flags & RF_UNDERWATER) { - return floor->floor << 8; + return sector->floor << 8; } - x_floor = (z - r->z) >> WALL_SHIFT; - y_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; + z_sector = (z - r->z) >> WALL_SHIFT; + x_sector = (x - r->x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->z_size]; } return NO_HEIGHT; } @@ -601,11 +603,11 @@ int16_t Room_GetIndexFromPos(const int32_t x, const int32_t y, const int32_t z) for (int i = 0; i < g_RoomCount; i++) { const ROOM_INFO *const room = &g_RoomInfo[i]; const int32_t x1 = room->x + WALL_L; - const int32_t x2 = room->x + (room->y_size << WALL_SHIFT) - WALL_L; + const int32_t x2 = room->x + (room->x_size << WALL_SHIFT) - WALL_L; const int32_t y1 = room->max_ceiling; const int32_t y2 = room->min_floor; const int32_t z1 = room->z + WALL_L; - const int32_t z2 = room->z + (room->x_size << WALL_SHIFT) - WALL_L; + const int32_t z2 = room->z + (room->z_size << WALL_SHIFT) - WALL_L; if (x >= x1 && x < x2 && y >= y1 && y <= y2 && z >= z1 && z < z2) { return i; } @@ -620,59 +622,59 @@ void Room_AlterFloorHeight(ITEM_INFO *item, int32_t height) } int16_t data; - FLOOR_INFO *floor; - ROOM_INFO *r = &g_RoomInfo[item->room_number]; + SECTOR_INFO *sector; + const ROOM_INFO *r = &g_RoomInfo[item->room_number]; do { - int32_t z_floor = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t x_floor = (item->pos.x - r->x) >> WALL_SHIFT; - - if (z_floor <= 0) { - z_floor = 0; - CLAMP(x_floor, 1, r->y_size - 2); - } else if (z_floor >= r->x_size - 1) { - z_floor = r->x_size - 1; - CLAMP(x_floor, 1, r->y_size - 2); + int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; + int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; + + if (z_sector <= 0) { + z_sector = 0; + CLAMP(x_sector, 1, r->x_size - 2); + } else if (z_sector >= r->z_size - 1) { + z_sector = r->z_size - 1; + CLAMP(x_sector, 1, r->x_size - 2); } else { - CLAMP(x_floor, 0, r->y_size - 1); + CLAMP(x_sector, 0, r->x_size - 1); } - floor = &r->floor[z_floor + x_floor * r->x_size]; - data = Room_GetDoor(floor); + sector = &r->sectors[z_sector + x_sector * r->z_size]; + data = Room_GetDoor(sector); if (data != NO_ROOM) { r = &g_RoomInfo[data]; } } while (data != NO_ROOM); - FLOOR_INFO *f = floor; - while (f->sky_room != NO_ROOM) { - ROOM_INFO *r = &g_RoomInfo[f->sky_room]; - int32_t x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - f = &r->floor[x_floor + y_floor * r->x_size]; + SECTOR_INFO *sky_sector = sector; + while (sky_sector->sky_room != NO_ROOM) { + const ROOM_INFO *const r = &g_RoomInfo[sky_sector->sky_room]; + const int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; + const int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; + sky_sector = &r->sectors[z_sector + x_sector * r->z_size]; } - while (floor->pit_room != NO_ROOM) { - ROOM_INFO *r = &g_RoomInfo[floor->pit_room]; - int32_t x_floor = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t y_floor = (item->pos.x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + y_floor * r->x_size]; + while (sector->pit_room != NO_ROOM) { + const ROOM_INFO *const r = &g_RoomInfo[sector->pit_room]; + const int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; + const int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->z_size]; } - if (floor->floor != NO_HEIGHT / 256) { - floor->floor += height >> 8; - if (floor->floor == f->ceiling) { - floor->floor = NO_HEIGHT / 256; + if (sector->floor != NO_HEIGHT / 256) { + sector->floor += height >> 8; + if (sector->floor == sky_sector->ceiling) { + sector->floor = NO_HEIGHT / 256; } } else { - floor->floor = f->ceiling + (height >> 8); + sector->floor = sky_sector->ceiling + (height >> 8); } - if (g_Boxes[floor->box].overlap_index & BLOCKABLE) { + if (g_Boxes[sector->box].overlap_index & BLOCKABLE) { if (height < 0) { - g_Boxes[floor->box].overlap_index |= BLOCKED; + g_Boxes[sector->box].overlap_index |= BLOCKED; } else { - g_Boxes[floor->box].overlap_index &= ~BLOCKED; + g_Boxes[sector->box].overlap_index &= ~BLOCKED; } } } @@ -981,19 +983,19 @@ void Room_TestTriggers(int16_t *data, bool heavy) } bool Room_IsOnWalkable( - const FLOOR_INFO *floor, const int32_t x, const int32_t y, const int32_t z, - const int32_t room_height) + const SECTOR_INFO *sector, const int32_t x, const int32_t y, + const int32_t z, const int32_t room_height) { - while (floor->pit_room != NO_ROOM) { - const ROOM_INFO *const r = &g_RoomInfo[floor->pit_room]; - const int32_t x_floor = (z - r->z) >> WALL_SHIFT; - const int32_t z_floor = (x - r->x) >> WALL_SHIFT; - floor = &r->floor[x_floor + z_floor * r->x_size]; + while (sector->pit_room != NO_ROOM) { + const ROOM_INFO *const r = &g_RoomInfo[sector->pit_room]; + 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]; } - int16_t height = floor->floor << 8; + int16_t height = sector->floor << 8; - int16_t *floor_data = &g_FloorData[floor->index]; + int16_t *floor_data = &g_FloorData[sector->index]; int16_t type; int16_t trigger; int16_t trig_flags; diff --git a/src/game/room.h b/src/game/room.h index ed6519537..2f61381d5 100644 --- a/src/game/room.h +++ b/src/game/room.h @@ -12,17 +12,18 @@ extern int32_t g_FlipEffect; extern int32_t g_FlipStatus; extern int32_t g_FlipMapTable[MAX_FLIP_MAPS]; -int16_t Room_GetTiltType(FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z); +int16_t Room_GetTiltType( + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z); int32_t Room_FindGridShift(int32_t src, int32_t dst); void Room_GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num); void Room_GetNearByRooms( int32_t x, int32_t y, int32_t z, int32_t r, int32_t h, int16_t room_num); -FLOOR_INFO *Room_GetFloor(int32_t x, int32_t y, int32_t z, int16_t *room_num); +SECTOR_INFO *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num); int16_t Room_GetCeiling( - const FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z); -int16_t Room_GetDoor(FLOOR_INFO *floor); + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z); +int16_t Room_GetDoor(const SECTOR_INFO *sector); int16_t Room_GetHeight( - const FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z); + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z); int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num); int16_t Room_GetIndexFromPos(int32_t x, int32_t y, int32_t z); @@ -31,5 +32,5 @@ void Room_AlterFloorHeight(ITEM_INFO *item, int32_t height); void Room_TestTriggers(int16_t *data, bool heavy); void Room_FlipMap(void); bool Room_IsOnWalkable( - const FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z, + const SECTOR_INFO *sector, int32_t x, int32_t y, int32_t z, int32_t room_height); diff --git a/src/game/savegame/savegame.c b/src/game/savegame/savegame.c index 18c5d2ed2..15df3a189 100644 --- a/src/game/savegame/savegame.c +++ b/src/game/savegame/savegame.c @@ -89,10 +89,10 @@ static void Savegame_LoadPostprocess(void) if (obj->save_position && obj->shadow_size) { int16_t room_num = item->room_number; - FLOOR_INFO *floor = - Room_GetFloor(item->pos.x, item->pos.y, item->pos.z, &room_num); + const SECTOR_INFO *const sector = Room_GetSector( + item->pos.x, item->pos.y, item->pos.z, &room_num); item->floor = - Room_GetHeight(floor, item->pos.x, item->pos.y, item->pos.z); + Room_GetHeight(sector, item->pos.x, item->pos.y, item->pos.z); } if (obj->save_flags) { diff --git a/src/game/stats.c b/src/game/stats.c index ed53bc1a2..1f1005da4 100644 --- a/src/game/stats.c +++ b/src/game/stats.c @@ -18,7 +18,7 @@ #define MAX_TEXTSTRINGS 10 static int32_t m_CachedItemCount = 0; -static FLOOR_INFO **m_CachedFloorArray = NULL; +static SECTOR_INFO **m_CachedSectorArray = NULL; static int32_t m_LevelPickups = 0; static int32_t m_LevelKillables = 0; static int32_t m_LevelSecrets = 0; @@ -53,7 +53,7 @@ int16_t m_KillableObjs[] = { static void Stats_TraverseFloor(void); static void Stats_CheckTriggers( - ROOM_INFO *r, int room_num, int x_floor, int y_floor); + ROOM_INFO *r, int room_num, int z_sector, int x_sector); static bool Stats_IsObjectKillable(int32_t obj_num); static void Stats_IncludeKillableItem(int16_t item_num); @@ -63,31 +63,31 @@ static void Stats_TraverseFloor(void) for (int i = 0; i < g_RoomCount; i++) { ROOM_INFO *r = &g_RoomInfo[i]; - for (int x_floor = 0; x_floor < r->x_size; x_floor++) { - for (int y_floor = 0; y_floor < r->y_size; y_floor++) { - Stats_CheckTriggers(r, i, x_floor, y_floor); + for (int z_sector = 0; z_sector < r->z_size; z_sector++) { + for (int x_sector = 0; x_sector < r->x_size; x_sector++) { + Stats_CheckTriggers(r, i, z_sector, x_sector); } } } } static void Stats_CheckTriggers( - ROOM_INFO *r, int room_num, int x_floor, int y_floor) + ROOM_INFO *r, int room_num, int z_sector, int x_sector) { - if (x_floor == 0 || x_floor == r->x_size - 1) { - if (y_floor == 0 || y_floor == r->y_size - 1) { + if (z_sector == 0 || z_sector == r->z_size - 1) { + if (x_sector == 0 || x_sector == r->x_size - 1) { return; } } - FLOOR_INFO *floor = - &m_CachedFloorArray[room_num][x_floor + y_floor * r->x_size]; + const SECTOR_INFO *const sector = + &m_CachedSectorArray[room_num][z_sector + x_sector * r->z_size]; - if (!floor->index) { + if (!sector->index) { return; } - int16_t *data = &g_FloorData[floor->index]; + int16_t *data = &g_FloorData[sector->index]; int16_t type; int16_t trigger; int16_t trig_flags; @@ -209,16 +209,17 @@ void Stats_ComputeTotal( void Stats_ObserveRoomsLoad(void) { - m_CachedFloorArray = - GameBuf_Alloc(g_RoomCount * sizeof(FLOOR_INFO *), GBUF_ROOM_FLOOR); + m_CachedSectorArray = + GameBuf_Alloc(g_RoomCount * sizeof(SECTOR_INFO *), GBUF_ROOM_SECTOR); for (int i = 0; i < g_RoomCount; i++) { const ROOM_INFO *current_room_info = &g_RoomInfo[i]; - int count = current_room_info->y_size * current_room_info->x_size; - m_CachedFloorArray[i] = - GameBuf_Alloc(count * sizeof(FLOOR_INFO), GBUF_ROOM_FLOOR); + const int32_t count = + current_room_info->x_size * current_room_info->z_size; + m_CachedSectorArray[i] = + GameBuf_Alloc(count * sizeof(SECTOR_INFO), GBUF_ROOM_SECTOR); memcpy( - m_CachedFloorArray[i], current_room_info->floor, - count * sizeof(FLOOR_INFO)); + m_CachedSectorArray[i], current_room_info->sectors, + count * sizeof(SECTOR_INFO)); } } diff --git a/src/global/types.h b/src/global/types.h index 1b6cb7a8c..824b61fab 100644 --- a/src/global/types.h +++ b/src/global/types.h @@ -1160,18 +1160,18 @@ typedef struct DOOR_INFOS { DOOR_INFO door[]; } DOOR_INFOS; -typedef struct FLOOR_INFO { +typedef struct SECTOR_INFO { uint16_t index; int16_t box; uint8_t pit_room; int8_t floor; uint8_t sky_room; int8_t ceiling; -} FLOOR_INFO; +} SECTOR_INFO; typedef struct DOORPOS_DATA { - FLOOR_INFO *floor; - FLOOR_INFO old_floor; + SECTOR_INFO *sector; + SECTOR_INFO old_sector; int16_t block; } DOORPOS_DATA; @@ -1200,7 +1200,7 @@ typedef struct MESH_INFO { typedef struct ROOM_INFO { int16_t *data; DOOR_INFOS *doors; - FLOOR_INFO *floor; + SECTOR_INFO *sectors; LIGHT_INFO *light; MESH_INFO *mesh; int32_t x; @@ -1208,8 +1208,8 @@ typedef struct ROOM_INFO { int32_t z; int32_t min_floor; int32_t max_ceiling; + int16_t z_size; int16_t x_size; - int16_t y_size; int16_t ambient; int16_t num_lights; int16_t num_meshes;