summaryrefslogtreecommitdiffstats
path: root/src/area.c
blob: 3a03198a52620e0d1f87122123a9947fdfddf078 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <SDL.h>
#include "area.h"
#include "layer.h"
#include "viewport.h"

void
render_area_to_viewport(struct area *area, struct viewport *vp)
{
	SDL_Rect srcrect;
	SDL_Rect dstrect;

	srcrect.x = vp->x;
	srcrect.y = vp->y;
	srcrect.w = vp->w;
	srcrect.h = vp->h;
	dstrect.x = 0;
	dstrect.y = 0;
	dstrect.w = vp->w;
	dstrect.h = vp->h;

	render_area_to_surface(area, &srcrect, vp->screen, &dstrect);
}

void
render_area_to_surface(struct area *area, SDL_Rect *arearect,
		SDL_Surface *dst, SDL_Rect *dstrect)
{
	/* Fast fill with black to avoid artifacts in off-map pixels. */
	SDL_FillRect(dst, dstrect, 0);

	/* Blit ground layer. */
	SDL_BlitSurface(area->map_layers[LAYER_GROUND], arearect,
			dst, dstrect);

	/* Blit low objects layer. */
	SDL_BlitSurface(area->map_layers[LAYER_OBJ_LOW], arearect,
			dst, dstrect);

	/* TODO: Blit low sprites. */

	/* Blit middle objects layer. */
	SDL_BlitSurface(area->map_layers[LAYER_OBJ_MID], arearect,
			dst, dstrect);

	/* TODO: Blit high sprites. */

	/* Blit high objects layer. */
	SDL_BlitSurface(area->map_layers[LAYER_OBJ_HIGH], arearect,
			dst, dstrect);
}