mirror of
https://github.com/jhaizhou-ops/d2r-mobile
synced 2026-11-26 13:57:52 +08:00
- Android (#113, @yyan160; graphics engine and shader-bundle packer from @biglawine's HarmonyOS port): an Android app (dm/android) with a JNI host, a touch overlay on the shared touch state machine, Vulkan presentation and AAudio sound; an NVN-to-Vulkan replay engine (dm/gfx/vulkan) behind the same backend interface as Metal; the shared host now builds for Apple and Android, and the module rewriter has an Android target (DM_TARGET=android; Apple output unchanged). Measured by the authors at a median 60 fps on a Redmi K50 Ultra. - Android install with your own game files: the release APK (dm/android/tools/shell_apk.sh) contains no game content; dm/tools/d2rm_android.py makes an import pack (rewritten program, Vulkan shader bundles, touch overlay, data tables) that the App imports from Download/S2X/D2R Mobile/android with a progress screen. The shader export step (dm/gfx/tools/dmsh_vk.py) makes the 6,927 game shader bundles byte-for-byte identical to the tested set. - Android rewriter fix (#113, @yyan160): rewrite blocks no longer stash registers below sp (Android has no red zone); equiv.py checks Android outputs, structck.py recognizes the Android block shapes. Apple output unchanged. - Android touch controls drawn as on iOS (sockets, silver skill silhouettes, joystick), no map key in game state, no virtual pad buttons over panels; dm/android/tools/art_compare.sh compares the two drawings pixel by pixel. - HarmonyOS (#114, @biglawine): a HarmonyOS NEXT app (dm/harmony, ArkTS shell + N-API library) on the same shared host and Vulkan engine as Android; shared changes are behind __OHOS__ or opt-in switches (adaptive present tier, fence waits woken on completion, OHAudio, HiTrace markers, a byte-identical BC fast path). - HarmonyOS install with your own game files (@biglawine, 0.19.4 / code122): the release HAP is unsigned and contains no game content; players re-sign it with their own debug certificate and import a pack made with dm/tools/d2rm_android.py --target ohos. The registering stand-ins read the tables only when dm_derived_reload() is called (on __OHOS__); first import creates the target folders; outside a game a map toggle request is dropped before the AutoMap exists. Run by the author on a Mate 90 Pro Max: re-sign, install, import, in game, save and exit. - Vulkan: NaN-ignoring min / max / clamp as on Maxwell (#113, @yyan160), fixing one-frame black tiles on the OnePlus 13. - Xbox controllers (from #110, @rrroy5640): recognized automatically and given the PC / Xbox layout (bottom confirms, right goes back) with the game's Xbox button icons; other controllers are unchanged. The Mac-only keyboard prompt switch became a three-way prompt style (Switch / keyboard / Xbox) on every platform. - Separate base and update packages (#106, @PowerBeef): setup.sh and extract_game.sh take both packages and read the title keys from their tickets. - Mac App (#108, #109, @PowerBeef): the project's icon by default; the pointer hides after resting 3 s. - run.sh install no longer goes through the test-device battery gate (#107, @PowerBeef). - Chinese wording (#101, @zzz6519003): 「旧接口版」 and 「默认构建」 throughout. - Dynamic 3D resolution (from #113): a run of dropped frames counts only its first 3 frames unless it lasts 1 s, so one-off stalls no longer lower the resolution. - In-game Korean (#118, @soulsakura): a 한국어 column for all our UI text, a fifth option in the language row (each checkbox now sits before its name), Korean touch wording and map name plates, Korean voice when the game files carry it; a Korean system language picks Korean on first install. - iPhone Duo: in full screen the output size follows the window when the phone is unfolded or folded, up to the size the game started with; needs Xcode 27.1 for the inner screen to be filled. Test switches DM_TEST_FOLD and DM_TEST_SCREEN simulate the two screens with the iOS package on a Mac. - README: Android and HarmonyOS sections, device table and credits in all three languages; dependency list for Android. Every change was ported into the internal tree with its authors credited. For the shared files, the code changes match the pull requests' after stripping comments. Host / graphics / iOS unit tests, the full acceptance gate and the Mac smoke test passed; the rewriter's rule sets were rebuilt and passed the equivalence regression; an iOS build of this code was played on an iPhone; the Android APK with an import pack made from our own game files was played on a vivo X200 Ultra. Exported from main 8055e5212. Co-authored-by: Yuechuan Yang <22333122+yyan160@users.noreply.github.com> Co-authored-by: biglawine <26263820+biglawine@users.noreply.github.com> Co-authored-by: rrroy <hly5640@gmail.com> Co-authored-by: Patrice Déry <109446870+PowerBeef@users.noreply.github.com> Co-authored-by: Sam Snowman(赵正中) <zhengzhongzhao@gmail.com> Co-authored-by: soulsakura <74704744+soulsakura@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
70 lines
4.6 KiB
C
70 lines
4.6 KiB
C
// 安卓前端(front.h 的安卓实现,对应 Mac 的 front_mac.m、iOS 的 front_ios.m)。
|
||
// 两种形态:
|
||
// 命令行(adb shell 直接跑 dmhost,开发验证用):没有窗口,front_run 在当前线程直接跑客体,front_metal_layer 为 NULL(图形层走无窗口路径)。
|
||
// App(Java 外壳经 JNI 交来 ANativeWindow,见 jni_android.c):客体在独立线程跑,front_metal_layer 返回 ANativeWindow*(图形层出图的目标面)。
|
||
// Android front end (the Android implementation of front.h, counterpart of Mac's front_mac.m and iOS's front_ios.m).
|
||
// Two forms:
|
||
// Command line (dmhost run directly from adb shell, for development checks): no window, front_run runs the guest directly on the current thread, front_metal_layer is NULL (the graphics layer takes the no-window path).
|
||
// App (the Java shell hands over an ANativeWindow through JNI, see jni_android.c): the guest runs on its own thread, front_metal_layer returns the ANativeWindow* (the surface the graphics layer presents to).
|
||
#include "../host/dm.h"
|
||
#include "../host/front.h"
|
||
#include "../host/dm_input.h"
|
||
#include "touch_android.h"
|
||
#include "../ios/Sources/dm_touch_game_state.h"
|
||
#include <math.h>
|
||
#include <stdatomic.h>
|
||
|
||
static void *_Atomic g_window; // ANativeWindow*;命令行形态为 NULL | ANativeWindow*; NULL in the command-line form
|
||
static _Atomic int g_screen_w, g_screen_h;
|
||
void front_android_set_window(void *win, int w, int h) { atomic_store(&g_window, win); atomic_store(&g_screen_w, w); atomic_store(&g_screen_h, h); }
|
||
|
||
// UI 线程从当前 Display 读实际刷新率;0 表示未知,不冒充实测 60 Hz。
|
||
// The UI thread reads the current Display refresh rate; 0 means unknown, not a measured 60 Hz.
|
||
static _Atomic int g_refresh_millihz;
|
||
void front_android_set_refresh(float hz) {
|
||
atomic_store(&g_refresh_millihz, isfinite(hz) && hz > 0 && hz < 1000 ? (int)lroundf(hz * 1000) : 0);
|
||
}
|
||
double front_display_refresh(char *name, size_t n) {
|
||
if (name && n) *name = 0;
|
||
return atomic_load(&g_refresh_millihz) / 1000.0;
|
||
}
|
||
|
||
void *front_metal_layer(void) { return atomic_load(&g_window); }
|
||
|
||
void front_run(void (*guest)(void)) {
|
||
// 观测门在装载后才可订阅;这里沿用 iOS 在 front_run 接入的时机。
|
||
// Observation gates exist only after loading; subscribe at front_run as iOS does.
|
||
if (front_metal_layer()) {
|
||
void uimsg_subscribe(void (*)(const char *, const char *, const char *));
|
||
uimsg_subscribe(dm_android_touch_uimsg);
|
||
dm_pad_hook = dm_android_touch_step;
|
||
dm_touch_game_attach();
|
||
dm_touch_game_live_check(1);
|
||
}
|
||
guest(); // 两种形态都在调用线程上跑:App 形态由 JNI 侧先起好客体线程再进 dm_main | Both forms run on the calling thread: in the App form the JNI side starts the guest thread first and then enters dm_main
|
||
}
|
||
|
||
// 游戏输出分辨率:DM_GAME_RES 钉住;有屏幕尺寸时按同高度放宽到屏幕比例(与 Mac 真全屏、iOS 同一规则,宽 ≤ 4096、8 对齐),否则原版 16:9
|
||
// Game output resolution: pinned by DM_GAME_RES; with a known screen size, widen at the same height to the screen aspect (the same rule as Mac true full screen and iOS, width ≤ 4096, aligned to 8), otherwise the original 16:9
|
||
uint64_t front_game_res(int docked) {
|
||
unsigned w, h; const char *e = getenv("DM_GAME_RES");
|
||
if (e && sscanf(e, "%ux%u", &w, &h) == 2) return docked ? (uint64_t)h << 32 | w : (uint64_t)(h * 4 / 5) << 32 | (w * 4 / 5 + 3) / 4 * 4;
|
||
int dm = atomic_load(&g_screen_w), sh = atomic_load(&g_screen_h);
|
||
unsigned bh = docked ? 900 : 720;
|
||
if (dm > 0 && sh > 0 && dm * 9 > sh * 16) {
|
||
unsigned bw = (unsigned)(llround((double)bh * dm / sh / 8) * 8); if (bw > 4096) bw = 4096;
|
||
return (uint64_t)bh << 32 | bw;
|
||
}
|
||
return docked ? 900ull << 32 | 1600 : 720ull << 32 | 1280;
|
||
}
|
||
|
||
// 文本输入框:App 用 text_input_jni.c 的强实现弹系统输入框;命令行无窗口,返回 -1。
|
||
// Text input: the App overrides this with text_input_jni.c; windowless command-line runs return -1.
|
||
__attribute__((weak)) int front_android_text_input(const char *title, const char *sub, const char *guide, const char *initial, int max_chars, char *out, int out_cap) {
|
||
(void)title; (void)sub; (void)guide; (void)initial; (void)max_chars; (void)out; (void)out_cap; return -1;
|
||
}
|
||
int front_text_input(const char *title, const char *sub, const char *guide, const char *initial, int max_chars, char *out, int out_cap) {
|
||
if (!front_metal_layer()) return -1;
|
||
return front_android_text_input(title, sub, guide, initial, max_chars, out, out_cap);
|
||
}
|