rnd-19981116-1
authorHolger Schemel <info@artsoft.org>
Mon, 16 Nov 1998 18:31:33 +0000 (19:31 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:31:47 +0000 (10:31 +0200)
12 files changed:
src/files.c
src/files.h
src/game.c
src/image.c
src/image.h
src/init.c
src/main.c
src/main.h
src/misc.c
src/misc.h
src/network.c
src/screens.c

index ac1b0fa74a380246fa12e2f8880e3240648f6fae..c14b9d994ec128b1c451f2bd87a96ec71792bcd8 100644 (file)
@@ -12,6 +12,9 @@
 ***********************************************************/
 
 #include <ctype.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
 
 #include "files.h"
 #include "tools.h"
@@ -105,52 +108,6 @@ static void InitScoreDirectory(char *level_subdir)
   createDirectory(getScoreDir(level_subdir), "level score");
 }
 
-boolean LoadLevelInfo()
-{
-  int i;
-  char filename[MAX_FILENAME_LEN];
-  char cookie[MAX_FILENAME_LEN];
-  FILE *file;
-
-  sprintf(filename, "%s/%s", options.level_directory, LEVDIR_FILENAME);
-
-  if (!(file = fopen(filename, "r")))
-  {
-    Error(ERR_WARN, "cannot read level info '%s'", filename);
-    return(FALSE);
-  }
-
-  fscanf(file, "%s\n", cookie);
-  if (strcmp(cookie, LEVELDIR_COOKIE))
-  {
-    Error(ERR_WARN, "wrong format of level info file");
-    fclose(file);
-    return(FALSE);
-  }
-
-  num_leveldirs = 0;
-  leveldir_nr = 0;
-  for(i=0; i<MAX_LEVDIR_ENTRIES; i++)
-  {
-    fscanf(file, "%s", leveldir[i].filename);
-    fscanf(file, "%s", leveldir[i].name);
-    fscanf(file, "%d", &leveldir[i].levels);
-    fscanf(file, "%d", &leveldir[i].readonly);
-    if (feof(file))
-      break;
-
-    num_leveldirs++;
-  }
-
-  if (!num_leveldirs)
-  {
-    Error(ERR_WARN, "empty level info '%s'", filename);
-    return(FALSE);
-  }
-
-  return(TRUE);
-}
-
 void LoadLevel(int level_nr)
 {
   int i, x, y;
@@ -549,20 +506,22 @@ void SaveScore(int level_nr)
 
 #define TOKEN_VALUE_POSITION           30
 
-#define SETUP_TOKEN_SOUND              0
-#define SETUP_TOKEN_SOUND_LOOPS                1
-#define SETUP_TOKEN_SOUND_MUSIC                2
-#define SETUP_TOKEN_SOUND_SIMPLE       3
-#define SETUP_TOKEN_TOONS              4
-#define SETUP_TOKEN_DOUBLE_BUFFERING   5
-#define SETUP_TOKEN_SCROLL_DELAY       6
-#define SETUP_TOKEN_SOFT_SCROLLING     7
-#define SETUP_TOKEN_FADING             8
-#define SETUP_TOKEN_AUTORECORD         9
-#define SETUP_TOKEN_QUICK_DOORS                10
-#define SETUP_TOKEN_TEAM_MODE          11
-#define SETUP_TOKEN_ALIAS_NAME         12
-
+/* global setup */
+#define SETUP_TOKEN_PLAYER_NAME                0
+#define SETUP_TOKEN_SOUND              1
+#define SETUP_TOKEN_SOUND_LOOPS                2
+#define SETUP_TOKEN_SOUND_MUSIC                3
+#define SETUP_TOKEN_SOUND_SIMPLE       4
+#define SETUP_TOKEN_TOONS              5
+#define SETUP_TOKEN_DOUBLE_BUFFERING   6
+#define SETUP_TOKEN_SCROLL_DELAY       7
+#define SETUP_TOKEN_SOFT_SCROLLING     8
+#define SETUP_TOKEN_FADING             9
+#define SETUP_TOKEN_AUTORECORD         10
+#define SETUP_TOKEN_QUICK_DOORS                11
+#define SETUP_TOKEN_TEAM_MODE          12
+
+/* player setup */
 #define SETUP_TOKEN_USE_JOYSTICK       13
 #define SETUP_TOKEN_JOY_DEVICE_NAME    14
 #define SETUP_TOKEN_JOY_XLEFT          15
@@ -580,14 +539,21 @@ void SaveScore(int level_nr)
 #define SETUP_TOKEN_KEY_SNAP           27
 #define SETUP_TOKEN_KEY_BOMB           28
 
-#define NUM_SETUP_TOKENS               29
+/* level directory info */
+#define LEVELINFO_TOKEN_NAME           29
+#define LEVELINFO_TOKEN_LEVELS         30
+#define LEVELINFO_TOKEN_SORT_PRIORITY  31
+#define LEVELINFO_TOKEN_READONLY       32
 
-#define FIRST_GLOBAL_SETUP_TOKEN       SETUP_TOKEN_SOUND
-#define LAST_GLOBAL_SETUP_TOKEN                SETUP_TOKEN_ALIAS_NAME
+#define FIRST_GLOBAL_SETUP_TOKEN       SETUP_TOKEN_PLAYER_NAME
+#define LAST_GLOBAL_SETUP_TOKEN                SETUP_TOKEN_TEAM_MODE
 
 #define FIRST_PLAYER_SETUP_TOKEN       SETUP_TOKEN_USE_JOYSTICK
 #define LAST_PLAYER_SETUP_TOKEN                SETUP_TOKEN_KEY_BOMB
 
+#define FIRST_LEVELINFO_TOKEN          LEVELINFO_TOKEN_NAME
+#define LAST_LEVELINFO_TOKEN           LEVELINFO_TOKEN_READONLY
+
 #define TYPE_BOOLEAN                   1
 #define TYPE_SWITCH                    2
 #define TYPE_KEYSYM                    3
@@ -596,6 +562,7 @@ void SaveScore(int level_nr)
 
 static struct SetupInfo si;
 static struct SetupInputInfo sii;
+struct LevelDirInfo ldi;
 static struct
 {
   int type;
@@ -603,6 +570,8 @@ static struct
   char *text;
 } token_info[] =
 {
+  /* global setup */
+  { TYPE_STRING,  &si.player_name,     "player_name"                   },
   { TYPE_SWITCH,  &si.sound,           "sound"                         },
   { TYPE_SWITCH,  &si.sound_loops,     "repeating_sound_loops"         },
   { TYPE_SWITCH,  &si.sound_music,     "background_music"              },
@@ -615,9 +584,8 @@ static struct
   { TYPE_SWITCH,  &si.autorecord,      "automatic_tape_recording"      },
   { TYPE_SWITCH,  &si.quick_doors,     "quick_doors"                   },
   { TYPE_SWITCH,  &si.team_mode,       "team_mode"                     },
-  { TYPE_STRING,  &si.alias_name,      "alias_name"                    },
 
-  /* for each player: */
+  /* player setup */
   { TYPE_BOOLEAN, &sii.use_joystick,   ".use_joystick"                 },
   { TYPE_STRING,  &sii.joy.device_name,        ".joy.device_name"              },
   { TYPE_INTEGER, &sii.joy.xleft,      ".joy.xleft"                    },
@@ -633,7 +601,13 @@ static struct
   { TYPE_KEYSYM,  &sii.key.up,         ".key.move_up"                  },
   { TYPE_KEYSYM,  &sii.key.down,       ".key.move_down"                },
   { TYPE_KEYSYM,  &sii.key.snap,       ".key.snap_field"               },
-  { TYPE_KEYSYM,  &sii.key.bomb,       ".key.place_bomb"               }
+  { TYPE_KEYSYM,  &sii.key.bomb,       ".key.place_bomb"               },
+
+  /* level directory info */
+  { TYPE_STRING,  &ldi.name,           "name"                          },
+  { TYPE_INTEGER, &ldi.levels,         "levels"                        },
+  { TYPE_INTEGER, &ldi.sort_priority,  "sort_priority"                 },
+  { TYPE_BOOLEAN, &ldi.readonly,       "readonly"                      }
 };
 
 static char *string_tolower(char *s)
@@ -791,7 +765,7 @@ static struct SetupFileList *loadSetupFileList(char *filename)
 
   if (!(file = fopen(filename, "r")))
   {
-    Error(ERR_WARN, "cannot open setup file '%s'", filename);
+    Error(ERR_WARN, "cannot open setup/info file '%s'", filename);
     return NULL;
   }
 
@@ -859,8 +833,8 @@ static struct SetupFileList *loadSetupFileList(char *filename)
   setup_file_list->next = NULL;
   freeSetupFileList(setup_file_list);
 
-  if (!first_valid_list_entry)
-    Error(ERR_WARN, "setup file is empty");
+  if (first_valid_list_entry == NULL)
+    Error(ERR_WARN, "setup/info file '%s' is empty", filename);
 
   return first_valid_list_entry;
 }
