X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ftools.c;h=af239591b40067a32c8fdd39cb0a1ae5ac229f6c;hp=8ac74ac7178eb4d7f10247e9c6302ac594df460e;hb=67f3bfab902e53e0dc24a01eb6c0e4d274030a47;hpb=2d298d8e6d16600c4ea7cdbdc08508098f0218ef diff --git a/src/tools.c b/src/tools.c index 8ac74ac7..af239591 100644 --- a/src/tools.c +++ b/src/tools.c @@ -397,35 +397,35 @@ void DumpTile(int x, int y) int sy = SCREENY(y); char *token_name; - printf_line("-", 79); - printf("Field Info: SCREEN(%d, %d), LEVEL(%d, %d)\n", sx, sy, x, y); - printf_line("-", 79); + Info("---"); + Info("Field Info: SCREEN(%d, %d), LEVEL(%d, %d)", sx, sy, x, y); + Info("---"); if (!IN_LEV_FIELD(x, y)) { - printf("(not in level field)\n"); - printf("\n"); + Info("(not in level field)"); + Info(""); return; } - token_name = element_info[Feld[x][y]].token_name; + token_name = element_info[Tile[x][y]].token_name; - printf(" Feld: %d\t['%s']\n", Feld[x][y], token_name); - printf(" Back: %s\n", print_if_not_empty(Back[x][y])); - printf(" Store: %s\n", print_if_not_empty(Store[x][y])); - printf(" Store2: %s\n", print_if_not_empty(Store2[x][y])); - printf(" StorePlayer: %s\n", print_if_not_empty(StorePlayer[x][y])); - printf(" MovPos: %d\n", MovPos[x][y]); - printf(" MovDir: %d\n", MovDir[x][y]); - printf(" MovDelay: %d\n", MovDelay[x][y]); - printf(" ChangeDelay: %d\n", ChangeDelay[x][y]); - printf(" CustomValue: %d\n", CustomValue[x][y]); - printf(" GfxElement: %d\n", GfxElement[x][y]); - printf(" GfxAction: %d\n", GfxAction[x][y]); - printf(" GfxFrame: %d [%d]\n", GfxFrame[x][y], FrameCounter); - printf(" Player x/y: %d, %d\n", local_player->jx, local_player->jy); - printf("\n"); + Info("Tile: %d\t['%s']", Tile[x][y], token_name); + Info("Back: %s", print_if_not_empty(Back[x][y])); + Info("Store: %s", print_if_not_empty(Store[x][y])); + Info("Store2: %s", print_if_not_empty(Store2[x][y])); + Info("StorePlayer: %s", print_if_not_empty(StorePlayer[x][y])); + Info("MovPos: %d", MovPos[x][y]); + Info("MovDir: %d", MovDir[x][y]); + Info("MovDelay: %d", MovDelay[x][y]); + Info("ChangeDelay: %d", ChangeDelay[x][y]); + Info("CustomValue: %d", CustomValue[x][y]); + Info("GfxElement: %d", GfxElement[x][y]); + Info("GfxAction: %d", GfxAction[x][y]); + Info("GfxFrame: %d [%d]", GfxFrame[x][y], FrameCounter); + Info("Player x/y: %d, %d", local_player->jx, local_player->jy); + Info(""); } void DumpTileFromScreen(int sx, int sy) @@ -752,7 +752,7 @@ static void PrintFrameTimeDebugging(void) diff_bar[pos++] = '\0'; - Error(ERR_INFO, "%06d [%02d] [%c%02d] %s", + Debug("time:frame", "%06d [%02d] [%c%02d] %s", counter, diff_1, (diff_2 < 0 ? '-' : diff_2 > 0 ? '+' : ' '), ABS(diff_2), @@ -1337,6 +1337,9 @@ static void RedrawGlobalBorderIfNeeded(void) #if ONLY_REDRAW_GLOBAL_BORDER_IF_NEEDED if (CheckIfGlobalBorderRedrawIsNeeded()) +#else + // determine and store new global border bitmap for current game status + global_border_bitmap = getGlobalBorderBitmapFromStatus(game_status); #endif { // redraw global screen border (or clear, if defined to be empty) @@ -1442,7 +1445,7 @@ void SetBorderElement(void) { for (x = 0; x < lev_fieldx; x++) { - if (!IS_INDESTRUCTIBLE(Feld[x][y])) + if (!IS_INDESTRUCTIBLE(Tile[x][y])) BorderElement = EL_STEELWALL; if (y != 0 && y != lev_fieldy - 1 && x != lev_fieldx - 1) @@ -1468,7 +1471,7 @@ void FloodFillLevelExt(int from_x, int from_y, int fill_element, safety++; if (safety > max_fieldx * max_fieldy) - Error(ERR_EXIT, "Something went wrong in 'FloodFill()'. Please debug."); + Fail("Something went wrong in 'FloodFill()'. Please debug."); old_element = field[from_x][from_y]; field[from_x][from_y] = fill_element; @@ -1611,8 +1614,9 @@ void DrawGraphic(int x, int y, int graphic, int frame) #if DEBUG if (!IN_SCR_FIELD(x, y)) { - printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic); - printf("DrawGraphic(): This should never happen!\n"); + Debug("draw:DrawGraphic", "x = %d, y = %d, graphic = %d", x, y, graphic); + Debug("draw:DrawGraphic", "This should never happen!"); + return; } #endif @@ -1628,8 +1632,10 @@ void DrawFixedGraphic(int x, int y, int graphic, int frame) #if DEBUG if (!IN_SCR_FIELD(x, y)) { - printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n", x, y, graphic); - printf("DrawGraphic(): This should never happen!\n"); + Debug("draw:DrawFixedGraphic", "x = %d, y = %d, graphic = %d", + x, y, graphic); + Debug("draw:DrawFixedGraphic", "This should never happen!"); + return; } #endif @@ -1665,8 +1671,10 @@ void DrawGraphicThruMask(int x, int y, int graphic, int frame) #if DEBUG if (!IN_SCR_FIELD(x, y)) { - printf("DrawGraphicThruMask(): x = %d,y = %d, graphic = %d\n",x,y,graphic); - printf("DrawGraphicThruMask(): This should never happen!\n"); + Debug("draw:DrawGraphicThruMask", "x = %d,y = %d, graphic = %d", + x, y, graphic); + Debug("draw:DrawGraphicThruMask", "This should never happen!"); + return; } #endif @@ -1682,8 +1690,10 @@ void DrawFixedGraphicThruMask(int x, int y, int graphic, int frame) #if DEBUG if (!IN_SCR_FIELD(x, y)) { - printf("DrawGraphicThruMask(): x = %d,y = %d, graphic = %d\n",x,y,graphic); - printf("DrawGraphicThruMask(): This should never happen!\n"); + Debug("draw:DrawFixedGraphicThruMask", "x = %d,y = %d, graphic = %d", + x, y, graphic); + Debug("draw:DrawFixedGraphicThruMask", "This should never happen!"); + return; } #endif @@ -1844,8 +1854,10 @@ static void DrawGraphicShiftedNormal(int x, int y, int dx, int dy, #if DEBUG if (!IN_SCR_FIELD(x, y)) { - printf("DrawGraphicShifted(): x = %d, y = %d, graphic = %d\n",x,y,graphic); - printf("DrawGraphicShifted(): This should never happen!\n"); + Debug("draw:DrawGraphicShiftedNormal", "x = %d, y = %d, graphic = %d", + x, y, graphic); + Debug("draw:DrawGraphicShiftedNormal", "This should never happen!"); + return; } #endif @@ -1997,9 +2009,9 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, { boolean left_stopped = FALSE, right_stopped = FALSE; - if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Feld[lx - 1][ly])) + if (!IN_LEV_FIELD(lx - 1, ly) || IS_WALL(Tile[lx - 1][ly])) left_stopped = TRUE; - if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Feld[lx + 1][ly])) + if (!IN_LEV_FIELD(lx + 1, ly) || IS_WALL(Tile[lx + 1][ly])) right_stopped = TRUE; if (left_stopped && right_stopped) @@ -2051,7 +2063,7 @@ void DrawLevelElementThruMask(int x, int y, int element) void DrawLevelFieldThruMask(int x, int y) { - DrawLevelElementExt(x, y, 0, 0, Feld[x][y], NO_CUTTING, USE_MASKING); + DrawLevelElementExt(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING); } // !!! implementation of quicksand is totally broken !!! @@ -2258,8 +2270,8 @@ static void DrawLevelFieldCrumbledExt(int x, int y, int graphic, int frame) continue; // do not crumble fields that are being digged or snapped - if (Feld[xx][yy] == EL_EMPTY || - Feld[xx][yy] == EL_ELEMENT_SNAPPING) + if (Tile[xx][yy] == EL_EMPTY || + Tile[xx][yy] == EL_ELEMENT_SNAPPING) continue; element = TILE_GFX_ELEMENT(xx, yy); @@ -2288,7 +2300,7 @@ static void DrawLevelFieldCrumbledExt(int x, int y, int graphic, int frame) !IN_SCR_FIELD(sxx, syy)) continue; - if (Feld[xx][yy] == EL_ELEMENT_SNAPPING) + if (Tile[xx][yy] == EL_ELEMENT_SNAPPING) continue; element = TILE_GFX_ELEMENT(xx, yy); @@ -2314,7 +2326,7 @@ void DrawLevelFieldCrumbled(int x, int y) if (!IN_LEV_FIELD(x, y)) return; - if (Feld[x][y] == EL_ELEMENT_SNAPPING && + if (Tile[x][y] == EL_ELEMENT_SNAPPING && GfxElement[x][y] != EL_UNDEFINED && GFX_CRUMBLED(GfxElement[x][y])) { @@ -2363,7 +2375,7 @@ void DrawLevelFieldCrumbledNeighbours(int x, int y) if (!IN_LEV_FIELD(xx, yy) || !IN_SCR_FIELD(sxx, syy) || - !GFX_CRUMBLED(Feld[xx][yy]) || + !GFX_CRUMBLED(Tile[xx][yy]) || IS_MOVING(xx, yy)) continue; @@ -2382,7 +2394,7 @@ void DrawLevelFieldCrumbledNeighbours(int x, int y) if (!IN_LEV_FIELD(xx, yy) || !IN_SCR_FIELD(sxx, syy) || - !GFX_CRUMBLED(Feld[xx][yy]) || + !GFX_CRUMBLED(Tile[xx][yy]) || IS_MOVING(xx, yy)) continue; @@ -2447,7 +2459,7 @@ void DrawScreenField(int x, int y) return; } - element = Feld[lx][ly]; + element = Tile[lx][ly]; content = Store[lx][ly]; if (IS_MOVING(lx, ly)) @@ -2514,7 +2526,7 @@ void DrawScreenField(int x, int y) horiz_move = (MovDir[oldx][oldy] == MV_LEFT || MovDir[oldx][oldy] == MV_RIGHT); - element_old = Feld[oldx][oldy]; + element_old = Tile[oldx][oldy]; content_old = Store[oldx][oldy]; if (element_old == EL_QUICKSAND_EMPTYING || @@ -2667,7 +2679,7 @@ void DrawSizedElementOrWall(int sx, int sy, int scroll_x, int scroll_y, if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy) DrawSizedElement(sx, sy, EL_EMPTY, tilesize); else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy) - DrawSizedElement(sx, sy, Feld[x][y], tilesize); + DrawSizedElement(sx, sy, Tile[x][y], tilesize); else DrawSizedGraphic(sx, sy, el2edimg(getBorderElement(x, y)), 0, tilesize); } @@ -2679,7 +2691,7 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y) if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy) DrawMiniElement(sx, sy, EL_EMPTY); else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy) - DrawMiniElement(sx, sy, Feld[x][y]); + DrawMiniElement(sx, sy, Tile[x][y]); else DrawMiniGraphic(sx, sy, el2edimg(getBorderElement(x, y))); } @@ -3765,7 +3777,7 @@ void DrawLevelGraphicAnimationIfNeeded(int x, int y, int graphic) if (GFX_CRUMBLED(TILE_GFX_ELEMENT(x, y))) DrawLevelFieldCrumbled(x, y); #else - if (GFX_CRUMBLED(Feld[x][y])) + if (GFX_CRUMBLED(Tile[x][y])) DrawLevelFieldCrumbled(x, y); #endif } @@ -3869,8 +3881,8 @@ static void DrawPlayerExt(struct PlayerInfo *player, int drawing_stage) #if DEBUG if (!IN_LEV_FIELD(player->jx, player->jy)) { - printf("DrawPlayerField(): x = %d, y = %d\n", player->jx, player->jy); - printf("DrawPlayerField(): This should never happen!\n"); + Debug("draw:DrawPlayerExt", "x = %d, y = %d", player->jx, player->jy); + Debug("draw:DrawPlayerExt", "This should never happen!"); draw_player[pnr] = FALSE; @@ -3896,8 +3908,8 @@ static void DrawPlayerExt(struct PlayerInfo *player, int drawing_stage) int sy = SCREENY(jy); int sxx = (move_dir == MV_LEFT || move_dir == MV_RIGHT ? player->GfxPos : 0); int syy = (move_dir == MV_UP || move_dir == MV_DOWN ? player->GfxPos : 0); - int element = Feld[jx][jy]; - int last_element = Feld[last_jx][last_jy]; + int element = Tile[jx][jy]; + int last_element = Tile[last_jx][last_jy]; int action = (player->is_pushing ? ACTION_PUSHING : player->is_digging ? ACTION_DIGGING : player->is_collecting ? ACTION_COLLECTING : @@ -4023,7 +4035,7 @@ static void DrawPlayerExt(struct PlayerInfo *player, int drawing_stage) if (!IS_MOVING(jx, jy)) // push movement already finished { - element = Feld[next_jx][next_jy]; + element = Tile[next_jx][next_jy]; gfx_frame = GfxFrame[next_jx][next_jy]; } @@ -4057,7 +4069,7 @@ static void DrawPlayerExt(struct PlayerInfo *player, int drawing_stage) // do not draw (EM style) pushing animation when pushing is finished // (two-tile animations usually do not contain start and end frame) if (graphic_info[graphic].double_movement && !IS_MOVING(jx, jy)) - DrawLevelElement(next_jx, next_jy, Feld[next_jx][next_jy]); + DrawLevelElement(next_jx, next_jy, Tile[next_jx][next_jy]); else DrawGraphicShiftedThruMask(px, py, pxx, pyy, graphic, frame, NO_CUTTING); #else @@ -4184,6 +4196,7 @@ void DrawPlayerField(int x, int y) void WaitForEventToContinue(void) { + boolean first_wait = TRUE; boolean still_wait = TRUE; if (program.headless) @@ -4196,6 +4209,7 @@ void WaitForEventToContinue(void) button_status = MB_RELEASED; ClearEventQueue(); + ClearPlayerAction(); while (still_wait) { @@ -4205,17 +4219,22 @@ void WaitForEventToContinue(void) { switch (event.type) { - case EVENT_BUTTONRELEASE: + case EVENT_BUTTONPRESS: + case EVENT_FINGERPRESS: + first_wait = FALSE; + break; + + case EVENT_BUTTONRELEASE: + case EVENT_FINGERRELEASE: + still_wait = first_wait; + break; + case EVENT_KEYPRESS: case SDL_CONTROLLERBUTTONDOWN: case SDL_JOYBUTTONDOWN: still_wait = FALSE; break; - case EVENT_KEYRELEASE: - ClearPlayerAction(); - break; - default: HandleOtherEvents(&event); break; @@ -4226,7 +4245,8 @@ void WaitForEventToContinue(void) still_wait = FALSE; } - BackToFront(); + if (!PendingEvent()) + BackToFront(); } } @@ -4438,6 +4458,7 @@ static int RequestHandleEvents(unsigned int req_state) break; } + case EVENT_FINGERRELEASE: case EVENT_KEYRELEASE: ClearPlayerAction(); break; @@ -5339,7 +5360,7 @@ unsigned int MoveDoor(unsigned int door_state) if (width > door_rect->width) width = door_rect->width; - // printf("::: k == %d [%d] \n", k, start_step); + // Debug("tools:MoveDoor", "k == %d [%d]", k, start_step); } if (pos->step_yoffset < 0) // door part on bottom side @@ -5671,7 +5692,7 @@ void CreateToolButtons(void) GDI_END); if (gi == NULL) - Error(ERR_EXIT, "cannot create gadget"); + Fail("cannot create gadget"); tool_gadget[id] = gi; } @@ -7704,7 +7725,7 @@ int map_element_RND_to_EM_cave(int element_rnd) if (element_rnd < 0 || element_rnd >= NUM_FILE_ELEMENTS) { - Error(ERR_WARN, "invalid RND level element %d", element_rnd); + Warn("invalid RND level element %d", element_rnd); return EL_UNKNOWN; } @@ -7734,7 +7755,7 @@ int map_element_EM_to_RND_cave(int element_em_cave) if (element_em_cave < 0 || element_em_cave >= CAVE_TILE_MAX) { - Error(ERR_WARN, "invalid EM cave element %d", element_em_cave); + Warn("invalid EM cave element %d", element_em_cave); return EL_UNKNOWN; } @@ -7764,7 +7785,7 @@ int map_element_EM_to_RND_game(int element_em_game) if (element_em_game < 0 || element_em_game >= GAME_TILE_MAX) { - Error(ERR_WARN, "invalid EM game element %d", element_em_game); + Warn("invalid EM game element %d", element_em_game); return EL_UNKNOWN; } @@ -9069,10 +9090,10 @@ static void CheckSaveEngineSnapshot_MM(boolean element_clicked, } } -void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame, - boolean any_player_moving, - boolean any_player_snapping, - boolean any_player_dropping) +boolean CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame, + boolean any_player_moving, + boolean any_player_snapping, + boolean any_player_dropping) { if (tape.single_step && tape.recording && !tape.pausing) if (frame == 7 && !any_player_dropping) @@ -9080,6 +9101,8 @@ void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame, CheckSaveEngineSnapshot_EM(action, frame, any_player_moving, any_player_snapping, any_player_dropping); + + return tape.pausing; } void CheckSingleStepMode_SP(boolean murphy_is_waiting, @@ -9243,35 +9266,30 @@ void PlaySoundSelecting(void) #endif } -void ToggleFullscreenOrChangeWindowScalingIfNeeded(void) +void ToggleFullscreenIfNeeded(void) { - boolean change_fullscreen = (setup.fullscreen != - video.fullscreen_enabled); - boolean change_window_scaling_percent = (!video.fullscreen_enabled && - setup.window_scaling_percent != - video.window_scaling_percent); - - if (change_window_scaling_percent && video.fullscreen_enabled) + // if setup and video fullscreen state are already matching, nothing do do + if (setup.fullscreen == video.fullscreen_enabled || + !video.fullscreen_available) return; - if (!change_window_scaling_percent && !video.fullscreen_available) - return; + SDLSetWindowFullscreen(setup.fullscreen); - if (change_window_scaling_percent) - { - SDLSetWindowScaling(setup.window_scaling_percent); + // set setup value according to successfully changed fullscreen mode + setup.fullscreen = video.fullscreen_enabled; +} +void ChangeWindowScalingIfNeeded(void) +{ + // if setup and video window scaling are already matching, nothing do do + if (setup.window_scaling_percent == video.window_scaling_percent || + video.fullscreen_enabled) return; - } - else if (change_fullscreen) - { - SDLSetWindowFullscreen(setup.fullscreen); - // set setup value according to successfully changed fullscreen mode - setup.fullscreen = video.fullscreen_enabled; + SDLSetWindowScaling(setup.window_scaling_percent); - return; - } + // set setup value according to successfully changed window scaling + setup.window_scaling_percent = video.window_scaling_percent; } void ChangeVsyncModeIfNeeded(void) @@ -9504,7 +9522,7 @@ void ChangeViewportPropertiesIfNeeded(void) init_gfx_buffers = TRUE; init_gadgets_and_anims = TRUE; - // printf("::: video: init_video_buffer, init_gfx_buffers\n"); + // Debug("tools:viewport", "video: init_video_buffer, init_gfx_buffers"); } if (new_scr_fieldx != SCR_FIELDX || @@ -9515,7 +9533,7 @@ void ChangeViewportPropertiesIfNeeded(void) SCR_FIELDX = new_scr_fieldx; SCR_FIELDY = new_scr_fieldy; - // printf("::: new_scr_fieldx != SCR_FIELDX ...\n"); + // Debug("tools:viewport", "new_scr_fieldx != SCR_FIELDX ..."); } if (new_sx != SX || @@ -9585,7 +9603,7 @@ void ChangeViewportPropertiesIfNeeded(void) if (new_tilesize_var != TILESIZE_VAR) { - // printf("::: new_tilesize_var != TILESIZE_VAR\n"); + // Debug("tools:viewport", "new_tilesize_var != TILESIZE_VAR"); // changing tile size invalidates scroll values of engine snapshots FreeEngineSnapshotSingle(); @@ -9619,13 +9637,13 @@ void ChangeViewportPropertiesIfNeeded(void) init_gfx_buffers = TRUE; init_gadgets_and_anims = TRUE; - // printf("::: viewports: init_gfx_buffers\n"); - // printf("::: viewports: init_gadgets_and_anims\n"); + // Debug("tools:viewport", "viewports: init_gfx_buffers"); + // Debug("tools:viewport", "viewports: init_gadgets_and_anims"); } if (init_gfx_buffers) { - // printf("::: init_gfx_buffers\n"); + // Debug("tools:viewport", "init_gfx_buffers"); SCR_FIELDX = new_scr_fieldx_buffers; SCR_FIELDY = new_scr_fieldy_buffers; @@ -9641,7 +9659,7 @@ void ChangeViewportPropertiesIfNeeded(void) if (init_video_buffer) { - // printf("::: init_video_buffer\n"); + // Debug("tools:viewport", "init_video_buffer"); FreeAllImageTextures(); // needs old renderer to free the textures @@ -9651,7 +9669,7 @@ void ChangeViewportPropertiesIfNeeded(void) if (init_gadgets_and_anims) { - // printf("::: init_gadgets_and_anims\n"); + // Debug("tools:viewport", "init_gadgets_and_anims"); InitGadgets(); InitGlobalAnimations();