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:
shenlei
2026-10-12 20:45:07 +09:00
co-authored by Claude Opus 5.5
parent 260d421bde
commit b79fbce0b0
16 changed files with 475 additions and 73 deletions
+33
View File
@@ -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.