@@ -875,7 +849,7 @@ static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list,
   {
     if (strcmp(setup_file_list->value, identifier) != 0)
     {
-      Error(ERR_WARN, "setup file has wrong version");
+      Error(ERR_WARN, "setup/info file has wrong version");
       return;
     }
     else
@@ -886,15 +860,25 @@ static void checkSetupFileListIdentifier(struct SetupFileList *setup_file_list,
     checkSetupFileListIdentifier(setup_file_list->next, identifier);
   else
   {
-    Error(ERR_WARN, "setup file has no version information");
+    Error(ERR_WARN, "setup/info file has no version information");
     return;
   }
 }
 
+static void setLevelDirInfoToDefaults(struct LevelDirInfo *ldi)
+{
+  ldi->name = getStringCopy("non-existing");
+  ldi->levels = 0;
+  ldi->sort_priority = 999;    /* default: least priority */
+  ldi->readonly = TRUE;
+}
+
 static void setSetupInfoToDefaults(struct SetupInfo *si)
 {
   int i;
 
+  si->player_name = getStringCopy(getLoginName());
+
   si->sound = TRUE;
   si->sound_loops = FALSE;
   si->sound_music = FALSE;
@@ -908,15 +892,10 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->autorecord = FALSE;
   si->quick_doors = FALSE;
 
-  strncpy(si->login_name, getLoginName(), MAX_NAMELEN-1);
-  si->login_name[MAX_NAMELEN-1] = '\0';
-  strncpy(si->alias_name, getLoginName(), MAX_NAMELEN-1);
-  si->alias_name[MAX_NAMELEN-1] = '\0';
-
   for (i=0; i<MAX_PLAYERS; i++)
   {
     si->input[i].use_joystick = FALSE;
-    strcpy(si->input[i].joy.device_name, joystick_device_name[i]);
+    si->input[i].joy.device_name = getStringCopy(joystick_device_name[i]);
     si->input[i].joy.xleft   = JOYSTICK_XLEFT;
     si->input[i].joy.xmiddle = JOYSTICK_XMIDDLE;
     si->input[i].joy.xright  = JOYSTICK_XRIGHT;
@@ -959,7 +938,9 @@ static void setSetupInfo(int token_nr, char *token_value)
       break;
 
     case TYPE_STRING:
-      strcpy((char *)setup_value, token_value);
+      if (*(char **)setup_value != NULL)
+       free(*(char **)setup_value);
+      *(char **)setup_value = getStringCopy(token_value);
       break;
 
     default:
@@ -1039,6 +1020,85 @@ int getLastPlayedLevelOfLevelSeries(char *level_series_name)
   return last_level_nr;
 }
 
+void LoadLevelInfo()
+{
+  DIR *dir;
+  struct stat file_status;
+  char *level_directory = options.level_directory;
+  char *directory = NULL;
+  char *filename = NULL;
+  struct SetupFileList *setup_file_list = NULL;
+  struct dirent *dir_entry;
+  int i, num_entries = 0;
+
+  if ((dir = opendir(level_directory)) == NULL)
+    Error(ERR_EXIT, "cannot read level directory '%s'", level_directory);
+
+  while (num_entries < MAX_LEVDIR_ENTRIES)
+  {
+    if ((dir_entry = readdir(dir)) == NULL)    /* last directory entry */
+      break;
+
+    /* skip entries for current and parent directory */
+    if (strcmp(dir_entry->d_name, ".")  == 0 ||
+       strcmp(dir_entry->d_name, "..") == 0)
+      continue;
+
+    /* find out if directory entry is itself a directory */
+    directory = getPath2(level_directory, dir_entry->d_name);
+    if (stat(directory, &file_status) != 0 ||          /* cannot stat file */
+       (file_status.st_mode & S_IFMT) != S_IFDIR)      /* not a directory */
+    {
+      free(directory);
+      continue;
+    }
+
+    if (strlen(dir_entry->d_name) >= MAX_LEVDIR_FILENAME)
+    {
+      Error(ERR_WARN, "filename of level directory '%s' too long -- ignoring",
+           dir_entry->d_name);
+      continue;
+    }
+
+    filename = getPath2(directory, LEVELINFO_FILENAME);
+    setup_file_list = loadSetupFileList(filename);
+
+    if (setup_file_list)
+    {
+      checkSetupFileListIdentifier(setup_file_list, LEVELINFO_COOKIE);
+      setLevelDirInfoToDefaults(&leveldir[num_entries]);
+
+      ldi = leveldir[num_entries];
+      for (i=FIRST_LEVELINFO_TOKEN; i<=LAST_LEVELINFO_TOKEN; i++)
+       setSetupInfo(i, getTokenValue(setup_file_list, token_info[i].text));
+      leveldir[num_entries] = ldi;
+
+      leveldir[num_entries].filename = getStringCopy(dir_entry->d_name);
+
+      freeSetupFileList(setup_file_list);
+      num_entries++;
+    }
+    else
+      Error(ERR_WARN, "ignoring level directory '%s'", directory);
+
+    free(directory);
+    free(filename);
+  }
+
+  if (num_entries == MAX_LEVDIR_ENTRIES)
+    Error(ERR_WARN, "using %d level directories -- ignoring the rest",
+         num_entries);
+
+  closedir(dir);
+
+  num_leveldirs = num_entries;
+  leveldir_nr = 0;
+
+  if (!num_leveldirs)
+    Error(ERR_EXIT, "cannot find any valid level series in directory '%s'",
+         level_directory);
+}
+
 void LoadSetup()
 {
   char filename[MAX_FILENAME_LEN];
@@ -1059,6 +1119,18 @@ void LoadSetup()
     setup.direct_draw = !setup.double_buffering;
 
     freeSetupFileList(setup_file_list);
+
+    /* needed to work around problems with fixed length strings */
+    if (strlen(setup.player_name) >= MAX_NAMELEN)
+      setup.player_name[MAX_NAMELEN - 1] = '\0';
+    else if (strlen(setup.player_name) < MAX_NAMELEN - 1)
+    {
+      char *new_name = checked_malloc(MAX_NAMELEN);
+
+      strcpy(new_name, setup.player_name);
+      free(setup.player_name);
+      setup.player_name = new_name;
+    }
   }
   else
     Error(ERR_WARN, "using default setup values");
@@ -1117,7 +1189,7 @@ static char *getSetupLine(char *prefix, int token_nr)
       break;
 
     case TYPE_STRING:
-      strcat(entry, (char *)setup_value);
+      strcat(entry, *(char **)setup_value);
       break;
 
     default:
@@ -1151,11 +1223,11 @@ void SaveSetup()
   si = setup;
   for (i=FIRST_GLOBAL_SETUP_TOKEN; i<=LAST_GLOBAL_SETUP_TOKEN; i++)
   {
+    fprintf(file, "%s\n", getSetupLine("", i));
+
     /* just to make things nicer :) */
-    if (i == SETUP_TOKEN_ALIAS_NAME)
+    if (i == SETUP_TOKEN_PLAYER_NAME)
       fprintf(file, "\n");
-
-    fprintf(file, "%s\n", getSetupLine("", i));
   }
 
   /* handle player specific setup values */
@@ -1203,7 +1275,11 @@ void LoadLevelSetup()
     checkSetupFileListIdentifier(level_setup_list, LEVELSETUP_COOKIE);
   }
   else
+  {
+    level_setup_list = newSetupFileList(TOKEN_STR_FILE_IDENTIFIER,
+                                       LEVELSETUP_COOKIE);
     Error(ERR_WARN, "using default setup values");
+  }
 }
 
 void SaveLevelSetup()
