rnd-20020324-1-src
[rocksndiamonds.git] / src / libgame / system.c
index b4ac9ce4e83a3b8bb4e49a954e78f071a6ab4391..a91d243876c6800365a2f039af56257f9ed7d1ee 100644 (file)
@@ -22,6 +22,8 @@
 
 #include "system.h"
 #include "sound.h"
+#include "setup.h"
+#include "joystick.h"
 #include "misc.h"
 
 
@@ -34,26 +36,29 @@ struct OptionInfo   options;
 struct VideoSystemInfo video;
 struct AudioSystemInfo audio;
 struct GfxInfo         gfx;
+struct JoystickInfo    joystick;
+struct SetupInfo       setup;
 
 struct LevelDirInfo    *leveldir_first = NULL;
 struct LevelDirInfo    *leveldir_current = NULL;
+int                    level_nr;
 
-Display        *display = NULL;
-Visual        *visual = NULL;
-int            screen = 0;
-Colormap       cmap = None;
+Display                       *display = NULL;
+Visual                *visual = NULL;
+int                    screen = 0;
+Colormap               cmap = None;
 
-DrawWindow     *window = NULL;
-DrawBuffer     *backbuffer = NULL;
-DrawBuffer     *drawto = NULL;
+DrawWindow            *window = NULL;
+DrawBuffer            *backbuffer = NULL;
+DrawBuffer            *drawto = NULL;
 
-int            button_status = MB_NOT_PRESSED;
-boolean                motion_status = FALSE;
+int                    button_status = MB_NOT_PRESSED;
+boolean                        motion_status = FALSE;
 
-int            redraw_mask = REDRAW_NONE;
-int            redraw_tiles = 0;
+int                    redraw_mask = REDRAW_NONE;
+int                    redraw_tiles = 0;
 
-int            FrameCounter = 0;
+int                    FrameCounter = 0;
 
 
 /* ========================================================================= */
@@ -107,14 +112,15 @@ void ClosePlatformDependantStuff(void)
 void InitProgramInfo(char *unix_userdata_directory, char *program_title,
                     char *window_title, char *icon_title,
                     char *x11_icon_basename, char *x11_iconmask_basename,
-                    char *msdos_pointer_basename)
+                    char *msdos_pointer_basename,
+                    char *cookie_prefix, int program_version)
 {
-  char *gfx_dir = getPath2(options.ro_base_directory, GRAPHICS_DIRECTORY);
-  char *x11_icon_filename = getPath2(gfx_dir, x11_icon_basename);
-  char *x11_iconmask_filename = getPath2(gfx_dir, x11_iconmask_basename);
-  char *msdos_pointer_filename = getPath2(gfx_dir, msdos_pointer_basename);
-
-  free(gfx_dir);
+  char *x11_icon_filename =
+    getPath2(options.graphics_directory, x11_icon_basename);
+  char *x11_iconmask_filename =
+    getPath2(options.graphics_directory, x11_iconmask_basename);
+  char *msdos_pointer_filename =
+    getPath2(options.graphics_directory, msdos_pointer_basename);
 
 #if defined(PLATFORM_UNIX)
   program.userdata_directory = unix_userdata_directory;
@@ -128,6 +134,10 @@ void InitProgramInfo(char *unix_userdata_directory, char *program_title,
   program.x11_icon_filename = x11_icon_filename;
   program.x11_iconmask_filename = x11_iconmask_filename;
   program.msdos_pointer_filename = msdos_pointer_filename;
+  program.cookie_prefix = cookie_prefix;
+  program.version_major = VERSION_MAJOR(program_version);
+  program.version_minor = VERSION_MINOR(program_version);
+  program.version_patch = VERSION_PATCH(program_version);
 }
 
 void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize,
@@ -581,8 +591,7 @@ inline boolean ChangeVideoModeIfNeeded(boolean fullscreen)
 Bitmap *LoadImage(char *basename)
 {
   Bitmap *new_bitmap;
-  char *filename = getPath3(options.ro_base_directory, GRAPHICS_DIRECTORY,
-                           basename);
+  char *filename = getPath2(options.graphics_directory, basename);
 
 #if defined(TARGET_SDL)
   new_bitmap = SDLLoadImage(filename);
@@ -620,10 +629,10 @@ inline void OpenAudio(void)
 
 #if defined(TARGET_SDL)
   SDLOpenAudio();
-#elif defined(PLATFORM_MSDOS)
-  MSDOSOpenAudio();
 #elif defined(PLATFORM_UNIX)
   UnixOpenAudio();
+#elif defined(PLATFORM_MSDOS)
+  MSDOSOpenAudio();
 #endif
 }
 
@@ -631,10 +640,10 @@ inline void CloseAudio(void)
 {
 #if defined(TARGET_SDL)
   SDLCloseAudio();
-#elif defined(PLATFORM_MSDOS)
-  MSDOSCloseAudio();
 #elif defined(PLATFORM_UNIX)
   UnixCloseAudio();
+#elif defined(PLATFORM_MSDOS)
+  MSDOSCloseAudio();
 #endif
 
   audio.sound_enabled = FALSE;
@@ -724,9 +733,39 @@ inline boolean CheckCloseWindowEvent(ClientMessageEvent *event)
 }
 
 
-inline void dummy(void)
+/* ========================================================================= */
+/* joystick functions                                                        */
+/* ========================================================================= */
+
+inline void InitJoysticks()
 {
-#ifdef TARGET_SDL
-#else
+  int i;
+
+#ifdef NO_JOYSTICK
+  return;      /* joysticks generally deactivated by compile-time directive */
+#endif
+
+  /* always start with reliable default values */
+  joystick.status = JOYSTICK_NOT_AVAILABLE;
+  for (i=0; i<MAX_PLAYERS; i++)
+    joystick.fd[i] = -1;               /* joystick device closed */
+
+#if defined(TARGET_SDL)
+  SDLInitJoysticks();
+#elif defined(PLATFORM_UNIX)
+  UnixInitJoysticks();
+#elif defined(PLATFORM_MSDOS)
+  MSDOSInitJoysticks();
+#endif
+}
+
+inline boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
+{
+#if defined(TARGET_SDL)
+  return SDLReadJoystick(nr, x, y, b1, b2);
+#elif defined(PLATFORM_UNIX)
+  return UnixReadJoystick(nr, x, y, b1, b2);
+#elif defined(PLATFORM_MSDOS)
+  return MSDOSReadJoystick(nr, x, y, b1, b2);
 #endif
 }