***********************************************************/
#include <ctype.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "files.h"
#include "tools.h"
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;
#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
#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
static struct SetupInfo si;
static struct SetupInputInfo sii;
+struct LevelDirInfo ldi;
static struct
{
int type;
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" },
{ 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" },
{ 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)
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;
}
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;
}
{
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
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;
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;
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:
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];
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");
break;
case TYPE_STRING:
- strcat(entry, (char *)setup_value);
+ strcat(entry, *(char **)setup_value);
break;
default:
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 */
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()
#include "main.h"
-boolean LoadLevelInfo(void);
-
void LoadLevel(int);
void SaveLevel(int);
int getLastPlayedLevelOfLevelSeries(char *);
+void LoadLevelInfo(void);
void LoadSetup(void);
void SaveSetup(void);
void LoadLevelSetup(void);
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);
#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;
#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
#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
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];
redvalue = greenvalue = bluevalue = NULL;
ximageinfo = checked_malloc(sizeof(XImageInfo));
ximageinfo->display = display;
- ximageinfo->screen = screen;
ximageinfo->depth = depth;
switch (visual->class)
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 */
}
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;
}
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,
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);
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;
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 */
#include "network.h"
#include "netserv.h"
-#ifdef DEBUG
-
-#define DEBUG_TIMING
-
-#endif
-
struct PictureFileInfo
{
char *picture_filename;
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 */
}
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)
{ -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]);
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));
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;
char *picture_ext = ".pcx";
#endif
-#ifdef DEBUG_TIMING
- long count1, count2;
-#endif
-
/* Grafik laden */
if (pic->picture_filename)
{
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:
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:
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);
/* 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:
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);
{
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);
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
#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;
struct SetupJoystickInfo
{
- char device_name[MAX_FILENAME_LEN];
+ char *device_name;
int xleft, xmiddle, xright;
int yupper, ymiddle, ylower;
int snap;
struct SetupInfo
{
+ char *player_name;
+
boolean sound;
boolean sound_loops;
boolean sound_music;
boolean quick_doors;
boolean team_mode;
- char login_name[MAX_NAMELEN];
- char alias_name[MAX_NAMELEN];
-
struct SetupInputInfo input[MAX_PLAYERS];
};
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
extern Pixmap pix[];
extern Pixmap clipmask[], tile_clipmask[];
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
extern XpmAttributes xpm_att[];
#endif
#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
#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)
#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"
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;
}
}
-void Error(int mode, char *format_str, ...)
+void Error(int mode, char *format, ...)
{
FILE *output_stream = stderr;
char *process_name = "";
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");
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();
+}
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 *, ...);
KeySym getKeySymFromX11KeyName(char *);
char *getJoyNameFromJoySymbol(int);
int getJoySymbolFromJoyName(char *);
+void debug_print_timestamp(int, char *);
-#endif
+#endif /* MISC_H */
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);
}
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));
if (y==3)
{
game_status = TYPENAME;
- HandleTypeName(strlen(setup.alias_name),0);
+ HandleTypeName(strlen(setup.player_name), 0);
}
else if (y==4)
{
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;
}
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();
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)