summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-09-14 14:32:53 -0300
committerGitHub <noreply@github.com>2016-09-14 14:32:53 -0300
commit51466ae5d2f4f36f155a9f9b3e84c878c0a86707 (patch)
tree0d5eecb214fb9203d826a334f9cc6bb2b1d64676 /scene/main
parent827a9aa8294e7e2405f645579cc3e7044f3be079 (diff)
parent97cf3eba56f7f89b9a6b275c70e54e52303e25a7 (diff)
Merge pull request #6486 from Faless/viewport2d
Restore Viewport::set_world_2d() functionality (2D Split Screen)
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/viewport.cpp54
-rw-r--r--scene/main/viewport.h2
2 files changed, 34 insertions, 22 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 347d72aecd..b22d1fcdf4 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -359,13 +359,7 @@ void Viewport::_notification(int p_what) {
_update_listener_2d();
_update_rect();
- if (world_2d.is_valid()) {
- find_world_2d()->_register_viewport(this,Rect2());
-//best to defer this and not do it here, as it can annoy a lot of setup logic if user
-//adds a node and then moves it, will get enter/exit screen/viewport notifications
-//unnecesarily
-// update_worlds();
- }
+ find_world_2d()->_register_viewport(this,Rect2());
add_to_group("_viewports");
if (get_tree()->is_debugging_collisions_hint()) {
@@ -1001,19 +995,34 @@ bool Viewport::has_transparent_background() const {
return transparent_bg;
}
-#if 0
void Viewport::set_world_2d(const Ref<World2D>& p_world_2d) {
+ if (world_2d==p_world_2d)
+ return;
+
+ if (parent && parent->find_world_2d()==p_world_2d) {
+ WARN_PRINT("Unable to use parent world as world_2d");
+ return;
+ }
+
+ if (is_inside_tree()) {
+ find_world_2d()->_remove_viewport(this);
+ VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas);
+ }
+
+ if (p_world_2d.is_valid())
+ world_2d=p_world_2d;
+ else {
+ WARN_PRINT("Invalid world");
+ world_2d=Ref<World2D>( memnew( World2D ));
+ }
- world_2d=p_world_2d;
_update_listener_2d();
- if (is_inside_scene()) {
- if (current_canvas.is_valid())
- VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas);
+ if (is_inside_tree()) {
current_canvas=find_world_2d()->get_canvas();
VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas);
+ find_world_2d()->_register_viewport(this,Rect2());
}
-
}
Ref<World2D> Viewport::find_world_2d() const{
@@ -1025,13 +1034,6 @@ Ref<World2D> Viewport::find_world_2d() const{
else
return Ref<World2D>();
}
-#endif
-
-Ref<World2D> Viewport::find_world_2d() const{
-
- return world_2d;
-}
-
void Viewport::_propagate_enter_world(Node *p_node) {
@@ -1141,6 +1143,11 @@ Ref<World> Viewport::get_world() const{
return world;
}
+Ref<World2D> Viewport::get_world_2d() const{
+
+ return world_2d;
+}
+
Ref<World> Viewport::find_world() const{
if (own_world.is_valid())
@@ -1303,6 +1310,9 @@ void Viewport::render_target_clear() {
void Viewport::set_render_target_filter(bool p_enable) {
+ if(!render_target)
+ return;
+
render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0));
}
@@ -2587,8 +2597,8 @@ void Viewport::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_rect","rect"), &Viewport::set_rect);
ObjectTypeDB::bind_method(_MD("get_rect"), &Viewport::get_rect);
- //ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d);
- //ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d);
+ ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d);
+ ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d);
ObjectTypeDB::bind_method(_MD("find_world_2d:World2D"), &Viewport::find_world_2d);
ObjectTypeDB::bind_method(_MD("set_world","world:World"), &Viewport::set_world);
ObjectTypeDB::bind_method(_MD("get_world:World"), &Viewport::get_world);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 145f642fd3..f657f0507d 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -305,9 +305,11 @@ public:
RID get_viewport() const;
void set_world(const Ref<World>& p_world);
+ void set_world_2d(const Ref<World2D>& p_world_2d);
Ref<World> get_world() const;
Ref<World> find_world() const;
+ Ref<World2D> get_world_2d() const;
Ref<World2D> find_world_2d() const;