* misc.c *
***********************************************************/
-#include <pwd.h>
-#include <unistd.h>
#include <time.h>
#include <sys/time.h>
-#include <sys/param.h>
#include <sys/types.h>
#include <stdarg.h>
#include <ctype.h>
+#ifndef WIN32
+#include <pwd.h>
+#include <sys/param.h>
+#endif
+
#include "misc.h"
#include "init.h"
#include "tools.h"
#endif
-
/* maximal allowed length of a command line option */
#define MAX_OPTION_LEN 256
+#ifdef USE_SDL_LIBRARY
+
+static unsigned long mainCounter(int mode)
+{
+ static unsigned long base_ms = 0;
+ unsigned long current_ms;
+ unsigned long counter_ms;
+
+ current_ms = SDL_GetTicks();
+
+ /* reset base time in case of counter initializing or wrap-around */
+ if (mode == INIT_COUNTER || current_ms < base_ms)
+ base_ms = current_ms;
+
+ counter_ms = current_ms - base_ms;
+
+ return counter_ms; /* return milliseconds since last init */
+}
+
+#else /* !USE_SDL_LIBRARY */
#ifndef MSDOS
+
static unsigned long mainCounter(int mode)
{
static struct timeval base_time = { 0, 0 };
gettimeofday(¤t_time, NULL);
+ /* reset base time in case of counter initializing or wrap-around */
if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec)
base_time = current_time;
return counter_ms; /* return milliseconds since last init */
}
-#endif
+
+#endif /* !MSDOS */
+#endif /* !USE_SDL_LIBRARY */
void InitCounter() /* set counter back to zero */
{
boolean do_busy_waiting = (milliseconds_delay < 5 ? TRUE : FALSE);
#ifdef MSDOS
- /* donït use select() to perform waiting operations under DOS/Windows
+ /* don't use select() to perform waiting operations under DOS/Windows
environment; always use a busy loop for waiting instead */
do_busy_waiting = TRUE;
#endif
}
else
{
+#ifdef USE_SDL_LIBRARY
+ SDL_Delay(milliseconds_delay);
+#else /* !USE_SDL_LIBRARY */
struct timeval delay;
delay.tv_sec = milliseconds_delay / 1000;
if (select(0, NULL, NULL, NULL, &delay) != 0)
Error(ERR_WARN, "sleep_milliseconds(): select() failed");
+#endif /* !USE_SDL_LIBRARY */
}
}
unsigned int SimpleRND(unsigned int max)
{
+#ifdef USE_SDL_LIBRARY
+
+ static unsigned long root = 654321;
+ unsigned long current_ms;
+
+ current_ms = SDL_GetTicks();
+ root = root * 4253261 + current_ms;
+ return (root % max);
+
+#else /* !USE_SDL_LIBRARY */
+
static unsigned long root = 654321;
struct timeval current_time;
- gettimeofday(¤t_time,NULL);
+ gettimeofday(¤t_time, NULL);
root = root * 4253261 + current_time.tv_sec + current_time.tv_usec;
return (root % max);
+
+#endif /* !USE_SDL_LIBRARY */
}
#ifdef DEBUG
unsigned int InitRND(long seed)
{
+#ifdef USE_SDL_LIBRARY
+ unsigned long current_ms;
+
+ if (seed == NEW_RANDOMIZE)
+ {
+ current_ms = SDL_GetTicks();
+ srandom_linux_libc((unsigned int) current_ms);
+ return (unsigned int) current_ms;
+ }
+ else
+ {
+ srandom_linux_libc((unsigned int) seed);
+ return (unsigned int) seed;
+ }
+#else /* !USE_SDL_LIBRARY */
struct timeval current_time;
if (seed == NEW_RANDOMIZE)
{
- gettimeofday(¤t_time,NULL);
+ gettimeofday(¤t_time, NULL);
srandom_linux_libc((unsigned int) current_time.tv_usec);
- return (unsigned int)current_time.tv_usec;
+ return (unsigned int) current_time.tv_usec;
}
else
{
srandom_linux_libc((unsigned int) seed);
- return (unsigned int)seed;
+ return (unsigned int) seed;
}
+#endif /* !USE_SDL_LIBRARY */
}
char *getLoginName()
{
+#ifdef WIN32
+ return ANONYMOUS_NAME;
+#else
struct passwd *pwd;
if ((pwd = getpwuid(getuid())) == NULL)
return ANONYMOUS_NAME;
else
return pwd->pw_name;
+#endif
}
char *getRealName()
{
-#ifndef MSDOS
+#if defined(MSDOS) || defined(WIN32)
+ return ANONYMOUS_NAME;
+#else
struct passwd *pwd;
if ((pwd = getpwuid(getuid())) == NULL || strlen(pwd->pw_gecos) == 0)
return real_name;
}
-#else
- return ANONYMOUS_NAME;
#endif
}
char *getHomeDir()
{
-#ifndef MSDOS
+#if defined(MSDOS) || defined(WIN32)
+ return ".";
+#else
static char *home_dir = NULL;
if (!home_dir)
}
return home_dir;
-#else
- return ".";
#endif
}
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)
{
"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",
{
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);
if (mode & ERR_WARN && !options.verbose)
return;
-#ifdef MSDOS
+#if defined(MSDOS) || defined(WIN32)
if ((error = openErrorFile()) == NULL)
{
printf("Cannot write to error output file!\n");
{ KEY_Meta_R, "XK_Meta_R", "right meta" },
{ KEY_Alt_L, "XK_Alt_L", "left alt" },
{ KEY_Alt_R, "XK_Alt_R", "right alt" },
- { KEY_Mode_switch, "XK_Mode_switch", "mode switch" },
- { KEY_Multi_key, "XK_Multi_key", "multi key" },
+ { KEY_Super_L, "XK_Super_L", "left super" }, /* Win-L */
+ { KEY_Super_R, "XK_Super_R", "right super" }, /* Win-R */
+ { KEY_Mode_switch, "XK_Mode_switch", "mode switch" }, /* Alt-R */
+ { KEY_Multi_key, "XK_Multi_key", "multi key" }, /* Ctrl-R */
/* some special keys */
{ KEY_BackSpace, "XK_BackSpace", "backspace" },
{ KEY_End, "XK_End", "end" },
{ KEY_Page_Up, "XK_Page_Up", "page up" },
{ KEY_Page_Down, "XK_Page_Down", "page down" },
-
+ { KEY_Menu, "XK_Menu", "menu" }, /* Win-Menu */
/* ASCII 0x20 to 0x40 keys (except numbers) */
{ KEY_space, "XK_space", "space" },