From: Holger Schemel Date: Thu, 11 Sep 2014 08:58:51 +0000 (+0200) Subject: Merge branch 'topic-tilesize-cleanup' X-Git-Tag: 4.0.0.0-rc1~354 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c3c190ae0fb103b7843b84b964bdfa1acb9b0091;hp=e5bb8b3337a96aea82e7b3b3eeab7a98e20e3a3e;p=rocksndiamonds.git Merge branch 'topic-tilesize-cleanup' --- diff --git a/ChangeLog b/ChangeLog index b1896e90..3711c4ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2014-09-10 + * fixed some drawing bugs when scaling graphics due to "game.tile_size" + * added some performance improvements when handling SDL surface scaling + +2014-09-04 + * added custom graphics property "game.tile_size" to define in-game tile + size (this defines the tile size actually displayed on the playfield); + tile graphics will either be scaled to the defined game tile size or + have to be specified with the same image size (using ".tile_size") + +2014-09-01 + * added custom graphics property ".tile_size" to define tile image size + for game element graphics (like "custom_1.tile_size"); non-standard + sized images will then be scaled accordingly to standard tile size + 2014-08-30 * fixed music still being played in Android version when in background diff --git a/src/conf_gfx.c b/src/conf_gfx.c index 9ac6c908..fad76e3f 100644 --- a/src/conf_gfx.c +++ b/src/conf_gfx.c @@ -59,6 +59,7 @@ struct ConfigTypeInfo image_config_suffix[] = { ".post_delay_random", ARG_UNDEFINED, TYPE_INTEGER }, { ".name", ARG_UNDEFINED, TYPE_STRING }, { ".scale_up_factor", ARG_UNDEFINED, TYPE_INTEGER }, + { ".tile_size", ARG_UNDEFINED, TYPE_INTEGER }, { ".clone_from", ARG_UNDEFINED, TYPE_GRAPHIC }, { ".fade_mode", ARG_UNDEFINED, TYPE_INTEGER }, { ".fade_delay", ARG_UNDEFINED, TYPE_INTEGER }, diff --git a/src/conftime.h b/src/conftime.h index b9b2330a..6e813d9b 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-09-02 22:37" +#define COMPILE_DATE_STRING "2014-09-10 22:28" diff --git a/src/init.c b/src/init.c index 0dc30c65..8e02ffe2 100644 --- a/src/init.c +++ b/src/init.c @@ -196,11 +196,14 @@ inline void InitElementSmallImagesScaledUp(int graphic) printf("::: '%s' -> '%s'\n", fi->token, fi->filename); #endif - CreateImageWithSmallImages(graphic, graphic_info[graphic].scale_up_factor); + CreateImageWithSmallImages(graphic, graphic_info[graphic].scale_up_factor, + graphic_info[graphic].tile_size); } void InitElementSmallImages() { + print_timestamp_init("InitElementSmallImages"); + static int special_graphics[] = { IMG_EDITOR_ELEMENT_BORDER, @@ -213,21 +216,30 @@ void InitElementSmallImages() int num_property_mappings = getImageListPropertyMappingSize(); int i; + print_timestamp_time("getImageListPropertyMapping/Size"); + + print_timestamp_init("InitElementSmallImagesScaledUp (1)"); /* initialize normal images from static configuration */ for (i = 0; element_to_graphic[i].element > -1; i++) InitElementSmallImagesScaledUp(element_to_graphic[i].graphic); + print_timestamp_done("InitElementSmallImagesScaledUp (1)"); /* initialize special images from static configuration */ for (i = 0; element_to_special_graphic[i].element > -1; i++) InitElementSmallImagesScaledUp(element_to_special_graphic[i].graphic); + print_timestamp_time("InitElementSmallImagesScaledUp (2)"); /* initialize images from dynamic configuration (may be elements or other) */ for (i = 0; i < num_property_mappings; i++) InitElementSmallImagesScaledUp(property_mapping[i].artwork_index); + print_timestamp_time("InitElementSmallImagesScaledUp (3)"); /* initialize special images from above list (non-element images) */ for (i = 0; special_graphics[i] > -1; i++) InitElementSmallImagesScaledUp(special_graphics[i]); + print_timestamp_time("InitElementSmallImagesScaledUp (4)"); + + print_timestamp_done("InitElementSmallImages"); } void InitScaledImages() @@ -1182,6 +1194,7 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->diggable_like = -1; /* do not use clone element */ g->border_size = TILEX / 8; /* "CRUMBLED" border size */ g->scale_up_factor = 1; /* default: no scaling up */ + g->tile_size = TILESIZE; /* default: standard tile size */ g->clone_from = -1; /* do not use clone graphic */ g->anim_delay_fixed = 0; g->anim_delay_random = 0; @@ -1207,6 +1220,14 @@ static void set_graphic_parameters_ext(int graphic, int *parameter, g->scale_up_factor = 1; /* no scaling */ #endif +#if 1 + /* optional tile size for using non-standard image size */ + if (parameter[GFX_ARG_TILE_SIZE] != ARG_UNDEFINED_VALUE) + g->tile_size = parameter[GFX_ARG_TILE_SIZE]; + if (g->tile_size < TILESIZE) + g->tile_size = TILESIZE; /* standard tile size */ +#endif + #if 1 if (g->use_image_size) { @@ -2402,6 +2423,10 @@ static void ReinitializeGraphics() { print_timestamp_init("ReinitializeGraphics"); +#if NEW_GAME_TILESIZE + InitGfxTileSizeInfo(game.tile_size, TILESIZE); +#endif + InitGraphicInfo(); /* graphic properties mapping */ print_timestamp_time("InitGraphicInfo"); InitElementGraphicInfo(); /* element game graphic mapping */ diff --git a/src/libgame/image.c b/src/libgame/image.c index 36fd184a..7f8302fc 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -260,14 +260,14 @@ void ReloadCustomImages() print_timestamp_done("ReloadCustomImages"); } -void CreateImageWithSmallImages(int pos, int zoom_factor) +void CreateImageWithSmallImages(int pos, int zoom_factor, int tile_size) { ImageInfo *img_info = getImageInfoEntryFromImageID(pos); if (img_info == NULL || img_info->contains_small_images) return; - CreateBitmapWithSmallBitmaps(img_info->bitmap, zoom_factor); + CreateBitmapWithSmallBitmaps(img_info->bitmap, zoom_factor, tile_size); img_info->contains_small_images = TRUE; img_info->scaled_up = TRUE; diff --git a/src/libgame/image.h b/src/libgame/image.h index 0d8dd27a..12754ea9 100644 --- a/src/libgame/image.h +++ b/src/libgame/image.h @@ -31,7 +31,7 @@ void InitImageList(struct ConfigInfo *, int, struct ConfigTypeInfo *, char **, char **, char **, char **, char **); void ReloadCustomImages(); -void CreateImageWithSmallImages(int, int); +void CreateImageWithSmallImages(int, int, int); void ScaleImage(int, int); void FreeAllImages(); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index b6fd5b40..bf875a6d 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -177,14 +177,113 @@ static void SDLSetWindowIcon(char *basename) } #if defined(TARGET_SDL2) + +static boolean equalSDLPixelFormat(SDL_PixelFormat *format1, + SDL_PixelFormat *format2) +{ + return (format1->format == format2->format && + format1->BitsPerPixel == format2->BitsPerPixel && + format1->BytesPerPixel == format2->BytesPerPixel && + format1->Rmask == format2->Rmask && + format1->Gmask == format2->Gmask && + format1->Bmask == format2->Bmask && + format1->Amask == format2->Amask); +} + +boolean SDLSetNativeSurface(SDL_Surface **surface) +{ + SDL_Surface *new_surface; + + if (surface == NULL || + *surface == NULL || + backbuffer == NULL || + backbuffer->surface == NULL) + return FALSE; + + // if pixel format already optimized for destination surface, do nothing + if (equalSDLPixelFormat((*surface)->format, backbuffer->surface->format)) + return FALSE; + + new_surface = SDL_ConvertSurface(*surface, backbuffer->surface->format, 0); + + SDL_FreeSurface(*surface); + + *surface = new_surface; + + return TRUE; +} + +SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) +{ + if (surface == NULL || + backbuffer == NULL || + backbuffer->surface == NULL) + return NULL; + + return SDL_ConvertSurface(surface, backbuffer->surface->format, 0); +} + SDL_Surface *SDL_DisplayFormat(SDL_Surface *surface) { - if (backbuffer == NULL || + if (surface == NULL || + backbuffer == NULL || backbuffer->surface == NULL) return NULL; +#if 0 + boolean same_pixel_format = + equalSDLPixelFormat(surface->format, backbuffer->surface->format); + + printf("::: SDL_DisplayFormat: %08x -> %08x [%08x, %08x, %08x -> %08x, %08x, %08x] [%d, %d -> %d, %d] => %s\n", + surface->format->format, + backbuffer->surface->format->format, + surface->format->Rmask, + surface->format->Gmask, + surface->format->Bmask, + backbuffer->surface->format->Rmask, + backbuffer->surface->format->Gmask, + backbuffer->surface->format->Bmask, + surface->format->BitsPerPixel, + surface->format->BytesPerPixel, + backbuffer->surface->format->BitsPerPixel, + backbuffer->surface->format->BytesPerPixel, + (same_pixel_format ? "SAME" : "DIFF")); +#endif + return SDL_ConvertSurface(surface, backbuffer->surface->format, 0); } + +#else + +boolean SDLSetNativeSurface(SDL_Surface **surface) +{ + SDL_Surface *new_surface; + + if (surface == NULL) + return FALSE; + + new_surface = SDL_DisplayFormat(*surface); + + if (new_surface == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); + + SDL_FreeSurface(*surface); + + *surface = new_surface; + + return TRUE; +} + +SDL_Surface *SDLGetNativeSurface(SDL_Surface *surface) +{ + SDL_Surface *new_surface = SDL_DisplayFormat(surface); + + if (new_surface == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError()); + + return new_surface; +} + #endif void SDLInitVideoDisplay(void) @@ -540,6 +639,11 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, if (sdl_texture != NULL) { +#if 1 + // use SDL default values for RGB masks and no alpha channel + new_surface = SDL_CreateRGBSurface(0, width, height, 32, 0,0,0, 0); +#else + #if 1 // (do not use alpha channel) new_surface = SDL_CreateRGBSurface(0, width, height, 32, @@ -554,6 +658,8 @@ static SDL_Surface *SDLCreateScreen(DrawBuffer **backbuffer, 0x0000FF00, 0x000000FF, 0xFF000000); +#endif + #endif if (new_surface == NULL) @@ -950,9 +1056,22 @@ void SDLRedrawWindow() } #endif -void SDLCreateBitmapContent(Bitmap *new_bitmap, int width, int height, +void SDLCreateBitmapContent(Bitmap *bitmap, int width, int height, int depth) { +#if 1 + SDL_Surface *surface = + SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, 0,0,0, 0); + + if (surface == NULL) + Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError()); + + SDLSetNativeSurface(&surface); + + bitmap->surface = surface; + +#else + SDL_Surface *surface_tmp, *surface_native; if ((surface_tmp = SDL_CreateRGBSurface(SURFACE_FLAGS, width, height, depth, @@ -966,6 +1085,7 @@ void SDLCreateBitmapContent(Bitmap *new_bitmap, int width, int height, SDL_FreeSurface(surface_tmp); new_bitmap->surface = surface_native; +#endif } void SDLFreeBitmapPointers(Bitmap *bitmap) @@ -2058,6 +2178,80 @@ int zoomSurfaceRGBA_scaleDownBy2(SDL_Surface *src, SDL_Surface *dst) return 0; } +#if 1 + +int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) +{ + int x, y, *sax, *say, *csax, *csay; + float sx, sy; + tColorRGBA *sp, *csp, *csp0, *dp; + int dgap; + + /* use specialized zoom function when scaling down to exactly half size */ + if (src->w == 2 * dst->w && + src->h == 2 * dst->h) + return zoomSurfaceRGBA_scaleDownBy2(src, dst); + +#if 0 + printf("::: zoomSurfaceRGBA: %d, %d -> %d, %d\n", + src->w, src->h, dst->w, dst->h); +#endif + + /* variable setup */ + sx = (float) src->w / (float) dst->w; + sy = (float) src->h / (float) dst->h; + + /* allocate memory for row increments */ + csax = sax = (int *)checked_malloc((dst->w + 1) * sizeof(Uint32)); + csay = say = (int *)checked_malloc((dst->h + 1) * sizeof(Uint32)); + + /* precalculate row increments */ + for (x = 0; x <= dst->w; x++) + *csax++ = (int)(sx * x); + + for (y = 0; y <= dst->h; y++) + *csay++ = (int)(sy * y); + + /* pointer setup */ + sp = csp = csp0 = (tColorRGBA *) src->pixels; + dp = (tColorRGBA *) dst->pixels; + dgap = dst->pitch - dst->w * 4; + + csay = say; + for (y = 0; y < dst->h; y++) + { + sp = csp; + csax = sax; + + for (x = 0; x < dst->w; x++) + { + /* draw */ + *dp = *sp; + + /* advance source pointers */ + csax++; + sp = csp + *csax; + + /* advance destination pointer */ + dp++; + } + + /* advance source pointer */ + csay++; + csp = (tColorRGBA *) ((Uint8 *) csp0 + *csay * src->pitch); + + /* advance destination pointers */ + dp = (tColorRGBA *) ((Uint8 *) dp + dgap); + } + + free(sax); + free(say); + + return 0; +} + +#else + int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) { int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; @@ -2142,6 +2336,8 @@ int zoomSurfaceRGBA(SDL_Surface *src, SDL_Surface *dst) return 0; } +#endif + /* ----------------------------------------------------------------------------- 8 bit zoomer @@ -2272,7 +2468,7 @@ SDL_Surface *zoomSurface(SDL_Surface *src, int dst_width, int dst_height) else { /* new source surface is 32 bit with a defined RGB ordering */ - zoom_src = SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, + zoom_src = SDL_CreateRGBSurface(SURFACE_FLAGS, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0); SDL_BlitSurface(src, NULL, zoom_src, NULL); is_32bit = TRUE; @@ -2283,7 +2479,7 @@ SDL_Surface *zoomSurface(SDL_Surface *src, int dst_width, int dst_height) if (is_32bit) { /* target surface is 32 bit with source RGBA/ABGR ordering */ - zoom_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 32, + zoom_dst = SDL_CreateRGBSurface(SURFACE_FLAGS, dst_width, dst_height, 32, zoom_src->format->Rmask, zoom_src->format->Gmask, zoom_src->format->Bmask, 0); @@ -2291,7 +2487,7 @@ SDL_Surface *zoomSurface(SDL_Surface *src, int dst_width, int dst_height) else { /* target surface is 8 bit */ - zoom_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dst_width, dst_height, 8, + zoom_dst = SDL_CreateRGBSurface(SURFACE_FLAGS, dst_width, dst_height, 8, 0, 0, 0, 0); } @@ -2327,25 +2523,92 @@ SDL_Surface *zoomSurface(SDL_Surface *src, int dst_width, int dst_height) return zoom_dst; } +#if 1 + +Bitmap *SDLZoomBitmap(Bitmap *src_bitmap, int dst_width, int dst_height) +{ +#if 1 + + Bitmap *dst_bitmap = CreateBitmapStruct(); + SDL_Surface **dst_surface = &dst_bitmap->surface; + + dst_width = MAX(1, dst_width); /* prevent zero bitmap width */ + dst_height = MAX(1, dst_height); /* prevent zero bitmap height */ + + dst_bitmap->width = dst_width; + dst_bitmap->height = dst_height; + + /* create zoomed temporary surface from source surface */ + *dst_surface = zoomSurface(src_bitmap->surface, dst_width, dst_height); + + /* create native format destination surface from zoomed temporary surface */ + SDLSetNativeSurface(dst_surface); + + return dst_bitmap; + +#else + + Bitmap *dst_bitmap = CreateBitmapStruct(); + SDL_Surface *sdl_surface_tmp; + + dst_width = MAX(1, dst_width); /* prevent zero bitmap width */ + dst_height = MAX(1, dst_height); /* prevent zero bitmap height */ + + dst_bitmap->width = dst_width; + dst_bitmap->height = dst_height; + + print_timestamp_init("SDLZoomBitmap"); + + /* create zoomed temporary surface from source surface */ + sdl_surface_tmp = zoomSurface(src_bitmap->surface, dst_width, dst_height); + print_timestamp_time("zoomSurface"); + + /* create native format destination surface from zoomed temporary surface */ + dst_bitmap->surface = SDL_DisplayFormat(sdl_surface_tmp); + print_timestamp_time("SDL_DisplayFormat"); + + /* free temporary surface */ + SDL_FreeSurface(sdl_surface_tmp); + print_timestamp_time("SDL_FreeSurface"); + + print_timestamp_done("SDLZoomBitmap"); + + return dst_bitmap; + +#endif +} + +#else + void SDLZoomBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap) { SDL_Surface *sdl_surface_tmp; int dst_width = dst_bitmap->width; int dst_height = dst_bitmap->height; + print_timestamp_init("SDLZoomBitmap"); + /* throw away old destination surface */ SDL_FreeSurface(dst_bitmap->surface); + print_timestamp_time("SDL_FreeSurface"); /* create zoomed temporary surface from source surface */ sdl_surface_tmp = zoomSurface(src_bitmap->surface, dst_width, dst_height); + print_timestamp_time("zoomSurface"); /* create native format destination surface from zoomed temporary surface */ dst_bitmap->surface = SDL_DisplayFormat(sdl_surface_tmp); + print_timestamp_time("SDL_DisplayFormat"); /* free temporary surface */ SDL_FreeSurface(sdl_surface_tmp); + print_timestamp_time("SDL_FreeSurface"); + + print_timestamp_done("SDLZoomBitmap"); } +#endif + /* ========================================================================= */ /* load image to bitmap */ @@ -2373,12 +2636,21 @@ Bitmap *SDLLoadImage(char *filename) UPDATE_BUSY_STATE(); /* create native non-transparent surface for current image */ +#if 1 + if ((new_bitmap->surface = SDLGetNativeSurface(sdl_image_tmp)) == NULL) + { + SetError("SDL_DisplayFormat(): %s", SDL_GetError()); + + return NULL; + } +#else if ((new_bitmap->surface = SDL_DisplayFormat(sdl_image_tmp)) == NULL) { SetError("SDL_DisplayFormat(): %s", SDL_GetError()); return NULL; } +#endif print_timestamp_time("SDL_DisplayFormat (opaque)"); @@ -2387,12 +2659,21 @@ Bitmap *SDLLoadImage(char *filename) /* create native transparent surface for current image */ SDL_SetColorKey(sdl_image_tmp, SET_TRANSPARENT_PIXEL, SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00)); +#if 1 + if ((new_bitmap->surface_masked = SDLGetNativeSurface(sdl_image_tmp)) == NULL) + { + SetError("SDL_DisplayFormat(): %s", SDL_GetError()); + + return NULL; + } +#else if ((new_bitmap->surface_masked = SDL_DisplayFormat(sdl_image_tmp)) == NULL) { SetError("SDL_DisplayFormat(): %s", SDL_GetError()); return NULL; } +#endif print_timestamp_time("SDL_DisplayFormat (masked)"); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index fe4bf7da..ef2cfd25 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -436,6 +436,9 @@ struct MouseCursorInfo /* SDL function definitions */ +boolean SDLSetNativeSurface(SDL_Surface **); +SDL_Surface *SDLGetNativeSurface(SDL_Surface *); + #if defined(TARGET_SDL2) SDL_Surface *SDL_DisplayFormat(SDL_Surface *); void SDLSetWindowScaling(int); @@ -464,7 +467,11 @@ void SDLPutPixel(Bitmap *, int, int, Pixel); void SDLInvertArea(Bitmap *, int, int, int, int, Uint32); void SDLCopyInverseMasked(Bitmap *, Bitmap *, int, int, int, int, int, int); +#if 1 +Bitmap *SDLZoomBitmap(Bitmap *, int, int); +#else void SDLZoomBitmap(Bitmap *, Bitmap *); +#endif Bitmap *SDLLoadImage(char *); diff --git a/src/libgame/system.c b/src/libgame/system.c index f8a60680..615d9d33 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -196,6 +196,12 @@ void InitGfxFieldInfo(int sx, int sy, int sxsize, int sysize, SetDrawBackgroundMask(REDRAW_NONE); /* deactivate masked drawing */ } +void InitGfxTileSizeInfo(int game_tile_size, int standard_tile_size) +{ + gfx.game_tile_size = game_tile_size; + gfx.standard_tile_size = standard_tile_size; +} + void InitGfxDoor1Info(int dx, int dy, int dxsize, int dysize) { gfx.dx = dx; @@ -1109,50 +1115,148 @@ void ReloadCustomImage(Bitmap *bitmap, char *basename) Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height) { +#if 0 + // !!! TEST ONLY !!! + Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH); + print_timestamp_time("CreateBitmap"); + + SDL_Rect src_rect, dst_rect; + + src_rect.x = 0; + src_rect.y = 0; + src_rect.w = src_bitmap->width - 0; + src_rect.h = src_bitmap->height; - SDLZoomBitmap(src_bitmap, dst_bitmap); + dst_rect.x = 0; + dst_rect.y = 0; + dst_rect.w = dst_bitmap->width; + dst_rect.h = dst_bitmap->height; + + SDL_BlitScaled(src_bitmap->surface, &src_rect, + dst_bitmap->surface, &dst_rect); + print_timestamp_time("SDL_BlitScaled"); + +#else + + Bitmap *dst_bitmap = SDLZoomBitmap(src_bitmap, zoom_width, zoom_height); +#endif return dst_bitmap; } static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, - boolean create_small_bitmaps) + int tile_size, boolean create_small_bitmaps) { Bitmap swap_bitmap; Bitmap *new_bitmap; - Bitmap *tmp_bitmap_1; - Bitmap *tmp_bitmap_2; - Bitmap *tmp_bitmap_4; - Bitmap *tmp_bitmap_8; - Bitmap *tmp_bitmap_16; - Bitmap *tmp_bitmap_32; + Bitmap *tmp_bitmap_final = NULL; + Bitmap *tmp_bitmap_0 = NULL; + Bitmap *tmp_bitmap_1 = NULL; + Bitmap *tmp_bitmap_2 = NULL; + Bitmap *tmp_bitmap_4 = NULL; + Bitmap *tmp_bitmap_8 = NULL; + Bitmap *tmp_bitmap_16 = NULL; + Bitmap *tmp_bitmap_32 = NULL; + int width_final, height_final; + int width_0, height_0; int width_1, height_1; int width_2, height_2; int width_4, height_4; int width_8, height_8; int width_16, height_16; -#if 0 +#if 1 int width_32, height_32; #endif + int old_width, old_height; int new_width, new_height; - /* calculate new image dimensions for normal sized image */ - width_1 = old_bitmap->width * zoom_factor; - height_1 = old_bitmap->height * zoom_factor; + print_timestamp_init("CreateScaledBitmaps"); - /* get image with normal size (this might require scaling up) */ + old_width = old_bitmap->width; + old_height = old_bitmap->height; + +#if 1 + /* calculate new image dimensions for final image size */ + width_final = old_width * zoom_factor; + height_final = old_height * zoom_factor; + + /* get image with final size (this might require scaling up) */ + /* ("final" size may result in non-standard tile size image) */ + if (zoom_factor != 1) + tmp_bitmap_final = ZoomBitmap(old_bitmap, width_final, height_final); + else + tmp_bitmap_final = old_bitmap; + +#else + + /* calculate new image dimensions for final image size */ + width_1 = old_width * zoom_factor; + height_1 = old_height * zoom_factor; + + /* get image with final size (this might require scaling up) */ + /* ("final" size may result in non-standard tile size image) */ if (zoom_factor != 1) tmp_bitmap_1 = ZoomBitmap(old_bitmap, width_1, height_1); else tmp_bitmap_1 = old_bitmap; +#endif + + UPDATE_BUSY_STATE(); + + width_0 = width_1 = width_final; + height_0 = height_1 = height_final; + + tmp_bitmap_0 = tmp_bitmap_1 = tmp_bitmap_final; - /* this is only needed to make compilers happy */ - tmp_bitmap_2 = NULL; - tmp_bitmap_4 = NULL; - tmp_bitmap_8 = NULL; - tmp_bitmap_16 = NULL; - tmp_bitmap_32 = NULL; +#if 1 + if (create_small_bitmaps) + { + /* check if we have a non-gameplay tile size image */ + if (tile_size != gfx.game_tile_size) + { + /* get image with gameplay tile size */ + width_0 = width_final * gfx.game_tile_size / tile_size; + height_0 = height_final * gfx.game_tile_size / tile_size; + + if (width_0 == old_width) + tmp_bitmap_0 = old_bitmap; + else if (width_0 == width_final) + tmp_bitmap_0 = tmp_bitmap_final; + else + { +#if 0 + if (old_width != width_0) + printf("::: %d, %d -> %d, %d\n", + old_width, old_height, width_0, height_0); +#endif + + tmp_bitmap_0 = ZoomBitmap(old_bitmap, width_0, height_0); + } + + UPDATE_BUSY_STATE(); + } + + /* check if we have a non-standard tile size image */ + if (tile_size != gfx.standard_tile_size) + { + /* get image with standard tile size */ + width_1 = width_final * gfx.standard_tile_size / tile_size; + height_1 = height_final * gfx.standard_tile_size / tile_size; + + if (width_1 == old_width) + tmp_bitmap_1 = old_bitmap; + else if (width_1 == width_final) + tmp_bitmap_1 = tmp_bitmap_final; + else if (width_1 == width_0) + tmp_bitmap_1 = tmp_bitmap_0; + else + tmp_bitmap_1 = ZoomBitmap(old_bitmap, width_1, height_1); + + UPDATE_BUSY_STATE(); + } + } +#endif if (create_small_bitmaps) { @@ -1165,13 +1269,54 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, height_8 = height_1 / 8; width_16 = width_1 / 16; height_16 = height_1 / 16; -#if 0 +#if 1 width_32 = width_1 / 32; height_32 = height_1 / 32; #endif +#if 1 + /* get image with 1/2 of normal size (for use in the level editor) */ + if (width_2 == old_width) + tmp_bitmap_2 = old_bitmap; + else + tmp_bitmap_2 = ZoomBitmap(tmp_bitmap_1, width_2, height_2); + + UPDATE_BUSY_STATE(); + + /* get image with 1/4 of normal size (for use in the level editor) */ + if (width_4 == old_width) + tmp_bitmap_4 = old_bitmap; + else + tmp_bitmap_4 = ZoomBitmap(tmp_bitmap_2, width_4, height_4); + + UPDATE_BUSY_STATE(); + + /* get image with 1/8 of normal size (for use on the preview screen) */ + if (width_8 == old_width) + tmp_bitmap_8 = old_bitmap; + else + tmp_bitmap_8 = ZoomBitmap(tmp_bitmap_4, width_8, height_8); + + UPDATE_BUSY_STATE(); + + /* get image with 1/16 of normal size (for use on the preview screen) */ + if (width_16 == old_width) + tmp_bitmap_16 = old_bitmap; + else + tmp_bitmap_16 = ZoomBitmap(tmp_bitmap_8, width_16, height_16); + + UPDATE_BUSY_STATE(); + + /* get image with 1/32 of normal size (for use on the preview screen) */ + if (width_32 == old_width) + tmp_bitmap_32 = old_bitmap; + else + tmp_bitmap_32 = ZoomBitmap(tmp_bitmap_16, width_32, height_32); + UPDATE_BUSY_STATE(); +#else + /* get image with 1/2 of normal size (for use in the level editor) */ if (zoom_factor != 2) tmp_bitmap_2 = ZoomBitmap(tmp_bitmap_1, width_1 / 2, height_1 / 2); @@ -1211,6 +1356,7 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, tmp_bitmap_32 = old_bitmap; UPDATE_BUSY_STATE(); +#endif } #if 0 @@ -1235,8 +1381,21 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, new_width = width_1; new_height = height_1 + (height_1 + 1) / 2; /* prevent odd height */ +#if 1 + if (width_0 != width_1) + { + new_width += width_0; + new_height = MAX(new_height, height_0); + } +#endif + new_bitmap = CreateBitmap(new_width, new_height, DEFAULT_DEPTH); +#if 1 + if (width_0 != width_1) + BlitBitmap(tmp_bitmap_0, new_bitmap, 0, 0, width_0, height_0, width_1, 0); +#endif + BlitBitmap(tmp_bitmap_1, new_bitmap, 0, 0, width_1, height_1, 0, 0); BlitBitmap(tmp_bitmap_2, new_bitmap, 0, 0, width_1 / 2, height_1 / 2, 0, height_1); @@ -1262,6 +1421,37 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if (create_small_bitmaps) { /* if no small bitmaps created, tmp_bitmap_1 is used as new bitmap now */ + +#if 1 + if (tmp_bitmap_final != old_bitmap) + FreeBitmap(tmp_bitmap_final); + + if (tmp_bitmap_0 != old_bitmap && + tmp_bitmap_0 != tmp_bitmap_final) + FreeBitmap(tmp_bitmap_0); + + if (tmp_bitmap_1 != old_bitmap && + tmp_bitmap_1 != tmp_bitmap_final && + tmp_bitmap_1 != tmp_bitmap_0) + FreeBitmap(tmp_bitmap_1); + + if (tmp_bitmap_2 != old_bitmap) + FreeBitmap(tmp_bitmap_2); + + if (tmp_bitmap_4 != old_bitmap) + FreeBitmap(tmp_bitmap_4); + + if (tmp_bitmap_8 != old_bitmap) + FreeBitmap(tmp_bitmap_8); + + if (tmp_bitmap_16 != old_bitmap) + FreeBitmap(tmp_bitmap_16); + + if (tmp_bitmap_32 != old_bitmap) + FreeBitmap(tmp_bitmap_32); + +#else + if (zoom_factor != 1) FreeBitmap(tmp_bitmap_1); @@ -1279,6 +1469,7 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if (zoom_factor != 32) FreeBitmap(tmp_bitmap_32); +#endif } /* replace image with extended image (containing 1/1, 1/2, 1/4, 1/8 size) */ @@ -1305,8 +1496,15 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, SDL_SetColorKey(old_surface, SET_TRANSPARENT_PIXEL, SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00)); - if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) ==NULL) + +#if 1 + if ((old_bitmap->surface_masked = SDLGetNativeSurface(old_surface)) == NULL) + Error(ERR_EXIT, "SDL_DisplayFormat() failed"); +#else + if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) == NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); +#endif + SDL_SetColorKey(old_surface, UNSET_TRANSPARENT_PIXEL, 0); } #endif @@ -1314,16 +1512,19 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, UPDATE_BUSY_STATE(); FreeBitmap(new_bitmap); /* this actually frees the _old_ bitmap now */ + + print_timestamp_done("CreateScaledBitmaps"); } -void CreateBitmapWithSmallBitmaps(Bitmap *old_bitmap, int zoom_factor) +void CreateBitmapWithSmallBitmaps(Bitmap *old_bitmap, int zoom_factor, + int tile_size) { - CreateScaledBitmaps(old_bitmap, zoom_factor, TRUE); + CreateScaledBitmaps(old_bitmap, zoom_factor, tile_size, TRUE); } void ScaleBitmap(Bitmap *old_bitmap, int zoom_factor) { - CreateScaledBitmaps(old_bitmap, zoom_factor, FALSE); + CreateScaledBitmaps(old_bitmap, zoom_factor, 0, FALSE); } diff --git a/src/libgame/system.h b/src/libgame/system.h index e9b4cb51..162e1536 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -775,6 +775,8 @@ struct GfxInfo int full_sxsize, full_sysize; int scrollbuffer_width, scrollbuffer_height; + int game_tile_size, standard_tile_size; + int dx, dy; int dxsize, dysize; @@ -1276,6 +1278,7 @@ void InitPlatformDependentStuff(void); void ClosePlatformDependentStuff(void); void InitGfxFieldInfo(int, int, int, int, int, int, int, int, Bitmap *); +void InitGfxTileSizeInfo(int, int); void InitGfxDoor1Info(int, int, int, int); void InitGfxDoor2Info(int, int, int, int); void InitGfxDoor3Info(int, int, int, int); @@ -1331,7 +1334,7 @@ Bitmap *LoadCustomImage(char *); void ReloadCustomImage(Bitmap *, char *); Bitmap *ZoomBitmap(Bitmap *, int, int); -void CreateBitmapWithSmallBitmaps(Bitmap *, int); +void CreateBitmapWithSmallBitmaps(Bitmap *, int, int); void ScaleBitmap(Bitmap *, int); void SetMouseCursor(int); diff --git a/src/main.h b/src/main.h index 0bd31a50..1357db71 100644 --- a/src/main.h +++ b/src/main.h @@ -31,6 +31,7 @@ #include "conf_mus.h" /* include auto-generated data structure definitions */ +#define NEW_GAME_TILESIZE 1 #define NEW_TILESIZE 1 #define NEW_SCROLL 1 @@ -1950,22 +1951,23 @@ #define GFX_ARG_POST_DELAY_RANDOM 35 #define GFX_ARG_NAME 36 #define GFX_ARG_SCALE_UP_FACTOR 37 -#define GFX_ARG_CLONE_FROM 38 -#define GFX_ARG_FADE_MODE 39 -#define GFX_ARG_FADE_DELAY 40 -#define GFX_ARG_POST_DELAY 41 -#define GFX_ARG_AUTO_DELAY 42 -#define GFX_ARG_ALIGN 43 -#define GFX_ARG_VALIGN 44 -#define GFX_ARG_SORT_PRIORITY 45 -#define GFX_ARG_CLASS 46 -#define GFX_ARG_STYLE 47 -#define GFX_ARG_ACTIVE_XOFFSET 48 -#define GFX_ARG_ACTIVE_YOFFSET 49 -#define GFX_ARG_PRESSED_XOFFSET 50 -#define GFX_ARG_PRESSED_YOFFSET 51 - -#define NUM_GFX_ARGS 52 +#define GFX_ARG_TILE_SIZE 38 +#define GFX_ARG_CLONE_FROM 39 +#define GFX_ARG_FADE_MODE 40 +#define GFX_ARG_FADE_DELAY 41 +#define GFX_ARG_POST_DELAY 42 +#define GFX_ARG_AUTO_DELAY 43 +#define GFX_ARG_ALIGN 44 +#define GFX_ARG_VALIGN 45 +#define GFX_ARG_SORT_PRIORITY 46 +#define GFX_ARG_CLASS 47 +#define GFX_ARG_STYLE 48 +#define GFX_ARG_ACTIVE_XOFFSET 49 +#define GFX_ARG_ACTIVE_YOFFSET 50 +#define GFX_ARG_PRESSED_XOFFSET 51 +#define GFX_ARG_PRESSED_YOFFSET 52 + +#define NUM_GFX_ARGS 53 /* values for sound configuration suffixes */ @@ -2792,6 +2794,7 @@ struct GraphicInfo int border_size; /* border size for "crumbled" graphics */ int scale_up_factor; /* optional factor for scaling image up */ + int tile_size; /* optional explicitly defined tile size */ int clone_from; /* graphic for cloning *all* settings */ diff --git a/src/tools.c b/src/tools.c index c812e302..6e1ffddc 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1520,12 +1520,28 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize_raw, Bitmap *src_bitmap = g->bitmap; int tilesize = MIN(MAX(1, tilesize_raw), TILESIZE); int offset_calc_pos = log_2(tilesize); + int bitmap_width = src_bitmap->width; + int bitmap_height = src_bitmap->height; int width_mult = offset_calc[offset_calc_pos].width_mult; int width_div = offset_calc[offset_calc_pos].width_div; int height_mult = offset_calc[offset_calc_pos].height_mult; int height_div = offset_calc[offset_calc_pos].height_div; - int startx = src_bitmap->width * width_mult / width_div; - int starty = src_bitmap->height * height_mult / height_div; + int startx = bitmap_width * width_mult / width_div; + int starty = bitmap_height * height_mult / height_div; + +#if NEW_GAME_TILESIZE + + int src_x = (g->src_x + (get_backside ? g->offset2_x : 0)) * + tilesize_raw / TILESIZE; + int src_y = (g->src_y + (get_backside ? g->offset2_y : 0)) * + tilesize_raw / TILESIZE; + int width = g->width * tilesize_raw / TILESIZE; + int height = g->height * tilesize_raw / TILESIZE; + int offset_x = g->offset_x * tilesize_raw / TILESIZE; + int offset_y = g->offset_y * tilesize_raw / TILESIZE; + +#else + #if NEW_TILESIZE int src_x = (g->src_x + (get_backside ? g->offset2_x : 0)) * tilesize / TILESIZE; @@ -1540,6 +1556,34 @@ void getSizedGraphicSourceExt(int graphic, int frame, int tilesize_raw, int offset_x = g->offset_x * tilesize / TILESIZE; int offset_y = g->offset_y * tilesize / TILESIZE; +#endif + +#if NEW_GAME_TILESIZE + if (game.tile_size != TILESIZE) + { + int bitmap_width_std = + bitmap_width * TILESIZE / (TILESIZE + game.tile_size); + int bitmap_height_std = + bitmap_height * TILESIZE / game.tile_size * 3 / 2; + + if (tilesize_raw == game.tile_size) + { + startx = bitmap_width_std; + starty = 0; + } + else + { + bitmap_width = bitmap_width_std; + + if (game.tile_size > TILESIZE * 3 / 2) + bitmap_height = bitmap_height_std; + + startx = bitmap_width * width_mult / width_div; + starty = bitmap_height * height_mult / height_div; + } + } +#endif + if (g->offset_y == 0) /* frames are ordered horizontally */ { int max_width = g->anim_frames_per_line * width; @@ -1609,7 +1653,6 @@ inline void getGraphicSourceExt(int graphic, int frame, Bitmap **bitmap, int src_y = g->src_y + (get_backside ? g->offset2_y : 0); #if NEW_TILESIZE - if (TILESIZE_VAR != TILESIZE) return getSizedGraphicSourceExt(graphic, frame, TILESIZE_VAR, bitmap, x, y, get_backside); @@ -2191,8 +2234,8 @@ static void DrawLevelFieldCrumbledInnerCorners(int x, int y, int dx, int dy, #if NEW_TILESIZE width = crumbled_border_size * TILESIZE_VAR / TILESIZE; height = crumbled_border_size * TILESIZE_VAR / TILESIZE; - cx = (dx > 0 ? TILEX - crumbled_border_size : 0) * TILESIZE_VAR / TILESIZE; - cy = (dy > 0 ? TILEY - crumbled_border_size : 0) * TILESIZE_VAR / TILESIZE; + cx = (dx > 0 ? TILESIZE_VAR - width : 0); + cy = (dy > 0 ? TILESIZE_VAR - height : 0); BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height, FX + sx * TILEX_VAR + cx, FY + sy * TILEY_VAR + cy); @@ -2215,6 +2258,8 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, int width, height, bx, by, cx, cy; int sx = SCREENX(x), sy = SCREENY(y); int crumbled_border_size = graphic_info[graphic].border_size; + int crumbled_border_size_var = crumbled_border_size * TILESIZE_VAR / TILESIZE; + int crumbled_border_pos_var = TILESIZE_VAR - crumbled_border_size_var; int i; getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y); @@ -2222,10 +2267,10 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, /* draw simple, sloppy, non-corner-accurate crumbled border */ #if 1 - width = (dir == 1 || dir == 2 ? crumbled_border_size : TILEX); - height = (dir == 0 || dir == 3 ? crumbled_border_size : TILEY); - cx = (dir == 2 ? TILEX - crumbled_border_size : 0); - cy = (dir == 3 ? TILEY - crumbled_border_size : 0); + width = (dir == 1 || dir == 2 ? crumbled_border_size_var : TILESIZE_VAR); + height = (dir == 0 || dir == 3 ? crumbled_border_size_var : TILESIZE_VAR); + cx = (dir == 2 ? crumbled_border_pos_var : 0); + cy = (dir == 3 ? crumbled_border_pos_var : 0); #else if (dir == 1 || dir == 2) /* left or right crumbled border */ { @@ -2245,12 +2290,12 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, #if NEW_TILESIZE BlitBitmap(src_bitmap, drawto_field, - src_x + cx * TILESIZE_VAR / TILESIZE, - src_y + cy * TILESIZE_VAR / TILESIZE, - width * TILESIZE_VAR / TILESIZE, - height * TILESIZE_VAR / TILESIZE, - FX + sx * TILEX_VAR + cx * TILESIZE_VAR / TILESIZE, - FY + sy * TILEY_VAR + cy * TILESIZE_VAR / TILESIZE); + src_x + cx, + src_y + cy, + width, + height, + FX + sx * TILEX_VAR + cx, + FY + sy * TILEY_VAR + cy); #else BlitBitmap(src_bitmap, drawto_field, src_x + cx, src_y + cy, width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); @@ -2264,7 +2309,7 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, /* correct corners of crumbled border, if needed */ #if 1 - for (i = -1; i <= 1; i+=2) + for (i = -1; i <= 1; i += 2) { int xx = x + (dir == 0 || dir == 3 ? i : 0); int yy = y + (dir == 1 || dir == 2 ? i : 0); @@ -2278,13 +2323,13 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, { /* no crumbled corner, but continued crumbled border */ - int c1 = (dir == 2 || dir == 3 ? TILESIZE - crumbled_border_size : 0); - int c2 = (i == 1 ? TILESIZE - crumbled_border_size : 0); - int b1 = (i == 1 ? crumbled_border_size : - TILESIZE - 2 * crumbled_border_size); + int c1 = (dir == 2 || dir == 3 ? crumbled_border_pos_var : 0); + int c2 = (i == 1 ? crumbled_border_pos_var : 0); + int b1 = (i == 1 ? crumbled_border_size_var : + TILESIZE_VAR - 2 * crumbled_border_size_var); - width = crumbled_border_size; - height = crumbled_border_size; + width = crumbled_border_size_var; + height = crumbled_border_size_var; if (dir == 1 || dir == 2) { @@ -2303,12 +2348,12 @@ static void DrawLevelFieldCrumbledBorders(int x, int y, int graphic, int frame, #if NEW_TILESIZE BlitBitmap(src_bitmap, drawto_field, - src_x + bx * TILESIZE_VAR / TILESIZE, - src_y + by * TILESIZE_VAR / TILESIZE, - width * TILESIZE_VAR / TILESIZE, - height * TILESIZE_VAR / TILESIZE, - FX + sx * TILEX_VAR + cx * TILESIZE_VAR / TILESIZE, - FY + sy * TILEY_VAR + cy * TILESIZE_VAR / TILESIZE); + src_x + bx, + src_y + by, + width, + height, + FX + sx * TILEX_VAR + cx, + FY + sy * TILEY_VAR + cy); #else BlitBitmap(src_bitmap, drawto_field, src_x + bx, src_y + by, width, height, FX + sx * TILEX + cx, FY + sy * TILEY + cy); @@ -11510,7 +11555,14 @@ void ChangeViewportPropertiesIfNeeded() int new_exsize = vp_door_3->width; int new_eysize = vp_door_3->height; #if NEW_TILESIZE + +#if NEW_GAME_TILESIZE + int new_tilesize_var = + (setup.small_game_graphics ? MINI_TILESIZE : game.tile_size); +#else int new_tilesize_var = TILESIZE / (setup.small_game_graphics ? 2 : 1); +#endif + int tilesize = (gfx_game_mode == GAME_MODE_PLAYING ? new_tilesize_var : gfx_game_mode == GAME_MODE_EDITOR ? MINI_TILESIZE : TILESIZE); int new_scr_fieldx = new_sxsize / tilesize;