Massively improve "Global Player Models" option

This commit is contained in:
Agent X 2024-03-17 20:58:38 -04:00
parent c4ef095a37
commit 7dd02b5c4d
16 changed files with 30 additions and 82 deletions

View File

@ -7693,14 +7693,6 @@ function obj_set_billboard(obj)
-- ...
end
--- @param obj Object
--- @param index integer
--- @param modelID integer
--- @return nil
function obj_set_character_model(obj, index, modelID)
-- ...
end
--- @param obj Object
--- @return nil
function obj_set_cylboard(obj)

View File

@ -36,7 +36,7 @@ void dynos_pack_init(void);
void dynos_generate_packs(const char* directory);
// -- geos -- //
void dynos_actor_override(void** aSharedChild);
void dynos_actor_override(struct Object* obj, void** aSharedChild);
void dynos_add_actor_custom(const char *filePath, const char* geoName);
const void* dynos_geolayout_get(const char *name);

View File

@ -887,7 +887,7 @@ const void *DynOS_Actor_GetLayoutFromName(const char *aActorName);
ActorGfx* DynOS_Actor_GetActorGfx(const GraphNode* aGraphNode);
void DynOS_Actor_Valid(const void* aGeoref, ActorGfx& aActorGfx);
void DynOS_Actor_Invalid(const void* aGeoref, s32 aPackIndex);
void DynOS_Actor_Override(void** aSharedChild);
void DynOS_Actor_Override(struct Object* obj, void** aSharedChild);
void DynOS_Actor_Override_All(void);
void DynOS_Actor_ModShutdown();

View File