index a8dd277463c64cedaee17aa67ef648c454f7467a..429fe63f6b3b84548ab92f64276deb335019df70 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "main.h"
 
-boolean LoadLevelInfo(void);
-
 void LoadLevel(int);
 void SaveLevel(int);
 
@@ -29,6 +27,7 @@ void SaveScore(int);
 
 int getLastPlayedLevelOfLevelSeries(char *);
 
+void LoadLevelInfo(void);
 void LoadSetup(void);
 void SaveSetup(void);
 void LoadLevelSetup(void);
index 017adc470abf7a353bd45c16c5738af65bff89cc..13ae62bb51347d394f92fcb9647febd254b49ce9 100644 (file)
@@ -572,7 +572,7 @@ boolean NewHiScore()
 
   LoadScore(level_nr);
 
-  if (!strcmp(setup.alias_name,EMPTY_ALIAS) ||
+  if (!strcmp(setup.player_name, EMPTY_ALIAS) ||
       local_player->score < highscore[MAX_SCORE_ENTRIES-1].Score) 
     return(-1);
 
@@ -588,7 +588,7 @@ boolean NewHiScore()
 
 #ifdef ONE_PER_NAME
        for(l=k;l<MAX_SCORE_ENTRIES;l++)
-         if (!strcmp(setup.alias_name,highscore[l].Name))
+         if (!strcmp(setup.player_name, highscore[l].Name))
            m = l;
        if (m==k)       /* Spieler überschreibt seine alte Position */
          goto put_into_list;
@@ -604,14 +604,15 @@ boolean NewHiScore()
 #ifdef ONE_PER_NAME
       put_into_list:
 #endif
-      sprintf(highscore[k].Name,setup.alias_name);
+      strncpy(highscore[k].Name, setup.player_name, MAX_NAMELEN - 1);
+      highscore[k].Name[MAX_NAMELEN - 1] = '\0';
       highscore[k].Score = local_player->score; 
       position = k;
       break;
     }
 
 #ifdef ONE_PER_NAME
