rnd-20001125-3-src
[rocksndiamonds.git] / src / misc.c
index 8b86b89c3476d77a01244b9cf956bf1ce82309b4..3d448a69f57c10c39e18078c85e06aa0cbe769e1 100644 (file)
@@ -45,7 +45,7 @@ END_OF_FUNCTION(increment_counter);
 /* maximal allowed length of a command line option */
 #define MAX_OPTION_LEN         256
 
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
 
 static unsigned long mainCounter(int mode)
 {
@@ -64,7 +64,7 @@ static unsigned long mainCounter(int mode)
   return counter_ms;           /* return milliseconds since last init */
 }
 
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
 #ifndef MSDOS
 
 static unsigned long mainCounter(int mode)
@@ -86,7 +86,7 @@ static unsigned long mainCounter(int mode)
 }
 
 #endif /* !MSDOS */
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
 
 void InitCounter()             /* set counter back to zero */
 {
@@ -133,9 +133,9 @@ static void sleep_milliseconds(unsigned long milliseconds_delay)
   }
   else
   {
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
     SDL_Delay(milliseconds_delay);
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
     struct timeval delay;
 
     delay.tv_sec  = milliseconds_delay / 1000;
@@ -143,7 +143,7 @@ static void sleep_milliseconds(unsigned long milliseconds_delay)
 
     if (select(0, NULL, NULL, NULL, &delay) != 0)
       Error(ERR_WARN, "sleep_milliseconds(): select() failed");
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
   }
 }
 
@@ -228,7 +228,7 @@ char *int2str(int number, int size)
 
 unsigned int SimpleRND(unsigned int max)
 {
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
 
   static unsigned long root = 654321;
   unsigned long current_ms;
@@ -237,7 +237,7 @@ unsigned int SimpleRND(unsigned int max)
   root = root * 4253261 + current_ms;
   return (root % max);
 
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
 
   static unsigned long root = 654321;
   struct timeval current_time;
@@ -246,7 +246,7 @@ unsigned int SimpleRND(unsigned int max)
   root = root * 4253261 + current_time.tv_sec + current_time.tv_usec;
   return (root % max);
 
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
 }
 
 #ifdef DEBUG
@@ -269,7 +269,7 @@ unsigned int RND(unsigned int max)
 
 unsigned int InitRND(long seed)
 {
-#ifdef USE_SDL_LIBRARY
+#ifdef TARGET_SDL
   unsigned long current_ms;
 
   if (seed == NEW_RANDOMIZE)
@@ -283,7 +283,7 @@ unsigned int InitRND(long seed)
     srandom_linux_libc((unsigned int) seed);
     return (unsigned int) seed;
   }
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
   struct timeval current_time;
 
   if (seed == NEW_RANDOMIZE)
@@ -297,7 +297,7 @@ unsigned int InitRND(long seed)
     srandom_linux_libc((unsigned int) seed);
     return (unsigned int) seed;
   }
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
 }
 
 char *getLoginName()
@@ -464,6 +464,12 @@ void GetOptions(char *argv[])
   options.serveronly = FALSE;
   options.network = FALSE;
   options.verbose = FALSE;
+  options.debug = FALSE;
+
+  /* initialize some more global variables */
+  global.frames_per_second = 0;
+  global.fps_slowdown = FALSE;
+  global.fps_slowdown_factor = 1;
 
   while (*options_left)
   {
@@ -505,7 +511,7 @@ void GetOptions(char *argv[])
             "Options:\n"
             "  -d, --display machine:0       X server display\n"
             "  -b, --basepath directory      alternative base directory\n"
-            "  -l, --level directory        alternative level directory\n"
+            "  -l, --level directory         alternative level directory\n"
             "  -s, --serveronly              only start network server\n"
             "  -n, --network                 network multiplayer game\n"
             "  -v, --verbose                 verbose mode\n",
@@ -557,6 +563,10 @@ void GetOptions(char *argv[])
     {
       options.verbose = TRUE;
     }
+    else if (strncmp(option, "-debug", option_len) == 0)
+    {
+      options.debug = TRUE;
+    }
     else if (*option == '-')
     {
       Error(ERR_EXIT_HELP, "unrecognized option '%s'", option_str);
@@ -1172,8 +1182,13 @@ boolean validLevelSeries(struct LevelDirInfo *node)
 
 struct LevelDirInfo *getFirstValidLevelSeries(struct LevelDirInfo *node)
 {
-  if (node == NULL)            /* start with first level directory entry */
-    return getFirstValidLevelSeries(leveldir_first);
+  if (node == NULL)
+  {
+    if (leveldir_first)                /* start with first level directory entry */
+      return getFirstValidLevelSeries(leveldir_first);
+    else
+      return NULL;
+  }
   else if (node->node_group)   /* enter level group (step down into tree) */
     return getFirstValidLevelSeries(node->node_group);
   else if (node->parent_link)  /* skip start entry of level group */