From 9d0a61450b1b1388eb0ca3a40dce7252e94d1bb4 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+Agent-11@users.noreply.github.com> Date: Thu, 11 Aug 2022 04:23:54 -0400 Subject: [PATCH] gsDPSetTextureFilter, refactoring and o.header.gfx.skipInViewCheck (#147) * Add gsDPSetTextureFilter to DynOS symbols * Refactor code and fix 2 year oversight Refactored the main menu background code, now uses vec3f_set instead of manually setting every vector Also finally fixed the bug where you load in with only 3 lives, this has been in coop for 2 years now and was likely made as a test for syncing live count and was never reversed. * add skipInViewCheck to GraphNodeObject * Remove idle set Co-authored-by: djoslin0 --- autogen/lua_definitions/structs.lua | 1 + data/dynos_bin_gfx.cpp | 1 + docs/lua/structs.md | 1 + include/types.h | 2 + src/game/level_update.c | 184 +++++++++++----------------- src/game/mario.c | 2 +- src/game/rendering_graph_node.c | 2 + src/pc/lua/smlua_cobject_autogen.c | 3 +- 8 files changed, 83 insertions(+), 113 deletions(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index e8be7bea..3b953910 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -558,6 +558,7 @@ --- @field public prevTimestamp integer --- @field public scale Vec3f --- @field public sharedChild GraphNode +--- @field public skipInViewCheck boolean --- @field public skipInterpolationTimestamp integer --- @field public unk4C SpawnInfo diff --git a/data/dynos_bin_gfx.cpp b/data/dynos_bin_gfx.cpp index 33a2e914..5807f48f 100644 --- a/data/dynos_bin_gfx.cpp +++ b/data/dynos_bin_gfx.cpp @@ -732,6 +732,7 @@ static void ParseGfxSymbol(GfxData* aGfxData, DataNode* aNode, Gfx*& aHead, gfx_symbol_4(gsDPSetFogColor); gfx_symbol_2(gsSPFogPosition, false); gfx_symbol_1(gsDPSetAlphaCompare, false); + gfx_symbol_1(gsDPSetTextureFilter, false); gfx_symbol_2(gsSPCopyLightEXT, false); gfx_symbol_2(gsSPFogFactor, false); diff --git a/docs/lua/structs.md b/docs/lua/structs.md index dc591b85..36968fdc 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -805,6 +805,7 @@ | prevTimestamp | `integer` | | | scale | [Vec3f](structs.md#Vec3f) | read-only | | sharedChild | [GraphNode](structs.md#GraphNode) | | +| skipInViewCheck | `boolean` | | | skipInterpolationTimestamp | `integer` | | | unk4C | [SpawnInfo](structs.md#SpawnInfo) | | diff --git a/include/types.h b/include/types.h index 932396b0..c07d6f32 100644 --- a/include/types.h +++ b/include/types.h @@ -7,6 +7,7 @@ #include #include "macros.h" #include "pc/network/version.h" +#include "src/pc/platform.h" // Certain functions are marked as having return values, but do not // actually return a value. This causes undefined behavior, which we'd rather @@ -155,6 +156,7 @@ struct GraphNodeObject Mat4 *throwMatrixPrev; /*0x54*/ Vec3f cameraToObject; u32 skipInterpolationTimestamp; + bool skipInViewCheck; }; struct ObjectNode diff --git a/src/game/level_update.c b/src/game/level_update.c index a9d01a38..056319ad 100644 --- a/src/game/level_update.c +++ b/src/game/level_update.c @@ -961,7 +961,7 @@ void initiate_delayed_warp(void) { switch (sDelayedWarpOp) { case WARP_OP_GAME_OVER: gChangeLevel = gLevelValues.entryLevel; - gMarioStates[0].numLives = 3; + gMarioStates[0].numLives = 4; gMarioStates[0].health = 0x880; break; @@ -1331,7 +1331,7 @@ void update_menu_level(void) { default: curLevel = LEVEL_CASTLE_GROUNDS; break; } - // warp to level + // warp to level, this feels buggy if (gCurrLevelNum != curLevel) { if (curLevel == LEVEL_JRB) { dynos_warp_to_level(curLevel, 1, 2); @@ -1347,128 +1347,90 @@ void update_menu_level(void) { sFirstCastleGroundsMenu = false; } + struct Object *o; // set mario/camera pos - if (gCurrLevelNum == LEVEL_CASTLE_GROUNDS) { - if (!sFirstCastleGroundsMenu) { - gMarioState->pos[0] = -1328; - gMarioState->pos[1] = 260; - gMarioState->pos[2] = 4664; - gMarioState->faceAngle[1] = 0x0; - gLakituState.curPos[1] = 390; - gLakituState.curPos[0] = -1328; - gLakituState.curPos[2] = 6064; - } - } else if (gCurrLevelNum == LEVEL_BOB) { - gMarioState->pos[0] = 7008; - gMarioState->pos[1] = 864; - gMarioState->pos[2] = 1943; - gLakituState.curPos[1] = 1064; - gLakituState.curPos[2] = 2843; - gLakituState.curPos[0] = 7908; - gMarioState->faceAngle[1] = 0x2000; + switch (gCurrLevelNum) { + case LEVEL_CASTLE_GROUNDS: + if (!sFirstCastleGroundsMenu) { + vec3f_set(gMarioState->pos, -1328, 260, 4664); + vec3f_set(gLakituState.curPos, -1328, 390, 6064); + gMarioState->faceAngle[1] = 0; + gLakituState.nextYaw = gMarioState->faceAngle[1] + 0x8000; + } + break; + case LEVEL_BOB: + vec3f_set(gMarioState->pos, 7008, 864, 1943); + vec3f_set(gLakituState.curPos, 7909, 1064, 2843); + gMarioState->faceAngle[1] = 0x2000; - // delete all goombas as they interfere with the main menu - - struct Object *o; - - o = find_object_with_behavior(bhvGoomba); - - if (o != NULL) { - if (obj_has_behavior(o, bhvGoomba)) { + // delete all goombas as they interfere with the main menu + o = find_object_with_behavior(bhvGoomba); + if (o != NULL) { obj_mark_for_deletion(o); } - } + break; + case LEVEL_WF: + vec3f_set(gMarioState->pos, -2904, 2560, -327); + vec3f_set(gLakituState.curPos, -4504, 2760, -777); + gMarioState->faceAngle[1] = -15536; + break; + case LEVEL_WMOTR: + vec3f_set(gMarioState->pos, 3548, -2738, 4663); + vec3f_set(gLakituState.curPos, 3548, -2438, 6063); + gMarioState->faceAngle[1] = 0; + break; + case LEVEL_JRB: + vec3f_set(gMarioState->pos, 3639, 1536, 6202); + vec3f_set(gLakituState.curPos, 5039, 1736, 6402); + break; + case LEVEL_SSL: + vec3f_set(gMarioState->pos, -2048, 256, 961); + vec3f_set(gLakituState.curPos, -2048, 356, 2461); + gMarioState->faceAngle[1] = 0; + break; + case LEVEL_TTM: + vec3f_set(gMarioState->pos, 2488, 1460, 2011); + vec3f_set(gLakituState.curPos, 3488, 1763, 3411); + gMarioState->faceAngle[1] = 0x1000; + break; + case LEVEL_SL: + vec3f_set(gMarioState->pos, 5494, 1024, 443); + vec3f_set(gLakituState.curPos, 6994, 1124, 443); + gMarioState->faceAngle[1] = 0x4000; + break; + case LEVEL_BBH: + vec3f_set(gMarioState->pos, 666, -204, 5303); + vec3f_set(gLakituState.curPos, 666, -204, 6803); + gMarioState->faceAngle[1] = 0; + break; + case LEVEL_LLL: + vec3f_set(gMarioState->pos, -2376, 638, 956); + vec3f_set(gLakituState.curPos, -3576, 938, 1576); + gMarioState->faceAngle[1] = -0x2800; + break; + case LEVEL_THI: + vec3f_set(gMarioState->pos, -1010, 341, -324); + vec3f_set(gLakituState.curPos, -2246, 431, -324); + gMarioState->faceAngle[1] = -0x4000; - } else if (gCurrLevelNum == LEVEL_WF) { - gLakituState.curPos[1] = 2760; - gLakituState.curPos[2] = -777; - gLakituState.curPos[0] = -4504; - gMarioState->pos[1] = 2560; - gMarioState->pos[2] = -327; - gMarioState->pos[0] = -2904; - gMarioState->faceAngle[1] = -31072 / 2; - } else if (gCurrLevelNum == LEVEL_WMOTR) { - gLakituState.curPos[1] = -2438; - gLakituState.curPos[2] = 6063; - gLakituState.curPos[0] = 3548; - gMarioState->pos[1] = -2738; - gMarioState->pos[2] = 4663; - gMarioState->pos[0] = 3548; - gMarioState->faceAngle[1] = 0; - } else if (gCurrLevelNum == LEVEL_JRB) { - gLakituState.curPos[1] = 1736; - gLakituState.curPos[2] = 6402; - gLakituState.curPos[0] = 5039; - gMarioState->pos[1] = 1536; - gMarioState->pos[2] = 6202; - gMarioState->pos[0] = 3639; - } else if (gCurrLevelNum == LEVEL_SSL) { - gLakituState.curPos[1] = 356; - gLakituState.curPos[2] = 2461; - gLakituState.curPos[0] = -2048; - gMarioState->pos[1] = 256; - gMarioState->pos[2] = 961; - gMarioState->pos[0] = -2048; - gMarioState->faceAngle[1] = 0; - } else if (gCurrLevelNum == LEVEL_TTM) { - gLakituState.curPos[1] = 1763; - gLakituState.curPos[2] = 3411; - gLakituState.curPos[0] = 3488; - gMarioState->pos[1] = 1460; - gMarioState->pos[2] = 2011; - gMarioState->pos[0] = 2488; - gMarioState->faceAngle[1] = 0x1000; - } else if (gCurrLevelNum == LEVEL_SL) { - gLakituState.curPos[1] = 1124; - gLakituState.curPos[2] = 443; - gLakituState.curPos[0] = 6994; - gMarioState->pos[1] = 1024; - gMarioState->pos[2] = 443; - gMarioState->pos[0] = 5494; - gMarioState->faceAngle[1] = 0x4000; - } else if (gCurrLevelNum == LEVEL_BBH) { - gLakituState.curPos[1] = -204; - gLakituState.curPos[2] = 6803; - gLakituState.curPos[0] = 666; - gMarioState->pos[1] = -204; - gMarioState->pos[2] = 5303; - gMarioState->pos[0] = 666; - gMarioState->faceAngle[1] = 0; - } else if (gCurrLevelNum == LEVEL_LLL) { - gLakituState.curPos[1] = 938; - gLakituState.curPos[2] = 1576; - gLakituState.curPos[0] = -3576; - gMarioState->pos[1] = 638; - gMarioState->pos[2] = 956; - gMarioState->pos[0] = -2376; - gMarioState->faceAngle[1] = -0x2800; - } else if (gCurrLevelNum == LEVEL_THI) { - gLakituState.curPos[1] = 431; - gLakituState.curPos[2] = -324; - gLakituState.curPos[0] = -2246; - gMarioState->pos[1] = 341; - gMarioState->pos[2] = -324; - gMarioState->pos[0] = -1010; - gMarioState->faceAngle[1] = -0x4000; - - // delete all goombas as they interfere with the main menu - - struct Object *o; - - o = find_object_with_behavior(bhvGoomba); - - if (o != NULL) { - if (obj_has_behavior(o, bhvGoomba)) { + // delete all goombas as they interfere with the main menu + o = find_object_with_behavior(bhvGoomba); + if (o != NULL) { obj_mark_for_deletion(o); } - } + break; } + gMarioState->health = 0x880; // reset input gMarioState->input = 0; + gMarioState->controller->rawStickX = 0; + gMarioState->controller->rawStickY = 0; + gMarioState->controller->stickX = 0; + gMarioState->controller->stickY = 0; // figure out music - if (!configMenuSound) { + if (!configMenuSound || curLevel == LEVEL_CASTLE_GROUNDS) { reset_volume(); disable_background_sound(); set_background_music(0, 0x0021, 0); diff --git a/src/game/mario.c b/src/game/mario.c index 128d6f66..5d8cad2a 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -2267,7 +2267,7 @@ static void init_mario_single_from_save_file(struct MarioState* m, u16 index) { m->numStars = save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1); m->numKeys = 0; - m->numLives = 3; + m->numLives = 4; m->health = 0x880; m->prevNumStarsForDialog = m->numStars; diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 5ce8d55c..f3c1cfbb 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -1119,6 +1119,8 @@ static void geo_process_shadow(struct GraphNodeShadow *node) { static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) { if (node->node.flags & GRAPH_RENDER_INVISIBLE) { return FALSE; + } else if (node->skipInViewCheck) { + return TRUE; } // ! @bug The aspect ratio is not accounted for. When the fov value is 45, diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index cd44cc1f..e11e6f71 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -627,7 +627,7 @@ static struct LuaObjectField sGraphNodeFields[LUA_GRAPH_NODE_FIELD_COUNT] = { { "type", LVT_S16, offsetof(struct GraphNode, type), false, LOT_NONE }, }; -#define LUA_GRAPH_NODE_OBJECT_FIELD_COUNT 19 +#define LUA_GRAPH_NODE_OBJECT_FIELD_COUNT 20 static struct LuaObjectField sGraphNodeObjectFields[LUA_GRAPH_NODE_OBJECT_FIELD_COUNT] = { { "activeAreaIndex", LVT_S8, offsetof(struct GraphNodeObject, activeAreaIndex), false, LOT_NONE }, { "angle", LVT_COBJECT, offsetof(struct GraphNodeObject, angle), true, LOT_VEC3S }, @@ -647,6 +647,7 @@ static struct LuaObjectField sGraphNodeObjectFields[LUA_GRAPH_NODE_OBJECT_FIELD_ { "prevTimestamp", LVT_U32, offsetof(struct GraphNodeObject, prevTimestamp), false, LOT_NONE }, { "scale", LVT_COBJECT, offsetof(struct GraphNodeObject, scale), true, LOT_VEC3F }, { "sharedChild", LVT_COBJECT_P, offsetof(struct GraphNodeObject, sharedChild), false, LOT_GRAPHNODE }, + { "skipInViewCheck", LVT_BOOL, offsetof(struct GraphNodeObject, skipInViewCheck), false, LOT_NONE }, { "skipInterpolationTimestamp", LVT_U32, offsetof(struct GraphNodeObject, skipInterpolationTimestamp), false, LOT_NONE }, // { "throwMatrix", LVT_???, offsetof(struct GraphNodeObject, throwMatrix), false, LOT_??? }, <--- UNIMPLEMENTED // { "throwMatrixPrev", LVT_???, offsetof(struct GraphNodeObject, throwMatrixPrev), false, LOT_??? }, <--- UNIMPLEMENTED