Add mute window when unfocused option

Co-Authored-By: Tulpen <63363329+tulpenkiste@users.noreply.github.com>
This commit is contained in:
Agent X 2024-06-30 11:42:37 -04:00
parent fa2a182830
commit 099b97b934
20 changed files with 51 additions and 15 deletions

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Hlasitost písničky"
SFX_VOLUME = "Hlasitost zvuků"
ENV_VOLUME = "Hlasitost prostředí"
FADEOUT = "Ztišit daleké zvuky"
MUTE_FOCUS_LOSS = "Ztlumit, když je okno na pozadí"
[LANGUAGE]
LANGUAGE = "JAZYK"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Muziek Geluid"
SFX_VOLUME = "Sfx Geluid"
ENV_VOLUME = "Env Geluid"
FADEOUT = "Vervaagd Geluid in de Verte"
MUTE_FOCUS_LOSS = "Dempen wanneer venster niet meer scherp is"
[LANGUAGE]
LANGUAGE = "TAAL"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Music Volume"
SFX_VOLUME = "Sound Effects Volume"
ENV_VOLUME = "Environment Volume"
FADEOUT = "Fade Out Distant Sounds"
MUTE_FOCUS_LOSS = "Mute When Window Unfocused"
[LANGUAGE]
LANGUAGE = "LANGUAGE"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Volume de la musique"
SFX_VOLUME = "Volume des effets sonores"
ENV_VOLUME = "Volume de l'environnement"
FADEOUT = "Disparition des sons distants"
MUTE_FOCUS_LOSS = "Muet en arrière plan"
[LANGUAGE]
LANGUAGE = "LANGUE"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Musiklautstärke"
SFX_VOLUME = "Effektlautstärke"
ENV_VOLUME = "Umgebungslautstärke"
FADEOUT = "Ausblenden"
MUTE_FOCUS_LOSS = "Stumm wenn nicht fokussiert"
[LANGUAGE]
LANGUAGE = "SPRACHE"

View File

@ -360,6 +360,7 @@ MUSIC_VOLUME = "Musica"
SFX_VOLUME = "Effetti sonori"
ENV_VOLUME = "Ambiente"
FADEOUT = "Suoni lontani in dissolvenza"
MUTE_FOCUS_LOSS = "Disattiva l'audio quando la finestra non è a fuoco"
[LANGUAGE]
LANGUAGE = "LINGUA"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Głośność Muzyki"
SFX_VOLUME = "Głośność Efektów"
ENV_VOLUME = "Głośność Środowiska"
FADEOUT = "Zanikanie Odległych Dźwięków"
MUTE_FOCUS_LOSS = "Wycisz dźwięk, gdy okno traci fokus"
[LANGUAGE]
LANGUAGE = "JĘZYK"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Volume da música"
SFX_VOLUME = "Volume dos efeitos"
ENV_VOLUME = "Volume ambiente"
FADEOUT = "Desvanecer sons distantes"
MUTE_FOCUS_LOSS = "Silenciar quando a janela estiver desfocada"
[LANGUAGE]
LANGUAGE = "IDIOMA"

View File

@ -361,6 +361,7 @@ MUSIC_VOLUME = "Громкость музыки"
SFX_VOLUME = "Громкость звуков"
ENV_VOLUME = "Объёмное звучание"
FADEOUT = "Затухание звуков на расстоянии"
MUTE_FOCUS_LOSS = "Выключить звук когда окно не выбрано"
[LANGUAGE]
LANGUAGE = "LANGUAGE"

View File

@ -362,6 +362,7 @@ MUSIC_VOLUME = "Volumen de Música"
SFX_VOLUME = "Volumen de Efectos de Sonido"
ENV_VOLUME = "Volumen de Entorno"
FADEOUT = "Disminuir sonidos lejanos"
MUTE_FOCUS_LOSS = "Muda sonido cuando ventana esta desenfocado"
[LANGUAGE]
LANGUAGE = "IDIOMA"

View File

