Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
libtrx: update rooms typing
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Sep 24, 2024
1 parent 2b29714 commit 3900709
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 139 deletions.
4 changes: 2 additions & 2 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 23 additions & 23 deletions docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ typedef struct __unaligned { // decompiled
int16_t box_num;
int16_t timer;
uint16_t flags;
int16_t shade1;
int16_t shade2;
int16_t shade_1;
int16_t shade_2;
int16_t carried_item;
void *data;
union {
Expand Down Expand Up @@ -885,9 +885,7 @@ typedef struct { // decompiled

typedef struct __unaligned { // decompiled
int16_t room;
int16_t x;
int16_t y;
int16_t z;
XYZ_16 normal;
XYZ_16 vertex[4];
} PORTAL;

Expand All @@ -900,19 +898,19 @@ typedef struct __unaligned { // decompiled
int32_t x;
int32_t y;
int32_t z;
int16_t intensity1;
int16_t intensity2;
int32_t falloff1;
int32_t falloff2;
int16_t intensity_1;
int16_t intensity_2;
int32_t falloff_1;
int32_t falloff_2;
} LIGHT;

typedef struct __unaligned { // decompiled
int32_t x;
int32_t y;
int32_t z;
int16_t y_rot;
int16_t shade1;
int16_t shade2;
XYZ_16 pos;
struct __unaligned {
int16_t y;
} rot;
int16_t shade_1;
int16_t shade_2;
int16_t static_num;
} MESH;

Expand All @@ -932,16 +930,18 @@ typedef struct __unaligned {
typedef struct __unaligned { // decompiled
int16_t *data;
PORTALS *portals;
SECTOR *sector;
LIGHT *light;
MESH *mesh;
SECTOR *sectors;
LIGHT *lights;
MESH *meshes;
XYZ_32 pos;
int32_t min_floor;
int32_t max_ceiling;
int16_t z_size;
int16_t x_size;
int16_t ambient1;
int16_t ambient2;
struct __unaligned {
int16_t z;
int16_t x;
} size;
int16_t ambient_1;
int16_t ambient_2;
int16_t light_mode;
int16_t num_lights;
int16_t num_meshes;
Expand Down Expand Up @@ -4014,7 +4014,7 @@ typedef enum {
0x00450F80 0x01F1 -R void __cdecl S_PrintShadow(int16_t radius, const BOUNDS_16 *bounds, const ITEM *item);
0x00451180 0x02F6 -R void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num);
0x00451480 0x0031 -R void __cdecl S_CalculateStaticLight(int16_t adder);
0x004514C0 0x0124 -R void __cdecl S_CalculateStaticMeshLight(int32_t x, int32_t y, int32_t z, int32_t shade1, int32_t shade2, ROOM *room);
0x004514C0 0x0124 -R void __cdecl S_CalculateStaticMeshLight(int32_t x, int32_t y, int32_t z, int32_t shade_1, int32_t shade_2, ROOM *room);
0x004515F0 0x0206 -R void __cdecl S_LightRoom(ROOM *room);
0x00451800 0x01CC -R void __cdecl S_DrawHealthBar(int32_t percent);
0x004519D0 0x01F6 -R void __cdecl S_DrawAirBar(int32_t percent);
Expand Down
4 changes: 2 additions & 2 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void __cdecl Camera_SmartShift(
const ROOM *r = &g_Rooms[g_Camera.target.room_num];
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;
int16_t item_box = r->sector[z_sector + x_sector * r->z_size].box;
int16_t item_box = r->sectors[z_sector + x_sector * r->size.z].box;
const BOX_INFO *box = &g_Boxes[item_box];

int32_t left = (int32_t)box->left << WALL_SHIFT;
Expand All @@ -254,7 +254,7 @@ void __cdecl Camera_SmartShift(
r = &g_Rooms[target->room_num];
z_sector = (target->z - r->pos.z) >> WALL_SHIFT;
x_sector = (target->x - r->pos.x) >> WALL_SHIFT;
int16_t camera_box = r->sector[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
&& (target->z < left || target->z > right || target->x < top
Expand Down
40 changes: 20 additions & 20 deletions src/game/collide.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int32_t __cdecl Collide_CollideStaticObjects(
const ROOM *const room = &g_Rooms[g_DrawRoomsArray[i]];

for (int32_t j = 0; j < room->num_meshes; j++) {
const MESH *const mesh = &room->mesh[j];
const MESH *const mesh = &room->meshes[j];
const STATIC_INFO *const sinfo = &g_StaticObjects[mesh->static_num];

if (sinfo->flags & 1) {
Expand All @@ -320,35 +320,35 @@ int32_t __cdecl Collide_CollideStaticObjects(
int32_t x_max;
int32_t z_min;
int32_t z_max;
int32_t y_min = mesh->y + sinfo->collision_bounds.min_y;
int32_t y_max = mesh->y + sinfo->collision_bounds.max_y;
switch (mesh->y_rot) {
const int32_t y_min = mesh->pos.y + sinfo->collision_bounds.min_y;
const int32_t y_max = mesh->pos.y + sinfo->collision_bounds.max_y;
switch (mesh->rot.y) {
case PHD_90:
x_min = mesh->x + sinfo->collision_bounds.min_z;
x_max = mesh->x + sinfo->collision_bounds.max_z;
z_min = mesh->z - sinfo->collision_bounds.max_x;
z_max = mesh->z - sinfo->collision_bounds.min_x;
x_min = mesh->pos.x + sinfo->collision_bounds.min_z;
x_max = mesh->pos.x + sinfo->collision_bounds.max_z;
z_min = mesh->pos.z - sinfo->collision_bounds.max_x;
z_max = mesh->pos.z - sinfo->collision_bounds.min_x;
break;

case -PHD_180:
x_min = mesh->x - sinfo->collision_bounds.max_x;
x_max = mesh->x - sinfo->collision_bounds.min_x;
z_min = mesh->z - sinfo->collision_bounds.max_z;
z_max = mesh->z - sinfo->collision_bounds.min_z;
x_min = mesh->pos.x - sinfo->collision_bounds.max_x;
x_max = mesh->pos.x - sinfo->collision_bounds.min_x;
z_min = mesh->pos.z - sinfo->collision_bounds.max_z;
z_max = mesh->pos.z - sinfo->collision_bounds.min_z;
break;

case -PHD_90:
x_min = mesh->x - sinfo->collision_bounds.max_z;
x_max = mesh->x - sinfo->collision_bounds.min_z;
z_min = mesh->z + sinfo->collision_bounds.min_x;
z_max = mesh->z + sinfo->collision_bounds.max_x;
x_min = mesh->pos.x - sinfo->collision_bounds.max_z;
x_max = mesh->pos.x - sinfo->collision_bounds.min_z;
z_min = mesh->pos.z + sinfo->collision_bounds.min_x;
z_max = mesh->pos.z + sinfo->collision_bounds.max_x;
break;

default:
x_min = mesh->x + sinfo->collision_bounds.min_x;
x_max = mesh->x + sinfo->collision_bounds.max_x;
z_min = mesh->z + sinfo->collision_bounds.min_z;
z_max = mesh->z + sinfo->collision_bounds.max_z;
x_min = mesh->pos.x + sinfo->collision_bounds.min_x;
x_max = mesh->pos.x + sinfo->collision_bounds.max_x;
z_min = mesh->pos.z + sinfo->collision_bounds.min_z;
z_max = mesh->pos.z + sinfo->collision_bounds.max_z;
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/game/creature.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ void __cdecl Creature_AIInfo(ITEM *const item, AI_INFO *const info)
const ROOM *const r = &g_Rooms[item->room_num];
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->sector[z_sector + x_sector * r->z_size].box;
item->box_num = r->sectors[z_sector + x_sector * r->size.z].box;
info->zone_num = zone[item->box_num];
}

{
const ROOM *const r = &g_Rooms[enemy->room_num];
const int32_t z_sector = (enemy->pos.z - r->pos.z) >> WALL_SHIFT;
const int32_t x_sector = (enemy->pos.x - r->pos.x) >> WALL_SHIFT;
enemy->box_num = r->sector[z_sector + x_sector * r->z_size].box;
enemy->box_num = r->sectors[z_sector + x_sector * r->size.z].box;
info->enemy_zone_num = zone[enemy->box_num];
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void __cdecl Item_Initialise(const int16_t item_num)

const int32_t dx = (item->pos.x - room->pos.x) >> WALL_SHIFT;
const int32_t dz = (item->pos.z - room->pos.z) >> WALL_SHIFT;
const SECTOR *const sector = &room->sector[dx * room->z_size + dz];
const SECTOR *const sector = &room->sectors[dx * room->size.z + dz];
item->floor = sector->floor << 8;

if (g_SaveGame.bonus_flag && !g_IsDemoLevelType) {
Expand Down
26 changes: 13 additions & 13 deletions src/game/lara/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ void __cdecl Lara_BaddieCollision(ITEM *lara_item, COLL_INFO *coll)
if (roomies_count >= MAX_BADDIE_COLLISION) {
break;
}
roomies[roomies_count++] = portals->portal[i].room;
roomies[roomies_count++] = portals->portal[i].room_num;
}
}

Expand Down Expand Up @@ -1556,23 +1556,23 @@ int32_t __cdecl Lara_GetWaterDepth(
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->sector[z_sector + x_sector * r->z_size];
sector = &r->sectors[z_sector + x_sector * r->size.z];
const int16_t data = Room_GetDoor(sector);
if (data == NO_ROOM) {
break;
Expand All @@ -1591,7 +1591,7 @@ int32_t __cdecl Lara_GetWaterDepth(
}
const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT;
const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT;
sector = &r->sector[z_sector + x_sector * r->z_size];
sector = &r->sectors[z_sector + x_sector * r->size.z];
}
return 0x7FFF;
}
Expand All @@ -1605,7 +1605,7 @@ int32_t __cdecl Lara_GetWaterDepth(
}
const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT;
const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT;
sector = &r->sector[z_sector + x_sector * r->z_size];
sector = &r->sectors[z_sector + x_sector * r->size.z];
}
return NO_HEIGHT;
}
Expand Down Expand Up @@ -1713,7 +1713,7 @@ void __cdecl Lara_WaterCurrent(COLL_INFO *const coll)
const ROOM *const r = &g_Rooms[g_LaraItem->room_num];
const int32_t z_sector = (g_LaraItem->pos.z - r->pos.z) >> WALL_SHIFT;
const int32_t x_sector = (g_LaraItem->pos.x - r->pos.x) >> WALL_SHIFT;
g_LaraItem->box_num = r->sector[z_sector + x_sector * r->z_size].box;
g_LaraItem->box_num = r->sectors[z_sector + x_sector * r->size.z].box;

if (g_Lara.creature == NULL) {
g_Lara.current_active = 0;
Expand Down
58 changes: 29 additions & 29 deletions src/game/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ static void __cdecl M_LoadRooms(VFILE *const file)
VFile_Read(file, r->portals->portal, sizeof(PORTAL) * num_doors);
}

r->z_size = VFile_ReadS16(file);
r->x_size = VFile_ReadS16(file);
r->size.z = VFile_ReadS16(file);
r->size.x = VFile_ReadS16(file);

r->sector = game_malloc(
sizeof(SECTOR) * r->z_size * r->x_size, GBUF_ROOM_FLOOR);
for (int32_t i = 0; i < r->z_size * r->x_size; i++) {
SECTOR *const sector = &r->sector[i];
r->sectors = game_malloc(
sizeof(SECTOR) * r->size.z * r->size.x, GBUF_ROOM_FLOOR);
for (int32_t i = 0; i < r->size.z * r->size.x; i++) {
SECTOR *const sector = &r->sectors[i];
sector->idx = VFile_ReadU16(file);
sector->box = VFile_ReadS16(file);
sector->pit_room = VFile_ReadU8(file);
Expand All @@ -149,42 +149,42 @@ static void __cdecl M_LoadRooms(VFILE *const file)
sector->ceiling = VFile_ReadS8(file);
}

r->ambient1 = VFile_ReadS16(file);
r->ambient2 = VFile_ReadS16(file);
r->ambient_1 = VFile_ReadS16(file);
r->ambient_2 = VFile_ReadS16(file);
r->light_mode = VFile_ReadS16(file);

r->num_lights = VFile_ReadS16(file);
if (!r->num_lights) {
r->light = NULL;
r->lights = NULL;
} else {
r->light =
r->lights =
game_malloc(sizeof(LIGHT) * r->num_lights, GBUF_ROOM_LIGHTS);
for (int32_t i = 0; i < r->num_lights; i++) {
LIGHT *const light = &r->light[i];
light->x = VFile_ReadS32(file);
light->y = VFile_ReadS32(file);
light->z = VFile_ReadS32(file);
light->intensity1 = VFile_ReadS16(file);
light->intensity2 = VFile_ReadS16(file);
light->falloff1 = VFile_ReadS32(file);
light->falloff2 = VFile_ReadS32(file);
LIGHT *const light = &r->lights[i];
light->pos.x = VFile_ReadS32(file);
light->pos.y = VFile_ReadS32(file);
light->pos.z = VFile_ReadS32(file);
light->intensity_1 = VFile_ReadS16(file);
light->intensity_2 = VFile_ReadS16(file);
light->falloff_1 = VFile_ReadS32(file);
light->falloff_2 = VFile_ReadS32(file);
}
}

r->num_meshes = VFile_ReadS16(file);
if (!r->num_meshes) {
r->mesh = NULL;
r->meshes = NULL;
} else {
r->mesh = game_malloc(
r->meshes = game_malloc(
sizeof(MESH) * r->num_meshes, GBUF_ROOM_STATIC_MESHES);
for (int32_t i = 0; i < r->num_meshes; i++) {
MESH *const mesh = &r->mesh[i];
mesh->x = VFile_ReadS32(file);
mesh->y = VFile_ReadS32(file);
mesh->z = VFile_ReadS32(file);
mesh->y_rot = VFile_ReadS16(file);
mesh->shade1 = VFile_ReadS16(file);
mesh->shade2 = VFile_ReadS16(file);
MESH *const mesh = &r->meshes[i];
mesh->pos.x = VFile_ReadS32(file);
mesh->pos.y = VFile_ReadS32(file);
mesh->pos.z = VFile_ReadS32(file);
mesh->rot.y = VFile_ReadS16(file);
mesh->shade_1 = VFile_ReadS16(file);
mesh->shade_2 = VFile_ReadS16(file);
mesh->static_num = VFile_ReadS16(file);
}
}
Expand Down Expand Up @@ -490,8 +490,8 @@ static void __cdecl M_LoadItems(VFILE *const file)
item->pos.y = VFile_ReadS32(file);
item->pos.z = VFile_ReadS32(file);
item->rot.y = VFile_ReadS16(file);
item->shade1 = VFile_ReadS16(file);
item->shade2 = VFile_ReadS16(file);
item->shade_1 = VFile_ReadS16(file);
item->shade_2 = VFile_ReadS16(file);
item->flags = VFile_ReadS16(file);
if (item->object_id < 0 || item->object_id >= O_NUMBER_OF) {
Shell_ExitSystemFmt(
Expand Down
2 changes: 1 addition & 1 deletion src/game/lot.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void __cdecl LOT_CreateZone(ITEM *const item)
const ROOM *const r = &g_Rooms[item->room_num];
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->sector[z_sector + x_sector * r->z_size].box;
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];
Expand Down
Loading

0 comments on commit 3900709

Please sign in to comment.