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

This should fix (all?) 60fps interpolation issues left. #938

Merged
merged 25 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions soh/include/z64effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ typedef struct {
/* 0x0C */ Vec3f position;
/* 0x18 */ Vec3s unkVelocity;
/* 0x1E */ Vec3s unkPosition;
} EffectSparkElement; // size = 0x24
/* 0x24 */ s32 epoch;
} EffectSparkElement; // size = 0x28

typedef struct {
/* 0x000 */ Vec3s position;
Expand Down Expand Up @@ -117,7 +118,8 @@ typedef struct {
/* 0x10 */ f32 startX;
/* 0x14 */ s16 yaw;
/* 0x16 */ s16 pitch;
} EffectShieldParticleElement; // size = 0x18
/* 0x18 */ s32 epoch;
} EffectShieldParticleElement; // size = 0x1C

typedef struct {
/* 0x00 */ u8 numElements;
Expand Down
4 changes: 2 additions & 2 deletions soh/src/code/speed_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ void SpeedMeter_DrawTimeEntries(SpeedMeter* this, GraphicsContext* gfxCtx) {
uly = this->y;
lry = this->y + 2;

OPEN_DISPS(gfxCtx);

/*! @bug if gIrqMgrRetraceTime is 0, CLOSE_DISPS will never be reached */
if (gIrqMgrRetraceTime == 0) {
return;
}

OPEN_DISPS(gfxCtx);
briaguya-ai marked this conversation as resolved.
Show resolved Hide resolved

sSpeedMeterTimeEntryPtr = &sSpeedMeterTimeEntryArray[0];
for (i = 0; i < ARRAY_COUNT(sSpeedMeterTimeEntryArray); i++) {
temp = ((f64) * (sSpeedMeterTimeEntryPtr->time) / gIrqMgrRetraceTime) * 64.0;
Expand Down
4 changes: 4 additions & 0 deletions soh/src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3973,6 +3973,8 @@ void Actor_DrawDoorLock(GlobalContext* globalCtx, s32 frame, s32 type) {
f32 chainsTranslateX;
f32 chainsTranslateY;
f32 rotZStep;
static s32 epoch = 0;
epoch++;

entry = &sDoorLocksInfo[type];
chainRotZ = entry->chainsRotZInit;
Expand All @@ -3986,6 +3988,7 @@ void Actor_DrawDoorLock(GlobalContext* globalCtx, s32 frame, s32 type) {
chainsTranslateY = cosf(entry->chainAngle - chainRotZ) * (10 - frame) * 0.1f * entry->chainLength;

for (i = 0; i < 4; i++) {
FrameInterpolation_RecordOpenChild(entry, epoch + i * 25);
Matrix_Put(&baseMtxF);
Matrix_RotateZ(chainRotZ, MTXMODE_APPLY);
Matrix_Translate(chainsTranslateX, chainsTranslateY, 0.0f, MTXMODE_APPLY);
Expand All @@ -4005,6 +4008,7 @@ void Actor_DrawDoorLock(GlobalContext* globalCtx, s32 frame, s32 type) {
}

chainRotZ += rotZStep;
FrameInterpolation_RecordCloseChild();
}

Matrix_Put(&baseMtxF);
Expand Down
7 changes: 5 additions & 2 deletions soh/src/code/z_eff_shield_particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void EffectShieldParticle_Init(void* thisx, void* initParamsx) {
elem->endXChange = elem->initialSpeed;
elem->yaw = Rand_ZeroOne() * 65534.0f;
elem->pitch = Rand_ZeroOne() * 65534.0f;
elem->epoch++;
}

this->lightDecay = initParams->lightDecay;
Expand Down Expand Up @@ -156,7 +157,6 @@ void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) {
Color_RGBA8 primColor;
Color_RGBA8 envColor;

FrameInterpolation_RecordOpenChild(this, 0);
OPEN_DISPS(gfxCtx);

if (this != NULL) {
Expand All @@ -182,6 +182,8 @@ void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) {
gDPPipeSync(POLY_XLU_DISP++);

for (elem = &this->elements[0]; elem < &this->elements[this->numElements]; elem++) {
FrameInterpolation_RecordOpenChild(elem, elem->epoch);

Mtx* mtx;
MtxF sp104;
MtxF spC4;
Expand Down Expand Up @@ -212,9 +214,10 @@ void EffectShieldParticle_Draw(void* thisx, GraphicsContext* gfxCtx) {
gSPMatrix(POLY_XLU_DISP++, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPVertex(POLY_XLU_DISP++, sVertices, 4, 0);
gSP2Triangles(POLY_XLU_DISP++, 0, 1, 2, 0, 0, 3, 1, 0);

FrameInterpolation_RecordCloseChild();
}
}

CLOSE_DISPS(gfxCtx);
FrameInterpolation_RecordCloseChild();
}
6 changes: 6 additions & 0 deletions soh/src/code/z_eff_spark.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void EffectSpark_Init(void* thisx, void* initParamsx) {
elem->unkPosition.x = Rand_ZeroOne() * 65534.0f;
elem->unkPosition.y = Rand_ZeroOne() * 65534.0f;
elem->unkPosition.z = Rand_ZeroOne() * 65534.0f;
elem->epoch++;
}

this->timer = 0;
Expand Down Expand Up @@ -210,6 +211,8 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) {
Mtx* mtx;
f32 temp;

FrameInterpolation_RecordOpenChild(elem, elem->epoch);

SkinMatrix_SetTranslate(&spEC, elem->position.x, elem->position.y, elem->position.z);
temp = ((Rand_ZeroOne() * 2.5f) + 1.5f) / 64.0f;
SkinMatrix_SetScale(&spAC, temp, temp, 1.0f);
Expand Down Expand Up @@ -264,6 +267,7 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) {

mtx = SkinMatrix_MtxFToNewMtx(gfxCtx, &sp12C);
if (mtx == NULL) {
FrameInterpolation_RecordCloseChild();
goto end;
}

Expand All @@ -273,6 +277,8 @@ void EffectSpark_Draw(void* thisx, GraphicsContext* gfxCtx) {
}

gDPPipeSync(POLY_XLU_DISP++);

FrameInterpolation_RecordCloseChild();
}

end:
Expand Down
28 changes: 24 additions & 4 deletions soh/src/code/z_kankyo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "vt.h"
#include "objects/gameplay_keep/gameplay_keep.h"
#include "objects/gameplay_field_keep/gameplay_field_keep.h"
#include "soh/frame_interpolation.h"

typedef enum {
/* 0 */ LENS_FLARE_CIRCLE0,
Expand Down Expand Up @@ -950,7 +951,6 @@ void Environment_Update(GlobalContext* globalCtx, EnvironmentContext* envCtx, Li
Gfx* prevDisplayList;

OPEN_DISPS(globalCtx->state.gfxCtx);

prevDisplayList = POLY_OPA_DISP;
displayList = Graph_GfxPlusOne(POLY_OPA_DISP);
gSPDisplayList(OVERLAY_DISP++, displayList);
Expand Down Expand Up @@ -1459,6 +1459,8 @@ void Environment_DrawLensFlare(GlobalContext* globalCtx, EnvironmentContext* env
LENS_FLARE_RING, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1,
LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1, LENS_FLARE_CIRCLE1,
};
static s32 epoch = 0;
epoch++;
Comment on lines +1462 to +1463
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the purpose of these kind of statements to disable interpolation for this object? In any case, use u32 rather than s32 when the number can wrap around since it's UB when an s32 overflows.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You never resolved this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed the s32 vs u32 thing when going through it this last time, i'll make a cleanup pr for those rn

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first sentence also still applies. Incrementing epoch in the draw function will basically disable interpolation for this object. Don't know if that was intended...


OPEN_DISPS(gfxCtx);

Expand Down Expand Up @@ -1502,9 +1504,7 @@ void Environment_DrawLensFlare(GlobalContext* globalCtx, EnvironmentContext* env
unk88Target = cosAngle;
}

if (cosAngle < 0.0f) {

} else {
if (!(cosAngle < 0.0f)) {
if (arg9) {
u32 shrink = ShrinkWindow_GetCurrentVal();
func_800C016C(globalCtx, &pos, &screenPos);
Expand All @@ -1517,6 +1517,8 @@ void Environment_DrawLensFlare(GlobalContext* globalCtx, EnvironmentContext* env
}

for (i = 0; i < ARRAY_COUNT(lensFlareTypes); i++) {
FrameInterpolation_RecordOpenChild("Lens Flare", epoch + i * 25);

Matrix_Translate(pos.x, pos.y, pos.z, MTXMODE_NEW);

if (arg9) {
Expand Down Expand Up @@ -1573,6 +1575,8 @@ void Environment_DrawLensFlare(GlobalContext* globalCtx, EnvironmentContext* env
gSPDisplayList(POLY_XLU_DISP++, gLensFlareRingDL);
break;
}

FrameInterpolation_RecordCloseChild();
}

alphaScale = cosAngle - (1.5f - cosAngle);
Expand Down Expand Up @@ -1638,6 +1642,8 @@ void Environment_DrawRain(GlobalContext* globalCtx, View* view, GraphicsContext*
Vec3f unused = { 0.0f, 0.0f, 0.0f };
Vec3f windDirection = { 0.0f, 0.0f, 0.0f };
Player* player = GET_PLAYER(globalCtx);
static s32 epoch = 0;
epoch++;

if (!(globalCtx->cameraPtrs[0]->unk_14C & 0x100) && (globalCtx->envCtx.unk_EE[2] == 0)) {
OPEN_DISPS(gfxCtx);
Expand Down Expand Up @@ -1667,6 +1673,8 @@ void Environment_DrawRain(GlobalContext* globalCtx, View* view, GraphicsContext*

// draw rain drops
for (i = 0; i < globalCtx->envCtx.unk_EE[1]; i++) {
FrameInterpolation_RecordOpenChild("Rain Drop", epoch + i * 25);

temp2 = Rand_ZeroOne();
temp1 = Rand_ZeroOne();
temp3 = Rand_ZeroOne();
Expand All @@ -1692,13 +1700,17 @@ void Environment_DrawRain(GlobalContext* globalCtx, View* view, GraphicsContext*
gSPMatrix(POLY_XLU_DISP++, MATRIX_NEWMTX(gfxCtx),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, gRaindropDL);

FrameInterpolation_RecordCloseChild();
}

// draw droplet rings on the ground
if (player->actor.world.pos.y < view->eye.y) {
u8 firstDone = false;

for (i = 0; i < globalCtx->envCtx.unk_EE[1]; i++) {
FrameInterpolation_RecordOpenChild("Droplet Ring", epoch + i * 25);

if (!firstDone) {
func_80093D84(gfxCtx);
gDPSetEnvColor(POLY_XLU_DISP++, 155, 155, 155, 0);
Expand All @@ -1719,6 +1731,8 @@ void Environment_DrawRain(GlobalContext* globalCtx, View* view, GraphicsContext*
gSPMatrix(POLY_XLU_DISP++, MATRIX_NEWMTX(gfxCtx),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, gEffShockwaveDL);

FrameInterpolation_RecordCloseChild();
}
}

Expand Down Expand Up @@ -1911,10 +1925,14 @@ void Environment_DrawLightning(GlobalContext* globalCtx, s32 unused) {
s32 pad[2];
Vec3f unused1 = { 0.0f, 0.0f, 0.0f };
Vec3f unused2 = { 0.0f, 0.0f, 0.0f };
static s32 epoch = 0;
epoch++;

OPEN_DISPS(globalCtx->state.gfxCtx);

for (i = 0; i < ARRAY_COUNT(sLightningBolts); i++) {
FrameInterpolation_RecordOpenChild("Lightning Bolt", epoch + i * 25);

switch (sLightningBolts[i].state) {
case LIGHTNING_BOLT_START:
dx = globalCtx->view.lookAt.x - globalCtx->view.eye.x;
Expand Down Expand Up @@ -1969,6 +1987,8 @@ void Environment_DrawLightning(GlobalContext* globalCtx, s32 unused) {
gSPMatrix(POLY_XLU_DISP++, SEG_ADDR(1, 0), G_MTX_NOPUSH | G_MTX_MUL | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, gEffLightningDL);
}

FrameInterpolation_RecordCloseChild();
}

CLOSE_DISPS(globalCtx->state.gfxCtx);
Expand Down
7 changes: 7 additions & 0 deletions soh/src/code/z_lifemeter.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "global.h"
#include "textures/parameter_static/parameter_static.h"
#include "soh/frame_interpolation.h"

s16 Top_LM_Margin = 0;
s16 Left_LM_Margin = 0;
Expand Down Expand Up @@ -412,6 +413,8 @@ void HealthMeter_Draw(GlobalContext* globalCtx) {
s32 curCombineModeSet = 0;
u8* curBgImgLoaded = NULL;
s32 ddHeartCountMinusOne = gSaveContext.inventory.defenseHearts - 1;
static s32 epoch = 0;
epoch++;

OPEN_DISPS(gfxCtx);

Expand Down Expand Up @@ -449,6 +452,8 @@ void HealthMeter_Draw(GlobalContext* globalCtx) {
}

for (i = 0; i < totalHeartCount; i++) {
FrameInterpolation_RecordOpenChild("HealthMeter Heart", epoch + i * 25);

if ((ddHeartCountMinusOne < 0) || (i > ddHeartCountMinusOne)) {
if (i < fullHeartCount) {
if (curColorSet != 0) {
Expand Down Expand Up @@ -624,6 +629,8 @@ void HealthMeter_Draw(GlobalContext* globalCtx) {
offsetX = PosX_original;
}
}

FrameInterpolation_RecordCloseChild();
}

CLOSE_DISPS(gfxCtx);
Expand Down
6 changes: 6 additions & 0 deletions soh/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "overlays/actors/ovl_Demo_Effect/z_demo_effect.h"
#include "scenes/indoors/yousei_izumi_yoko/yousei_izumi_yoko_scene.h"
#include "scenes/indoors/daiyousei_izumi/daiyousei_izumi_scene.h"
#include "soh/frame_interpolation.h"

#define FLAGS (ACTOR_FLAG_4 | ACTOR_FLAG_5 | ACTOR_FLAG_25)

Expand Down Expand Up @@ -960,6 +961,7 @@ void BgDyYoseizo_ParticleInit(BgDyYoseizo* this, Vec3f* initPos, Vec3f* initVelo
particle->pitch = 0.0f;
particle->yaw = Rand_CenteredFloat(30000.0f);
particle->roll = 0.0f;
particle->epoch++;
return;
}
}
Expand Down Expand Up @@ -1039,6 +1041,8 @@ void BgDyYoseizo_ParticleDraw(BgDyYoseizo* this, GlobalContext* globalCtx) {
func_80093D84(globalCtx->state.gfxCtx);

for (i = 0; i < 200; i++, particle++) {
FrameInterpolation_RecordOpenChild(particle, particle->epoch);

if (particle->alive == 1) {
if (phi_s3 == 0) {
gSPDisplayList(POLY_XLU_DISP++, SEGMENTED_TO_VIRTUAL(gGreatFairyParticleAppearDL));
Expand All @@ -1060,6 +1064,8 @@ void BgDyYoseizo_ParticleDraw(BgDyYoseizo* this, GlobalContext* globalCtx) {
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_XLU_DISP++, SEGMENTED_TO_VIRTUAL(gGreatFairyParticleAliveDL));
}

FrameInterpolation_RecordCloseChild();
}

CLOSE_DISPS(gfxCtx);
Expand Down
3 changes: 2 additions & 1 deletion soh/src/overlays/actors/ovl_Bg_Dy_Yoseizo/z_bg_dy_yoseizo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ typedef struct {
/* 0x36 */ f32 pitch;
/* 0x36 */ f32 yaw;
/* 0x40 */ f32 roll;
} BgDyYoseizoParticle; // size = 0x44
/* 0x44 */ s32 epoch;
} BgDyYoseizoParticle; // size = 0x48

typedef struct BgDyYoseizo {
/* 0x0000 */ Actor actor;
Expand Down
7 changes: 7 additions & 0 deletions soh/src/overlays/actors/ovl_Bg_Jya_Megami/z_bg_jya_megami.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "z_bg_jya_megami.h"
#include "overlays/effects/ovl_Effect_Ss_Kakera/z_eff_ss_kakera.h"
#include "objects/object_jya_obj/object_jya_obj.h"
#include "soh/frame_interpolation.h"

#define FLAGS 0

Expand Down Expand Up @@ -217,6 +218,7 @@ void BgJyaMegami_SetupExplode(BgJyaMegami* this) {
for (i = 0; i < ARRAY_COUNT(this->pieces); i++) {
Math_Vec3f_Copy(&this->pieces[i].pos, &this->dyna.actor.world.pos);
this->pieces[i].vel.x = sPiecesInit[i].velX;
this->pieces[i].epoch++;
}
this->explosionTimer = 0;
}
Expand Down Expand Up @@ -326,6 +328,9 @@ void BgJyaMegami_DrawExplode(BgJyaMegami* this, GlobalContext* globalCtx) {

for (i = 0; i < ARRAY_COUNT(this->pieces); i++) {
piece = &this->pieces[i];

FrameInterpolation_RecordOpenChild(piece, piece->epoch);

Matrix_Translate(piece->pos.x + sPiecesInit[i].unk_00.x, piece->pos.y + sPiecesInit[i].unk_00.y,
piece->pos.z + sPiecesInit[i].unk_00.z, MTXMODE_NEW);
Matrix_RotateY(piece->rotVelY * (M_PI / 0x8000), MTXMODE_APPLY);
Expand All @@ -337,6 +342,8 @@ void BgJyaMegami_DrawExplode(BgJyaMegami* this, GlobalContext* globalCtx) {
gSPMatrix(POLY_OPA_DISP++, MATRIX_NEWMTX(globalCtx->state.gfxCtx),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, sDLists[i]);

FrameInterpolation_RecordCloseChild();
}

CLOSE_DISPS(globalCtx->state.gfxCtx);
Expand Down
3 changes: 2 additions & 1 deletion soh/src/overlays/actors/ovl_Bg_Jya_Megami/z_bg_jya_megami.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ typedef struct {
/* 0x0C */ Vec3f vel;
/* 0x18 */ s16 rotVelX;
/* 0x1A */ s16 rotVelY;
} BgJyaMegamiPiece; // size = 0x1C
/* 0x1C */ s32 epoch;
} BgJyaMegamiPiece; // size = 0x20

typedef struct BgJyaMegami {
/* 0x0000 */ DynaPolyActor dyna;
Expand Down
Loading