Remove struct size literals in geo traversal code

This commit is contained in:
Ryan Dwyer 2024-08-20 23:18:14 +10:00
parent 54b681798e
commit 66adbfb179
3 changed files with 44 additions and 34 deletions

View File

@ -35,19 +35,24 @@ void stage_parse_tiles(void)
while (geo < end) {
if (geo->type == GEOTYPE_TILE_I) {
struct geotilei *tile = (struct geotilei *) geo;
tile->xmin = mult6(tile->xmin) + 14;
tile->xmax = mult6(tile->xmax) + 14;
tile->ymin = mult6(tile->ymin) + 16;
tile->ymax = mult6(tile->ymax) + 16;
tile->zmin = mult6(tile->zmin) + 18;
tile->zmax = mult6(tile->zmax) + 18;
geo = (struct geo *)((u8 *)geo + (uintptr_t)(geo->numvertices - 0x40) * 6 + 0x18e);
tile->xmin = 14 + mult6(tile->xmin);
tile->xmax = 14 + mult6(tile->xmax);
tile->ymin = 16 + mult6(tile->ymin);
tile->ymax = 16 + mult6(tile->ymax);
tile->zmin = 18 + mult6(tile->zmin);
tile->zmax = 18 + mult6(tile->zmax);
geo = (struct geo *) ((u8 *) geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
geo = (struct geo *)((u8 *)geo + (uintptr_t)(geo->numvertices - 0x40) * 12 + 0x310);
struct geotilef *tile = (struct geotilef *) geo;
geo = (struct geo *) ((u8 *) geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
geo = (struct geo *)((u8 *)geo + sizeof(struct geoblock));
struct geoblock *block = (struct geoblock *) geo;
geo = (struct geo *) ((u8 *) geo + GEOBLOCK_SIZE(geo));
} else if (geo->type == GEOTYPE_CYL) {
geo = (struct geo *)((u8 *)geo + sizeof(struct geocyl));
struct geocyl *cyl = (struct geocyl *) geo;
geo = (struct geo *) ((u8 *) geo + GEOCYL_SIZE(cyl));
}
}
}

View File

@ -1198,6 +1198,11 @@
#define GEOFLAG_DIE 0x4000
#define GEOFLAG_LADDER_PLAYERONLY 0x8000 // Used for most ledges in Chicago, but not near drain pickup
#define GEOTILEI_SIZE(geo) (sizeof(struct geotilei) + (geo->header.numvertices - ARRAYCOUNT(geo->vertices)) * sizeof(geo->vertices[0]))
#define GEOTILEF_SIZE(geo) (sizeof(struct geotilef) + (geo->header.numvertices - ARRAYCOUNT(geo->vertices)) * sizeof(geo->vertices[0]))
#define GEOBLOCK_SIZE(geo) sizeof(struct geoblock)
#define GEOCYL_SIZE(geo) sizeof(struct geocyl)
#define GEOTYPE_TILE_I 0 // Tiles with integer vertices - used for BG
#define GEOTYPE_TILE_F 1 // Tiles with float vertices - used for lifts
#define GEOTYPE_BLOCK 2 // Most objects - multiple x/z vertices, and a single ymin and ymax

View File

@ -1197,7 +1197,7 @@ void cd_collect_geo_for_cyl_from_list(struct coord *pos, f32 radius, u8 *start,
}
}
geo = (struct geo *)((uintptr_t)geo + tile->header.numvertices * 6 + 0xe);
geo = (struct geo *)((uintptr_t)geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
struct geotilef *tile = (struct geotilef *) geo;
@ -1220,7 +1220,7 @@ void cd_collect_geo_for_cyl_from_list(struct coord *pos, f32 radius, u8 *start,
}
}
geo = (struct geo *)((uintptr_t)geo + (tile->header.numvertices - 0x40) * sizeof(struct coord) + 0x310);
geo = (struct geo *)((uintptr_t)geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
struct geoblock *block = (struct geoblock *) geo;
@ -1238,7 +1238,7 @@ void cd_collect_geo_for_cyl_from_list(struct coord *pos, f32 radius, u8 *start,
}
}
geo = (struct geo *)((uintptr_t)geo + 0x4c);
geo = (struct geo *)((uintptr_t)geo + GEOBLOCK_SIZE(block));
} else if (geo->type == GEOTYPE_CYL) {
struct geocyl *cyl = (struct geocyl *) geo;
@ -1256,7 +1256,7 @@ void cd_collect_geo_for_cyl_from_list(struct coord *pos, f32 radius, u8 *start,
}
}
geo = (struct geo *)((uintptr_t)geo + 0x18);
geo = (struct geo *)((uintptr_t)geo + GEOCYL_SIZE(cyl));
}
}
}
@ -1552,7 +1552,7 @@ void cd_collect_geo_for_cyl_move_from_list(u8 *start, u8 *end, struct coord *pos
}
}
geo = (struct geo *)((uintptr_t)geo + tile->header.numvertices * 6 + 0xe);
geo = (struct geo *)((uintptr_t)geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
struct geotilef *tile = (struct geotilef *) geo;
@ -1566,7 +1566,7 @@ void cd_collect_geo_for_cyl_move_from_list(u8 *start, u8 *end, struct coord *pos
cd_0002840c(tile, pos->x, pos->z, radius, prop, collisions, maxcollisions, numcollisions);
}
geo = (struct geo *)((uintptr_t)geo + (uintptr_t)(tile->header.numvertices - 0x40) * 0xc + 0x310);
geo = (struct geo *)((uintptr_t)geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
struct geoblock *block = (struct geoblock *) geo;
@ -1575,7 +1575,7 @@ void cd_collect_geo_for_cyl_move_from_list(u8 *start, u8 *end, struct coord *pos
cd_00028638(block, pos->x, pos->z, radius, prop, collisions, maxcollisions, numcollisions);
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geoblock));
geo = (struct geo *)((uintptr_t)geo + GEOBLOCK_SIZE(block));
} else if (geo->type == GEOTYPE_CYL) {
struct geocyl *cyl = (struct geocyl *) geo;
@ -1584,7 +1584,7 @@ void cd_collect_geo_for_cyl_move_from_list(u8 *start, u8 *end, struct coord *pos
cd_0002885c(cyl, pos->x, pos->z, radius, prop, collisions, maxcollisions, numcollisions);
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geocyl));
geo = (struct geo *)((uintptr_t)geo + GEOCYL_SIZE(cyl));
}
}
}
@ -2913,7 +2913,7 @@ bool cd_test_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
}
}
geo = (struct geo *)((uintptr_t)geo + tile->header.numvertices * 6 + 0xe);
geo = (struct geo *)((uintptr_t)geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
struct geotilef *tile = (struct geotilef *) geo;
struct coord min;
@ -2947,7 +2947,7 @@ bool cd_test_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
}
}
geo = (struct geo *)((uintptr_t)geo + (uintptr_t)(tile->header.numvertices - 0x40) * 0xc + 0x310);
geo = (struct geo *)((uintptr_t)geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
struct coord sp78;
struct geoblock *block = (struct geoblock *) geo;
@ -2957,7 +2957,7 @@ bool cd_test_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
return false;
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geoblock));
geo = (struct geo *)((uintptr_t)geo + GEOBLOCK_SIZE(block));
} else if (geo->type == GEOTYPE_CYL) {
struct coord sp68;
struct geocyl *cyl = (struct geocyl *) geo;
@ -2967,7 +2967,7 @@ bool cd_test_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
return false;
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geocyl));
geo = (struct geo *)((uintptr_t)geo + GEOCYL_SIZE(cyl));
}
}
@ -3184,7 +3184,7 @@ bool cd_exam_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
}
}
geo = (struct geo *)((uintptr_t)geo + (uintptr_t)(tile->header.numvertices * 6) + 0xe);
geo = (struct geo *)((uintptr_t)geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
struct geotilef *tile = (struct geotilef *) geo;
struct coord min;
@ -3260,7 +3260,7 @@ bool cd_exam_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
}
}
geo = (struct geo *)((uintptr_t)geo + (uintptr_t)(tile->header.numvertices - 0x40) * 0xc + 0x310);
geo = (struct geo *)((uintptr_t)geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
struct coord spb0;
struct coord spa4;
@ -3294,7 +3294,7 @@ bool cd_exam_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
}
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geoblock));
geo = (struct geo *)((uintptr_t)geo + GEOBLOCK_SIZE(geo));
} else if (geo->type == GEOTYPE_CYL) {
struct geocyl *cyl = (struct geocyl *) geo;
struct coord sp88;
@ -3329,7 +3329,7 @@ bool cd_exam_a_to_b_geolist(u8 *start, u8 *end, struct coord *arg2, struct coord
}
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geocyl));
geo = (struct geo *)((uintptr_t)geo + GEOCYL_SIZE(cyl));
}
}
@ -3750,10 +3750,10 @@ s32 cd_test_block_overlaps_geolist(u8 *start, u8 *end, struct geoblock *block, u
while (geo < (struct geo *) end) {
if (geo->type == GEOTYPE_TILE_I) {
struct geotilei *tile = (struct geotilei *) geo;
geo = (struct geo *)((uintptr_t)geo + tile->header.numvertices * 6 + 0xe);
geo = (struct geo *)((uintptr_t)geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
struct geotilef *tile = (struct geotilef *) geo;
geo = (struct geo *)((uintptr_t)geo + tile->header.numvertices * 0xc + 0x10);
geo = (struct geo *)((uintptr_t)geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
struct geoblock *thisblock = (struct geoblock *) geo;
@ -3782,7 +3782,7 @@ s32 cd_test_block_overlaps_geolist(u8 *start, u8 *end, struct geoblock *block, u
}
}
geo = (struct geo *)((uintptr_t)geo + 0x4c);
geo = (struct geo *)((uintptr_t)geo + GEOBLOCK_SIZE(thisblock));
} else if (geo->type == GEOTYPE_CYL) {
struct geocyl *cyl = (struct geocyl *) geo;
@ -3793,7 +3793,7 @@ s32 cd_test_block_overlaps_geolist(u8 *start, u8 *end, struct geoblock *block, u
return CDRESULT_COLLISION;
}
geo = (struct geo *)((uintptr_t)geo + 0x18);
geo = (struct geo *)((uintptr_t)geo + GEOCYL_SIZE(cyl));
}
}
@ -4024,7 +4024,7 @@ bool cd_0002ed30(u8 *start, u8 *end, struct geoblock *block, s32 numvertices, st
return false;
}
geo = (struct geo *)((uintptr_t)geo + tile->header.numvertices * 6 + 0xe);
geo = (struct geo *)((uintptr_t)geo + GEOTILEI_SIZE(tile));
} else if (geo->type == GEOTYPE_TILE_F) {
struct geotilef *tile = (struct geotilef *)geo;
@ -4035,7 +4035,7 @@ bool cd_0002ed30(u8 *start, u8 *end, struct geoblock *block, s32 numvertices, st
return false;
}
geo = (struct geo *)((uintptr_t)geo + (uintptr_t)(tile->header.numvertices - 0x40) * 0xc + 0x310);
geo = (struct geo *)((uintptr_t)geo + GEOTILEF_SIZE(tile));
} else if (geo->type == GEOTYPE_BLOCK) {
struct geoblock *block2 = (struct geoblock *)geo;
@ -4046,7 +4046,7 @@ bool cd_0002ed30(u8 *start, u8 *end, struct geoblock *block, s32 numvertices, st
return false;
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geoblock));
geo = (struct geo *)((uintptr_t)geo + GEOBLOCK_SIZE(block2));
} else if (geo->type == GEOTYPE_CYL) {
struct geocyl *cyl = (struct geocyl *)geo;
@ -4057,7 +4057,7 @@ bool cd_0002ed30(u8 *start, u8 *end, struct geoblock *block, s32 numvertices, st
return false;
}
geo = (struct geo *)((uintptr_t)geo + sizeof(struct geocyl));
geo = (struct geo *)((uintptr_t)geo + GEOCYL_SIZE(cyl));
}
}