mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-03 16:31:56 -04:00
Add pause on unfocus feature
This commit is contained in:
@@ -77,6 +77,14 @@ void dusk::audio::SetMasterVolume(const f32 value) {
|
||||
MasterVolume = value;
|
||||
}
|
||||
|
||||
void dusk::audio::SetPaused(const bool paused) {
|
||||
if (paused) {
|
||||
SDL_PauseAudioStreamDevice(PlaybackStream);
|
||||
} else {
|
||||
SDL_ResumeAudioStreamDevice(PlaybackStream);
|
||||
}
|
||||
}
|
||||
|
||||
void dusk::audio::SetEnableReverb(const bool value) {
|
||||
JASCriticalSection section;
|
||||
|
||||
|
||||
@@ -29,6 +29,11 @@ void reset_accumulator() {
|
||||
s_sim_accumulator = 0.0f;
|
||||
}
|
||||
|
||||
void reset_frame_timer() {
|
||||
s_previous_sample = clock::now();
|
||||
s_sim_accumulator = 0.0f;
|
||||
}
|
||||
|
||||
MainLoopPacer advance_main_loop() {
|
||||
ensure_initialized();
|
||||
|
||||
|
||||
@@ -194,6 +194,9 @@ namespace dusk {
|
||||
#if DUSK_ENABLE_SENTRY_NATIVE
|
||||
config::ImGuiCheckbox("Enable Crash Reporting", getSettings().backend.enableCrashReporting);
|
||||
#endif
|
||||
if (!IsMobile) {
|
||||
config::ImGuiCheckbox("Pause on Focus Lost", getSettings().game.pauseOnFocusLost);
|
||||
}
|
||||
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ UserSettings g_userSettings = {
|
||||
.enableMirrorMode {"game.enableMirrorMode", false},
|
||||
.invertCameraXAxis {"game.invertCameraXAxis", false},
|
||||
.disableMainHUD {"game.disableMainHUD", false},
|
||||
.pauseOnFocusLost {"game.pauseOnFocusLost", false},
|
||||
|
||||
// Graphics
|
||||
.bloomMode {"game.bloomMode", BloomMode::Classic},
|
||||
@@ -136,6 +137,7 @@ void registerSettings() {
|
||||
Register(g_userSettings.game.enableMirrorMode);
|
||||
Register(g_userSettings.game.invertCameraXAxis);
|
||||
Register(g_userSettings.game.disableMainHUD);
|
||||
Register(g_userSettings.game.pauseOnFocusLost);
|
||||
Register(g_userSettings.game.bloomMode);
|
||||
Register(g_userSettings.game.bloomMultiplier);
|
||||
Register(g_userSettings.game.enableWaterRefraction);
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
#include "cxxopts.hpp"
|
||||
#include "dusk/audio/DuskAudioSystem.h"
|
||||
#include "dusk/config.hpp"
|
||||
#include "dusk/settings.h"
|
||||
#include "dusk/imgui/ImGuiConsole.hpp"
|
||||
#include "tracy/Tracy.hpp"
|
||||
|
||||
@@ -92,6 +93,7 @@ const int audioHeapSize = 0x14D800;
|
||||
bool dusk::IsRunning = true;
|
||||
bool dusk::IsShuttingDown = false;
|
||||
bool dusk::IsGameLaunched = false;
|
||||
bool dusk::IsFocusPaused = false;
|
||||
#endif
|
||||
|
||||
s32 LOAD_COPYDATE(void*) {
|
||||
@@ -208,6 +210,16 @@ void main01(void) {
|
||||
goto eventsDone;
|
||||
case AURORA_SDL_EVENT:
|
||||
dusk::g_imguiConsole.HandleSDLEvent(event->sdl);
|
||||
if (event->sdl.type == SDL_EVENT_WINDOW_FOCUS_LOST &&
|
||||
dusk::getSettings().game.pauseOnFocusLost) {
|
||||
dusk::IsFocusPaused = true;
|
||||
dusk::audio::SetPaused(true);
|
||||
} else if (event->sdl.type == SDL_EVENT_WINDOW_FOCUS_GAINED &&
|
||||
dusk::IsFocusPaused) {
|
||||
dusk::IsFocusPaused = false;
|
||||
dusk::audio::SetPaused(false);
|
||||
dusk::game_clock::reset_frame_timer();
|
||||
}
|
||||
break;
|
||||
case AURORA_DISPLAY_SCALE_CHANGED:
|
||||
dusk::ImGuiEngine_Initialize(event->windowSize.scale);
|
||||
@@ -221,6 +233,11 @@ void main01(void) {
|
||||
|
||||
eventsDone:;
|
||||
|
||||
if (dusk::IsFocusPaused) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(16));
|
||||
continue;
|
||||
}
|
||||
|
||||
const dusk::game_clock::MainLoopPacer pacing = dusk::game_clock::advance_main_loop();
|
||||
|
||||
VIWaitForRetrace();
|
||||
|
||||
Reference in New Issue
Block a user