X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=32f7b638d094bb7d3de5bc419576eccbe42110ea;hb=d905e6df72c773e1943694b96710a2bc25cc863e;hp=8d0fe8deab0d5524716148911957e9aa00005232;hpb=f7704e2d22e9499efe6380e0c916c2bd4918e4be;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index 8d0fe8de..32f7b638 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1,7 +1,7 @@ /*********************************************************** * Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-2002 Artsoft Entertainment * +* (c) 1995-2006 Artsoft Entertainment * * Holger Schemel * * Detmolder Strasse 189 * * 33604 Bielefeld * @@ -138,8 +138,10 @@ void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height) level.game_engine_type == GAME_ENGINE_TYPE_EM) { /* currently there is no partial redraw -- always redraw whole playfield */ - RedrawPlayfield_EM(TRUE); + + /* blit playfield from scroll buffer to normal back buffer for fading in */ + BlitScreenToBitmap_EM(backbuffer); } else if (game_status == GAME_MODE_PLAYING && !game.envelope_active) { @@ -181,9 +183,78 @@ void RedrawPlayfield(boolean force_redraw, int x, int y, int width, int height) } } + if (force_redraw) + { + x = gfx.sx; + y = gfx.sy; + width = gfx.sxsize; + height = gfx.sysize; + } + BlitBitmap(drawto, window, x, y, width, height, x, y); } +void DrawMaskedBorder_Rect(int x, int y, int width, int height) +{ + Bitmap *bitmap = graphic_info[IMG_GLOBAL_BORDER].bitmap; + + SetClipOrigin(bitmap, bitmap->stored_clip_gc, 0, 0); + BlitBitmapMasked(bitmap, backbuffer, x, y, width, height, x, y); +} + +void DrawMaskedBorder_FIELD() +{ + if (game_status >= GAME_MODE_TITLE && + game_status <= GAME_MODE_PLAYING && + border.draw_masked[game_status]) + DrawMaskedBorder_Rect(REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); +} + +void DrawMaskedBorder_DOOR_1() +{ + if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] && + (game_status != GAME_MODE_EDITOR || + border.draw_masked[GFX_SPECIAL_ARG_EDITOR])) + DrawMaskedBorder_Rect(DX, DY, DXSIZE, DYSIZE); +} + +void DrawMaskedBorder_DOOR_2() +{ + if (border.draw_masked[GFX_SPECIAL_ARG_DOOR] && + game_status != GAME_MODE_EDITOR) + DrawMaskedBorder_Rect(VX, VY, VXSIZE, VYSIZE); +} + +void DrawMaskedBorder_DOOR_3() +{ + /* currently not available */ +} + +void DrawMaskedBorder_ALL() +{ + DrawMaskedBorder_FIELD(); + DrawMaskedBorder_DOOR_1(); + DrawMaskedBorder_DOOR_2(); + DrawMaskedBorder_DOOR_3(); +} + +void DrawMaskedBorder(int redraw_mask) +{ + if (redraw_mask & REDRAW_ALL) + DrawMaskedBorder_ALL(); + else + { + if (redraw_mask & REDRAW_FIELD) + DrawMaskedBorder_FIELD(); + if (redraw_mask & REDRAW_DOOR_1) + DrawMaskedBorder_DOOR_1(); + if (redraw_mask & REDRAW_DOOR_2) + DrawMaskedBorder_DOOR_2(); + if (redraw_mask & REDRAW_DOOR_3) + DrawMaskedBorder_DOOR_3(); + } +} + void BackToFront() { int x,y; @@ -201,6 +272,11 @@ void BackToFront() if (redraw_mask == REDRAW_NONE) return; + if (redraw_mask & REDRAW_TILES && + game_status == GAME_MODE_PLAYING && + border.draw_masked[game_status]) + redraw_mask |= REDRAW_FIELD; + if (global.fps_slowdown && game_status == GAME_MODE_PLAYING) { static boolean last_frame_skipped = FALSE; @@ -238,8 +314,15 @@ void BackToFront() SyncDisplay(); +#if 1 + DrawMaskedBorder(redraw_mask); +#endif + if (redraw_mask & REDRAW_ALL) { +#if 0 + DrawMaskedBorder(REDRAW_ALL); +#endif BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); redraw_mask = REDRAW_NONE; @@ -250,6 +333,9 @@ void BackToFront() if (game_status != GAME_MODE_PLAYING || redraw_mask & REDRAW_FROM_BACKBUFFER) { +#if 0 + DrawMaskedBorder(REDRAW_FIELD); +#endif BlitBitmap(backbuffer, window, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY); } @@ -268,7 +354,21 @@ void BackToFront() ABS(ScreenMovPos) == ScrollStepSize || redraw_tiles > REDRAWTILES_THRESHOLD) { +#if 1 + if (border.draw_masked[GFX_SPECIAL_ARG_MAIN]) + { + BlitBitmap(buffer, backbuffer, fx, fy, SXSIZE, SYSIZE, SX, SY); + + DrawMaskedBorder(REDRAW_FIELD); + BlitBitmap(backbuffer, window, + REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, + REAL_SX, REAL_SY); + } + else + BlitBitmap(buffer, window, fx, fy, SXSIZE, SYSIZE, SX, SY); +#else BlitBitmap(buffer, window, fx, fy, SXSIZE, SYSIZE, SX, SY); +#endif #if 0 #ifdef DEBUG @@ -292,13 +392,28 @@ void BackToFront() if (redraw_mask & REDRAW_DOORS) { if (redraw_mask & REDRAW_DOOR_1) + { +#if 0 + DrawMaskedBorder(REDRAW_DOOR_1); +#endif BlitBitmap(backbuffer, window, DX, DY, DXSIZE, DYSIZE, DX, DY); + } if (redraw_mask & REDRAW_DOOR_2) + { +#if 0 + DrawMaskedBorder(REDRAW_DOOR_2); +#endif BlitBitmap(backbuffer, window, VX, VY, VXSIZE, VYSIZE, VX, VY); + } if (redraw_mask & REDRAW_DOOR_3) + { +#if 0 + DrawMaskedBorder(REDRAW_DOOR_3); +#endif BlitBitmap(backbuffer, window, EX, EY, EXSIZE, EYSIZE, EX, EY); + } redraw_mask &= ~REDRAW_DOORS; } @@ -414,99 +529,67 @@ void FadeToFront() BackToFront(); } -void FadeIn(int fade_delay) +void FadeExt(int fade_mask, int fade_mode) { - if (fade_delay == 0) + void (*draw_border_function)(void) = NULL; + Bitmap *bitmap = (fade_mode == FADE_MODE_CROSSFADE ? bitmap_db_cross : NULL); + int fade_delay = menu.fade_delay; + int post_delay = (fade_mode == FADE_MODE_FADE_OUT ? menu.post_delay : 0); + int x, y, width, height; + + if (fade_mask & REDRAW_FIELD) { - BackToFront(); + x = REAL_SX; + y = REAL_SY; + width = FULL_SXSIZE; + height = FULL_SYSIZE; - return; + draw_border_function = DrawMaskedBorder_FIELD; } - - FadeRectangle(NULL, 0, 0, WIN_XSIZE, WIN_YSIZE, - FADE_MODE_FADE_IN, fade_delay, 0); - - redraw_mask = REDRAW_NONE; -} - -void FadeOut(int fade_delay, int post_delay) -{ - if (fade_delay == 0) + else /* REDRAW_ALL */ { - ClearRectangle(backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE); - BackToFront(); - - return; + x = 0; + y = 0; + width = WIN_XSIZE; + height = WIN_YSIZE; } - FadeRectangle(NULL, 0, 0, WIN_XSIZE, WIN_YSIZE, - FADE_MODE_FADE_OUT, fade_delay, post_delay); - - redraw_mask = REDRAW_NONE; -} + redraw_mask |= fade_mask; -void FadeCross(int fade_delay) -{ - if (fade_delay == 0) + if (!setup.fade_screens || fade_delay == 0) { - BlitBitmap(bitmap_db_title, backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); + if (fade_mode == FADE_MODE_FADE_OUT) + ClearRectangle(backbuffer, x, y, width, height); + BackToFront(); return; } - FadeRectangle(bitmap_db_title, 0, 0, WIN_XSIZE, WIN_YSIZE, - FADE_MODE_CROSSFADE, fade_delay, 0); + FadeRectangle(bitmap, x, y, width, height, fade_mode, fade_delay, post_delay, + draw_border_function); - redraw_mask = REDRAW_NONE; + redraw_mask &= ~fade_mask; } -void FadeInField(int fade_delay) +void FadeIn(int fade_mask) { - if (fade_delay == 0) - { - BackToFront(); - - return; - } - - FadeRectangle(NULL, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, - FADE_MODE_FADE_IN, fade_delay, 0); - - redraw_mask &= ~REDRAW_FIELD; + FadeExt(fade_mask, FADE_MODE_FADE_IN); } -void FadeOutField(int fade_delay, int post_delay) +void FadeOut(int fade_mask) { - if (fade_delay == 0) - { - ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - BackToFront(); - - return; - } - - FadeRectangle(NULL, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, - FADE_MODE_FADE_OUT, fade_delay, post_delay); - - redraw_mask &= ~REDRAW_FIELD; + FadeExt(fade_mask, FADE_MODE_FADE_OUT); } -void FadeCrossField(int fade_delay) +void FadeCross(int fade_mask) { - if (fade_delay == 0) - { - BlitBitmap(bitmap_db_title, backbuffer, REAL_SX, REAL_SY, - FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY); - BackToFront(); - - return; - } - - FadeRectangle(bitmap_db_title, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, - FADE_MODE_CROSSFADE, fade_delay, 0); + FadeExt(fade_mask, FADE_MODE_CROSSFADE); +} - redraw_mask &= ~REDRAW_FIELD; +void FadeCrossSaveBackbuffer() +{ + BlitBitmap(backbuffer, bitmap_db_cross, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); } void SetMainBackgroundImageIfDefined(int graphic) @@ -611,17 +694,6 @@ inline int getGraphicAnimationFrame(int graphic, int sync_frame) if (graphic_info[graphic].anim_global_sync || sync_frame < 0) sync_frame = FrameCounter; -#if 0 - if (graphic == element_info[EL_CUSTOM_START + 255].graphic[ACTION_DEFAULT] && - sync_frame == 0 && - FrameCounter > 10) - { - int x = 1 / 0; - - printf("::: FOO!\n"); - } -#endif - return getAnimationFrame(graphic_info[graphic].anim_frames, graphic_info[graphic].anim_delay, graphic_info[graphic].anim_mode, @@ -1101,34 +1173,20 @@ static void DrawLevelFieldCrumbledSandExt(int x, int y, int graphic, int frame) int sxx = sx + xy[i][0]; int syy = sy + xy[i][1]; -#if 1 if (!IN_LEV_FIELD(xx, yy) || !IN_SCR_FIELD(sxx, syy) || IS_MOVING(xx, yy)) continue; -#if 1 if (Feld[xx][yy] == EL_ELEMENT_SNAPPING) continue; -#endif element = TILE_GFX_ELEMENT(xx, yy); if (!GFX_CRUMBLED(element)) continue; -#else - if (!IN_LEV_FIELD(xx, yy) || - !IN_SCR_FIELD(sxx, syy) || - !GFX_CRUMBLED(Feld[xx][yy]) || - IS_MOVING(xx, yy)) - continue; -#endif -#if 1 graphic = el_act2crm(element, ACTION_DEFAULT); -#else - graphic = el_act2crm(Feld[xx][yy], ACTION_DEFAULT); -#endif crumbled_border_size = graphic_info[graphic].border_size; getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); @@ -2002,12 +2060,10 @@ void DrawPlayer(struct PlayerInfo *player) int last_player_frame = player->Frame; int frame = 0; -#if 1 /* GfxElement[][] is set to the element the player is digging or collecting; remove also for off-screen player if the player is not moving anymore */ if (IN_LEV_FIELD(jx, jy) && !player_is_moving) GfxElement[jx][jy] = EL_UNDEFINED; -#endif if (!player->active || !IN_SCR_FIELD(SCREENX(last_jx), SCREENY(last_jy))) return; @@ -2033,10 +2089,8 @@ void DrawPlayer(struct PlayerInfo *player) player->is_dropping ? ACTION_DROPPING : player->is_waiting ? player->action_waiting : ACTION_DEFAULT); -#if 1 if (player->is_waiting) move_dir = player->dir_waiting; -#endif InitPlayerGfxAnimation(player, action, move_dir); @@ -2288,6 +2342,10 @@ void WaitForEventToContinue() button_status = MB_RELEASED; +#if 1 + ClearEventQueue(); +#endif + while (still_wait) { if (PendingEvent()) @@ -2593,8 +2651,13 @@ boolean Request(char *text, unsigned int req_state) DoAnimation(); +#if 1 + if (!PendingEvent()) /* delay only if no pending events */ + Delay(10); +#else /* don't eat all CPU time */ Delay(10); +#endif } if (game_status != GAME_MODE_MAIN) @@ -2760,17 +2823,8 @@ unsigned int MoveDoor(unsigned int door_state) int door_size = (handle_door_1 ? door_size_1 : door_size_2); int max_door_size = (handle_door_1 ? max_door_size_1 : max_door_size_2); int door_skip = max_door_size - door_size; -#if 1 int end = door_size; -#else - int end = (door_state & DOOR_ACTION_1 && door_1.anim_mode & ANIM_VERTICAL ? - DYSIZE : DXSIZE); -#endif -#if 1 int start = ((door_state & DOOR_NO_DELAY) ? end : 0); -#else - int start = ((door_state & DOOR_NO_DELAY) ? end : offset_skip); -#endif int k; if (!(door_state & DOOR_NO_DELAY) && !setup.quick_doors) @@ -2882,15 +2936,9 @@ unsigned int MoveDoor(unsigned int door_state) if (door_state & DOOR_ACTION_2) { -#if 1 int a = MIN(x * door_2.step_offset, door_size); int p = (door_state & DOOR_OPEN_2 ? door_size - a : a); int i = p + door_skip; -#else - int a = MIN(x * door_2.step_offset, door_size_2); - int p = (door_state & DOOR_OPEN_2 ? door_size_2 - a : a); - int i = p + door_skip; -#endif if (door_2.anim_mode & ANIM_STATIC_PANEL) { @@ -3159,6 +3207,7 @@ void CreateToolButtons() GDI_DECORATION_POSITION, deco_xpos, deco_ypos, GDI_DECORATION_SIZE, MINI_TILEX, MINI_TILEY, GDI_DECORATION_SHIFTING, 1, 1, + GDI_DIRECT_DRAW, FALSE, GDI_EVENT_MASK, event_mask, GDI_CALLBACK_ACTION, HandleToolButtons, GDI_END); @@ -5350,37 +5399,6 @@ int font2baseimg(int font_nr) return font_info[font_nr].special_graphic[GFX_SPECIAL_ARG_DEFAULT]; } -#if 0 -void setCenteredPlayerNr_EM(int centered_player_nr) -{ - game.centered_player_nr = game.centered_player_nr_next = centered_player_nr; -} - -int getCenteredPlayerNr_EM() -{ -#if 0 - if (game.centered_player_nr_next >= 0 && - !native_em_level.ply[game.centered_player_nr_next]->alive) - game.centered_player_nr_next = game.centered_player_nr; -#endif - - if (game.centered_player_nr != game.centered_player_nr_next) - game.centered_player_nr = game.centered_player_nr_next; - - return game.centered_player_nr; -} - -void setSetCenteredPlayer_EM(boolean set_centered_player) -{ - game.set_centered_player = set_centered_player; -} - -boolean getSetCenteredPlayer_EM() -{ - return game.set_centered_player; -} -#endif - int getNumActivePlayers_EM() { int num_players = 0; @@ -5396,7 +5414,6 @@ int getNumActivePlayers_EM() return num_players; } -#if 1 int getGameFrameDelay_EM(int native_em_game_frame_delay) { int game_frame_delay_value; @@ -5411,14 +5428,13 @@ int getGameFrameDelay_EM(int native_em_game_frame_delay) return game_frame_delay_value; } -#endif unsigned int InitRND(long seed) { if (level.game_engine_type == GAME_ENGINE_TYPE_EM) - return InitEngineRND_EM(seed); + return InitEngineRandom_EM(seed); else - return InitEngineRND(seed); + return InitEngineRandom_RND(seed); } void InitGraphicInfo_EM(void) @@ -5816,7 +5832,6 @@ void InitGraphicInfo_EM(void) g_em->height = TILEY - cy * step; } -#if 1 /* create unique graphic identifier to decide if tile must be redrawn */ /* bit 31 - 16 (16 bit): EM style graphic bit 15 - 12 ( 4 bit): EM style frame @@ -5824,29 +5839,12 @@ void InitGraphicInfo_EM(void) bit 5 - 0 ( 6 bit): graphic height */ g_em->unique_identifier = (graphic << 16) | (frame << 12) | (g_em->width << 6) | g_em->height; -#else - /* create unique graphic identifier to decide if tile must be redrawn */ - /* bit 31 - 16 (16 bit): EM style element - bit 15 - 12 ( 4 bit): EM style frame - bit 11 - 6 ( 6 bit): graphic width - bit 5 - 0 ( 6 bit): graphic height */ - g_em->unique_identifier = - (i << 16) | (j << 12) | (g_em->width << 6) | g_em->height; -#endif - -#if 0 - if (effective_element == EL_ROCK) - printf("::: EL_ROCK(%d, %d): %d, %d => %d\n", - effective_action, j, graphic, frame, g_em->unique_identifier); -#endif #if DEBUG_EM_GFX -#if 1 /* skip check for EMC elements not contained in original EMC artwork */ if (element == EL_EMC_FAKE_ACID) continue; -#endif if (g_em->bitmap != debug_bitmap || g_em->src_x != debug_src_x || @@ -5920,13 +5918,8 @@ void InitGraphicInfo_EM(void) int action = object_mapping[i].action; int direction = object_mapping[i].direction; boolean is_backside = object_mapping[i].is_backside; -#if 1 int graphic_action = el_act_dir2img(element, action, direction); int graphic_default = el_act_dir2img(element, ACTION_DEFAULT, direction); -#else - int graphic_action = element_info[element].graphic[action]; - int graphic_default = element_info[element].graphic[ACTION_DEFAULT]; -#endif if ((action == ACTION_SMASHED_BY_ROCK || action == ACTION_SMASHED_BY_SPRING || @@ -5952,9 +5945,7 @@ void InitGraphicInfo_EM(void) g_em->dst_offset_y = g_xx->dst_offset_y; g_em->width = g_xx->width; g_em->height = g_xx->height; -#if 1 g_em->unique_identifier = g_xx->unique_identifier; -#endif if (!is_backside) g_em->preserve_background = TRUE; @@ -6010,12 +6001,10 @@ void InitGraphicInfo_EM(void) #if DEBUG_EM_GFX -#if 1 /* skip check for EMC elements not contained in original EMC artwork */ if (element == EL_PLAYER_3 || element == EL_PLAYER_4) continue; -#endif if (g_em->bitmap != debug_bitmap || g_em->src_x != debug_src_x || @@ -6128,23 +6117,45 @@ void PlayMenuMusic() void ToggleFullscreenIfNeeded() { + boolean change_fullscreen = (setup.fullscreen != + video.fullscreen_enabled); + boolean change_fullscreen_mode = (video.fullscreen_enabled && + !strEqual(setup.fullscreen_mode, + video.fullscreen_mode_current)); + + if (!video.fullscreen_available) + return; + +#if 1 + if (change_fullscreen || change_fullscreen_mode) +#else if (setup.fullscreen != video.fullscreen_enabled || setup.fullscreen_mode != video.fullscreen_mode_current) +#endif { Bitmap *tmp_backbuffer = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH); /* save backbuffer content which gets lost when toggling fullscreen mode */ BlitBitmap(backbuffer, tmp_backbuffer, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); +#if 1 + if (change_fullscreen_mode) +#else if (setup.fullscreen && video.fullscreen_enabled) +#endif { - /* keep fullscreen mode, but change screen mode */ + /* keep fullscreen, but change fullscreen mode (screen resolution) */ +#if 1 + /* (this is now set in sdl.c) */ +#else video.fullscreen_mode_current = setup.fullscreen_mode; - video.fullscreen_enabled = FALSE; +#endif + video.fullscreen_enabled = FALSE; /* force new fullscreen mode */ } /* toggle fullscreen */ ChangeVideoModeIfNeeded(setup.fullscreen); + setup.fullscreen = video.fullscreen_enabled; /* restore backbuffer content from temporary backbuffer backup bitmap */ @@ -6152,6 +6163,11 @@ void ToggleFullscreenIfNeeded() FreeBitmap(tmp_backbuffer); +#if 1 + /* update visible window/screen */ + BlitBitmap(backbuffer, window, 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0); +#else redraw_mask = REDRAW_ALL; +#endif } }