X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Finit.c;h=ef6586f701c4f6465f59766db271a4c1a7fb0555;hb=19db00ff98326cb4b92cea42080d7094e0842243;hp=8032ffb3d82bd798bd690dea25364937cdc4c3a8;hpb=c3d03cdffce070695ba0520d00667b42b8460087;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 8032ffb3..ef6586f7 100644 --- a/src/init.c +++ b/src/init.c @@ -1,436 +1,469 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* ©1995 Artsoft Development * -* Holger Schemel * -* 33659 Bielefeld-Senne * -* Telefon: (0521) 493245 * -* eMail: aeglos@valinor.owl.de * -* aeglos@uni-paderborn.de * -* q99492@pbhrzx.uni-paderborn.de * +* (c) 1995-2001 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* init.c * +* init.c * ***********************************************************/ +#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 - -static int sound_process_id = 0; +#include "network.h" +#include "netserv.h" +#include "cartoons.h" +#include "config.h" -void OpenAll(int argc, char *argv[]) +static char *image_filename[NUM_PICTURES] = +{ + "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 InitArtworkInfo(void); +static void InitNetworkServer(void); +static void InitSoundServer(void); +static void InitSound(void); +static void InitGfx(void); +static void InitGfxBackground(void); +static void InitGadgets(void); +static void InitElementProperties(void); + +void OpenAll(void) { - InitLevelAndPlayerInfo(); + 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, getWindowTitleString(), + ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, + MSDOS_POINTER_FILENAME, + COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); + + InitSetup(); + InitPlayerInfo(); + InitArtworkInfo(); /* needed before loading gfx, sound & music */ InitCounter(); - InitSound(); - InitSoundProcess(); - InitJoystick(); + InitSoundServer(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAll); - signal(SIGTERM, CloseAll); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); + + InitEventFilter(FilterMouseMotionEvents); - InitDisplay(argc, argv); - InitWindow(argc, argv); InitGfx(); - InitElementProperties(); + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ + + InitLevelInfo(); + InitGadgets(); /* needs to know number of level series */ + InitSound(); /* needs to know current level directory */ + + InitGfxBackground(); + InitToons(); DrawMainMenu(); - XMapWindow(display, window); - XFlush(display); + InitNetworkServer(); } -void InitLevelAndPlayerInfo() +void InitSetup() { - if (!LoadLevelInfo()) /* global level info */ - CloseAll(); - - LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ - LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ + LoadSetup(); /* global setup info */ } -void InitSound() +void InitPlayerInfo() { int i; - if (sound_status==SOUND_OFF) - return; + /* choose default local player */ + local_player = &stored_player[0]; - if (access(sound_device_name,W_OK)<0) - { - fprintf(stderr,"%s: cannot access sound device - no sounds\n",progname); - sound_status=SOUND_OFF; - return; - } + for (i=0; iconnected = TRUE; +} + +void InitLevelInfo() +{ + LoadLevelInfo(); /* global level info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ +} + +void InitArtworkInfo() +{ + LoadArtworkInfo(); +} + +void InitNetworkServer() +{ +#if defined(PLATFORM_UNIX) + int nr_wanted; +#endif + + if (!options.network) return; - } - close(sound_device); - sound_status=SOUND_AVAILABLE; +#if defined(PLATFORM_UNIX) + nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED); + + if (!ConnectToServer(options.server_host, options.server_port)) + Error(ERR_EXIT, "cannot connect to network game server"); -#ifdef VOXWARE - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; + SendToServer_PlayerName(setup.player_name); + SendToServer_ProtocolVersion(); + + if (nr_wanted) + SendToServer_NrWanted(nr_wanted); #endif +} - for(i=0;iname); + InitReloadMusic(artwork.mus_current->name); +} - if (access(joystick_device_name[joystick_nr],R_OK)<0) +static void InitTileClipmasks() +{ +#if defined(TARGET_X11) + XGCValues clip_gc_values; + unsigned long clip_gc_valuemask; + +#if defined(TARGET_X11_NATIVE) + GC copy_clipmask_gc; + + static struct { - fprintf(stderr,"%s: cannot access joystick device '%s'\n", - progname,joystick_device_name[joystick_nr]); - joystick_status = JOYSTICK_OFF; - return; + int start; + int count; } + tile_needs_clipping[] = + { + { GFX_SPIELER1_UP, 4 }, + { GFX_SPIELER1_DOWN, 4 }, + { GFX_SPIELER1_LEFT, 4 }, + { GFX_SPIELER1_RIGHT, 4 }, + { GFX_SPIELER1_PUSH_LEFT, 4 }, + { GFX_SPIELER1_PUSH_RIGHT, 4 }, + { GFX_SPIELER2_UP, 4 }, + { GFX_SPIELER2_DOWN, 4 }, + { GFX_SPIELER2_LEFT, 4 }, + { GFX_SPIELER2_RIGHT, 4 }, + { GFX_SPIELER2_PUSH_LEFT, 4 }, + { GFX_SPIELER2_PUSH_RIGHT, 4 }, + { GFX_SPIELER3_UP, 4 }, + { GFX_SPIELER3_DOWN, 4 }, + { GFX_SPIELER3_LEFT, 4 }, + { GFX_SPIELER3_RIGHT, 4 }, + { GFX_SPIELER3_PUSH_LEFT, 4 }, + { GFX_SPIELER3_PUSH_RIGHT, 4 }, + { GFX_SPIELER4_UP, 4 }, + { GFX_SPIELER4_DOWN, 4 }, + { GFX_SPIELER4_LEFT, 4 }, + { GFX_SPIELER4_RIGHT, 4 }, + { GFX_SPIELER4_PUSH_LEFT, 4 }, + { GFX_SPIELER4_PUSH_RIGHT, 4 }, + { GFX_SP_MURPHY, 1 }, + { GFX_MURPHY_GO_LEFT, 3 }, + { GFX_MURPHY_GO_RIGHT, 3 }, + { GFX_MURPHY_SNAP_UP, 1 }, + { GFX_MURPHY_SNAP_DOWN, 1 }, + { GFX_MURPHY_SNAP_RIGHT, 1 }, + { GFX_MURPHY_SNAP_LEFT, 1 }, + { GFX_MURPHY_PUSH_RIGHT, 1 }, + { GFX_MURPHY_PUSH_LEFT, 1 }, + { GFX_GEBLUBBER, 4 }, + { GFX_DYNAMIT, 7 }, + { GFX_DYNABOMB, 4 }, + { GFX_EXPLOSION, 8 }, + { GFX_SOKOBAN_OBJEKT, 1 }, + { GFX_FUNKELN_BLAU, 3 }, + { GFX_FUNKELN_WEISS, 3 }, + { GFX2_SHIELD_PASSIVE, 3 }, + { GFX2_SHIELD_ACTIVE, 3 }, + { -1, 0 } + }; +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ - if ((joystick_device=open(joystick_device_name[joystick_nr],O_RDONLY))<0) + int i; + + /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */ + for(i=0; idrawable, clip_gc_valuemask, &clip_gc_values); + + 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); + } } - joystick_status = JOYSTICK_AVAILABLE; - LoadJoystickData(); -} +#if defined(TARGET_X11_NATIVE) -void InitDisplay(int argc, char *argv[]) -{ - char *display_name = NULL; - int i; + /* create graphic context structures needed for clipping */ + clip_gc_values.graphics_exposures = False; + clip_gc_valuemask = GCGraphicsExposures; + copy_clipmask_gc = + XCreateGC(display, pix[PIX_BACK]->clip_mask, + clip_gc_valuemask, &clip_gc_values); - /* get X server to connect to, if given as an argument */ - for (i=1;i=0; i++) { - char *dispstr="-display"; - int len=MAX(strlen(dispstr),strlen(argv[i])); + int j; - if (len<4) - continue; - else if (!strncmp(argv[i],dispstr,len)) + for(j=0; jclip_mask; + + 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); } } - /* connect to X server */ - if (!(display=XOpenDisplay(display_name))) - { - fprintf(stderr,"%s: cannot connect to X server %s\n", - progname, XDisplayName(display_name)); - exit(-1); - } - - screen = DefaultScreen(display); - cmap = DefaultColormap(display, screen); - pen_fg = WhitePixel(display,screen); - pen_bg = BlackPixel(display,screen); + XFreeGC(display, copy_clipmask_gc); + +#endif /* TARGET_X11_NATIVE */ +#endif /* TARGET_X11 */ } -void InitWindow(int argc, char *argv[]) +void FreeTileClipmasks() { - 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 = "Rocks'n'Diamonds"; - char *icon_name = "Rocks'n'Diamonds"; - long window_event_mask; - static struct PictureFile icon_pic = - { - "rocks_icon.xbm", - "rocks_iconmask.xbm" - }; - - width = WIN_XSIZE; - height = WIN_YSIZE; - - window = XCreateSimpleWindow(display, RootWindow(display, screen), - WIN_XPOS, WIN_YPOS, width, height, border_width, - pen_fg, pen_bg); - - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picture_filename); - XReadBitmapFile(display,window,icon_filename, - &icon_width,&icon_height, - &icon_pixmap,&icon_hot_x,&icon_hot_y); - if (!icon_pixmap) - { - fprintf(stderr, "%s: cannot read icon bitmap file '%s'.\n", - progname,icon_filename); - exit(-1); - } +#if defined(TARGET_X11) + int i; - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picturemask_filename); - XReadBitmapFile(display,window,icon_filename, - &icon_width,&icon_height, - &iconmask_pixmap,&icon_hot_x,&icon_hot_y); - if (!iconmask_pixmap) + for(i=0; istored_clip_gc) + { + XFreeGC(display, pix[i]->stored_clip_gc); + pix[i]->stored_clip_gc = None; + } } - - wm_hints.initial_state = NormalState; - wm_hints.input = True; - wm_hints.icon_pixmap = icon_pixmap; - wm_hints.icon_mask = iconmask_pixmap; - wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint; - - class_hints.res_name = progname; - class_hints.res_class = "Rocks'n'Diamonds"; - - XSetWMProperties(display, window, &windowName, &iconName, - argv, argc, &size_hints, &wm_hints, - &class_hints); - - XFree(windowName.value); - XFree(iconName.value); - - /* Select event types wanted */ - window_event_mask = ExposureMask | StructureNotifyMask | FocusChangeMask | - ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - KeyPressMask | KeyReleaseMask; - XSelectInput(display, window, window_event_mask); - - /* create GC for drawing with window depth */ - gc_values.graphics_exposures = False; - gc_values.foreground = pen_bg; - gc_values.background = pen_bg; - gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; - gc = XCreateGC(display, window, gc_valuemask, &gc_values); +#endif /* TARGET_X11 */ } void InitGfx() { - int i,j,x,y; - int xpm_err, xbm_err; - unsigned int width,height; - int hot_x,hot_y; - XGCValues gc_values; - unsigned long gc_valuemask; - XGCValues clip_gc_values; - unsigned long clip_gc_valuemask; - char filename[256]; - Pixmap shapemask; + int i; - static struct PictureFile pic[NUM_PICTURES] = - { - "RocksScreen.xpm", "RocksScreenMaske.xbm", - "RocksDoor.xpm", "RocksDoorMaske.xbm", - "RocksToons.xpm", "RocksToonsMaske.xbm", - "RocksFont.xpm", NULL, - "RocksFont2.xpm", NULL - }; + /* 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); + + pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]); + + InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]); - for(i=0;iname) { - if (clipmask[i]) + int i; + + ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE); + + for(i=0; iname; + } + + if (artwork.sounds_set_current != artwork.snd_current->name) + { + InitReloadSounds(artwork.snd_current->name); + + artwork.sounds_set_current = artwork.snd_current->name; } - drawto = drawto_field = backbuffer = pix[PIX_DB_BACK]; + if (artwork.music_set_current != artwork.mus_current->name) + { + InitReloadMusic(artwork.mus_current->name); - XCopyArea(display,pix[PIX_BACK],backbuffer,gc, - 0,0, WIN_XSIZE,WIN_YSIZE, 0,0); - XFillRectangle(display,backbuffer,gc, - REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE); + artwork.music_set_current = artwork.mus_current->name; + } +} - for(i=0;i