SCREEN_CENTER_X/Y usage

This commit is contained in:
Arceveti
2021-10-17 20:17:07 -07:00
parent ee19c27c95
commit 1e52ffce78
4 changed files with 50 additions and 59 deletions

View File

@@ -7,8 +7,8 @@ This file is for ports that want to enable widescreen.
Change the definitions to the following:
#include <math.h>
#define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) (SCREEN_WIDTH / 2 - SCREEN_HEIGHT / 2 * [current_aspect_ratio] + (v))
#define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_WIDTH / 2 + SCREEN_HEIGHT / 2 * [current_aspect_ratio] - (v))
#define GFX_DIMENSIONS_FROM_LEFT_EDGE(v) v(SCREEN_CENTER_X - SCREEN_CENTER_Y * [current_aspect_ratio] + (v))
#define GFX_DIMENSIONS_FROM_RIGHT_EDGE(v) (SCREEN_CENTER_X + SCREEN_CENTER_Y * [current_aspect_ratio] - (v))
#define GFX_DIMENSIONS_RECT_FROM_LEFT_EDGE(v) ((int)floorf(GFX_DIMENSIONS_FROM_LEFT_EDGE(v)))
#define GFX_DIMENSIONS_RECT_FROM_RIGHT_EDGE(v) ((int)ceilf(GFX_DIMENSIONS_FROM_RIGHT_EDGE(v)))
#define GFX_DIMENSIONS_ASPECT_RATIO [current_aspect_ratio]

View File

