Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
iOS true fullscreen: the picture fills the screen at its native aspect ratio
LNPANDY83655323243a
diff --git a/dm/host/front.h b/dm/host/front.hindex 2b0e63df..78485db7 100644--- a/dm/host/front.h+++ b/dm/host/front.h@@ -8,6 +8,10 @@ void *front_metal_layer(void);// The original game's constants are 1600x900 / 1280x720 (16:9); front ends with a different screen aspect ratio widen at the same height, and the game natively renders at the new width and re-lays out the UI (width ≤ 4096).#include <stdint.h>uint64_t front_game_res(int docked);+// Whether the front end runs true fullscreen (the picture fills the whole window at the screen's+// native aspect ratio). iOS only; the Mac front end has no implementation, callers treat it as 0.+// The iOS gamepad uses it to normalize touch points on the whole view instead of the 16:9 block.+int front_ios_true_fullscreen(void);// Text input box (for the software keyboard swkbd): the main thread shows a native input box and the calling thread blocks until the user confirms / cancels.// All text is UTF-8; max_chars is the maximum character count (0 = unlimited, only a hint for the front end; truncation is done uniformly by the caller hle_swkbd.c in UTF-16 units).// Confirm returns 1 and writes the result into out (including the terminating 0); cancel returns 0;diff --git a/dm/ios/Sources/DmGamepad.m b/dm/ios/Sources/DmGamepad.mindex ce4f1ae1..fd353c2b 100644--- a/dm/ios/Sources/DmGamepad.m+++ b/dm/ios/Sources/DmGamepad.m@@ -430,13 +430,17 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);if (changed || sticks || _sticksShown) [self refresh]; // also refresh on the stick release so the knob returns to the centre_sticksShown = sticks;}-// Touches no control takes (all of them while a physical controller is connected) go to the game's touch screen, normalized on the 16:9 picture that front_ios.m-// centres in the screen: Super Mario Galaxy's pointer in handheld mode (profile op_mode). The host reports them only in handheld mode, as on the Switch (hle_hid.c touch_read)+// Touches no control takes (all of them while a physical controller is connected) go to the game's touch screen, normalized on the picture front_ios.m+// lays out: true fullscreen = the whole view (the picture fills it); otherwise the centred 16:9 block (Super Mario Galaxy's pointer in handheld+// mode, profile op_mode). The host reports them only in handheld mode, as on the Switch (hle_hid.c touch_read)- (void)pushGame {CGRect b = self.bounds; CGFloat w = b.size.width, h = b.size.height;if (w <= 0 || h <= 0) return;- if (w / h > 16.0 / 9.0) w = h * 16.0 / 9.0; else h = w * 9.0 / 16.0;- CGFloat x0 = (b.size.width - w) / 2, y0 = (b.size.height - h) / 2;+ CGFloat x0 = 0, y0 = 0;+ if (!front_ios_true_fullscreen()) {+ if (w / h > 16.0 / 9.0) w = h * 16.0 / 9.0; else h = w * 9.0 / 16.0;+ x0 = (b.size.width - w) / 2; y0 = (b.size.height - h) / 2;+ }dm_touch t[16]; int n = 0;for (int i = 0; i < 16; i++) if (_game[i]) {CGPoint p = [_game[i] locationInView:self];diff --git a/dm/ios/Sources/front_ios.m b/dm/ios/Sources/front_ios.mindex 79f6357f..e904da8d 100644--- a/dm/ios/Sources/front_ios.m+++ b/dm/ios/Sources/front_ios.m@@ -65,6 +65,10 @@ static void front_ios_audio_watch(void);- (void)viewDidLayoutSubviews {[super viewDidLayoutSubviews];CGRect b = self.view.bounds; if (!self.game) return;+ if (front_ios_true_fullscreen()) { // true fullscreen: the Metal layer covers the whole window;+ // the game's picture (at the screen's own aspect ratio) already fills it — nothing to center+ self.game.frame = b; return;+ }CGFloat w = b.size.width, h = b.size.height; // Fit 16:9 into the whole screenif (w / h > 16.0 / 9.0) w = h * 16.0 / 9.0; else h = w * 9.0 / 16.0;self.game.frame = CGRectMake(floor((b.size.width - w) / 2), floor((b.size.height - h) / 2), w, h);@@ -91,7 +95,38 @@ static void front_ios_power_watch(void) {}void *front_metal_layer(void) { return (__bridge void *)g_layer; }-uint64_t front_game_res(int docked) { return docked ? 900ull << 32 | 1600 : 720ull << 32 | 1280; } // Same as Mac: the original 16:9 constants+// True fullscreen: the game renders at the screen's native aspect ratio (not stretched) — the game+// picture fills the whole window, and the 16:9 floor is gone. Hades II and the other Unity-family+// titles support any aspect ratio (they are widescreen games on the PC). DM_GAME_RES=WxH overrides+// (DM_GAME_RES=1600x900 restores the original 16:9 output as a negative control). The handheld+// profile keeps the original 720 height at the screen's aspect ratio.+static int g_fullscreen = -1; // decided once, from the screen ratio (and DM_FULL_OFF)+uint64_t front_game_res(int docked) {+ static double aspect; static unsigned fw, fh; static BOOL native;+ if (!aspect) {+ CGRect b = UIScreen.mainScreen.nativeBounds;+ aspect = fmax(b.size.width, b.size.height) / fmin(b.size.width, b.size.height);+ native = YES;+ const char *e = getenv("DM_GAME_RES");+ if (e && sscanf(e, "%ux%u", &fw, &fh) == 2) { aspect = (double)fw / fh; native = NO; }+ else { fw = (unsigned)fmax(b.size.width, b.size.height); fh = (unsigned)fmin(b.size.width, b.size.height); }+ if (native) { // a screen narrower than 16:9 (iPads) keeps the 16:9 output with black bars+ const char *off = getenv("DM_FULL_OFF");+ if (aspect < 16.0 / 9.0 - 0.01 || (off && atoi(off))) { native = NO; aspect = 16.0 / 9.0; fh = (unsigned)llround(fw * 9.0 / 16.0 / 2) * 2; }+ }+ if (native) g_fullscreen = 1;+ LOG("front end: game picture %ux%u (aspect %.3f%s)", fw, fh, aspect, g_fullscreen == 1 ? ", true fullscreen" : native ? "" : ", forced by DM_GAME_RES");+ }+ if (fw && docked && native) return (uint64_t)fh << 32 | fw; // docked + native screen: the screen's own pixels+ if (docked) { // a forced or 16:9-floored aspect at the docked height+ unsigned h = 900, w = (unsigned)llround(h * aspect / 8) * 8;+ if (native) { h = fh; w = fw; }+ return (uint64_t)h << 32 | w;+ }+ uint64_t h = 720, w = (uint64_t)llround(h * aspect / 8) * 8; // handheld: the original 720 height+ return h << 32 | w;+}+int front_ios_true_fullscreen(void) { if (g_fullscreen < 0) front_game_res(1); return g_fullscreen == 1; }void front_run(void (*guest)(void)) { guest(); } // Already on main.m's big-stack thread// Software keyboard: show a UIAlertController on the main thread, the calling thread waits for the result