mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 10:49:58 -04:00
Draw Ocarina in the window's shape: a wider picture and camera, with the HUD, menus and movies kept 16:9 in the middle.
The patch sets of recomp/patches-v111.txt read the game's 2560x1440 picture and 1920x1080 scene sizes from the patch page, give every 16:9 camera the picture's ratio, squeeze the UI's full-screen projection into the middle 16:9 (fades and the menu backgrounds that redraw a capture stay full width) and pillarbox movies. runtime/widescreen.c sets them up from the new Screen tab row Widescreen (NX2NAVI_GAME_ASPECT: 16:9, window, 21:9 or 32:9, at the next start). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
101
runtime/widescreen.c
Normal file
101
runtime/widescreen.c
Normal file
@@ -0,0 +1,101 @@
|
||||
// Widescreen (Ocarina of Time 1.1.1): the game draws a picture of another shape than 16:9, with the camera seeing more
|
||||
// of the world at the sides (Hor+: the vertical view stays the game's) instead of a stretched 16:9 view.
|
||||
//
|
||||
// The game presents a 2560x1440 picture at every console mode and renders its scene at 1920x1080, which its upscaler
|
||||
// takes to the picture's size; both sizes are constants in its code. The patch sets of recomp/patches-v111.txt read
|
||||
// them from the patch page instead (wide_out: the picture, wide_scene: the scene), wide_aspect replaces a 16:9 ratio of
|
||||
// sead's perspective projection (every 16:9 camera of the game) with the picture's, wide_hud keeps the HUD and menus
|
||||
// in their 16:9 shape in the middle of the picture (the UI's full-screen projection squeezed horizontally; fades and
|
||||
// the menu backgrounds that redraw a capture of the whole picture stay full width), and wide_movie shows pre-rendered
|
||||
// movies in the same middle 16:9. The heights stay the game's (1440 and 1080), so only the width grows, by the shape's
|
||||
// ratio to 16:9; the present scales the picture to the window keeping its shape (gfx_present.c, NX2NAVI_ASPECT=fit).
|
||||
//
|
||||
// Setting NX2NAVI_GAME_ASPECT, read at start: "16:9" (the game's own, every set off), "window" (the shape of the window,
|
||||
// or of the monitor in fullscreen), or a fixed shape "21:9" (2560x1080 monitors, 64:27), "32:9". A shape within 1% of
|
||||
// 16:9 or narrower than it keeps the game's own sizes; the widest is 32:9.
|
||||
//
|
||||
// The page's layout is described at the top of recomp/patches-v111.txt.
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cfg.h"
|
||||
#include "gfx_wsys.h"
|
||||
#include "host.h"
|
||||
#include "layout.h"
|
||||
#include "ui/menu.h"
|
||||
|
||||
#define GAME_W 2560 // the picture, main+0x1202ee0 and main+0x31f39f4
|
||||
#define GAME_H 1440
|
||||
#define SCENE_H 1080
|
||||
|
||||
// The shape the setting asks for as width / height; 0 for the game's own.
|
||||
static double wanted_ratio(void) {
|
||||
const char *s = cfg_value("NX2NAVI_GAME_ASPECT");
|
||||
if (!strcmp(s, "21:9")) return 64.0 / 27.0;
|
||||
if (!strcmp(s, "32:9")) return 32.0 / 9.0;
|
||||
if (strcmp(s, "window")) return 0;
|
||||
int w = 0, h = 0;
|
||||
if (gfx_cfg_fullscreen()) {
|
||||
if (!gfx_window_monitor_size(&w, &h)) {
|
||||
rt_log("widescreen: the monitor's size is unknown; the game's own 16:9");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
gfx_cfg_window_size(&w, &h);
|
||||
}
|
||||
return h > 0 ? (double)w / h : 0;
|
||||
}
|
||||
|
||||
void wide_init(void) {
|
||||
int so = rt_patch_set("wide_out"), ss = rt_patch_set("wide_scene"), sa = rt_patch_set("wide_aspect"),
|
||||
sh = rt_patch_set("wide_hud"), sm = rt_patch_set("wide_movie");
|
||||
double r = wanted_ratio(), game = (double)GAME_W / GAME_H;
|
||||
if (r <= 0 || r < game * 1.01) {
|
||||
if (r > 0) rt_log("widescreen: a %.4f picture is not wider than 16:9; the game's own 2560x1440", r);
|
||||
return;
|
||||
}
|
||||
if (so < 0 || ss < 0 || sa < 0 || sh < 0 || sm < 0) {
|
||||
rt_log("widescreen: the generated C has no widescreen patch sets (gen.py --patches recomp/patches-v111.txt); "
|
||||
"the game's own 16:9");
|
||||
return;
|
||||
}
|
||||
if (r > 32.0 / 9.0) r = 32.0 / 9.0;
|
||||
// Widths in whole multiples of 8 pixels (the scene keeps the game's 3:4 of the picture), heights the game's.
|
||||
unsigned ow = (unsigned)lround(GAME_H * r / 8) * 8, sw = (unsigned)lround(ow * 3.0 / 4 / 8) * 8;
|
||||
uint64_t out = (uint64_t)GAME_H << 32 | ow, scene = (uint64_t)SCENE_H << 32 | sw;
|
||||
float match = 16.0f / 9.0f, ratio = (float)ow / GAME_H, tolerance = 0.01f, squeeze = match / ratio;
|
||||
float ui[2] = {2.0f / 3840.0f, 2.0f / 2160.0f}, squeeze4[4] = {squeeze, squeeze, squeeze, squeeze};
|
||||
float margin = (1.0f - squeeze) / 2;
|
||||
// the screens whose UI keeps the whole picture (recomp/patches-v111.txt, set wide_hud): the item-wheel, pause and
|
||||
// system menu backgrounds, the event and loading fades
|
||||
uint64_t keep[2] = {MOD_MAIN_BASE + 0x4bed098, MOD_MAIN_BASE + 0x4be4fb0},
|
||||
keep2[2] = {MOD_MAIN_BASE + 0x4be61c8, MOD_MAIN_BASE + 0x4be7b30};
|
||||
uint8_t *page = rt_patch_page();
|
||||
memcpy(page + 96, &out, 8);
|
||||
memcpy(page + 104, &scene, 8);
|
||||
memcpy(page + 112, &match, 4);
|
||||
memcpy(page + 116, &ratio, 4);
|
||||
memcpy(page + 120, &tolerance, 4);
|
||||
memcpy(page + 144, ui, 8);
|
||||
memcpy(page + 160, keep, 16);
|
||||
memcpy(page + 176, squeeze4, 16);
|
||||
memcpy(page + 192, &margin, 4);
|
||||
memcpy(page + 208, keep2, 16);
|
||||
rt_patch_switch(so, 1);
|
||||
rt_patch_switch(ss, 1);
|
||||
rt_patch_switch(sa, 1);
|
||||
rt_patch_switch(sh, 1);
|
||||
rt_patch_switch(sm, 1);
|
||||
rt_log("widescreen: picture %ux%u, scene %ux%u, camera aspect ratio %.4f (16:9 is %.4f), UI and movies in the "
|
||||
"middle %.1f%%", ow, GAME_H, sw, SCENE_H, ratio, game, squeeze * 100);
|
||||
}
|
||||
|
||||
// The generated C has the widescreen patch sets (the menu shows the row only then).
|
||||
int wide_available(void) {
|
||||
static const char *const names[] = {"wide_out", "wide_scene", "wide_aspect", "wide_hud", "wide_movie"};
|
||||
for (int i = 0; i < 5; i++)
|
||||
if (rt_patch_set(names[i]) < 0) return 0;
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user