Add platform layer: lifecycle, data dirs, safe area (mobile step 2)
Move the macOS/Android data and config directory code out of main.cpp into src/app/platform. Handle background/foreground: save config and interface status, pause audio, cancel touch input and skip rendering while keeping the network pumped. Map the window safe area through the letterboxed presentation into TouchLayout and expose touch.GetSafeArea() so the mobile HUD stays clear of notches and gesture bars. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
260d421bde
commit
b79fbce0b0
@@ -7,7 +7,7 @@
|
||||
- `android/build.sh` 可以编出 arm64 调试 APK(SDL3 + FreeType 自动编译,16 KB 页对齐),连接手机时自动安装启动;真机运行尚未验证。
|
||||
- `android/push_assets.py` 把资源(`assets/loose` + python-root + `python27.zip`)推送到应用外部存储目录,客户端启动时切换到该目录。
|
||||
- 游戏资源为 2.8 GB、约 5 万个散文件(`assets/loose`),17 个源文件中 120 多处通过 `std::filesystem` / `ifstream` 直接读文件,无法读取 APK 内置资源。
|
||||
- 没有处理前后台切换(`SDL_EVENT_WILL_ENTER_BACKGROUND` / `DID_ENTER_FOREGROUND`)和低内存事件。
|
||||
- 平台层已实现(`src/app/platform/`):资源根目录与配置目录;前后台切换(进后台时保存配置、暂停声音、取消输入、停止渲染,网络照常收发;Android 设 `SDL_ANDROID_BLOCK_ON_PAUSE=0`);安全区域按逻辑分辨率换算后放进触摸布局,HUD 用 `touch.GetSafeArea()` 内缩。低内存事件目前只记日志;HUD 只在创建时读安全区;均未真机验证。
|
||||
- 触摸分流已实现(`src/app/input/touch_router.*`,见下文 `input/`):移动端或 `--touch` / `AVA2_TOUCH=1` 时关闭 SDL 触摸转鼠标,每个手指分到界面、攻击键、左下浮动摇杆或镜头(单指拖动转向、双指缩放、轻点=点地移动)。Python 模块 `touch` 供 HUD 设置攻击键位置并读取摇杆状态;`ui_mobile_joystick` / `ui_mobile_combat` 改为只做显示(`not_pick`)。多指同时操作尚未在真机验证。
|
||||
- 出招已接通(PORT-PLAN「Mobile step 3b」):触摸攻击键和键盘共用 `ProcessPlayerAttack`,按原版连招时序出招,发送 FUNC_COMBO 移动包,命中检测后发 `CG_ATTACK`;尚未在真服验证,弓箭飞行、技能、PvP 规则等仍缺。
|
||||
- 原型 HUD 用到的 `taskbar/attack_button_0x.sub`、`quickslot_0x.sub` 不在资源包里:攻击键暂用色块,技能圈槽位不可见。
|
||||
|
||||
@@ -1222,3 +1222,36 @@ skills are not wired; PvP `IsAttackableInstance` rules and the `__CanAttack`
|
||||
checks (emotion, private shop, observer, new mount) are missing; remote
|
||||
FUNC_ATTACK / FUNC_COMBO snap to the packet position instead of walking there
|
||||
when 50+ away.
|
||||
|
||||
### 2026-10-12 Mobile step 2 — platform layer
|
||||
|
||||
`src/app/platform/` (`ava2_platform`) takes the per-platform code out of
|
||||
`main.cpp`:
|
||||
|
||||
- `EnterClientDataDirectory` (macOS per-user data dir linking the bundle
|
||||
Resources; Android external files dir) and `ConfigDirectory` (Android
|
||||
internal storage for metin2.cfg / interface.cfg) — moved unchanged.
|
||||
- `Lifecycle`: an SDL event watch records background / foreground / low
|
||||
memory / terminating; the main loop applies them. Entering the background
|
||||
cancels movement and touch fingers, saves the config and interface status,
|
||||
and pauses the audio device (`SoundManager::SetPaused`); while in the
|
||||
background the loop skips game update and rendering but keeps receiving and
|
||||
dispatching network packets. Foreground resets the frame clock. Android
|
||||
runs with `SDL_ANDROID_BLOCK_ON_PAUSE=0` (SDL then waits up to 100 ms per
|
||||
poll while paused); SDL's Vulkan backend recreates the surface on resume.
|
||||
- Safe area: `SDL_GetWindowSafeArea` mapped through the letterboxed logical
|
||||
presentation (`MapSafeInsets`) into `TouchLayout` (`safe_*`;
|
||||
`ForScreen` keeps the joystick area and attack button inside) and
|
||||
re-queried on `SDL_EVENT_WINDOW_SAFE_AREA_CHANGED` / resize. Python
|
||||
`touch.GetSafeArea()`; the mobile HUD prototype insets the player panel,
|
||||
target bar, drawer, quick belt and combat wheel.
|
||||
|
||||
Verified: `ava2.platform` (lifecycle transitions incl. pause+resume between
|
||||
frames, inset mapping with letterbox bars and scaling, safe touch layout),
|
||||
`ava2.touch_game` (desktop insets 0; a HUD built with insets puts the attack
|
||||
button inside them), 53/53 desktop tests, `ava2_client --touch` starts,
|
||||
Android APK builds.
|
||||
Outstanding: no device run (background/resume, surface recreation, audio
|
||||
resume, server keepalive while paused); low memory only logs (no cache purge);
|
||||
the HUD reads the insets only when it is built; iOS lifecycle needs the event
|
||||
watch to do the save work synchronously.
|
||||
|
||||
Reference in New Issue
Block a user