static void InitNetworkServer(void);
static void InitSound(void);
static void InitSoundServer(void);
+static void InitDisplay(void);
static void InitGfx(void);
static void InitGfxBackground(void);
static void LoadGfx(int, struct PictureFileInfo *);
signal(SIGINT, CloseAllAndExit);
signal(SIGTERM, CloseAllAndExit);
- InitBufferedDisplay(&backbuffer, &window);
+ InitDisplay();
InitEventFilter(FilterMouseMotionEvents);
InitGfx();
#endif /* !TARGET_SDL */
}
+void InitDisplay()
+{
+ char *x11_icon_filename = getPath3(options.ro_base_directory,
+ GRAPHICS_DIRECTORY,
+ "rocks_icon.xbm");
+ char *x11_iconmask_filename = getPath3(options.ro_base_directory,
+ GRAPHICS_DIRECTORY,
+ "rocks_iconmask.xbm");
+
+ InitProgramInfo(program_name, PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
+ ICON_TITLE_STRING, x11_icon_filename, x11_iconmask_filename);
+ InitVideoDisplay();
+ InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
+ setup.fullscreen);
+}
+
void InitGfx()
{
int i, j;
{
int x, y;
- drawto = backbuffer = pix[PIX_DB_BACK];
+ drawto = backbuffer;
fieldbuffer = pix[PIX_DB_FIELD];
SetDrawtoField(DRAW_BACKBUFFER);
#include "joystick.h"
+#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
+#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
+
+void translate_joyname(int *joysymbol, char **name, int mode)
+{
+ static struct
+ {
+ int joysymbol;
+ char *name;
+ } translate_joy[] =
+ {
+ { JOY_LEFT, "joystick_left" },
+ { JOY_RIGHT, "joystick_right" },
+ { JOY_UP, "joystick_up" },
+ { JOY_DOWN, "joystick_down" },
+ { JOY_BUTTON_1, "joystick_button_1" },
+ { JOY_BUTTON_2, "joystick_button_2" },
+ };
+
+ int i;
+
+ if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME)
+ {
+ *name = "[undefined]";
+
+ for (i=0; i<6; i++)
+ {
+ if (*joysymbol == translate_joy[i].joysymbol)
+ {
+ *name = translate_joy[i].name;
+ break;
+ }
+ }
+ }
+ else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL)
+ {
+ *joysymbol = 0;
+
+ for (i=0; i<6; i++)
+ {
+ if (strcmp(*name, translate_joy[i].name) == 0)
+ {
+ *joysymbol = translate_joy[i].joysymbol;
+ break;
+ }
+ }
+ }
+}
+
+char *getJoyNameFromJoySymbol(int joysymbol)
+{
+ char *name;
+
+ translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME);
+ return name;
+}
+
+int getJoySymbolFromJoyName(char *name)
+{
+ int joysymbol;
+
+ translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
+ return joysymbol;
+}
+
+int getJoystickNrFromDeviceName(char *device_name)
+{
+ char c;
+ int joystick_nr = 0;
+
+ if (device_name == NULL || device_name[0] == '\0')
+ return 0;
+
+ c = device_name[strlen(device_name) - 1];
+
+ if (c >= '0' && c <= '9')
+ joystick_nr = (int)(c - '0');
+
+ if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS)
+ joystick_nr = 0;
+
+ return joystick_nr;
+}
+
#if !defined(PLATFORM_MSDOS)
static int JoystickPosition(int middle, int margin, int actual)
{
+++ /dev/null
-/***********************************************************
-* Rocks'n'Diamonds -- McDuffin Strikes Back! *
-*----------------------------------------------------------*
-* (c) 1995-98 Artsoft Entertainment *
-* Holger Schemel *
-* Oststrasse 11a *
-* 33604 Bielefeld *
-* phone: ++49 +521 290471 *
-* email: aeglos@valinor.owl.de *
-*----------------------------------------------------------*
-* joystick.h *
-***********************************************************/
-
-#ifndef JOYSTICK_H
-#define JOYSTICK_H
-
-/* values for the joystick */
-#define JOYSTICK_OFF 0
-#define JOYSTICK_AVAILABLE 1
-
-#ifdef __FreeBSD__
-#include <machine/joystick.h>
-#define DEV_JOYSTICK_0 "/dev/joy0"
-#define DEV_JOYSTICK_1 "/dev/joy1"
-#define DEV_JOYSTICK_2 "/dev/joy2"
-#define DEV_JOYSTICK_3 "/dev/joy3"
-#else
-#define DEV_JOYSTICK_0 "/dev/js0"
-#define DEV_JOYSTICK_1 "/dev/js1"
-#define DEV_JOYSTICK_2 "/dev/js2"
-#define DEV_JOYSTICK_3 "/dev/js3"
-#endif
-
-/* get these values from the program 'js' from the joystick package, */
-/* set JOYSTICK_PERCENT to a threshold appropriate for your joystick */
-
-#ifdef TARGET_SDL
-#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
-
-#define JOY_LEFT MV_LEFT
-#define JOY_RIGHT MV_RIGHT
-#define JOY_UP MV_UP
-#define JOY_DOWN MV_DOWN
-#define JOY_BUTTON_1 (1<<4)
-#define JOY_BUTTON_2 (1<<5)
-#define JOY_BUTTON (JOY_BUTTON_1 | JOY_BUTTON_2)
-
-#define JOY_BUTTON_NOT_PRESSED 0
-#define JOY_BUTTON_PRESSED 1
-#define JOY_BUTTON_NEW_PRESSED 2
-#define JOY_BUTTON_NEW_RELEASED 3
-
-#ifdef NO_JOYSTICK
-#define JOYSTICK_STATUS JOYSTICK_OFF
-#else
-#define JOYSTICK_STATUS JOYSTICK_AVAILABLE
-#endif
-
-
-#if defined(TARGET_SDL)
-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 AnyJoystick(void);
-int AnyJoystickButton(void);
-
-#endif /* JOYSTICK_H */
#include "misc.h"
+#if 0
#include "joystick_TMP.h"
+#endif
#if defined(PLATFORM_MSDOS)
volatile unsigned long counter = 0;
return letter;
}
-#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
-#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
-
-void translate_joyname(int *joysymbol, char **name, int mode)
-{
- static struct
- {
- int joysymbol;
- char *name;
- } translate_joy[] =
- {
- { JOY_LEFT, "joystick_left" },
- { JOY_RIGHT, "joystick_right" },
- { JOY_UP, "joystick_up" },
- { JOY_DOWN, "joystick_down" },
- { JOY_BUTTON_1, "joystick_button_1" },
- { JOY_BUTTON_2, "joystick_button_2" },
- };
-
- int i;
-
- if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME)
- {
- *name = "[undefined]";
-
- for (i=0; i<6; i++)
- {
- if (*joysymbol == translate_joy[i].joysymbol)
- {
- *name = translate_joy[i].name;
- break;
- }
- }
- }
- else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL)
- {
- *joysymbol = 0;
-
- for (i=0; i<6; i++)
- {
- if (strcmp(*name, translate_joy[i].name) == 0)
- {
- *joysymbol = translate_joy[i].joysymbol;
- break;
- }
- }
- }
-}
-
-char *getJoyNameFromJoySymbol(int joysymbol)
-{
- char *name;
-
- translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME);
- return name;
-}
-
-int getJoySymbolFromJoyName(char *name)
-{
- int joysymbol;
-
- translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
- return joysymbol;
-}
-
-int getJoystickNrFromDeviceName(char *device_name)
-{
- char c;
- int joystick_nr = 0;
-
- if (device_name == NULL || device_name[0] == '\0')
- return 0;
-
- c = device_name[strlen(device_name) - 1];
-
- if (c >= '0' && c <= '9')
- joystick_nr = (int)(c - '0');
-
- if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS)
- joystick_nr = 0;
-
- return joystick_nr;
-}
-
/* ------------------------------------------------------------------------- */
/* some functions to handle lists of level directories */
/* ------------------------------------------------------------------------- */
#ifdef TARGET_SDL
-inline void SDLInitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
+inline void SDLInitVideoDisplay(void)
{
/* initialize SDL video */
if (SDL_Init(SDL_INIT_VIDEO) < 0)
Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
- /* automatically cleanup SDL stuff after exit() */
+ /* set default SDL depth */
+ video.default_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel;
+
+ /* set exit function to automatically cleanup SDL stuff after exit() */
atexit(SDL_Quit);
+}
+inline void SDLInitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window,
+ boolean fullscreen)
+{
/* open SDL video output device (window or fullscreen mode) */
- if (!SDLSetVideoMode(backbuffer))
+ if (!SDLSetVideoMode(backbuffer, fullscreen))
Error(ERR_EXIT, "setting video mode failed");
/* set window and icon title */
- SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
-
- /* create additional buffer for double-buffering */
- pix[PIX_DB_BACK] = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
+ SDL_WM_SetCaption(program.window_title, program.window_title);
/* SDL cannot directly draw to the visible video framebuffer like X11,
but always uses a backbuffer, which is then blitted to the visible
buffer 'window' at the same size as the SDL backbuffer. Although it
should never be drawn to directly, it would do no harm nevertheless. */
- *window = pix[PIX_DB_BACK]; /* 'window' is only symbolic buffer */
- pix[PIX_DB_BACK] = *backbuffer; /* 'backbuffer' is SDL screen buffer */
+ /* create additional (symbolic) buffer for double-buffering */
+ *window = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
}
inline boolean SDLSetVideoMode(DrawBuffer *backbuffer, boolean fullscreen)
{
boolean success = TRUE;
+ int surface_flags = SDL_HWSURFACE | (fullscreen ? SDL_FULLSCREEN : 0);
if (fullscreen && !video.fullscreen_enabled && video.fullscreen_available)
{
DrawWindow window_old = *backbuffer;
DrawWindow window_new;
- if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
- SDL_HWSURFACE|SDL_FULLSCREEN))
- == NULL)
+ if ((window_new = SDL_SetVideoMode(video.width, video.height, video.depth,
+ surface_flags)) == NULL)
{
/* switching display to fullscreen mode failed */
Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
DrawWindow window_old = *backbuffer;
DrawWindow window_new;
- if ((window_new = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
- SDL_HWSURFACE))
- == NULL)
+ if ((window_new = SDL_SetVideoMode(video.width, video.height, video.depth,
+ surface_flags)) == NULL)
{
/* switching display to window mode failed -- should not happen */
Error(ERR_WARN, "SDL_SetVideoMode() failed: %s", SDL_GetError());
/* SDL function definitions */
-inline void SDLInitBufferedDisplay(DrawBuffer *, DrawWindow *);
+inline void SDLInitVideoDisplay(void);
+inline void SDLInitVideoBuffer(DrawBuffer *, DrawWindow *);
inline boolean SDLSetVideoMode(DrawBuffer *, boolean);
inline void SDLCopyArea(SDL_Surface *, SDL_Surface *,
int, int, int, int, int, int);
/* exported variables */
/* ========================================================================= */
+struct ProgramInfo program;
struct VideoSystemInfo video;
struct AudioSystemInfo audio;
struct OptionInfo options;
/* video functions */
/* ========================================================================= */
-inline void InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
+inline static int GetRealDepth(int depth)
{
- video.fullscreen_available = FULLSCREEN_STATUS;
- video.fullscreen_enabled = FALSE;
+ return (depth == DEFAULT_DEPTH ? video.default_depth : depth);
+}
+
+inline void InitProgramInfo(char *command_name, char *program_title,
+ char *window_title, char *icon_title,
+ char *x11_icon_filename,
+ char *x11_iconmask_filename)
+{
+ program.command_name = command_name;
+ program.program_title = program_title;
+ program.window_title = window_title;
+ program.icon_title = icon_title;
+ program.x11_icon_filename = x11_icon_filename;
+ program.x11_iconmask_filename = x11_iconmask_filename;
+}
+inline void InitVideoDisplay(void)
+{
#ifdef TARGET_SDL
- SDLInitBufferedDisplay(backbuffer, window);
+ SDLInitVideoDisplay();
#else
- X11InitBufferedDisplay(backbuffer, window);
+ X11InitVideoDisplay();
#endif
}
-inline int GetDisplayDepth(void)
+inline void InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window,
+ int width, int height, int depth,
+ boolean fullscreen)
{
+ video.width = width;
+ video.height = height;
+ video.depth = GetRealDepth(depth);
+ video.fullscreen_available = FULLSCREEN_STATUS;
+ video.fullscreen_enabled = FALSE;
+
#ifdef TARGET_SDL
- return SDL_GetVideoSurface()->format->BitsPerPixel;
+ SDLInitVideoBuffer(backbuffer, window, fullscreen);
#else
- return XDefaultDepth(display, screen);
+ X11InitVideoBuffer(backbuffer, window);
#endif
}
inline Bitmap CreateBitmap(int width, int height, int depth)
{
- int real_depth = (depth == DEFAULT_DEPTH ? GetDisplayDepth() : depth);
+ int real_depth = GetRealDepth(depth);
#ifdef TARGET_SDL
SDL_Surface *surface_tmp, *surface_native;
/* structure definitions */
+struct ProgramInfo
+{
+ char *command_name;
+ char *program_title;
+ char *window_title;
+ char *icon_title;
+ char *x11_icon_filename;
+ char *x11_iconmask_filename;
+};
+
struct VideoSystemInfo
{
+ int default_depth;
+ int width, height, depth;
boolean fullscreen_available;
boolean fullscreen_enabled;
};
/* exported variables */
/* ========================================================================= */
+extern struct ProgramInfo program;
extern struct VideoSystemInfo video;
extern struct AudioSystemInfo audio;
extern struct OptionInfo options;
/* function definitions */
-inline void InitBufferedDisplay(DrawBuffer *, DrawWindow *);
-inline int GetDisplayDepth(void);
+inline void InitProgramInfo(char *, char *, char *, char *, char *, char *);
+inline void InitVideoDisplay(void);
+inline void InitVideoBuffer(DrawBuffer *,DrawWindow *, int, int, int, boolean);
inline Bitmap CreateBitmap(int, int, int);
inline void FreeBitmap(Bitmap);
inline void ClearRectangle(Bitmap, int, int, int, int);
#if defined(TARGET_X11)
+#if 0
#include "main_TMP.h"
+#endif
+#if 0
struct IconFileInfo
{
char *picture_filename;
char *picturemask_filename;
};
+#endif
+
+static void X11InitDisplay();
+static DrawWindow X11InitWindow();
+
+inline void X11InitVideoDisplay(void)
+{
+ /* initialize X11 video */
+ X11InitDisplay();
+
+ /* set default X11 depth */
+ video.default_depth = XDefaultDepth(display, screen);
+}
+
+inline void X11InitVideoBuffer(DrawBuffer *backbuffer, DrawWindow *window)
+{
+ *window = X11InitWindow();
+
+ XMapWindow(display, *window);
+ FlushDisplay();
+
+ /* create additional (off-screen) buffer for double-buffering */
+ *backbuffer = CreateBitmap(video.width, video.height, video.depth);
+}
static void X11InitDisplay()
{
XSizeHints size_hints;
XWMHints wm_hints;
XClassHint class_hints;
- char *window_name = WINDOW_TITLE_STRING;
- char *icon_name = WINDOW_TITLE_STRING;
+ char *window_name = program.window_title;
+ char *icon_name = program.window_title;
long window_event_mask;
Atom proto_atom = None, delete_atom = None;
#endif
int screen_width, screen_height;
- int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
+ int win_xpos, win_ypos;
unsigned long pen_fg = WhitePixel(display,screen);
unsigned long pen_bg = BlackPixel(display,screen);
- const int width = WIN_XSIZE, height = WIN_YSIZE;
+ const int width = video.width, height = video.height;
+#if 0
#if !defined(PLATFORM_MSDOS)
static struct IconFileInfo icon_pic =
{
"rocks_icon.xbm",
"rocks_iconmask.xbm"
};
+#endif
#endif
screen_width = XDisplayWidth(display, screen);
XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
PropModePrepend, (unsigned char *) &delete_atom, 1);
+#if 0
sprintf(icon_filename, "%s/%s/%s",
options.ro_base_directory, GRAPHICS_DIRECTORY,
icon_pic.picture_filename);
- XReadBitmapFile(display,window,icon_filename,
- &icon_width,&icon_height,
- &icon_pixmap,&icon_hot_x,&icon_hot_y);
+#endif
+ XReadBitmapFile(display, window, program.x11_icon_filename,
+ &icon_width, &icon_height,
+ &icon_pixmap, &icon_hot_x, &icon_hot_y);
if (!icon_pixmap)
Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
+#if 0
sprintf(icon_filename, "%s/%s/%s",
options.ro_base_directory, GRAPHICS_DIRECTORY,
icon_pic.picturemask_filename);
- XReadBitmapFile(display,window,icon_filename,
- &icon_width,&icon_height,
- &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
+#endif
+ XReadBitmapFile(display, window, program.x11_iconmask_filename,
+ &icon_width, &icon_height,
+ &iconmask_pixmap, &icon_hot_x, &icon_hot_y);
if (!iconmask_pixmap)
Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
wm_hints.icon_mask = iconmask_pixmap;
wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
- class_hints.res_name = program_name;
- class_hints.res_class = "Rocks'n'Diamonds";
+ class_hints.res_name = program.command_name;
+ class_hints.res_class = program.program_title;
XSetWMProperties(display, window, &windowName, &iconName,
NULL, 0, &size_hints, &wm_hints,
return window;
}
-inline void X11InitBufferedDisplay(DrawBuffer *backbuffer, DrawWindow *window)
-{
- X11InitDisplay();
- *window = X11InitWindow();
-
- XMapWindow(display, *window);
- FlushDisplay();
-
- /* create additional buffer for double-buffering */
- *backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
- pix[PIX_DB_BACK] = *backbuffer; /* 'backbuffer' is off-screen buffer */
-}
-
#endif /* TARGET_X11 */
/* X11 function definitions */
-inline void X11InitBufferedDisplay(DrawBuffer *, DrawWindow *);
+inline void X11InitVideoDisplay(void);
+inline void X11InitVideoBuffer(DrawBuffer *, DrawWindow *);
#endif /* X11_H */
#define PIX_SMALLFONT 8
#define PIX_MEDIUMFONT 9
/* Bitmaps without graphic file */
-#define PIX_DB_BACK 10
-#define PIX_DB_DOOR 11
-#define PIX_DB_FIELD 12
+#define PIX_DB_DOOR 10
+#define PIX_DB_FIELD 11
#define NUM_PICTURES 10
-#define NUM_BITMAPS 13
+#define NUM_BITMAPS 12
/* boundaries of arrays etc. */
#define MAX_PLAYER_NAME_LEN 10
#define PROGRAM_IDENT_STRING PROGRAM_VERSION_STRING " " TARGET_STRING
#define WINDOW_TITLE_STRING PROGRAM_TITLE_STRING " " PROGRAM_IDENT_STRING
#define WINDOW_SUBTITLE_STRING PROGRAM_RIGHTS_STRING " " PROGRAM_AUTHOR_STRING
+#define ICON_TITLE_STRING PROGRAM_TITLE_STRING
/* default name for empty highscore entry */
#define EMPTY_PLAYER_NAME "no name"