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

Propogate previously unused NOTIFICATION_WORLD_2D_CHANGED, make CanvasItem/Camera2D/CollisionObject2D use it #52761

Closed

Conversation

spacechase0
Copy link
Contributor

@spacechase0 spacechase0 commented Sep 17, 2021

(Fixes #52423)

I'm not sure how do this in the master branch. I see in the comment in the PR template saying to do things for master first - if I could get some guidance on that, I would appreciate it.

…sItem/Camera2D/CollisionObject2D use it to fix godot/godotengine#52423
Copy link
Contributor

@pouleyKetchoupp pouleyKetchoupp left a comment

Choose a reason for hiding this comment

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

Thanks for contributing this fix!

It looks like it makes sense to handle world changes in 2D, although I haven't tested yet. I've left some comments on parts of the code that need to be a bit different from 3D logic, since entering/leaving worlds doesn't work the same in 2D and 3D.

Two other things that are needed before a possible approval:

@@ -1017,6 +1017,10 @@ void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) {

_update_listener_2d();

if (is_inside_tree()) {
_propagate_world_2d_changed(this);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be only called if the previous world is valid, otherwise it's going to do some unnecessary extra processing.


_setup_viewport();
_update_scroll();
} break;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this whole case really needed? It doesn't look like it's doing any world-related logic.

if (get_script_instance()) {
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_world_2d_changed, nullptr, 0);
}
} break;
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like this whole block is necessary (but I could be missing something).

From what I understand, only this modified code from _enter_canvas() seems really necessary (to be tested):

if (!canvas_layer) {
	RID canvas = get_viewport()->find_world_2d()->get_canvas();
	VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just those lines you suggested did not work (on master, working on this now - opening a new PR soon). I'm not sure what in _exit_canvas()/_enter_cavnas() makes it work, but trying just the snippet in your comment made it where the circle under the character did not move with it graphically.

Physics2DServer::get_singleton()->area_set_transform(rid, global_transform);
} else {
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think setting the transform is really necessary (unless I'm missing something).

Only setting the new space from the 2D world should be necessary.

Physics2DServer::get_singleton()->body_set_space(rid, space);
}

_update_pickable();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with _update_pickable(), from what I can see it doesn't seem to depend on the world.


_update_pickable();

//get space
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra comment to be removed.

@spacechase0
Copy link
Contributor Author

(Made a new PR that is for master, closing this one.)

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.

5 participants