X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=134cf74aeadfee1f092b95fb9496cb1adc9b2b09;hb=33df7a5ca87e883c2b718171fd7d05c22fc0353f;hp=8032ffb3d82bd798bd690dea25364937cdc4c3a8;hpb=c3d03cdffce070695ba0520d00667b42b8460087;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 8032ffb3..134cf74a 100644 --- a/src/init.c +++ b/src/init.c @@ -16,11 +16,42 @@ #include "misc.h" #include "sound.h" #include "screens.h" +#include "tools.h" #include "files.h" +#include "joystick.h" +#include "gfxloader.h" + #include +#ifdef DEBUG +/* +#define DEBUG_TIMING +*/ +#endif + +struct PictureFileInfo +{ + char *picture_filename; + BOOL picture_with_mask; +}; + +struct IconFileInfo +{ + char *picture_filename; + char *picturemask_filename; +}; + static int sound_process_id = 0; +static void InitLevelAndPlayerInfo(void); +static void InitDisplay(int, char **); +static void InitSound(void); +static void InitSoundProcess(void); +static void InitWindow(int, char **); +static void InitGfx(void); +static void LoadGfx(int, struct PictureFileInfo *); +static void InitElementProperties(void); + void OpenAll(int argc, char *argv[]) { InitLevelAndPlayerInfo(); @@ -36,13 +67,14 @@ void OpenAll(int argc, char *argv[]) InitDisplay(argc, argv); InitWindow(argc, argv); + + XMapWindow(display, window); + XFlush(display); + InitGfx(); InitElementProperties(); DrawMainMenu(); - - XMapWindow(display, window); - XFlush(display); } void InitLevelAndPlayerInfo() @@ -191,10 +223,10 @@ void InitWindow(int argc, char *argv[]) XTextProperty windowName, iconName; XGCValues gc_values; unsigned long gc_valuemask; - char *window_name = "Rocks'n'Diamonds"; - char *icon_name = "Rocks'n'Diamonds"; + char *window_name = WINDOWTITLE_STRING; + char *icon_name = WINDOWTITLE_STRING; long window_event_mask; - static struct PictureFile icon_pic = + static struct IconFileInfo icon_pic = { "rocks_icon.xbm", "rocks_iconmask.xbm" @@ -277,105 +309,51 @@ void InitWindow(int argc, char *argv[]) gc = XCreateGC(display, window, gc_valuemask, &gc_values); } +void DrawInitText(char *text, int ypos, int color) +{ + if (display && window && pix[PIX_SMALLFONT]) + { + XFillRectangle(display,window,gc,0,ypos, WIN_XSIZE,FONT2_YSIZE); + DrawTextExt(window,gc,(WIN_XSIZE-strlen(text)*FONT2_XSIZE)/2, + ypos,text,FS_SMALL,color); + XFlush(display); + } +} + void InitGfx() { - int i,j,x,y; - int xpm_err, xbm_err; - unsigned int width,height; - int hot_x,hot_y; - XGCValues gc_values; - unsigned long gc_valuemask; + int i,j; XGCValues clip_gc_values; unsigned long clip_gc_valuemask; - char filename[256]; - Pixmap shapemask; - - static struct PictureFile pic[NUM_PICTURES] = + static struct PictureFileInfo pic[NUM_PICTURES] = { - "RocksScreen.xpm", "RocksScreenMaske.xbm", - "RocksDoor.xpm", "RocksDoorMaske.xbm", - "RocksToons.xpm", "RocksToonsMaske.xbm", - "RocksFont.xpm", NULL, - "RocksFont2.xpm", NULL + { "RocksScreen", TRUE }, + { "RocksDoor", TRUE }, + { "RocksHeroes", TRUE }, + { "RocksToons", TRUE }, + { "RocksFont", FALSE }, + { "RocksFont2", FALSE } }; - for(i=0;ipicture_filename) + { + sprintf(basefilename,"%s%s",pic->picture_filename,picture_ext); + DrawInitText(basefilename,150,FC_YELLOW); + sprintf(filename,"%s/%s",GFX_PATH,basefilename); + +#ifdef DEBUG_TIMING + count1 = Counter(); +#endif + +#ifdef XPM_INCLUDE_FILE + + 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: + fprintf(stderr,"Cannot open Xpm file '%s' !\n",filename); + CloseAll(); + exit(-1); + case XpmFileInvalid: + fprintf(stderr,"Invalid Xpm file '%s'!\n",filename); + CloseAll(); + exit(-1); + case XpmNoMemory: + fprintf(stderr,"Not enough memory for Xpm file '%s'!\n",filename); + CloseAll(); + exit(1); + case XpmColorFailed: + fprintf(stderr,"Can't get colors for Xpm file '%s'!\n",filename); + CloseAll(); + exit(-1); + default: + break; + } + +#else + + gif_err = Read_GIF_to_Pixmap(display,filename,&pix[pos]); + + switch(gif_err) + { + case GIF_Success: + break; + case GIF_OpenFailed: + fprintf(stderr,"Cannot open GIF file '%s' !\n",filename); + CloseAll(); + exit(-1); + case GIF_ReadFailed: + fprintf(stderr,"Cannot read GIF file '%s' !\n",filename); + CloseAll(); + exit(-1); + case GIF_FileInvalid: + fprintf(stderr,"Invalid GIF file '%s'!\n",filename); + CloseAll(); + exit(-1); + case GIF_NoMemory: + fprintf(stderr,"Not enough memory for GIF file '%s'!\n",filename); + CloseAll(); + exit(1); + case GIF_ColorFailed: + fprintf(stderr,"Can't get colors for GIF file '%s'!\n",filename); + CloseAll(); + exit(-1); + default: + break; + } + +#endif + +#ifdef DEBUG_TIMING + count2 = Counter(); + printf("LOADING %s IN %.2f SECONDS\n", + filename,(float)(count2-count1)/100.0); +#endif + + if (!pix[pos]) + { + fprintf(stderr, "%s: cannot read graphics file '%s'.\n", + progname,filename); + CloseAll(); + exit(-1); + } + } + + /* zugehörige Maske laden (wenn vorhanden) */ + if (pic->picture_with_mask) + { + sprintf(basefilename,"%s%s",pic->picture_filename,picturemask_ext); + DrawInitText(basefilename,150,FC_YELLOW); + sprintf(filename,"%s/%s",GFX_PATH,basefilename); + +#ifdef DEBUG_TIMING + count1 = Counter(); +#endif + +#ifdef XPM_INCLUDE_FILE + + xbm_err = XReadBitmapFile(display,window,filename, + &width,&height,&clipmask[pos],&hot_x,&hot_y); + switch(xbm_err) + { + case BitmapSuccess: + break; + case BitmapOpenFailed: + fprintf(stderr,"Bitmap file open failed on '%s' !\n",filename); + CloseAll(); + exit(-1); + break; + case BitmapFileInvalid: + fprintf(stderr,"Bitmap file invalid: '%s' !\n",filename); + CloseAll(); + exit(-1); + break; + case BitmapNoMemory: + fprintf(stderr,"No memory for file '%s' !\n",filename); + CloseAll(); + exit(-1); + break; + default: + break; + } + +#else + + ilbm_err = Read_ILBM_to_Bitmap(display,filename,&clipmask[pos]); - for(i=0;i