X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=824327cc2cecd8cc85c8d33dc37e0894665af2ba;hb=67758fda340e825f188fc6a4caad03381bf031dc;hp=b37667c1f4d334223400ebbfe87ad8d65c08cbf4;hpb=3dc317d10b44cc6b75db10ac194966ad8114d390;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index b37667c1..824327cc 100644 --- a/src/tools.c +++ b/src/tools.c @@ -11,6 +11,8 @@ * tools.c * ***********************************************************/ +#include + #ifdef __FreeBSD__ #include #endif @@ -25,8 +27,6 @@ #include "cartoons.h" #include "network.h" -#include - #ifdef MSDOS extern boolean wait_for_vsync; #endif @@ -89,11 +89,13 @@ void BackToFront() this could mean that we have to wait for the graphics to complete, although we could go on doing calculations for the next frame */ - XSync(display,FALSE); + XSync(display, FALSE); + /* #ifdef MSDOS wait_for_vsync = TRUE; #endif + */ if (redraw_mask & REDRAW_ALL) { @@ -115,13 +117,31 @@ void BackToFront() if (setup.soft_scrolling) { - fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); - fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); + fx += (ScreenMovDir & (MV_LEFT | MV_RIGHT) ? ScreenGfxPos : 0); + fy += (ScreenMovDir & (MV_UP | MV_DOWN) ? ScreenGfxPos : 0); } - XCopyArea(display,buffer,window,gc, - fx,fy, SXSIZE,SYSIZE, - SX,SY); + if (setup.soft_scrolling || + ABS(ScreenMovPos) + ScrollStepSize == TILEX || + ABS(ScreenMovPos) == ScrollStepSize || + redraw_tiles > REDRAWTILES_THRESHOLD) + { + XCopyArea(display, buffer, window, gc, fx, fy, SXSIZE, SYSIZE, SX, SY); + +#ifdef DEBUG +#if 0 + printf("redrawing all (ScreenGfxPos == %d) because %s\n", + ScreenGfxPos, + (setup.soft_scrolling ? + "setup.soft_scrolling" : + ABS(ScreenGfxPos) + ScrollStepSize == TILEX ? + "ABS(ScreenGfxPos) + ScrollStepSize == TILEX" : + ABS(ScreenGfxPos) == ScrollStepSize ? + "ABS(ScreenGfxPos) == ScrollStepSize" : + "redraw_tiles > REDRAWTILES_THRESHOLD")); +#endif +#endif + } } redraw_mask &= ~REDRAW_MAIN; } @@ -157,6 +177,10 @@ void BackToFront() VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS); } } + if (redraw_mask & REDRAW_DOOR_3) + XCopyArea(display, backbuffer, window, gc, + EX, EY, EXSIZE, EYSIZE, + EX, EY); redraw_mask &= ~REDRAW_DOORS; } @@ -281,9 +305,39 @@ void ClearWindow() redraw_mask |= REDRAW_FIELD; } -void DrawText(int x, int y, char *text, int font, int col) +void DrawTextFCentered(int y, int font_type, char *format, ...) +{ + char buffer[FULL_SXSIZE / FONT3_XSIZE + 10]; + int font_xsize; + va_list ap; + + font_xsize = (font_type < FC_SPECIAL1 ? FONT2_XSIZE : + font_type < FC_SPECIAL2 ? FONT3_XSIZE : FONT4_XSIZE); + + va_start(ap, format); + vsprintf(buffer, format, ap); + va_end(ap); + + DrawText(SX + (SXSIZE - strlen(buffer) * font_xsize) / 2, SY + y, + buffer, FS_SMALL, font_type); +} + +void DrawTextF(int x, int y, int font_type, char *format, ...) { - DrawTextExt(drawto, gc, x, y, text, font, col); + char buffer[FULL_SXSIZE / FONT3_XSIZE + 10]; + va_list ap; + + va_start(ap, format); + vsprintf(buffer, format, ap); + va_end(ap); + + DrawText(SX + x, SY + y, buffer, FS_SMALL, font_type); +} + +void DrawText(int x, int y, char *text, int font_size, int font_type) +{ + DrawTextExt(drawto, gc, x, y, text, font_size, font_type); + if (x < DX) redraw_mask |= REDRAW_FIELD; else if (y < VY) @@ -291,23 +345,23 @@ void DrawText(int x, int y, char *text, int font, int col) } void DrawTextExt(Drawable d, GC gc, int x, int y, - char *text, int font, int font_color) + char *text, int font_size, int font_type) { int font_width, font_height, font_start; int font_pixmap; - if (font != FS_SMALL && font != FS_BIG) - font = FS_SMALL; - if (font_color < FC_RED || font_color > FC_SPECIAL2) - font_color = FC_RED; - - font_width = (font == FS_BIG ? FONT1_XSIZE : - font_color < FC_SPECIAL1 ? FONT2_XSIZE : - font_color < FC_SPECIAL2 ? FONT3_XSIZE : FONT4_XSIZE); - font_height = (font == FS_BIG ? FONT1_XSIZE : - font_color < FC_SPECIAL2 ? FONT2_XSIZE : FONT4_XSIZE); - font_pixmap = (font == FS_BIG ? PIX_BIGFONT : PIX_SMALLFONT); - font_start = (font_color * (font == FS_BIG ? FONT1_YSIZE : FONT2_YSIZE) * + if (font_size != FS_SMALL && font_size != FS_BIG) + font_size = FS_SMALL; + if (font_type < FC_RED || font_type > FC_SPECIAL2) + font_type = FC_RED; + + font_width = (font_size == FS_BIG ? FONT1_XSIZE : + font_type < FC_SPECIAL1 ? FONT2_XSIZE : + font_type < FC_SPECIAL2 ? FONT3_XSIZE : FONT4_XSIZE); + font_height = (font_size == FS_BIG ? FONT1_XSIZE : + font_type < FC_SPECIAL2 ? FONT2_XSIZE : FONT4_XSIZE); + font_pixmap = (font_size == FS_BIG ? PIX_BIGFONT : PIX_SMALLFONT); + font_start = (font_type * (font_size == FS_BIG ? FONT1_YSIZE : FONT2_YSIZE) * FONT_LINES_PER_FONT); while(*text) @@ -588,6 +642,14 @@ void DrawGraphicExt(Drawable d, GC gc, int x, int y, int graphic) SY + (graphic / GFX_PER_LINE) * TILEY, TILEX, TILEY, x, y); } + else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) + { + graphic -= GFX_START_ROCKSMORE; + XCopyArea(display, pix[PIX_MORE], d, gc, + (graphic % MORE_PER_LINE) * TILEX, + (graphic / MORE_PER_LINE) * TILEY, + TILEX, TILEY, x, y); + } else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES) { graphic -= GFX_START_ROCKSHEROES; @@ -639,6 +701,14 @@ void DrawGraphicThruMaskExt(Drawable d, int dest_x, int dest_y, int graphic) src_x = SX + (graphic % GFX_PER_LINE) * TILEX; src_y = SY + (graphic / GFX_PER_LINE) * TILEY; } + else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) + { + src_pixmap = pix[PIX_MORE]; + drawing_gc = clip_gc[PIX_MORE]; + graphic -= GFX_START_ROCKSMORE; + src_x = (graphic % MORE_PER_LINE) * TILEX; + src_y = (graphic / MORE_PER_LINE) * TILEY; + } else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES) { src_pixmap = pix[PIX_HEROES]; @@ -688,6 +758,14 @@ void DrawMiniGraphicExt(Drawable d, GC gc, int x, int y, int graphic) MINI_GFX_STARTY + (graphic / MINI_GFX_PER_LINE) * MINI_TILEY, MINI_TILEX, MINI_TILEY, x, y); } + else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) + { + graphic -= GFX_START_ROCKSMORE; + XCopyArea(display, pix[PIX_MORE], d, gc, + MINI_MORE_STARTX + (graphic % MINI_MORE_PER_LINE) * MINI_TILEX, + MINI_MORE_STARTY + (graphic / MINI_MORE_PER_LINE) * MINI_TILEY, + MINI_TILEX, MINI_TILEY, x, y); + } else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT) { graphic -= GFX_START_ROCKSFONT; @@ -789,6 +867,14 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, src_x = SX + (graphic % GFX_PER_LINE) * TILEX + cx; src_y = SY + (graphic / GFX_PER_LINE) * TILEY + cy; } + else if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) + { + src_pixmap = pix[PIX_MORE]; + drawing_gc = clip_gc[PIX_MORE]; + graphic -= GFX_START_ROCKSMORE; + src_x = (graphic % MORE_PER_LINE) * TILEX + cx; + src_y = (graphic / MORE_PER_LINE) * TILEY + cy; + } else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES) { src_pixmap = pix[PIX_HEROES]; @@ -797,6 +883,8 @@ void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, src_x = (graphic % HEROES_PER_LINE) * TILEX + cx; src_y = (graphic / HEROES_PER_LINE) * TILEY + cy; } + else /* big font graphics currently not allowed (and not needed) */ + return; dest_x = FX + x * TILEX + dx; dest_y = FY + y * TILEY + dy; @@ -848,13 +936,14 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, { int ux = LEVELX(x), uy = LEVELY(y); int graphic = el2gfx(element); - int phase4 = ABS(MovPos[ux][uy]) / (TILEX / 4); - int phase = phase4 / 2; + int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8); + int phase4 = phase8 / 2; + int phase2 = phase8 / 4; int dir = MovDir[ux][uy]; if (element == EL_PACMAN || element == EL_KAEFER || element == EL_FLIEGER) { - graphic += 4*!phase; + graphic += 4 * !phase2; if (dir == MV_UP) graphic += 1; @@ -863,6 +952,23 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, else if (dir == MV_DOWN) graphic += 3; } + else if (element == EL_SP_SNIKSNAK) + { + if (dir == MV_LEFT) + graphic = GFX_SP_SNIKSNAK_LEFT; + else if (dir == MV_RIGHT) + graphic = GFX_SP_SNIKSNAK_RIGHT; + else if (dir == MV_UP) + graphic = GFX_SP_SNIKSNAK_UP; + else + graphic = GFX_SP_SNIKSNAK_DOWN; + + graphic += (phase8 < 4 ? phase8 : 7 - phase8); + } + else if (element == EL_SP_ELECTRON) + { + graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); + } else if (element == EL_MAULWURF || element == EL_PINGUIN || element == EL_SCHWEIN || element == EL_DRACHE) { @@ -895,16 +1001,17 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, } else if (element == EL_BUTTERFLY || element == EL_FIREFLY) { - graphic += !phase; + graphic += !phase2; } else if ((element == EL_FELSBROCKEN || IS_GEM(element)) && !cut_mode) { - graphic += phase * (element == EL_FELSBROCKEN ? 2 : 1); + if (element != EL_SP_INFOTRON) + graphic += phase2 * (element == EL_FELSBROCKEN ? 2 : 1); } - else if ((element == EL_SIEB_LEER || element == EL_SIEB2_LEER || - element == EL_SIEB_VOLL || element == EL_SIEB2_VOLL) && SiebAktiv) + else if (element == EL_SIEB_LEER || element == EL_SIEB2_LEER || + element == EL_SIEB_VOLL || element == EL_SIEB2_VOLL) { - graphic += 3 - (SiebAktiv % 8) / 2; + graphic += 3 + getGraphicAnimationPhase(4, 4, ANIM_REVERSE); } else if (IS_AMOEBOID(element)) { @@ -1219,10 +1326,19 @@ void DrawMicroElement(int xpos, int ypos, int element) graphic = el2gfx(element); - XCopyArea(display, pix[PIX_BACK], drawto, gc, - MICRO_GFX_STARTX + (graphic % MICRO_GFX_PER_LINE) * MICRO_TILEX, - MICRO_GFX_STARTY + (graphic / MICRO_GFX_PER_LINE) * MICRO_TILEY, - MICRO_TILEX, MICRO_TILEY, xpos, ypos); + if (graphic >= GFX_START_ROCKSMORE && graphic <= GFX_END_ROCKSMORE) + { + graphic -= GFX_START_ROCKSMORE; + XCopyArea(display, pix[PIX_MORE], drawto, gc, + MICRO_MORE_STARTX + (graphic % MICRO_MORE_PER_LINE) *MICRO_TILEX, + MICRO_MORE_STARTY + (graphic / MICRO_MORE_PER_LINE) *MICRO_TILEY, + MICRO_TILEX, MICRO_TILEY, xpos, ypos); + } + else + XCopyArea(display, pix[PIX_BACK], drawto, gc, + MICRO_GFX_STARTX + (graphic % MICRO_GFX_PER_LINE) * MICRO_TILEX, + MICRO_GFX_STARTY + (graphic / MICRO_GFX_PER_LINE) * MICRO_TILEY, + MICRO_TILEX, MICRO_TILEY, xpos, ypos); } void DrawLevel() @@ -1308,11 +1424,13 @@ boolean Request(char *text, unsigned int req_state) int mx, my, ty, result = -1; unsigned int old_door_state; +#ifndef MSDOS /* pause network game while waiting for request to answer */ if (options.network && game_status == PLAYING && req_state & REQUEST_WAIT_FOR) SendToServer_PausePlaying(); +#endif old_door_state = GetDoorState(); @@ -1514,11 +1632,13 @@ boolean Request(char *text, unsigned int req_state) } } +#ifndef MSDOS /* continue network game after request */ if (options.network && game_status == PLAYING && req_state & REQUEST_WAIT_FOR) SendToServer_ContinuePlaying(); +#endif return(result); } @@ -1561,11 +1681,11 @@ unsigned int GetDoorState() unsigned int MoveDoor(unsigned int door_state) { - static unsigned int door1 = DOOR_OPEN_1; - static unsigned int door2 = DOOR_CLOSE_2; - static long door_delay = 0; + static int door1 = DOOR_OPEN_1; + static int door2 = DOOR_CLOSE_2; + static unsigned long door_delay = 0; int x, start, stepsize = 2; - long door_delay_value = stepsize * 5; + unsigned long door_delay_value = stepsize * 5; if (door_state == DOOR_GET_STATE) return(door1 | door2); @@ -1692,10 +1812,15 @@ unsigned int MoveDoor(unsigned int door_state) int ReadPixel(Drawable d, int x, int y) { - static XImage *pixelimage; + XImage *pixel_image; + unsigned long pixel_value; - pixelimage = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap); - return(XGetPixel(pixelimage, 0, 0)); + pixel_image = XGetImage(display, d, x, y, 1, 1, AllPlanes, ZPixmap); + pixel_value = XGetPixel(pixel_image, 0, 0); + + XDestroyImage(pixel_image); + + return pixel_value; } int el2gfx(int element) @@ -1745,6 +1870,7 @@ int el2gfx(int element) case EL_MORAST_VOLL: return GFX_MORAST_VOLL; case EL_TROPFEN: return GFX_TROPFEN; case EL_BOMBE: return GFX_BOMBE; + case EL_SIEB_INAKTIV: return GFX_SIEB_INAKTIV; case EL_SIEB_LEER: return GFX_SIEB_LEER; case EL_SIEB_VOLL: return GFX_SIEB_VOLL; case EL_SIEB_TOT: return GFX_SIEB_TOT; @@ -1805,6 +1931,7 @@ int el2gfx(int element) case EL_ERZ_EDEL_ROT: return GFX_ERZ_EDEL_ROT; case EL_ERZ_EDEL_LILA: return GFX_ERZ_EDEL_LILA; case EL_MAMPFER2: return GFX_MAMPFER2; + case EL_SIEB2_INAKTIV: return GFX_SIEB2_INAKTIV; case EL_SIEB2_LEER: return GFX_SIEB2_LEER; case EL_SIEB2_VOLL: return GFX_SIEB2_VOLL; case EL_SIEB2_TOT: return GFX_SIEB2_TOT; @@ -1824,10 +1951,23 @@ int el2gfx(int element) case EL_PFEIL_R: return GFX_PFEIL_R; case EL_PFEIL_O: return GFX_PFEIL_O; case EL_PFEIL_U: return GFX_PFEIL_U; + case EL_SPEED_PILL: return GFX_SPEED_PILL; + case EL_SP_TERMINAL_ACTIVE: return GFX_SP_TERMINAL; + default: { if (IS_CHAR(element)) return GFX_CHAR_START + (element - EL_CHAR_START); + else if (element >= EL_SP_START && element <= EL_SP_END) + { + int nr_element = element - EL_SP_START; + int gfx_per_line = 8; + int nr_graphic = + (nr_element / gfx_per_line) * MORE_PER_LINE + + (nr_element % gfx_per_line); + + return GFX_START_ROCKSMORE + nr_graphic; + } else return -1; }