From 5c8d2956859492b5324c1ffd2b18db74a2d34913 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 02 Mar 2013 14:15:11 -0500 Subject: src/area.c: Split up area_new(). --- diff --git a/src/area.c b/src/area.c index 4f0bc11..a41ff62 100644 --- a/src/area.c +++ b/src/area.c @@ -4,11 +4,13 @@ #include "resources/map.h" #include "logging.h" +static void init_map_layers(struct area *); +static void set_layers_palette(struct area *, struct viewport *); static void blit_map_layers(struct area *); static void blit_map_layer(struct area *, enum map_layer, enum area_layer); struct area * -area_new(struct map *map) +area_new(struct map *map, struct viewport *vp) { struct area *a; @@ -22,25 +24,19 @@ area_new(struct map *map) } a->map = map; + init_map_layers(a); + set_layers_palette(a, vp); blit_map_layers(a); return a; } static void -blit_map_layers(struct area *area) +init_map_layers(struct area *area) { - SDL_Color colors[256]; - int i; SDL_Rect dstrect; enum area_layer l; - for (i = 0; i < 256; ++i) { - colors[i].r = (i % 8) * 36; - colors[i].g = (i % 64 / 8) * 36; - colors[i].b = (i / 64) * 85; - } - dstrect.x = 0; dstrect.y = 0; dstrect.w = area->map->width * area->map->tilewidth; @@ -59,9 +55,26 @@ blit_map_layers(struct area *area) SDL_RLEACCEL, SDL_MapRGB(area->map_layers[l]->format, 0xFC, 0x00, 0xFF)); - SDL_SetColors(area->map_layers[l], colors, 0, 256); } +} + +static void +set_layers_palette(struct area *area, struct viewport *vp) +{ + enum area_layer l; + SDL_Palette *pal; + pal = vp->screen->format->palette; + + for (l = 0; l < AREA_LAYERS_MAX; ++l) { + SDL_SetColors(area->map_layers[l], + pal->colors, 0, pal->ncolors); + } +} + +static void +blit_map_layers(struct area *area) +{ blit_map_layer(area, MAP_LAYER_GROUND, AREA_LAYER_BOT); blit_map_layer(area, MAP_LAYER_OBJ_LOW, AREA_LAYER_BOT); blit_map_layer(area, MAP_LAYER_OBJ_MID, AREA_LAYER_MID); diff --git a/src/area.h b/src/area.h index 8fee049..3ab9aea 100644 --- a/src/area.h +++ b/src/area.h @@ -16,7 +16,7 @@ struct area { SDL_Surface *map_layers[AREA_LAYERS_MAX]; }; -struct area *area_new(struct map *map); +struct area *area_new(struct map *map, struct viewport *vp); void render_area_to_viewport(struct area *area, struct viewport *vp); void render_area_to_surface(struct area *area, SDL_Rect *arearect, SDL_Surface *surface, SDL_Rect *surfacerect); -- cgit v0.9.1