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

Include extensions in the call ordering of notifications #5585

Closed
CedNaru opened this issue Oct 14, 2022 · 4 comments · Fixed by godotengine/godot#78634
Closed

Include extensions in the call ordering of notifications #5585

CedNaru opened this issue Oct 14, 2022 · 4 comments · Fixed by godotengine/godot#78634

Comments

@CedNaru
Copy link

CedNaru commented Oct 14, 2022

Describe the project you are working on

Godot Kotlin, Godot Fmod

Describe the problem or limitation you are having in your project

Extensions are supposed to behave the same way native classes do in Godot core or a module. But currently, extensions are the last to receive notifications in all cases.
image

When reversed is true, it won't result in the correct behavior. In a chain of class A(native) ==> B(native) => C(extension).
The call order will be B, A, C instead of C, B, A.

Update:
The call order should also take into account the inheritance chain in extensions and scripts so they should also accept reversed as a parameter.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Simply add a condition that checks the value of reversed and notify the extension before everything else when it applies.

That change could also apply to scripts but I am not sure about potential side effects.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Extensions only:

void Object::notification(int p_notification, bool p_reversed) {
	if (p_reversed) { 
	    if (_extension && _extension->notification) {
		    _extension->notification(_extension_instance, p_notification, p_reversed);
	    }
        }

	_notificationv(p_notification, p_reversed);

	if (!p_reversed) { 
	  if (_extension && _extension->notification) {
		  _extension->notification(_extension_instance, p_notification, p_reversed);
	  }
        }

	if (script_instance) {
		script_instance->notification(p_notification);
	}
}

With Scripts:

void Object::notification(int p_notification, bool p_reversed) {
	if (p_reversed) { 
	    if (script_instance) {
		    script_instance->notification(p_notification, p_reversed);
	    }
    
	    if (_extension && _extension->notification) {
		    _extension->notification(_extension_instance, p_notification, p_reversed);
	    }
        }

	_notificationv(p_notification, p_reversed);

	if (!p_reversed) { 
	  if (_extension && _extension->notification) {
		  _extension->notification(_extension_instance, p_notification, p_reversed);
	  }

	  if (script_instance) {
		  script_instance->notification(p_notification, p_reversed);
	  }
        }
}

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, it's an Object behavior.

Is there a reason why this should be core and not an add-on in the asset library?

No, it's an Object behavior.

@kleonc
Copy link
Member

kleonc commented Oct 14, 2022

Personally I think that's a bug, already reported it: godotengine/godot#52325.

@CedNaru
Copy link
Author

CedNaru commented Oct 14, 2022

I didn't know about that issue. But reading it it seems that I forgot to take into account the chain of inheritance in extensions and scripts too. I guess I should update the proposal and add that the reversed parameter should also be passed to extensions and scripts.

@kleonc
Copy link
Member

kleonc commented Oct 14, 2022

Also note that currently in your suggested changes you have the conditions swapped:

  • if (!p_reversed) should be if (p_reversed),
  • if (p_reversed) should be if (!p_reversed).

In this regard Object::notification's docs seem to be correct about what p_reversed parameter mean:
https://github.com/godotengine/godot/blob/c97afc033f720a68b3ea8dabb2956d836d13613e/doc/classes/Object.xml#L467

At least that's how p_reversed is treated in Object::_notificationv (m_inherits is a base class of the given class):
https://github.com/godotengine/godot/blob/c97afc033f720a68b3ea8dabb2956d836d13613e/core/object/object.h#L446-L456

@CedNaru
Copy link
Author

CedNaru commented Oct 14, 2022

True. I naively copied the ifs in Object::_notificationv without much thinking. It should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants