X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=7a6057a79ad948320c4057282fc244b1a1b6eaba;hb=29014045f4de045f8452fdf7ab32622c94b37eef;hp=ebaeb4b180d987ae4245da094c3be32691344a2a;hpb=e4566563844c4bcfc472159c9ae870941099708c;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index ebaeb4b1..7a6057a7 100644 --- a/src/init.c +++ b/src/init.c @@ -1,17 +1,18 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1995-98 Artsoft Entertainment * +* Holger Schemel * +* Oststrasse 11a * +* 33604 Bielefeld * +* phone: ++49 +521 290471 * +* email: aeglos@valinor.owl.de * *----------------------------------------------------------* * init.c * ***********************************************************/ +#include + #include "init.h" #include "misc.h" #include "sound.h" @@ -21,13 +22,12 @@ #include "joystick.h" #include "gfxload.h" #include "gifload.h" - -#include +#include "network.h" #ifdef DEBUG - +/* #define DEBUG_TIMING - +*/ #endif struct PictureFileInfo @@ -44,8 +44,9 @@ struct IconFileInfo static int sound_process_id = 0; +static void InitServer(void); static void InitLevelAndPlayerInfo(void); -static void InitDisplay(int, char **); +static void InitDisplay(void); static void InitSound(void); static void InitSoundProcess(void); static void InitWindow(int, char **); @@ -56,6 +57,7 @@ static void InitElementProperties(void); void OpenAll(int argc, char *argv[]) { InitLevelAndPlayerInfo(); + InitServer(); InitCounter(); InitSound(); @@ -66,7 +68,7 @@ void OpenAll(int argc, char *argv[]) signal(SIGINT, CloseAll); signal(SIGTERM, CloseAll); - InitDisplay(argc, argv); + InitDisplay(); InitWindow(argc, argv); XMapWindow(display, window); @@ -80,6 +82,8 @@ void OpenAll(int argc, char *argv[]) void InitLevelAndPlayerInfo() { + local_player = &stored_player[0]; + if (!LoadLevelInfo()) /* global level info */ CloseAll(); @@ -87,6 +91,20 @@ void InitLevelAndPlayerInfo() LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ } +void InitServer() +{ + standalone = FALSE + TRUE; + + if (standalone) + return; + + if (!ConnectToServer(server_host, server_port)) + Error(ERR_EXIT, "cannot connect to multiplayer server"); + + SendNicknameToServer(local_player->alias_name); + SendProtocolVersionToServer(); +} + void InitSound() { int i; @@ -97,15 +115,15 @@ void InitSound() #ifndef MSDOS if (access(sound_device_name,W_OK)<0) { - fprintf(stderr,"%s: cannot access sound device - no sounds\n",progname); - sound_status=SOUND_OFF; + Error(ERR_RETURN, "cannot access sound device - no sounds"); + sound_status = SOUND_OFF; return; } if ((sound_device=open(sound_device_name,O_WRONLY))<0) { - fprintf(stderr,"%s: cannot open sound device - no sounds\n",progname); - sound_status=SOUND_OFF; + Error(ERR_RETURN, "cannot open sound device - no sounds"); + sound_status = SOUND_OFF; return; } @@ -143,14 +161,14 @@ void InitSoundProcess() #ifndef MSDOS if (pipe(sound_pipe)<0) { - fprintf(stderr,"%s: cannot create pipe - no sounds\n",progname); + Error(ERR_RETURN, "cannot create pipe - no sounds"); sound_status=SOUND_OFF; return; } if ((sound_process_id=fork())<0) { - fprintf(stderr,"%s: cannot create child process - no sounds\n",progname); + Error(ERR_RETURN, "cannot create child process - no sounds"); sound_status=SOUND_OFF; return; } @@ -172,16 +190,16 @@ void InitJoystick() #ifndef MSDOS if (access(joystick_device_name[joystick_nr],R_OK)<0) { - fprintf(stderr,"%s: cannot access joystick device '%s'\n", - progname,joystick_device_name[joystick_nr]); + Error(ERR_RETURN, "cannot access joystick device '%s'", + joystick_device_name[joystick_nr]); joystick_status = JOYSTICK_OFF; return; } if ((joystick_device=open(joystick_device_name[joystick_nr],O_RDONLY))<0) { - fprintf(stderr,"%s: cannot open joystick device '%s'\n", - progname,joystick_device_name[joystick_nr]); + Error(ERR_RETURN, "cannot open joystick device '%s'", + joystick_device_name[joystick_nr]); joystick_status = JOYSTICK_OFF; return; } @@ -193,43 +211,20 @@ void InitJoystick() #endif } -void InitDisplay(int argc, char *argv[]) +void InitDisplay() { - char *display_name = NULL; XVisualInfo vinfo_template, *vinfo; int num_visuals; unsigned int depth; - int i; - - /* get X server to connect to, if given as an argument */ - for (i=1;i=0; i++) { - fprintf(stderr, "%s: cannot create additional Pixmaps!\n",progname); - CloseAll(); - exit(-1); + for(j=0; j= GFX_START_ROCKSSCREEN && + graphic <= GFX_END_ROCKSSCREEN) + { + src_pixmap = clipmask[PIX_BACK]; + graphic -= GFX_START_ROCKSSCREEN; + src_x = SX + (graphic % GFX_PER_LINE) * TILEX; + src_y = SY + (graphic / GFX_PER_LINE) * TILEY; + } + else if (graphic >= GFX_START_ROCKSHEROES && + graphic <= GFX_END_ROCKSHEROES) + { + src_pixmap = clipmask[PIX_HEROES]; + graphic -= GFX_START_ROCKSHEROES; + src_x = (graphic % HEROES_PER_LINE) * TILEX; + src_y = (graphic / HEROES_PER_LINE) * TILEY; + } + else if (graphic >= GFX_START_ROCKSFONT && + graphic <= GFX_END_ROCKSFONT) + { + src_pixmap = clipmask[PIX_BIGFONT]; + graphic -= GFX_START_ROCKSFONT; + src_x = (graphic % FONT_CHARS_PER_LINE) * TILEX; + src_y = (graphic / FONT_CHARS_PER_LINE) * TILEY + + FC_SPECIAL1 * FONT_LINES_PER_FONT * TILEY; + } + else + break; + + tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1); + + XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc, + src_x,src_y, TILEX,TILEY, 0,0); + } } + if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR]) + Error(ERR_EXIT, "cannot create additional pixmaps"); + for(i=0;ipicture_filename) { - - - - - - sprintf(basefilename,"%s%s",pic->picture_filename,".gif"); + 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 - - Read_GIF_to_Pixmaps(display, window, filename); - -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("GIF LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/100.0); -#endif - - - - - - - sprintf(basefilename,"%s%s",pic->picture_filename,picture_ext); - DrawInitText(basefilename,150,FC_YELLOW); #ifdef MSDOS rest(100); #endif MSDOS - sprintf(filename,"%s/%s",GFX_PATH,basefilename); #ifdef DEBUG_TIMING count1 = Counter(); @@ -563,18 +608,9 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #ifdef XPM_INCLUDE_FILE xpm_att[pos].valuemask = XpmCloseness; - xpm_att[pos].closeness = 65535; - - /* xpm_att[pos].closeness = 20000; - */ - -#if 0 xpm_err = XpmReadFileToPixmap(display,window,filename, &pix[pos],&shapemask,&xpm_att[pos]); -#else - xpm_err = XpmSuccess; -#endif switch(xpm_err) { @@ -598,9 +634,16 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) break; } +#ifdef DEBUG_TIMING + count2 = Counter(); + printf("XPM LOADING %s IN %.2f SECONDS\n", + filename,(float)(count2-count1)/1000.0); +#endif + #else - gif_err = Read_GIF_to_Pixmap(display,filename,&pix[pos]); + gif_err = Read_GIF_to_Pixmaps(display, window, filename, + &pix[pos], &clipmask[pos]); switch(gif_err) { @@ -630,57 +673,35 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) break; } -#endif - #ifdef DEBUG_TIMING count2 = Counter(); - /* - printf("XPM LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/100.0); - */ + printf("GIF LOADING %s IN %.2f SECONDS\n", + filename,(float)(count2-count1)/1000.0); #endif -#if 0 - if (!pix[pos]) - { - fprintf(stderr, "%s: cannot read graphics file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); - } #endif + 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 MSDOS - xbm_err = BitmapSuccess; - clipmask[pos] = DUMMY_MASK; - goto msdos_jmp; -#else + +#ifdef XPM_INCLUDE_FILE + sprintf(basefilename,"%s%s",pic->picture_filename,picturemask_ext); DrawInitText(basefilename,150,FC_YELLOW); sprintf(filename,"%s/%s",GFX_PATH,basefilename); -#endif #ifdef DEBUG_TIMING count1 = Counter(); #endif -#ifdef XPM_INCLUDE_FILE - -#if 0 xbm_err = XReadBitmapFile(display,window,filename, &width,&height,&clipmask[pos],&hot_x,&hot_y); -#else - xbm_err = BitmapSuccess; -#endif -#ifdef MSDOS -msdos_jmp: -#endif switch(xbm_err) { case BitmapSuccess: @@ -704,58 +725,17 @@ msdos_jmp: break; } -#else - - ilbm_err = Read_ILBM_to_Bitmap(display,filename,&clipmask[pos]); - - switch(ilbm_err) - { - case ILBM_Success: - break; - case ILBM_OpenFailed: - fprintf(stderr,"Cannot open ILBM file '%s' !\n",filename); - CloseAll(); - exit(-1); - case ILBM_ReadFailed: - fprintf(stderr,"Cannot read ILBM file '%s' !\n",filename); - CloseAll(); - exit(-1); - case ILBM_FileInvalid: - fprintf(stderr,"Invalid ILBM file '%s'!\n",filename); - CloseAll(); - exit(-1); - case ILBM_NoMemory: - fprintf(stderr,"Not enough memory for ILBM 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); - */ + printf("XBM LOADING %s IN %.2f SECONDS\n", + filename,(float)(count2-count1)/1000.0); #endif -#if 0 - if (!clipmask[pos]) - { - fprintf(stderr, "%s: cannot read graphics file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); - } #endif + if (!clipmask[pos]) + Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); } - - pix[pos] = test_pix[test_picture_count-1]; - clipmask[pos] = test_clipmask[test_picture_count-1]; } void InitElementProperties() @@ -1200,6 +1180,16 @@ void InitElementProperties() }; static int ep_pushable_num = sizeof(ep_pushable)/sizeof(int); + static int ep_player[] = + { + EL_SPIELFIGUR, + EL_SPIELER1, + EL_SPIELER2, + EL_SPIELER3, + EL_SPIELER4 + }; + static int ep_player_num = sizeof(ep_player)/sizeof(int); + static long ep_bit[] = { EP_BIT_AMOEBALIVE, @@ -1225,7 +1215,8 @@ void InitElementProperties() EP_BIT_INACTIVE, EP_BIT_EXPLOSIVE, EP_BIT_MAMPF3, - EP_BIT_PUSHABLE + EP_BIT_PUSHABLE, + EP_BIT_PLAYER }; static int *ep_array[] = { @@ -1252,7 +1243,8 @@ void InitElementProperties() ep_inactive, ep_explosive, ep_mampf3, - ep_pushable + ep_pushable, + ep_player }; static int *ep_num[] = { @@ -1279,7 +1271,8 @@ void InitElementProperties() &ep_inactive_num, &ep_explosive_num, &ep_mampf3_num, - &ep_pushable_num + &ep_pushable_num, + &ep_player_num }; static int num_properties = sizeof(ep_num)/sizeof(int *); @@ -1326,8 +1319,12 @@ void CloseAll() if (gc) XFreeGC(display, gc); + if (display) + { + XAutoRepeatOn(display); XCloseDisplay(display); + } exit(0); }