endif
USE_SDL = true
-USE_SDL_OLD_LIBS = true
+USE_SDL_OLD_LIBS = false
ifeq ($(USE_SDL_OLD_LIBS),true)
-SDL_EXTRA_LIBS = -lIMG
+SDL_EXTRA_LIBS = -lIMG -lmixer
else
-SDL_EXTRA_LIBS = -lSDL_image
+SDL_EXTRA_LIBS = -lSDL_image -lSDL_mixer
endif
SDL_CFLAGS := -DUSE_SDL_LIBRARY $(shell sdl-config --cflags)
#define KEY_RELEASED FALSE
#define KEY_PRESSED TRUE
+
+/* event filter especially needed for SDL event filtering due to
+ delay problems with lots of mouse motion events when mouse
+ button not pressed */
+
+int EventFilter(const Event *event)
+{
+ if (event->type != EVENT_MOTIONNOTIFY)
+ return 1;
+
+ /* get mouse motion events without pressed button only in level editor */
+ if (button_status == MB_RELEASED && game_status != LEVELED)
+ return 0;
+ else
+ return 1;
+}
+
void EventLoop(void)
{
while(1)
NextEvent(&event);
- switch(event.type)
+ if (EventFilter(&event))
{
- case EVENT_BUTTONPRESS:
- case EVENT_BUTTONRELEASE:
- HandleButtonEvent((ButtonEvent *) &event);
- break;
-
- case EVENT_MOTIONNOTIFY:
- HandleMotionEvent((MotionEvent *) &event);
- break;
-
- case EVENT_KEYPRESS:
- case EVENT_KEYRELEASE:
- HandleKeyEvent((KeyEvent *) &event);
- break;
-
- default:
- HandleOtherEvents(&event);
- break;
+ switch(event.type)
+ {
+ case EVENT_BUTTONPRESS:
+ case EVENT_BUTTONRELEASE:
+ HandleButtonEvent((ButtonEvent *) &event);
+ break;
+
+ case EVENT_MOTIONNOTIFY:
+ HandleMotionEvent((MotionEvent *) &event);
+ break;
+
+ case EVENT_KEYPRESS:
+ case EVENT_KEYRELEASE:
+ HandleKeyEvent((KeyEvent *) &event);
+ break;
+
+ default:
+ HandleOtherEvents(&event);
+ break;
+ }
}
}
HandleClientMessageEvent((ClientMessageEvent *) event);
break;
+#ifdef USE_SDL_LIBRARY
+ case SDL_JOYAXISMOTION:
+ case SDL_JOYBUTTONDOWN:
+ case SDL_JOYBUTTONUP:
+ HandleJoystickEvent(event);
+ break;
+#endif
+
default:
break;
}
void HandleMotionEvent(MotionEvent *event)
{
- int win_x, win_y;
-
- if (!QueryPointer(window, &win_x, &win_y))
+ if (!PointerInWindow(window))
return; /* window and pointer are on different screens */
- if (!button_status && game_status != LEVELED)
+#if 0
+ if (button_status == MB_RELEASED && game_status != LEVELED)
return;
+#endif
motion_status = TRUE;
- HandleButton(win_x, win_y, button_status);
+ HandleButton(event->x, event->y, button_status);
}
void HandleKeyEvent(KeyEvent *event)
#include "main.h"
+int EventFilter(const Event *);
void EventLoop(void);
void HandleOtherEvents(Event *);
void ClearEventQueue(void);
#include <signal.h>
#include "init.h"
+#include "events.h"
#include "misc.h"
#include "sound.h"
#include "screens.h"
if (sound_status == SOUND_OFF)
return;
+#ifdef USE_SDL_LIBRARY
+ /* initialize SDL audio */
+
+ if (SDL_Init(SDL_INIT_AUDIO) < 0)
+ {
+ Error(ERR_WARN, "SDL_Init() failed: %s\n", SDL_GetError());
+ sound_status = SOUND_OFF;
+ return;
+ }
+
+ if (Mix_OpenAudio(22050, AUDIO_S16, 2, 256) < 0)
+ {
+ Error(ERR_WARN, "Mix_OpenAudio() failed: %s\n", SDL_GetError());
+ sound_status = SOUND_OFF;
+ return;
+ }
+
+ Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
+ Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
+
+ sound_status = SOUND_AVAILABLE;
+ sound_loops_allowed = TRUE;
+
+#else /* !USE_SDL_LIBRARY */
+
#ifndef MSDOS
if (access(sound_device_name, W_OK) != 0)
{
*/
#endif /* MSDOS */
+#endif /* !USE_SDL_LIBRARY */
for(i=0; i<NUM_SOUNDS; i++)
{
sprintf(sound_name[i], "%d", i + 1);
#endif
+#ifdef USE_SDL_LIBRARY
+ {
+ char *str = getStringCopy(sound_name[i]);
+ sprintf(str, "%d", i + 1);
+ Sound[i].name = str;
+ }
+#else
Sound[i].name = sound_name[i];
+#endif
if (!LoadSound(&Sound[i]))
{
sound_status = SOUND_OFF;
return;
}
}
+
+#if 0
+ sound_status = SOUND_OFF;
+#endif
+
}
void InitSoundServer()
if (sound_status == SOUND_OFF)
return;
+#ifdef USE_SDL_LIBRARY
+ return;
+#endif
+
#ifndef MSDOS
if (pipe(sound_pipe)<0)
void InitJoysticks()
{
+#ifdef USE_SDL_LIBRARY
+ static boolean sdl_joystick_subsystem_initialized = FALSE;
+#endif
+
int i;
if (global_joystick_status == JOYSTICK_OFF)
joystick_status = JOYSTICK_OFF;
+#ifdef USE_SDL_LIBRARY
+
+ if (!sdl_joystick_subsystem_initialized)
+ {
+ sdl_joystick_subsystem_initialized = TRUE;
+
+ if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
+ {
+ Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
+ return;
+ }
+ }
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ char *device_name = setup.input[i].joy.device_name;
+ int joystick_nr = getJoystickNrFromDeviceName(device_name);
+
+ if (joystick_nr >= SDL_NumJoysticks())
+ joystick_nr = -1;
+
+ /* misuse joystick file descriptor variable to store joystick number */
+ stored_player[i].joystick_fd = joystick_nr;
+
+ /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
+ if (Check_SDL_JoystickOpened(joystick_nr))
+ Close_SDL_Joystick(joystick_nr);
+
+ if (!setup.input[i].use_joystick)
+ continue;
+
+ if (!Open_SDL_Joystick(joystick_nr))
+ {
+ Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
+ continue;
+ }
+
+ joystick_status = JOYSTICK_AVAILABLE;
+ }
+
+#else /* !USE_SDL_LIBRARY */
+
#ifndef MSDOS
for (i=0; i<MAX_PLAYERS; i++)
{
stored_player[i].joystick_fd = joystick_nr;
}
#endif
+
+#endif /* !USE_SDL_LIBRARY */
}
void InitDisplay()
{
#ifdef USE_SDL_LIBRARY
- /* initialize SDL */
+ /* initialize SDL video */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
/* set window and icon title */
SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
+ /* set event filter to filter out certain mouse motion events */
+ SDL_SetEventFilter(EventFilter);
+
#else /* !USE_SDL_LIBRARY */
unsigned int border_width = 4;
#include "joystick.h"
#include "misc.h"
+#ifndef MSDOS
+static int JoystickPosition(int middle, int margin, int actual)
+{
+ long range, pos;
+ int percentage;
+
+ if (margin < middle && actual > middle)
+ return 0;
+ if (margin > middle && actual < middle)
+ return 0;
+
+ range = ABS(margin - middle);
+ pos = ABS(actual - middle);
+ percentage = (int)(pos * 100 / range);
+
+ if (percentage > 100)
+ percentage = 100;
+
+ return percentage;
+}
+#endif
+
+#ifdef USE_SDL_LIBRARY
+
+static SDL_Joystick *sdl_joystick[MAX_PLAYERS] = { NULL, NULL, NULL, NULL };
+static int sdl_js_axis[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
+static int sdl_js_button[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
+
+SDL_Joystick *Get_SDL_Joystick(int nr)
+{
+ return sdl_joystick[nr];
+}
+
+boolean Open_SDL_Joystick(int nr)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return FALSE;
+
+ return ((sdl_joystick[nr] = SDL_JoystickOpen(nr)) == NULL ? FALSE : TRUE);
+}
+
+void Close_SDL_Joystick(int nr)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return;
+
+ SDL_JoystickClose(sdl_joystick[nr]);
+}
+
+boolean Check_SDL_JoystickOpened(int nr)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return FALSE;
+
+ return (SDL_JoystickOpened(nr) ? TRUE : FALSE);
+}
+
+void HandleJoystickEvent(Event *event)
+{
+ switch(event->type)
+ {
+ case SDL_JOYAXISMOTION:
+ if (event->jaxis.axis < 2)
+ {
+ sdl_js_axis[event->jaxis.which][event->jaxis.axis]= event->jaxis.value;
+
+#if 0
+ printf("js_%d %s-axis: %d\n",
+ event->jaxis.which,
+ (event->jaxis.axis == 0 ? "x" : "y"),
+ event->jaxis.value);
+#endif
+ }
+ break;
+
+ case SDL_JOYBUTTONDOWN:
+ if (event->jbutton.button < 2)
+ {
+ sdl_js_button[event->jbutton.which][event->jbutton.button] = TRUE;
+
+#if 0
+ printf("js_%d button %d: pressed\n",
+ event->jbutton.which,
+ event->jbutton.button);
+#endif
+ }
+ break;
+
+ case SDL_JOYBUTTONUP:
+ if (event->jbutton.button < 2)
+ {
+ sdl_js_button[event->jbutton.which][event->jbutton.button] = FALSE;
+
+#if 0
+ printf("js_%d button %d: released\n",
+ event->jbutton.which,
+ event->jbutton.button);
+#endif
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+int Get_SDL_Joystick_Axis(int nr, int axis)
+{
+ if (nr < 0 || nr > MAX_PLAYERS)
+ return 0;
+
+ if (axis < 0 || axis > 1)
+ return 0;
+
+ return sdl_js_axis[nr][axis];
+}
+
+void CheckJoystickData()
+{
+}
+
+int Joystick(int player_nr)
+{
+ int joystick_nr = stored_player[player_nr].joystick_fd;
+ int js_x,js_y, js_b1,js_b2;
+ int left, right, up, down;
+ int result = 0;
+
+ if (joystick_status == JOYSTICK_OFF)
+ return 0;
+
+ if (game_status == SETUPINPUT)
+ return 0;
+
+ if (!setup.input[player_nr].use_joystick ||
+ !Check_SDL_JoystickOpened(joystick_nr))
+ return 0;
+
+ js_x = sdl_js_axis[joystick_nr][0];
+ js_y = sdl_js_axis[joystick_nr][1];
+
+ js_b1 = sdl_js_button[joystick_nr][0];
+ js_b2 = sdl_js_button[joystick_nr][1];
+
+
+
+#if 0
+ printf("JOYSTICK %d: js_x == %d, js_y == %d, js_b1 == %d, js_b2 == %d\n",
+ joystick_nr, js_x, js_y, js_b1, js_b2);
+#endif
+
+
+
+ left = JoystickPosition(setup.input[player_nr].joy.xmiddle,
+ setup.input[player_nr].joy.xleft, js_x);
+ right = JoystickPosition(setup.input[player_nr].joy.xmiddle,
+ setup.input[player_nr].joy.xright, js_x);
+ up = JoystickPosition(setup.input[player_nr].joy.ymiddle,
+ setup.input[player_nr].joy.yupper, js_y);
+ down = JoystickPosition(setup.input[player_nr].joy.ymiddle,
+ setup.input[player_nr].joy.ylower, js_y);
+
+ if (left > JOYSTICK_PERCENT)
+ result |= JOY_LEFT;
+ else if (right > JOYSTICK_PERCENT)
+ result |= JOY_RIGHT;
+ if (up > JOYSTICK_PERCENT)
+ result |= JOY_UP;
+ else if (down > JOYSTICK_PERCENT)
+ result |= JOY_DOWN;
+
+ if (js_b1)
+ result |= JOY_BUTTON_1;
+ if (js_b2)
+ result |= JOY_BUTTON_2;
+
+
+
+#if 0
+ printf("result == 0x%08x\n", result);
+#endif
+
+
+
+ return result;
+}
+
+#else /* !USE_SDL_LIBRARY */
+
void CheckJoystickData()
{
int i;
}
}
-#ifndef MSDOS
-static int JoystickPosition(int middle, int margin, int actual)
-{
- long range, pos;
- int percentage;
-
- if (margin < middle && actual > middle)
- return 0;
- if (margin > middle && actual < middle)
- return 0;
-
- range = ABS(margin - middle);
- pos = ABS(actual - middle);
- percentage = (int)(pos * 100 / range);
-
- if (percentage > 100)
- percentage = 100;
-
- return percentage;
-}
-#endif
-
#ifndef MSDOS
int Joystick(int player_nr)
{
}
#endif /* MSDOS */
+#endif /* !USE_SDL_LIBRARY */
+
int JoystickButton(int player_nr)
{
static int last_joy_button[MAX_PLAYERS] = { 0, 0, 0, 0 };
/* get these values from the program 'js' from the joystick package, */
/* set JOYSTICK_PERCENT to a threshold appropriate for your joystick */
+
+#ifdef USE_SDL_LIBRARY
+#define JOYSTICK_XLEFT -32767
+#define JOYSTICK_XMIDDLE 0
+#define JOYSTICK_XRIGHT 32767
+#define JOYSTICK_YUPPER -32767
+#define JOYSTICK_YMIDDLE 0
+#define JOYSTICK_YLOWER 32767
+#else
#define JOYSTICK_XLEFT 30
#define JOYSTICK_XMIDDLE 530
#define JOYSTICK_XRIGHT 1250
#define JOYSTICK_YUPPER 40
#define JOYSTICK_YMIDDLE 680
#define JOYSTICK_YLOWER 1440
+#endif
#define JOYSTICK_PERCENT 25
#endif
+#ifdef USE_SDL_LIBRARY
+SDL_Joystick *Get_SDL_Joystick(int);
+boolean Open_SDL_Joystick(int);
+void Close_SDL_Joystick(int);
+boolean Check_SDL_JoystickOpened(int);
+void HandleJoystickEvent(Event *);
+int Get_SDL_Joystick_Axis(int, int);
+#endif
+
void CheckJoystickData(void);
int Joystick(int);
int JoystickButton(int);
int AnyJoystickButton(void);
#endif
+
SDL_Quit();
}
+#define SCREEN_WIDTH 640
+#define SCREEN_HEIGHT 480
+
+void WatchJoysticks()
+{
+ SDL_Surface *screen;
+ const char *name;
+ int i, done;
+ SDL_Event event;
+ int x, y, draw;
+ SDL_Rect axis_area[2];
+ int joystick_nr = 0;
+ SDL_Joystick *joystick = Get_SDL_Joystick(joystick_nr);
+
+ /* Set a video mode to display joystick axis position */
+ screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 16, 0);
+ if ( screen == NULL ) {
+ fprintf(stderr, "Couldn't set video mode: %s\n",SDL_GetError());
+ return;
+ }
+
+ /* Print info about the joysticks we are watching */
+ for (i=0; i<2; i++)
+ {
+ joystick = Get_SDL_Joystick(i);
+
+ name = SDL_JoystickName(i);
+ printf("Watching joystick %d: (%s)\n", i,
+ name ? name : "Unknown Joystick");
+ printf("Joystick has %d axes, %d hats, %d balls, and %d buttons\n",
+ SDL_JoystickNumAxes(joystick),
+ SDL_JoystickNumHats(joystick),
+ SDL_JoystickNumBalls(joystick),
+ SDL_JoystickNumButtons(joystick));
+ }
+
+ /* Initialize drawing rectangles */
+ memset(axis_area, 0, (sizeof axis_area));
+ draw = 0;
+
+ /* Loop, getting joystick events! */
+ done = 0;
+ while ( ! done ) {
+ while ( SDL_PollEvent(&event) ) {
+ switch (event.type) {
+ case SDL_JOYAXISMOTION:
+ joystick_nr = event.jaxis.which;
+ printf("Joystick %d axis %d value: %d\n",
+ event.jaxis.which,
+ event.jaxis.axis,
+ event.jaxis.value);
+ break;
+ case SDL_JOYHATMOTION:
+ joystick_nr = event.jaxis.which;
+ printf("Joystick %d hat %d value:",
+ event.jhat.which,
+ event.jhat.hat);
+ if ( event.jhat.value == SDL_HAT_CENTERED )
+ printf(" centered");
+ if ( event.jhat.value & SDL_HAT_UP )
+ printf(" up");
+ if ( event.jhat.value & SDL_HAT_RIGHT )
+ printf(" right");
+ if ( event.jhat.value & SDL_HAT_DOWN )
+ printf(" down");
+ if ( event.jhat.value & SDL_HAT_LEFT )
+ printf(" left");
+ printf("\n");
+ break;
+ case SDL_JOYBALLMOTION:
+ joystick_nr = event.jaxis.which;
+ printf("Joystick %d ball %d delta: (%d,%d)\n",
+ event.jball.which,
+ event.jball.ball,
+ event.jball.xrel,
+ event.jball.yrel);
+ break;
+ case SDL_JOYBUTTONDOWN:
+ joystick_nr = event.jaxis.which;
+ printf("Joystick %d button %d down\n",
+ event.jbutton.which,
+ event.jbutton.button);
+ break;
+ case SDL_JOYBUTTONUP:
+ joystick_nr = event.jaxis.which;
+ printf("Joystick %d button %d up\n",
+ event.jbutton.which,
+ event.jbutton.button);
+ break;
+ case SDL_KEYDOWN:
+ if ( event.key.keysym.sym != SDLK_ESCAPE ) {
+ break;
+ }
+ /* Fall through to signal quit */
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+
+ joystick = Get_SDL_Joystick(joystick_nr);
+
+ /* Update visual joystick state */
+ for ( i=0; i<SDL_JoystickNumButtons(joystick); ++i ) {
+ SDL_Rect area;
+
+ area.x = i*34;
+ area.y = SCREEN_HEIGHT-34;
+ area.w = 32;
+ area.h = 32;
+ if (SDL_JoystickGetButton(joystick, i) == SDL_PRESSED) {
+ SDL_FillRect(screen, &area, 0xFFFF);
+ } else {
+ SDL_FillRect(screen, &area, 0x0000);
+ }
+ SDL_UpdateRects(screen, 1, &area);
+ }
+
+ /* Erase previous axes */
+ SDL_FillRect(screen, &axis_area[draw], 0x0000);
+
+ /* Draw the X/Y axis */
+ draw = !draw;
+ x = (((int)SDL_JoystickGetAxis(joystick, 0))+32768);
+ x *= SCREEN_WIDTH;
+ x /= 65535;
+ if ( x < 0 ) {
+ x = 0;
+ } else
+ if ( x > (SCREEN_WIDTH-16) ) {
+ x = SCREEN_WIDTH-16;
+ }
+ y = (((int)SDL_JoystickGetAxis(joystick, 1))+32768);
+ y *= SCREEN_HEIGHT;
+ y /= 65535;
+ if ( y < 0 ) {
+ y = 0;
+ } else
+ if ( y > (SCREEN_HEIGHT-16) ) {
+ y = SCREEN_HEIGHT-16;
+ }
+ axis_area[draw].x = (Sint16)x;
+ axis_area[draw].y = (Sint16)y;
+ axis_area[draw].w = 16;
+ axis_area[draw].h = 16;
+ SDL_FillRect(screen, &axis_area[draw], 0xFFFF);
+
+ SDL_UpdateRects(screen, 2, axis_area);
+ }
+}
+
+void TEST_SDL_JOYSTICK()
+{
+ const char *name;
+ int i;
+
+ /* Initialize SDL (Note: video is required to start event loop) */
+ if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 )
+ {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ exit(1);
+ }
+
+ /* Print information about the joysticks */
+ printf("There are %d joysticks attached\n", SDL_NumJoysticks());
+ for ( i=0; i<SDL_NumJoysticks(); ++i )
+ {
+ name = SDL_JoystickName(i);
+ printf("Joystick %d: %s\n",i,name ? name : "Unknown Joystick");
+ }
+
+ for (i=0; i<2; i++)
+ {
+ if (!Open_SDL_Joystick(i))
+ printf("Couldn't open joystick %d: %s\n", i, SDL_GetError());
+ }
+
+ WatchJoysticks();
+
+ for (i=0; i<2; i++)
+ Close_SDL_Joystick(i);
+
+ SDL_QuitSubSystem(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
+}
+
#endif /* USE_SDL_LIBRARY */
/* +-----------------------------------------------------------------------+ */
_fmode = O_BINARY;
#endif
+#if 1
GetOptions(argv);
OpenAll(argc,argv);
+#endif
#if 0
#ifdef USE_SDL_LIBRARY
+ /*
TEST_SDL_BLIT_RECT((WIN_XSIZE - TILEX)/2, (WIN_YSIZE - TILEY)/2);
TEST_SDL_EVENT_LOOP();
+ */
+ TEST_SDL_JOYSTICK();
exit(0);
#endif
#endif
}
#ifndef MSDOS
+
+#ifdef USE_SDL_LIBRARY
+ joy_ctrl.x = Get_SDL_Joystick_Axis(joystick_fd, 0);
+ joy_ctrl.y = Get_SDL_Joystick_Axis(joystick_fd, 1);
+#else
if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
{
joystick_status = JOYSTICK_OFF;
goto error_out;
}
+#endif
new_joystick_xleft = MIN(new_joystick_xleft, joy_ctrl.x);
new_joystick_xright = MAX(new_joystick_xright, joy_ctrl.x);
StopAnimation();
DrawSetupInputScreen();
- while(Joystick(player_nr) & JOY_BUTTON);
+
+ /* wait until the last pressed button was released */
+ while(Joystick(player_nr) & JOY_BUTTON)
+ {
+ if (PendingEvent()) /* got event */
+ {
+ Event event;
+
+ NextEvent(&event);
+ HandleOtherEvents(&event);
+ }
+ }
return;
error_out:
#if SDL_MAJOR_VERSION >= 1 && SDL_MINOR_VERSION >= 1
#include "SDL_image.h"
+#include "SDL_mixer.h"
#else
#include "IMG.h"
+#include "mixer.h"
#endif
/* SDL type definitions */
{
char filename[256];
char *sound_ext = "wav";
+#ifndef USE_SDL_LIBRARY
#ifndef MSDOS
byte sound_header_buffer[WAV_HEADER_SIZE];
char chunk[CHUNK_ID_LEN + 1];
int chunk_length, dummy;
FILE *file;
int i;
+#endif
#endif
sprintf(filename, "%s/%s/%s.%s",
options.ro_base_directory, SOUNDS_DIRECTORY,
snd_info->name, sound_ext);
+#ifdef USE_SDL_LIBRARY
+
+ snd_info->mix_chunk = Mix_LoadWAV(filename);
+ if (snd_info->mix_chunk == NULL)
+ {
+ Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename);
+ return FALSE;
+ }
+
+#else /* !USE_SDL_LIBRARY */
+
#ifndef MSDOS
if ((file = fopen(filename, "r")) == NULL)
if (!snd_info->sample_ptr)
{
Error(ERR_WARN, "cannot read sound file '%s' - no sounds", filename);
- return(FALSE);
+ return FALSE;
}
#endif /* MSDOS */
+#endif /* !USE_SDL_LIBRARY */
- return(TRUE);
+ return TRUE;
}
void PlaySound(int nr)
{
struct SoundControl snd_ctrl = emptySoundControl;
+#ifdef USE_SDL_LIBRARY
+ Mix_PlayChannel(-1, Sound[nr].mix_chunk, 0);
+
+ /*
+ Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
+ Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
+ */
+
+ return;
+#endif
+
if (sound_status==SOUND_OFF || !setup.sound)
return;
{
struct SoundControl snd_ctrl = emptySoundControl;
+#ifdef USE_SDL_LIBRARY
+ Mix_HaltMusic();
+ return;
+#endif
+
if (sound_status==SOUND_OFF)
return;
char *name;
byte *data_ptr;
long data_len;
+
#ifdef MSDOS
SAMPLE *sample_ptr;
#endif
+
+#ifdef USE_SDL_LIBRARY
+ Mix_Chunk *mix_chunk;
+#endif
};
struct SoundControl
#endif
}
-inline boolean QueryPointer(DrawWindow window, int *win_x, int *win_y)
+inline boolean PointerInWindow(DrawWindow window)
{
#ifdef USE_SDL_LIBRARY
- SDL_GetMouseState(win_x, win_y);
return TRUE;
#else
DrawWindow root, child;
int root_x, root_y;
unsigned int mask;
+ int win_x, win_y;
/* if XQueryPointer() returns False, the pointer
is not on the same screen as the specified window */
return XQueryPointer(display, window, &root, &child, &root_x, &root_y,
- win_x, win_y, &mask);
+ &win_x, &win_y, &mask);
#endif
}
inline void SyncDisplay();
inline void KeyboardAutoRepeatOn();
inline void KeyboardAutoRepeatOff();
-inline boolean QueryPointer(DrawWindow, int *, int *);
+inline boolean PointerInWindow(DrawWindow);
inline boolean PendingEvent();
inline void NextEvent(Event *event);
{
if (event.type == EVENT_MOTIONNOTIFY)
{
- int win_x, win_y;
-
- if (!QueryPointer(window, &win_x, &win_y))
+ if (!PointerInWindow(window))
continue; /* window and pointer are on different screens */
if (!button_status)