added HOOK_MIRROR_MARIO_RENDER to Lua (#514)

* added HOOK_MIRROR_MARIO_RENDER to Lua

Previously there was no way to interact with mirror Mario using the Lua api, so this fixes that.

* remove premature optimisation

* revert that
This commit is contained in:
Isaac0-dev 2023-11-20 11:21:15 +10:00 committed by GitHub
parent a5194c2f38
commit 6a9bd84f9e
8 changed files with 60 additions and 38 deletions

View File

@ -9026,7 +9026,10 @@ HOOK_ON_DIALOG = 33
HOOK_ON_HUD_RENDER_BEHIND = 34
--- @type LuaHookedEventType
HOOK_MAX = 35
HOOK_MIRROR_MARIO_RENDER = 35
--- @type LuaHookedEventType
HOOK_MAX = 36
--- @class HudDisplayFlags

View File

@ -3207,7 +3207,8 @@
| HOOK_ON_OBJECT_ANIM_UPDATE | 32 |
| HOOK_ON_DIALOG | 33 |
| HOOK_ON_HUD_RENDER_BEHIND | 34 |
| HOOK_MAX | 35 |
| HOOK_MIRROR_MARIO_RENDER | 35 |
| HOOK_MAX | 36 |
[:arrow_up_small:](#)

View File

@ -121,6 +121,7 @@ The lua functions sent to `hook_event()` will be automatically called by SM64 wh
| HOOK_BEFORE_SET_MARIO_ACTION | Called before Mario's action changes. Return an action to change the incoming action or `1` to cancel the action change. | [MarioState](structs.md#MarioState) mario, `integer` incomingAction |
| HOOK_ON_OBJECT_ANIM_UPDATE | Called when an object's animation is updated. | [Object](structs.md#Object) objNode |
| HOOK_ON_DIALOG | Called when a dialog appears. Return `false` to prevent it from appearing. | `integer` dialogId |
| HOOK_MIRROR_MARIO_RENDER | Called when a Mirror Mario is rendered. | [GraphNodeObject](structs.md#GraphNodeObject) mirrorMario | `integer` mirrorMarioIndex |
### Parameters

View File

@ -25,6 +25,7 @@
#include "hardcoded.h"
#include "sound_init.h"
#include "pc/network/network.h"
#include "pc/lua/smlua_hooks.h"
#define TOAD_STAR_1_REQUIREMENT gBehaviorValues.ToadStar1Requirement
#define TOAD_STAR_2_REQUIREMENT gBehaviorValues.ToadStar2Requirement
@ -704,6 +705,8 @@ Gfx* geo_render_mirror_mario(s32 callContext, struct GraphNode* node, UNUSED Mat
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);
} else {
gMirrorMario[i].node.flags &= ~GRAPH_RENDER_ACTIVE;
}

View File

@ -602,45 +602,33 @@ void smlua_cobject_init_globals(void) {
lua_setglobal(L, "gCharacters");
}
{
smlua_push_object(L, LOT_GLOBALTEXTURES, &gGlobalTextures);
lua_setglobal(L, "gTextures");
}
#define EXPOSE_GLOBAL(lot, ptr) \
{ \
smlua_push_object(L, lot, &ptr); \
lua_setglobal(L, #ptr); \
} \
{
smlua_push_object(L, LOT_GLOBALOBJECTANIMATIONS, &gGlobalObjectAnimations);
lua_setglobal(L, "gObjectAnimations");
}
#define EXPOSE_GLOBAL_WITH_NAME(lot, ptr, name) \
{ \
smlua_push_object(L, lot, &ptr); \
lua_setglobal(L, name); \
} \
{
smlua_push_object(L, LOT_GLOBALOBJECTCOLLISIONDATA, &gGlobalObjectCollisionData);
lua_setglobal(L, "gGlobalObjectCollisionData");
}
EXPOSE_GLOBAL_WITH_NAME(LOT_GLOBALTEXTURES, gGlobalTextures, "gTextures");
{
smlua_push_object(L, LOT_LAKITUSTATE, &gLakituState);
lua_setglobal(L, "gLakituState");
}
EXPOSE_GLOBAL_WITH_NAME(LOT_GLOBALOBJECTANIMATIONS, gGlobalObjectAnimations, "gObjectAnimations");
{
smlua_push_object(L, LOT_SERVERSETTINGS, &gServerSettings);
lua_setglobal(L, "gServerSettings");
}
EXPOSE_GLOBAL(LOT_GLOBALOBJECTCOLLISIONDATA, gGlobalObjectCollisionData);
{
smlua_push_object(L, LOT_LEVELVALUES, &gLevelValues);
lua_setglobal(L, "gLevelValues");
}
EXPOSE_GLOBAL(LOT_LAKITUSTATE, gLakituState);
{
smlua_push_object(L, LOT_BEHAVIORVALUES, &gBehaviorValues);
lua_setglobal(L, "gBehaviorValues");
}
EXPOSE_GLOBAL(LOT_SERVERSETTINGS, gServerSettings);
{
smlua_push_object(L, LOT_PAINTINGVALUES, &gPaintingValues);
lua_setglobal(L, "gPaintingValues");
}
EXPOSE_GLOBAL(LOT_LEVELVALUES, gLevelValues);
EXPOSE_GLOBAL(LOT_BEHAVIORVALUES, gBehaviorValues);
EXPOSE_GLOBAL(LOT_PAINTINGVALUES, gPaintingValues);
}
void smlua_cobject_init_per_file_globals(const char* path) {

View File

@ -3238,7 +3238,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_OBJECT_ANIM_UPDATE = 32\n"
"HOOK_ON_DIALOG = 33\n"
"HOOK_ON_HUD_RENDER_BEHIND = 34\n"
"HOOK_MAX = 35\n"
"HOOK_MIRROR_MARIO_RENDER = 35\n"
"HOOK_MAX = 36\n"
"ACTION_HOOK_EVERY_FRAME = 0\n"
"ACTION_HOOK_GRAVITY = 1\n"
"ACTION_HOOK_MAX = 2\n"

View File

@ -891,6 +891,28 @@ bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEv
return false;
}
void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
for (int i = 0; i < hook->count; i++) {
// push the callback onto the stack
lua_rawgeti(L, LUA_REGISTRYINDEX, hook->reference[i]);
// push graph node object
smlua_push_object(L, LOT_GRAPHNODEOBJECT, node);
// push param
lua_pushinteger(L, param);
// call the callback
if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) {
LOG_LUA("Failed to call the callback: %u", hookType);
continue;
}
}
}
////////////////////
// hooked actions //
////////////////////

View File

@ -46,6 +46,7 @@ enum LuaHookedEventType {
HOOK_ON_OBJECT_ANIM_UPDATE,
HOOK_ON_DIALOG,
HOOK_ON_HUD_RENDER_BEHIND,
HOOK_MIRROR_MARIO_RENDER,
HOOK_MAX,
};
@ -85,6 +86,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_OBJECT_ANIM_UPDATE",
"HOOK_ON_DIALOG",
"HOOK_ON_HUD_RENDER_BEHIND",
"HOOK_MIRROR_MARIO_RENDER",
"HOOK_MAX"
};
@ -129,6 +131,7 @@ void smlua_call_event_hooks_mario_action_params_ret_int(enum LuaHookedEventType
void smlua_call_event_hooks_mario_param_and_int_ret_bool(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, bool* returnValue);
bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, s32* returnValue);
bool smlua_call_event_hooks_mario_param_and_int_and_int_ret_int(enum LuaHookedEventType hookType, struct MarioState* m, s32 param, u32 args, s32* returnValue);
void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventType hookType, struct GraphNodeObject* node, s32 param);
enum BehaviorId smlua_get_original_behavior_id(const BehaviorScript* behavior);
const BehaviorScript* smlua_override_behavior(const BehaviorScript* behavior);