X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=2d6017f3708d77e5e124a9413e137c0b1a3e8a42;hb=b40c5be44ed492da183f29d9f2f8184391c31cf0;hp=ebaeb4b180d987ae4245da094c3be32691344a2a;hpb=e4566563844c4bcfc472159c9ae870941099708c;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index ebaeb4b1..2d6017f3 100644 --- a/src/init.c +++ b/src/init.c @@ -1,761 +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 "gfxload.h" -#include "gifload.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; +#include "network.h" +#include "netserv.h" -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); - - InitDisplay(argc, argv); - InitWindow(argc, argv); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); - 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]; -#ifndef MSDOS - if (access(sound_device_name,W_OK)<0) + for (i=0; iconnected = TRUE; -#ifdef VOXWARE - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif -#else - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif + LoadSetup(); /* global setup info */ +} - for(i=0;ivisual; - XFree((void *)vinfo); - } + char *device_name = setup.input[i].joy.device_name; + int joystick_nr = getJoystickNrFromDeviceName(device_name); - /* got appropriate visual? */ - if (depth < 8) - { - printf("Sorry, displays with less than 8 bits per pixel not supported.\n"); - exit(-1); - } - else if ((depth ==8 && visual->class != PseudoColor) || - (depth > 8 && visual->class != TrueColor && - visual->class != DirectColor)) - { - printf("Sorry, cannot get appropriate visual.\n"); - exit(-1); - } -} + if (joystick_nr >= SDL_NumJoysticks()) + joystick_nr = -1; -void InitWindow(int argc, char *argv[]) -{ - unsigned int border_width = 4; - Pixmap icon_pixmap, iconmask_pixmap; - unsigned int icon_width,icon_height; - int icon_hot_x,icon_hot_y; - char icon_filename[256]; - XSizeHints size_hints; - XWMHints wm_hints; - XClassHint class_hints; - XTextProperty windowName, iconName; - XGCValues gc_values; - unsigned long gc_valuemask; - char *window_name = WINDOWTITLE_STRING; - char *icon_name = WINDOWTITLE_STRING; - long window_event_mask; - Atom proto_atom = None, delete_atom = None; - int screen_width, screen_height; - int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS; - -#ifndef MSDOS - static struct IconFileInfo icon_pic = - { - "rocks_icon.xbm", - "rocks_iconmask.xbm" - }; -#endif + /* misuse joystick file descriptor variable to store joystick number */ + stored_player[i].joystick_fd = joystick_nr; - screen_width = XDisplayWidth(display, screen); - screen_height = XDisplayHeight(display, screen); + /* this allows subsequent calls to 'InitJoysticks' for re-initialization */ + if (Check_SDL_JoystickOpened(joystick_nr)) + Close_SDL_Joystick(joystick_nr); - width = WIN_XSIZE; - height = WIN_YSIZE; + if (!setup.input[i].use_joystick) + continue; - win_xpos = (screen_width - width) / 2; - win_ypos = (screen_height - height) / 2; + if (!Open_SDL_Joystick(joystick_nr)) + { + Error(ERR_WARN, "cannot open joystick %d", joystick_nr); + continue; + } - window = XCreateSimpleWindow(display, RootWindow(display, screen), - win_xpos, win_ypos, width, height, border_width, - pen_fg, pen_bg); + joystick_status = JOYSTICK_AVAILABLE; + } -#ifndef MSDOS - proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE); - delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE); - if ((proto_atom != None) && (delete_atom != None)) - XChangeProperty(display, window, proto_atom, XA_ATOM, 32, - PropModePrepend, (unsigned char *) &delete_atom, 1); +#else /* !TARGET_SDL */ - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picture_filename); - XReadBitmapFile(display,window,icon_filename, - &icon_width,&icon_height, - &icon_pixmap,&icon_hot_x,&icon_hot_y); - if (!icon_pixmap) +#if defined(PLATFORM_UNIX) + for (i=0; i= num_joysticks) + joystick_nr = -1; + /* misuse joystick file descriptor variable to store joystick number */ + stored_player[i].joystick_fd = joystick_nr; + } #endif - /* create GC for drawing with window depth */ - gc_values.graphics_exposures = False; - gc_values.foreground = pen_bg; - gc_values.background = pen_bg; - gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; - 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); - } +#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; -#ifdef MSDOS - static struct PictureFileInfo pic[NUM_PICTURES] = +#endif + +#if !defined(PLATFORM_MSDOS) + static char *image_filename[NUM_PICTURES] = { - { "Screen", TRUE }, - { "Door", TRUE }, - { "Heroes", TRUE }, - { "Toons", TRUE }, - { "Font", FALSE }, - { "Font2", 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] = { - { "RocksScreen", TRUE }, - { "RocksDoor", TRUE }, - { "RocksHeroes", TRUE }, - { "RocksToons", TRUE }, - { "RocksFont", FALSE }, - { "RocksFont2", FALSE } + "Screen.pcx", + "Door.pcx", + "Heroes.pcx", + "Toons.pcx", + "SP.pcx", + "DC.pcx", + "More.pcx", + "Font.pcx", + "Font2.pcx", + "Font3.pcx" }; #endif -#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); -#ifdef MSDOS - DrawInitText("MSDOS version done by Guido Schulz",210,FC_BLUE); - rest(200); -#endif MSDOS - DrawInitText("Loading graphics:",120,FC_GREEN); - - for(i=0;ipicture_filename) + for(i=0; ipicture_filename,".gif"); - 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(); -#endif - -#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) + 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("XPM 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 0 - 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); } -#endif - } - /* 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++) { -#ifdef MSDOS - xbm_err = BitmapSuccess; - clipmask[pos] = DUMMY_MASK; - goto msdos_jmp; -#else - 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 + int j; -#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) + 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 0 - if (!clipmask[pos]) - { - fprintf(stderr, "%s: cannot read graphics file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); - } -#endif + 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