From 2da776c9c00eb715f5954fc6d920f7725f4b27af Mon Sep 17 00:00:00 2001 From: someone2639 Date: Thu, 27 May 2021 00:15:06 -0400 Subject: [PATCH] s32 model ID to make the code cleaner --- include/level_commands.h | 11 ++++++----- include/types.h | 2 +- src/engine/level_script.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/level_commands.h b/include/level_commands.h index 1772a62b..a4dcabda 100644 --- a/include/level_commands.h +++ b/include/level_commands.h @@ -215,12 +215,13 @@ CMD_HH(layer, model) #define LOAD_MODEL_FROM_GEO(model, geo) \ - CMD_BBH(0x22, 0x08, model), \ - CMD_PTR(geo) + CMD_BBH(0x22, 0x0C, 0), \ + CMD_PTR(geo), \ + CMD_W(model) // unk8 is float, but doesn't really matter since CMD23 is unused #define CMD23(model, unk4, unk8) \ - CMD_BBH(0x22, 0x08, model), \ + CMD_BBH(0x22, 0x08, 0), \ CMD_PTR(unk4), \ CMD_W(unk8) @@ -229,7 +230,7 @@ CMD_HHHHHH(posX, posY, posZ, angleX, angleY, angleZ), \ CMD_W(behParam), \ CMD_PTR(beh), \ - CMD_HH(0, model) + CMD_W(model) #define OBJECT(model, posX, posY, posZ, angleX, angleY, angleZ, behParam, beh) \ OBJECT_WITH_ACTS(model, posX, posY, posZ, angleX, angleY, angleZ, behParam, beh, 0x1F) @@ -238,7 +239,7 @@ CMD_BBH(0x25, 0x10, 0), \ CMD_W(behArg), \ CMD_PTR(beh), \ - CMD_HH(0, model) + CMD_W(model) #define WARP_NODE(id, destLevel, destArea, destNode, flags) \ CMD_BBBB(0x26, 0x08, id, destLevel), \ diff --git a/include/types.h b/include/types.h index 475655cf..6e62e8c2 100644 --- a/include/types.h +++ b/include/types.h @@ -54,7 +54,7 @@ typedef s16 Trajectory; typedef s16 PaintingData; typedef uintptr_t BehaviorScript; typedef u8 Texture; -typedef u16 ModelID; +typedef s32 ModelID; enum SpTaskState { SPTASK_STATE_NOT_STARTED, diff --git a/src/engine/level_script.c b/src/engine/level_script.c index daeff54c..8ee3cc0c 100644 --- a/src/engine/level_script.c +++ b/src/engine/level_script.c @@ -379,7 +379,7 @@ static void level_cmd_load_model_from_dl(void) { s16 layer = CMD_GET(u16, 0x8); void *dl_ptr = CMD_GET(void *, 4); - if (model < 65536) { + if (model < ARRAY_COUNT(gLoadedGraphNodes)) { gLoadedGraphNodes[model] = (struct GraphNode *) init_graph_node_display_list(sLevelPool, 0, layer, dl_ptr); } @@ -388,11 +388,11 @@ static void level_cmd_load_model_from_dl(void) { } static void level_cmd_load_model_from_geo(void) { - ModelID arg0 = CMD_GET(ModelID, 2); - void *arg1 = CMD_GET(void *, 4); + ModelID model = CMD_GET(ModelID, 8); + void *geo = CMD_GET(void *, 4); - if (arg0 < 65536) { - gLoadedGraphNodes[arg0] = process_geo_layout(sLevelPool, arg1); + if (model < ARRAY_COUNT(gLoadedGraphNodes)) { + gLoadedGraphNodes[model] = process_geo_layout(sLevelPool, geo); } sCurrentCmd = CMD_NEXT; @@ -410,7 +410,7 @@ static void level_cmd_23(void) { // load an f32, but using an integer load instruction for some reason (hence the union) arg2.i = CMD_GET(s32, 8); - if (model < 65536) { + if (model < ARRAY_COUNT(gLoadedGraphNodes)) { // GraphNodeScale has a GraphNode at the top. This // is being stored to the array, so cast the pointer. gLoadedGraphNodes[model] = @@ -428,7 +428,7 @@ static void level_cmd_init_mario(void) { gMarioSpawnInfo->areaIndex = 0; gMarioSpawnInfo->behaviorArg = CMD_GET(u32, 4); gMarioSpawnInfo->behaviorScript = CMD_GET(void *, 8); - gMarioSpawnInfo->unk18 = gLoadedGraphNodes[CMD_GET(ModelID, 0xE)]; + gMarioSpawnInfo->unk18 = gLoadedGraphNodes[CMD_GET(ModelID, 0xC)]; gMarioSpawnInfo->next = NULL; sCurrentCmd = CMD_NEXT; @@ -440,7 +440,7 @@ static void level_cmd_place_object(void) { struct SpawnInfo *spawnInfo; if (sCurrAreaIndex != -1 && ((CMD_GET(u8, 2) & val7) || CMD_GET(u8, 2) == 0x1F)) { - model = CMD_GET(ModelID, 0x1A); + model = CMD_GET(ModelID, 0x18); spawnInfo = alloc_only_pool_alloc(sLevelPool, sizeof(struct SpawnInfo)); spawnInfo->startPos[0] = CMD_GET(s16, 4);