X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftools.c;h=e241c79adb289bdb3fe69614687019ebf79a8aed;hb=c6f9fba81fc59eff4b6b454dff92adecd28a7ad5;hp=efb413e13c34a21a3ea589c93f8480c85e2954a8;hpb=75ebfce89c39bc740367807c4c16f469135ba6d5;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index efb413e1..e241c79a 100644 --- a/src/tools.c +++ b/src/tools.c @@ -32,7 +32,6 @@ #define NUM_TOOL_BUTTONS 7 /* forward declaration for internal use */ -static int getGraphicAnimationPhase(int, int, int); static void UnmapToolButtons(); static void HandleToolButtons(struct GadgetInfo *); @@ -384,6 +383,39 @@ void ClearWindow() redraw_mask |= REDRAW_FIELD; } +static int getGraphicAnimationPhase(int frames, int delay, int mode) +{ + int phase; + + if (mode & ANIM_PINGPONG) + { + int max_anim_frames = 2 * frames - 2; + + phase = (FrameCounter % (delay * max_anim_frames)) / delay; + phase = (phase < frames ? phase : max_anim_frames - phase); + } + else + phase = (FrameCounter % (delay * frames)) / delay; + + if (mode & ANIM_REVERSE) + phase = -phase; + + return phase; +} + +inline int getGraphicAnimationFrame(int graphic, int sync_frame) +{ + /* animation synchronized with global frame counter, not move position */ + if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) + sync_frame = FrameCounter; + + return getAnimationFrame(new_graphic_info[graphic].anim_frames, + new_graphic_info[graphic].anim_delay, + new_graphic_info[graphic].anim_mode, + new_graphic_info[graphic].anim_start_frame, + sync_frame); +} + void MarkTileDirty(int x, int y) { int xx = redraw_x1 + x; @@ -736,87 +768,26 @@ void DrawPlayer(struct PlayerInfo *player) MarkTileDirty(sx,sy); } -static int getGraphicAnimationPhase(int frames, int delay, int mode) +void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y, + int graphic, int mask_mode) { - int phase; - - if (mode & ANIM_PINGPONG) - { - int max_anim_frames = 2 * frames - 2; + int frame = getGraphicAnimationFrame(graphic, -1); - phase = (FrameCounter % (delay * max_anim_frames)) / delay; - phase = (phase < frames ? phase : max_anim_frames - phase); - } + if (mask_mode == USE_MASKING) + DrawGraphicThruMaskExt(dst_bitmap, x, y, graphic, frame); else - phase = (FrameCounter % (delay * frames)) / delay; - - if (mode & ANIM_REVERSE) - phase = -phase; - - return phase; -} - -int getGraphicAnimationFrame(int graphic, int sync_frame) -{ - int num_frames = new_graphic_info[graphic].anim_frames; - int delay = new_graphic_info[graphic].anim_delay; - int mode = new_graphic_info[graphic].anim_mode; - int frame = 0; - - /* animation synchronized with global frame counter, not move position */ - if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) - sync_frame = FrameCounter; - - sync_frame += new_graphic_info[graphic].anim_start_frame * delay; - - if (mode & ANIM_LOOP) /* normal, looping animation */ - { - frame = (sync_frame % (delay * num_frames)) / delay; - } - else if (mode & ANIM_LINEAR) /* normal, non-looping animation */ - { - frame = sync_frame / delay; - - if (frame > num_frames - 1) - frame = num_frames - 1; - } - else if (mode & ANIM_PINGPONG) /* use border frames once */ - { - int max_anim_frames = 2 * num_frames - 2; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame); - } - else if (mode & ANIM_PINGPONG2) /* use border frames twice */ - { - int max_anim_frames = 2 * num_frames; - - frame = (sync_frame % (delay * max_anim_frames)) / delay; - frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); - } - - if (mode & ANIM_REVERSE) /* use reverse animation direction */ - frame = num_frames - frame - 1; - - return frame; -} - -void DrawGraphicAnimationExt(int x, int y, int graphic, int mask_mode) -{ - if (IN_SCR_FIELD(x, y)) - { - int frame = getGraphicAnimationFrame(graphic, -1); - - if (mask_mode == USE_MASKING) - DrawGraphicThruMask(x, y, graphic, frame); - else - DrawGraphic(x, y, graphic, frame); - } + DrawGraphicExt(dst_bitmap, x, y, graphic, frame); } void DrawGraphicAnimation(int x, int y, int graphic) { - DrawGraphicAnimationExt(x, y, graphic, NO_MASKING); + if (!IN_SCR_FIELD(x, y) || + (FrameCounter % new_graphic_info[graphic].anim_delay) != 0) + return; + + DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY, + graphic, NO_MASKING); + MarkTileDirty(x, y); } #if 1 @@ -908,7 +879,7 @@ void DrawGraphic(int x, int y, int graphic, int frame) MarkTileDirty(x, y); } -#if 1 +#if 0 void DrawOldGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic) { Bitmap *src_bitmap; @@ -998,6 +969,17 @@ void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) int src_x = mini_startx + new_graphic_info[graphic].src_x / 2; int src_y = mini_starty + new_graphic_info[graphic].src_y / 2; + if (src_x + MINI_TILEX > src_bitmap->width || + src_y + MINI_TILEY > src_bitmap->height) + { + /* graphic of desired size seems not to be contained in this image; + dirty workaround: get it from the middle of the normal sized image */ + + getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y); + src_x += (TILEX / 2 - MINI_TILEX / 2); + src_y += (TILEY / 2 - MINI_TILEY / 2); + } + *bitmap = src_bitmap; *x = src_x; *y = src_y; @@ -1715,6 +1697,17 @@ void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y) int src_x = mini_startx + new_graphic_info[graphic].src_x / 8; int src_y = mini_starty + new_graphic_info[graphic].src_y / 8; + if (src_x + MICRO_TILEX > src_bitmap->width || + src_y + MICRO_TILEY > src_bitmap->height) + { + /* graphic of desired size seems not to be contained in this image; + dirty workaround: get it from the middle of the normal sized image */ + + getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y); + src_x += (TILEX / 2 - MICRO_TILEX / 2); + src_y += (TILEY / 2 - MICRO_TILEY / 2); + } + *bitmap = src_bitmap; *x = src_x; *y = src_y;