@@ -115,9 +115,9 @@ void print_intro_text(void) {
if ((gGlobalTimer & 0x1F) < 20) {
if (gControllerBits == 0) {
#if MULTILANG
print_text_centered((SCREEN_WIDTH / 2), 20, gNoControllerMsg[language]);
print_text_centered(SCREEN_CENTER_X, 20, gNoControllerMsg[language]);
#else
print_text_centered((SCREEN_WIDTH / 2), 20, "NO CONTROLLER");
print_text_centered(SCREEN_CENTER_X, 20, "NO CONTROLLER");
#endif
} else {
#ifdef VERSION_EU

View File

@@ -207,7 +207,7 @@ void print_ram_bar(void) {
s32 i = 0;
f32 perfPercentage;
s32 graphPos = 0;
s32 prevGraph = (SCREEN_WIDTH / 2) - (BAR_LENGTH / 2);
s32 prevGraph = (SCREEN_CENTER_X - (BAR_LENGTH / 2));
s32 ramsize = osGetMemSize();
prepare_blank_box();
@@ -217,16 +217,16 @@ void print_ram_bar(void) {
continue;
}
perfPercentage = (f32)ramsizeSegment[i]/ramsize;
graphPos = prevGraph + CLAMP((BAR_LENGTH * perfPercentage), 1, (SCREEN_WIDTH / 2) + (BAR_LENGTH / 2));
render_blank_box(prevGraph, SCREEN_HEIGHT - 30, graphPos, SCREEN_HEIGHT - 22, colourChart[i][0], colourChart[i][1], colourChart[i][2], 255);
graphPos = prevGraph + CLAMP((BAR_LENGTH * perfPercentage), 1, SCREEN_CENTER_X + (BAR_LENGTH / 2));
render_blank_box(prevGraph, (SCREEN_HEIGHT - 30), graphPos, (SCREEN_HEIGHT - 22), colourChart[i][0], colourChart[i][1], colourChart[i][2], 255);
prevGraph = graphPos;
}
perfPercentage = (f32)ramsizeSegment[NUM_TLB_SEGMENTS] / ramsize;
graphPos = prevGraph + CLAMP((BAR_LENGTH * perfPercentage), 1, (SCREEN_WIDTH / 2) + (BAR_LENGTH / 2));
render_blank_box(prevGraph, SCREEN_HEIGHT - 30, graphPos, SCREEN_HEIGHT-22, 255, 255, 255, 255);
graphPos = (prevGraph + CLAMP((BAR_LENGTH * perfPercentage), 1, SCREEN_CENTER_X + (BAR_LENGTH / 2)));
render_blank_box(prevGraph, (SCREEN_HEIGHT - 30), graphPos, (SCREEN_HEIGHT - 22), 255, 255, 255, 255);
prevGraph = graphPos;
render_blank_box(prevGraph, SCREEN_HEIGHT - 30, (SCREEN_WIDTH / 2) + (BAR_LENGTH / 2), SCREEN_HEIGHT-22, 0, 0, 0, 255);
render_blank_box(prevGraph, (SCREEN_HEIGHT - 30), SCREEN_CENTER_X + (BAR_LENGTH / 2), (SCREEN_HEIGHT - 22), 0, 0, 0, 255);
finish_blank_box();
}
@@ -266,7 +266,7 @@ void print_ram_overview(void) {
if (i < 8) {
sprintf(textBytes, "%s: %X", ramNames[i], ramsizeSegment[i]);
} else {
sprintf(textBytes, "Segment %02X: %X", i - nameTable + 2, ramsizeSegment[i]);
sprintf(textBytes, "Segment %02X: %X", ((i - nameTable) + 2), ramsizeSegment[i]);
}
print_set_envcolour(colourChart[i][0], colourChart[i][1], colourChart[i][2], 255);
print_small_text(x, y, textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_DEFAULT);
@@ -367,10 +367,10 @@ void print_which_benchmark(void) {
char textBytes[40];
prepare_blank_box();
render_blank_box(((SCREEN_WIDTH / 2) - 50), 115, (SCREEN_WIDTH / 2) + 50, 160, 0, 0, 0, 255);
render_blank_box((SCREEN_CENTER_X - 50), 115, (SCREEN_CENTER_X + 50), 160, 0, 0, 0, 255);
finish_blank_box();
sprintf(textBytes, "Select Option#%s#L: Confirm", benchNames[benchOption]);
print_small_text((SCREEN_WIDTH / 2), 120, textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_DEFAULT);
print_small_text(SCREEN_CENTER_X, 120, textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_DEFAULT);
}
char consoleLogTable[LOG_BUFFER_SIZE][255];
@@ -452,7 +452,7 @@ void puppyprint_render_profiler(void) {
}
sprintf(textBytes, "RAM: %06X/%06X (%d_)", main_pool_available(), mempool, (s32)(((f32)main_pool_available() / (f32)mempool) * 100));
print_small_text((SCREEN_WIDTH / 2), (SCREEN_HEIGHT - 16), textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_OUTLINE);
print_small_text(SCREEN_CENTER_X, (SCREEN_HEIGHT - 16), textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_OUTLINE);
if (!ramViewer && !audioRamViewer && !benchViewer && !logViewer) {
print_fps(16, 40);
@@ -476,10 +476,10 @@ void puppyprint_render_profiler(void) {
if (benchmarkTimer > 0) {
benchmarkTimer--;
prepare_blank_box();
sprintf(textBytes, "Done in %0.000f seconds#Benchmark: %dus#High: %dus", (f32)(benchmarkProgramTimer) * 0.000001f, (s32)CYCLE_CONV(benchMark[NUM_BENCH_ITERATIONS]), (s32)CYCLE_CONV(benchMark[NUM_BENCH_ITERATIONS + 1]));
render_blank_box((SCREEN_WIDTH / 2) - (get_text_width(textBytes, FONT_OUTLINE) / 2) - 4, 158, (SCREEN_WIDTH / 2) + (get_text_width(textBytes, FONT_OUTLINE) / 2) + 4, 196, 0, 0, 0, 255);
sprintf(textBytes, "Done in %0.000f seconds#Benchmark: %dus#High: %dus", ((f32)(benchmarkProgramTimer) * 0.000001f), (s32)CYCLE_CONV(benchMark[NUM_BENCH_ITERATIONS]), (s32)CYCLE_CONV(benchMark[NUM_BENCH_ITERATIONS + 1]));
render_blank_box((SCREEN_CENTER_X - (get_text_width(textBytes, FONT_OUTLINE) / 2) - 4), 158, (SCREEN_CENTER_X + (get_text_width(textBytes, FONT_OUTLINE) / 2) + 4), 196, 0, 0, 0, 255);
print_set_envcolour(255, 255, 255, 255);
print_small_text((SCREEN_WIDTH / 2), 160, textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_OUTLINE);
print_small_text(SCREEN_CENTER_X, 160, textBytes, PRINT_TEXT_ALIGN_CENTRE, PRINT_ALL, FONT_OUTLINE);
finish_blank_box();
}
@@ -1043,7 +1043,7 @@ void render_multi_image(Texture *image, s32 x, s32 y, s32 width, s32 height, UNU
posH -= peakH;
}
gDPLoadSync(gDisplayListHead++);
gDPLoadTextureTile(gDisplayListHead++, image, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, posW, posH, posW + imW - 1, posH + imH - 1, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, maskW, maskH, 0, 0);
gDPLoadTextureTile(gDisplayListHead++, image, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, posW, posH, ((posW + imW) - 1), ((posH + imH) - 1), 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, maskW, maskH, 0, 0);
gSPScisTextureRectangle(gDisplayListHead++, (x + posW) << 2, (y + posH) << 2, (x + posW + imW - mOne) << 2, (y + posH + imH-mOne) << 2, G_TX_RENDERTILE, 0, 0, modeSC << 10, 1 << 10);
}
// If there's a remainder on the vertical side, then it will cycle through that too.
@@ -1053,7 +1053,7 @@ void render_multi_image(Texture *image, s32 x, s32 y, s32 width, s32 height, UNU
for (i = 0; i < (width / imW); i++) {
posW = (i * imW);
gDPLoadSync(gDisplayListHead++);
gDPLoadTextureTile(gDisplayListHead++, image, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, posW, posH, posW + imW - 1, height-1, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, maskW, maskH, 0, 0);
gDPLoadTextureTile(gDisplayListHead++, image, G_IM_FMT_RGBA, G_IM_SIZ_16b, width, height, posW, posH, ((posW + imW) - 1), (height - 1), 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, maskW, maskH, 0, 0);
gSPScisTextureRectangle(gDisplayListHead++, (x + posW) << 2, (y + posH) << 2, (x + posW + imW - mOne) << 2, (y + posH + imH - mOne) << 2, G_TX_RENDERTILE, 0, 0, modeSC << 10, 1 << 10);
}
}

View File

@@ -123,7 +123,7 @@ ColorRGB sSkyboxColors[] = {
/**
* The vertical length of the skybox tilemap in tiles.
*/
#define SKYBOX_ROWS (8 * SKYBOX_SIZE)
#define SKYBOX_ROWS ( 8 * SKYBOX_SIZE)
/**
@@ -139,12 +139,12 @@ ColorRGB sSkyboxColors[] = {
s32 calculate_skybox_scaled_x(s8 player, f32 fov) {
f32 yaw = sSkyBoxInfo[player].yaw;
f32 yawScaled = SCREEN_WIDTH * 360.0f * yaw / (fov * 65536.0f);
f32 yawScaled = (SCREEN_WIDTH * 360.0f * yaw / (fov * 65536.0f));
// Round the scaled yaw. Since yaw is a u16, it doesn't need to check for < 0
s32 scaledX = yawScaled + 0.5f;
s32 scaledX = (yawScaled + 0.5f);
if (scaledX > SKYBOX_WIDTH) {
scaledX -= scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH;
scaledX -= (scaledX / SKYBOX_WIDTH * SKYBOX_WIDTH);
}
return SKYBOX_WIDTH - scaledX;
}
@@ -160,19 +160,14 @@ s32 calculate_skybox_scaled_y(s8 player, UNUSED f32 fov) {
f32 pitchInDegrees = (f32) sSkyBoxInfo[player].pitch * 360.0f / 65535.0f;
// Scale by 360 / fov
f32 degreesToScale = 360.0f * pitchInDegrees / 90.0f;
f32 degreesToScale = (360.0f * pitchInDegrees / 90.0f);
s32 roundedY = round_float(degreesToScale);
// Since pitch can be negative, and the tile grid starts 1 octant above the camera's focus, add
// 5 octants to the y position
s32 scaledY = roundedY + (5 * SKYBOX_SIZE) * SKYBOX_TILE_HEIGHT;
s32 scaledY = (roundedY + ((5 * SKYBOX_SIZE) * SKYBOX_TILE_HEIGHT));
if (scaledY > SKYBOX_HEIGHT) {
scaledY = SKYBOX_HEIGHT;
}
if (scaledY < SCREEN_HEIGHT) {
scaledY = SCREEN_HEIGHT;
}
scaledY = CLAMP(scaledY, SCREEN_HEIGHT, SKYBOX_HEIGHT);
return scaledY;
}
@@ -180,10 +175,10 @@ s32 calculate_skybox_scaled_y(s8 player, UNUSED f32 fov) {
* Converts the upper left xPos and yPos to the index of the upper left tile in the skybox.
*/
static s32 get_top_left_tile_idx(s8 player) {
s32 tileCol = sSkyBoxInfo[player].scaledX / SKYBOX_TILE_WIDTH;
s32 tileRow = (SKYBOX_HEIGHT - sSkyBoxInfo[player].scaledY) / SKYBOX_TILE_HEIGHT;
s32 tileCol = (sSkyBoxInfo[player].scaledX / SKYBOX_TILE_WIDTH);
s32 tileRow = ((SKYBOX_HEIGHT - sSkyBoxInfo[player].scaledY) / SKYBOX_TILE_HEIGHT);
return tileRow * SKYBOX_COLS + tileCol;
return ((tileRow * SKYBOX_COLS) + tileCol);
}
/**
@@ -195,18 +190,14 @@ static s32 get_top_left_tile_idx(s8 player) {
*/
Vtx *make_skybox_rect(s32 tileIndex, s8 colorIndex) {
Vtx *verts = alloc_display_list(4 * sizeof(*verts));
s16 x = tileIndex % SKYBOX_COLS * SKYBOX_TILE_WIDTH;
s16 y = SKYBOX_HEIGHT - tileIndex / SKYBOX_COLS * SKYBOX_TILE_HEIGHT;
s16 x = (tileIndex % SKYBOX_COLS * SKYBOX_TILE_WIDTH);
s16 y = (SKYBOX_HEIGHT - (tileIndex / SKYBOX_COLS * SKYBOX_TILE_HEIGHT));
if (verts != NULL) {
make_vertex(verts, 0, x, y, -1, 0, 0, sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1],
sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 1, x, y - SKYBOX_TILE_HEIGHT, -1, 0, 31 << 5, sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1],
sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 2, x + SKYBOX_TILE_WIDTH, y - SKYBOX_TILE_HEIGHT, -1, 31 << 5, 31 << 5, sSkyboxColors[colorIndex][0],
sSkyboxColors[colorIndex][1], sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 3, x + SKYBOX_TILE_WIDTH, y, -1, 31 << 5, 0, sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1],
sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 0, x, y, -1, 0, 0, sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1], sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 1, x, (y - SKYBOX_TILE_HEIGHT), -1, 0, (31 << 5), sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1], sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 2, (x + SKYBOX_TILE_WIDTH), (y - SKYBOX_TILE_HEIGHT), -1, (31 << 5), (31 << 5), sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1], sSkyboxColors[colorIndex][2], 255);
make_vertex(verts, 3, (x + SKYBOX_TILE_WIDTH), y, -1, (31 << 5), 0, sSkyboxColors[colorIndex][0], sSkyboxColors[colorIndex][1], sSkyboxColors[colorIndex][2], 255);
}
return verts;
}
@@ -222,7 +213,7 @@ void draw_skybox_tile_grid(Gfx **dlist, s8 background, s8 player, s8 colorIndex)
for (row = 0; row < (3 * SKYBOX_SIZE); row++) {
for (col = 0; col < (3 * SKYBOX_SIZE); col++) {
s32 tileIndex = sSkyBoxInfo[player].upperLeftTile + row * SKYBOX_COLS + col;
s32 tileIndex = (sSkyBoxInfo[player].upperLeftTile + (row * SKYBOX_COLS) + col);
const Texture *const texture =
(*(SkyboxTexture *) segmented_to_virtual(sSkyboxTextures[background]))[tileIndex];
Vtx *vertices = make_skybox_rect(tileIndex, colorIndex);
@@ -235,19 +226,19 @@ void draw_skybox_tile_grid(Gfx **dlist, s8 background, s8 player, s8 colorIndex)
}
void *create_skybox_ortho_matrix(s8 player) {
f32 left = sSkyBoxInfo[player].scaledX;
f32 right = sSkyBoxInfo[player].scaledX + SCREEN_WIDTH;
f32 bottom = sSkyBoxInfo[player].scaledY - SCREEN_HEIGHT;
f32 top = sSkyBoxInfo[player].scaledY;
f32 left = sSkyBoxInfo[player].scaledX;
f32 right = (sSkyBoxInfo[player].scaledX + SCREEN_WIDTH );
f32 bottom = (sSkyBoxInfo[player].scaledY - SCREEN_HEIGHT);
f32 top = sSkyBoxInfo[player].scaledY;
Mtx *mtx = alloc_display_list(sizeof(*mtx));
#ifdef WIDESCREEN
f32 half_width = (4.0f / 3.0f) / GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_WIDTH / 2;
f32 center = (sSkyBoxInfo[player].scaledX + SCREEN_WIDTH / 2);
if (half_width < SCREEN_WIDTH / 2) {
f32 half_width = ((4.0f / 3.0f) / GFX_DIMENSIONS_ASPECT_RATIO * SCREEN_CENTER_X);
f32 center = (sSkyBoxInfo[player].scaledX + SCREEN_CENTER_X);
if (half_width < SCREEN_CENTER_X) {
// A wider screen than 4:3
left = center - half_width;
right = center + half_width;
left = (center - half_width);
right = (center + half_width);
}
#endif
@@ -272,7 +263,7 @@ Gfx *init_skybox_display_list(s8 player, s8 background, s8 colorIndex) {
Mtx *ortho = create_skybox_ortho_matrix(player);
gSPDisplayList(dlist++, dl_skybox_begin);
gSPMatrix(dlist++, VIRTUAL_TO_PHYSICAL(ortho), G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH);
gSPMatrix(dlist++, VIRTUAL_TO_PHYSICAL(ortho), (G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH));
gSPDisplayList(dlist++, dl_skybox_tile_tex_settings);
draw_skybox_tile_grid(&dlist, background, player, colorIndex);
gSPDisplayList(dlist++, dl_skybox_end);
@@ -295,9 +286,9 @@ 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) {
f32 cameraFaceX = focX - posX;
f32 cameraFaceY = focY - posY;
f32 cameraFaceZ = focZ - posZ;
f32 cameraFaceX = (focX - posX);
f32 cameraFaceY = (focY - posY);
f32 cameraFaceZ = (focZ - posZ);
s8 colorIndex = 1;
// If the first star is collected in JRB, make the sky darker and slightly green
@@ -308,7 +299,7 @@ Gfx *create_skybox_facing_camera(s8 player, s8 background, f32 fov,
//! fov is always set to 90.0f. If this line is removed, then the game crashes because fov is 0 on
//! the first frame, which causes a floating point divide by 0
fov = 90.0f;
sSkyBoxInfo[player].yaw = atan2s(cameraFaceZ, cameraFaceX);
sSkyBoxInfo[player].yaw = atan2s(cameraFaceZ, cameraFaceX);
sSkyBoxInfo[player].pitch = atan2s(sqrtf(sqr(cameraFaceX) + sqr(cameraFaceZ)), cameraFaceY);
sSkyBoxInfo[player].scaledX = calculate_skybox_scaled_x(player, fov);
sSkyBoxInfo[player].scaledY = calculate_skybox_scaled_y(player, fov);