From ae0316ff59541b43ff333731b80a45f6605350a3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 30 Aug 2022 14:31:23 +0200 Subject: [PATCH] Fix more issues with World overrides. --- scene/main/world.cpp | 24 +++++++++++++++++++++++- scene/main/world.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/scene/main/world.cpp b/scene/main/world.cpp index 1b0fcef0f..366f5172b 100644 --- a/scene/main/world.cpp +++ b/scene/main/world.cpp @@ -346,11 +346,19 @@ RID World::get_viewport_rid() const { } Vector2 World::get_camera_coords(const Vector2 &p_viewport_coords) const { + if (_override_world) { + return _override_world->get_camera_coords(p_viewport_coords); + } + Transform2D xf = get_final_transform(); return xf.xform(p_viewport_coords); } Vector2 World::get_camera_rect_size() const { + if (_override_world) { + return _override_world->get_camera_rect_size(); + } + return size; } @@ -395,21 +403,30 @@ void World::_world_3d_register_camera_as_override(Camera *p_camera) { find_world_3d_no_override()->_register_camera(p_camera); _override_cameras.push_back(p_camera); + + _camera_add(p_camera); } void World::_world_3d_remove_camera_as_override(Camera *p_camera) { find_world_3d_no_override()->_remove_camera(p_camera); _override_cameras.erase(p_camera); + + _camera_remove(p_camera); } void World::_clear_override_cameras() { while (_override_cameras.size() > 0) { _world_3d_remove_camera_as_override(_override_cameras[0]); } + + _camera_set(_own_active_camera); + _own_active_camera = NULL; } void World::_add_override_cameras_into(World *p_from) { + _own_active_camera = camera; + Ref w3d = find_world_3d_no_override(); ERR_FAIL_COND(!w3d.is_valid()); @@ -422,13 +439,18 @@ void World::_add_override_cameras_into(World *p_from) { _world_3d_register_camera_as_override(cam); } + + if (p_from->get_camera()) { + _camera_set(p_from->get_camera()); + } } World::World() { world_2d = Ref(memnew(World2D)); _override_world = NULL; _override_in_parent_viewport = false; - camera = nullptr; + camera = NULL; + _own_active_camera = NULL; } World::~World() { } diff --git a/scene/main/world.h b/scene/main/world.h index f749b7786..3d96fc4a9 100644 --- a/scene/main/world.h +++ b/scene/main/world.h @@ -119,6 +119,7 @@ protected: Camera *camera; Set cameras; + Camera *_own_active_camera; Size2 size; };