summaryrefslogtreecommitdiff
path: root/src/code/z_actor.c
diff options
context:
space:
mode:
authorfig02 <fig02srl@gmail.com>2024-03-23 12:21:45 -0400
committerGitHub <noreply@github.com>2024-03-23 12:21:45 -0400
commitbd0941405d116ba14efacb6aeccea067958366fe (patch)
tree390c14cb27ea407063fd1780bac8d080d65a643e /src/code/z_actor.c
parent07505dae371a99abef82f7ba3b7acc0d5253eeca (diff)
Document Player's Face and z_actor FaceChange functions (#1928)
* create some enums * gonna try struct instead of array * struct works. add docs too * inline function comments * fix function comment * name faces, move enums * rename textures * outnames * remove comments * change comment slightly * fixup face comments * review * offset comments * add and use PLAYER_FACE_MAX * typo * more comment on blinkDuration * another change to the comment
Diffstat (limited to 'src/code/z_actor.c')
-rw-r--r--src/code/z_actor.c69
1 files changed, 50 insertions, 19 deletions
diff --git a/src/code/z_actor.c b/src/code/z_actor.c
index d9b7f579c..128fa94d8 100644
--- a/src/code/z_actor.c
+++ b/src/code/z_actor.c
@@ -3189,33 +3189,64 @@ void Enemy_StartFinishingBlow(PlayState* play, Actor* actor) {
SfxSource_PlaySfxAtFixedWorldPos(play, &actor->world.pos, 20, NA_SE_EN_LAST_DAMAGE);
}
-s16 func_80032CB4(s16* arg0, s16 arg1, s16 arg2, s16 arg3) {
- if (DECR(arg0[1]) == 0) {
- arg0[1] = Rand_S16Offset(arg1, arg2);
- }
-
- if ((arg0[1] - arg3) > 0) {
- arg0[0] = 0;
- } else if (((arg0[1] - arg3) > -2) || (arg0[1] < 2)) {
- arg0[0] = 1;
+/**
+ * Updates `FaceChange` data for a blinking pattern.
+ * This system expects that the actor using the system has defined 3 faces in this exact order:
+ * "eyes open", "eyes half open", "eyes closed".
+ *
+ * @param faceChange pointer to an actor's faceChange data
+ * @param blinkIntervalBase The base number of frames between blinks
+ * @param blinkIntervalRandRange The range for a random number of frames that can be added to `blinkIntervalBase`
+ * @param blinkDuration The number of frames it takes for a single blink to occur
+ */
+s16 FaceChange_UpdateBlinking(FaceChange* faceChange, s16 blinkIntervalBase, s16 blinkIntervalRandRange,
+ s16 blinkDuration) {
+ if (DECR(faceChange->timer) == 0) {
+ faceChange->timer = Rand_S16Offset(blinkIntervalBase, blinkIntervalRandRange);
+ }
+
+ if ((faceChange->timer - blinkDuration) > 0) {
+ // `timer - duration` is positive so this is the default state: "eyes open" face
+ faceChange->face = 0;
+ } else if (((faceChange->timer - blinkDuration) > -2) || (faceChange->timer < 2)) {
+ // This condition aims to catch both cases where the "eyes half open" face is needed.
+ // Note that the comparison assumes the duration of the "eyes half open" phase is 2 frames, irrespective of the
+ // value of `blinkDuration`. The duration for the "eyes closed" phase is `blinkDuration - 4`.
+ // For Player's use case `blinkDuration` is 6, so the "eyes closed" phase happens to have
+ // the same duration as each "eyes half open" phase.
+ faceChange->face = 1;
} else {
- arg0[0] = 2;
+ // If both conditions above fail, the only possibility left is the "eyes closed" face
+ faceChange->face = 2;
}
- return arg0[0];
+ return faceChange->face;
}
-s16 func_80032D60(s16* arg0, s16 arg1, s16 arg2, s16 arg3) {
- if (DECR(arg0[1]) == 0) {
- arg0[1] = Rand_S16Offset(arg1, arg2);
- arg0[0]++;
-
- if ((arg0[0] % 3) == 0) {
- arg0[0] = (s32)(Rand_ZeroOne() * arg3) * 3;
+/**
+ * Updates `FaceChange` data for randomly selected face sets.
+ * Each set contains 3 faces. After the timer runs out, the next face in the set is used.
+ * After the third face in a set is used, a new face set is randomly chosen.
+ *
+ * @param faceChange pointer to an actor's faceChange data
+ * @param changeTimerBase The base number of frames between each face change
+ * @param changeTimerRandRange The range for a random number of frames that can be added to `changeTimerBase`
+ * @param faceSetRange The max number of face sets that will be chosen from
+ */
+s16 FaceChange_UpdateRandomSet(FaceChange* faceChange, s16 changeTimerBase, s16 changeTimerRandRange,
+ s16 faceSetRange) {
+ if (DECR(faceChange->timer) == 0) {
+ faceChange->timer = Rand_S16Offset(changeTimerBase, changeTimerRandRange);
+ faceChange->face++;
+
+ if ((faceChange->face % 3) == 0) {
+ // Randomly chose a "set number", then multiply by 3 because each set has 3 faces.
+ // This will use the first face in the newly chosen set.
+ faceChange->face = (s32)(Rand_ZeroOne() * faceSetRange) * 3;
}
}
- return arg0[0];
+ return faceChange->face;
}
void BodyBreak_Alloc(BodyBreak* bodyBreak, s32 count, PlayState* play) {