Mobile step 7b: iOS packaging (simulator verified to the game scene)
- ios/build.sh builds static SDL3 + FreeType, then the .app (code only, embedded Python); signs ad hoc and runs on a simulator, or signs with a development profile and installs with devicectl (device path untested). Simulator-only SDL patch: accept the simulator Metal device for SDL_GPU. - ios/Info.plist.in: landscape, full screen, launch screen, file sharing. - Data dir is Documents on iOS; ios/push_assets.py stages the client root lower-cased (iOS is case-sensitive, the client opens lower-cased paths) and copies it into the app container. - EffectData path normalisation folds A-Z like the effect cache key. - android/push_assets.py: test-rundir base layer + svside/, which the game phase needs (also fixes Android); --lowercase (ASCII only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f973b24abc
commit
908838c8f9
@@ -368,6 +368,21 @@ if(AVA2_BUILD_HOST)
|
|||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
add_library(main SHARED ${AVA2_HOST_SOURCES})
|
add_library(main SHARED ${AVA2_HOST_SOURCES})
|
||||||
set(AVA2_HOST main)
|
set(AVA2_HOST main)
|
||||||
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
|
||||||
|
# ios/build.sh: an .app with code only; the client root goes to Documents (ios/push_assets.py).
|
||||||
|
add_executable(ava2_client MACOSX_BUNDLE ${AVA2_HOST_SOURCES})
|
||||||
|
set(AVA2_HOST ava2_client)
|
||||||
|
if(CMAKE_OSX_SYSROOT MATCHES "[Ss]imulator")
|
||||||
|
set(AVA2_IOS_PLATFORM iPhoneSimulator)
|
||||||
|
else()
|
||||||
|
set(AVA2_IOS_PLATFORM iPhoneOS)
|
||||||
|
endif()
|
||||||
|
set(AVA2_IOS_BUNDLE_ID "com.metin2.ava2" CACHE STRING "iOS bundle identifier")
|
||||||
|
set_target_properties(ava2_client PROPERTIES
|
||||||
|
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/ios/Info.plist.in"
|
||||||
|
MACOSX_BUNDLE_GUI_IDENTIFIER "${AVA2_IOS_BUNDLE_ID}"
|
||||||
|
MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0.0"
|
||||||
|
MACOSX_BUNDLE_BUNDLE_VERSION "1")
|
||||||
else()
|
else()
|
||||||
add_executable(ava2_client ${AVA2_HOST_SOURCES})
|
add_executable(ava2_client ${AVA2_HOST_SOURCES})
|
||||||
set(AVA2_HOST ava2_client)
|
set(AVA2_HOST ava2_client)
|
||||||
|
|||||||
+45
-6
@@ -4,13 +4,17 @@
|
|||||||
The APK holds code only; on Android the client runs in its external files directory
|
The APK holds code only; on Android the client runs in its external files directory
|
||||||
(/sdcard/Android/data/com.metin2.ava2/files) and reads the flattened client root from there:
|
(/sdcard/Android/data/com.metin2.ava2/files) and reads the flattened client root from there:
|
||||||
|
|
||||||
|
0. build/dev/test-rundir the pack-manifest client root (tools/make_test_rundir.py)
|
||||||
1. assets/loose the client-root asset tree
|
1. assets/loose the client-root asset tree
|
||||||
2. upstream/python-root scripts; win over same-named asset files (case-insensitive)
|
2. upstream/python-root scripts; win over same-named asset files (case-insensitive)
|
||||||
3. python27.zip the embedded interpreter's stdlib
|
3. <pack_maker>/../svside loose client-root folder that is in no pack
|
||||||
|
4. python27.zip the embedded interpreter's stdlib
|
||||||
|
|
||||||
|
Later layers replace earlier files with the same (case-insensitive) path.
|
||||||
|
|
||||||
The merged tree is staged as hard links (no copy) in build/android-data/root, then sent with
|
The merged tree is staged as hard links (no copy) in build/android-data/root, then sent with
|
||||||
`adb push --sync`, which skips files the device already has with the same timestamp, so later
|
`adb push --sync`, which skips files the device already has with the same timestamp, so later
|
||||||
runs only transfer what changed. The first run moves about 2.8 GB.
|
runs only transfer what changed. The first run moves about 4 GB.
|
||||||
|
|
||||||
assets/loose keeps a few symlinks into the decoded pack_maker tree of the machine it was
|
assets/loose keeps a few symlinks into the decoded pack_maker tree of the machine it was
|
||||||
committed on; they are remapped to --pack-maker (default ../AVA2/TEST/1. Client DEV/pack_maker).
|
committed on; they are remapped to --pack-maker (default ../AVA2/TEST/1. Client DEV/pack_maker).
|
||||||
@@ -30,6 +34,8 @@ ROOT = Path(__file__).resolve().parent.parent
|
|||||||
PACKAGE = "com.metin2.ava2"
|
PACKAGE = "com.metin2.ava2"
|
||||||
DEVICE_DIR = f"/sdcard/Android/data/{PACKAGE}/files"
|
DEVICE_DIR = f"/sdcard/Android/data/{PACKAGE}/files"
|
||||||
PACK_MAKER_MARK = "/pack_maker/"
|
PACK_MAKER_MARK = "/pack_maker/"
|
||||||
|
LOOSE_DIRS = ["svside"]
|
||||||
|
RUNDIR_MARKER = ".ava2_test_rundir"
|
||||||
|
|
||||||
|
|
||||||
def find_stdlib():
|
def find_stdlib():
|
||||||
@@ -39,11 +45,21 @@ def find_stdlib():
|
|||||||
return max(candidates, key=os.path.getmtime) if candidates else None
|
return max(candidates, key=os.path.getmtime) if candidates else None
|
||||||
|
|
||||||
|
|
||||||
|
def ascii_lower(name):
|
||||||
|
"""Lower-cases A-Z only, like the client's ResourceManager::NormalizePath; legacy CP949 names
|
||||||
|
(stored as Latin-1 code points) must keep their bytes."""
|
||||||
|
return name.translate(ASCII_LOWER)
|
||||||
|
|
||||||
|
|
||||||
|
ASCII_LOWER = str.maketrans("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")
|
||||||
|
|
||||||
|
|
||||||
class Stage:
|
class Stage:
|
||||||
"""Hard-link tree; a later source replaces an earlier file with the same lower-case path."""
|
"""Hard-link tree; a later source replaces an earlier file with the same lower-case path."""
|
||||||
|
|
||||||
def __init__(self, out):
|
def __init__(self, out, lowercase=False):
|
||||||
self.out = out
|
self.out = out
|
||||||
|
self.lowercase = lowercase # stage every name lower-case (case-sensitive targets, iOS)
|
||||||
self.files = {} # lower-case relative path -> staged path
|
self.files = {} # lower-case relative path -> staged path
|
||||||
self.dirs = {"": out}
|
self.dirs = {"": out}
|
||||||
|
|
||||||
@@ -53,7 +69,7 @@ class Stage:
|
|||||||
parent = self.dirs[key]
|
parent = self.dirs[key]
|
||||||
key = f"{key}/{part.lower()}" if key else part.lower()
|
key = f"{key}/{part.lower()}" if key else part.lower()
|
||||||
if key not in self.dirs:
|
if key not in self.dirs:
|
||||||
self.dirs[key] = parent / part
|
self.dirs[key] = parent / (ascii_lower(part) if self.lowercase else part)
|
||||||
self.dirs[key].mkdir()
|
self.dirs[key].mkdir()
|
||||||
return self.dirs[key]
|
return self.dirs[key]
|
||||||
|
|
||||||
@@ -62,7 +78,7 @@ class Stage:
|
|||||||
old = self.files.pop(key, None)
|
old = self.files.pop(key, None)
|
||||||
if old is not None:
|
if old is not None:
|
||||||
old.unlink()
|
old.unlink()
|
||||||
target = self._dir(rel.parent) / rel.name
|
target = self._dir(rel.parent) / (ascii_lower(rel.name) if self.lowercase else rel.name)
|
||||||
try:
|
try:
|
||||||
os.link(source, target)
|
os.link(source, target)
|
||||||
except OSError: # another volume
|
except OSError: # another volume
|
||||||
@@ -105,7 +121,11 @@ def main():
|
|||||||
parser.add_argument("--pack-maker", type=Path, default=ROOT.parent / "AVA2/TEST/1. Client DEV/pack_maker")
|
parser.add_argument("--pack-maker", type=Path, default=ROOT.parent / "AVA2/TEST/1. Client DEV/pack_maker")
|
||||||
parser.add_argument("--stdlib", help="python27.zip (default: newest Android/desktop build output)")
|
parser.add_argument("--stdlib", help="python27.zip (default: newest Android/desktop build output)")
|
||||||
parser.add_argument("--stage", type=Path, default=ROOT / "build/android-data/root")
|
parser.add_argument("--stage", type=Path, default=ROOT / "build/android-data/root")
|
||||||
|
parser.add_argument("--rundir", type=Path, default=ROOT / "build/dev/test-rundir",
|
||||||
|
help="pack-manifest client root (tools/make_test_rundir.py), staged underneath")
|
||||||
parser.add_argument("--stage-only", action="store_true", help="build the staging tree, do not push")
|
parser.add_argument("--stage-only", action="store_true", help="build the staging tree, do not push")
|
||||||
|
parser.add_argument("--lowercase", action="store_true",
|
||||||
|
help="lower-case every staged name, for case-sensitive file systems (iOS)")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
stdlib = args.stdlib or find_stdlib()
|
stdlib = args.stdlib or find_stdlib()
|
||||||
@@ -115,10 +135,29 @@ def main():
|
|||||||
if args.stage.exists():
|
if args.stage.exists():
|
||||||
shutil.rmtree(args.stage)
|
shutil.rmtree(args.stage)
|
||||||
args.stage.mkdir(parents=True)
|
args.stage.mkdir(parents=True)
|
||||||
stage, missing = Stage(args.stage), []
|
stage, missing = Stage(args.stage, args.lowercase), []
|
||||||
|
# Base layer: the pack-manifest client root the desktop tests run against. assets/loose alone
|
||||||
|
# lacks the pack files (Dopador_manual/*, the switcher art...) game.py needs, and a failed window
|
||||||
|
# load there ends the game phase.
|
||||||
|
if args.rundir.is_dir():
|
||||||
|
for rel, path in walk(args.rundir, args.pack_maker, missing):
|
||||||
|
if rel.name != RUNDIR_MARKER:
|
||||||
|
stage.add(rel, path)
|
||||||
|
else:
|
||||||
|
print(f"warning: {args.rundir} not found (tools/make_test_rundir.py); the game phase will miss "
|
||||||
|
"pack files", file=sys.stderr)
|
||||||
for top in (ROOT / "assets/loose", ROOT / "upstream/python-root"):
|
for top in (ROOT / "assets/loose", ROOT / "upstream/python-root"):
|
||||||
for rel, path in walk(top, args.pack_maker, missing):
|
for rel, path in walk(top, args.pack_maker, missing):
|
||||||
stage.add(rel, path)
|
stage.add(rel, path)
|
||||||
|
# Loose client-root folders that are in neither assets/loose nor any pack (same as
|
||||||
|
# tools/make_test_rundir.py); svsideoi.py, built by game.py, needs svside/*.jpg.
|
||||||
|
for name in LOOSE_DIRS:
|
||||||
|
top = args.pack_maker.parent / name
|
||||||
|
if not top.is_dir():
|
||||||
|
missing.append(f"{name} -> {top}")
|
||||||
|
continue
|
||||||
|
for rel, path in walk(top, args.pack_maker, missing):
|
||||||
|
stage.add(Path(name) / rel, path)
|
||||||
stage.add(Path("python27.zip"), stdlib)
|
stage.add(Path("python27.zip"), stdlib)
|
||||||
for line in missing:
|
for line in missing:
|
||||||
print(f"warning: unresolved symlink {line}", file=sys.stderr)
|
print(f"warning: unresolved symlink {line}", file=sys.stderr)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
```
|
```
|
||||||
┌──────────────────────────────────────────────────────────────┐
|
┌──────────────────────────────────────────────────────────────┐
|
||||||
│ 平台打包 android/ (Gradle + SDLActivity + build.sh) │ 新增
|
│ 平台打包 android/ (Gradle + SDLActivity + build.sh) │ 新增
|
||||||
│ ios/ (以后) macOS .app (已有脚本) │
|
│ ios/ (build.sh) macOS .app (已有脚本) │
|
||||||
├──────────────────────────────────────────────────────────────┤
|
├──────────────────────────────────────────────────────────────┤
|
||||||
│ 主程序 src/app/ │
|
│ 主程序 src/app/ │
|
||||||
│ main.cpp 入口、命令行参数 │ 拆分
|
│ main.cpp 入口、命令行参数 │ 拆分
|
||||||
@@ -104,7 +104,7 @@ Python 更新(原版脚本 + mobile HUD)
|
|||||||
|---|---|---|---|---|
|
|---|---|---|---|---|
|
||||||
| macOS(开发和测试) | `ava2_client`、.app | Metal | 原版 PC 界面(可开关手机 HUD) | 键盘鼠标 |
|
| macOS(开发和测试) | `ava2_client`、.app | Metal | 原版 PC 界面(可开关手机 HUD) | 键盘鼠标 |
|
||||||
| Android(主目标) | APK(`libmain.so`) | Vulkan | 原版界面 + 手机 HUD | 触屏 |
|
| Android(主目标) | APK(`libmain.so`) | Vulkan | 原版界面 + 手机 HUD | 触屏 |
|
||||||
| iOS(以后) | .app | Metal | 同 Android | 触屏 |
|
| iOS | .app(`ios/build.sh`,资源用 `ios/push_assets.py` 小写拷入 Documents) | Metal | 同 Android | 触屏 |
|
||||||
|
|
||||||
## 手机 HUD 布局
|
## 手机 HUD 布局
|
||||||
|
|
||||||
@@ -144,6 +144,6 @@ Python 更新(原版脚本 + mobile HUD)
|
|||||||
3. `input/`:触摸分流、虚拟摇杆、攻击键、镜头手势——可在手机上移动和战斗。
|
3. `input/`:触摸分流、虚拟摇杆、攻击键、镜头手势——可在手机上移动和战斗。
|
||||||
4. `mobile/`:手机 HUD(状态面板、技能圈和快捷栏、右上角入口、小地图、左侧按钮)。
|
4. `mobile/`:手机 HUD(状态面板、技能圈和快捷栏、右上角入口、小地图、左侧按钮)。
|
||||||
5. 界面缩放和安全区域收尾。
|
5. 界面缩放和安全区域收尾。
|
||||||
6. 自动战斗等新增功能(自动狩猎已完成,见 PORT-PLAN);iOS 打包与 `app_loop` 拆分。
|
6. 自动战斗等新增功能(自动狩猎已完成,见 PORT-PLAN);iOS 打包与 `app_loop` 拆分(均已完成,模拟器验证到游戏场景;真机签名安装未测)。
|
||||||
|
|
||||||
第 3、4 步大部分可在 macOS 上开发(鼠标模拟单指,触控板测双指);多指同时操作和性能需要真机验证。
|
第 3、4 步大部分可在 macOS 上开发(鼠标模拟单指,触控板测双指);多指同时操作和性能需要真机验证。
|
||||||
|
|||||||
@@ -1403,3 +1403,53 @@ bad arguments still exit 1.
|
|||||||
Outstanding: Android stays on the classic loop until callbacks are tried on
|
Outstanding: Android stays on the classic loop until callbacks are tried on
|
||||||
a device; the frame body is still one function (state not yet split into
|
a device; the frame body is still one function (state not yet split into
|
||||||
classes).
|
classes).
|
||||||
|
|
||||||
|
### 2026-10-13 Mobile step 7b — iOS packaging
|
||||||
|
|
||||||
|
- `ios/build.sh [sim|device] [deps] [--no-run]`: builds static SDL3 3.4.16
|
||||||
|
and FreeType 2.13.3 once into `build/ios-deps/prefix-<sdk>` (tarballs
|
||||||
|
shared with `build/android-deps`), then the client as
|
||||||
|
`build/ios-<sdk>/ava2_client.app` (8.8 MB, code only, Python embedded,
|
||||||
|
deployment target 15.0, arm64). The simulator build is signed ad hoc,
|
||||||
|
booted, installed and launched. A device build is signed with
|
||||||
|
`AVA2_IOS_SIGN_IDENTITY` and the entitlements of `AVA2_IOS_PROFILE`, and
|
||||||
|
is installed with `xcrun devicectl`.
|
||||||
|
`ios/Info.plist.in` sets landscape only, full screen, a hidden status bar,
|
||||||
|
an empty launch screen (native resolution), `UIFileSharingEnabled`
|
||||||
|
and a local-network usage string.
|
||||||
|
- Simulator only: SDL_GPU rejects the simulator's Metal device because it
|
||||||
|
does not report MTLGPUFamilyApple3. `build.sh` patches its private
|
||||||
|
extracted copy of `SDL_gpu_metal.m` (`|| TARGET_OS_SIMULATOR`). Device
|
||||||
|
builds use stock SDL.
|
||||||
|
- Data directory: `platform.cpp` uses the app's Documents folder
|
||||||
|
(`SDL_FOLDER_DOCUMENTS`). The "game data not found" box names
|
||||||
|
`ios/push_assets.py`. That script stages the tree with
|
||||||
|
`android/push_assets.py --stage-only --lowercase` and copies it into the
|
||||||
|
simulator container as APFS clones (`cp -Rc`), or to a device with
|
||||||
|
`xcrun devicectl device copy to`.
|
||||||
|
- iOS file systems are case-sensitive as the app sees them, including the
|
||||||
|
simulator container. The client opens lower-cased paths
|
||||||
|
(ResourceManager::NormalizePath), but the data is mixed case
|
||||||
|
(`Dopador_manual/…`). So the iOS tree is staged with every name
|
||||||
|
ASCII-lowercased. Only A–Z is folded: legacy CP949 names stored as
|
||||||
|
Latin-1 code points (`oxà캥æ®.dds`) must keep their bytes.
|
||||||
|
`EffectData`'s path normalisation now also folds A–Z (scripts spell
|
||||||
|
`empire_A.mse`), like the effect cache key already did.
|
||||||
|
- Staging fixes that also apply to Android: `android/push_assets.py` now
|
||||||
|
uses `build/dev/test-rundir` (tools/make_test_rundir.py) as the base layer
|
||||||
|
and adds the loose `svside/` folder. Before, `assets/loose` alone lacked
|
||||||
|
pack files that game.py needs (Dopador_manual/*, the switcher art,
|
||||||
|
svside/*.jpg), and the game phase ended. The staged tree is now
|
||||||
|
98,349 files / 3.95 GiB.
|
||||||
|
|
||||||
|
Verified: iPhone 17 Pro simulator, `--phase game --preview-data`. The game
|
||||||
|
scene and the mobile HUD render; the safe area (118/0/118/38) keeps the HUD
|
||||||
|
clear of the notch on either landscape side. The console has 0 TraceError
|
||||||
|
or Traceback lines. Without data, the app shows the "game data not found"
|
||||||
|
box. Desktop 54/54.
|
||||||
|
Outstanding: the device build, signing and devicectl install/copy are
|
||||||
|
untested (no device or profile). The network keepalive does not run while
|
||||||
|
the app is in the background (iOS suspends SDL_AppIterate). Android still
|
||||||
|
uses the classic loop. Paths the client opens without lower-casing them
|
||||||
|
would fail on iOS; none showed up in the login screen or the game phase,
|
||||||
|
but character select and a real-server login have not been run on iOS yet.
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>ava2_client</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>${MACOSX_BUNDLE_GUI_IDENTIFIER}</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>AVA2</string>
|
||||||
|
<key>CFBundleDisplayName</key>
|
||||||
|
<string>AVA2</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>${MACOSX_BUNDLE_SHORT_VERSION_STRING}</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>${MACOSX_BUNDLE_BUNDLE_VERSION}</string>
|
||||||
|
<key>CFBundleSupportedPlatforms</key>
|
||||||
|
<array>
|
||||||
|
<string>${AVA2_IOS_PLATFORM}</string>
|
||||||
|
</array>
|
||||||
|
<key>MinimumOSVersion</key>
|
||||||
|
<string>${CMAKE_OSX_DEPLOYMENT_TARGET}</string>
|
||||||
|
<key>UIDeviceFamily</key>
|
||||||
|
<array>
|
||||||
|
<integer>1</integer>
|
||||||
|
<integer>2</integer>
|
||||||
|
</array>
|
||||||
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
<true/>
|
||||||
|
<!-- An (empty) launch screen opts into the native resolution instead of legacy letterboxing. -->
|
||||||
|
<key>UILaunchScreen</key>
|
||||||
|
<dict/>
|
||||||
|
<key>UIRequiresFullScreen</key>
|
||||||
|
<true/>
|
||||||
|
<key>UIStatusBarHidden</key>
|
||||||
|
<true/>
|
||||||
|
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||||
|
<false/>
|
||||||
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
</array>
|
||||||
|
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
</array>
|
||||||
|
<key>UIRequiredDeviceCapabilities</key>
|
||||||
|
<array>
|
||||||
|
<string>arm64</string>
|
||||||
|
<string>metal</string>
|
||||||
|
</array>
|
||||||
|
<!-- The client root lives in Documents (ios/push_assets.py); Finder / the Files app can copy it in. -->
|
||||||
|
<key>UIFileSharingEnabled</key>
|
||||||
|
<true/>
|
||||||
|
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||||
|
<true/>
|
||||||
|
<!-- The game server is plain TCP on the local network. -->
|
||||||
|
<key>NSLocalNetworkUsageDescription</key>
|
||||||
|
<string>Connects to the AVA2 game server on your network.</string>
|
||||||
|
<key>LSApplicationCategoryType</key>
|
||||||
|
<string>public.app-category.role-playing-games</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
Executable
+133
@@ -0,0 +1,133 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Builds the iOS app (arm64) and installs + launches it on a simulator or an attached device.
|
||||||
|
#
|
||||||
|
# ios/build.sh simulator build; boots $AVA2_IOS_SIMULATOR (default: first available
|
||||||
|
# iPhone), installs and launches
|
||||||
|
# ios/build.sh device device build, signed with $AVA2_IOS_SIGN_IDENTITY and
|
||||||
|
# $AVA2_IOS_PROFILE (.mobileprovision); installs + launches when
|
||||||
|
# `xcrun devicectl` sees a device
|
||||||
|
# ios/build.sh deps [device] only (re)build the native dependencies
|
||||||
|
# --no-run (any mode) build only
|
||||||
|
#
|
||||||
|
# Like the APK, the .app holds code only; push the client root with ios/push_assets.py.
|
||||||
|
# Native dependencies (static SDL3 + FreeType) are built once into build/ios-deps (sources are
|
||||||
|
# shared with build/android-deps when already downloaded).
|
||||||
|
# Environment overrides: AVA2_SDK_ROOT, AVA2_SOURCE_DIR (CMake source tree, default this checkout),
|
||||||
|
# AVA2_IOS_BUNDLE_ID (default com.metin2.ava2), AVA2_IOS_SIMULATOR, AVA2_IOS_DEVICE,
|
||||||
|
# AVA2_IOS_BUILD_TYPE (default RelWithDebInfo).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
ROOT="$(cd "$HERE/.." && pwd)"
|
||||||
|
SOURCE_DIR="${AVA2_SOURCE_DIR:-$ROOT}"
|
||||||
|
|
||||||
|
SDL_VERSION=3.4.16
|
||||||
|
FREETYPE_VERSION=2.13.3
|
||||||
|
DEPLOYMENT_TARGET=15.0
|
||||||
|
|
||||||
|
MODE=simulator RUN=1 DEPS_ONLY=0
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
sim|simulator) MODE=simulator ;;
|
||||||
|
device) MODE=device ;;
|
||||||
|
deps) DEPS_ONLY=1 ;;
|
||||||
|
--no-run) RUN=0 ;;
|
||||||
|
*) echo "unknown argument: $arg"; exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
if [[ "$MODE" == simulator ]]; then SDK=iphonesimulator; else SDK=iphoneos; fi
|
||||||
|
xcrun --sdk "$SDK" --show-sdk-path >/dev/null 2>&1 || { echo "Xcode $SDK SDK not found (xcode-select)"; exit 1; }
|
||||||
|
|
||||||
|
DEPS="$ROOT/build/ios-deps"
|
||||||
|
PREFIX="$DEPS/prefix-$SDK"
|
||||||
|
mkdir -p "$DEPS/src"
|
||||||
|
IOS_CMAKE=(-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT="$SDK" -DCMAKE_OSX_ARCHITECTURES=arm64
|
||||||
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=$DEPLOYMENT_TARGET)
|
||||||
|
|
||||||
|
fetch() { # url file
|
||||||
|
[[ -f "$DEPS/src/$2" ]] && return
|
||||||
|
if [[ -f "$ROOT/build/android-deps/src/$2" ]]; then cp "$ROOT/build/android-deps/src/$2" "$DEPS/src/$2"; return; fi
|
||||||
|
curl -fL --retry 3 -o "$DEPS/src/$2.part" "$1" || { echo "download failed: $1"; exit 1; }
|
||||||
|
mv -f "$DEPS/src/$2.part" "$DEPS/src/$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmake_dep() { # source-dir build-dir extra-args...
|
||||||
|
local src="$1" bld="$2"; shift 2
|
||||||
|
cmake -S "$src" -B "$bld" "${IOS_CMAKE[@]}" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$PREFIX" "$@"
|
||||||
|
cmake --build "$bld" -j"$(sysctl -n hw.ncpu)"
|
||||||
|
cmake --install "$bld"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ ! -f "$PREFIX/lib/libSDL3.a" ]]; then
|
||||||
|
fetch "https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL3-$SDL_VERSION.tar.gz" "SDL3-$SDL_VERSION.tar.gz"
|
||||||
|
rm -rf "$DEPS/src/SDL3-$SDL_VERSION-$SDK" && mkdir "$DEPS/src/SDL3-$SDL_VERSION-$SDK"
|
||||||
|
tar -xzf "$DEPS/src/SDL3-$SDL_VERSION.tar.gz" -C "$DEPS/src/SDL3-$SDL_VERSION-$SDK" --strip-components 1
|
||||||
|
if [[ "$SDK" == iphonesimulator ]]; then
|
||||||
|
# The simulator's Metal device does not report MTLGPUFamilyApple3, so SDL_GPU refuses it
|
||||||
|
# although the host GPU runs the client fine. Skip the check there; device builds are untouched.
|
||||||
|
perl -0pi -e 's/(hasHardwareSupport = \[device supportsFamily:MTLGPUFamilyApple3\])/$1 || TARGET_OS_SIMULATOR/' \
|
||||||
|
"$DEPS/src/SDL3-$SDL_VERSION-$SDK/src/gpu/metal/SDL_gpu_metal.m"
|
||||||
|
grep -q "MTLGPUFamilyApple3\] || TARGET_OS_SIMULATOR" \
|
||||||
|
"$DEPS/src/SDL3-$SDL_VERSION-$SDK/src/gpu/metal/SDL_gpu_metal.m" || { echo "SDL simulator patch failed"; exit 1; }
|
||||||
|
fi
|
||||||
|
cmake_dep "$DEPS/src/SDL3-$SDL_VERSION-$SDK" "$DEPS/build-sdl3-$SDK" \
|
||||||
|
-DSDL_SHARED=OFF -DSDL_STATIC=ON -DSDL_TEST_LIBRARY=OFF -DSDL_TESTS=OFF -DSDL_EXAMPLES=OFF
|
||||||
|
fi
|
||||||
|
if [[ ! -f "$PREFIX/lib/libfreetype.a" ]]; then
|
||||||
|
fetch "https://download.savannah.gnu.org/releases/freetype/freetype-$FREETYPE_VERSION.tar.xz" "freetype-$FREETYPE_VERSION.tar.xz"
|
||||||
|
rm -rf "$DEPS/src/freetype-$FREETYPE_VERSION" && tar -xJf "$DEPS/src/freetype-$FREETYPE_VERSION.tar.xz" -C "$DEPS/src"
|
||||||
|
cmake_dep "$DEPS/src/freetype-$FREETYPE_VERSION" "$DEPS/build-freetype-$SDK" -DBUILD_SHARED_LIBS=OFF \
|
||||||
|
-DFT_DISABLE_ZLIB=ON -DFT_DISABLE_BZIP2=ON -DFT_DISABLE_PNG=ON -DFT_DISABLE_HARFBUZZ=ON -DFT_DISABLE_BROTLI=ON
|
||||||
|
fi
|
||||||
|
[[ "$DEPS_ONLY" == 1 ]] && exit 0
|
||||||
|
|
||||||
|
BUILD="$ROOT/build/ios-$SDK"
|
||||||
|
CONFIG_ARGS=("${IOS_CMAKE[@]}" -DCMAKE_BUILD_TYPE="${AVA2_IOS_BUILD_TYPE:-RelWithDebInfo}"
|
||||||
|
-DAVA2_BUILD_HOST=ON -DAVA2_EMBED_PYTHON=ON -DBUILD_TESTING=OFF
|
||||||
|
-DSDL3_DIR="$PREFIX/lib/cmake/SDL3" -DCMAKE_PREFIX_PATH="$PREFIX"
|
||||||
|
-DAVA2_IOS_BUNDLE_ID="${AVA2_IOS_BUNDLE_ID:-com.metin2.ava2}")
|
||||||
|
[[ -n "${AVA2_SDK_ROOT:-}" ]] && CONFIG_ARGS+=(-DAVA2_SDK_ROOT="$AVA2_SDK_ROOT")
|
||||||
|
cmake -S "$SOURCE_DIR" -B "$BUILD" "${CONFIG_ARGS[@]}"
|
||||||
|
cmake --build "$BUILD" --target ava2_client mtpython_stdlib -j"$(sysctl -n hw.ncpu)"
|
||||||
|
APP="$BUILD/ava2_client.app"
|
||||||
|
BUNDLE_ID="${AVA2_IOS_BUNDLE_ID:-com.metin2.ava2}"
|
||||||
|
|
||||||
|
if [[ "$MODE" == simulator ]]; then
|
||||||
|
codesign --force --sign - --timestamp=none "$APP"
|
||||||
|
else
|
||||||
|
[[ -n "${AVA2_IOS_SIGN_IDENTITY:-}" && -f "${AVA2_IOS_PROFILE:-}" ]] || {
|
||||||
|
echo "Device builds need AVA2_IOS_SIGN_IDENTITY (security find-identity -v -p codesigning) and"
|
||||||
|
echo "AVA2_IOS_PROFILE (a development .mobileprovision for $BUNDLE_ID)."; exit 1; }
|
||||||
|
cp "$AVA2_IOS_PROFILE" "$APP/embedded.mobileprovision"
|
||||||
|
ENTITLEMENTS="$BUILD/entitlements.plist"
|
||||||
|
security cms -D -i "$AVA2_IOS_PROFILE" > "$BUILD/profile.plist"
|
||||||
|
/usr/libexec/PlistBuddy -x -c "Print :Entitlements" "$BUILD/profile.plist" > "$ENTITLEMENTS"
|
||||||
|
codesign --force --sign "$AVA2_IOS_SIGN_IDENTITY" --entitlements "$ENTITLEMENTS" --timestamp=none "$APP"
|
||||||
|
fi
|
||||||
|
du -sh "$APP"
|
||||||
|
[[ "$RUN" == 1 ]] || exit 0
|
||||||
|
|
||||||
|
if [[ "$MODE" == simulator ]]; then
|
||||||
|
SIM="${AVA2_IOS_SIMULATOR:-}"
|
||||||
|
if [[ -z "$SIM" ]]; then
|
||||||
|
SIM="$(xcrun simctl list devices booted | sed -nE 's/.*\(([0-9A-F-]{36})\) \(Booted\).*/\1/p' | head -1)"
|
||||||
|
fi
|
||||||
|
if [[ -z "$SIM" ]]; then
|
||||||
|
SIM="$(xcrun simctl list devices available | grep -E '^ +iPhone' | tail -1 | sed -nE 's/.*\(([0-9A-F-]{36})\).*/\1/p')"
|
||||||
|
fi
|
||||||
|
[[ -n "$SIM" ]] || { echo "No iOS simulator available (Xcode > Settings > Platforms)"; exit 1; }
|
||||||
|
xcrun simctl boot "$SIM" 2>/dev/null || true
|
||||||
|
open -a Simulator --args -CurrentDeviceUDID "$SIM" || true
|
||||||
|
xcrun simctl bootstatus "$SIM" -b >/dev/null
|
||||||
|
xcrun simctl install "$SIM" "$APP"
|
||||||
|
xcrun simctl launch "$SIM" "$BUNDLE_ID"
|
||||||
|
echo "Launched on simulator $SIM. Logs: xcrun simctl spawn $SIM log stream --predicate 'process == \"ava2_client\"'"
|
||||||
|
else
|
||||||
|
DEVICE="${AVA2_IOS_DEVICE:-}"
|
||||||
|
if [[ -z "$DEVICE" ]]; then
|
||||||
|
DEVICE="$(xcrun devicectl list devices 2>/dev/null | awk '/available|connected/ && /iPhone|iPad/ {print $3; exit}')"
|
||||||
|
fi
|
||||||
|
if [[ -z "$DEVICE" ]]; then echo "No device attached; app not installed."; exit 0; fi
|
||||||
|
xcrun devicectl device install app --device "$DEVICE" "$APP"
|
||||||
|
xcrun devicectl device process launch --device "$DEVICE" "$BUNDLE_ID"
|
||||||
|
fi
|
||||||
Executable
+89
@@ -0,0 +1,89 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Copy the client root into the iOS app's Documents directory (development builds).
|
||||||
|
|
||||||
|
The .app holds code only; on iOS the client runs in its Documents directory and reads the same
|
||||||
|
flattened client root as Android (test-rundir + assets/loose + upstream/python-root + python27.zip).
|
||||||
|
The tree is staged by android/push_assets.py --stage-only --lowercase into build/ios-data/root (all
|
||||||
|
names ASCII lower-case: iOS file systems are case-sensitive and the client opens lower-cased
|
||||||
|
paths), then:
|
||||||
|
|
||||||
|
simulator copied into `xcrun simctl get_app_container <udid> <bundle> data`/Documents as APFS
|
||||||
|
clones (cp -c: no extra disk space, and the app cannot write through to the checkout)
|
||||||
|
device sent with `xcrun devicectl device copy to` into the app data container
|
||||||
|
|
||||||
|
Install the app first (ios/build.sh), since the container only exists after install.
|
||||||
|
|
||||||
|
usage: ios/push_assets.py [device] [--simulator UDID] [--device ID] [--stdlib ZIP] [--pack-maker DIR]
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
BUNDLE_ID = os.environ.get("AVA2_IOS_BUNDLE_ID", "com.metin2.ava2")
|
||||||
|
|
||||||
|
|
||||||
|
def booted_simulator():
|
||||||
|
out = subprocess.run(["xcrun", "simctl", "list", "devices", "booted"], check=True,
|
||||||
|
capture_output=True, text=True).stdout
|
||||||
|
match = re.search(r"\(([0-9A-F-]{36})\) \(Booted\)", out)
|
||||||
|
return match.group(1) if match else None
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||||
|
parser.add_argument("target", nargs="?", choices=["sim", "simulator", "device"], default="simulator")
|
||||||
|
parser.add_argument("--simulator", default=os.environ.get("AVA2_IOS_SIMULATOR"), help="UDID (default: booted)")
|
||||||
|
parser.add_argument("--device", default=os.environ.get("AVA2_IOS_DEVICE"), help="devicectl device id")
|
||||||
|
parser.add_argument("--stdlib", help="python27.zip (default: the matching ios/build.sh output)")
|
||||||
|
parser.add_argument("--pack-maker", help="passed to android/push_assets.py")
|
||||||
|
parser.add_argument("--stage", type=Path, default=ROOT / "build/ios-data/root")
|
||||||
|
args = parser.parse_args()
|
||||||
|
device = args.target == "device"
|
||||||
|
|
||||||
|
stdlib = args.stdlib or ROOT / f"build/ios-{'iphoneos' if device else 'iphonesimulator'}/python27.zip"
|
||||||
|
if not Path(stdlib).is_file():
|
||||||
|
sys.exit(f"{stdlib} not found; run ios/build.sh first or pass --stdlib")
|
||||||
|
# iOS file systems are case-sensitive while the client lower-cases the paths it opens
|
||||||
|
# (ResourceManager::NormalizePath) and the data mixes cases, so stage every name lower-case.
|
||||||
|
stage_cmd = [sys.executable, str(ROOT / "android/push_assets.py"), "--stage-only", "--lowercase",
|
||||||
|
"--stage", str(args.stage), "--stdlib", str(stdlib)]
|
||||||
|
if args.pack_maker:
|
||||||
|
stage_cmd += ["--pack-maker", args.pack_maker]
|
||||||
|
subprocess.run(stage_cmd, check=True)
|
||||||
|
|
||||||
|
if not device:
|
||||||
|
udid = args.simulator or booted_simulator()
|
||||||
|
if not udid:
|
||||||
|
sys.exit("no booted simulator; run ios/build.sh or pass --simulator")
|
||||||
|
container = subprocess.run(["xcrun", "simctl", "get_app_container", udid, BUNDLE_ID, "data"],
|
||||||
|
check=True, capture_output=True, text=True).stdout.strip()
|
||||||
|
docs = Path(container) / "Documents"
|
||||||
|
docs.mkdir(parents=True, exist_ok=True)
|
||||||
|
# Trailing "/." copies the directory's contents; -c clones, plain copy across volumes.
|
||||||
|
if subprocess.run(["cp", "-Rc", f"{args.stage}/.", str(docs)]).returncode != 0:
|
||||||
|
subprocess.run(["cp", "-R", f"{args.stage}/.", str(docs)], check=True)
|
||||||
|
print(f"copied to {docs}")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not args.device:
|
||||||
|
out = subprocess.run(["xcrun", "devicectl", "list", "devices"], check=True,
|
||||||
|
capture_output=True, text=True).stdout
|
||||||
|
ids = [line.split()[2] for line in out.splitlines()
|
||||||
|
if re.search(r"available|connected", line) and re.search(r"iPhone|iPad", line)]
|
||||||
|
if not ids:
|
||||||
|
sys.exit("no device attached")
|
||||||
|
args.device = ids[0]
|
||||||
|
subprocess.run(["xcrun", "devicectl", "device", "copy", "to", "--device", args.device,
|
||||||
|
"--domain-type", "appDataContainer", "--domain-identifier", BUNDLE_ID,
|
||||||
|
"--source", str(args.stage), "--destination", "Documents"], check=True)
|
||||||
|
print(f"copied to {args.device}:{BUNDLE_ID}/Documents")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -294,10 +294,15 @@ ava2::app::AppLoop::Frame RunClient(ava2::app::AppLoop* loop, int argc, char** a
|
|||||||
// A flattened client root (scripts beside the assets), e.g. the Android data directory.
|
// A flattened client root (scripts beside the assets), e.g. the Android data directory.
|
||||||
else if (std::filesystem::exists("game.py") && std::filesystem::exists("uiscript")) script_root = ".";
|
else if (std::filesystem::exists("game.py") && std::filesystem::exists("uiscript")) script_root = ".";
|
||||||
}
|
}
|
||||||
#ifdef __ANDROID__
|
#if defined(__ANDROID__) || defined(SDL_PLATFORM_IOS)
|
||||||
if (stdlib.empty() || script_root.empty()) {
|
if (stdlib.empty() || script_root.empty()) {
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
const char* push = "android/push_assets.py";
|
||||||
|
#else
|
||||||
|
const char* push = "ios/push_assets.py";
|
||||||
|
#endif
|
||||||
const std::string message = "Game data not found in " + std::filesystem::current_path().string()
|
const std::string message = "Game data not found in " + std::filesystem::current_path().string()
|
||||||
+ ".\nPush it with android/push_assets.py.";
|
+ ".\nPush it with " + push + ".";
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "AVA2", message.c_str(), nullptr);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "AVA2", message.c_str(), nullptr);
|
||||||
throw std::runtime_error(message);
|
throw std::runtime_error(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,18 @@
|
|||||||
namespace ava2::platform {
|
namespace ava2::platform {
|
||||||
|
|
||||||
bool EnterClientDataDirectory(std::string* error) {
|
bool EnterClientDataDirectory(std::string* error) {
|
||||||
#if defined(__APPLE__)
|
#if defined(SDL_PLATFORM_IOS)
|
||||||
|
// Like the APK, the .app holds code only. The flattened client root (ios/push_assets.py, or
|
||||||
|
// copied in with Finder / the Files app — Info.plist enables file sharing) lives in Documents.
|
||||||
|
const char* data = SDL_GetUserFolder(SDL_FOLDER_DOCUMENTS);
|
||||||
|
std::error_code ec;
|
||||||
|
if (data) std::filesystem::current_path(data, ec);
|
||||||
|
if (!data || ec) {
|
||||||
|
if (error) *error = std::string("Cannot enter client data directory: ") + (data ? ec.message() : SDL_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SDL_Log("Client data: %s", data);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
// Keep legacy Python's relative config/chat writes outside the signed application.
|
// Keep legacy Python's relative config/chat writes outside the signed application.
|
||||||
try {
|
try {
|
||||||
std::filesystem::path base = std::filesystem::path(SDL_GetBasePath()).lexically_normal();
|
std::filesystem::path base = std::filesystem::path(SDL_GetBasePath()).lexically_normal();
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ namespace ava2::platform {
|
|||||||
|
|
||||||
// Enters the client root the legacy code reads relative paths from: on macOS the per-user data
|
// Enters the client root the legacy code reads relative paths from: on macOS the per-user data
|
||||||
// directory that links the bundle Resources (config/chat writes stay outside the signed app); on
|
// directory that links the bundle Resources (config/chat writes stay outside the signed app); on
|
||||||
// Android the app's external files directory (android/push_assets.py). Elsewhere a no-op.
|
// Android the app's external files directory (android/push_assets.py); on iOS the app's Documents
|
||||||
|
// folder (ios/push_assets.py). Elsewhere a no-op.
|
||||||
// False with *error set when the directory cannot be entered.
|
// False with *error set when the directory cannot be entered.
|
||||||
bool EnterClientDataDirectory(std::string* error);
|
bool EnterClientDataDirectory(std::string* error);
|
||||||
|
|
||||||
|
|||||||
@@ -34,9 +34,13 @@ float InterpolateTimeEvent(const std::vector<TimeEvent>& events, float time, flo
|
|||||||
EffectData::EffectData() = default;
|
EffectData::EffectData() = default;
|
||||||
EffectData::~EffectData() = default;
|
EffectData::~EffectData() = default;
|
||||||
|
|
||||||
|
// Slashes forward and A-Z lower-cased, like ResourceManager::NormalizePath: the client root is
|
||||||
|
// staged lower-case on case-sensitive file systems (iOS), and scripts spell names in mixed case
|
||||||
|
// (d:/ymir work/effect/etc/empire/empire_A.mse).
|
||||||
static std::string NormalizePath(std::string path) {
|
static std::string NormalizePath(std::string path) {
|
||||||
for (char& c : path) {
|
for (char& c : path) {
|
||||||
if (c == '\\') c = '/';
|
if (c == '\\') c = '/';
|
||||||
|
else if (c >= 'A' && c <= 'Z') c = static_cast<char>(c - 'A' + 'a');
|
||||||
}
|
}
|
||||||
if (path.size() >= 3 && (path[0] == 'd' || path[0] == 'D') && path[1] == ':' && path[2] == '/') {
|
if (path.size() >= 3 && (path[0] == 'd' || path[0] == 'D') && path[1] == ':' && path[2] == '/') {
|
||||||
path = path.substr(3);
|
path = path.substr(3);
|
||||||
|
|||||||
Reference in New Issue
Block a user