summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-03-02 14:15:11 (EST)
committer P. J. McDermott <pjm@nac.net>2013-03-02 14:15:11 (EST)
commit5c8d2956859492b5324c1ffd2b18db74a2d34913 (patch)
tree54ba0ce8597e1ee349e95f0be7fa3ab968018d9a /src
parentce21693e65a79d6005c5bd6092799fff208fb45b (diff)
downloadoverworld-rpg-5c8d2956859492b5324c1ffd2b18db74a2d34913.zip
overworld-rpg-5c8d2956859492b5324c1ffd2b18db74a2d34913.tar.gz
overworld-rpg-5c8d2956859492b5324c1ffd2b18db74a2d34913.tar.bz2
src/area.c: Split up area_new().
Diffstat (limited to 'src')
-rw-r--r--src/area.c35
-rw-r--r--src/area.h2
2 files changed, 25 insertions, 12 deletions
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);