X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=e03d2ae2aa4bcbe15fa6d34f733df304ab19e9a1;hb=b59a0eedca464cba38e8a6bcfae54db32ac6b15e;hp=040270a1b844941f1c37a59d4a5a904128b1d6ad;hpb=ab9b68feafe2cf6012533e5ad0581e6b9d423959;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 040270a1..e03d2ae2 100644 --- a/src/init.c +++ b/src/init.c @@ -1,81 +1,85 @@ /*********************************************************** -* 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" #include "events.h" -#include "misc.h" -#include "sound.h" #include "screens.h" #include "editor.h" #include "game.h" #include "tape.h" #include "tools.h" #include "files.h" -#include "joystick.h" -#include "image.h" -#include "pcx.h" #include "network.h" #include "netserv.h" +#include "cartoons.h" +#include "config.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 InitSetup(void); static void InitPlayerInfo(void); static void InitLevelInfo(void); static void InitNetworkServer(void); static void InitSound(void); -static void InitSoundServer(void); static void InitGfx(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, getWindowTitleString(), + 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); - InitBufferedDisplay(&backbuffer, &window); InitEventFilter(FilterMouseMotionEvents); InitGfx(); @@ -85,11 +89,18 @@ void OpenAll(int argc, char *argv[]) InitGadgets(); /* needs to know number of level series */ InitGfxBackground(); + InitToons(); + DrawMainMenu(); InitNetworkServer(); } +void InitSetup() +{ + LoadSetup(); /* global setup info */ +} + void InitPlayerInfo() { int i; @@ -98,14 +109,9 @@ void InitPlayerInfo() local_player = &stored_player[0]; for (i=0; iconnected = TRUE; - - LoadSetup(); /* global setup info */ } void InitLevelInfo() @@ -142,215 +148,34 @@ void InitSound() { int i; - audio = InitAudio(); + 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 */ + StartSoundserver(); } -void InitGfx() +void InitTileClipmasks() { - 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; @@ -402,96 +227,50 @@ void InitGfx() { GFX2_SHIELD_ACTIVE, 3 }, { -1, 0 } }; - - /* 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]); - 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; clip_gc_valuemask = GCGraphicsExposures; copy_clipmask_gc = - XCreateGC(display, clipmask[PIX_BACK], clip_gc_valuemask, &clip_gc_values); + XCreateGC(display, pix[PIX_BACK]->clip_mask, + clip_gc_valuemask, &clip_gc_values); clip_gc_values.graphics_exposures = False; clip_gc_valuemask = GCGraphicsExposures; tile_clip_gc = - XCreateGC(display, window, clip_gc_valuemask, &clip_gc_values); + 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 = clipmask[i]; + clip_gc_values.clip_mask = pix[i]->clip_mask; clip_gc_valuemask = GCGraphicsExposures | GCClipMask; - clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values); + pix[i]->stored_clip_gc = XCreateGC(display, window->drawable, + clip_gc_valuemask,&clip_gc_values); } } - /* initialize pixmap array to Pixmap 'None' */ - for(i=0; i=0; i++) { + int j; + for(j=0; jclip_mask; - tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1); + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); - XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc, - src_x,src_y, TILEX,TILEY, 0,0); + XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc, + 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; + int i; - drawto = backbuffer = pix[PIX_DB_BACK]; - 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) - { - sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext); - DrawInitText(basefilename, 150, FC_YELLOW); - sprintf(filename, "%s/%s/%s", - options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename); + InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); + DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW); + DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED); #if defined(PLATFORM_MSDOS) - rest(100); + DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE); + rest(200); #endif + DrawInitText("Loading graphics:",120,FC_GREEN); -#if defined(TARGET_SDL) - /* load image to temporary surface */ - if ((sdl_image_tmp = IMG_Load(filename)) == NULL) - Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError()); - - /* 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()); + for(i=0; ipicture_filename); +void InitGfxBackground() +{ + int x, y; - /* 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]; + drawto = backbuffer; + fieldbuffer = pix[PIX_DB_FIELD]; + SetDrawtoField(DRAW_BACKBUFFER); -#endif /* !TARGET_SDL */ - } + 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); -#if defined(TARGET_X11) - /* check if clip mask was correctly created */ - if (pic->picture_with_mask && !clipmask[pos]) - Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); -#endif + for(x=0; x