X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;ds=inline;f=src%2Finit.c;h=2ddbbcd5769c56c30cadc67d8092fc3fefb3f9f2;hb=fe158e864d3fa4b0221e9c88d8dfff0157051396;hp=2f6bb8ed971a97e28b695647c0863c89eb75f9d5;hpb=b2a0ff1ddd4430110b331129469dabb8ea7b6ba7;p=rocksndiamonds.git diff --git a/src/init.c b/src/init.c index 2f6bb8ed..2ddbbcd5 100644 --- a/src/init.c +++ b/src/init.c @@ -1,665 +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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#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" - -#ifdef DEBUG -/* -#define DEBUG_TIMING -*/ -#endif - -struct PictureFileInfo -{ - char *picture_filename; - BOOL picture_with_mask; -}; +#include "network.h" +#include "netserv.h" -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(int, char **); + "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) { + 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); - /* TEST TEST TEST */ - InitServer(); - /* TEST TEST TEST */ - - - InitLevelAndPlayerInfo(); + InitSetup(); + InitPlayerInfo(); InitCounter(); InitSound(); - InitSoundProcess(); - InitJoystick(); + InitJoysticks(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAll); - signal(SIGTERM, CloseAll); + InitVideoDisplay(); + InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, + setup.fullscreen); - InitDisplay(argc, argv); - InitWindow(argc, argv); - - XMapWindow(display, window); - XFlush(display); + InitEventFilter(FilterMouseMotionEvents); InitGfx(); - InitElementProperties(); - - DrawMainMenu(); -} - + InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */ + InitLevelInfo(); + InitGadgets(); /* needs to know number of level series */ -/* TEST STUFF -------------------------------------------------------------- */ - -int norestart = 0; -int nospeedup = 0; - -#define DEFAULTPORT 19503 - -#define PROT_VERS_1 1 -#define PROT_VERS_2 0 -#define PROT_VERS_3 1 - -#define OP_NICK 1 -#define OP_PLAY 2 -#define OP_FALL 3 -#define OP_DRAW 4 -#define OP_LOST 5 -#define OP_GONE 6 -#define OP_CLEAR 7 -#define OP_NEW 8 -#define OP_LINES 9 -#define OP_GROW 10 -#define OP_MODE 11 -#define OP_LEVEL 12 -#define OP_BOT 13 -#define OP_KILL 14 -#define OP_PAUSE 15 -#define OP_CONT 16 -#define OP_VERSION 17 -#define OP_BADVERS 18 -#define OP_MSG 19 -#define OP_YOUARE 20 -#define OP_LINESTO 21 -#define OP_WON 22 -#define OP_ZERO 23 - -/* server stuff */ - -#define BUFLEN 4096 - -int sfd; -unsigned char realbuf[512], readbuf[BUFLEN], writbuf[BUFLEN]; -unsigned char *buf = realbuf + 4; -int nread = 0, nwrite = 0; - -void sysmsg(char *s) -{ - printf("** %s\n", s); - fflush(stdout); -} - -void fatal(char *s) -{ - fprintf(stderr, "%s.\n", s); - exit(1); -} - -void u_sleep(int i) -{ - struct timeval tm; - tm.tv_sec = i / 1000000; - tm.tv_usec = i % 1000000; - select(0, NULL, NULL, NULL, &tm); -} - -void flushbuf() -{ - if (nwrite) - { - write(sfd, writbuf, nwrite); - nwrite = 0; - } -} - -void sendbuf(int len) -{ - if (!standalone) - { - realbuf[0] = realbuf[1] = realbuf[2] = 0; - realbuf[3] = (unsigned char)len; - buf[0] = 0; - if (nwrite + 4 + len >= BUFLEN) - fatal("Internal error: send buffer overflow"); - memcpy(writbuf + nwrite, realbuf, 4 + len); - nwrite += 4 + len; - } -} - -void startserver() -{ - char *options[2]; - int n = 0; - - options[0] = options[1] = NULL; - if (norestart) - options[n++] = "-norestart"; - if (nospeedup) - options[n++] = "-nospeedup"; - - switch (fork()) - { - case 0: - execlp( -#ifdef XTRISPATH - XTRISPATH "/rnd_server", -#else - "rnd_server", -#endif - "rnd_server", "-once", "-v", options[0], options[1], NULL); + InitCustomGraphics(); - fprintf(stderr, "Can't start server '%s'.\n", -#ifdef XTRISPATH - XTRISPATH "/rnd_server" -#else - "rnd_server" -#endif - ); - - _exit(1); - - case -1: - fatal("fork() failed"); - - default: - return; - } -} - -void connect2server(char *host, int port) -{ - struct hostent *hp; - struct sockaddr_in s; - struct protoent *tcpproto; - int on = 1, i; + InitGfxBackground(); + DrawMainMenu(); - if (host) - { - if ((s.sin_addr.s_addr = inet_addr(host)) == -1) - { - hp = gethostbyname(host); - if (!hp) - fatal("Host not found"); - s.sin_addr = *(struct in_addr *)(hp->h_addr_list[0]); - } - } - else - s.sin_addr.s_addr = inet_addr("127.0.0.1"); - - s.sin_port = htons(port); - s.sin_family = AF_INET; - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) - fatal("Out of file descriptors"); - if ((tcpproto = getprotobyname("tcp")) != NULL) - setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int)); - - if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) < 0) - { - if (!host) - { - printf("No rocksndiamonds server on localhost - starting up one ...\n"); - startserver(); - for (i=0; i<6; i++) - { - u_sleep(500000); - close(sfd); - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) - fatal("Out of file descriptors"); - setsockopt(sfd, tcpproto->p_proto, TCP_NODELAY, (char *)&on, sizeof(int)); - if (connect(sfd, (struct sockaddr *)&s, sizeof(s)) >= 0) - break; - } - if (i==6) - fatal("Can't connect to server"); - } - else - fatal("Can't connect to server"); - } + InitNetworkServer(); } -static void send_nickname(char *nickname) +void InitSetup() { - static char msgbuf[300]; - - buf[1] = OP_NICK; - memcpy(&buf[2], nickname, strlen(nickname)); - sendbuf(2 + strlen(nickname)); - sprintf(msgbuf, "you set your nick to %s", nickname); - sysmsg(msgbuf); + LoadSetup(); /* global setup info */ } -void InitServer() +void InitPlayerInfo() { - if (server_port == 0) - server_port = DEFAULTPORT; - - standalone = FALSE; - - if (!standalone) - connect2server(server_host, server_port); - - send_nickname("dummyplayer"); - - buf[1] = OP_VERSION; - buf[2] = PROT_VERS_1; - buf[3] = PROT_VERS_2; - buf[4] = PROT_VERS_3; - sendbuf(5); -} - -/* TEST STUFF -------------------------------------------------------------- */ - - + int i; -void InitLevelAndPlayerInfo() -{ + /* choose default local player */ local_player = &stored_player[0]; - if (!LoadLevelInfo()) /* global level info */ - CloseAll(); + for (i=0; iconnected = TRUE; } -void InitSound() +void InitLevelInfo() { - int i; - - if (sound_status==SOUND_OFF) - return; - -#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; - return; - } - - 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; - return; - } - - close(sound_device); - sound_status=SOUND_AVAILABLE; - -#ifdef VOXWARE - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif -#else - sound_loops_allowed = TRUE; - sound_loops_on = TRUE; -#endif - - for(i=0;ivisual; - XFree((void *)vinfo); - } - - /* 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); - } -} - -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 = - { - "rocks_icon.xbm", - "rocks_iconmask.xbm" - }; -#endif - - screen_width = XDisplayWidth(display, screen); - screen_height = XDisplayHeight(display, screen); - - width = WIN_XSIZE; - height = WIN_YSIZE; - - win_xpos = (screen_width - width) / 2; - win_ypos = (screen_height - height) / 2; - - 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",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); - } - - 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) - { - fprintf(stderr, "%s: cannot read icon bitmap file '%s'.\n", - progname,icon_filename); - exit(-1); - } - - 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; + OpenAudio(); - if (win_xpos || win_ypos) + 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]) - { - fprintf(stderr, "%s: cannot create additional Pixmaps!\n",progname); - CloseAll(); - exit(-1); - } + 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); - CloseAll(); - exit(-1); - } + /* 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: - fprintf(stderr,"Bitmap file open failed on '%s' !\n",filename); - CloseAll(); - exit(-1); - break; - case BitmapFileInvalid: - fprintf(stderr,"Bitmap file invalid: '%s' !\n",filename); - CloseAll(); - exit(-1); - break; - case BitmapNoMemory: - fprintf(stderr,"No memory for file '%s' !\n",filename); - CloseAll(); - exit(-1); - 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]) - { - fprintf(stderr, "%s: cannot get clipmask for '%s'.\n", - progname, pic->picture_filename); - CloseAll(); - exit(-1); - } - } + 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