Skip to content

Serialization: Reuse SerializedBlock resources #137

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

Merged
merged 6 commits into from
Jul 18, 2024
Merged

Conversation

manuq
Copy link
Contributor

@manuq manuq commented Jul 16, 2024

Add a resource property to blocks of type SerializedBlock. The resource will be updated before building the tree.

This mitigates having a huge diff in scenes with blocks for minimum changes like moving a block in the canvas.

https://phabricator.endlessm.com/T35565

@manuq
Copy link
Contributor Author

manuq commented Jul 16, 2024

We can do something similar to SerializedBlockTreeNode and SerializedBlockTreeNodeArray. But this totally breaks the undo/redo. The benefit of having the tree of resources being rebuilt each time is that it makes undo/redo so trivial. So marking this as draft for now.

if resource == null:
resource = SerializedBlock.new()
resource.block_class = get_block_class()
resource.serialized_props = get_serialized_props()
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to have this check if there are changes and return a boolean indicating that. That might help with the undo/redo functionality as there's no reason to add a change point if nothing has changed. Otherwise I think you'd have to pass the EditorUndoRedoManager into here.

@dbnicholson
Copy link
Member

I certainly like that. Can you pass the EditorUndoRedoManager down through get_canvas_block_trees?

@manuq manuq force-pushed the improve-serialization branch 2 times, most recently from 496572d to 5b8c349 Compare July 16, 2024 17:16
@manuq
Copy link
Contributor Author

manuq commented Jul 16, 2024

I certainly like that. Can you pass the EditorUndoRedoManager down through get_canvas_block_trees?

Good point, yes I did so. Now the undo/redo works with block properties, like changing a parameter or moving the block to another position.

Then I tried to do the same for the children blocks (path_child_pairs), but is not behaving correctly. I'm running out of ideas, it seems to be the tree being built recursively. Any help welcome!

Comment on lines 144 to 147
if generated_script != block_script.generated_script:
undo_redo.add_undo_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script)
block_script.generated_script = generated_script
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script)
Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't be changing the generated_script property on our own here, and we should consistently use the var block_script: BlockScriptData we defined earlier:

Suggested change
if generated_script != block_script.generated_script:
undo_redo.add_undo_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script)
block_script.generated_script = generated_script
undo_redo.add_do_property(_current_block_code_node.block_script, "generated_script", _current_block_code_node.block_script.generated_script)
if generated_script != block_script.generated_script:
undo_redo.add_undo_property(block_script, "generated_script", block_script.generated_script)
undo_redo.add_do_property(block_script, "generated_script", generated_script)

Copy link
Contributor

Choose a reason for hiding this comment

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

Turns out we're doing this in a lot of places. I included this and a bunch of similar fixes in #140.

@@ -38,6 +38,8 @@ var zoom: float:
get:
return _window.scale.x

var _undo_redo: EditorUndoRedoManager
Copy link
Member

Choose a reason for hiding this comment

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

Personally I would just pass this down in to build_tree rather than stashing it in the object. It's only called internally to this object, so there's no danger of it breaking another user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I though about that, I did it like this because is also used in the build_tree() method that's called recursively. But yes it can be passed around to build_tree() as parameter.

@manuq manuq force-pushed the improve-serialization branch from 48bf072 to f079f18 Compare July 17, 2024 11:58
@manuq manuq marked this pull request as ready for review July 17, 2024 11:59
@manuq
Copy link
Contributor Author

manuq commented Jul 17, 2024

This is now ready for review thanks to @dylanmccall fixes. The undo-redo is now piling actions to the history instead of going back as before. I couldn't find how to fix it. But is usable (can undo, can redo).

@manuq manuq force-pushed the improve-serialization branch from f079f18 to eb1f780 Compare July 17, 2024 12:03
@manuq
Copy link
Contributor Author

manuq commented Jul 17, 2024

This is now ready for review thanks to @dylanmccall fixes. The undo-redo is now piling actions to the history instead of going back as before. I couldn't find how to fix it. But is usable (can undo, can redo).

The undo-redo piling actions was an issue in the input parameter, fixed in: #142

func update_resources(undo_redo: EditorUndoRedoManager):
if resource == null:
resource = SerializedBlockTreeNode.new()
resource.serialized_block = SerializedBlock.new(get_block_class(), get_serialized_props())
Copy link
Member

Choose a reason for hiding this comment

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

I think you can return early here. There's no need to compare the serialized properties again if the serialized block was just constructed with them.

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 added a fixup commit for this. Hopefully it won't conflict with Dylan's changes in the same function when automerging.

Copy link
Member

@dbnicholson dbnicholson left a comment

Choose a reason for hiding this comment

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

Looks good to me. From my perspective, feel free to merge after squashing the fixup.

manuq and others added 6 commits July 18, 2024 12:32
Add a resource property to blocks. The resource will be updated before
building the tree.

This mitigates having a huge diff in scenes with blocks for minimum
changes like moving a block in the canvas.
In block_canvas.gd, instead of modifying _current_bsd.block_trees.array
outside of the UndoRedo action, use add_undo_property and
add_do_property.
@manuq manuq force-pushed the improve-serialization branch from 261f08d to 22ef121 Compare July 18, 2024 15:32
@manuq manuq merged commit 3cf47d0 into main Jul 18, 2024
2 checks passed
@manuq manuq deleted the improve-serialization branch July 18, 2024 15:33
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.

3 participants