#include "network.h"
#include "netserv.h"
+static char *image_filename[NUM_PICTURES] =
+{
+ "RocksScreen.pcx",
+ "RocksDoor.pcx",
+ "RocksHeroes.pcx",
+ "RocksToons.pcx",
+ "RocksSP.pcx",
+ "RocksDC.pcx",
+ "RocksMore.pcx",
+ "RocksFont.pcx",
+ "RocksFont2.pcx",
+ "RocksFont3.pcx"
+};
+
static void InitPlayerInfo(void);
static void InitLevelInfo(void);
static void InitNetworkServer(void);
static void InitSound(void);
static void InitGfx(void);
+static void InitCustomGraphics(void);
static void InitGfxBackground(void);
static void InitGadgets(void);
static void InitElementProperties(void);
PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING,
ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
MSDOS_POINTER_FILENAME,
- COOKIE_PREFIX, GAME_VERSION_ACTUAL);
+ COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
InitPlayerInfo();
InitLevelInfo();
InitGadgets(); /* needs to know number of level series */
+ InitCustomGraphics();
+
InitGfxBackground();
DrawMainMenu();
StartSoundserver();
}
-void InitGfx()
+void InitTileClipmasks()
{
- int i;
-
#if defined(TARGET_X11)
GC copy_clipmask_gc;
XGCValues clip_gc_values;
unsigned long clip_gc_valuemask;
#endif
-#if !defined(PLATFORM_MSDOS)
- static char *image_filename[NUM_PICTURES] =
- {
- "RocksScreen.pcx",
- "RocksDoor.pcx",
- "RocksHeroes.pcx",
- "RocksToons.pcx",
- "RocksSP.pcx",
- "RocksDC.pcx",
- "RocksMore.pcx",
- "RocksFont.pcx",
- "RocksFont2.pcx",
- "RocksFont3.pcx"
- };
-#else
- static char *image_filename[NUM_PICTURES] =
- {
- "Screen.pcx",
- "Door.pcx",
- "Heroes.pcx",
- "Toons.pcx",
- "SP.pcx",
- "DC.pcx",
- "More.pcx",
- "Font.pcx",
- "Font2.pcx",
- "Font3.pcx"
- };
-#endif
-
#if defined(TARGET_X11_NATIVE)
static struct
{
};
#endif
- /* initialize some global variables */
- global.frames_per_second = 0;
- global.fps_slowdown = FALSE;
- global.fps_slowdown_factor = 1;
-
- /* initialize screen properties */
- InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
- REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
- InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
- InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
- InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
-
- /* create additional image buffers for double-buffering */
- pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
- pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
-
- pix[PIX_SMALLFONT] = LoadImage(image_filename[PIX_SMALLFONT]);
- InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
-
- DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
- DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
-#if defined(PLATFORM_MSDOS)
- DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
- rest(200);
-#endif
- DrawInitText("Loading graphics:",120,FC_GREEN);
-
- for(i=0; i<NUM_PICTURES; i++)
- {
- if (i != PIX_SMALLFONT)
- {
- DrawInitText(image_filename[i], 150, FC_YELLOW);
- pix[i] = LoadImage(image_filename[i]);
- }
- }
-
- InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
+ int i;
/* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
for(i=0; i<NUM_TILES; i++)
#endif /* TARGET_X11 */
}
+void InitGfx()
+{
+ char *filename;
+ int i;
+
+ /* initialize some global variables */
+ global.frames_per_second = 0;
+ global.fps_slowdown = FALSE;
+ global.fps_slowdown_factor = 1;
+
+ /* initialize screen properties */
+ InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
+ REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+ InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
+ InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
+ InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
+
+ /* create additional image buffers for double-buffering */
+ pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
+ pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
+
+ filename = getImageFilename(image_filename[PIX_SMALLFONT]);
+ if ((pix_default[PIX_SMALLFONT] = LoadImage(filename)) == NULL)
+ Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
+ pix_custom[PIX_SMALLFONT] = NULL;
+ pix[PIX_SMALLFONT] = pix_default[PIX_SMALLFONT];
+
+ InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
+
+ DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
+ DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
+#if defined(PLATFORM_MSDOS)
+ DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
+ rest(200);
+#endif
+ DrawInitText("Loading graphics:",120,FC_GREEN);
+
+ for(i=0; i<NUM_PICTURES; i++)
+ {
+ if (i != PIX_SMALLFONT)
+ {
+ DrawInitText(image_filename[i], 150, FC_YELLOW);
+
+ filename = getImageFilename(image_filename[i]);
+ if ((pix_default[i] = LoadImage(filename)) == NULL)
+ Error(ERR_EXIT, "LoadImage() failed: %s", GetError());
+ pix_custom[i] = NULL;
+ pix[i] = pix_default[i];
+ }
+ }
+
+ InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
+
+ InitTileClipmasks();
+}
+
+void LoadCustomGraphics()
+{
+#if 0
+ int i;
+
+ for(i=0; i<NUM_PICTURES; i++)
+ {
+ Bitmap *new_pic =
+ pix_custom[i] = LoadImage(image_filename[i]);
+ }
+#endif
+}
+
+void InitCustomGraphics()
+{
+#if 0
+ static char *filename = NULL;
+
+ /* look for optional directory ~/.<program>/graphics */
+ filename = getPath2(getUserDataDir(), GRAPHICS_DIRECTORY);
+ if (access(dir, F_OK) == 0)
+ {
+ }
+
+
+
+
+(leveldir_current->user_defined ?
+ getUserLevelDir("") :
+ options.level_directory),
+ leveldir_current->fullpath,
+ basename);
+
+
+
+ filename = getPath3((leveldir_current->user_defined ?
+ getUserLevelDir("") :
+ options.level_directory),
+ leveldir_current->fullpath,
+ basename);
+#endif
+}
+
void InitGfxBackground()
{
int x, y;
CloseAudio();
for(i=0; i<NUM_BITMAPS; i++)
- FreeBitmap(pix[i]);
- CloseVideoDisplay();
+ {
+ FreeBitmap(pix_default[i]);
+ FreeBitmap(pix_custom[i]);
+ }
+ CloseVideoDisplay();
ClosePlatformDependantStuff();
exit(exit_value);
XImage *ximage;
XImageInfo *ximageinfo;
byte *src_ptr, *dst_ptr;
+ char *error = "Image_to_Pixmap(): %s";
if (image->type == IMAGETYPE_TRUECOLOR && depth == 8)
- Error(ERR_EXIT, "cannot handle true-color images on 8-bit display");
+ {
+ SetError(error, "cannot handle true-color images on 8-bit display");
+ return NULL;
+ }
if (!global_cmap)
{
}
if (!color_found) /* no more free color cells */
- Error(ERR_EXIT, "cannot allocate enough color cells");
+ {
+ SetError(error, "cannot allocate enough color cells");
+ return NULL;
+ }
xcolor.pixel = xcolor2.pixel;
xcolor_private[xcolor.pixel] = xcolor;
break;
default:
- Error(ERR_RETURN, "display class not supported");
- Error(ERR_EXIT, "DirectColor, TrueColor or PseudoColor display needed");
- break;
+ Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed");
+ SetError(error, "display class not supported");
+ return NULL;
}
#if DEBUG_TIMING
}
default:
- Error(ERR_RETURN, "image type not supported");
- Error(ERR_EXIT, "RGB or TrueColor image needed");
- break;
+ Error(ERR_RETURN, "RGB or TrueColor image needed");
+ SetError(error, "image type not supported");
+ return NULL;
}
break;
}
}
default:
- Error(ERR_RETURN, "display class not supported");
- Error(ERR_EXIT, "DirectColor, TrueColor or PseudoColor display needed");
- break;
+ Error(ERR_RETURN,"DirectColor, TrueColor or PseudoColor display needed");
+ SetError(error, "display class not supported");
+ return NULL;
}
if (redvalue)
/* convert image structure to X11 Pixmap */
if (!(ximageinfo = Image_to_Pixmap(display, screen, visual,
window, gc, depth, image)))
- Error(ERR_EXIT, "cannot convert Image to Pixmap");
+ return PCX_OtherError;
/* if a private colormap has been created, install it */
if (ximageinfo->cmap != DefaultColormap(display, screen))
}
}
+/* used by SetError() and GetError() to store internal error messages */
+static char internal_error[1024]; /* this is bad */
+
+void SetError(char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ vsprintf(internal_error, format, ap);
+ va_end(ap);
+}
+
+char *GetError()
+{
+ return internal_error;
+}
+
void Error(int mode, char *format, ...)
{
char *process_name = "";
char *getPath3(char *, char *, char*);
char *getStringCopy(char *);
char *getStringToLower(char *);
+
void GetOptions(char **);
+
+void SetError(char *, ...);
+char *GetError(void);
void Error(int, char *, ...);
+
void *checked_malloc(unsigned long);
void *checked_calloc(unsigned long);
void *checked_realloc(void *, unsigned long);
#define PCX_FileInvalid -3
#define PCX_NoMemory -4
#define PCX_ColorFailed -5
+#define PCX_OtherError -6
/* global PCX error value */
extern int errno_pcx;
/* load image to temporary surface */
if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
- Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
+ {
+ SetError("IMG_Load(): %s", SDL_GetError());
+ return NULL;
+ }
/* create native non-transparent surface for current image */
if ((new_bitmap->surface = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
+ {
+ SetError("SDL_DisplayFormat(): %s", SDL_GetError());
+ return NULL;
+ }
/* create native transparent surface for current image */
SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
if ((new_bitmap->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
- Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
+ {
+ SetError("SDL_DisplayFormat(): %s", SDL_GetError());
+ return NULL;
+ }
/* free temporary surface */
SDL_FreeSurface(sdl_image_tmp);
return filename;
}
+static char *getImageBasename(char *basename)
+{
+ char *result = basename;
+
+#if defined(PLATFORM_MSDOS)
+ if (program.filename_prefix != NULL)
+ {
+ int prefix_len = strlen(program.filename_prefix);
+
+ if (strncmp(basename, program.filename_prefix, prefix_len) == 0)
+ result = &basename[prefix_len];
+ }
+#endif
+
+ return result;
+}
+
+char *getImageFilename(char *basename)
+{
+ static char *filename = NULL;
+
+ if (filename != NULL)
+ free(filename);
+
+ filename = getPath2(options.graphics_directory, getImageBasename(basename));
+
+ return filename;
+}
+
void InitTapeDirectory(char *level_subdir)
{
createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE);
char *getTapeFilename(int);
char *getScoreFilename(int);
char *getSetupFilename(void);
+char *getImageFilename(char *);
void InitTapeDirectory(char *);
void InitScoreDirectory(char *);
struct VideoSystemInfo video;
struct AudioSystemInfo audio;
struct GfxInfo gfx;
+struct ArtworkInfo artwork;
struct JoystickInfo joystick;
struct SetupInfo setup;
char *window_title, char *icon_title,
char *x11_icon_basename, char *x11_iconmask_basename,
char *msdos_pointer_basename,
- char *cookie_prefix, int program_version)
+ char *cookie_prefix, char *filename_prefix,
+ int program_version)
{
char *x11_icon_filename =
getPath2(options.graphics_directory, x11_icon_basename);
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.filename_prefix = filename_prefix;
+
program.version_major = VERSION_MAJOR(program_version);
program.version_minor = VERSION_MINOR(program_version);
program.version_patch = VERSION_PATCH(program_version);
return fullscreen;
}
-Bitmap *LoadImage(char *basename)
+Bitmap *LoadImage(char *filename)
{
Bitmap *new_bitmap;
- char *filename = getPath2(options.graphics_directory, basename);
#if defined(TARGET_SDL)
new_bitmap = SDLLoadImage(filename);
new_bitmap = X11LoadImage(filename);
#endif
- free(filename);
-
return new_bitmap;
}
char *msdos_pointer_filename;
char *cookie_prefix;
+ char *filename_prefix; /* prefix to cut off from DOS filenames */
int version_major;
int version_minor;
int vxsize, vysize;
};
+struct ArtworkInfo
+{
+ char *custom_artwork;
+ char *custom_graphics;
+ char *custom_sounds;
+ char *custom_music;
+};
+
struct JoystickInfo
{
int status;
extern struct VideoSystemInfo video;
extern struct AudioSystemInfo audio;
extern struct GfxInfo gfx;
+extern struct ArtworkInfo artwork;
extern struct JoystickInfo joystick;
extern struct SetupInfo setup;
void ClosePlatformDependantStuff(void);
void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
- char *, int);
+ char *, char *, int);
void InitGfxFieldInfo(int, int, int, int, int, int, int, int);
void InitGfxDoor1Info(int, int, int, int);
Bitmap *X11LoadImage(char *filename)
{
Bitmap *new_bitmap = CreateBitmapStruct();
+ char *error = "Read_PCX_to_Pixmap(): %s '%s'";
int pcx_err;
#if defined(PLATFORM_MSDOS)
case PCX_Success:
break;
case PCX_OpenFailed:
- Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
+ SetError(error, "cannot open PCX file", filename);
+ return NULL;
case PCX_ReadFailed:
- Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
+ SetError(error, "cannot read PCX file", filename);
+ return NULL;
case PCX_FileInvalid:
- Error(ERR_EXIT, "invalid PCX file '%s'", filename);
+ SetError(error, "invalid PCX file", filename);
+ return NULL;
case PCX_NoMemory:
- Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
+ SetError(error, "not enough memory for PCX file", filename);
+ return NULL;
case PCX_ColorFailed:
- Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
+ SetError(error, "cannot get colors for PCX file", filename);
+ return NULL;
+ case PCX_OtherError:
+ /* this should already have called SetError() */
+ return NULL;
default:
- break;
+ SetError(error, "unknown error reading PCX file", filename);
+ return NULL;
}
if (!new_bitmap->drawable)
- Error(ERR_EXIT, "cannot get graphics for '%s'", filename);
+ {
+ SetError("X11LoadImage(): cannot get graphics for '%s'", filename);
+ return NULL;
+ }
if (!new_bitmap->clip_mask)
- Error(ERR_EXIT, "cannot get clipmask for '%s'", filename);
+ {
+ SetError("X11LoadImage(): cannot get clipmask for '%s'", filename);
+ return NULL;
+ }
/* set GraphicContext inheritated from Window */
new_bitmap->gc = window->gc;
GC tile_clip_gc;
Bitmap *pix[NUM_BITMAPS];
+Bitmap *pix_default[NUM_BITMAPS];
+Bitmap *pix_custom[NUM_BITMAPS];
Pixmap tile_clipmask[NUM_TILES];
DrawBuffer *fieldbuffer;
DrawBuffer *drawto_field;
extern GC tile_clip_gc;
extern Bitmap *pix[];
+extern Bitmap *pix_default[];
+extern Bitmap *pix_custom[];
extern Pixmap tile_clipmask[];
extern DrawBuffer *fieldbuffer;
extern DrawBuffer *drawto_field;
#define ICON_TITLE_STRING PROGRAM_TITLE_STRING
#define UNIX_USERDATA_DIRECTORY ".rocksndiamonds"
#define COOKIE_PREFIX "ROCKSNDIAMONDS"
+#define FILENAME_PREFIX "Rocks"
#define X11_ICON_FILENAME "rocks_icon.xbm"
#define X11_ICONMASK_FILENAME "rocks_iconmask.xbm"