X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=2ddbbcd5769c56c30cadc67d8092fc3fefb3f9f2;hb=fe158e864d3fa4b0221e9c88d8dfff0157051396;hp=1c56fc0a3d9b7f6cfc782690452bc007333b5ae0;hpb=621b6a2c4781c9c3e2f5849f9c184a906e0ce5b6;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 1c56fc0a..2ddbbcd5 100644 --- a/src/init.c +++ b/src/init.c @@ -1,18 +1,16 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-98 Artsoft Entertainment * -* Holger Schemel * -* Oststrasse 11a * -* 33604 Bielefeld * -* phone: ++49 +521 290471 * -* email: aeglos@valinor.owl.de * +* (c) 1995-2001 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* init.c * +* init.c * ***********************************************************/ -#include - #include "libgame/libgame.h" #include "init.h" @@ -23,58 +21,64 @@ #include "tape.h" #include "tools.h" #include "files.h" -#include "joystick.h" #include "network.h" #include "netserv.h" -struct PictureFileInfo +static char *image_filename[NUM_PICTURES] = { - char *picture_filename; - boolean picture_with_mask; -}; + "RocksScreen.pcx", + "RocksDoor.pcx", + "RocksHeroes.pcx", + "RocksToons.pcx", + "RocksSP.pcx", + "RocksDC.pcx", + "RocksMore.pcx", + "RocksFont.pcx", + "RocksFont2.pcx", + "RocksFont3.pcx" +}; static void InitPlayerInfo(void); +static void InitSetup(void); static void InitLevelInfo(void); static void InitNetworkServer(void); static void InitSound(void); -static void InitSoundServer(void); -static void InitDisplay(void); static void InitGfx(void); +static void InitCustomGraphics(void); static void InitGfxBackground(void); -static void LoadGfx(int, struct PictureFileInfo *); static void InitGadgets(void); static void InitElementProperties(void); -void OpenAll(int argc, char *argv[]) +void OpenAll(void) { -#if !defined(PLATFORM_UNIX) - initErrorFile(); -#endif - if (options.serveronly) { #if defined(PLATFORM_UNIX) NetworkServer(options.server_port, options.serveronly); #else - Error(ERR_WARN, "networking not supported in Windows version"); + Error(ERR_WARN, "networking only supported in Unix version"); #endif - - /* never reached */ - exit(0); + 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, + COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); + + InitSetup(); InitPlayerInfo(); InitCounter(); InitSound(); - InitSoundServer(); InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAllAndExit); - signal(SIGTERM, CloseAllAndExit); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); - InitDisplay(); InitEventFilter(FilterMouseMotionEvents); InitGfx(); @@ -83,12 +87,19 @@ void OpenAll(int argc, char *argv[]) InitLevelInfo(); InitGadgets(); /* needs to know number of level series */ + InitCustomGraphics(); + InitGfxBackground(); DrawMainMenu(); InitNetworkServer(); } +void InitSetup() +{ + LoadSetup(); /* global setup info */ +} + void InitPlayerInfo() { int i; @@ -97,14 +108,9 @@ void InitPlayerInfo() local_player = &stored_player[0]; for (i=0; iconnected = TRUE; - - LoadSetup(); /* global setup info */ } void InitLevelInfo() @@ -141,233 +147,34 @@ void InitSound() { int i; - OpenAudio(&audio); + OpenAudio(); for(i=0; i= SDL_NumJoysticks()) - joystick_nr = -1; - - /* misuse joystick file descriptor variable to store joystick number */ - stored_player[i].joystick_fd = joystick_nr; - - /* this allows subsequent calls to 'InitJoysticks' for re-initialization */ - if (Check_SDL_JoystickOpened(joystick_nr)) - Close_SDL_Joystick(joystick_nr); + num_bg_loops = LoadMusic(); - if (!setup.input[i].use_joystick) - continue; - - if (!Open_SDL_Joystick(joystick_nr)) - { - Error(ERR_WARN, "cannot open joystick %d", joystick_nr); - continue; - } - - joystick_status = JOYSTICK_AVAILABLE; - } - -#else /* !TARGET_SDL */ - -#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 - -#endif /* !TARGET_SDL */ + StartSoundserver(); } -void InitDisplay() +void InitTileClipmasks() { - char *gfx_dir = getPath2(options.ro_base_directory, GRAPHICS_DIRECTORY); - char *x11_icon_filename = getPath2(gfx_dir, X11_ICON_FILENAME); - char *x11_iconmask_filename = getPath2(gfx_dir, X11_ICONMASK_FILENAME); - char *msdos_pointer_filename = getPath2(gfx_dir, MSDOS_POINTER_FILENAME); - - free(gfx_dir); - - InitProgramInfo(program_name, PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING, - ICON_TITLE_STRING, x11_icon_filename, x11_iconmask_filename, - msdos_pointer_filename); - - InitVideoDisplay(); - InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, - setup.fullscreen); -} - -void InitGfx() -{ - int i, j; - -#if defined(TARGET_SDL) - SDL_Surface *sdl_image_tmp; -#else +#if defined(TARGET_X11) GC copy_clipmask_gc; XGCValues clip_gc_values; unsigned long clip_gc_valuemask; #endif -#if !defined(PLATFORM_MSDOS) - static struct PictureFileInfo pic[NUM_PICTURES] = - { - { "RocksScreen", TRUE }, - { "RocksDoor", TRUE }, - { "RocksHeroes", TRUE }, - { "RocksToons", TRUE }, - { "RocksSP", TRUE }, - { "RocksDC", TRUE }, - { "RocksMore", TRUE }, - { "RocksFont", FALSE }, - { "RocksFont2", FALSE }, - { "RocksFont3", FALSE } - }; -#else - static struct PictureFileInfo pic[NUM_PICTURES] = - { - { "Screen", TRUE }, - { "Door", TRUE }, - { "Heroes", TRUE }, - { "Toons", TRUE }, - { "SP", TRUE }, - { "DC", TRUE }, - { "More", TRUE }, - { "Font", FALSE }, - { "Font2", FALSE }, - { "Font3", FALSE } - }; -#endif - +#if defined(TARGET_X11_NATIVE) static struct { int start; @@ -419,78 +226,19 @@ void InitGfx() { GFX2_SHIELD_ACTIVE, 3 }, { -1, 0 } }; - - /* initialize playfield properties */ - - InitPlayfieldInfo(SX, SY, SXSIZE, SYSIZE, - REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - InitDoor1Info(DX, DY, DXSIZE, DYSIZE); - InitDoor2Info(VX, VY, VXSIZE, VYSIZE); - InitScrollbufferInfo(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); - - LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]); - InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); - - 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); - - for(i=0; i=0; i++) - { - for(j=0; jformat, 0x00, 0x00, 0x00)); - if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - - SDL_FreeSurface(sdl_image_tmp); - - BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0); - } - } + tile_clipmask[i] = None; -#else /* !TARGET_SDL */ +#if defined(TARGET_X11) + /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is + often very slow when preparing a masked XCopyArea() for big Pixmaps. + To prevent this, create small (tile-sized) mask Pixmaps which will then + be set much faster with XSetClipOrigin() and speed things up a lot. */ /* create graphic context structures needed for clipping */ clip_gc_values.graphics_exposures = False; @@ -516,13 +264,12 @@ void InitGfx() } } - /* initialize pixmap array to Pixmap 'None' */ - for(i=0; i=0; i++) { + int j; + for(j=0; jpicture_filename) + for(i=0; ipicture_filename, picture_ext); - DrawInitText(basefilename, 150, FC_YELLOW); - sprintf(filename, "%s/%s/%s", - options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename); + if (i != PIX_SMALLFONT) + { + DrawInitText(image_filename[i], 150, FC_YELLOW); -#if defined(PLATFORM_MSDOS) - rest(100); + pix[i] = LoadCustomImage(image_filename[i]); + } + } + + InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]); + + InitTileClipmasks(); +} + +void LoadCustomGraphics() +{ +#if 0 + int i; + + for(i=0; i/graphics */ + filename = getPath2(getUserDataDir(), GRAPHICS_DIRECTORY); + if (access(dir, F_OK) == 0) + { + } - /* create native non-transparent surface for current image */ - if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - /* create native transparent surface for current image */ - SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY, - SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00)); - if ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) - Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); - /* free temporary surface */ - SDL_FreeSurface(sdl_image_tmp); -#else /* !TARGET_SDL */ +(leveldir_current->user_defined ? + getUserLevelDir("") : + options.level_directory), + leveldir_current->fullpath, + basename); - pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, - filename, - &pix[pos]->drawable, &pix[pos]->clip_mask); - switch(pcx_err) - { - case PCX_Success: - break; - case PCX_OpenFailed: - Error(ERR_EXIT, "cannot open PCX file '%s'", filename); - case PCX_ReadFailed: - Error(ERR_EXIT, "cannot read PCX file '%s'", filename); - case PCX_FileInvalid: - Error(ERR_EXIT, "invalid PCX file '%s'", filename); - case PCX_NoMemory: - Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename); - case PCX_ColorFailed: - Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename); - default: - break; - } - if (!pix[pos]->drawable) - Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); -#if 0 - /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always - use pix_masked[], although they are the same when not using SDL */ - pix_masked[pos] = pix[pos]; + filename = getPath3((leveldir_current->user_defined ? + getUserLevelDir("") : + options.level_directory), + leveldir_current->fullpath, + basename); #endif +} -#endif /* !TARGET_SDL */ - } +void InitGfxBackground() +{ + int x, y; -#if defined(TARGET_X11) - /* check if clip mask was correctly created */ - if (pic->picture_with_mask && !pix[pos]->clip_mask) - Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); -#endif + drawto = backbuffer; + fieldbuffer = pix[PIX_DB_FIELD]; + SetDrawtoField(DRAW_BACKBUFFER); + + 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