From: Holger Schemel Date: Sat, 21 Jan 2023 12:32:29 +0000 (+0100) Subject: improved performance of game actions loop in MM engine X-Git-Tag: 4.3.5.0~33 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=97849fee52785abc83312cb229cb481eeb530b6b;p=rocksndiamonds.git improved performance of game actions loop in MM engine --- diff --git a/src/engines.h b/src/engines.h index 4f9aa1e0..254f82d4 100644 --- a/src/engines.h +++ b/src/engines.h @@ -71,6 +71,7 @@ int getGraphicAnimationFrameXY(int, int, int); void getGraphicSource(int, int, Bitmap **, int *, int *); void getMiniGraphicSource(int, Bitmap **, int *, int *); void getSizedGraphicSource(int, int, int, Bitmap **, int *, int *); +boolean getGraphicInfo_NewFrame(int, int, int); void AdvanceFrameCounter(void); void AdvanceGfxFrame(void); diff --git a/src/game_mm/mm_game.c b/src/game_mm/mm_game.c index 316c891e..326880f1 100644 --- a/src/game_mm/mm_game.c +++ b/src/game_mm/mm_game.c @@ -2553,33 +2553,43 @@ static void GrowAmoeba(int x, int y) } static void DrawFieldAnimated_MM(int x, int y) +{ + DrawField_MM(x, y); + + laser.redraw = TRUE; +} + +static void DrawFieldAnimatedIfNeeded_MM(int x, int y) { int element = Tile[x][y]; + int graphic = el2gfx(element); - if (IS_BLOCKED(x, y)) + if (!getGraphicInfo_NewFrame(x, y, graphic)) return; DrawField_MM(x, y); - if (IS_MIRROR(element) || - IS_MIRROR_FIXED(element) || - element == EL_PRISM) + laser.redraw = TRUE; +} + +static void DrawFieldTwinkle(int x, int y) +{ + if (MovDelay[x][y] != 0) // wait some time before next frame { - if (MovDelay[x][y] != 0) // wait some time before next frame - { - MovDelay[x][y]--; + MovDelay[x][y]--; - if (MovDelay[x][y] != 0) - { - int graphic = IMG_TWINKLE_WHITE; - int frame = getGraphicAnimationFrame(graphic, 10 - MovDelay[x][y]); + DrawField_MM(x, y); - DrawGraphicThruMask_MM(SCREENX(x), SCREENY(y), graphic, frame); - } + if (MovDelay[x][y] != 0) + { + int graphic = IMG_TWINKLE_WHITE; + int frame = getGraphicAnimationFrame(graphic, 10 - MovDelay[x][y]); + + DrawGraphicThruMask_MM(SCREENX(x), SCREENY(y), graphic, frame); } - } - laser.redraw = TRUE; + laser.redraw = TRUE; + } } static void Explode_MM(int x, int y, int phase, int mode) @@ -3223,8 +3233,16 @@ static void GameActions_MM_Ext(void) MeltIce(x, y); else if (IS_WALL_CHANGING(element) && Store[x][y] == EL_WALL_AMOEBA) GrowAmoeba(x, y); - else + else if (IS_MIRROR(element) || + IS_MIRROR_FIXED(element) || + element == EL_PRISM) + DrawFieldTwinkle(x, y); + else if (element == EL_GRAY_BALL_OPENING || + element == EL_BOMB_ACTIVE || + element == EL_MINE_ACTIVE) DrawFieldAnimated_MM(x, y); + else if (!IS_BLOCKED(x, y)) + DrawFieldAnimatedIfNeeded_MM(x, y); } AutoRotateMirrors(); diff --git a/src/tools.c b/src/tools.c index fbfb601a..5e5a2e1d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -9427,6 +9427,17 @@ int getGraphicInfo_Delay(int graphic) return graphic_info[graphic].anim_delay; } +boolean getGraphicInfo_NewFrame(int x, int y, int graphic) +{ + if (!IS_NEW_FRAME(GfxFrame[x][y], graphic)) + return FALSE; + + if (ANIM_MODE(graphic) & (ANIM_TILED | ANIM_RANDOM_STATIC)) + return FALSE; + + return TRUE; +} + void PlayMenuSoundExt(int sound) { if (sound == SND_UNDEFINED)