Split the frame loop out of main.cpp (app_loop) for SDL main callbacks

main.cpp moves to app_loop.cpp; its body becomes RunClient, a C++20
coroutine suspended at the top of each frame, driven by ava2::app::AppLoop
(Start/Iterate/QueueEvent/Finish/Run). The new main.cpp uses SDL main
callbacks (AVA2_MAIN_CALLBACKS, default on except Android) or the classic
loop. Screenshots are byte-identical through both drivers; 54/54 tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 22:28:50 +09:00
co-authored by Claude Opus 5.5
parent 64d25e3571
commit f973b24abc
6 changed files with 2851 additions and 2614 deletions
+1 -1
View File
@@ -75,7 +75,7 @@
```
最终都调用原版已有的移动和攻击接口,游戏逻辑不感知输入设备差异。多指同时操作(摇杆 + 攻击 + 镜头)由此支持。
- `app_loop` 从 `main.cpp` 抽出,便于 iOS 改用 SDL 回调式主循环;可在做 iOS 时再拆。
- `app_loop` 从 `main.cpp` 抽出,便于 iOS 改用 SDL 回调式主循环;可在做 iOS 时再拆。(已完成:`src/app/app_loop.{h,cpp}`,主体为每帧挂起一次的协程;`main.cpp` 只选择 SDL 回调或经典循环。)
### Python 界面层
+25
View File
@@ -1378,3 +1378,28 @@ pick-up refusals, attack speed); straight-line walking only, the stuck
watchdog is the only obstacle handling; party loot rules ignored (only own /
unowned drops); no desktop hotkey (F9 is taken by the preview mode);
English labels, no locale strings; does not run in `--preview-data`.
### 2026-10-12 Mobile step 7a — app_loop split
- `src/app/main.cpp` moved to `src/app/app_loop.cpp` (history kept). The
former `main()` body is now `RunClient`, a C++20 coroutine that suspends
at the top of every frame (`co_yield`), so start-up, frame body and
teardown stay one function with all their locals in the coroutine frame.
`ava2::app::AppLoop` (`app_loop.h`) drives it: `Start` (start-up up to the
first frame), `Iterate` (one frame), `QueueEvent`, `Finish` (lets a running
client leave the loop and tear down), `Run` (classic loop).
- The new `src/app/main.cpp` only picks the driver: SDL main callbacks
(`AVA2_MAIN_CALLBACKS`, default ON except Android; iOS requires it because
UIKit owns the main thread) or a classic `main` loop (Android for now).
With callbacks, SDL_AppEvent queues events and the frame's event pass reads
the queue instead of `SDL_PollEvent`.
- iOS: no software FPS cap by default (SDL_AppIterate follows the display).
Verified: 54/54 desktop tests; `ava2_client --phone 2400x1080@2.75
--safe-insets 50,0,0,24 --phase game --preview-data --frames 150
--screenshot` gives a byte-identical BMP with the callbacks and with the
classic loop (`-DAVA2_MAIN_CALLBACKS=OFF`) compared to before the split;
bad arguments still exit 1.
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
classes).