twn_textures.c: fix srcrect setting on atlas rebuild
This commit is contained in:
		| @@ -94,9 +94,9 @@ static void ingame_tick(struct state *state) { | ||||
|                             (t_fvec3){ (float)x,     d0, (float)y }, | ||||
|                             (t_fvec3){ (float)x + 1, d1, (float)y }, | ||||
|                             (t_fvec3){ (float)x,     d3, (float)y - 1 }, | ||||
|                             (t_shvec2){ 0, 768 }, | ||||
|                             (t_shvec2){ 1024, 768 }, | ||||
|                             (t_shvec2){ 1024, 0 }); | ||||
|                             (t_shvec2){ 1024, 0 }, | ||||
|                             (t_shvec2){ 0, 768 }); | ||||
|  | ||||
|             unfurl_triangle("/assets/grass.gif", | ||||
|                             (t_fvec3){ (float)x + 1, d1, (float)y }, | ||||
|   | ||||
| @@ -130,8 +130,8 @@ static void upload_texture_from_surface(gpu_texture texture, SDL_Surface *surfac | ||||
|  | ||||
|  | ||||
| static void recreate_current_atlas_texture(struct texture_cache *cache) { | ||||
|     /* TODO: figure out if SDL_UpdateTexture alone is faster than blitting */ | ||||
|     /* TODO: should surfaces be freed after they cannot be referenced in atlas builing? */ | ||||
|     /*       for example, if full page of 64x64 tiles was already filled, there's no real reason to process them further */ | ||||
|     SDL_Surface *atlas_surface = cache->atlas_surfaces[cache->atlas_index]; | ||||
|  | ||||
|     /* clear */ | ||||
| @@ -230,13 +230,19 @@ static bool update_rects(struct texture_cache *cache, stbrp_rect *rects, stbrp_r | ||||
|  | ||||
| /* updates the atlas location of every rect in the cache */ | ||||
| static void update_texture_rects_in_atlas(struct texture_cache *cache, stbrp_rect *rects) { | ||||
|     int r = 0; | ||||
|     for (size_t i = 0; i < arrlenu(rects); ++i) { | ||||
|         if (cache->hash[i].value.loner_texture != 0) | ||||
|             continue; | ||||
|  | ||||
|         cache->hash[i].value.srcrect = (t_frect) { | ||||
|             .x = (float)rects[i].x, | ||||
|             .y = (float)rects[i].y, | ||||
|             .w = (float)rects[i].w, | ||||
|             .h = (float)rects[i].h, | ||||
|             .x = (float)rects[r].x, | ||||
|             .y = (float)rects[r].y, | ||||
|             .w = (float)rects[r].w, | ||||
|             .h = (float)rects[r].h, | ||||
|         }; | ||||
|  | ||||
|         r++; | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user