Repository navigation
Conversation
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A hot reload keeps the state of the game, but most of the code of a Flame game runs once, in constructors and
onLoad. Changing a speed, a size or which components a level adds therefore only shows after a hot restart, which loses the state.This adds
flame reload --merge, a hot reload that also applies those changes to the live components while they keep their state. It works as a three way merge:getObject), so custom classes need no setup.evaluate. Values that differ between the two old shadows aren't deterministic, for example random ones, and are ignored. When the live value changed at runtime too, the code wins and the conflict is reported, or--keep-runtimekeeps the live value.setFrom, then replacing the elements of a collection, and lastly plain assignment. That way a finalNotifyingVector2is set throughTransform2D.positionand the listeners are notified.Changes in
flame:Component.debugDeclarationIndex, set in debug mode, is the order in which a component was added to its parent before the parent was mounted. It separates declared components from runtime spawns, and matches shadow components to live ones exactly.HotReloadConnector: builds the shadows, describes the trees, and adopts and removes components.FlameGame.isHotReloadShadow: user code can check it to skip side effects in shadows. A shadow doesn't take over the DevTools connection.Changes in
flame_cli:lib/src/merge/tree_match.dart: matches the trees. Old to live is matched exactly by declaration index. Old to new is aligned like a text diff, with a weighted longest common subsequence over types and position hints, and namedComponentKeys are paired first.lib/src/merge/merge.dart: the merge rules, against a reader and a writer interface.lib/src/merge/heap.dart: the VM service reader and writer.I tested it end to end on the
flutter-testerdevice with a small game:speed,state.hp, a finalListin a plain user class, and aRectangleComponentsize were merged. A newCircleComponentwas added. The moving player kept its runtime position, and a runtime-spawned component was untouched.Known limitations, to follow up on:
onLoadto a parent that is already mounted, for example a HUD added to the viewport from the world, counts as a runtime spawn.SingleGameInstancegames are not supported.Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Related to #4131