Skip to content

Commit

Permalink
Match yaw based on BK (#7)
Browse files Browse the repository at this point in the history
* match yaw to BK

* seperate external function protocols to headers

* update symbols
  • Loading branch information
MittenzHugg authored Oct 30, 2024
1 parent 7e45386 commit ffb81de
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 45 deletions.
2 changes: 1 addition & 1 deletion baserom.us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ segments:
- [0x1E75920, c, 1E75920]
- [0x1E75B90, c, 1E75B90]
- [0x1E75BC0, c, 1E75BC0]
- [0x1E75E90, c, 1E75E90]
- [0x1E75E90, c, yaw]
- [0x1E76360, c, 1E76360]
- [0x1E76500, c, 1E76500]
- [0x1E76880, c, 1E76880]
Expand Down
15 changes: 4 additions & 11 deletions include/ba/physics.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef __BA_PHYSICS_H__
#define __BA_PHYSICS_H__

#include "playerstate.h"
#include "anim.h"
#include "playerstate.h"
#include "yaw.h" // for YawType

typedef enum ba_physics_type_e {
BA_PHYSICS_NONE,
Expand All @@ -21,21 +22,13 @@ typedef enum ba_physics_type_e {
BA_PHYSICS_END
} BaPhysicsType;

typedef enum yaw_state_e {
YAW_STATE_0_NONE,
YAW_STATE_1_DEFAULT,
YAW_STATE_2_UNBOUNDED,
YAW_STATE_3_BOUNDED
} YawState;

f32 yaw_getIdeal(PlayerState *thisx);

void baphysics_set_target_yaw(PlayerState *this_x, f32 target_yaw);
f32 baphysics_get_target_horizontal_velocity(PlayerState *self);
void baphysics_set_horizontal_velocity(PlayerState *thisx, f32 yaw, f32 vel);
void baphysics_set_target_horizontal_velocity(PlayerState* thisx, f32 vel);
void baphysics_reset_gravity(PlayerState* thisx);
void func_8009FFD8(PlayerState* thisx, BaAnimUpdateType anim_update_type, YawState yaw_state, s32 arg2, BaPhysicsType arg3);
void yaw_setVelocityBounded(PlayerState* thisx, f32 arg0, f32 arg1);

void func_8009FFD8(PlayerState* thisx, BaAnimUpdateType anim_update_type, YawType yaw_state, s32 arg2, BaPhysicsType arg3);

#endif
14 changes: 13 additions & 1 deletion include/ba/playerstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ typedef enum bs_e {
BS_4C_LANDING_IN_WATER = 0x4C
} BanjoStateId;

typedef struct player_yaw_s {
f32 value;
f32 ideal;
f32 unk8;
s32 update_type;
f32 velocity_degPerSec;
f32 limit_degPerSec;
f32 step_percent;
} PlayerYaw;

typedef struct player_state_s {
u8 pad0[0x15C];
u8 pad0[0xF8];
PlayerYaw *yaw;
u8 unkFC[0x60];
s32 unk15C;
s32 unk160;
s32 unk164;
Expand Down
29 changes: 29 additions & 0 deletions include/ba/yaw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef __BA_YAW_H__
#define __BA_YAW_H__

#include <ultra64.h>
#include "playerstate.h" // for PlayerState

typedef enum yaw_type_e{
YAW_TYPE_0_NONE,
YAW_TYPE_1_DEFAULT,
YAW_TYPE_2_UNBOUNDED,
YAW_TYPE_3_BOUNDED
} YawType;

s32 yaw_size(void);
void yaw_init(PlayerState *self);
void yaw_update(PlayerState *self);
void yaw_setUpdateType(PlayerState *self, YawType type);
void yaw_setIdeal(PlayerState *self, f32 arg1);
void yaw_set(PlayerState *self, f32 arg1);
void yaw_applyIdeal(PlayerState *self);
f32 yaw_get(PlayerState *self);
f32 yaw_getIdeal(PlayerState *self);
void yaw_setVelocityBounded(PlayerState *self, f32 limit_degPerSec, f32 step_percent);
void yaw_setVelocityUnbounded(PlayerState *self, f32 velocity_degPerSec);
void yaw_rotateTimed(PlayerState *self, f32 time_sec);



#endif // __BA_YAW_H__
9 changes: 9 additions & 0 deletions include/core2/1E2B200.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __CORE2_1E2B200_H__
#define __CORE2_1E2B200_H__

#include <ultra64.h>

f32 func_800136E4(f32); // mlNormalizeAngle()
f32 func_80013728(f32); //mlAbsNormalized()

#endif // #define __CORE2_1E2B200_H__
8 changes: 8 additions & 0 deletions include/core2/1EB2840.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __CORE2_1EB2840_H__
#define __CORE2_1EB2840_H__

#include <ultra64.h>

f32 func_800D8FF8(void); //time_getDelta()

#endif // #define __CORE2_1EB2840_H__
8 changes: 8 additions & 0 deletions include/core2/1ECA640.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __CORE2_1ECA640_H__
#define __CORE2_1ECA640_H__

#include <ultra64.h>

f32 func_800F0D50(f32, f32, f32); // mlClamp()

#endif // #define __CORE2_1ECA640_H__
9 changes: 9 additions & 0 deletions include/core2/1ECB9F0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __CORE2_1ECB9F0_H__
#define __CORE2_1ECB9F0_H__

#include <ultra64.h>

f32 mlAbsF(f32);
f32 func_800F212C(f32, f32);

#endif // #define __CORE2_1ECB9F0_H__
10 changes: 10 additions & 0 deletions include/ml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef __ML_H__
#define __ML_H__

#include "ml/mtx.h"

#include "core2/1E2B200.h"
#include "core2/1ECA640.h"
#include "core2/1ECB9F0.h"

#endif // __ML_H__
29 changes: 0 additions & 29 deletions src/core2/1E75E90.c

This file was deleted.

124 changes: 124 additions & 0 deletions src/core2/yaw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@

#include "common.h"

#include "ba/yaw.h"
#include "core2/1EB2840.h"
#include "ml.h"

s32 yaw_size(void){
return sizeof(PlayerYaw);
}

void __yaw_update_limitless(PlayerState *self, f32 velocity_degPerSec) {
f32 dYaw_deg;
f32 sp20;

velocity_degPerSec *= func_800D8FF8();
dYaw_deg = self->yaw->ideal - self->yaw->value;
if (mlAbsF(dYaw_deg) > 180.0f) {
dYaw_deg += (dYaw_deg < 0.0f) ? 360.0f : -360.0f;
}

sp20 = (mlAbsF(dYaw_deg) > 180.0f) ? velocity_degPerSec : ((dYaw_deg < 0.0f)? -velocity_degPerSec: velocity_degPerSec);

if (mlAbsF(sp20) <= mlAbsF(dYaw_deg)) {
self->yaw->value += sp20;
} else {
self->yaw->value = self->yaw->ideal;
}

if (self->yaw->value < 360.0f) {
if (self->yaw->value < 0.0f) {
self->yaw->value = (f32) (self->yaw->value + 360.0f);
}
} else {
self->yaw->value -= 360.0f;
}
}

void __yaw_update_limited(PlayerState *self, f32 limit_degPerSec, f32 step_percent) {
PlayerYaw *pYaw;
f32 val_deg;
f32 dyaw_deg;
f32 dt_s;

dt_s = func_800D8FF8();
pYaw = self->yaw;
dyaw_deg = func_80013728(pYaw->ideal - pYaw->value);

val_deg = dyaw_deg * step_percent;
if (val_deg != 0) {
val_deg = (val_deg < 0) ? func_800F0D50(val_deg, -limit_degPerSec, -3.0f) : func_800F0D50(val_deg, 3.0f, limit_degPerSec);
}
pYaw->unk8 = val_deg;
pYaw->value += func_800F212C(val_deg*dt_s, dyaw_deg);
pYaw->value = func_800136E4(pYaw->value);
}

void yaw_init(PlayerState *self) {
self->yaw->value = 0.0f;
self->yaw->ideal = 0.0f;
yaw_setVelocityBounded(self, 700.0f, 7.5f);
yaw_setVelocityUnbounded(self, 360.0f);
self->yaw->update_type = YAW_TYPE_0_NONE;
yaw_setUpdateType(self, YAW_TYPE_1_DEFAULT);
}

void yaw_update(PlayerState *self) {
switch(self->yaw->update_type) {
case YAW_TYPE_0_NONE:
break;
case YAW_TYPE_1_DEFAULT:
__yaw_update_limited(self, 700.0f, 7.5f);
break;
case YAW_TYPE_2_UNBOUNDED:
__yaw_update_limitless(self, self->yaw->velocity_degPerSec);
break;
case YAW_TYPE_3_BOUNDED:
__yaw_update_limited(self, self->yaw->limit_degPerSec, self->yaw->step_percent);
break;
}
}

void yaw_setUpdateType(PlayerState *self, YawType type) {
self->yaw->update_type = type;
}

void yaw_setIdeal(PlayerState *self, f32 arg1) {
self->yaw->ideal = func_800136E4(arg1);
}

void yaw_set(PlayerState *self, f32 arg1) {
self->yaw->value = func_800136E4(arg1);
}

void yaw_applyIdeal(PlayerState *self) {
self->yaw->value = self->yaw->ideal;
}

f32 yaw_get(PlayerState *self) {
return self->yaw->value;
}

f32 yaw_getIdeal(PlayerState *self) {
return self->yaw->ideal;
}

void yaw_setVelocityBounded(PlayerState *self, f32 limit_degPerSec, f32 step_percent){
self->yaw->limit_degPerSec = limit_degPerSec;
self->yaw->step_percent = step_percent;

}

void yaw_setVelocityUnbounded(PlayerState *self, f32 velocity_degPerSec){
self->yaw->velocity_degPerSec = velocity_degPerSec;
}

void yaw_rotateTimed(PlayerState *self, f32 time_sec) {
f32 dyaw_deg = self->yaw->ideal - self->yaw->value;
if (180.0f < mlAbsF(dyaw_deg)) {
dyaw_deg += (dyaw_deg < 0.0f)? 360.0f: -360.0f;
}

self->yaw->velocity_degPerSec = mlAbsF(dyaw_deg/time_sec);
}
2 changes: 1 addition & 1 deletion src/overlays/bsbeggass/bsbeggass.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// bseggass_init
void bsbeggass_entrypoint_0(PlayerState* arg0){
baanim_playForDuration_onceSmooth(arg0, ASSET_2B_ANIM_BSEGGASS, 1.0f);
func_8009FFD8(arg0, BAANIM_UPDATE_1_NORMAL, YAW_STATE_3_BOUNDED, 1, BA_PHYSICS_LOCKED_ROTATION);
func_8009FFD8(arg0, BAANIM_UPDATE_1_NORMAL, YAW_TYPE_3_BOUNDED, 1, BA_PHYSICS_LOCKED_ROTATION);
yaw_setVelocityBounded(arg0, 350.0f, 14.0f);
baphysics_set_target_horizontal_velocity(arg0, 0.0f);
func_800A0CDC(arg0, 1);
Expand Down
14 changes: 12 additions & 2 deletions symbol_addrs.us.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,18 @@ defragment_overlays = 0x80081BEC;
core2_VRAM_END = 0x80137390;
baphysics_set_target_horizontal_velocity = 0x8009B9B0;
baphysics_reset_gravity = 0x8009BC6C;
yaw_size = 0x8009C5A0;
yaw_init = 0x8009C830;
yaw_update = 0x8009C88C;
yaw_setUpdateType = 0x8009C908;
yaw_setIdeal = 0x8009C914;
yaw_set = 0x8009C944;
yaw_applyIdeal = 0x8009C974;
yaw_get = 0x8009C984;
yaw_getIdeal = 0x8009C990;
yaw_setVelocityBounded = 0x8009C99C;
yaw_setVelocityUnbounded = 0x8009C9B8;
yaw_rotateTimed = 0x8009C9C8;
button_held = 0x800919F4;
animctrl_isAt = 0x8008B348;
animctrl_setStart = 0x8008B24C;
Expand All @@ -153,7 +164,6 @@ button_pressed = 0x80091A58;
baphysics_set_target_yaw = 0x8009B9C0;
baphysics_set_horizontal_velocity = 0x8009BA68;
baphysics_get_target_horizontal_velocity = 0x8009BB00;
yaw_getIdeal = 0x8009C990;
bs_setState = 0x8009E5C8;
bs_getTypeOfJump = 0x8009FE84;
bitfield_get_bit = 0x800D9E60;
Expand Down Expand Up @@ -192,7 +202,7 @@ vector_pop_back_n = 0x800B2EFC;
vector_assign = 0x800B2F18;
vector_defrag = 0x800B2F58;
vector_update_pointers = 0x800B2FB0;
fabsf = 0x800F2100;
mlAbsF = 0x800F2100;

// Actual size is 0x26 without file alignment padding
D_8012D580 = 0x8012D580; // size:0x30
Expand Down

0 comments on commit ffb81de

Please sign in to comment.