Removed strange custom world2d in CanvasLayer, been there since always and not sure why.

Fixes #17524, fixes #17523.
This commit is contained in:
Juan Linietsky 2018-04-07 19:42:11 -03:00
parent cd7e9d9642
commit 9e7cee2ceb
4 changed files with 30 additions and 27 deletions

View File

@ -412,7 +412,7 @@ void CanvasItem::_enter_canvas() {
RID canvas; RID canvas;
if (canvas_layer) if (canvas_layer)
canvas = canvas_layer->get_world_2d()->get_canvas(); canvas = canvas_layer->get_canvas();
else else
canvas = get_viewport()->find_world_2d()->get_canvas(); canvas = get_viewport()->find_world_2d()->get_canvas();
@ -860,7 +860,7 @@ RID CanvasItem::get_canvas() const {
ERR_FAIL_COND_V(!is_inside_tree(), RID()); ERR_FAIL_COND_V(!is_inside_tree(), RID());
if (canvas_layer) if (canvas_layer)
return canvas_layer->get_world_2d()->get_canvas(); return canvas_layer->get_canvas();
else else
return get_viewport()->find_world_2d()->get_canvas(); return get_viewport()->find_world_2d()->get_canvas();
} }
@ -881,9 +881,7 @@ Ref<World2D> CanvasItem::get_world_2d() const {
CanvasItem *tl = get_toplevel(); CanvasItem *tl = get_toplevel();
if (tl->canvas_layer) { if (tl->get_viewport()) {
return tl->canvas_layer->get_world_2d();
} else if (tl->get_viewport()) {
return tl->get_viewport()->find_world_2d(); return tl->get_viewport()->find_world_2d();
} else { } else {
return Ref<World2D>(); return Ref<World2D>();

View File

@ -72,7 +72,7 @@ void ParallaxLayer::_update_mirroring() {
ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent()); ParallaxBackground *pb = Object::cast_to<ParallaxBackground>(get_parent());
if (pb) { if (pb) {
RID c = pb->get_world_2d()->get_canvas(); RID c = pb->get_canvas();
RID ci = get_canvas_item(); RID ci = get_canvas_item();
Point2 mirrorScale = mirroring * get_scale(); Point2 mirrorScale = mirroring * get_scale();
VisualServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirrorScale); VisualServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirrorScale);

View File

@ -35,7 +35,7 @@ void CanvasLayer::set_layer(int p_xform) {
layer = p_xform; layer = p_xform;
if (viewport.is_valid()) if (viewport.is_valid())
VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas->get_canvas(), layer); VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas, layer);
} }
int CanvasLayer::get_layer() const { int CanvasLayer::get_layer() const {
@ -48,7 +48,7 @@ void CanvasLayer::set_transform(const Transform2D &p_xform) {
transform = p_xform; transform = p_xform;
locrotscale_dirty = true; locrotscale_dirty = true;
if (viewport.is_valid()) if (viewport.is_valid())
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
} }
Transform2D CanvasLayer::get_transform() const { Transform2D CanvasLayer::get_transform() const {
@ -61,7 +61,7 @@ void CanvasLayer::_update_xform() {
transform.set_rotation_and_scale(rot, scale); transform.set_rotation_and_scale(rot, scale);
transform.set_origin(ofs); transform.set_origin(ofs);
if (viewport.is_valid()) if (viewport.is_valid())
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
} }
void CanvasLayer::_update_locrotscale() { void CanvasLayer::_update_locrotscale() {
@ -133,11 +133,6 @@ Vector2 CanvasLayer::get_scale() const {
return scale; return scale;
} }
Ref<World2D> CanvasLayer::get_world_2d() const {
return canvas;
}
void CanvasLayer::_notification(int p_what) { void CanvasLayer::_notification(int p_what) {
switch (p_what) { switch (p_what) {
@ -153,14 +148,14 @@ void CanvasLayer::_notification(int p_what) {
ERR_FAIL_COND(!vp); ERR_FAIL_COND(!vp);
viewport = vp->get_viewport_rid(); viewport = vp->get_viewport_rid();
VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas->get_canvas()); VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas);
VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas->get_canvas(), layer); VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas, layer);
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
} break; } break;
case NOTIFICATION_EXIT_TREE: { case NOTIFICATION_EXIT_TREE: {
VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas->get_canvas()); VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas);
viewport = RID(); viewport = RID();
} break; } break;
@ -184,7 +179,7 @@ RID CanvasLayer::get_viewport() const {
void CanvasLayer::set_custom_viewport(Node *p_viewport) { void CanvasLayer::set_custom_viewport(Node *p_viewport) {
ERR_FAIL_NULL(p_viewport); ERR_FAIL_NULL(p_viewport);
if (is_inside_tree()) { if (is_inside_tree()) {
VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas->get_canvas()); VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas);
viewport = RID(); viewport = RID();
} }
@ -205,9 +200,9 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) {
viewport = vp->get_viewport_rid(); viewport = vp->get_viewport_rid();
VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas->get_canvas()); VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas);
VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas->get_canvas(), layer); VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas, layer);
VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
} }
} }
@ -225,6 +220,10 @@ int CanvasLayer::get_sort_index() {
return sort_index++; return sort_index++;
} }
RID CanvasLayer::get_canvas() const {
return canvas;
}
void CanvasLayer::_bind_methods() { void CanvasLayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_layer", "layer"), &CanvasLayer::set_layer); ClassDB::bind_method(D_METHOD("set_layer", "layer"), &CanvasLayer::set_layer);
@ -248,7 +247,7 @@ void CanvasLayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_viewport", "viewport"), &CanvasLayer::set_custom_viewport); ClassDB::bind_method(D_METHOD("set_custom_viewport", "viewport"), &CanvasLayer::set_custom_viewport);
ClassDB::bind_method(D_METHOD("get_custom_viewport"), &CanvasLayer::get_custom_viewport); ClassDB::bind_method(D_METHOD("get_custom_viewport"), &CanvasLayer::get_custom_viewport);
ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasLayer::get_world_2d); ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasLayer::get_canvas);
//ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasLayer::get_viewport); //ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasLayer::get_viewport);
ADD_PROPERTY(PropertyInfo(Variant::INT, "layer", PROPERTY_HINT_RANGE, "-128,128,1"), "set_layer", "get_layer"); ADD_PROPERTY(PropertyInfo(Variant::INT, "layer", PROPERTY_HINT_RANGE, "-128,128,1"), "set_layer", "get_layer");
@ -268,8 +267,13 @@ CanvasLayer::CanvasLayer() {
rot = 0; rot = 0;
locrotscale_dirty = false; locrotscale_dirty = false;
layer = 1; layer = 1;
canvas = Ref<World2D>(memnew(World2D)); canvas = VS::get_singleton()->canvas_create();
custom_viewport = NULL; custom_viewport = NULL;
custom_viewport_id = 0; custom_viewport_id = 0;
sort_index = 0; sort_index = 0;
} }
CanvasLayer::~CanvasLayer() {
VS::get_singleton()->free(canvas);
}

View File

@ -45,7 +45,7 @@ class CanvasLayer : public Node {
real_t rot; real_t rot;
int layer; int layer;
Transform2D transform; Transform2D transform;
Ref<World2D> canvas; RID canvas;
ObjectID custom_viewport_id; // to check validity ObjectID custom_viewport_id; // to check validity
Viewport *custom_viewport; Viewport *custom_viewport;
@ -81,8 +81,6 @@ public:
void set_scale(const Size2 &p_scale); void set_scale(const Size2 &p_scale);
Size2 get_scale() const; Size2 get_scale() const;
Ref<World2D> get_world_2d() const;
Size2 get_viewport_size() const; Size2 get_viewport_size() const;
RID get_viewport() const; RID get_viewport() const;
@ -93,7 +91,10 @@ public:
void reset_sort_index(); void reset_sort_index();
int get_sort_index(); int get_sort_index();
RID get_canvas() const;
CanvasLayer(); CanvasLayer();
~CanvasLayer();
}; };
#endif // CANVAS_LAYER_H #endif // CANVAS_LAYER_H