Skip to content

Commit

Permalink
remove union for params to keep them separated
Browse files Browse the repository at this point in the history
  • Loading branch information
z64a committed Jun 19, 2024
1 parent 8c02618 commit 7e7be4a
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 21 deletions.
4 changes: 2 additions & 2 deletions include/common_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,15 @@ typedef struct Camera {
/* 0x002 */ s16 moveFlags;
/* 0x004 */ s16 updateMode;
/* 0x006 */ b16 needsInit;
/* 0x008 */ b16 clearPrevZoneSettings;
/* 0x008 */ b16 needsReinit; // used when loading from a save point or calling SetCamPerspective
/* 0x00A */ s16 viewportW;
/* 0x00C */ s16 viewportH;
/* 0x00E */ s16 viewportStartX;
/* 0x010 */ s16 viewportStartY;
/* 0x012 */ s16 nearClip;
/* 0x014 */ s16 farClip;
/* 0x018 */ f32 vfov;
union {
struct {
struct {
s16 zoomPercent;
} world;
Expand Down
12 changes: 12 additions & 0 deletions include/script_api/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ API_CALLABLE(SetCamUpdateMode);
/// @evtapi
API_CALLABLE(GrabCamera);

/// @evtapi
API_CALLABLE(GetInterpCamDist);

/// @evtapi
API_CALLABLE(GetInterpCamOffsetY);

/// @evtapi
API_CALLABLE(SetInterpCamDist);

/// @evtapi
API_CALLABLE(SetInterpCamOffsetY);

/// @evtapi
API_CALLABLE(SetInterpCamParams);

Expand Down
4 changes: 2 additions & 2 deletions src/cam_mode_no_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ void update_camera_no_interp(Camera* camera) {
f32 pitchAngle, sinPitch, cosPitch;
f32 dx, dy, dz, dr;

if (camera->needsInit || camera->clearPrevZoneSettings) {
if (camera->needsInit || camera->needsReinit) {
camera->needsInit = FALSE;
camera->clearPrevZoneSettings = FALSE;
camera->needsReinit = FALSE;
camera->params.basic.skipRecalc = FALSE;
camera->params.basic.dist = 100;
camera->params.basic.pitch = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/cam_mode_unused_ahead.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ void update_camera_unused_ahead(Camera* camera) {
f32 pitchAngle, sinPitch, cosPitch;
f32 dx, dy, dz, dr;

if (camera->needsInit || camera->clearPrevZoneSettings) {
if (camera->needsInit || camera->needsReinit) {
camera->needsInit = FALSE;
camera->clearPrevZoneSettings = FALSE;
camera->needsReinit = FALSE;
camera->params.basic.skipRecalc = FALSE;
camera->params.basic.dist = 100;
camera->params.basic.pitch = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/cam_mode_zone_interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ void update_camera_zone_interp(Camera* camera) {
targetZ = camera->targetPos.z;
changingZone = FALSE;

if (camera->clearPrevZoneSettings) {
if (camera->needsReinit) {
camera->curSettings = NULL;
camera->prevSettings = NULL;
camera->linearInterp = 0.0f;
Expand Down Expand Up @@ -734,7 +734,7 @@ void update_camera_zone_interp(Camera* camera) {
|| camera->prevTargetPos.x != targetX
|| camera->prevTargetPos.y != targetY
|| camera->prevTargetPos.z != targetZ
|| camera->clearPrevZoneSettings
|| camera->needsReinit
) {
if (camera->useOverrideSettings) {
nextSettings = &camera->overrideSettings;
Expand Down Expand Up @@ -856,11 +856,11 @@ void update_camera_zone_interp(Camera* camera) {
update_camera_from_controller(camera,
&camera->prevRig, &camera->prevSettings, &camera->nextRig, &camera->curSettings,
posX, posY, posZ, tX, tY, tZ,
&camera->interpAlpha, camera->clearPrevZoneSettings, changingZone);
&camera->interpAlpha, camera->needsReinit, changingZone);

if (camera->clearPrevZoneSettings) {
if (camera->needsReinit) {
camera->prevRig = camera->nextRig;
camera->clearPrevZoneSettings = FALSE;
camera->needsReinit = FALSE;
camera->interpAlpha = 1.0f;
}

Expand Down
38 changes: 37 additions & 1 deletion src/evt/cam_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ API_CALLABLE(SetCamPerspective) {

camera->updateMode = mode;
camera->needsInit = TRUE;
camera->clearPrevZoneSettings = TRUE;
camera->needsReinit = TRUE;

camera->vfov = vfov;
camera->farClip = farClip;
Expand Down Expand Up @@ -102,6 +102,42 @@ API_CALLABLE(GrabCamera) {
return ApiStatus_DONE2;
}

API_CALLABLE(GetInterpCamDist) {
Bytecode* args = script->ptrReadPos;
Bytecode id = evt_get_variable(script, *args++);
Bytecode outVar = *args++;

evt_set_variable(script, outVar, gCameras[id].params.interp.dist);
return ApiStatus_DONE2;
}

API_CALLABLE(GetInterpCamOffsetY) {
Bytecode* args = script->ptrReadPos;
Bytecode id = evt_get_variable(script, *args++);
Bytecode outVar = *args++;

evt_set_variable(script, outVar, gCameras[id].params.interp.offsetY);
return ApiStatus_DONE2;
}

API_CALLABLE(SetInterpCamDist) {
Bytecode* args = script->ptrReadPos;
s32 id = evt_get_variable(script, *args++);
s32 dist = evt_get_variable(script, *args++);

gCameras[id].params.interp.dist = dist;
return ApiStatus_DONE2;
}

API_CALLABLE(SetInterpCamOffsetY) {
Bytecode* args = script->ptrReadPos;
s32 id = evt_get_variable(script, *args++);
s32 offsetY = evt_get_variable(script, *args++);

gCameras[id].params.interp.offsetY = offsetY;
return ApiStatus_DONE2;
}

API_CALLABLE(SetInterpCamParams) {
Bytecode* args = script->ptrReadPos;
s32 id = evt_get_variable(script, *args++);
Expand Down
16 changes: 8 additions & 8 deletions src/world/area_kpa/kpa_134/kpa_134_3_chains.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ EvtScript N(EVS_LowerWaterLevel0) = {
Call(MakeLerp, LVar6, 600, 20, EASING_LINEAR)
Label(10)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar0, LVar7)
Call(SetInterpCamDist, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(10)
Expand All @@ -141,7 +141,7 @@ EvtScript N(EVS_LowerWaterLevel0) = {
Call(MakeLerp, LVar7, -20, 20, EASING_LINEAR)
Label(15)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar2, LVar0)
Call(SetInterpCamOffsetY, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(15)
Expand Down Expand Up @@ -196,7 +196,7 @@ EvtScript N(EVS_RaiseWaterLevel1) = {
Call(MakeLerp, LVar6, 600, 20, EASING_LINEAR)
Label(10)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar0, LVar7)
Call(SetInterpCamDist, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(10)
Expand All @@ -206,7 +206,7 @@ EvtScript N(EVS_RaiseWaterLevel1) = {
Call(MakeLerp, LVar7, -20, 20, EASING_LINEAR)
Label(15)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar2, LVar0)
Call(SetInterpCamOffsetY, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(15)
Expand Down Expand Up @@ -365,7 +365,7 @@ EvtScript N(EVS_LowerWaterLevel1) = {
Call(MakeLerp, LVar6, 600, 20, EASING_LINEAR)
Label(10)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar0, LVar7)
Call(SetInterpCamDist, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(10)
Expand All @@ -375,7 +375,7 @@ EvtScript N(EVS_LowerWaterLevel1) = {
Call(MakeLerp, LVar7, -20, 20, EASING_LINEAR)
Label(15)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar2, LVar0)
Call(SetInterpCamOffsetY, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(15)
Expand Down Expand Up @@ -425,7 +425,7 @@ EvtScript N(EVS_RaiseWaterLevel2) = {
Call(MakeLerp, LVar6, 600, 20, EASING_LINEAR)
Label(10)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar0, LVar7)
Call(SetInterpCamDist, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(10)
Expand All @@ -435,7 +435,7 @@ EvtScript N(EVS_RaiseWaterLevel2) = {
Call(MakeLerp, LVar7, -20, 20, EASING_LINEAR)
Label(15)
Call(UpdateLerp)
Call(SetInterpCamParams, CAM_DEFAULT, LVar4, LVar5, LVar2, LVar0)
Call(SetInterpCamOffsetY, CAM_DEFAULT, LVar0)
Wait(1)
IfEq(LVar1, 1)
Goto(15)
Expand Down
2 changes: 1 addition & 1 deletion src/world/script_api/enter_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ API_CALLABLE(SetPlayerPositionFromSaveData) {
enable_partner_ai();
}

camera->clearPrevZoneSettings = TRUE;
camera->needsReinit = TRUE;
return ApiStatus_DONE2;
}

Expand Down

0 comments on commit 7e7be4a

Please sign in to comment.