EventThread: Pause OpenAL device when entering background
This requires ALC_SOFT_pause_device to be present. It stops the alc thread from needlessly consuming CPU resources.
This commit is contained in:
		
							parent
							
								
									7c6a2b2c62
								
							
						
					
					
						commit
						c92df0ce3a
					
				
					 1 changed files with 39 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -28,13 +28,45 @@
 | 
			
		|||
#include <SDL_thread.h>
 | 
			
		||||
#include <SDL_touch.h>
 | 
			
		||||
 | 
			
		||||
#include <alext.h>
 | 
			
		||||
 | 
			
		||||
#include "sharedstate.h"
 | 
			
		||||
#include "graphics.h"
 | 
			
		||||
#include "settingsmenu.h"
 | 
			
		||||
#include "al-util.h"
 | 
			
		||||
#include "debugwriter.h"
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
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<Vec2i> &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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue