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)
/* oActiveParticleFlags */
#define ACTIVE_PARTICLE_NONE (0 << 0) // 0x00000000
#define ACTIVE_PARTICLE_DUST (1 << 0) // 0x00000001
#define ACTIVE_PARTICLE_UNUSED_1 (1 << 1) // 0x00000002
#define ACTIVE_PARTICLE_UNUSED_2 (1 << 2) // 0x00000004

View File

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

View File

@@ -290,7 +290,7 @@ s32 perform_hanging_step(struct MarioState *m, Vec3f nextPos) {
struct WallCollisionData 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);
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;
vec3f_copy(m->pos, nextPos);
m->floor = floor;
m->floorHeight = floorHeight;
m->ceil = ceil;
m->ceilHeight = ceilHeight;
set_mario_floor(m, floor, floorHeight);
set_mario_ceil(m, ceil, ceilHeight);
return HANG_NONE;
}
@@ -830,8 +828,7 @@ s32 act_tornado_twirling(struct MarioState *m) {
floorHeight = find_floor(nextPos[0], nextPos[1], nextPos[2], &floor);
if (floor != NULL) {
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
vec3f_copy(m->pos, nextPos);
} else {
if (nextPos[1] >= m->floorHeight) {

View File

@@ -291,7 +291,7 @@ void apply_slope_accel(struct MarioState *m) {
struct Surface *floor = m->floor;
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)) {
s16 slopeClass = 0;
@@ -356,8 +356,7 @@ void update_shell_speed(struct MarioState *m) {
f32 targetSpeed;
if (m->floorHeight < m->waterLevel) {
m->floorHeight = m->waterLevel;
m->floor = &gWaterSurfacePseudoFloor;
set_mario_floor(m, &gWaterSurfacePseudoFloor, m->waterLevel);
m->floor->originOffset = m->waterLevel; //! Negative origin offset
}
@@ -434,11 +433,6 @@ s32 update_decelerating_speed(struct MarioState *m) {
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) {
f32 maxTargetSpeed;

View File

@@ -87,8 +87,7 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
if (nextPos[1] >= floorHeight) {
if (ceilHeight - nextPos[1] >= 160.0f) {
vec3f_copy(m->pos, nextPos);
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
if (wall != NULL) {
return WATER_STEP_HIT_WALL;
@@ -103,8 +102,7 @@ static u32 perform_water_full_step(struct MarioState *m, Vec3f nextPos) {
//! Water ceiling downwarp
vec3f_set(m->pos, nextPos[0], ceilHeight - 160.0f, nextPos[2]);
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
return WATER_STEP_HIT_CEILING;
} else {
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]);
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
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) {
s16 floorDYaw = m->floorAngle - m->faceAngle[1];
s16 floorDYaw = m->floorYaw - m->faceAngle[1];
if (floorDYaw > -0x4000 && floorDYaw < 0x4000) {
m->forwardVel = 16.0f;
m->faceAngle[1] = m->floorAngle;
m->faceAngle[1] = m->floorYaw;
} else {
m->forwardVel = -16.0f;
m->faceAngle[1] = m->floorAngle + 0x8000;
m->faceAngle[1] = m->floorYaw + 0x8000;
}
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);
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
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]);
m->floor = floor;
m->floorHeight = floorHeight;
if (!SURFACE_IS_QUICKSAND(floor->type) && (floor->type != SURFACE_BURNING)) vec3_copy(m->lastSafePos, m->pos);
set_mario_floor(m, floor, floorHeight);
if (m->wall != NULL) {
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;
if (absWallDYaw > oldWallDYaw) {
oldWallDYaw = absWallDYaw;
m->wall = upperWall.walls[i];
set_mario_wall(m, upperWall.walls[i]);
}
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) {
wallDYaw = atan2s(wallData->walls[i]->normal.z, wallData->walls[i]->normal.x) - m->faceAngle[1];
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;
}
@@ -425,7 +424,7 @@ s32 bonk_or_hit_lava_wall(struct MarioState *m, struct WallCollisionData *wallDa
absWallDYaw = wallDYaw < 0 ? -wallDYaw : wallDYaw;
if (absWallDYaw > oldWallDYaw) {
oldWallDYaw = absWallDYaw;
m->wall = wallData->walls[i];
set_mario_wall(m, wallData->walls[i]);
if (wallDYaw < -0x6000 || wallDYaw > 0x6000) {
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) {
m->pos[0] = nextPos[0];
m->pos[2] = nextPos[2];
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
}
//! 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
if ((stepArg & AIR_STEP_CHECK_LEDGE_GRAB) && upperWall.numWalls == 0) {
for (i = 0; i < lowerWall.numWalls; i++)
if ((grabbedWall = check_ledge_grab(m, grabbedWall, lowerWall.walls[i], intendedPos, nextPos, ledgePos, &ledgeFloor)))
for (i = 0; i < lowerWall.numWalls; i++) {
if ((grabbedWall = check_ledge_grab(m, grabbedWall, lowerWall.walls[i], intendedPos, nextPos, ledgePos, &ledgeFloor))) {
stepResult = AIR_STEP_GRABBED_LEDGE;
if (stepResult == AIR_STEP_GRABBED_LEDGE)
{
}
}
if (stepResult == AIR_STEP_GRABBED_LEDGE) {
vec3f_copy(m->pos, ledgePos);
m->floor = ledgeFloor;
m->floorHeight = ledgePos[1];
m->floorAngle = atan2s(ledgeFloor->normal.z, ledgeFloor->normal.x);
set_mario_floor(m, floor, ledgePos[1]);
m->faceAngle[0] = 0;
m->faceAngle[1] = atan2s(grabbedWall->normal.z, grabbedWall->normal.x) + 0x8000;
}
else {
vec3f_copy(m->pos, nextPos);
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
}
return stepResult;
}
vec3f_copy(m->pos, nextPos);
m->floor = floor;
m->floorHeight = floorHeight;
set_mario_floor(m, floor, floorHeight);
stepResult = bonk_or_hit_lava_wall(m, &upperWall);
if (stepResult != AIR_STEP_NONE)
if (stepResult != AIR_STEP_NONE) {
return stepResult;
}
return bonk_or_hit_lava_wall(m, &lowerWall);
}

View File

@@ -267,7 +267,7 @@ void bhv_mario_update(void) {
u32 particleFlags = 0;
s32 i;
particleFlags = execute_mario_action(gCurrentObject);
particleFlags = execute_mario_action(gMarioState);
gCurrentObject->oMarioParticleFlags = particleFlags;
// 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;
}
farClip = CLAMP(farClip / gWorldScale, 4096, 61440);
if (farClip / farClipDelta != 1)
{
if (farClip / farClipDelta != 1) {
farClipDelta /= farClip;
gWorldScale *= farClipDelta;
}