Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

sdlfuncs.c 2.54 KB
Newer Older
1
#include <stdlib.h>	/* getenv()/exit()/atexit() */
2 3
#include <stdio.h>	/* NULL */

4
#include <SDL.h>
5
#include "gen_defs.h"
deuce's avatar
deuce committed
6
#include "threadwrap.h"
7 8
#include "sdlfuncs.h"

9
struct sdlfuncs xpbeep_sdl;
10

11 12 13 14
/* Make xp_dl do static linking */
#ifdef STATIC_SDL
#define STATIC_LINK
#endif
deuce's avatar
deuce committed
15
#include "xp_dl.h"
16

17 18 19
static int sdl_funcs_loaded=0;
static int sdl_initialized=0;
static int sdl_audio_initialized=0;
20

21
int xpbeep_load_sdl_funcs(struct sdlfuncs *sdlf)
22
{
23 24
	dll_handle	sdl_dll;
	const char *libnames[]={"SDL", "SDL-1.2", "SDL-1.1", NULL};
25

deuce's avatar
deuce committed
26
	putenv("SDL_VIDEO_ALLOW_SCREENSAVER=1");
27
	sdlf->gotfuncs=0;
28
	if((sdl_dll=xp_dlopen(libnames,RTLD_LAZY|RTLD_GLOBAL,SDL_PATCHLEVEL))==NULL)
29
		return(-1);
30 31 32

	if((sdlf->Init=xp_dlsym(sdl_dll, SDL_Init))==NULL) {
		xp_dlclose(sdl_dll);
33 34
		return(-1);
	}
35 36
	if((sdlf->Quit=xp_dlsym(sdl_dll, SDL_Quit))==NULL) {
		xp_dlclose(sdl_dll);
37 38
		return(-1);
	}
39 40
	if((sdlf->SemWait=xp_dlsym(sdl_dll, SDL_SemWait))==NULL) {
		xp_dlclose(sdl_dll);
41 42
		return(-1);
	}
43 44
	if((sdlf->SemPost=xp_dlsym(sdl_dll, SDL_SemPost))==NULL) {
		xp_dlclose(sdl_dll);
45 46
		return(-1);
	}
47 48
	if((sdlf->SDL_CreateSemaphore=xp_dlsym(sdl_dll, SDL_CreateSemaphore))==NULL) {
		xp_dlclose(sdl_dll);
49 50
		return(-1);
	}
51 52
	if((sdlf->SDL_DestroySemaphore=xp_dlsym(sdl_dll, SDL_DestroySemaphore))==NULL) {
		xp_dlclose(sdl_dll);
53 54
		return(-1);
	}
55 56
	if((sdlf->InitSubSystem=xp_dlsym(sdl_dll, SDL_InitSubSystem))==NULL) {
		xp_dlclose(sdl_dll);
57 58
		return(-1);
	}
59 60
	if((sdlf->QuitSubSystem=xp_dlsym(sdl_dll, SDL_QuitSubSystem))==NULL) {
		xp_dlclose(sdl_dll);
61 62
		return(-1);
	}
63 64
	if((sdlf->OpenAudio=xp_dlsym(sdl_dll, SDL_OpenAudio))==NULL) {
		xp_dlclose(sdl_dll);
65 66
		return(-1);
	}
67 68
	if((sdlf->CloseAudio=xp_dlsym(sdl_dll, SDL_CloseAudio))==NULL) {
		xp_dlclose(sdl_dll);
69 70
		return(-1);
	}
71 72
	if((sdlf->PauseAudio=xp_dlsym(sdl_dll, SDL_PauseAudio))==NULL) {
		xp_dlclose(sdl_dll);
73 74
		return(-1);
	}
75 76
	if((sdlf->LockAudio=xp_dlsym(sdl_dll, SDL_LockAudio))==NULL) {
		xp_dlclose(sdl_dll);
77 78
		return(-1);
	}
79 80
	if((sdlf->UnlockAudio=xp_dlsym(sdl_dll, SDL_UnlockAudio))==NULL) {
		xp_dlclose(sdl_dll);
81 82
		return(-1);
	}
83 84
	if((sdlf->GetAudioStatus=xp_dlsym(sdl_dll, SDL_GetAudioStatus))==NULL) {
		xp_dlclose(sdl_dll);
deuce's avatar
deuce committed
85 86
		return(-1);
	}
87 88 89 90 91 92 93
	sdlf->gotfuncs=1;
	sdl_funcs_loaded=1;
	return(0);
}

int init_sdl_audio(void)
{
94
	if (!sdl_funcs_loaded) {
95
		if (xpbeep_load_sdl_funcs(&xpbeep_sdl) != 0)
96 97 98
			return -1;
	}
	if(!sdl_initialized) {
99
		if(xpbeep_sdl.Init(0)==0)
100 101 102 103
			sdl_initialized=TRUE;
		else
			return(-1);
	}
104 105
	if(sdl_audio_initialized)
		return(0);
106
	if(xpbeep_sdl.InitSubSystem(SDL_INIT_AUDIO)==0) {
107 108 109 110 111
		sdl_audio_initialized=TRUE;
		return(0);
	}
	return(-1);
}