Add some fields to MarioState

This commit is contained in:
Arceveti
2021-09-27 10:21:25 -07:00
parent abb6fd286d
commit e71ba07b22
10 changed files with 168 additions and 237 deletions

View File

@@ -97,6 +97,7 @@
OBJ_MOVE_UNDERWATER_ON_GROUND) OBJ_MOVE_UNDERWATER_ON_GROUND)
/* oActiveParticleFlags */ /* oActiveParticleFlags */
#define ACTIVE_PARTICLE_NONE (0 << 0) // 0x00000000
#define ACTIVE_PARTICLE_DUST (1 << 0) // 0x00000001 #define ACTIVE_PARTICLE_DUST (1 << 0) // 0x00000001
#define ACTIVE_PARTICLE_UNUSED_1 (1 << 1) // 0x00000002 #define ACTIVE_PARTICLE_UNUSED_1 (1 << 1) // 0x00000002
#define ACTIVE_PARTICLE_UNUSED_2 (1 << 2) // 0x00000004 #define ACTIVE_PARTICLE_UNUSED_2 (1 << 2) // 0x00000004

View File

@@ -348,7 +348,7 @@ struct MarioState
/*0x68*/ struct Surface *floor; /*0x68*/ struct Surface *floor;
/*0x6C*/ f32 ceilHeight; /*0x6C*/ f32 ceilHeight;
/*0x70*/ f32 floorHeight; /*0x70*/ f32 floorHeight;
/*0x74*/ s16 floorAngle; /*0x74*/ s16 floorYaw;
/*0x76*/ s16 waterLevel; /*0x76*/ s16 waterLevel;
/*0x78*/ struct Object *interactObj; /*0x78*/ struct Object *interactObj;
/*0x7C*/ struct Object *heldObj; /*0x7C*/ struct Object *heldObj;
@@ -364,14 +364,14 @@ struct MarioState
/*0xA4*/ u32 collidedObjInteractTypes; /*0xA4*/ u32 collidedObjInteractTypes;
/*0xA8*/ s16 numCoins; /*0xA8*/ s16 numCoins;
/*0xAA*/ s16 numStars; /*0xAA*/ s16 numStars;
/*0xAC*/ s8 numKeys; // Unused key mechanic /*0xAC*/ s8 numKeys; // Unused key mechanic
/*0xAD*/ s8 numLives; /*0xAD*/ s8 numLives;
/*0xAE*/ s16 health; /*0xAE*/ s16 health;
/*0xB0*/ s16 animYTrans; /*0xB0*/ s16 animYTrans;
/*0xB2*/ u8 hurtCounter; /*0xB2*/ u8 hurtCounter;
/*0xB3*/ u8 healCounter; /*0xB3*/ u8 healCounter;
/*0xB4*/ u8 squishTimer; /*0xB4*/ u8 squishTimer;
/*0xB5*/ u8 fadeWarpOpacity; /*0xB5*/ u8 fadeWarpOpacity;
/*0xB6*/ u16 capTimer; /*0xB6*/ u16 capTimer;
/*0xB8*/ s16 prevNumStarsForDialog; /*0xB8*/ s16 prevNumStarsForDialog;
/*0xBC*/ f32 peakHeight; /*0xBC*/ f32 peakHeight;
@@ -381,6 +381,14 @@ struct MarioState
s16 breath; s16 breath;
u8 breathCounter; u8 breathCounter;
#endif #endif
Vec3f lastSafePos;
Vec3f prevPos;
f32 lateralSpeed;
f32 moveSpeed;
Angle movePitch;
Angle moveYaw;
Angle ceilYaw;
Angle wallYaw;
}; };
#endif // TYPES_H #endif // TYPES_H

File diff suppressed because it is too large Load Diff

View File

@@ -34,6 +34,10 @@ s32 mario_floor_is_slope(struct MarioState *m);
s32 mario_floor_is_steep(struct MarioState *m); s32 mario_floor_is_steep(struct MarioState *m);
f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario); f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario);
s16 find_floor_slope(struct MarioState *m, s16 yawOffset); s16 find_floor_slope(struct MarioState *m, s16 yawOffset);
Bool32 set_mario_wall(struct MarioState *m, struct Surface *wall);
Bool32 set_mario_ceil(struct MarioState *m, struct Surface *ceil, f32 ceilHeight);
Bool32 set_mario_floor(struct MarioState *m, struct Surface *floor, f32 floorHeight);
Bool32 analog_stick_held_back(struct MarioState *m);
void update_mario_sound_and_camera(struct MarioState *m); void update_mario_sound_and_camera(struct MarioState *m);
void set_steep_jump_action(struct MarioState *m); void set_steep_jump_action(struct MarioState *m);
u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg); u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg);
@@ -46,7 +50,7 @@ s32 check_common_hold_action_exits(struct MarioState *m);
s32 transition_submerged_to_walking(struct MarioState *m); s32 transition_submerged_to_walking(struct MarioState *m);
s32 transition_submerged_to_airborne(struct MarioState *m); s32 transition_submerged_to_airborne(struct MarioState *m);
s32 set_water_plunge_action(struct MarioState *m); s32 set_water_plunge_action(struct MarioState *m);
s32 execute_mario_action(UNUSED struct Object *o); s32 execute_mario_action(struct MarioState *m);
void init_mario(void); void init_mario(void);
void init_mario_from_save_file(void); void init_mario_from_save_file(void);

