From 6fd606e95cceca17c82e2f97e2ca2832b238f96d Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Fri, 17 Jan 2014 16:55:52 +0100 Subject: [PATCH] rnd-20140117-1-src * improved speed of displaying progress when loading levels and artwork --- ChangeLog | 3 +++ src/conftime.h | 2 +- src/init.c | 13 ++++++----- src/libgame/sdl.c | 52 ++++++++++++++++++++++++++++++++++---------- src/libgame/sdl.h | 1 + src/libgame/system.c | 7 ++++++ src/libgame/system.h | 2 ++ src/libgame/text.c | 43 ++++++++++++++++++++++++++++++++++++ src/libgame/text.h | 2 ++ src/screens.c | 2 ++ 10 files changed, 110 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03bb49af..c1e55e26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2014-01-17 + * improved speed of displaying progress when loading levels and artwork + 2014-01-15 * fixed toons stopping on continuous touch events on Mac OS X diff --git a/src/conftime.h b/src/conftime.h index db55b7e1..a7724675 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-01-15 20:15" +#define COMPILE_DATE_STRING "2014-01-17 16:49" diff --git a/src/init.c b/src/init.c index 723f8af0..a1b92d25 100644 --- a/src/init.c +++ b/src/init.c @@ -5593,14 +5593,15 @@ void InitGfx() font_height = getFontHeight(FC_RED); #if 1 - DrawInitText(getWindowTitleString(), 20, FC_YELLOW); + DrawInitTextAlways(getWindowTitleString(), 20, FC_YELLOW); #else - DrawInitText(getProgramInitString(), 20, FC_YELLOW); + DrawInitTextAlways(getProgramInitString(), 20, FC_YELLOW); #endif - DrawInitText(PROGRAM_COPYRIGHT_STRING, 50, FC_RED); - DrawInitText(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, FC_RED); + DrawInitTextAlways(PROGRAM_COPYRIGHT_STRING, 50, FC_RED); + DrawInitTextAlways(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, + FC_RED); - DrawInitText("Loading graphics", 120, FC_GREEN); + DrawInitTextAlways("Loading graphics", 120, FC_GREEN); #if 1 #if 1 @@ -6216,6 +6217,8 @@ void ReloadCustomArtwork(int force_reload) #endif print_timestamp_done("ReloadCustomArtwork"); + + LimitScreenUpdates(FALSE); } void KeyboardAutoRepeatOffUnlessAutoplay() diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 4fd21a30..12391652 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -40,13 +40,31 @@ static int fullscreen_xoffset; static int fullscreen_yoffset; static int video_xoffset; static int video_yoffset; +static boolean limit_screen_updates = FALSE; + /* functions from SGE library */ void sge_Line(SDL_Surface *, Sint16, Sint16, Sint16, Sint16, Uint32); -#if defined(TARGET_SDL2) +void SDLLimitScreenUpdates(boolean enable) +{ + limit_screen_updates = enable; +} + static void UpdateScreen(SDL_Rect *rect) { + static unsigned int update_screen_delay = 0; + unsigned int update_screen_delay_value = 100; /* (milliseconds) */ + +#if 1 + if (limit_screen_updates && + !DelayReached(&update_screen_delay, update_screen_delay_value)) + return; + + LimitScreenUpdates(FALSE); +#endif + +#if defined(TARGET_SDL2) #if USE_RENDERER SDL_Surface *screen = backbuffer->surface; @@ -79,8 +97,14 @@ static void UpdateScreen(SDL_Rect *rect) else SDL_UpdateWindowSurface(sdl_window); #endif -} + +#else // TARGET_SDL + if (rect) + SDL_UpdateRects(backbuffer->surface, 1, rect); + else + SDL_UpdateRect(backbuffer->surface, 0, 0, 0, 0); #endif +} static void setFullscreenParameters(char *fullscreen_mode_string) { @@ -391,9 +415,9 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, boolean fullscreen) { SDL_Surface *new_surface = NULL; - static boolean fullscreen_enabled = FALSE; #if defined(TARGET_SDL2) + static boolean fullscreen_enabled = FALSE; int surface_flags_window = SURFACE_FLAGS | SDL_WINDOW_RESIZABLE; #if USE_DESKTOP_FULLSCREEN int surface_flags_fullscreen = SURFACE_FLAGS | SDL_WINDOW_FULLSCREEN_DESKTOP; @@ -559,9 +583,11 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, new_surface = SDL_SetVideoMode(width, height, video.depth, surface_flags); #endif +#if defined(TARGET_SDL2) // store fullscreen state ("video.fullscreen_enabled" may not reflect this!) if (new_surface != NULL) fullscreen_enabled = fullscreen; +#endif return new_surface; } @@ -934,7 +960,10 @@ void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, } #else if (dst_bitmap == window) - SDL_UpdateRect(backbuffer->surface, dst_x, dst_y, width, height); + { + // SDL_UpdateRect(backbuffer->surface, dst_x, dst_y, width, height); + UpdateScreen(&dst_rect); + } #endif } @@ -966,7 +995,10 @@ void SDLFillRectangle(Bitmap *dst_bitmap, int x, int y, int width, int height, } #else if (dst_bitmap == window) - SDL_UpdateRect(backbuffer->surface, x, y, width, height); + { + // SDL_UpdateRect(backbuffer->surface, x, y, width, height); + UpdateScreen(&rect); + } #endif } @@ -981,9 +1013,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, SDL_Surface *surface_screen = backbuffer->surface; SDL_Surface *surface_cross = (bitmap_cross ? bitmap_cross->surface : NULL); SDL_Rect src_rect, dst_rect; -#if defined(TARGET_SDL2) SDL_Rect dst_rect2; -#endif int src_x = x, src_y = y; int dst_x = x, dst_y = y; unsigned int time_last, time_current; @@ -1012,9 +1042,7 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, dst_rect.w = width; /* (ignored) */ dst_rect.h = height; /* (ignored) */ -#if defined(TARGET_SDL2) dst_rect2 = dst_rect; -#endif if (initialization_needed) { @@ -1215,7 +1243,8 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, // SDL_UpdateWindowSurfaceRects(sdl_window, &dst_rect2, 1); UpdateScreen(&dst_rect2); #else - SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height); + // SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height); + UpdateScreen(&dst_rect2); #endif } } @@ -1254,7 +1283,8 @@ void SDLFadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, // SDL_UpdateWindowSurfaceRects(sdl_window, &dst_rect, 1); UpdateScreen(&dst_rect); #else - SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height); + // SDL_UpdateRect(surface_screen, dst_x, dst_y, width, height); + UpdateScreen(&dst_rect); #endif #else SDL_Flip(surface_screen); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 05ddfed6..710d247c 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -442,6 +442,7 @@ void SDLSetWindowFullscreen(boolean); void SDLRedrawWindow(); #endif +void SDLLimitScreenUpdates(boolean); void SDLInitVideoDisplay(void); void SDLInitVideoBuffer(DrawBuffer **, DrawWindow **, boolean); boolean SDLSetVideoMode(DrawBuffer **, boolean); diff --git a/src/libgame/system.c b/src/libgame/system.c index 6bc36f96..94fe631b 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -415,6 +415,13 @@ inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, #endif } +void LimitScreenUpdates(boolean enable) +{ +#if defined(TARGET_SDL) + SDLLimitScreenUpdates(enable); +#endif +} + void InitVideoDisplay(void) { #if defined(TARGET_SDL) diff --git a/src/libgame/system.h b/src/libgame/system.h index abb63b59..95076061 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1276,6 +1276,8 @@ void SetWindowBackgroundBitmap(Bitmap *); void SetMainBackgroundBitmap(Bitmap *); void SetDoorBackgroundBitmap(Bitmap *); +void LimitScreenUpdates(boolean); + void InitVideoDisplay(void); void CloseVideoDisplay(void); void InitVideoBuffer(int, int, int, boolean); diff --git a/src/libgame/text.c b/src/libgame/text.c index 8f8bf8f6..61feaae1 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -210,8 +210,44 @@ int maxWordLengthInString(char *text) void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force) { +#if 1 +#if 0 static unsigned int progress_delay = 0; unsigned int progress_delay_value = 100; /* (in milliseconds) */ +#endif + + // LimitScreenUpdates(TRUE); // (ignore "force" for now) + // LimitScreenUpdates(!force); + LimitScreenUpdates(TRUE); + + UPDATE_BUSY_STATE(); + +#if 0 + if (!force && !DelayReached(&progress_delay, progress_delay_value)) + return; +#endif + + if (window != NULL && + gfx.draw_init_text && + gfx.num_fonts > 0 && + gfx.font_bitmap_info[font_nr].bitmap != NULL) + { + int x = (video.width - getTextWidth(text, font_nr)) / 2; + int y = ypos; + int width = video.width; + int height = getFontHeight(font_nr); + + ClearRectangle(drawto, 0, y, width, height); + DrawTextExt(drawto, x, y, text, font_nr, BLIT_OPAQUE); + + BlitBitmap(drawto, window, 0, 0, video.width, video.height, 0, 0); + } +#else + static unsigned int progress_delay = 0; + unsigned int progress_delay_value = 100; /* (in milliseconds) */ + + // LimitScreenUpdates(TRUE); // (ignore "force" for now) + LimitScreenUpdates(!force); UPDATE_BUSY_STATE(); @@ -234,9 +270,16 @@ void DrawInitTextExt(char *text, int ypos, int font_nr, boolean force) /* this makes things significantly faster than directly drawing to window */ BlitBitmap(drawto, window, 0, y, width, height, 0, y); } +#endif } void DrawInitText(char *text, int ypos, int font_nr) +{ + // DrawInitTextExt(text, ypos, font_nr, TRUE); + DrawInitTextExt(text, ypos, font_nr, FALSE); +} + +void DrawInitTextAlways(char *text, int ypos, int font_nr) { DrawInitTextExt(text, ypos, font_nr, TRUE); } diff --git a/src/libgame/text.h b/src/libgame/text.h index 17d350a0..e01dccdd 100644 --- a/src/libgame/text.h +++ b/src/libgame/text.h @@ -76,8 +76,10 @@ void getFontCharSource(int, char, Bitmap **, int *, int *); int maxWordLengthInString(char *); void DrawInitText(char *, int, int); +void DrawInitTextAlways(char *, int, int); void DrawInitTextIfNeeded(char *, int, int); void DrawInitTextExt(char *, int, int, boolean); + void DrawTextF(int, int, int, char *, ...); void DrawTextFCentered(int, int, char *, ...); void DrawTextS(int, int, int, char *); diff --git a/src/screens.c b/src/screens.c index 7f694d98..6951099f 100644 --- a/src/screens.c +++ b/src/screens.c @@ -1317,6 +1317,8 @@ void DrawMainMenuExt(int fade_mask, boolean do_fading) static LevelDirTree *leveldir_last_valid = NULL; boolean levelset_has_changed = FALSE; + LimitScreenUpdates(FALSE); + FadeSetLeaveScreen(); /* do not fade out here -- function may continue and fade on editor screen */ -- 2.34.1