-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -596,6 +596,13 @@ void CanvasItem::_notification(int p_what) { | |
case NOTIFICATION_VISIBILITY_CHANGED: { | ||
emit_signal(SceneStringNames::get_singleton()->visibility_changed); | ||
} break; | ||
case NOTIFICATION_WORLD_2D_CHANGED: { | ||
_exit_canvas(); | ||
_enter_canvas(); | ||
if (get_script_instance()) { | ||
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_world_2d_changed, nullptr, 0); | ||
} | ||
} break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
} | ||
|
||
|
@@ -1199,6 +1206,7 @@ void CanvasItem::_bind_methods() { | |
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); | ||
BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS); | ||
BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS); | ||
BIND_CONSTANT(NOTIFICATION_WORLD_2D_CHANGED); | ||
} | ||
|
||
Transform2D CanvasItem::get_canvas_transform() const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,27 @@ void CollisionObject2D::_notification(int p_what) { | |
Physics2DServer::get_singleton()->body_attach_canvas_instance_id(rid, 0); | ||
} | ||
} break; | ||
|
||
case NOTIFICATION_WORLD_2D_CHANGED: { | ||
Transform2D global_transform = get_global_transform(); | ||
|
||
if (area) { | ||
Physics2DServer::get_singleton()->area_set_transform(rid, global_transform); | ||
} else { | ||
Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, global_transform); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
RID space = get_world_2d()->get_space(); | ||
if (area) { | ||
Physics2DServer::get_singleton()->area_set_space(rid, space); | ||
} else { | ||
Physics2DServer::get_singleton()->body_set_space(rid, space); | ||
} | ||
|
||
_update_pickable(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same with |
||
|
||
//get space | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra comment to be removed. |
||
} break; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
if (is_inside_tree()) { | ||
current_canvas = find_world_2d()->get_canvas(); | ||
VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); | ||
|
@@ -1057,6 +1061,29 @@ void Viewport::_propagate_enter_world(Node *p_node) { | |
} | ||
} | ||
|
||
void Viewport::_propagate_world_2d_changed(Node *p_node) { | ||
if (p_node != this) { | ||
if (!p_node->is_inside_tree()) { //may not have entered scene yet | ||
return; | ||
} | ||
|
||
if (Object::cast_to<CanvasItem>(p_node)) { | ||
p_node->notification(CanvasItem::NOTIFICATION_WORLD_2D_CHANGED); | ||
} else { | ||
Viewport *v = Object::cast_to<Viewport>(p_node); | ||
if (v) { | ||
if (v->world_2d.is_valid()) { | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (int i = 0; i < p_node->get_child_count(); i++) { | ||
_propagate_world_2d_changed(p_node->get_child(i)); | ||
} | ||
} | ||
|
||
void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) { | ||
p_node->notification(p_what); | ||
for (int i = 0; i < p_node->get_child_count(); i++) { | ||
|
There was a problem hiding this comment.
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.