From 5e8e01f1109a7fc1c5353c0ff5f1ee8807757667 Mon Sep 17 00:00:00 2001 From: Tharo <17233964+Thar0@users.noreply.github.com> Date: Thu, 1 Feb 2024 01:09:16 +0000 Subject: [PATCH] z_view.c gc-eu-mq OK (#1681) * z_view.c retail * Replace PERSPECTIVE_EDITOR_ACTIVE, adjust PRINTF selection condition * Macro-ify View_ErrorCheckEyePosition --- include/functions.h | 2 + include/macros.h | 10 +++-- include/z64view.h | 6 +++ src/code/z_actor.c | 4 +- src/code/z_view.c | 85 +++++++++++++++++++++--------------- tools/m2ctx.py | 2 +- tools/permuter_settings.toml | 8 ++++ 7 files changed, 76 insertions(+), 41 deletions(-) diff --git a/include/functions.h b/include/functions.h index 95bf1ba6b9..db35c381ae 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1187,7 +1187,9 @@ s32 View_ApplyOrthoToOverlay(View* view); s32 View_ApplyPerspectiveToOverlay(View* view); s32 View_UpdateViewingMatrix(View* view); s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxP); +#if OOT_DEBUG s32 View_ErrorCheckEyePosition(f32 eyeX, f32 eyeY, f32 eyeZ); +#endif void ViMode_LogPrint(OSViMode* osViMode); 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); diff --git a/include/macros.h b/include/macros.h index 2a436718cb..7cb0c88a4b 100644 --- a/include/macros.h +++ b/include/macros.h @@ -100,13 +100,17 @@ #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 // 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 // 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 #else #define PRINTF(format, ...) (void)0 diff --git a/include/z64view.h b/include/z64view.h index e37d7026f2..5bce71f485 100644 --- a/include/z64view.h +++ b/include/z64view.h @@ -49,4 +49,10 @@ typedef struct { #define VIEW_FORCE_PROJECTION_PERSPECTIVE (VIEW_PROJECTION_PERSPECTIVE << 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 diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 86ff82728c..4ca742749a 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -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, 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 + 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, 1.0f, 0.0f, lightDir->x, lightDir->y, lightDir->z, lightDir->x, lightDir->y, lightDir->z, 16, 16); diff --git a/src/code/z_view.c b/src/code/z_view.c index 4b16385613..1d07362452 100644 --- a/src/code/z_view.c +++ b/src/code/z_view.c @@ -37,25 +37,30 @@ void View_Free(View* view) { void View_Init(View* view, GraphicsContext* gfxCtx) { view->gfxCtx = gfxCtx; + view->viewport.topY = 0; view->viewport.bottomY = SCREEN_HEIGHT; view->viewport.leftX = 0; view->viewport.rightX = SCREEN_WIDTH; + view->magic = 0x56494557; // "VIEW" - view->eye.x = 0.0f; - view->eye.y = 0.0f; + + if (sLogOnNextViewInit == false) {} + view->scale = 1.0f; view->fovy = 60.0f; view->zNear = 10.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->up.x = 0.0f; view->up.y = 1.0f; view->up.z = 0.0f; - view->eye.z = -1.0f; if (sLogOnNextViewInit) { - if (sLogOnNextViewInit == false) {} PRINTF("\nview: initialize ---\n"); sLogOnNextViewInit = false; } @@ -136,37 +141,38 @@ void View_GetViewport(View* view, Viewport* viewport) { } void View_ApplyLetterbox(View* view) { - s32 varY; - s32 varX; - s32 pad; + GraphicsContext* gfxCtx = view->gfxCtx; + s32 letterboxSize; + s32 pillarboxSize; s32 ulx; s32 uly; s32 lrx; 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) { - varX = 0; + if (pillarboxSize < 0) { + pillarboxSize = 0; } - if (varX > SCREEN_WIDTH / 2) { - varX = SCREEN_WIDTH / 2; + if (pillarboxSize > SCREEN_WIDTH / 2) { + pillarboxSize = SCREEN_WIDTH / 2; } - if (varY < 0) { - varY = 0; + if (letterboxSize < 0) { + letterboxSize = 0; } - if (varY > SCREEN_HEIGHT / 2) { - varY = SCREEN_HEIGHT / 2; + if (letterboxSize > SCREEN_HEIGHT / 2) { + letterboxSize = SCREEN_HEIGHT / 2; } - ulx = view->viewport.leftX + varX; - uly = view->viewport.topY + varY; - lrx = view->viewport.rightX - varX; - lry = view->viewport.bottomY - varY; + ulx = view->viewport.leftX + pillarboxSize; + uly = view->viewport.topY + letterboxSize; + lrx = view->viewport.rightX - pillarboxSize; + lry = view->viewport.bottomY - letterboxSize; ASSERT(ulx >= 0, "ulx >= 0", "../z_view.c", 454); 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) { - f32 aspect; + GraphicsContext* gfxCtx = view->gfxCtx; s32 width; s32 height; Vp* vp; Mtx* projection; Mtx* viewing; - GraphicsContext* gfxCtx = view->gfxCtx; + f32 aspect; OPEN_DISPS(gfxCtx, "../z_view.c", 596); @@ -310,7 +316,7 @@ s32 View_ApplyPerspective(View* view) { height = view->viewport.bottomY - view->viewport.topY; 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) { R_PERSPECTIVE_INIT = HREG_MODE_PERSPECTIVE; 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); } +#if OOT_DEBUG if (QREG(88) & 1) { s32 i; MtxF mf; @@ -339,6 +346,7 @@ s32 View_ApplyPerspective(View* view) { } PRINTF("\n"); } +#endif view->projection = *projection; @@ -360,24 +368,27 @@ s32 View_ApplyPerspective(View* view) { 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, view->up.z); view->viewing = *viewing; +#if OOT_DEBUG // Debug print view matrix if (QREG(88) & 2) { s32 i; MtxF mf; - Matrix_MtxToMtxF(view->viewingPtr, &mf); + PRINTF("viewing\n"); 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("\n"); } +#endif 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); @@ -426,11 +437,9 @@ s32 View_ApplyOrtho(View* view) { * Apply scissor, viewport and projection (ortho) to OVERLAY_DISP. */ s32 View_ApplyOrthoToOverlay(View* view) { + GraphicsContext* gfxCtx = view->gfxCtx; Vp* vp; Mtx* projection; - GraphicsContext* gfxCtx; - - gfxCtx = view->gfxCtx; 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. */ s32 View_ApplyPerspectiveToOverlay(View* view) { - s32 pad[2]; + GraphicsContext* gfxCtx = view->gfxCtx; + s32 pad; f32 aspect; s32 width; s32 height; Vp* vp; Mtx* projection; Mtx* viewing; - GraphicsContext* gfxCtx = view->gfxCtx; + s32 pad1; OPEN_DISPS(gfxCtx, "../z_view.c", 816); @@ -511,7 +521,8 @@ s32 View_ApplyPerspectiveToOverlay(View* view) { 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, view->up.z); @@ -530,7 +541,8 @@ s32 View_ApplyPerspectiveToOverlay(View* view) { s32 View_UpdateViewingMatrix(View* view) { 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, 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); 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, view->up.y, view->up.z); @@ -611,6 +624,7 @@ s32 View_ApplyTo(View* view, s32 mask, Gfx** gfxP) { return 1; } +#if OOT_DEBUG /** * 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; } +#endif diff --git a/tools/m2ctx.py b/tools/m2ctx.py index e8846b2fc1..7e5c522c8f 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -27,7 +27,7 @@ def get_c_file(directory): def import_c_file(in_file): 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] try: return subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") diff --git a/tools/permuter_settings.toml b/tools/permuter_settings.toml index ef882c5c62..57c19f3b50 100644 --- a/tools/permuter_settings.toml +++ b/tools/permuter_settings.toml @@ -8,6 +8,14 @@ LOG = "void" SET_FULLSCREEN_VIEWPORT = "void" OPEN_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" SQ = "int" CLAMP = "int"