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

New logic tree variable system #2439

Merged
merged 13 commits into from
Feb 26, 2022

Conversation

MoritzBrueckner
Copy link
Collaborator

@MoritzBrueckner MoritzBrueckner commented Feb 21, 2022

Fixes #2434.

What started as an attempt to fix a simple issue became an almost complete rewrite of the logic ID system. Previously it was easily possible to create a few different situations where the correctness of the exported logic tree was completely violated or at least depending on external things such as iteration orders when exporting nodes:

  • if multiple variable nodes shared the same values, only one random node was exported, so the initial value was undefined if the nodes had different values.
  • it was possible to use the same logic ID for nodes with different types. Because all linked nodes were replaced with the exported node of another type, this could lead to runtime exceptions/type errors in other places of the tree.
  • the above also happened with the dynamic getter/setter nodes, which caused the linked issue.

New Tree Variables panel

Now, the logic ID is no longer directly accessible, instead the user has to promote variable nodes to tree variable nodes to let them share data. So if a variable node is linked to a tree variable, it shares its values with all other variable nodes that are linked to the same tree variable. A variable node does not have to be linked to a tree variable, in this case it acts for its own, just as before if the logic ID was unset.

In one sentence: if the variable node has no logic ID, all stays as it was before. If it has one set, the logic ID acts as a reference for a tree variable.

Files that are saved before SDK 2022.03 will be automatically upgraded to the new system (assuming that the version number of the SDK in the code will be bumped for the release), apart from the fact that the initial value may be affected by said race conditions.

Technical explanation of the new system:

A tree variable stores the type of the variable node to ensure correctness, and it uses one linked node (internally called the "master node") to actually store the variable values. This node is also used to show the variable values in the UI in the side panel, and the master node automatically synchronizes its values with all other nodes that are linked to the same variable (called "replica nodes" in the code). The user doesn't need to know about this concept, it is all done in the background and it even works to copy tree variable nodes between trees, there is always only one master node for each tree var, and for each variable node with a logic ID in the tree there will be a tree variable automatically. If there is no linked node left for a tree variable, the tree variable is removed.

In case this short paragraph is too briefly explained, there is a more detailed explanation in arm_nodes.py :)

User perspective:

The following operators are relevant for the user:

  • New Var From Node: creates a new tree variable for the selected variable node. This operator is not visible in the screenshot above, as it shares its position based on the selected node with the next operator, namely...
  • ...Make Node Local: unlinks the selected variable node from the selected tree variable. If the selected node was the last to link to the tree variable, the tree variable is removed.
  • Assign To Node: link the selected variable node to the selected tree variable.
  • Add Getter/Add Setter: as before, just that the getter/setter nodes are no longer dynamic but typed the same as the variable.

The tree variables have a color that is automatically synchronized with their linked nodes, and the name of the tree variable is shown in the node's body and header instead of the input sockets and other settings (which are now only editable in the sidebar if the node is linked, because the master node needs to be edited):

Linked tree variable node

The name of a tree variable can be edited by double clicking on it in the sidebar list.

Thanks a lot to @QuantumCoderQC for the helpful discussions and ideas on Discord!

@MoritzBrueckner MoritzBrueckner added Release Notes: Fixes A pull request that fixes something. Used to generate release notes. Release Notes: Changes A pull request that is a feature change, not a fix. Used to generate release notes. labels Feb 21, 2022
@QuantumCoderQC
Copy link
Contributor

Awesome work!!

I just wanted to point out that the Transform node cannot be promoted to a Tree Variable. Was this intentional?

@MoritzBrueckner
Copy link
Collaborator Author

Ah no, this wasn't intentional, thanks for mentioning this :) I will add another commit tomorrow.

@luboslenco luboslenco merged commit 932476c into armory3d:master Feb 26, 2022
@luboslenco
Copy link
Member

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release Notes: Changes A pull request that is a feature change, not a fix. Used to generate release notes. Release Notes: Fixes A pull request that fixes something. Used to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic getter node not correctly initialized
3 participants