@ -115,8 +115,8 @@ void dynos_generate_packs(const char* directory) {
// -- geos -- //
void dynos_actor_override(void** aSharedChild) {
DynOS_Actor_Override(aSharedChild);
void dynos_actor_override(struct Object* obj, void** aSharedChild) {
DynOS_Actor_Override(obj, aSharedChild);
}
void dynos_add_actor_custom(const char *filePath, const char* geoName) {

View File

@ -7,6 +7,7 @@ extern "C" {
#include "game/level_update.h"
#include "game/object_list_processor.h"
#include "pc/configfile.h"
#include "pc/lua/smlua_hooks.h"
}
// Static maps/arrays
@ -148,7 +149,7 @@ void DynOS_Actor_Invalid(const void* aGeoref, s32 aPackIndex) {
_ValidActors.erase(aGeoref);
}
void DynOS_Actor_Override(void** aSharedChild) {
void DynOS_Actor_Override(struct Object* obj, void** aSharedChild) {
if ((aSharedChild == NULL) || (*aSharedChild == NULL)) { return; }
const void* georef = (*(GraphNode**)aSharedChild)->georef;
@ -157,6 +158,19 @@ void DynOS_Actor_Override(void** aSharedChild) {
auto& _ValidActors = DynosValidActors();
if (_ValidActors.count(georef) == 0) { return; }
// Check if the behavior uses a character specific model
if (obj && (obj->behavior == smlua_override_behavior(bhvMario) ||
obj->behavior == smlua_override_behavior(bhvNormalCap) ||
obj->behavior == smlua_override_behavior(bhvWingCap) ||
obj->behavior == smlua_override_behavior(bhvMetalCap) ||
obj->behavior == smlua_override_behavior(bhvVanishCap))) {
struct NetworkPlayer* np = network_player_from_global_index(obj->globalPlayerIndex);
if (np && np->localIndex > 0 && !configGlobalPlayerModels) {
return;
}
}
*aSharedChild = (void*)_ValidActors[georef].mGraphNode;
}
@ -171,7 +185,7 @@ void DynOS_Actor_Override_All(void) {
u32 id = 0;
_Object->header.gfx.sharedChild = DynOS_Model_LoadGeo(&id, MODEL_POOL_PERMANENT, georef, true);
}
DynOS_Actor_Override((void**)&_Object->header.gfx.sharedChild);
DynOS_Actor_Override(_Object, (void**)&_Object->header.gfx.sharedChild);
}
}
}

View File

@ -5979,28 +5979,6 @@
<br />
## [obj_set_character_model](#obj_set_character_model)
### Lua Example
`obj_set_character_model(obj, index, modelID)`
### Parameters
| Field | Type |
| ----- | ---- |
| obj | [Object](structs.md#Object) |
| index | `integer` |
| modelID | `integer` |
### Returns
- None
### C Prototype
`void obj_set_character_model(struct Object* obj, u16 index, s32 modelID);`
[:arrow_up_small:](#)
<br />
## [obj_set_cylboard](#obj_set_cylboard)
### Lua Example

View File

@ -1444,7 +1444,6 @@
- [obj_set_angle](functions-4.md#obj_set_angle)
- [obj_set_behavior](functions-4.md#obj_set_behavior)
- [obj_set_billboard](functions-4.md#obj_set_billboard)
- [obj_set_character_model](functions-4.md#obj_set_character_model)
- [obj_set_cylboard](functions-4.md#obj_set_cylboard)
- [obj_set_face_angle](functions-4.md#obj_set_face_angle)
- [obj_set_face_angle_to_move_angle](functions-4.md#obj_set_face_angle_to_move_angle)

View File

@ -329,7 +329,7 @@ struct GraphNodeObject *init_graph_node_object(struct DynamicPool *pool,
graphNode->animInfo.animAccel = 0x10000;
graphNode->animInfo.animTimer = 0;
graphNode->node.flags |= GRAPH_RENDER_HAS_ANIMATION;
dynos_actor_override((void*)&graphNode->sharedChild);
dynos_actor_override(NULL, (void*)&graphNode->sharedChild);
}
return graphNode;
@ -447,7 +447,7 @@ struct GraphNodeObjectParent *init_graph_node_object_parent(struct DynamicPool *
if (graphNode != NULL) {
init_scene_graph_node_links(&graphNode->node, GRAPH_NODE_TYPE_OBJECT_PARENT);
graphNode->sharedChild = sharedChild;
dynos_actor_override((void*)&graphNode->sharedChild);
dynos_actor_override(NULL, (void*)&graphNode->sharedChild);
}
return graphNode;
@ -745,7 +745,7 @@ void geo_obj_init(struct GraphNodeObject *graphNode, void *sharedChild, Vec3f po
graphNode->unk4C = 0;
graphNode->throwMatrix = NULL;
graphNode->animInfo.curAnim = NULL;
dynos_actor_override((void*)&graphNode->sharedChild);
dynos_actor_override(NULL, (void*)&graphNode->sharedChild);
graphNode->node.flags |= GRAPH_RENDER_ACTIVE;
graphNode->node.flags &= ~GRAPH_RENDER_INVISIBLE;
@ -770,7 +770,7 @@ void geo_obj_init_spawninfo(struct GraphNodeObject *graphNode, struct SpawnInfo
graphNode->unk4C = spawn;
graphNode->throwMatrix = NULL;
graphNode->animInfo.curAnim = 0;
dynos_actor_override((void*)&graphNode->sharedChild);
dynos_actor_override(NULL, (void*)&graphNode->sharedChild);
graphNode->node.flags |= GRAPH_RENDER_ACTIVE;
graphNode->node.flags &= ~GRAPH_RENDER_INVISIBLE;

View File

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

View File

@ -20,7 +20,7 @@ void bhv_1up_interact(void) {
}
void bhv_1up_trigger_init(void) {
obj_set_model_extended(o, E_MODEL_NONE);
obj_set_model(o, MODEL_NONE);
cur_obj_hide();
}

View File

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

View File

@ -691,9 +691,7 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat
if (mario && (((struct GraphNode*)&mario->header.gfx)->flags & GRAPH_RENDER_ACTIVE) && np->connected) {
// TODO: Is this a geo layout copy or a graph node copy?
gMirrorMario[i].sharedChild = mario->header.gfx.sharedChild;
if (configGlobalPlayerModels || i == 0) {
dynos_actor_override((void*)&gMirrorMario[i].sharedChild);
}
dynos_actor_override(mario, (void*)&gMirrorMario[i].sharedChild);
gMirrorMario[i].areaIndex = mario->header.gfx.areaIndex;
vec3s_copy(gMirrorMario[i].angle, mario->header.gfx.angle);
vec3f_copy(gMirrorMario[i].pos, mario->header.gfx.pos);
@ -707,7 +705,6 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat
gMirrorMario[i].pos[0] = mirroredX + MIRROR_X;
gMirrorMario[i].angle[1] = -gMirrorMario[i].angle[1];
gMirrorMario[i].scale[0] *= -1.0f;
// TODO: does rendering the mirror room still crash?
gMirrorMario[i].node.flags |= GRAPH_RENDER_ACTIVE;
smlua_call_event_hooks_graph_node_object_and_int_param(HOOK_MIRROR_MARIO_RENDER, &gMirrorMario[i], i);

View File

@ -1437,15 +1437,7 @@ void cur_obj_set_model(s32 modelID) {
void obj_set_model(struct Object* obj, s32 modelID) {
obj->header.gfx.sharedChild = dynos_model_get_geo(modelID);
dynos_actor_override((void*)&obj->header.gfx.sharedChild);
smlua_call_event_hooks_object_model_param(HOOK_OBJECT_SET_MODEL, obj, modelID);
}
void obj_set_character_model(struct Object* obj, u16 index, s32 modelID) {
obj->header.gfx.sharedChild = dynos_model_get_geo(modelID);
if (configGlobalPlayerModels || index == 0) {
dynos_actor_override((void*)&obj->header.gfx.sharedChild);
}
dynos_actor_override(obj, (void*)&obj->header.gfx.sharedChild);
smlua_call_event_hooks_object_model_param(HOOK_OBJECT_SET_MODEL, obj, modelID);
}

View File

@ -175,7 +175,6 @@ 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 obj_set_character_model(struct Object* obj, u16 index, 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

@ -25833,28 +25833,6 @@ int smlua_func_obj_set_billboard(lua_State* L) {
return 1;
}
int smlua_func_obj_set_character_model(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 3) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "obj_set_character_model", 3, top);
return 0;
}
struct Object* obj = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "obj_set_character_model"); return 0; }
u16 index = smlua_to_integer(L, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "obj_set_character_model"); return 0; }
s32 modelID = smlua_to_integer(L, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "obj_set_character_model"); return 0; }
extern void obj_set_character_model(struct Object* obj, u16 index, s32 modelID);
obj_set_character_model(obj, index, modelID);
return 1;
}
/*
int smlua_func_obj_set_collision_data(lua_State* L) {
if (L == NULL) { return 0; }
@ -32814,7 +32792,6 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "obj_set_angle", smlua_func_obj_set_angle);
smlua_bind_function(L, "obj_set_behavior", smlua_func_obj_set_behavior);
smlua_bind_function(L, "obj_set_billboard", smlua_func_obj_set_billboard);
smlua_bind_function(L, "obj_set_character_model", smlua_func_obj_set_character_model);
//smlua_bind_function(L, "obj_set_collision_data", smlua_func_obj_set_collision_data); <--- UNIMPLEMENTED
smlua_bind_function(L, "obj_set_cylboard", smlua_func_obj_set_cylboard);
smlua_bind_function(L, "obj_set_face_angle", smlua_func_obj_set_face_angle);

View File

@ -39,7 +39,7 @@ void network_player_update_model(u8 localIndex) {
m->character = &gCharacters[index];
if (m->marioObj == NULL) { return; }
obj_set_character_model(m->marioObj, m->playerIndex, m->character->modelId);
obj_set_model(m->marioObj, m->character->modelId);
}
bool network_player_any_connected(void) {