feat(m3a): playable flame client with camera, hud and device perf gate
This commit is contained in:
@@ -0,0 +1,405 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flame/game.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../native/native_match.dart';
|
||||
|
||||
/// World dimensions in simulation pixels (must match crates/sim).
|
||||
const double kWorldWidth = 2048;
|
||||
const double kWorldHeight = 1152;
|
||||
const int kSamplePx = 2;
|
||||
|
||||
/// Immutable HUD snapshot, only replaced when something actually changed.
|
||||
@immutable
|
||||
class HudState {
|
||||
const HudState({
|
||||
required this.turn,
|
||||
required this.current,
|
||||
required this.wind,
|
||||
required this.hp0,
|
||||
required this.hp1,
|
||||
required this.phase,
|
||||
required this.winner,
|
||||
required this.aimAngle,
|
||||
required this.aimPower,
|
||||
});
|
||||
|
||||
final int turn;
|
||||
final int current;
|
||||
final int wind;
|
||||
final int hp0;
|
||||
final int hp1;
|
||||
final int phase;
|
||||
final int winner;
|
||||
final double aimAngle;
|
||||
final double aimPower;
|
||||
|
||||
bool get isFinished => phase == 2;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is HudState &&
|
||||
other.turn == turn &&
|
||||
other.current == current &&
|
||||
other.wind == wind &&
|
||||
other.hp0 == hp0 &&
|
||||
other.hp1 == hp1 &&
|
||||
other.phase == phase &&
|
||||
other.winner == winner &&
|
||||
other.aimAngle == aimAngle &&
|
||||
other.aimPower == aimPower;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
turn, current, wind, hp0, hp1, phase, winner, aimAngle, aimPower);
|
||||
}
|
||||
|
||||
/// The playable match. Flame drives the loop; Rust owns the simulation.
|
||||
class IronArcGame extends FlameGame {
|
||||
IronArcGame({this.seed = 42});
|
||||
|
||||
final int seed;
|
||||
|
||||
late NativeMatch _match;
|
||||
final ValueNotifier<HudState> hud = ValueNotifier<HudState>(
|
||||
const HudState(
|
||||
turn: 1,
|
||||
current: 0,
|
||||
wind: 0,
|
||||
hp0: 100,
|
||||
hp1: 100,
|
||||
phase: 0,
|
||||
winner: 254,
|
||||
aimAngle: 45,
|
||||
aimPower: 0.6,
|
||||
),
|
||||
);
|
||||
|
||||
double _accumulator = 0;
|
||||
double _impactFlash = 0;
|
||||
Offset? _lastImpact;
|
||||
|
||||
/// Aim state in simulation units (degrees / 0..1).
|
||||
double aimAngle = 45;
|
||||
double aimPower = 0.6;
|
||||
bool _dragging = false;
|
||||
|
||||
double _zoom = 1;
|
||||
double _camX = 0;
|
||||
|
||||
int _terrainVersion = -1;
|
||||
Path? _terrainFill;
|
||||
Path? _terrainLine;
|
||||
|
||||
bool get isReady => isLoaded;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
_match = NativeMatch(seed);
|
||||
_pushHud();
|
||||
}
|
||||
|
||||
@override
|
||||
void update(double dt) {
|
||||
super.update(dt);
|
||||
if (_match.isFlying) {
|
||||
_accumulator += dt;
|
||||
const step = 1 / 60;
|
||||
var steps = 0;
|
||||
while (_accumulator >= step && steps < 8) {
|
||||
final impacts = _match.tick(1);
|
||||
if (impacts > 0) {
|
||||
final p = _match.lastImpact();
|
||||
_lastImpact = Offset(p.x.toDouble(), p.y.toDouble());
|
||||
_impactFlash = 1;
|
||||
}
|
||||
_accumulator -= step;
|
||||
steps++;
|
||||
}
|
||||
_pushHud();
|
||||
} else if (_match.isAiming) {
|
||||
_accumulator = 0;
|
||||
}
|
||||
if (_impactFlash > 0) {
|
||||
_impactFlash = math.max(0, _impactFlash - dt * 1.8);
|
||||
}
|
||||
_updateCamera(dt);
|
||||
}
|
||||
|
||||
void _pushHud() {
|
||||
final next = HudState(
|
||||
turn: _match.turn,
|
||||
current: _match.current,
|
||||
wind: _match.wind,
|
||||
hp0: _match.tankHp(0),
|
||||
hp1: _match.tankHp(1),
|
||||
phase: _match.phase,
|
||||
winner: _match.winner,
|
||||
aimAngle: aimAngle,
|
||||
aimPower: aimPower,
|
||||
);
|
||||
if (hud.value != next) hud.value = next;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- input
|
||||
|
||||
/// Starts aiming at the given screen position.
|
||||
void beginAim(Offset screen) {
|
||||
if (!_match.isAiming) return;
|
||||
_dragging = true;
|
||||
_aimAt(screen);
|
||||
}
|
||||
|
||||
/// Updates the aim while dragging.
|
||||
void updateAim(Offset screen) {
|
||||
if (!_dragging) return;
|
||||
_aimAt(screen);
|
||||
}
|
||||
|
||||
/// Fires if a drag produced a valid shot.
|
||||
void releaseAim() {
|
||||
if (!_dragging) return;
|
||||
_dragging = false;
|
||||
if (!_match.isAiming) return;
|
||||
final angleMdeg = (aimAngle * 1000).round().clamp(1000, 89000);
|
||||
final powerQ16 = (aimPower * 65536).round().clamp(3277, 65536);
|
||||
_match.fire(angleMdeg: angleMdeg, powerQ16: powerQ16);
|
||||
_pushHud();
|
||||
}
|
||||
|
||||
void _aimAt(Offset screen) {
|
||||
final world = screenToWorld(screen);
|
||||
final player = _match.current;
|
||||
final tank = Offset(_match.tankX(player).toDouble(),
|
||||
_match.tankY(player).toDouble() - 14);
|
||||
final dx = world.dx - tank.dx;
|
||||
final dy = world.dy - tank.dy;
|
||||
final distance = math.sqrt(dx * dx + dy * dy);
|
||||
aimPower = (distance / 250).clamp(0.05, 1.0);
|
||||
final radians = math.atan2(-dy, dx.abs());
|
||||
aimAngle = (radians * 180 / math.pi).clamp(1.0, 89.0);
|
||||
_pushHud();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- transform
|
||||
|
||||
/// Zoom fits the world height; the camera pans horizontally.
|
||||
double get _viewWidthWorld => size.x / _zoom;
|
||||
|
||||
void _updateCamera(double dt) {
|
||||
if (size.y <= 0 || size.x <= 0) return;
|
||||
// Fit height, but never crop the world horizontally more than necessary.
|
||||
final zoomForHeight = size.y / kWorldHeight;
|
||||
final zoomForWidth = size.x / kWorldWidth;
|
||||
_zoom = math.max(zoomForHeight, zoomForWidth);
|
||||
|
||||
final viewW = _viewWidthWorld;
|
||||
final focus = _match.isFlying
|
||||
? (_match.projectile()?.x.toDouble() ??
|
||||
_match.tankX(_match.current).toDouble())
|
||||
: _match.tankX(_match.current).toDouble();
|
||||
final desiredLeft = (focus - viewW / 2).clamp(0.0, math.max(0, kWorldWidth - viewW));
|
||||
// Smooth follow; instant on first frame.
|
||||
final t = _camX == 0 ? 1.0 : (dt * 5).clamp(0.0, 1.0);
|
||||
_camX += (desiredLeft - _camX) * t;
|
||||
_camX = _camX.clamp(0.0, math.max(0, kWorldWidth - viewW));
|
||||
}
|
||||
|
||||
/// Screen -> world pixels.
|
||||
Offset screenToWorld(Offset p) => Offset(p.dx / _zoom + _camX, p.dy / _zoom);
|
||||
|
||||
/// World -> screen pixels.
|
||||
Offset worldToScreen(Offset p) => Offset((p.dx - _camX) * _zoom, p.dy * _zoom);
|
||||
|
||||
// ------------------------------------------------------------- rendering
|
||||
|
||||
@override
|
||||
void render(Canvas canvas) {
|
||||
super.render(canvas);
|
||||
if (!isLoaded) return;
|
||||
canvas.save();
|
||||
canvas.scale(_zoom);
|
||||
canvas.translate(-_camX, 0);
|
||||
|
||||
_drawSky(canvas);
|
||||
_drawTerrain(canvas);
|
||||
_drawTank(canvas, 0);
|
||||
_drawTank(canvas, 1);
|
||||
_drawProjectile(canvas);
|
||||
if (_match.isAiming) _drawAim(canvas);
|
||||
_drawImpact(canvas);
|
||||
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
void _drawSky(Canvas canvas) {
|
||||
final rect = Rect.fromLTWH(0, 0, kWorldWidth, kWorldHeight);
|
||||
final paint = Paint()
|
||||
..shader = ui.Gradient.linear(
|
||||
const Offset(0, 0),
|
||||
const Offset(0, kWorldHeight),
|
||||
const [Color(0xFF0B1220), Color(0xFF243B53), Color(0xFF7A5C3E)],
|
||||
const [0.0, 0.55, 1.0],
|
||||
);
|
||||
canvas.drawRect(rect, paint);
|
||||
|
||||
// Distant hills for depth.
|
||||
final hills = Path()
|
||||
..moveTo(0, 760)
|
||||
..quadraticBezierTo(360, 620, 720, 750)
|
||||
..quadraticBezierTo(1120, 880, 1500, 720)
|
||||
..quadraticBezierTo(1800, 610, kWorldWidth, 740)
|
||||
..lineTo(kWorldWidth, kWorldHeight)
|
||||
..lineTo(0, kWorldHeight)
|
||||
..close();
|
||||
canvas.drawPath(hills, Paint()..color = const Color(0x33FFFFFF));
|
||||
}
|
||||
|
||||
void _drawTerrain(Canvas canvas) {
|
||||
final version = _match.terrainVersion;
|
||||
if (version != _terrainVersion || _terrainFill == null) {
|
||||
_terrainVersion = version;
|
||||
final heights = _match.terrain();
|
||||
final fill = Path()..moveTo(0, heights[0].toDouble());
|
||||
final line = Path()..moveTo(0, heights[0].toDouble());
|
||||
for (var i = 1; i < heights.length; i++) {
|
||||
final x = i * kSamplePx.toDouble();
|
||||
final y = heights[i].toDouble();
|
||||
fill.lineTo(x, y);
|
||||
line.lineTo(x, y);
|
||||
}
|
||||
fill
|
||||
..lineTo(kWorldWidth, kWorldHeight)
|
||||
..lineTo(0, kWorldHeight)
|
||||
..close();
|
||||
_terrainFill = fill;
|
||||
_terrainLine = line;
|
||||
}
|
||||
|
||||
canvas.drawPath(
|
||||
_terrainFill!,
|
||||
Paint()
|
||||
..shader = ui.Gradient.linear(
|
||||
const Offset(0, 400),
|
||||
const Offset(0, kWorldHeight),
|
||||
const [Color(0xFF6B4A2F), Color(0xFF2E1F16)],
|
||||
),
|
||||
);
|
||||
canvas.drawPath(
|
||||
_terrainLine!,
|
||||
Paint()
|
||||
..color = const Color(0xFF8FD694)
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 6
|
||||
..strokeJoin = StrokeJoin.round,
|
||||
);
|
||||
}
|
||||
|
||||
void _drawTank(Canvas canvas, int player) {
|
||||
if (!isLoaded) return;
|
||||
final x = _match.tankX(player).toDouble();
|
||||
final y = _match.tankY(player).toDouble();
|
||||
final alive = _match.tankHp(player) > 0;
|
||||
final color = player == 0 ? const Color(0xFFFF8A3D) : const Color(0xFF4DD0E1);
|
||||
final body = Paint()..color = alive ? color : color.withValues(alpha: 0.3);
|
||||
|
||||
final hull = RRect.fromRectAndRadius(
|
||||
Rect.fromCenter(center: Offset(x, y - 9), width: 52, height: 18),
|
||||
const Radius.circular(5),
|
||||
);
|
||||
canvas.drawRRect(hull, body);
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromCenter(center: Offset(x, y - 9), width: 26, height: 12),
|
||||
const Radius.circular(4),
|
||||
),
|
||||
Paint()..color = const Color(0x22000000),
|
||||
);
|
||||
|
||||
final dir = player == 0 ? 1.0 : -1.0;
|
||||
final angle = player == _match.current ? aimAngle : 35.0;
|
||||
final radians = angle * math.pi / 180;
|
||||
final muzzle = Offset(
|
||||
x + dir * math.cos(radians) * 34,
|
||||
y - 16 - math.sin(radians) * 34,
|
||||
);
|
||||
canvas.drawLine(
|
||||
Offset(x, y - 15),
|
||||
muzzle,
|
||||
Paint()
|
||||
..color = Colors.white
|
||||
..strokeWidth = 6
|
||||
..strokeCap = StrokeCap.round,
|
||||
);
|
||||
|
||||
// Health bar.
|
||||
final hp = _match.tankHp(player).clamp(0, 100) / 100.0;
|
||||
final barRect = RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(x - 30, y - 46, 60, 8),
|
||||
const Radius.circular(4),
|
||||
);
|
||||
canvas.drawRRect(barRect, Paint()..color = const Color(0xAA000000));
|
||||
canvas.drawRRect(
|
||||
RRect.fromRectAndRadius(
|
||||
Rect.fromLTWH(x - 30, y - 46, 60 * hp, 8),
|
||||
const Radius.circular(4),
|
||||
),
|
||||
Paint()..color = hp > 0.5
|
||||
? const Color(0xFF66BB6A)
|
||||
: hp > 0.25
|
||||
? const Color(0xFFFFC107)
|
||||
: const Color(0xFFE53935),
|
||||
);
|
||||
}
|
||||
|
||||
void _drawProjectile(Canvas canvas) {
|
||||
final p = _match.projectile();
|
||||
if (p == null) return;
|
||||
final center = Offset(p.x.toDouble(), p.y.toDouble());
|
||||
canvas.drawCircle(center, 16, Paint()..color = const Color(0x33FFD54F));
|
||||
canvas.drawCircle(center, 7, Paint()..color = const Color(0xFFFFD54F));
|
||||
}
|
||||
|
||||
void _drawAim(Canvas canvas) {
|
||||
final player = _match.current;
|
||||
final dir = player == 0 ? 1.0 : -1.0;
|
||||
final x = _match.tankX(player).toDouble();
|
||||
final y = _match.tankY(player).toDouble() - 16;
|
||||
final radians = aimAngle * math.pi / 180;
|
||||
final paint = Paint()
|
||||
..color = const Color(0xCCFFFFFF)
|
||||
..strokeWidth = 3
|
||||
..strokeCap = StrokeCap.round;
|
||||
for (var i = 1; i <= 6; i++) {
|
||||
final r = 40.0 + i * 26;
|
||||
final p = Offset(
|
||||
x + dir * math.cos(radians) * r,
|
||||
y - math.sin(radians) * r + 0.12 * i * i,
|
||||
);
|
||||
canvas.drawCircle(p, 4, paint);
|
||||
}
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(x - 40, y - 70, 80 * aimPower, 6),
|
||||
Paint()..color = const Color(0xCCFFB74D),
|
||||
);
|
||||
}
|
||||
|
||||
void _drawImpact(Canvas canvas) {
|
||||
final pos = _lastImpact;
|
||||
if (pos == null || _impactFlash <= 0) return;
|
||||
final alpha = (_impactFlash * 200).clamp(0, 200).toInt();
|
||||
canvas.drawCircle(
|
||||
pos,
|
||||
30 + 60 * (1 - _impactFlash),
|
||||
Paint()..color = Color.fromARGB(alpha, 0xFF, 0xB3, 0x00),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void onRemove() {
|
||||
_match.dispose();
|
||||
super.onRemove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
import 'dart:ffi';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
|
||||
/// Raw C signatures of the Rust match API (see crates/ffi/src/match_api.rs).
|
||||
typedef _NewMatchC = Pointer<Void> Function(Uint64);
|
||||
typedef _NewMatchDart = Pointer<Void> Function(int);
|
||||
|
||||
typedef _FreeMatchC = Void Function(Pointer<Void>);
|
||||
typedef _FreeMatchDart = void Function(Pointer<Void>);
|
||||
|
||||
typedef _FireC = Int32 Function(Pointer<Void>, Uint32, Int32, Uint8);
|
||||
typedef _FireDart = int Function(Pointer<Void>, int, int, int);
|
||||
|
||||
typedef _EndTurnC = Int32 Function(Pointer<Void>);
|
||||
typedef _EndTurnDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _TickC = Uint32 Function(Pointer<Void>, Uint32);
|
||||
typedef _TickDart = int Function(Pointer<Void>, int);
|
||||
|
||||
typedef _PhaseC = Uint8 Function(Pointer<Void>);
|
||||
typedef _PhaseDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _CurrentC = Uint8 Function(Pointer<Void>);
|
||||
typedef _CurrentDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _WindC = Int32 Function(Pointer<Void>);
|
||||
typedef _WindDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _TurnC = Uint32 Function(Pointer<Void>);
|
||||
typedef _TurnDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _WinnerC = Uint8 Function(Pointer<Void>);
|
||||
typedef _WinnerDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _TankIntC = Int32 Function(Pointer<Void>, Uint8);
|
||||
typedef _TankIntDart = int Function(Pointer<Void>, int);
|
||||
|
||||
typedef _TerrainPtrC = Pointer<Uint16> Function(Pointer<Void>);
|
||||
typedef _TerrainPtrDart = Pointer<Uint16> Function(Pointer<Void>);
|
||||
|
||||
typedef _TerrainLenC = Uint32 Function();
|
||||
typedef _TerrainLenDart = int Function();
|
||||
|
||||
typedef _TerrainVersionC = Uint32 Function(Pointer<Void>);
|
||||
typedef _TerrainVersionDart = int Function(Pointer<Void>);
|
||||
|
||||
typedef _ProjectileC = Int32 Function(Pointer<Void>, Pointer<Int32>);
|
||||
typedef _ProjectileDart = int Function(Pointer<Void>, Pointer<Int32>);
|
||||
|
||||
typedef _ImpactC = Uint32 Function(Pointer<Void>, Pointer<Int32>);
|
||||
typedef _ImpactDart = int Function(Pointer<Void>, Pointer<Int32>);
|
||||
|
||||
/// Thin typed wrapper around the Rust match handle.
|
||||
///
|
||||
/// The handle owns the simulation; Dart only pulls snapshots for rendering.
|
||||
class NativeMatch {
|
||||
NativeMatch(int seed) : _handle = _newMatch(seed);
|
||||
|
||||
final Pointer<Void> _handle;
|
||||
bool _disposed = false;
|
||||
|
||||
static final DynamicLibrary _lib = DynamicLibrary.open('libffi.so');
|
||||
|
||||
static final _NewMatchDart _newMatch =
|
||||
_lib.lookupFunction<_NewMatchC, _NewMatchDart>('iron_arc_new_match');
|
||||
static final _FreeMatchDart _freeMatch =
|
||||
_lib.lookupFunction<_FreeMatchC, _FreeMatchDart>('iron_arc_free_match');
|
||||
static final _FireDart _fire =
|
||||
_lib.lookupFunction<_FireC, _FireDart>('iron_arc_fire');
|
||||
static final _EndTurnDart _endTurn =
|
||||
_lib.lookupFunction<_EndTurnC, _EndTurnDart>('iron_arc_end_turn');
|
||||
static final _TickDart _tick =
|
||||
_lib.lookupFunction<_TickC, _TickDart>('iron_arc_tick');
|
||||
static final _PhaseDart _phase =
|
||||
_lib.lookupFunction<_PhaseC, _PhaseDart>('iron_arc_phase');
|
||||
static final _CurrentDart _current =
|
||||
_lib.lookupFunction<_CurrentC, _CurrentDart>('iron_arc_current');
|
||||
static final _WindDart _wind =
|
||||
_lib.lookupFunction<_WindC, _WindDart>('iron_arc_wind');
|
||||
static final _TurnDart _turn =
|
||||
_lib.lookupFunction<_TurnC, _TurnDart>('iron_arc_turn');
|
||||
static final _WinnerDart _winner =
|
||||
_lib.lookupFunction<_WinnerC, _WinnerDart>('iron_arc_winner');
|
||||
static final _TankIntDart _tankX =
|
||||
_lib.lookupFunction<_TankIntC, _TankIntDart>('iron_arc_tank_x');
|
||||
static final _TankIntDart _tankY =
|
||||
_lib.lookupFunction<_TankIntC, _TankIntDart>('iron_arc_tank_y');
|
||||
static final _TankIntDart _tankHp =
|
||||
_lib.lookupFunction<_TankIntC, _TankIntDart>('iron_arc_tank_hp');
|
||||
static final _TerrainPtrDart _terrainPtr =
|
||||
_lib.lookupFunction<_TerrainPtrC, _TerrainPtrDart>('iron_arc_terrain_ptr');
|
||||
static final _TerrainLenDart _terrainLen =
|
||||
_lib.lookupFunction<_TerrainLenC, _TerrainLenDart>('iron_arc_terrain_len');
|
||||
static final _TerrainVersionDart _terrainVersion = _lib
|
||||
.lookupFunction<_TerrainVersionC, _TerrainVersionDart>(
|
||||
'iron_arc_terrain_version');
|
||||
static final _ProjectileDart _projectile =
|
||||
_lib.lookupFunction<_ProjectileC, _ProjectileDart>('iron_arc_projectile');
|
||||
static final _ImpactDart _lastImpact =
|
||||
_lib.lookupFunction<_ImpactC, _ImpactDart>('iron_arc_last_impact');
|
||||
|
||||
/// Phase: 0 aiming, 1 flying, 2 finished.
|
||||
int get phase => _phase(_handle);
|
||||
|
||||
bool get isAiming => phase == 0;
|
||||
bool get isFlying => phase == 1;
|
||||
bool get isFinished => phase == 2;
|
||||
|
||||
/// Active player index.
|
||||
int get current => _current(_handle);
|
||||
|
||||
/// Wind in units -8..8.
|
||||
int get wind => _wind(_handle);
|
||||
|
||||
/// Turn number starting at 1.
|
||||
int get turn => _turn(_handle);
|
||||
|
||||
/// 0/1 winner, 255 draw, 254 still running.
|
||||
int get winner => _winner(_handle);
|
||||
|
||||
int tankX(int player) => _tankX(_handle, player);
|
||||
int tankY(int player) => _tankY(_handle, player);
|
||||
int tankHp(int player) => _tankHp(_handle, player);
|
||||
|
||||
/// Fires a shot. Returns 0 on success.
|
||||
int fire({required int angleMdeg, required int powerQ16, int weapon = 1}) =>
|
||||
_fire(_handle, angleMdeg, powerQ16, weapon);
|
||||
|
||||
int endTurn() => _endTurn(_handle);
|
||||
|
||||
/// Advances the simulation, returns the number of impacts.
|
||||
int tick(int ticks) => _tick(_handle, ticks);
|
||||
|
||||
/// Bumped whenever the terrain changed.
|
||||
int get terrainVersion => _terrainVersion(_handle);
|
||||
|
||||
/// Live view into the Rust heightmap (valid until [dispose]).
|
||||
Uint16List terrain() =>
|
||||
_terrainPtr(_handle).asTypedList(_terrainLen());
|
||||
|
||||
/// Projectile position in world pixels, or null if none is in flight.
|
||||
({int x, int y})? projectile() {
|
||||
final out = calloc<Int32>(2);
|
||||
try {
|
||||
return _projectile(_handle, out) == 1
|
||||
? (x: out[0], y: out[1])
|
||||
: null;
|
||||
} finally {
|
||||
calloc.free(out);
|
||||
}
|
||||
}
|
||||
|
||||
/// World position of the most recent impact.
|
||||
({int x, int y}) lastImpact() {
|
||||
final out = calloc<Int32>(2);
|
||||
try {
|
||||
_lastImpact(_handle, out);
|
||||
return (x: out[0], y: out[1]);
|
||||
} finally {
|
||||
calloc.free(out);
|
||||
}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
_freeMatch(_handle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user