summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_item.cpp8
-rw-r--r--scene/main/canvas_item.h2
-rw-r--r--scene/main/scene_tree.cpp12
-rw-r--r--scene/main/viewport.cpp96
-rw-r--r--scene/main/viewport.h19
-rw-r--r--scene/main/window.cpp4
6 files changed, 81 insertions, 60 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index c3fd62640a..5a12480577 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -523,7 +523,7 @@ void CanvasItem::_enter_canvas() {
get_viewport()->gui_reset_canvas_sort_index();
}
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_top_level_raise_self");
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, SNAME("_top_level_raise_self"));
} else {
CanvasItem *parent = get_parent_item();
@@ -542,7 +542,7 @@ void CanvasItem::_exit_canvas() {
notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
RenderingServer::get_singleton()->canvas_item_set_parent(canvas_item, RID());
canvas_layer = nullptr;
- group = "";
+ group = StringName();
}
void CanvasItem::_notification(int p_what) {
@@ -588,7 +588,7 @@ void CanvasItem::_notification(int p_what) {
break;
}
- if (group != "") {
+ if (group != StringName()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_top_level_raise_self");
} else {
CanvasItem *p = get_parent_item();
@@ -648,7 +648,7 @@ void CanvasItem::update() {
pending_update = true;
- MessageQueue::get_singleton()->push_call(this, "_update_callback");
+ MessageQueue::get_singleton()->push_call(this, SNAME("_update_callback"));
}
void CanvasItem::set_modulate(const Color &p_modulate) {
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index afdd18d76b..f264764870 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -187,7 +187,7 @@ private:
mutable SelfList<Node> xform_change;
RID canvas_item;
- String group;
+ StringName group;
CanvasLayer *canvas_layer = nullptr;
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index cc947560a2..2fe5d7aa78 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -408,9 +408,9 @@ bool SceneTree::physics_process(float p_time) {
emit_signal(SNAME("physics_frame"));
- _notify_group_pause("physics_process_internal", Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
- call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_process_picking");
- _notify_group_pause("physics_process", Node::NOTIFICATION_PHYSICS_PROCESS);
+ _notify_group_pause(SNAME("physics_process_internal"), Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS);
+ call_group_flags(GROUP_CALL_REALTIME, SNAME("_picking_viewports"), SNAME("_process_picking"));
+ _notify_group_pause(SNAME("physics_process"), Node::NOTIFICATION_PHYSICS_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
@@ -442,8 +442,8 @@ bool SceneTree::process(float p_time) {
flush_transform_notifications();
- _notify_group_pause("process_internal", Node::NOTIFICATION_INTERNAL_PROCESS);
- _notify_group_pause("process", Node::NOTIFICATION_PROCESS);
+ _notify_group_pause(SNAME("process_internal"), Node::NOTIFICATION_INTERNAL_PROCESS);
+ _notify_group_pause(SNAME("process"), Node::NOTIFICATION_PROCESS);
_flush_ugc();
MessageQueue::get_singleton()->flush(); //small little hack
@@ -490,7 +490,7 @@ bool SceneTree::process(float p_time) {
if (Engine::get_singleton()->is_editor_hint()) {
//simple hack to reload fallback environment if it changed from editor
- String env_path = ProjectSettings::get_singleton()->get("rendering/environment/defaults/default_environment");
+ String env_path = ProjectSettings::get_singleton()->get(SNAME("rendering/environment/defaults/default_environment"));
env_path = env_path.strip_edges(); //user may have added a space or two
String cpath;
Ref<Environment> fallback = get_root()->get_world_3d()->get_fallback_environment();
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index b366f2d670..5a0a27520b 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -37,6 +37,7 @@
#include "core/os/os.h"
#include "core/string/translation.h"
+#include "scene/2d/camera_2d.h"
#include "scene/2d/collision_object_2d.h"
#include "scene/3d/camera_3d.h"
#include "scene/3d/collision_object_3d.h"
@@ -195,7 +196,7 @@ void Viewport::_collision_object_input_event(CollisionObject3D *p_object, Camera
return; //discarded
}
}
- p_object->_input_event(camera, p_input_event, p_pos, p_normal, p_shape);
+ p_object->_input_event(camera_3d, p_input_event, p_pos, p_normal, p_shape);
physics_last_object_transform = object_transform;
physics_last_camera_transform = camera_transform;
physics_last_id = id;
@@ -444,6 +445,7 @@ void Viewport::_notification(int p_what) {
RenderingServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh);
RenderingServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world_3d()->get_scenario());
//RenderingServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, RS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true);
+ set_physics_process_internal(true);
}
} break;
@@ -462,7 +464,7 @@ void Viewport::_notification(int p_what) {
}
}
- if (cameras.size() && !camera) {
+ if (cameras.size() && !camera_3d) {
//there are cameras but no current camera, pick first in tree and make it current
Camera3D *first = nullptr;
for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) {
@@ -477,10 +479,6 @@ void Viewport::_notification(int p_what) {
}
#endif
- // Enable processing for tooltips, collision debugging, physics object picking, etc.
- set_process_internal(true);
- set_physics_process_internal(true);
-
} break;
case NOTIFICATION_EXIT_TREE: {
_gui_cancel_tooltip();
@@ -500,6 +498,7 @@ void Viewport::_notification(int p_what) {
}
remove_from_group("_viewports");
+ set_physics_process_internal(false);
RS::get_singleton()->viewport_set_active(viewport, false);
RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID());
@@ -510,6 +509,7 @@ void Viewport::_notification(int p_what) {
gui.tooltip_timer -= get_process_delta_time();
if (gui.tooltip_timer < 0) {
_gui_show_tooltip();
+ set_process_internal(false);
}
}
@@ -743,8 +743,8 @@ void Viewport::_process_picking() {
if (physics_object_capture.is_valid()) {
CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_capture));
- if (co && camera) {
- _collision_object_input_event(co, camera, ev, Vector3(), Vector3(), 0);
+ if (co && camera_3d) {
+ _collision_object_input_event(co, camera_3d, ev, Vector3(), Vector3(), 0);
captured = true;
if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
physics_object_capture = ObjectID();
@@ -761,16 +761,16 @@ void Viewport::_process_picking() {
if (last_id.is_valid()) {
if (ObjectDB::get_instance(last_id) && last_object) {
//good, exists
- _collision_object_input_event(last_object, camera, ev, result.position, result.normal, result.shape);
+ _collision_object_input_event(last_object, camera_3d, ev, result.position, result.normal, result.shape);
if (last_object->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
physics_object_capture = last_id;
}
}
}
} else {
- if (camera) {
- Vector3 from = camera->project_ray_origin(pos);
- Vector3 dir = camera->project_ray_normal(pos);
+ if (camera_3d) {
+ Vector3 from = camera_3d->project_ray_origin(pos);
+ Vector3 dir = camera_3d->project_ray_normal(pos);
PhysicsDirectSpaceState3D *space = PhysicsServer3D::get_singleton()->space_get_direct_state(find_world_3d()->get_space());
if (space) {
@@ -778,8 +778,8 @@ void Viewport::_process_picking() {
ObjectID new_collider;
if (col) {
CollisionObject3D *co = Object::cast_to<CollisionObject3D>(result.collider);
- if (co && co->can_process()) {
- _collision_object_input_event(co, camera, ev, result.position, result.normal, result.shape);
+ if (co) {
+ _collision_object_input_event(co, camera_3d, ev, result.position, result.normal, result.shape);
last_object = co;
last_id = result.collider_id;
new_collider = last_id;
@@ -1033,64 +1033,68 @@ void Viewport::_listener_make_next_current(Listener3D *p_exclude) {
}
} else {
// Attempt to reset listener to the camera position
- if (camera != nullptr) {
+ if (camera_3d != nullptr) {
_update_listener();
- _camera_transform_changed_notify();
+ _camera_3d_transform_changed_notify();
}
}
}
#endif
-void Viewport::_camera_transform_changed_notify() {
+void Viewport::_camera_3d_transform_changed_notify() {
#ifndef _3D_DISABLED
#endif
}
-void Viewport::_camera_set(Camera3D *p_camera) {
+void Viewport::_camera_3d_set(Camera3D *p_camera) {
#ifndef _3D_DISABLED
- if (camera == p_camera) {
+ if (camera_3d == p_camera) {
return;
}
- if (camera) {
- camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
+ if (camera_3d) {
+ camera_3d->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
}
- camera = p_camera;
+ camera_3d = p_camera;
if (!camera_override) {
- if (camera) {
- RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
+ if (camera_3d) {
+ RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_3d->get_camera());
} else {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID());
}
}
- if (camera) {
- camera->notification(Camera3D::NOTIFICATION_BECAME_CURRENT);
+ if (camera_3d) {
+ camera_3d->notification(Camera3D::NOTIFICATION_BECAME_CURRENT);
}
_update_listener();
- _camera_transform_changed_notify();
+ _camera_3d_transform_changed_notify();
#endif
}
-bool Viewport::_camera_add(Camera3D *p_camera) {
+void Viewport::_camera_2d_set(Camera2D *p_camera_2d) {
+ camera_2d = p_camera_2d;
+}
+
+bool Viewport::_camera_3d_add(Camera3D *p_camera) {
cameras.insert(p_camera);
return cameras.size() == 1;
}
-void Viewport::_camera_remove(Camera3D *p_camera) {
+void Viewport::_camera_3d_remove(Camera3D *p_camera) {
cameras.erase(p_camera);
- if (camera == p_camera) {
- camera->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
- camera = nullptr;
+ if (camera_3d == p_camera) {
+ camera_3d->notification(Camera3D::NOTIFICATION_LOST_CURRENT);
+ camera_3d = nullptr;
}
}
#ifndef _3D_DISABLED
-void Viewport::_camera_make_next_current(Camera3D *p_exclude) {
+void Viewport::_camera_3d_make_next_current(Camera3D *p_exclude) {
for (Set<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) {
if (p_exclude == E->get()) {
continue;
@@ -1098,7 +1102,7 @@ void Viewport::_camera_make_next_current(Camera3D *p_exclude) {
if (!E->get()->is_inside_tree()) {
continue;
}
- if (camera != nullptr) {
+ if (camera_3d != nullptr) {
return;
}
@@ -1287,8 +1291,12 @@ Listener3D *Viewport::get_listener() const {
return listener;
}
-Camera3D *Viewport::get_camera() const {
- return camera;
+Camera3D *Viewport::get_camera_3d() const {
+ return camera_3d;
+}
+
+Camera2D *Viewport::get_camera_2d() const {
+ return camera_2d;
}
void Viewport::enable_camera_override(bool p_enable) {
@@ -1306,8 +1314,8 @@ void Viewport::enable_camera_override(bool p_enable) {
if (p_enable) {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_override.rid);
- } else if (camera) {
- RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera());
+ } else if (camera_3d) {
+ RenderingServer::get_singleton()->viewport_attach_camera(viewport, camera_3d->get_camera());
} else {
RenderingServer::get_singleton()->viewport_attach_camera(viewport, RID());
}
@@ -1482,6 +1490,7 @@ void Viewport::_gui_sort_roots() {
void Viewport::_gui_cancel_tooltip() {
gui.tooltip_control = nullptr;
gui.tooltip_timer = -1;
+ set_process_internal(false);
if (gui.tooltip_popup) {
gui.tooltip_popup->queue_delete();
gui.tooltip_popup = nullptr;
@@ -2133,6 +2142,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
gui.tooltip_control = over;
gui.tooltip_pos = over->get_screen_transform().xform(pos);
gui.tooltip_timer = gui.tooltip_delay;
+ set_process_internal(true);
}
}
@@ -3172,8 +3182,13 @@ bool Viewport::is_using_own_world_3d() const {
void Viewport::set_physics_object_picking(bool p_enable) {
physics_object_picking = p_enable;
- if (!physics_object_picking) {
+ if (physics_object_picking) {
+ add_to_group("_picking_viewports");
+ } else {
physics_picking_events.clear();
+ if (is_in_group("_picking_viewports")) {
+ remove_from_group("_picking_viewports");
+ }
}
}
@@ -3542,7 +3557,8 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_own_world_3d", "enable"), &Viewport::set_use_own_world_3d);
ClassDB::bind_method(D_METHOD("is_using_own_world_3d"), &Viewport::is_using_own_world_3d);
- ClassDB::bind_method(D_METHOD("get_camera"), &Viewport::get_camera);
+ ClassDB::bind_method(D_METHOD("get_camera_3d"), &Viewport::get_camera_3d);
+ ClassDB::bind_method(D_METHOD("get_camera_2d"), &Viewport::get_camera_2d);
ClassDB::bind_method(D_METHOD("set_as_audio_listener", "enable"), &Viewport::set_as_audio_listener);
ClassDB::bind_method(D_METHOD("is_audio_listener"), &Viewport::is_audio_listener);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 59715ebd0e..7b7f1c3818 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -214,7 +214,8 @@ private:
}
} camera_override;
- Camera3D *camera = nullptr;
+ Camera3D *camera_3d = nullptr;
+ Camera2D *camera_2d = nullptr;
Set<Camera3D *> cameras;
Set<CanvasLayer *> canvas_layers;
@@ -450,11 +451,14 @@ private:
void _listener_make_next_current(Listener3D *p_exclude);
friend class Camera3D;
- void _camera_transform_changed_notify();
- void _camera_set(Camera3D *p_camera);
- bool _camera_add(Camera3D *p_camera); //true if first
- void _camera_remove(Camera3D *p_camera);
- void _camera_make_next_current(Camera3D *p_exclude);
+ void _camera_3d_transform_changed_notify();
+ void _camera_3d_set(Camera3D *p_camera);
+ bool _camera_3d_add(Camera3D *p_camera); //true if first
+ void _camera_3d_remove(Camera3D *p_camera);
+ void _camera_3d_make_next_current(Camera3D *p_exclude);
+
+ friend class Camera2D;
+ void _camera_2d_set(Camera2D *p_camera_2d);
friend class CanvasLayer;
void _canvas_layer_add(CanvasLayer *p_canvas_layer);
@@ -497,7 +501,8 @@ public:
uint64_t get_processed_events_count() const { return event_count; }
Listener3D *get_listener() const;
- Camera3D *get_camera() const;
+ Camera3D *get_camera_3d() const;
+ Camera2D *get_camera_2d() const;
void enable_camera_override(bool p_enable);
bool is_camera_override_enabled() const;
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 7aa88fa766..bf7512e8eb 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1325,14 +1325,14 @@ bool Window::is_layout_rtl() const {
if (parent) {
return parent->is_layout_rtl();
} else {
- if (GLOBAL_GET("internationalization/rendering/force_right_to_left_layout_direction")) {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
return true;
}
String locale = TranslationServer::get_singleton()->get_tool_locale();
return TS->is_locale_right_to_left(locale);
}
} else if (layout_dir == LAYOUT_DIRECTION_LOCALE) {
- if (GLOBAL_GET("internationalization/rendering/force_right_to_left_layout_direction")) {
+ if (GLOBAL_GET(SNAME("internationalization/rendering/force_right_to_left_layout_direction"))) {
return true;
}
String locale = TranslationServer::get_singleton()->get_tool_locale();