Add some fields to MarioState

This commit is contained in:
Arceveti committed 2021-09-27 10:21:25 -07:00
1 parent abb6fd286d
commit e71ba07b22
10 files changed
+168 -237

No files matched your search

+116 -178
View File
@@ -178,8 +178,7 @@ s32 is_anim_past_frame(struct MarioState *m, s16 animFrame) {
* and returns the animation's flags.
*/
s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s translation) {
f32 dx;
f32 dz;
f32 dx, dz;
struct Animation *curAnim = (void *) obj->header.gfx.animInfo.curAnim;
s16 animFrame = geo_update_animation_frame(&obj->header.gfx.animInfo, NULL);
@@ -193,7 +192,7 @@ s16 find_mario_anim_flags_and_translation(struct Object *obj, s32 yaw, Vec3s tra
translation[1] = *(animValues + (retrieve_animation_index(animFrame, &animIndex))) / 4.0f;
dz = *(animValues + (retrieve_animation_index(animFrame, &animIndex))) / 4.0f;
translation[0] = (dx * c) + (dz * s);
translation[0] = ( dx * c) + (dz * s);
translation[2] = (-dx * s) + (dz * c);
return curAnim->flags;
@@ -524,9 +523,7 @@ s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw) {
if (turnYaw && m->forwardVel < 0.0f) {
faceAngleYaw += 0x8000;
}
faceAngleYaw = m->floorAngle - faceAngleYaw;
faceAngleYaw = m->floorYaw - faceAngleYaw;
return (-0x4000 < faceAngleYaw) && (faceAngleYaw < 0x4000);
}
@@ -536,28 +533,15 @@ s32 mario_facing_downhill(struct MarioState *m, s32 turnYaw) {
u32 mario_floor_is_slippery(struct MarioState *m) {
f32 normY;
if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE
&& m->floor->normal.y < 0.9998477f //~cos(1 deg)
) {
if ((m->area->terrainType & TERRAIN_MASK) == TERRAIN_SLIDE && m->floor->normal.y < 0.9998477f) { //~cos(1 deg)
return TRUE;
}
switch (mario_get_floor_class(m)) {
case SURFACE_VERY_SLIPPERY:
normY = 0.9848077f; //~cos(10 deg)
break;
case SURFACE_SLIPPERY:
normY = 0.9396926f; //~cos(20 deg)
break;
default:
normY = 0.7880108f; //~cos(38 deg)
break;
case SURFACE_NOT_SLIPPERY:
normY = 0.0f;
break;
case SURFACE_VERY_SLIPPERY: normY = 0.9848077f; break; //~cos(10 deg)
case SURFACE_SLIPPERY: normY = 0.9396926f; break; //~cos(20 deg)
default: normY = 0.7880108f; break; //~cos(38 deg)
case SURFACE_NOT_SLIPPERY: normY = 0.0f; break;
}
return m->floor->normal.y <= normY;
@@ -575,21 +559,10 @@ s32 mario_floor_is_slope(struct MarioState *m) {
}
switch (mario_get_floor_class(m)) {
case SURFACE_VERY_SLIPPERY:
normY = 0.9961947f; // ~cos(5 deg)
break;
case SURFACE_SLIPPERY:
normY = 0.9848077f; // ~cos(10 deg)
break;
default:
normY = 0.9659258f; // ~cos(15 deg)
break;
case SURFACE_NOT_SLIPPERY:
normY = 0.9396926f; // ~cos(20 deg)
break;
case SURFACE_VERY_SLIPPERY: normY = 0.9961947f; break; // ~cos(5 deg)
case SURFACE_SLIPPERY: normY = 0.9848077f; break; // ~cos(10 deg)
default: normY = 0.9659258f; break; // ~cos(15 deg)
case SURFACE_NOT_SLIPPERY: normY = 0.9396926f; break; // ~cos(20 deg)
}
return m->floor->normal.y <= normY;
@@ -613,21 +586,10 @@ s32 mario_floor_is_steep(struct MarioState *m) {
// This does not matter in vanilla game practice.
if (!mario_facing_downhill(m, FALSE)) {
switch (mario_get_floor_class(m)) {
case SURFACE_VERY_SLIPPERY:
normY = 0.9659258f; // ~cos(15 deg)
break;
case SURFACE_SLIPPERY:
normY = 0.9396926f; // ~cos(20 deg)
break;
default:
normY = 0.8660254f; // ~cos(30 deg)
break;
case SURFACE_NOT_SLIPPERY:
normY = 0.8660254f; // ~cos(30 deg)
break;
case SURFACE_VERY_SLIPPERY: normY = 0.9659258f; break; // ~cos(15 deg)
case SURFACE_SLIPPERY: normY = 0.9396926f; break; // ~cos(20 deg)
default: normY = 0.8660254f; break; // ~cos(30 deg)
case SURFACE_NOT_SLIPPERY: normY = 0.8660254f; break; // ~cos(30 deg)
}
result = m->floor->normal.y <= normY;
@@ -641,14 +603,11 @@ s32 mario_floor_is_steep(struct MarioState *m) {
*/
f32 find_floor_height_relative_polar(struct MarioState *m, s16 angleFromMario, f32 distFromMario) {
struct Surface *floor;
f32 floorY;
f32 y = sins(m->faceAngle[1] + angleFromMario) * distFromMario;
f32 x = coss(m->faceAngle[1] + angleFromMario) * distFromMario;
floorY = find_floor(m->pos[0] + y, m->pos[1] + 100.0f, m->pos[2] + x, &floor);
return floorY;
return find_floor(m->pos[0] + y, m->pos[1] + 100.0f, m->pos[2] + x, &floor);
}
/**
@@ -668,19 +627,21 @@ s16 find_floor_slope(struct MarioState *m, s16 yawOffset) {
backwardFloorY = get_surface_height_at_location((m->pos[0] - x), (m->pos[2] - z), floor);
} else {
forwardFloorY = find_floor((m->pos[0] + x), (m->pos[1] + 100.0f), (m->pos[2] + z), &floor);
if (floor == NULL) forwardFloorY = m->floorHeight; // handle OOB slopes
backwardFloorY = find_floor((m->pos[0] - x), (m->pos[1] + 100.0f), (m->pos[2] - z), &floor);
if (floor == NULL) backwardFloorY = m->floorHeight; // handle OOB slopes
}
#else
forwardFloorY = find_floor((m->pos[0] + x), (m->pos[1] + 100.0f), (m->pos[2] + z), &floor);
if (floor == NULL) forwardFloorY = m->floorHeight; // handle OOB slopes
backwardFloorY = find_floor((m->pos[0] - x), (m->pos[1] + 100.0f), (m->pos[2] - z), &floor);
if (floor == NULL) backwardFloorY = m->floorHeight; // handle OOB slopes
#endif
//! If Mario is near OOB, these floorY's can sometimes be -11000.
// This will cause these to be off and give improper slopes.
forwardYDelta = forwardFloorY - m->pos[1];
backwardYDelta = m->pos[1] - backwardFloorY;
if (forwardYDelta * forwardYDelta < backwardYDelta * backwardYDelta) {
if (sqr(forwardYDelta) < sqr(backwardYDelta)) {
result = atan2s(5.0f, forwardYDelta);
} else {
result = atan2s(5.0f, backwardYDelta);
@@ -689,6 +650,32 @@ s16 find_floor_slope(struct MarioState *m, s16 yawOffset) {
return result;
}
Bool32 set_mario_wall(struct MarioState *m, struct Surface *wall) {
if (m->wall != wall) {
m->wall = wall;
if (m->wall != NULL) m->wallYaw = SURFACE_YAW(wall);
}
return (m->wall != NULL);
}
Bool32 set_mario_ceil(struct MarioState *m, struct Surface *ceil, f32 ceilHeight) {
if (m->ceil != ceil) {
m->ceil = ceil;
if (m->ceil != NULL) m->ceilYaw = SURFACE_YAW(ceil);
}
m->ceilHeight = ceilHeight;
return (m->ceil != NULL);
}
Bool32 set_mario_floor(struct MarioState *m, struct Surface *floor, f32 floorHeight) {
if (m->floor != floor) {
m->floor = floor;
if (m->floor != NULL) m->floorYaw = SURFACE_YAW(floor);
}
m->floorHeight = floorHeight;
return (m->floor != NULL);
}
/**
* Adjusts Mario's camera and sound based on his action status.
*/
@@ -720,8 +707,8 @@ void set_steep_jump_action(struct MarioState *m) {
if (m->forwardVel > 0.0f) {
//! ((s16)0x8000) has undefined behavior. Therefore, this downcast has
// undefined behavior if m->floorAngle >= 0.
s16 angleTemp = m->floorAngle + 0x8000;
// undefined behavior if m->floorYaw >= 0.
s16 angleTemp = m->floorYaw + 0x8000;
s16 faceAngleTemp = m->faceAngle[1] - angleTemp;
f32 y = sins(faceAngleTemp) * m->forwardVel;
@@ -955,21 +942,10 @@ static u32 set_mario_action_cutscene(struct MarioState *m, u32 action, UNUSED u3
*/
u32 set_mario_action(struct MarioState *m, u32 action, u32 actionArg) {
switch (action & ACT_GROUP_MASK) {
case ACT_GROUP_MOVING:
action = set_mario_action_moving(m, action, actionArg);
break;
case ACT_GROUP_AIRBORNE:
action = set_mario_action_airborne(m, action, actionArg);
break;
case ACT_GROUP_SUBMERGED:
action = set_mario_action_submerged(m, action, actionArg);
break;
case ACT_GROUP_CUTSCENE:
action = set_mario_action_cutscene(m, action, actionArg);
break;
case ACT_GROUP_MOVING: action = set_mario_action_moving (m, action, actionArg); break;
case ACT_GROUP_AIRBORNE: action = set_mario_action_airborne (m, action, actionArg); break;
case ACT_GROUP_SUBMERGED: action = set_mario_action_submerged(m, action, actionArg); break;
case ACT_GROUP_CUTSCENE: action = set_mario_action_cutscene (m, action, actionArg); break;
}
// Resets the sound played flags, meaning Mario can play those sound types again.
@@ -1111,19 +1087,10 @@ s32 check_common_action_exits(struct MarioState *m) {
* object holding actions. A holding variant of the above function.
*/
s32 check_common_hold_action_exits(struct MarioState *m) {
if (m->input & INPUT_A_PRESSED) {
return set_mario_action(m, ACT_HOLD_JUMP, 0);
}
if (m->input & INPUT_OFF_FLOOR) {
return set_mario_action(m, ACT_HOLD_FREEFALL, 0);
}
if (m->input & INPUT_NONZERO_ANALOG) {
return set_mario_action(m, ACT_HOLD_WALKING, 0);
}
if (m->input & INPUT_ABOVE_SLIDE) {
return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);
}
if (m->input & INPUT_A_PRESSED ) return set_mario_action(m, ACT_HOLD_JUMP, 0);
if (m->input & INPUT_OFF_FLOOR ) return set_mario_action(m, ACT_HOLD_FREEFALL, 0);
if (m->input & INPUT_NONZERO_ANALOG) return set_mario_action(m, ACT_HOLD_WALKING, 0);
if (m->input & INPUT_ABOVE_SLIDE ) return set_mario_action(m, ACT_HOLD_BEGIN_SLIDING, 0);
return FALSE;
}
@@ -1149,7 +1116,7 @@ s32 transition_submerged_to_walking(struct MarioState *m) {
s32 transition_submerged_to_airborne(struct MarioState *m) {
set_camera_mode(m->area->camera, m->area->camera->defMode, 1);
vec3s_set(m->angleVel, 0, 0, 0);
vec3_zero(m->angleVel);
if (m->heldObj == NULL) {
if (m->input & INPUT_A_DOWN) return set_mario_action(m, ACT_DIVE, 0);
@@ -1173,7 +1140,7 @@ s32 set_water_plunge_action(struct MarioState *m) {
m->faceAngle[2] = 0;
vec3s_set(m->angleVel, 0, 0, 0);
vec3_zero(m->angleVel);
if (!(m->action & ACT_FLAG_DIVING)) {
m->faceAngle[0] = 0;
@@ -1307,6 +1274,11 @@ void update_mario_joystick_inputs(struct MarioState *m) {
}
}
Bool32 analog_stick_held_back(struct MarioState *m) {
s16 intendedDYaw = (m->intendedYaw - m->faceAngle[1]);
return ((intendedDYaw < -0x471C) || (intendedDYaw > 0x471C));
}
/**
* Resolves wall collisions, and updates a variety of inputs.
*/
@@ -1333,7 +1305,7 @@ void update_mario_geometry_inputs(struct MarioState *m) {
m->waterLevel = find_water_level(m->pos[0], m->pos[2]);
if (m->floor != NULL) {
m->floorAngle = atan2s(m->floor->normal.z, m->floor->normal.x);
m->floorYaw = atan2s(m->floor->normal.z, m->floor->normal.x);
m->terrainSoundAddend = mario_get_terrain_sound_addend(m);
if ((m->pos[1] > m->waterLevel - 40) && mario_floor_is_slippery(m)) {
@@ -1375,13 +1347,12 @@ void update_mario_inputs(struct MarioState *m) {
m->collidedObjInteractTypes = m->marioObj->collidedObjInteractTypes;
m->flags &= 0xFFFFFF;
#ifdef PUPPYCAM
if (gPuppyCam.mode3Flags & PUPPYCAM_MODE3_ENTER_FIRST_PERSON || (gPuppyCam.flags & PUPPYCAM_BEHAVIOUR_FREE && gPuppyCam.debugFlags & PUPPYDEBUG_LOCK_CONTROLS))
{
#ifdef PUPPYCAM
if (gPuppyCam.mode3Flags & PUPPYCAM_MODE3_ENTER_FIRST_PERSON || (gPuppyCam.flags & PUPPYCAM_BEHAVIOUR_FREE && gPuppyCam.debugFlags & PUPPYDEBUG_LOCK_CONTROLS)) {
m->input = INPUT_FIRST_PERSON;
return;
}
#endif
#endif
update_mario_button_inputs(m);
update_mario_joystick_inputs(m);
@@ -1460,7 +1431,6 @@ void set_submerged_cam_preset_and_spawn_bubbles(struct MarioState *m) {
*/
void update_mario_health(struct MarioState *m) {
s32 terrainIsSnow;
if (m->health >= 0x100) {
// When already healing or hurting Mario, Mario's HP is not changed any more here.
if (((u32) m->healCounter | (u32) m->hurtCounter) == 0) {
@@ -1497,12 +1467,8 @@ void update_mario_health(struct MarioState *m) {
m->hurtCounter--;
}
if (m->health > 0x880) {
m->health = 0x880;
}
if (m->health < 0x100) {
m->health = 0xFF;
}
if (m->health > 0x880) m->health = 0x880;
if (m->health < 0x100) m->health = 0xFF;
#ifndef BREATH_METER
// Play a noise to alert the player when Mario is close to drowning.
if (((m->action & ACT_GROUP_MASK) == ACT_GROUP_SUBMERGED) && (m->health < 0x300)) {
@@ -1548,6 +1514,7 @@ void update_mario_breath(struct MarioState *m) {
}
if (m->breath > 0x880) m->breath = 0x880;
if (m->breath < 0x100) {
// If breath is "zero", set health to "zero"
m->breath = 0xFF;
m->health = 0xFF;
}
@@ -1598,13 +1565,12 @@ void sink_mario_in_quicksand(struct MarioState *m) {
}
/**
* Is a binary representation of the frames to flicker Mario's cap when the timer
* is running out.
*
* Is a binary representation of the frames to flicker Mario's cap when the timer is running out.
* 0x4444449249255555
* Equals [1000]^5 . [100]^8 . [10]^9 . [1] in binary, which is
* 100010001000100010001001001001001001001001001010101010101010101.
*/
u64 sCapFlickerFrames = 0x4444449249255555;
u64 sCapFlickerFrames = 0b100010001000100010001001001001001001001001001010101010101010101;
/**
* Updates the cap flags mainly based on the cap timer.
@@ -1739,97 +1705,79 @@ void queue_rumble_particles(void) {
#endif
/**
* Main function for executing Mario's behavior.
* Main function for executing Mario's behavior. Returns particleFlags.
*/
s32 execute_mario_action(UNUSED struct Object *o) {
s32 execute_mario_action(struct MarioState *m) {
s32 inLoop = TRUE;
if (gMarioState->action) {
gMarioState->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
mario_reset_bodystate(gMarioState);
update_mario_inputs(gMarioState);
// Updates once per frame:
vec3f_get_dist_and_lateral_dist_and_angle(m->prevPos, m->pos, &m->moveSpeed, &m->lateralSpeed, &m->movePitch, &m->moveYaw);
vec3_copy(m->prevPos, m->pos);
if (m->action) {
m->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE;
mario_reset_bodystate(m);
update_mario_inputs(m);
#ifdef PUPPYCAM
if (!(gPuppyCam.flags & PUPPYCAM_BEHAVIOUR_FREE))
#endif
mario_handle_special_floors(gMarioState);
mario_process_interactions(gMarioState);
mario_handle_special_floors(m);
mario_process_interactions(m);
// If Mario is OOB, stop executing actions.
if (gMarioState->floor == NULL) {
return 0;
if (m->floor == NULL) {
return ACTIVE_PARTICLE_NONE;
}
// The function can loop through many action shifts in one frame,
// which can lead to unexpected sub-frame behavior. Could potentially hang
// if a loop of actions were found, but there has not been a situation found.
while (inLoop) {
switch (gMarioState->action & ACT_GROUP_MASK) {
case ACT_GROUP_STATIONARY:
inLoop = mario_execute_stationary_action(gMarioState);
break;
case ACT_GROUP_MOVING:
inLoop = mario_execute_moving_action(gMarioState);
break;
case ACT_GROUP_AIRBORNE:
inLoop = mario_execute_airborne_action(gMarioState);
break;
case ACT_GROUP_SUBMERGED:
inLoop = mario_execute_submerged_action(gMarioState);
break;
case ACT_GROUP_CUTSCENE:
inLoop = mario_execute_cutscene_action(gMarioState);
break;
case ACT_GROUP_AUTOMATIC:
inLoop = mario_execute_automatic_action(gMarioState);
break;
case ACT_GROUP_OBJECT:
inLoop = mario_execute_object_action(gMarioState);
break;
switch (m->action & ACT_GROUP_MASK) {
case ACT_GROUP_STATIONARY: inLoop = mario_execute_stationary_action(m); break;
case ACT_GROUP_MOVING: inLoop = mario_execute_moving_action (m); break;
case ACT_GROUP_AIRBORNE: inLoop = mario_execute_airborne_action (m); break;
case ACT_GROUP_SUBMERGED: inLoop = mario_execute_submerged_action (m); break;
case ACT_GROUP_CUTSCENE: inLoop = mario_execute_cutscene_action (m); break;
case ACT_GROUP_AUTOMATIC: inLoop = mario_execute_automatic_action (m); break;
case ACT_GROUP_OBJECT: inLoop = mario_execute_object_action (m); break;
}
}
sink_mario_in_quicksand(gMarioState);
squish_mario_model(gMarioState);
set_submerged_cam_preset_and_spawn_bubbles(gMarioState);
update_mario_health(gMarioState);
sink_mario_in_quicksand(m);
squish_mario_model(m);
set_submerged_cam_preset_and_spawn_bubbles(m);
update_mario_health(m);
#ifdef BREATH_METER
update_mario_breath(gMarioState);
update_mario_breath(m);
#endif
update_mario_info_for_cam(gMarioState);
mario_update_hitbox_and_cap_model(gMarioState);
update_mario_info_for_cam(m);
mario_update_hitbox_and_cap_model(m);
// Both of the wind handling portions play wind audio only in
// non-Japanese releases.
if (gMarioState->floor->type == SURFACE_HORIZONTAL_WIND) {
spawn_wind_particles(0, (gMarioState->floor->force << 8));
if (m->floor->type == SURFACE_HORIZONTAL_WIND) {
spawn_wind_particles(0, (m->floor->force << 8));
#ifndef VERSION_JP
play_sound(SOUND_ENV_WIND2, gMarioState->marioObj->header.gfx.cameraToObject);
play_sound(SOUND_ENV_WIND2, m->marioObj->header.gfx.cameraToObject);
#endif
}
if (gMarioState->floor->type == SURFACE_VERTICAL_WIND) {
if (m->floor->type == SURFACE_VERTICAL_WIND) {
spawn_wind_particles(1, 0);
#ifndef VERSION_JP
play_sound(SOUND_ENV_WIND2, gMarioState->marioObj->header.gfx.cameraToObject);
play_sound(SOUND_ENV_WIND2, m->marioObj->header.gfx.cameraToObject);
#endif
}
play_infinite_stairs_music();
gMarioState->marioObj->oInteractStatus = 0;
m->marioObj->oInteractStatus = 0;
#if ENABLE_RUMBLE
queue_rumble_particles();
#endif
return gMarioState->particleFlags;
return m->particleFlags;
}
return 0;
return ACTIVE_PARTICLE_NONE;
}
/**************************************************
@@ -1873,6 +1821,7 @@ void init_mario(void) {
vec3_copy(gMarioState->faceAngle, gMarioSpawnInfo->startAngle);
vec3_zero(gMarioState->angleVel);
vec3_copy(gMarioState->pos, gMarioSpawnInfo->startPos);
vec3_copy(gMarioState->prevPos, gMarioState->pos);
vec3_zero(gMarioState->vel);
gMarioState->floorHeight = find_floor(gMarioState->pos[0], gMarioState->pos[1], gMarioState->pos[2], &gMarioState->floor);
@@ -1882,33 +1831,22 @@ void init_mario(void) {
gMarioState->marioObj->header.gfx.pos[1] = gMarioState->pos[1];
gMarioState->action =
(gMarioState->pos[1] <= (gMarioState->waterLevel - 100)) ? ACT_WATER_IDLE : ACT_IDLE;
gMarioState->action = (gMarioState->pos[1] <= (gMarioState->waterLevel - 100)) ? ACT_WATER_IDLE : ACT_IDLE;
mario_reset_bodystate(gMarioState);
update_mario_info_for_cam(gMarioState);
gMarioState->marioBodyState->punchState = 0;
gMarioState->marioObj->oPosX = gMarioState->pos[0];
gMarioState->marioObj->oPosY = gMarioState->pos[1];
gMarioState->marioObj->oPosZ = gMarioState->pos[2];
gMarioState->marioObj->oMoveAnglePitch = gMarioState->faceAngle[0];
gMarioState->marioObj->oMoveAngleYaw = gMarioState->faceAngle[1];
gMarioState->marioObj->oMoveAngleRoll = gMarioState->faceAngle[2];
vec3_copy(&gMarioState->marioObj->oPosVec, gMarioState->pos);
vec3_copy(&gMarioState->marioObj->oMoveAngleVec, gMarioState->faceAngle);
vec3f_copy(gMarioState->marioObj->header.gfx.pos, gMarioState->pos);
vec3s_set(gMarioState->marioObj->header.gfx.angle, 0, gMarioState->faceAngle[1], 0);
if (save_file_get_cap_pos(capPos)) {
capObject = spawn_object(gMarioState->marioObj, MODEL_MARIOS_CAP, bhvNormalCap);
capObject->oPosX = capPos[0];
capObject->oPosY = capPos[1];
capObject->oPosZ = capPos[2];
vec3_copy(&capObject->oPosVec, capPos);
capObject->oForwardVel = 0;
capObject->oMoveAngleYaw = 0;
}
}