summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c166
1 files changed, 60 insertions, 106 deletions
diff --git a/src/main.c b/src/main.c
index abfbf8d..0d75e4a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -11,7 +11,52 @@
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; \
+ pal_end = map->palettes[MAP_PALETTE_DAY] \
+ .palette->palette; \
+ } else if (i % 720 < 360) { \
+ pal_start = map->palettes[MAP_PALETTE_DAY] \
+ .palette->palette; \
+ pal_end = map->palettes[MAP_PALETTE_EVE] \
+ .palette->palette; \
+ } else if (i % 720 < 540) { \
+ pal_start = map->palettes[MAP_PALETTE_EVE] \
+ .palette->palette; \
+ pal_end = map->palettes[MAP_PALETTE_NIGHT] \
+ .palette->palette; \
+ } else { \
+ pal_start = map->palettes[MAP_PALETTE_NIGHT] \
+ .palette->palette; \
+ pal_end = map->palettes[MAP_PALETTE_MORN] \
+ .palette->palette; \
+ } \
+ if (!cycle_palettes_cosine(i, 180, pal_start, pal_end, pal)) { \
+ warn("Failed to cycle palettes"); \
+ } \
+ if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, \
+ pal->colors, 0, pal->ncolors)) { \
+ warn("Failed to set palette"); \
+ } \
SDL_Flip(vp->screen); \
SDL_Delay(10); \
++i; \
@@ -54,122 +99,31 @@ main(void)
e->target_x_coord, e->target_y_coord);
}
- render_area_to_viewport(a, vp);
+ /* Demo */
{
- Uint32 d, t;
+ Uint32 start, end;
+ int x, y;
+ SDL_Palette *pal_start, *pal_end;
pal = malloc(sizeof(*pal));
pal->colors = calloc(58, sizeof(*pal->colors));
pal->ncolors = 58;
- for (d = 0; d < 4; ++d) {
- t = 0;
- debug("Day %d morn", d);
- /* morn -> day */
- for (; t < 360; t += 1) {
- if (cycle_palettes_cosine(t, 360,
- map->palettes[MAP_PALETTE_MORN]
- .palette->palette,
- map->palettes[MAP_PALETTE_DAY]
- .palette->palette,
- pal) == NULL) {
- warn("Failed to cycle palettes");
- }
- if (!SDL_SetPalette(vp->screen, SDL_LOGPAL,
- pal->colors,
- 0, pal->ncolors)) {
- warn("Failed to set palette");
- }
- SDL_Flip(vp->screen);
- SDL_Delay(10);
- }
- debug("Day %d day", d);
- /* day -> eve */
- for (; t < 720; t += 1) {
- if (cycle_palettes_cosine(t, 360,
- map->palettes[MAP_PALETTE_DAY]
- .palette->palette,
- map->palettes[MAP_PALETTE_EVE]
- .palette->palette,
- pal) == NULL) {
- warn("Failed to cycle palettes");
- }
- if (!SDL_SetPalette(vp->screen, SDL_LOGPAL,
- pal->colors,
- 0, pal->ncolors)) {
- warn("Failed to set palette");
- }
- SDL_Flip(vp->screen);
- SDL_Delay(10);
- }
- debug("Day %d eve", d);
- /* eve -> night */
- for (; t < 1080; t += 1) {
- if (cycle_palettes_cosine(t, 360,
- map->palettes[MAP_PALETTE_EVE]
- .palette->palette,
- map->palettes[MAP_PALETTE_NIGHT]
- .palette->palette,
- pal) == NULL) {
- warn("Failed to cycle palettes");
- }
- if (!SDL_SetPalette(vp->screen, SDL_LOGPAL,
- pal->colors,
- 0, pal->ncolors)) {
- warn("Failed to set palette");
- }
- SDL_Flip(vp->screen);
- SDL_Delay(10);
- }
- debug("Day %d night", d);
- /* night -> morn */
- for (; t < 1440; t += 1) {
- if (cycle_palettes_cosine(t, 360,
- map->palettes[MAP_PALETTE_NIGHT]
- .palette->palette,
- map->palettes[MAP_PALETTE_MORN]
- .palette->palette,
- pal) == NULL) {
- warn("Failed to cycle palettes");
- }
- if (!SDL_SetPalette(vp->screen, SDL_LOGPAL,
- pal->colors,
- 0, pal->ncolors)) {
- warn("Failed to set palette");
- }
- SDL_Flip(vp->screen);
- SDL_Delay(10);
- }
- }
- }
- quit(0);
-
- /* Demo */
- pal = map->palettes[MAP_PALETTE_DAY].palette->palette;
- if (!SDL_SetPalette(vp->screen, SDL_LOGPAL, pal->colors,
- 0, pal->ncolors)) {
- warn("Failed to set palette");
- }
-
- {
- Uint32 start, end;
- int x, y;
-
i = 0;
start = SDL_GetTicks();
x = 19 * map->tilewidth ;
y = 38 * map->tileheight;
- for (; y > 34 * map->tileheight; y -= 2) DEMO(); /* Up */
- for (; x < 23 * map->tilewidth ; x += 2) DEMO(); /* Right */
- for (; y > 16 * map->tileheight; y -= 2) DEMO(); /* Up */
- for (; x > 15 * map->tilewidth ; x -= 2) DEMO(); /* Left */
- for (; y < 25 * map->tileheight; y += 2) DEMO(); /* Down */
- for (; x > 4 * map->tilewidth ; x -= 2) DEMO(); /* Left */
- for (; y > 18 * map->tileheight; y -= 2) DEMO(); /* Up */
- for (; x < 9 * map->tilewidth ; x += 2) DEMO(); /* Right */
- for (; y > 5 * map->tileheight; y -= 2) DEMO(); /* Up */
- for (; x < 15 * map->tilewidth ; x += 2) DEMO(); /* Right */
- for (; y > 1 * map->tileheight; y -= 2) DEMO(); /* Up */
+ for (; y > 34 * map->tileheight; y -= 1) DEMO(); /* Up */
+ for (; x < 23 * map->tilewidth ; x += 1) DEMO(); /* Right */
+ for (; y > 16 * map->tileheight; y -= 1) DEMO(); /* Up */
+ for (; x > 15 * map->tilewidth ; x -= 1) DEMO(); /* Left */
+ for (; y < 25 * map->tileheight; y += 1) DEMO(); /* Down */
+ for (; x > 4 * map->tilewidth ; x -= 1) DEMO(); /* Left */
+ for (; y > 18 * map->tileheight; y -= 1) DEMO(); /* Up */
+ for (; x < 9 * map->tilewidth ; x += 1) DEMO(); /* Right */
+ for (; y > 5 * map->tileheight; y -= 1) DEMO(); /* Up */
+ for (; x < 15 * map->tilewidth ; x += 1) DEMO(); /* Right */
+ for (; y > 1 * map->tileheight; y -= 1) DEMO(); /* Up */
end = SDL_GetTicks();
debug("Rendered %d frames in %d milliseconds", i, end - start);
}