Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Widescreen for games that read oe::GetDefaultDisplayResolution; H2 layout removed

LNPANDY56560ab77752
diff --git a/dm/games/0100A00019DE0000/pad_icons/attack.png b/dm/games/0100A00019DE0000/pad_icons/attack.png
deleted file mode 100644
index 03eb2ab1..00000000
Binary files a/dm/games/0100A00019DE0000/pad_icons/attack.png and /dev/null differ
diff --git a/dm/games/0100A00019DE0000/pad_icons/cast.png b/dm/games/0100A00019DE0000/pad_icons/cast.png
deleted file mode 100644
index 68cca348..00000000
Binary files a/dm/games/0100A00019DE0000/pad_icons/cast.png and /dev/null differ
diff --git a/dm/games/0100A00019DE0000/pad_icons/dash.png b/dm/games/0100A00019DE0000/pad_icons/dash.png
deleted file mode 100644
index e83abb9d..00000000
Binary files a/dm/games/0100A00019DE0000/pad_icons/dash.png and /dev/null differ
diff --git a/dm/games/0100A00019DE0000/pad_icons/hex.png b/dm/games/0100A00019DE0000/pad_icons/hex.png
deleted file mode 100644
index ff4153e6..00000000
Binary files a/dm/games/0100A00019DE0000/pad_icons/hex.png and /dev/null differ
diff --git a/dm/games/0100A00019DE0000/pad_icons/omega.png b/dm/games/0100A00019DE0000/pad_icons/omega.png
deleted file mode 100644
index 16088b1a..00000000
Binary files a/dm/games/0100A00019DE0000/pad_icons/omega.png and /dev/null differ
diff --git a/dm/games/0100A00019DE0000/pad_icons/special.png b/dm/games/0100A00019DE0000/pad_icons/special.png
deleted file mode 100644
index 16cbff18..00000000
Binary files a/dm/games/0100A00019DE0000/pad_icons/special.png and /dev/null differ
diff --git a/dm/host/hle_oe.c b/dm/host/hle_oe.c
index b9594a33..46acfe1c 100644
--- a/dm/host/hle_oe.c
+++ b/dm/host/hle_oe.c
@@ -111,8 +111,10 @@ HLE_FORCE("_ZN2nn2oe18GetPerformanceModeEv", "performance mode query; same as th
// SDK 11 calls of Monster Hunter Rise: the CPU overclock query reads an apm session the host never opened (null read in sdk+0x35258 at the start of nnMain, main+0x6bc8650);
// the default display resolution is the TV's (1080p docked) or the panel's (720p handheld) and only changes with the operation mode
HLE_FORCE("_ZN2nn2oe21IsCpuOverclockEnabledEv", "CPU overclock state (through apm): not enabled", unsigned, h_oe_CpuOc, void) { return 0; }
-HLE_FORCE("_ZN2nn2oe27GetDefaultDisplayResolutionEPiS1_", "default display resolution: 1920x1080 docked, 1280x720 handheld", void, h_oe_DefRes, int *w, int *h) {
- int con = opmode() == 1; if (w) *w = con ? 1920 : 1280; if (h) *h = con ? 1080 : 720;
+HLE_FORCE("_ZN2nn2oe27GetDefaultDisplayResolutionEPiS1_", "default display resolution: the front end's game picture (d2r-mobile's widescreen path; was hardcoded 1920x1080 docked / 1280x720 handheld, which held Hades II at 16:9 inside a taller window)", void, h_oe_DefRes, int *w, int *h) {
+ uint64_t r = dm_game_res(opmode() == 1);
+ static _Atomic int said; if (!atomic_exchange(&said, 1)) LOG("oe::GetDefaultDisplayResolution → %ux%u", (unsigned)(uint32_t)r, (unsigned)(r >> 32));
+ if (w) *w = (int)(uint32_t)r; if (h) *h = (int)(uint32_t)(r >> 32);
}
HLE_FORCE("_ZN2nn2oe38GetDefaultDisplayResolutionChangeEventEPNS_2os11SystemEventE", "default display resolution change event: bound, never signaled (the operation mode notification carries the change)",
void, h_oe_DefResEv, void *ev) { hle_bind_system_event(ev, 0); }
diff --git a/dm/ios/Sources/DmGamepad.m b/dm/ios/Sources/DmGamepad.m
index fd353c2b..c034c5f9 100644
--- a/dm/ios/Sources/DmGamepad.m
+++ b/dm/ios/Sources/DmGamepad.m
@@ -1,38 +1,13 @@
// Virtual gamepad (Nintendo button positions) + physical controllers (GameController). Both are merged and handed to the host through dm_input_set (hle_hid.c, bit layout in dm_input.h).
-// Three layouts; one tap on the layout button at the top centre (labelled with the current layout, "2D" / "3D" / "H2") cycles them, and the choice is kept in NSUserDefaults (each game is its own app, so per game); the first launch uses the game profile's pad_layout (DM_GAME_PAD_FULL).
+// Two layouts; one tap on the layout button at the top centre (labelled with the current layout, "2D" / "3D") switches them, and the choice is kept in NSUserDefaults (each game is its own app, so per game); the first launch uses the game profile's pad_layout (DM_GAME_PAD_FULL).
// 2D (simple): top corners ZL above L (one column), ZR above R likewise, teardrops with the tip toward the screen corner; − and + side by side at the top centre; the left stick in the bottom-left corner (fixed ring, tilt measured from the ring centre, small dead zone);
// the A (right) B (bottom) X (top) Y (left) diamond in the bottom-right corner, sliding a finger between keys switches keys. Each bottom corner holds a single control, so it sits close in (reaching halfway into the side safe-area inset).
// 3D (full, Pro Controller style): everything in 2D (left stick and diamond keep their place and size), plus a D-pad (inward of and below the left stick, 8-way), a right stick (inward of and below the diamond, a smaller ring)
// and L3 / R3 (small round keys in the top row, inward of ZL / ZR). Breath of the Wild crouches with L3 and uses the scope with R3; 3D World and Breath of the Wild turn the camera with the right stick.
-// H2 (Hades II, see the block below): a floating stick on the left (the base starts wherever the
-// finger lands) and combat keys on the right, sized by the game's own use frequency, with the
-// Ω latch standing in for the pad's hold-ZR modifier.
// Touch-down ownership: locked keys first (shoulders, − / +, the layout button, L3 / R3), then whichever of the diamond, the D-pad and the two sticks has the smallest distance / grab radius (the left stick's grab circle borders the D-pad).
// Everything hugs the edges and corners to leave the picture room; controls sit over the picture, one CAShapeLayer each: a press only swaps the fill, a stick only moves its knob, nothing redraws the whole screen.
// Touches no control takes go to the game's touch screen (pushGame; Super Mario Galaxy's pointer in handheld mode).
// The virtual gamepad (layout button included) hides while a physical controller is connected and comes back when it is removed; meanwhile every touch goes to the game. Physical controllers keep every button (D-pad and right stick included) and map by position: bottom = B, right = A, left = Y, top = X (same positions as on a Switch controller).
-// ---- Hades II layout ----
-// The stick starts wherever the finger lands inside the lower-left start zone (40% of the width,
-// from 45% of the height down): the base centre = the touch point, direction and magnitude are
-// measured from that point, and dragging any distance keeps working (the base does not follow the
-// finger). A touch outside the zone that hits nothing else goes to the game's touch screen, as in
-// the other layouts. A stick finger cancelled by the system (notification banner, system gesture)
-// resumes when a finger lands near the same place within 2 s, keeping the old base centre so the
-// base does not jump.
-// The right side holds the combat keys, laid out by the game's own frequency (from the help text:
-// Attack 32 hints, Special 25, Dash 17, Cast 8, Hex 9) and the Switch mapping (Y attack, X special,
-// B dash, A cast):
-// Y attack biggest, rightmost (thumb rest) — holding passes the press duration through, which is the Ω attack
-// X special second size, upper-left of Y — the Ω special works the same way
-// B dash third size, below, wide hit area (the most救命 key)
-// A cast smaller, inner
-// ZR omega the Ω moves are "hold ZR then press attack / special" on a pad; here the key is a
-// latch: tap once to arm (the ring lights), the next attack / special press carries
-// ZR 0.12 s ahead of itself (the game's own "hold ZR first" order), then it disarms.
-// Holding the key works as well.
-// R hex smallest, innermost: the blue-meter spell (hold-and-release variants pass through)
-// Each combat key draws the game's own glyph when the profile ships one
-// (dm/games/<id>/pad_icons/<name>.png); without one it falls back to the button letter.
#import <UIKit/UIKit.h>
#import <GameController/GameController.h>
#import <CoreText/CoreText.h>
@@ -42,30 +17,7 @@
#include "game_profile.h"
enum { B_A = 0, B_B, B_X, B_Y, B_LS, B_RS, B_L, B_R, B_ZL, B_ZR, B_PLUS, B_MINUS, B_LEFT, B_UP, B_RIGHT, B_DOWN, B_N };
-enum { C_NONE = 0, C_STICK, C_DPAD, C_FACE, C_BTN, C_SWAP, C_GAME, C_H2KEY }; // C_GAME: none, the touch goes to the game's touch screen (finger slot << 8); C_H2KEY: a Hades II combat key (key << 8)
-
-// ---- Hades II layout constants (round seven: verified on paper against the smallest and the
-// largest iPhone landscape screens — every key inside the frame, no two keys overlapping) ----
-// The combat keys hang off Y (the attack anchor, the biggest key) at the offsets below, in u
-// (+x toward the right edge, +y up): B below-outward (dash under the thumb), X inward of B,
-// A above X, Ω above-outward of Y, R above Ω toward the corner. The menu key sits on the top
-// edge between the + pill and the cluster (absolute: x = W − 200u, y = 30u); L on the left edge
-// at Y's height.
-static const CGFloat KH_FACE_X = 132, KH_FACE_Y = 190,
- KH_Y_R = 46, KH_OTHER_R = 34, KH_HEX_R = 26; // the hex spell key a little smaller
-static const CGFloat
- KH_B_DX = -6, KH_B_DY = -108,
- KH_X_DX = -88, KH_X_DY = 48,
- KH_A_DX = -96, KH_A_DY = 48,
- KH_OMEGA_DX = 36, KH_OMEGA_DY = 82,
- KH_HEX_DX = 98, KH_HEX_DY = 116;
-static const CGFloat KH_MENU_X = 200, KH_MENU_Y = 30, KH_MENU_R = 30; // the menu key: x from the right edge, y from the top (absolute, on the top edge)
-static const CGFloat KH_L_X = 58; // L: from the left edge (its height follows Y's)
-// Floating stick: the start zone's right bound (fraction of the width) and upper bound (fraction of
-// the height from the bottom); the base radius, full-tilt fraction, dead zone, the resume window for
-// a system-cancelled stick finger, its grab factor, and how long the Ω latch leads the attack key.
-static const CGFloat KH_ZONE_R = 0.40, KH_ZONE_T = 0.45, KH_STICK_R = 62, KH_FULL = 0.75,
- KH_DEAD = 0.08, KH_RESUME_S = 2.0, KH_RESUME_K = 1.6, KH_ZR_LEAD = 0.12;
+enum { C_NONE = 0, C_STICK, C_DPAD, C_FACE, C_BTN, C_SWAP, C_GAME }; // which control a touch holds; C_GAME: none, the touch goes to the game's touch screen (finger slot << 8)
static pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER;
static uint64_t g_touch_btn, g_pad_btn;
@@ -102,36 +54,13 @@ static const CGFloat
K_CLICK_X = 102, K_CLICK_R = 17; // L3 / R3: centre from the outer edge (level with ZL / ZR), radius
static const int k_btns[] = {B_ZL, B_L, B_ZR, B_R, B_MINUS, B_PLUS, B_LS, B_RS}; // keys locked at touch-down (L3 / R3 only in the 3D layout)
static NSString *const k_layout_key = @"DmPadLayout"; // NSUserDefaults: 1 = 3D, 0 = 2D
-static NSString *const k_h2_key = @"DmPadH2"; // NSUserDefaults: 1 = Hades II layout (overrides 2D / 3D)
-
-// ---- Hades II combat keys ----
-// Each entry: button, centre angle (degrees, from Y at KH_RING distance), radius, icon name.
-// Y is the anchor at radius KH_Y_R; the rest share KH_OTHER_R and fan out evenly (the play-test
-// asked for equal gaps and equal sizes).
-typedef struct { int b; CGFloat dx, dy, r; NSString *icon; } h2key;
-// Centres from Y (the anchor), in u (+x toward the right edge, +y up). See the constants block
-// (round seven: verified against the smallest and largest iPhone screens).
-static const h2key k_h2[] = {
- { B_Y, 0, 0, KH_Y_R, @"attack" },
- { B_ZR, KH_OMEGA_DX, KH_OMEGA_DY, KH_OTHER_R, @"omega" },
- { B_R, KH_HEX_DX, KH_HEX_DY, KH_HEX_R, @"hex" },
- { B_X, KH_X_DX, KH_X_DY, KH_OTHER_R, @"special" },
- { B_B, KH_B_DX, KH_B_DY, KH_OTHER_R, @"dash" },
- { B_A, KH_A_DX, KH_A_DY, KH_OTHER_R, @"cast" }, // A above X (the sketch's left column)
-};
-enum { KH_N = sizeof k_h2 / sizeof *k_h2 };
-static UIImage *h2_icon(NSString *name) { // the game's own glyph from the profile folder, if present
- NSString *p = [[NSBundle.mainBundle.resourcePath stringByAppendingPathComponent:@"dm/pad_icons"]
- stringByAppendingPathComponent:[name stringByAppendingString:@".png"]];
- return [UIImage imageWithContentsOfFile:p];
-}
@interface DmGamepad : UIView
@end
static __weak DmGamepad *g_view;
@implementation DmGamepad {
- NSMapTable<UITouch *, NSNumber *> *_owner; // touch → control (with the key for C_BTN / C_H2KEY or the stick for C_STICK, << 8)
+ NSMapTable<UITouch *, NSNumber *> *_owner; // touch → control (with the key for C_BTN or the stick for C_STICK, << 8)
UITouch *_stick[2]; CGPoint _stickNow[2]; // the touch holding each stick and where it is now (0 left, 1 right)
uint64_t _faceBits, _dpadBits, _btnBits;
NSMapTable<UITouch *, NSNumber *> *_faceOf; // which keys each touch on the diamond currently holds
@@ -140,24 +69,9 @@ static __weak DmGamepad *g_view;
CAShapeLayer *_swap; CATextLayer *_swapLabel; BOOL _swapHeld;
BOOL _sticksShown; // a stick was held at the last refresh
BOOL _full; // the 3D layout is current
- BOOL _h2; // the Hades II layout is current
CALayer *_controls; // holds every control layer: hidden while a physical controller is connected (the view itself stays, for game touches)
BOOL _padOff; // a physical controller is connected: every touch goes to the game
UITouch *_game[16]; // touches on the game's touch screen by finger slot
- // ---- Hades II state ----
- CAShapeLayer *_h2key[KH_N]; CALayer *_h2icon[KH_N]; // combat keys: ring + the game's glyph (or the letter label when no glyph ships)
- CATextLayer *_h2label[KH_N];
- CAShapeLayer *_h2ring, *_h2knob; // the floating base and its knob (own layers: reusing _ring[0] hid the 2D/3D stick)
- UITouch *_h2stick; // the finger holding the floating stick
- CGPoint _h2origin, _h2now; // the base centre (the touch-down point) and the finger now
- CGPoint _h2lostOrigin; double _h2lostS; // the base centre and time of a cancelled stick finger (for the resume)
- BOOL _h2stickShown; // the floating base was drawn at the last refresh
- BOOL _h2omega; // the Ω latch is armed: the next attack / special carries ZR
- double _h2omegaSince; // when the latch went down (the lead time runs from it)
- double _h2keyDown[KH_N]; // when each key's finger went down (0 = up; Ω needs the duration)
- uint64_t _h2bits; // the combat-key bits as published at the last recompute
- // ---- Hades II menu keys ----
- CAShapeLayer *_h2menuKey[2]; CATextLayer *_h2menuLabel[2]; // 0 = D-pad right (open the inventory), 1 = L
}
static UIColor *k_idle, *k_on, *k_line, *k_ringFill, *k_text, *k_textOn;
@@ -197,36 +111,8 @@ static BOOL fullOnly(int b) { return b == B_LS || b == B_RS || b >= B_LEFT; }
if (names[b]) _label[b] = label(_key[b], names[b]); // the D-pad arms carry no label
}
_swap = shape(_controls); _swapLabel = label(_swap, @"");
- // Hades II combat keys: one ring + one content layer each; the content is the game's own
- // glyph when the profile ships one, else the button letter.
- static NSString *const h2names[] = {@"Y", @"Ω", @"A", @"B", @"X", @"R"}; // matches k_h2's order
- for (int i = 0; i < KH_N; i++) {
- _h2key[i] = shape(_controls);
- UIImage *im = h2_icon(k_h2[i].icon);
- if (im) {
- _h2icon[i] = [CALayer layer]; _h2icon[i].contents = (__bridge id)im.CGImage;
- _h2icon[i].contentsGravity = kCAGravityResizeAspect;
- [_h2key[i] addSublayer:_h2icon[i]];
- } else {
- _h2label[i] = label(_h2key[i], h2names[i]);
- }
- }
NSNumber *saved = [NSUserDefaults.standardUserDefaults objectForKey:k_layout_key];
_full = saved ? saved.boolValue : DM_GAME_PAD_FULL;
- NSNumber *h2saved = [NSUserDefaults.standardUserDefaults objectForKey:k_h2_key];
- _h2 = h2saved ? h2saved.boolValue : NO;
- // The floating base and knob: own layers, not the fixed stick's — sharing them hid the 2D/3D stick.
- _h2ring = shape(_controls); _h2ring.fillColor = k_ringFill.CGColor;
- _h2knob = shape(_controls);
- CAShapeLayer *h2in = [CAShapeLayer layer]; h2in.fillColor = nil; h2in.strokeColor = k_line.CGColor; h2in.lineWidth = 1.5;
- [_h2knob addSublayer:h2in];
- // The menu keys: always visible in H2. The left one doubles as the handle (D-pad right);
- // L and R sit beside their screen edges for the inventory's pages.
- static NSString *const h2menuNames[2] = {@"◀", @"L"}; // the menu key's label is a left-pointing triangle
- for (int i = 0; i < 2; i++) {
- _h2menuKey[i] = shape(_controls); _h2menuKey[i].hidden = YES;
- _h2menuLabel[i] = label(_h2menuKey[i], h2menuNames[i]);
- }
[self applyLayout];
NSNotificationCenter *nc = NSNotificationCenter.defaultCenter;
[nc addObserver:self selector:@selector(padsChanged) name:GCControllerDidConnectNotification object:nil];
@@ -237,25 +123,16 @@ static BOOL fullOnly(int b) { return b == B_LS || b == B_RS || b >= B_LEFT; }
}
- (void)applyLayout { // show / hide the controls for the current layout
[CATransaction begin]; [CATransaction setDisableActions:YES];
- for (int b = 0; b < B_N; b++) _key[b].hidden = _h2 || (fullOnly(b) && !_full);
- _ring[1].hidden = _knob[1].hidden = _h2 || !_full;
- _ring[0].hidden = _knob[0].hidden = _h2; // the H2 stick has its own floating base layers
- for (int i = 0; i < KH_N; i++) _h2key[i].hidden = !_h2;
- for (int i = 0; i < 2; i++) _h2menuKey[i].hidden = !_h2; // the menu keys always show in H2
- _swapLabel.string = _h2 ? @"H2" : _full ? @"3D" : @"2D";
+ for (int b = 0; b < B_N; b++) _key[b].hidden = fullOnly(b) && !_full;
+ _ring[1].hidden = _knob[1].hidden = !_full;
+ _swapLabel.string = _full ? @"3D" : @"2D";
[CATransaction commit];
}
-- (void)setFull:(BOOL)full { // cycle layouts: 2D → 3D → H2 → 2D. Release every touch first (no key stays held), save, lay out again
- if (full) {
- if (!_full) { [self reset]; _full = YES; _h2 = NO; }
- else if (!_h2) { [self reset]; _h2 = YES; }
- else { [self reset]; _full = NO; _h2 = NO; }
- } else {
- if (!_full && !_h2) { [self reset]; _full = YES; }
- else { [self reset]; _full = NO; _h2 = NO; }
- }
- [NSUserDefaults.standardUserDefaults setObject:@(_full) forKey:k_layout_key];
- [NSUserDefaults.standardUserDefaults setObject:@(_h2) forKey:k_h2_key];
+- (void)setFull:(BOOL)full { // switch layouts: release every touch first (no key stays held), save, lay out again
+ if (full == _full) return;
+ [self reset];
+ _full = full;
+ [NSUserDefaults.standardUserDefaults setObject:@(full) forKey:k_layout_key];
[self applyLayout]; [self setNeedsLayout];
}
@@ -285,56 +162,6 @@ static BOOL isClick(int b) { return b == B_LS || b == B_RS; }
return CGRectMake(c.x - w / 2, c.y - h / 2, w, h); }
- (CGPoint)swapCenter { CGRect s = self.safe; return CGPointMake(CGRectGetMidX(s), CGRectGetMinY(s) + K_PILL_Y * self.u); }
-// ---- Hades II geometry ----
-- (CGFloat)h2u { // the H2 layout scales by the SHORT screen edge, tighter than the global u:
- // the key cluster spans about 320 u horizontally (Y anchor + A/R inward + ZR up), and it must
- // fit half the screen next to the stick zone on every iPhone (smallest landscape height 375).
- CGFloat byHeight = self.bounds.size.height / 430.0, byWidth = self.bounds.size.width / 932.0;
- return fmin(fmin(byHeight, byWidth), 1.3) * fmin(1.0, self.bounds.size.width * 0.5 / 340.0);
-}
-- (CGPoint)h2Anchor { // Y, the anchor every other key is placed from
- CGRect s = self.corner; CGFloat u = self.h2u;
- return side(s, 1, KH_FACE_X * u, CGRectGetMaxY(s) - KH_FACE_Y * u);
-}
-- (CGPoint)h2keyCenter:(int)i {
- CGPoint a = self.h2Anchor; CGFloat u = self.h2u;
- return CGPointMake(a.x + k_h2[i].dx * u, a.y - k_h2[i].dy * u); // +dy = up
-}
-- (CGFloat)h2keyR:(int)i { return k_h2[i].r * self.h2u; }
-- (int)h2keyAt:(CGPoint)p {
- for (int i = 0; i < KH_N; i++) { CGFloat r = [self h2keyR:i] * 1.18; // a slightly generous hit area: small keys must not need pixel aim
- if (dist(p, [self h2keyCenter:i]) <= r) return i; }
- return -1;
-}
-// ---- Hades II menu keys ----
-// Three keys, always visible in H2:
-// 0 menu a circle key with a left-pointing triangle inside, top-right corner — the tap IS
-// D-pad right (open the inventory)
-// 1 L the left edge, at Y's height (the sketch's yellow circle, alone on its side)
-// 2 R the right edge, directly below the menu key
-- (CGPoint)h2menuKey:(int)i {
- CGFloat u = self.h2u;
- if (i == 0) return CGPointMake(CGRectGetMaxX(self.safe) - KH_MENU_X * u, CGRectGetMinY(self.safe) + KH_MENU_Y * u);
- return CGPointMake(CGRectGetMinX(self.safe) + KH_L_X * u, [self h2Anchor].y);
-}
-- (CGFloat)h2menuR { return KH_MENU_R * self.h2u; }
-- (int)h2menuAt:(CGPoint)p { // 0 = D-pad right (open the inventory), 1 = L (page); -1 none
- for (int i = 0; i < 2; i++) if (dist(p, [self h2menuKey:i]) <= [self h2menuR] * 1.15) return i;
- return -1;
-}
-- (BOOL)h2inStickZone:(CGPoint)p { // the lower-left zone the floating stick starts in
- return p.x >= 0 && p.y <= self.bounds.size.height
- && p.x < self.bounds.size.width * KH_ZONE_R
- && p.y > self.bounds.size.height * (1 - KH_ZONE_T);
-}
-// The knob offset from the floating base (clamped to the base edge), the same convention as knobOffset.
-- (CGPoint)h2knobOffset {
- if (!_h2stick) return CGPointZero;
- CGFloat dx = _h2now.x - _h2origin.x, dy = _h2now.y - _h2origin.y, d = hypot(dx, dy), R = KH_STICK_R * self.h2u;
- if (d > R) { dx *= R / d; dy *= R / d; }
- return CGPointMake(dx, dy);
-}
-
static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y); }
- (int)btnAt:(CGPoint)p { // locked keys (tested on touch-down only, then locked)
CGFloat u = self.u;
@@ -384,49 +211,13 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);
CGFloat m = fmin((d - dz) / (R * K_FULL - dz), 1) / d; // outside the dead zone: 0 rising to full at the full-tilt radius
ax[i * 2] = (int32_t)lrint(o.x * m * 32767); ax[i * 2 + 1] = (int32_t)lrint(-o.y * m * 32767); // host: up is positive; rounded so full tilt is exactly 32767
}
- // Hades II combat keys: the bits from every finger on an H2 key, plus the Ω latch. The latch
- // leads the attack / special by KH_ZR_LEAD: when a key that carries ZR goes down within the
- // lead window of the latch, the published button set waits the remainder before adding it, so
- // a quick tap-Ω-attack still arrives in the game's own "hold ZR first" order. Press durations
- // pass through untouched (the Ω moves are holds; the hex's hold-and-release works as is).
- uint64_t h2 = 0;
- static const int h2menuBtn[2] = {B_RIGHT, B_L}; // menu key = D-pad right (open the inventory), L = page
- for (UITouch *t in _owner) { uint64_t v = [_owner objectForKey:t].unsignedLongLongValue;
- if ((v & 0xff) != C_H2KEY) continue;
- int tag = (int)(v >> 8);
- if (tag < KH_N) h2 |= 1ull << k_h2[tag].b;
- else h2 |= 1ull << h2menuBtn[tag - KH_N - 8]; }
- BOOL h2changed = h2 != _h2bits;
- _h2bits = h2;
- // The H2 floating stick: axis values from the finger's offset to the base centre (the same
- // curve as the fixed sticks — dead zone, then rising to full at KH_FULL of the base radius).
- if (_h2 && _h2stick) {
- CGPoint o = [self h2knobOffset]; CGFloat R = KH_STICK_R * self.h2u, d = hypot(o.x, o.y), dz = R * KH_DEAD;
- if (d > dz) {
- CGFloat m = fmin((d - dz) / (R * KH_FULL - dz), 1) / d;
- ax[0] = (int32_t)lrint(o.x * m * 32767); ax[1] = (int32_t)lrint(-o.y * m * 32767);
- }
- }
- if (_h2 && _h2omega) {
- // A ZR-carrying key is down (or comes down): ZR leads it by the remainder of the window.
- BOOL carry = (h2 & ((1ull << B_Y) | (1ull << B_X))) != 0;
- double now = [NSDate timeIntervalSinceReferenceDate];
- if (carry && now - _h2omegaSince < KH_ZR_LEAD) {
- double left = KH_ZR_LEAD - (now - _h2omegaSince);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(left * NSEC_PER_SEC)),
- dispatch_get_main_queue(), ^{ [self recompute]; });
- } else if (carry || now - _h2omegaSince >= KH_ZR_LEAD) {
- h2 |= 1ull << B_ZR;
- }
- }
- BOOL changed = face != _faceBits || dpad != _dpadBits || btn != _btnBits || swap != _swapHeld || h2changed;
+ BOOL changed = face != _faceBits || dpad != _dpadBits || btn != _btnBits || swap != _swapHeld;
_faceBits = face; _dpadBits = dpad; _btnBits = btn; _swapHeld = swap;
pthread_mutex_lock(&g_mu);
- if (_h2) { g_touch_btn = h2 | btn; g_touch_lx = ax[0]; g_touch_ly = ax[1]; g_touch_rx = 0; g_touch_ry = 0; }
- else { g_touch_btn = face | dpad | btn; g_touch_lx = ax[0]; g_touch_ly = ax[1]; g_touch_rx = ax[2]; g_touch_ry = ax[3]; }
+ g_touch_btn = face | dpad | btn; g_touch_lx = ax[0]; g_touch_ly = ax[1]; g_touch_rx = ax[2]; g_touch_ry = ax[3];
pthread_mutex_unlock(&g_mu);
publish();
- BOOL sticks = _h2 ? _h2stick != nil : (_stick[0] || _stick[1]);
+ BOOL sticks = _stick[0] || _stick[1];
if (changed || sticks || _sticksShown) [self refresh]; // also refresh on the stick release so the knob returns to the centre
_sticksShown = sticks;
}
@@ -452,57 +243,10 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);
for (int i = 0; i < 16; i++) if (!_game[i]) { _game[i] = t; [_owner setObject:@(C_GAME | (uint64_t)i << 8) forKey:t]; return YES; }
return NO;
}
-- (BOOL)touchesBeganH2:(NSSet<UITouch *> *)ts {
- BOOL game = NO;
- for (UITouch *t in ts) {
- CGPoint p = [t locationInView:self];
- // locked keys first (shoulders, − / +, the layout button), then H2 keys, then the menu pad, then the stick zone
- int hit = [self btnAt:p];
- if (hit >= 0) { [_owner setObject:@(C_BTN | (uint64_t)hit << 8) forKey:t]; continue; }
- if ([self inSwap:p]) { [_owner setObject:@(C_SWAP) forKey:t]; continue; }
- int m = [self h2menuAt:p]; // the menu keys sit clear of the combat cluster: menu key / L
- if (m >= 0) { [_owner setObject:@(C_H2KEY | (uint64_t)(KH_N + 8 + m) << 8) forKey:t]; continue; }
- int k = [self h2keyAt:p];
- if (k >= 0) {
- [_owner setObject:@(C_H2KEY | (uint64_t)k << 8) forKey:t];
- _h2keyDown[k] = [NSDate timeIntervalSinceReferenceDate];
- if (k_h2[k].b == B_ZR) { _h2omega = YES; _h2omegaSince = _h2keyDown[k]; } // the Ω latch arms
- continue;
- }
- // The floating stick: a touch in the lower-left zone starts it, base centre = the touch
- // point (clamped so the base stays on screen). A finger resuming after a system cancel
- // keeps the old base instead of jumping to the new touch point.
- if (!_h2stick && [self h2inStickZone:p]) {
- BOOL resume = _h2lostS > 0 && [NSDate timeIntervalSinceReferenceDate] - _h2lostS <= KH_RESUME_S
- && dist(p, CGPointMake(_h2lostOrigin.x, _h2lostOrigin.y)) <= KH_RESUME_K * KH_STICK_R * self.h2u;
- _h2stick = t; _h2now = p;
- if (resume) _h2origin = _h2lostOrigin;
- else {
- CGFloat R = KH_STICK_R * self.h2u, m = CGRectGetMinX(self.bounds) + R + 8;
- _h2origin = CGPointMake(fmax(p.x, m), fmin(p.y, self.bounds.size.height - R - 8));
- }
- _h2lostS = 0;
- [_owner setObject:@(C_STICK | (uint64_t)2 << 8) forKey:t]; // slot 2 = the H2 floating stick
- continue;
- }
- game |= [self gameBegin:t];
- }
- return game;
-}
-- (BOOL)touchesMovedH2:(NSSet<UITouch *> *)ts {
- BOOL game = NO;
- for (UITouch *t in ts) {
- uint64_t v = [_owner objectForKey:t].unsignedLongLongValue;
- if ((v & 0xff) == C_STICK && (v >> 8) == 2) _h2now = [t locationInView:self];
- else if ((v & 0xff) == C_GAME) game = YES;
- }
- return game;
-}
- (void)touchesBegan:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e {
BOOL game = NO;
- if (_padOff) { for (UITouch *t in ts) game |= [self gameBegin:t]; }
- else if (_h2) game = [self touchesBeganH2:ts];
- else for (UITouch *t in ts) {
+ for (UITouch *t in ts) {
+ if (_padOff) { game |= [self gameBegin:t]; continue; }
CGPoint p = [t locationInView:self]; int hit = [self btnAt:p];
if (hit >= 0) { [_owner setObject:@(C_BTN | (uint64_t)hit << 8) forKey:t]; continue; }
if ([self inSwap:p]) { [_owner setObject:@(C_SWAP) forKey:t]; continue; }
@@ -522,8 +266,7 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);
}
- (void)touchesMoved:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e {
BOOL game = NO;
- if (_h2) game = [self touchesMovedH2:ts];
- else for (UITouch *t in ts) {
+ for (UITouch *t in ts) {
uint64_t v = [_owner objectForKey:t].unsignedLongLongValue; int c = (int)(v & 0xff); CGPoint p = [t locationInView:self];
if (c == C_FACE) [_faceOf setObject:@([self faceAt:p]) forKey:t];
else if (c == C_STICK) _stickNow[v >> 8] = p;
@@ -537,24 +280,16 @@ static CGFloat dist(CGPoint a, CGPoint b) { return hypot(a.x - b.x, a.y - b.y);
for (UITouch *t in ts) {
uint64_t v = [_owner objectForKey:t].unsignedLongLongValue;
if (ended && (v & 0xff) == C_SWAP && [self inSwap:[t locationInView:self]]) swap = YES; // layout button: counts only when released on the button
- if ((v & 0xff) == C_STICK && (v >> 8) == 2 && t == _h2stick) { // the floating stick: record for the resume
- _h2stick = nil; _h2lostOrigin = _h2origin; _h2lostS = [NSDate timeIntervalSinceReferenceDate];
- }
- if ((v & 0xff) == C_H2KEY) {
- int tag = (int)(v >> 8);
- if (tag < KH_N) { _h2keyDown[tag] = 0; if (k_h2[tag].b == B_ZR) _h2omega = NO; }
- }
if ((v & 0xff) == C_GAME && (v >> 8) < 16) { _game[v >> 8] = nil; game = YES; }
[_owner removeObjectForKey:t]; [_faceOf removeObjectForKey:t]; for (int i = 0; i < 2; i++) if (t == _stick[i]) _stick[i] = nil;
}
if (game) [self pushGame];
[self recompute];
- if (swap) [self setFull:YES]; // cycle 2D → 3D → H2 → 2D
+ if (swap) [self setFull:!_full];
}
- (void)touchesEnded:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e { [self endTouches:ts tapped:YES]; }
- (void)touchesCancelled:(NSSet<UITouch *> *)ts withEvent:(UIEvent *)e { [self endTouches:ts tapped:NO]; }
-- (void)reset { [_owner removeAllObjects]; [_faceOf removeAllObjects]; _stick[0] = _stick[1] = nil; for (int i = 0; i < 16; i++) _game[i] = nil;
- _h2stick = nil; _h2omega = NO; for (int i = 0; i < KH_N; i++) _h2keyDown[i] = 0; _h2lostS = 0; [self pushGame]; [self recompute]; }
+- (void)reset { [_owner removeAllObjects]; [_faceOf removeAllObjects]; _stick[0] = _stick[1] = nil; for (int i = 0; i < 16; i++) _game[i] = nil; [self pushGame]; [self recompute]; }
// ---- Shapes ----
static CGPathRef circlePath(CGPoint c, CGFloat r) { return CGPathCreateWithEllipseInRect(CGRectMake(c.x - r, c.y - r, 2 * r, 2 * r), NULL); }
@@ -606,23 +341,6 @@ static void placeLabel(CATextLayer *t, CGPoint c, CGFloat fs) {
static const struct { int b; CGFloat angle; } arms[] = {{B_UP, 0}, {B_RIGHT, M_PI_2}, {B_DOWN, M_PI}, {B_LEFT, -M_PI_2}}; // the same arm in 90° steps
for (int i = 0; i < 4; i++) setPath(_key[arms[i].b], armPath(self.dpadCenter, self.dpadR, K_ARM_W * u, K_ARM_IN * u, arms[i].angle, 6 * u));
CGPoint sc = self.swapCenter; setPath(_swap, circlePath(sc, K_SWAP_R * u)); placeLabel(_swapLabel, sc, 12 * u);
- // Hades II combat keys: rings at their centres, the glyph (or letter) centred inside
- for (int i = 0; i < KH_N; i++) {
- CGPoint c = [self h2keyCenter:i]; CGFloat r = [self h2keyR:i];
- setPath(_h2key[i], circlePath(c, r));
- if (_h2icon[i]) {
- CGFloat s = r * 1.1; // the glyph slightly larger than the ring's inner circle
- _h2icon[i].frame = CGRectMake(c.x - s / 2, c.y - s / 2, s, s);
- } else if (_h2label[i]) {
- placeLabel(_h2label[i], c, r * 0.75);
- }
- }
- // Hades II menu keys: two circle keys (the menu key carries a ◀ label, L its letter)
- for (int i = 0; i < 2; i++) {
- CGPoint mc = [self h2menuKey:i]; CGFloat mr = [self h2menuR];
- setPath(_h2menuKey[i], circlePath(mc, mr));
- placeLabel(_h2menuLabel[i], mc, mr * 0.5);
- }
for (int i = 0; i < 2; i++) {
setPath(_ring[i], circlePath([self stickHome:i], [self stickR:i]));
CGFloat k = (i ? K_RKNOB_R : K_KNOB_R) * u; _knob[i].bounds = CGRectMake(0, 0, 2 * k, 2 * k);
@@ -635,44 +353,15 @@ static void placeLabel(CATextLayer *t, CGPoint c, CGFloat fs) {
}
- (void)safeAreaInsetsDidChange { [super safeAreaInsetsDidChange]; [self setNeedsLayout]; }
- (void)refresh { // pressed state → fill, sticks → knob position
- uint64_t all = _faceBits | _dpadBits | _btnBits | (_h2 ? _h2bits : 0);
+ uint64_t all = _faceBits | _dpadBits | _btnBits;
[CATransaction begin]; [CATransaction setDisableActions:YES];
for (int b = 0; b < B_N; b++) { BOOL on = (all >> b) & 1;
_key[b].fillColor = (on ? k_on : k_idle).CGColor; _label[b].foregroundColor = (on ? k_textOn : k_text).CGColor; }
_swap.fillColor = (_swapHeld ? k_on : k_idle).CGColor; _swapLabel.foregroundColor = (_swapHeld ? k_textOn : k_text).CGColor;
- for (int i = 0; i < KH_N; i++) {
- BOOL on = (_h2bits >> k_h2[i].b) & 1;
- BOOL armed = _h2 && k_h2[i].b == B_ZR && _h2omega; // the Ω latch glows while armed
- _h2key[i].fillColor = (on || armed ? k_on : k_idle).CGColor;
- if (_h2label[i]) _h2label[i].foregroundColor = (on || armed ? k_textOn : k_text).CGColor;
- }
- // the menu pad: handle always visible in H2; the expanded keys light on press
- {
- static const int h2menuBtn[2] = {B_RIGHT, B_L};
- for (int i = 0; i < 2; i++) {
- BOOL on = (_h2bits >> h2menuBtn[i]) & 1;
- _h2menuKey[i].fillColor = (on ? k_on : k_idle).CGColor;
- _h2menuLabel[i].foregroundColor = (on ? k_textOn : k_text).CGColor;
- }
- }
for (int i = 0; i < 2; i++) {
CGPoint h = [self stickHome:i], o = [self knobOffset:i];
_knob[i].position = CGPointMake(h.x + o.x, h.y + o.y); _knob[i].fillColor = (_stick[i] ? k_on : k_idle).CGColor;
}
- // the H2 floating base: hidden with no stick finger, drawn at its origin with the knob when held
- BOOL h2s = _h2 && _h2stick != nil;
- _h2ring.hidden = !h2s; _h2knob.hidden = !h2s;
- if (h2s) {
- CGFloat R = KH_STICK_R * self.h2u, k = K_KNOB_R * self.u;
- setPath(_h2ring, circlePath(_h2origin, R));
- _h2knob.bounds = CGRectMake(0, 0, 2 * k, 2 * k);
- setPath(_h2knob, circlePath(CGPointMake(k, k), k));
- CAShapeLayer *in = (CAShapeLayer *)_h2knob.sublayers.firstObject; CGPathRef ip = circlePath(CGPointMake(k, k), k * 0.62);
- in.frame = _h2knob.bounds; in.path = ip; CGPathRelease(ip);
- CGPoint o = [self h2knobOffset];
- _h2knob.position = CGPointMake(_h2origin.x + o.x, _h2origin.y + o.y);
- _h2knob.fillColor = k_on.CGColor;
- }
[CATransaction commit];
}