-    else if (!strcmp(setup.alias_name,highscore[k].Name))
+    else if (!strncmp(setup.player_name, highscore[k].Name, MAX_NAMELEN - 1))
       break;   /* Spieler schon mit besserer Punktzahl in der Liste */
 #endif
 
index 675240d0703b39d4d5450f31eb58c3c176a0892d..3cc85e34fc057f1a3eed88490c7015e42ead41c5 100644 (file)
 #include "image.h"
 #include "misc.h"
 
-
-#ifdef DEBUG
-
-#define DEBUG_TIMING
-
-#endif
-
-#ifdef DEBUG_TIMING
-  long count1, count2;
-#endif
-
-
 /* extra colors to try allocating in private color maps to minimize flashing */
 #define NOFLASH_COLORS 256
 
@@ -91,36 +79,29 @@ static Pixmap Image_to_Mask(Image *image, Display *display, Window window)
   return mask_pixmap;
 }
 
-/* find the best pixmap depth supported by the server for a particular
-   visual and return that depth */
-
-static unsigned int bitsPerPixelAtDepth(Display *display, int screen,
-                                       unsigned int depth)
+static int bitsPerPixelAtDepth(Display *display, int screen, int depth)
 {
-  XPixmapFormatValues *xf;
-  int nxf, a;
+  XPixmapFormatValues *pixmap_format;
+  int i, num_pixmap_formats, bits_per_pixel = -1;
 
-  xf = XListPixmapFormats(display, &nxf);
-  for (a = 0; a < nxf; a++)
-  {
-    if (xf[a].depth == depth)
-    {
-      int bpp;
-      bpp = xf[a].bits_per_pixel;
-      XFree(xf);
-      return (unsigned int) bpp;
-    }
-  }
-  XFree(xf);
+  /* get Pixmap formats supported by the X server */
+  pixmap_format = XListPixmapFormats(display, &num_pixmap_formats);
+
+  /* find format that matches the given depth */
+  for (i=0; i<num_pixmap_formats; i++)
+    if (pixmap_format[i].depth == depth)
+      bits_per_pixel = pixmap_format[i].bits_per_pixel;
+
+  XFree(pixmap_format);
+
+  if (bits_per_pixel == -1)
+    Error(ERR_EXIT, "cannot find pixmap format for depth %d", depth);
 
-  /* this should never happen; if it does, we're in trouble */
-  Error(ERR_EXIT, "bitsPerPixelAtDepth: can't find pixmap depth info");
-  return 0; /* never reached -- just to make gcc happy */
+  return bits_per_pixel;
 }
 
 XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
-                           Window window, GC gc,
-                           unsigned int depth, Image *image)
+                           Window window, GC gc, int depth, Image *image)
 {
   static XColor xcolor_private[NOFLASH_COLORS];
   static int colorcell_used[NOFLASH_COLORS];
@@ -151,7 +132,6 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
   redvalue = greenvalue = bluevalue = NULL;
   ximageinfo = checked_malloc(sizeof(XImageInfo));
   ximageinfo->display = display;
-  ximageinfo->screen = screen;
   ximageinfo->depth = depth;
 
   switch (visual->class)
@@ -369,16 +349,13 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
       break;
   
     default:
-      Error(ERR_RETURN, "display type not supported");
+      Error(ERR_RETURN, "display class not supported");
       Error(ERR_EXIT, "DirectColor, TrueColor or PseudoColor display needed");
       break;
   }
 
-#ifdef DEBUG_TIMING
-  count2 = Counter();
-  printf("   CONVERTING IMAGE TO XIMAGE (IMAGE COLORMAP) IN %.2f SECONDS\n",
-        (float)(count2-count1)/1000.0);
-  count1 = Counter();
+#if DEBUG_TIMING
+  debug_print_timestamp(2, "   ALLOCATING IMAGE COLORS:   ");
 #endif
 
   /* create XImage from internal image structure and convert it to Pixmap */
@@ -443,7 +420,7 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
     }
 
     default:
-      Error(ERR_RETURN, "display type not supported");
+      Error(ERR_RETURN, "display class not supported");
       Error(ERR_EXIT, "DirectColor, TrueColor or PseudoColor display needed");
       break;
   }
@@ -455,11 +432,8 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual,
     free((byte *)bluevalue);
   }
 
