From d77d7ac6d22b63ff3e10608e54c7ac919915fae9 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 19 Jan 2016 23:24:49 +0100 Subject: [PATCH] added initialization of config and textures for global animations --- src/init.c | 32 +++++++++++++++++++++++++++++++- src/libgame/image.c | 14 ++++++++++++++ src/libgame/image.h | 1 + src/libgame/sdl.c | 35 +++++++++++++++++++++++++++++++++++ src/libgame/sdl.h | 5 +++++ src/libgame/system.c | 10 ++++++++++ src/libgame/system.h | 3 +++ 7 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index 67079ca5..8dfd5f78 100644 --- a/src/init.c +++ b/src/init.c @@ -129,6 +129,10 @@ void DrawInitAnim() FrameCounter++; } +void DrawGlobalAnim() +{ +} + void FreeGadgets() { FreeLevelEditorGadgets(); @@ -226,6 +230,28 @@ void InitBitmapPointers() graphic_info[i].bitmap = graphic_info[i].bitmaps[IMG_BITMAP_STANDARD]; } +static void InitGlobalAnimImages() +{ + int i, j, k; + + for (i = 0; i < NUM_GLOBAL_ANIMS; i++) + { + for (j = 0; j < NUM_GLOBAL_ANIM_PARTS; j++) + { + for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++) + { + int graphic = global_anim_info[i].graphic[j][k]; + + if (graphic == IMG_UNDEFINED) + continue; + + // create textures from images for fast GPU blitting, if possible + CreateImageTextures(graphic); + } + } + } +} + #if 1 /* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */ void SetBitmaps_EM(Bitmap **em_bitmap) @@ -1991,8 +2017,10 @@ static void ReinitializeGraphics() print_timestamp_time("InitBitmapPointers"); InitFontGraphicInfo(); /* initialize text drawing functions */ print_timestamp_time("InitFontGraphicInfo"); - InitGlobalAnimGraphicInfo(); /* initialize global animations */ + InitGlobalAnimGraphicInfo(); /* initialize global animation config */ print_timestamp_time("InitGlobalAnimGraphicInfo"); + InitGlobalAnimImages(); /* initialize global animation images */ + print_timestamp_time("InitGlobalAnimImages"); InitGraphicInfo_EM(); /* graphic mapping for EM engine */ print_timestamp_time("InitGraphicInfo_EM"); @@ -5267,7 +5295,9 @@ void InitGfx() init.busy.height = anim_initial.height; InitMenuDesignSettings_Static(); + InitGfxDrawBusyAnimFunction(DrawInitAnim); + InitGfxDrawGlobalAnimFunction(DrawGlobalAnim); /* use copy of busy animation to prevent change while reloading artwork */ init_last = init; diff --git a/src/libgame/image.c b/src/libgame/image.c index 7fc7e2b8..2275bc73 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -25,6 +25,7 @@ struct ImageInfo int original_height; /* original image file height */ boolean contains_small_images; /* set after adding small images */ + boolean contains_textures; /* set after adding GPU textures */ boolean scaled_up; /* set after scaling up */ int conf_tile_size; /* tile size as defined in config */ @@ -56,6 +57,7 @@ static void *Load_Image(char *filename) img_info->original_height = img_info->bitmaps[IMG_BITMAP_STANDARD]->height; img_info->contains_small_images = FALSE; + img_info->contains_textures = FALSE; img_info->scaled_up = FALSE; img_info->conf_tile_size = 0; // will be set later @@ -349,6 +351,18 @@ void CreateImageWithSmallImages(int pos, int zoom_factor, int tile_size) setString(&img_info->leveldir, leveldir_current->identifier); } +void CreateImageTextures(int pos) +{ + ImageInfo *img_info = getImageInfoEntryFromImageID(pos); + + if (img_info == NULL || img_info->contains_textures) + return; + + CreateBitmapTextures(img_info->bitmaps); + + img_info->contains_textures = TRUE; +} + void ScaleImage(int pos, int zoom_factor) { ImageInfo *img_info = getImageInfoEntryFromImageID(pos); diff --git a/src/libgame/image.h b/src/libgame/image.h index db988c6b..627694c0 100644 --- a/src/libgame/image.h +++ b/src/libgame/image.h @@ -67,6 +67,7 @@ void InitImageList(struct ConfigInfo *, int, struct ConfigTypeInfo *, void ReloadCustomImages(); void CreateImageWithSmallImages(int, int, int); +void CreateImageTextures(int); void ScaleImage(int, int); void FreeAllImages(); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 3ab03783..71f6cf17 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -286,6 +286,30 @@ SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) #endif +#if defined(TARGET_SDL2) +static SDL_Texture *SDLCreateTextureFromSurface(SDL_Surface *surface) +{ + SDL_Texture *texture = SDL_CreateTextureFromSurface(sdl_renderer, surface); + + if (texture == NULL) + Error(ERR_EXIT, "SDL_CreateTextureFromSurface() failed: %s", + SDL_GetError()); + + return texture; +} +#endif + +void SDLCreateBitmapTextures(Bitmap *bitmap) +{ +#if defined(TARGET_SDL2) + if (bitmap == NULL) + return; + + bitmap->texture = SDLCreateTextureFromSurface(bitmap->surface); + bitmap->texture_masked = SDLCreateTextureFromSurface(bitmap->surface_masked); +#endif +} + void SDLInitVideoDisplay(void) { #if !defined(TARGET_SDL2) @@ -871,8 +895,19 @@ void SDLFreeBitmapPointers(Bitmap *bitmap) SDL_FreeSurface(bitmap->surface); if (bitmap->surface_masked) SDL_FreeSurface(bitmap->surface_masked); + bitmap->surface = NULL; bitmap->surface_masked = NULL; + +#if defined(TARGET_SDL2) + if (bitmap->texture) + SDL_DestroyTexture(bitmap->texture); + if (bitmap->texture_masked) + SDL_DestroyTexture(bitmap->texture_masked); + + bitmap->texture = NULL; + bitmap->texture_masked = NULL; +#endif } void SDLCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 79827b45..c881a3df 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -102,6 +102,10 @@ struct SDLSurfaceInfo int width, height; SDL_Surface *surface; SDL_Surface *surface_masked; +#if defined(TARGET_SDL2) + SDL_Texture *texture; + SDL_Texture *texture_masked; +#endif }; struct MouseCursorInfo @@ -428,6 +432,7 @@ struct MouseCursorInfo boolean SDLSetNativeSurface(SDL_Surface **); SDL_Surface *SDLGetNativeSurface(SDL_Surface *); +void SDLCreateBitmapTextures(Bitmap *); #if defined(TARGET_SDL2) SDL_Surface *SDL_DisplayFormat(SDL_Surface *); diff --git a/src/libgame/system.c b/src/libgame/system.c index b5e4f270..a4d3f9e8 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -231,6 +231,11 @@ void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void)) gfx.draw_busy_anim_function = draw_busy_anim_function; } +void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(void)) +{ + gfx.draw_global_anim_function = draw_global_anim_function; +} + void InitGfxCustomArtworkInfo() { gfx.override_level_graphics = FALSE; @@ -1125,6 +1130,11 @@ void CreateBitmapWithSmallBitmaps(Bitmap **bitmaps, int zoom_factor, CreateScaledBitmaps(bitmaps, zoom_factor, tile_size, TRUE); } +void CreateBitmapTextures(Bitmap **bitmaps) +{ + SDLCreateBitmapTextures(bitmaps[IMG_BITMAP_STANDARD]); +} + void ScaleBitmap(Bitmap **bitmaps, int zoom_factor) { CreateScaledBitmaps(bitmaps, zoom_factor, 0, FALSE); diff --git a/src/libgame/system.h b/src/libgame/system.h index fdda818e..f8aa8296 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -810,6 +810,7 @@ struct GfxInfo int anim_random_frame; void (*draw_busy_anim_function)(void); + void (*draw_global_anim_function)(void); int cursor_mode; }; @@ -1306,6 +1307,7 @@ void InitGfxWindowInfo(int, int); void InitGfxScrollbufferInfo(int, int); void InitGfxClipRegion(boolean, int, int, int, int); void InitGfxDrawBusyAnimFunction(void (*draw_busy_anim_function)(void)); +void InitGfxDrawGlobalAnimFunction(void (*draw_global_anim_function)(void)); void InitGfxCustomArtworkInfo(); void InitGfxOtherSettings(); void SetDrawDeactivationMask(int); @@ -1354,6 +1356,7 @@ void ReloadCustomImage(Bitmap *, char *); Bitmap *ZoomBitmap(Bitmap *, int, int); void ReCreateGameTileSizeBitmap(Bitmap **); void CreateBitmapWithSmallBitmaps(Bitmap **, int, int); +void CreateBitmapTextures(Bitmap **); void ScaleBitmap(Bitmap **, int); void SetMouseCursor(int); -- 2.34.1