X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=70604f2a9392854cd4bda2dc4fc30ad16bcb6105;hb=93806fb4c23f4b6ef58d9562e908a1b89ece869d;hp=8d9571c9a88834006fc2934aac026245de8c6f97;hpb=3d07b68a314ce189f207e42d95f786979662410d;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 8d9571c9..70604f2a 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,63 +21,62 @@ #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 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(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); + MSDOS_POINTER_FILENAME, + COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); 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(); @@ -88,6 +85,8 @@ void OpenAll(void) InitLevelInfo(); InitGadgets(); /* needs to know number of level series */ + InitCustomGraphics(); + InitGfxBackground(); DrawMainMenu(); @@ -102,10 +101,7 @@ void InitPlayerInfo() local_player = &stored_player[0]; for (i=0; iconnected = TRUE; @@ -146,13 +142,11 @@ void InitSound() { int i; - OpenAudio(&audio); - - AllocSoundArray(NUM_SOUNDS); + 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); - - 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 */ -} + num_bg_loops = LoadMusic(); -void InitDisplay() -{ - InitVideoDisplay(); - InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, - setup.fullscreen); + StartSoundserver(); } -void InitGfx() +void InitTileClipmasks() { - int i; - #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 - -#ifdef TARGET_X11 +#if defined(TARGET_X11_NATIVE) static struct { int start; @@ -416,83 +223,17 @@ void InitGfx() }; #endif - /* initialize some global variables */ - global.frames_per_second = 0; - global.fps_slowdown = FALSE; - global.fps_slowdown_factor = 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); - - 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); - } - } -#endif + 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; @@ -518,10 +259,7 @@ void InitGfx() } } - /* initialize pixmap array to Pixmap 'None' */ - for(i=0; i=0; i++) { @@ -545,113 +283,126 @@ void InitGfx() src_x, src_y, TILEX, TILEY, 0, 0); } } - -#endif /* !TARGET_SDL */ +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ } -void InitGfxBackground() +void InitGfx() { - int x, y; + char *filename; + int i; - drawto = backbuffer; - fieldbuffer = pix[PIX_DB_FIELD]; - SetDrawtoField(DRAW_BACKBUFFER); + /* initialize some global variables */ + global.frames_per_second = 0; + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 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); + /* 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); - for(x=0; xpicture_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); + filename = getImageFilename(image_filename[i]); + if ((pix_default[i] = LoadImage(filename)) == NULL) + Error(ERR_EXIT, "LoadImage() failed: %s", GetError()); + pix_custom[i] = NULL; + pix[i] = pix_default[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]->surface = 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[pos]->surface_masked = 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