From d6508def28d411aa3ef5ec200ed6be8b891a84ab Mon Sep 17 00:00:00 2001 From: Isaac0-dev <62234577+Isaac0-dev@users.noreply.github.com> Date: Wed, 4 Jun 2025 07:58:02 +1000 Subject: [PATCH] revise my latest changes --- data/dynos_mgr_actor.cpp | 20 +++++++++++--------- data/dynos_mgr_anim.cpp | 4 ++-- src/game/mario_misc.c | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/data/dynos_mgr_actor.cpp b/data/dynos_mgr_actor.cpp index 022e774a9..d80adb44f 100644 --- a/data/dynos_mgr_actor.cpp +++ b/data/dynos_mgr_actor.cpp @@ -22,7 +22,7 @@ static Array>& DynosCustomActors() { return sDynosCustomActors; } -static std::map sModifiedModels; +static std::map sModifiedGraphNodes; // TODO: the cleanup/refactor didn't really go as planned. // clean up the actor management code more @@ -237,7 +237,7 @@ void DynOS_Actor_Override_All(void) { } } -std::unordered_map graphNodeInitMap = { +static std::unordered_map sGraphNodeSizeMap = { { GRAPH_NODE_TYPE_ROOT, sizeof(GraphNodeRoot) }, { GRAPH_NODE_TYPE_ORTHO_PROJECTION, sizeof(GraphNodeOrthoProjection) }, { GRAPH_NODE_TYPE_PERSPECTIVE, sizeof(GraphNodePerspective) }, @@ -262,17 +262,18 @@ std::unordered_map graphNodeInitMap = { { GRAPH_NODE_TYPE_HELD_OBJ, sizeof(GraphNodeHeldObject) }, }; -size_t get_graph_node_size(uint16_t nodeType) { - auto it = graphNodeInitMap.find(nodeType); - return it != graphNodeInitMap.end() ? it->second : 0; +size_t get_graph_node_size(s16 nodeType) { + auto it = sGraphNodeSizeMap.find(nodeType); + return it != sGraphNodeSizeMap.end() ? it->second : 0; } void DynOS_Actor_RegisterModifiedGraphNode(GraphNode *aNode) { - if (sModifiedModels.find(aNode) == sModifiedModels.end()) { + if (sModifiedGraphNodes.find(aNode) == sModifiedGraphNodes.end()) { size_t size = get_graph_node_size(aNode->type); + if (size == 0) { return; } // Unexpected GraphNode *graphNodeCopy = (GraphNode *) malloc(size); memcpy(graphNodeCopy, aNode, size); - sModifiedModels[aNode] = graphNodeCopy; + sModifiedGraphNodes[aNode] = graphNodeCopy; } } @@ -299,10 +300,11 @@ void DynOS_Actor_ModShutdown() { DynOS_Actor_Override_All(); // Reset modified graph nodes - for (auto& node : sModifiedModels) { + for (auto& node : sModifiedGraphNodes) { size_t size = get_graph_node_size(node.second->type); + if (size == 0) { continue; } // Unexpected memcpy(node.first, node.second, size); free(node.second); } - sModifiedModels.clear(); + sModifiedGraphNodes.clear(); } diff --git a/data/dynos_mgr_anim.cpp b/data/dynos_mgr_anim.cpp index a3567b5e4..af7f319f4 100644 --- a/data/dynos_mgr_anim.cpp +++ b/data/dynos_mgr_anim.cpp @@ -8,7 +8,7 @@ extern "C" { #include "behavior_data.h" #include "pc/lua/smlua_hooks.h" -s16 geo_get_processing_mario_index(void); +s8 geo_get_processing_mario_index(void); } // @@ -77,7 +77,7 @@ void DynOS_Anim_Swap(void *aPtr) { // Animation index s32 _AnimIndex = -1; - u8 index = geo_get_processing_mario_index(); + s8 index = geo_get_processing_mario_index(); if (index != -1) { _AnimIndex = RetrieveCurrentMarioAnimationIndex(index); diff --git a/src/game/mario_misc.c b/src/game/mario_misc.c index 9977a8e3a..fb76332dd 100644 --- a/src/game/mario_misc.c +++ b/src/game/mario_misc.c @@ -351,7 +351,7 @@ static u8 geo_get_processing_object_index(void) { return (index >= MAX_PLAYERS) ? 0 : index; } -s16 geo_get_processing_mario_index(void) { +s8 geo_get_processing_mario_index(void) { if (gCurGraphNodeProcessingObject == NULL) { return -1; } s8 index = geo_get_processing_mirror_mario_index();