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

Commit d3d10271 authored by deuce's avatar deuce

Completely disentangle xpdev/xpbeep.c from conio/sdlfuncs.c

SDL audio should work from any thread, and on the platforms that care,
SDL video is coddled appropriately.
The only question is around SDL_Quit() in an audio-only build, but we
can punt on that since the default builds will never do that... the only
thing I'm aware of that could be broken that way is tone, which nobody
likes anyway.
parent 7ada8709
......@@ -168,10 +168,8 @@ UIFC_SRC = $(SRC_ROOT)$(DIRSEP)uifc
# SDL ciolib enabled by default for the moment.
!ifndef WITHOUT_SDL
!ifndef USE_SDL_AUDIO
USE_SDL = 1
!endif
!endif
# Pull in lib-specific flags
!include $(XPDEV_SRC)$(DIRSEP)Common.make
......
......@@ -157,9 +157,7 @@ endif
ifdef NO_X
ifndef WITH_SDL
ifndef WITH_SDL_AUDIO
CIOLIB-MT_CFLAGS += -DNO_FONTS
CIOLIB_CFLAGS += -DNO_FONTS
endif
CIOLIB-MT_CFLAGS += -DNO_FONTS
CIOLIB_CFLAGS += -DNO_FONTS
endif
endif
......@@ -19,16 +19,10 @@ else
NEED_BITMAP := 1
endif
ifdef WITH_SDL_AUDIO
ifdef WITH_SDL
NEED_BITMAP := 1
OBJS += $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)sdlfuncs$(OFILE)
NEED_BITMAP := 1
else
ifdef WITH_SDL
NEED_BITMAP := 1
OBJS += $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)sdlfuncs$(OFILE)
endif
endif
ifeq ($(os),netbsd)
......
......@@ -20,16 +20,12 @@ SRC_ROOT = ..
# Cross platform/compiler definitions
!include ..\build\Common.bmake # defines clean and output directory rules
!ifdef USE_SDL_AUDIO
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
!else
!ifdef USE_SDL
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)sdl_con$(OFILE)
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)SDL_win32_main$(OFILE)
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)sdlfuncs$(OFILE)
NEED_BITMAP = 1
!endif
!endif
!ifdef NEED_BITMAP
OBJS = $(OBJS) $(MTOBJODIR)$(DIRSEP)bitmap_con$(OFILE)
......
......@@ -50,7 +50,7 @@
#define CIOLIB_NO_MACROS
#include "ciolib.h"
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
#include "sdl_con.h"
#include "sdlfuncs.h"
#endif
......@@ -141,13 +141,13 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_setwinsize(int width, int height);
CIOLIBEXPORT void CIOLIBCALL ciolib_setwinposition(int x, int y);
CIOLIBEXPORT enum ciolib_codepage CIOLIBCALL ciolib_getcodepage(void);
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
int sdl_video_initialized = 0;
#endif
#define CIOLIB_INIT() { if(initialized != 1) initciolib(CIOLIB_MODE_AUTO); }
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
static int try_sdl_init(int mode)
{
if(!sdl_initciolib(mode)) {
......@@ -201,10 +201,9 @@ static int try_sdl_init(int mode)
#ifndef NO_X
static int try_x_init(int mode)
{
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
if (sdl_video_initialized) {
sdl.QuitSubSystem(SDL_INIT_VIDEO);
sdl_video_initialized = FALSE;
}
#endif
......@@ -256,10 +255,9 @@ static int try_x_init(int mode)
static int try_curses_init(int mode)
{
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
if (sdl_video_initialized) {
sdl.QuitSubSystem(SDL_INIT_VIDEO);
sdl_video_initialized = FALSE;
}
#endif
......@@ -293,10 +291,9 @@ static int try_curses_init(int mode)
static int try_ansi_init(int mode)
{
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
if (sdl_video_initialized) {
sdl.QuitSubSystem(SDL_INIT_VIDEO);
sdl_video_initialized = FALSE;
}
#endif
......@@ -324,10 +321,9 @@ static int try_ansi_init(int mode)
#endif
static int try_conio_init(int mode)
{
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
if (sdl_video_initialized) {
sdl.QuitSubSystem(SDL_INIT_VIDEO);
sdl_video_initialized = FALSE;
}
#endif
......@@ -389,7 +385,7 @@ CIOLIBEXPORT int CIOLIBCALL initciolib(int mode)
switch(mode) {
case CIOLIB_MODE_AUTO:
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
if(!try_sdl_init(CIOLIB_MODE_SDL))
#endif
#ifdef _WIN32
......@@ -424,7 +420,7 @@ CIOLIBEXPORT int CIOLIBCALL initciolib(int mode)
try_ansi_init(mode);
break;
#if defined(WITH_SDL) || defined(WITH_SDL_AUDIO)
#if defined(WITH_SDL)
case CIOLIB_MODE_SDL:
case CIOLIB_MODE_SDL_FULLSCREEN:
try_sdl_init(mode);
......
......@@ -19,8 +19,6 @@ struct sdlfuncs sdl;
#include "ciolib.h"
static int sdl_funcs_loaded=0;
static int sdl_initialized=0;
static int sdl_audio_initialized=0;
static void QuitWrap(void);
......@@ -109,30 +107,6 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->OpenAudio=xp_dlsym(sdl_dll, SDL_OpenAudio))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->CloseAudio=xp_dlsym(sdl_dll, SDL_CloseAudio))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->PauseAudio=xp_dlsym(sdl_dll, SDL_PauseAudio))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->LockAudio=xp_dlsym(sdl_dll, SDL_LockAudio))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->UnlockAudio=xp_dlsym(sdl_dll, SDL_UnlockAudio))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->GetAudioStatus=xp_dlsym(sdl_dll, SDL_GetAudioStatus))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
}
if((sdlf->CreateTexture=xp_dlsym(sdl_dll, SDL_CreateTexture))==NULL) {
xp_dlclose(sdl_dll);
return(-1);
......@@ -226,10 +200,6 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
int init_sdl_video(void)
{
char *drivername;
int use_sdl_video=FALSE;
#ifdef _WIN32
char *driver_env=NULL;
#endif
if(sdl_video_initialized)
return(0);
......@@ -239,19 +209,12 @@ int init_sdl_video(void)
if (!sdl.gotfuncs)
return -1;
use_sdl_video=TRUE;
sdl.SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2" );
sdl.SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1" );
#ifdef _WIN32
/* Fail to windib (ie: No mouse attached) */
if(sdl.Init(SDL_INIT_VIDEO)) {
if(sdl.Init(0)==0)
sdl_initialized=TRUE;
}
else {
if(sdl.Init(SDL_INIT_VIDEO) == 0) {
sdl_video_initialized=TRUE;
sdl_initialized=TRUE;
}
#else
/*
......@@ -262,32 +225,18 @@ int init_sdl_video(void)
* This ugly hack attempts to prevent this... of course, remote X11
* connections must still be allowed.
*/
if((!use_sdl_video) || ((getenv("REMOTEHOST")!=NULL || getenv("SSH_CLIENT")!=NULL) && getenv("DISPLAY")==NULL)) {
/* Sure ,we can't use video, but audio is still valid! */
if(sdl.Init(0)==0)
sdl_initialized=TRUE;
}
else {
if(getenv("DISPLAY") != NULL || (getenv("REMOTEHOST") == NULL && getenv("SSH_CLIENT") == NULL)) {
if(sdl.Init(SDL_INIT_VIDEO)==0) {
sdl_initialized=TRUE;
sdl_video_initialized=TRUE;
}
else {
/* Sure ,we can't use video, but audio is still valid! */
if(sdl.Init(0)==0)
sdl_initialized=TRUE;
}
}
#endif
if(sdl_video_initialized && (drivername = sdl.GetCurrentVideoDriver())!=NULL) {
/* Unacceptable drivers */
if((!strcmp(drivername, "caca")) || (!strcmp(drivername,"aalib")) || (!strcmp(drivername,"dummy"))) {
sdl.QuitSubSystem(SDL_INIT_VIDEO);
sdl.Quit();
sdl_video_initialized=FALSE;
}
else {
sdl_video_initialized=TRUE;
}
}
if(sdl_video_initialized) {
......@@ -298,22 +247,9 @@ int init_sdl_video(void)
return(-1);
}
int init_sdl_audio(void)
{
if(!sdl_initialized)
return(-1);
if(sdl_audio_initialized)
return(0);
if(sdl.InitSubSystem(SDL_INIT_AUDIO)==0) {
sdl_audio_initialized=TRUE;
return(0);
}
return(-1);
}
static void QuitWrap(void)
{
if (sdl_initialized) {
if (sdl_video_initialized) {
#if !defined(__DARWIN__)
exit_sdl_con();
#endif
......
......@@ -32,12 +32,6 @@ struct sdlfuncs {
const char *(HACK_HACK_HACK *GetError) (void);
int (HACK_HACK_HACK *InitSubSystem)(Uint32 flags);
void (HACK_HACK_HACK *QuitSubSystem)(Uint32 flags);
int (HACK_HACK_HACK *OpenAudio)(SDL_AudioSpec *desired, SDL_AudioSpec *obtained);
void (HACK_HACK_HACK *CloseAudio)(void);
void (HACK_HACK_HACK *LockAudio)(void);
void (HACK_HACK_HACK *UnlockAudio)(void);
void (HACK_HACK_HACK *PauseAudio)(int pause_on);
SDL_AudioStatus (HACK_HACK_HACK *GetAudioStatus)(void);
SDL_Texture* (HACK_HACK_HACK *CreateTexture) (SDL_Renderer *renderer, Uint32 format, int access, int w, int h);
int (HACK_HACK_HACK *UpdateTexture) (SDL_Texture *texture, const SDL_Rect * rect, const void *pixels, int pitch);
int (HACK_HACK_HACK *RenderClear) (SDL_Renderer *renderer);
......
......@@ -39,7 +39,7 @@ Refer to src/build/Common.gmake or src/build/Common.bmake for details of some
of the make options the build system supports.
Release builds for Mac OS X use the following command line:
make USE_SDL_AUDIO=1 STATIC_SDL=1 RELEASE=1 PREFIX=/usr
make RELEASE=1 USE_SDL_AUDIO=1 PREFIX=/usr
The package is generated and copied do a disk image which is then converted
with the following command:
......
......@@ -2,19 +2,11 @@
#include <stdio.h> /* NULL */
#include <SDL.h>
#ifndef main
#define USE_REAL_MAIN
#endif
#include "gen_defs.h"
#include "threadwrap.h"
#ifdef USE_REAL_MAIN
#undef main
#endif
#include "sdlfuncs.h"
#ifndef _WIN32
struct sdlfuncs sdl;
#endif
struct sdlfuncs xpbeep_sdl;
/* Make xp_dl do static linking */
#ifdef STATIC_SDL
......@@ -26,7 +18,7 @@ static int sdl_funcs_loaded=0;
static int sdl_initialized=0;
static int sdl_audio_initialized=0;
int load_sdl_funcs(struct sdlfuncs *sdlf)
int xpbeep_load_sdl_funcs(struct sdlfuncs *sdlf)
{
dll_handle sdl_dll;
const char *libnames[]={"SDL", "SDL-1.2", "SDL-1.1", NULL};
......@@ -100,18 +92,18 @@ int load_sdl_funcs(struct sdlfuncs *sdlf)
int init_sdl_audio(void)
{
if (!sdl_funcs_loaded) {
if (load_sdl_funcs(&sdl) != 0)
if (xpbeep_load_sdl_funcs(&xpbeep_sdl) != 0)
return -1;
}
if(!sdl_initialized) {
if(sdl.Init(0)==0)
if(xpbeep_sdl.Init(0)==0)
sdl_initialized=TRUE;
else
return(-1);
}
if(sdl_audio_initialized)
return(0);
if(sdl.InitSubSystem(SDL_INIT_AUDIO)==0) {
if(xpbeep_sdl.InitSubSystem(SDL_INIT_AUDIO)==0) {
sdl_audio_initialized=TRUE;
return(0);
}
......
......@@ -23,8 +23,7 @@ struct sdlfuncs {
int gotfuncs;
};
/* Defined in SDL_win32_main.c for Win32 */
extern struct sdlfuncs sdl;
extern struct sdlfuncs xpbeep_sdl;
extern SDL_sem *sdl_exit_sem;
#ifdef __cplusplus
......
......@@ -335,7 +335,7 @@ void DLLCALL sdl_fillbuf(void *userdata, Uint8 *stream, int len)
sdl_audio_buf_pos+=copylen;
/* If we're done, post the semaphore */
if(sdl_audio_buf_pos>=sdl_audio_buf_len) {
sdl.SemPost(sdlToneDone);
xpbeep_sdl.SemPost(sdlToneDone);
sdl_audio_buf_len=0;
sdl_audio_buf_pos=0;
free((void *)swave);
......@@ -447,14 +447,14 @@ DLLCALL xptone_open_locked(void)
spec.size=256;
spec.callback=sdl_fillbuf;
spec.userdata=NULL;
if(sdl.OpenAudio(&spec, NULL)==-1) {
if(xpbeep_sdl.OpenAudio(&spec, NULL)==-1) {
sdl_device_open_failed=TRUE;
}
else {
sdlToneDone=sdl.SDL_CreateSemaphore(0);
sdlToneDone=xpbeep_sdl.SDL_CreateSemaphore(0);
sdl_audio_buf_len=0;
sdl_audio_buf_pos=0;
sdl.PauseAudio(FALSE);
xpbeep_sdl.PauseAudio(FALSE);
handle_type=SOUND_DEVICE_SDL;
handle_rc++;
return(TRUE);
......@@ -611,7 +611,7 @@ xptone_complete_locked(void)
#ifdef WITH_SDL_AUDIO
else if(handle_type==SOUND_DEVICE_SDL) {
while(sdl.GetAudioStatus()==SDL_AUDIO_PLAYING)
while(xpbeep_sdl.GetAudioStatus()==SDL_AUDIO_PLAYING)
SLEEP(1);
}
#endif
......@@ -676,8 +676,8 @@ BOOL DLLCALL xptone_close_locked(void)
#ifdef WITH_SDL_AUDIO
if(handle_type==SOUND_DEVICE_SDL) {
sdl.CloseAudio();
sdl.SDL_DestroySemaphore(sdlToneDone);
xpbeep_sdl.CloseAudio();
xpbeep_sdl.SDL_DestroySemaphore(sdlToneDone);
}
#endif
......@@ -786,14 +786,14 @@ do_xp_play_sample(const unsigned char *sampo, size_t sz, int *freed)
#ifdef WITH_SDL_AUDIO
if(handle_type==SOUND_DEVICE_SDL) {
sdl.LockAudio();
xpbeep_sdl.LockAudio();
swave=samp;
sdl_audio_buf_pos=0;
sdl_audio_buf_len=sz;
sdl.UnlockAudio();
sdl.PauseAudio(FALSE);
sdl.SemWait(sdlToneDone);
sdl.PauseAudio(TRUE);
xpbeep_sdl.UnlockAudio();
xpbeep_sdl.PauseAudio(FALSE);
xpbeep_sdl.SemWait(sdlToneDone);
xpbeep_sdl.PauseAudio(TRUE);
return TRUE;
}
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment