From a66293b56aed7ef9db678eea1d4dc693965ac1a7 Mon Sep 17 00:00:00 2001 From: PeachyPeach <72323920+PeachyPeachSM64@users.noreply.github.com> Date: Fri, 21 Apr 2023 01:43:37 +0200 Subject: [PATCH] obj_init_animation_with_accel_and_sound + fix collision_find_surface_on_ray parameter names (#352) --- autogen/lua_definitions/functions.lua | 16 +++++++++--- docs/lua/functions-4.md | 32 ++++++++++++++++++++---- docs/lua/functions.md | 1 + src/game/object_helpers.c | 11 ++++++++ src/game/object_helpers.h | 1 + src/pc/lua/smlua_functions_autogen.c | 31 ++++++++++++++++++++--- src/pc/lua/utils/smlua_collision_utils.c | 6 ++--- src/pc/lua/utils/smlua_collision_utils.h | 2 +- 8 files changed, 83 insertions(+), 17 deletions(-) diff --git a/autogen/lua_definitions/functions.lua b/autogen/lua_definitions/functions.lua index 363df1ff..c11aaeea 100644 --- a/autogen/lua_definitions/functions.lua +++ b/autogen/lua_definitions/functions.lua @@ -7366,6 +7366,14 @@ function obj_init_animation(obj, animIndex) -- ... end +--- @param obj Object +--- @param animIndex integer +--- @param accel number +--- @return nil +function obj_init_animation_with_accel_and_sound(obj, animIndex, accel) + -- ... +end + --- @param obj Object --- @return integer function obj_is_hidden(obj) @@ -7990,11 +7998,11 @@ end --- @param startX number --- @param startY number --- @param startZ number ---- @param endX number ---- @param endY number ---- @param endZ number +--- @param dirX number +--- @param dirY number +--- @param dirZ number --- @return RayIntersectionInfo -function collision_find_surface_on_ray(startX, startY, startZ, endX, endY, endZ) +function collision_find_surface_on_ray(startX, startY, startZ, dirX, dirY, dirZ) -- ... end diff --git a/docs/lua/functions-4.md b/docs/lua/functions-4.md index 522f0eff..52a92822 100644 --- a/docs/lua/functions-4.md +++ b/docs/lua/functions-4.md @@ -5299,6 +5299,28 @@
+## [obj_init_animation_with_accel_and_sound](#obj_init_animation_with_accel_and_sound) + +### Lua Example +`obj_init_animation_with_accel_and_sound(obj, animIndex, accel)` + +### Parameters +| Field | Type | +| ----- | ---- | +| obj | [Object](structs.md#Object) | +| animIndex | `integer` | +| accel | `number` | + +### Returns +- None + +### C Prototype +`void obj_init_animation_with_accel_and_sound(struct Object *obj, s32 animIndex, f32 accel);` + +[:arrow_up_small:](#) + +
+ ## [obj_is_hidden](#obj_is_hidden) ### Lua Example @@ -7191,7 +7213,7 @@ ## [collision_find_surface_on_ray](#collision_find_surface_on_ray) ### Lua Example -`local RayIntersectionInfoValue = collision_find_surface_on_ray(startX, startY, startZ, endX, endY, endZ)` +`local RayIntersectionInfoValue = collision_find_surface_on_ray(startX, startY, startZ, dirX, dirY, dirZ)` ### Parameters | Field | Type | @@ -7199,15 +7221,15 @@ | startX | `number` | | startY | `number` | | startZ | `number` | -| endX | `number` | -| endY | `number` | -| endZ | `number` | +| dirX | `number` | +| dirY | `number` | +| dirZ | `number` | ### Returns [RayIntersectionInfo](structs.md#RayIntersectionInfo) ### C Prototype -`struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ);` +`struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ);` [:arrow_up_small:](#) diff --git a/docs/lua/functions.md b/docs/lua/functions.md index 29c6b88c..32f7d1c7 100644 --- a/docs/lua/functions.md +++ b/docs/lua/functions.md @@ -1374,6 +1374,7 @@ - [obj_explode_and_spawn_coins](functions-4.md#obj_explode_and_spawn_coins) - [obj_has_behavior](functions-4.md#obj_has_behavior) - [obj_init_animation](functions-4.md#obj_init_animation) + - [obj_init_animation_with_accel_and_sound](functions-4.md#obj_init_animation_with_accel_and_sound) - [obj_is_hidden](functions-4.md#obj_is_hidden) - [obj_mark_for_deletion](functions-4.md#obj_mark_for_deletion) - [obj_pitch_to_object](functions-4.md#obj_pitch_to_object) diff --git a/src/game/object_helpers.c b/src/game/object_helpers.c index 350b7e01..b5290f3c 100644 --- a/src/game/object_helpers.c +++ b/src/game/object_helpers.c @@ -880,6 +880,17 @@ void cur_obj_init_animation_with_sound(s32 animIndex) { o->oSoundStateID = animIndex; } +void obj_init_animation_with_accel_and_sound(struct Object *obj, s32 animIndex, f32 accel) { + if (obj != NULL) { + struct Animation **anims = obj->oAnimations; + if (anims != NULL) { + s32 animAccel = (s32)(accel * 65536.0f); + geo_obj_init_animation_accel(&obj->header.gfx, &anims[animIndex], animAccel); + } + obj->oSoundStateID = animIndex; + } +} + void cur_obj_init_animation_with_accel_and_sound(s32 animIndex, f32 accel) { struct Animation **anims = o->oAnimations; if (anims != NULL) { diff --git a/src/game/object_helpers.h b/src/game/object_helpers.h index 83c8c531..1ff092cd 100644 --- a/src/game/object_helpers.h +++ b/src/game/object_helpers.h @@ -135,6 +135,7 @@ void obj_scale_xyz(struct Object* obj, f32 xScale, f32 yScale, f32 zScale); void obj_scale(struct Object *obj, f32 scale); void cur_obj_scale(f32 scale); void cur_obj_init_animation_with_sound(s32 animIndex); +void obj_init_animation_with_accel_and_sound(struct Object *obj, s32 animIndex, f32 accel); void cur_obj_init_animation_with_accel_and_sound(s32 animIndex, f32 accel); void cur_obj_init_animation(s32 animIndex); void obj_init_animation_with_sound(struct Object *obj, const struct Animation * const* animations, s32 animIndex); diff --git a/src/pc/lua/smlua_functions_autogen.c b/src/pc/lua/smlua_functions_autogen.c index 926a7fa2..803203ff 100644 --- a/src/pc/lua/smlua_functions_autogen.c +++ b/src/pc/lua/smlua_functions_autogen.c @@ -24343,6 +24343,28 @@ int smlua_func_obj_init_animation(lua_State* L) { return 1; } +int smlua_func_obj_init_animation_with_accel_and_sound(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_init_animation_with_accel_and_sound", 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_init_animation_with_accel_and_sound"); return 0; } + s32 animIndex = smlua_to_integer(L, 2); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "obj_init_animation_with_accel_and_sound"); return 0; } + f32 accel = smlua_to_number(L, 3); + if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "obj_init_animation_with_accel_and_sound"); return 0; } + + extern void obj_init_animation_with_accel_and_sound(struct Object *obj, s32 animIndex, f32 accel); + obj_init_animation_with_accel_and_sound(obj, animIndex, accel); + + return 1; +} + /* int smlua_func_obj_init_animation_with_sound(lua_State* L) { if (L == NULL) { return 0; } @@ -26213,14 +26235,14 @@ int smlua_func_collision_find_surface_on_ray(lua_State* L) { if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "collision_find_surface_on_ray"); return 0; } f32 startZ = smlua_to_number(L, 3); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 3, "collision_find_surface_on_ray"); return 0; } - f32 endX = smlua_to_number(L, 4); + f32 dirX = smlua_to_number(L, 4); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 4, "collision_find_surface_on_ray"); return 0; } - f32 endY = smlua_to_number(L, 5); + f32 dirY = smlua_to_number(L, 5); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 5, "collision_find_surface_on_ray"); return 0; } - f32 endZ = smlua_to_number(L, 6); + f32 dirZ = smlua_to_number(L, 6); if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 6, "collision_find_surface_on_ray"); return 0; } - smlua_push_object(L, LOT_RAYINTERSECTIONINFO, collision_find_surface_on_ray(startX, startY, startZ, endX, endY, endZ)); + smlua_push_object(L, LOT_RAYINTERSECTIONINFO, collision_find_surface_on_ray(startX, startY, startZ, dirX, dirY, dirZ)); return 1; } @@ -30470,6 +30492,7 @@ void smlua_bind_functions_autogen(void) { smlua_bind_function(L, "obj_explode_and_spawn_coins", smlua_func_obj_explode_and_spawn_coins); smlua_bind_function(L, "obj_has_behavior", smlua_func_obj_has_behavior); smlua_bind_function(L, "obj_init_animation", smlua_func_obj_init_animation); + smlua_bind_function(L, "obj_init_animation_with_accel_and_sound", smlua_func_obj_init_animation_with_accel_and_sound); //smlua_bind_function(L, "obj_init_animation_with_sound", smlua_func_obj_init_animation_with_sound); <--- UNIMPLEMENTED smlua_bind_function(L, "obj_is_hidden", smlua_func_obj_is_hidden); smlua_bind_function(L, "obj_mark_for_deletion", smlua_func_obj_mark_for_deletion); diff --git a/src/pc/lua/utils/smlua_collision_utils.c b/src/pc/lua/utils/smlua_collision_utils.c index a078550b..e867e1e2 100644 --- a/src/pc/lua/utils/smlua_collision_utils.c +++ b/src/pc/lua/utils/smlua_collision_utils.c @@ -156,11 +156,11 @@ struct GlobalObjectCollisionData gGlobalObjectCollisionData = { .wooden_signpost_seg3_collision_0302DD80 = (Collision*) wooden_signpost_seg3_collision_0302DD80, }; -struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ) { +struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ) { static struct RayIntersectionInfo info = { 0 }; Vec3f orig = { startX, startY, startZ }; - Vec3f end = { endX, endY, endZ }; - find_surface_on_ray(orig, end, &info.surface, info.hitPos); + Vec3f dir = { dirX, dirY, dirZ }; + find_surface_on_ray(orig, dir, &info.surface, info.hitPos); return &info; } diff --git a/src/pc/lua/utils/smlua_collision_utils.h b/src/pc/lua/utils/smlua_collision_utils.h index 87e95479..8430f957 100644 --- a/src/pc/lua/utils/smlua_collision_utils.h +++ b/src/pc/lua/utils/smlua_collision_utils.h @@ -112,7 +112,7 @@ struct GlobalObjectCollisionData { extern struct GlobalObjectCollisionData gGlobalObjectCollisionData; -struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 endX, f32 endY, f32 endZ); +struct RayIntersectionInfo* collision_find_surface_on_ray(f32 startX, f32 startY, f32 startZ, f32 dirX, f32 dirY, f32 dirZ); struct Surface* get_water_surface_pseudo_floor(void);