diff --git a/scene/main/world.cpp b/scene/main/world.cpp index a4a8bcbc2..200c2e243 100644 --- a/scene/main/world.cpp +++ b/scene/main/world.cpp @@ -6,38 +6,8 @@ #include "scene/resources/world_2d.h" #include "scene/resources/world_3d.h" -void World::set_use_own_world_3d(bool p_use_own_world_3d) { - if (p_use_own_world_3d == own_world_3d.is_valid()) { - return; - } - - if (is_inside_tree()) { - _propagate_exit_world(this); - } - - if (p_use_own_world_3d) { - if (world_3d.is_valid()) { - own_world_3d = world_3d->duplicate(); - world_3d->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_3d_changed"); - } else { - own_world_3d = Ref(memnew(World3D)); - } - } else { - own_world_3d = Ref(); - if (world_3d.is_valid()) { - world_3d->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_3d_changed"); - } - } - - if (is_inside_tree()) { - _propagate_enter_world(this); - } - - _on_set_use_own_world_3d(p_use_own_world_3d); -} - -bool World::is_using_own_world_3d() const { - return own_world_3d.is_valid(); +Ref World::get_world_2d() const { + return world_2d; } void World::set_world_2d(const Ref &p_world_2d) { @@ -76,6 +46,10 @@ Ref World::find_world_2d() const { } } +Ref World::get_world_3d() const { + return world_3d; +} + void World::set_world_3d(const Ref &p_world_3d) { if (world_3d == p_world_3d) { return; @@ -109,14 +83,6 @@ void World::set_world_3d(const Ref &p_world_3d) { _on_set_world_3d(old_world); } -Ref World::get_world_3d() const { - return world_3d; -} - -Ref World::get_world_2d() const { - return world_2d; -} - Ref World::find_world_3d() const { if (own_world_3d.is_valid()) { return own_world_3d; @@ -129,6 +95,46 @@ Ref World::find_world_3d() const { } } +bool World::is_using_own_world_3d() const { + return own_world_3d.is_valid(); +} + +void World::set_use_own_world_3d(bool p_use_own_world_3d) { + if (p_use_own_world_3d == own_world_3d.is_valid()) { + return; + } + + if (is_inside_tree()) { + _propagate_exit_world(this); + } + + if (p_use_own_world_3d) { + if (world_3d.is_valid()) { + own_world_3d = world_3d->duplicate(); + world_3d->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_3d_changed"); + } else { + own_world_3d = Ref(memnew(World3D)); + } + } else { + own_world_3d = Ref(); + if (world_3d.is_valid()) { + world_3d->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_3d_changed"); + } + } + + if (is_inside_tree()) { + _propagate_enter_world(this); + } + + _on_set_use_own_world_3d(p_use_own_world_3d); +} + +World::World() { + world_2d = Ref(memnew(World2D)); +} +World::~World() { +} + void World::_propagate_enter_world(Node *p_node) { if (p_node != this) { if (!p_node->is_inside_tree()) { //may not have entered scene yet @@ -198,12 +204,6 @@ void World::_on_set_world_3d(const Ref &p_old_world) { void World::_on_set_world_2d(const Ref &p_old_world_2d) { } -World::World() { - world_2d = Ref(memnew(World2D)); -} -World::~World() { -} - void World::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -233,4 +233,4 @@ void World::_bind_methods() { ClassDB::bind_method(D_METHOD("find_world_3d"), &World::find_world_3d); ClassDB::bind_method(D_METHOD("_own_world_3d_changed"), &World::_own_world_3d_changed); -} \ No newline at end of file +} diff --git a/scene/main/world.h b/scene/main/world.h index 8f54de328..5c6f37d1a 100644 --- a/scene/main/world.h +++ b/scene/main/world.h @@ -12,15 +12,16 @@ class World : public Node { GDCLASS(World, Node); public: - void set_world_3d(const Ref &p_world); + Ref get_world_2d() const; void set_world_2d(const Ref &p_world_2d); - Ref get_world_3d() const; - Ref find_world_3d() const; - - Ref get_world_2d() const; Ref find_world_2d() const; + Ref get_world_3d() const; + void set_world_3d(const Ref &p_world); + + Ref find_world_3d() const; + void set_use_own_world_3d(bool p_use_own_world_3d); bool is_using_own_world_3d() const;