summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml18
-rw-r--r--core/debugger/remote_debugger.cpp22
-rw-r--r--core/image.cpp8
-rw-r--r--core/image.h2
-rw-r--r--core/os/main_loop.cpp6
-rw-r--r--core/os/main_loop.h6
-rw-r--r--core/os/os.cpp36
-rw-r--r--core/os/os.h3
-rw-r--r--doc/classes/Performance.xml69
-rw-r--r--doc/classes/PhysicsShapeQueryParameters2D.xml27
-rw-r--r--doc/classes/PhysicsShapeQueryParameters3D.xml27
-rw-r--r--drivers/dummy/rasterizer_dummy.h33
-rw-r--r--editor/debugger/editor_performance_profiler.cpp394
-rw-r--r--editor/debugger/editor_performance_profiler.h90
-rw-r--r--editor/debugger/script_editor_debugger.cpp265
-rw-r--r--editor/debugger/script_editor_debugger.h12
-rw-r--r--editor/editor_help_search.cpp19
-rw-r--r--editor/editor_node.cpp4
-rw-r--r--editor/editor_plugin_settings.cpp2
-rw-r--r--editor/editor_spin_slider.cpp4
-rw-r--r--editor/plugins/script_editor_plugin.cpp2
-rw-r--r--editor/plugins/shader_editor_plugin.cpp2
-rw-r--r--editor/plugins/shader_file_editor_plugin.cpp2
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp2
-rw-r--r--editor/scene_tree_dock.cpp19
-rw-r--r--main/main.cpp36
-rw-r--r--main/main.h1
-rw-r--r--main/performance.cpp76
-rw-r--r--main/performance.h22
-rw-r--r--modules/csg/csg.cpp11
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp4
-rw-r--r--modules/tga/image_loader_tga.cpp14
-rw-r--r--platform/android/java_godot_lib_jni.cpp4
-rw-r--r--platform/osx/display_server_osx.mm12
-rw-r--r--platform/osx/export/export.cpp5
-rw-r--r--platform/windows/display_server_windows.cpp19
-rw-r--r--platform/windows/display_server_windows.h1
-rw-r--r--scene/gui/dialogs.cpp5
-rw-r--r--scene/gui/dialogs.h1
-rw-r--r--scene/gui/line_edit.cpp4
-rw-r--r--scene/gui/text_edit.cpp4
-rw-r--r--scene/gui/tree.cpp2
-rw-r--r--scene/main/node.cpp10
-rw-r--r--scene/main/node.h10
-rw-r--r--scene/main/scene_tree.cpp8
-rw-r--r--scene/main/viewport.cpp2
-rw-r--r--scene/main/window.cpp16
-rw-r--r--scene/resources/environment.cpp2
-rw-r--r--servers/physics_2d/broad_phase_2d_hash_grid.cpp51
-rw-r--r--servers/physics_2d/collision_object_2d_sw.h10
-rw-r--r--servers/physics_3d/collision_object_3d_sw.h10
-rw-r--r--servers/physics_server_2d.cpp19
-rw-r--r--servers/physics_server_2d.h5
-rw-r--r--servers/physics_server_3d.cpp19
-rw-r--r--servers/physics_server_3d.h4
-rw-r--r--servers/rendering/rendering_device.cpp2
56 files changed, 1037 insertions, 426 deletions
diff --git a/.travis.yml b/.travis.yml
index 9376fbcc06..2639cf9661 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -100,15 +100,15 @@ matrix:
packages:
- *linux_deps
-# - name: Javascript export template (release, emscripten latest)
-# stage: build
-# env: PLATFORM=javascript TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-emcc-latest EXTRA_ARGS="use_closure_compiler=yes"
-# os: linux
-# compiler: clang
-# addons:
-# apt:
-# packages:
-# - *linux_deps
+ - name: JavaScript export template (release, emscripten latest)
+ stage: build
+ env: PLATFORM=javascript TOOLS=no TARGET=release CACHE_NAME=${PLATFORM}-emcc-latest EXTRA_ARGS="use_closure_compiler=yes"
+ os: linux
+ compiler: clang
+ addons:
+ apt:
+ packages:
+ - *linux_deps
before_install:
- eval "${MATRIX_EVAL}"
diff --git a/core/debugger/remote_debugger.cpp b/core/debugger/remote_debugger.cpp
index 62f600c5e5..9d55e1312e 100644
--- a/core/debugger/remote_debugger.cpp
+++ b/core/debugger/remote_debugger.cpp
@@ -373,6 +373,7 @@ struct RemoteDebugger::VisualProfiler {
struct RemoteDebugger::PerformanceProfiler {
Object *performance = nullptr;
int last_perf_time = 0;
+ uint64_t last_monitor_modification_time = 0;
void toggle(bool p_enable, const Array &p_opts) {}
void add(const Array &p_data) {}
@@ -386,12 +387,31 @@ struct RemoteDebugger::PerformanceProfiler {
return;
}
last_perf_time = pt;
+
+ Array custom_monitor_names = performance->call("get_custom_monitor_names");
+
+ uint64_t monitor_modification_time = performance->call("get_monitor_modification_time");
+ if (monitor_modification_time > last_monitor_modification_time) {
+ last_monitor_modification_time = monitor_modification_time;
+ EngineDebugger::get_singleton()->send_message("performance:profile_names", custom_monitor_names);
+ }
+
int max = performance->get("MONITOR_MAX");
Array arr;
- arr.resize(max);
+ arr.resize(max + custom_monitor_names.size());
for (int i = 0; i < max; i++) {
arr[i] = performance->call("get_monitor", i);
}
+
+ for (int i = 0; i < custom_monitor_names.size(); i++) {
+ Variant monitor_value = performance->call("get_custom_monitor", custom_monitor_names[i]);
+ if (!monitor_value.is_num()) {
+ ERR_PRINT("Value of custom monitor '" + String(custom_monitor_names[i]) + "' is not a number");
+ arr[i + max] = Variant();
+ }
+ arr[i + max] = monitor_value;
+ }
+
EngineDebugger::get_singleton()->send_message("performance:profile_frame", arr);
}
diff --git a/core/image.cpp b/core/image.cpp
index 45f10625a9..e2b184fcde 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -30,6 +30,7 @@
#include "image.h"
+#include "core/error_macros.h"
#include "core/hash_map.h"
#include "core/io/image_loader.h"
#include "core/io/resource_loader.h"
@@ -2629,6 +2630,7 @@ void Image::fill(const Color &c) {
ImageMemLoadFunc Image::_png_mem_loader_func = nullptr;
ImageMemLoadFunc Image::_jpg_mem_loader_func = nullptr;
ImageMemLoadFunc Image::_webp_mem_loader_func = nullptr;
+ImageMemLoadFunc Image::_tga_mem_loader_func = nullptr;
void (*Image::_image_compress_bc_func)(Image *, float, Image::UsedChannels) = nullptr;
void (*Image::_image_compress_bptc_func)(Image *, float, Image::UsedChannels) = nullptr;
@@ -3058,6 +3060,7 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_png_from_buffer", "buffer"), &Image::load_png_from_buffer);
ClassDB::bind_method(D_METHOD("load_jpg_from_buffer", "buffer"), &Image::load_jpg_from_buffer);
ClassDB::bind_method(D_METHOD("load_webp_from_buffer", "buffer"), &Image::load_webp_from_buffer);
+ ClassDB::bind_method(D_METHOD("load_tga_from_buffer", "buffer"), &Image::load_tga_from_buffer);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "_set_data", "_get_data");
@@ -3389,6 +3392,11 @@ Error Image::load_webp_from_buffer(const Vector<uint8_t> &p_array) {
return _load_from_buffer(p_array, _webp_mem_loader_func);
}
+Error Image::load_tga_from_buffer(const Vector<uint8_t> &p_array) {
+ ERR_FAIL_NULL_V_MSG(_tga_mem_loader_func, ERR_UNAVAILABLE, "TGA module was not installed.");
+ return _load_from_buffer(p_array, _tga_mem_loader_func);
+}
+
void Image::convert_rg_to_ra_rgba8() {
ERR_FAIL_COND(format != FORMAT_RGBA8);
ERR_FAIL_COND(!data.size());
diff --git a/core/image.h b/core/image.h
index 53c203998e..711bf5721c 100644
--- a/core/image.h
+++ b/core/image.h
@@ -135,6 +135,7 @@ public:
static ImageMemLoadFunc _png_mem_loader_func;
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
+ static ImageMemLoadFunc _tga_mem_loader_func;
static void (*_image_compress_bc_func)(Image *, float, UsedChannels p_channels);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, UsedChannels p_channels);
@@ -360,6 +361,7 @@ public:
Error load_png_from_buffer(const Vector<uint8_t> &p_array);
Error load_jpg_from_buffer(const Vector<uint8_t> &p_array);
Error load_webp_from_buffer(const Vector<uint8_t> &p_array);
+ Error load_tga_from_buffer(const Vector<uint8_t> &p_array);
void convert_rg_to_ra_rgba8();
void convert_ra_rgba8_to_rg();
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index dc68c2a9f9..434f6fa300 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -48,8 +48,10 @@ void MainLoop::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_ABOUT);
BIND_CONSTANT(NOTIFICATION_CRASH);
BIND_CONSTANT(NOTIFICATION_OS_IME_UPDATE);
- BIND_CONSTANT(NOTIFICATION_APP_RESUMED);
- BIND_CONSTANT(NOTIFICATION_APP_PAUSED);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_RESUMED);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_PAUSED);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_IN);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_OUT);
ADD_SIGNAL(MethodInfo("on_request_permissions_result", PropertyInfo(Variant::STRING, "permission"), PropertyInfo(Variant::BOOL, "granted")));
};
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index 90790a45a1..2c34cf193c 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -52,8 +52,10 @@ public:
NOTIFICATION_WM_ABOUT = 2011,
NOTIFICATION_CRASH = 2012,
NOTIFICATION_OS_IME_UPDATE = 2013,
- NOTIFICATION_APP_RESUMED = 2014,
- NOTIFICATION_APP_PAUSED = 2015,
+ NOTIFICATION_APPLICATION_RESUMED = 2014,
+ NOTIFICATION_APPLICATION_PAUSED = 2015,
+ NOTIFICATION_APPLICATION_FOCUS_IN = 2016,
+ NOTIFICATION_APPLICATION_FOCUS_OUT = 2017,
};
virtual void init();
diff --git a/core/os/os.cpp b/core/os/os.cpp
index c842be333c..231069fcfb 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -41,6 +41,7 @@
#include <stdarg.h>
OS *OS::singleton = nullptr;
+uint64_t OS::target_ticks = 0;
OS *OS::get_singleton() {
return singleton;
@@ -468,6 +469,41 @@ void OS::close_midi_inputs() {
}
}
+void OS::add_frame_delay(bool p_can_draw) {
+ const uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
+ if (frame_delay) {
+ // Add fixed frame delay to decrease CPU/GPU usage. This doesn't take
+ // the actual frame time into account.
+ // Due to the high fluctuation of the actual sleep duration, it's not recommended
+ // to use this as a FPS limiter.
+ delay_usec(frame_delay * 1000);
+ }
+
+ // Add a dynamic frame delay to decrease CPU/GPU usage. This takes the
+ // previous frame time into account for a smoother result.
+ uint64_t dynamic_delay = 0;
+ if (is_in_low_processor_usage_mode() || !p_can_draw) {
+ dynamic_delay = get_low_processor_usage_mode_sleep_usec();
+ }
+ const int target_fps = Engine::get_singleton()->get_target_fps();
+ if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) {
+ // Override the low processor usage mode sleep delay if the target FPS is lower.
+ dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / target_fps));
+ }
+
+ if (dynamic_delay > 0) {
+ target_ticks += dynamic_delay;
+ uint64_t current_ticks = get_ticks_usec();
+
+ if (current_ticks < target_ticks) {
+ delay_usec(target_ticks - current_ticks);
+ }
+
+ current_ticks = get_ticks_usec();
+ target_ticks = MIN(MAX(target_ticks, current_ticks - dynamic_delay), current_ticks + dynamic_delay);
+ }
+}
+
OS::OS() {
void *volatile stack_bottom;
diff --git a/core/os/os.h b/core/os/os.h
index 04e10518dc..f21c0d4df7 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -43,6 +43,7 @@
class OS {
static OS *singleton;
+ static uint64_t target_ticks;
String _execpath;
List<String> _cmdline;
bool _keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
@@ -212,6 +213,8 @@ public:
virtual double get_unix_time() const;
virtual void delay_usec(uint32_t p_usec) const = 0;
+ virtual void add_frame_delay(bool p_can_draw);
+
virtual uint64_t get_ticks_usec() const = 0;
uint32_t get_ticks_msec() const;
uint64_t get_splash_tick_msec() const;
diff --git a/doc/classes/Performance.xml b/doc/classes/Performance.xml
index 2a0c153267..0a9079ce71 100644
--- a/doc/classes/Performance.xml
+++ b/doc/classes/Performance.xml
@@ -5,12 +5,55 @@
</brief_description>
<description>
This class provides access to a number of different monitors related to performance, such as memory usage, draw calls, and FPS. These are the same as the values displayed in the [b]Monitor[/b] tab in the editor's [b]Debugger[/b] panel. By using the [method get_monitor] method of this class, you can access this data from your code.
+ You can add custom monitors using the [method add_custom_monitor] method. Custom monitors are available in [b]Monitor[/b] tab in the editor's [b]Debugger[/b] panel together with built-in monitors.
[b]Note:[/b] A few of these monitors are only available in debug mode and will always return 0 when used in a release build.
[b]Note:[/b] Many of these monitors are not updated in real-time, so there may be a short delay between changes.
+ [b]Note:[/b] Custom monitors do not support negative values. Negative values are clamped to 0.
</description>
<tutorials>
</tutorials>
<methods>
+ <method name="add_custom_monitor">
+ <return type="void">
+ </return>
+ <argument index="0" name="id" type="StringName">
+ </argument>
+ <argument index="1" name="callable" type="Callable">
+ </argument>
+ <argument index="2" name="arguments" type="Array" default="[ ]">
+ </argument>
+ <description>
+ Adds a custom monitor with name same as id. You can specify the category of monitor using '/' in id. If there are more than one '/' then default category is used. Default category is "Custom".
+ [codeblock]
+ Performance.add_custom_monitor("MyCategory/MyMonitor", some_callable) # Adds monitor with name "MyName" to category "MyCategory"
+ Performance.add_custom_monitor("MyMonitor", some_callable) # Adds monitor with name "MyName" to category "Custom"
+ # Note: "MyCategory/MyMonitor" and "MyMonitor" have same name but different ids so above code is valid
+ Performance.add_custom_monitor("Custom/MyMonitor", some_callable) # Adds monitor with name "MyName" to category "Custom"
+ # Note: "MyMonitor" and "Custom/MyMonitor" have same name and same category but different ids so above code is valid
+ Performance.add_custom_monitor("MyCategoryOne/MyCategoryTwo/MyMonitor", some_callable) # Adds monitor with name "MyCategoryOne/MyCategoryTwo/MyMonitor" to category "Custom"
+ [/codeblock]
+ The debugger calls the callable to get the value of custom monitor. The callable must return a number.
+ Callables are called with arguments supplied in argument array.
+ [b]Note:[/b] It throws an error if given id is already present.
+ </description>
+ </method>
+ <method name="get_custom_monitor">
+ <return type="Variant">
+ </return>
+ <argument index="0" name="id" type="StringName">
+ </argument>
+ <description>
+ Returns the value of custom monitor with given id. The callable is called to get the value of custom monitor.
+ [b]Note:[/b] It throws an error if the given id is absent.
+ </description>
+ </method>
+ <method name="get_custom_monitor_names">
+ <return type="Array">
+ </return>
+ <description>
+ Returns the names of active custom monitors in an array.
+ </description>
+ </method>
<method name="get_monitor" qualifiers="const">
<return type="float">
</return>
@@ -23,6 +66,32 @@
[/codeblock]
</description>
</method>
+ <method name="get_monitor_modification_time">
+ <return type="int">
+ </return>
+ <description>
+ Returns the last tick in which custom monitor was added/removed.
+ </description>
+ </method>
+ <method name="has_custom_monitor">
+ <return type="bool">
+ </return>
+ <argument index="0" name="id" type="StringName">
+ </argument>
+ <description>
+ Returns true if custom monitor with the given id is present otherwise returns false.
+ </description>
+ </method>
+ <method name="remove_custom_monitor">
+ <return type="void">
+ </return>
+ <argument index="0" name="id" type="StringName">
+ </argument>
+ <description>
+ Removes the custom monitor with given id.
+ [b]Note:[/b] It throws an error if the given id is already absent.
+ </description>
+ </method>
</methods>
<constants>
<constant name="TIME_FPS" value="0" enum="Monitor">
diff --git a/doc/classes/PhysicsShapeQueryParameters2D.xml b/doc/classes/PhysicsShapeQueryParameters2D.xml
index 9a162dabbb..63e13954ab 100644
--- a/doc/classes/PhysicsShapeQueryParameters2D.xml
+++ b/doc/classes/PhysicsShapeQueryParameters2D.xml
@@ -9,15 +9,6 @@
<tutorials>
</tutorials>
<methods>
- <method name="set_shape">
- <return type="void">
- </return>
- <argument index="0" name="shape" type="Resource">
- </argument>
- <description>
- Sets the [Shape2D] that will be used for collision/intersection queries.
- </description>
- </method>
</methods>
<members>
<member name="collide_with_areas" type="bool" setter="set_collide_with_areas" getter="is_collide_with_areas_enabled" default="false">
@@ -38,8 +29,24 @@
<member name="motion" type="Vector2" setter="set_motion" getter="get_motion" default="Vector2( 0, 0 )">
The motion of the shape being queried for.
</member>
+ <member name="shape" type="Resource" setter="set_shape" getter="get_shape">
+ The [Shape2D] that will be used for collision/intersection queries. This stores the actual reference which avoids the shape to be released while being used for queries, so always prefer using this over [member shape_rid].
+ </member>
<member name="shape_rid" type="RID" setter="set_shape_rid" getter="get_shape_rid">
- The queried shape's [RID]. See also [method set_shape].
+ The queried shape's [RID] that will be used for collision/intersection queries. Use this over [member shape] if you want to optimize for performance using the Servers API:
+ [codeblock]
+ var shape_rid = PhysicsServer2D.circle_shape_create()
+ var radius = 64
+ PhysicsServer2D.shape_set_data(shape_rid, radius)
+
+ var params = PhysicsShapeQueryParameters2D.new()
+ params.shape_rid = shape_rid
+
+ # Execute physics queries here...
+
+ # Release the shape when done with physics queries.
+ PhysicsServer2D.free_rid(shape_rid)
+ [/codeblock]
</member>
<member name="transform" type="Transform2D" setter="set_transform" getter="get_transform" default="Transform2D( 1, 0, 0, 1, 0, 0 )">
The queried shape's transform matrix.
diff --git a/doc/classes/PhysicsShapeQueryParameters3D.xml b/doc/classes/PhysicsShapeQueryParameters3D.xml
index 6606cfbc59..f4191d4862 100644
--- a/doc/classes/PhysicsShapeQueryParameters3D.xml
+++ b/doc/classes/PhysicsShapeQueryParameters3D.xml
@@ -9,15 +9,6 @@
<tutorials>
</tutorials>
<methods>
- <method name="set_shape">
- <return type="void">
- </return>
- <argument index="0" name="shape" type="Resource">
- </argument>
- <description>
- Sets the [Shape3D] that will be used for collision/intersection queries.
- </description>
- </method>
</methods>
<members>
<member name="collide_with_areas" type="bool" setter="set_collide_with_areas" getter="is_collide_with_areas_enabled" default="false">
@@ -35,8 +26,24 @@
<member name="margin" type="float" setter="set_margin" getter="get_margin" default="0.0">
The collision margin for the shape.
</member>
+ <member name="shape" type="Resource" setter="set_shape" getter="get_shape">
+ The [Shape3D] that will be used for collision/intersection queries. This stores the actual reference which avoids the shape to be released while being used for queries, so always prefer using this over [member shape_rid].
+ </member>
<member name="shape_rid" type="RID" setter="set_shape_rid" getter="get_shape_rid">
- The queried shape's [RID]. See also [method set_shape].
+ The queried shape's [RID] that will be used for collision/intersection queries. Use this over [member shape] if you want to optimize for performance using the Servers API:
+ [codeblock]
+ var shape_rid = PhysicsServer3D.shape_create(PhysicsServer3D.SHAPE_SPHERE)
+ var radius = 2.0
+ PhysicsServer3D.shape_set_data(shape_rid, radius)
+
+ var params = PhysicsShapeQueryParameters3D.new()
+ params.shape_rid = shape_rid
+
+ # Execute physics queries here...
+
+ # Release the shape when done with physics queries.
+ PhysicsServer3D.free_rid(shape_rid)
+ [/codeblock]
</member>
<member name="transform" type="Transform" setter="set_transform" getter="get_transform" default="Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )">
The queried shape's transform matrix.
diff --git a/drivers/dummy/rasterizer_dummy.h b/drivers/dummy/rasterizer_dummy.h
index 7af7678f63..636a885c89 100644
--- a/drivers/dummy/rasterizer_dummy.h
+++ b/drivers/dummy/rasterizer_dummy.h
@@ -51,6 +51,14 @@ public:
int get_directional_light_shadow_size(RID p_light_intance) { return 0; }
void set_directional_shadow_count(int p_count) {}
+ /* SDFGI UPDATE */
+
+ virtual void sdfgi_update(RID p_render_buffers, RID p_environment, const Vector3 &p_world_position) {}
+ virtual int sdfgi_get_pending_region_count(RID p_render_buffers) const { return 0; }
+ virtual AABB sdfgi_get_pending_region_bounds(RID p_render_buffers, int p_region) const { return AABB(); }
+ virtual uint32_t sdfgi_get_pending_region_cascade(RID p_render_buffers, int p_region) const { return 0; }
+ virtual void sdfgi_update_probes(RID p_render_buffers, RID p_environment, const RID *p_directional_light_instances, uint32_t p_directional_light_count, const RID *p_positional_light_instances, uint32_t p_positional_light_count) {}
+
/* SKY API */
RID sky_create() { return RID(); }
@@ -87,6 +95,11 @@ public:
virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_bias, float p_light_affect, float p_ao_channel_affect, RS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) {}
virtual void environment_set_ssao_quality(RS::EnvironmentSSAOQuality p_quality, bool p_half_size) {}
+ virtual void environment_set_sdfgi(RID p_env, bool p_enable, RS::EnvironmentSDFGICascades p_cascades, float p_min_cell_size, RS::EnvironmentSDFGIYScale p_y_scale, bool p_use_occlusion, bool p_use_multibounce, bool p_read_sky, bool p_enhance_ssr, float p_energy, float p_normal_bias, float p_probe_bias) {}
+
+ virtual void environment_set_sdfgi_ray_count(RS::EnvironmentSDFGIRayCount p_ray_count) {}
+ virtual void environment_set_sdfgi_frames_to_converge(RS::EnvironmentSDFGIFramesToConverge p_frames) {}
+
void environment_set_tonemap(RID p_env, RS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) {}
void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) {}
@@ -114,6 +127,7 @@ public:
RID light_instance_create(RID p_light) { return RID(); }
void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {}
+ virtual void light_instance_set_aabb(RID p_light_instance, const AABB &p_aabb) {}
void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_shadow_texel_size, float p_bias_scale = 1.0, float p_range_begin = 0, const Vector2 &p_uv_scale = Vector2()) {}
void light_instance_mark_visible(RID p_light_instance) {}
@@ -137,9 +151,13 @@ public:
virtual bool gi_probe_needs_update(RID p_probe) const { return false; }
virtual void gi_probe_update(RID p_probe, bool p_update_light_instances, const Vector<RID> &p_light_instances, int p_dynamic_object_count, InstanceBase **p_dynamic_objects) {}
+ virtual void gi_probe_set_quality(RS::GIProbeQuality) {}
+
virtual void render_scene(RID p_render_buffers, const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID *p_gi_probe_cull_result, int p_gi_probe_cull_count, RID *p_decal_cull_result, int p_decal_cull_count, InstanceBase **p_lightmap_cull_result, int p_lightmap_cull_count, RID p_environment, RID p_camera_effects, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) {}
void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) {}
virtual void render_material(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID p_framebuffer, const Rect2i &p_region) {}
+ virtual void render_sdfgi(RID p_render_buffers, int p_region, InstanceBase **p_cull_result, int p_cull_count) {}
+ virtual void render_sdfgi_static_lights(RID p_render_buffers, uint32_t p_cascade_count, const uint32_t *p_cascade_indices, const RID **p_positional_light_cull_result, const uint32_t *p_positional_light_cull_count) {}
void set_scene_pass(uint64_t p_pass) {}
virtual void set_time(double p_time, double p_step) {}
@@ -148,7 +166,7 @@ public:
virtual RID render_buffers_create() { return RID(); }
virtual void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, RS::ViewportMSAA p_msaa, RS::ViewportScreenSpaceAA p_screen_space_aa) {}
- virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_curve) {}
+ virtual void screen_space_roughness_limiter_set_active(bool p_enable, float p_amount, float p_curve) {}
virtual bool screen_space_roughness_limiter_is_active() const { return false; }
virtual void sub_surface_scattering_set_quality(RS::SubSurfaceScatteringQuality p_quality) {}
@@ -158,6 +176,7 @@ public:
bool free(RID p_rid) { return true; }
virtual void update() {}
+ virtual void sdfgi_set_debug_probe_select(const Vector3 &p_position, const Vector3 &p_dir) {}
RasterizerSceneDummy() {}
~RasterizerSceneDummy() {}
@@ -576,7 +595,8 @@ public:
void light_set_negative(RID p_light, bool p_enable) {}
void light_set_cull_mask(RID p_light, uint32_t p_mask) {}
void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) {}
- void light_set_use_gi(RID p_light, bool p_enabled) {}
+ void light_set_bake_mode(RID p_light, RS::LightBakeMode p_bake_mode) {}
+ void light_set_max_sdfgi_cascade(RID p_light, uint32_t p_cascade) {}
void light_omni_set_shadow_mode(RID p_light, RS::LightOmniShadowMode p_mode) {}
@@ -595,7 +615,8 @@ public:
AABB light_get_aabb(RID p_light) const { return AABB(); }
float light_get_param(RID p_light, RS::LightParam p_param) { return 0.0; }
Color light_get_color(RID p_light) { return Color(); }
- bool light_get_use_gi(RID p_light) { return false; }
+ virtual RS::LightBakeMode light_get_bake_mode(RID p_light) { return RS::LIGHT_BAKE_DISABLED; }
+ virtual uint32_t light_get_max_sdfgi_cascade(RID p_light) { return 0; }
uint64_t light_get_version(RID p_light) const { return 0; }
/* PROBE API */
@@ -604,9 +625,9 @@ public:
void reflection_probe_set_update_mode(RID p_probe, RS::ReflectionProbeUpdateMode p_mode) {}
void reflection_probe_set_intensity(RID p_probe, float p_intensity) {}
- void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient) {}
- void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy) {}
- void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib) {}
+ void reflection_probe_set_ambient_mode(RID p_probe, RS::ReflectionProbeAmbientMode p_mode) {}
+ void reflection_probe_set_ambient_color(RID p_probe, const Color &p_color) {}
+ void reflection_probe_set_ambient_energy(RID p_probe, float p_energy) {}
void reflection_probe_set_max_distance(RID p_probe, float p_distance) {}
void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) {}
void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) {}
diff --git a/editor/debugger/editor_performance_profiler.cpp b/editor/debugger/editor_performance_profiler.cpp
new file mode 100644
index 0000000000..47fe282758
--- /dev/null
+++ b/editor/debugger/editor_performance_profiler.cpp
@@ -0,0 +1,394 @@
+/*************************************************************************/
+/* editor_performance_profiler.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "editor_performance_profiler.h"
+
+#include "editor/editor_scale.h"
+#include "editor/editor_settings.h"
+#include "main/performance.h"
+
+EditorPerformanceProfiler::Monitor::Monitor() {}
+
+EditorPerformanceProfiler::Monitor::Monitor(String p_name, String p_base, int p_frame_index, Performance::MonitorType p_type, TreeItem *p_item) {
+ type = p_type;
+ item = p_item;
+ frame_index = p_frame_index;
+ name = p_name;
+ base = p_base;
+}
+
+void EditorPerformanceProfiler::Monitor::update_value(float p_value) {
+ ERR_FAIL_COND(!item);
+ String label = EditorPerformanceProfiler::_create_label(p_value, type);
+ String tooltip = label;
+ switch (type) {
+ case Performance::MONITOR_TYPE_MEMORY: {
+ tooltip = label;
+ } break;
+ case Performance::MONITOR_TYPE_TIME: {
+ tooltip = label;
+ } break;
+ default: {
+ tooltip += " " + item->get_text(0);
+ } break;
+ }
+ item->set_text(1, label);
+ item->set_tooltip(1, tooltip);
+
+ if (p_value > max) {
+ max = p_value;
+ }
+}
+
+void EditorPerformanceProfiler::Monitor::reset() {
+ history.clear();
+ max = 0.0f;
+ if (item) {
+ item->set_text(1, "");
+ item->set_tooltip(1, "");
+ }
+}
+
+String EditorPerformanceProfiler::_create_label(float p_value, Performance::MonitorType p_type) {
+ switch (p_type) {
+ case Performance::MONITOR_TYPE_MEMORY: {
+ return String::humanize_size(p_value);
+ }
+ case Performance::MONITOR_TYPE_TIME: {
+ return rtos(p_value * 1000).pad_decimals(2) + " ms";
+ }
+ default: {
+ return rtos(p_value);
+ }
+ }
+}
+
+void EditorPerformanceProfiler::_monitor_select() {
+ monitor_draw->update();
+}
+
+void EditorPerformanceProfiler::_monitor_draw() {
+ Vector<StringName> active;
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ if (i.value().item->is_checked(0)) {
+ active.push_back(i.key());
+ }
+ }
+
+ if (active.empty()) {
+ info_message->show();
+ return;
+ }
+
+ info_message->hide();
+
+ Ref<StyleBox> graph_style_box = get_theme_stylebox("normal", "TextEdit");
+ Ref<Font> graph_font = get_theme_font("font", "TextEdit");
+
+ int columns = int(Math::ceil(Math::sqrt(float(active.size()))));
+ int rows = int(Math::ceil(float(active.size()) / float(columns)));
+ if (active.size() == 1) {
+ rows = 1;
+ }
+ Size2i cell_size = Size2i(monitor_draw->get_size()) / Size2i(columns, rows);
+ float spacing = float(POINT_SEPARATION) / float(columns);
+ float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4f : 0.55f;
+ float hue_shift = 1.0f / float(monitors.size());
+
+ for (int i = 0; i < active.size(); i++) {
+ Monitor &current = monitors[active[i]];
+ Rect2i rect(Point2i(i % columns, i / columns) * cell_size + Point2i(MARGIN, MARGIN), cell_size - Point2i(MARGIN, MARGIN) * 2);
+ monitor_draw->draw_style_box(graph_style_box, rect);
+
+ rect.position += graph_style_box->get_offset();
+ rect.size -= graph_style_box->get_minimum_size();
+ Color draw_color = get_theme_color("accent_color", "Editor");
+ draw_color.set_hsv(Math::fmod(hue_shift * float(current.frame_index), 0.9f), draw_color.get_s() * 0.9f, draw_color.get_v() * value_multiplier, 0.6f);
+ monitor_draw->draw_string(graph_font, rect.position + Point2(0, graph_font->get_ascent()), current.item->get_text(0), draw_color, rect.size.x);
+
+ draw_color.a = 0.9f;
+ float value_position = rect.size.width - graph_font->get_string_size(current.item->get_text(1)).width;
+ if (value_position < 0) {
+ value_position = 0;
+ }
+ monitor_draw->draw_string(graph_font, rect.position + Point2(value_position, graph_font->get_ascent()), current.item->get_text(1), draw_color, rect.size.x);
+
+ rect.position.y += graph_font->get_height();
+ rect.size.height -= graph_font->get_height();
+
+ int line_count = rect.size.height / (graph_font->get_height() * 2);
+ if (line_count > 5) {
+ line_count = 5;
+ }
+ if (line_count > 0) {
+ Color horizontal_line_color;
+ horizontal_line_color.set_hsv(draw_color.get_h(), draw_color.get_s() * 0.5f, draw_color.get_v() * 0.5f, 0.3f);
+ monitor_draw->draw_line(rect.position, rect.position + Vector2(rect.size.width, 0), horizontal_line_color, Math::round(EDSCALE));
+ monitor_draw->draw_string(graph_font, rect.position + Vector2(0, graph_font->get_ascent()), _create_label(current.max, current.type), horizontal_line_color, rect.size.width);
+
+ for (int j = 0; j < line_count; j++) {
+ Vector2 y_offset = Vector2(0, rect.size.height * (1.0f - float(j) / float(line_count)));
+ monitor_draw->draw_line(rect.position + y_offset, rect.position + Vector2(rect.size.width, 0) + y_offset, horizontal_line_color, Math::round(EDSCALE));
+ monitor_draw->draw_string(graph_font, rect.position - Vector2(0, graph_font->get_descent()) + y_offset, _create_label(current.max * float(j) / float(line_count), current.type), horizontal_line_color, rect.size.width);
+ }
+ }
+
+ float from = rect.size.width;
+ float prev = -1.0f;
+ int count = 0;
+ List<float>::Element *e = current.history.front();
+
+ while (from >= 0 && e) {
+ float m = current.max;
+ float h2 = 0;
+ if (m != 0) {
+ h2 = (e->get() / m);
+ }
+ h2 = (1.0f - h2) * float(rect.size.y);
+ if (e != current.history.front()) {
+ monitor_draw->draw_line(rect.position + Point2(from, h2), rect.position + Point2(from + spacing, prev), draw_color, Math::round(EDSCALE));
+ }
+
+ if (marker_key == active[i] && count == marker_frame) {
+ Color line_color;
+ line_color.set_hsv(draw_color.get_h(), draw_color.get_s() * 0.8f, draw_color.get_v(), 0.5f);
+ monitor_draw->draw_line(rect.position + Point2(from, 0), rect.position + Point2(from, rect.size.y), line_color, Math::round(EDSCALE));
+
+ String label = _create_label(e->get(), current.type);
+ Size2 size = graph_font->get_string_size(label);
+ Vector2 text_top_left_position = Vector2(from, h2) - (size + Vector2(MARKER_MARGIN, MARKER_MARGIN));
+ if (text_top_left_position.x < 0) {
+ text_top_left_position.x = from + MARKER_MARGIN;
+ }
+ if (text_top_left_position.y < 0) {
+ text_top_left_position.y = h2 + MARKER_MARGIN;
+ }
+ monitor_draw->draw_string(graph_font, rect.position + text_top_left_position + Point2(0, graph_font->get_ascent()), label, line_color, rect.size.x);
+ }
+ prev = h2;
+ e = e->next();
+ from -= spacing;
+ count++;
+ }
+ }
+}
+
+void EditorPerformanceProfiler::_build_monitor_tree() {
+ Set<StringName> monitor_checked;
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ if (i.value().item && i.value().item->is_checked(0)) {
+ monitor_checked.insert(i.key());
+ }
+ }
+
+ base_map.clear();
+ monitor_tree->get_root()->clear_children();
+
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ TreeItem *base = _get_monitor_base(i.value().base);
+ TreeItem *item = _create_monitor_item(i.value().name, base);
+ item->set_checked(0, monitor_checked.has(i.key()));
+ i.value().item = item;
+ if (!i.value().history.empty()) {
+ i.value().update_value(i.value().history.front()->get());
+ }
+ }
+}
+
+TreeItem *EditorPerformanceProfiler::_get_monitor_base(const StringName &p_base_name) {
+ if (base_map.has(p_base_name)) {
+ return base_map[p_base_name];
+ }
+
+ TreeItem *base = monitor_tree->create_item(monitor_tree->get_root());
+ base->set_text(0, p_base_name);
+ base->set_editable(0, false);
+ base->set_selectable(0, false);
+ base->set_expand_right(0, true);
+ base_map.insert(p_base_name, base);
+ return base;
+}
+
+TreeItem *EditorPerformanceProfiler::_create_monitor_item(const StringName &p_monitor_name, TreeItem *p_base) {
+ TreeItem *item = monitor_tree->create_item(p_base);
+ item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
+ item->set_editable(0, true);
+ item->set_selectable(0, false);
+ item->set_selectable(1, false);
+ item->set_text(0, p_monitor_name);
+ return item;
+}
+
+void EditorPerformanceProfiler::_marker_input(const Ref<InputEvent> &p_event) {
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+ Vector<StringName> active;
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ if (i.value().item->is_checked(0)) {
+ active.push_back(i.key());
+ }
+ }
+ if (active.size() > 0) {
+ int columns = int(Math::ceil(Math::sqrt(float(active.size()))));
+ int rows = int(Math::ceil(float(active.size()) / float(columns)));
+ if (active.size() == 1) {
+ rows = 1;
+ }
+ Size2i cell_size = Size2i(monitor_draw->get_size()) / Size2i(columns, rows);
+ Vector2i index = mb->get_position() / cell_size;
+ Rect2i rect(index * cell_size + Point2i(MARGIN, MARGIN), cell_size - Point2i(MARGIN, MARGIN) * 2);
+ if (rect.has_point(mb->get_position())) {
+ if (index.x + index.y * columns < active.size()) {
+ marker_key = active[index.x + index.y * columns];
+ } else {
+ marker_key = "";
+ }
+ Ref<StyleBox> graph_style_box = get_theme_stylebox("normal", "TextEdit");
+ rect.position += graph_style_box->get_offset();
+ rect.size -= graph_style_box->get_minimum_size();
+ Vector2 point = mb->get_position() - rect.position;
+ if (point.x >= rect.size.x) {
+ marker_frame = 0;
+ } else {
+ int point_sep = 5;
+ float spacing = float(point_sep) / float(columns);
+ marker_frame = (rect.size.x - point.x) / spacing;
+ }
+ monitor_draw->update();
+ return;
+ }
+ }
+ marker_key = "";
+ monitor_draw->update();
+ }
+}
+
+void EditorPerformanceProfiler::reset() {
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ if (String(i.key()).begins_with("custom:")) {
+ monitors.erase(i);
+ } else {
+ i.value().reset();
+ }
+ }
+
+ _build_monitor_tree();
+ marker_key = "";
+ marker_frame = 0;
+ monitor_draw->update();
+}
+
+void EditorPerformanceProfiler::update_monitors(const Vector<StringName> &p_names) {
+ OrderedHashMap<StringName, int> names;
+ for (int i = 0; i < p_names.size(); i++) {
+ names.insert("custom:" + p_names[i], Performance::MONITOR_MAX + i);
+ }
+
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ if (String(i.key()).begins_with("custom:")) {
+ if (!names.has(i.key())) {
+ monitors.erase(i);
+ } else {
+ i.value().frame_index = names[i.key()];
+ names.erase(i.key());
+ }
+ }
+ }
+
+ for (OrderedHashMap<StringName, int>::Element i = names.front(); i; i = i.next()) {
+ String name = String(i.key()).replace_first("custom:", "");
+ String base = "Custom";
+ if (name.get_slice_count("/") == 2) {
+ base = name.get_slicec('/', 0);
+ name = name.get_slicec('/', 1);
+ }
+ monitors.insert(i.key(), Monitor(name, base, i.value(), Performance::MONITOR_TYPE_QUANTITY, nullptr));
+ }
+
+ _build_monitor_tree();
+}
+
+void EditorPerformanceProfiler::add_profile_frame(const Vector<float> &p_values) {
+ for (OrderedHashMap<StringName, Monitor>::Element i = monitors.front(); i; i = i.next()) {
+ float data = 0.0f;
+ if (i.value().frame_index >= 0 && i.value().frame_index < p_values.size()) {
+ data = p_values[i.value().frame_index];
+ }
+ i.value().history.push_front(data);
+ i.value().update_value(data);
+ }
+ marker_frame++;
+ monitor_draw->update();
+}
+
+List<float> *EditorPerformanceProfiler::get_monitor_data(const StringName &p_name) {
+ if (monitors.has(p_name)) {
+ return &monitors[p_name].history;
+ }
+ return nullptr;
+}
+
+EditorPerformanceProfiler::EditorPerformanceProfiler() {
+ set_name(TTR("Monitors"));
+ set_split_offset(340 * EDSCALE);
+
+ monitor_tree = memnew(Tree);
+ monitor_tree->set_columns(2);
+ monitor_tree->set_column_title(0, TTR("Monitor"));
+ monitor_tree->set_column_title(1, TTR("Value"));
+ monitor_tree->set_column_titles_visible(true);
+ monitor_tree->connect("item_edited", callable_mp(this, &EditorPerformanceProfiler::_monitor_select));
+ monitor_tree->create_item();
+ monitor_tree->set_hide_root(true);
+ add_child(monitor_tree);
+
+ monitor_draw = memnew(Control);
+ monitor_draw->set_clip_contents(true);
+ monitor_draw->connect("draw", callable_mp(this, &EditorPerformanceProfiler::_monitor_draw));
+ monitor_draw->connect("gui_input", callable_mp(this, &EditorPerformanceProfiler::_marker_input));
+ add_child(monitor_draw);
+
+ info_message = memnew(Label);
+ info_message->set_text(TTR("Pick one or more items from the list to display the graph."));
+ info_message->set_valign(Label::VALIGN_CENTER);
+ info_message->set_align(Label::ALIGN_CENTER);
+ info_message->set_autowrap(true);
+ info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
+ info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
+ monitor_draw->add_child(info_message);
+
+ for (int i = 0; i < Performance::MONITOR_MAX; i++) {
+ String base = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)).get_slicec('/', 0).capitalize();
+ String name = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)).get_slicec('/', 1).capitalize();
+ monitors.insert(Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)), Monitor(name, base, i, Performance::get_singleton()->get_monitor_type(Performance::Monitor(i)), nullptr));
+ }
+
+ _build_monitor_tree();
+}
diff --git a/editor/debugger/editor_performance_profiler.h b/editor/debugger/editor_performance_profiler.h
new file mode 100644
index 0000000000..144dd34103
--- /dev/null
+++ b/editor/debugger/editor_performance_profiler.h
@@ -0,0 +1,90 @@
+/*************************************************************************/
+/* editor_performance_profiler.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef EDITOR_PERFORMANCE_PROFILER_H
+#define EDITOR_PERFORMANCE_PROFILER_H
+
+#include "core/map.h"
+#include "core/ordered_hash_map.h"
+#include "main/performance.h"
+#include "scene/gui/control.h"
+#include "scene/gui/label.h"
+#include "scene/gui/split_container.h"
+#include "scene/gui/tree.h"
+
+class EditorPerformanceProfiler : public HSplitContainer {
+ GDCLASS(EditorPerformanceProfiler, HSplitContainer);
+
+private:
+ class Monitor {
+ public:
+ String name;
+ String base;
+ List<float> history;
+ float max = 0.0f;
+ TreeItem *item = nullptr;
+ Performance::MonitorType type = Performance::MONITOR_TYPE_QUANTITY;
+ int frame_index = 0;
+
+ Monitor();
+ Monitor(String p_name, String p_base, int p_frame_index, Performance::MonitorType p_type, TreeItem *p_item);
+ void update_value(float p_value);
+ void reset();
+ };
+
+ OrderedHashMap<StringName, Monitor> monitors;
+
+ Map<StringName, TreeItem *> base_map;
+ Tree *monitor_tree;
+ Control *monitor_draw;
+ Label *info_message;
+ StringName marker_key;
+ int marker_frame;
+ const int MARGIN = 4;
+ const int POINT_SEPARATION = 5;
+ const int MARKER_MARGIN = 2;
+
+ static String _create_label(float p_value, Performance::MonitorType p_type);
+ void _monitor_select();
+ void _monitor_draw();
+ void _build_monitor_tree();
+ TreeItem *_get_monitor_base(const StringName &p_base_name);
+ TreeItem *_create_monitor_item(const StringName &p_monitor_name, TreeItem *p_base);
+ void _marker_input(const Ref<InputEvent> &p_event);
+
+public:
+ void reset();
+ void update_monitors(const Vector<StringName> &p_names);
+ void add_profile_frame(const Vector<float> &p_values);
+ List<float> *get_monitor_data(const StringName &p_name);
+ EditorPerformanceProfiler();
+};
+
+#endif // EDITOR_PERFORMANCE_PROFILER_H
diff --git a/editor/debugger/script_editor_debugger.cpp b/editor/debugger/script_editor_debugger.cpp
index 6b010fbfb5..a828e29558 100644
--- a/editor/debugger/script_editor_debugger.cpp
+++ b/editor/debugger/script_editor_debugger.cpp
@@ -36,6 +36,7 @@
#include "core/project_settings.h"
#include "core/ustring.h"
#include "editor/debugger/editor_network_profiler.h"
+#include "editor/debugger/editor_performance_profiler.h"
#include "editor/debugger/editor_profiler.h"
#include "editor/debugger/editor_visual_profiler.h"
#include "editor/editor_log.h"
@@ -172,14 +173,25 @@ void ScriptEditorDebugger::_file_selected(const String &p_file) {
file->store_csv_line(line);
// values
- List<Vector<float>>::Element *E = perf_history.back();
- while (E) {
- Vector<float> &perf_data = E->get();
- for (int i = 0; i < perf_data.size(); i++) {
- line.write[i] = String::num_real(perf_data[i]);
+ Vector<List<float>::Element *> iterators;
+ iterators.resize(Performance::MONITOR_MAX);
+ bool continue_iteration = false;
+ for (int i = 0; i < Performance::MONITOR_MAX; i++) {
+ iterators.write[i] = performance_profiler->get_monitor_data(Performance::get_singleton()->get_monitor_name(Performance::Monitor(i)))->back();
+ continue_iteration = continue_iteration || iterators[i];
+ }
+ while (continue_iteration) {
+ continue_iteration = false;
+ for (int i = 0; i < Performance::MONITOR_MAX; i++) {
+ if (iterators[i]) {
+ line.write[i] = String::num_real(iterators[i]->get());
+ iterators.write[i] = iterators[i]->prev();
+ } else {
+ line.write[i] = "";
+ }
+ continue_iteration = continue_iteration || iterators[i];
}
file->store_csv_line(line);
- E = E->prev();
}
file->store_string("\n");
@@ -409,37 +421,12 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
EditorNode::get_log()->add_message(output_strings[i], msg_type);
}
} else if (p_msg == "performance:profile_frame") {
- Vector<float> p;
- p.resize(p_data.size());
+ Vector<float> frame_data;
+ frame_data.resize(p_data.size());
for (int i = 0; i < p_data.size(); i++) {
- p.write[i] = p_data[i];
- if (i < perf_items.size()) {
- const float value = p[i];
- String label = rtos(value);
- String tooltip = label;
- switch (Performance::MonitorType((int)perf_items[i]->get_metadata(1))) {
- case Performance::MONITOR_TYPE_MEMORY: {
- label = String::humanize_size(value);
- tooltip = label;
- } break;
- case Performance::MONITOR_TYPE_TIME: {
- label = rtos(value * 1000).pad_decimals(2) + " ms";
- tooltip = label;
- } break;
- default: {
- tooltip += " " + perf_items[i]->get_text(0);
- } break;
- }
-
- perf_items[i]->set_text(1, label);
- perf_items[i]->set_tooltip(1, tooltip);
- if (p[i] > perf_max[i]) {
- perf_max.write[i] = p[i];
- }
- }
+ frame_data.write[i] = p_data[i];
}
- perf_history.push_front(p);
- perf_draw->update();
+ performance_profiler->add_profile_frame(frame_data);
} else if (p_msg == "visual:profile_frame") {
DebuggerMarshalls::VisualProfilerFrame frame;
@@ -704,6 +691,15 @@ void ScriptEditorDebugger::_parse_message(const String &p_msg, const Array &p_da
emit_signal("stop_requested");
_stop_and_notify();
+ } else if (p_msg == "performance:profile_names") {
+ Vector<StringName> monitors;
+ monitors.resize(p_data.size());
+ for (int i = 0; i < p_data.size(); i++) {
+ ERR_FAIL_COND(p_data[i].get_type() != Variant::STRING_NAME);
+ monitors.set(i, p_data[i]);
+ }
+ performance_profiler->update_monitors(monitors);
+
} else {
WARN_PRINT("unknown message " + p_msg);
}
@@ -724,141 +720,6 @@ void ScriptEditorDebugger::_set_reason_text(const String &p_reason, MessageType
reason->set_tooltip(p_reason.word_wrap(80));
}
-void ScriptEditorDebugger::_performance_select() {
- perf_draw->update();
-}
-
-void ScriptEditorDebugger::_performance_draw() {
- Vector<int> which;
- for (int i = 0; i < perf_items.size(); i++) {
- if (perf_items[i]->is_checked(0)) {
- which.push_back(i);
- }
- }
-
- if (which.empty()) {
- info_message->show();
- return;
- }
-
- info_message->hide();
-
- const Ref<StyleBox> graph_sb = get_theme_stylebox("normal", "TextEdit");
- const Ref<Font> graph_font = get_theme_font("font", "TextEdit");
-
- const int cols = Math::ceil(Math::sqrt((float)which.size()));
- int rows = Math::ceil((float)which.size() / cols);
- if (which.size() == 1) {
- rows = 1;
- }
-
- const int margin = 3;
- const int point_sep = 5;
- const Size2i s = Size2i(perf_draw->get_size()) / Size2i(cols, rows);
-
- for (int i = 0; i < which.size(); i++) {
- Point2i p(i % cols, i / cols);
- Rect2i r(p * s, s);
- r.position += Point2(margin, margin);
- r.size -= Point2(margin, margin) * 2.0;
- perf_draw->draw_style_box(graph_sb, r);
- r.position += graph_sb->get_offset();
- r.size -= graph_sb->get_minimum_size();
- const int pi = which[i];
-
- // Draw horizontal lines with labels.
-
- int nb_lines = 5;
- // Draw less lines if the monitor isn't tall enough to display 5 labels.
- if (r.size.height <= 160 * EDSCALE) {
- nb_lines = 3;
- } else if (r.size.height <= 240 * EDSCALE) {
- nb_lines = 4;
- }
-
- const float inv_nb_lines = 1.0 / nb_lines;
-
- for (int line = 0; line < nb_lines; line += 1) {
- const int from_x = r.position.x;
- const int to_x = r.position.x + r.size.width;
- const int y = r.position.y + (r.size.height * inv_nb_lines + line * inv_nb_lines * r.size.height);
- perf_draw->draw_line(
- Point2(from_x, y),
- Point2i(to_x, y),
- Color(0.5, 0.5, 0.5, 0.25),
- Math::round(EDSCALE));
-
- String label;
- switch (Performance::MonitorType((int)perf_items[pi]->get_metadata(1))) {
- case Performance::MONITOR_TYPE_MEMORY: {
- label = String::humanize_size(Math::ceil((1 - inv_nb_lines - inv_nb_lines * line) * perf_max[pi]));
- } break;
- case Performance::MONITOR_TYPE_TIME: {
- label = rtos((1 - inv_nb_lines - inv_nb_lines * line) * perf_max[pi] * 1000).pad_decimals(2) + " ms";
- } break;
- default: {
- label = itos(Math::ceil((1 - inv_nb_lines - inv_nb_lines * line) * perf_max[pi]));
- } break;
- }
-
- perf_draw->draw_string(
- graph_font,
- Point2(from_x, y - graph_font->get_ascent() * 0.25),
- label,
- Color(0.5, 0.5, 0.5, 1.0));
- }
-
- const float h = (float)which[i] / (float)(perf_items.size());
- // Use a darker color on light backgrounds for better visibility.
- const float value_multiplier = EditorSettings::get_singleton()->is_dark_theme() ? 1.4 : 0.55;
- Color color = get_theme_color("accent_color", "Editor");
- color.set_hsv(Math::fmod(h + 0.4, 0.9), color.get_s() * 0.9, color.get_v() * value_multiplier);
-
- // Draw the monitor name in the top-left corner.
- color.a = 0.6;
- perf_draw->draw_string(
- graph_font,
- r.position + Point2(0, graph_font->get_ascent()),
- perf_items[pi]->get_text(0),
- color,
- r.size.x);
-
- // Draw the monitor value in the top-left corner, just below the name.
- color.a = 0.9;
- perf_draw->draw_string(
- graph_font,
- r.position + Point2(0, graph_font->get_ascent() + graph_font->get_height()),
- perf_items[pi]->get_text(1),
- color,
- r.size.y);
-
- const float spacing = point_sep / float(cols);
- float from = r.size.width;
-
- const List<Vector<float>>::Element *E = perf_history.front();
- float prev = -1;
- while (from >= 0 && E) {
- float m = perf_max[pi];
- if (m == 0) {
- m = 0.00001;
- }
- float h2 = E->get()[pi] / m;
- h2 = (1.0 - h2) * r.size.y;
-
- if (E != perf_history.front()) {
- perf_draw->draw_line(
- r.position + Point2(from, h2),
- r.position + Point2(from + spacing, prev),
- color,
- Math::round(EDSCALE));
- }
- prev = h2;
- E = E->next();
- from -= spacing;
- }
- }
-}
-
void ScriptEditorDebugger::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -976,10 +837,7 @@ void ScriptEditorDebugger::start(Ref<RemoteDebuggerPeer> p_peer) {
peer = p_peer;
ERR_FAIL_COND(p_peer.is_null());
- perf_history.clear();
- for (int i = 0; i < Performance::MONITOR_MAX; i++) {
- perf_max.write[i] = 0;
- }
+ performance_profiler->reset();
set_process(true);
breaked = false;
@@ -1727,63 +1585,8 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor) {
}
{ //monitors
-
- HSplitContainer *hsp = memnew(HSplitContainer);
-
- perf_monitors = memnew(Tree);
- perf_monitors->set_columns(2);
- perf_monitors->set_column_title(0, TTR("Monitor"));
- perf_monitors->set_column_title(1, TTR("Value"));
- perf_monitors->set_column_titles_visible(true);
- perf_monitors->connect("item_edited", callable_mp(this, &ScriptEditorDebugger::_performance_select));
- hsp->add_child(perf_monitors);
-
- perf_draw = memnew(Control);
- perf_draw->set_clip_contents(true);
- perf_draw->connect("draw", callable_mp(this, &ScriptEditorDebugger::_performance_draw));
- hsp->add_child(perf_draw);
-
- hsp->set_name(TTR("Monitors"));
- hsp->set_split_offset(340 * EDSCALE);
- tabs->add_child(hsp);
- perf_max.resize(Performance::MONITOR_MAX);
-
- Map<String, TreeItem *> bases;
- TreeItem *root = perf_monitors->create_item();
- perf_monitors->set_hide_root(true);
- for (int i = 0; i < Performance::MONITOR_MAX; i++) {
- String n = Performance::get_singleton()->get_monitor_name(Performance::Monitor(i));
- Performance::MonitorType mtype = Performance::get_singleton()->get_monitor_type(Performance::Monitor(i));
- String base = n.get_slice("/", 0);
- String name = n.get_slice("/", 1);
- if (!bases.has(base)) {
- TreeItem *b = perf_monitors->create_item(root);
- b->set_text(0, base.capitalize());
- b->set_editable(0, false);
- b->set_selectable(0, false);
- b->set_expand_right(0, true);
- bases[base] = b;
- }
-
- TreeItem *it = perf_monitors->create_item(bases[base]);
- it->set_metadata(1, mtype);
- it->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
- it->set_editable(0, true);
- it->set_selectable(0, false);
- it->set_selectable(1, false);
- it->set_text(0, name.capitalize());
- perf_items.push_back(it);
- perf_max.write[i] = 0;
- }
-
- info_message = memnew(Label);
- info_message->set_text(TTR("Pick one or more items from the list to display the graph."));
- info_message->set_valign(Label::VALIGN_CENTER);
- info_message->set_align(Label::ALIGN_CENTER);
- info_message->set_autowrap(true);
- info_message->set_custom_minimum_size(Size2(100 * EDSCALE, 0));
- info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE);
- perf_draw->add_child(info_message);
+ performance_profiler = memnew(EditorPerformanceProfiler);
+ tabs->add_child(performance_profiler);
}
{ //vmem inspect
diff --git a/editor/debugger/script_editor_debugger.h b/editor/debugger/script_editor_debugger.h
index 2984051aa1..12fb82cc6f 100644
--- a/editor/debugger/script_editor_debugger.h
+++ b/editor/debugger/script_editor_debugger.h
@@ -52,6 +52,7 @@ class ItemList;
class EditorProfiler;
class EditorVisualProfiler;
class EditorNetworkProfiler;
+class EditorPerformanceProfiler;
class SceneDebuggerTree;
class ScriptEditorDebugger : public MarginContainer {
@@ -113,16 +114,8 @@ private:
// Each debugger should have it's tree in the future I guess.
const Tree *editor_remote_tree = nullptr;
- List<Vector<float>> perf_history;
- Vector<float> perf_max;
- Vector<TreeItem *> perf_items;
-
Map<int, String> profiler_signature;
- Tree *perf_monitors;
- Control *perf_draw;
- Label *info_message;
-
Tree *vmem_tree;
Button *vmem_refresh;
Button *vmem_export;
@@ -141,6 +134,7 @@ private:
EditorProfiler *profiler;
EditorVisualProfiler *visual_profiler;
EditorNetworkProfiler *network_profiler;
+ EditorPerformanceProfiler *performance_profiler;
EditorNode *editor;
@@ -152,8 +146,6 @@ private:
EditorDebuggerNode::CameraOverride camera_override;
- void _performance_draw();
- void _performance_select();
void _stack_dump_frame_selected();
void _file_selected(const String &p_file);
diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp
index d2b9405552..4392538737 100644
--- a/editor/editor_help_search.cpp
+++ b/editor/editor_help_search.cpp
@@ -332,17 +332,10 @@ bool EditorHelpSearch::Runner::_phase_match_classes() {
if (search_flags & SEARCH_METHODS) {
for (int i = 0; i < class_doc.methods.size(); i++) {
String method_name = (search_flags & SEARCH_CASE_SENSITIVE) ? class_doc.methods[i].name : class_doc.methods[i].name.to_lower();
- String aux_term = (search_flags & SEARCH_CASE_SENSITIVE) ? term : term.to_lower();
-
- if (aux_term.begins_with(".")) {
- aux_term = aux_term.right(1);
- }
-
- if (aux_term.ends_with("(")) {
- aux_term = aux_term.left(aux_term.length() - 1).strip_edges();
- }
-
- if (aux_term.is_subsequence_of(method_name)) {
+ if (method_name.find(term) > -1 ||
+ (term.begins_with(".") && method_name.begins_with(term.right(1))) ||
+ (term.ends_with("(") && method_name.ends_with(term.left(term.length() - 1).strip_edges())) ||
+ (term.begins_with(".") && term.ends_with("(") && method_name == term.substr(1, term.length() - 2).strip_edges())) {
match.methods.push_back(const_cast<DocData::MethodDoc *>(&class_doc.methods[i]));
}
}
@@ -448,9 +441,9 @@ bool EditorHelpSearch::Runner::_phase_select_match() {
bool EditorHelpSearch::Runner::_match_string(const String &p_term, const String &p_string) const {
if (search_flags & SEARCH_CASE_SENSITIVE) {
- return p_term.is_subsequence_of(p_string);
+ return p_string.find(p_term) > -1;
} else {
- return p_term.is_subsequence_ofi(p_string);
+ return p_string.findn(p_term) > -1;
}
}
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index f2f8805aaf..8909fb2cfe 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -435,14 +435,14 @@ void EditorNode::_notification(int p_what) {
/* DO NOT LOAD SCENES HERE, WAIT FOR FILE SCANNING AND REIMPORT TO COMPLETE */
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
+ case NOTIFICATION_APPLICATION_FOCUS_IN: {
// Restore the original FPS cap after focusing back on the editor
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/low_processor_mode_sleep_usec")));
EditorFileSystem::get_singleton()->scan_changes();
} break;
- case NOTIFICATION_WM_FOCUS_OUT: {
+ case NOTIFICATION_APPLICATION_FOCUS_OUT: {
// Set a low FPS cap to decrease CPU/GPU usage while the editor is unfocused
OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec")));
} break;
diff --git a/editor/editor_plugin_settings.cpp b/editor/editor_plugin_settings.cpp
index b5f1133a9e..fe49198e8f 100644
--- a/editor/editor_plugin_settings.cpp
+++ b/editor/editor_plugin_settings.cpp
@@ -39,7 +39,7 @@
#include "scene/gui/margin_container.h"
void EditorPluginSettings::_notification(int p_what) {
- if (p_what == NOTIFICATION_WM_FOCUS_IN) {
+ if (p_what == NOTIFICATION_WM_WINDOW_FOCUS_IN) {
update_plugins();
} else if (p_what == Node::NOTIFICATION_READY) {
plugin_config_dialog->connect_compat("plugin_ready", EditorNode::get_singleton(), "_on_plugin_ready");
diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp
index 67d92c4839..d76a3d2da7 100644
--- a/editor/editor_spin_slider.cpp
+++ b/editor/editor_spin_slider.cpp
@@ -182,8 +182,8 @@ void EditorSpinSlider::_grabber_gui_input(const Ref<InputEvent> &p_event) {
}
void EditorSpinSlider::_notification(int p_what) {
- if (p_what == NOTIFICATION_WM_FOCUS_OUT ||
- p_what == NOTIFICATION_WM_FOCUS_IN ||
+ if (p_what == NOTIFICATION_WM_WINDOW_FOCUS_OUT ||
+ p_what == NOTIFICATION_WM_WINDOW_FOCUS_IN ||
p_what == NOTIFICATION_EXIT_TREE) {
if (grabbing_spinner) {
grabber->hide();
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 96079d5418..fd415d40da 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1337,7 +1337,7 @@ void ScriptEditor::_notification(int p_what) {
editor->disconnect("stop_pressed", callable_mp(this, &ScriptEditor::_editor_stop));
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
_test_script_times_on_disk();
_update_modified_scripts_for_external_editor();
} break;
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index 0c3a44e4cd..7dd0b8a238 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -338,7 +338,7 @@ void ShaderEditor::_menu_option(int p_option) {
}
void ShaderEditor::_notification(int p_what) {
- if (p_what == NOTIFICATION_WM_FOCUS_IN) {
+ if (p_what == NOTIFICATION_WM_WINDOW_FOCUS_IN) {
_check_for_external_edit();
}
}
diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp
index 0ac29f68f6..f15a801530 100644
--- a/editor/plugins/shader_file_editor_plugin.cpp
+++ b/editor/plugins/shader_file_editor_plugin.cpp
@@ -200,7 +200,7 @@ void ShaderFileEditor::_update_options() {
}
void ShaderFileEditor::_notification(int p_what) {
- if (p_what == NOTIFICATION_WM_FOCUS_IN) {
+ if (p_what == NOTIFICATION_WM_WINDOW_FOCUS_IN) {
if (is_visible_in_tree() && shader_file.is_valid()) {
_update_options();
}
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 3a92818779..762f42abeb 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -780,7 +780,7 @@ void TextureRegionEditor::_notification(int p_what) {
_update_autoslice();
}
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
// This happens when the user leaves the Editor and returns,
// they could have changed the textures, so the cache is cleared.
cache_map.clear();
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index e0693df838..9831f1bd31 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -350,17 +350,22 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
if (!profile_allow_editing) {
break;
}
- String preferred = "";
- Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
+ // Prefer nodes that inherit from the current scene root.
+ Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
if (current_edited_scene_root) {
- if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D")) {
- preferred = "Node2D";
- } else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node3D")) {
- preferred = "Node3D";
+ static const String preferred_types[] = { "Node2D", "Node3D", "Control" };
+
+ StringName root_class = current_edited_scene_root->get_class_name();
+
+ for (int i = 0; i < preferred_types->size(); i++) {
+ if (ClassDB::is_parent_class(root_class, preferred_types[i])) {
+ create_dialog->set_preferred_search_result_type(preferred_types[i]);
+ break;
+ }
}
}
- create_dialog->set_preferred_search_result_type(preferred);
+
create_dialog->popup_create(true);
} break;
case TOOL_INSTANCE: {
diff --git a/main/main.cpp b/main/main.cpp
index 00760b39b0..79c8fe532d 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -1620,7 +1620,7 @@ bool Main::start() {
{
DirAccessRef da = DirAccess::open(doc_tool);
- ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a base Godot build directory.");
+ ERR_FAIL_COND_V_MSG(!da, false, "Argument supplied to --doctool must be a valid directory path.");
}
#ifndef MODULE_MONO_ENABLED
@@ -2115,7 +2115,6 @@ bool Main::start() {
*/
uint64_t Main::last_ticks = 0;
-uint64_t Main::target_ticks = 0;
uint32_t Main::frames = 0;
uint32_t Main::frame = 0;
bool Main::force_redraw_requested = false;
@@ -2266,38 +2265,7 @@ bool Main::iteration() {
return exit;
}
- const uint32_t frame_delay = Engine::get_singleton()->get_frame_delay();
- if (frame_delay) {
- // Add fixed frame delay to decrease CPU/GPU usage. This doesn't take
- // the actual frame time into account.
- // Due to the high fluctuation of the actual sleep duration, it's not recommended
- // to use this as a FPS limiter.
- OS::get_singleton()->delay_usec(frame_delay * 1000);
- }
-
- // Add a dynamic frame delay to decrease CPU/GPU usage. This takes the
- // previous frame time into account for a smoother result.
- uint64_t dynamic_delay = 0;
- if (OS::get_singleton()->is_in_low_processor_usage_mode() || !DisplayServer::get_singleton()->window_can_draw()) {
- dynamic_delay = OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
- }
- const int target_fps = Engine::get_singleton()->get_target_fps();
- if (target_fps > 0 && !Engine::get_singleton()->is_editor_hint()) {
- // Override the low processor usage mode sleep delay if the target FPS is lower.
- dynamic_delay = MAX(dynamic_delay, (uint64_t)(1000000 / target_fps));
- }
-
- if (dynamic_delay > 0) {
- target_ticks += dynamic_delay;
- uint64_t current_ticks = OS::get_singleton()->get_ticks_usec();
-
- if (current_ticks < target_ticks) {
- OS::get_singleton()->delay_usec(target_ticks - current_ticks);
- }
-
- current_ticks = OS::get_singleton()->get_ticks_usec();
- target_ticks = MIN(MAX(target_ticks, current_ticks - dynamic_delay), current_ticks + dynamic_delay);
- }
+ OS::get_singleton()->add_frame_delay(DisplayServer::get_singleton()->window_can_draw());
#ifdef TOOLS_ENABLED
if (auto_build_solutions) {
diff --git a/main/main.h b/main/main.h
index ab6917a65c..308128735c 100644
--- a/main/main.h
+++ b/main/main.h
@@ -38,7 +38,6 @@
class Main {
static void print_help(const char *p_binary);
static uint64_t last_ticks;
- static uint64_t target_ticks;
static uint32_t frames;
static uint32_t frame;
static bool force_redraw_requested;
diff --git a/main/performance.cpp b/main/performance.cpp
index 7e6b9fca64..7234511aeb 100644
--- a/main/performance.cpp
+++ b/main/performance.cpp
@@ -43,6 +43,12 @@ Performance *Performance::singleton = nullptr;
void Performance::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_monitor", "monitor"), &Performance::get_monitor);
+ ClassDB::bind_method(D_METHOD("add_custom_monitor", "id", "callable", "arguments"), &Performance::add_custom_monitor, DEFVAL(Array()));
+ ClassDB::bind_method(D_METHOD("remove_custom_monitor", "id"), &Performance::remove_custom_monitor);
+ ClassDB::bind_method(D_METHOD("has_custom_monitor", "id"), &Performance::has_custom_monitor);
+ ClassDB::bind_method(D_METHOD("get_custom_monitor", "id"), &Performance::get_custom_monitor);
+ ClassDB::bind_method(D_METHOD("get_monitor_modification_time"), &Performance::get_monitor_modification_time);
+ ClassDB::bind_method(D_METHOD("get_custom_monitor_names"), &Performance::get_custom_monitor_names);
BIND_ENUM_CONSTANT(TIME_FPS);
BIND_ENUM_CONSTANT(TIME_PROCESS);
@@ -231,8 +237,78 @@ void Performance::set_physics_process_time(float p_pt) {
_physics_process_time = p_pt;
}
+void Performance::add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args) {
+ ERR_FAIL_COND_MSG(has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' already exists.");
+ _monitor_map.insert(p_id, MonitorCall(p_callable, p_args));
+ _monitor_modification_time = OS::get_singleton()->get_ticks_usec();
+}
+
+void Performance::remove_custom_monitor(const StringName &p_id) {
+ ERR_FAIL_COND_MSG(!has_custom_monitor(p_id), "Custom monitor with id '" + String(p_id) + "' doesn't exists.");
+ _monitor_map.erase(p_id);
+ _monitor_modification_time = OS::get_singleton()->get_ticks_usec();
+}
+
+bool Performance::has_custom_monitor(const StringName &p_id) {
+ return _monitor_map.has(p_id);
+}
+
+Variant Performance::get_custom_monitor(const StringName &p_id) {
+ ERR_FAIL_COND_V_MSG(!has_custom_monitor(p_id), Variant(), "Custom monitor with id '" + String(p_id) + "' doesn't exists.");
+ bool error;
+ String error_message;
+ Variant return_value = _monitor_map[p_id].call(error, error_message);
+ ERR_FAIL_COND_V_MSG(error, return_value, "Error calling from custom monitor '" + String(p_id) + "' to callable: " + error_message);
+ return return_value;
+}
+
+Array Performance::get_custom_monitor_names() {
+ if (!_monitor_map.size()) {
+ return Array();
+ }
+ Array return_array;
+ return_array.resize(_monitor_map.size());
+ int index = 0;
+ for (OrderedHashMap<StringName, MonitorCall>::Element i = _monitor_map.front(); i; i = i.next()) {
+ return_array.set(index, i.key());
+ index++;
+ }
+ return return_array;
+}
+
+uint64_t Performance::get_monitor_modification_time() {
+ return _monitor_modification_time;
+}
+
Performance::Performance() {
_process_time = 0;
_physics_process_time = 0;
+ _monitor_modification_time = 0;
singleton = this;
}
+
+Performance::MonitorCall::MonitorCall(Callable p_callable, Vector<Variant> p_arguments) {
+ _callable = p_callable;
+ _arguments = p_arguments;
+}
+
+Performance::MonitorCall::MonitorCall() {
+}
+
+Variant Performance::MonitorCall::call(bool &r_error, String &r_error_message) {
+ Vector<const Variant *> arguments_mem;
+ arguments_mem.resize(_arguments.size());
+ for (int i = 0; i < _arguments.size(); i++) {
+ arguments_mem.write[i] = &_arguments[i];
+ }
+ const Variant **args = (const Variant **)arguments_mem.ptr();
+ int argc = _arguments.size();
+ Variant return_value;
+ Callable::CallError error;
+ _callable.call(args, argc, return_value, error);
+ r_error = (error.error != Callable::CallError::CALL_OK);
+ if (r_error) {
+ r_error_message = Variant::get_callable_error_text(_callable, args, argc, error);
+ }
+ return return_value;
+}
diff --git a/main/performance.h b/main/performance.h
index ddbe45fa00..5f88a24c0f 100644
--- a/main/performance.h
+++ b/main/performance.h
@@ -32,6 +32,7 @@
#define PERFORMANCE_H
#include "core/object.h"
+#include "core/ordered_hash_map.h"
#define PERF_WARN_OFFLINE_FUNCTION
#define PERF_WARN_PROCESS_SYNC
@@ -47,6 +48,19 @@ class Performance : public Object {
float _process_time;
float _physics_process_time;
+ class MonitorCall {
+ Callable _callable;
+ Vector<Variant> _arguments;
+
+ public:
+ MonitorCall(Callable p_callable, Vector<Variant> p_arguments);
+ MonitorCall();
+ Variant call(bool &r_error, String &r_error_message);
+ };
+
+ OrderedHashMap<StringName, MonitorCall> _monitor_map;
+ uint64_t _monitor_modification_time;
+
public:
enum Monitor {
@@ -95,6 +109,14 @@ public:
void set_process_time(float p_pt);
void set_physics_process_time(float p_pt);
+ void add_custom_monitor(const StringName &p_id, const Callable &p_callable, const Vector<Variant> &p_args);
+ void remove_custom_monitor(const StringName &p_id);
+ bool has_custom_monitor(const StringName &p_id);
+ Variant get_custom_monitor(const StringName &p_id);
+ Array get_custom_monitor_names();
+
+ uint64_t get_monitor_modification_time();
+
static Performance *get_singleton() { return singleton; }
Performance();
diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp
index d0c9bf5d38..6c0a3a4ca3 100644
--- a/modules/csg/csg.cpp
+++ b/modules/csg/csg.cpp
@@ -523,7 +523,7 @@ void CSGBrushOperation::MeshMerge::_add_distance(List<real_t> &r_intersectionsA,
// Check if distance exists.
for (const List<real_t>::Element *E = intersections.front(); E; E = E->next()) {
- if (Math::abs(**E - p_distance) < vertex_snap) {
+ if (Math::is_equal_approx(**E, p_distance)) {
return;
}
}
@@ -1068,15 +1068,6 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s
break;
}
- // Don't create degenerate triangles.
- Vector2 split_edge1[2] = { vertices[new_vertex_idx].point, edge_points[0] };
- Vector2 split_edge2[2] = { vertices[new_vertex_idx].point, edge_points[1] };
- Vector2 new_edge[2] = { vertices[new_vertex_idx].point, vertices[opposite_vertex_idx].point };
- if (are_segements_parallel(split_edge1, new_edge, vertex_snap2) &&
- are_segements_parallel(split_edge2, new_edge, vertex_snap2)) {
- break;
- }
-
// If opposite point is on the segemnt, add its index to segment indices too.
Vector2 closest_point = Geometry2D::get_closest_point_to_segment(vertices[opposite_vertex_idx].point, p_segment_points);
if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2) {
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 06b9534fce..94aa2125c2 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -1853,7 +1853,7 @@ void NativeReloadNode::_notification(int p_what) {
#ifdef TOOLS_ENABLED
switch (p_what) {
- case NOTIFICATION_WM_FOCUS_OUT: {
+ case NOTIFICATION_APPLICATION_FOCUS_OUT: {
if (unloaded) {
break;
}
@@ -1887,7 +1887,7 @@ void NativeReloadNode::_notification(int p_what) {
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
+ case NOTIFICATION_APPLICATION_FOCUS_IN: {
if (!unloaded) {
break;
}
diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp
index ce889a4928..1475d24792 100644
--- a/modules/tga/image_loader_tga.cpp
+++ b/modules/tga/image_loader_tga.cpp
@@ -30,6 +30,8 @@
#include "image_loader_tga.h"
+#include "core/error_macros.h"
+#include "core/io/file_access_memory.h"
#include "core/os/os.h"
#include "core/print_string.h"
@@ -311,5 +313,17 @@ void ImageLoaderTGA::get_recognized_extensions(List<String> *p_extensions) const
p_extensions->push_back("tga");
}
+static Ref<Image> _tga_mem_loader_func(const uint8_t *p_png, int p_size) {
+ FileAccessMemory memfile;
+ Error open_memfile_error = memfile.open_custom(p_png, p_size);
+ ERR_FAIL_COND_V_MSG(open_memfile_error, Ref<Image>(), "Could not create memfile for TGA image buffer.");
+ Ref<Image> img;
+ img.instance();
+ Error load_error = ImageLoaderTGA().load_image(img, &memfile, false, 1.0f);
+ ERR_FAIL_COND_V_MSG(load_error, Ref<Image>(), "Failed to load TGA image.");
+ return img;
+}
+
ImageLoaderTGA::ImageLoaderTGA() {
+ Image::_tga_mem_loader_func = _tga_mem_loader_func;
}
diff --git a/platform/android/java_godot_lib_jni.cpp b/platform/android/java_godot_lib_jni.cpp
index a032ae8d2c..4610b94363 100644
--- a/platform/android/java_godot_lib_jni.cpp
+++ b/platform/android/java_godot_lib_jni.cpp
@@ -457,7 +457,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererResumed(JNI
return;
if (os_android->get_main_loop()) {
- os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_RESUMED);
+ os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_RESUMED);
}
}
@@ -466,7 +466,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_onRendererPaused(JNIE
return;
if (os_android->get_main_loop()) {
- os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APP_PAUSED);
+ os_android->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_PAUSED);
}
}
}
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm
index 920fd24c4a..93f6e3540a 100644
--- a/platform/osx/display_server_osx.mm
+++ b/platform/osx/display_server_osx.mm
@@ -197,6 +197,18 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) {
}
}
+- (void)applicationDidResignActive:(NSNotification *)notification {
+ if (OS_OSX::get_singleton()->get_main_loop()) {
+ OS_OSX::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT);
+ }
+}
+
+- (void)applicationDidBecomeActive:(NSNotification *)notification {
+ if (OS_OSX::get_singleton()->get_main_loop()) {
+ OS_OSX::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_IN);
+ }
+}
+
- (void)globalMenuCallback:(id)sender {
if (![sender representedObject])
return;
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 9af7c02351..916816325d 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -825,14 +825,15 @@ void EditorExportPlatformOSX::_zip_folder_recursive(zipFile &p_zip, const String
zipfi.tmz_date.tm_hour = time.hour;
zipfi.tmz_date.tm_mday = date.day;
zipfi.tmz_date.tm_min = time.min;
- zipfi.tmz_date.tm_mon = date.month;
+ zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, http://www.cplusplus.com/reference/ctime/tm/
zipfi.tmz_date.tm_sec = time.sec;
zipfi.tmz_date.tm_year = date.year;
zipfi.dosDate = 0;
// 0100000: regular file type
// 0000755: permissions rwxr-xr-x
// 0000644: permissions rw-r--r--
- zipfi.external_fa = (is_executable ? 0100755 : 0100644) << 16L;
+ uint32_t _mode = (is_executable ? 0100755 : 0100644);
+ zipfi.external_fa = (_mode << 16L) | !(_mode & 0200);
zipfi.internal_fa = 0;
zipOpenNewFileInZip4(p_zip,
diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp
index f47afcc4e5..61dc156fbc 100644
--- a/platform/windows/display_server_windows.cpp
+++ b/platform/windows/display_server_windows.cpp
@@ -1790,6 +1790,12 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
// Restore mouse mode
_set_mouse_mode_impl(mouse_mode);
+ if (!app_focused) {
+ if (OS::get_singleton()->get_main_loop()) {
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_IN);
+ }
+ app_focused = true;
+ }
break;
}
case WM_KILLFOCUS: {
@@ -1805,6 +1811,19 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
}
touch_state.clear();
+ bool self_steal = false;
+ HWND new_hwnd = (HWND)wParam;
+ if (IsWindow(new_hwnd)) {
+ self_steal = true;
+ }
+
+ if (!self_steal) {
+ if (OS::get_singleton()->get_main_loop()) {
+ OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT);
+ }
+ app_focused = false;
+ }
+
break;
}
case WM_ACTIVATE: // Watch For Window Activate Message
diff --git a/platform/windows/display_server_windows.h b/platform/windows/display_server_windows.h
index 995ced0809..8433bb449b 100644
--- a/platform/windows/display_server_windows.h
+++ b/platform/windows/display_server_windows.h
@@ -317,6 +317,7 @@ private:
int pressrc;
HINSTANCE hInstance; // Holds The Instance Of The Application
String rendering_driver;
+ bool app_focused = false;
struct WindowData {
HWND hWnd;
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index c6897fc684..bacc65c7bf 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -51,7 +51,9 @@ void AcceptDialog::_input_from_window(const Ref<InputEvent> &p_event) {
}
void AcceptDialog::_parent_focused() {
- _cancel_pressed();
+ if (!is_exclusive()) {
+ _cancel_pressed();
+ }
}
void AcceptDialog::_notification(int p_what) {
@@ -295,6 +297,7 @@ AcceptDialog::AcceptDialog() {
set_wrap_controls(true);
set_visible(false);
set_transient(true);
+ set_exclusive(true);
bg = memnew(Panel);
add_child(bg);
diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h
index 5d7b6272bf..81664733a3 100644
--- a/scene/gui/dialogs.h
+++ b/scene/gui/dialogs.h
@@ -44,6 +44,7 @@ class LineEdit;
class AcceptDialog : public Window {
GDCLASS(AcceptDialog, Window);
+public:
Window *parent_visible;
Panel *bg;
HBoxContainer *hbc;
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index ba55927980..251f31ce4e 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -688,12 +688,12 @@ void LineEdit::_notification(int p_what) {
update_placeholder_width();
update();
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
window_has_focus = true;
draw_caret = true;
update();
} break;
- case NOTIFICATION_WM_FOCUS_OUT: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
window_has_focus = false;
draw_caret = false;
update();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index c7fc8dbe43..3860ce61e9 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -603,12 +603,12 @@ void TextEdit::_notification(int p_what) {
_update_wrap_at();
syntax_highlighting_cache.clear();
} break;
- case NOTIFICATION_WM_FOCUS_IN: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
window_has_focus = true;
draw_caret = true;
update();
} break;
- case NOTIFICATION_WM_FOCUS_OUT: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
window_has_focus = false;
draw_caret = false;
update();
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 7b9db7c081..34161a9e80 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -3410,7 +3410,7 @@ void Tree::scroll_to_item(TreeItem *p_item) {
const Rect2 r = get_item_rect(p_item);
- if (r.position.y < v_scroll->get_value()) {
+ if (r.position.y <= v_scroll->get_value()) {
v_scroll->set_value(r.position.y);
} else if (r.position.y + r.size.y + 2 * cache.vseparation > v_scroll->get_value() + get_size().y) {
v_scroll->set_value(r.position.y + r.size.y + 2 * cache.vseparation - get_size().y);
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 1bf828a03b..88f9730f78 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2857,8 +2857,8 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_MOUSE_ENTER);
BIND_CONSTANT(NOTIFICATION_WM_MOUSE_EXIT);
- BIND_CONSTANT(NOTIFICATION_WM_FOCUS_IN);
- BIND_CONSTANT(NOTIFICATION_WM_FOCUS_OUT);
+ BIND_CONSTANT(NOTIFICATION_WM_WINDOW_FOCUS_IN);
+ BIND_CONSTANT(NOTIFICATION_WM_WINDOW_FOCUS_OUT);
BIND_CONSTANT(NOTIFICATION_WM_CLOSE_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_GO_BACK_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_SIZE_CHANGED);
@@ -2867,8 +2867,10 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_ABOUT);
BIND_CONSTANT(NOTIFICATION_CRASH);
BIND_CONSTANT(NOTIFICATION_OS_IME_UPDATE);
- BIND_CONSTANT(NOTIFICATION_APP_RESUMED);
- BIND_CONSTANT(NOTIFICATION_APP_PAUSED);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_RESUMED);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_PAUSED);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_IN);
+ BIND_CONSTANT(NOTIFICATION_APPLICATION_FOCUS_OUT);
BIND_ENUM_CONSTANT(PAUSE_MODE_INHERIT);
BIND_ENUM_CONSTANT(PAUSE_MODE_STOP);
diff --git a/scene/main/node.h b/scene/main/node.h
index 7595aabd9a..c3972e2d8e 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -243,8 +243,8 @@ public:
NOTIFICATION_WM_MOUSE_ENTER = 1002,
NOTIFICATION_WM_MOUSE_EXIT = 1003,
- NOTIFICATION_WM_FOCUS_IN = 1004,
- NOTIFICATION_WM_FOCUS_OUT = 1005,
+ NOTIFICATION_WM_WINDOW_FOCUS_IN = 1004,
+ NOTIFICATION_WM_WINDOW_FOCUS_OUT = 1005,
NOTIFICATION_WM_CLOSE_REQUEST = 1006,
NOTIFICATION_WM_GO_BACK_REQUEST = 1007,
NOTIFICATION_WM_SIZE_CHANGED = 1008,
@@ -255,8 +255,10 @@ public:
NOTIFICATION_WM_ABOUT = MainLoop::NOTIFICATION_WM_ABOUT,
NOTIFICATION_CRASH = MainLoop::NOTIFICATION_CRASH,
NOTIFICATION_OS_IME_UPDATE = MainLoop::NOTIFICATION_OS_IME_UPDATE,
- NOTIFICATION_APP_RESUMED = MainLoop::NOTIFICATION_APP_RESUMED,
- NOTIFICATION_APP_PAUSED = MainLoop::NOTIFICATION_APP_PAUSED
+ NOTIFICATION_APPLICATION_RESUMED = MainLoop::NOTIFICATION_APPLICATION_RESUMED,
+ NOTIFICATION_APPLICATION_PAUSED = MainLoop::NOTIFICATION_APPLICATION_PAUSED,
+ NOTIFICATION_APPLICATION_FOCUS_IN = MainLoop::NOTIFICATION_APPLICATION_FOCUS_IN,
+ NOTIFICATION_APPLICATION_FOCUS_OUT = MainLoop::NOTIFICATION_APPLICATION_FOCUS_OUT
};
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 3c3c7533a3..a418883506 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -587,9 +587,11 @@ void SceneTree::_notification(int p_notification) {
case NOTIFICATION_OS_IME_UPDATE:
case NOTIFICATION_WM_ABOUT:
case NOTIFICATION_CRASH:
- case NOTIFICATION_APP_RESUMED:
- case NOTIFICATION_APP_PAUSED: {
- get_root()->propagate_notification(p_notification);
+ case NOTIFICATION_APPLICATION_RESUMED:
+ case NOTIFICATION_APPLICATION_PAUSED:
+ case NOTIFICATION_APPLICATION_FOCUS_IN:
+ case NOTIFICATION_APPLICATION_FOCUS_OUT: {
+ get_root()->propagate_notification(p_notification); //pass these to nodes, since they are mirrored
} break;
default:
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 606f39370b..8042f02fa6 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -815,7 +815,7 @@ void Viewport::_notification(int p_what) {
} break;
case NOTIFICATION_WM_MOUSE_EXIT:
- case NOTIFICATION_WM_FOCUS_OUT: {
+ case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
_drop_physics_mouseover();
if (gui.mouse_focus && !gui.forced_mouse_focus) {
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index a9be8a1eff..7f2160c6a5 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -316,13 +316,13 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_IN: {
focused = true;
- _propagate_window_notification(this, NOTIFICATION_WM_FOCUS_IN);
+ _propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_IN);
emit_signal("focus_entered");
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_OUT: {
focused = false;
- _propagate_window_notification(this, NOTIFICATION_WM_FOCUS_OUT);
+ _propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_OUT);
emit_signal("focus_exited");
} break;
case DisplayServer::WINDOW_EVENT_CLOSE_REQUEST: {
@@ -398,6 +398,18 @@ void Window::set_visible(bool p_visible) {
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
RS::get_singleton()->viewport_set_active(get_viewport_rid(), visible);
+
+ //update transient exclusive
+ if (transient_parent) {
+ if (exclusive && visible) {
+ ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
+ transient_parent->exclusive_child = this;
+ } else {
+ if (transient_parent->exclusive_child == this) {
+ transient_parent->exclusive_child = nullptr;
+ }
+ }
+ }
}
void Window::_clear_transient() {
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 854a9ee9da..c003a99a2b 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -1007,7 +1007,7 @@ void Environment::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_grey"), &Environment::get_tonemap_auto_exposure_grey);
ADD_GROUP("Tonemap", "tonemap_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reinhard,Filmic,Aces"), "set_tonemapper", "get_tonemapper");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reinhard,Filmic,ACES"), "set_tonemapper", "get_tonemapper");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_exposure", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_exposure", "get_tonemap_exposure");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "tonemap_white", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_white", "get_tonemap_white");
ADD_GROUP("Auto Exposure", "auto_exposure_");
diff --git a/servers/physics_2d/broad_phase_2d_hash_grid.cpp b/servers/physics_2d/broad_phase_2d_hash_grid.cpp
index ae549ed2e4..ec74507e03 100644
--- a/servers/physics_2d/broad_phase_2d_hash_grid.cpp
+++ b/servers/physics_2d/broad_phase_2d_hash_grid.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "broad_phase_2d_hash_grid.h"
+#include "collision_object_2d_sw.h"
#include "core/project_settings.h"
#define LARGE_ELEMENT_FI 1.01239812
@@ -70,20 +71,22 @@ void BroadPhase2DHashGrid::_unpair_attempt(Element *p_elem, Element *p_with) {
void BroadPhase2DHashGrid::_check_motion(Element *p_elem) {
for (Map<Element *, PairData *>::Element *E = p_elem->paired.front(); E; E = E->next()) {
- bool pairing = p_elem->aabb.intersects(E->key()->aabb);
-
- if (pairing != E->get()->colliding) {
- if (pairing) {
- if (pair_callback) {
- E->get()->ud = pair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, pair_userdata);
- }
- } else {
- if (unpair_callback) {
- unpair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, E->get()->ud, unpair_userdata);
- }
+ bool physical_collision = p_elem->aabb.intersects(E->key()->aabb);
+ bool logical_collision = p_elem->owner->test_collision_mask(E->key()->owner);
+
+ if (physical_collision) {
+ if (!E->get()->colliding || (logical_collision && !E->get()->ud && pair_callback)) {
+ E->get()->ud = pair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, pair_userdata);
+ } else if (E->get()->colliding && !logical_collision && E->get()->ud && unpair_callback) {
+ unpair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, E->get()->ud, unpair_userdata);
+ E->get()->ud = nullptr;
}
-
- E->get()->colliding = pairing;
+ E->get()->colliding = true;
+ } else { // No physcial_collision
+ if (E->get()->colliding && unpair_callback) {
+ unpair_callback(p_elem->owner, p_elem->subindex, E->key()->owner, E->key()->subindex, E->get()->ud, unpair_userdata);
+ }
+ E->get()->colliding = false;
}
}
}
@@ -317,23 +320,17 @@ void BroadPhase2DHashGrid::move(ID p_id, const Rect2 &p_aabb) {
Element &e = E->get();
- if (p_aabb == e.aabb) {
- return;
- }
-
- if (p_aabb != Rect2()) {
- _enter_grid(&e, p_aabb, e._static);
- }
-
- if (e.aabb != Rect2()) {
- _exit_grid(&e, e.aabb, e._static);
+ if (p_aabb != e.aabb) {
+ if (p_aabb != Rect2()) {
+ _enter_grid(&e, p_aabb, e._static);
+ }
+ if (e.aabb != Rect2()) {
+ _exit_grid(&e, e.aabb, e._static);
+ }
+ e.aabb = p_aabb;
}
- e.aabb = p_aabb;
-
_check_motion(&e);
-
- e.aabb = p_aabb;
}
void BroadPhase2DHashGrid::set_static(ID p_id, bool p_static) {
diff --git a/servers/physics_2d/collision_object_2d_sw.h b/servers/physics_2d/collision_object_2d_sw.h
index 84a2baaa74..8caa53680d 100644
--- a/servers/physics_2d/collision_object_2d_sw.h
+++ b/servers/physics_2d/collision_object_2d_sw.h
@@ -168,10 +168,16 @@ public:
return shapes[p_idx].one_way_collision_margin;
}
- void set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; }
+ void set_collision_mask(uint32_t p_mask) {
+ collision_mask = p_mask;
+ _shape_changed();
+ }
_FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; }
- void set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; }
+ void set_collision_layer(uint32_t p_layer) {
+ collision_layer = p_layer;
+ _shape_changed();
+ }
_FORCE_INLINE_ uint32_t get_collision_layer() const { return collision_layer; }
void remove_shape(Shape2DSW *p_shape);
diff --git a/servers/physics_3d/collision_object_3d_sw.h b/servers/physics_3d/collision_object_3d_sw.h
index 9506f14402..a3a5787ced 100644
--- a/servers/physics_3d/collision_object_3d_sw.h
+++ b/servers/physics_3d/collision_object_3d_sw.h
@@ -142,10 +142,16 @@ public:
return shapes[p_idx].disabled;
}
- _FORCE_INLINE_ void set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; }
+ _FORCE_INLINE_ void set_collision_layer(uint32_t p_layer) {
+ collision_layer = p_layer;
+ _shape_changed();
+ }
_FORCE_INLINE_ uint32_t get_collision_layer() const { return collision_layer; }
- _FORCE_INLINE_ void set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; }
+ _FORCE_INLINE_ void set_collision_mask(uint32_t p_mask) {
+ collision_mask = p_mask;
+ _shape_changed();
+ }
_FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; }
_FORCE_INLINE_ bool test_collision_mask(CollisionObject3DSW *p_other) const {
diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp
index 080b8c61ad..19b575a259 100644
--- a/servers/physics_server_2d.cpp
+++ b/servers/physics_server_2d.cpp
@@ -132,13 +132,21 @@ PhysicsDirectBodyState2D::PhysicsDirectBodyState2D() {}
///////////////////////////////////////////////////////
-void PhysicsShapeQueryParameters2D::set_shape(const RES &p_shape) {
- ERR_FAIL_COND(p_shape.is_null());
- shape = p_shape->get_rid();
+void PhysicsShapeQueryParameters2D::set_shape(const RES &p_shape_ref) {
+ ERR_FAIL_COND(p_shape_ref.is_null());
+ shape_ref = p_shape_ref;
+ shape = p_shape_ref->get_rid();
+}
+
+RES PhysicsShapeQueryParameters2D::get_shape() const {
+ return shape_ref;
}
void PhysicsShapeQueryParameters2D::set_shape_rid(const RID &p_shape) {
- shape = p_shape;
+ if (shape != p_shape) {
+ shape_ref = RES();
+ shape = p_shape;
+ }
}
RID PhysicsShapeQueryParameters2D::get_shape_rid() const {
@@ -212,6 +220,7 @@ bool PhysicsShapeQueryParameters2D::is_collide_with_areas_enabled() const {
void PhysicsShapeQueryParameters2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters2D::set_shape);
+ ClassDB::bind_method(D_METHOD("get_shape"), &PhysicsShapeQueryParameters2D::get_shape);
ClassDB::bind_method(D_METHOD("set_shape_rid", "shape"), &PhysicsShapeQueryParameters2D::set_shape_rid);
ClassDB::bind_method(D_METHOD("get_shape_rid"), &PhysicsShapeQueryParameters2D::get_shape_rid);
@@ -240,7 +249,7 @@ void PhysicsShapeQueryParameters2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_NONE, itos(Variant::_RID) + ":"), "set_exclude", "get_exclude");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion"), "set_motion", "get_motion");
- //ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", ""); // FIXME: Lacks a getter
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "shape_rid"), "set_shape_rid", "get_shape_rid");
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform"), "set_transform", "get_transform");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h
index 549a78aa1f..b2f2e786ee 100644
--- a/servers/physics_server_2d.h
+++ b/servers/physics_server_2d.h
@@ -98,6 +98,8 @@ class PhysicsShapeQueryResult2D;
class PhysicsShapeQueryParameters2D : public Reference {
GDCLASS(PhysicsShapeQueryParameters2D, Reference);
friend class PhysicsDirectSpaceState2D;
+
+ RES shape_ref;
RID shape;
Transform2D transform;
Vector2 motion;
@@ -112,7 +114,8 @@ protected:
static void _bind_methods();
public:
- void set_shape(const RES &p_shape);
+ void set_shape(const RES &p_shape_ref);
+ RES get_shape() const;
void set_shape_rid(const RID &p_shape);
RID get_shape_rid() const;
diff --git a/servers/physics_server_3d.cpp b/servers/physics_server_3d.cpp
index 9668358710..3b361fee55 100644
--- a/servers/physics_server_3d.cpp
+++ b/servers/physics_server_3d.cpp
@@ -136,13 +136,21 @@ PhysicsDirectBodyState3D::PhysicsDirectBodyState3D() {}
///////////////////////////////////////////////////////
-void PhysicsShapeQueryParameters3D::set_shape(const RES &p_shape) {
- ERR_FAIL_COND(p_shape.is_null());
- shape = p_shape->get_rid();
+void PhysicsShapeQueryParameters3D::set_shape(const RES &p_shape_ref) {
+ ERR_FAIL_COND(p_shape_ref.is_null());
+ shape_ref = p_shape_ref;
+ shape = p_shape_ref->get_rid();
+}
+
+RES PhysicsShapeQueryParameters3D::get_shape() const {
+ return shape_ref;
}
void PhysicsShapeQueryParameters3D::set_shape_rid(const RID &p_shape) {
- shape = p_shape;
+ if (shape != p_shape) {
+ shape_ref = RES();
+ shape = p_shape;
+ }
}
RID PhysicsShapeQueryParameters3D::get_shape_rid() const {
@@ -208,6 +216,7 @@ bool PhysicsShapeQueryParameters3D::is_collide_with_areas_enabled() const {
void PhysicsShapeQueryParameters3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shape", "shape"), &PhysicsShapeQueryParameters3D::set_shape);
+ ClassDB::bind_method(D_METHOD("get_shape"), &PhysicsShapeQueryParameters3D::get_shape);
ClassDB::bind_method(D_METHOD("set_shape_rid", "shape"), &PhysicsShapeQueryParameters3D::set_shape_rid);
ClassDB::bind_method(D_METHOD("get_shape_rid"), &PhysicsShapeQueryParameters3D::get_shape_rid);
@@ -232,7 +241,7 @@ void PhysicsShapeQueryParameters3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "exclude", PROPERTY_HINT_NONE, itos(Variant::_RID) + ":"), "set_exclude", "get_exclude");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_margin", "get_margin");
- //ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", ""); // FIXME: Lacks a getter
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape");
ADD_PROPERTY(PropertyInfo(Variant::_RID, "shape_rid"), "set_shape_rid", "get_shape_rid");
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform"), "set_transform", "get_transform");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies"), "set_collide_with_bodies", "is_collide_with_bodies_enabled");
diff --git a/servers/physics_server_3d.h b/servers/physics_server_3d.h
index 2465b40d3e..1cfa4d8565 100644
--- a/servers/physics_server_3d.h
+++ b/servers/physics_server_3d.h
@@ -100,6 +100,7 @@ class PhysicsShapeQueryParameters3D : public Reference {
GDCLASS(PhysicsShapeQueryParameters3D, Reference);
friend class PhysicsDirectSpaceState3D;
+ RES shape_ref;
RID shape;
Transform transform;
float margin;
@@ -113,7 +114,8 @@ protected:
static void _bind_methods();
public:
- void set_shape(const RES &p_shape);
+ void set_shape(const RES &p_shape_ref);
+ RES get_shape() const;
void set_shape_rid(const RID &p_shape);
RID get_shape_rid() const;
diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp
index 7c70148180..3a580f0cd9 100644
--- a/servers/rendering/rendering_device.cpp
+++ b/servers/rendering/rendering_device.cpp
@@ -281,7 +281,7 @@ void RenderingDevice::_bind_methods() {
ClassDB::bind_method(D_METHOD("shader_get_vertex_input_attribute_mask", "shader"), &RenderingDevice::shader_get_vertex_input_attribute_mask);
ClassDB::bind_method(D_METHOD("uniform_buffer_create", "size_bytes", "data"), &RenderingDevice::uniform_buffer_create, DEFVAL(Vector<uint8_t>()));
- ClassDB::bind_method(D_METHOD("storage_buffer_create", "size_bytes", "data"), &RenderingDevice::storage_buffer_create, DEFVAL(Vector<uint8_t>()));
+ ClassDB::bind_method(D_METHOD("storage_buffer_create", "size_bytes", "data"), &RenderingDevice::storage_buffer_create, DEFVAL(Vector<uint8_t>()), DEFVAL(0));
ClassDB::bind_method(D_METHOD("texture_buffer_create", "size_bytes", "format", "data"), &RenderingDevice::texture_buffer_create, DEFVAL(Vector<uint8_t>()));
ClassDB::bind_method(D_METHOD("uniform_set_create", "uniforms", "shader", "shader_set"), &RenderingDevice::_uniform_set_create);