From 475f167bb2803999c5116bc285601d1f9a05d7de Mon Sep 17 00:00:00 2001 From: MegaMech Date: Thu, 14 Nov 2024 23:32:55 -0700 Subject: [modding] Big Update PR (#118) * Implement kart vehicle * Fix menu CC * Actors * variable framerate * Implement Actors vector * Fix water & scrolling textures * Finish ACoin * Refactor finishline * Refactor mtx to vector * Fix refactored screen code bugs * Fix playlist bug * Switching courses working now * Fix podium ceremony * Mostly Fix Demo and Credits * Credits Load Actors and Textures * Fix credits * Formatting * Update lus and torch * Fix water features * Fix crabs * Combine function * Fix wheels * Add Moon Jump Cheat * Wheel Change * Fix smoke due to wheel change * Fix screens for wheels * Fix transparency * Fix staff ghost * Fix lakitu transition widescreen * Rename and export credits text * Fixes --------- Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com> --- src/engine/Matrix.cpp | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/engine/Matrix.cpp (limited to 'src/engine/Matrix.cpp') diff --git a/src/engine/Matrix.cpp b/src/engine/Matrix.cpp new file mode 100644 index 000000000..7b8c3b1fb --- /dev/null +++ b/src/engine/Matrix.cpp @@ -0,0 +1,123 @@ +#include +#include +#include "engine/World.h" + +extern "C" { +#include "common_structs.h" +} + +void AddMatrix(std::vector& stack, Mat4 mtx, s32 flags) { + // Reserve space if needed to avoid reallocation overhead + stack.reserve(1000); + + // Push a new matrix to the stack + stack.emplace_back(); + + // Convert to a fixed-point matrix + guMtxF2L(mtx, &stack.back()); + + // Load the matrix + gSPMatrix(gDisplayListHead++, &stack.back(), flags); +} + +Mtx* GetMatrix(std::vector& stack) { + stack.emplace_back(); + return &stack.back(); +} + +/** + * Use GetMatrix first + */ +void AddMatrixFixed(std::vector& stack, s32 flags) { + // Load the matrix + gSPMatrix(gDisplayListHead++, &stack.back(), flags); +} + +// Used in func_80095BD0 +void SetTextMatrix(f32 arg1, f32 arg2, f32 arg3, f32 arg4) { + Mat4 mtx; + mtx[0][0] = arg3; + mtx[0][1] = 0.0f; + mtx[0][2] = 0.0f; + mtx[0][3] = 0.0f; + mtx[1][0] = 0.0f; + mtx[1][1] = arg4; + mtx[1][2] = 0.0f; + mtx[1][3] = 0.0f; + mtx[2][0] = 0.0f; + mtx[2][1] = 0.0f; + mtx[2][2] = 1.0f; + mtx[2][3] = 0.0f; + mtx[3][0] = arg1; + mtx[3][1] = arg2; + mtx[3][2] = 0.0f; + mtx[3][3] = 1.0f; + + AddMatrix(gWorldInstance.Mtx.Effects, mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); +} + + +// API +extern "C" { + + void AddHudMatrix(Mat4 mtx, s32 flags) { + AddMatrix(gWorldInstance.Mtx.Hud, mtx, flags); + } + + void AddObjectMatrix(Mat4 mtx, s32 flags) { + AddMatrix(gWorldInstance.Mtx.Objects, mtx, flags); + } + + void AddShadowMatrix(Mat4 mtx, s32 flags) { + AddMatrix(gWorldInstance.Mtx.Shadows, mtx, flags); + } + + void AddKartMatrix(Mat4 mtx, s32 flags) { + AddMatrix(gWorldInstance.Mtx.Karts, mtx, flags); + } + + void AddEffectMatrix(Mat4 mtx, s32 flags) { + AddMatrix(gWorldInstance.Mtx.Effects, mtx, flags); + } + + void AddEffectMatrixFixed(s32 flags) { + AddMatrixFixed(gWorldInstance.Mtx.Effects, flags); + } + + void AddEffectMatrixOrtho(void) { + auto& stack = gWorldInstance.Mtx.Effects; + stack.emplace_back(); + + guOrtho(&stack.back(), 0.0f, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0.0f, -100.0f, 100.0f, 1.0f); + + gSPMatrix(gDisplayListHead++, &stack.back(), G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); + } + + Mtx* GetEffectMatrix(void) { + return GetMatrix(gWorldInstance.Mtx.Effects); + } + + + /** + * Note that the game doesn't seem to clear all of these at the beginning of a new frame. + * We might need to adjust which ones we clear. + */ + void ClearMatrixPools(void) { + gWorldInstance.Mtx.Hud.clear(); + gWorldInstance.Mtx.Objects.clear(); + gWorldInstance.Mtx.Shadows.clear(); + gWorldInstance.Mtx.Karts.clear(); + gWorldInstance.Mtx.Effects.clear(); + } + + void ClearHudMatrixPool(void) { + gWorldInstance.Mtx.Hud.clear(); + } + void ClearEffectsMatrixPool(void) { + gWorldInstance.Mtx.Effects.clear(); + } + + void ClearObjectsMatrixPool(void) { + gWorldInstance.Mtx.Objects.clear(); + } +} -- cgit v1.2.3