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

Deactivate synchronization for child nodes? #436

Open
Dirk-27 opened this issue Nov 9, 2023 · 9 comments
Open

Deactivate synchronization for child nodes? #436

Dirk-27 opened this issue Nov 9, 2023 · 9 comments

Comments

@Dirk-27
Copy link

Dirk-27 commented Nov 9, 2023

Is it possible to temporarily deactivate synchronization for the children of a node?

Background:
We have components that control child elements. If this component is synchronized, its child elements should not be controlled on the remote side.

@Dirk-27 Dirk-27 changed the title Deactivate synchronization? Deactivate synchronization for child nodes? Nov 9, 2023
@vincentfretin
Copy link
Member

networked entities are synchronized if you own them. To temporarily disable, I guess you could set the owner to "scene" or anything that is not your NAF.clientId.

But I didn't quite understand your use case, it seems you want a participant to control, so taking ownership and send the changes but forbid other participants to take ownership make changes?

@Dirk-27
Copy link
Author

Dirk-27 commented Nov 9, 2023

Thanks, we have components which control child elements:

<a-entity networked>
  <a-entity id="controlNode" ... controlchilds="">
     <a-entity id="child1" ... >
     </a-entity>
     <a-entity id="child2" ... >
     </a-entity>
  </a-entity>
</a-entity>

We want the host to control the remote "controlNode", but not the child of this node, because controlNode already controls them without synchronization.

@vincentfretin
Copy link
Member

All that is bit abstract. The above code is missing the networked template and schema. And I have no idea what controlschilds is doing.
Did I answer your question about the ownership? If not, please provide a more complete example to discuss it further.

@Dirk-27
Copy link
Author

Dirk-27 commented Nov 9, 2023

controlchilds is an aframe component that combines a-entities to construct an element such as a canopy. For example, it controls the position and size of the child nodes such as the height of the beam(s). If we write controlchilds="width:2; height:2.2", then controlchild sets this value for some children.

When the controlchilds component is synchronized in the remote client, it is not necessary to synchronize the already controlled children.

We want to specify that some children (and some attributes) are temporarily not synchronized because we know that other elements are already doing so.

@vincentfretin
Copy link
Member

Maybe you can add controlchilds in the networked schema (with the correct selector), and add a prop synced:boolean to controlchilds. When a networked entity in synced, it will call the update method in your controlchilds component, if synced is false, then don't do any update of your children.

@Dirk-27
Copy link
Author

Dirk-27 commented Nov 9, 2023

Thanks, we did it this way:

AFRAME.components.networked.Component.prototype.updateNetworkedComponents = function(components) {
      for (var componentIndex = 0, l = this.componentSchemas.length; componentIndex < l; componentIndex++) {
        var componentData = components[componentIndex];
        var componentSchema = this.componentSchemas[componentIndex];
        var componentElement = this.getCachedElement(componentIndex);


        if (this.skipComponentUpdate) {
          /*
            Some kind of check to skip updates for specific elements and components.
            To allow manual component updates the bufferInfo entry needs to be removed.
          */
          continue;
        }
(...)

Additional we have to remove the bufferInfo for the element. Otherwise it is in the remote client not possible to manipulate the component.

It looks like this is one solution. When there is a way to avoid the messages from the host that may be a better solution. What do you think?

But in the meantime it works this way.

Many thanks!

@vincentfretin
Copy link
Member

This is hacky but yeah that works and it avoid sending any changes at all. My proposed solution was still sending changes but ignored on the receiving side.

If you want to disable sending update at the component level, you can define your own function to use in requiresNetworkUpdate for the component in your networked schema, like the vectorRequiresUpdate function, see https://github.com/networked-aframe/networked-aframe#syncing-components-optimization

@vincentfretin
Copy link
Member

This is what I have in mind with a synced prop that you add to your controlchilds component (not tested):

// Same function as in networked.js but it is not exported so we need to define again.
// You also need to define deepEqual (see DeepEquals.js:equal)
function defaultRequiresUpdate() {
  let cachedData = null;

  return (newData) => {
    if (cachedData === null || !deepEqual(cachedData, newData)) {
      cachedData = AFRAME.utils.clone(newData);
      return true;
    }

    return false;
  };
}

const componentRequiresUpdate = () => {
  return data => {
    return data.synced && defaultRequiresUpdate(data)
  };
};

// schema
{
  template: '#my-template',
  components: [
    {
      component: 'controlchilds',
      requiresNetworkUpdate: componentRequiresUpdate
    }
  ]
}

@Dirk-27
Copy link
Author

Dirk-27 commented Nov 9, 2023

Ok, thanks, we will test it.

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

No branches or pull requests

2 participants