X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=7a5f5eeb521a651bff36cf587fed803df82831df;hb=b59a0eedca464cba38e8a6bcfae54db32ac6b15e;hp=134cf74aeadfee1f092b95fb9496cb1adc9b2b09;hpb=33df7a5ca87e883c2b718171fd7d05c22fc0353f;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 134cf74a..e03d2ae2 100644 --- a/src/init.c +++ b/src/init.c @@ -1,601 +1,371 @@ /*********************************************************** -* 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 +#include "network.h" +#include "netserv.h" +#include "cartoons.h" +#include "config.h" -struct PictureFileInfo +static char *image_filename[NUM_PICTURES] = { - 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 **); + "RocksScreen.pcx", + "RocksDoor.pcx", + "RocksHeroes.pcx", + "RocksToons.pcx", + "RocksSP.pcx", + "RocksDC.pcx", + "RocksMore.pcx", + "RocksFont.pcx", + "RocksFont2.pcx", + "RocksFont3.pcx" +}; + +static void InitSetup(void); +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, getWindowTitleString(), + ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, + MSDOS_POINTER_FILENAME, + COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); + + InitSetup(); + 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() */ + + InitLevelInfo(); + InitGadgets(); /* needs to know number of level series */ + + InitGfxBackground(); + InitToons(); DrawMainMenu(); + + InitNetworkServer(); } -void InitLevelAndPlayerInfo() +void InitSetup() { - if (!LoadLevelInfo()) /* global level info */ - CloseAll(); - - LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ - LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ + LoadSetup(); /* global setup info */ } -void InitSound() +void InitPlayerInfo() { int i; - if (sound_status==SOUND_OFF) - return; - - if (access(sound_device_name,W_OK)<0) - { - fprintf(stderr,"%s: cannot access sound device - no sounds\n",progname); - sound_status=SOUND_OFF; - return; - } + /* choose default local player */ + local_player = &stored_player[0]; - 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; - return; - } + for (i=0; iconnected = TRUE; } -void InitSoundProcess() +void InitLevelInfo() { - if (sound_status==SOUND_OFF) - return; - - if (pipe(sound_pipe)<0) - { - fprintf(stderr,"%s: cannot create pipe - no sounds\n",progname); - sound_status=SOUND_OFF; - return; - } - - if ((sound_process_id=fork())<0) - { - fprintf(stderr,"%s: cannot create child process - no sounds\n",progname); - sound_status=SOUND_OFF; - return; - } - - if (!sound_process_id) /* we are child */ - SoundServer(); - else /* we are parent */ - close(sound_pipe[0]); /* no reading from pipe needed */ + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ } -void InitJoystick() +void InitNetworkServer() { - if (global_joystick_status==JOYSTICK_OFF) - return; - - 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]); - joystick_status = JOYSTICK_OFF; - return; - } +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif - 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]); - joystick_status = JOYSTICK_OFF; + if (!options.network) return; - } - - joystick_status = JOYSTICK_AVAILABLE; - LoadJoystickData(); -} -void InitDisplay(int argc, char *argv[]) -{ - char *display_name = NULL; - int i; +#if defined(PLATFORM_UNIX) + nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); - /* get X server to connect to, if given as an argument */ - for (i=1;iclip_mask, + clip_gc_valuemask, &clip_gc_values); + + clip_gc_values.graphics_exposures = False; + clip_gc_valuemask = GCGraphicsExposures; + tile_clip_gc = + XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values); + + for(i=0; iclip_mask) { clip_gc_values.graphics_exposures = False; - clip_gc_values.foreground = pen_fg; - clip_gc_values.background = pen_bg; - clip_gc_values.clip_mask = clipmask[i]; - clip_gc_valuemask = - GCGraphicsExposures | GCForeground | GCBackground | GCClipMask; - clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values); + 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); } } - drawto = backbuffer = pix[PIX_DB_BACK]; - fieldbuffer = pix[PIX_DB_FIELD]; - SetDrawtoField(DRAW_BACKBUFFER); - - XCopyArea(display,pix[PIX_BACK],backbuffer,gc, - 0,0, WIN_XSIZE,WIN_YSIZE, 0,0); - XFillRectangle(display,pix[PIX_DB_BACK],gc, - REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE); - XFillRectangle(display,pix[PIX_DB_DOOR],gc, - 0,0, 3*DXSIZE,DYSIZE+VYSIZE); - - for(i=0; i=0; i++) + { + int j; -void LoadGfx(int pos, struct PictureFileInfo *pic) -{ - char basefilename[256]; - char filename[256]; - -#ifdef XPM_INCLUDE_FILE - int xpm_err, xbm_err; - unsigned int width,height; - int hot_x,hot_y; - Pixmap shapemask; - char *picture_ext = ".xpm"; - char *picturemask_ext = "Mask.xbm"; -#else - int gif_err, ilbm_err; - char *picture_ext = ".gif"; - char *picturemask_ext = "Mask.ilbm"; -#endif + for(j=0; jclip_mask; - /* Grafik laden */ - if (pic->picture_filename) - { - sprintf(basefilename,"%s%s",pic->picture_filename,picture_ext); - DrawInitText(basefilename,150,FC_YELLOW); - sprintf(filename,"%s/%s",GFX_PATH,basefilename); + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); -#ifdef DEBUG_TIMING - count1 = Counter(); -#endif + 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 */ +} -#ifdef XPM_INCLUDE_FILE +void InitGfx() +{ + int i; - 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; - } + /* initialize some global variables */ + global.frames_per_second = 0; + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; -#else + /* initialize screen properties */ + InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE, + REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); + InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE); + InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE); + InitGfxScrollbufferInfo(FXSIZE, FYSIZE); - gif_err = Read_GIF_to_Pixmap(display,filename,&pix[pos]); + /* create additional image buffers for double-buffering */ + pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH); + pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH); - 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; - } + pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]); -#endif + InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/100.0); + DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); + DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); +#if defined(PLATFORM_MSDOS) + DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE); + rest(200); #endif + DrawInitText("Loading graphics:",120,FC_GREEN); - if (!pix[pos]) + for(i=0; ipicture_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 + InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]); - 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 + InitTileClipmasks(); +} - ilbm_err = Read_ILBM_to_Bitmap(display,filename,&clipmask[pos]); +void InitGfxBackground() +{ + int x, y; - 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; - } + drawto = backbuffer; + fieldbuffer = pix[PIX_DB_FIELD]; + SetDrawtoField(DRAW_BACKBUFFER); -#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); -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/100.0); -#endif + for(x=0; x