#include #include "init.h" #include "logging.h" #include "resources/image.h" #include "resources/map.h" #include "viewport.h" #include "area.h" #include "palettes.h" #define DEMO() \ do { \ vp->x = x + map->tilewidth / 2 - vp->w / 2; \ vp->y = y + map->tileheight / 2 - vp->h / 2; \ 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"); \ } \ 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; \ } while (0) int main(void) { struct viewport *vp; struct map *map; struct area *a; SDL_Palette *pal; int i; struct map_exit *e; init(); vp = init_viewport(240, 160, 8); map = map_get(MAPSDIR "/forest1-8bit.tmx"); if (map == NULL) { map = map_get("data/maps/forest1-8bit.tmx"); } if (map == NULL) { err(1, "Where's the map, George?"); } 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"); } 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) " "to map %s (size %dx%d) at (%d,%d)", e->width, e->height, e->x, e->y, e->target_map_name, e->target_map->width, e->target_map->height, e->target_x_coord, e->target_y_coord); } /* Demo */ { Uint32 start, end; int x, y; SDL_Palette *pal_start, *pal_end; pal = malloc(sizeof(*pal)); pal->colors = calloc(59, sizeof(*pal->colors)); pal->ncolors = 59; i = 0; start = SDL_GetTicks(); x = 19 * map->tilewidth ; y = 38 * map->tileheight; 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); } quit(0); /* Control doesn't actually reach here. */ return 0; }