Merge pull request #99555 from Meorge/mute-game

Add "Mute Game" toggle in Game view
This commit is contained in:
Thaddeus Crews 2025-03-19 17:46:11 -05:00
commit 97241ffea6
No known key found for this signature in database
GPG Key ID: 62181B86FE9E5D84
12 changed files with 108 additions and 0 deletions

View File

@ -871,6 +871,17 @@ void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const No
});
}
void EditorDebuggerNode::set_debug_mute_audio(bool p_mute) {
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
dbg->set_debug_mute_audio(p_mute);
});
debug_mute_audio = p_mute;
}
bool EditorDebuggerNode::get_debug_mute_audio() const {
return debug_mute_audio;
}
void EditorDebuggerNode::set_camera_override(CameraOverride p_override) {
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
dbg->set_camera_override(p_override);

View File

@ -113,6 +113,8 @@ private:
bool keep_open = false;
String current_uri;
bool debug_mute_audio = false;
CameraOverride camera_override = OVERRIDE_NONE;
HashMap<Breakpoint, bool, Breakpoint> breakpoints;
@ -214,6 +216,9 @@ public:
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
void set_debug_mute_audio(bool p_mute);
bool get_debug_mute_audio() const;
void set_camera_override(CameraOverride p_override);
CameraOverride get_camera_override();

View File

@ -1543,6 +1543,17 @@ void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const
}
}
bool ScriptEditorDebugger::get_debug_mute_audio() const {
return debug_mute_audio;
}
void ScriptEditorDebugger::set_debug_mute_audio(bool p_mute) {
Array msg;
msg.push_back(p_mute);
_put_msg("scene:debug_mute_audio", msg);
debug_mute_audio = p_mute;
}
CameraOverride ScriptEditorDebugger::get_camera_override() const {
return camera_override;
}

View File

@ -183,6 +183,8 @@ private:
void _select_thread(int p_index);
bool debug_mute_audio = false;
EditorDebuggerNode::CameraOverride camera_override;
void _stack_dump_frame_selected();
@ -303,6 +305,9 @@ public:
void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name);
void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos);
bool get_debug_mute_audio() const;
void set_debug_mute_audio(bool p_mute);
EditorDebuggerNode::CameraOverride get_camera_override() const;
void set_camera_override(EditorDebuggerNode::CameraOverride p_override);

View File

