added initialization of config and textures for global animations
authorHolger Schemel <info@artsoft.org>
Tue, 19 Jan 2016 22:24:49 +0000 (23:24 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 19 Jan 2016 22:24:49 +0000 (23:24 +0100)
src/init.c
src/libgame/image.c
src/libgame/image.h
src/libgame/sdl.c
src/libgame/sdl.h
src/libgame/system.c
src/libgame/system.h

index 67079ca5f2327f9e01c5def3c1856942a19ade60..8dfd5f785c00308234e3514905019bd92643865b 100644 (file)
@@ -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;
index 7fc7e2b82bca4edbaad546b5e996ac623b545658..2275bc73544b657313149d1cc9652c4a40484b0f 100644 (file)
@@ -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);
index db988c6bf0012891fc3658c7652a957f9f2d877d..627694c04a38c0a288a1e2c9a9027f58aacfbba6 100644 (file)
@@ -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();
index 3ab03783ba16a33a1da73c7c76362b368118368b..71f6cf171ec796583b48dd40e09ddf05728cdc20 100644 (file)
@@ -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,
index 79827b4501dc6247076dc4dd1385378d813ca1be..c881a3df3cbfb31abc203271d59c29c4febefd44 100644 (file)
@@ -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 *);
index b5e4f270c284fbde5d20661d1fb7322fb6b81fcd..a4d3f9e8b2780cae85bc519e2cbc8fef9849b162 100644 (file)
@@ -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);
index fdda818ec8f4b7be172a2b2ccc8a1c930a72ce8b..f8aa8296e396bba3d045e23ae410da3f61f53f2a 100644 (file)
@@ -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);