-#ifdef DEBUG_TIMING
-  count2 = Counter();
-  printf("   CONVERTING IMAGE TO XIMAGE IN %.2f SECONDS\n",
-        (float)(count2-count1)/1000.0);
-  count1 = Counter();
+#if DEBUG_TIMING
+  debug_print_timestamp(2, "   CONVERTING IMAGE TO XIMAGE:");
 #endif
 
   ximageinfo->pixmap = XCreatePixmap(display, window,
@@ -524,21 +498,19 @@ int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename,
   XImageInfo *ximageinfo;
   int screen;
   Visual *visual;
-  unsigned int depth;
+  int depth;
 
-#ifdef DEBUG_TIMING
-  count1 = Counter();
+#if DEBUG_TIMING
+  debug_print_timestamp(2, NULL);      /* initialize timestamp function */
 #endif
 
   /* read the graphic file in PCX format to image structure */
   if ((image = Read_PCX_to_Image(filename)) == NULL)
     return PCX_FileInvalid;
 
-#ifdef DEBUG_TIMING
-  count2 = Counter();
-  printf("   LOADING '%s' IN %.2f SECONDS\n",
-        filename, (float)(count2-count1)/1000.0);
-  count1 = Counter();
+#if DEBUG_TIMING
+  printf("%s:\n", filename);
+  debug_print_timestamp(2, "   READING PCX FILE TO IMAGE: ");
 #endif
 
   screen = DefaultScreen(display);
@@ -554,21 +526,15 @@ int Read_PCX_to_Pixmaps(Display *display, Window window, GC gc, char *filename,
   if (ximageinfo->cmap != DefaultColormap(display, screen))
     XSetWindowColormap(display, window, ximageinfo->cmap);
 
-#ifdef DEBUG_TIMING
-  count2 = Counter();
-  printf("   CONVERTING IMAGE TO PIXMAP IN %.2f SECONDS\n",
-        (float)(count2-count1)/1000.0);
-  count1 = Counter();
+#if DEBUG_TIMING
+  debug_print_timestamp(2, "   CONVERTING IMAGE TO PIXMAP:");
 #endif
 
   /* create clip mask for the image */
   ximageinfo->pixmap_mask = Image_to_Mask(image, display, window);
 
-#ifdef DEBUG_TIMING
-  count2 = Counter();
-  printf("   CONVERTING IMAGE TO MASK IN %.2f SECONDS\n",
-        (float)(count2-count1)/1000.0);
-  count1 = Counter();
+#if DEBUG_TIMING
+  debug_print_timestamp(2, "   CONVERTING IMAGE TO MASK:  ");
 #endif
 
   *pixmap = ximageinfo->pixmap;
index 50335eea15a5eaff0117bbe4a4f0f217c49ad3b8..5f96d592f6f71cbebeca6d43347defab1b8c89df 100644 (file)
@@ -23,7 +23,6 @@ typedef unsigned short Intensity;     /* RGB intensity for X11 */
 typedef struct
 {
   Display  *display;           /* destination display             */
-  int       screen;            /* destination screen              */
   int       depth;             /* depth of destination drawable   */
   Pixel     index[MAX_COLORS]; /* array of pixel values           */
   int       no;                        /* number of pixels in the array   */
index 37c0a1fefc624d78356d5d39a6a53a7cfb9ff34e..a80393344f993fccaf72e302fc65420c71ba33b9 100644 (file)
 #include "network.h"
 #include "netserv.h"
 
-#ifdef DEBUG
-
-#define DEBUG_TIMING
-
-#endif
-
 struct PictureFileInfo
 {
   char *picture_filename;
@@ -104,9 +98,7 @@ void InitLevelAndPlayerInfo()
 
   local_player->connected = TRUE;
 
-  if (!LoadLevelInfo())                        /* global level info */
-    Error(ERR_EXIT, NULL);
-
+  LoadLevelInfo();                     /* global level info */
   LoadSetup();                         /* global setup info */
   LoadLevelSetup();                    /* info about last played level */
 }
@@ -123,7 +115,7 @@ void InitNetworkServer()
   if (!ConnectToServer(options.server_host, options.server_port))
     Error(ERR_EXIT, "cannot connect to multiplayer server");
 
-  SendToServer_Nickname(setup.alias_name);
+  SendToServer_Nickname(setup.player_name);
   SendToServer_ProtocolVersion();
 
   if (nr_wanted)
@@ -502,9 +494,8 @@ void InitGfx()
     { -1, 0 }
   };
 
-#ifdef DEBUG_TIMING
-  long count1, count2;
-  count1 = Counter();
+#if DEBUG_TIMING
+  debug_print_timestamp(0, NULL);      /* initialize timestamp function */
 #endif
 
   LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]);
@@ -520,12 +511,10 @@ void InitGfx()
     if (i != PIX_SMALLFONT)
       LoadGfx(i,&pic[i]);
 
-#ifdef DEBUG_TIMING
-  count2 = Counter();
-  printf("SUMMARY: %.2f SECONDS LOADING TIME\n",(float)(count2-count1)/1000.0);
+#if DEBUG_TIMING
+  debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:");
 #endif
 
-
   pix[PIX_DB_BACK] = XCreatePixmap(display, window,
                                   WIN_XSIZE,WIN_YSIZE,
                                   XDefaultDepth(display,screen));
@@ -632,7 +621,7 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
   char basefilename[256];
   char filename[256];
 
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
   int xpm_err, xbm_err;
   unsigned int width,height;
   int hot_x,hot_y;
@@ -644,10 +633,6 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
   char *picture_ext = ".pcx";
 #endif
 
