summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_item.cpp278
-rw-r--r--scene/main/canvas_item.h125
-rw-r--r--scene/main/canvas_layer.h1
-rw-r--r--scene/main/http_request.cpp2
-rw-r--r--scene/main/http_request.h6
-rw-r--r--scene/main/node.cpp4
-rw-r--r--scene/main/scene_tree.cpp15
-rw-r--r--scene/main/shader_globals_override.cpp3
-rw-r--r--scene/main/shader_globals_override.h2
-rw-r--r--scene/main/timer.cpp2
-rw-r--r--scene/main/viewport.cpp45
-rw-r--r--scene/main/viewport.h23
-rw-r--r--scene/main/window.cpp2
-rw-r--r--scene/main/window.h6
14 files changed, 67 insertions, 447 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index 0a76351885..f2415eaf71 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -30,289 +30,17 @@
#include "canvas_item.h"
-#include "core/input/input.h"
#include "core/object/message_queue.h"
#include "scene/2d/canvas_group.h"
#include "scene/main/canvas_layer.h"
-#include "scene/main/viewport.h"
#include "scene/main/window.h"
+#include "scene/resources/canvas_item_material.h"
#include "scene/resources/font.h"
+#include "scene/resources/multimesh.h"
#include "scene/resources/style_box.h"
-#include "scene/resources/texture.h"
+#include "scene/resources/world_2d.h"
#include "scene/scene_string_names.h"
-#include "servers/rendering_server.h"
-Mutex CanvasItemMaterial::material_mutex;
-SelfList<CanvasItemMaterial>::List *CanvasItemMaterial::dirty_materials = nullptr;
-Map<CanvasItemMaterial::MaterialKey, CanvasItemMaterial::ShaderData> CanvasItemMaterial::shader_map;
-CanvasItemMaterial::ShaderNames *CanvasItemMaterial::shader_names = nullptr;
-
-void CanvasItemMaterial::init_shaders() {
- dirty_materials = memnew(SelfList<CanvasItemMaterial>::List);
-
- shader_names = memnew(ShaderNames);
-
- shader_names->particles_anim_h_frames = "particles_anim_h_frames";
- shader_names->particles_anim_v_frames = "particles_anim_v_frames";
- shader_names->particles_anim_loop = "particles_anim_loop";
-}
-
-void CanvasItemMaterial::finish_shaders() {
- memdelete(dirty_materials);
- memdelete(shader_names);
- dirty_materials = nullptr;
-}
-
-void CanvasItemMaterial::_update_shader() {
- dirty_materials->remove(&element);
-
- MaterialKey mk = _compute_key();
- if (mk.key == current_key.key) {
- return; //no update required in the end
- }
-
- if (shader_map.has(current_key)) {
- shader_map[current_key].users--;
- if (shader_map[current_key].users == 0) {
- //deallocate shader, as it's no longer in use
- RS::get_singleton()->free(shader_map[current_key].shader);
- shader_map.erase(current_key);
- }
- }
-
- current_key = mk;
-
- if (shader_map.has(mk)) {
- RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader);
- shader_map[mk].users++;
- return;
- }
-
- //must create a shader!
-
- String code = "shader_type canvas_item;\nrender_mode ";
- switch (blend_mode) {
- case BLEND_MODE_MIX:
- code += "blend_mix";
- break;
- case BLEND_MODE_ADD:
- code += "blend_add";
- break;
- case BLEND_MODE_SUB:
- code += "blend_sub";
- break;
- case BLEND_MODE_MUL:
- code += "blend_mul";
- break;
- case BLEND_MODE_PREMULT_ALPHA:
- code += "blend_premul_alpha";
- break;
- case BLEND_MODE_DISABLED:
- code += "blend_disabled";
- break;
- }
-
- switch (light_mode) {
- case LIGHT_MODE_NORMAL:
- break;
- case LIGHT_MODE_UNSHADED:
- code += ",unshaded";
- break;
- case LIGHT_MODE_LIGHT_ONLY:
- code += ",light_only";
- break;
- }
-
- code += ";\n";
-
- if (particles_animation) {
- code += "uniform int particles_anim_h_frames;\n";
- code += "uniform int particles_anim_v_frames;\n";
- code += "uniform bool particles_anim_loop;\n\n";
-
- code += "void vertex() {\n";
- code += " float h_frames = float(particles_anim_h_frames);\n";
- code += " float v_frames = float(particles_anim_v_frames);\n";
- code += " VERTEX.xy /= vec2(h_frames, v_frames);\n";
- code += " float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n";
- code += " float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n";
- code += " if (!particles_anim_loop) {\n";
- code += " particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n";
- code += " } else {\n";
- code += " particle_frame = mod(particle_frame, particle_total_frames);\n";
- code += " }";
- code += " UV /= vec2(h_frames, v_frames);\n";
- code += " UV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n";
- code += "}\n";
- }
-
- ShaderData shader_data;
- shader_data.shader = RS::get_singleton()->shader_create();
- shader_data.users = 1;
-
- RS::get_singleton()->shader_set_code(shader_data.shader, code);
-
- shader_map[mk] = shader_data;
-
- RS::get_singleton()->material_set_shader(_get_material(), shader_data.shader);
-}
-
-void CanvasItemMaterial::flush_changes() {
- MutexLock lock(material_mutex);
-
- while (dirty_materials->first()) {
- dirty_materials->first()->self()->_update_shader();
- }
-}
-
-void CanvasItemMaterial::_queue_shader_change() {
- MutexLock lock(material_mutex);
-
- if (!element.in_list()) {
- dirty_materials->add(&element);
- }
-}
-
-bool CanvasItemMaterial::_is_shader_dirty() const {
- MutexLock lock(material_mutex);
-
- return element.in_list();
-}
-
-void CanvasItemMaterial::set_blend_mode(BlendMode p_blend_mode) {
- blend_mode = p_blend_mode;
- _queue_shader_change();
-}
-
-CanvasItemMaterial::BlendMode CanvasItemMaterial::get_blend_mode() const {
- return blend_mode;
-}
-
-void CanvasItemMaterial::set_light_mode(LightMode p_light_mode) {
- light_mode = p_light_mode;
- _queue_shader_change();
-}
-
-CanvasItemMaterial::LightMode CanvasItemMaterial::get_light_mode() const {
- return light_mode;
-}
-
-void CanvasItemMaterial::set_particles_animation(bool p_particles_anim) {
- particles_animation = p_particles_anim;
- _queue_shader_change();
- notify_property_list_changed();
-}
-
-bool CanvasItemMaterial::get_particles_animation() const {
- return particles_animation;
-}
-
-void CanvasItemMaterial::set_particles_anim_h_frames(int p_frames) {
- particles_anim_h_frames = p_frames;
- RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_h_frames, p_frames);
-}
-
-int CanvasItemMaterial::get_particles_anim_h_frames() const {
- return particles_anim_h_frames;
-}
-
-void CanvasItemMaterial::set_particles_anim_v_frames(int p_frames) {
- particles_anim_v_frames = p_frames;
- RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_v_frames, p_frames);
-}
-
-int CanvasItemMaterial::get_particles_anim_v_frames() const {
- return particles_anim_v_frames;
-}
-
-void CanvasItemMaterial::set_particles_anim_loop(bool p_loop) {
- particles_anim_loop = p_loop;
- RS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop);
-}
-
-bool CanvasItemMaterial::get_particles_anim_loop() const {
- return particles_anim_loop;
-}
-
-void CanvasItemMaterial::_validate_property(PropertyInfo &property) const {
- if (property.name.begins_with("particles_anim_") && !particles_animation) {
- property.usage = PROPERTY_USAGE_NONE;
- }
-}
-
-RID CanvasItemMaterial::get_shader_rid() const {
- ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
- return shader_map[current_key].shader;
-}
-
-Shader::Mode CanvasItemMaterial::get_shader_mode() const {
- return Shader::MODE_CANVAS_ITEM;
-}
-
-void CanvasItemMaterial::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_blend_mode", "blend_mode"), &CanvasItemMaterial::set_blend_mode);
- ClassDB::bind_method(D_METHOD("get_blend_mode"), &CanvasItemMaterial::get_blend_mode);
-
- ClassDB::bind_method(D_METHOD("set_light_mode", "light_mode"), &CanvasItemMaterial::set_light_mode);
- ClassDB::bind_method(D_METHOD("get_light_mode"), &CanvasItemMaterial::get_light_mode);
-
- ClassDB::bind_method(D_METHOD("set_particles_animation", "particles_anim"), &CanvasItemMaterial::set_particles_animation);
- ClassDB::bind_method(D_METHOD("get_particles_animation"), &CanvasItemMaterial::get_particles_animation);
-
- ClassDB::bind_method(D_METHOD("set_particles_anim_h_frames", "frames"), &CanvasItemMaterial::set_particles_anim_h_frames);
- ClassDB::bind_method(D_METHOD("get_particles_anim_h_frames"), &CanvasItemMaterial::get_particles_anim_h_frames);
-
- ClassDB::bind_method(D_METHOD("set_particles_anim_v_frames", "frames"), &CanvasItemMaterial::set_particles_anim_v_frames);
- ClassDB::bind_method(D_METHOD("get_particles_anim_v_frames"), &CanvasItemMaterial::get_particles_anim_v_frames);
-
- ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "loop"), &CanvasItemMaterial::set_particles_anim_loop);
- ClassDB::bind_method(D_METHOD("get_particles_anim_loop"), &CanvasItemMaterial::get_particles_anim_loop);
-
- ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Subtract,Multiply,Premultiplied Alpha"), "set_blend_mode", "get_blend_mode");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mode", PROPERTY_HINT_ENUM, "Normal,Unshaded,Light Only"), "set_light_mode", "get_light_mode");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "particles_animation"), "set_particles_animation", "get_particles_animation");
-
- ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_h_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_h_frames", "get_particles_anim_h_frames");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_v_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_v_frames", "get_particles_anim_v_frames");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "particles_anim_loop"), "set_particles_anim_loop", "get_particles_anim_loop");
-
- BIND_ENUM_CONSTANT(BLEND_MODE_MIX);
- BIND_ENUM_CONSTANT(BLEND_MODE_ADD);
- BIND_ENUM_CONSTANT(BLEND_MODE_SUB);
- BIND_ENUM_CONSTANT(BLEND_MODE_MUL);
- BIND_ENUM_CONSTANT(BLEND_MODE_PREMULT_ALPHA);
-
- BIND_ENUM_CONSTANT(LIGHT_MODE_NORMAL);
- BIND_ENUM_CONSTANT(LIGHT_MODE_UNSHADED);
- BIND_ENUM_CONSTANT(LIGHT_MODE_LIGHT_ONLY);
-}
-
-CanvasItemMaterial::CanvasItemMaterial() :
- element(this) {
- set_particles_anim_h_frames(1);
- set_particles_anim_v_frames(1);
- set_particles_anim_loop(false);
-
- current_key.invalid_key = 1;
- _queue_shader_change();
-}
-
-CanvasItemMaterial::~CanvasItemMaterial() {
- MutexLock lock(material_mutex);
-
- if (shader_map.has(current_key)) {
- shader_map[current_key].users--;
- if (shader_map[current_key].users == 0) {
- //deallocate shader, as it's no longer in use
- RS::get_singleton()->free(shader_map[current_key].shader);
- shader_map.erase(current_key);
- }
-
- RS::get_singleton()->material_set_shader(_get_material(), RID());
- }
-}
-
-///////////////////////////////////////////////////////////////////
#ifdef TOOLS_ENABLED
bool CanvasItem::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const {
if (_edit_use_rect()) {
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index f264764870..dc7ad2bf5d 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -33,132 +33,15 @@
#include "scene/main/node.h"
#include "scene/main/scene_tree.h"
-#include "scene/resources/material.h"
-#include "scene/resources/multimesh.h"
-#include "scene/resources/shader.h"
-#include "scene/resources/texture.h"
+#include "scene/resources/canvas_item_material.h"
#include "servers/text_server.h"
class CanvasLayer;
-class Viewport;
class Font;
-
+class MultiMesh;
class StyleBox;
-
-class CanvasItemMaterial : public Material {
- GDCLASS(CanvasItemMaterial, Material);
-
-public:
- enum BlendMode {
- BLEND_MODE_MIX,
- BLEND_MODE_ADD,
- BLEND_MODE_SUB,
- BLEND_MODE_MUL,
- BLEND_MODE_PREMULT_ALPHA,
- BLEND_MODE_DISABLED
- };
-
- enum LightMode {
- LIGHT_MODE_NORMAL,
- LIGHT_MODE_UNSHADED,
- LIGHT_MODE_LIGHT_ONLY
- };
-
-private:
- union MaterialKey {
- struct {
- uint32_t blend_mode : 4;
- uint32_t light_mode : 4;
- uint32_t particles_animation : 1;
- uint32_t invalid_key : 1;
- };
-
- uint32_t key = 0;
-
- bool operator<(const MaterialKey &p_key) const {
- return key < p_key.key;
- }
- };
-
- struct ShaderNames {
- StringName particles_anim_h_frames;
- StringName particles_anim_v_frames;
- StringName particles_anim_loop;
- };
-
- static ShaderNames *shader_names;
-
- struct ShaderData {
- RID shader;
- int users = 0;
- };
-
- static Map<MaterialKey, ShaderData> shader_map;
-
- MaterialKey current_key;
-
- _FORCE_INLINE_ MaterialKey _compute_key() const {
- MaterialKey mk;
- mk.key = 0;
- mk.blend_mode = blend_mode;
- mk.light_mode = light_mode;
- mk.particles_animation = particles_animation;
- return mk;
- }
-
- static Mutex material_mutex;
- static SelfList<CanvasItemMaterial>::List *dirty_materials;
- SelfList<CanvasItemMaterial> element;
-
- void _update_shader();
- _FORCE_INLINE_ void _queue_shader_change();
- _FORCE_INLINE_ bool _is_shader_dirty() const;
-
- BlendMode blend_mode = BLEND_MODE_MIX;
- LightMode light_mode = LIGHT_MODE_NORMAL;
- bool particles_animation = false;
-
- // Initialized in the constructor.
- int particles_anim_h_frames;
- int particles_anim_v_frames;
- bool particles_anim_loop;
-
-protected:
- static void _bind_methods();
- void _validate_property(PropertyInfo &property) const override;
-
-public:
- void set_blend_mode(BlendMode p_blend_mode);
- BlendMode get_blend_mode() const;
-
- void set_light_mode(LightMode p_light_mode);
- LightMode get_light_mode() const;
-
- void set_particles_animation(bool p_particles_anim);
- bool get_particles_animation() const;
-
- void set_particles_anim_h_frames(int p_frames);
- int get_particles_anim_h_frames() const;
- void set_particles_anim_v_frames(int p_frames);
- int get_particles_anim_v_frames() const;
-
- void set_particles_anim_loop(bool p_loop);
- bool get_particles_anim_loop() const;
-
- static void init_shaders();
- static void finish_shaders();
- static void flush_changes();
-
- virtual RID get_shader_rid() const override;
-
- virtual Shader::Mode get_shader_mode() const override;
-
- CanvasItemMaterial();
- virtual ~CanvasItemMaterial();
-};
-
-VARIANT_ENUM_CAST(CanvasItemMaterial::BlendMode)
-VARIANT_ENUM_CAST(CanvasItemMaterial::LightMode)
+class Window;
+class World2D;
class CanvasItem : public Node {
GDCLASS(CanvasItem, Node);
diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h
index 5de1ebf18d..9d8e0c203d 100644
--- a/scene/main/canvas_layer.h
+++ b/scene/main/canvas_layer.h
@@ -32,7 +32,6 @@
#define CANVAS_LAYER_H
#include "scene/main/node.h"
-#include "scene/resources/world_2d.h"
class Viewport;
class CanvasLayer : public Node {
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 2c6cefa771..f24d880045 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -30,7 +30,7 @@
#include "http_request.h"
#include "core/io/compression.h"
-#include "core/string/ustring.h"
+#include "scene/main/timer.h"
void HTTPRequest::_redirect_request(const String &p_new_url) {
}
diff --git a/scene/main/http_request.h b/scene/main/http_request.h
index 22e822253f..673cf3a740 100644
--- a/scene/main/http_request.h
+++ b/scene/main/http_request.h
@@ -31,12 +31,12 @@
#ifndef HTTPREQUEST_H
#define HTTPREQUEST_H
-#include "core/io/file_access.h"
#include "core/io/http_client.h"
#include "core/os/thread.h"
#include "core/templates/safe_refcount.h"
-#include "node.h"
-#include "scene/main/timer.h"
+#include "scene/main/node.h"
+
+class Timer;
class HTTPRequest : public Node {
GDCLASS(HTTPRequest, Node);
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index cbd5fa7425..155af30a6d 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2465,7 +2465,7 @@ NodePath Node::get_import_path() const {
static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<String> *r_options) {
#ifdef TOOLS_ENABLED
- const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", 0) ? "'" : "\"";
+ const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\"";
#else
const String quote_style = "\"";
#endif
@@ -2474,7 +2474,7 @@ static void _add_nodes_to_options(const Node *p_base, const Node *p_node, List<S
return;
}
String n = p_base->get_path_to(p_node);
- r_options->push_back(quote_style + n + quote_style);
+ r_options->push_back(n.quote(quote_style));
for (int i = 0; i < p_node->get_child_count(); i++) {
_add_nodes_to_options(p_base, p_node->get_child(i), r_options);
}
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 420516cbcd..5b707498a7 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -499,7 +499,7 @@ bool SceneTree::process(double p_time) {
_call_idle_callbacks();
#ifdef TOOLS_ENABLED
-
+#ifndef _3D_DISABLED
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(SNAME("rendering/environment/defaults/default_environment"));
@@ -522,8 +522,8 @@ bool SceneTree::process(double p_time) {
get_root()->get_world_3d()->set_fallback_environment(fallback);
}
}
-
-#endif
+#endif // _3D_DISABLED
+#endif // TOOLS_ENABLED
return _quit;
}
@@ -1333,20 +1333,21 @@ SceneTree::SceneTree() {
root = memnew(Window);
root->set_name("root");
+#ifndef _3D_DISABLED
if (!root->get_world_3d().is_valid()) {
root->set_world_3d(Ref<World3D>(memnew(World3D)));
}
+ root->set_as_audio_listener_3d(true);
+#endif // _3D_DISABLED
// Initialize network state.
set_multiplayer(Ref<MultiplayerAPI>(memnew(MultiplayerAPI)));
- //root->set_world_2d( Ref<World2D>( memnew( World2D )));
- root->set_as_audio_listener_3d(true);
root->set_as_audio_listener_2d(true);
current_scene = nullptr;
const int msaa_mode = GLOBAL_DEF("rendering/anti_aliasing/quality/msaa", 0);
- ProjectSettings::get_singleton()->set_custom_property_info("rendering/anti_aliasing/quality/msaa", PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa", PROPERTY_HINT_ENUM, "Disabled (Fastest),2x (Fast),4x (Average),8x (Slow),16x (Slower)"));
+ ProjectSettings::get_singleton()->set_custom_property_info("rendering/anti_aliasing/quality/msaa", PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Fast),4× (Average),8× (Slow),16× (Slower)")));
root->set_msaa(Viewport::MSAA(msaa_mode));
const int ssaa_mode = GLOBAL_DEF("rendering/anti_aliasing/quality/screen_space_aa", 0);
@@ -1397,6 +1398,7 @@ SceneTree::SceneTree() {
ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/sdf/oversize", PropertyInfo(Variant::INT, "rendering/2d/sdf/oversize", PROPERTY_HINT_ENUM, "100%,120%,150%,200%"));
ProjectSettings::get_singleton()->set_custom_property_info("rendering/2d/sdf/scale", PropertyInfo(Variant::INT, "rendering/2d/sdf/scale", PROPERTY_HINT_ENUM, "100%,50%,25%"));
+#ifndef _3D_DISABLED
{ // Load default fallback environment.
// Get possible extensions.
List<String> exts;
@@ -1428,6 +1430,7 @@ SceneTree::SceneTree() {
}
}
}
+#endif // _3D_DISABLED
root->set_physics_object_picking(GLOBAL_DEF("physics/common/enable_object_picking", true));
diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp
index d22a6b2875..9477e300d1 100644
--- a/scene/main/shader_globals_override.cpp
+++ b/scene/main/shader_globals_override.cpp
@@ -30,8 +30,7 @@
#include "shader_globals_override.h"
-#include "core/core_string_names.h"
-#include "scene/main/window.h"
+#include "scene/3d/node_3d.h"
#include "scene/scene_string_names.h"
StringName *ShaderGlobalsOverride::_remap(const StringName &p_name) const {
diff --git a/scene/main/shader_globals_override.h b/scene/main/shader_globals_override.h
index 2d9c3c76bd..ab4b9de727 100644
--- a/scene/main/shader_globals_override.h
+++ b/scene/main/shader_globals_override.h
@@ -31,7 +31,7 @@
#ifndef SHADER_GLOBALS_OVERRIDE_H
#define SHADER_GLOBALS_OVERRIDE_H
-#include "scene/3d/node_3d.h"
+#include "scene/main/node.h"
class ShaderGlobalsOverride : public Node {
GDCLASS(ShaderGlobalsOverride, Node);
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index b5a2a30b3b..9e462eb1c8 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -30,8 +30,6 @@
#include "timer.h"
-#include "core/config/engine.h"
-
void Timer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY: {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 908950a714..78fa0985a9 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -30,33 +30,27 @@
#include "viewport.h"
-#include "core/config/project_settings.h"
#include "core/core_string_names.h"
#include "core/debugger/engine_debugger.h"
-#include "core/input/input.h"
-#include "core/os/os.h"
#include "core/string/translation.h"
-
+#include "core/templates/pair.h"
#include "scene/2d/camera_2d.h"
#include "scene/2d/collision_object_2d.h"
+#ifndef _3D_DISABLED
#include "scene/3d/camera_3d.h"
#include "scene/3d/collision_object_3d.h"
#include "scene/3d/listener_3d.h"
-#include "scene/3d/node_3d.h"
#include "scene/3d/world_environment.h"
+#endif // _3D_DISABLED
#include "scene/gui/control.h"
#include "scene/gui/label.h"
-#include "scene/gui/menu_button.h"
-#include "scene/gui/panel.h"
-#include "scene/gui/panel_container.h"
-#include "scene/gui/popup_menu.h"
+#include "scene/gui/popup.h"
#include "scene/main/canvas_layer.h"
-#include "scene/main/timer.h"
#include "scene/main/window.h"
#include "scene/resources/mesh.h"
+#include "scene/resources/text_line.h"
+#include "scene/resources/world_2d.h"
#include "scene/scene_string_names.h"
-#include "servers/display_server.h"
-#include "servers/physics_server_2d.h"
void ViewportTexture::setup_local_to_scene() {
if (vp) {
@@ -385,14 +379,17 @@ void Viewport::_notification(int p_what) {
current_canvas = find_world_2d()->get_canvas();
RenderingServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas);
_update_listener_2d();
+#ifndef _3D_DISABLED
RenderingServer::get_singleton()->viewport_set_scenario(viewport, find_world_3d()->get_scenario());
_update_listener_3d();
+#endif // _3D_DISABLED
add_to_group("_viewports");
if (get_tree()->is_debugging_collisions_hint()) {
PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count());
contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create();
RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas());
+#ifndef _3D_DISABLED
PhysicsServer3D::get_singleton()->space_set_debug_contacts(find_world_3d()->get_space(), get_tree()->get_collision_debug_contact_count());
contact_3d_debug_multimesh = RenderingServer::get_singleton()->multimesh_create();
RenderingServer::get_singleton()->multimesh_allocate_data(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), RS::MULTIMESH_TRANSFORM_3D, true);
@@ -402,10 +399,12 @@ 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);
+#endif // _3D_DISABLED
}
} break;
case NOTIFICATION_READY: {
+#ifndef _3D_DISABLED
if (listener_3d_set.size() && !listener_3d) {
Listener3D *first = nullptr;
for (Set<Listener3D *>::Element *E = listener_3d_set.front(); E; E = E->next()) {
@@ -432,7 +431,7 @@ void Viewport::_notification(int p_what) {
first->make_current();
}
}
-
+#endif // _3D_DISABLED
} break;
case NOTIFICATION_EXIT_TREE: {
_gui_cancel_tooltip();
@@ -470,6 +469,7 @@ void Viewport::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol);
}
}
+#ifndef _3D_DISABLED
if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) {
Vector<Vector3> points = PhysicsServer3D::get_singleton()->space_get_contacts(find_world_3d()->get_space());
int point_count = PhysicsServer3D::get_singleton()->space_get_contact_count(find_world_3d()->get_space());
@@ -482,6 +482,7 @@ void Viewport::_notification(int p_what) {
RS::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh, i, point_transform);
}
}
+#endif // _3D_DISABLED
} break;
case NOTIFICATION_WM_MOUSE_EXIT: {
_drop_physics_mouseover();
@@ -514,10 +515,6 @@ void Viewport::_process_picking() {
_drop_physics_mouseover(true);
- Vector2 last_pos(1e20, 1e20);
- CollisionObject3D *last_object = nullptr;
- ObjectID last_id;
- PhysicsDirectSpaceState3D::RayResult result;
PhysicsDirectSpaceState2D *ss2d = PhysicsServer2D::get_singleton()->space_get_direct_state(find_world_2d()->get_space());
if (physics_has_last_mousepos) {
@@ -677,6 +674,11 @@ void Viewport::_process_picking() {
}
}
+#ifndef _3D_DISABLED
+ Vector2 last_pos(1e20, 1e20);
+ CollisionObject3D *last_object = nullptr;
+ ObjectID last_id;
+ PhysicsDirectSpaceState3D::RayResult result;
bool captured = false;
if (physics_object_capture.is_valid()) {
@@ -749,6 +751,7 @@ void Viewport::_process_picking() {
last_pos = pos;
}
}
+#endif // _3D_DISABLED
}
}
@@ -2212,6 +2215,7 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) {
_cleanup_mouseover_colliders(true, p_paused_only);
+#ifndef _3D_DISABLED
if (physics_object_over.is_valid()) {
CollisionObject3D *co = Object::cast_to<CollisionObject3D>(ObjectDB::get_instance(physics_object_over));
if (co) {
@@ -2222,6 +2226,7 @@ void Viewport::_drop_physics_mouseover(bool p_paused_only) {
}
}
}
+#endif // _3D_DISABLED
}
void Viewport::_cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference) {
@@ -3071,6 +3076,7 @@ Viewport::SDFScale Viewport::get_sdf_scale() const {
return sdf_scale;
}
+#ifndef _3D_DISABLED
Listener3D *Viewport::get_listener_3d() const {
return listener_3d;
}
@@ -3468,6 +3474,7 @@ void Viewport::set_use_xr(bool p_use_xr) {
bool Viewport::is_using_xr() {
return use_xr;
}
+#endif // _3D_DISABLED
void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_world_2d", "world_2d"), &Viewport::set_world_2d);
@@ -3573,6 +3580,7 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("_process_picking"), &Viewport::_process_picking);
+#ifndef _3D_DISABLED
ClassDB::bind_method(D_METHOD("set_world_3d", "world_3d"), &Viewport::set_world_3d);
ClassDB::bind_method(D_METHOD("get_world_3d"), &Viewport::get_world_3d);
ClassDB::bind_method(D_METHOD("find_world_3d"), &Viewport::find_world_3d);
@@ -3595,13 +3603,14 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener_3d", "is_audio_listener_3d");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world_3d"), "set_use_own_world_3d", "is_using_own_world_3d");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_3d", PROPERTY_HINT_RESOURCE_TYPE, "World3D"), "set_world_3d", "get_world_3d");
+#endif // _3D_DISABLED
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world_2d", PROPERTY_HINT_RESOURCE_TYPE, "World2D", PROPERTY_USAGE_NONE), "set_world_2d", "get_world_2d");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "handle_input_locally"), "set_handle_input_locally", "is_handling_input_locally");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_transforms_to_pixel"), "set_snap_2d_transforms_to_pixel", "is_snap_2d_transforms_to_pixel_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "snap_2d_vertices_to_pixel"), "set_snap_2d_vertices_to_pixel", "is_snap_2d_vertices_to_pixel_enabled");
ADD_GROUP("Rendering", "");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled (Fastest),2x (Fast),4x (Average),8x (Slow),16x (Slower)"), "set_msaa", "get_msaa");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Fast),4× (Average),8× (Slow),16× (Slower)")), "set_msaa", "get_msaa");
ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_space_aa", PROPERTY_HINT_ENUM, "Disabled (Fastest),FXAA (Fast)"), "set_screen_space_aa", "get_screen_space_aa");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_debanding"), "set_use_debanding", "is_using_debanding");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_occlusion_culling"), "set_use_occlusion_culling", "is_using_occlusion_culling");
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 7a25f5aa00..9c51f404d7 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -31,26 +31,25 @@
#ifndef VIEWPORT_H
#define VIEWPORT_H
-#include "core/math/transform_2d.h"
-#include "core/templates/pair.h"
#include "scene/main/node.h"
#include "scene/resources/texture.h"
-#include "scene/resources/world_2d.h"
-#include "servers/display_server.h"
-#include "servers/rendering_server.h"
+#ifndef _3D_DISABLED
class Camera3D;
-class Camera2D;
+class CollisionObject3D;
class Listener3D;
-class Control;
+class World3D;
+#endif // _3D_DISABLED
+
+class Camera2D;
class CanvasItem;
class CanvasLayer;
-class Panel;
+class Control;
class Label;
-class Timer;
-class Viewport;
-class CollisionObject3D;
class SceneTreeTimer;
+class Viewport;
+class Window;
+class World2D;
class ViewportTexture : public Texture2D {
GDCLASS(ViewportTexture, Texture2D);
@@ -576,6 +575,7 @@ public:
void pass_mouse_focus_to(Viewport *p_viewport, Control *p_control);
+#ifndef _3D_DISABLED
bool use_xr = false;
friend class Listener3D;
Listener3D *listener_3d = nullptr;
@@ -647,6 +647,7 @@ public:
void set_use_xr(bool p_use_xr);
bool is_using_xr();
+#endif // _3D_DISABLED
Viewport();
~Viewport();
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 1f1da7cefb..6995c77b8e 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -31,10 +31,8 @@
#include "window.h"
#include "core/debugger/engine_debugger.h"
-#include "core/os/keyboard.h"
#include "core/string/translation.h"
#include "scene/gui/control.h"
-#include "scene/resources/font.h"
#include "scene/scene_string_names.h"
void Window::set_title(const String &p_title) {
diff --git a/scene/main/window.h b/scene/main/window.h
index 7013694a06..4f31d9cd1f 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -32,10 +32,12 @@
#define WINDOW_H
#include "scene/main/viewport.h"
-#include "scene/resources/theme.h"
-#include "servers/display_server.h"
class Control;
+class Font;
+class StyleBox;
+class Theme;
+
class Window : public Viewport {
GDCLASS(Window, Viewport)
public: