Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Enemy healthbar crashing on Linux #3092

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions soh/src/code/z_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -3643,7 +3643,8 @@ void Interface_DrawMagicBar(PlayState* play) {
CLOSE_DISPS(play->state.gfxCtx);
}

static Vtx sEnemyHealthVtx[12];
static Vtx sEnemyHealthVtx[16];
static Mtx sEnemyHealthMtx[2];

// Build vertex coordinates for a quad command
// In order of top left, top right, bottom left, then bottom right
Expand Down Expand Up @@ -3704,7 +3705,7 @@ void Interface_DrawEnemyHealthBar(TargetContext* targetCtx, PlayState* play) {
s16 endTexWidth = 8;
f32 scaleY = -0.75f;
f32 scaledHeight = -texHeight * scaleY;
f32 halfBarWidth = endTexWidth + (healthbar_fillWidth / 2);
f32 halfBarWidth = endTexWidth + ((f32)healthbar_fillWidth / 2);
s16 healthBarFill = ((f32)actor->colChkInfo.health / actor->maximumHealth) * healthbar_fillWidth;

if (anchorType == ENEMYHEALTH_ANCHOR_ACTOR) {
Expand All @@ -3729,15 +3730,15 @@ void Interface_DrawEnemyHealthBar(TargetContext* targetCtx, PlayState* play) {
}

// Health bar border end left
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[0], -halfBarWidth, -texHeight / 2, endTexWidth, texHeight, 0);
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[0], -floorf(halfBarWidth), -texHeight / 2, endTexWidth, texHeight, 0);
// Health bar border middle
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[4], -halfBarWidth + endTexWidth, -texHeight / 2,
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[4], -floorf(halfBarWidth) + endTexWidth, -texHeight / 2,
healthbar_fillWidth, texHeight, 0);
// Health bar border end right
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[8], halfBarWidth - endTexWidth, -texHeight / 2, endTexWidth,
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[8], ceilf(halfBarWidth) - endTexWidth, -texHeight / 2, endTexWidth,
texHeight, 1);
// Health bar fill
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[12], -halfBarWidth + endTexWidth, (-texHeight / 2) + 3,
Interface_CreateQuadVertexGroup(&sEnemyHealthVtx[12], -floorf(halfBarWidth) + endTexWidth, (-texHeight / 2) + 3,
healthBarFill, 7, 0);

if (((!(player->stateFlags1 & 0x40)) || (actor != player->unk_664)) && targetCtx->unk_44 < 500.0f) {
Expand All @@ -3757,7 +3758,8 @@ void Interface_DrawEnemyHealthBar(TargetContext* targetCtx, PlayState* play) {

Matrix_Translate(projTargetCenter.x, projTargetCenter.y - slideInOffsetY, 0, MTXMODE_NEW);
Matrix_Scale(1.0f, scaleY, 1.0f, MTXMODE_APPLY);
gSPMatrix(OVERLAY_DISP++, MATRIX_NEWMTX(play->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD);
Matrix_ToMtx(&sEnemyHealthMtx[0], __FILE__, __LINE__);
gSPMatrix(OVERLAY_DISP++, &sEnemyHealthMtx[0], G_MTX_MODELVIEW | G_MTX_LOAD);

// Health bar border
gDPPipeSync(OVERLAY_DISP++);
Expand Down Expand Up @@ -3788,7 +3790,8 @@ void Interface_DrawEnemyHealthBar(TargetContext* targetCtx, PlayState* play) {
// Health bar fill
Matrix_Push();
Matrix_Translate(-0.375f, -0.5f, 0, MTXMODE_APPLY);
gSPMatrix(OVERLAY_DISP++, MATRIX_NEWMTX(play->state.gfxCtx), G_MTX_MODELVIEW | G_MTX_LOAD);
Matrix_ToMtx(&sEnemyHealthMtx[1], __FILE__, __LINE__);
gSPMatrix(OVERLAY_DISP++, &sEnemyHealthMtx[1], G_MTX_MODELVIEW | G_MTX_LOAD);

gDPPipeSync(OVERLAY_DISP++);
gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, 0, 0, 0, PRIMITIVE,
Expand Down