X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=1c56fc0a3d9b7f6cfc782690452bc007333b5ae0;hb=621b6a2c4781c9c3e2f5849f9c184a906e0ce5b6;hp=a8ce6a50bc357ce2dde3cede3b3535b47224973e;hpb=b96c3dc500494652748c24f0aa48a8201ea202dd;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index a8ce6a50..1c56fc0a 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,8 +24,6 @@ #include "tools.h" #include "files.h" #include "joystick.h" -#include "image.h" -#include "pcx.h" #include "network.h" #include "netserv.h" @@ -35,15 +33,12 @@ struct PictureFileInfo boolean picture_with_mask; }; -#ifndef USE_SDL_LIBRARY -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 *); @@ -52,16 +47,16 @@ static void InitElementProperties(void); void OpenAll(int argc, char *argv[]) { -#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 */ @@ -79,7 +74,7 @@ void OpenAll(int argc, char *argv[]) signal(SIGINT, CloseAllAndExit); signal(SIGTERM, CloseAllAndExit); - InitBufferedDisplay(&backbuffer, &window); + InitDisplay(); InitEventFilter(FilterMouseMotionEvents); InitGfx(); @@ -121,14 +116,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,69 +141,7 @@ void InitSound() { int i; - if (sound_status == SOUND_OFF) - return; - -#ifdef USE_SDL_LIBRARY - /* initialize SDL audio */ - - if (SDL_Init(SDL_INIT_AUDIO) < 0) - { - Error(ERR_WARN, "SDL_Init() failed: %s", SDL_GetError()); - sound_status = SOUND_OFF; - return; - } - - if (Mix_OpenAudio(22050, AUDIO_S16, 2, 512) < 0) - { - Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError()); - sound_status = SOUND_OFF; - return; - } - - Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4); - Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4); - - sound_status = SOUND_AVAILABLE; - sound_loops_allowed = TRUE; - -#else /* !USE_SDL_LIBRARY */ - -#if !defined(MSDOS) && !defined(WIN32) - if (access(sound_device_name, W_OK) != 0) - { - Error(ERR_WARN, "cannot access sound device - no sounds"); - sound_status = SOUND_OFF; - return; - } - - if ((sound_device = OpenAudio(sound_device_name)) < 0) - { - Error(ERR_WARN, "cannot open sound device - no sounds"); - sound_status = SOUND_OFF; - return; - } - - close(sound_device); - sound_status = SOUND_AVAILABLE; - -#ifdef VOXWARE - sound_loops_allowed = TRUE; - - /* - setup.sound_loops_on = TRUE; - */ - -#endif -#else /* MSDOS || WIN32 */ - sound_loops_allowed = TRUE; - - /* - setup.sound_loops_on = TRUE; - */ - -#endif /* MSDOS || WIN32 */ -#endif /* !USE_SDL_LIBRARY */ + OpenAudio(&audio); 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); } } @@ -574,23 +532,24 @@ void InitGfx() Pixmap src_pixmap; getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y); - src_pixmap = clipmask[pixmap_nr]; + src_pixmap = pix[pixmap_nr]->clip_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 /* !USE_SDL_LIBRARY */ +#endif /* !TARGET_SDL */ } void InitGfxBackground() { int x, y; - drawto = backbuffer = pix[PIX_DB_BACK]; + drawto = backbuffer; fieldbuffer = pix[PIX_DB_FIELD]; SetDrawtoField(DRAW_BACKBUFFER); @@ -610,11 +569,11 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) char basefilename[256]; char filename[256]; -#ifdef USE_SDL_LIBRARY +#if defined(TARGET_SDL) SDL_Surface *sdl_image_tmp; -#else /* !USE_SDL_LIBRARY */ +#else int pcx_err; -#endif /* !USE_SDL_LIBRARY */ +#endif char *picture_ext = ".pcx"; /* Grafik laden */ @@ -625,11 +584,13 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) sprintf(filename, "%s/%s/%s", options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename); -#ifdef MSDOS +#if defined(PLATFORM_MSDOS) rest(100); -#endif /* MSDOS */ +#endif -#ifdef USE_SDL_LIBRARY + pix[pos] = CreateBitmapStruct(); + +#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()); @@ -647,10 +608,11 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) /* free temporary surface */ SDL_FreeSurface(sdl_image_tmp); -#else /* !USE_SDL_LIBRARY */ +#else /* !TARGET_SDL */ - pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename, - &pix[pos], &clipmask[pos]); + 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: @@ -669,21 +631,23 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) break; } - if (!pix[pos]) + 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]; +#endif -#endif /* !USE_SDL_LIBRARY */ +#endif /* !TARGET_SDL */ } -#ifndef USE_SDL_LIBRARY - /* zugehörige Maske laden (wenn vorhanden) */ - if (pic->picture_with_mask && !clipmask[pos]) +#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 /* !USE_SDL_LIBRARY */ +#endif } void InitGadgets() @@ -1847,38 +1811,29 @@ void CloseAllAndExit(int exit_value) { int i; -#ifdef USE_SDL_LIBRARY +#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