Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add editor vital redraws only option #53463

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/os/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ bool OS::is_in_low_processor_usage_mode() const {
return low_processor_usage_mode;
}

void OS::set_update_vital_only(bool p_enabled) {
_update_vital_only = p_enabled;
}

void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
low_processor_usage_mode_sleep_usec = p_usec;
}
Expand Down Expand Up @@ -834,6 +838,8 @@ OS::OS() {
_keep_screen_on = true; // set default value to true, because this had been true before godot 2.0.
low_processor_usage_mode = false;
low_processor_usage_mode_sleep_usec = 10000;
_update_vital_only = false;
_update_pending = false;
_verbose_stdout = false;
_debug_stdout = false;
_no_window = false;
Expand Down
23 changes: 23 additions & 0 deletions core/os/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class OS {
bool _keep_screen_on;
bool low_processor_usage_mode;
int low_processor_usage_mode_sleep_usec;
bool _update_vital_only;
bool _update_pending;
bool _verbose_stdout;
bool _debug_stdout;
String _local_clipboard;
Expand Down Expand Up @@ -287,6 +289,27 @@ class OS {
virtual bool is_in_low_processor_usage_mode() const;
virtual void set_low_processor_usage_mode_sleep_usec(int p_usec);
virtual int get_low_processor_usage_mode_sleep_usec() const;
virtual void set_update_vital_only(bool p_enabled);
virtual void set_update_pending(bool p_pending) { _update_pending = p_pending; }

// Convenience easy switch for turning this off outside tools builds, without littering calling code
// with #ifdefs. It will also hopefully be compiled out in release.
#ifdef TOOLS_ENABLED
// This function is used to throttle back updates of animations and particle systems when using UPDATE_VITAL_ONLY mode.

// CASE 1) We are not in UPDATE_VITAL_ONLY mode - always return true and update.
// CASE 2) We are in UPDATE_VITAL_ONLY mode -

// In most cases this will return false and prevent animations etc updating.
// The exception is that we can also choose to receive a true
// each time a frame is redrawn as a result of moving the mouse, clicking etc.
// This enables us to keep e.g. particle systems processing, but ONLY when other
// events have caused a redraw.
virtual bool is_update_pending(bool p_include_redraws = false) const { return !_update_vital_only || (_update_pending && p_include_redraws); }
#else
// Always update when outside the editor, UPDATE_VITAL_ONLY has no effect outside the editor.
virtual bool is_update_pending(bool p_include_redraws = false) const { return true; }
#endif

virtual String get_executable_path() const;
virtual Error execute(const String &p_path, const List<String> &p_arguments, bool p_blocking = true, ProcessID *r_child_id = nullptr, String *r_pipe = nullptr, int *r_exitcode = nullptr, bool read_stderr = false, Mutex *p_pipe_mutex = nullptr, bool p_open_console = false) = 0;
Expand Down
11 changes: 11 additions & 0 deletions doc/classes/VisualServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,10 @@
</method>
<method name="has_changed" qualifiers="const">
<return type="bool" />
<argument index="0" name="queried_priority" type="int" enum="VisualServer.ChangedPriority" default="0" />
<description>
Returns [code]true[/code] if changes have been made to the VisualServer's data. [method draw] is usually called if this happens.
As changes are registered as either high or low priority (e.g. dynamic shaders), this function takes an optional argument to query either low or high priority changes, or any changes.
</description>
</method>
<method name="has_feature" qualifiers="const">
Expand Down Expand Up @@ -3841,5 +3843,14 @@
<constant name="ENV_SSAO_BLUR_3x3" value="3" enum="EnvironmentSSAOBlur">
Performs a 3x3 blur on the SSAO output. Use this for smoothest SSAO.
</constant>
<constant name="CHANGED_PRIORITY_ANY" value="0" enum="ChangedPriority">
Used to query for any changes that request a redraw, whatever the priority.
</constant>
<constant name="CHANGED_PRIORITY_LOW" value="1" enum="ChangedPriority">
Registered changes which have low priority can be optionally prevented from causing editor redraws. Examples might include dynamic shaders (typically using the [code]TIME[/code] built-in).
</constant>
<constant name="CHANGED_PRIORITY_HIGH" value="2" enum="ChangedPriority">
Registered changes which can cause a redraw default to high priority.
</constant>
</constants>
</class>
4 changes: 2 additions & 2 deletions drivers/gles2/rasterizer_canvas_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ void RasterizerCanvasGLES2::_legacy_canvas_render_item(Item *p_ci, RenderItemSta

if (shader_ptr != r_ris.shader_cache) {
if (shader_ptr->canvas_item.uses_time) {
VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);
}

state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
Expand Down Expand Up @@ -2021,7 +2021,7 @@ void RasterizerCanvasGLES2::render_joined_item(const BItemJoined &p_bij, RenderI

if (shader_ptr != r_ris.shader_cache) {
if (shader_ptr->canvas_item.uses_time) {
VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);
lawnjelly marked this conversation as resolved.
Show resolved Hide resolved
}

state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles2/rasterizer_scene_gles2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ void RasterizerSceneGLES2::_add_geometry_with_material(RasterizerStorageGLES2::G
// do not add anything here, as lights are duplicated elements..

if (p_material->shader->spatial.uses_time) {
VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);
}
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/gles3/rasterizer_canvas_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void RasterizerCanvasGLES3::_legacy_canvas_render_item(Item *p_ci, RenderItemSta

if (shader_ptr != r_ris.shader_cache || r_ris.rebind_shader) {
if (shader_ptr->canvas_item.uses_time) {
VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);
}

state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
Expand Down Expand Up @@ -968,7 +968,7 @@ void RasterizerCanvasGLES3::render_batches(Item *p_current_clip, bool &r_reclip,

glVertexAttrib4f(VS::ARRAY_COLOR, 1, 1, 1, 1); //not used, so keep white

VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);

storage->particles_request_process(particles_cmd->particles);
//enable instancing
Expand Down Expand Up @@ -1250,7 +1250,7 @@ void RasterizerCanvasGLES3::render_joined_item(const BItemJoined &p_bij, RenderI

if (shader_ptr != r_ris.shader_cache || r_ris.rebind_shader) {
if (shader_ptr->canvas_item.uses_time) {
VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);
}

state.canvas_shader.set_custom_shader(shader_ptr->custom_code_id);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/rasterizer_scene_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,7 @@ void RasterizerSceneGLES3::_add_geometry_with_material(RasterizerStorageGLES3::G
}

if (p_material->shader->spatial.uses_time) {
VisualServerRaster::redraw_request();
VisualServerRaster::redraw_request(false);
}
}

Expand Down
2 changes: 1 addition & 1 deletion editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ void CodeTextEditor::update_editor_settings() {
text_editor->set_line_length_guideline_hard_column(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column"));
text_editor->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file"));
text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->is_caret_blink_active());
text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
text_editor->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete"));
}
Expand Down
25 changes: 23 additions & 2 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,17 @@ void EditorNode::_update_update_spinner() {
update_spinner->set_visible(EditorSettings::get_singleton()->get("interface/editor/show_update_spinner"));

const bool update_continuously = EditorSettings::get_singleton()->get("interface/editor/update_continuously");
const bool vital_only = EditorSettings::get_singleton()->get("interface/editor/update_vital_only");
PopupMenu *update_popup = update_spinner->get_popup();
update_popup->set_item_checked(update_popup->get_item_index(SETTINGS_UPDATE_CONTINUOUSLY), update_continuously);
update_popup->set_item_checked(update_popup->get_item_index(SETTINGS_UPDATE_WHEN_CHANGED), !update_continuously);

if (update_continuously) {
update_popup->set_item_checked(update_popup->get_item_index(SETTINGS_UPDATE_WHEN_CHANGED), false);
update_popup->set_item_checked(update_popup->get_item_index(SETTINGS_UPDATE_VITAL_ONLY), false);
} else {
update_popup->set_item_checked(update_popup->get_item_index(SETTINGS_UPDATE_WHEN_CHANGED), !vital_only);
update_popup->set_item_checked(update_popup->get_item_index(SETTINGS_UPDATE_VITAL_ONLY), vital_only);
}

if (update_continuously) {
update_spinner->set_tooltip(TTR("Spins when the editor window redraws.\nUpdate Continuously is enabled, which can increase power usage. Click to disable it."));
Expand All @@ -656,6 +664,11 @@ void EditorNode::_update_update_spinner() {
}

OS::get_singleton()->set_low_processor_usage_mode(!update_continuously);

// Only set low priority redraws to false in the editor.
// When we run the project in the editor, we don't want it to prevent
// rendering any frames.
OS::get_singleton()->set_update_vital_only(vital_only && !update_continuously);
}

void EditorNode::_on_plugin_ready(Object *p_script, const String &p_activate_name) {
Expand Down Expand Up @@ -2791,6 +2804,12 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
} break;
case SETTINGS_UPDATE_WHEN_CHANGED: {
EditorSettings::get_singleton()->set("interface/editor/update_continuously", false);
EditorSettings::get_singleton()->set("interface/editor/update_vital_only", false);
_update_update_spinner();
} break;
case SETTINGS_UPDATE_VITAL_ONLY: {
EditorSettings::get_singleton()->set("interface/editor/update_continuously", false);
EditorSettings::get_singleton()->set("interface/editor/update_vital_only", true);
_update_update_spinner();
} break;
case SETTINGS_UPDATE_SPINNER_HIDE: {
Expand Down Expand Up @@ -5951,6 +5970,7 @@ EditorNode::EditorNode() {
EDITOR_DEF("interface/editor/quit_confirmation", true);
EDITOR_DEF("interface/editor/show_update_spinner", false);
EDITOR_DEF("interface/editor/update_continuously", false);
EDITOR_DEF("interface/editor/update_vital_only", false);
EDITOR_DEF_RST("interface/scene_tabs/restore_scenes_on_load", false);
EDITOR_DEF_RST("interface/scene_tabs/show_thumbnail_on_hover", true);
EDITOR_DEF_RST("interface/inspector/capitalize_properties", true);
Expand Down Expand Up @@ -6622,7 +6642,8 @@ EditorNode::EditorNode() {
update_spinner->get_popup()->connect("id_pressed", this, "_menu_option");
p = update_spinner->get_popup();
p->add_radio_check_item(TTR("Update Continuously"), SETTINGS_UPDATE_CONTINUOUSLY);
p->add_radio_check_item(TTR("Update When Changed"), SETTINGS_UPDATE_WHEN_CHANGED);
p->add_radio_check_item(TTR("Update All Changes"), SETTINGS_UPDATE_WHEN_CHANGED);
p->add_radio_check_item(TTR("Update Vital Changes"), SETTINGS_UPDATE_VITAL_ONLY);
p->add_separator();
p->add_item(TTR("Hide Update Spinner"), SETTINGS_UPDATE_SPINNER_HIDE);
_update_update_spinner();
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class EditorNode : public Node {
RUN_VCS_SETTINGS,
RUN_VCS_SHUT_DOWN,
SETTINGS_UPDATE_CONTINUOUSLY,
SETTINGS_UPDATE_VITAL_ONLY,
SETTINGS_UPDATE_WHEN_CHANGED,
SETTINGS_UPDATE_ALWAYS,
SETTINGS_UPDATE_CHANGES,
Expand Down
13 changes: 13 additions & 0 deletions editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,19 @@ void EditorSettings::load_favorites() {
}
}

// The logic for this is rather convoluted as it takes into account whether
// vital updates only is selected.
bool EditorSettings::is_caret_blink_active() const {
bool blink = get("text_editor/cursor/caret_blink");
bool vital_only = get("interface/editor/update_vital_only");
bool continuous = get("interface/editor/update_continuously");

if (vital_only && !continuous) {
blink = false;
}
return blink;
}

bool EditorSettings::is_dark_theme() {
int AUTO_COLOR = 0;
int LIGHT_COLOR = 2;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class EditorSettings : public Resource {
void load_favorites();

bool is_dark_theme();
bool is_caret_blink_active() const;

void list_text_editor_themes();
void load_text_editor_theme();
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ void ShaderEditor::_editor_settings_changed() {
shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting"));
shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences"));
shader_editor->get_text_edit()->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line"));
shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink"));
shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->is_caret_blink_active());
shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed"));
shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing"));
shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret"));
Expand Down
11 changes: 10 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2277,7 +2277,16 @@ bool Main::iteration() {

if (OS::get_singleton()->can_draw() && VisualServer::get_singleton()->is_render_loop_enabled()) {
if ((!force_redraw_requested) && OS::get_singleton()->is_in_low_processor_usage_mode()) {
if (VisualServer::get_singleton()->has_changed()) {
// We can choose whether to redraw as a result of any redraw request, or redraw only for vital requests.
VisualServer::ChangedPriority priority = (OS::get_singleton()->is_update_pending() ? VisualServer::CHANGED_PRIORITY_ANY : VisualServer::CHANGED_PRIORITY_HIGH);

// Determine whether the scene has changed, to know whether to draw.
// If it has changed, inform the update pending system so it can keep
// particle systems etc updating when running in vital updates only mode.
bool has_changed = VisualServer::get_singleton()->has_changed(priority);
OS::get_singleton()->set_update_pending(has_changed);

if (has_changed) {
VisualServer::get_singleton()->draw(true, scaled_step); // flush visual commands
Engine::get_singleton()->frames_drawn++;
}
Expand Down
9 changes: 6 additions & 3 deletions scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "cpu_particles_2d.h"
#include "core/core_string_names.h"
#include "core/os/os.h"
#include "scene/2d/canvas_item.h"
#include "scene/2d/particles_2d.h"
#include "scene/resources/particles_material.h"
Expand Down Expand Up @@ -1028,9 +1029,11 @@ void CPUParticles2D::_set_redraw(bool p_redraw) {
}

void CPUParticles2D::_update_render_thread() {
update_mutex.lock();
VS::get_singleton()->multimesh_set_as_bulk_array(multimesh, particle_data);
update_mutex.unlock();
if (OS::get_singleton()->is_update_pending(true)) {
update_mutex.lock();
VS::get_singleton()->multimesh_set_as_bulk_array(multimesh, particle_data);
update_mutex.unlock();
}
}

void CPUParticles2D::_notification(int p_what) {
Expand Down
15 changes: 9 additions & 6 deletions scene/3d/cpu_particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "cpu_particles.h"

#include "core/os/os.h"
#include "scene/3d/camera.h"
#include "scene/3d/particles.h"
#include "scene/resources/particles_material.h"
Expand Down Expand Up @@ -1152,14 +1153,16 @@ void CPUParticles::_set_redraw(bool p_redraw) {
}

void CPUParticles::_update_render_thread() {
update_mutex.lock();
if (OS::get_singleton()->is_update_pending(true)) {
update_mutex.lock();

if (can_update.is_set()) {
VS::get_singleton()->multimesh_set_as_bulk_array(multimesh, particle_data);
can_update.clear(); //wait for next time
}
if (can_update.is_set()) {
VS::get_singleton()->multimesh_set_as_bulk_array(multimesh, particle_data);
can_update.clear(); //wait for next time
}

update_mutex.unlock();
update_mutex.unlock();
}
}

void CPUParticles::_notification(int p_what) {
Expand Down
12 changes: 7 additions & 5 deletions scene/animation/animation_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,12 +1236,14 @@ void AnimationTree::advance(float p_time) {
}

void AnimationTree::_notification(int p_what) {
if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) {
_process_graph(get_physics_process_delta_time());
}
if (active && OS::get_singleton()->is_update_pending()) {
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) {
_process_graph(get_physics_process_delta_time());
}

if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_mode == ANIMATION_PROCESS_IDLE) {
_process_graph(get_process_delta_time());
if (p_what == NOTIFICATION_INTERNAL_PROCESS && process_mode == ANIMATION_PROCESS_IDLE) {
_process_graph(get_process_delta_time());
}
}

if (p_what == NOTIFICATION_EXIT_TREE) {
Expand Down
5 changes: 3 additions & 2 deletions scene/animation/animation_tree_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "animation_tree_player.h"
#include "animation_player.h"

#include "core/os/os.h"
#include "scene/scene_string_names.h"

void AnimationTreePlayer::set_animation_process_mode(AnimationProcessMode p_mode) {
Expand Down Expand Up @@ -433,7 +434,7 @@ void AnimationTreePlayer::_notification(int p_what) {
break;
}

if (processing) {
if (processing && OS::get_singleton()->is_update_pending()) {
_process_animation(get_process_delta_time());
}
} break;
Expand All @@ -442,7 +443,7 @@ void AnimationTreePlayer::_notification(int p_what) {
break;
}

if (processing) {
if (processing && OS::get_singleton()->is_update_pending()) {
_process_animation(get_physics_process_delta_time());
}
} break;
Expand Down
6 changes: 4 additions & 2 deletions scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,8 @@ void LineEdit::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() && !get_tree()->is_node_being_edited(this)) {
cursor_set_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false));
EDITOR_DEF("text_editor/cursor/caret_blink", false);
cursor_set_blink_enabled(EditorSettings::get_singleton()->is_caret_blink_active());
cursor_set_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65));

if (!EditorSettings::get_singleton()->is_connected("settings_changed", this, "_editor_settings_changed")) {
Expand Down Expand Up @@ -1669,7 +1670,8 @@ PopupMenu *LineEdit::get_menu() const {

void LineEdit::_editor_settings_changed() {
#ifdef TOOLS_ENABLED
cursor_set_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false));
EDITOR_DEF("text_editor/cursor/caret_blink", false);
cursor_set_blink_enabled(EditorSettings::get_singleton()->is_caret_blink_active());
cursor_set_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65));
#endif
}
Expand Down
Loading