1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 04:24:43 +00:00

z_view.c gc-eu-mq OK (#1681)

* z_view.c retail

* Replace PERSPECTIVE_EDITOR_ACTIVE, adjust PRINTF selection condition

* Macro-ify View_ErrorCheckEyePosition
This commit is contained in:
Tharo 2024-02-01 01:09:16 +00:00 committed by GitHub
parent 2bc159e518
commit 5e8e01f110
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 76 additions and 41 deletions

View File

@ -1187,7 +1187,9 @@ s32 View_ApplyOrthoToOverlay(View* view);
s32 View_ApplyPerspectiveToOverlay(View* view); s32 View_ApplyPerspectiveToOverlay(View* view);
s32 View_UpdateViewingMatrix(View* view); s32 View_UpdateViewingMatrix(View* view);
s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxP); s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxP);
#if OOT_DEBUG
s32 View_ErrorCheckEyePosition(f32 eyeX, f32 eyeY, f32 eyeZ); s32 View_ErrorCheckEyePosition(f32 eyeX, f32 eyeY, f32 eyeZ);
#endif
void ViMode_LogPrint(OSViMode* osViMode); void ViMode_LogPrint(OSViMode* osViMode);
void ViMode_Configure(ViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 antialiasOff, s32 modeN, s32 fb16Bit, void ViMode_Configure(ViMode* viMode, s32 type, s32 tvType, s32 loRes, s32 antialiasOff, s32 modeN, s32 fb16Bit,
s32 width, s32 height, s32 leftAdjust, s32 rightAdjust, s32 upperAdjust, s32 lowerAdjust); s32 width, s32 height, s32 leftAdjust, s32 rightAdjust, s32 upperAdjust, s32 lowerAdjust);

View File

@ -100,13 +100,17 @@
#define CHECK_FLAG_ALL(flags, mask) (((flags) & (mask)) == (mask)) #define CHECK_FLAG_ALL(flags, mask) (((flags) & (mask)) == (mask))
#if OOT_DEBUG
#define PRINTF osSyncPrintf
#elif defined(__sgi) /* IDO compiler */
// IDO doesn't support variadic macros, but it merely throws a warning for the // IDO doesn't support variadic macros, but it merely throws a warning for the
// number of arguments not matching the definition (warning 609) instead of // number of arguments not matching the definition (warning 609) instead of
// throwing an error. We suppress this warning and rely on GCC to catch macro // throwing an error. We suppress this warning and rely on GCC to catch macro
// argument errors instead. // argument errors instead.
// Note some tools define __sgi but preprocess with a modern cpp implementation,
// ensure that these do not use the IDO workaround to avoid errors.
#define IDO_PRINTF_WORKAROUND (__sgi && !__GNUC__ && !PERMUTER && !M2CTX)
#if OOT_DEBUG
#define PRINTF osSyncPrintf
#elif IDO_PRINTF_WORKAROUND
#define PRINTF(args) (void)0 #define PRINTF(args) (void)0
#else #else
#define PRINTF(format, ...) (void)0 #define PRINTF(format, ...) (void)0

View File

@ -49,4 +49,10 @@ typedef struct {
#define VIEW_FORCE_PROJECTION_PERSPECTIVE (VIEW_PROJECTION_PERSPECTIVE << 4) #define VIEW_FORCE_PROJECTION_PERSPECTIVE (VIEW_PROJECTION_PERSPECTIVE << 4)
#define VIEW_FORCE_PROJECTION_ORTHO (VIEW_PROJECTION_ORTHO << 4) #define VIEW_FORCE_PROJECTION_ORTHO (VIEW_PROJECTION_ORTHO << 4)
#if OOT_DEBUG
#define VIEW_ERROR_CHECK_EYE_POS(x, y, z) View_ErrorCheckEyePosition((x), (y), (z))
#else
#define VIEW_ERROR_CHECK_EYE_POS(x, y, z) (void)0
#endif
#endif #endif

View File

@ -1398,10 +1398,10 @@ Gfx* func_8002E830(Vec3f* object, Vec3f* eye, Vec3f* lightDir, GraphicsContext*
PRINTF("z_actor.c 3529 eye=[%f(%f) %f %f] object=[%f %f %f] light_direction=[%f %f %f]\n", correctedEyeX, PRINTF("z_actor.c 3529 eye=[%f(%f) %f %f] object=[%f %f %f] light_direction=[%f %f %f]\n", correctedEyeX,
eye->x, eye->y, eye->z, object->x, object->y, object->z, lightDir->x, lightDir->y, lightDir->z); eye->x, eye->y, eye->z, object->x, object->y, object->z, lightDir->x, lightDir->y, lightDir->z);
} }
View_ErrorCheckEyePosition(correctedEyeX, eye->y, eye->z);
#endif #endif
VIEW_ERROR_CHECK_EYE_POS(correctedEyeX, eye->y, eye->z);
guLookAtHilite(&D_8015BBA8, lookAt, *hilite, correctedEyeX, eye->y, eye->z, object->x, object->y, object->z, 0.0f, guLookAtHilite(&D_8015BBA8, lookAt, *hilite, correctedEyeX, eye->y, eye->z, object->x, object->y, object->z, 0.0f,
1.0f, 0.0f, lightDir->x, lightDir->y, lightDir->z, lightDir->x, lightDir->y, lightDir->z, 16, 16); 1.0f, 0.0f, lightDir->x, lightDir->y, lightDir->z, lightDir->x, lightDir->y, lightDir->z, 16, 16);

