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
+12
View File
@@ -118,6 +118,18 @@ int main(int argc, char** argv) {
router.FingerUp(4, W * 0.6f, H * 0.4f, 450);
assert(sink.taps == 1);
// Safe area (platform/): desktop has none; a HUD built with insets keeps the attack button inside.
runtime.execute("assert touch.GetSafeArea() == (0, 0, 0, 0)\n");
router.SetLayout(ava2::input::TouchLayout::ForScreen(W, H, 40.0f, 0.0f, 30.0f, 20.0f));
runtime.execute("assert touch.GetSafeArea() == (40, 0, 30, 20)\n"
"import ui_mobile_hud\n"
"safe_hud = ui_mobile_hud.MobileHUD(game.interface)\n"
"(ax, ay, ar), joy = touch.GetLayout()\n"
"assert (ax, ay, ar) == (1024 - 30 - 120, 768 - 20 - 120, 60), (ax, ay, ar)\n"
"assert safe_hud.player_hud.GetGlobalPosition()[0] == 40 + 25\n"
"safe_hud.Hide()\nsafe_hud = None\n");
router.SetLayout(layout);
SDL_FillSurfaceRect(surface, nullptr, 0xff10141e);
wm->Render(); SDL_RenderPresent(renderer);
if (argc > 3) SDL_SaveBMP(surface, argv[3]);