Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Option to use toImageSync in ImageComposition class #2593

Merged

Conversation

ASGAlex
Copy link
Contributor

@ASGAlex ASGAlex commented Jun 28, 2023

Description

Added ImageComposition.composeSync() function

Checklist

  • I have followed the [Contributor Guide] when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Related Issues

Closes #2315

doc/flame/rendering/images.md Outdated Show resolved Hide resolved
doc/flame/rendering/images.md Outdated Show resolved Hide resolved
packages/flame/lib/src/parallax.dart Show resolved Hide resolved
packages/flame/lib/src/sprite.dart Outdated Show resolved Hide resolved
ASGAlex and others added 5 commits June 29, 2023 12:25
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
@@ -55,6 +55,7 @@ extension ParallaxExtension on Game {
ImageRepeat repeat = ImageRepeat.repeatX,
Alignment alignment = Alignment.bottomLeft,
LayerFill fill = LayerFill.height,
bool composeSync = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to expose this option to the user, or what would be the reason for that?
Can we get a runtime crash if using the sync method when it starts rendering and the rasterization isn't done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory - yes, we can. But I used it everywhere since this feature introduction and never had any problems.
From perfectionists point of view - if we decide to use Sync everywhere, draw exception also should be catched everywhere in render methods, but I'm in doubts how to catch a thing I had never seen and have no idea how to reproduce..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's skip this Boolean and just use sync then. So the sync method is pretty much fire and forget then, if it has no impact on parallelization like you say?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed that, maybe you have launched my demo projects with alternative collision system recently - there is a lot of toImageSync operations per update, and everything works fine even in browser.
Also Flutter team promizes that everything should be async under hood: https://api.flutter.dev/flutter/dart-ui/Picture/toImageSync.html. I hope we can beleive them :-)
Of course I'd prefer to use more performant implementation instead old async version everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can switch this boolean to true by default in case if somebody will have an issue with that. After some time without bugreports we could to remove option completely. I see your point that unnecessary code is not good thing, but on other hand I am not a representative enougth, if somebody will have any problems with Sync on specific devices - he could just change the flag in constructor, without needing to fork whole framework to change just one line of code...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do the other way around instead, let's skip this code for now and if people report bugs regarding it we'll introduce the boolean again.

doc/flame/rendering/images.md Outdated Show resolved Hide resolved
/// detailed description of possible benefits in performance.
Image toImageSync() {
final composition = ImageComposition()
..add(image, Vector2.zero(), source: src);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Vector2.zero should be possible to add as a static on this class instead, so that it doesn't need to be recreated for every call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

ASGAlex and others added 3 commits June 29, 2023 22:38
Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com>
…age_sync_support' into asgalex/image_composition_to_image_sync_support
@spydon spydon merged commit 66d5f97 into flame-engine:main Jun 29, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to use toImageSync in ImageComposition class
2 participants