diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/map.c | 17 | ||||
-rw-r--r-- | src/tileset.c | 12 | ||||
-rw-r--r-- | src/tileset.h | 4 |
3 files changed, 17 insertions, 16 deletions
@@ -507,7 +507,7 @@ _db_tmx_map_start(void *pv, const char *name, const char **attr) static int _db_map_render_layer(struct db_map *map, struct db_map_layer *layer, - SDL_Renderer *renderer, SDL_Texture *texture) + SDL_Renderer *renderer) { int i; int gid; @@ -553,8 +553,11 @@ _db_map_render_layer(struct db_map *map, struct db_map_layer *layer, tile_rect.w, tile_rect.h, tile_rect.x, tile_rect.y, layer_rect.x, layer_rect.y); - if (SDL_RenderCopy(renderer, texture, - &tile_rect, &layer_rect) != 0) { + if (SDL_RenderCopy(renderer, db_tileset_texture( + tileset, + renderer), + &tile_rect, &layer_rect) + != 0) { db_err("Failed to copy texture (%s)", SDL_GetError()); return -1; @@ -574,16 +577,10 @@ _db_map_render_layer(struct db_map *map, struct db_map_layer *layer, SDL_Texture * db_map_render(struct db_map *map, SDL_Renderer *renderer) { - struct db_tileset *tileset; SDL_Texture *texture; SDL_Texture *old_target; struct db_map_layer *layer; - for (tileset = map->tileset_head; tileset != NULL; - tileset = db_tileset_next(tileset)) { - db_tileset_create_texture(tileset, renderer); - } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, map->w, map->h); old_target = SDL_GetRenderTarget(renderer); @@ -594,7 +591,7 @@ db_map_render(struct db_map *map, SDL_Renderer *renderer) } for (layer = map->layer_head; layer != NULL; layer = layer->next) { - if (_db_map_render_layer(map, layer, renderer, texture) != 0) { + if (_db_map_render_layer(map, layer, renderer) != 0) { return NULL; } } diff --git a/src/tileset.c b/src/tileset.c index 0871602..366c925 100644 --- a/src/tileset.c +++ b/src/tileset.c @@ -448,10 +448,12 @@ db_tileset_next(struct db_tileset *tileset) return tileset->next; } -int -db_tileset_create_texture(struct db_tileset *tileset, SDL_Renderer *renderer) +SDL_Texture * +db_tileset_texture(struct db_tileset *tileset, SDL_Renderer *renderer) { - tileset->texture = SDL_CreateTextureFromSurface(renderer, - tileset->image); - return (tileset->texture != NULL ? 0 : -1); + if (tileset->texture == NULL) { + tileset->texture = SDL_CreateTextureFromSurface(renderer, + tileset->image); + } + return tileset->texture; } diff --git a/src/tileset.h b/src/tileset.h index 8d660b7..d350765 100644 --- a/src/tileset.h +++ b/src/tileset.h @@ -20,6 +20,8 @@ #ifndef DB_TILESET_H_ #define DB_TILESET_H_ +#include <SDL.h> + struct db_tileset; struct db_tileset *db_tileset_new(const char *game_id, const char *file, @@ -31,7 +33,7 @@ int db_tileset_columns (struct db_tileset *tileset) __attribute__((__pure__)); int db_tileset_firstgid (struct db_tileset *tileset) __attribute__((__pure__)); struct db_tileset *db_tileset_next(struct db_tileset *tileset) __attribute__((__pure__)); -int db_tileset_create_texture(struct db_tileset *tileset, +SDL_Texture *db_tileset_texture(struct db_tileset *tileset, SDL_Renderer *renderer); #endif /* DB_TILESET_H_ */ |