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

[3.x] Increase VARIANT_ARG_MAX to 8 #54188

Merged
merged 1 commit into from
Mar 8, 2022

Conversation

Rubonnek
Copy link
Member

Fixes:

Aside from the issues above, the other reason for increasing VARIANT_ARG_MAX to 8 is because it was done on master already to fix similar issues.

See:

@Rubonnek Rubonnek requested review from a team as code owners October 24, 2021 11:38
@Rubonnek Rubonnek added this to the 3.5 milestone Oct 24, 2021
@Rubonnek Rubonnek requested a review from a team as a code owner October 24, 2021 12:30
@Rubonnek Rubonnek force-pushed the increase_var_arg_max_3x branch 2 times, most recently from 0ede2d8 to 0b362c1 Compare December 27, 2021 14:55
@Rubonnek
Copy link
Member Author

Updated a code block in AnimationTree that also depends on VARIANT_ARG_MAX.

I should say that this pull request now also allows users to call TileMap.set_cell successfully through an AnimationPlayer and AnimationTree, given that the we are now able to pass the number of parameters required to properly call such functions.

Comment on lines +559 to +560
static_assert(VARIANT_ARG_MAX == 8, "PROPERTY_HINT_RANGE needs to be updated if VARIANT_ARG_MAX != 8");
p_list->push_back(PropertyInfo(Variant::INT, "arg_count", PROPERTY_HINT_RANGE, "0,8,1"));
Copy link
Member

Choose a reason for hiding this comment

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

We discussed this in a PR review meeting and we're not sure it's worth changing the whole VARIANT_ARG_MAX just for this - the limit on animation code doesn't seem related to VARIANT_ARG_MAX and could likely be lifted to allow any number of arguments, no?

Copy link
Member Author

@Rubonnek Rubonnek Jan 7, 2022

Choose a reason for hiding this comment

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

In this code the user is modifying a key within a method-type track of an Animation, right? The number of arguments for a method-type track in an Animation is bound by the maximum number of arguments the AnimationPlayer itself supports when playing this track. VARIANT_ARG_MAX is related. I fail to see how it could not. Keep an eye on Animation::TYPE_METHOD.

When the AnimationPlayer attempts to play the method-type track, it will run the following code (only pay attention to the first line, the last line, and params near the bottom):

case Animation::TYPE_METHOD: {
if (!nc->node) {
continue;
}
if (p_delta == 0) {
continue;
}
if (!p_is_current) {
break;
}
List<int> indices;
a->method_track_get_key_indices(i, p_time, p_delta, &indices);
for (List<int>::Element *E = indices.front(); E; E = E->next()) {
StringName method = a->method_track_get_name(i, E->get());
Vector<Variant> params = a->method_track_get_params(i, E->get());
int s = params.size();
ERR_CONTINUE(s > VARIANT_ARG_MAX);

The very last line of that code block has a direct reference to VARIANT_ARG_MAX. That check is there because further below AnimationPlayer reconstructs the method call extracted from the track:

if (method_call_mode == ANIMATION_METHOD_CALL_DEFERRED) {
MessageQueue::get_singleton()->push_call(
nc->node,
method,
s >= 1 ? params[0] : Variant(),
s >= 2 ? params[1] : Variant(),
s >= 3 ? params[2] : Variant(),
s >= 4 ? params[3] : Variant(),
s >= 5 ? params[4] : Variant());
} else {
nc->node->call(
method,
s >= 1 ? params[0] : Variant(),
s >= 2 ? params[1] : Variant(),
s >= 3 ? params[2] : Variant(),
s >= 4 ? params[3] : Variant(),
s >= 5 ? params[4] : Variant());
}

The params array holds the number of arguments previously saved on the track through the AnimationTrackEditor. Everytime VARIANT_ARG_MAX is updated, that last code block needs to be updated to support the maximum number of arguments.

Copy link
Member Author

Choose a reason for hiding this comment

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

@akien-mga is there anything holding back this PR?

For what is worth, sure, we could remove the limit on this referenced code but that doesn't mean the AnimationPlayer can execute the saved tracks -- that's what ties VARIANT_ARG_MAX to the code you've referenced.

int args = 0;
if (p_arg5.get_type() != Variant::NIL) {
if (p_arg7.get_type() != Variant::NIL) {
Copy link
Member

Choose a reason for hiding this comment

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

Missing p_arg8.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed,

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Discussed in PR review meeting, we're slightly concerned about the potential performance impact but given the places where it's used, it should be fine.

For Godot 4.0, this needs to be changed to use variadic templates so we can dehardcode things properly.

@akien-mga akien-mga merged commit 85b4848 into godotengine:3.x Mar 8, 2022
@akien-mga
Copy link
Member

Thanks!

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.

Unable to configure functions with more than five parameters in AnimationTrack
3 participants