From 2f311e7ce65de007d0799b7baf249de97626dd11 Mon Sep 17 00:00:00 2001 From: coco875 Date: Tue, 22 Oct 2024 09:38:44 +0200 Subject: [PATCH] improve how asset are manage --- courses/all_course_offsets.h | 23 +++++---- courses/banshee_boardwalk/course_offsets.c | 3 +- courses/bowsers_castle/course_offsets.c | 3 +- courses/choco_mountain/course_offsets.c | 3 +- courses/courseTable.c | 3 ++ courses/courseTable.h | 2 + courses/kalimari_desert/course_offsets.c | 3 +- courses/luigi_raceway/course_offsets.c | 3 +- courses/mario_raceway/course_offsets.c | 3 +- courses/moo_moo_farm/course_offsets.c | 3 +- courses/royal_raceway/course_offsets.c | 3 +- courses/sherbet_land/course_offsets.c | 5 +- include/asset_types.h | 7 +++ include/config.h | 2 + include/macros.h | 22 ++++++++ include/objects.h | 7 +-- src/actors/falling_rock/update.inc.c | 13 +++-- src/code_80005FD0.c | 10 +--- src/racing/actors.c | 59 +++++++++++----------- src/racing/collision.c | 36 ++++++------- src/racing/math_util.c | 12 ++--- src/racing/memory.c | 22 ++++---- src/racing/render_courses.c | 6 +-- 23 files changed, 148 insertions(+), 105 deletions(-) create mode 100644 include/asset_types.h diff --git a/courses/all_course_offsets.h b/courses/all_course_offsets.h index dea700562a..bc510b30ae 100644 --- a/courses/all_course_offsets.h +++ b/courses/all_course_offsets.h @@ -2,18 +2,19 @@ #define ALL_COURSE_OFFSETS_H #include "course_offsets.h" +#include "asset_types.h" -extern Gfx* banshee_boardwalk_dls[]; -extern Gfx* bowsers_castle_dls[]; -extern Gfx* choco_mountain_dls[]; -extern Gfx* kalimari_desert_dls[]; -extern Gfx* luigi_raceway_dls[]; -extern Gfx* mario_raceway_dls[]; -extern Gfx* moo_moo_farm_dls[]; -extern Gfx* royal_raceway_dls[]; -extern Gfx* sherbet_land_dls[]; -extern Gfx* sherbet_land_dls_2[]; -extern Gfx* wario_stadium_dls[]; +extern GfxAsset banshee_boardwalk_dls[]; +extern GfxAsset bowsers_castle_dls[]; +extern GfxAsset choco_mountain_dls[]; +extern GfxAsset kalimari_desert_dls[]; +extern GfxAsset luigi_raceway_dls[]; +extern GfxAsset mario_raceway_dls[]; +extern GfxAsset moo_moo_farm_dls[]; +extern GfxAsset royal_raceway_dls[]; +extern GfxAsset sherbet_land_dls[]; +extern GfxAsset sherbet_land_dls_2[]; +extern GfxAsset wario_stadium_dls[]; extern Gfx toads_turnpike_dl_0[]; extern Gfx toads_turnpike_dl_1[]; diff --git a/courses/banshee_boardwalk/course_offsets.c b/courses/banshee_boardwalk/course_offsets.c index c30bf9ccb0..cdcf601ba4 100644 --- a/courses/banshee_boardwalk/course_offsets.c +++ b/courses/banshee_boardwalk/course_offsets.c @@ -3,6 +3,7 @@ #include "course_offsets.h" #include "courses/banshee_boardwalk/course_data.h" #include +#include "asset_types.h" extern u8 gTexture6447C4[]; extern u8 gTexture676FB0[]; @@ -53,7 +54,7 @@ const course_texture banshee_boardwalk_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* banshee_boardwalk_dls[] = { +const GfxAsset banshee_boardwalk_dls[] = { d_course_banshee_boardwalk_dl_A0, d_course_banshee_boardwalk_dl_210, d_course_banshee_boardwalk_dl_160, d_course_banshee_boardwalk_dl_270, d_course_banshee_boardwalk_dl_358, d_course_banshee_boardwalk_dl_4F0, d_course_banshee_boardwalk_dl_408, d_course_banshee_boardwalk_dl_540, d_course_banshee_boardwalk_dl_620, diff --git a/courses/bowsers_castle/course_offsets.c b/courses/bowsers_castle/course_offsets.c index 5e731badf6..72473cdb78 100644 --- a/courses/bowsers_castle/course_offsets.c +++ b/courses/bowsers_castle/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTexture64313C[]; extern u8 gTexture6528DC[]; @@ -63,7 +64,7 @@ const course_texture bowsers_castle_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* bowsers_castle_dls[] = { +const GfxAsset bowsers_castle_dls[] = { d_course_bowsers_castle_dl_0, d_course_bowsers_castle_dl_230, d_course_bowsers_castle_dl_110, d_course_bowsers_castle_dl_398, d_course_bowsers_castle_dl_428, d_course_bowsers_castle_dl_640, d_course_bowsers_castle_dl_4F0, d_course_bowsers_castle_dl_7A0, d_course_bowsers_castle_dl_860, diff --git a/courses/choco_mountain/course_offsets.c b/courses/choco_mountain/course_offsets.c index 74055cac94..d70a42c4c5 100644 --- a/courses/choco_mountain/course_offsets.c +++ b/courses/choco_mountain/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTexture64619C[]; extern u8 gTexture64647C[]; @@ -47,7 +48,7 @@ const course_texture choco_mountain_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* choco_mountain_dls[] = { +const GfxAsset choco_mountain_dls[] = { d_course_choco_mountain_dl_0, d_course_choco_mountain_dl_150, d_course_choco_mountain_dl_B0, d_course_choco_mountain_dl_208, d_course_choco_mountain_dl_2A8, d_course_choco_mountain_dl_410, d_course_choco_mountain_dl_330, d_course_choco_mountain_dl_4D8, d_course_choco_mountain_dl_588, diff --git a/courses/courseTable.c b/courses/courseTable.c index d9c2e680cf..c716df05e5 100644 --- a/courses/courseTable.c +++ b/courses/courseTable.c @@ -3,7 +3,9 @@ #include "courseTable.h" #include "all_course_model.h" #include "all_course_packed.h" +#include "config.h" +#if !ENABLE_CUSTOM_COURSE_ENGINE struct CourseTable gCourseTable[] = { { _course_mario_raceway_dl_mio0SegmentRomStart, _course_mario_raceway_dl_mio0SegmentRomEnd, @@ -304,3 +306,4 @@ struct CourseTable gCourseTable[] = { { 0, 0x0000, } }; +#endif diff --git a/courses/courseTable.h b/courses/courseTable.h index aad2cc39a4..ea7c64812d 100644 --- a/courses/courseTable.h +++ b/courses/courseTable.h @@ -21,7 +21,9 @@ struct CourseTable { u16 padding; // 0x2E }; +#if !ENABLE_CUSTOM_COURSE_ENGINE extern struct CourseTable gCourseTable[]; +#endif //! @todo These should probably be ptr's instead of array's? extern u8 _course_mario_raceway_dl_mio0SegmentRomStart[]; diff --git a/courses/kalimari_desert/course_offsets.c b/courses/kalimari_desert/course_offsets.c index adba118191..d3468d4c60 100644 --- a/courses/kalimari_desert/course_offsets.c +++ b/courses/kalimari_desert/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTexture6684F8[]; extern u8 gTextureSignLuigis0[]; @@ -44,7 +45,7 @@ const course_texture kalimari_desert_textures[] = { { gTextureSignKoopaAir1, 0x0304, 0x1000, 0x0 }, { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* kalimari_desert_dls[] = { +const GfxAsset kalimari_desert_dls[] = { d_course_kalimari_desert_dl_0, d_course_kalimari_desert_dl_258, d_course_kalimari_desert_dl_100, d_course_kalimari_desert_dl_310, d_course_kalimari_desert_dl_4A0, d_course_kalimari_desert_dl_778, d_course_kalimari_desert_dl_5C0, d_course_kalimari_desert_dl_858, d_course_kalimari_desert_dl_A58, diff --git a/courses/luigi_raceway/course_offsets.c b/courses/luigi_raceway/course_offsets.c index 5ba10b28e2..04793c4e9b 100644 --- a/courses/luigi_raceway/course_offsets.c +++ b/courses/luigi_raceway/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTextureSignShellShot0[]; extern u8 gTextureSignShellShot1[]; @@ -87,7 +88,7 @@ const course_texture luigi_raceway_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* luigi_raceway_dls[] = { +const GfxAsset luigi_raceway_dls[] = { d_course_luigi_raceway_dl_0, d_course_luigi_raceway_dl_328, d_course_luigi_raceway_dl_1A8, d_course_luigi_raceway_dl_480, d_course_luigi_raceway_dl_6E0, d_course_luigi_raceway_dl_9F8, d_course_luigi_raceway_dl_868, d_course_luigi_raceway_dl_B48, d_course_luigi_raceway_dl_D80, diff --git a/courses/mario_raceway/course_offsets.c b/courses/mario_raceway/course_offsets.c index 9c7f445ad3..4bf620b654 100644 --- a/courses/mario_raceway/course_offsets.c +++ b/courses/mario_raceway/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTextureCheckerboardYellowPink[]; extern u8 gTexture64619C[]; @@ -67,7 +68,7 @@ const course_texture mario_raceway_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* mario_raceway_dls[] = { +const GfxAsset mario_raceway_dls[] = { d_course_mario_raceway_dl_0, d_course_mario_raceway_dl_1D0, d_course_mario_raceway_dl_E8, d_course_mario_raceway_dl_2C8, d_course_mario_raceway_dl_3A8, d_course_mario_raceway_dl_568, d_course_mario_raceway_dl_478, d_course_mario_raceway_dl_668, d_course_mario_raceway_dl_750, diff --git a/courses/moo_moo_farm/course_offsets.c b/courses/moo_moo_farm/course_offsets.c index bd8293a9a8..648d169960 100644 --- a/courses/moo_moo_farm/course_offsets.c +++ b/courses/moo_moo_farm/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTextureWoodDoor0[]; extern u8 gTextureGrass2[]; @@ -63,7 +64,7 @@ const course_texture moo_moo_farm_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* moo_moo_farm_dls[] = { +const GfxAsset moo_moo_farm_dls[] = { d_course_moo_moo_farm_dl_88, d_course_moo_moo_farm_dl_598, d_course_moo_moo_farm_dl_338, d_course_moo_moo_farm_dl_8A0, d_course_moo_moo_farm_dl_B00, d_course_moo_moo_farm_dl_FE0, d_course_moo_moo_farm_dl_D70, d_course_moo_moo_farm_dl_12B8, d_course_moo_moo_farm_dl_1530, diff --git a/courses/royal_raceway/course_offsets.c b/courses/royal_raceway/course_offsets.c index 60c52f8c71..a303184ee3 100644 --- a/courses/royal_raceway/course_offsets.c +++ b/courses/royal_raceway/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTexture64619C[]; extern u8 gTexture645134[]; @@ -93,7 +94,7 @@ const course_texture royal_raceway_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* royal_raceway_dls[] = { +const GfxAsset royal_raceway_dls[] = { d_course_royal_raceway_dl_0, d_course_royal_raceway_dl_360, d_course_royal_raceway_dl_258, d_course_royal_raceway_dl_470, d_course_royal_raceway_dl_6D0, d_course_royal_raceway_dl_A48, d_course_royal_raceway_dl_8E0, d_course_royal_raceway_dl_B40, d_course_royal_raceway_dl_DA0, diff --git a/courses/sherbet_land/course_offsets.c b/courses/sherbet_land/course_offsets.c index b606a47ae6..fd9b2f5f73 100644 --- a/courses/sherbet_land/course_offsets.c +++ b/courses/sherbet_land/course_offsets.c @@ -1,6 +1,7 @@ #include #include "course_offsets.h" #include "course_data.h" +#include "asset_types.h" extern u8 gTexture643B3C[]; extern u8 gTexture66D024[]; @@ -22,7 +23,7 @@ const course_texture sherbet_land_textures[] = { { 0x00000000, 0x0000, 0x0000, 0x0 }, }; -const Gfx* sherbet_land_dls[] = { +const GfxAsset sherbet_land_dls[] = { d_course_sherbet_land_dl_0, d_course_sherbet_land_dl_158, d_course_sherbet_land_dl_C0, d_course_sherbet_land_dl_1A8, d_course_sherbet_land_dl_280, d_course_sherbet_land_dl_3B8, d_course_sherbet_land_dl_310, d_course_sherbet_land_dl_400, d_course_sherbet_land_dl_4E8, @@ -49,7 +50,7 @@ const Gfx* sherbet_land_dls[] = { d_course_sherbet_land_dl_25A0, d_course_sherbet_land_dl_2530, d_course_sherbet_land_dl_25F8, }; -const Gfx* sherbet_land_dls_2[] = { +const GfxAsset sherbet_land_dls_2[] = { d_course_sherbet_land_dl_26D0, d_course_sherbet_land_dl_28A0, d_course_sherbet_land_dl_27F0, d_course_sherbet_land_dl_2918, d_course_sherbet_land_dl_2A38, d_course_sherbet_land_dl_2BE0, d_course_sherbet_land_dl_2B08, d_course_sherbet_land_dl_2C58, d_course_sherbet_land_dl_2D78, diff --git a/include/asset_types.h b/include/asset_types.h new file mode 100644 index 0000000000..e9e0154299 --- /dev/null +++ b/include/asset_types.h @@ -0,0 +1,7 @@ +#if !ENABLE_CUSTOM_ASSET_TYPE +typedef Gfx* GfxAsset; +typedef u8* TextureAsset; +typedef u8* TextureAssetList; +#else + +#endif \ No newline at end of file diff --git a/include/config.h b/include/config.h index 85d1a89eb9..68e3dec26b 100644 --- a/include/config.h +++ b/include/config.h @@ -8,4 +8,6 @@ * */ #define ENABLE_CUSTOM_COURSE_ENGINE 0 + +#define ENABLE_CUSTOM_ASSET_TYPE 0 #endif diff --git a/include/macros.h b/include/macros.h index 9eec8230ba..fe87abb758 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,6 +1,8 @@ #ifndef _MACROS_H_ #define _MACROS_H_ +#include "config.h" + #ifndef __sgi #define GLOBAL_ASM(...) #endif @@ -92,6 +94,14 @@ // another way of converting virtual to physical #define VIRTUAL_TO_PHYSICAL2(addr) ((u8*) (addr) - 0x80000000U) +#if !ENABLE_CUSTOM_ASSET_TYPE +#define VIRTUAL_TO_PHYSICAL_ASSET(addr) \ + VIRTUAL_TO_PHYSICAL2(gSegmentTable[SEGMENT_NUMBER2(addr)] + SEGMENT_OFFSET(addr)) +#else +#define VIRTUAL_TO_PHYSICAL_ASSET(addr) + +#endif + // aligns an address to the next 16 bytes #define ALIGN16(val) (((val) + 0xF) & ~0xF) @@ -103,4 +113,16 @@ **/ #define GET_PACKED_END(dl) (((u8*) dl) + sizeof(dl) - sizeof(dl[0]) - 0x07000000) +#ifndef MAX +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#endif + +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + +#ifndef CLAMP +#define CLAMP(var, min, max) ((var) < (min) ? min : (var) > (max) ? max : var) +#endif + #endif diff --git a/include/objects.h b/include/objects.h index 9768adc8dd..3f522ce625 100644 --- a/include/objects.h +++ b/include/objects.h @@ -3,6 +3,7 @@ #include "spline.h" #include +#include "asset_types.h" #define OBJECT_LIST_SIZE 0x226 #define SOME_OBJECT_INDEX_LIST_SIZE 32 @@ -22,15 +23,15 @@ typedef struct { /* 0x54 */ s32 status; /* 0x58 */ s32 unk_058; /* 0x5C */ s32 unk_05C; - /* 0x60 */ u8* activeTLUT; - /* 0x64 */ u8* activeTexture; + /* 0x60 */ TextureAsset activeTLUT; + /* 0x64 */ TextureAsset activeTexture; /** * "list" is something of a misnomer for the names here * they can be pointers to just 1 tlut/texture, but it is common for one or the other * to be a pointer to an array of tluts/textures. **/ /* 0x68 */ u8* tlutList; // I feel like this should actually be `u8 (*tlutList)[512]`, but that causes mismatches - /* 0x6C */ u8* textureList; + /* 0x6C */ TextureAssetList textureList; /* 0x70 */ Gfx* model; /* 0x74 */ Vtx* vertex; /* 0x78 */ s8 unk_078[0x04]; diff --git a/src/actors/falling_rock/update.inc.c b/src/actors/falling_rock/update.inc.c index 6d37306695..02b3c2bbe0 100644 --- a/src/actors/falling_rock/update.inc.c +++ b/src/actors/falling_rock/update.inc.c @@ -4,9 +4,9 @@ #include "courses/choco_mountain/course_data.h" void func_8029CF0C(struct ActorSpawnData* spawnData, struct FallingRock* rock) { - s32 segment = SEGMENT_NUMBER2(spawnData); - s32 offset = SEGMENT_OFFSET(spawnData); - struct ActorSpawnData* temp_v0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED u32 unk; + UNUSED u32 unk2; + struct ActorSpawnData* temp_v0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(spawnData); Vec3s sp24 = { 60, 120, 180 }; temp_v0 += rock->unk_06; rock->respawnTimer = sp24[rock->unk_06]; // * 2 @@ -24,10 +24,9 @@ void func_8029CF0C(struct ActorSpawnData* spawnData, struct FallingRock* rock) { * @param spawnData */ void spawn_falling_rocks(struct ActorSpawnData* spawnData) { - s32 addr = SEGMENT_NUMBER2(spawnData); - s32 offset = SEGMENT_OFFSET(spawnData); - // Casting this to prevent warning does not work. - struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[addr] + offset); + UNUSED u32 unk; + UNUSED u32 unk1; + struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(spawnData); struct FallingRock* temp_v1; Vec3f startingPos; Vec3f startingVelocity; diff --git a/src/code_80005FD0.c b/src/code_80005FD0.c index 648a079f6e..693c2a5155 100644 --- a/src/code_80005FD0.c +++ b/src/code_80005FD0.c @@ -4345,9 +4345,7 @@ void func_80011EC0(s32 arg0, Player* player, s32 arg2, UNUSED u16 arg3) { void generate_train_waypoints(void) { s32 i; Path2D* temp; - TrackWaypoint* waypoint = - (TrackWaypoint*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[SEGMENT_NUMBER2(d_course_kalimari_desert_train_waypoints)] + - SEGMENT_OFFSET(d_course_kalimari_desert_train_waypoints)); + TrackWaypoint* waypoint = (TrackWaypoint*) VIRTUAL_TO_PHYSICAL_ASSET(d_course_kalimari_desert_train_waypoints); GET_PATH_LENGTH(waypoint) @@ -4357,13 +4355,9 @@ void generate_train_waypoints(void) { } void generate_ferry_waypoints(void) { - TrackWaypoint* waypoint; + TrackWaypoint* waypoint = (TrackWaypoint*) VIRTUAL_TO_PHYSICAL_ASSET(d_course_dks_jungle_parkway_ferry_waypoints); s32 i; - waypoint = (TrackWaypoint*) VIRTUAL_TO_PHYSICAL2( - gSegmentTable[SEGMENT_NUMBER2(d_course_dks_jungle_parkway_ferry_waypoints)] + - (SEGMENT_OFFSET(d_course_dks_jungle_parkway_ferry_waypoints))); - GET_PATH_LENGTH(waypoint) gVehicle2DWaypointLength = generate_2d_path(gVehicle2DWaypoint, waypoint, i - 1); diff --git a/src/racing/actors.c b/src/racing/actors.c index e602490239..6ba0942546 100644 --- a/src/racing/actors.c +++ b/src/racing/actors.c @@ -401,8 +401,7 @@ void func_802977E4(Player* arg0) { // Invert green and red on green shell texture void init_red_shell_texture(void) { s16* red_shell_texture = (s16*) &gTLUTRedShell[0]; - s16* green_shell_texture = (s16*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[SEGMENT_NUMBER2(common_tlut_green_shell)] + - SEGMENT_OFFSET(common_tlut_green_shell)); + s16* green_shell_texture = (s16*) VIRTUAL_TO_PHYSICAL_ASSET(common_tlut_green_shell); s16 color_pixel, red_color, green_color, blue_color, alpha_color; s32 i; for (i = 0; i < 256; i++) { @@ -475,10 +474,9 @@ void render_cows(Camera* camera, Mat4 arg1, UNUSED struct Actor* actor) { struct ActorSpawnData* var_s5; Vec3f sp88; u32 soundThing = SOUND_ARG_LOAD(0x19, 0x01, 0x90, 0x4D); - s32 segment = SEGMENT_NUMBER2(d_course_moo_moo_farm_cow_spawn); - s32 offset = SEGMENT_OFFSET(d_course_moo_moo_farm_cow_spawn); - - var_t1 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED u32 unk; + UNUSED u32 unk2; + var_t1 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(d_course_moo_moo_farm_cow_spawn); D_8015F704 = 6.4e7f; gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON); gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA); @@ -544,9 +542,10 @@ void render_cows(Camera* camera, Mat4 arg1, UNUSED struct Actor* actor) { void evaluate_collision_player_palm_trees(Player* player) { Vec3f pos; - s32 segment = SEGMENT_NUMBER2(d_course_dks_jungle_parkway_tree_spawn); - s32 offset = SEGMENT_OFFSET(d_course_dks_jungle_parkway_tree_spawn); - struct UnkActorSpawnData* data = (struct UnkActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED s32 segment; + UNUSED s32 offset; + struct UnkActorSpawnData* data = + (struct UnkActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(d_course_dks_jungle_parkway_tree_spawn); while (data->pos[0] != END_OF_SPAWN_DATA) { pos[0] = data->pos[0] * gCourseDirection; @@ -580,10 +579,10 @@ void evaluate_collision_players_palm_trees(void) { } void func_80298D10(void) { - s32 segment = SEGMENT_NUMBER2(d_course_dks_jungle_parkway_tree_spawn); - s32 offset = SEGMENT_OFFSET(d_course_dks_jungle_parkway_tree_spawn); + UNUSED s32 segment; + UNUSED s32 offset = SEGMENT_OFFSET(d_course_dks_jungle_parkway_tree_spawn); struct UnkActorSpawnData* temp_v1 = - (struct UnkActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + (struct UnkActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(d_course_dks_jungle_parkway_tree_spawn); while (temp_v1->pos[0] != END_OF_SPAWN_DATA) { temp_v1->pos[1] = temp_v1->unk8; @@ -593,10 +592,10 @@ void func_80298D10(void) { } void render_palm_trees(Camera* camera, Mat4 arg1, UNUSED struct Actor* actor) { - s32 segment = SEGMENT_NUMBER2(d_course_dks_jungle_parkway_tree_spawn); - s32 offset = SEGMENT_OFFSET(d_course_dks_jungle_parkway_tree_spawn); + UNUSED s32 segment; + UNUSED s32 offset; struct UnkActorSpawnData* var_s1 = - (struct UnkActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + (struct UnkActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(d_course_dks_jungle_parkway_tree_spawn); UNUSED s32 pad; Vec3f spD4; f32 var_f22; @@ -814,9 +813,9 @@ UNUSED void func_8029AE14() { #include "actors/falling_rock/render.inc.c" void spawn_piranha_plants(struct ActorSpawnData* spawnData) { - s32 segment = SEGMENT_NUMBER2(spawnData); - s32 offset = SEGMENT_OFFSET(spawnData); - struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED s32 segment; + UNUSED s32 offset; + struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(spawnData); struct PiranhaPlant* temp_v1; UNUSED s32 pad; Vec3f startingPos; @@ -846,9 +845,9 @@ void spawn_piranha_plants(struct ActorSpawnData* spawnData) { } void spawn_palm_trees(struct ActorSpawnData* spawnData) { - s32 segment = SEGMENT_NUMBER2(spawnData); - s32 offset = SEGMENT_OFFSET(spawnData); - struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED s32 segment; + UNUSED s32 offset; + struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(spawnData); struct PalmTree* temp_v1; Vec3f startingPos; Vec3f startingVelocity; @@ -884,10 +883,10 @@ void spawn_foliage(struct ActorSpawnData* arg0) { s16 actorType; struct Actor* temp_s0; struct ActorSpawnData* var_s3; - s32 segment = SEGMENT_NUMBER2(arg0); - s32 offset = SEGMENT_OFFSET(arg0); + UNUSED s32 segment; + UNUSED s32 offset; - var_s3 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + var_s3 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(arg0); vec3f_set(velocity, 0.0f, 0.0f, 0.0f); rotation[0] = 0x4000; rotation[1] = 0; @@ -958,14 +957,14 @@ void spawn_foliage(struct ActorSpawnData* arg0) { } void spawn_all_item_boxes(struct ActorSpawnData* spawnData) { - s32 segment = SEGMENT_NUMBER2(spawnData); - s32 offset = SEGMENT_OFFSET(spawnData); + UNUSED s32 segment; + UNUSED s32 offset; s16 temp_s1; f32 temp_f0; Vec3f startingPos; Vec3f startingVelocity; Vec3s startingRot; - struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + struct ActorSpawnData* temp_s0 = (struct ActorSpawnData*) VIRTUAL_TO_PHYSICAL_ASSET(spawnData); // struct ItemBox *itemBox; if ((gModeSelection == TIME_TRIALS) || (gPlaceItemBoxes == 0)) { @@ -1478,10 +1477,10 @@ struct test { UNUSED void prototype_actor_spawn_data(Player* player, uintptr_t arg1) { Vec3f sp64; struct test* var_s0; - s32 segment = SEGMENT_NUMBER2(arg1); - s32 offset = SEGMENT_OFFSET(arg1); + UNUSED s32 segment; + UNUSED s32 offset; - var_s0 = (struct test*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + var_s0 = (struct test*) VIRTUAL_TO_PHYSICAL_ASSET(arg1); while (var_s0->thing[0] != END_OF_SPAWN_DATA) { sp64[0] = var_s0->thing[0] * gCourseDirection; sp64[1] = var_s0->thing[1]; diff --git a/src/racing/collision.c b/src/racing/collision.c index 5aa7133ad6..eab90a4955 100644 --- a/src/racing/collision.c +++ b/src/racing/collision.c @@ -17,12 +17,12 @@ // Used to delete the choco mountain guard rail void nullify_displaylist(uintptr_t addr) { - s32 segment = SEGMENT_NUMBER2(addr); - s32 offset = SEGMENT_OFFSET(addr); + UNUSED u32 segment; + UNUSED s32 offset; Gfx* macro; - macro = (Gfx*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + macro = (Gfx*) VIRTUAL_TO_PHYSICAL_ASSET(addr); macro->words.w0 = (G_ENDDL << 24); macro->words.w1 = 0; } @@ -1813,9 +1813,9 @@ void set_vtx_from_quadrangle(u32 line, s8 surfaceType, u16 sectionId) { */ void set_vtx_buffer(uintptr_t addr, u32 numVertices, u32 bufferIndex) { u32 i; - u32 segment = SEGMENT_NUMBER2(addr); - u32 offset = SEGMENT_OFFSET(addr); - Vtx* vtx = (Vtx*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED u32 segment; + UNUSED u32 offset; + Vtx* vtx = (Vtx*) VIRTUAL_TO_PHYSICAL_ASSET(addr); for (i = 0; i < numVertices; i++) { vtxBuffer[bufferIndex] = vtx; vtx++; @@ -2026,9 +2026,9 @@ void generate_collision_mesh(Gfx* addr, s8 surfaceType, u16 sectionId) { uintptr_t hi; s32 i; - s32 segment = SEGMENT_NUMBER2(addr); - s32 offset = SEGMENT_OFFSET(addr); - Gfx* gfx = (Gfx*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED s32 segment; + UNUSED s32 offset; + Gfx* gfx = (Gfx*) VIRTUAL_TO_PHYSICAL_ASSET(addr); D_8015F6FA = 0; D_8015F6FC = 0; @@ -2068,9 +2068,9 @@ void generate_collision_mesh(Gfx* addr, s8 surfaceType, u16 sectionId) { * Search for G_SETTILESIZE and set its args. */ void find_and_set_tile_size(uintptr_t addr, s32 uls, s32 ult) { - u32 segment = SEGMENT_NUMBER2(addr); - u32 offset = SEGMENT_OFFSET(addr); - Gfx* gfx = (Gfx*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED u32 segment; + UNUSED u32 offset; + Gfx* gfx = (Gfx*) VIRTUAL_TO_PHYSICAL_ASSET(addr); u32 opcode; uls = (uls << 12) & 0xFFF000; @@ -2092,10 +2092,10 @@ void find_and_set_tile_size(uintptr_t addr, s32 uls, s32 ult) { } void set_vertex_colours(uintptr_t addr, u32 vertexCount, UNUSED s32 vert3, s8 alpha, u8 red, u8 green, u8 blue) { - s32 segment = SEGMENT_NUMBER2(addr); - s32 offset = SEGMENT_OFFSET(addr); + UNUSED s32 segment; + UNUSED s32 offset; s32 i; - Vtx* vtx = (Vtx*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + Vtx* vtx = (Vtx*) VIRTUAL_TO_PHYSICAL_ASSET(addr); for (i = 0; (u32) i < vertexCount; i++) { if (red) { @@ -2112,9 +2112,9 @@ void set_vertex_colours(uintptr_t addr, u32 vertexCount, UNUSED s32 vert3, s8 al * Recursive search for vertices and set their colour values. */ void find_vtx_and_set_colours(uintptr_t displayList, s8 alpha, u8 red, u8 green, u8 blue) { - s32 segment = SEGMENT_NUMBER2(displayList); - s32 offset = SEGMENT_OFFSET(displayList); - Gfx* gfx = (Gfx*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED s32 segment; + UNUSED s32 offset; + Gfx* gfx = (Gfx*) VIRTUAL_TO_PHYSICAL_ASSET(displayList); uintptr_t lo; uintptr_t hi; s32 opcode; diff --git a/src/racing/math_util.c b/src/racing/math_util.c index fb2770e3f9..33d1ab8104 100644 --- a/src/racing/math_util.c +++ b/src/racing/math_util.c @@ -433,8 +433,8 @@ void func_802B5D30(s16 arg0, s16 arg1, s32 arg2) { * @param arg3 */ void set_course_lighting(Lights1* addr, s16 arg1, s16 arg2, s32 arg3) { - u32 segment = SEGMENT_NUMBER2(addr); - u32 offset = SEGMENT_OFFSET(addr); + UNUSED u32 segment; + UNUSED u32 offset; UNUSED s32 pad; f32 sp48; f32 sp44; @@ -445,7 +445,7 @@ void set_course_lighting(Lights1* addr, s16 arg1, s16 arg2, s32 arg3) { s8 sp2C[3]; Lights1* var_s0; - var_s0 = (Lights1*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + var_s0 = (Lights1*) VIRTUAL_TO_PHYSICAL_ASSET(addr); sp48 = sins(arg2); sp44 = coss(arg2); sp40 = sins(arg1); @@ -1186,8 +1186,8 @@ f32 is_within_render_distance(Vec3f cameraPos, Vec3f objectPos, u16 orientationY // No idea if arg1 is actually a Mat4 or not, but since this function is unused // its impossible to know with certainty either way, very close of set_course_lighting UNUSED void func_802B8414(uintptr_t addr, Mat4 arg1, s16 arg2, s16 arg3, s32 arg4) { - u32 segment = SEGMENT_NUMBER2(addr); - u32 offset = SEGMENT_OFFSET(addr); + UNUSED u32 segment; + UNUSED u32 offset; UNUSED s32 pad; Vec3f sp40; s8 sp3C[3]; @@ -1195,7 +1195,7 @@ UNUSED void func_802B8414(uintptr_t addr, Mat4 arg1, s16 arg2, s16 arg3, s32 arg UNUSED s32 pad2[3]; Lights1* var_s0; - var_s0 = (Lights1*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + var_s0 = (Lights1*) VIRTUAL_TO_PHYSICAL_ASSET(addr); sins(arg3); coss(arg3); sins(arg2); diff --git a/src/racing/memory.c b/src/racing/memory.c index bdccfd84f1..5294b44b20 100644 --- a/src/racing/memory.c +++ b/src/racing/memory.c @@ -459,10 +459,10 @@ void func_802A86A8(CourseVtx* data, u32 arg1) { void decompress_vtx(CourseVtx* arg0, u32 vertexCount) { s32 size = ALIGN16(vertexCount * 0x18); - u32 segment = SEGMENT_NUMBER2(arg0); - u32 offset = SEGMENT_OFFSET(arg0); + UNUSED u32 segment; + UNUSED u32 offset; void* freeSpace; - u8* vtxCompressed = VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + u8* vtxCompressed = VIRTUAL_TO_PHYSICAL_ASSET(arg0); UNUSED s32 pad; freeSpace = (void*) gNextFreeMemoryAddress; @@ -961,9 +961,9 @@ UNUSED void func_802A9AEC(void) { * increments the file pointer the correct number of times. */ void displaylist_unpack(uintptr_t* data, uintptr_t finalDisplaylistOffset, u32 arg2) { - uintptr_t segment = SEGMENT_NUMBER2(data); - uintptr_t offset = SEGMENT_OFFSET(data); - u8* packed_dl = VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED uintptr_t segment; + UNUSED uintptr_t offset; + u8* packed_dl = VIRTUAL_TO_PHYSICAL_ASSET(data); Gfx* gfx; u32 addr; @@ -1265,9 +1265,9 @@ struct UnkStr_802AA7C8 { }; void decompress_textures(u32* arg0) { - u32 segment = SEGMENT_NUMBER2(arg0); - u32 offset = SEGMENT_OFFSET(arg0); - struct UnkStr_802AA7C8* phi_s0 = (struct UnkStr_802AA7C8*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED u32 segment; + UNUSED u32 offset; + struct UnkStr_802AA7C8* phi_s0 = (struct UnkStr_802AA7C8*) VIRTUAL_TO_PHYSICAL_ASSET(arg0); struct UnkStr_802AA7C8* temp_s0; uintptr_t temp_t2; u8* temp_a0; @@ -1324,6 +1324,7 @@ void* decompress_segments(u8* start, u8* end) { * @param courseId */ u8* load_course(s32 courseId) { +#if !ENABLE_CUSTOM_COURSE_ENGINE UNUSED s32 pad[4]; u8* vtxCompressed; // mio0 compressed u8* courseDataRomStart; // mio0 compressed @@ -1375,4 +1376,7 @@ u8* load_course(s32 courseId) { decompress_textures(textures); gNextFreeMemoryAddress = prevLoadedAddress_saved; return vtxCompressed; +#else + +#endif } diff --git a/src/racing/render_courses.c b/src/racing/render_courses.c index 4cb202acb8..c6fc363caf 100644 --- a/src/racing/render_courses.c +++ b/src/racing/render_courses.c @@ -44,9 +44,9 @@ s32 func_80290C20(Camera* camera) { } void parse_course_displaylists(uintptr_t addr) { - s32 segment = SEGMENT_NUMBER2(addr); - s32 offset = SEGMENT_OFFSET(addr); - TrackSections* section = (TrackSections*) VIRTUAL_TO_PHYSICAL2(gSegmentTable[segment] + offset); + UNUSED s32 segment; + UNUSED s32 offset; + TrackSections* section = (TrackSections*) VIRTUAL_TO_PHYSICAL_ASSET(addr); while (section->addr != 0) { if (section->flags & 0x8000) {