diff options
Diffstat (limited to 'src/area.c')
-rw-r--r-- | src/area.c | 35 |
1 files changed, 24 insertions, 11 deletions
@@ -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); |