android: AAssetManager bootstrap + APK asset bundling + scissor TODO

platform/android.sx: `sx_android_bootstrap(app)` now also reads the
ANativeActivity's `assetManager` (offset 64) and `internalDataPath`
(offset 32) into module globals so consumers can route file I/O
through the APK's bundled `assets/` tree.

target.zig (`createApk`): also zips the project's `./assets/`
directory into the APK alongside `lib/<arch>/`. Resolves relative
to the user's CWD at invoke time — matches the convention chess
uses (assets/ next to main.sx).

gles3.sx: scissor is currently a no-op on Android. The renderer's
ScrollView clip_push path feeds bounds that land outside the
framebuffer (clipping everything off-screen). With scissor disabled
the chess board + pieces render correctly. TODO recorded in the
file to fix the bounds path properly.
This commit is contained in:
agra
2026-05-19 10:09:30 +03:00
parent 5c41e9c180
commit b5bf789b7b
3 changed files with 66 additions and 25 deletions

View File

@@ -85,14 +85,45 @@ TimeSpec :: struct { sec: s64; nsec: s64; }
g_android_app : *void = null;
g_android_plat : *AndroidPlatform = null;
// `app->activity` (ANativeActivity*) at byte 24.
// `activity->assetManager` at byte 64 inside ANativeActivity.
APP_OFF_activity :s64: 24;
ACTIVITY_OFF_assetManager :s64: 64;
ACTIVITY_OFF_internalData :s64: 32;
// AAssetManager handle the user's `android_main` stashes via the
// bootstrap. Consumers that want to read bundled APK assets (font.ttf,
// piece sprites, level data, ...) read this and feed it into their own
// file-IO shim — e.g. chess wires it through `vendors/file_utils.c`
// which routes `read_file_bytes` through AAssetManager_open on Android.
g_android_asset_manager : *void = null;
g_android_internal_path : *u8 = null;
// ── Bootstrap (called by user's `android_main`) ────────────────────────
// Stashes the NDK app pointer the OS handed to `android_main(app)` so
// the rest of the platform module can find it. Single responsibility —
// the user's `android_main` calls this once, then calls their own
// `main()` to enter the normal cross-platform setup flow.
//
// Also extracts `AAssetManager*` and `internalDataPath` from the
// ANativeActivity that the app pointer carries — these are the two
// pieces consumers need to touch APK assets / per-app storage on
// Android. Reachable as `g_android_asset_manager` / `g_android_internal_path`.
sx_android_bootstrap :: (app: *void) {
g_android_app = app;
inline if OS == .android {
g_android_app = app;
base : s64 = xx app;
activity_pp : **void = xx (base + APP_OFF_activity);
activity_ptr := activity_pp.*;
if activity_ptr != null {
act_base : s64 = xx activity_ptr;
mgr_pp : **void = xx (act_base + ACTIVITY_OFF_assetManager);
g_android_asset_manager = mgr_pp.*;
path_pp : **u8 = xx (act_base + ACTIVITY_OFF_internalData);
g_android_internal_path = path_pp.*;
}
}
}
// ── Helpers ────────────────────────────────────────────────────────────