X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=327d8843b1cbbe6d336ab3a5cd2b80899f486f2f;hb=7ac743d295c6e08f80f5649dd95112e3a94f0570;hp=794174c1d1ccbe0ccf34b87a474b9fb59d596c4e;hpb=67b32ebb347487d2d3a9d926ad8d1c4ed3d9aec6;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index 794174c1..327d8843 100644 --- a/src/tools.c +++ b/src/tools.c @@ -622,11 +622,24 @@ void DrawFramesPerSecond() char text[100]; int font_nr = FONT_TEXT_2; int font_width = getFontWidth(font_nr); + int draw_deactivation_mask = GetDrawDeactivationMask(); + boolean draw_masked = (draw_deactivation_mask == REDRAW_NONE); - sprintf(text, "%04.1f fps", global.frames_per_second); + /* draw FPS with leading space (needed if field buffer deactivated) */ + sprintf(text, " %04.1f fps", global.frames_per_second); - DrawTextExt(backbuffer, WIN_XSIZE - font_width * strlen(text), 0, text, - font_nr, BLIT_OPAQUE); + /* override draw deactivation mask (required for invisible warp mode) */ + SetDrawDeactivationMask(REDRAW_NONE); + + /* draw opaque FPS if field buffer deactivated, else draw masked FPS */ + DrawTextExt(backbuffer, SX + SXSIZE - font_width * strlen(text), SY, text, + font_nr, (draw_masked ? BLIT_MASKED : BLIT_OPAQUE)); + + /* set draw deactivation mask to previous value */ + SetDrawDeactivationMask(draw_deactivation_mask); + + /* force full-screen redraw in this frame */ + redraw_mask = REDRAW_ALL; } #if DEBUG_FRAME_TIME @@ -759,6 +772,13 @@ void BackToFront() y2 = MAX(y2, EY + EYSIZE); } + // make sure that at least one pixel is blitted, and inside the screen + // (else nothing is blitted, causing the animations not to be updated) + x1 = MIN(MAX(0, x1), WIN_XSIZE - 1); + y1 = MIN(MAX(0, y1), WIN_YSIZE - 1); + x2 = MIN(MAX(1, x2), WIN_XSIZE); + y2 = MIN(MAX(1, y2), WIN_YSIZE); + BlitBitmap(backbuffer, window, x1, y1, x2 - x1, y2 - y1, x1, y1); } @@ -3729,6 +3749,9 @@ void WaitForEventToContinue() { boolean still_wait = TRUE; + if (program.headless) + return; + /* simulate releasing mouse button over last gadget, if still pressed */ if (button_status) HandleGadgets(-1, -1, 0); @@ -3749,6 +3772,10 @@ void WaitForEventToContinue() { case EVENT_BUTTONPRESS: case EVENT_KEYPRESS: +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONDOWN: +#endif + case SDL_JOYBUTTONDOWN: still_wait = FALSE; break; @@ -3876,6 +3903,19 @@ static int RequestHandleEvents(unsigned int req_state) break; } +#if defined(TARGET_SDL2) + case SDL_WINDOWEVENT: + HandleWindowEvent((WindowEvent *) &event); + break; + + case SDL_APP_WILLENTERBACKGROUND: + case SDL_APP_DIDENTERBACKGROUND: + case SDL_APP_WILLENTERFOREGROUND: + case SDL_APP_DIDENTERFOREGROUND: + HandlePauseResumeEvent((PauseResumeEvent *) &event); + break; +#endif + case EVENT_KEYPRESS: { Key key = GetEventKey((KeyEvent *)&event, TRUE); @@ -3889,7 +3929,11 @@ static int RequestHandleEvents(unsigned int req_state) case KSYM_Return: #if defined(TARGET_SDL2) + case KSYM_Select: case KSYM_Menu: +#if defined(KSYM_Rewind) + case KSYM_Rewind: /* for Amazon Fire TV remote */ +#endif #endif result = 1; break; @@ -3897,6 +3941,9 @@ static int RequestHandleEvents(unsigned int req_state) case KSYM_Escape: #if defined(TARGET_SDL2) case KSYM_Back: +#if defined(KSYM_FastForward) + case KSYM_FastForward: /* for Amazon Fire TV remote */ +#endif #endif result = 0; break; @@ -3916,6 +3963,35 @@ static int RequestHandleEvents(unsigned int req_state) ClearPlayerAction(); break; +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONDOWN: + switch (event.cbutton.button) + { + case SDL_CONTROLLER_BUTTON_A: + case SDL_CONTROLLER_BUTTON_X: + case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: + result = 1; + break; + + case SDL_CONTROLLER_BUTTON_B: + case SDL_CONTROLLER_BUTTON_Y: + case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: + case SDL_CONTROLLER_BUTTON_BACK: + result = 0; + break; + } + + if (req_state & REQ_PLAYER) + result = 0; + + break; + + case SDL_CONTROLLERBUTTONUP: + HandleJoystickEvent(&event); + ClearPlayerAction(); + break; +#endif + default: HandleOtherEvents(&event); break; @@ -4790,6 +4866,9 @@ unsigned int MoveDoor(unsigned int door_state) SkipUntilDelayReached(&door_delay, door_delay_value, &k, last_frame); current_move_delay += max_step_delay; + + /* prevent OS (Windows) from complaining about program not responding */ + CheckQuitEvent(); } if (door_part_done_all) @@ -8307,8 +8386,15 @@ void CheckSingleStepMode_EM(byte action[MAX_PLAYERS], int frame, void CheckSingleStepMode_SP(boolean murphy_is_waiting, boolean murphy_is_dropping) { + boolean murphy_starts_dropping = FALSE; + int i; + + for (i = 0; i < MAX_PLAYERS; i++) + if (stored_player[i].force_dropping) + murphy_starts_dropping = TRUE; + if (tape.single_step && tape.recording && !tape.pausing) - if (murphy_is_waiting) + if (murphy_is_waiting && !murphy_starts_dropping) TapeTogglePause(TAPE_TOGGLE_AUTOMATIC); CheckSaveEngineSnapshot_SP(murphy_is_waiting, murphy_is_dropping); @@ -8398,7 +8484,37 @@ void PlayMenuMusicExt(int music) void PlayMenuMusic() { - PlayMenuMusicExt(menu.music[game_status]); + char *curr_music = getCurrentlyPlayingMusicFilename(); + char *next_music = getMusicListEntry(menu.music[game_status])->filename; + + if (!strEqual(curr_music, next_music)) + PlayMenuMusicExt(menu.music[game_status]); +} + +void PlayMenuSoundsAndMusic() +{ + PlayMenuSound(); + PlayMenuMusic(); +} + +static void FadeMenuSounds() +{ + FadeSounds(); +} + +static void FadeMenuMusic() +{ + char *curr_music = getCurrentlyPlayingMusicFilename(); + char *next_music = getMusicListEntry(menu.music[game_status])->filename; + + if (!strEqual(curr_music, next_music)) + FadeMusic(); +} + +void FadeMenuSoundsAndMusic() +{ + FadeMenuSounds(); + FadeMenuMusic(); } void PlaySoundActivating() @@ -8494,6 +8610,8 @@ void SetAnimStatus(int anim_status_new) { if (anim_status_new == GAME_MODE_MAIN) anim_status_new = GAME_MODE_PSEUDO_MAINONLY; + else if (anim_status_new == GAME_MODE_SCORES) + anim_status_new = GAME_MODE_PSEUDO_SCORESOLD; global.anim_status_next = anim_status_new; @@ -8507,6 +8625,9 @@ void SetAnimStatus(int anim_status_new) void SetGameStatus(int game_status_new) { + if (game_status_new != game_status) + game_status_last_screen = game_status; + game_status = game_status_new; SetAnimStatus(game_status_new);