Files
d2r-mobile/dm/android/compat/include/dm_android_compat.h
b811b90172 v2.0: Android and HarmonyOS ports, Korean, iPhone Duo, Xbox controller layout, separate game packages, Mac icon and pointer
- 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>
2026-10-23 09:21:08 +08:00

57 lines
3.4 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 安卓构建强制包含(CMake -include):宿主源码里零散用到的苹果 libc 扩展,在 bionic 上给出同名同语义的薄实现。
// 只放「一行能说清、语义完全对得上」的;对不上的(Mach 线程挂起、实时调度策略、GCD、音频)在原文件按 __APPLE__ 分支各自实现,不在这里假装。
// Force-included in the Android build (CMake -include): Apple libc extensions used here and there in the host source, given thin implementations with the same name and semantics on bionic.
// Only things that are "explainable in one line with fully matching semantics" go here; those that do not match (Mach thread suspension, real-time scheduling policy, GCD, audio) are implemented in their own files under __APPLE__ branches, not faked here.
#pragma once
#if defined(__ANDROID__) || defined(__OHOS__)
#include <errno.h>
#include <fcntl.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <time.h>
#include <unistd.h>
// 苹果的 CLOCK_UPTIME_RAW(睡眠不走的单调钟)= Linux CLOCK_MONOTONIC;CLOCK_MONOTONIC_RAW 两边同名
// Apple's CLOCK_UPTIME_RAW (a monotonic clock that stops during sleep) = Linux CLOCK_MONOTONIC; CLOCK_MONOTONIC_RAW has the same name on both
#ifndef CLOCK_UPTIME_RAW
#define CLOCK_UPTIME_RAW CLOCK_MONOTONIC
#endif
static inline uint64_t clock_gettime_nsec_np(clockid_t c) {
struct timespec ts; if (clock_gettime(c, &ts)) return 0;
return (uint64_t)ts.tv_sec * 1000000000ull + (uint64_t)ts.tv_nsec;
}
#ifndef __OHOS__ // musl 自带 | musl has its own
static inline int getdtablesize(void) { return (int)sysconf(_SC_OPEN_MAX); }
#endif
static inline size_t pthread_get_stacksize_np(pthread_t t) {
pthread_attr_t a; size_t s = 0;
if (!pthread_getattr_np(t, &a)) { pthread_attr_getstacksize(&a, &s); pthread_attr_destroy(&a); }
return s;
}
// 苹果 pthread_get_stackaddr_np 返回栈顶(最高地址);bionic 的 attr 给的是栈底 + 大小
// Apple's pthread_get_stackaddr_np returns the stack top (highest address); bionic's attr gives the stack bottom + size
static inline void *pthread_get_stackaddr_np(pthread_t t) {
pthread_attr_t a; void *lo = NULL; size_t s = 0;
if (!pthread_getattr_np(t, &a)) { pthread_attr_getstack(&a, &lo, &s); pthread_attr_destroy(&a); }
return (char *)lo + s;
}
// struct stat 的纳秒时间字段:苹果叫 st_mtimespec,Linux 叫 st_mtim
// Nanosecond time field of struct stat: called st_mtimespec on Apple, st_mtim on Linux
#define st_mtimespec st_mtim
#define st_atimespec st_atim
#define st_ctimespec st_ctim
// 存档事务(hle_fs.c):clonefile 在安卓上是整树拷贝(含 user.* 扩展属性,存档目录只有几 MB),renamex_np(RENAME_SWAP) = renameat2(RENAME_EXCHANGE)
// Save transactions (hle_fs.c): clonefile on Android is a whole-tree copy (including user.* extended attributes; the save directory is only a few MB), renamex_np(RENAME_SWAP) = renameat2(RENAME_EXCHANGE)
int clonefile(const char *src, const char *dst, int flags); // dm/android/compat/clonefile.c
#ifndef RENAME_SWAP
#define RENAME_SWAP (1u << 1) // 与 Linux RENAME_EXCHANGE 同值 | Same value as Linux RENAME_EXCHANGE
#endif
static inline int renamex_np(const char *from, const char *to, unsigned flags) {
return (int)syscall(__NR_renameat2, AT_FDCWD, from, AT_FDCWD, to, flags & RENAME_SWAP ? (1u << 1) : 0u);
}
#endif