Skip to content

Commit

Permalink
Merge pull request godotengine#21 from Meorge/mute-game
Browse files Browse the repository at this point in the history
Mute game
  • Loading branch information
Norrox authored Nov 24, 2024
2 parents f87f7b2 + 938e0e5 commit ea358cd
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 1 deletion.
7 changes: 7 additions & 0 deletions editor/debugger/editor_debugger_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,13 @@ void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const No
});
}

void EditorDebuggerNode::set_audio_enabled(bool p_enabled) {
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
dbg->set_audio_enabled(p_enabled);
});
audio_enabled = p_enabled;
}

void EditorDebuggerNode::set_camera_override(CameraOverride p_override) {
_for_all(tabs, [&](ScriptEditorDebugger *dbg) {
dbg->set_camera_override(p_override);
Expand Down
4 changes: 4 additions & 0 deletions editor/debugger/editor_debugger_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class EditorDebuggerNode : public MarginContainer {
bool keep_open = false;
String current_uri;

bool audio_enabled = true;

CameraOverride camera_override = OVERRIDE_NONE;
HashMap<Breakpoint, bool, Breakpoint> breakpoints;

Expand Down Expand Up @@ -205,6 +207,8 @@ class EditorDebuggerNode : public MarginContainer {
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_audio_enabled(bool p_enabled);

void set_camera_override(CameraOverride p_override);
CameraOverride get_camera_override();

Expand Down
11 changes: 11 additions & 0 deletions editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,17 @@ void ScriptEditorDebugger::live_debug_reparent_node(const NodePath &p_at, const
}
}

bool ScriptEditorDebugger::get_audio_enabled() const {
return audio_enabled;
}

void ScriptEditorDebugger::set_audio_enabled(bool p_enabled) {
Array msg;
msg.push_back(p_enabled);
_put_msg("scene:enable_audio", msg);
audio_enabled = p_enabled;
}

CameraOverride ScriptEditorDebugger::get_camera_override() const {
return camera_override;
}
Expand Down
5 changes: 5 additions & 0 deletions editor/debugger/script_editor_debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class ScriptEditorDebugger : public MarginContainer {

void _select_thread(int p_index);

bool audio_enabled = true;

EditorDebuggerNode::CameraOverride camera_override;

void _stack_dump_frame_selected();
Expand Down Expand Up @@ -299,6 +301,9 @@ class ScriptEditorDebugger : public MarginContainer {
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_audio_enabled() const;
void set_audio_enabled(bool p_enabled);

EditorDebuggerNode::CameraOverride get_camera_override() const;
void set_camera_override(EditorDebuggerNode::CameraOverride p_override);

Expand Down
19 changes: 19 additions & 0 deletions editor/plugins/game_view_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ void GameViewDebugger::set_select_mode(int p_mode) {
}
}

void GameViewDebugger::set_audio_enabled(bool p_enabled) {
EditorDebuggerNode::get_singleton()->set_audio_enabled(p_enabled);
}

void GameViewDebugger::set_camera_override(bool p_enabled) {
EditorDebuggerNode::get_singleton()->set_camera_override(p_enabled ? camera_override_mode : EditorDebuggerNode::OVERRIDE_NONE);
}
Expand Down Expand Up @@ -359,6 +363,10 @@ void GameView::_hide_selection_toggled(bool p_pressed) {
debugger->set_selection_visible(!p_pressed);
}

void GameView::_enable_audio_button_toggled(bool p_pressed) {
debugger->set_audio_enabled(p_pressed);
}

void GameView::_camera_override_button_toggled(bool p_pressed) {
_update_debugger_buttons();

Expand Down Expand Up @@ -414,6 +422,7 @@ void GameView::_notification(int p_what) {
keep_aspect_button->set_button_icon(get_editor_theme_icon(SNAME("KeepAspect")));
embed_options_menu->set_button_icon(get_editor_theme_icon(SNAME("GuiTabMenuHl")));

enable_audio_button->set_button_icon(get_editor_theme_icon(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;
Expand Down Expand Up @@ -654,6 +663,16 @@ GameView::GameView(Ref<GameViewDebugger> p_debugger, WindowWrapper *p_wrapper) {

main_menu_hbox->add_child(memnew(VSeparator));

enable_audio_button = memnew(Button);
main_menu_hbox->add_child(enable_audio_button);
enable_audio_button->set_toggle_mode(true);
enable_audio_button->set_pressed(true);
enable_audio_button->set_theme_type_variation("FlatButton");
enable_audio_button->connect(SceneStringName(toggled), callable_mp(this, &GameView::_enable_audio_button_toggled));
enable_audio_button->set_tooltip_text("Enable or 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);
Expand Down
6 changes: 6 additions & 0 deletions editor/plugins/game_view_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class GameViewDebugger : public EditorDebuggerPlugin {

void set_selection_visible(bool p_visible);

void set_audio_enabled(bool p_enabled);

void set_camera_override(bool p_enabled);
void set_camera_manipulate_mode(EditorDebuggerNode::CameraOverride p_mode);

Expand Down Expand Up @@ -115,6 +117,8 @@ class GameView : public VBoxContainer {

Button *hide_selection = nullptr;

Button *enable_audio_button = nullptr;

Button *camera_override_button = nullptr;
MenuButton *camera_override_menu = nullptr;

Expand Down Expand Up @@ -153,6 +157,8 @@ class GameView : public VBoxContainer {

void _hide_selection_toggled(bool p_pressed);

void _enable_audio_button_toggled(bool p_pressed);

void _camera_override_button_toggled(bool p_pressed);
void _camera_override_menu_id_pressed(int p_id);

Expand Down
6 changes: 6 additions & 0 deletions scene/debugger/scene_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,6 +145,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 == "enable_audio") { // Enable/disable audio
ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);
bool enable = p_args[0];
AudioServer::get_singleton()->set_mute(!enable);

} else if (p_msg == "override_cameras") { // Camera
ERR_FAIL_COND_V(p_args.is_empty(), ERR_INVALID_DATA);
bool enable = p_args[0];
Expand Down
10 changes: 9 additions & 1 deletion servers/audio_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ 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)];

if (master->channels[k].active) {
if (master->channels[k].active && !mute) {
const AudioFrame *buf = master->channels[k].buffer.ptr();

for (int j = 0; j < to_copy; j++) {
Expand Down Expand Up @@ -766,6 +766,14 @@ int AudioServer::thread_find_bus_index(const StringName &p_name) {
}
}

void AudioServer::set_mute(bool p_mute) {
mute = p_mute;
}

bool AudioServer::get_mute() const {
return mute;
}

void AudioServer::set_bus_count(int p_count) {
ERR_FAIL_COND(p_count < 1);
ERR_FAIL_INDEX(p_count, 256);
Expand Down
5 changes: 5 additions & 0 deletions servers/audio_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class AudioServer : public Object {

bool tag_used_audio_streams = false;

bool mute = false;

struct Bus {
StringName name;
bool solo = false;
Expand Down Expand Up @@ -367,6 +369,9 @@ class AudioServer : public Object {
int thread_get_mix_buffer_size() const;
int thread_find_bus_index(const StringName &p_name);

void set_mute(bool p_mute);
bool get_mute() const;

void set_bus_count(int p_count);
int get_bus_count() const;

Expand Down

0 comments on commit ea358cd

Please sign in to comment.