diff --git a/src/game/camera.c b/src/game/camera.c index 27795b3e5..f4172fd52 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -104,17 +104,17 @@ static void M_SmartShift( LOS_Check(&g_Camera.target, ideal); const ROOM *r = &g_RoomInfo[g_Camera.target.room_num]; - int32_t z_sector = (g_Camera.target.z - r->z) >> WALL_SHIFT; - int32_t x_sector = (g_Camera.target.x - r->x) >> WALL_SHIFT; + int32_t z_sector = (g_Camera.target.z - r->pos.z) >> WALL_SHIFT; + int32_t x_sector = (g_Camera.target.x - r->pos.x) >> WALL_SHIFT; - const int16_t item_box = r->sectors[z_sector + x_sector * r->z_size].box; + const int16_t item_box = r->sectors[z_sector + x_sector * r->size.z].box; BOX_INFO *box = &g_Boxes[item_box]; r = &g_RoomInfo[ideal->room_num]; - z_sector = (ideal->z - r->z) >> WALL_SHIFT; - x_sector = (ideal->x - r->x) >> WALL_SHIFT; + z_sector = (ideal->z - r->pos.z) >> WALL_SHIFT; + x_sector = (ideal->x - r->pos.x) >> WALL_SHIFT; - int16_t camera_box = r->sectors[z_sector + x_sector * r->z_size].box; + int16_t camera_box = r->sectors[z_sector + x_sector * r->size.z].box; if (camera_box != NO_BOX && (ideal->z < box->left || ideal->z > box->right || ideal->x < box->top || ideal->x > box->bottom)) { @@ -129,7 +129,7 @@ static void M_SmartShift( int32_t test = (ideal->z - WALL_L) | (WALL_L - 1); bool bad_left = M_BadPosition(ideal->x, ideal->y, test, ideal->room_num); if (!bad_left) { - camera_box = r->sectors[z_sector - 1 + x_sector * r->z_size].box; + camera_box = r->sectors[z_sector - 1 + x_sector * r->size.z].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].left < left) { left = g_Boxes[camera_box].left; } @@ -138,7 +138,7 @@ static void M_SmartShift( test = (ideal->z + WALL_L) & (~(WALL_L - 1)); bool bad_right = M_BadPosition(ideal->x, ideal->y, test, ideal->room_num); if (!bad_right) { - camera_box = r->sectors[z_sector + 1 + x_sector * r->z_size].box; + camera_box = r->sectors[z_sector + 1 + x_sector * r->size.z].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].right > right) { right = g_Boxes[camera_box].right; } @@ -147,7 +147,7 @@ static void M_SmartShift( test = (ideal->x - WALL_L) | (WALL_L - 1); bool bad_top = M_BadPosition(test, ideal->y, ideal->z, ideal->room_num); if (!bad_top) { - camera_box = r->sectors[z_sector + (x_sector - 1) * r->z_size].box; + camera_box = r->sectors[z_sector + (x_sector - 1) * r->size.z].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].top < top) { top = g_Boxes[camera_box].top; } @@ -156,7 +156,7 @@ static void M_SmartShift( test = (ideal->x + WALL_L) & (~(WALL_L - 1)); bool bad_bottom = M_BadPosition(test, ideal->y, ideal->z, ideal->room_num); if (!bad_bottom) { - camera_box = r->sectors[z_sector + (x_sector + 1) * r->z_size].box; + camera_box = r->sectors[z_sector + (x_sector + 1) * r->size.z].box; if (camera_box != NO_ITEM && g_Boxes[camera_box].bottom > bottom) { bottom = g_Boxes[camera_box].bottom; } diff --git a/src/game/collide.c b/src/game/collide.c index b24257392..8b5c118c3 100644 --- a/src/game/collide.c +++ b/src/game/collide.c @@ -343,7 +343,7 @@ bool Collide_CollideStaticObjects( for (int i = 0; i < g_RoomsToDrawCount; i++) { int16_t room_num = g_RoomsToDraw[i]; ROOM *r = &g_RoomInfo[room_num]; - MESH *mesh = r->mesh; + MESH *mesh = r->meshes; for (int j = 0; j < r->num_meshes; j++, mesh++) { STATIC_INFO *sinfo = &g_StaticObjects[mesh->static_num]; diff --git a/src/game/creature.c b/src/game/creature.c index 5c6f2fc29..6a6a23132 100644 --- a/src/game/creature.c +++ b/src/game/creature.c @@ -54,15 +54,15 @@ void Creature_AIInfo(ITEM *item, AI_INFO *info) } const ROOM *r = &g_RoomInfo[item->room_num]; - int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; - item->box_num = r->sectors[z_sector + x_sector * r->z_size].box; + int32_t z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT; + int32_t x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT; + item->box_num = r->sectors[z_sector + x_sector * r->size.z].box; info->zone_num = zone[item->box_num]; r = &g_RoomInfo[g_LaraItem->room_num]; - z_sector = (g_LaraItem->pos.z - r->z) >> WALL_SHIFT; - x_sector = (g_LaraItem->pos.x - r->x) >> WALL_SHIFT; - g_LaraItem->box_num = r->sectors[z_sector + x_sector * r->z_size].box; + z_sector = (g_LaraItem->pos.z - r->pos.z) >> WALL_SHIFT; + x_sector = (g_LaraItem->pos.x - r->pos.x) >> WALL_SHIFT; + g_LaraItem->box_num = r->sectors[z_sector + x_sector * r->size.z].box; info->enemy_zone = zone[g_LaraItem->box_num]; if (g_Boxes[g_LaraItem->box_num].overlap_index & creature->lot.block_mask) { diff --git a/src/game/game/game_draw.c b/src/game/game/game_draw.c index 6ef1a468a..3eb6761d9 100644 --- a/src/game/game/game_draw.c +++ b/src/game/game/game_draw.c @@ -46,10 +46,10 @@ void Game_DrawScene(bool draw_overlay) for (int i = 0; i < g_RoomsToDrawCount; i++) { int16_t room_num = g_RoomsToDraw[i]; ROOM *r = &g_RoomInfo[room_num]; - r->top = 0; - r->left = 0; - r->right = Viewport_GetMaxX(); - r->bottom = Viewport_GetMaxY(); + r->bound_top = 0; + r->bound_left = 0; + r->bound_right = Viewport_GetMaxX(); + r->bound_bottom = Viewport_GetMaxY(); Room_DrawSingleRoom(room_num); } diff --git a/src/game/inject.c b/src/game/inject.c index 50f423785..0c96745e9 100644 --- a/src/game/inject.c +++ b/src/game/inject.c @@ -1100,11 +1100,11 @@ static void M_FloorDataEdits(INJECTION *injection, LEVEL_INFO *level_info) LOG_WARNING("Room index %d is invalid", room); } else { r = &g_RoomInfo[room]; - if (x >= r->x_size || z >= r->z_size) { + if (x >= r->size.x || z >= r->size.z) { LOG_WARNING( "Sector [%d,%d] is invalid for room %d", x, z, room); } else { - sector = &r->sectors[r->z_size * x + z]; + sector = &r->sectors[r->size.z * x + z]; } } @@ -1216,8 +1216,8 @@ static void M_RoomShift(INJECTION *injection, int16_t room_num) const int32_t y_shift = ROUND_TO_CLICK(VFile_ReadS32(fp)); ROOM *room = &g_RoomInfo[room_num]; - room->x += x_shift; - room->z += z_shift; + room->pos.x += x_shift; + room->pos.z += z_shift; room->min_floor += y_shift; room->max_ceiling += y_shift; @@ -1238,7 +1238,7 @@ static void M_RoomShift(INJECTION *injection, int16_t room_num) } // Update the sector floor and ceiling heights to match. - for (int32_t i = 0; i < room->z_size * room->x_size; i++) { + for (int32_t i = 0; i < room->size.z * room->size.x; i++) { SECTOR *const sector = &room->sectors[i]; if (sector->floor.height == NO_HEIGHT || sector->ceiling.height == NO_HEIGHT) { diff --git a/src/game/items.c b/src/game/items.c index 338c73674..4751d18cb 100644 --- a/src/game/items.c +++ b/src/game/items.c @@ -146,9 +146,9 @@ void Item_Initialise(int16_t item_num) ROOM *const r = &g_RoomInfo[item->room_num]; item->next_item = r->item_num; r->item_num = item_num; - 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 *const sector = &r->sectors[z_sector + x_sector * r->z_size]; + const int32_t z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT; + const int32_t x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT; + const SECTOR *const sector = &r->sectors[z_sector + x_sector * r->size.z]; item->floor = sector->floor.height; if (g_GameInfo.bonus_flag & GBF_NGPLUS) { diff --git a/src/game/lara/control.c b/src/game/lara/control.c index 15e83fbbb..7f3bc27d9 100644 --- a/src/game/lara/control.c +++ b/src/game/lara/control.c @@ -37,8 +37,8 @@ static void M_WaterCurrent(COLL_INFO *coll) const ROOM *const r = &g_RoomInfo[item->room_num]; const SECTOR *const sector = &r->sectors - [((item->pos.z - r->z) >> WALL_SHIFT) - + ((item->pos.x - r->x) >> WALL_SHIFT) * r->z_size]; + [((item->pos.z - r->pos.z) >> WALL_SHIFT) + + ((item->pos.x - r->pos.x) >> WALL_SHIFT) * r->size.z]; item->box_num = sector->box; if (Box_CalculateTarget(&target, item, &g_Lara.lot) == TARGET_NONE) { diff --git a/src/game/level.c b/src/game/level.c index b27d3c4e9..42c50c0f7 100644 --- a/src/game/level.c +++ b/src/game/level.c @@ -149,35 +149,33 @@ static void M_LoadRooms(VFILE *file) g_RoomInfo = GameBuf_Alloc(sizeof(ROOM) * g_RoomCount, GBUF_ROOMS); int i = 0; - for (ROOM *current_room_info = g_RoomInfo; i < g_RoomCount; - i++, current_room_info++) { + for (ROOM *r = g_RoomInfo; i < g_RoomCount; i++, r++) { // Room position - current_room_info->x = VFile_ReadS32(file); - current_room_info->y = 0; - current_room_info->z = VFile_ReadS32(file); + r->pos.x = VFile_ReadS32(file); + r->pos.y = 0; + r->pos.z = VFile_ReadS32(file); // Room floor/ceiling - current_room_info->min_floor = VFile_ReadS32(file); - current_room_info->max_ceiling = VFile_ReadS32(file); + r->min_floor = VFile_ReadS32(file); + r->max_ceiling = VFile_ReadS32(file); // Room mesh const uint32_t num_meshes = VFile_ReadS32(file); const uint32_t inj_mesh_size = Inject_GetExtraRoomMeshSize(i); - current_room_info->data = GameBuf_Alloc( + r->data = GameBuf_Alloc( sizeof(uint16_t) * (num_meshes + inj_mesh_size), GBUF_ROOM_MESH); - VFile_Read( - file, current_room_info->data, sizeof(uint16_t) * num_meshes); + VFile_Read(file, r->data, sizeof(uint16_t) * num_meshes); // Doors const uint16_t num_doors = VFile_ReadS16(file); if (!num_doors) { - current_room_info->portals = NULL; + r->portals = NULL; } else { - current_room_info->portals = GameBuf_Alloc( + r->portals = GameBuf_Alloc( sizeof(uint16_t) + sizeof(PORTAL) * num_doors, GBUF_ROOM_DOOR); - current_room_info->portals->count = num_doors; + r->portals->count = num_doors; for (int32_t j = 0; j < num_doors; j++) { - PORTAL *const portal = ¤t_room_info->portals->portal[j]; + PORTAL *const portal = &r->portals->portal[j]; portal->room_num = VFile_ReadS16(file); portal->normal.x = VFile_ReadS16(file); portal->normal.y = VFile_ReadS16(file); @@ -191,15 +189,14 @@ static void M_LoadRooms(VFILE *file) } // Room floor - current_room_info->z_size = VFile_ReadS16(file); - current_room_info->x_size = VFile_ReadS16(file); - const int32_t sector_count = - current_room_info->x_size * current_room_info->z_size; - current_room_info->sectors = + r->size.z = VFile_ReadS16(file); + r->size.x = VFile_ReadS16(file); + const int32_t sector_count = r->size.x * r->size.z; + r->sectors = GameBuf_Alloc(sizeof(SECTOR) * sector_count, GBUF_ROOM_SECTOR); for (int32_t j = 0; j < sector_count; j++) { - SECTOR *const sector = ¤t_room_info->sectors[j]; - sector->index = VFile_ReadU16(file); + SECTOR *const sector = &r->sectors[j]; + sector->idx = VFile_ReadU16(file); sector->box = VFile_ReadS16(file); sector->portal_room.pit = VFile_ReadU8(file); const int8_t floor_clicks = VFile_ReadS8(file); @@ -211,16 +208,15 @@ static void M_LoadRooms(VFILE *file) } // Room lights - current_room_info->ambient = VFile_ReadS16(file); - current_room_info->num_lights = VFile_ReadS16(file); - if (!current_room_info->num_lights) { - current_room_info->light = NULL; + r->ambient = VFile_ReadS16(file); + r->num_lights = VFile_ReadS16(file); + if (!r->num_lights) { + r->lights = NULL; } else { - current_room_info->light = GameBuf_Alloc( - sizeof(LIGHT) * current_room_info->num_lights, - GBUF_ROOM_LIGHTS); - for (int32_t j = 0; j < current_room_info->num_lights; j++) { - LIGHT *light = ¤t_room_info->light[j]; + r->lights = + GameBuf_Alloc(sizeof(LIGHT) * r->num_lights, GBUF_ROOM_LIGHTS); + for (int32_t j = 0; j < r->num_lights; j++) { + LIGHT *light = &r->lights[j]; light->pos.x = VFile_ReadS32(file); light->pos.y = VFile_ReadS32(file); light->pos.z = VFile_ReadS32(file); @@ -230,15 +226,14 @@ static void M_LoadRooms(VFILE *file) } // Static mesh infos - current_room_info->num_meshes = VFile_ReadS16(file); - if (!current_room_info->num_meshes) { - current_room_info->mesh = NULL; + r->num_meshes = VFile_ReadS16(file); + if (!r->num_meshes) { + r->meshes = NULL; } else { - current_room_info->mesh = GameBuf_Alloc( - sizeof(MESH) * current_room_info->num_meshes, - GBUF_ROOM_STATIC_MESHES); - for (int32_t j = 0; j < current_room_info->num_meshes; j++) { - MESH *mesh = ¤t_room_info->mesh[j]; + r->meshes = GameBuf_Alloc( + sizeof(MESH) * r->num_meshes, GBUF_ROOM_STATIC_MESHES); + for (int32_t j = 0; j < r->num_meshes; j++) { + MESH *mesh = &r->meshes[j]; mesh->pos.x = VFile_ReadS32(file); mesh->pos.y = VFile_ReadS32(file); mesh->pos.z = VFile_ReadS32(file); @@ -249,19 +244,19 @@ static void M_LoadRooms(VFILE *file) } // Flipped (alternative) room - current_room_info->flipped_room = VFile_ReadS16(file); + r->flipped_room = VFile_ReadS16(file); // Room flags - current_room_info->flags = VFile_ReadU16(file); + r->flags = VFile_ReadU16(file); // Initialise some variables - current_room_info->bound_active = 0; - current_room_info->left = Viewport_GetMaxX(); - current_room_info->top = Viewport_GetMaxY(); - current_room_info->bottom = 0; - current_room_info->right = 0; - current_room_info->item_num = NO_ITEM; - current_room_info->fx_num = NO_ITEM; + r->bound_active = 0; + r->bound_left = Viewport_GetMaxX(); + r->bound_top = Viewport_GetMaxY(); + r->bound_bottom = 0; + r->bound_right = 0; + r->item_num = NO_ITEM; + r->fx_num = NO_ITEM; } const int32_t fd_length = VFile_ReadS32(file); diff --git a/src/game/lot.c b/src/game/lot.c index 3f7a188ad..232127593 100644 --- a/src/game/lot.c +++ b/src/game/lot.c @@ -159,9 +159,9 @@ void LOT_CreateZone(ITEM *item) } const ROOM *const r = &g_RoomInfo[item->room_num]; - 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_num = r->sectors[z_sector + x_sector * r->z_size].box; + const int32_t z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT; + const int32_t x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT; + item->box_num = r->sectors[z_sector + x_sector * r->size.z].box; int16_t zone_num = zone[item->box_num]; int16_t flip_num = flip[item->box_num]; diff --git a/src/game/objects/creatures/bacon_lara.c b/src/game/objects/creatures/bacon_lara.c index 4a543b2d5..8199c52db 100644 --- a/src/game/objects/creatures/bacon_lara.c +++ b/src/game/objects/creatures/bacon_lara.c @@ -42,8 +42,8 @@ bool BaconLara_InitialiseAnchor(int32_t room_index) } ROOM *r = &g_RoomInfo[room_index]; - m_AnchorX = r->x + r->x_size * (WALL_L >> 1); - m_AnchorZ = r->z + r->z_size * (WALL_L >> 1); + m_AnchorX = r->pos.x + r->size.x * (WALL_L >> 1); + m_AnchorZ = r->pos.z + r->size.z * (WALL_L >> 1); return true; } diff --git a/src/game/objects/general/door.c b/src/game/objects/general/door.c index d26d02dfb..9d2f524f1 100644 --- a/src/game/objects/general/door.c +++ b/src/game/objects/general/door.c @@ -113,17 +113,17 @@ void Door_Initialise(int16_t item_num) int16_t box_num; r = &g_RoomInfo[item->room_num]; - z_sector = ((item->pos.z - r->z) >> WALL_SHIFT) + dx; - x_sector = ((item->pos.x - r->x) >> WALL_SHIFT) + dy; - door->d1.sector = &r->sectors[z_sector + x_sector * r->z_size]; + z_sector = ((item->pos.z - r->pos.z) >> WALL_SHIFT) + dx; + x_sector = ((item->pos.x - r->pos.x) >> WALL_SHIFT) + dy; + door->d1.sector = &r->sectors[z_sector + x_sector * r->size.z]; room_num = door->d1.sector->portal_room.wall; if (room_num == NO_ROOM) { box_num = door->d1.sector->box; } else { b = &g_RoomInfo[room_num]; - 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; + z_sector = ((item->pos.z - b->pos.z) >> WALL_SHIFT) + dx; + x_sector = ((item->pos.x - b->pos.x) >> WALL_SHIFT) + dy; + box_num = b->sectors[z_sector + x_sector * b->size.z].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; @@ -133,17 +133,17 @@ void Door_Initialise(int16_t item_num) if (r->flipped_room != -1) { r = &g_RoomInfo[r->flipped_room]; - 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]; + z_sector = ((item->pos.z - r->pos.z) >> WALL_SHIFT) + dx; + x_sector = ((item->pos.x - r->pos.x) >> WALL_SHIFT) + dy; + door->d1flip.sector = &r->sectors[z_sector + x_sector * r->size.z]; room_num = door->d1flip.sector->portal_room.wall; if (room_num == NO_ROOM) { box_num = door->d1flip.sector->box; } else { b = &g_RoomInfo[room_num]; - 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; + z_sector = ((item->pos.z - b->pos.z) >> WALL_SHIFT) + dx; + x_sector = ((item->pos.x - b->pos.x) >> WALL_SHIFT) + dy; + box_num = b->sectors[z_sector + x_sector * b->size.z].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; @@ -165,17 +165,17 @@ void Door_Initialise(int16_t item_num) } r = &g_RoomInfo[room_num]; - z_sector = (item->pos.z - r->z) >> WALL_SHIFT; - x_sector = (item->pos.x - r->x) >> WALL_SHIFT; - door->d2.sector = &r->sectors[z_sector + x_sector * r->z_size]; + z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT; + x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT; + door->d2.sector = &r->sectors[z_sector + x_sector * r->size.z]; room_num = door->d2.sector->portal_room.wall; if (room_num == NO_ROOM) { box_num = door->d2.sector->box; } else { b = &g_RoomInfo[room_num]; - 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; + z_sector = (item->pos.z - b->pos.z) >> WALL_SHIFT; + x_sector = (item->pos.x - b->pos.x) >> WALL_SHIFT; + box_num = b->sectors[z_sector + x_sector * b->size.z].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; @@ -185,17 +185,17 @@ void Door_Initialise(int16_t item_num) if (r->flipped_room != -1) { r = &g_RoomInfo[r->flipped_room]; - 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]; + z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT; + x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT; + door->d2flip.sector = &r->sectors[z_sector + x_sector * r->size.z]; room_num = door->d2flip.sector->portal_room.wall; if (room_num == NO_ROOM) { box_num = door->d2flip.sector->box; } else { b = &g_RoomInfo[room_num]; - 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; + z_sector = (item->pos.z - b->pos.z) >> WALL_SHIFT; + x_sector = (item->pos.x - b->pos.x) >> WALL_SHIFT; + box_num = b->sectors[z_sector + x_sector * b->size.z].box; } if (!(g_Boxes[box_num].overlap_index & BLOCKABLE)) { box_num = NO_BOX; diff --git a/src/game/output.c b/src/game/output.c index dd995b541..6277239bd 100644 --- a/src/game/output.c +++ b/src/game/output.c @@ -619,7 +619,7 @@ void Output_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num) .z = 0, }; for (int i = 0; i < r->num_lights; i++) { - LIGHT *light = &r->light[i]; + LIGHT *light = &r->lights[i]; XYZ_32 lc = { .x = x - light->pos.x, .y = y - light->pos.y, diff --git a/src/game/room.c b/src/game/room.c index f8c0e5838..20e7dcfdc 100644 --- a/src/game/room.c +++ b/src/game/room.c @@ -236,9 +236,9 @@ SECTOR *Room_GetPitSector( { while (sector->portal_room.pit != NO_ROOM) { const ROOM *const r = &g_RoomInfo[sector->portal_room.pit]; - 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]; + const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT; + const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->size.z]; } return (SECTOR *)sector; @@ -249,9 +249,9 @@ static SECTOR *M_GetSkySector( { while (sector->portal_room.sky != NO_ROOM) { const ROOM *const r = &g_RoomInfo[sector->portal_room.sky]; - 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]; + const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT; + const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->size.z]; } return (SECTOR *)sector; @@ -263,30 +263,30 @@ SECTOR *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num) SECTOR *sector; const ROOM *r = &g_RoomInfo[*room_num]; do { - int32_t z_sector = (z - r->z) >> WALL_SHIFT; - int32_t x_sector = (x - r->x) >> WALL_SHIFT; + int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT; + int32_t x_sector = (x - r->pos.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_sector > r->size.x - 2) { + x_sector = r->size.x - 2; } - } else if (z_sector >= r->z_size - 1) { - z_sector = r->z_size - 1; + } else if (z_sector >= r->size.z - 1) { + z_sector = r->size.z - 1; if (x_sector < 1) { x_sector = 1; - } else if (x_sector > r->x_size - 2) { - x_sector = r->x_size - 2; + } else if (x_sector > r->size.x - 2) { + x_sector = r->size.x - 2; } } else if (x_sector < 0) { x_sector = 0; - } else if (x_sector >= r->x_size) { - x_sector = r->x_size - 1; + } else if (x_sector >= r->size.x) { + x_sector = r->size.x - 1; } - sector = &r->sectors[z_sector + x_sector * r->z_size]; + sector = &r->sectors[z_sector + x_sector * r->size.z]; portal_room = sector->portal_room.wall; if (portal_room != NO_ROOM) { *room_num = portal_room; @@ -303,9 +303,9 @@ SECTOR *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num) *room_num = sector->portal_room.pit; r = &g_RoomInfo[sector->portal_room.pit]; - 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]; + const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT; + const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->size.z]; } while (y >= sector->floor.height); } else if (y < sector->ceiling.height) { do { @@ -316,9 +316,9 @@ SECTOR *Room_GetSector(int32_t x, int32_t y, int32_t z, int16_t *room_num) *room_num = sector->portal_room.sky; r = &g_RoomInfo[sector->portal_room.sky]; - 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]; + const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT; + const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->size.z]; } while (y < sector->ceiling.height); } @@ -455,30 +455,30 @@ int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num) int32_t z_sector, x_sector; do { - z_sector = (z - r->z) >> WALL_SHIFT; - x_sector = (x - r->x) >> WALL_SHIFT; + z_sector = (z - r->pos.z) >> WALL_SHIFT; + x_sector = (x - r->pos.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_sector > r->size.x - 2) { + x_sector = r->size.x - 2; } - } else if (z_sector >= r->z_size - 1) { - z_sector = r->z_size - 1; + } else if (z_sector >= r->size.z - 1) { + z_sector = r->size.z - 1; if (x_sector < 1) { x_sector = 1; - } else if (x_sector > r->x_size - 2) { - x_sector = r->x_size - 2; + } else if (x_sector > r->size.x - 2) { + x_sector = r->size.x - 2; } } else if (x_sector < 0) { x_sector = 0; - } else if (x_sector >= r->x_size) { - x_sector = r->x_size - 1; + } else if (x_sector >= r->size.x) { + x_sector = r->size.x - 1; } - sector = &r->sectors[z_sector + x_sector * r->z_size]; + sector = &r->sectors[z_sector + x_sector * r->size.z]; portal_room = sector->portal_room.wall; if (portal_room != NO_ROOM) { r = &g_RoomInfo[portal_room]; @@ -491,9 +491,9 @@ int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num) if (!(r->flags & RF_UNDERWATER)) { break; } - z_sector = (z - r->z) >> WALL_SHIFT; - x_sector = (x - r->x) >> WALL_SHIFT; - sector = &r->sectors[z_sector + x_sector * r->z_size]; + z_sector = (z - r->pos.z) >> WALL_SHIFT; + x_sector = (x - r->pos.x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->size.z]; } return sector->ceiling.height; } else { @@ -502,9 +502,9 @@ int16_t Room_GetWaterHeight(int32_t x, int32_t y, int32_t z, int16_t room_num) if (r->flags & RF_UNDERWATER) { return sector->floor.height; } - z_sector = (z - r->z) >> WALL_SHIFT; - x_sector = (x - r->x) >> WALL_SHIFT; - sector = &r->sectors[z_sector + x_sector * r->z_size]; + z_sector = (z - r->pos.z) >> WALL_SHIFT; + x_sector = (x - r->pos.x) >> WALL_SHIFT; + sector = &r->sectors[z_sector + x_sector * r->size.z]; } return NO_HEIGHT; } @@ -514,12 +514,12 @@ 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 *const room = &g_RoomInfo[i]; - const int32_t x1 = room->x + WALL_L; - const int32_t x2 = room->x + (room->x_size << WALL_SHIFT) - WALL_L; + const int32_t x1 = room->pos.x + WALL_L; + const int32_t x2 = room->pos.x + (room->size.x << 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->z_size << WALL_SHIFT) - WALL_L; + const int32_t z1 = room->pos.z + WALL_L; + const int32_t z2 = room->pos.z + (room->size.z << WALL_SHIFT) - WALL_L; if (x >= x1 && x < x2 && y >= y1 && y <= y2 && z >= z1 && z < z2) { return i; } @@ -538,20 +538,20 @@ void Room_AlterFloorHeight(ITEM *item, int32_t height) const ROOM *r = &g_RoomInfo[item->room_num]; do { - int32_t z_sector = (item->pos.z - r->z) >> WALL_SHIFT; - int32_t x_sector = (item->pos.x - r->x) >> WALL_SHIFT; + int32_t z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT; + int32_t x_sector = (item->pos.x - r->pos.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); + CLAMP(x_sector, 1, r->size.x - 2); + } else if (z_sector >= r->size.z - 1) { + z_sector = r->size.z - 1; + CLAMP(x_sector, 1, r->size.x - 2); } else { - CLAMP(x_sector, 0, r->x_size - 1); + CLAMP(x_sector, 0, r->size.x - 1); } - sector = &r->sectors[z_sector + x_sector * r->z_size]; + sector = &r->sectors[z_sector + x_sector * r->size.z]; portal_room = sector->portal_room.wall; if (portal_room != NO_ROOM) { r = &g_RoomInfo[portal_room]; @@ -615,10 +615,10 @@ void Room_ParseFloorData(const int16_t *floor_data) { for (int32_t i = 0; i < g_RoomCount; i++) { const ROOM *const room = &g_RoomInfo[i]; - for (int32_t j = 0; j < room->x_size * room->z_size; j++) { + for (int32_t j = 0; j < room->size.x * room->size.z; j++) { SECTOR *const sector = &room->sectors[j]; Room_PopulateSectorData( - &room->sectors[j], floor_data, sector->index, NULL_FD_INDEX); + &room->sectors[j], floor_data, sector->idx, NULL_FD_INDEX); } } } diff --git a/src/game/room_draw.c b/src/game/room_draw.c index 393c65e14..7314d6b3b 100644 --- a/src/game/room_draw.c +++ b/src/game/room_draw.c @@ -33,21 +33,21 @@ static void M_PrintDrawStack(void) static bool M_SetBounds(const PORTAL *portal, const ROOM *parent) { - const int32_t x = - portal->normal.x * (parent->x + portal->vertex[0].x - g_W2VMatrix._03); - const int32_t y = - portal->normal.y * (parent->y + portal->vertex[0].y - g_W2VMatrix._13); - const int32_t z = - portal->normal.z * (parent->z + portal->vertex[0].z - g_W2VMatrix._23); + const int32_t x = portal->normal.x + * (parent->pos.x + portal->vertex[0].x - g_W2VMatrix._03); + const int32_t y = portal->normal.y + * (parent->pos.y + portal->vertex[0].y - g_W2VMatrix._13); + const int32_t z = portal->normal.z + * (parent->pos.z + portal->vertex[0].z - g_W2VMatrix._23); if (x + y + z >= 0) { return false; } DOOR_VBUF door_vbuf[4]; - int32_t left = parent->right; - int32_t right = parent->left; - int32_t top = parent->bottom; - int32_t bottom = parent->top; + int32_t left = parent->bound_right; + int32_t right = parent->bound_left; + int32_t top = parent->bound_bottom; + int32_t bottom = parent->bound_top; int32_t z_toofar = 0; int32_t z_behind = 0; @@ -132,17 +132,17 @@ static bool M_SetBounds(const PORTAL *portal, const ROOM *parent) } } - if (left < parent->left) { - left = parent->left; + if (left < parent->bound_left) { + left = parent->bound_left; } - if (right > parent->right) { - right = parent->right; + if (right > parent->bound_right) { + right = parent->bound_right; } - if (top < parent->top) { - top = parent->top; + if (top < parent->bound_top) { + top = parent->bound_top; } - if (bottom > parent->bottom) { - bottom = parent->bottom; + if (bottom > parent->bound_bottom) { + bottom = parent->bound_bottom; } if (left >= right || top >= bottom) { @@ -150,17 +150,17 @@ static bool M_SetBounds(const PORTAL *portal, const ROOM *parent) } ROOM *r = &g_RoomInfo[portal->room_num]; - if (left < r->left) { - r->left = left; + if (left < r->bound_left) { + r->bound_left = left; } - if (top < r->top) { - r->top = top; + if (top < r->bound_top) { + r->bound_top = top; } - if (right > r->right) { - r->right = right; + if (right > r->bound_right) { + r->bound_right = right; } - if (bottom > r->bottom) { - r->bottom = bottom; + if (bottom > r->bound_bottom) { + r->bound_bottom = bottom; } if (!r->bound_active) { @@ -180,7 +180,7 @@ static void M_GetBounds(int16_t room_num) Shell_ExitSystem("Matrix stack overflow."); } m_RoomNumStack[m_RoomNumStackIdx++] = room_num; - Matrix_TranslateAbs(r->x, r->y, r->z); + Matrix_TranslateAbs(r->pos.x, r->pos.y, r->pos.z); if (r->portals != NULL) { for (int i = 0; i < r->portals->count; i++) { const PORTAL *portal = &r->portals->portal[i]; @@ -218,10 +218,10 @@ static void M_PrepareToDraw(int16_t room_num) return; } - r->left = g_PhdLeft; - r->top = g_PhdTop; - r->right = g_PhdRight; - r->bottom = g_PhdBottom; + r->bound_left = g_PhdLeft; + r->bound_top = g_PhdTop; + r->bound_right = g_PhdRight; + r->bound_bottom = g_PhdBottom; r->bound_active = 1; if (g_RoomsToDrawCount + 1 < MAX_ROOMS_TO_DRAW) { @@ -229,7 +229,7 @@ static void M_PrepareToDraw(int16_t room_num) } Matrix_Push(); - Matrix_TranslateAbs(r->x, r->y, r->z); + Matrix_TranslateAbs(r->pos.x, r->pos.y, r->pos.z); if (r->portals != NULL) { for (int i = 0; i < r->portals->count; i++) { const PORTAL *portal = &r->portals->portal[i]; @@ -276,12 +276,12 @@ void Room_DrawSingleRoom(int16_t room_num) r->bound_active = 0; Matrix_Push(); - Matrix_TranslateAbs(r->x, r->y, r->z); + Matrix_TranslateAbs(r->pos.x, r->pos.y, r->pos.z); - g_PhdLeft = r->left; - g_PhdRight = r->right; - g_PhdTop = r->top; - g_PhdBottom = r->bottom; + g_PhdLeft = r->bound_left; + g_PhdRight = r->bound_right; + g_PhdTop = r->bound_top; + g_PhdBottom = r->bound_bottom; Output_DrawRoom(r->data); @@ -293,7 +293,7 @@ void Room_DrawSingleRoom(int16_t room_num) } for (int i = 0; i < r->num_meshes; i++) { - MESH *mesh = &r->mesh[i]; + MESH *mesh = &r->meshes[i]; if (g_StaticObjects[mesh->static_num].flags & 2) { Matrix_Push(); Matrix_TranslateAbs(mesh->pos.x, mesh->pos.y, mesh->pos.z); @@ -315,8 +315,8 @@ void Room_DrawSingleRoom(int16_t room_num) Matrix_Pop(); - r->left = Viewport_GetMaxX(); - r->bottom = 0; - r->right = 0; - r->top = Viewport_GetMaxY(); + r->bound_left = Viewport_GetMaxX(); + r->bound_bottom = 0; + r->bound_right = 0; + r->bound_top = Viewport_GetMaxY(); } diff --git a/src/game/stats.c b/src/game/stats.c index 21c4d5ce2..d9b2f8607 100644 --- a/src/game/stats.c +++ b/src/game/stats.c @@ -43,8 +43,8 @@ static void M_TraverseFloor(void) for (int i = 0; i < g_RoomCount; i++) { ROOM *r = &g_RoomInfo[i]; - for (int z_sector = 0; z_sector < r->z_size; z_sector++) { - for (int x_sector = 0; x_sector < r->x_size; x_sector++) { + for (int z_sector = 0; z_sector < r->size.z; z_sector++) { + for (int x_sector = 0; x_sector < r->size.x; x_sector++) { M_CheckTriggers(r, i, z_sector, x_sector); } } @@ -53,14 +53,14 @@ static void M_TraverseFloor(void) static void M_CheckTriggers(ROOM *r, int room_num, int z_sector, int x_sector) { - if (z_sector == 0 || z_sector == r->z_size - 1) { - if (x_sector == 0 || x_sector == r->x_size - 1) { + if (z_sector == 0 || z_sector == r->size.z - 1) { + if (x_sector == 0 || x_sector == r->size.x - 1) { return; } } const SECTOR *const sector = - &m_CachedSectorArray[room_num][z_sector + x_sector * r->z_size]; + &m_CachedSectorArray[room_num][z_sector + x_sector * r->size.z]; if (sector->trigger == NULL) { return; @@ -156,7 +156,7 @@ void Stats_ObserveRoomsLoad(void) for (int i = 0; i < g_RoomCount; i++) { const ROOM *current_room_info = &g_RoomInfo[i]; const int32_t count = - current_room_info->x_size * current_room_info->z_size; + current_room_info->size.x * current_room_info->size.z; m_CachedSectorArray[i] = GameBuf_Alloc(count * sizeof(SECTOR), GBUF_ROOM_SECTOR); memcpy( diff --git a/subprojects/libtrx b/subprojects/libtrx index 198f10361..0776388ff 160000 --- a/subprojects/libtrx +++ b/subprojects/libtrx @@ -1 +1 @@ -Subproject commit 198f10361bc0994678deccbd281393750f39ab69 +Subproject commit 0776388ff52e6dade3ffc8d469806ec43a0dce18