X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Finit.c;h=f77bd79ef23bb37dcf915ef4fe78e2b0cee4a249;hp=251d32d64d6dd4efbb967486b22acd84cecd146a;hb=8d46c5298f0fcce7bdb52f3835b2fbbdc403dfe0;hpb=046d80f9a1b3fad9d4d3d3aa92dcb3689849aebf diff --git a/src/init.c b/src/init.c index 251d32d6..f77bd79e 100644 --- a/src/init.c +++ b/src/init.c @@ -1,251 +1,460 @@ /*********************************************************** * 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-98 Artsoft Entertainment * +* Holger Schemel * +* Oststrasse 11a * +* 33604 Bielefeld * +* phone: ++49 +521 290471 * +* email: aeglos@valinor.owl.de * *----------------------------------------------------------* * init.c * ***********************************************************/ +#include + #include "init.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 +#include "joystick.h" +#include "image.h" +#include "pcx.h" +#include "network.h" +#include "netserv.h" + +struct PictureFileInfo +{ + char *picture_filename; + boolean picture_with_mask; +}; + +struct IconFileInfo +{ + char *picture_filename; + char *picturemask_filename; +}; static int sound_process_id = 0; +static void InitLevelAndPlayerInfo(void); +static void InitNetworkServer(void); +static void InitDisplay(void); +static void InitSound(void); +static void InitSoundServer(void); +static void InitWindow(int, char **); +static void InitGfx(void); +static void LoadGfx(int, struct PictureFileInfo *); +static void InitGadgets(void); +static void InitElementProperties(void); + void OpenAll(int argc, char *argv[]) { - InitLevelAndPlayerInfo(); +#ifdef MSDOS + initErrorFile(); +#endif + + if (options.serveronly) + { + NetworkServer(options.server_port, options.serveronly); + + /* never reached */ + exit(0); + } InitCounter(); InitSound(); - InitSoundProcess(); - InitJoystick(); + InitSoundServer(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAll); - signal(SIGTERM, CloseAll); + signal(SIGINT, CloseAllAndExit); + signal(SIGTERM, CloseAllAndExit); - InitDisplay(argc, argv); + InitDisplay(); InitWindow(argc, argv); + +#ifndef USE_SDL_LIBRARY + XMapWindow(display, window); + XFlush(display); +#endif + InitGfx(); - InitElementProperties(); + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ + + InitLevelAndPlayerInfo(); + return; + InitGadgets(); /* needs to know number of level series */ DrawMainMenu(); - XMapWindow(display, window); - XFlush(display); + InitNetworkServer(); } void InitLevelAndPlayerInfo() { - if (!LoadLevelInfo()) /* global level info */ - CloseAll(); + int i; + + /* choose default local player */ + local_player = &stored_player[0]; - LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ - LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ + for (i=0; iconnected = TRUE; + + LoadLevelInfo(); /* global level info */ + LoadSetup(); /* global setup info */ + LoadLevelSetup_LastSeries(); /* last played series info */ + LoadLevelSetup_SeriesInfo(); /* last played level info */ +} + +void InitNetworkServer() +{ +#ifndef MSDOS + int nr_wanted; +#endif + + if (!options.network) + return; + +#ifndef MSDOS + 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"); + + SendToServer_PlayerName(setup.player_name); + SendToServer_ProtocolVersion(); + + if (nr_wanted) + SendToServer_NrWanted(nr_wanted); +#endif } void InitSound() { int i; - if (sound_status==SOUND_OFF) + if (sound_status == SOUND_OFF) return; - if (access(sound_device_name,W_OK)<0) +#ifndef MSDOS + if (access(sound_device_name, W_OK) != 0) { - fprintf(stderr,"%s: cannot access sound device - no sounds\n",progname); - sound_status=SOUND_OFF; + Error(ERR_WARN, "cannot access sound device - no sounds"); + sound_status = SOUND_OFF; return; } - if ((sound_device=open(sound_device_name,O_WRONLY))<0) + if ((sound_device = open(sound_device_name,O_WRONLY))<0) { - fprintf(stderr,"%s: cannot open sound device - no sounds\n",progname); - sound_status=SOUND_OFF; + Error(ERR_WARN, "cannot open sound device - no sounds"); + sound_status = SOUND_OFF; return; } close(sound_device); - sound_status=SOUND_AVAILABLE; + sound_status = SOUND_AVAILABLE; #ifdef VOXWARE sound_loops_allowed = TRUE; - sound_loops_on = TRUE; + + /* + setup.sound_loops_on = TRUE; + */ + #endif +#else /* MSDOS */ + sound_loops_allowed = TRUE; - for(i=0;i= num_joysticks) + joystick_nr = -1; - joystick_status = JOYSTICK_AVAILABLE; - LoadJoystickData(); + /* misuse joystick file descriptor variable to store joystick number */ + stored_player[i].joystick_fd = joystick_nr; + } +#endif } -void InitDisplay(int argc, char *argv[]) +void InitDisplay() { - char *display_name = NULL; - int i; +#ifdef USE_SDL_LIBRARY + /* initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO) < 0) + Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError()); - /* get X server to connect to, if given as an argument */ - for (i=1;ivisual; + XFree((void *)vinfo); + } + + /* got appropriate visual? */ + if (depth < 8) { - fprintf(stderr,"%s: cannot connect to X server %s\n", - progname, XDisplayName(display_name)); + printf("Sorry, displays with less than 8 bits per pixel not supported.\n"); exit(-1); } - - screen = DefaultScreen(display); - cmap = DefaultColormap(display, screen); - pen_fg = WhitePixel(display,screen); - pen_bg = BlackPixel(display,screen); + else if ((depth ==8 && visual->class != PseudoColor) || + (depth > 8 && visual->class != TrueColor && + visual->class != DirectColor)) + { + printf("Sorry, cannot get appropriate visual.\n"); + exit(-1); + } +#endif /* !MSDOS */ +#endif /* !USE_SDL_LIBRARY */ } void InitWindow(int argc, char *argv[]) { +#ifdef USE_SDL_LIBRARY + /* open SDL video output device (window or fullscreen mode) */ + if ((sdl_window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH, + SDL_HWSURFACE)) + == NULL) + Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError()); + + /* set window and icon title */ + SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING); + + /* select event types: initially no mouse motion events */ + SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); + +#else /* !USE_SDL_LIBRARY */ + unsigned int border_width = 4; + XGCValues gc_values; + unsigned long gc_valuemask; +#ifndef MSDOS + XTextProperty windowName, iconName; Pixmap icon_pixmap, iconmask_pixmap; - unsigned int icon_width,icon_height; - int icon_hot_x,icon_hot_y; + 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"; + char *window_name = WINDOW_TITLE_STRING; + char *icon_name = WINDOW_TITLE_STRING; long window_event_mask; - static struct PictureFile icon_pic = + Atom proto_atom = None, delete_atom = None; +#endif + 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); + const int width = WIN_XSIZE, height = WIN_YSIZE; + +#ifndef MSDOS + static struct IconFileInfo icon_pic = { "rocks_icon.xbm", "rocks_iconmask.xbm" }; +#endif - width = WIN_XSIZE; - height = WIN_YSIZE; + screen_width = XDisplayWidth(display, screen); + screen_height = XDisplayHeight(display, screen); - window = XCreateSimpleWindow(display, RootWindow(display, screen), - WIN_XPOS, WIN_YPOS, width, height, border_width, - pen_fg, pen_bg); + win_xpos = (screen_width - width) / 2; + win_ypos = (screen_height - height) / 2; - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picture_filename); + window = XCreateSimpleWindow(display, RootWindow(display, screen), + win_xpos, win_ypos, width, height, border_width, + pen_fg, pen_bg); + +#ifndef MSDOS + proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE); + delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE); + if ((proto_atom != None) && (delete_atom != None)) + XChangeProperty(display, window, proto_atom, XA_ATOM, 32, + PropModePrepend, (unsigned char *) &delete_atom, 1); + + sprintf(icon_filename, "%s/%s/%s", + options.ro_base_directory, GRAPHICS_DIRECTORY, + 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); - } + Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename); - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picturemask_filename); + sprintf(icon_filename, "%s/%s/%s", + options.ro_base_directory, GRAPHICS_DIRECTORY, + icon_pic.picturemask_filename); XReadBitmapFile(display,window,icon_filename, &icon_width,&icon_height, &iconmask_pixmap,&icon_hot_x,&icon_hot_y); if (!iconmask_pixmap) - { - fprintf(stderr, "%s: cannot read icon bitmap file '%s'.\n", - progname,icon_filename); - exit(-1); - } + Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename); - size_hints.flags = PSize | PMinSize | PMaxSize; size_hints.width = size_hints.min_width = size_hints.max_width = width; size_hints.height = size_hints.min_height = size_hints.max_height = height; + size_hints.flags = PSize | PMinSize | PMaxSize; - if (!XStringListToTextProperty(&window_name, 1, &windowName)) + if (win_xpos || win_ypos) { - fprintf(stderr, "%s: structure allocation for windowName failed.\n", - progname); - exit(-1); + size_hints.x = win_xpos; + size_hints.y = win_ypos; + size_hints.flags |= PPosition; } + if (!XStringListToTextProperty(&window_name, 1, &windowName)) + Error(ERR_EXIT, "structure allocation for windowName failed"); + if (!XStringListToTextProperty(&icon_name, 1, &iconName)) - { - fprintf(stderr, "%s: structure allocation for iconName failed.\n", - progname); - exit(-1); - } + Error(ERR_EXIT, "structure allocation for iconName failed"); wm_hints.initial_state = NormalState; wm_hints.input = True; @@ -253,7 +462,7 @@ void InitWindow(int argc, char *argv[]) wm_hints.icon_mask = iconmask_pixmap; wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint; - class_hints.res_name = progname; + class_hints.res_name = program_name; class_hints.res_class = "Rocks'n'Diamonds"; XSetWMProperties(display, window, &windowName, &iconName, @@ -264,10 +473,13 @@ void InitWindow(int argc, char *argv[]) XFree(iconName.value); /* Select event types wanted */ - window_event_mask = ExposureMask | StructureNotifyMask | FocusChangeMask | - ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | - KeyPressMask | KeyReleaseMask; + window_event_mask = + ExposureMask | StructureNotifyMask | FocusChangeMask | + ButtonPressMask | ButtonReleaseMask | PointerMotionMask | + PointerMotionHintMask | KeyPressMask | KeyReleaseMask; + XSelectInput(display, window, window_event_mask); +#endif /* create GC for drawing with window depth */ gc_values.graphics_exposures = False; @@ -275,162 +487,477 @@ void InitWindow(int argc, char *argv[]) gc_values.background = pen_bg; gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; gc = XCreateGC(display, window, gc_valuemask, &gc_values); +#endif /* !USE_SDL_LIBRARY */ } 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; + int i,j; + +#ifdef USE_SDL_LIBRARY + SDL_Surface *sdl_image_tmp; +#else + GC copy_clipmask_gc; XGCValues clip_gc_values; unsigned long clip_gc_valuemask; - char filename[256]; - Pixmap shapemask; +#endif - static struct PictureFile pic[NUM_PICTURES] = +#ifdef MSDOS + 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 } + }; +#else + static struct PictureFileInfo pic[NUM_PICTURES] = { - "RocksScreen.xpm", "RocksScreenMaske.xbm", - "RocksDoor.xpm", "RocksDoorMaske.xbm", - "RocksToons.xpm", "RocksToonsMaske.xbm", - "RocksFont.xpm", NULL, - "RocksFont2.xpm", NULL + { "RocksScreen", TRUE }, + { "RocksDoor", TRUE }, + { "RocksHeroes", TRUE }, + { "RocksToons", TRUE }, + { "RocksSP", TRUE }, + { "RocksDC", TRUE }, + { "RocksMore", TRUE }, + { "RocksFont", FALSE }, + { "RocksFont2", FALSE }, + { "RocksFont3", FALSE } }; +#endif - for(i=0;i=0; i++) + { + for(j=0; j=0; i++) + { + for(j=0; jpicture_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 */ + +#if DEBUG_TIMING + debug_print_timestamp(1, NULL); /* initialize timestamp function */ +#endif + +#ifdef USE_SDL_LIBRARY + /* load image to temporary surface */ + if ((sdl_image_tmp = IMG_Load(filename)) == NULL) + Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError()); + + /* create native non-transparent surface for current image */ + if ((sdl_pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", 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 ((sdl_pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError()); + + /* free temporary surface */ + SDL_FreeSurface(sdl_image_tmp); + +#else /* !USE_SDL_LIBRARY */ + +#ifdef USE_XPM_LIBRARY + + xpm_att[pos].valuemask = XpmCloseness; + xpm_att[pos].closeness = 20000; + xpm_err = XpmReadFileToPixmap(display,window,filename, + &pix[pos],&shapemask,&xpm_att[pos]); + switch(xpm_err) + { + case XpmOpenFailed: + Error(ERR_EXIT, "cannot open XPM file '%s'", filename); + case XpmFileInvalid: + Error(ERR_EXIT, "invalid XPM file '%s'", filename); + case XpmNoMemory: + Error(ERR_EXIT, "not enough memory for XPM file '%s'", filename); + case XpmColorFailed: + Error(ERR_EXIT, "cannot get colors for XPM file '%s'", filename); + default: + break; + } + +#if DEBUG_TIMING + printf("LOADING XPM FILE %s:", filename); + debug_print_timestamp(1, ""); +#endif + +#else /* !USE_XPM_LIBRARY */ + + 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 DEBUG_TIMING + printf("SUMMARY LOADING PCX FILE %s:", filename); + debug_print_timestamp(1, ""); +#endif + +#endif /* !USE_XPM_LIBRARY */ + + if (!pix[pos]) + Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename); +#endif /* !USE_SDL_LIBRARY */ + } + +#ifndef USE_SDL_LIBRARY + /* zugehörige Maske laden (wenn vorhanden) */ + if (pic->picture_with_mask) + { +#ifdef USE_XPM_LIBRARY + + sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext); + DrawInitText(basefilename, 150, FC_YELLOW); + sprintf(filename, "%s/%s/%s", + options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename); + +#if DEBUG_TIMING + debug_print_timestamp(1, NULL); /* initialize timestamp function */ +#endif + + 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; + } + +#if DEBUG_TIMING + printf("LOADING XBM FILE %s:", filename); + debug_print_timestamp(1, ""); +#endif + +#endif /* USE_XPM_LIBRARY */ + + if (!clipmask[pos]) + Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename); + } +#endif /* !USE_SDL_LIBRARY */ +} - for(i=0;i