diff --git a/CHANGELOG.md b/CHANGELOG.md index ea4f999..d3a0ead 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,11 +14,16 @@ Alle nennenswerten Änderungen an diesem Projekt. Format nach ### Fixed - (app) HUD blieb auf dem Initialwert (100 HP), weil `onLoad` waehrend des ersten Builds publizierte +- (app) Top-Level-`Stopwatch` startete erst beim ersten Zugriff (Dart initialisiert Top-Level-Finals lazy) - das Bootlog zeigte 0 ms ### Changed - (build) Version 0.7.0 (7); signiertes App Bundle mit Upload-Keystore ### Added +- (app) Splash-Kette ohne weissen Bildschirm: Markenfarbe `#05070A` als Launch- und Normal-Theme, + Android-12-Splash-API (`values-v31`), pulsierendes Logo inkl. Fortschrittslinie bis die native + Bibliothek, die Session und das Ad-SDK bereit sind, danach Fade in die Partie +- (app) Startlog `iron_arc: ready after N ms` (Debug + Release), nutzbar als Regressionswaechter - (legal) Datenschutzerklaerung DE/EN als Markdown und als hostbare HTML-Seite - (app) Geraete-ID im Einstellungen-Sheet sichtbar und kopierbar (fuer Loeschantraege) - (ads) UMP-Consent-Flow vor SDK-Init, Fail-Safe ohne Zustimmung, Einstellungen-Sheet mit „Datenschutz-Optionen“ diff --git a/app/android/app/src/main/res/drawable-v21/launch_background.xml b/app/android/app/src/main/res/drawable-v21/launch_background.xml index f74085f..517db01 100644 --- a/app/android/app/src/main/res/drawable-v21/launch_background.xml +++ b/app/android/app/src/main/res/drawable-v21/launch_background.xml @@ -1,12 +1,10 @@ - + - - - - + android:src="@drawable/launch_logo" /> + diff --git a/app/android/app/src/main/res/drawable-xxxhdpi/launch_logo.png b/app/android/app/src/main/res/drawable-xxxhdpi/launch_logo.png new file mode 100644 index 0000000..540034c Binary files /dev/null and b/app/android/app/src/main/res/drawable-xxxhdpi/launch_logo.png differ diff --git a/app/android/app/src/main/res/drawable-xxxhdpi/launch_logo_splash.png b/app/android/app/src/main/res/drawable-xxxhdpi/launch_logo_splash.png new file mode 100644 index 0000000..88546ea Binary files /dev/null and b/app/android/app/src/main/res/drawable-xxxhdpi/launch_logo_splash.png differ diff --git a/app/android/app/src/main/res/drawable/launch_background.xml b/app/android/app/src/main/res/drawable/launch_background.xml index 304732f..1dc9d9b 100644 --- a/app/android/app/src/main/res/drawable/launch_background.xml +++ b/app/android/app/src/main/res/drawable/launch_background.xml @@ -1,12 +1,12 @@ - + - - - - + android:src="@drawable/launch_logo" /> + diff --git a/app/android/app/src/main/res/values-night/styles.xml b/app/android/app/src/main/res/values-night/styles.xml index 06952be..183030c 100644 --- a/app/android/app/src/main/res/values-night/styles.xml +++ b/app/android/app/src/main/res/values-night/styles.xml @@ -2,9 +2,9 @@ diff --git a/app/android/app/src/main/res/values-v31/styles.xml b/app/android/app/src/main/res/values-v31/styles.xml new file mode 100644 index 0000000..dd7293e --- /dev/null +++ b/app/android/app/src/main/res/values-v31/styles.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/app/android/app/src/main/res/values/colors.xml b/app/android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..340af42 --- /dev/null +++ b/app/android/app/src/main/res/values/colors.xml @@ -0,0 +1,8 @@ + + + + #FF05070A + + #FF0B1220 + diff --git a/app/android/app/src/main/res/values/styles.xml b/app/android/app/src/main/res/values/styles.xml index cb1ef88..72cc4e2 100644 --- a/app/android/app/src/main/res/values/styles.xml +++ b/app/android/app/src/main/res/values/styles.xml @@ -1,10 +1,12 @@ - - - diff --git a/app/assets/logo_mark.png b/app/assets/logo_mark.png new file mode 100644 index 0000000..540034c Binary files /dev/null and b/app/assets/logo_mark.png differ diff --git a/app/lib/main.dart b/app/lib/main.dart index 6fcacc5..9412752 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -10,9 +10,18 @@ import 'src/native/native_match.dart'; import 'src/net/api_client.dart'; import 'src/net/match_session.dart'; import 'src/net/offline_queue.dart'; +import 'src/ui/splash_screen.dart'; import 'src/ui/widgets.dart'; -void main() => runApp(const IronArcApp()); +/// Started in `main()`, so the boot log line covers the whole cold start +/// (engine, Dart isolate and native match load). Must be initialised eagerly - +/// a top-level `final` would only start on first access. +final Stopwatch _bootWatch = Stopwatch(); + +void main() { + _bootWatch.start(); + runApp(const IronArcApp()); +} class IronArcApp extends StatelessWidget { const IronArcApp({super.key}); @@ -39,18 +48,52 @@ class MatchScreen extends StatefulWidget { class _MatchScreenState extends State { static const _baseUrl = 'http://127.0.0.1:8080'; + /// Minimum time the splash stays up, so even a warm start shows the brand + /// instead of a single-frame flicker. + static const _minSplash = Duration(milliseconds: 700); + int _seed = 42; late final ApiClient _api = ApiClient(baseUrl: _baseUrl); late final OfflineQueue _queue = OfflineQueue(); late final AdsService _ads = AdsService(); late final MatchSession _session = MatchSession(client: _api, queue: _queue, deviceId: 'pending'); - late IronArcGame _game = _buildGame(); + + /// Null while booting. Constructing a game loads the native match library, + /// which must not block the first frame - that used to be the white screen. + IronArcGame? _game; + bool _splashGone = false; @override void initState() { super.initState(); - _initSession(); + // Boot after the first frame so the splash is painted before any blocking + // work (FFI library load, shared preferences, ad SDK). + WidgetsBinding.instance.addPostFrameCallback((_) => _bootstrap()); + } + + /// Session, native match and ad SDK - all while the splash is on screen. + Future _bootstrap() async { + // Measured from the first Flutter frame, so the pulse is always visible + // even when the engine took seconds to start (debug builds, cold JIT). + final splashStart = Stopwatch()..start(); + + await _initSession(); + final game = _buildGame(); + if (!mounted) return; + + // Keep the brand moment on screen even when everything loads instantly. + final left = _minSplash - splashStart.elapsed; + if (left > Duration.zero) await Future.delayed(left); + if (!mounted) return; + + setState(() => _game = game); + // Fade out over the already-built match, then drop the splash from the tree. + await Future.delayed(const Duration(milliseconds: 320)); + if (!mounted) return; + setState(() => _splashGone = true); + + debugPrint('iron_arc: ready after ${_bootWatch.elapsedMilliseconds} ms'); _ads.initialize(); } @@ -109,7 +152,9 @@ class _MatchScreenState extends State { } void _playReplay() { - final json = _game.replayJson(); + final game = _game; + if (game == null) return; + final json = game.replayJson(); debugPrint('iron_arc: replay tapped, ${json.length} bytes'); if (json.isEmpty) { _toast('Kein Replay vorhanden'); @@ -208,70 +253,92 @@ class _MatchScreenState extends State { @override Widget build(BuildContext context) { + final game = _game; return Scaffold( - backgroundColor: const Color(0xFF05070A), - body: SafeArea( - child: Column( - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(12, 8, 12, 0), - child: Column( - children: [ - ValueListenableBuilder( - valueListenable: _game.hud, - builder: (context, hud, _) => Hud(hud: hud), - ), - const SizedBox(height: 6), - AnimatedBuilder( - animation: _session, - builder: (context, _) => - StatusBar(session: _session, onSettings: _openSettings), - ), - ], + backgroundColor: SplashScreen.background, + body: Stack( + children: [ + // The match only exists once the native library and session are up; + // until then the pulsing splash covers the whole window. + if (game != null) _buildMatch(game), + if (!_splashGone) + Positioned.fill( + child: AnimatedOpacity( + opacity: game == null ? 1 : 0, + duration: const Duration(milliseconds: 280), + curve: Curves.easeOut, + child: const SplashScreen(), ), ), - // Play area: gestures only affect the game, never the controls. - Expanded( - child: Stack( - children: [ - Positioned.fill(child: GameWidget(key: ValueKey(_game), game: _game)), - Positioned.fill( - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onPanStart: (d) => _game.beginAim(d.localPosition), - onPanUpdate: (d) => _game.updateAim(d.localPosition), - onPanEnd: (_) => _game.releaseAim(), - ), - ), - Positioned( - left: 16, - right: 16, - bottom: 8, - child: ValueListenableBuilder( - valueListenable: _game.hud, - builder: (context, hud, _) => hud.isFinished - ? GameOver(hud: hud, onRestart: _restart) - : HintBubble(hud: hud), - ), - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(12, 8, 12, 8), - child: AnimatedBuilder( - animation: _session, - builder: (context, _) => Controls( - session: _session, - onOnline: _startOnline, - onReplay: _playReplay, - onFlush: _flushQueue, - onAd: _showRewardedAd, + ], + ), + ); + } + + /// HUD, canvas and controls of a running match. + Widget _buildMatch(IronArcGame game) { + return SafeArea( + child: Column( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(12, 8, 12, 0), + child: Column( + children: [ + ValueListenableBuilder( + valueListenable: game.hud, + builder: (context, hud, _) => Hud(hud: hud), ), + const SizedBox(height: 6), + AnimatedBuilder( + animation: _session, + builder: (context, _) => + StatusBar(session: _session, onSettings: _openSettings), + ), + ], + ), + ), + // Play area: gestures only affect the game, never the controls. + Expanded( + child: Stack( + children: [ + Positioned.fill( + child: GameWidget(key: ValueKey(game), game: game)), + Positioned.fill( + child: GestureDetector( + behavior: HitTestBehavior.opaque, + onPanStart: (d) => game.beginAim(d.localPosition), + onPanUpdate: (d) => game.updateAim(d.localPosition), + onPanEnd: (_) => game.releaseAim(), + ), + ), + Positioned( + left: 16, + right: 16, + bottom: 8, + child: ValueListenableBuilder( + valueListenable: game.hud, + builder: (context, hud, _) => hud.isFinished + ? GameOver(hud: hud, onRestart: _restart) + : HintBubble(hud: hud), + ), + ), + ], + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(12, 8, 12, 8), + child: AnimatedBuilder( + animation: _session, + builder: (context, _) => Controls( + session: _session, + onOnline: _startOnline, + onReplay: _playReplay, + onFlush: _flushQueue, + onAd: _showRewardedAd, ), ), - ], - ), + ), + ], ), ); } diff --git a/app/lib/src/ui/splash_screen.dart b/app/lib/src/ui/splash_screen.dart new file mode 100644 index 0000000..db5b77c --- /dev/null +++ b/app/lib/src/ui/splash_screen.dart @@ -0,0 +1,75 @@ +import 'package:flutter/material.dart'; + +/// Brand splash shown while the native match library, the session and the +/// ad SDK boot. The logo pulses so a cold start reads as "loading" instead of +/// a frozen screen - the native launch theme uses the same colour and image, +/// so the handover from the Android window to Flutter is invisible. +class SplashScreen extends StatefulWidget { + const SplashScreen({super.key}); + + /// Canvas colour of the game; the Android launch theme uses the same value. + static const background = Color(0xFF05070A); + static const accent = Color(0xFFFF8A3D); + + @override + State createState() => _SplashScreenState(); +} + +class _SplashScreenState extends State + with SingleTickerProviderStateMixin { + late final AnimationController _pulse = AnimationController( + vsync: this, + duration: const Duration(milliseconds: 1100), + )..repeat(reverse: true); + + late final Animation _scale = Tween(begin: 0.96, end: 1.04) + .animate(CurvedAnimation(parent: _pulse, curve: Curves.easeInOut)); + late final Animation _opacity = Tween(begin: 0.72, end: 1.0) + .animate(CurvedAnimation(parent: _pulse, curve: Curves.easeInOut)); + + @override + void dispose() { + _pulse.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return ColoredBox( + color: SplashScreen.background, + child: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + FadeTransition( + opacity: _opacity, + child: ScaleTransition( + scale: _scale, + child: Image.asset( + 'assets/logo_mark.png', + width: 220, + filterQuality: FilterQuality.medium, + semanticLabel: 'Iron Arc', + ), + ), + ), + const SizedBox(height: 28), + // Thin indeterminate bar: tells the player the app is working, + // not hung. Kept subtle so the logo stays the focus. + SizedBox( + width: 140, + child: ClipRRect( + borderRadius: BorderRadius.circular(2), + child: LinearProgressIndicator( + minHeight: 2, + color: SplashScreen.accent, + backgroundColor: const Color(0xFF16202E), + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 012f83a..33443fa 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -62,10 +62,10 @@ flutter: # the material Icons class. uses-material-design: true - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg + # Brand mark used by the in-app splash (the Android launch theme ships the + # same image as res/drawable-xxxhdpi/launch_logo.png). + assets: + - assets/logo_mark.png # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/to/resolution-aware-images diff --git a/docs/status/autonomous-log.md b/docs/status/autonomous-log.md index 5a0c2e0..f244a64 100644 --- a/docs/status/autonomous-log.md +++ b/docs/status/autonomous-log.md @@ -138,6 +138,34 @@ Startspieler hatte Spieler 0 einen 59/40-Vorteil. | Reihenfolge | `consent=ConsentStatus.obtained` **vor** `SDK initialised` → keine Ad-Anfrage ohne Einwilligung | | Einstiegspunkt | Zahnrad → Datenschutz-Optionen öffnet das Formular erneut | +## M7c — Startzeit & Splash (erledigt 2026-10-25) + +**Problem:** 5 s weisser Bildschirm vor dem ersten Frame (Stock-`launch_background` mit +`@android:color/white`, dazu die gesamte Bootarbeit vor dem ersten Frame). + +| Massnahme | Datei | +|---|---| +| Launch- und Normal-Theme dunkel (`#05070A`), Status-/Nav-Bar gleich | `res/values/styles.xml`, `values-night`, `values/colors.xml` | +| Androids Splash-API ab 31: Markenfarbe, beschnitt-sicheres Icon, Icon-Platte in Icon-Navy | `res/values-v31/styles.xml`, `res/drawable-xxxhdpi/launch_logo{,_splash}.png` | +| Pulsierendes Logo + Fortschrittslinie waehrend der Bootarbeit | `lib/src/ui/splash_screen.dart` | +| Boot (Session, native Lib, Ad-SDK) erst **nach** dem ersten Frame, Splash mit Mindeststandzeit | `lib/main.dart` (`_bootstrap`) | +| Logo-Mark aus dem Store-Icon freigestellt (Alpha-Ramp + Un-Premultiply, kein Navy-Saum) | `store/assets/logo_mark.png` → `app/assets/logo_mark.png` | + +**Messung** (Redmi Note 10, API 31, Consent erteilt): Debug 3053 ms, Profile/AOT **2040 ms**, +`iron_arc: ready after` 1740 / **1037 ms**. Neues Skript `tools/device/startup.sh`. + +**Erkenntnisse** +- Android 12 maskiert beim Splash-Icon alles ausserhalb der inneren 192 dp eines 288-dp-Bereichs → +ein breites Wortmarken-Logo wird oben/unten abgeschnitten; Loesung ist eine 512×512-Vorlage mit +Motiv auf 59 % Breite. +- Die Icon-Platte ist ueber `windowSplashScreenIconBackgroundColor` steuerbar (mit Testfarbe Rot +verifiziert), Groesse ~153 dp. +- `am start -W` zaehlt den UMP-Dialog mit (7863 ms statt 3076 ms) → nur nach erteiltem Consent messen. +- Dart initialisiert Top-Level-`final`s **lazy**: `final Stopwatch _bootWatch = Stopwatch()..start();` +startete erst beim ersten Zugriff (Bootlog 0 ms). Jetzt Start in `main()`. +- MIUI verweigert `adb install` von release-signierten APKs (`INSTALL_FAILED_USER_RESTRICTED`) → +fuer Messungen `--profile` (AOT, debug-signiert). + ## Nächste Schritte (aktualisiert) 1. `bundletool build-apks --connected-device` aus `~/exports/iron-arc-0.7.0.aab` → Install → Smoke. diff --git a/docs/testing.md b/docs/testing.md index 2224697..5374a08 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -73,11 +73,47 @@ flutter test --update-goldens # nur nach bewusster UI-Änderung, im PR begr | `install.sh` | Deinstallieren, installieren, starten, PID prüfen | | `smoke.sh` | Start → Menü → Match → 3 Schüsse → Ergebnis; 20 Screenshots nach `/tmp/shots` | | `perf.sh` | **SurfaceFlinger-Frame-Timestamps** (Flutter rendert nicht über HWUI, `gfxinfo` liefert 0 Frames): p50/p90/p99 + Jank gegen 1,2 × Vsync | +| `startup.sh` | Kaltstart: `am start -W` (`TotalTime`) plus `iron_arc: ready after N ms` aus dem Log – läuft nur sinnvoll, **nachdem** der Consent einmal erteilt wurde (sonst zählt der UMP-Dialog mit) | | `logs.sh` | Filter: Rust-Panic, `wgpu`/`Vulkan`, JNI, Billing, Consent | **Wichtig:** Screenshots werden als PNG abgelegt und im Review **angesehen**; `perf.sh`-Report landet in `docs/perf/-.md` und ist Release-Voraussetzung. +### Startzeit & Splash-Kette + +Gemessen auf dem Redmi Note 10 (Android 12, API 31), Consent bereits erteilt: + +| Build | `TotalTime` (erster Frame) | `iron_arc: ready after` | +|---|---|---| +| Debug (JIT) | 3053 ms | ~1740 ms | +| Profile/AOT, erster Start nach Installation | 2040 ms | ~1040 ms | +| Profile/AOT, weitere Kaltstarts (Caches warm) | **850–960 ms** | ~1030 ms | + +`TotalTime` ist der Zeitpunkt, ab dem der Splash steht – die Partie erscheint gut 1 s später +(700 ms Mindeststandzeit + 280 ms Fade). + +Die Startstrecke ist bewusst dreiteilig, damit zu keinem Zeitpunkt ein weißer Screen zu sehen ist: + +1. **Nativer Splash** (ab Prozessstart): `LaunchTheme` mit `windowBackground` = `@color/launch_bg` + (`#05070A`), darunter zentriert das Logo. Ab API 31 übernimmt die System-Splash-API + (`values-v31`): Markenfarbe + `launch_logo_splash` auf einer Icon-Platte in Icon-Navy. + Die 512×512-Vorlage hat das Motiv nur auf 59 % Breite, weil Android alles außerhalb der + inneren 192 dp des 288-dp-Icon-Bereichs **wegmaskiert** (sonst wird „IRON“ abgeschnitten). +2. **Flutter-Splash** (`lib/src/ui/splash_screen.dart`): pulsierendes Logo (Scale 0,96→1,04, + Deckkraft 0,72→1,0, 1100 ms) plus dünne Fortschrittslinie. Mindeststandzeit 700 ms, + gemessen ab dem ersten Flutter-Frame – nicht ab Prozessstart, sonst überspringt ein langsamer + Enginestart die Animation komplett. +3. **Fade** (280 ms) über die bereits gebaute Partie, danach wird der Splash aus dem Baum entfernt. + +Erst danach startet das Ad-SDK (`_ads.initialize()`), damit UMP-Dialog und SDK-Init niemals +vor dem ersten Frame liegen. Video-Nachweis: 6-fps-Aufnahme des Kaltstarts, Frames bei +0,4 s (nativer Splash), 1,5–1,8 s (pulsierendes Logo), ab 2,1 s Partie. + +**MIUI-Falle:** `adb install` eines **release**-signierten APKs scheitert mit +`INSTALL_FAILED_USER_RESTRICTED`. Für Messungen auf dem Gerät daher `flutter build apk --profile` +(AOT wie Release, aber debug-signiert); die echte Release-Prüfung läuft über die Split-APKs aus +dem AAB. + ## 6. CI-Gates (Definition of Done für jeden PR) 1. `cargo fmt --check` diff --git a/store/assets/logo_mark.png b/store/assets/logo_mark.png new file mode 100644 index 0000000..540034c Binary files /dev/null and b/store/assets/logo_mark.png differ diff --git a/tools/device/startup.sh b/tools/device/startup.sh new file mode 100755 index 0000000..ec91e81 --- /dev/null +++ b/tools/device/startup.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Cold-start measurement: time to first frame plus the in-app boot log. +# +# `am start -W` measures until the activity is idle. That number is polluted by +# the Google UMP consent form (a second window), so run this only *after* +# consent has been given once - otherwise TotalTime includes the dialog. +# +# Usage: tools/device/startup.sh [runs] (default 3) +set -euo pipefail +ADB=${ADB:-adb} +PKG=${PKG:-de.softwareapp_hb.ironarc} +ACT=${ACT:-.MainActivity} +RUNS=${1:-3} + +echo "## Kaltstart ($RUNS Laeufe, $PKG)" +for i in $(seq 1 "$RUNS"); do + $ADB shell am force-stop "$PKG" + sleep 2 + $ADB logcat -c + total=$($ADB shell am start -W -n "$PKG/$ACT" 2>/dev/null \ + | tr -d '\r' | awk '/TotalTime/ {print $2}') + sleep 2 + ready=$($ADB logcat -d 2>/dev/null | tr -d '\r' \ + | grep -oE 'iron_arc: ready after [0-9]+ ms' | tail -1) + echo " Lauf $i: TotalTime ${total:-?} ms | ${ready:-kein Bootlog (Release ohne Log?)}" +done + +echo +echo "Richtwerte (Redmi Note 10, Android 12): Debug ~3050 ms, Profile/AOT ~2040 ms." +echo "Splash-Kette: nativer Splash -> Flutter-Splash (Puls, min. 700 ms) -> Fade in die Partie."