Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ inputs:
flutter-version:
description: 'The version of Flutter to use'
required: false
default: '3.24.5'
default: '3.35.3'
pub-cache:
description: 'The name of the pub cache variable'
required: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: 🚂 Setup Flutter and dependencies
uses: ./.github/actions/setup
with:
flutter-version: 3.27.1
flutter-version: 3.35.3

- name: 👷 Install Dependencies
timeout-minutes: 1
Expand Down
65 changes: 20 additions & 45 deletions lib/src/collisions/quadtree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,8 @@ extension type QuadTree$QueryResult._(Float32List _bytes) {
/// The walk stops when it iterates over all objects or
/// when the callback returns false.
void forEach(
bool Function(
int id,
double left,
double top,
double width,
double height,
) cb,
bool Function(int id, double left, double top, double width, double height)
cb,
) {
if (isEmpty) return;
final ids = Uint32List.sublistView(_bytes);
Expand Down Expand Up @@ -183,14 +178,13 @@ final class QuadTree {
required Float32List objects,
required Uint32List recycledIds,
required Uint32List id2node,
}) :
// Nodes
_nodes = nodes,
_recycledNodes = recycledNodes,
// Objects
_objects = objects,
_recycledIds = recycledIds,
_id2node = id2node;
}) : // Nodes
_nodes = nodes,
_recycledNodes = recycledNodes,
// Objects
_objects = objects,
_recycledIds = recycledIds,
_id2node = id2node;