View File

@ -37,25 +37,30 @@ void View_Free(View* view) {
void View_Init(View* view, GraphicsContext* gfxCtx) { void View_Init(View* view, GraphicsContext* gfxCtx) {
view->gfxCtx = gfxCtx; view->gfxCtx = gfxCtx;
view->viewport.topY = 0; view->viewport.topY = 0;
view->viewport.bottomY = SCREEN_HEIGHT; view->viewport.bottomY = SCREEN_HEIGHT;
view->viewport.leftX = 0; view->viewport.leftX = 0;
view->viewport.rightX = SCREEN_WIDTH; view->viewport.rightX = SCREEN_WIDTH;
view->magic = 0x56494557; // "VIEW" view->magic = 0x56494557; // "VIEW"
view->eye.x = 0.0f;
view->eye.y = 0.0f; if (sLogOnNextViewInit == false) {}
view->scale = 1.0f; view->scale = 1.0f;
view->fovy = 60.0f; view->fovy = 60.0f;
view->zNear = 10.0f; view->zNear = 10.0f;
view->zFar = 12800.0f; view->zFar = 12800.0f;
view->eye.x = 0.0f;
view->eye.y = 0.0f;
view->eye.z = -1.0f;
view->at.x = 0.0f; view->at.x = 0.0f;
view->up.x = 0.0f; view->up.x = 0.0f;
view->up.y = 1.0f; view->up.y = 1.0f;
view->up.z = 0.0f; view->up.z = 0.0f;
view->eye.z = -1.0f;
if (sLogOnNextViewInit) { if (sLogOnNextViewInit) {
if (sLogOnNextViewInit == false) {}
PRINTF("\nview: initialize ---\n"); PRINTF("\nview: initialize ---\n");
sLogOnNextViewInit = false; sLogOnNextViewInit = false;
} }
@ -136,37 +141,38 @@ void View_GetViewport(View* view, Viewport* viewport) {
} }
void View_ApplyLetterbox(View* view) { void View_ApplyLetterbox(View* view) {
s32 varY; GraphicsContext* gfxCtx = view->gfxCtx;
s32 varX; s32 letterboxSize;
s32 pad; s32 pillarboxSize;
s32 ulx; s32 ulx;
s32 uly; s32 uly;
s32 lrx; s32 lrx;
s32 lry; s32 lry;
GraphicsContext* gfxCtx = view->gfxCtx; s32 pad;
varY = Letterbox_GetSize(); letterboxSize = Letterbox_GetSize();
varX = -1; // The following is optimized to varX = 0 but affects codegen // The following is optimized to pillarboxSize = 0 but affects codegen
pillarboxSize = -1;
if (varX < 0) { if (pillarboxSize < 0) {
varX = 0; pillarboxSize = 0;
} }
if (varX > SCREEN_WIDTH / 2) { if (pillarboxSize > SCREEN_WIDTH / 2) {
varX = SCREEN_WIDTH / 2; pillarboxSize = SCREEN_WIDTH / 2;
} }
if (varY < 0) { if (letterboxSize < 0) {
varY = 0; letterboxSize = 0;
} }
if (varY > SCREEN_HEIGHT / 2) { if (letterboxSize > SCREEN_HEIGHT / 2) {
varY = SCREEN_HEIGHT / 2; letterboxSize = SCREEN_HEIGHT / 2;
} }
ulx = view->viewport.leftX + varX; ulx = view->viewport.leftX + pillarboxSize;
uly = view->viewport.topY + varY; uly = view->viewport.topY + letterboxSize;
lrx = view->viewport.rightX - varX; lrx = view->viewport.rightX - pillarboxSize;
lry = view->viewport.bottomY - varY; lry = view->viewport.bottomY - letterboxSize;
ASSERT(ulx >= 0, "ulx >= 0", "../z_view.c", 454); ASSERT(ulx >= 0, "ulx >= 0", "../z_view.c", 454);
ASSERT(uly >= 0, "uly >= 0", "../z_view.c", 455); ASSERT(uly >= 0, "uly >= 0", "../z_view.c", 455);
@ -280,13 +286,13 @@ void View_Apply(View* view, s32 mask) {
} }
s32 View_ApplyPerspective(View* view) { s32 View_ApplyPerspective(View* view) {
f32 aspect; GraphicsContext* gfxCtx = view->gfxCtx;
s32 width; s32 width;
s32 height; s32 height;
Vp* vp; Vp* vp;
Mtx* projection; Mtx* projection;
Mtx* viewing; Mtx* viewing;
GraphicsContext* gfxCtx = view->gfxCtx; f32 aspect;
OPEN_DISPS(gfxCtx, "../z_view.c", 596); OPEN_DISPS(gfxCtx, "../z_view.c", 596);
@ -310,7 +316,7 @@ s32 View_ApplyPerspective(View* view) {
height = view->viewport.bottomY - view->viewport.topY; height = view->viewport.bottomY - view->viewport.topY;
aspect = (f32)width / (f32)height; aspect = (f32)width / (f32)height;
if (R_HREG_MODE == HREG_MODE_PERSPECTIVE) { if (OOT_DEBUG && R_HREG_MODE == HREG_MODE_PERSPECTIVE) {
if (R_PERSPECTIVE_INIT != HREG_MODE_PERSPECTIVE) { if (R_PERSPECTIVE_INIT != HREG_MODE_PERSPECTIVE) {
R_PERSPECTIVE_INIT = HREG_MODE_PERSPECTIVE; R_PERSPECTIVE_INIT = HREG_MODE_PERSPECTIVE;
R_PERSPECTIVE_FOVY = 60; R_PERSPECTIVE_FOVY = 60;
@ -325,6 +331,7 @@ s32 View_ApplyPerspective(View* view) {
guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale); guPerspective(projection, &view->normal, view->fovy, aspect, view->zNear, view->zFar, view->scale);
} }
#if OOT_DEBUG
if (QREG(88) & 1) { if (QREG(88) & 1) {
s32 i; s32 i;
MtxF mf; MtxF mf;
@ -339,6 +346,7 @@ s32 View_ApplyPerspective(View* view) {
} }
PRINTF("\n"); PRINTF("\n");
} }
#endif
view->projection = *projection; view->projection = *projection;
@ -360,24 +368,27 @@ s32 View_ApplyPerspective(View* view) {
view->eye.z += 1.0f; view->eye.z += 1.0f;
} }
View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z); VIEW_ERROR_CHECK_EYE_POS(view->eye.x, view->eye.y, view->eye.z);
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x, view->up.y, guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x, view->up.y,
view->up.z); view->up.z);
view->viewing = *viewing; view->viewing = *viewing;
#if OOT_DEBUG
// Debug print view matrix // Debug print view matrix
if (QREG(88) & 2) { if (QREG(88) & 2) {
s32 i; s32 i;
MtxF mf; MtxF mf;
Matrix_MtxToMtxF(view->viewingPtr, &mf); Matrix_MtxToMtxF(view->viewingPtr, &mf);
PRINTF("viewing\n"); PRINTF("viewing\n");
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
PRINTF("\t%f\t%f\t%f\t%f\n", mf.mf[i][0], mf.mf[i][1], mf.mf[i][2], mf.mf[i][3]); PRINTF("\t%f\t%f\t%f\t%f\n", mf.mf[i][0], mf.mf[i][1], mf.mf[i][2], mf.mf[i][3]);
} }
PRINTF("\n"); PRINTF("\n");
} }
#endif
gSPMatrix(POLY_OPA_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION); gSPMatrix(POLY_OPA_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
gSPMatrix(POLY_XLU_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION); gSPMatrix(POLY_XLU_DISP++, viewing, G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION);
@ -426,11 +437,9 @@ s32 View_ApplyOrtho(View* view) {
* Apply scissor, viewport and projection (ortho) to OVERLAY_DISP. * Apply scissor, viewport and projection (ortho) to OVERLAY_DISP.
*/ */
s32 View_ApplyOrthoToOverlay(View* view) { s32 View_ApplyOrthoToOverlay(View* view) {
GraphicsContext* gfxCtx = view->gfxCtx;
Vp* vp; Vp* vp;
Mtx* projection; Mtx* projection;
GraphicsContext* gfxCtx;
gfxCtx = view->gfxCtx;
OPEN_DISPS(gfxCtx, "../z_view.c", 777); OPEN_DISPS(gfxCtx, "../z_view.c", 777);
@ -464,14 +473,15 @@ s32 View_ApplyOrthoToOverlay(View* view) {
* Apply scissor, viewport, view and projection (perspective) to OVERLAY_DISP. * Apply scissor, viewport, view and projection (perspective) to OVERLAY_DISP.
*/ */
s32 View_ApplyPerspectiveToOverlay(View* view) { s32 View_ApplyPerspectiveToOverlay(View* view) {
s32 pad[2]; GraphicsContext* gfxCtx = view->gfxCtx;
s32 pad;
f32 aspect; f32 aspect;
s32 width; s32 width;
s32 height; s32 height;
Vp* vp; Vp* vp;
Mtx* projection; Mtx* projection;
Mtx* viewing; Mtx* viewing;
GraphicsContext* gfxCtx = view->gfxCtx; s32 pad1;
OPEN_DISPS(gfxCtx, "../z_view.c", 816); OPEN_DISPS(gfxCtx, "../z_view.c", 816);
@ -511,7 +521,8 @@ s32 View_ApplyPerspectiveToOverlay(View* view) {
view->eye.z += 1.0f; view->eye.z += 1.0f;
} }
View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z); VIEW_ERROR_CHECK_EYE_POS(view->eye.x, view->eye.y, view->eye.z);
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x, view->up.y, guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x, view->up.y,
view->up.z); view->up.z);
@ -530,7 +541,8 @@ s32 View_ApplyPerspectiveToOverlay(View* view) {
s32 View_UpdateViewingMatrix(View* view) { s32 View_UpdateViewingMatrix(View* view) {
OPEN_DISPS(view->gfxCtx, "../z_view.c", 878); OPEN_DISPS(view->gfxCtx, "../z_view.c", 878);
View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z); VIEW_ERROR_CHECK_EYE_POS(view->eye.x, view->eye.y, view->eye.z);
guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x, guLookAt(view->viewingPtr, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x,
view->up.y, view->up.z); view->up.y, view->up.z);
@ -596,7 +608,8 @@ s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxP) {
LOG_UTILS_CHECK_NULL_POINTER("viewing", viewing, "../z_view.c", 948); LOG_UTILS_CHECK_NULL_POINTER("viewing", viewing, "../z_view.c", 948);
view->viewingPtr = viewing; view->viewingPtr = viewing;
View_ErrorCheckEyePosition(view->eye.x, view->eye.y, view->eye.z); VIEW_ERROR_CHECK_EYE_POS(view->eye.x, view->eye.y, view->eye.z);
guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x, guLookAt(viewing, view->eye.x, view->eye.y, view->eye.z, view->at.x, view->at.y, view->at.z, view->up.x,
view->up.y, view->up.z); view->up.y, view->up.z);
@ -611,6 +624,7 @@ s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxP) {
return 1; return 1;
} }
#if OOT_DEBUG
/** /**
* Logs an error and returns nonzero if camera is too far from the origin. * Logs an error and returns nonzero if camera is too far from the origin.
*/ */
@ -640,3 +654,4 @@ s32 View_ErrorCheckEyePosition(f32 eyeX, f32 eyeY, f32 eyeZ) {
return error; return error;
} }
#endif

View File

@ -27,7 +27,7 @@ def get_c_file(directory):
def import_c_file(in_file): def import_c_file(in_file):
in_file = os.path.relpath(in_file, root_dir) in_file = os.path.relpath(in_file, root_dir)
cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Isrc", "-undef", "-D__sgi", "-D_LANGUAGE_C", cpp_command = ["gcc", "-E", "-P", "-Iinclude", "-Isrc", "-undef", "-DM2CTX", "-D__sgi", "-D_LANGUAGE_C",
"-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", in_file] "-DNON_MATCHING", "-D_Static_assert(x, y)=", "-D__attribute__(x)=", in_file]
try: try:
return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8")

View File

@ -8,6 +8,14 @@ LOG = "void"
SET_FULLSCREEN_VIEWPORT = "void" SET_FULLSCREEN_VIEWPORT = "void"
OPEN_DISPS = "void" OPEN_DISPS = "void"
CLOSE_DISPS = "void" CLOSE_DISPS = "void"
GRAPH_ALLOC = "void*"
LOG_UTILS_CHECK_NULL_POINTER = "void"
PRINTF = "void"
WORK_DISP = "void*"
POLY_OPA_DISP = "void*"
POLY_XLU_DISP = "void*"
OVERLAY_DISP = "void*"
"G_MTX_.*" = "int"
ABS = "int" ABS = "int"
SQ = "int" SQ = "int"
CLAMP = "int" CLAMP = "int"