X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=ae65640f67f152bd51070ef2da3027a9a0a7c10b;hb=ae32fd8a4316c5d7f18fe6966f999ebf5509df94;hp=411d54070a0170ff274c47e19b095bfe8a8caa81;hpb=a8b2caa1d373c84c1b3fc2f615370c2a319051ca;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 411d5407..ae65640f 100644 --- a/src/init.c +++ b/src/init.c @@ -13,10 +13,10 @@ #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" @@ -24,50 +24,43 @@ #include "tools.h" #include "files.h" #include "joystick.h" -#include "image.h" -#include "pcx.h" #include "network.h" #include "netserv.h" -struct PictureFileInfo -{ - char *picture_filename; - boolean picture_with_mask; -}; - -#ifndef TARGET_SDL -static int sound_process_id = 0; -#endif - 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 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(MSDOS) || defined(WIN32) +#if !defined(PLATFORM_UNIX) initErrorFile(); #endif if (options.serveronly) { -#ifdef WIN32 - Error(ERR_WARN, "networking not supported in Windows version"); -#else +#if defined(PLATFORM_UNIX) NetworkServer(options.server_port, options.serveronly); +#else + Error(ERR_WARN, "networking not supported in Windows version"); #endif /* never reached */ exit(0); } + InitProgramInfo(UNIX_USERDATA_DIRECTORY, + PROGRAM_TITLE_STRING, WINDOW_TITLE_STRING, + ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, + MSDOS_POINTER_FILENAME); + InitPlayerInfo(); InitCounter(); @@ -79,7 +72,7 @@ void OpenAll(int argc, char *argv[]) signal(SIGINT, CloseAllAndExit); signal(SIGTERM, CloseAllAndExit); - InitBufferedDisplay(&backbuffer, &window); + InitDisplay(); InitEventFilter(FilterMouseMotionEvents); InitGfx(); @@ -121,14 +114,14 @@ void InitLevelInfo() void InitNetworkServer() { -#if !defined(MSDOS) && !defined(WIN32) +#if defined(PLATFORM_UNIX) int nr_wanted; #endif if (!options.network) return; -#if !defined(MSDOS) && !defined(WIN32) +#if defined(PLATFORM_UNIX) nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); if (!ConnectToServer(options.server_host, options.server_port)) @@ -146,43 +139,18 @@ void InitSound() { int i; - if (sound_status == SOUND_OFF) - return; - -#ifdef TARGET_SDL - if (InitAudio()) - { - sound_status = SOUND_AVAILABLE; - sound_loops_allowed = TRUE; - } - else - { - sound_status = SOUND_OFF; - } -#else /* !TARGET_SDL */ + OpenAudio(&audio); -#if !defined(MSDOS) && !defined(WIN32) - if ((sound_status = CheckAudio(sound_device_name)) == SOUND_OFF) - return; - -#ifdef VOXWARE - sound_loops_allowed = TRUE; -#endif - -#else /* MSDOS || WIN32 */ - sound_loops_allowed = TRUE; - -#endif /* MSDOS || WIN32 */ -#endif /* !TARGET_SDL */ + AllocSoundArray(NUM_SOUNDS); for(i=0; iclip_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); } } @@ -525,6 +523,8 @@ void InitGfx() /* create only those clipping Pixmaps we really need */ for(i=0; tile_needs_clipping[i].start>=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); } } @@ -550,7 +551,7 @@ void InitGfxBackground() { int x, y; - drawto = backbuffer = pix[PIX_DB_BACK]; + drawto = backbuffer; fieldbuffer = pix[PIX_DB_FIELD]; SetDrawtoField(DRAW_BACKBUFFER); @@ -565,87 +566,6 @@ void InitGfxBackground() redraw_mask = REDRAW_ALL; } -void LoadGfx(int pos, struct PictureFileInfo *pic) -{ - char basefilename[256]; - char filename[256]; - -#ifdef TARGET_SDL - SDL_Surface *sdl_image_tmp; -#else /* !TARGET_SDL */ - int pcx_err; -#endif /* !TARGET_SDL */ - char *picture_ext = ".pcx"; - - /* Grafik laden */ - if (pic->picture_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); - -#ifdef MSDOS - rest(100); -#endif /* MSDOS */ - -#ifdef 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()); - - /* free temporary surface */ - SDL_FreeSurface(sdl_image_tmp); - -#else /* !TARGET_SDL */ - - pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename, - &pix[pos], &clipmask[pos]); - 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]) - Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); - - /* 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]; - -#endif /* !TARGET_SDL */ - } - -#ifndef TARGET_SDL - /* zugehörige Maske laden (wenn vorhanden) */ - if (pic->picture_with_mask && !clipmask[pos]) - Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); -#endif /* !TARGET_SDL */ -} - void InitGadgets() { CreateLevelEditorGadgets(); @@ -1807,38 +1727,29 @@ void CloseAllAndExit(int exit_value) { int i; -#ifdef TARGET_SDL +#if defined(TARGET_SDL) StopSounds(); FreeSounds(NUM_SOUNDS); #else - if (sound_process_id) + if (audio.soundserver_pid) { StopSounds(); - kill(sound_process_id, SIGTERM); + kill(audio.soundserver_pid, SIGTERM); FreeSounds(NUM_SOUNDS); } #endif for(i=0; i