// --------------------------------------------------------------------------
// PROPERTIES
Expand Down Expand Up @@ -290,10 +284,7 @@ final class QuadTree {

// Get the root node of the QuadTree
// or create a new one if it does not exist.
final root = _root ??= _createNode(
parent: null,
boundary: boundary,
);
final root = _root ??= _createNode(parent: null, boundary: boundary);

// Create a new object in the QuadTree.
final objectId = _getNextObjectId();
Expand Down Expand Up @@ -434,10 +425,7 @@ final class QuadTree {

// Resize recycled ids array if needed
if (_recycledIdsCount == _recycledIds.length)
_recycledIds = _resizeUint32List(
_recycledIds,
_recycledIds.length << 1,
);
_recycledIds = _resizeUint32List(_recycledIds, _recycledIds.length << 1);
_recycledIds[_recycledIdsCount++] = objectId;

return true;
Expand All @@ -452,13 +440,8 @@ final class QuadTree {
/// The walk stops when it iterates over all objects or
/// when the callback returns false.
void forEach(
bool Function(
int id,
double left,
double top,
double width,
double height,
) cb,
bool Function(int id, double left, double top, double width, double height)
cb,
) {
final root = _root;
if (root == null) return;
Expand Down Expand Up @@ -1013,7 +996,8 @@ final class QuadTree {
// --------------------------------------------------------------------------

@override
String toString() => 'QuadTree{'
String toString() =>
'QuadTree{'
'nodes: $nodes, '
'objects: $length'
'}';
Expand Down Expand Up @@ -1137,13 +1121,8 @@ final class QuadTree$Node {
/// when the callback returns false.
@pragma('vm:prefer-inline')
void forEach(
bool Function(
int id,
double left,
double top,
double width,
double height,
) cb,
bool Function(int id, double left, double top, double width, double height)
cb,
) {
if (isEmpty) return;
if (subdivided) {
Expand Down Expand Up @@ -1184,12 +1163,7 @@ final class QuadTree$Node {
final top = boundary.top;
final nw = _northWest = tree._createNode(
parent: this,
boundary: ui.Rect.fromLTWH(
left,
top,
halfWidth,
halfHeight,
),
boundary: ui.Rect.fromLTWH(left, top, halfWidth, halfHeight),
),
ne = _northEast = tree._createNode(
parent: this,
Expand Down Expand Up @@ -1327,7 +1301,8 @@ final class QuadTree$Node {
identical(this, other) || other is QuadTree$Node && id == other.id;

@override
String toString() => r'QuadTree$Node{'
String toString() =>
r'QuadTree$Node{'
'id: $id, '
'objects: $length, '
'subdivided: $_subdivided'
Expand Down
55 changes: 28 additions & 27 deletions lib/src/repaint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ class RePaint extends LeafRenderObjectWidget {
Listenable? repaint,
bool repaintBoundary = false,
Key? key,
}) =>
RePaintInline<T>(
render: render,
setUp: setUp,
update: update,
tearDown: tearDown,
frameRate: frameRate,
repaint: repaint,
repaintBoundary: repaintBoundary,
key: key,
);
}) => RePaintInline<T>(
render: render,
setUp: setUp,
update: update,
tearDown: tearDown,
frameRate: frameRate,
repaint: repaint,
repaintBoundary: repaintBoundary,
key: key,
);

/// The painter controller, used to update and paint the scene.
/// For example, a game controller or a custom painter.
Expand All @@ -76,10 +75,10 @@ class RePaint extends LeafRenderObjectWidget {

@override
RenderObject createRenderObject(BuildContext context) => RePaintBox(
painter: painter,
context: context,
isRepaintBoundary: repaintBoundary,
);
painter: painter,
context: context,
isRepaintBoundary: repaintBoundary,
);

@override
void updateRenderObject(BuildContext context, RePaintBox renderObject) {
Expand All @@ -92,7 +91,8 @@ class RePaint extends LeafRenderObjectWidget {
renderObject._painter = painter
..mount(renderObject, renderObject.owner!)
..lifecycle(
WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed);
WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed,
);
}
}

Expand Down Expand Up @@ -136,9 +136,9 @@ class RePaintBox extends RenderBox with WidgetsBindingObserver {
required RePainter painter,
required BuildContext context,
required bool isRepaintBoundary,
}) : _painter = painter,
_context = context,
_$isRepaintBoundary = isRepaintBoundary;
}) : _painter = painter,
_context = context,
_$isRepaintBoundary = isRepaintBoundary;

/// Current controller.
RePainter get painter => _painter;
Expand Down Expand Up @@ -185,19 +185,17 @@ class RePaintBox extends RenderBox with WidgetsBindingObserver {
_painter
..mount(this, owner)
..lifecycle(
WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed);
WidgetsBinding.instance.lifecycleState ?? AppLifecycleState.resumed,
);
WidgetsBinding.instance.addObserver(this);
_ticker = Ticker(_onTick, debugLabel: 'RePaintBox')..start();
_ticker = Ticker(onTick, debugLabel: 'RePaintBox')..start();
}

@override
bool hitTestSelf(Offset position) => true;

@override
bool hitTestChildren(
BoxHitTestResult result, {
required Offset position,
}) =>
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) =>
false;

@override
Expand Down Expand Up @@ -250,10 +248,13 @@ class RePaintBox extends RenderBox with WidgetsBindingObserver {
Duration _lastFrameTime = Duration.zero;

/// This method is periodically invoked by the [_ticker].
void _onTick(Duration elapsed) {
void onTick(Duration elapsed) {
if (!attached) return;
// Delta can be negative when widget is paused.
// Sometimes even like "-15" seconds.
final delta = elapsed - _lastFrameTime;
final deltaMs = delta.inMicroseconds / Duration.microsecondsPerMillisecond;
final deltaMs =
delta.inMicroseconds.abs() / Duration.microsecondsPerMillisecond;
_lastFrameTime = elapsed;
// Update game scene and prepare for rendering.
_painter.update(this, elapsed, deltaMs);
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ platforms:
# path: example.png

environment:
sdk: ^3.6.0
flutter: ">=3.27.0"
sdk: ^3.8.0
flutter: ">=3.35.3"

dependencies:
flutter:
Expand All @@ -52,5 +52,5 @@ dev_dependencies:
fake_async: ^1.3.0
flutter_lints: ">=4.0.0 <6.0.0"
benchmark_harness: ^2.3.1
flame: ^1.23.0
vector_math: ^2.1.4
flame: ^1.34.0
vector_math: ^2.2.0
Loading