diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index c2a44de59..c6631b5db 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -185,7 +185,6 @@ static Vp sViewportPrev = { 0 }; static Vp sViewportInterp = { 0 }; Gfx* gBackgroundSkyboxGfx = NULL; -Vtx* gBackgroundSkyboxVerts[SKYBOX_TILES_Y][SKYBOX_TILES_X] = { 0 }; Mtx* gBackgroundSkyboxMtx = NULL; static struct GraphNodeBackground* sBackgroundNode = NULL; @@ -1090,7 +1089,7 @@ static void anim_process(Vec3f translation, Vec3s rotation, u8 *animType, s16 an rotation[1] += retrieve_animation_value(gCurAnim, animFrame, animAttribute); rotation[2] += retrieve_animation_value(gCurAnim, animFrame, animAttribute); if (gCurAnim->flags & ANIM_FLAG_BONE_TRANS) { - *animType = ANIM_TYPE_TRANSLATION; + *animType = ANIM_TYPE_TRANSLATION; } } } @@ -1944,7 +1943,6 @@ static void geo_clear_interp_variables(void) { sBackgroundNode = NULL; gBackgroundSkyboxGfx = NULL; - memset(gBackgroundSkyboxVerts, 0, sizeof(Vtx*) * SKYBOX_TILES_Y * SKYBOX_TILES_X); gBackgroundSkyboxMtx = NULL; sBackgroundNodeRoot = NULL; diff --git a/src/game/skybox.c b/src/game/skybox.c index dc6cdb69e..e8d9815c2 100644 --- a/src/game/skybox.c +++ b/src/game/skybox.c @@ -131,6 +131,10 @@ u8 sSkyboxColors[][3] = { */ #define SKYBOX_ROWS (8) +static u16 sSkyboxTileNumX = 5; +static const u16 sSkyboxTileNumY = 3; // Shouldn't need to change this + +struct GrowingArray *gBackgroundSkyboxVerts = NULL; /** * Convert the camera's yaw into an x position into the scaled skybox image. @@ -188,14 +192,13 @@ f32 calculate_skybox_scaled_y(s8 player, UNUSED f32 fov) { * SKYBOX_TILE_WIDTH to get a point in world space. */ Vtx *make_skybox_rect(s32 tileRow, s32 tileCol, s8 colorIndex, s32 row, s32 col) { - extern Vtx* gBackgroundSkyboxVerts[SKYBOX_TILES_Y][SKYBOX_TILES_X]; - + u16 index = row * sSkyboxTileNumX + col; Vtx *verts; if (gRenderingInterpolated) { - verts = gBackgroundSkyboxVerts[row][col]; + verts = gBackgroundSkyboxVerts->buffer[index]; } else { verts = alloc_display_list(4 * sizeof(*verts)); - gBackgroundSkyboxVerts[row][col] = verts; + gBackgroundSkyboxVerts->buffer[index] = verts; } f32 x = tileCol * SKYBOX_TILE_WIDTH; @@ -223,10 +226,11 @@ void draw_skybox_tile_grid(Gfx **dlist, s8 background, s8 player, s8 colorIndex) s32 row; s32 col; - for (row = 0; row < SKYBOX_TILES_Y; row++) { - for (col = 0; col < SKYBOX_TILES_X; col++) { + s32 colOffset = (sSkyboxTileNumX / 2) - 1; + for (row = 0; row < sSkyboxTileNumY; row++) { + for (col = 0; col < sSkyboxTileNumX; col++) { s32 tileRow = (s32) (((SKYBOX_HEIGHT - sSkyBoxInfo[player].scaledY) / SKYBOX_TILE_HEIGHT) + row) * SKYBOX_COLS; - s32 tileColTmp = ((floor(sSkyBoxInfo[player].scaledX / SKYBOX_TILE_WIDTH) + col) - 1); + s32 tileColTmp = ((floor(sSkyBoxInfo[player].scaledX / SKYBOX_TILE_WIDTH) + col) - colOffset); s32 tileCol = tileColTmp; if (tileCol >= SKYBOX_ROWS) { tileCol -= SKYBOX_ROWS; } if (tileCol < 0) { tileCol += SKYBOX_ROWS; } @@ -266,15 +270,6 @@ void *create_skybox_ortho_matrix(s8 player) { gBackgroundSkyboxMtx = mtx; } - // Stretch the screen to hide sides of skybox - f32 half_width = (21.0f / 9.0f) / GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_WIDTH / 2; - f32 center = (sSkyBoxInfo[player].scaledX + SCREEN_WIDTH / 2); - if (half_width < SCREEN_WIDTH / 2) { - // A wider screen than 21:9 - left = center - half_width; - right = center + half_width; - } - if (mtx != NULL) { guOrtho(mtx, left, right, bottom, top, 0.0f, 3.0f, 1.0f); } else { @@ -289,7 +284,7 @@ void *create_skybox_ortho_matrix(s8 player) { Gfx *init_skybox_display_list(s8 player, s8 background, s8 colorIndex) { extern Gfx* gBackgroundSkyboxGfx; - s32 dlCommandCount = 5 + (SKYBOX_TILES_Y * SKYBOX_TILES_X) * 7; // 5 for the start and end, plus the amount of skybox tiles + s32 dlCommandCount = 5 + (sSkyboxTileNumY * sSkyboxTileNumX) * 7; // 5 for the start and end, plus the amount of skybox tiles void *skybox; if (gRenderingInterpolated) { @@ -330,6 +325,28 @@ Gfx *init_skybox_display_list(s8 player, s8 background, s8 colorIndex) { Gfx *create_skybox_facing_camera(s8 player, s8 background, f32 fov, f32 posX, f32 posY, f32 posZ, f32 focX, f32 focY, f32 focZ) { + if (!gBackgroundSkyboxVerts) { + gBackgroundSkyboxVerts = growing_array_init(NULL, sSkyboxTileNumY * sSkyboxTileNumX, malloc, free); + gBackgroundSkyboxVerts->count = sSkyboxTileNumY * sSkyboxTileNumX; + if (!gBackgroundSkyboxVerts) { + sys_fatal("Cannot allocate skybox vertex buffer"); + } + } + + if (!gRenderingInterpolated) { + f32 skyboxAspectRatio = ((f32)sSkyboxTileNumX * (f32)SKYBOX_TILE_WIDTH) / ((f32)sSkyboxTileNumY * (f32)SKYBOX_TILE_HEIGHT); + f32 half_width = skyboxAspectRatio / GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_WIDTH / 2; + if (half_width < SCREEN_WIDTH / 2) { + // how many horizontal tiles are needed to match the screen aspect ratio + f32 minTilesX = sSkyboxTileNumY * ((f32)SKYBOX_TILE_HEIGHT / (f32)SKYBOX_TILE_WIDTH) * GFX_DIMENSIONS_ASPECT_RATIO; + sSkyboxTileNumX = (u16) ceilf(minTilesX); + + // Update vertex buffer size + gBackgroundSkyboxVerts->count = sSkyboxTileNumY * sSkyboxTileNumX; + growing_array_alloc(gBackgroundSkyboxVerts, 0); + } + } + gReadOnlyBackground = background; background = gOverrideBackground == -1 ? background : gOverrideBackground; diff --git a/src/game/skybox.h b/src/game/skybox.h index 043020e8c..5bd617edc 100644 --- a/src/game/skybox.h +++ b/src/game/skybox.h @@ -4,8 +4,6 @@ #include #include -#define SKYBOX_TILES_X 5 -#define SKYBOX_TILES_Y 3 extern s8 gReadOnlyBackground; extern s8 gOverrideBackground;