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

Commit a45aa29

Browse files
committed
libtrx: update rooms typing
1 parent 4d6b01b commit a45aa29

File tree

13 files changed

+140
-139
lines changed

13 files changed

+140
-139
lines changed

docs/progress.svg

Lines changed: 2 additions & 2 deletions
Loading

docs/progress.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ typedef struct __unaligned { // decompiled
545545
int16_t box_num;
546546
int16_t timer;
547547
uint16_t flags;
548-
int16_t shade1;
549-
int16_t shade2;
548+
int16_t shade_1;
549+
int16_t shade_2;
550550
int16_t carried_item;
551551
void *data;
552552
union {
@@ -885,9 +885,7 @@ typedef struct { // decompiled
885885

886886
typedef struct __unaligned { // decompiled
887887
int16_t room;
888-
int16_t x;
889-
int16_t y;
890-
int16_t z;
888+
XYZ_16 normal;
891889
XYZ_16 vertex[4];
892890
} PORTAL;
893891

@@ -900,19 +898,19 @@ typedef struct __unaligned { // decompiled
900898
int32_t x;
901899
int32_t y;
902900
int32_t z;
903-
int16_t intensity1;
904-
int16_t intensity2;
905-
int32_t falloff1;
906-
int32_t falloff2;
901+
int16_t intensity_1;
902+
int16_t intensity_2;
903+
int32_t falloff_1;
904+
int32_t falloff_2;
907905
} LIGHT;
908906

909907
typedef struct __unaligned { // decompiled
910-
int32_t x;
911-
int32_t y;
912-
int32_t z;
913-
int16_t y_rot;
914-
int16_t shade1;
915-
int16_t shade2;
908+
XYZ_16 pos;
909+
struct __unaligned {
910+
int16_t y;
911+
} rot;
912+
int16_t shade_1;
913+
int16_t shade_2;
916914
int16_t static_num;
917915
} MESH;
918916

@@ -932,16 +930,18 @@ typedef struct __unaligned {
932930
typedef struct __unaligned { // decompiled
933931
int16_t *data;
934932
PORTALS *portals;
935-
SECTOR *sector;
936-
LIGHT *light;
937-
MESH *mesh;
933+
SECTOR *sectors;
934+
LIGHT *lights;
935+
MESH *meshes;
938936
XYZ_32 pos;
939937
int32_t min_floor;
940938
int32_t max_ceiling;
941-
int16_t z_size;
942-
int16_t x_size;
943-
int16_t ambient1;
944-
int16_t ambient2;
939+
struct __unaligned {
940+
int16_t z;
941+
int16_t x;
942+
} size;
943+
int16_t ambient_1;
944+
int16_t ambient_2;
945945
int16_t light_mode;
946946
int16_t num_lights;
947947
int16_t num_meshes;
@@ -4014,7 +4014,7 @@ typedef enum {
40144014
0x00450F80 0x01F1 -R void __cdecl S_PrintShadow(int16_t radius, const BOUNDS_16 *bounds, const ITEM *item);
40154015
0x00451180 0x02F6 -R void __cdecl S_CalculateLight(int32_t x, int32_t y, int32_t z, int16_t room_num);
40164016
0x00451480 0x0031 -R void __cdecl S_CalculateStaticLight(int16_t adder);
4017-
0x004514C0 0x0124 -R void __cdecl S_CalculateStaticMeshLight(int32_t x, int32_t y, int32_t z, int32_t shade1, int32_t shade2, ROOM *room);
4017+
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);
40184018
0x004515F0 0x0206 -R void __cdecl S_LightRoom(ROOM *room);
40194019
0x00451800 0x01CC -R void __cdecl S_DrawHealthBar(int32_t percent);
40204020
0x004519D0 0x01F6 -R void __cdecl S_DrawAirBar(int32_t percent);

src/game/camera.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ void __cdecl Camera_SmartShift(
243243
const ROOM *r = &g_Rooms[g_Camera.target.room_num];
244244
int32_t z_sector = (g_Camera.target.z - r->pos.z) >> WALL_SHIFT;
245245
int32_t x_sector = (g_Camera.target.x - r->pos.x) >> WALL_SHIFT;
246-
int16_t item_box = r->sector[z_sector + x_sector * r->z_size].box;
246+
int16_t item_box = r->sectors[z_sector + x_sector * r->size.z].box;
247247
const BOX_INFO *box = &g_Boxes[item_box];
248248

249249
int32_t left = (int32_t)box->left << WALL_SHIFT;
@@ -254,7 +254,7 @@ void __cdecl Camera_SmartShift(
254254
r = &g_Rooms[target->room_num];
255255
z_sector = (target->z - r->pos.z) >> WALL_SHIFT;
256256
x_sector = (target->x - r->pos.x) >> WALL_SHIFT;
257-
int16_t camera_box = r->sector[z_sector + x_sector * r->z_size].box;
257+
int16_t camera_box = r->sectors[z_sector + x_sector * r->size.z].box;
258258

259259
if (camera_box != NO_BOX
260260
&& (target->z < left || target->z > right || target->x < top

src/game/collide.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ int32_t __cdecl Collide_CollideStaticObjects(
309309
const ROOM *const room = &g_Rooms[g_DrawRoomsArray[i]];
310310

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

315315
if (sinfo->flags & 1) {
@@ -320,35 +320,35 @@ int32_t __cdecl Collide_CollideStaticObjects(
320320
int32_t x_max;
321321
int32_t z_min;
322322
int32_t z_max;
323-
int32_t y_min = mesh->y + sinfo->collision_bounds.min_y;
324-
int32_t y_max = mesh->y + sinfo->collision_bounds.max_y;
325-
switch (mesh->y_rot) {
323+
const int32_t y_min = mesh->pos.y + sinfo->collision_bounds.min_y;
324+
const int32_t y_max = mesh->pos.y + sinfo->collision_bounds.max_y;
325+
switch (mesh->rot.y) {
326326
case PHD_90:
327-
x_min = mesh->x + sinfo->collision_bounds.min_z;
328-
x_max = mesh->x + sinfo->collision_bounds.max_z;
329-
z_min = mesh->z - sinfo->collision_bounds.max_x;
330-
z_max = mesh->z - sinfo->collision_bounds.min_x;
327+
x_min = mesh->pos.x + sinfo->collision_bounds.min_z;
328+
x_max = mesh->pos.x + sinfo->collision_bounds.max_z;
329+
z_min = mesh->pos.z - sinfo->collision_bounds.max_x;
330+
z_max = mesh->pos.z - sinfo->collision_bounds.min_x;
331331
break;
332332

333333
case -PHD_180:
334-
x_min = mesh->x - sinfo->collision_bounds.max_x;
335-
x_max = mesh->x - sinfo->collision_bounds.min_x;
336-
z_min = mesh->z - sinfo->collision_bounds.max_z;
337-
z_max = mesh->z - sinfo->collision_bounds.min_z;
334+
x_min = mesh->pos.x - sinfo->collision_bounds.max_x;
335+
x_max = mesh->pos.x - sinfo->collision_bounds.min_x;
336+
z_min = mesh->pos.z - sinfo->collision_bounds.max_z;
337+
z_max = mesh->pos.z - sinfo->collision_bounds.min_z;
338338
break;
339339

340340
case -PHD_90:
341-
x_min = mesh->x - sinfo->collision_bounds.max_z;
342-
x_max = mesh->x - sinfo->collision_bounds.min_z;
343-
z_min = mesh->z + sinfo->collision_bounds.min_x;
344-
z_max = mesh->z + sinfo->collision_bounds.max_x;
341+
x_min = mesh->pos.x - sinfo->collision_bounds.max_z;
342+
x_max = mesh->pos.x - sinfo->collision_bounds.min_z;
343+
z_min = mesh->pos.z + sinfo->collision_bounds.min_x;
344+
z_max = mesh->pos.z + sinfo->collision_bounds.max_x;
345345
break;
346346

347347
default:
348-
x_min = mesh->x + sinfo->collision_bounds.min_x;
349-
x_max = mesh->x + sinfo->collision_bounds.max_x;
350-
z_min = mesh->z + sinfo->collision_bounds.min_z;
351-
z_max = mesh->z + sinfo->collision_bounds.max_z;
348+
x_min = mesh->pos.x + sinfo->collision_bounds.min_x;
349+
x_max = mesh->pos.x + sinfo->collision_bounds.max_x;
350+
z_min = mesh->pos.z + sinfo->collision_bounds.min_z;
351+
z_max = mesh->pos.z + sinfo->collision_bounds.max_z;
352352
break;
353353
}
354354

src/game/creature.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ void __cdecl Creature_AIInfo(ITEM *const item, AI_INFO *const info)
9292
const ROOM *const r = &g_Rooms[item->room_num];
9393
const int32_t z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT;
9494
const int32_t x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT;
95-
item->box_num = r->sector[z_sector + x_sector * r->z_size].box;
95+
item->box_num = r->sectors[z_sector + x_sector * r->size.z].box;
9696
info->zone_num = zone[item->box_num];
9797
}
9898

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

src/game/items.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void __cdecl Item_Initialise(const int16_t item_num)
154154

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

160160
if (g_SaveGame.bonus_flag && !g_IsDemoLevelType) {

src/game/lara/misc.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ void __cdecl Lara_BaddieCollision(ITEM *lara_item, COLL_INFO *coll)
10551055
if (roomies_count >= MAX_BADDIE_COLLISION) {
10561056
break;
10571057
}
1058-
roomies[roomies_count++] = portals->portal[i].room;
1058+
roomies[roomies_count++] = portals->portal[i].room_num;
10591059
}
10601060
}
10611061

@@ -1556,23 +1556,23 @@ int32_t __cdecl Lara_GetWaterDepth(
15561556
z_sector = 0;
15571557
if (x_sector < 1) {
15581558
x_sector = 1;
1559-
} else if (x_sector > r->x_size - 2) {
1560-
x_sector = r->x_size - 2;
1559+
} else if (x_sector > r->size.x - 2) {
1560+
x_sector = r->size.x - 2;
15611561
}
1562-
} else if (z_sector >= r->z_size - 1) {
1563-
z_sector = r->z_size - 1;
1562+
} else if (z_sector >= r->size.z - 1) {
1563+
z_sector = r->size.z - 1;
15641564
if (x_sector < 1) {
15651565
x_sector = 1;
1566-
} else if (x_sector > r->x_size - 2) {
1567-
x_sector = r->x_size - 2;
1566+
} else if (x_sector > r->size.x - 2) {
1567+
x_sector = r->size.x - 2;
15681568
}
15691569
} else if (x_sector < 0) {
15701570
x_sector = 0;
1571-
} else if (x_sector >= r->x_size) {
1572-
x_sector = r->x_size - 1;
1571+
} else if (x_sector >= r->size.x) {
1572+
x_sector = r->size.x - 1;
15731573
}
15741574

1575-
sector = &r->sector[z_sector + x_sector * r->z_size];
1575+
sector = &r->sectors[z_sector + x_sector * r->size.z];
15761576
const int16_t data = Room_GetDoor(sector);
15771577
if (data == NO_ROOM) {
15781578
break;
@@ -1591,7 +1591,7 @@ int32_t __cdecl Lara_GetWaterDepth(
15911591
}
15921592
const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT;
15931593
const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT;
1594-
sector = &r->sector[z_sector + x_sector * r->z_size];
1594+
sector = &r->sectors[z_sector + x_sector * r->size.z];
15951595
}
15961596
return 0x7FFF;
15971597
}
@@ -1605,7 +1605,7 @@ int32_t __cdecl Lara_GetWaterDepth(
16051605
}
16061606
const int32_t z_sector = (z - r->pos.z) >> WALL_SHIFT;
16071607
const int32_t x_sector = (x - r->pos.x) >> WALL_SHIFT;
1608-
sector = &r->sector[z_sector + x_sector * r->z_size];
1608+
sector = &r->sectors[z_sector + x_sector * r->size.z];
16091609
}
16101610
return NO_HEIGHT;
16111611
}
@@ -1713,7 +1713,7 @@ void __cdecl Lara_WaterCurrent(COLL_INFO *const coll)
17131713
const ROOM *const r = &g_Rooms[g_LaraItem->room_num];
17141714
const int32_t z_sector = (g_LaraItem->pos.z - r->pos.z) >> WALL_SHIFT;
17151715
const int32_t x_sector = (g_LaraItem->pos.x - r->pos.x) >> WALL_SHIFT;
1716-
g_LaraItem->box_num = r->sector[z_sector + x_sector * r->z_size].box;
1716+
g_LaraItem->box_num = r->sectors[z_sector + x_sector * r->size.z].box;
17171717

17181718
if (g_Lara.creature == NULL) {
17191719
g_Lara.current_active = 0;

src/game/level.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ static void __cdecl M_LoadRooms(VFILE *const file)
134134
VFile_Read(file, r->portals->portal, sizeof(PORTAL) * num_doors);
135135
}
136136

137-
r->z_size = VFile_ReadS16(file);
138-
r->x_size = VFile_ReadS16(file);
137+
r->size.z = VFile_ReadS16(file);
138+
r->size.x = VFile_ReadS16(file);
139139

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

152-
r->ambient1 = VFile_ReadS16(file);
153-
r->ambient2 = VFile_ReadS16(file);
152+
r->ambient_1 = VFile_ReadS16(file);
153+
r->ambient_2 = VFile_ReadS16(file);
154154
r->light_mode = VFile_ReadS16(file);
155155

156156
r->num_lights = VFile_ReadS16(file);
157157
if (!r->num_lights) {
158-
r->light = NULL;
158+
r->lights = NULL;
159159
} else {
160-
r->light =
160+
r->lights =
161161
game_malloc(sizeof(LIGHT) * r->num_lights, GBUF_ROOM_LIGHTS);
162162
for (int32_t i = 0; i < r->num_lights; i++) {
163-
LIGHT *const light = &r->light[i];
164-
light->x = VFile_ReadS32(file);
165-
light->y = VFile_ReadS32(file);
166-
light->z = VFile_ReadS32(file);
167-
light->intensity1 = VFile_ReadS16(file);
168-
light->intensity2 = VFile_ReadS16(file);
169-
light->falloff1 = VFile_ReadS32(file);
170-
light->falloff2 = VFile_ReadS32(file);
163+
LIGHT *const light = &r->lights[i];
164+
light->pos.x = VFile_ReadS32(file);
165+
light->pos.y = VFile_ReadS32(file);
166+
light->pos.z = VFile_ReadS32(file);
167+
light->intensity_1 = VFile_ReadS16(file);
168+
light->intensity_2 = VFile_ReadS16(file);
169+
light->falloff_1 = VFile_ReadS32(file);
170+
light->falloff_2 = VFile_ReadS32(file);
171171
}
172172
}
173173

174174
r->num_meshes = VFile_ReadS16(file);
175175
if (!r->num_meshes) {
176-
r->mesh = NULL;
176+
r->meshes = NULL;
177177
} else {
178-
r->mesh = game_malloc(
178+
r->meshes = game_malloc(
179179
sizeof(MESH) * r->num_meshes, GBUF_ROOM_STATIC_MESHES);
180180
for (int32_t i = 0; i < r->num_meshes; i++) {
181-
MESH *const mesh = &r->mesh[i];
182-
mesh->x = VFile_ReadS32(file);
183-
mesh->y = VFile_ReadS32(file);
184-
mesh->z = VFile_ReadS32(file);
185-
mesh->y_rot = VFile_ReadS16(file);
186-
mesh->shade1 = VFile_ReadS16(file);
187-
mesh->shade2 = VFile_ReadS16(file);
181+
MESH *const mesh = &r->meshes[i];
182+
mesh->pos.x = VFile_ReadS32(file);
183+
mesh->pos.y = VFile_ReadS32(file);
184+
mesh->pos.z = VFile_ReadS32(file);
185+
mesh->rot.y = VFile_ReadS16(file);
186+
mesh->shade_1 = VFile_ReadS16(file);
187+
mesh->shade_2 = VFile_ReadS16(file);
188188
mesh->static_num = VFile_ReadS16(file);
189189
}
190190
}
@@ -490,8 +490,8 @@ static void __cdecl M_LoadItems(VFILE *const file)
490490
item->pos.y = VFile_ReadS32(file);
491491
item->pos.z = VFile_ReadS32(file);
492492
item->rot.y = VFile_ReadS16(file);
493-
item->shade1 = VFile_ReadS16(file);
494-
item->shade2 = VFile_ReadS16(file);
493+
item->shade_1 = VFile_ReadS16(file);
494+
item->shade_2 = VFile_ReadS16(file);
495495
item->flags = VFile_ReadS16(file);
496496
if (item->object_id < 0 || item->object_id >= O_NUMBER_OF) {
497497
Shell_ExitSystemFmt(

src/game/lot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void __cdecl LOT_CreateZone(ITEM *const item)
189189
const ROOM *const r = &g_Rooms[item->room_num];
190190
const int32_t z_sector = (item->pos.z - r->pos.z) >> WALL_SHIFT;
191191
const int32_t x_sector = (item->pos.x - r->pos.x) >> WALL_SHIFT;
192-
item->box_num = r->sector[z_sector + x_sector * r->z_size].box;
192+
item->box_num = r->sectors[z_sector + x_sector * r->size.z].box;
193193

194194
int16_t zone_num = zone[item->box_num];
195195
int16_t flip_num = flip[item->box_num];

0 commit comments

Comments
 (0)