@ -73,6 +73,7 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie, const V
bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
bool debug_avoidance = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_avoidance", false);
bool debug_canvas_redraw = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_canvas_redraw", false);
bool debug_mute_audio = EditorDebuggerNode::get_singleton()->get_debug_mute_audio();
if (debug_collisions) {
args.push_back("--debug-collisions");
@ -94,6 +95,10 @@ Error EditorRun::run(const String &p_scene, const String &p_write_movie, const V
args.push_back("--debug-canvas-item-redraw");
}
if (debug_mute_audio) {
args.push_back("--debug-mute-audio");
}
if (p_write_movie != "") {
args.push_back("--write-movie");
args.push_back(p_write_movie);

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" width="16" height="16" version="1.0" viewBox="0 0 2.4 2.4"><path fill="#e0e0e0" d="M 1.2518555 0.15 A 0.1 0.1 0 0 0 1.1701172 0.17988281 L 0.6 0.75 L 0.31787109 0.75 C 0.22487119 0.75 0.15 0.81700008 0.15 0.9 L 0.15 1.5 C 0.15 1.5424221 0.16969512 1.5805593 0.20126953 1.6078125 L 1.35 0.45527344 L 1.35 0.25605469 A 0.106 0.106 0 0 0 1.2518555 0.15 z M 1.35 1.6438477 L 0.97236328 2.0223633 L 1.1701172 2.2201172 C 1.2361171 2.2871171 1.35 2.239996 1.35 2.1459961 L 1.35 1.6438477 z"/><path fill="#e0e0e0" d="M 2.1984375 0.79306641 L 2.0660156 0.92578125 C 2.1142629 1.1320246 2.0935608 1.3239034 2.0487305 1.4882812 C 1.9692536 1.7796963 1.8105469 1.9725586 1.8105469 1.9725586 A 0.0825 0.0825 0 0 0 1.8222656 2.0879883 A 0.0825 0.0825 0 0 0 1.9394531 2.0780273 C 1.9394531 2.0780273 2.1176607 1.8586814 2.2069336 1.5313477 C 2.2638362 1.3227069 2.2834498 1.0648044 2.1984375 0.79306641 z M 1.8539062 1.1384766 L 1.6790039 1.3136719 C 1.6747238 1.3346601 1.6697313 1.3550615 1.6640625 1.3749023 C 1.6131343 1.5531513 1.5117188 1.6719727 1.5117187 1.6719727 A 0.0825 0.0825 0 0 0 1.5213867 1.7871094 A 0.0825 0.0825 0 0 0 1.6368164 1.7791992 C 1.6368164 1.7791992 1.7606941 1.6355198 1.8222656 1.4200195 C 1.8460259 1.3368593 1.8597024 1.2410136 1.8539062 1.1384766 z" color="#000" paint-order="markers stroke fill" style="-inkscape-stroke:none"/><path fill="#fc7f7f" d="M.08295 2.0529 2.0502.07965 2.31705.34725.34965 2.32035ZM-1.2804596 3.0939027 3.0879072-1.2877874Z"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -95,6 +95,9 @@ void GameViewDebugger::_session_started(Ref<EditorDebuggerSession> p_session) {
Array mode;
mode.append(select_mode);
p_session->send_message("scene:runtime_node_select_set_mode", mode);
Array mute_audio_data;
mute_audio_data.append(mute_audio);
p_session->send_message("scene:debug_mute_audio", mute_audio_data);
emit_signal(SNAME("session_started"));
}
@ -169,6 +172,11 @@ void GameViewDebugger::set_select_mode(int p_mode) {
}
}
void GameViewDebugger::set_debug_mute_audio(bool p_enabled) {
mute_audio = p_enabled;
EditorDebuggerNode::get_singleton()->set_debug_mute_audio(p_enabled);
}
void GameViewDebugger::set_camera_override(bool p_enabled) {
EditorDebuggerNode::get_singleton()->set_camera_override(p_enabled ? camera_override_mode : EditorDebuggerNode::OVERRIDE_NONE);
}
@ -593,6 +601,13 @@ void GameView::_hide_selection_toggled(bool p_pressed) {
EditorSettings::get_singleton()->set_project_metadata("game_view", "hide_selection", p_pressed);
}
void GameView::_debug_mute_audio_button_pressed() {
debug_mute_audio = !debug_mute_audio;
debug_mute_audio_button->set_button_icon(get_editor_theme_icon(debug_mute_audio ? SNAME("AudioMute") : SNAME("AudioStreamPlayer")));
debug_mute_audio_button->set_tooltip_text(debug_mute_audio ? TTRC("Unmute game audio.") : TTRC("Mute game audio."));
debugger->set_debug_mute_audio(debug_mute_audio);
}
void GameView::_camera_override_button_toggled(bool p_pressed) {
_update_debugger_buttons();
@ -654,6 +669,8 @@ void GameView::_notification(int p_what) {
stretch_button->set_button_icon(get_editor_theme_icon(SNAME("Stretch")));
embed_options_menu->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
debug_mute_audio_button->set_button_icon(get_editor_theme_icon(debug_mute_audio ? SNAME("AudioMute") : SNAME("AudioStreamPlayer")));
camera_override_button->set_button_icon(get_editor_theme_icon(SNAME("Camera")));
camera_override_menu->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));
} break;
@ -963,6 +980,14 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, WindowWrapper *p_wrapper) {
main_menu_hbox->add_child(memnew(VSeparator));
debug_mute_audio_button = memnew(Button);
main_menu_hbox->add_child(debug_mute_audio_button);
debug_mute_audio_button->set_theme_type_variation("FlatButton");
debug_mute_audio_button->connect(SceneStringName(pressed), callable_mp(this, &GameView::_debug_mute_audio_button_pressed));
debug_mute_audio_button->set_tooltip_text(debug_mute_audio ? TTRC("Unmute game audio.") : TTRC("Mute game audio."));
main_menu_hbox->add_child(memnew(VSeparator));
camera_override_button = memnew(Button);
main_menu_hbox->add_child(camera_override_button);
camera_override_button->set_toggle_mode(true);

View File

@ -52,6 +52,7 @@ private:
int node_type = RuntimeNodeSelect::NODE_TYPE_NONE;
bool selection_visible = true;
int select_mode = RuntimeNodeSelect::SELECT_MODE_SINGLE;
bool mute_audio = false;
EditorDebuggerNode::CameraOverride camera_override_mode = EditorDebuggerNode::OVERRIDE_INGAME;
void _session_started(Ref<EditorDebuggerSession> p_session);
@ -71,6 +72,8 @@ public:
void set_selection_visible(bool p_visible);
void set_debug_mute_audio(bool p_enabled);
void set_camera_override(bool p_enabled);
void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode);
@ -127,6 +130,8 @@ class GameView : public VBoxContainer {
Rect2i floating_window_rect;
int floating_window_screen = -1;
bool debug_mute_audio = false;
Button *suspend_button = nullptr;
Button *next_frame_button = nullptr;
@ -135,6 +140,8 @@ class GameView : public VBoxContainer {
Button *hide_selection = nullptr;
Button *debug_mute_audio_button = nullptr;
Button *camera_override_button = nullptr;
MenuButton *camera_override_menu = nullptr;
@ -178,6 +185,8 @@ class GameView : public VBoxContainer {
void _hide_selection_toggled(bool p_pressed);
void _debug_mute_audio_button_pressed();
void _camera_override_button_toggled(bool p_pressed);
void _camera_override_menu_id_pressed(int p_id);

View File

@ -246,6 +246,7 @@ static bool debug_paths = false;
static bool debug_navigation = false;
static bool debug_avoidance = false;
static bool debug_canvas_item_redraw = false;
static bool debug_mute_audio = false;
#endif
static int max_fps = -1;
static int frame_delay = 0;
@ -1678,6 +1679,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
debug_canvas_item_redraw = true;
} else if (arg == "--debug-stringnames") {
StringName::set_debug_stringnames(true);
} else if (arg == "--debug-mute-audio") {
debug_mute_audio = true;
#endif
#if defined(TOOLS_ENABLED) && (defined(WINDOWS_ENABLED) || defined(LINUXBSD_ENABLED))
} else if (arg == "--test-rd-support") {
@ -4084,6 +4087,10 @@ int Main::start() {
if (debug_canvas_item_redraw) {
RenderingServer::get_singleton()->canvas_item_set_debug_redraw(true);
}
if (debug_mute_audio) {
AudioServer::get_singleton()->set_debug_mute(true);
}
#endif
if (single_threaded_scene) {

View File

@ -52,6 +52,7 @@
#include "scene/main/window.h"
#include "scene/resources/packed_scene.h"
#include "scene/theme/theme_db.h"
#include "servers/audio_server.h"
SceneDebugger::SceneDebugger() {
singleton = this;
@ -150,6 +151,11 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra
} else if (p_msg == "next_frame") {
_next_frame();
} else if (p_msg == "debug_mute_audio") { // Enable/disable audio.
ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);
bool do_mute = p_args[0];
AudioServer::get_singleton()->set_debug_mute(do_mute);
} else if (p_msg == "override_cameras") { /// Camera
ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);
bool enable = p_args[0];

View File

@ -294,7 +294,11 @@ void AudioServer::_driver_process(int p_frames, int32_t *p_buffer) {
// The destination start for data will be the same in all cases.
int32_t *dest = &p_buffer[from_buf * (cs * 2) + (k * 2)];
#ifdef DEBUG_ENABLED
if (!debug_mute && master->channels[k].active) {
#else
if (master->channels[k].active) {
#endif // DEBUG_ENABLED
const AudioFrame *buf = master->channels[k].buffer.ptr();
for (int j = 0; j < to_copy; j++) {
@ -765,6 +769,16 @@ int AudioServer::thread_find_bus_index(const StringName &p_name) {
}
}
#ifdef DEBUG_ENABLED
void AudioServer::set_debug_mute(bool p_mute) {
debug_mute = p_mute;
}
bool AudioServer::get_debug_mute() const {
return debug_mute;
}
#endif // DEBUG_ENABLED
void AudioServer::set_bus_count(int p_count) {
ERR_FAIL_COND(p_count < 1);
ERR_FAIL_INDEX(p_count, 256);

View File

@ -228,6 +228,10 @@ private:
bool tag_used_audio_streams = false;
#ifdef DEBUG_ENABLED
bool debug_mute = false;
#endif // DEBUG_ENABLED
struct Bus {
StringName name;
bool solo = false;
@ -366,6 +370,11 @@ public:
int thread_get_mix_buffer_size() const;
int thread_find_bus_index(const StringName &p_name);
#ifdef DEBUG_ENABLED
void set_debug_mute(bool p_mute);
bool get_debug_mute() const;
#endif // DEBUG_ENABLED
void set_bus_count(int p_count);
int get_bus_count() const;