Expose and create some useful functions (#819)

This commit is contained in:
Sunk 2025-05-20 19:40:30 -04:00 committed by GitHub
parent 52759ff981
commit 047adf35bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 145 additions and 17 deletions

View file

@ -5641,6 +5641,12 @@ function update_ledge_climb(m, animation, endAction)
-- ...
end
--- @param m MarioState
--- Makes Mario act like he was popped from a bubble. Useful for custom bubble popping behaviors.
function mario_pop_bubble(m)
-- ...
end
--- @param m MarioState
--- @return integer
--- Checks if Mario should cancel his current automatic action, primarily by detecting if he falls into deep water. If so, transitions him to the water-plunge state
@ -11388,6 +11394,14 @@ function set_find_wall_direction(dir, active, airborne)
-- ...
end
--- @param surf Surface
--- @param src Vec3f
--- @param out Vec3f
--- Gets the closest point of the triangle to `src` and returns it in `out`.
function closest_point_to_triangle(surf, src, out)
-- ...
end
--- Loads the object's collision data into dynamic collision. You must run this every frame in your object's behavior loop for it to have collision
function load_object_collision_model()
-- ...

View file

@ -2018,6 +2018,29 @@ Updates Mario's climb onto a ledge by setting the chosen climbing animation and
<br />
## [mario_pop_bubble](#mario_pop_bubble)
### Description
Makes Mario act like he was popped from a bubble. Useful for custom bubble popping behaviors.
### Lua Example
`mario_pop_bubble(m)`
### Parameters
| Field | Type |
| ----- | ---- |
| m | [MarioState](structs.md#MarioState) |
### Returns
- None
### C Prototype
`void mario_pop_bubble(struct MarioState* m);`
[:arrow_up_small:](#)
<br />
## [check_common_automatic_cancels](#check_common_automatic_cancels)
### Description

View file

@ -6782,6 +6782,31 @@ Sets whether collision finding functions should check wall directions.
<br />
## [closest_point_to_triangle](#closest_point_to_triangle)
### Description
Gets the closest point of the triangle to `src` and returns it in `out`.
### Lua Example
`closest_point_to_triangle(surf, src, out)`
### Parameters
| Field | Type |
| ----- | ---- |
| surf | [Surface](structs.md#Surface) |
| src | [Vec3f](structs.md#Vec3f) |
| out | [Vec3f](structs.md#Vec3f) |
### Returns
- None
### C Prototype
`void closest_point_to_triangle(struct Surface* surf, Vec3f src, Vec3f out);`
[:arrow_up_small:](#)
<br />
---
# functions from surface_load.h

View file

@ -1067,6 +1067,7 @@
- [climb_up_ledge](functions-4.md#climb_up_ledge)
- [update_ledge_climb_camera](functions-4.md#update_ledge_climb_camera)
- [update_ledge_climb](functions-4.md#update_ledge_climb)
- [mario_pop_bubble](functions-4.md#mario_pop_bubble)
- [check_common_automatic_cancels](functions-4.md#check_common_automatic_cancels)
- [mario_execute_automatic_action](functions-4.md#mario_execute_automatic_action)
@ -2050,6 +2051,7 @@
- [find_water_level](functions-6.md#find_water_level)
- [find_poison_gas_level](functions-6.md#find_poison_gas_level)
- [set_find_wall_direction](functions-6.md#set_find_wall_direction)
- [closest_point_to_triangle](functions-6.md#closest_point_to_triangle)
<br />

View file

@ -27,7 +27,7 @@ void set_find_wall_direction(Vec3f dir, bool active, bool airborne) {
gFindWallDirectionAirborne = airborne;
}
static void closest_point_to_triangle(struct Surface* surf, Vec3f src, Vec3f out) {
void closest_point_to_triangle(struct Surface* surf, Vec3f src, Vec3f out) {
Vec3f v1; vec3s_to_vec3f(v1, surf->vertex1);
Vec3f v2; vec3s_to_vec3f(v2, surf->vertex2);
Vec3f v3; vec3s_to_vec3f(v3, surf->vertex3);

View file

@ -84,4 +84,9 @@ Sets whether collision finding functions should check wall directions.
|descriptionEnd| */
void set_find_wall_direction(Vec3f dir, bool active, bool airborne);
/* |description|
Gets the closest point of the triangle to `src` and returns it in `out`.
|descriptionEnd| */
void closest_point_to_triangle(struct Surface* surf, Vec3f src, Vec3f out);
#endif // SURFACE_COLLISION_H

View file

@ -1024,6 +1024,29 @@ static struct MarioState* nearest_antibubble_mario_state_to_object(struct Object
return nearest;
}
/* |description|
Makes Mario act like he was popped from a bubble. Useful for custom bubble popping behaviors.
|descriptionEnd| */
void mario_pop_bubble(struct MarioState* m) {
if (!m) { return; }
m->marioObj->activeFlags &= ~ACTIVE_FLAG_MOVE_THROUGH_GRATE;
m->hurtCounter = 0;
m->healCounter = 31;
m->health = 0x100;
m->marioObj->oIntangibleTimer = 0;
m->peakHeight = m->pos[1];
mario_set_forward_vel(m, 0.0f);
m->vel[1] = 0.0f;
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
m->invincTimer = 30 * 3;
if (m->playerIndex == 0) {
if (m->statusForCamera) { m->statusForCamera->action = m->action; }
soft_reset_camera(m->area->camera);
}
u8 underWater = (m->pos[1] < ((f32)m->waterLevel));
set_mario_action(m, underWater ? ACT_WATER_IDLE : ACT_FREEFALL, 0);
}
s32 act_bubbled(struct MarioState* m) {
if (!m) { return 0; }
if (m->playerIndex == 0 && m->area->camera->mode == CAMERA_MODE_WATER_SURFACE) {
@ -1134,22 +1157,8 @@ s32 act_bubbled(struct MarioState* m) {
// pop bubble
if (m->playerIndex == 0 && distanceToPlayer < 120 && is_player_active(targetMarioState) && m->numLives != -1 && gLocalBubbleCounter == 0) {
m->marioObj->activeFlags &= ~ACTIVE_FLAG_MOVE_THROUGH_GRATE;
m->hurtCounter = 0;
m->healCounter = 31;
m->health = 0x100;
m->marioObj->oIntangibleTimer = 0;
m->peakHeight = m->pos[1];
mario_set_forward_vel(m, 0.0f);
m->vel[1] = 0.0f;
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
m->invincTimer = 30 * 3;
if (m->playerIndex == 0) {
if (m->statusForCamera) { m->statusForCamera->action = m->action; }
soft_reset_camera(m->area->camera);
}
u8 underWater = (m->pos[1] < ((f32)m->waterLevel));
return set_mario_action(m, underWater ? ACT_WATER_IDLE : ACT_FREEFALL, 0);
mario_pop_bubble(m);
return TRUE;
}
return FALSE;

View file

@ -6,5 +6,6 @@
#include "types.h"
s32 mario_execute_automatic_action(struct MarioState *m);
void mario_pop_bubble(struct MarioState* m);
#endif // MARIO_ACTIONS_AUTOMATIC_H

View file

@ -17052,6 +17052,24 @@ int smlua_func_update_ledge_climb(lua_State* L) {
return 1;
}
int smlua_func_mario_pop_bubble(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "mario_pop_bubble", 1, top);
return 0;
}
struct MarioState* m = (struct MarioState*)smlua_to_cobject(L, 1, LOT_MARIOSTATE);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "mario_pop_bubble"); return 0; }
extern void mario_pop_bubble(struct MarioState* m);
mario_pop_bubble(m);
return 1;
}
int smlua_func_check_common_automatic_cancels(lua_State* L) {
if (L == NULL) { return 0; }
@ -33921,6 +33939,35 @@ int smlua_func_set_find_wall_direction(lua_State* L) {
return 1;
}
int smlua_func_closest_point_to_triangle(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", "closest_point_to_triangle", 3, top);
return 0;
}
struct Surface* surf = (struct Surface*)smlua_to_cobject(L, 1, LOT_SURFACE);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "closest_point_to_triangle"); return 0; }
Vec3f src;
smlua_get_vec3f(src, 2);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "closest_point_to_triangle"); return 0; }
Vec3f out;
smlua_get_vec3f(out, 3);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "closest_point_to_triangle"); return 0; }
closest_point_to_triangle(surf, src, out);
smlua_push_vec3f(src, 2);
smlua_push_vec3f(out, 3);
return 1;
}
////////////////////
// surface_load.h //
////////////////////
@ -34988,6 +35035,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "climb_up_ledge", smlua_func_climb_up_ledge);
smlua_bind_function(L, "update_ledge_climb_camera", smlua_func_update_ledge_climb_camera);
smlua_bind_function(L, "update_ledge_climb", smlua_func_update_ledge_climb);
smlua_bind_function(L, "mario_pop_bubble", smlua_func_mario_pop_bubble);
smlua_bind_function(L, "check_common_automatic_cancels", smlua_func_check_common_automatic_cancels);
smlua_bind_function(L, "mario_execute_automatic_action", smlua_func_mario_execute_automatic_action);
@ -35927,6 +35975,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "find_poison_gas_level", smlua_func_find_poison_gas_level);
//smlua_bind_function(L, "find_surface_on_ray", smlua_func_find_surface_on_ray); <--- UNIMPLEMENTED
smlua_bind_function(L, "set_find_wall_direction", smlua_func_set_find_wall_direction);
smlua_bind_function(L, "closest_point_to_triangle", smlua_func_closest_point_to_triangle);
// surface_load.h
smlua_bind_function(L, "load_object_collision_model", smlua_func_load_object_collision_model);