Final touches for geo hooks (#588)

* new geo process children hook

* EXPOSE the mat stack

* fix formatting (oops)
This commit is contained in:
jayden 2024-12-28 13:44:36 +00:00 committed by GitHub
parent ff9a2329fb
commit c8faa22072
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 52 additions and 11 deletions

View file

@ -9164,7 +9164,10 @@ HOOK_ON_GEO_PROCESS = 48
HOOK_BEFORE_GEO_PROCESS = 49
--- @type LuaHookedEventType
HOOK_MAX = 50
HOOK_ON_GEO_PROCESS_CHILDREN = 50
--- @type LuaHookedEventType
HOOK_MAX = 51
--- @class LuaModMenuElementType

View file

@ -31,6 +31,16 @@ gCharacters = {}
--- - Index 0 always refers to the local player
gControllers = {}
--- @type Pointer_Mat4[]
--- Matrix stack used during geo process
--- - Only has an effect when used in a geo process hook
gMatStack = {}
--- @type Pointer_Mat4[]
--- Matrix stack used during geo process
--- - Only has an effect when used in a geo process hook
gMatStackPrev = {}
--- @type GlobalTextures
--- Struct containing HUD glyph textures
gTextures = {}

View file

@ -3337,7 +3337,8 @@
| HOOK_ON_DJUI_THEME_CHANGED | 47 |
| HOOK_ON_GEO_PROCESS | 48 |
| HOOK_BEFORE_GEO_PROCESS | 49 |
| HOOK_MAX | 50 |
| HOOK_ON_GEO_PROCESS_CHILDREN | 50 |
| HOOK_MAX | 51 |
### [enum LuaModMenuElementType](#LuaModMenuElementType)
| Identifier | Value |

View file

@ -44,6 +44,20 @@ The `gControllers[]` table is an array from `0` to `(MAX_PLAYERS - 1)` that cont
<br />
## [gMatStack](#gMatStack)
The `gMatStack[]` table is an array from `0` to `(MATRIX_STACK_SIZE - 1)` that contains `Mat4`s used by geo process.
[:arrow_up_small:](#)
<br />
## [gMatStackPrev](#gMatStackPrev)
The `gMatStackPrev[]` table is similar to [gMatStack](#gMatStack) for interpolation.
[:arrow_up_small:](#)
<br />
## [gTextures](#gTextures)
The `gTextures` table contains references to textures. Listed in [GlobalTextures](structs.md#GlobalTextures).
@ -126,7 +140,7 @@ The `gGlobalSyncTable` is a table used for networking. Any field set inside of t
<br />
## [gPlayerSyncTable](#gPlayerSyncTable)
The `gPlayerSyncTable[]` is an array from 0 to `(MAX_PLAYERS - 1)` that is used for networking. Any field set inside of this table is automatically synchronized with all other clients.
The `gPlayerSyncTable[]` is an array from 0 to `(MAX_PLAYERS - 1)` that is used for networking. Any field set inside of this table is automatically synchronized with all other clients.
It is indexed by the local `playerIndex`, so `gPlayerSyncTable[0]` is always for the local player.

View file

@ -43,7 +43,6 @@
*
*/
#define MATRIX_STACK_SIZE 64
#define DISPLAY_LIST_HEAP_SIZE 32000
f32 gProjectionMaxNearValue = 5;
@ -1512,6 +1511,8 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
// processed instead of all children like usual
if (parent != NULL) {
iterateChildren = (parent->type != GRAPH_NODE_TYPE_SWITCH_CASE);
if (parent->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_ON_GEO_PROCESS_CHILDREN, parent, gMatStackIndex);
}
do {
@ -1538,7 +1539,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
}
if (curGraphNode->flags & GRAPH_RENDER_ACTIVE) {
if (curGraphNode->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_BEFORE_GEO_PROCESS, curGraphNode, curGraphNode->hookProcess);
if (curGraphNode->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_BEFORE_GEO_PROCESS, curGraphNode, gMatStackIndex);
if (curGraphNode->flags & GRAPH_RENDER_CHILDREN_FIRST) {
geo_try_process_children(curGraphNode);
} else {
@ -1606,7 +1607,7 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
break;
}
}
if (curGraphNode->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_ON_GEO_PROCESS, curGraphNode, curGraphNode->hookProcess);
if (curGraphNode->hookProcess) smlua_call_event_hooks_graph_node_and_int_param(HOOK_ON_GEO_PROCESS, curGraphNode, gMatStackIndex + 1);
} else {
if (curGraphNode && curGraphNode->type == GRAPH_NODE_TYPE_OBJECT) {
((struct GraphNodeObject *) curGraphNode)->throwMatrix = NULL;

View file

@ -5,6 +5,10 @@
#include "engine/graph_node.h"
#define MATRIX_STACK_SIZE 64
extern Mat4 gMatStack[MATRIX_STACK_SIZE];
extern Mat4 gMatStackPrev[MATRIX_STACK_SIZE];
extern f32 gProjectionMaxNearValue;
extern s16 gProjectionVanillaNearValue;
extern s16 gProjectionVanillaFarValue;

View file

@ -6,6 +6,7 @@
#include "game/first_person_cam.h"
#include "game/hardcoded.h"
#include "game/scroll_targets.h"
#include "game/rendering_graph_node.h"
#include "audio/external.h"
#include "object_fields.h"
#include "pc/djui/djui_hud_utils.h"
@ -663,6 +664,10 @@ void smlua_cobject_init_globals(void) {
EXPOSE_GLOBAL_ARRAY(LOT_CONTROLLER, gControllers, MAX_PLAYERS);
EXPOSE_GLOBAL_ARRAY(LOT_MAT4, gMatStack, MATRIX_STACK_SIZE);
EXPOSE_GLOBAL_ARRAY(LOT_MAT4, gMatStackPrev, MATRIX_STACK_SIZE);
// Structs
EXPOSE_GLOBAL_WITH_NAME(LOT_GLOBALTEXTURES, gGlobalTextures, "gTextures");

View file

@ -3204,7 +3204,8 @@ char gSmluaConstants[] = ""
"HOOK_ON_DJUI_THEME_CHANGED = 47\n"
"HOOK_ON_GEO_PROCESS = 48\n"
"HOOK_BEFORE_GEO_PROCESS = 49\n"
"HOOK_MAX = 50\n"
"HOOK_ON_GEO_PROCESS_CHILDREN = 50\n"
"HOOK_MAX = 51\n"
"ACTION_HOOK_EVERY_FRAME = 0\n"
"ACTION_HOOK_GRAVITY = 1\n"
"ACTION_HOOK_MAX = 2\n"

View file

@ -1049,7 +1049,7 @@ void smlua_call_event_hooks_graph_node_object_and_int_param(enum LuaHookedEventT
}
}
void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hookType, struct GraphNode* node, s32 param) {
void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hookType, struct GraphNode* node, s16 matIndex) {
lua_State* L = gLuaState;
if (L == NULL) { return; }
struct LuaHookedEvent* hook = &sHookedEvents[hookType];
@ -1060,8 +1060,8 @@ void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hoo
// push graph node
smlua_push_object(L, LOT_GRAPHNODE, node);
// push param
lua_pushinteger(L, param);
// push mat index
lua_pushinteger(L, matIndex);
// call the callback
if (0 != smlua_call_hook(L, 2, 0, 0, hook->mod[i])) {

View file

@ -61,6 +61,7 @@ enum LuaHookedEventType {
HOOK_ON_DJUI_THEME_CHANGED,
HOOK_ON_GEO_PROCESS,
HOOK_BEFORE_GEO_PROCESS,
HOOK_ON_GEO_PROCESS_CHILDREN,
HOOK_MAX,
};
@ -115,6 +116,7 @@ static const char* LuaHookedEventTypeName[] = {
"HOOK_ON_DJUI_THEME_CHANGED",
"HOOK_ON_GEO_PROCESS",
"HOOK_BEFORE_GEO_PROCESS",
"HOOK_ON_GEO_PROCESS_CHILDREN",
"HOOK_MAX"
};
@ -191,7 +193,7 @@ bool smlua_call_event_hooks_mario_param_and_int_ret_int(enum LuaHookedEventType
bool smlua_call_event_hooks_mario_param_ret_float(enum LuaHookedEventType hookType, struct MarioState* m, f32* 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);
void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hookType, struct GraphNode* node, s32 param);
void smlua_call_event_hooks_graph_node_and_int_param(enum LuaHookedEventType hookType, struct GraphNode* node, s16 matIndex);
void smlua_call_event_hooks_on_seq_load(enum LuaHookedEventType hookType, u32 player, u32 seqId, s32 loadAsync, s16* returnValue);
const char *smlua_call_event_hooks_int_ret_bool_and_string(enum LuaHookedEventType hookType, s32 param, bool* returnValue);
void smlua_call_event_hooks_string_param(enum LuaHookedEventType hookType, const char* string);