From ae32fd8a4316c5d7f18fe6966f999ebf5509df94 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 5 Dec 2000 00:39:36 +0100 Subject: [PATCH] rnd-20001205-2-src --- src/init.c | 148 +++++++++---------------------------------- src/libgame/sdl.c | 25 ++++++++ src/libgame/sdl.h | 2 + src/libgame/system.c | 17 +++++ src/libgame/system.h | 2 + src/libgame/x11.c | 42 ++++++++++++ src/libgame/x11.h | 1 + 7 files changed, 118 insertions(+), 119 deletions(-) diff --git a/src/init.c b/src/init.c index d83b7542..ae65640f 100644 --- a/src/init.c +++ b/src/init.c @@ -27,12 +27,6 @@ #include "network.h" #include "netserv.h" -struct PictureFileInfo -{ - char *picture_filename; - boolean picture_with_mask; -}; - static void InitPlayerInfo(void); static void InitLevelInfo(void); static void InitNetworkServer(void); @@ -41,7 +35,6 @@ static void InitSoundServer(void); static void InitDisplay(void); static void InitGfx(void); static void InitGfxBackground(void); -static void LoadGfx(int, struct PictureFileInfo *); static void InitGadgets(void); static void InitElementProperties(void); @@ -333,32 +326,32 @@ void InitGfx() #endif #if !defined(PLATFORM_MSDOS) - static struct PictureFileInfo pic[NUM_PICTURES] = + static char *image_filename[NUM_PICTURES] = { - { "RocksScreen", TRUE }, - { "RocksDoor", TRUE }, - { "RocksHeroes", TRUE }, - { "RocksToons", TRUE }, - { "RocksSP", TRUE }, - { "RocksDC", TRUE }, - { "RocksMore", TRUE }, - { "RocksFont", FALSE }, - { "RocksFont2", FALSE }, - { "RocksFont3", FALSE } + "RocksScreen.pcx", + "RocksDoor.pcx", + "RocksHeroes.pcx", + "RocksToons.pcx", + "RocksSP.pcx", + "RocksDC.pcx", + "RocksMore.pcx", + "RocksFont.pcx", + "RocksFont2.pcx", + "RocksFont3.pcx" }; #else - static struct PictureFileInfo pic[NUM_PICTURES] = + static char *image_filename[NUM_PICTURES] = { - { "Screen", TRUE }, - { "Door", TRUE }, - { "Heroes", TRUE }, - { "Toons", TRUE }, - { "SP", TRUE }, - { "DC", TRUE }, - { "More", TRUE }, - { "Font", FALSE }, - { "Font2", FALSE }, - { "Font3", FALSE } + "Screen.pcx", + "Door.pcx", + "Heroes.pcx", + "Toons.pcx", + "SP.pcx", + "DC.pcx", + "More.pcx", + "Font.pcx", + "Font2.pcx", + "Font3.pcx" }; #endif @@ -432,7 +425,7 @@ void InitGfx() pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); - LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]); + pix[PIX_SMALLFONT] = LoadImage(image_filename[PIX_SMALLFONT]); InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); @@ -444,8 +437,13 @@ void InitGfx() DrawInitText("Loading graphics:",120,FC_GREEN); for(i=0; ipicture_filename) - { - sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext); - DrawInitText(basefilename, 150, FC_YELLOW); - sprintf(filename, "%s/%s/%s", - options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename); - -#if defined(PLATFORM_MSDOS) - rest(100); -#endif - - pix[pos] = CreateBitmapStruct(); - -#if defined(TARGET_SDL) - /* load image to temporary surface */ - if ((sdl_image_tmp = IMG_Load(filename)) == NULL) - Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError()); - - /* create native non-transparent surface for current image */ - if ((pix[pos]->surface = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - - /* create native transparent surface for current image */ - SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY, - SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00)); - if ((pix[pos]->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - - /* free temporary surface */ - SDL_FreeSurface(sdl_image_tmp); - -#else /* !TARGET_SDL */ - - pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, - filename, - &pix[pos]->drawable, &pix[pos]->clip_mask); - switch(pcx_err) - { - case PCX_Success: - break; - case PCX_OpenFailed: - Error(ERR_EXIT, "cannot open PCX file '%s'", filename); - case PCX_ReadFailed: - Error(ERR_EXIT, "cannot read PCX file '%s'", filename); - case PCX_FileInvalid: - Error(ERR_EXIT, "invalid PCX file '%s'", filename); - case PCX_NoMemory: - Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename); - case PCX_ColorFailed: - Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename); - default: - break; - } - - if (!pix[pos]->drawable) - Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); - - pix[pos]->gc = window->gc; - -#if 0 - /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always - use pix_masked[], although they are the same when not using SDL */ - pix_masked[pos] = pix[pos]; -#endif - -#endif /* !TARGET_SDL */ - } - -#if defined(TARGET_X11) - /* check if clip mask was correctly created */ - if (pic->picture_with_mask && !pix[pos]->clip_mask) - Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); -#endif -} - void InitGadgets() { CreateLevelEditorGadgets(); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 8f6fdee5..c9de611e 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -678,6 +678,31 @@ void sge_LineRGB(SDL_Surface *Surface, Sint16 x1, Sint16 y1, Sint16 x2, sge_Line(Surface, x1, y1, x2, y2, SDL_MapRGB(Surface->format, R, G, B)); } +Bitmap *SDLLoadImage(char *filename) +{ + Bitmap *new_bitmap = CreateBitmapStruct(); + SDL_Surface *sdl_image_tmp; + + /* load image to temporary surface */ + if ((sdl_image_tmp = IMG_Load(filename)) == NULL) + Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError()); + + /* 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()); + + /* 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()); + + /* free temporary surface */ + SDL_FreeSurface(sdl_image_tmp); + + return new_bitmap; +} + /* ========================================================================= */ /* audio functions */ diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 8f36722b..e6543a9e 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -324,6 +324,8 @@ inline void SDLDrawLine(SDL_Surface *, int, int, int, int, Uint32); /* functions from SGE library */ void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32); +Bitmap *SDLLoadImage(char *); + inline boolean SDLOpenAudio(void); inline void SDLCloseAudio(void); diff --git a/src/libgame/system.c b/src/libgame/system.c index b2909afd..7ee3e857 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -515,6 +515,23 @@ inline boolean ChangeVideoModeIfNeeded(boolean fullscreen) return fullscreen; } +Bitmap *LoadImage(char *basename) +{ + Bitmap *new_bitmap; + char filename[256]; + + sprintf(filename, "%s/%s/%s", + options.ro_base_directory, GRAPHICS_DIRECTORY, basename); + +#if defined(TARGET_SDL) + new_bitmap = SDLLoadImage(filename); +#else + new_bitmap = X11LoadImage(filename); +#endif + + return new_bitmap; +} + /* ========================================================================= */ /* audio functions */ diff --git a/src/libgame/system.h b/src/libgame/system.h index 81153193..e65cd99a 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -286,6 +286,8 @@ inline boolean PointerInWindow(DrawWindow *); inline boolean SetVideoMode(boolean); inline boolean ChangeVideoModeIfNeeded(boolean); +Bitmap *LoadImage(char *); + inline boolean OpenAudio(struct AudioSystemInfo *); inline void CloseAudio(struct AudioSystemInfo *); inline void SetAudioMode(boolean); diff --git a/src/libgame/x11.c b/src/libgame/x11.c index 7d33a623..196bd8e7 100644 --- a/src/libgame/x11.c +++ b/src/libgame/x11.c @@ -12,6 +12,7 @@ ***********************************************************/ #include "system.h" +#include "pcx.h" #include "misc.h" @@ -234,4 +235,45 @@ static DrawWindow *X11InitWindow() return new_window; } +Bitmap *X11LoadImage(char *filename) +{ + Bitmap *new_bitmap = CreateBitmapStruct(); + int pcx_err; + +#if defined(PLATFORM_MSDOS) + rest(100); +#endif + + pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, filename, + &new_bitmap->drawable, &new_bitmap->clip_mask); + switch(pcx_err) + { + case PCX_Success: + break; + case PCX_OpenFailed: + Error(ERR_EXIT, "cannot open PCX file '%s'", filename); + case PCX_ReadFailed: + Error(ERR_EXIT, "cannot read PCX file '%s'", filename); + case PCX_FileInvalid: + Error(ERR_EXIT, "invalid PCX file '%s'", filename); + case PCX_NoMemory: + Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename); + case PCX_ColorFailed: + Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename); + default: + break; + } + + if (!new_bitmap->drawable) + Error(ERR_EXIT, "cannot get graphics for '%s'", filename); + + if (!new_bitmap->clip_mask) + Error(ERR_EXIT, "cannot get clipmask for '%s'", filename); + + /* set GraphicContext inheritated from Window */ + new_bitmap->gc = window->gc; + + return new_bitmap; +} + #endif /* TARGET_X11 */ diff --git a/src/libgame/x11.h b/src/libgame/x11.h index e0f88e51..4f36b193 100644 --- a/src/libgame/x11.h +++ b/src/libgame/x11.h @@ -288,5 +288,6 @@ struct XY inline void X11InitVideoDisplay(void); inline void X11InitVideoBuffer(DrawBuffer **, DrawWindow **); +Bitmap *X11LoadImage(char *); #endif /* X11_H */ -- 2.34.1