View File

@@ -290,7 +290,7 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
struct WallCollisionData wallCollisionData; struct WallCollisionData wallCollisionData;
resolve_and_return_wall_collisions(nextPos, 50.0f, 50.0f, &wallCollisionData); resolve_and_return_wall_collisions(nextPos, 50.0f, 50.0f, &wallCollisionData);
m->wall = wallCollisionData.numWalls == 0 ? NULL : wallCollisionData.walls[0]; set_mario_wall(m, wallCollisionData.numWalls == 0 ? NULL : wallCollisionData.walls[0]);
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
ceilHeight = find_ceil(nextPos[0], nextPos[1] + 3.0f, nextPos[2], &ceil); ceilHeight = find_ceil(nextPos[0], nextPos[1] + 3.0f, nextPos[2], &ceil);
@@ -319,10 +319,8 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
nextPos[1] = m->ceilHeight - 160.0f; nextPos[1] = m->ceilHeight - 160.0f;
vec3f_copy(m->pos, nextPos); vec3f_copy(m->pos, nextPos);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight; set_mario_ceil(m, ceil, ceilHeight);
m->ceil = ceil;
m->ceilHeight = ceilHeight;
return HANG_NONE; return HANG_NONE;
} }
@@ -830,8 +828,7 @@ s32 act_tornado_twirling(struct MarioState *m) {
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor); floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
if (floor != NULL) { if (floor != NULL) {
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
vec3f_copy(m->pos, nextPos); vec3f_copy(m->pos, nextPos);
} else { } else {
if (nextPos[1] >= m->floorHeight) { if (nextPos[1] >= m->floorHeight) {

View File

@@ -291,7 +291,7 @@ void apply_slope_accel(struct MarioState *m) {
struct Surface *floor = m->floor; struct Surface *floor = m->floor;
f32 steepness = sqrtf(sqr(floor->normal.x) + sqr(floor->normal.z)); f32 steepness = sqrtf(sqr(floor->normal.x) + sqr(floor->normal.z));
s16 floorDYaw = m->floorAngle - m->faceAngle[1]; s16 floorDYaw = m->floorYaw - m->faceAngle[1];
if (mario_floor_is_slope(m)) { if (mario_floor_is_slope(m)) {
s16 slopeClass = 0; s16 slopeClass = 0;
@@ -356,8 +356,7 @@ void update_shell_speed(struct MarioState *m) {
f32 targetSpeed; f32 targetSpeed;
if (m->floorHeight < m->waterLevel) { if (m->floorHeight < m->waterLevel) {
m->floorHeight = m->waterLevel; set_mario_floor(m, &gWaterSurfacePseudoFloor, m->waterLevel);
m->floor = &gWaterSurfacePseudoFloor;
m->floor->originOffset = m->waterLevel; //! Negative origin offset m->floor->originOffset = m->waterLevel; //! Negative origin offset
} }
@@ -434,11 +433,6 @@ s32 update_decelerating_speed(struct MarioState *m) {
return stopped; return stopped;
} }
s32 analog_stick_held_back(struct MarioState *m) {
s16 intendedDYaw = (m->intendedYaw - m->faceAngle[1]);
return ((intendedDYaw < -0x471C) || (intendedDYaw > 0x471C));
}
void update_walking_speed(struct MarioState *m) { void update_walking_speed(struct MarioState *m) {
f32 maxTargetSpeed; f32 maxTargetSpeed;

View File

@@ -87,8 +87,7 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
if (nextPos[1] >= floorHeight) { if (nextPos[1] >= floorHeight) {
if (ceilHeight - nextPos[1] >= 160.0f) { if (ceilHeight - nextPos[1] >= 160.0f) {
vec3f_copy(m->pos, nextPos); vec3f_copy(m->pos, nextPos);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
if (wall != NULL) { if (wall != NULL) {
return WATER_STEP_HIT_WALL; return WATER_STEP_HIT_WALL;
@@ -103,8 +102,7 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
//! Water ceiling downwarp //! Water ceiling downwarp
vec3f_set(m->pos, nextPos[0], ceilHeight - 160.0f, nextPos[2]); vec3f_set(m->pos, nextPos[0], ceilHeight - 160.0f, nextPos[2]);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
return WATER_STEP_HIT_CEILING; return WATER_STEP_HIT_CEILING;
} else { } else {
if (ceilHeight - floorHeight < 160.0f) { if (ceilHeight - floorHeight < 160.0f) {
@@ -112,8 +110,7 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
} }
vec3f_set(m->pos, nextPos[0], floorHeight, nextPos[2]); vec3f_set(m->pos, nextPos[0], floorHeight, nextPos[2]);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
return WATER_STEP_HIT_FLOOR; return WATER_STEP_HIT_FLOOR;
} }
} }

View File

@@ -159,14 +159,14 @@ u32 mario_update_quicksand(struct MarioState *m, f32 sinkingSpeed) {
} }
u32 mario_push_off_steep_floor(struct MarioState *m, u32 action, u32 actionArg) { u32 mario_push_off_steep_floor(struct MarioState *m, u32 action, u32 actionArg) {
s16 floorDYaw = m->floorAngle - m->faceAngle[1]; s16 floorDYaw = m->floorYaw - m->faceAngle[1];
if (floorDYaw > -0x4000 && floorDYaw < 0x4000) { if (floorDYaw > -0x4000 && floorDYaw < 0x4000) {
m->forwardVel = 16.0f; m->forwardVel = 16.0f;
m->faceAngle[1] = m->floorAngle; m->faceAngle[1] = m->floorYaw;
} else { } else {
m->forwardVel = -16.0f; m->forwardVel = -16.0f;
m->faceAngle[1] = m->floorAngle + 0x8000; m->faceAngle[1] = m->floorYaw + 0x8000;
} }
return set_mario_action(m, action, actionArg); return set_mario_action(m, action, actionArg);
@@ -296,8 +296,7 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
} }
vec3f_copy(m->pos, nextPos); vec3f_copy(m->pos, nextPos);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
return GROUND_STEP_LEFT_GROUND; return GROUND_STEP_LEFT_GROUND;
} }
@@ -306,8 +305,8 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
} }
vec3f_set(m->pos, nextPos[0], floorHeight, nextPos[2]); vec3f_set(m->pos, nextPos[0], floorHeight, nextPos[2]);
m->floor = floor; if (!SURFACE_IS_QUICKSAND(floor->type) && (floor->type != SURFACE_BURNING)) vec3_copy(m->lastSafePos, m->pos);
m->floorHeight = floorHeight; set_mario_floor(m, floor, floorHeight);
if (m->wall != NULL) { if (m->wall != NULL) {
oldWallDYaw = atan2s(m->wall->normal.z, m->wall->normal.x) - m->faceAngle[1]; oldWallDYaw = atan2s(m->wall->normal.z, m->wall->normal.x) - m->faceAngle[1];
@@ -320,7 +319,7 @@ static s32 perform_ground_quarter_step(struct MarioState *m, Vec3f nextPos) {
absWallDYaw = wallDYaw < 0 ? -wallDYaw : wallDYaw; absWallDYaw = wallDYaw < 0 ? -wallDYaw : wallDYaw;
if (absWallDYaw > oldWallDYaw) { if (absWallDYaw > oldWallDYaw) {
oldWallDYaw = absWallDYaw; oldWallDYaw = absWallDYaw;
m->wall = upperWall.walls[i]; set_mario_wall(m, upperWall.walls[i]);
} }
if (wallDYaw >= 0x2AAA && wallDYaw <= 0x5555) { if (wallDYaw >= 0x2AAA && wallDYaw <= 0x5555) {
@@ -417,7 +416,7 @@ s32 bonk_or_hit_lava_wall(struct MarioState *m, struct WallCollisionData *wallDa
if (wallData->walls[i] != NULL) { if (wallData->walls[i] != NULL) {
wallDYaw = atan2s(wallData->walls[i]->normal.z, wallData->walls[i]->normal.x) - m->faceAngle[1]; wallDYaw = atan2s(wallData->walls[i]->normal.z, wallData->walls[i]->normal.x) - m->faceAngle[1];
if (wallData->walls[i]->type == SURFACE_BURNING) { if (wallData->walls[i]->type == SURFACE_BURNING) {
m->wall = wallData->walls[i]; set_mario_wall(m, wallData->walls[i]);
return AIR_STEP_HIT_LAVA_WALL; return AIR_STEP_HIT_LAVA_WALL;
} }
@@ -425,7 +424,7 @@ s32 bonk_or_hit_lava_wall(struct MarioState *m, struct WallCollisionData *wallDa
absWallDYaw = wallDYaw < 0 ? -wallDYaw : wallDYaw; absWallDYaw = wallDYaw < 0 ? -wallDYaw : wallDYaw;
if (absWallDYaw > oldWallDYaw) { if (absWallDYaw > oldWallDYaw) {
oldWallDYaw = absWallDYaw; oldWallDYaw = absWallDYaw;
m->wall = wallData->walls[i]; set_mario_wall(m, wallData->walls[i]);
if (wallDYaw < -0x6000 || wallDYaw > 0x6000) { if (wallDYaw < -0x6000 || wallDYaw > 0x6000) {
m->flags |= MARIO_AIR_HIT_WALL; m->flags |= MARIO_AIR_HIT_WALL;
@@ -494,8 +493,7 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
if (ceilHeight - floorHeight > 160.0f) { if (ceilHeight - floorHeight > 160.0f) {
m->pos[0] = nextPos[0]; m->pos[0] = nextPos[0];
m->pos[2] = nextPos[2]; m->pos[2] = nextPos[2];
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
} }
//! When ceilHeight - floorHeight <= 160, the step result says that //! When ceilHeight - floorHeight <= 160, the step result says that
@@ -536,36 +534,31 @@ s32 perform_air_quarter_step(struct MarioState *m, Vec3f intendedPos, u32 stepAr
// misalignment, you can activate these conditions in unexpected situations // misalignment, you can activate these conditions in unexpected situations
if ((stepArg & AIR_STEP_CHECK_LEDGE_GRAB) && upperWall.numWalls == 0) { if ((stepArg & AIR_STEP_CHECK_LEDGE_GRAB) && upperWall.numWalls == 0) {
for (i = 0; i < lowerWall.numWalls; i++) for (i = 0; i < lowerWall.numWalls; i++) {
if ((grabbedWall = check_ledge_grab(m, grabbedWall, lowerWall.walls[i], intendedPos, nextPos, ledgePos, &ledgeFloor))) if ((grabbedWall = check_ledge_grab(m, grabbedWall, lowerWall.walls[i], intendedPos, nextPos, ledgePos, &ledgeFloor))) {
stepResult = AIR_STEP_GRABBED_LEDGE; stepResult = AIR_STEP_GRABBED_LEDGE;
if (stepResult == AIR_STEP_GRABBED_LEDGE) }
{ }
if (stepResult == AIR_STEP_GRABBED_LEDGE) {
vec3f_copy(m->pos, ledgePos); vec3f_copy(m->pos, ledgePos);
m->floor = ledgeFloor; set_mario_floor(m, floor, ledgePos[1]);
m->floorHeight = ledgePos[1];
m->floorAngle = atan2s(ledgeFloor->normal.z, ledgeFloor->normal.x);
m->faceAngle[0] = 0; m->faceAngle[0] = 0;
m->faceAngle[1] = atan2s(grabbedWall->normal.z, grabbedWall->normal.x) + 0x8000; m->faceAngle[1] = atan2s(grabbedWall->normal.z, grabbedWall->normal.x) + 0x8000;
} }
else { else {
vec3f_copy(m->pos, nextPos); vec3f_copy(m->pos, nextPos);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
} }
return stepResult; return stepResult;
} }
vec3f_copy(m->pos, nextPos); vec3f_copy(m->pos, nextPos);
m->floor = floor; set_mario_floor(m, floor, floorHeight);
m->floorHeight = floorHeight;
stepResult = bonk_or_hit_lava_wall(m, &upperWall); stepResult = bonk_or_hit_lava_wall(m, &upperWall);
if (stepResult != AIR_STEP_NONE) if (stepResult != AIR_STEP_NONE) {
return stepResult; return stepResult;
}
return bonk_or_hit_lava_wall(m, &lowerWall); return bonk_or_hit_lava_wall(m, &lowerWall);
} }

View File

@@ -267,7 +267,7 @@ void bhv_mario_update(void) {
u32 particleFlags = 0; u32 particleFlags = 0;
s32 i; s32 i;
particleFlags = execute_mario_action(gCurrentObject); particleFlags = execute_mario_action(gMarioState);
gCurrentObject->oMarioParticleFlags = particleFlags; gCurrentObject->oMarioParticleFlags = particleFlags;
// Mario code updates MarioState's versions of position etc, so we need // Mario code updates MarioState's versions of position etc, so we need

View File

@@ -437,8 +437,7 @@ void geo_process_perspective(struct GraphNodePerspective *node) {
gWorldScale = 1.0f; gWorldScale = 1.0f;
} }
farClip = CLAMP(farClip / gWorldScale, 4096, 61440); farClip = CLAMP(farClip / gWorldScale, 4096, 61440);
if (farClip / farClipDelta != 1) if (farClip / farClipDelta != 1) {
{
farClipDelta /= farClip; farClipDelta /= farClip;
gWorldScale *= farClipDelta; gWorldScale *= farClipDelta;
} }