X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Finit.c;h=fe585257360fc68d0dc3785be8dbf0f4761013b4;hb=335f4db8f7a8bea9b06eeea911b6d1e1d4de4623;hp=251d32d64d6dd4efbb967486b22acd84cecd146a;hpb=046d80f9a1b3fad9d4d3d3aa92dcb3689849aebf;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 251d32d6..fe585257 100644 --- a/src/init.c +++ b/src/init.c @@ -1,436 +1,378 @@ /*********************************************************** -* 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 - -static int sound_process_id = 0; +#include "network.h" +#include "netserv.h" +#include "cartoons.h" +#include "config.h" -void OpenAll(int argc, char *argv[]) +static char *image_filename[NUM_PICTURES] = { - InitLevelAndPlayerInfo(); + "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 InitArtworkInfo(void); +static void InitNetworkServer(void); +static void InitSound(void); +static void InitGfx(void); +static void InitGfxBackground(void); +static void InitGadgets(void); +static void InitElementProperties(void); + +void OpenAll(void) +{ + 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); + InitEventFilter(FilterMouseMotionEvents); + + InitArtworkInfo(); InitGfx(); - InitElementProperties(); + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ + + InitLevelInfo(); + InitGadgets(); /* needs to know number of level series */ + + InitGfxBackground(); + InitToons(); DrawMainMenu(); - XMapWindow(display, window); - XFlush(display); + 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; - } - - 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; - } + /* choose default local player */ + local_player = &stored_player[0]; - close(sound_device); - sound_status=SOUND_AVAILABLE; + 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; - } + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ +} - if (!sound_process_id) /* we are child */ - SoundServer(); - else /* we are parent */ - close(sound_pipe[0]); /* no reading from pipe needed */ +void InitArtworkInfo() +{ + LoadArtworkInfo(); } -void InitJoystick() +void InitNetworkServer() { - if (global_joystick_status==JOYSTICK_OFF) - return; +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif - 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; + if (!options.network) 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]); - joystick_status = JOYSTICK_OFF; - return; - } +#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"); - joystick_status = JOYSTICK_AVAILABLE; - LoadJoystickData(); + SendToServer_PlayerName(setup.player_name); + SendToServer_ProtocolVersion(); + + if (nr_wanted) + SendToServer_NrWanted(nr_wanted); +#endif } -void InitDisplay(int argc, char *argv[]) +void InitSound() { - char *display_name = NULL; int i; - /* 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.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); + } } - if (!XStringListToTextProperty(&icon_name, 1, &iconName)) +#if defined(TARGET_X11_NATIVE) + /* create only those clipping Pixmaps we really need */ + for(i=0; tile_needs_clipping[i].start>=0; i++) { - fprintf(stderr, "%s: structure allocation for iconName failed.\n", - progname); - exit(-1); - } - - wm_hints.initial_state = NormalState; - wm_hints.input = True; - wm_hints.icon_pixmap = icon_pixmap; - wm_hints.icon_mask = iconmask_pixmap; - wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint; - - class_hints.res_name = progname; - class_hints.res_class = "Rocks'n'Diamonds"; - - XSetWMProperties(display, window, &windowName, &iconName, - argv, argc, &size_hints, &wm_hints, - &class_hints); - - XFree(windowName.value); - XFree(iconName.value); - - /* Select event types wanted */ - window_event_mask = ExposureMask | StructureNotifyMask | FocusChangeMask | - ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - KeyPressMask | KeyReleaseMask; - XSelectInput(display, window, window_event_mask); - - /* 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); -} + int j; -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; - XGCValues clip_gc_values; - unsigned long clip_gc_valuemask; - char filename[256]; - Pixmap shapemask; + for(j=0; jclip_mask; - for(i=0;idrawable, + TILEX, TILEY, 1); - if (pic[i].picturemask_filename) - { - sprintf(filename,"%s/%s",GFX_PATH,pic[i].picturemask_filename); - - xbm_err = XReadBitmapFile(display,window,filename, - &width,&height,&clipmask[i],&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; - } - if (!clipmask[i]) - { - fprintf(stderr, "%s: cannot read X11 bitmap file '%s'.\n", - progname,filename); - CloseAll(); - exit(-1); - } + 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 */ +} - pix[PIX_DB_BACK] = XCreatePixmap(display, window, - WIN_XSIZE,WIN_YSIZE, - XDefaultDepth(display,screen)); - pix[PIX_DB_DOOR] = XCreatePixmap(display, window, - 3*DXSIZE,DYSIZE+VYSIZE, - XDefaultDepth(display,screen)); +void InitGfx() +{ + int i; - clipmask[PIX_FADEMASK] = XCreatePixmap(display, window, - SXSIZE+TILEX,SYSIZE+TILEY,1); + /* initialize some global variables */ + global.frames_per_second = 0; + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; - if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR] || !clipmask[PIX_FADEMASK]) - { - fprintf(stderr, "%s: cannot create additional Pixmaps!\n",progname); - CloseAll(); - exit(-1); - } + /* 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); + + /* 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); - /* create GC for drawing with bitplane depth */ - gc_values.graphics_exposures = False; - gc_values.foreground = pen_bg; - gc_values.background = pen_bg; - gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; - plane_gc = XCreateGC(display, clipmask[PIX_BACK], gc_valuemask, &gc_values); + pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]); - for(y=0;y<=SCR_FIELDY;y++) for(x=0;x<=SCR_FIELDX;x++) - XCopyArea(display,clipmask[PIX_BACK],clipmask[PIX_FADEMASK],plane_gc, - SX+2*TILEX,SY+10*TILEY,TILEX,TILEY,x*TILEX,y*TILEY); + InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); - for(i=0;i