X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=ecafc3b848cc3932394cf38ebf9184248b621782;hb=681721dddc91bcdaef50002d1e861cc8d484e938;hp=0f0bd65234873a2ea12c2877b54c65b68c810924;hpb=cf5b3a1e9077e88eb40ce2fb59e985a0ae037c84;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 0f0bd652..9af44248 100644 --- a/src/init.c +++ b/src/init.c @@ -1,600 +1,484 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* 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-2001 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* init.c * +* init.c * ***********************************************************/ +#include "libgame/libgame.h" + #include "init.h" -#include "misc.h" -#include "sound.h" +#include "events.h" #include "screens.h" +#include "editor.h" +#include "game.h" +#include "tape.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; -}; +#include "network.h" +#include "netserv.h" -static int sound_process_id = 0; - -static void InitLevelAndPlayerInfo(void); -static void InitDisplay(int, char **); +static void InitPlayerInfo(void); +static void InitLevelInfo(void); +static void InitNetworkServer(void); 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 InitGfxBackground(void); +static void InitGadgets(void); static void InitElementProperties(void); -void OpenAll(int argc, char *argv[]) +void OpenAll(void) { - InitLevelAndPlayerInfo(); + if (options.serveronly) + { +#if defined(PLATFORM_UNIX) + NetworkServer(options.server_port, options.serveronly); +#else + Error(ERR_WARN, "networking only supported in Unix version"); +#endif + exit(0); /* never reached */ + } + + InitProgramInfo(UNIX_USERDATA_DIRECTORY, + PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING, + ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, + MSDOS_POINTER_FILENAME); + + InitPlayerInfo(); InitCounter(); InitSound(); - InitSoundProcess(); - InitJoystick(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAll); - signal(SIGTERM, CloseAll); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); - InitDisplay(argc, argv); - InitWindow(argc, argv); - - XMapWindow(display, window); - XFlush(display); + InitEventFilter(FilterMouseMotionEvents); InitGfx(); - InitElementProperties(); + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ - DrawMainMenu(); -} + InitLevelInfo(); + InitGadgets(); /* needs to know number of level series */ -void InitLevelAndPlayerInfo() -{ - if (!LoadLevelInfo()) /* global level info */ - CloseAll(); + InitGfxBackground(); + DrawMainMenu(); - LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ - LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ + InitNetworkServer(); } -void InitSound() +void InitPlayerInfo() { int i; - if (sound_status==SOUND_OFF) - return; + /* choose default local player */ + local_player = &stored_player[0]; - if (access(sound_device_name,W_OK)<0) + for (i=0; iconnected = TRUE; + + LoadSetup(); /* global setup info */ +} + +void InitLevelInfo() +{ + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ +} + +void InitNetworkServer() +{ +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif + + if (!options.network) return; - } - close(sound_device); - sound_status=SOUND_AVAILABLE; +#if defined(PLATFORM_UNIX) + nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); + + if (!ConnectToServer(options.server_host, options.server_port)) + Error(ERR_EXIT, "cannot connect to network game server"); + + SendToServer_PlayerName(setup.player_name); + SendToServer_ProtocolVersion(); -#ifdef VOXWARE - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; + if (nr_wanted) + SendToServer_NrWanted(nr_wanted); #endif +} - for(i=0;i= SDL_NumJoysticks()) + joystick_nr = -1; -void InitDisplay(int argc, char *argv[]) -{ - char *display_name = NULL; - int i; + /* misuse joystick file descriptor variable to store joystick number */ + stored_player[i].joystick_fd = joystick_nr; - /* get X server to connect to, if given as an argument */ - for (i=1;i= num_joysticks) + joystick_nr = -1; -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); + /* misuse joystick file descriptor variable to store joystick number */ + stored_player[i].joystick_fd = joystick_nr; } +#endif + +#endif /* !TARGET_SDL */ } void InitGfx() { - int i,j; + int i; + +#if defined(TARGET_X11) + GC copy_clipmask_gc; XGCValues clip_gc_values; unsigned long clip_gc_valuemask; - static struct PictureFileInfo pic[NUM_PICTURES] = - { - { "RocksScreen", TRUE }, - { "RocksDoor", TRUE }, - { "RocksHeroes", TRUE }, - { "RocksToons", TRUE }, - { "RocksFont", FALSE }, - { "RocksFont2", FALSE } - }; - -#ifdef DEBUG_TIMING - long count1, count2; - count1 = Counter(); #endif - LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]); - DrawInitText(WINDOWTITLE_STRING,20,FC_YELLOW); - DrawInitText(COPYRIGHT_STRING,50,FC_RED); - DrawInitText("Loading graphics:",120,FC_GREEN); - - for(i=0;ipicture_filename) + for(i=0; ipicture_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) + if (i != PIX_SMALLFONT) { - 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; + DrawInitText(image_filename[i], 150, FC_YELLOW); + pix[i] = LoadImage(image_filename[i]); } + } -#else + InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]); - gif_err = Read_GIF_to_Pixmap(display,filename,&pix[pos]); + /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */ + for(i=0; iclip_mask, + clip_gc_valuemask, &clip_gc_values); -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/100.0); -#endif + clip_gc_values.graphics_exposures = False; + clip_gc_valuemask = GCGraphicsExposures; + tile_clip_gc = + XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values); - if (!pix[pos]) + for(i=0; iclip_mask) { - fprintf(stderr, "%s: cannot read graphics file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); + clip_gc_values.graphics_exposures = False; + clip_gc_values.clip_mask = pix[i]->clip_mask; + clip_gc_valuemask = GCGraphicsExposures | GCClipMask; + pix[i]->stored_clip_gc = XCreateGC(display, window->drawable, + clip_gc_valuemask,&clip_gc_values); } } - /* zugehörige Maske laden (wenn vorhanden) */ - if (pic->picture_with_mask) +#if defined(TARGET_X11_NATIVE) + /* create only those clipping Pixmaps we really need */ + for(i=0; tile_needs_clipping[i].start>=0; i++) { - sprintf(basefilename,"%s%s",pic->picture_filename,picturemask_ext); - DrawInitText(basefilename,150,FC_YELLOW); - sprintf(filename,"%s/%s",GFX_PATH,basefilename); + int j; -#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) + for(j=0; jclip_mask; - ilbm_err = Read_ILBM_to_Bitmap(display,filename,&clipmask[pos]); + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); - 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; + XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc, + src_x, src_y, TILEX, TILEY, 0, 0); } + } +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ +} -#endif +void InitGfxBackground() +{ + int x, y; -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/100.0); -#endif + drawto = backbuffer; + fieldbuffer = pix[PIX_DB_FIELD]; + SetDrawtoField(DRAW_BACKBUFFER); - if (!clipmask[pos]) - { - fprintf(stderr, "%s: cannot read graphics file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); - } - } + BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0); + ClearRectangle(backbuffer, REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE); + ClearRectangle(pix[PIX_DB_DOOR], 0,0, 3*DXSIZE,DYSIZE+VYSIZE); + + for(x=0; x