mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-12-05 07:32:52 +00:00
fix apply_platform_displacement (#740)
This commit is contained in:
parent
f22855d21e
commit
26d64ee79d
10 changed files with 102 additions and 45 deletions
|
|
@ -5361,6 +5361,13 @@ function mario_update_wall(m, wcd)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param o Object
|
||||
--- @return MarioState
|
||||
--- Gets the MarioState corresponding to the provided object if the object is a Mario object
|
||||
function get_mario_state_from_object(o)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param m MarioState
|
||||
--- @param frame1 integer
|
||||
--- @param frame2 integer
|
||||
|
|
@ -8734,10 +8741,10 @@ function set_object_respawn_info_bits(obj, bits)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param playerIndex integer
|
||||
--- @param o Object
|
||||
--- @param platform Object
|
||||
--- Apply one frame of platform rotation to Mario (player index) or an object (-1) using the given platform
|
||||
function apply_platform_displacement(playerIndex, platform)
|
||||
--- Apply one frame of platform rotation to the object using the given platform
|
||||
function apply_platform_displacement(o, platform)
|
||||
-- ...
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1253,6 +1253,29 @@ Updates Mario's wall information based on wall collisions (`WallCollisionData`).
|
|||
|
||||
<br />
|
||||
|
||||
## [get_mario_state_from_object](#get_mario_state_from_object)
|
||||
|
||||
### Description
|
||||
Gets the MarioState corresponding to the provided object if the object is a Mario object
|
||||
|
||||
### Lua Example
|
||||
`local MarioStateValue = get_mario_state_from_object(o)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| o | [Object](structs.md#Object) |
|
||||
|
||||
### Returns
|
||||
[MarioState](structs.md#MarioState)
|
||||
|
||||
### C Prototype
|
||||
`struct MarioState *get_mario_state_from_object(struct Object *o);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
---
|
||||
# functions from mario_actions_airborne.c
|
||||
|
||||
|
|
|
|||
|
|
@ -5548,22 +5548,22 @@ Runs an OR operator on the `obj`'s respawn info with `bits` << 8. If `bits` is 0
|
|||
## [apply_platform_displacement](#apply_platform_displacement)
|
||||
|
||||
### Description
|
||||
Apply one frame of platform rotation to Mario (player index) or an object (-1) using the given platform
|
||||
Apply one frame of platform rotation to the object using the given platform
|
||||
|
||||
### Lua Example
|
||||
`apply_platform_displacement(playerIndex, platform)`
|
||||
`apply_platform_displacement(o, platform)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| playerIndex | `integer` |
|
||||
| o | [Object](structs.md#Object) |
|
||||
| platform | [Object](structs.md#Object) |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void apply_platform_displacement(u32 playerIndex, struct Object *platform);`
|
||||
`void apply_platform_displacement(struct Object *o, struct Object *platform);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
|
|
|
|||
|
|
@ -1023,6 +1023,7 @@
|
|||
- [init_single_mario](functions-4.md#init_single_mario)
|
||||
- [set_mario_particle_flags](functions-4.md#set_mario_particle_flags)
|
||||
- [mario_update_wall](functions-4.md#mario_update_wall)
|
||||
- [get_mario_state_from_object](functions-4.md#get_mario_state_from_object)
|
||||
|
||||
<br />
|
||||
|
||||
|
|
|
|||
|
|
@ -1206,7 +1206,7 @@ void bowser_free_update(void) {
|
|||
struct Object *platform;
|
||||
UNUSED f32 floorHeight;
|
||||
if ((platform = o->platform) != NULL)
|
||||
apply_platform_displacement((u32)-1, platform);
|
||||
apply_platform_displacement(o, platform);
|
||||
o->oBowserUnk10E = 0;
|
||||
|
||||
cur_obj_update_floor_and_walls();
|
||||
|
|
|
|||
|
|
@ -2392,3 +2392,14 @@ void mario_update_wall(struct MarioState* m, struct WallCollisionData* wcd) {
|
|||
m->wall->normal.z);
|
||||
}
|
||||
}
|
||||
|
||||
struct MarioState *get_mario_state_from_object(struct Object *o) {
|
||||
if (!o) { return NULL; }
|
||||
for (s32 i = 0; i != MAX_PLAYERS; ++i) {
|
||||
struct MarioState *m = &gMarioStates[i];
|
||||
if (m->marioObj == o) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,4 +300,9 @@ Updates Mario's wall information based on wall collisions (`WallCollisionData`).
|
|||
|descriptionEnd| */
|
||||
void mario_update_wall(struct MarioState* m, struct WallCollisionData* wcd);
|
||||
|
||||
/* |description|
|
||||
Gets the MarioState corresponding to the provided object if the object is a Mario object
|
||||
|descriptionEnd| */
|
||||
struct MarioState *get_mario_state_from_object(struct Object *o);
|
||||
|
||||
#endif // MARIO_H
|
||||
|
|
|
|||
|
|
@ -7,12 +7,9 @@
|
|||
#include "object_helpers.h"
|
||||
#include "object_list_processor.h"
|
||||
#include "platform_displacement.h"
|
||||
#include "mario.h"
|
||||
#include "types.h"
|
||||
|
||||
u16 D_8032FEC0 = 0;
|
||||
|
||||
u32 unused_8032FEC4[4] = { 0 };
|
||||
|
||||
struct Object *gMarioPlatform = NULL;
|
||||
|
||||
/**
|
||||
|
|
@ -89,10 +86,10 @@ void set_mario_pos(struct MarioState* m, f32 x, f32 y, f32 z) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Apply one frame of platform rotation to Mario or an object using the given
|
||||
* platform. If isMario is false, use gCurrentObject.
|
||||
* Apply one frame of platform rotation to an object using the given platform.
|
||||
* If the object is a Mario object, use the corresponding MarioState instead.
|
||||
*/
|
||||
void apply_platform_displacement(u32 playerIndex, struct Object *platform) {
|
||||
void apply_platform_displacement(struct Object *o, struct Object *platform) {
|
||||
f32 x;
|
||||
f32 y;
|
||||
f32 z;
|
||||
|
|
@ -103,37 +100,30 @@ void apply_platform_displacement(u32 playerIndex, struct Object *platform) {
|
|||
Vec3f relativeOffset;
|
||||
Vec3f newObjectOffset;
|
||||
Vec3s rotation;
|
||||
UNUSED s16 unused1;
|
||||
UNUSED s16 unused2;
|
||||
UNUSED s16 unused3;
|
||||
f32 displaceMatrix[4][4];
|
||||
if (!platform) { return; }
|
||||
if (!o || !platform) { return; }
|
||||
|
||||
rotation[0] = platform->oAngleVelPitch;
|
||||
rotation[1] = platform->oAngleVelYaw;
|
||||
rotation[2] = platform->oAngleVelRoll;
|
||||
|
||||
if (playerIndex != (u32)-1) {
|
||||
D_8032FEC0 = 0;
|
||||
x = gMarioStates[playerIndex].pos[0];
|
||||
y = gMarioStates[playerIndex].pos[1];
|
||||
z = gMarioStates[playerIndex].pos[2];
|
||||
struct MarioState *m = get_mario_state_from_object(o);
|
||||
if (m != NULL) {
|
||||
x = m->pos[0];
|
||||
y = m->pos[1];
|
||||
z = m->pos[2];
|
||||
} else {
|
||||
x = gCurrentObject->oPosX;
|
||||
y = gCurrentObject->oPosY;
|
||||
z = gCurrentObject->oPosZ;
|
||||
x = o->oPosX;
|
||||
y = o->oPosY;
|
||||
z = o->oPosZ;
|
||||
}
|
||||
|
||||
x += platform->oVelX;
|
||||
z += platform->oVelZ;
|
||||
|
||||
if (rotation[0] != 0 || rotation[1] != 0 || rotation[2] != 0) {
|
||||
unused1 = rotation[0];
|
||||
unused2 = rotation[2];
|
||||
unused3 = platform->oFaceAngleYaw;
|
||||
|
||||
if (playerIndex != (u32)-1) {
|
||||
gMarioStates[playerIndex].faceAngle[1] += rotation[1];
|
||||
if (m != NULL) {
|
||||
m->faceAngle[1] += rotation[1];
|
||||
}
|
||||
|
||||
platformPosX = platform->oPosX;
|
||||
|
|
@ -163,14 +153,14 @@ void apply_platform_displacement(u32 playerIndex, struct Object *platform) {
|
|||
z = platformPosZ + newObjectOffset[2];
|
||||
}
|
||||
|
||||
if (playerIndex != (u32)-1) {
|
||||
gMarioStates[playerIndex].pos[0] = x;
|
||||
gMarioStates[playerIndex].pos[1] = y;
|
||||
gMarioStates[playerIndex].pos[2] = z;
|
||||
if (m != NULL) {
|
||||
m->pos[0] = x;
|
||||
m->pos[1] = y;
|
||||
m->pos[2] = z;
|
||||
} else {
|
||||
gCurrentObject->oPosX = x;
|
||||
gCurrentObject->oPosY = y;
|
||||
gCurrentObject->oPosZ = z;
|
||||
o->oPosX = x;
|
||||
o->oPosY = y;
|
||||
o->oPosZ = z;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +174,7 @@ void apply_mario_platform_displacement(void) {
|
|||
|
||||
struct Object *platform = player->platform;
|
||||
if (!(gTimeStopState & TIME_STOP_ACTIVE) && player != NULL && platform != NULL) {
|
||||
apply_platform_displacement(i, platform);
|
||||
apply_platform_displacement(player, platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ void update_mario_platform(void);
|
|||
void get_mario_pos(struct MarioState* m, f32 *x, f32 *y, f32 *z);
|
||||
void set_mario_pos(struct MarioState* m, f32 x, f32 y, f32 z);
|
||||
|
||||
/* |description|Apply one frame of platform rotation to Mario (player index) or an object (-1) using the given platform|descriptionEnd| */
|
||||
void apply_platform_displacement(u32 playerIndex, struct Object *platform);
|
||||
/* |description|Apply one frame of platform rotation to the object using the given platform|descriptionEnd| */
|
||||
void apply_platform_displacement(struct Object *o, struct Object *platform);
|
||||
|
||||
void apply_mario_platform_displacement(void);
|
||||
#ifndef VERSION_JP
|
||||
|
|
|
|||
|
|
@ -16549,6 +16549,24 @@ int smlua_func_mario_update_wall(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_get_mario_state_from_object(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", "get_mario_state_from_object", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lua_isnil(L, 1)) { return 0; }
|
||||
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "get_mario_state_from_object"); return 0; }
|
||||
|
||||
smlua_push_object(L, LOT_MARIOSTATE, get_mario_state_from_object(o), NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// mario_actions_airborne.c //
|
||||
//////////////////////////////
|
||||
|
|
@ -27532,13 +27550,14 @@ int smlua_func_apply_platform_displacement(lua_State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
u32 playerIndex = smlua_to_integer(L, 1);
|
||||
if (lua_isnil(L, 1)) { return 0; }
|
||||
struct Object* o = (struct Object*)smlua_to_cobject(L, 1, LOT_OBJECT);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "apply_platform_displacement"); return 0; }
|
||||
if (lua_isnil(L, 2)) { return 0; }
|
||||
struct Object* platform = (struct Object*)smlua_to_cobject(L, 2, LOT_OBJECT);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 2, "apply_platform_displacement"); return 0; }
|
||||
|
||||
apply_platform_displacement(playerIndex, platform);
|
||||
apply_platform_displacement(o, platform);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -34877,6 +34896,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "init_single_mario", smlua_func_init_single_mario);
|
||||
smlua_bind_function(L, "set_mario_particle_flags", smlua_func_set_mario_particle_flags);
|
||||
smlua_bind_function(L, "mario_update_wall", smlua_func_mario_update_wall);
|
||||
smlua_bind_function(L, "get_mario_state_from_object", smlua_func_get_mario_state_from_object);
|
||||
|
||||
// mario_actions_airborne.c
|
||||
smlua_bind_function(L, "play_flip_sounds", smlua_func_play_flip_sounds);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue