X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=21f062b41cdc21fb2bfc3c257f08ffbefc87d9f7;hb=a59ecddb639a019558ca97f61783fd229dce077e;hp=b07e19d37ee75fd9b92f6835d43513a67fa55f74;hpb=8d71e6fb8309bd90ce5f2900d84c686b17950492;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index b07e19d3..21f062b4 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); } @@ -1424,13 +1444,6 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize, *y = *y * tilesize / g->tile_size; } -void getFixedGraphicSourceExt(int graphic, int frame, Bitmap **bitmap, - int *x, int *y, boolean get_backside) -{ - getSizedGraphicSourceExt(graphic, frame, TILESIZE, bitmap, x, y, - get_backside); -} - void getSizedGraphicSource(int graphic, int frame, int tilesize, Bitmap **bitmap, int *x, int *y) { @@ -2498,7 +2511,7 @@ void AnimateEnvelope(int envelope_nr, int anim_mode, int action) boolean no_delay = (tape.warp_forward); unsigned int anim_delay = 0; int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay); - int anim_delay_value = (no_delay ? 0 : frame_delay_value) / 2; + int anim_delay_value = MAX(1, (no_delay ? 0 : frame_delay_value) / 2); int font_nr = FONT_ENVELOPE_1 + envelope_nr; int font_width = getFontWidth(font_nr); int font_height = getFontHeight(font_nr); @@ -2755,7 +2768,7 @@ void AnimateEnvelopeRequest(int anim_mode, int action) boolean ffwd_delay = (tape.playing && tape.fast_forward); boolean no_delay = (tape.warp_forward); int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal); - int anim_delay_value = (no_delay ? 0 : delay_value + 500 * 0) / 2; + int anim_delay_value = MAX(1, (no_delay ? 0 : delay_value + 500 * 0) / 2); unsigned int anim_delay = 0; int tile_size = MAX(request.step_offset, 1); @@ -2961,7 +2974,7 @@ void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y) redraw_mask |= REDRAW_FIELD; } -static void DrawPreviewLevelPlayfieldExt(int from_x, int from_y) +static void DrawPreviewLevelPlayfield(int from_x, int from_y) { boolean show_level_border = (BorderElement != EL_EMPTY); int level_xsize = lev_fieldx + (show_level_border ? 2 : 0); @@ -3026,9 +3039,8 @@ static int getMaxTextLength(struct TextPosInfo *pos, int font_nr) return max_text_width / font_width; } -static void DrawPreviewLevelLabelExt(int mode) +static void DrawPreviewLevelLabelExt(int mode, struct TextPosInfo *pos) { - struct TextPosInfo *pos = &menu.main.text.level_info_2; char label_text[MAX_OUTPUT_LINESIZE + 1]; int max_len_label_text; int font_nr = pos->font; @@ -3071,6 +3083,19 @@ static void DrawPreviewLevelLabelExt(int mode) redraw_mask |= REDRAW_FIELD; } +static void DrawPreviewLevelLabel(int mode) +{ + DrawPreviewLevelLabelExt(mode, &menu.main.text.level_info_2); +} + +static void DrawPreviewLevelInfo(int mode) +{ + if (mode == MICROLABEL_LEVEL_NAME) + DrawPreviewLevelLabelExt(mode, &menu.main.text.level_name); + else if (mode == MICROLABEL_LEVEL_AUTHOR) + DrawPreviewLevelLabelExt(mode, &menu.main.text.level_author); +} + static void DrawPreviewLevelExt(boolean restart) { static unsigned int scroll_delay = 0; @@ -3102,8 +3127,11 @@ static void DrawPreviewLevelExt(boolean restart) label_state = 1; label_counter = 0; - DrawPreviewLevelPlayfieldExt(from_x, from_y); - DrawPreviewLevelLabelExt(label_state); + DrawPreviewLevelPlayfield(from_x, from_y); + DrawPreviewLevelLabel(label_state); + + DrawPreviewLevelInfo(MICROLABEL_LEVEL_NAME); + DrawPreviewLevelInfo(MICROLABEL_LEVEL_AUTHOR); /* initialize delay counters */ DelayReached(&scroll_delay, 0); @@ -3182,7 +3210,7 @@ static void DrawPreviewLevelExt(boolean restart) break; } - DrawPreviewLevelPlayfieldExt(from_x, from_y); + DrawPreviewLevelPlayfield(from_x, from_y); } /* !!! THIS ALL SUCKS -- SHOULD BE CLEANLY REWRITTEN !!! */ @@ -3223,7 +3251,7 @@ static void DrawPreviewLevelExt(boolean restart) label_state = (label_state == MICROLABEL_IMPORTED_FROM_HEAD ? MICROLABEL_IMPORTED_BY_HEAD : MICROLABEL_IMPORTED_BY); - DrawPreviewLevelLabelExt(label_state); + DrawPreviewLevelLabel(label_state); } } @@ -3729,6 +3757,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); @@ -3739,16 +3770,18 @@ void WaitForEventToContinue() while (still_wait) { - if (PendingEvent()) - { - Event event; - - NextEvent(&event); + Event event; + if (NextValidEvent(&event)) + { switch (event.type) { case EVENT_BUTTONPRESS: case EVENT_KEYPRESS: +#if defined(TARGET_SDL2) + case SDL_CONTROLLERBUTTONDOWN: +#endif + case SDL_JOYBUTTONDOWN: still_wait = FALSE; break; @@ -3876,6 +3909,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 +3935,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 +3947,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 +3969,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 +4872,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 +8392,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); @@ -8399,7 +8491,7 @@ void PlayMenuMusicExt(int music) void PlayMenuMusic() { char *curr_music = getCurrentlyPlayingMusicFilename(); - char *next_music = getMusicListEntry(menu.music[game_status])->filename; + char *next_music = getMusicInfoEntryFilename(menu.music[game_status]); if (!strEqual(curr_music, next_music)) PlayMenuMusicExt(menu.music[game_status]); @@ -8419,7 +8511,7 @@ static void FadeMenuSounds() static void FadeMenuMusic() { char *curr_music = getCurrentlyPlayingMusicFilename(); - char *next_music = getMusicListEntry(menu.music[game_status])->filename; + char *next_music = getMusicInfoEntryFilename(menu.music[game_status]); if (!strEqual(curr_music, next_music)) FadeMusic(); @@ -8524,6 +8616,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;