Skip to content

Commit fc9a775

Browse files
committed
Merge pull request #104420 from pafuent/pause_audio_when_game_is_paused
Pause audio when game is paused
2 parents 3d91a48 + b008050 commit fc9a775

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

editor/debugger/script_editor_debugger.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void ScriptEditorDebugger::debug_break() {
129129
ERR_FAIL_COND(is_breaked());
130130

131131
_put_msg("break", Array());
132+
_mute_audio_on_break(true);
132133
}
133134

134135
void ScriptEditorDebugger::debug_continue() {
@@ -142,6 +143,7 @@ void ScriptEditorDebugger::debug_continue() {
142143
_clear_execution();
143144
_put_msg("continue", Array(), debugging_thread_id);
144145
_put_msg("servers:foreground", Array());
146+
_mute_audio_on_break(false);
145147
}
146148

147149
void ScriptEditorDebugger::update_tabs() {
@@ -324,6 +326,7 @@ void ScriptEditorDebugger::_thread_debug_enter(uint64_t p_thread_id) {
324326
ThreadDebugged &td = threads_debugged[p_thread_id];
325327
_set_reason_text(td.error, MESSAGE_ERROR);
326328
emit_signal(SNAME("breaked"), true, td.can_debug, td.error, td.has_stackdump);
329+
_mute_audio_on_break(true);
327330
if (!td.error.is_empty() && EDITOR_GET("debugger/auto_switch_to_stack_trace")) {
328331
tabs->set_current_tab(0);
329332
}
@@ -395,6 +398,7 @@ void ScriptEditorDebugger::_msg_debug_exit(uint64_t p_thread_id, const Array &p_
395398

396399
_set_reason_text(TTR("Execution resumed."), MESSAGE_SUCCESS);
397400
emit_signal(SNAME("breaked"), false, false, "", false);
401+
_mute_audio_on_break(false);
398402

399403
_update_buttons_state();
400404
} else {
@@ -446,6 +450,11 @@ void ScriptEditorDebugger::_msg_scene_inspect_object(uint64_t p_thread_id, const
446450
}
447451
#endif // DISABLE_DEPRECATED
448452

453+
void ScriptEditorDebugger::_msg_scene_debug_mute_audio(uint64_t p_thread_id, const Array &p_data) {
454+
ERR_FAIL_COND(p_data.is_empty());
455+
// This is handled by SceneDebugger, we need to ignore here to not show a warning.
456+
}
457+
449458
void ScriptEditorDebugger::_msg_servers_memory_usage(uint64_t p_thread_id, const Array &p_data) {
450459
vmem_tree->clear();
451460
TreeItem *root = vmem_tree->create_item();
@@ -966,6 +975,7 @@ void ScriptEditorDebugger::_init_parse_message_handlers() {
966975
#ifndef DISABLE_DEPRECATED
967976
parse_message_handlers["scene:inspect_object"] = &ScriptEditorDebugger::_msg_scene_inspect_object;
968977
#endif // DISABLE_DEPRECATED
978+
parse_message_handlers["scene:debug_mute_audio"] = &ScriptEditorDebugger::_msg_scene_debug_mute_audio;
969979
parse_message_handlers["servers:memory_usage"] = &ScriptEditorDebugger::_msg_servers_memory_usage;
970980
parse_message_handlers["servers:drawn"] = &ScriptEditorDebugger::_msg_servers_drawn;
971981
parse_message_handlers["stack_dump"] = &ScriptEditorDebugger::_msg_stack_dump;
@@ -1628,12 +1638,27 @@ bool ScriptEditorDebugger::get_debug_mute_audio() const {
16281638
return debug_mute_audio;
16291639
}
16301640

1631-
void ScriptEditorDebugger::set_debug_mute_audio(bool p_mute) {
1641+
void ScriptEditorDebugger::_send_debug_mute_audio_msg(bool p_mute) {
16321642
Array msg = { p_mute };
16331643
_put_msg("scene:debug_mute_audio", msg);
1644+
}
1645+
1646+
void ScriptEditorDebugger::set_debug_mute_audio(bool p_mute) {
1647+
// Send the message if we want to mute the audio or if it isn't muted already due to a break.
1648+
if (p_mute || !audio_muted_on_break) {
1649+
_send_debug_mute_audio_msg(p_mute);
1650+
}
16341651
debug_mute_audio = p_mute;
16351652
}
16361653

1654+
void ScriptEditorDebugger::_mute_audio_on_break(bool p_mute) {
1655+
// Send the message if we want to mute the audio on a break or if it isn't muted already.
1656+
if (p_mute || !debug_mute_audio) {
1657+
_send_debug_mute_audio_msg(p_mute);
1658+
}
1659+
audio_muted_on_break = p_mute;
1660+
}
1661+
16371662
CameraOverride ScriptEditorDebugger::get_camera_override() const {
16381663
return camera_override;
16391664
}

editor/debugger/script_editor_debugger.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ class ScriptEditorDebugger : public MarginContainer {
185185
void _select_thread(int p_index);
186186

187187
bool debug_mute_audio = false;
188+
bool audio_muted_on_break = false;
189+
void _mute_audio_on_break(bool p_mute);
190+
void _send_debug_mute_audio_msg(bool p_mute);
188191

189192
EditorDebuggerNode::CameraOverride camera_override;
190193

@@ -206,6 +209,7 @@ class ScriptEditorDebugger : public MarginContainer {
206209
#ifndef DISABLE_DEPRECATED
207210
void _msg_scene_inspect_object(uint64_t p_thread_id, const Array &p_data);
208211
#endif // DISABLE_DEPRECATED
212+
void _msg_scene_debug_mute_audio(uint64_t p_thread_id, const Array &p_data);
209213
void _msg_servers_memory_usage(uint64_t p_thread_id, const Array &p_data);
210214
void _msg_servers_drawn(uint64_t p_thread_id, const Array &p_data);
211215
void _msg_stack_dump(uint64_t p_thread_id, const Array &p_data);

0 commit comments

Comments
 (0)