feat(m3a): playable flame client with camera, hud and device perf gate

This commit is contained in:
2026-10-24 22:54:29 +02:00
parent e77595eaf0
commit a30784479b
15 changed files with 1238 additions and 144 deletions
+187 -99
View File
@@ -1,47 +1,7 @@
import 'dart:ffi';
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
/// Expected hash for seed 42, recorded on x86_64 host.
/// Must match on arm64 (cross-target determinism, ADR 0002).
const hostHash = '6237310299140737418';
typedef _SelftestC = Uint64 Function(Uint64);
typedef _SelftestDart = int Function(int);
typedef _MarkerC = Uint32 Function();
typedef _MarkerDart = int Function();
typedef _VersionC = Uint32 Function();
typedef _VersionDart = int Function();
class Probe {
final String status;
final String marker;
final String version;
final String hash;
const Probe(this.status, this.marker, this.version, this.hash);
static Probe run() {
try {
final lib = DynamicLibrary.open('libffi.so');
final selftest =
lib.lookupFunction<_SelftestC, _SelftestDart>('iron_arc_selftest');
final marker =
lib.lookupFunction<_MarkerC, _MarkerDart>('iron_arc_abi_marker');
final version = lib.lookupFunction<_VersionC, _VersionDart>(
'iron_arc_sim_version_code');
return Probe(
'RUST OK',
marker().toRadixString(16).padLeft(8, '0'),
(version() / 100).toStringAsFixed(2),
BigInt.from(selftest(42)).toUnsigned(64).toString(),
);
} catch (e) {
return Probe('RUST FAIL', '-', '-', '$e');
}
}
}
import 'src/game/iron_arc_game.dart';
void main() => runApp(const IronArcApp());
@@ -50,80 +10,208 @@ class IronArcApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
final probe = Probe.run();
final matches = probe.hash == hostHash;
return MaterialApp(
title: 'Iron Arc',
debugShowCheckedModeBanner: false,
theme: ThemeData.dark(useMaterial3: true),
home: Scaffold(
backgroundColor: const Color(0xFF101418),
body: SafeArea(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('IRON ARC',
style: TextStyle(
fontSize: 34,
fontWeight: FontWeight.w800,
letterSpacing: 4)),
const SizedBox(height: 4),
const Text('M0 pipeline probe',
style: TextStyle(color: Colors.white54)),
const SizedBox(height: 32),
_Row('FFI status', probe.status),
_Row('ABI marker', probe.marker),
_Row('sim version', probe.version),
_Row('device hash', probe.hash),
_Row('host hash', hostHash),
const SizedBox(height: 24),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: matches ? Colors.green.shade900 : Colors.red.shade900,
borderRadius: BorderRadius.circular(8),
),
child: Text(
matches
? 'DETERMINISM PASS (arm64 == x86_64)'
: 'DETERMINISM MISMATCH',
style: const TextStyle(fontWeight: FontWeight.bold),
),
),
],
home: const MatchScreen(),
);
}
}
/// One hotseat match; restart creates a new game with a new seed.
class MatchScreen extends StatefulWidget {
const MatchScreen({super.key});
@override
State<MatchScreen> createState() => _MatchScreenState();
}
class _MatchScreenState extends State<MatchScreen> {
int _seed = 42;
late IronArcGame _game = IronArcGame(seed: _seed);
void _restart() {
setState(() {
_seed += 1;
_game = IronArcGame(seed: _seed);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF05070A),
body: SafeArea(
child: Stack(
children: [
Positioned.fill(child: GameWidget(game: _game)),
Positioned.fill(
child: GestureDetector(
behavior: HitTestBehavior.translucent,
onPanStart: (d) => _game.beginAim(d.localPosition),
onPanUpdate: (d) => _game.updateAim(d.localPosition),
onPanEnd: (_) => _game.releaseAim(),
),
),
),
Positioned(
top: 8,
left: 12,
right: 12,
child: ValueListenableBuilder<HudState>(
valueListenable: _game.hud,
builder: (context, hud, _) => _Hud(hud: hud),
),
),
Positioned(
bottom: 16,
left: 16,
right: 16,
child: ValueListenableBuilder<HudState>(
valueListenable: _game.hud,
builder: (context, hud, _) => hud.isFinished
? _GameOver(hud: hud, onRestart: _restart)
: _Hint(hud: hud),
),
),
],
),
),
);
}
}
class _Row extends StatelessWidget {
const _Row(this.label, this.value);
final String label;
final String value;
class _Hud extends StatelessWidget {
const _Hud({required this.hud});
final HudState hud;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
return Row(
children: [
_Pill(
label: 'P1',
value: '${hud.hp0} HP',
color: const Color(0xFFFF8A3D),
active: hud.current == 0 && !hud.isFinished,
),
const SizedBox(width: 8),
Expanded(
child: Column(
children: [
Text('Zug ${hud.turn}',
style: const TextStyle(
fontSize: 13, fontWeight: FontWeight.w700)),
const SizedBox(height: 2),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.air, size: 14),
const SizedBox(width: 4),
Text('${hud.wind > 0 ? '+' : ''}${hud.wind}',
style: const TextStyle(fontSize: 13)),
],
),
],
),
),
const SizedBox(width: 8),
_Pill(
label: 'P2',
value: '${hud.hp1} HP',
color: const Color(0xFF4DD0E1),
active: hud.current == 1 && !hud.isFinished,
),
],
);
}
}
class _Pill extends StatelessWidget {
const _Pill({
required this.label,
required this.value,
required this.color,
required this.active,
});
final String label;
final String value;
final Color color;
final bool active;
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: color.withValues(alpha: active ? 0.28 : 0.10),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: color.withValues(alpha: active ? 0.9 : 0.3),
width: active ? 2 : 1,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 120,
child: Text(label,
style: const TextStyle(color: Colors.white60, fontSize: 13))),
Expanded(
child: Text(value,
style: const TextStyle(fontFamily: 'monospace', fontSize: 13)),
),
Text(label,
style: TextStyle(
fontSize: 11,
color: color,
fontWeight: FontWeight.w800)),
Text(value, style: const TextStyle(fontSize: 15)),
],
),
);
}
}
class _Hint extends StatelessWidget {
const _Hint({required this.hud});
final HudState hud;
@override
Widget build(BuildContext context) {
final text = hud.phase == 1
? 'Projektil im Flug…'
: 'Ziehen zum Zielen · Loslassen zum Schießen';
return Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xCC0B1220),
borderRadius: BorderRadius.circular(20),
),
child: Text(text, style: const TextStyle(fontSize: 13)),
),
);
}
}
class _GameOver extends StatelessWidget {
const _GameOver({required this.hud, required this.onRestart});
final HudState hud;
final VoidCallback onRestart;
@override
Widget build(BuildContext context) {
final text = switch (hud.winner) {
0 => 'Spieler 1 gewinnt',
1 => 'Spieler 2 gewinnt',
_ => 'Unentschieden',
};
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(text,
style: const TextStyle(fontSize: 26, fontWeight: FontWeight.w800)),
const SizedBox(height: 12),
FilledButton.icon(
onPressed: onRestart,
icon: const Icon(Icons.refresh),
label: const Text('Neuer Match'),
),
],
);
}
}