diff --git a/src/eventthread.cpp b/src/eventthread.cpp index f87b5aa..63a6d86 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -28,13 +28,45 @@ #include #include +#include + #include "sharedstate.h" #include "graphics.h" #include "settingsmenu.h" +#include "al-util.h" #include "debugwriter.h" #include +typedef void (ALC_APIENTRY *LPALCDEVICEPAUSESOFT) (ALCdevice *device); +typedef void (ALC_APIENTRY *LPALCDEVICERESUMESOFT) (ALCdevice *device); + +#define AL_DEVICE_PAUSE_FUN \ + AL_FUN(DevicePause, LPALCDEVICEPAUSESOFT) \ + AL_FUN(DeviceResume, LPALCDEVICERESUMESOFT) + +struct ALCFunctions +{ +#define AL_FUN(name, type) type name; + AL_DEVICE_PAUSE_FUN +#undef AL_FUN +} static alc; + +static void +initALCFunctions(ALCdevice *alcDev) +{ + if (!strstr(alcGetString(alcDev, ALC_EXTENSIONS), "ALC_SOFT_pause_device")) + return; + + Debug() << "ALC_SOFT_pause_device present"; + +#define AL_FUN(name, type) alc. name = (type) alcGetProcAddress(alcDev, "alc" #name "SOFT"); + AL_DEVICE_PAUSE_FUN; +#undef AL_FUN +} + +#define HAVE_ALC_DEVICE_PAUSE alc.DevicePause + uint8_t EventThread::keyStates[]; EventThread::JoyState EventThread::joyState; EventThread::MouseState EventThread::mouseState; @@ -76,6 +108,7 @@ void EventThread::process(RGSSThreadData &rtData) SDL_Window *win = rtData.window; UnidirMessage &windowSizeMsg = rtData.windowSizeMsg; + initALCFunctions(rtData.alcDev); SDL_SetEventFilter(eventFilter, &rtData); fullscreen = rtData.config.fullscreen; @@ -422,6 +455,9 @@ int EventThread::eventFilter(void *data, SDL_Event *event) case SDL_APP_WILLENTERBACKGROUND : Debug() << "SDL_APP_WILLENTERBACKGROUND"; + if (HAVE_ALC_DEVICE_PAUSE) + alc.DevicePause(rtData.alcDev); + rtData.syncPoint.haltThreads(); return 0; @@ -437,6 +473,9 @@ int EventThread::eventFilter(void *data, SDL_Event *event) case SDL_APP_DIDENTERFOREGROUND : Debug() << "SDL_APP_DIDENTERFOREGROUND"; + if (HAVE_ALC_DEVICE_PAUSE) + alc.DeviceResume(rtData.alcDev); + rtData.syncPoint.resumeThreads(); return 0;