mirror of
https://github.com/zeldaret/oot
synced 2026-07-02 20:46:16 -04:00
z_bgcheck.c, 800430A0.c, 80043480.c (#256)
* beginning of migrating changes * got matching * changed order a bit * clean up bgcheck * fix conflict * fix conflict again * first stab at identifying types, some oks * Clean up most bad structs/pointer math, move relevant structs to z64bgcheck.h, get some OKs * more OKs, z_bgcheck.bss migration, update some sys_math3d.c args * couple more OKs * pushing some OKs * fix compilation issues * code_800430A0.c OK, more files decomp'd * 8003A3E0 big OK :) * Decomp most of func_8003C614, decomp helper funcs * Decomp SurfaceType, CamData, and WaterBox property related functions * more OKs, big OK in 8003C078 * more OKs, more progress, move a function definition in z_collision_check to functions.h * more clean-ups, more OKs, dyn_vtx is now defined as u8* * 8003A5B8, 8003A7D8, 8003C614, 8003DD6C OK, document function args better * data migrated, more OKs * 80041240 OK, func_8003B3C8 and func_8003BB18 disassembled * func_80040284, 800409A8 non_matching, add IS_ZERO macro * All asm files have C representations, some big OKs, lots of minor tweaks * More OKs, non-matching code cleanup * 8003FBF4 and 80040BE4 OK, improve codegen for most functions * format z_bgcheck.c * fix warnings, compile errors on NON_MATCHING * func_8003EE80 is now NON_MATCHING * begin documenting some functions * formatting * more documentation, func_8003A95C OK * fix PHYSICAL_TO_VIRTUAL changes * fix var rename * More documentation, functions 80040E40, 80041648 OK, change types to not be compatible with ZAP * func_8004239C ok, more NON_MATCHING improvements, more documentation * Implement most suggested changes * Convert comments to slower comments * /** * Implement ZAP2 changes * my anti-virus ate my format.sh results * Rename a couple hundred functions, fix minor stuff * rename var so that clang formats correctly * run format.sh * implement Petrie's matches/suggestions * format * matches * and the asm * slight error * Add SSList * two more matches * stuff * implement code changes * clean up Petrie's matchings Co-authored-by: Arthur <arthurtilly413@gmail.com> Co-authored-by: fig02 <fig02srl@gmail.com> Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain>
This commit is contained in:
+50
-47
@@ -215,7 +215,7 @@ s32 Camera_BGCheckInfo(Camera* camera, Vec3f* from, CamColChk* to) {
|
||||
fromToOffset.r += 8.0f;
|
||||
Camera_Vec3fVecSphGeoAdd(&toPoint, from, &fromToOffset);
|
||||
|
||||
if (!func_8003DD6C(colCtx, from, &toPoint, &toNewPos, &to->poly, 1, 1, 1, -1, &to->bgId)) {
|
||||
if (!BgCheck_CameraLineTest1(colCtx, from, &toPoint, &toNewPos, &to->poly, 1, 1, 1, -1, &to->bgId)) {
|
||||
// no poly in path.
|
||||
OLib_Vec3fDistNormalize(&fromToNorm, from, &to->pos);
|
||||
|
||||
@@ -225,7 +225,7 @@ s32 Camera_BGCheckInfo(Camera* camera, Vec3f* from, CamColChk* to) {
|
||||
|
||||
toNewPos = to->pos;
|
||||
toNewPos.y += 5.0f;
|
||||
floorPolyY = func_8003CCA4(colCtx, &floorPoly, &floorBgId, &toNewPos);
|
||||
floorPolyY = BgCheck_CameraRaycastFloor2(colCtx, &floorPoly, &floorBgId, &toNewPos);
|
||||
|
||||
if ((to->pos.y - floorPolyY) > 5.0f) {
|
||||
// if the y distance from the check point to the floor is more than 5 units
|
||||
@@ -241,9 +241,9 @@ s32 Camera_BGCheckInfo(Camera* camera, Vec3f* from, CamColChk* to) {
|
||||
to->bgId = floorBgId;
|
||||
}
|
||||
|
||||
to->norm.x = to->poly->norm.x * COLPOLY_NORM_FRAC;
|
||||
to->norm.y = to->poly->norm.y * COLPOLY_NORM_FRAC;
|
||||
to->norm.z = to->poly->norm.z * COLPOLY_NORM_FRAC;
|
||||
to->norm.x = COLPOLY_GET_NORMAL(to->poly->normal.x);
|
||||
to->norm.y = COLPOLY_GET_NORMAL(to->poly->normal.y);
|
||||
to->norm.z = COLPOLY_GET_NORMAL(to->poly->normal.z);
|
||||
to->pos.x = to->norm.x + toNewPos.x;
|
||||
to->pos.y = to->norm.y + toNewPos.y;
|
||||
to->pos.z = to->norm.z + toNewPos.z;
|
||||
@@ -278,14 +278,14 @@ s32 func_80043F94(Camera* camera, Vec3f* from, CamColChk* to) {
|
||||
OLib_Vec3fDiffToVecSphGeo(&fromToGeo, from, &to->pos);
|
||||
fromToGeo.r += 8.0f;
|
||||
Camera_Vec3fVecSphGeoAdd(&toPos, from, &fromToGeo);
|
||||
if (!func_8003DD6C(colCtx, from, &toPos, &toNewPos, &to->poly, 1, 1, 1, -1, &to->bgId)) {
|
||||
if (!BgCheck_CameraLineTest1(colCtx, from, &toPos, &toNewPos, &to->poly, 1, 1, 1, -1, &to->bgId)) {
|
||||
OLib_Vec3fDistNormalize(&fromToNorm, from, &to->pos);
|
||||
to->norm.x = -fromToNorm.x;
|
||||
to->norm.y = -fromToNorm.y;
|
||||
to->norm.z = -fromToNorm.z;
|
||||
toNewPos = to->pos;
|
||||
toNewPos.y += 5.0f;
|
||||
floorY = func_8003CCA4(colCtx, &floorPoly, &bgId, &toNewPos);
|
||||
floorY = BgCheck_CameraRaycastFloor2(colCtx, &floorPoly, &bgId, &toNewPos);
|
||||
if ((to->pos.y - floorY) > 5.0f) {
|
||||
// to is not on the ground or below it.
|
||||
to->pos.x += to->norm.x;
|
||||
@@ -298,17 +298,17 @@ s32 func_80043F94(Camera* camera, Vec3f* from, CamColChk* to) {
|
||||
toNewPos.y = floorY + 1.0f;
|
||||
to->bgId = bgId;
|
||||
}
|
||||
to->norm.x = to->poly->norm.x * COLPOLY_NORM_FRAC;
|
||||
to->norm.y = to->poly->norm.y * COLPOLY_NORM_FRAC;
|
||||
to->norm.z = to->poly->norm.z * COLPOLY_NORM_FRAC;
|
||||
to->norm.x = COLPOLY_GET_NORMAL(to->poly->normal.x);
|
||||
to->norm.y = COLPOLY_GET_NORMAL(to->poly->normal.y);
|
||||
to->norm.z = COLPOLY_GET_NORMAL(to->poly->normal.z);
|
||||
if ((to->norm.y > 0.5f) || (to->norm.y < -0.8f)) {
|
||||
to->pos.x = to->norm.x + toNewPos.x;
|
||||
to->pos.y = to->norm.y + toNewPos.y;
|
||||
to->pos.z = to->norm.z + toNewPos.z;
|
||||
} else if (playerFloorPoly != NULL) {
|
||||
playerFloorNormF.x = playerFloorPoly->norm.x * COLPOLY_NORM_FRAC;
|
||||
playerFloorNormF.y = playerFloorPoly->norm.y * COLPOLY_NORM_FRAC;
|
||||
playerFloorNormF.z = playerFloorPoly->norm.z * COLPOLY_NORM_FRAC;
|
||||
playerFloorNormF.x = COLPOLY_GET_NORMAL(playerFloorPoly->normal.x);
|
||||
playerFloorNormF.y = COLPOLY_GET_NORMAL(playerFloorPoly->normal.y);
|
||||
playerFloorNormF.z = COLPOLY_GET_NORMAL(playerFloorPoly->normal.z);
|
||||
if (Math3D_LineSegVsPlane(playerFloorNormF.x, playerFloorNormF.y, playerFloorNormF.z, playerFloorPoly->dist,
|
||||
from, &toPos, &toNewPos, 1)) {
|
||||
// line is from->to is touching the poly the player is on.
|
||||
@@ -353,7 +353,8 @@ s32 Camera_CheckOOB(Camera* camera, Vec3f* from, Vec3f* to) {
|
||||
CollisionContext* colCtx = &camera->globalCtx->colCtx;
|
||||
|
||||
poly = NULL;
|
||||
if (func_8003DD6C(colCtx, from, to, &intersect, &poly, 1, 1, 1, 0, &bgId) && (func_80038B7C(poly, from) < 0.0f)) {
|
||||
if (BgCheck_CameraLineTest1(colCtx, from, to, &intersect, &poly, 1, 1, 1, 0, &bgId) &&
|
||||
(CollisionPoly_GetPointDistanceFromPlane(poly, from) < 0.0f)) {
|
||||
// if there is a poly between `from` and `to` and the `from` is behind the poly.
|
||||
return true;
|
||||
}
|
||||
@@ -368,7 +369,7 @@ s32 Camera_CheckOOB(Camera* camera, Vec3f* from, Vec3f* to) {
|
||||
f32 Camera_GetFloorYNorm(Camera* camera, Vec3f* floorNorm, Vec3f* chkPos, s32* bgId) {
|
||||
s32 pad;
|
||||
CollisionPoly* floorPoly;
|
||||
f32 floorY = func_8003C940(&camera->globalCtx->colCtx, &floorPoly, bgId, chkPos);
|
||||
f32 floorY = BgCheck_EntityRaycastFloor3(&camera->globalCtx->colCtx, &floorPoly, bgId, chkPos);
|
||||
|
||||
if (floorY == BGCHECK_Y_MIN) {
|
||||
// no floor
|
||||
@@ -376,9 +377,9 @@ f32 Camera_GetFloorYNorm(Camera* camera, Vec3f* floorNorm, Vec3f* chkPos, s32* b
|
||||
floorNorm->y = 1.0f;
|
||||
floorNorm->z = 0.0f;
|
||||
} else {
|
||||
floorNorm->x = floorPoly->norm.x * COLPOLY_NORM_FRAC;
|
||||
floorNorm->y = floorPoly->norm.y * COLPOLY_NORM_FRAC;
|
||||
floorNorm->z = floorPoly->norm.z * COLPOLY_NORM_FRAC;
|
||||
floorNorm->x = COLPOLY_GET_NORMAL(floorPoly->normal.x);
|
||||
floorNorm->y = COLPOLY_GET_NORMAL(floorPoly->normal.y);
|
||||
floorNorm->z = COLPOLY_GET_NORMAL(floorPoly->normal.z);
|
||||
}
|
||||
|
||||
return floorY;
|
||||
@@ -409,9 +410,9 @@ f32 Camera_GetFloorYLayer(Camera* camera, Vec3f* norm, Vec3f* pos, u32* bgId) {
|
||||
s32 i;
|
||||
|
||||
for (i = 3; i > 0; i--) {
|
||||
floorY = func_8003CCA4(colCtx, &floorPoly, bgId, pos);
|
||||
floorY = BgCheck_CameraRaycastFloor2(colCtx, &floorPoly, bgId, pos);
|
||||
if (floorY == BGCHECK_Y_MIN ||
|
||||
(camera->playerGroundY < floorY && !((floorPoly->norm.y * COLPOLY_NORM_FRAC) > 0.5f))) {
|
||||
(camera->playerGroundY < floorY && !(COLPOLY_GET_NORMAL(floorPoly->normal.y) > 0.5f))) {
|
||||
// no floor, or player is below the floor and floor is not considered steep
|
||||
norm->x = 0.0f;
|
||||
norm->y = 1.0f;
|
||||
@@ -423,9 +424,9 @@ f32 Camera_GetFloorYLayer(Camera* camera, Vec3f* norm, Vec3f* pos, u32* bgId) {
|
||||
pos->y = floorY - 10.0f;
|
||||
continue;
|
||||
} else {
|
||||
norm->x = floorPoly->norm.x * COLPOLY_NORM_FRAC;
|
||||
norm->y = floorPoly->norm.y * COLPOLY_NORM_FRAC;
|
||||
norm->z = floorPoly->norm.z * COLPOLY_NORM_FRAC;
|
||||
norm->x = COLPOLY_GET_NORMAL(floorPoly->normal.x);
|
||||
norm->y = COLPOLY_GET_NORMAL(floorPoly->normal.y);
|
||||
norm->z = COLPOLY_GET_NORMAL(floorPoly->normal.z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -439,14 +440,14 @@ f32 Camera_GetFloorYLayer(Camera* camera, Vec3f* norm, Vec3f* pos, u32* bgId) {
|
||||
* Returns the CameraSettingType of the camera at index `camDataIdx`
|
||||
*/
|
||||
s16 Camera_GetCamDataSetting(Camera* camera, s32 camDataIdx) {
|
||||
return func_80041A4C(&camera->globalCtx->colCtx, camDataIdx, 50);
|
||||
return func_80041A4C(&camera->globalCtx->colCtx, camDataIdx, BGCHECK_SCENE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the scene camera info for the current camera data index
|
||||
*/
|
||||
Vec3s* Camera_GetCamBGData(Camera* camera) {
|
||||
return func_80041C10(&camera->globalCtx->colCtx, camera->camDataIdx, 50);
|
||||
return func_80041C10(&camera->globalCtx->colCtx, camera->camDataIdx, BGCHECK_SCENE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -459,7 +460,7 @@ s32 Camera_GetDataIdxForPoly(Camera* camera, u32* bgId, CollisionPoly* poly) {
|
||||
s32 ret;
|
||||
|
||||
func_8002EF44(&playerPosRot, &camera->player->actor); // unused.
|
||||
camDataIdx = func_80041A28(&camera->globalCtx->colCtx, poly, *bgId);
|
||||
camDataIdx = SurfaceType_GetCamDataIndex(&camera->globalCtx->colCtx, poly, *bgId);
|
||||
|
||||
if (func_80041A4C(&camera->globalCtx->colCtx, camDataIdx, *bgId) == CAM_SET_NONE) {
|
||||
ret = -1;
|
||||
@@ -482,12 +483,13 @@ Vec3s* Camera_GetCamBgDataUnderPlayer(Camera* camera, u16* dataCnt) {
|
||||
|
||||
func_8002EF44(&playerPosShape, &camera->player->actor);
|
||||
playerPosShape.pos.y += Player_GetHeight(camera->player);
|
||||
if (func_8003C940(&camera->globalCtx->colCtx, &floorPoly, &bgId, &playerPosShape.pos) == BGCHECK_Y_MIN) {
|
||||
if (BgCheck_EntityRaycastFloor3(&camera->globalCtx->colCtx, &floorPoly, &bgId, &playerPosShape.pos) ==
|
||||
BGCHECK_Y_MIN) {
|
||||
// no floor
|
||||
return NULL;
|
||||
}
|
||||
*dataCnt = func_80041B80(&camera->globalCtx->colCtx, floorPoly, bgId);
|
||||
return func_80041C98(&camera->globalCtx->colCtx, floorPoly, bgId);
|
||||
*dataCnt = SurfaceType_GetNumCameras(&camera->globalCtx->colCtx, floorPoly, bgId);
|
||||
return SurfaceType_GetCamPosData(&camera->globalCtx->colCtx, floorPoly, bgId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -504,8 +506,8 @@ s32 Camera_GetWaterBoxDataIdx(Camera* camera, f32* waterY) {
|
||||
func_8002EF44(&playerPosShape, &camera->player->actor);
|
||||
*waterY = playerPosShape.pos.y;
|
||||
|
||||
if (!func_8004213C(camera->globalCtx, &camera->globalCtx->colCtx, playerPosShape.pos.x, playerPosShape.pos.z,
|
||||
waterY, &waterBox)) {
|
||||
if (!WaterBox_GetSurface1(camera->globalCtx, &camera->globalCtx->colCtx, playerPosShape.pos.x, playerPosShape.pos.z,
|
||||
waterY, &waterBox)) {
|
||||
// player's position is not in a water box.
|
||||
*waterY = BGCHECK_Y_MIN;
|
||||
return -1;
|
||||
@@ -517,8 +519,8 @@ s32 Camera_GetWaterBoxDataIdx(Camera* camera, f32* waterY) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = func_80042538(&camera->globalCtx->colCtx, waterBox);
|
||||
if ((ret <= 0) || (func_80042548(&camera->globalCtx->colCtx, waterBox) <= 0)) {
|
||||
ret = WaterBox_GetCamDataIndex(&camera->globalCtx->colCtx, waterBox);
|
||||
if ((ret <= 0) || (WaterBox_GetCameraSType(&camera->globalCtx->colCtx, waterBox) <= 0)) {
|
||||
// no camera data idx, or no CameraSettingType
|
||||
return -2;
|
||||
}
|
||||
@@ -539,7 +541,8 @@ f32 Camera_GetWaterSurface(Camera* camera, Vec3f* chkPos, s32* envProp) {
|
||||
func_8002EF44(&playerPosRot, &camera->player->actor);
|
||||
waterY = playerPosRot.pos.y;
|
||||
|
||||
if (!func_8004213C(camera->globalCtx, &camera->globalCtx->colCtx, chkPos->x, chkPos->z, &waterY, &waterBox)) {
|
||||
if (!WaterBox_GetSurface1(camera->globalCtx, &camera->globalCtx->colCtx, chkPos->x, chkPos->z, &waterY,
|
||||
&waterBox)) {
|
||||
// chkPos is not within the x/z boundaries of a water box.
|
||||
return BGCHECK_Y_MIN;
|
||||
}
|
||||
@@ -550,7 +553,7 @@ f32 Camera_GetWaterSurface(Camera* camera, Vec3f* chkPos, s32* envProp) {
|
||||
return BGCHECK_Y_MIN;
|
||||
}
|
||||
|
||||
*envProp = func_8004259C(&camera->globalCtx->colCtx, waterBox);
|
||||
*envProp = WaterBox_GetLightSettingIndex(&camera->globalCtx->colCtx, waterBox);
|
||||
return waterY;
|
||||
}
|
||||
|
||||
@@ -1284,7 +1287,7 @@ s16 Camera_CalcDefaultYaw(Camera* camera, s16 cur, s16 target, f32 arg3, f32 acc
|
||||
|
||||
if (camera->xzSpeed > 0.001f) {
|
||||
angDelta = target - BINANG_ROT180(cur);
|
||||
speedT = BINANG_ROT180(angDelta) * COLPOLY_NORM_FRAC;
|
||||
speedT = COLPOLY_GET_NORMAL(BINANG_ROT180(angDelta));
|
||||
} else {
|
||||
angDelta = target - BINANG_ROT180(cur);
|
||||
speedT = PCT(OREG(48));
|
||||
@@ -3603,7 +3606,7 @@ s32 Camera_KeepOn4(Camera* camera) {
|
||||
OLib_Vec3fDiffToVecSphGeo(&spA8, at, eyeNext);
|
||||
D_8015BD50 = playerPosRot->pos;
|
||||
D_8015BD50.y += playerHeight;
|
||||
temp_f0_2 = func_8003CCA4(&camera->globalCtx->colCtx, &spC0, &i, &D_8015BD50);
|
||||
temp_f0_2 = BgCheck_CameraRaycastFloor2(&camera->globalCtx->colCtx, &spC0, &i, &D_8015BD50);
|
||||
if (temp_f0_2 > (keep4->unk_00 + D_8015BD50.y)) {
|
||||
D_8015BD50.y = temp_f0_2 + 10.0f;
|
||||
} else {
|
||||
@@ -6833,7 +6836,7 @@ void Camera_Init(Camera* camera, View* view, CollisionContext* colCtx, GlobalCon
|
||||
camera->setting = camera->prevSetting = 0x21;
|
||||
camera->camDataIdx = camera->prevCamDataIdx = -1;
|
||||
camera->mode = 0;
|
||||
camera->bgCheckId = 0x32;
|
||||
camera->bgCheckId = BGCHECK_SCENE;
|
||||
camera->unk_168 = 0x7FFF;
|
||||
camera->timer = -1;
|
||||
camera->unk_14C |= 0x4000;
|
||||
@@ -7092,7 +7095,7 @@ s32 Camera_CheckWater(Camera* camera) {
|
||||
}
|
||||
if (camera->playerGroundY != camera->playerPosRot.pos.y) {
|
||||
prevBgId = camera->bgCheckId;
|
||||
camera->bgCheckId = 50;
|
||||
camera->bgCheckId = BGCHECK_SCENE;
|
||||
Camera_ChangeSettingFlags(camera, CAM_SET_NORMAL3, 2);
|
||||
*waterPrevCamSetting = camera->setting;
|
||||
camera->bgCheckId = prevBgId;
|
||||
@@ -7108,7 +7111,7 @@ s32 Camera_CheckWater(Camera* camera) {
|
||||
}
|
||||
if (camera->playerGroundY != camera->playerPosRot.pos.y) {
|
||||
prevBgId = camera->bgCheckId;
|
||||
camera->bgCheckId = 50;
|
||||
camera->bgCheckId = BGCHECK_SCENE;
|
||||
Camera_ChangeDataIdx(camera, waterCamIdx);
|
||||
*waterPrevCamSetting = camera->setting;
|
||||
camera->bgCheckId = prevBgId;
|
||||
@@ -7118,7 +7121,7 @@ s32 Camera_CheckWater(Camera* camera) {
|
||||
osSyncPrintf("camera: water: off\n");
|
||||
camera->unk_14C &= ~0x200;
|
||||
prevBgId = camera->bgCheckId;
|
||||
camera->bgCheckId = 50;
|
||||
camera->bgCheckId = BGCHECK_SCENE;
|
||||
if (camera->waterPrevCamIdx < 0) {
|
||||
func_80057FC4(camera);
|
||||
camera->camDataIdx = -1;
|
||||
@@ -7342,14 +7345,14 @@ Vec3s* Camera_Update(Vec3s* outVec, Camera* camera) {
|
||||
spAC = curPlayerPosRot.pos;
|
||||
spAC.y += Player_GetHeight(camera->player);
|
||||
|
||||
playerGroundY = func_8003CA0C(camera->globalCtx, &camera->globalCtx->colCtx, &playerFloorPoly, &bgCheckId,
|
||||
&camera->player->actor, &spAC);
|
||||
playerGroundY = BgCheck_EntityRaycastFloor5(camera->globalCtx, &camera->globalCtx->colCtx, &playerFloorPoly,
|
||||
&bgCheckId, &camera->player->actor, &spAC);
|
||||
if (playerGroundY != BGCHECK_Y_MIN) {
|
||||
// player is above ground.
|
||||
sOOBTimer = 0;
|
||||
camera->floorNorm.x = playerFloorPoly->norm.x * COLPOLY_NORM_FRAC;
|
||||
camera->floorNorm.y = playerFloorPoly->norm.y * COLPOLY_NORM_FRAC;
|
||||
camera->floorNorm.z = playerFloorPoly->norm.z * COLPOLY_NORM_FRAC;
|
||||
camera->floorNorm.x = COLPOLY_GET_NORMAL(playerFloorPoly->normal.x);
|
||||
camera->floorNorm.y = COLPOLY_GET_NORMAL(playerFloorPoly->normal.y);
|
||||
camera->floorNorm.z = COLPOLY_GET_NORMAL(playerFloorPoly->normal.z);
|
||||
camera->bgCheckId = bgCheckId;
|
||||
camera->playerGroundY = playerGroundY;
|
||||
} else {
|
||||
@@ -7378,7 +7381,7 @@ Vec3s* Camera_Update(Vec3s* outVec, Camera* camera) {
|
||||
camDataIdx = Camera_GetDataIdxForPoly(camera, &bgCheckId, playerFloorPoly);
|
||||
if (camDataIdx != -1) {
|
||||
camera->nextBGCheckId = bgCheckId;
|
||||
if (bgCheckId == 50) {
|
||||
if (bgCheckId == BGCHECK_SCENE) {
|
||||
camera->nextCamDataIdx = camDataIdx;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user