-
-
Notifications
You must be signed in to change notification settings - Fork 934
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into luan.context-api
- Loading branch information
Showing
131 changed files
with
1,279 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Benchmark | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
benchmark: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: subosito/flutter-action@v2 | ||
- uses: bluefireteam/melos-action@v3 | ||
|
||
- uses: luanpotter/[email protected] | ||
with: | ||
paths: "packages/flame/" | ||
ignore-tag: "no-benchmark" | ||
is-flutter: true | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
```{toctree} | ||
:hidden: | ||
Debugging <debug.md> | ||
Utils <util.md> | ||
Widgets <widgets.md> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ environment: | |
sdk: ">=3.4.0 <4.0.0" | ||
|
||
dependencies: | ||
flame: ^1.22.0 | ||
flame: ^1.23.0 | ||
flutter: | ||
sdk: flutter | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ environment: | |
flutter: ">=3.24.0" | ||
|
||
dependencies: | ||
flame: ^1.22.0 | ||
flame: ^1.23.0 | ||
flutter: | ||
sdk: flutter | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ environment: | |
sdk: ">=3.4.0 <4.0.0" | ||
|
||
dependencies: | ||
flame: ^1.22.0 | ||
flame: ^1.23.0 | ||
flutter: | ||
sdk: flutter | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ environment: | |
flutter: ">=3.24.0" | ||
|
||
dependencies: | ||
flame: ^1.22.0 | ||
flame: ^1.23.0 | ||
flutter: | ||
sdk: flutter | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ environment: | |
|
||
dependencies: | ||
collection: ^1.16.0 | ||
flame: ^1.22.0 | ||
flame: ^1.23.0 | ||
flutter: | ||
sdk: flutter | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/extensions.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
class ImageBrightnessExample extends FlameGame { | ||
ImageBrightnessExample({ | ||
required this.brightness, | ||
}); | ||
|
||
final double brightness; | ||
|
||
static const String description = ''' | ||
Shows how a dart:ui `Image` can be brightened using Flame Image extensions. | ||
Use the properties on the side to change the brightness of the image. | ||
'''; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
final image = await images.load('flame.png'); | ||
final brightenedImage = await image.brighten(brightness / 100); | ||
|
||
add( | ||
SpriteComponent( | ||
sprite: Sprite(image), | ||
position: (size / 2) - Vector2(0, image.height / 2), | ||
size: image.size, | ||
anchor: Anchor.center, | ||
), | ||
); | ||
|
||
add( | ||
SpriteComponent( | ||
sprite: Sprite(brightenedImage), | ||
position: (size / 2) + Vector2(0, brightenedImage.height / 2), | ||
size: image.size, | ||
anchor: Anchor.center, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/extensions.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
class ImageDarknessExample extends FlameGame { | ||
ImageDarknessExample({ | ||
required this.darkness, | ||
}); | ||
|
||
final double darkness; | ||
|
||
static const String description = ''' | ||
Shows how a dart:ui `Image` can be darkened using Flame Image extensions. | ||
Use the properties on the side to change the darkness of the image. | ||
'''; | ||
|
||
@override | ||
Future<void> onLoad() async { | ||
final image = await images.load('flame.png'); | ||
final darkenedImage = await image.darken(darkness / 100); | ||
|
||
add( | ||
SpriteComponent( | ||
sprite: Sprite(image), | ||
position: (size / 2) - Vector2(0, image.height / 2), | ||
size: image.size, | ||
anchor: Anchor.center, | ||
), | ||
); | ||
|
||
add( | ||
SpriteComponent( | ||
sprite: Sprite(darkenedImage), | ||
position: (size / 2) + Vector2(0, darkenedImage.height / 2), | ||
size: image.size, | ||
anchor: Anchor.center, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import 'update_components_benchmark.dart'; | ||
|
||
Future<void> main() async { | ||
await UpdateComponentsBenchmark.main(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:benchmark_harness/benchmark_harness.dart'; | ||
import 'package:flame/components.dart'; | ||
import 'package:flame/game.dart'; | ||
|
||
const _amountComponents = 20; | ||
const _amountTicks = 1000; | ||
const _amountInputs = 100; | ||
|
||
class UpdateComponentsBenchmark extends AsyncBenchmarkBase { | ||
final Random random; | ||
|
||
late final FlameGame _game; | ||
late final List<_BenchmarkComponent> _components; | ||
late final List<double> _dts; | ||
late final Set<int> _inputTicks; | ||
|
||
UpdateComponentsBenchmark(this.random) | ||
: super('Updating Components Benchmark'); | ||
|
||
static Future<void> main() async { | ||
final r = Random(69420); | ||
await UpdateComponentsBenchmark(r).report(); | ||
} | ||
|
||
@override | ||
Future<void> setup() async { | ||
_game = FlameGame(); | ||
await _game.addAll( | ||
List.generate(_amountComponents, _BenchmarkComponent.new), | ||
); | ||
|
||
await _game.ready(); | ||
|
||
_components = | ||
_game.children.whereType<_BenchmarkComponent>().toList(growable: false); | ||
|
||
_dts = List.generate(_amountTicks, (_) => random.nextDouble()); | ||
_inputTicks = List.generate( | ||
_amountInputs, | ||
(_) => random.nextInt(_amountTicks), | ||
).toSet(); | ||
} | ||
|
||
@override | ||
Future<void> exercise() async { | ||
for (final (idx, dt) in _dts.indexed) { | ||
if (_inputTicks.contains(idx)) { | ||
_components[random.nextInt(_amountComponents)].input( | ||
xDirection: random.nextInt(3) - 1, | ||
doJump: random.nextBool(), | ||
); | ||
} | ||
_game.update(dt); | ||
} | ||
} | ||
} | ||
|
||
class _BenchmarkComponent extends PositionComponent { | ||
static const _groundY = -20.0; | ||
|
||
final int id; | ||
final Vector2 velocity = Vector2.zero(); | ||
|
||
_BenchmarkComponent(this.id); | ||
|
||
void input({ | ||
required int xDirection, | ||
required bool doJump, | ||
}) { | ||
// move x | ||
velocity.x = xDirection * 100; | ||
|
||
// jump | ||
if (position.y == _groundY) { | ||
velocity.y -= 100; | ||
} | ||
} | ||
|
||
@override | ||
void update(double dt) { | ||
super.update(dt); | ||
|
||
position.add(velocity * dt); | ||
velocity.add(Vector2(0, 10 * dt)); | ||
|
||
if (position.y > _groundY) { | ||
position.y = _groundY; | ||
velocity.setValues(0, 0); | ||
} | ||
} | ||
|
||
@override | ||
String toString() => '[Component $id]'; | ||
} |
Oops, something went wrong.