summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-03-04 20:41:33 (EST)
committer P. J. McDermott <pjm@nac.net>2013-03-04 20:41:33 (EST)
commitb69ee811a0f3b49bef2eb26163f34e8430a24580 (patch)
treec28dcac00c52876c3d5cb1b646bf833f44da2ff0
parent4b554530020c4bef37feb02a83d640d224bbfd56 (diff)
downloadoverworld-rpg-b69ee811a0f3b49bef2eb26163f34e8430a24580.zip
overworld-rpg-b69ee811a0f3b49bef2eb26163f34e8430a24580.tar.gz
overworld-rpg-b69ee811a0f3b49bef2eb26163f34e8430a24580.tar.bz2
Support palette cycling in area layers.
-rw-r--r--src/area.c30
-rw-r--r--src/area.h3
-rw-r--r--src/main.c22
3 files changed, 18 insertions, 37 deletions
diff --git a/src/area.c b/src/area.c
index a41ff62..2e55fe9 100644
--- a/src/area.c
+++ b/src/area.c
@@ -5,12 +5,11 @@
#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, struct viewport *vp)
+area_new(struct map *map, SDL_Palette *pal)
{
struct area *a;
@@ -25,12 +24,23 @@ area_new(struct map *map, struct viewport *vp)
a->map = map;
init_map_layers(a);
- set_layers_palette(a, vp);
+ set_area_palette(a, pal);
blit_map_layers(a);
return a;
}
+void
+set_area_palette(struct area *area, SDL_Palette *pal)
+{
+ enum area_layer l;
+
+ for (l = 0; l < AREA_LAYERS_MAX; ++l) {
+ SDL_SetPalette(area->map_layers[l], SDL_LOGPAL,
+ pal->colors, 0, pal->ncolors);
+ }
+}
+
static void
init_map_layers(struct area *area)
{
@@ -59,20 +69,6 @@ init_map_layers(struct area *area)
}
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);
diff --git a/src/area.h b/src/area.h
index 3ab9aea..fae524d 100644
--- a/src/area.h
+++ b/src/area.h
@@ -16,7 +16,8 @@ struct area {
SDL_Surface *map_layers[AREA_LAYERS_MAX];
};
-struct area *area_new(struct map *map, struct viewport *vp);
+struct area *area_new(struct map *map, SDL_Palette *pal);
+void set_area_palette(struct area *area, SDL_Palette *pal);
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);
diff --git a/src/main.c b/src/main.c
index 0d75e4a..1dd376a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,24 +11,6 @@
do { \
vp->x = x + map->tilewidth / 2 - vp->w / 2; \
vp->y = y + map->tileheight / 2 - vp->h / 2; \
- /* This causes render_area_to_viewport() to use a lot more CPU \
- * time. \
- * Presumably, this is because SDL is mapping the area layers' \
- * color palettes onto the screen's palette. (But they should \
- * be equal, so color mapping shouldn't happen…) \
- * Oddly, the effect of this SDL_SetPalette() call is much \
- * greater than is that of the other one. \
- * Hopefully, cycling the palettes of the area layers should \
- * fix _everything_. */ \
- if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, \
- map->palettes[MAP_PALETTE_DAY] \
- .palette->palette->colors, \
- 0, \
- map->palettes[MAP_PALETTE_DAY] \
- .palette->palette->ncolors)) { \
- warn("Failed to set palette"); \
- } \
- render_area_to_viewport(a, vp); \
if (i % 720 < 180) { \
pal_start = map->palettes[MAP_PALETTE_MORN] \
.palette->palette; \
@@ -53,10 +35,12 @@
if (!cycle_palettes_cosine(i, 180, pal_start, pal_end, pal)) { \
warn("Failed to cycle palettes"); \
} \
+ set_area_palette(a, pal); \
if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, \
pal->colors, 0, pal->ncolors)) { \
warn("Failed to set palette"); \
} \
+ render_area_to_viewport(a, vp); \
SDL_Flip(vp->screen); \
SDL_Delay(10); \
++i; \
@@ -87,7 +71,7 @@ main(void)
0, pal->ncolors)) {
warn("Failed to set palette");
}
- a = area_new(map, vp);
+ a = area_new(map, vp->screen->format->palette);
for (e = map->map_exits_head; e != NULL; e = e->next) {
debug("Map exit (size %dx%d) at (%d,%d) "