X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fsystem.c;h=37ca4841276a290a2ccbc7f54c0bbefbc8ad1180;hb=228a5718ede5ee00512ed2e333b3cee47baa124c;hp=c600152f46636180f9964c4fa0f9798f6ff7ee79;hpb=b96c3dc500494652748c24f0aa48a8201ea202dd;p=rocksndiamonds.git diff --git a/src/system.c b/src/system.c index c600152f..37ca4841 100644 --- a/src/system.c +++ b/src/system.c @@ -14,18 +14,16 @@ #include "main.h" #include "misc.h" +#include "sound.h" -inline void InitEventFilter(EventFilter filter_function) -{ -#ifdef USE_SDL_LIBRARY - /* set event filter to filter out certain events */ - SDL_SetEventFilter(filter_function); -#endif -} + +/* ========================================================================= */ +/* video functions */ +/* ========================================================================= */ inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDLInitBufferedDisplay(backbuffer, window); #else X11InitBufferedDisplay(backbuffer, window); @@ -34,7 +32,7 @@ inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window) inline int GetDisplayDepth(void) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL return SDL_GetVideoSurface()->format->BitsPerPixel; #else return XDefaultDepth(display, screen); @@ -45,7 +43,7 @@ inline Bitmap CreateBitmap(int width, int height, int depth) { int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth); -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDL_Surface *surface_tmp, *surface_native; if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, @@ -71,7 +69,7 @@ inline Bitmap CreateBitmap(int width, int height, int depth) inline void FreeBitmap(Bitmap bitmap) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDL_FreeSurface(bitmap); #else XFreePixmap(display, bitmap); @@ -80,7 +78,7 @@ inline void FreeBitmap(Bitmap bitmap) inline void ClearRectangle(Bitmap bitmap, int x, int y, int width, int height) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDLFillRectangle(bitmap, x, y, width, height, 0x000000); #else XFillRectangle(display, bitmap, gc, x, y, width, height); @@ -92,7 +90,7 @@ inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap, int width, int height, int dst_x, int dst_y) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y); #else @@ -101,13 +99,13 @@ inline void BlitBitmap(Bitmap src_bitmap, Bitmap dst_bitmap, #endif } -#ifndef USE_SDL_LIBRARY +#ifndef TARGET_SDL static GC last_clip_gc = 0; /* needed for XCopyArea() through clip mask */ #endif inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap) { -#ifndef USE_SDL_LIBRARY +#ifndef TARGET_SDL XSetClipMask(display, clip_gc, clip_pixmap); last_clip_gc = clip_gc; #endif @@ -115,7 +113,7 @@ inline void SetClipMask(GC clip_gc, Pixmap clip_pixmap) inline void SetClipOrigin(GC clip_gc, int clip_x, int clip_y) { -#ifndef USE_SDL_LIBRARY +#ifndef TARGET_SDL XSetClipOrigin(display, clip_gc, clip_x, clip_y); last_clip_gc = clip_gc; #endif @@ -126,7 +124,7 @@ inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap, int width, int height, int dst_x, int dst_y) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y); #else @@ -138,7 +136,7 @@ inline void BlitBitmapMasked(Bitmap src_bitmap, Bitmap dst_bitmap, inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y, int to_x, int to_y) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, 0xffffff); #else XSetForeground(display, gc, WhitePixel(display, screen)); @@ -150,7 +148,7 @@ inline void DrawSimpleWhiteLine(Bitmap bitmap, int from_x, int from_y, /* execute all pending screen drawing operations */ inline void FlushDisplay(void) { -#ifndef USE_SDL_LIBRARY +#ifndef TARGET_SDL XFlush(display); #endif } @@ -158,14 +156,14 @@ inline void FlushDisplay(void) /* execute and wait for all pending screen drawing operations */ inline void SyncDisplay(void) { -#ifndef USE_SDL_LIBRARY +#ifndef TARGET_SDL XSync(display, FALSE); #endif } inline void KeyboardAutoRepeatOn(void) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY / 2, SDL_DEFAULT_REPEAT_INTERVAL / 2); SDL_EnableUNICODE(1); @@ -176,7 +174,7 @@ inline void KeyboardAutoRepeatOn(void) inline void KeyboardAutoRepeatOff(void) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableUNICODE(0); #else @@ -186,7 +184,7 @@ inline void KeyboardAutoRepeatOff(void) inline boolean PointerInWindow(DrawWindow window) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL return TRUE; #else DrawWindow root, child; @@ -201,9 +199,98 @@ inline boolean PointerInWindow(DrawWindow window) #endif } +inline boolean SetVideoMode(void) +{ +#ifdef TARGET_SDL + return SDLSetVideoMode(&backbuffer); +#else + boolean success = TRUE; + + if (setup.fullscreen && fullscreen_available) + { + Error(ERR_WARN, "fullscreen not available in X11 version"); + + /* display error message only once */ + fullscreen_available = FALSE; + + success = FALSE; + } + + return success; +#endif +} + +inline void ChangeVideoModeIfNeeded(void) +{ +#ifdef TARGET_SDL + if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) || + (!setup.fullscreen && fullscreen_enabled)) + SetVideoMode(); +#endif +} + + +/* ========================================================================= */ +/* audio functions */ +/* ========================================================================= */ + +inline boolean OpenAudio(struct AudioSystemInfo *audio) +{ + audio->sound_available = FALSE; + audio->loops_available = FALSE; + audio->soundserver_pipe[0] = audio->soundserver_pipe[1] = 0; + audio->soundserver_pid = 0; + audio->device_fd = 0; + +#if defined(TARGET_SDL) + if (SDLOpenAudio()) + { + audio->sound_available = TRUE; + audio->loops_available = TRUE; + } +#elif defined(PLATFORM_MSDOS) + if (MSDOSOpenAudio()) + { + audio->sound_available = TRUE; + audio->loops_available = TRUE; + } +#elif defined(PLATFORM_UNIX) + UnixOpenAudio(audio); +#endif + + return audio->sound_available; +} + +inline void CloseAudio(struct AudioSystemInfo *audio) +{ +#if defined(TARGET_SDL) + SDLCloseAudio(); +#elif defined(PLATFORM_MSDOS) + MSDOSCloseAudio(); +#elif defined(PLATFORM_UNIX) + UnixCloseAudio(audio); +#endif + + audio->sound_available = FALSE; + audio->loops_available = FALSE; +} + + +/* ========================================================================= */ +/* event functions */ +/* ========================================================================= */ + +inline void InitEventFilter(EventFilter filter_function) +{ +#ifdef TARGET_SDL + /* set event filter to filter out certain events */ + SDL_SetEventFilter(filter_function); +#endif +} + inline boolean PendingEvent(void) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL return (SDL_PollEvent(NULL) ? TRUE : FALSE); #else return (XPending(display) ? TRUE : FALSE); @@ -212,7 +299,7 @@ inline boolean PendingEvent(void) inline void NextEvent(Event *event) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL SDL_WaitEvent(event); #else XNextEvent(display, event); @@ -221,7 +308,7 @@ inline void NextEvent(Event *event) inline Key GetEventKey(KeyEvent *event, boolean with_modifiers) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL #if 0 printf("unicode == '%d', sym == '%d', mod == '0x%04x'\n", (int)event->keysym.unicode, @@ -247,39 +334,26 @@ inline Key GetEventKey(KeyEvent *event, boolean with_modifiers) #endif } -inline boolean SetVideoMode(void) +inline boolean CheckCloseWindowEvent(ClientMessageEvent *event) { -#ifdef USE_SDL_LIBRARY - return SDLSetVideoMode(&backbuffer); -#else - boolean success = TRUE; - - if (setup.fullscreen && fullscreen_available) - { - Error(ERR_WARN, "fullscreen not available in X11 version"); - - /* display error message only once */ - fullscreen_available = FALSE; - - success = FALSE; - } - - return success; + if (event->type != EVENT_CLIENTMESSAGE) + return FALSE; + +#if defined(TARGET_SDL) + return TRUE; /* the only possible message here is SDL_QUIT */ +#elif defined(PLATFORM_UNIX) + if ((event->window == window) && + (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) + return TRUE; #endif -} -inline void ChangeVideoModeIfNeeded(void) -{ -#ifdef USE_SDL_LIBRARY - if ((setup.fullscreen && !fullscreen_enabled && fullscreen_available) || - (!setup.fullscreen && fullscreen_enabled)) - SetVideoMode(); -#endif + return FALSE; } + inline void dummy(void) { -#ifdef USE_SDL_LIBRARY +#ifdef TARGET_SDL #else #endif }