Refactor how objects set their models

This commit is contained in:
MysterD 2022-04-19 18:47:50 -07:00
parent 8f773ea887
commit dd6f6c430e
13 changed files with 18 additions and 53 deletions

View file

@ -79,7 +79,7 @@ override_disallowed_functions = {
"src/game/sound_init.h": [ "_loop_", "thread4_", "set_sound_mode" ],
"src/pc/network/network_utils.h": [ "network_get_player_text_color[^_]" ],
"src/pc/network/network_player.h": [ "_init", "_connected[^_]", "_shutdown", "_disconnected", "_update" ],
"src/game/object_helpers.c": [ "spawn_obj", "^bhv_", "abs[fi]", "^bit_shift", "_debug$", "^stub_" ],
"src/game/object_helpers.c": [ "spawn_obj", "^bhv_", "abs[fi]", "^bit_shift", "_debug$", "^stub_", "_set_model" ],
"src/game/obj_behaviors.c": [ "debug_" ],
"src/game/obj_behaviors_2.c": [ "wiggler_jumped_on_attack_handler", "huge_goomba_weakly_attacked" ],
"src/game/spawn_sound.c": [ "spawner" ],

View file

@ -6193,12 +6193,6 @@ function cur_obj_set_hurtbox_radius_and_height(radius, height)
-- ...
end
--- @param modelID integer
--- @return nil
function cur_obj_set_model(modelID)
-- ...
end
--- @param other Object
--- @param dleft number
--- @param dy number

View file

@ -1163,7 +1163,6 @@
- [cur_obj_set_hitbox_and_die_if_attacked](#cur_obj_set_hitbox_and_die_if_attacked)
- [cur_obj_set_hitbox_radius_and_height](#cur_obj_set_hitbox_radius_and_height)
- [cur_obj_set_hurtbox_radius_and_height](#cur_obj_set_hurtbox_radius_and_height)
- [cur_obj_set_model](#cur_obj_set_model)
- [cur_obj_set_pos_relative](#cur_obj_set_pos_relative)
- [cur_obj_set_pos_relative_to_parent](#cur_obj_set_pos_relative_to_parent)
- [cur_obj_set_pos_to_home](#cur_obj_set_pos_to_home)
@ -22003,26 +22002,6 @@ The `reliable` field will ensure that the packet arrives, but should be used spa
<br />
## [cur_obj_set_model](#cur_obj_set_model)
### Lua Example
`cur_obj_set_model(modelID)`
### Parameters
| Field | Type |
| ----- | ---- |
| modelID | `integer` |
### Returns
- None
### C Prototype
`void cur_obj_set_model(s32 modelID);`
[:arrow_up_small:](#)
<br />
## [cur_obj_set_pos_relative](#cur_obj_set_pos_relative)
### Lua Example

View file

@ -183,7 +183,7 @@ static s32 bhv_cmd_cylboard(void) {
static s32 bhv_cmd_set_model(void) {
s32 modelID = BHV_CMD_GET_2ND_S16(0);
gCurrentObject->header.gfx.sharedChild = gLoadedGraphNodes[modelID];
obj_set_model(gCurrentObject, modelID);
gCurBhvCommand++;
return BHV_PROC_CONTINUE;

View file

@ -70,8 +70,7 @@ void register_scene_graph_node(struct GraphNode *graphNode) {
}
} else {
if (gCurGraphNodeList[gCurGraphNodeIndex - 1]->type == GRAPH_NODE_TYPE_OBJECT_PARENT) {
((struct GraphNodeObjectParent *) gCurGraphNodeList[gCurGraphNodeIndex - 1])
->sharedChild = graphNode;
((struct GraphNodeObjectParent *) gCurGraphNodeList[gCurGraphNodeIndex - 1])->sharedChild = graphNode;
} else {
geo_add_child(gCurGraphNodeList[gCurGraphNodeIndex - 1], graphNode);
}

View file

@ -8,20 +8,20 @@ void bhv_celebration_star_init(void) {
o->oCelebStarDiameterOfRotation = 100;
#if BUGFIX_STAR_BOWSER_KEY
if (gCurrLevelNum == LEVEL_BOWSER_1 || gCurrLevelNum == LEVEL_BOWSER_2) {
o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_BOWSER_KEY];
cur_obj_set_model(MODEL_BOWSER_KEY);
o->oFaceAnglePitch = 0;
o->oFaceAngleRoll = 49152;
cur_obj_scale(0.1f);
o->oCelebStarUnkF4 = 1;
} else {
o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_STAR];
cur_obj_set_model(MODEL_STAR);
o->oFaceAnglePitch = 0;
o->oFaceAngleRoll = 0;
cur_obj_scale(0.4f);
o->oCelebStarUnkF4 = 0;
}
#else
o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_STAR];
cur_obj_set_model(MODEL_STAR);
cur_obj_scale(0.4f);
o->oFaceAnglePitch = 0;
o->oFaceAngleRoll = 0;

View file

@ -19,9 +19,9 @@ void bhv_collect_star_init(void) {
starId = (o->oBehParams >> 24) & 0xFF;
currentLevelStarFlags = save_file_get_star_flags(gCurrSaveFileNum - 1, gCurrCourseNum - 1);
if (currentLevelStarFlags & (1 << starId)) {
o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_TRANSPARENT_STAR];
cur_obj_set_model(MODEL_TRANSPARENT_STAR);
} else {
o->header.gfx.sharedChild = gLoadedGraphNodes[MODEL_STAR];
cur_obj_set_model(MODEL_STAR);
}
obj_set_hitbox(o, &sCollectStarHitbox);

View file

@ -2233,7 +2233,7 @@ static void init_single_mario(struct MarioState* m) {
u8 modelIndex = gNetworkPlayers[playerIndex].overrideModelIndex;
if (modelIndex >= CT_MAX) { modelIndex = 0; }
m->character = &gCharacters[modelIndex];
m->marioObj->header.gfx.sharedChild = gLoadedGraphNodes[m->character->modelId];
obj_set_model(m->marioObj, m->character->modelId);
}
void init_mario(void) {

View file

@ -1285,7 +1285,11 @@ void cur_obj_get_dropped(void) {
}
void cur_obj_set_model(s32 modelID) {
o->header.gfx.sharedChild = gLoadedGraphNodes[modelID];
obj_set_model(o, modelID);
}
void obj_set_model(struct Object* obj, s32 modelID) {
obj->header.gfx.sharedChild = gLoadedGraphNodes[modelID];
}
void mario_set_flag(s32 flag) {

View file

@ -168,6 +168,7 @@ void cur_obj_unrender_and_reset_state(s32 sp18, s32 sp1C);
void cur_obj_get_thrown_or_placed(f32 forwardVel, f32 velY, s32 thrownAction);
void cur_obj_get_dropped(void);
void cur_obj_set_model(s32 modelID);
void obj_set_model(struct Object* obj, s32 modelID);
void mario_set_flag(s32 flag);
s32 cur_obj_clear_interact_status_flag(s32 flag);
void obj_mark_for_deletion(struct Object *obj);

View file

@ -12709,18 +12709,6 @@ int smlua_func_cur_obj_set_hurtbox_radius_and_height(lua_State* L) {
return 1;
}
int smlua_func_cur_obj_set_model(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
s32 modelID = smlua_to_integer(L, 1);
if (!gSmLuaConvertSuccess) { return 0; }
extern void cur_obj_set_model(s32 modelID);
cur_obj_set_model(modelID);
return 1;
}
int smlua_func_cur_obj_set_pos_relative(lua_State* L) {
if(!smlua_functions_valid_param_count(L, 4)) { return 0; }
@ -16837,7 +16825,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "cur_obj_set_hitbox_and_die_if_attacked", smlua_func_cur_obj_set_hitbox_and_die_if_attacked);
smlua_bind_function(L, "cur_obj_set_hitbox_radius_and_height", smlua_func_cur_obj_set_hitbox_radius_and_height);
smlua_bind_function(L, "cur_obj_set_hurtbox_radius_and_height", smlua_func_cur_obj_set_hurtbox_radius_and_height);
smlua_bind_function(L, "cur_obj_set_model", smlua_func_cur_obj_set_model);
smlua_bind_function(L, "cur_obj_set_pos_relative", smlua_func_cur_obj_set_pos_relative);
smlua_bind_function(L, "cur_obj_set_pos_relative_to_parent", smlua_func_cur_obj_set_pos_relative_to_parent);
smlua_bind_function(L, "cur_obj_set_pos_to_home", smlua_func_cur_obj_set_pos_to_home);

View file

@ -94,7 +94,7 @@ s32 obj_has_model_extended(struct Object *o, enum ModelExtendedId modelId) {
}
void obj_set_model_extended(struct Object *o, enum ModelExtendedId modelId) {
o->header.gfx.sharedChild = gLoadedGraphNodes[smlua_model_util_load(modelId)];
obj_set_model(o, smlua_model_util_load(modelId));
}
Trajectory* get_trajectory(const char* name) {

View file

@ -8,6 +8,7 @@
#include "game/area.h"
#include "game/level_info.h"
#include "game/hardcoded.h"
#include "game/object_helpers.h"
#include "pc/lua/smlua_hooks.h"
struct NetworkPlayer gNetworkPlayers[MAX_PLAYERS] = { 0 };
@ -32,7 +33,7 @@ void network_player_update_model(u8 localIndex) {
m->character = &gCharacters[index];
if (m->marioObj == NULL) { return; }
m->marioObj->header.gfx.sharedChild = gLoadedGraphNodes[m->character->modelId];
obj_set_model(m->marioObj, m->character->modelId);
}
bool network_player_any_connected(void) {