@ -71,7 +71,7 @@ ConfigWindow configWindow = {
.y = WAPI_WIN_CENTERPOS,
.w = DESIRED_SCREEN_WIDTH,
.h = DESIRED_SCREEN_HEIGHT,
.vsync = 0,
.vsync = 1,
.reset = false,
.fullscreen = false,
.exiting_fullscreen = false,
@ -82,7 +82,7 @@ ConfigWindow configWindow = {
// display settings
unsigned int configFiltering = 2; // 0 = Nearest, 1 = Bilinear, 2 = Trilinear
bool configShowFPS = false;
bool configUncappedFramerate = false;
bool configUncappedFramerate = true;
unsigned int configFrameLimit = 60;
unsigned int configInterpolationMode = 1;
unsigned int configDrawDistance = 4;
@ -92,6 +92,7 @@ unsigned int configMusicVolume = MAX_VOLUME;
unsigned int configSfxVolume = MAX_VOLUME;
unsigned int configEnvVolume = MAX_VOLUME;
bool configFadeoutDistantSounds = false;
bool configMuteFocusLoss = false;
// control binds
unsigned int configKeyA[MAX_BINDS] = { 0x0026, 0x1000, 0x1103 };
unsigned int configKeyB[MAX_BINDS] = { 0x0033, 0x1001, 0x1101 };
@ -207,6 +208,7 @@ static const struct ConfigOption options[] = {
{.name = "sfx_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configSfxVolume},
{.name = "env_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configEnvVolume},
{.name = "fade_distant_sounds", .type = CONFIG_TYPE_BOOL, .boolValue = &configFadeoutDistantSounds},
{.name = "mute_focus_loss", .type = CONFIG_TYPE_BOOL, .boolValue = &configMuteFocusLoss},
// control binds
{.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA},
{.name = "key_b", .type = CONFIG_TYPE_BIND, .uintValue = configKeyB},

View File

@ -43,6 +43,7 @@ extern unsigned int configMusicVolume;
extern unsigned int configSfxVolume;
extern unsigned int configEnvVolume;
extern bool configFadeoutDistantSounds;
extern bool configMuteFocusLoss;
// control binds
extern unsigned int configKeyA[MAX_BINDS];
extern unsigned int configKeyB[MAX_BINDS];

View File

@ -173,7 +173,7 @@ static void controller_sdl_read(OSContPad *pad) {
return;
}
if ((newcam_mouse == 1 || gFirstPersonCamera.enabled || gDjuiHudLockMouse) && gMenuMode == -1 && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) {
if ((newcam_mouse == 1 || gFirstPersonCamera.enabled || gDjuiHudLockMouse) && gMenuMode == -1 && !gDjuiInMainMenu && !gDjuiChatBoxFocus && !gDjuiConsoleFocus && WAPI.has_focus()) {
SDL_SetRelativeMouseMode(SDL_TRUE);
} else {
SDL_SetRelativeMouseMode(SDL_FALSE);

View File

@ -18,6 +18,7 @@ void djui_panel_sound_create(struct DjuiBase* caller) {
djui_slider_create(body, DLANG(SOUND, SFX_VOLUME), &configSfxVolume, 0, 127, djui_panel_sound_value_change);
djui_slider_create(body, DLANG(SOUND, ENV_VOLUME), &configEnvVolume, 0, 127, djui_panel_sound_value_change);
djui_checkbox_create(body, DLANG(SOUND, FADEOUT), &configFadeoutDistantSounds, NULL);
djui_checkbox_create(body, DLANG(SOUND, MUTE_FOCUS_LOSS), &configMuteFocusLoss, NULL);
djui_button_create(body, DLANG(MENU, BACK), DJUI_BUTTON_STYLE_BACK, djui_panel_menu_back);
}

View File

@ -80,14 +80,14 @@ static void gfx_dummy_wm_delay(u32 ms) {
sleep_ms(ms);
}
static int gfx_dummy_get_max_msaa(void) {
static int gfx_dummy_wm_get_max_msaa(void) {
return 0;
}
static void gfx_dummy_set_window_title(UNUSED const char* title) {
static void gfx_dummy_wm_set_window_title(UNUSED const char* title) {
}
static void gfx_dummy_reset_window_title(void) {
static void gfx_dummy_wm_reset_window_title(void) {
}
static void gfx_dummy_wm_swap_buffers_begin(void) {
@ -119,6 +119,10 @@ static void gfx_dummy_wm_set_clipboard_text(UNUSED char* text) {
static void gfx_dummy_wm_set_cursor_visible(UNUSED bool visible) {
}
static bool gfx_dummy_wm_has_focus(void) {
return true;
}
static bool gfx_dummy_renderer_z_is_from_0_to_1(void) {
return false;
}
@ -212,9 +216,10 @@ struct GfxWindowManagerAPI gfx_dummy_wm_api = {
gfx_dummy_wm_set_clipboard_text,
gfx_dummy_wm_set_cursor_visible,
gfx_dummy_wm_delay,
gfx_dummy_get_max_msaa,
gfx_dummy_set_window_title,
gfx_dummy_reset_window_title
gfx_dummy_wm_get_max_msaa,
gfx_dummy_wm_set_window_title,
gfx_dummy_wm_reset_window_title,
gfx_dummy_wm_has_focus
};
struct GfxRenderingAPI gfx_dummy_renderer_api = {

View File

@ -704,6 +704,10 @@ static void gfx_dxgi_reset_window_title(void) {
SetWindowTextA(dxgi.h_wnd, TITLE);
}
static bool gfx_dxgi_has_focus(void) {
return GetFocus() == dxgi.h_wnd;
}
HWND gfx_dxgi_get_h_wnd(void) {
return dxgi.h_wnd;
}
@ -775,7 +779,8 @@ struct GfxWindowManagerAPI gfx_dxgi = {
gfx_dxgi_delay,
gfx_dxgi_get_max_msaa,
gfx_dxgi_set_window_title,
gfx_dxgi_reset_window_title
gfx_dxgi_reset_window_title,
gfx_dxgi_has_focus
};
#endif

View File

@ -205,6 +205,10 @@ static void gfx_sdl_shutdown(void) {
SDL_Quit();
}
static bool gfx_sdl_has_focus(void) {
return SDL_GetAppState() & SDL_APPINPUTFOCUS;
}
static void gfx_sdl_start_text_input(void) { return; }
static void gfx_sdl_stop_text_input(void) { return; }
static char* gfx_sdl_get_clipboard_text(void) { return NULL; }
@ -230,7 +234,8 @@ struct GfxWindowManagerAPI gfx_sdl = {
gfx_sdl_delay,
gfx_sdl_get_max_msaa,
gfx_sdl_set_window_title,
gfx_sdl_reset_window_title
gfx_sdl_reset_window_title,
gfx_sdl_has_focus
};
#endif // BACKEND_WM

View File

@ -298,6 +298,10 @@ static void gfx_sdl_shutdown(void) {
}
}
static bool gfx_sdl_has_focus(void) {
return (SDL_GetWindowFlags(wnd) & SDL_WINDOW_INPUT_FOCUS);
}
static void gfx_sdl_start_text_input(void) { SDL_StartTextInput(); }
static void gfx_sdl_stop_text_input(void) { SDL_StopTextInput(); }
static char* gfx_sdl_get_clipboard_text(void) { return SDL_GetClipboardText(); }
@ -323,7 +327,8 @@ struct GfxWindowManagerAPI gfx_sdl = {
gfx_sdl_delay,
gfx_sdl_get_max_msaa,
gfx_sdl_set_window_title,
gfx_sdl_reset_window_title
gfx_sdl_reset_window_title,
gfx_sdl_has_focus
};
#endif // BACKEND_WM

View File

@ -29,6 +29,7 @@ struct GfxWindowManagerAPI {
int (*get_max_msaa)(void);
void (*set_window_title)(const char* title);
void (*reset_window_title)(void);
bool (*has_focus)(void);
};
#endif

View File

@ -218,10 +218,11 @@ void produce_interpolation_frames_and_delay(void) {
}
inline static void buffer_audio(void) {
bool shouldMute = configMuteFocusLoss && !WAPI.has_focus();
const f32 masterMod = (f32)configMasterVolume / 127.0f * (f32)gLuaVolumeMaster / 127.0f;
set_sequence_player_volume(SEQ_PLAYER_LEVEL, (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f * masterMod);
set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f * masterMod);
set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * (f32)gLuaVolumeEnv / 127.0f * masterMod);
set_sequence_player_volume(SEQ_PLAYER_LEVEL, shouldMute ? 0 : (f32)configMusicVolume / 127.0f * (f32)gLuaVolumeLevel / 127.0f * masterMod);
set_sequence_player_volume(SEQ_PLAYER_SFX, shouldMute ? 0 : (f32)configSfxVolume / 127.0f * (f32)gLuaVolumeSfx / 127.0f * masterMod);
set_sequence_player_volume(SEQ_PLAYER_ENV, shouldMute ? 0 : (f32)configEnvVolume / 127.0f * (f32)gLuaVolumeEnv / 127.0f * masterMod);
int samplesLeft = audio_api->buffered();
u32 numAudioSamples = samplesLeft < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW;