Document Player's Face and z_actor FaceChange functions (#1777)

* player face docs

* more docs

* cleanup

* toto

* more comments

* fix bss, names

* better comment

* PR, fix comment

* fix bss

* sEyeTextures comment

* FaceChange_UpdateBlinkingNonHuman

---------

Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
Co-authored-by: Derek Hensley <hensley.derek58@gmail.com>
This commit is contained in:
engineer124
2025-06-04 11:59:25 +10:00
committed by GitHub
parent ace4043d1a
commit d31ceacfdf
20 changed files with 405 additions and 192 deletions
+67 -28
View File
@@ -3831,51 +3831,90 @@ void Enemy_StartFinishingBlow(PlayState* play, Actor* actor) {
SoundSource_PlaySfxAtFixedWorldPos(play, &actor->world.pos, 20, NA_SE_EN_LAST_DAMAGE);
}
// blinking routine
s16 func_800BBAC0(BlinkInfo* info, s16 arg1, s16 arg2, s16 arg3) {
if (DECR(info->blinkTimer) == 0) {
info->blinkTimer = Rand_S16Offset(arg1, arg2);
/**
* 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 (info->blinkTimer - arg3 > 0) {
info->eyeTexIndex = 0;
} else if ((info->blinkTimer - arg3 >= -1) || (info->blinkTimer < 2)) {
info->eyeTexIndex = 1;
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 >= -1) || (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 {
info->eyeTexIndex = 2;
// If both conditions above fail, the only possibility left is the "eyes closed" face
faceChange->face = 2;
}
return info->eyeTexIndex;
return faceChange->face;
}
// blinking routine
s16 func_800BBB74(BlinkInfo* info, s16 arg1, s16 arg2, s16 arg3) {
if (DECR(info->blinkTimer) == 0) {
info->blinkTimer = Rand_S16Offset(arg1, arg2);
/**
* 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_UpdateBlinkingNonHuman(FaceChange* faceChange, s16 blinkIntervalBase, s16 blinkIntervalRandRange,
s16 blinkDuration) {
if (DECR(faceChange->timer) == 0) {
faceChange->timer = Rand_S16Offset(blinkIntervalBase, blinkIntervalRandRange);
}
if (info->blinkTimer - arg3 > 0) {
info->eyeTexIndex = 0;
} else if (info->blinkTimer - arg3 == 0) {
info->eyeTexIndex = 1;
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 == 0) {
faceChange->face = 1;
} else {
info->eyeTexIndex = 2;
// If both conditions above fail, the only possibility left is the "eyes closed" face
faceChange->face = 2;
}
return info->eyeTexIndex;
return faceChange->face;
}
// unused blinking routine
s16 func_800BBC20(BlinkInfo* info, s16 arg1, s16 arg2, s16 arg3) {
if (DECR(info->blinkTimer) == 0) {
info->blinkTimer = Rand_S16Offset(arg1, arg2);
info->eyeTexIndex++;
if ((info->eyeTexIndex % 3) == 0) {
info->eyeTexIndex = (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) {
faceChange->face = (s32)(Rand_ZeroOne() * faceSetRange) * 3;
}
}
return info->eyeTexIndex;
return faceChange->face;
}
void Actor_SpawnBodyParts(Actor* actor, PlayState* play, s32 partParams, Gfx** dList) {