X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Ftools.c;h=6522b8e741382bc55352fb961f2e4fc5149fdd03;hp=8d8fba9cb77badc951886b218369c0d1dfba74da;hb=4002450137caf7133ae05ee9bf5302faac3d5040;hpb=64e7c54dce6ea8c063f04198c64c5057d751c928 diff --git a/src/tools.c b/src/tools.c index 8d8fba9c..6522b8e7 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1042,8 +1042,9 @@ void FadeIn(int fade_mask) FADE_SXSIZE = FULL_SXSIZE; FADE_SYSIZE = FULL_SYSIZE; - if (game_status == GAME_MODE_PLAYING && - strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS)) + // activate virtual buttons depending on upcoming game status + if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS) && + game_status == GAME_MODE_PLAYING && !tape.playing) SetOverlayActive(TRUE); SetScreenStates_AfterFadingIn(); @@ -1907,8 +1908,8 @@ static void DrawGraphicShiftedDouble(int x, int y, int dx, int dy, int x2 = x + SIGN(dx); int y2 = y + SIGN(dy); - /* movement with two-tile animations must be sync'ed with movement position, - not with current GfxFrame (which can be higher when using slow movement) */ + // movement with two-tile animations must be sync'ed with movement position, + // not with current GfxFrame (which can be higher when using slow movement) int anim_pos = (dx ? ABS(dx) : ABS(dy)); int anim_frames = graphic_info[graphic].anim_frames; @@ -3870,8 +3871,8 @@ void DrawPlayer(struct PlayerInfo *player) int last_player_frame = player->Frame; int frame = 0; - /* 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 */ + // 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; @@ -3989,8 +3990,8 @@ void DrawPlayer(struct PlayerInfo *player) graphic = getPlayerGraphic(player, move_dir); - /* in the case of changed player action or direction, prevent the current - animation frame from being restarted for identical animations */ + // in the case of changed player action or direction, prevent the current + // animation frame from being restarted for identical animations if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic)) player->Frame = last_player_frame; @@ -4094,8 +4095,8 @@ void DrawPlayer(struct PlayerInfo *player) graphic = getPlayerGraphic(player, move_dir); - /* in the case of changed player action or direction, prevent the current - animation frame from being restarted for identical animations */ + // in the case of changed player action or direction, prevent the current + // animation frame from being restarted for identical animations if (player->Frame == 0 && equalGraphics(graphic, last_player_graphic)) player->Frame = last_player_frame; @@ -4205,9 +4206,7 @@ void WaitForEventToContinue(void) { case EVENT_BUTTONRELEASE: case EVENT_KEYPRESS: -#if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONDOWN: -#endif case SDL_JOYBUTTONDOWN: still_wait = FALSE; break; @@ -4344,7 +4343,6 @@ static int RequestHandleEvents(unsigned int req_state) break; } -#if defined(TARGET_SDL2) case SDL_WINDOWEVENT: HandleWindowEvent((WindowEvent *) &event); break; @@ -4355,7 +4353,6 @@ static int RequestHandleEvents(unsigned int req_state) case SDL_APP_DIDENTERFOREGROUND: HandlePauseResumeEvent((PauseResumeEvent *) &event); break; -#endif case EVENT_KEYPRESS: { @@ -4370,31 +4367,27 @@ static int RequestHandleEvents(unsigned int req_state) case KSYM_Return: case KSYM_y: -#if defined(TARGET_SDL2) case KSYM_Y: case KSYM_Select: case KSYM_Menu: #if defined(KSYM_Rewind) case KSYM_Rewind: // for Amazon Fire TV remote -#endif #endif result = 1; break; case KSYM_Escape: case KSYM_n: -#if defined(TARGET_SDL2) case KSYM_N: case KSYM_Back: #if defined(KSYM_FastForward) case KSYM_FastForward: // for Amazon Fire TV remote -#endif #endif result = 0; break; default: - HandleKeysDebug(key); + HandleKeysDebug(key, KEY_PRESSED); break; } @@ -4443,7 +4436,6 @@ static int RequestHandleEvents(unsigned int req_state) ClearPlayerAction(); break; -#if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONDOWN: switch (event.cbutton.button) { @@ -4503,7 +4495,6 @@ static int RequestHandleEvents(unsigned int req_state) HandleJoystickEvent(&event); ClearPlayerAction(); break; -#endif default: HandleOtherEvents(&event); @@ -4581,7 +4572,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) // pause network game while waiting for request to answer if (network.enabled && game_status == GAME_MODE_PLAYING && - !AllPlayersGone && + !game.all_players_gone && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_PausePlaying(); @@ -4722,7 +4713,7 @@ static boolean RequestDoor(char *text, unsigned int req_state) // continue network game after request if (network.enabled && game_status == GAME_MODE_PLAYING && - !AllPlayersGone && + !game.all_players_gone && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_ContinuePlaying(); @@ -4749,7 +4740,7 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) // pause network game while waiting for request to answer if (network.enabled && game_status == GAME_MODE_PLAYING && - !AllPlayersGone && + !game.all_players_gone && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_PausePlaying(); @@ -4807,7 +4798,7 @@ static boolean RequestEnvelope(char *text, unsigned int req_state) // continue network game after request if (network.enabled && game_status == GAME_MODE_PLAYING && - !AllPlayersGone && + !game.all_players_gone && req_state & REQUEST_WAIT_FOR_INPUT) SendToServer_ContinuePlaying(); @@ -8266,9 +8257,9 @@ static void set_crumbled_graphics_EM(struct GraphicInfo_EM *g_em, boolean has_crumbled_graphics, int crumbled, int sync_frame) { - /* if element can be crumbled, but certain action graphics are just empty - space (like instantly snapping sand to empty space in 1 frame), do not - treat these empty space graphics as crumbled graphics in EMC engine */ + // if element can be crumbled, but certain action graphics are just empty + // space (like instantly snapping sand to empty space in 1 frame), do not + // treat these empty space graphics as crumbled graphics in EMC engine if (crumbled == IMG_EMPTY_SPACE) has_crumbled_graphics = FALSE; @@ -8332,9 +8323,9 @@ void SetGfxAnimation_EM(struct GraphicInfo_EM *g_em, action == ACTION_FILLING || action == ACTION_EMPTYING); - /* special case: graphic uses "2nd movement tile" and has defined - 7 frames for movement animation (or less) => use default graphic - for last (8th) frame which ends the movement animation */ + // special case: graphic uses "2nd movement tile" and has defined + // 7 frames for movement animation (or less) => use default graphic + // for last (8th) frame which ends the movement animation if (g->double_movement && g->anim_frames < 8 && frame_em == 7) { action = ACTION_DEFAULT; // (keep action_* unchanged for now) @@ -8427,9 +8418,9 @@ void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em, struct GraphicInfo *g = &graphic_info[graphic]; int sync_frame; - /* special case: graphic uses "2nd movement tile" and has defined - 7 frames for movement animation (or less) => use default graphic - for last (8th) frame which ends the movement animation */ + // special case: graphic uses "2nd movement tile" and has defined + // 7 frames for movement animation (or less) => use default graphic + // for last (8th) frame which ends the movement animation if (g->double_movement && g->anim_frames < 8 && frame_em == 7) { effective_action = ACTION_DEFAULT; @@ -8463,8 +8454,8 @@ void getGraphicSourceObjectExt_EM(struct GraphicInfo_EM *g_em, getGraphicSourceExt(graphic, frame, &g_em->bitmap, &g_em->src_x, &g_em->src_y, g->double_movement && is_backside); - /* (updating the "crumbled" graphic definitions is probably not really needed, - as animations for crumbled graphics can't be longer than one EMC cycle) */ + // (updating the "crumbled" graphic definitions is probably not really needed, + // as animations for crumbled graphics can't be longer than one EMC cycle) set_crumbled_graphics_EM(g_em, has_crumbled_graphics, crumbled, sync_frame); } @@ -9297,7 +9288,6 @@ void ToggleFullscreenOrChangeWindowScalingIfNeeded(void) if (!change_window_scaling_percent && !video.fullscreen_available) return; -#if defined(TARGET_SDL2) if (change_window_scaling_percent) { SDLSetWindowScaling(setup.window_scaling_percent); @@ -9313,7 +9303,6 @@ void ToggleFullscreenOrChangeWindowScalingIfNeeded(void) return; } -#endif if (change_fullscreen || change_window_scaling_percent) @@ -9414,29 +9403,58 @@ void SetLevelSetInfo(char *identifier, int level_nr) levelset.level_nr = level_nr; } -boolean CheckIfPlayfieldViewportHasChanged(void) +boolean CheckIfAllViewportsHaveChanged(void) { - // if game status has not changed, playfield viewport has not changed either + // if game status has not changed, viewports have not changed either if (game_status == game_status_last) return FALSE; - // check if playfield viewport has changed with current game status + // check if all viewports have changed with current game status + struct RectWithBorder *vp_playfield = &viewport.playfield[game_status]; + struct RectWithBorder *vp_door_1 = &viewport.door_1[game_status]; + struct RectWithBorder *vp_door_2 = &viewport.door_2[game_status]; int new_real_sx = vp_playfield->x; int new_real_sy = vp_playfield->y; int new_full_sxsize = vp_playfield->width; int new_full_sysize = vp_playfield->height; + int new_dx = vp_door_1->x; + int new_dy = vp_door_1->y; + int new_dxsize = vp_door_1->width; + int new_dysize = vp_door_1->height; + int new_vx = vp_door_2->x; + int new_vy = vp_door_2->y; + int new_vxsize = vp_door_2->width; + int new_vysize = vp_door_2->height; + + boolean playfield_viewport_has_changed = + (new_real_sx != REAL_SX || + new_real_sy != REAL_SY || + new_full_sxsize != FULL_SXSIZE || + new_full_sysize != FULL_SYSIZE); + + boolean door_1_viewport_has_changed = + (new_dx != DX || + new_dy != DY || + new_dxsize != DXSIZE || + new_dysize != DYSIZE); + + boolean door_2_viewport_has_changed = + (new_vx != VX || + new_vy != VY || + new_vxsize != VXSIZE || + new_vysize != VYSIZE || + game_status_last == GAME_MODE_EDITOR); - return (new_real_sx != REAL_SX || - new_real_sy != REAL_SY || - new_full_sxsize != FULL_SXSIZE || - new_full_sysize != FULL_SYSIZE); + return (playfield_viewport_has_changed && + door_1_viewport_has_changed && + door_2_viewport_has_changed); } -boolean CheckIfGlobalBorderOrPlayfieldViewportHasChanged(void) +boolean CheckFadeAll(void) { return (CheckIfGlobalBorderHasChanged() || - CheckIfPlayfieldViewportHasChanged()); + CheckIfAllViewportsHaveChanged()); } void ChangeViewportPropertiesIfNeeded(void) @@ -9453,11 +9471,14 @@ void ChangeViewportPropertiesIfNeeded(void) struct RectWithBorder *vp_door_3 = &viewport.door_2[GAME_MODE_EDITOR]; int new_win_xsize = vp_window->width; int new_win_ysize = vp_window->height; - int border_size = vp_playfield->border_size; - int new_sx = vp_playfield->x + border_size; - int new_sy = vp_playfield->y + border_size; - int new_sxsize = vp_playfield->width - 2 * border_size; - int new_sysize = vp_playfield->height - 2 * border_size; + int border_left = vp_playfield->border_left; + int border_right = vp_playfield->border_right; + int border_top = vp_playfield->border_top; + int border_bottom = vp_playfield->border_bottom; + int new_sx = vp_playfield->x + border_left; + int new_sy = vp_playfield->y + border_top; + int new_sxsize = vp_playfield->width - border_left - border_right; + int new_sysize = vp_playfield->height - border_top - border_bottom; int new_real_sx = vp_playfield->x; int new_real_sy = vp_playfield->y; int new_full_sxsize = vp_playfield->width; @@ -9562,8 +9583,8 @@ void ChangeViewportPropertiesIfNeeded(void) } // add current and new door 2 area if position or size has changed - if (new_dx != VX || new_dy != VY || - new_dxsize != VXSIZE || new_dysize != VYSIZE) + if (new_vx != VX || new_vy != VY || + new_vxsize != VXSIZE || new_vysize != VYSIZE) { JoinRectangles(&FADE_SX, &FADE_SY, &FADE_SXSIZE, &FADE_SYSIZE, VX, VY, VXSIZE, VYSIZE);