sm64pc/src/game/screen_transition.c

300 lines
14 KiB
C
Raw Normal View History

2019-08-25 04:46:40 +00:00
#include <ultra64.h>
#include "sm64.h"
2020-05-07 18:21:22 +00:00
#include "gfx_dimensions.h"
2019-08-25 04:46:40 +00:00
#include "area.h"
2020-04-03 18:57:26 +00:00
#include "game/game_init.h"
2019-08-25 04:46:40 +00:00
#include "engine/math_util.h"
#include "engine/graph_node.h"
2019-12-02 02:52:53 +00:00
#include "screen_transition.h"
2019-08-25 04:46:40 +00:00
#include "memory.h"
#include "geo_misc.h"
#include "segment2.h"
2020-01-03 15:38:57 +00:00
#include "camera.h"
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
u8 sTransitionColorFadeCount[4] = { 0 };
u16 sTransitionTextureFadeCount[2] = { 0 };
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
s32 set_and_reset_transition_fade_timer(s8 fadeTimer, u8 transTime) {
s32 reset = FALSE;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
sTransitionColorFadeCount[fadeTimer]++;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
if (sTransitionColorFadeCount[fadeTimer] == transTime) {
sTransitionColorFadeCount[fadeTimer] = 0;
sTransitionTextureFadeCount[fadeTimer] = 0;
reset = TRUE;
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
return reset;
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
u8 set_transition_color_fade_alpha(s8 fadeType, s8 fadeTimer, u8 transTime) {
u8 time;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
switch (fadeType) {
2019-08-25 04:46:40 +00:00
case 0:
2019-12-02 02:52:53 +00:00
time = (f32) sTransitionColorFadeCount[fadeTimer] * 255.0 / (f32)(transTime - 1) + 0.5; // fade in
2019-08-25 04:46:40 +00:00
break;
case 1:
2019-12-02 02:52:53 +00:00
time = (1.0 - sTransitionColorFadeCount[fadeTimer] / (f32)(transTime - 1)) * 255.0 + 0.5; // fade out
2019-08-25 04:46:40 +00:00
break;
}
2019-12-02 02:52:53 +00:00
return time;
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
Vtx *vertex_transition_color(struct WarpTransitionData *transData, u8 alpha) {
2019-08-25 04:46:40 +00:00
Vtx *verts = alloc_display_list(4 * sizeof(*verts));
u8 r = transData->red;
u8 g = transData->green;
u8 b = transData->blue;
if (verts != NULL) {
2020-05-07 18:21:22 +00:00
make_vertex(verts, 0, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), 0, -1, 0, 0, r, g, b, alpha);
make_vertex(verts, 1, GFX_DIMENSIONS_FROM_RIGHT_EDGE(0), 0, -1, 0, 0, r, g, b, alpha);
make_vertex(verts, 2, GFX_DIMENSIONS_FROM_RIGHT_EDGE(0), SCREEN_HEIGHT, -1, 0, 0, r, g, b, alpha);
make_vertex(verts, 3, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), SCREEN_HEIGHT, -1, 0, 0, r, g, b, alpha);
2019-08-25 04:46:40 +00:00
} else {
}
return verts;
}
2019-12-02 02:52:53 +00:00
s32 dl_transition_color(s8 fadeTimer, u8 transTime, struct WarpTransitionData *transData, u8 alpha) {
Vtx *verts = vertex_transition_color(transData, alpha);
2019-08-25 04:46:40 +00:00
if (verts != NULL) {
2019-11-03 19:36:27 +00:00
gSPDisplayList(gDisplayListHead++, dl_proj_mtx_fullscreen);
gDPSetCombineMode(gDisplayListHead++, G_CC_SHADE, G_CC_SHADE);
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2);
gSPVertex(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(verts), 4, 0);
gSPDisplayList(gDisplayListHead++, dl_draw_quad_verts_0123);
gSPDisplayList(gDisplayListHead++, dl_screen_transition_end);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
return set_and_reset_transition_fade_timer(fadeTimer, transTime);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
s32 render_fade_transition_from_color(s8 fadeTimer, u8 transTime, struct WarpTransitionData *transData) {
u8 alpha = set_transition_color_fade_alpha(1, fadeTimer, transTime);
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return dl_transition_color(fadeTimer, transTime, transData, alpha);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
s32 render_fade_transition_into_color(s8 fadeTimer, u8 transTime, struct WarpTransitionData *transData) {
u8 alpha = set_transition_color_fade_alpha(0, fadeTimer, transTime);
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return dl_transition_color(fadeTimer, transTime, transData, alpha);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
s16 calc_tex_transition_radius(s8 fadeTimer, s8 transTime, struct WarpTransitionData *transData) {
f32 texRadius = transData->endTexRadius - transData->startTexRadius;
f32 radiusTime = sTransitionColorFadeCount[fadeTimer] * texRadius / (f32)(transTime - 1);
f32 result = transData->startTexRadius + radiusTime;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return (s16)(result + 0.5);;
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
f32 calc_tex_transition_time(s8 fadeTimer, s8 transTime, struct WarpTransitionData *transData) {
f32 startX = transData->startTexX;
f32 startY = transData->startTexY;
f32 endX = transData->endTexX;
f32 endY = transData->endTexY;
f32 sqrtfXY = sqrtf((startX - endX) * (startX - endX) + (startY - endY) * (startY - endY));
f32 result = (f32) sTransitionColorFadeCount[fadeTimer] * sqrtfXY / (f32)(transTime - 1);
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return result;
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
u16 convert_tex_transition_angle_to_pos(struct WarpTransitionData *transData) {
f32 x = transData->endTexX - transData->startTexX;
f32 y = transData->endTexY - transData->startTexY;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return atan2s(x, y);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
s16 center_tex_transition_x(struct WarpTransitionData *transData, f32 texTransTime, u16 texTransPos) {
f32 x = transData->startTexX + coss(texTransPos) * texTransTime;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return (s16)(x + 0.5);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
s16 center_tex_transition_y(struct WarpTransitionData *transData, f32 texTransTime, u16 texTransPos) {
f32 y = transData->startTexY + sins(texTransPos) * texTransTime;
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
return (s16)(y + 0.5);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
void make_tex_transition_vertex(Vtx *verts, s32 n, s8 fadeTimer, struct WarpTransitionData *transData, s16 centerTransX, s16 centerTransY,
s16 texRadius1, s16 texRadius2, s16 tx, s16 ty) {
2019-08-25 04:46:40 +00:00
u8 r = transData->red;
u8 g = transData->green;
u8 b = transData->blue;
2019-12-02 02:52:53 +00:00
u16 zeroTimer = sTransitionTextureFadeCount[fadeTimer];
f32 centerX = texRadius1 * coss(zeroTimer) - texRadius2 * sins(zeroTimer) + centerTransX;
f32 centerY = texRadius1 * sins(zeroTimer) + texRadius2 * coss(zeroTimer) + centerTransY;
s16 x = round_float(centerX);
s16 y = round_float(centerY);
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
make_vertex(verts, n, x, y, -1, tx * 32, ty * 32, r, g, b, 255);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
void load_tex_transition_vertex(Vtx *verts, s8 fadeTimer, struct WarpTransitionData *transData, s16 centerTransX, s16 centerTransY,
s16 texTransRadius, s8 transTexType) {
switch (transTexType) {
case TRANS_TYPE_MIRROR:
make_tex_transition_vertex(verts, 0, fadeTimer, transData, centerTransX, centerTransY, -texTransRadius, -texTransRadius, -31, 63);
make_tex_transition_vertex(verts, 1, fadeTimer, transData, centerTransX, centerTransY, texTransRadius, -texTransRadius, 31, 63);
make_tex_transition_vertex(verts, 2, fadeTimer, transData, centerTransX, centerTransY, texTransRadius, texTransRadius, 31, 0);
make_tex_transition_vertex(verts, 3, fadeTimer, transData, centerTransX, centerTransY, -texTransRadius, texTransRadius, -31, 0);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case TRANS_TYPE_CLAMP:
make_tex_transition_vertex(verts, 0, fadeTimer, transData, centerTransX, centerTransY, -texTransRadius, -texTransRadius, 0, 63);
make_tex_transition_vertex(verts, 1, fadeTimer, transData, centerTransX, centerTransY, texTransRadius, -texTransRadius, 63, 63);
make_tex_transition_vertex(verts, 2, fadeTimer, transData, centerTransX, centerTransY, texTransRadius, texTransRadius, 63, 0);
make_tex_transition_vertex(verts, 3, fadeTimer, transData, centerTransX, centerTransY, -texTransRadius, texTransRadius, 0, 0);
2019-08-25 04:46:40 +00:00
break;
}
2019-12-02 02:52:53 +00:00
make_tex_transition_vertex(verts, 4, fadeTimer, transData, centerTransX, centerTransY, -2000, -2000, 0, 0);
make_tex_transition_vertex(verts, 5, fadeTimer, transData, centerTransX, centerTransY, 2000, -2000, 0, 0);
make_tex_transition_vertex(verts, 6, fadeTimer, transData, centerTransX, centerTransY, 2000, 2000, 0, 0);
make_tex_transition_vertex(verts, 7, fadeTimer, transData, centerTransX, centerTransY, -2000, 2000, 0, 0);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
void *sTextureTransitionID[] = {
2019-08-25 04:46:40 +00:00
texture_transition_star_half,
texture_transition_circle_half,
texture_transition_mario,
texture_transition_bowser_half,
};
2019-12-02 02:52:53 +00:00
s32 render_textured_transition(s8 fadeTimer, s8 transTime, struct WarpTransitionData *transData, s8 texID, s8 transTexType) {
f32 texTransTime = calc_tex_transition_time(fadeTimer, transTime, transData);
u16 texTransPos = convert_tex_transition_angle_to_pos(transData);
s16 centerTransX = center_tex_transition_x(transData, texTransTime, texTransPos);
s16 centerTransY = center_tex_transition_y(transData, texTransTime, texTransPos);
s16 texTransRadius = calc_tex_transition_radius(fadeTimer, transTime, transData);
Vtx *verts = alloc_display_list(8 * sizeof(*verts));
2019-08-25 04:46:40 +00:00
2019-12-02 02:52:53 +00:00
if (verts != NULL) {
load_tex_transition_vertex(verts, fadeTimer, transData, centerTransX, centerTransY, texTransRadius, transTexType);
gSPDisplayList(gDisplayListHead++, dl_proj_mtx_fullscreen)
2019-11-03 19:36:27 +00:00
gDPSetCombineMode(gDisplayListHead++, G_CC_SHADE, G_CC_SHADE);
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_OPA_SURF, G_RM_AA_OPA_SURF2);
2019-12-02 02:52:53 +00:00
gSPVertex(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(verts), 8, 0);
2019-11-03 19:36:27 +00:00
gSPDisplayList(gDisplayListHead++, dl_transition_draw_filled_region);
gDPPipeSync(gDisplayListHead++);
gDPSetCombineMode(gDisplayListHead++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA);
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2);
2019-12-02 02:52:53 +00:00
gDPSetTextureFilter(gDisplayListHead++, G_TF_BILERP);
2020-05-07 18:21:22 +00:00
switch (transTexType) {
2019-12-02 02:52:53 +00:00
case TRANS_TYPE_MIRROR:
gDPLoadTextureBlock(gDisplayListHead++, sTextureTransitionID[texID], G_IM_FMT_IA, G_IM_SIZ_8b, 32, 64, 0,
2019-11-03 19:36:27 +00:00
G_TX_WRAP | G_TX_MIRROR, G_TX_WRAP | G_TX_MIRROR, 5, 6, G_TX_NOLOD, G_TX_NOLOD);
break;
2019-12-02 02:52:53 +00:00
case TRANS_TYPE_CLAMP:
gDPLoadTextureBlock(gDisplayListHead++, sTextureTransitionID[texID], G_IM_FMT_IA, G_IM_SIZ_8b, 64, 64, 0,
2019-11-03 19:36:27 +00:00
G_TX_CLAMP, G_TX_CLAMP, 6, 6, G_TX_NOLOD, G_TX_NOLOD);
break;
2019-08-25 04:46:40 +00:00
}
2019-11-03 19:36:27 +00:00
gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
2019-12-02 02:52:53 +00:00
gSPVertex(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(verts), 4, 0);
2019-11-03 19:36:27 +00:00
gSPDisplayList(gDisplayListHead++, dl_draw_quad_verts_0123);
gSPTexture(gDisplayListHead++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF);
gSPDisplayList(gDisplayListHead++, dl_screen_transition_end);
2019-12-02 02:52:53 +00:00
sTransitionTextureFadeCount[fadeTimer] += transData->texTimer;
2019-08-25 04:46:40 +00:00
} else {
}
2019-12-02 02:52:53 +00:00
return set_and_reset_transition_fade_timer(fadeTimer, transTime);
2019-08-25 04:46:40 +00:00
}
2019-12-02 02:52:53 +00:00
int render_screen_transition(s8 fadeTimer, s8 transType, u8 transTime, struct WarpTransitionData *transData) {
switch (transType) {
case WARP_TRANSITION_FADE_FROM_COLOR:
return render_fade_transition_from_color(fadeTimer, transTime, transData);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_INTO_COLOR:
return render_fade_transition_into_color(fadeTimer, transTime, transData);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_FROM_STAR:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_STAR, TRANS_TYPE_MIRROR);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_INTO_STAR:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_STAR, TRANS_TYPE_MIRROR);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_FROM_CIRCLE:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_CIRCLE, TRANS_TYPE_MIRROR);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_INTO_CIRCLE:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_CIRCLE, TRANS_TYPE_MIRROR);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_FROM_MARIO:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_MARIO, TRANS_TYPE_CLAMP);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_INTO_MARIO:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_MARIO, TRANS_TYPE_CLAMP);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_FROM_BOWSER:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_BOWSER, TRANS_TYPE_MIRROR);
2019-08-25 04:46:40 +00:00
break;
2019-12-02 02:52:53 +00:00
case WARP_TRANSITION_FADE_INTO_BOWSER:
return render_textured_transition(fadeTimer, transTime, transData, TEX_TRANS_BOWSER, TRANS_TYPE_MIRROR);
2019-08-25 04:46:40 +00:00
break;
}
}
2019-12-02 02:52:53 +00:00
Gfx *render_cannon_circle_base(void) {
2020-05-07 18:21:22 +00:00
#ifdef TARGET_N64
2019-08-25 04:46:40 +00:00
Vtx *verts = alloc_display_list(4 * sizeof(*verts));
Gfx *dlist = alloc_display_list(16 * sizeof(*dlist));
2020-05-07 18:21:22 +00:00
#else
Vtx *verts = alloc_display_list(8 * sizeof(*verts));
Gfx *dlist = alloc_display_list(20 * sizeof(*dlist));
#endif
2019-08-25 04:46:40 +00:00
Gfx *g = dlist;
if (verts != NULL && dlist != NULL) {
make_vertex(verts, 0, 0, 0, -1, -1152, 1824, 0, 0, 0, 255);
2019-12-02 02:52:53 +00:00
make_vertex(verts, 1, SCREEN_WIDTH, 0, -1, 1152, 1824, 0, 0, 0, 255);
make_vertex(verts, 2, SCREEN_WIDTH, SCREEN_HEIGHT, -1, 1152, 192, 0, 0, 0, 255);
make_vertex(verts, 3, 0, SCREEN_HEIGHT, -1, -1152, 192, 0, 0, 0, 255);
2019-08-25 04:46:40 +00:00
2020-05-07 18:21:22 +00:00
#ifndef TARGET_N64
make_vertex(verts, 4, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), 0, -1, 0, 0, 0, 0, 0, 255);
make_vertex(verts, 5, GFX_DIMENSIONS_FROM_RIGHT_EDGE(0), 0, -1, 0, 0, 0, 0, 0, 255);
make_vertex(verts, 6, GFX_DIMENSIONS_FROM_RIGHT_EDGE(0), SCREEN_HEIGHT, -1, 0, 0, 0, 0, 0, 255);
make_vertex(verts, 7, GFX_DIMENSIONS_FROM_LEFT_EDGE(0), SCREEN_HEIGHT, -1, 0, 0, 0, 0, 0, 255);
#endif
2019-12-02 02:52:53 +00:00
gSPDisplayList(g++, dl_proj_mtx_fullscreen);
2019-11-03 19:36:27 +00:00
gDPSetCombineMode(g++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA);
gDPSetTextureFilter(g++, G_TF_BILERP);
2019-12-02 02:52:53 +00:00
gDPLoadTextureBlock(g++, sTextureTransitionID[TEX_TRANS_CIRCLE], G_IM_FMT_IA, G_IM_SIZ_8b, 32, 64, 0,
2019-11-03 19:36:27 +00:00
G_TX_WRAP | G_TX_MIRROR, G_TX_WRAP | G_TX_MIRROR, 5, 6, G_TX_NOLOD, G_TX_NOLOD);
gSPTexture(g++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_ON);
gSPVertex(g++, VIRTUAL_TO_PHYSICAL(verts), 4, 0);
gSPDisplayList(g++, dl_draw_quad_verts_0123);
gSPTexture(g++, 0xFFFF, 0xFFFF, 0, G_TX_RENDERTILE, G_OFF);
2020-05-07 18:21:22 +00:00
#ifndef TARGET_N64
gDPSetCombineMode(g++, G_CC_SHADE, G_CC_SHADE);
gSPVertex(g++, VIRTUAL_TO_PHYSICAL(verts + 4), 4, 4);
gSP2Triangles(g++, 4, 0, 3, 0, 4, 3, 7, 0);
gSP2Triangles(g++, 1, 5, 6, 0, 1, 6, 2, 0);
#endif
2019-11-03 19:36:27 +00:00
gSPDisplayList(g++, dl_screen_transition_end);
gSPEndDisplayList(g);
2019-08-25 04:46:40 +00:00
} else {
return NULL;
}
return dlist;
}
2019-12-02 02:52:53 +00:00
Gfx *geo_cannon_circle_base(s32 callContext, struct GraphNode *node, UNUSED f32 mtx[4][4]) {
struct GraphNodeGenerated *graphNode = (struct GraphNodeGenerated *) node;
2019-08-25 04:46:40 +00:00
Gfx *dlist = NULL;
2019-12-02 02:52:53 +00:00
if (callContext == GEO_CONTEXT_RENDER && gCurrentArea != NULL
2020-01-03 15:38:57 +00:00
&& gCurrentArea->camera->mode == CAMERA_MODE_INSIDE_CANNON) {
2019-12-02 02:52:53 +00:00
graphNode->fnNode.node.flags = (graphNode->fnNode.node.flags & 0xFF) | 0x500;
dlist = render_cannon_circle_base();
2019-08-25 04:46:40 +00:00
}
return dlist;
}