Create OpenAL device in main() and store in RGSSThreadData

This commit is contained in:
Jonas Kulla 2014-12-23 20:32:16 +01:00
parent 3596fc568d
commit 5974d05380
2 changed files with 21 additions and 16 deletions

View File

@ -37,6 +37,7 @@
#include <stdint.h>
struct RGSSThreadData;
typedef struct ALCdevice_struct ALCdevice;
struct SDL_Window;
class EventThread
@ -225,6 +226,7 @@ struct RGSSThreadData
const char *argv0;
SDL_Window *window;
ALCdevice *alcDev;
Vec2 sizeResoRatio;
Vec2i screenOffset;
@ -236,10 +238,12 @@ struct RGSSThreadData
RGSSThreadData(EventThread *ethread,
const char *argv0,
SDL_Window *window,
ALCdevice *alcDev,
const Config& newconf)
: ethread(ethread),
argv0(argv0),
window(window),
alcDev(alcDev),
sizeResoRatio(1, 1),
config(newconf)
{}

View File

@ -108,22 +108,11 @@ int rgssThreadFun(void *userdata)
GLDebugLogger dLogger;
/* Setup AL context */
ALCdevice *alcDev = alcOpenDevice(0);
if (!alcDev)
{
rgssThreadError(threadData, "Error opening OpenAL device");
SDL_GL_DeleteContext(glCtx);
return 0;
}
ALCcontext *alcCtx = alcCreateContext(alcDev, 0);
ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0);
if (!alcCtx)
{
rgssThreadError(threadData, "Error creating OpenAL context");
alcCloseDevice(alcDev);
SDL_GL_DeleteContext(glCtx);
return 0;
@ -139,7 +128,6 @@ int rgssThreadFun(void *userdata)
{
rgssThreadError(threadData, exc.msg);
alcDestroyContext(alcCtx);
alcCloseDevice(alcDev);
SDL_GL_DeleteContext(glCtx);
return 0;
@ -154,8 +142,6 @@ int rgssThreadFun(void *userdata)
SharedState::finiInstance();
alcDestroyContext(alcCtx);
alcCloseDevice(alcDev);
SDL_GL_DeleteContext(glCtx);
return 0;
@ -284,8 +270,22 @@ int main(int argc, char *argv[])
SDL_FreeSurface(iconImg);
}
ALCdevice *alcDev = alcOpenDevice(0);
if (!alcDev)
{
showInitError("Error opening OpenAL device");
SDL_DestroyWindow(win);
TTF_Quit();
IMG_Quit();
SDL_Quit();
return 0;
}
EventThread eventThread;
RGSSThreadData rtData(&eventThread, argv[0], win, conf);
RGSSThreadData rtData(&eventThread, argv[0], win,
alcDev, conf);
int winW, winH;
SDL_GetWindowSize(win, &winW, &winH);
@ -338,6 +338,7 @@ int main(int argc, char *argv[])
Debug() << "Shutting down.";
alcCloseDevice(alcDev);
SDL_DestroyWindow(win);
Sound_Quit();