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

Added signals to AnimationNodeStateMachine #30508

Closed
wants to merge 1 commit into from
Closed

Added signals to AnimationNodeStateMachine #30508

wants to merge 1 commit into from

Conversation

jedStevens
Copy link

Sorry for re-opening this PR but I royally screwed the last one (#24328) so please forgive me; it's been recently closed in favor of this PR.

This should expose the from_state and to_state when an AnimationNodeStateMachine changes states. This should allow for a more direct control with AnimationTrees; by setting "advance parameters" in the tree, there can be a response when the signal is emitted.

I welcome any additional testing but this works on my machine quite well and I can't seem to find errors. Let me know if you can.

@Sslaxx
Copy link

Sslaxx commented Jul 11, 2019

Again: it'd be nice to have more descriptive signal names for this than state_changed.

@akien-mga akien-mga added this to the 3.2 milestone Jul 11, 2019
@akien-mga akien-mga requested a review from reduz July 11, 2019 07:28
float AnimationNodeStateMachine::process(float p_time, bool p_seek) {

Ref<AnimationNodeStateMachinePlayback> playback = get_parameter(this->playback);
ERR_FAIL_COND_V(playback.is_null(), 0.0);

if (!playback->is_connected("state_changed", this, "_on_playback_state_changed")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder whether it's possible to simply connect the state_changed signal whenever AnimationNodeStateMachinePlayback is assigned to state machine rather than checking this in process, though I don't see an easy way to assign it here. Perhaps it should be handled somewhere in _set('parameters/playback', playback).

AnimationNodeStateMachinePlayback is also not shared between instances by default, so I wonder whether it's by design and if it makes sense to create and assign a different playback resource at all:

AnimationNodeStateMachinePlayback::AnimationNodeStateMachinePlayback() {
    set_local_to_scene(true); //only one per instanced scene
    // ...
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be the only place that instances playback resource:

Variant AnimationNodeStateMachine::get_parameter_default_value(const StringName &p_parameter) const {

	if (p_parameter == playback) {
		Ref<AnimationNodeStateMachinePlayback> p;
		p.instance();
                // Connect here?
		// p->connect("state_changed", this, "_on_playback_state_changed"));
		return p;
	} else {
		return false; //advance condition
	}
}

Copy link
Author

Choose a reason for hiding this comment

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

Ok I'll try a version where it connects here and run my tests to see

Choose a reason for hiding this comment

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

@Xrayez @jedStevens I've got a working version where the connection is made in AnimationNodeStateMachine::get_parameter_default_value() and also in AnimationNodeStateMachine::_set(). Note that this requires AnimationNodeStateMachine::get_parameter_default_value() to no longer be a const method.

Is it possible for me to push my changes to this PR or do I need to open a new one?

@jedStevens
Copy link
Author

@Sslaxx I was just taking a look and I'm curious as to which signals you might have been hinting at. My simple test seems to work with this current implementation. I'm unsure of what you meant specifically was all.

@Xrayez
Copy link
Contributor

Xrayez commented Jul 11, 2019

Perhaps "more descriptive" means answering the question of whether the signal is fired before the actual state is about to be changed, or is it actually changed already. But that should be reflected in documentation if that's the case.

@jedStevens
Copy link
Author

I suppose since it is the line just before the actual assignment, this could cause errors. I can modify it so that it temporarily stores the previous state and emit the signal after the assignment to not cause any confusion about if it's been changed or not.

Copy link

@JohnodonCode JohnodonCode left a comment

Choose a reason for hiding this comment

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

yess

@aaronfranke
Copy link
Member

@jedStevens Is this still desired? If so, it needs to be rebased on the latest master branch.

@aaronfranke
Copy link
Member

The repository this PR comes from has been deleted, so this PR is no longer valid. Closing.

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

Successfully merging this pull request may close these issues.

8 participants