diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/area.c | 47 | ||||
-rw-r--r-- | src/area.h | 2 |
2 files changed, 34 insertions, 15 deletions
@@ -118,35 +118,54 @@ render_area_to_viewport(struct area *area, struct viewport *vp) void render_area_to_surface(struct area *area, SDL_Rect *arearect, - SDL_Surface *dst, SDL_Rect *dstrect) + SDL_Surface *surface, SDL_Rect *surfacerect) { - debug("Rendering %dx%d area rect at (%d,%d) " - "onto %dx%d surface rect at (%d,%d)...", - arearect->w, arearect->h, arearect->x, arearect->y, - dstrect->w, dstrect->h, dstrect->x, dstrect->y); + SDL_Rect srcrect, dstrect; + + memcpy(&srcrect, arearect, sizeof(srcrect)); + memcpy(&dstrect, surfacerect, sizeof(dstrect)); /* Fast fill with black to avoid artifacts in off-map pixels. */ /* NB: This is gray, at least temporarily. */ - SDL_FillRect(dst, dstrect, SDL_MapRGB(dst->format, 63, 63, 63)); + SDL_FillRect(surface, &dstrect, + SDL_MapRGB(surface->format, 63, 63, 63)); + + /* Avoid fun glitches due to negative coordinates in source + * rectangles. */ + if (srcrect.x < 0) { + srcrect.x = 0; + dstrect.x = surfacerect->x - arearect->x; + } + if (srcrect.y < 0) { + srcrect.y = 0; + dstrect.y = surfacerect->y - arearect->y; + } + +#if 0 + debug("Rendering %dx%d area rect at (%d,%d) " + "onto %dx%d surface rect at (%d,%d)...", + srcrect.w, srcrect.h, srcrect.x, srcrect.y, + dstrect.w, dstrect.h, dstrect.x, dstrect.y); +#endif /* Blit ground layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_GROUND], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_GROUND], &srcrect, + surface, &dstrect); /* Blit low objects layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_LOW], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_LOW], &srcrect, + surface, &dstrect); /* return;*/ /* TODO: Blit low sprites. */ /* Blit middle objects layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_MID], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_MID], &srcrect, + surface, &dstrect); /* TODO: Blit high sprites. */ /* Blit high objects layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_HIGH], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_HIGH], &srcrect, + surface, &dstrect); } @@ -13,6 +13,6 @@ struct area { struct area *area_new(struct map *map); void render_area_to_viewport(struct area *area, struct viewport *vp); void render_area_to_surface(struct area *area, SDL_Rect *arearect, - SDL_Surface *dst, SDL_Rect *dstrect); + SDL_Surface *surface, SDL_Rect *surfacerect); #endif |