From 93806fb4c23f4b6ef58d9562e908a1b89ece869d Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sun, 24 Mar 2002 18:02:31 +0100 Subject: [PATCH] rnd-20020324-2-src --- src/init.c | 197 +++++++++++++++++++++++++++---------------- src/libgame/image.c | 31 ++++--- src/libgame/misc.c | 17 ++++ src/libgame/misc.h | 5 ++ src/libgame/pcx.h | 1 + src/libgame/sdl.c | 15 +++- src/libgame/setup.c | 29 +++++++ src/libgame/setup.h | 1 + src/libgame/system.c | 12 +-- src/libgame/system.h | 12 ++- src/libgame/x11.c | 32 +++++-- src/main.c | 2 + src/main.h | 3 + 13 files changed, 255 insertions(+), 102 deletions(-) diff --git a/src/init.c b/src/init.c index bb185774..70604f2a 100644 --- a/src/init.c +++ b/src/init.c @@ -24,11 +24,26 @@ #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); @@ -49,7 +64,7 @@ void OpenAll(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(); @@ -70,6 +85,8 @@ void OpenAll(void) InitLevelInfo(); InitGadgets(); /* needs to know number of level series */ + InitCustomGraphics(); + InitGfxBackground(); DrawMainMenu(); @@ -144,46 +161,14 @@ void InitSound() 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 { @@ -238,43 +223,7 @@ void InitGfx() }; #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/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; @@ -1524,9 +1572,12 @@ void CloseAllAndExit(int exit_value) CloseAudio(); for(i=0; itype == 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) { @@ -392,7 +396,10 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, } 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; @@ -412,9 +419,9 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, 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 @@ -483,9 +490,9 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, } 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; } @@ -514,9 +521,9 @@ XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, } 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) @@ -586,7 +593,7 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, /* 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)) diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 9fc0cf04..b0244aa6 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -584,6 +584,23 @@ void GetOptions(char *argv[]) } } +/* 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 = ""; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 453c5640..fbfc9023 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -70,8 +70,13 @@ char *getPath2(char *, char *); 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); diff --git a/src/libgame/pcx.h b/src/libgame/pcx.h index 9c345dc1..8bfd0777 100644 --- a/src/libgame/pcx.h +++ b/src/libgame/pcx.h @@ -26,6 +26,7 @@ #define PCX_FileInvalid -3 #define PCX_NoMemory -4 #define PCX_ColorFailed -5 +#define PCX_OtherError -6 /* global PCX error value */ extern int errno_pcx; diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 7cd64118..c4e15425 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -829,17 +829,26 @@ Bitmap *SDLLoadImage(char *filename) /* 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); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index fcc105bd..0b39ff7c 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -218,6 +218,35 @@ char *getSetupFilename() 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); diff --git a/src/libgame/setup.h b/src/libgame/setup.h index a467079a..d702ef1f 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -110,6 +110,7 @@ char *getLevelFilename(int); char *getTapeFilename(int); char *getScoreFilename(int); char *getSetupFilename(void); +char *getImageFilename(char *); void InitTapeDirectory(char *); void InitScoreDirectory(char *); diff --git a/src/libgame/system.c b/src/libgame/system.c index a91d2438..423570dd 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -36,6 +36,7 @@ struct OptionInfo options; struct VideoSystemInfo video; struct AudioSystemInfo audio; struct GfxInfo gfx; +struct ArtworkInfo artwork; struct JoystickInfo joystick; struct SetupInfo setup; @@ -113,7 +114,8 @@ void InitProgramInfo(char *unix_userdata_directory, char *program_title, 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); @@ -134,7 +136,10 @@ void InitProgramInfo(char *unix_userdata_directory, char *program_title, 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); @@ -588,10 +593,9 @@ inline boolean ChangeVideoModeIfNeeded(boolean fullscreen) 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); @@ -599,8 +603,6 @@ Bitmap *LoadImage(char *basename) new_bitmap = X11LoadImage(filename); #endif - free(filename); - return new_bitmap; } diff --git a/src/libgame/system.h b/src/libgame/system.h index 6800aeaf..e1456a96 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -172,6 +172,7 @@ struct ProgramInfo char *msdos_pointer_filename; char *cookie_prefix; + char *filename_prefix; /* prefix to cut off from DOS filenames */ int version_major; int version_minor; @@ -238,6 +239,14 @@ struct GfxInfo int vxsize, vysize; }; +struct ArtworkInfo +{ + char *custom_artwork; + char *custom_graphics; + char *custom_sounds; + char *custom_music; +}; + struct JoystickInfo { int status; @@ -334,6 +343,7 @@ extern struct OptionInfo options; extern struct VideoSystemInfo video; extern struct AudioSystemInfo audio; extern struct GfxInfo gfx; +extern struct ArtworkInfo artwork; extern struct JoystickInfo joystick; extern struct SetupInfo setup; @@ -367,7 +377,7 @@ void InitPlatformDependantStuff(void); 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); diff --git a/src/libgame/x11.c b/src/libgame/x11.c index 6adfc11d..fd1d8b80 100644 --- a/src/libgame/x11.c +++ b/src/libgame/x11.c @@ -234,6 +234,7 @@ static DrawWindow *X11InitWindow() Bitmap *X11LoadImage(char *filename) { Bitmap *new_bitmap = CreateBitmapStruct(); + char *error = "Read_PCX_to_Pixmap(): %s '%s'"; int pcx_err; #if defined(PLATFORM_MSDOS) @@ -247,24 +248,39 @@ Bitmap *X11LoadImage(char *filename) 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; diff --git a/src/main.c b/src/main.c index 8533d336..210bf381 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,8 @@ 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; diff --git a/src/main.h b/src/main.h index 5c7c417c..40b06764 100644 --- a/src/main.h +++ b/src/main.h @@ -337,6 +337,8 @@ struct GlobalInfo 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; @@ -1464,6 +1466,7 @@ extern int num_element_info; #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" -- 2.34.1