-#ifdef DEBUG_TIMING
-  long count1, count2;
-#endif
-
   /* Grafik laden */
   if (pic->picture_filename)
   {
@@ -660,17 +645,16 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
     rest(100);
 #endif MSDOS
 
-#ifdef DEBUG_TIMING
-    count1 = Counter();
+#if DEBUG_TIMING
+    debug_print_timestamp(1, NULL);    /* initialize timestamp function */
 #endif
 
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
 
     xpm_att[pos].valuemask = XpmCloseness;
     xpm_att[pos].closeness = 20000;
     xpm_err = XpmReadFileToPixmap(display,window,filename,
                                  &pix[pos],&shapemask,&xpm_att[pos]);
-
     switch(xpm_err)
     {
       case XpmOpenFailed:
@@ -685,17 +669,15 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
        break;
     }
 
-#ifdef DEBUG_TIMING
-    count2 = Counter();
-    printf("XPM LOADING %s IN %.2f SECONDS\n",
-          filename,(float)(count2-count1)/1000.0);
+#if DEBUG_TIMING
+    printf("LOADING XPM FILE %s:", filename);
+    debug_print_timestamp(1, "");
 #endif
 
-#else 
+#else /* !USE_XPM_LIBRARY */
 
     pcx_err = Read_PCX_to_Pixmaps(display, window, gc, filename,
                                  &pix[pos], &clipmask[pos]);
-
     switch(pcx_err)
     {
       case PCX_Success:
@@ -714,13 +696,12 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
        break;
     }
 
-#ifdef DEBUG_TIMING
-    count2 = Counter();
-    printf("PCX LOADING %s IN %.2f SECONDS\n",
-          filename,(float)(count2-count1)/1000.0);
+#if DEBUG_TIMING
+    printf("SUMMARY LOADING PCX FILE %s:", filename);
+    debug_print_timestamp(1, "");
 #endif
 
-#endif
+#endif /* !USE_XPM_LIBRARY */
 
     if (!pix[pos])
       Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
@@ -729,21 +710,19 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
   /* zugehörige Maske laden (wenn vorhanden) */
   if (pic->picture_with_mask)
   {
-
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
 
     sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext);
     DrawInitText(basefilename, 150, FC_YELLOW);
     sprintf(filename, "%s/%s/%s",
            options.base_directory, GRAPHICS_DIRECTORY, basefilename);
 
-#ifdef DEBUG_TIMING
-    count1 = Counter();
+#if DEBUG_TIMING
+    debug_print_timestamp(1, NULL);    /* initialize timestamp function */
 #endif
 
     xbm_err = XReadBitmapFile(display,window,filename,
                              &width,&height,&clipmask[pos],&hot_x,&hot_y);
-
     switch(xbm_err)
     {
       case BitmapSuccess:
@@ -759,13 +738,12 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
        break;
     }
 
-#ifdef DEBUG_TIMING
-    count2 = Counter();
-    printf("XBM LOADING %s IN %.2f SECONDS\n",
-          filename,(float)(count2-count1)/1000.0);
+#if DEBUG_TIMING
+    printf("LOADING XBM FILE %s:", filename);
+    debug_print_timestamp(1, "");
 #endif
 
-#endif
+#endif /* USE_XPM_LIBRARY */
 
     if (!clipmask[pos])
       Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
@@ -1341,8 +1319,8 @@ void CloseAllAndExit(int exit_value)
   {
     if (pix[i])
     {
-#ifdef XPM_INCLUDE_FILE
-      if (i<NUM_PICTURES)      /* XPM pictures */
+#ifdef USE_XPM_LIBRARY
+      if (i < NUM_PICTURES)    /* XPM pictures */
       {
        XFreeColors(display,DefaultColormap(display,screen),
                    xpm_att[i].pixels,xpm_att[i].npixels,0);
index be179b53be95de09c069970bd5dc4c8682e33d8b..6626f7019e4b509e9aed316aa390d659828166e2 100644 (file)
@@ -31,7 +31,7 @@ GC            gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
 Pixmap         pix[NUM_PIXMAPS];
 Pixmap         clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
 
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
 XpmAttributes  xpm_att[NUM_PICTURES];
 #endif
 
index d698ffdf42bc298a637096e09f35eb47e55bf4d7..602fce8c7c5aa3dcbd563914c69da0b6e1db31dc 100644 (file)
 #include <X11/keysymdef.h>
 
 #ifdef   XPM_INCLUDE_FILE
+#define  USE_XPM_LIBRARY
 #include XPM_INCLUDE_FILE
 #endif
 #else  /* MSDOS */
 #include "msdos.h"
 #endif  /* MSDOS */
 
+#ifdef DEBUG
+#define DEBUG_TIMING   0
+#endif
+
 typedef unsigned char boolean;
 typedef unsigned char byte;
 
@@ -222,7 +227,7 @@ struct OptionInfo
 
 struct SetupJoystickInfo
 {
-  char device_name[MAX_FILENAME_LEN];
+  char *device_name;
   int xleft, xmiddle, xright;
   int yupper, ymiddle, ylower;
   int snap;
@@ -248,6 +253,8 @@ struct SetupInputInfo
 
 struct SetupInfo
 {
+  char *player_name;
+
   boolean sound;
   boolean sound_loops;
   boolean sound_music;
@@ -262,9 +269,6 @@ struct SetupInfo
   boolean quick_doors;
   boolean team_mode;
 
-  char login_name[MAX_NAMELEN];
-  char alias_name[MAX_NAMELEN];
-
   struct SetupInputInfo input[MAX_PLAYERS];
 };
 
@@ -335,10 +339,11 @@ struct LevelInfo
 
 struct LevelDirInfo
 {
-  char filename[MAX_LEVDIR_FILENAME];
-  char name[MAX_LEVDIR_NAME];
+  char *filename;
+  char *name;
   int levels;
-  int readonly;
+  int sort_priority;
+  boolean readonly;
 };
 
 struct RecordingInfo
@@ -369,7 +374,7 @@ extern GC           gc, clip_gc[], tile_clip_gc;
 extern Pixmap          pix[];
 extern Pixmap          clipmask[], tile_clipmask[];
 
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
 extern XpmAttributes   xpm_att[];
 #endif
 
@@ -1083,16 +1088,16 @@ extern int              num_bg_loops;
 
 #ifndef MSDOS
 #define USERDATA_DIRECTORY     ".rocksndiamonds"
-#define LEVDIR_FILENAME                "ROCKS.levelinfo"
-#define SETUP_FILENAME         "setup"
-#define LEVELSETUP_FILENAME    "setup.level"
+#define SETUP_FILENAME         "setup.conf"
+#define LEVELSETUP_FILENAME    "levelsetup.conf"
+#define LEVELINFO_FILENAME     "levelinfo.conf"
 #define TAPEFILE_EXTENSION     "tape"
 #define SCOREFILE_EXTENSION    "score"
 #else
 #define USERDATA_DIRECTORY     "userdata"
-#define LEVDIR_FILENAME                "ROCKS.lev"
-#define SETUP_FILENAME         "setup"
-#define LEVELSETUP_FILENAME    "setup.lev"
+#define SETUP_FILENAME         "setup.cnf"
+#define LEVELSETUP_FILENAME    "lvlsetup.cnf"
+#define LEVELINFO_FILENAME     "lvlinfo.cnf"
 #define TAPEFILE_EXTENSION     "rec"
 #define SCOREFILE_EXTENSION    "sco"
 #endif
@@ -1119,6 +1124,7 @@ extern int                num_bg_loops;
 #define JOYSTICK_COOKIE                "ROCKSNDIAMONDS_JOYSTICK_FILE_VERSION_1.0"
 #define SETUP_COOKIE           "ROCKSNDIAMONDS_SETUP_FILE_VERSION_1.2"
 #define LEVELSETUP_COOKIE      "ROCKSNDIAMONDS_LEVELSETUP_FILE_VERSION_1.2"
+#define LEVELINFO_COOKIE       "ROCKSNDIAMONDS_LEVELINFO_FILE_VERSION_1.2"
 #define LEVEL_COOKIE_LEN       (strlen(LEVEL_COOKIE)+1)
 #define SCORE_COOKIE_LEN       (strlen(SCORE_COOKIE)+1)
 #define LEVELDIR_COOKIE_LEN    (strlen(LEVELDIR_COOKIE)+1)
@@ -1126,6 +1132,7 @@ extern int                num_bg_loops;
 #define JOYSTICK_COOKIE_LEN    (strlen(JOYSTICK_COOKIE)+1)
 #define SETUP_COOKIE_LEN       (strlen(SETUP_COOKIE)+1)
 #define LEVELSETUP_COOKIE_LEN  (strlen(LEVELSETUP_COOKIE)+1)
+#define LEVELINFO_COOKIE_LEN   (strlen(LEVELINFO_COOKIE)+1)
 
 #define VERSION_STRING         "1.2 preview 1"
 #define GAMETITLE_STRING       "Rocks'n'Diamonds"
index a7e52dcc4a71aaf2273ae986ec1ff2551ed46a50..8c88fe2930ff054b8a7721df85b53bdc9eddcd53 100644 (file)
@@ -210,6 +210,22 @@ char *getHomeDir()
   return home_dir;
 }
 
+char *getPath2(char *path1, char *path2)
+{
+  char *complete_path = checked_malloc(strlen(path1) + strlen(path2) + 2);
+
+  sprintf(complete_path, "%s/%s", path1, path2);
+  return complete_path;
+}
+
+char *getStringCopy(char *s)
+{
+  char *s_copy = checked_malloc(strlen(s) + 1);
+
+  strcpy(s_copy, s);
+  return s_copy;
+}
+
 void MarkTileDirty(int x, int y)
 {
   int xx = redraw_x1 + x;
@@ -363,7 +379,7 @@ void GetOptions(char *argv[])
   }
 }
 
-void Error(int mode, char *format_str, ...)
+void Error(int mode, char *format, ...)
 {
   FILE *output_stream = stderr;
   char *process_name = "";
@@ -371,53 +387,17 @@ void Error(int mode, char *format_str, ...)
   if (mode & ERR_SOUNDSERVER)
     process_name = " sound server";
 
-  if (format_str)
+  if (format)
   {
     va_list ap;
-    char *format_ptr;
-    char *s_value;
-    int i_value;
-    double d_value;
 
     fprintf(output_stream, "%s%s: ", program_name, process_name);
 
     if (mode & ERR_WARN)
       fprintf(output_stream, "warning: ");
 
-    va_start(ap, format_str);  /* ap points to first unnamed argument */
-  
-    for(format_ptr=format_str; *format_ptr; format_ptr++)
-    {
-      if (*format_ptr != '%')
-      {
-       fprintf(output_stream, "%c", *format_ptr);
-       continue;
-      }
-  
-      switch(*++format_ptr)
-      {
-       case 'd':
-         i_value = va_arg(ap, int);
-         fprintf(output_stream, "%d", i_value);
-         break;
-  
-       case 'f':
-         d_value = va_arg(ap, double);
-         fprintf(output_stream, "%f", d_value);
-         break;
-  
-       case 's':
-         s_value = va_arg(ap, char *);
-         fprintf(output_stream, "%s", s_value);
-         break;
-  
-       default:
-         fprintf(stderr, "\n%s: Error(): invalid format string: %s\n",
-                 program_name, format_str);
-         CloseAllAndExit(10);
-      }
-    }
-
+    va_start(ap, format);
+    vfprintf(output_stream, format, ap);
     va_end(ap);
   
     fprintf(output_stream, "\n");
@@ -786,3 +766,22 @@ int getJoySymbolFromJoyName(char *name)
   translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
   return joysymbol;
 }
+
+/* the following is only for debugging purpose and normally not used */
+#define DEBUG_NUM_TIMESTAMPS   3
+
+void debug_print_timestamp(int counter_nr, char *message)
+{
+  static long counter[DEBUG_NUM_TIMESTAMPS][2];
+
+  if (counter_nr >= DEBUG_NUM_TIMESTAMPS)
+    Error(ERR_EXIT, "debugging: increase DEBUG_NUM_TIMESTAMPS in misc.c");
+
+  counter[counter_nr][0] = Counter();
+
+  if (message)
+    printf("%s %.2f seconds\n", message,
+          (float)(counter[counter_nr][0] - counter[counter_nr][1]) / 1000);
+
+  counter[counter_nr][1] = Counter();
+}
index c01091757486e956a3b456b10635d2ba85b06e68..65f2966cfd39677f6d5347308f49043018527289 100644 (file)
@@ -41,6 +41,8 @@ unsigned int RND(unsigned int);
 unsigned int InitRND(long);
 char *getLoginName(void);
 char *getHomeDir(void);
+char *getPath2(char *, char *);
+char *getStringCopy(char *);
 void MarkTileDirty(int, int);
 void GetOptions(char **);
 void Error(int, char *, ...);
@@ -51,5 +53,6 @@ char *getX11KeyNameFromKeySym(KeySym);
 KeySym getKeySymFromX11KeyName(char *);
 char *getJoyNameFromJoySymbol(int);
 int getJoySymbolFromJoyName(char *);
+void debug_print_timestamp(int, char *);
 
-#endif
+#endif /* MISC_H */
index 890f405f91662423040114fc731f1db90c322af7..76b4e66fa9b9221876ca6eaa0c634237480159b2 100644 (file)
@@ -226,10 +226,11 @@ boolean ConnectToServer(char *host, int port)
 void SendToServer_Nickname(char *nickname)
 {
   static char msgbuf[300];
+  int len_nickname = strlen(nickname);
 
   buf[1] = OP_NICKNAME;
-  memcpy(&buf[2], nickname, strlen(nickname));
-  sendbuf(2 + strlen(nickname));
+  memcpy(&buf[2], nickname, len_nickname);
+  sendbuf(2 + len_nickname);
   sprintf(msgbuf, "you set your nick to \"%s\"", nickname);
   sysmsg(msgbuf);
 }
index 139c6d9ca3f8d89569df3d3d612d19ae6d71bebc..1ff8bd1d64402921ddb3560959c2992fc1d4d791 100644 (file)
@@ -53,7 +53,7 @@ void DrawMainMenu()
   ClearWindow();
   DrawHeadline();
   DrawText(SX + 32,    SY + 2*32, name_text, FS_BIG, FC_GREEN);
-  DrawText(SX + 6*32,  SY + 2*32, setup.alias_name, FS_BIG, FC_RED);
+  DrawText(SX + 6*32,  SY + 2*32, setup.player_name, FS_BIG, FC_RED);
   DrawText(SX + 32,    SY + 3*32, "Level:", FS_BIG, FC_GREEN);
   DrawText(SX + 11*32, SY + 3*32, int2str(level_nr,3), FS_BIG,
           (level_nr<leveldir[leveldir_nr].levels ? FC_RED : FC_YELLOW));
@@ -192,7 +192,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button)
       if (y==3)
       {
        game_status = TYPENAME;
-       HandleTypeName(strlen(setup.alias_name),0);
+       HandleTypeName(strlen(setup.player_name), 0);
       }
       else if (y==4)
       {
@@ -695,7 +695,7 @@ void HandleTypeName(int newxpos, KeySym key)
   if (newxpos)
   {
     xpos = newxpos;
-    DrawText(SX+6*32, SY+ypos*32, setup.alias_name, FS_BIG, FC_YELLOW);
+    DrawText(SX+6*32, SY+ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
     return;
   }
@@ -712,25 +712,25 @@ void HandleTypeName(int newxpos, KeySym key)
   if((ascii = get_ascii(key)) && xpos<MAX_NAMELEN-1)
   {
 #endif
-    setup.alias_name[xpos] = ascii;
-    setup.alias_name[xpos+1] = 0;
+    setup.player_name[xpos] = ascii;
+    setup.player_name[xpos+1] = 0;
     xpos++;
     DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32,
-               setup.alias_name,FS_BIG,FC_YELLOW);
+               setup.player_name,FS_BIG,FC_YELLOW);
     DrawTextExt(window,gc,SX+6*32,SY+ypos*32,
-               setup.alias_name,FS_BIG,FC_YELLOW);
+               setup.player_name,FS_BIG,FC_YELLOW);
     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
   }
   else if ((key==XK_Delete || key==XK_BackSpace) && xpos>0)
   {
     xpos--;
-    setup.alias_name[xpos] = 0;
+    setup.player_name[xpos] = 0;
     DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
     DrawGraphic(xpos+7,ypos,GFX_LEERRAUM);
   }
   else if (key==XK_Return && xpos>0)
   {
-    DrawText(SX+6*32,SY+ypos*32,setup.alias_name,FS_BIG,FC_RED);
+    DrawText(SX+6*32,SY+ypos*32,setup.player_name,FS_BIG,FC_RED);
     DrawGraphic(xpos+6,ypos,GFX_LEERRAUM);
 
     SaveSetup();
@@ -1187,7 +1187,7 @@ static void setJoystickDeviceToNr(char *device_name, int device_nr)
       device_name[strlen(device_name) - 1] = '0' + (char)(device_nr % 10);
   }
   else
-    strcpy(device_name, joystick_device_name[device_nr]);
+    strncpy(device_name, joystick_device_name[device_nr], strlen(device_name));
 }
 
 static void drawPlayerSetupInputInfo(int player_nr)