X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=2ddbbcd5769c56c30cadc67d8092fc3fefb3f9f2;hb=fe158e864d3fa4b0221e9c88d8dfff0157051396;hp=d466c7e5a215b132c128eaf448bb10478d08626f;hpb=e557b2b5d9951a4e692fd4e32a5cf45c84252c64;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index d466c7e5..2ddbbcd5 100644 --- a/src/init.c +++ b/src/init.c @@ -1,409 +1,180 @@ /*********************************************************** -* 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 "misc.h" -#include "sound.h" +#include "events.h" #include "screens.h" +#include "editor.h" +#include "game.h" +#include "tape.h" #include "tools.h" #include "files.h" -#include "joystick.h" -#include "gfxload.h" -#include "gifload.h" #include "network.h" +#include "netserv.h" -#ifdef DEBUG -/* -#define DEBUG_TIMING -*/ -#endif - -struct PictureFileInfo -{ - char *picture_filename; - BOOL picture_with_mask; -}; - -struct IconFileInfo +static char *image_filename[NUM_PICTURES] = { - char *picture_filename; - char *picturemask_filename; -}; - -static int sound_process_id = 0; - -static void InitServer(void); -static void InitLevelAndPlayerInfo(void); -static void InitDisplay(void); + "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 InitSoundProcess(void); -static void InitWindow(int, char **); static void InitGfx(void); -static void LoadGfx(int, struct PictureFileInfo *); +static void InitCustomGraphics(void); +static void InitGfxBackground(void); +static void InitGadgets(void); static void InitElementProperties(void); -void OpenAll(int argc, char *argv[]) +void OpenAll(void) { - InitLevelAndPlayerInfo(); - InitServer(); + if (options.serveronly) + { +#if defined(PLATFORM_UNIX) + NetworkServer(options.server_port, options.serveronly); +#else + Error(ERR_WARN, "networking only supported in Unix version"); +#endif + 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(); - InitSoundProcess(); - InitJoystick(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAllAndExit); - signal(SIGTERM, CloseAllAndExit); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); - InitDisplay(); - InitWindow(argc, argv); - - XMapWindow(display, window); - XFlush(display); + InitEventFilter(FilterMouseMotionEvents); InitGfx(); - InitElementProperties(); + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ - DrawMainMenu(); -} + InitLevelInfo(); + InitGadgets(); /* needs to know number of level series */ -void InitLevelAndPlayerInfo() -{ - local_player = &stored_player[0]; + InitCustomGraphics(); - if (!LoadLevelInfo()) /* global level info */ - Error(ERR_EXIT, NULL); + InitGfxBackground(); + DrawMainMenu(); - LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ - LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ + InitNetworkServer(); } -void InitServer() +void InitSetup() { - standalone = FALSE + TRUE; - - if (standalone) - return; - - if (!ConnectToServer(server_host, server_port)) - Error(ERR_EXIT, "cannot connect to multiplayer server"); - - SendNicknameToServer(local_player->alias_name); - SendProtocolVersionToServer(); + LoadSetup(); /* global setup info */ } -void InitSound() +void InitPlayerInfo() { int i; - if (sound_status==SOUND_OFF) - return; - -#ifndef MSDOS - if (access(sound_device_name,W_OK)<0) - { - Error(ERR_RETURN, "cannot access sound device - no sounds"); - sound_status = SOUND_OFF; - return; - } - - if ((sound_device=open(sound_device_name,O_WRONLY))<0) - { - Error(ERR_RETURN, "cannot open sound device - no sounds"); - sound_status = SOUND_OFF; - return; - } - - close(sound_device); - sound_status=SOUND_AVAILABLE; + /* choose default local player */ + local_player = &stored_player[0]; -#ifdef VOXWARE - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif -#else - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif + for (i=0; iconnected = TRUE; } -void InitSoundProcess() +void InitLevelInfo() { - if (sound_status==SOUND_OFF) - return; - -#ifndef MSDOS - if (pipe(sound_pipe)<0) - { - Error(ERR_RETURN, "cannot create pipe - no sounds"); - sound_status=SOUND_OFF; - return; - } - - if ((sound_process_id=fork())<0) - { - Error(ERR_RETURN, "cannot create child process - no sounds"); - sound_status=SOUND_OFF; - return; - } - - if (!sound_process_id) /* we are child */ - SoundServer(); - else /* we are parent */ - close(sound_pipe[0]); /* no reading from pipe needed */ -#else - SoundServer(); -#endif + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ } -void InitJoystick() +void InitNetworkServer() { - if (global_joystick_status==JOYSTICK_OFF) - return; +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif -#ifndef MSDOS - if (access(joystick_device_name[joystick_nr],R_OK)<0) - { - Error(ERR_RETURN, "cannot access joystick device '%s'", - joystick_device_name[joystick_nr]); - joystick_status = JOYSTICK_OFF; + if (!options.network) return; - } - if ((joystick_device=open(joystick_device_name[joystick_nr],O_RDONLY))<0) - { - Error(ERR_RETURN, "cannot open joystick device '%s'", - joystick_device_name[joystick_nr]); - joystick_status = JOYSTICK_OFF; - return; - } +#if defined(PLATFORM_UNIX) + nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); - joystick_status = JOYSTICK_AVAILABLE; - LoadJoystickData(); -#else - joystick_status = JOYSTICK_AVAILABLE; + if (!ConnectToServer(options.server_host, options.server_port)) + Error(ERR_EXIT, "cannot connect to network game server"); + + SendToServer_PlayerName(setup.player_name); + SendToServer_ProtocolVersion(); + + if (nr_wanted) + SendToServer_NrWanted(nr_wanted); #endif } -void InitDisplay() +void InitSound() { - XVisualInfo vinfo_template, *vinfo; - int num_visuals; - unsigned int depth; - - /* connect to X server */ - if (!(display = XOpenDisplay(display_name))) - Error(ERR_EXIT,"cannot connect to X server %s",XDisplayName(display_name)); - - screen = DefaultScreen(display); - visual = DefaultVisual(display, screen); - depth = DefaultDepth(display, screen); - cmap = DefaultColormap(display, screen); - - /* look for good enough visual */ - vinfo_template.screen = screen; - vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor); - vinfo_template.depth = depth; - if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask | - VisualDepthMask, &vinfo_template, &num_visuals))) - { - visual = vinfo->visual; - XFree((void *)vinfo); - } + int i; - /* got appropriate visual? */ - if (depth < 8) - { - printf("Sorry, displays with less than 8 bits per pixel not supported.\n"); - exit(-1); - } - else if ((depth ==8 && visual->class != PseudoColor) || - (depth > 8 && visual->class != TrueColor && - visual->class != DirectColor)) - { - printf("Sorry, cannot get appropriate visual.\n"); - exit(-1); - } -} + OpenAudio(); -void InitWindow(int argc, char *argv[]) -{ - unsigned int border_width = 4; - Pixmap icon_pixmap, iconmask_pixmap; - unsigned int icon_width,icon_height; - int icon_hot_x,icon_hot_y; - char icon_filename[256]; - XSizeHints size_hints; - XWMHints wm_hints; - XClassHint class_hints; - XTextProperty windowName, iconName; - XGCValues gc_values; - unsigned long gc_valuemask; - char *window_name = WINDOWTITLE_STRING; - char *icon_name = WINDOWTITLE_STRING; - long window_event_mask; - Atom proto_atom = None, delete_atom = None; - int screen_width, screen_height; - int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS; - unsigned long pen_fg = WhitePixel(display,screen); - unsigned long pen_bg = BlackPixel(display,screen); - -#ifndef MSDOS - static struct IconFileInfo icon_pic = + 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); - /* initialize pixmap array to Pixmap 'None' */ - for(i=0; iclip_mask) + { + clip_gc_values.graphics_exposures = False; + clip_gc_values.clip_mask = pix[i]->clip_mask; + clip_gc_valuemask = GCGraphicsExposures | GCClipMask; + pix[i]->stored_clip_gc = XCreateGC(display, window->drawable, + clip_gc_valuemask,&clip_gc_values); + } + } +#if defined(TARGET_X11_NATIVE) /* create only those clipping Pixmaps we really need */ for(i=0; tile_needs_clipping[i].start>=0; i++) { + int j; + for(j=0; j= GFX_START_ROCKSSCREEN && - graphic <= GFX_END_ROCKSSCREEN) - { - src_pixmap = clipmask[PIX_BACK]; - graphic -= GFX_START_ROCKSSCREEN; - src_x = SX + (graphic % GFX_PER_LINE) * TILEX; - src_y = SY + (graphic / GFX_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSHEROES && - graphic <= GFX_END_ROCKSHEROES) - { - src_pixmap = clipmask[PIX_HEROES]; - graphic -= GFX_START_ROCKSHEROES; - src_x = (graphic % HEROES_PER_LINE) * TILEX; - src_y = (graphic / HEROES_PER_LINE) * TILEY; - } - else if (graphic >= GFX_START_ROCKSFONT && - graphic <= GFX_END_ROCKSFONT) - { - src_pixmap = clipmask[PIX_BIGFONT]; - graphic -= GFX_START_ROCKSFONT; - src_x = (graphic % FONT_CHARS_PER_LINE) * TILEX; - src_y = (graphic / FONT_CHARS_PER_LINE) * TILEY + - FC_SPECIAL1 * FONT_LINES_PER_FONT * TILEY; - } - else - break; - - tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1); - - XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc, - src_x,src_y, TILEX,TILEY, 0,0); - } - } + getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y); + src_pixmap = pix[pixmap_nr]->clip_mask; - if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR]) - Error(ERR_EXIT, "cannot create additional pixmaps"); + tile_clipmask[tile] = XCreatePixmap(display, window->drawable, + TILEX, TILEY, 1); - for(i=0;ipicture_filename) - { - sprintf(basefilename,"%s%s",pic->picture_filename,picture_ext); - DrawInitText(basefilename,150,FC_YELLOW); - sprintf(filename,"%s/%s",GFX_PATH,basefilename); + /* 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); -#ifdef MSDOS - rest(100); -#endif MSDOS + /* 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); -#ifdef DEBUG_TIMING - count1 = Counter(); -#endif + pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]); -#ifdef XPM_INCLUDE_FILE + InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); - xpm_att[pos].valuemask = XpmCloseness; - xpm_att[pos].closeness = 20000; - xpm_err = XpmReadFileToPixmap(display,window,filename, - &pix[pos],&shapemask,&xpm_att[pos]); + 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); - switch(xpm_err) + for(i=0; ipicture_filename); + /* look for optional directory ~/./graphics */ + filename = getPath2(getUserDataDir(), GRAPHICS_DIRECTORY); + if (access(dir, F_OK) == 0) + { } - /* zugehörige Maske laden (wenn vorhanden) */ - if (pic->picture_with_mask) - { -#ifdef XPM_INCLUDE_FILE - sprintf(basefilename,"%s%s",pic->picture_filename,picturemask_ext); - DrawInitText(basefilename,150,FC_YELLOW); - sprintf(filename,"%s/%s",GFX_PATH,basefilename); -#ifdef DEBUG_TIMING - count1 = Counter(); -#endif +(leveldir_current->user_defined ? + getUserLevelDir("") : + options.level_directory), + leveldir_current->fullpath, + basename); - xbm_err = XReadBitmapFile(display,window,filename, - &width,&height,&clipmask[pos],&hot_x,&hot_y); - switch(xbm_err) - { - case BitmapSuccess: - break; - case BitmapOpenFailed: - Error(ERR_EXIT, "cannot open XBM file '%s'", filename); - case BitmapFileInvalid: - Error(ERR_EXIT, "invalid XBM file '%s'", filename); - case BitmapNoMemory: - Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename); - break; - default: - break; - } -#ifdef DEBUG_TIMING - count2 = Counter(); - printf("XBM LOADING %s IN %.2f SECONDS\n", - filename,(float)(count2-count1)/1000.0); + filename = getPath3((leveldir_current->user_defined ? + getUserLevelDir("") : + options.level_directory), + leveldir_current->fullpath, + basename); #endif +} -#endif +void InitGfxBackground() +{ + int x, y; - if (!clipmask[pos]) - Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); - } + 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