# HG changeset patch # User John Tsiombikas # Date 1421627521 -7200 # Node ID 0baf4e98315e2cd7bf98f406f4ff560f5e258e44 # Parent ce0548d24918f2a9e014fd426fc01163ba50a21e depth cueing diff -r ce0548d24918 -r 0baf4e98315e src/rend.c --- a/src/rend.c Sun Jan 18 13:30:30 2015 +0200 +++ b/src/rend.c Mon Jan 19 02:32:01 2015 +0200 @@ -1,5 +1,6 @@ #include #include +#include #include "rend.h" #include "player.h" @@ -39,7 +40,7 @@ int i, j, dx, dy, backz, clear_start, clear_end; char cells[3][MAX_Z + 1]; struct tileset *ts = &lvl->tileset; - struct tile *tile_ceil, *tile_floor; + struct tile *tile; dx = pdir == DIR_EAST ? 1 : (pdir == DIR_WEST ? -1 : 0); dy = pdir == DIR_NORTH ? -1 : (pdir == DIR_SOUTH ? 1 : 0); @@ -57,14 +58,28 @@ } /* draw floor and ceiling */ - tile_ceil = get_tile(ts, "ceil"); - tile_floor = get_tile(ts, "floor"); + clear_start = 0; + clear_end = fb.ysz; - clear_start = tile_ceil ? tile_ceil->orig_y + tile_ceil->img.ysz : 0; - clear_end = tile_floor ? tile_floor->orig_y : fb.ysz; + for(i=0; i */ + draw_tile(tile); - draw_tile(tile_ceil); - draw_tile(tile_floor); + if(i == MAX_Z - 1) { + clear_start = tile->orig_y + tile->img.ysz; + } + } + + if((tile = get_tilef(ts, "fcs%d", i))) { /* floor-center-solid- */ + draw_tile(tile); + if(i == MAX_Z - 1) { + clear_end = tile->orig_y; + } + } + } + assert(clear_end >= clear_start); + + /* fill the area between floor an ceiling with black */ memset(fb.pixels + clear_start * fb.xsz, 0, (clear_end - clear_start) * fb.xsz); /* find where the back wall should go if it is within visual range @@ -73,21 +88,17 @@ backz = -1; for(i=1; i-- */ diff -r ce0548d24918 -r 0baf4e98315e src/tileset.c --- a/src/tileset.c Sun Jan 18 13:30:30 2015 +0200 +++ b/src/tileset.c Mon Jan 19 02:32:01 2015 +0200 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -198,7 +199,7 @@ printf("loaded tileset %s\n", fname); for(i=0; itile[i].name); + printf(" tile: %s (orig: %d,%d)\n", ts->tile[i].name, ts->tile[i].orig_x, ts->tile[i].orig_y); } return 0; @@ -240,6 +241,19 @@ return bsearch(&key, ts->tile, ts->num_tiles, sizeof *ts->tile, tilecmp); } +struct tile *get_tilef(struct tileset *ts, const char *fmt, ...) +{ + va_list ap; + int sz = strlen(fmt) * 2; + char *buf = alloca(sz + 1); + + va_start(ap, fmt); + vsnprintf(buf, sz, fmt, ap); + va_end(ap); + + return get_tile(ts, buf); +} + static struct orig_node *load_origin_list(const char *fname) { FILE *fp; diff -r ce0548d24918 -r 0baf4e98315e src/tileset.h --- a/src/tileset.h Sun Jan 18 13:30:30 2015 +0200 +++ b/src/tileset.h Mon Jan 19 02:32:01 2015 +0200 @@ -21,5 +21,6 @@ void destroy_tileset(struct tileset *ts); struct tile *get_tile(struct tileset *ts, const char *name); +struct tile *get_tilef(struct tileset *ts, const char *fmt, ...); #endif /* TILESET_H_ */ diff -r ce0548d24918 -r 0baf4e98315e utils/tileproc.c --- a/utils/tileproc.c Sun Jan 18 13:30:30 2015 +0200 +++ b/utils/tileproc.c Mon Jan 19 02:32:01 2015 +0200 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -16,16 +17,22 @@ struct palentry *next; }; +void print_usage(const char *argv0); int load_palette(const char *fname); +int save_palette(const char *fname); int proc_tile(const char *fname); float find_nearest(float r, float g, float b); struct palentry *palette; int palsize; +float colscale[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; +int scale_count = 0; +int key = -1; int main(int argc, char **argv) { int i; + const char *outpalname = 0; for(i=1; i= pairs\n"); + return 1; + } + if(idx < 0 || idx >= 10) { + fprintf(stderr, "-f expects a z value from 0 to 9\n"); + return 1; + } + colscale[idx] = (float)maxcol / 255.0; + if(idx >= scale_count) scale_count = idx + 1; + } + break; + + case 'k': + { + char *endp; + long x = strtol(argv[++i], &endp, 10); + if(endp == argv[i]) { + fprintf(stderr, "-k must be followed by a palette index\n"); + return 1; + } + key = x; + } + break; + + case 'h': + print_usage(argv[0]); + return 0; + default: fprintf(stderr, "invalid option: %s\n", argv[i]); + print_usage(argv[0]); return 1; } } else { @@ -46,9 +90,27 @@ } } } + + if(outpalname) { + if(save_palette(outpalname) == -1) { + fprintf(stderr, "failed to write extended palette: %s\n", outpalname); + return 1; + } + } + return 0; } +void print_usage(const char *argv0) +{ + printf("Usage: %s [img1 img2 img3 ... imgN]\n", argv0); + printf("Options:\n"); + printf(" -p use palette from file\n"); + printf(" -f = darken the image (max brightness 'b') based on the digit (z) in its filename\n"); + printf(" -k colorkey index (preserve this color regardless of depth cues)\n"); + printf(" -h print usage and exit\n"); +} + int load_palette(const char *fname) { FILE *fp; @@ -133,6 +195,40 @@ return -1; } +int save_palette(const char *fname) +{ + FILE *fp; + int i, j; + int extsize = palsize * scale_count; + + printf("saving extended palette: %s\n", fname); + + if(!(fp = fopen(fname, "w"))) { + fprintf(stderr, "failed to save extended palette: %s: %s\n", fname, strerror(errno)); + return -1; + } + + if(extsize > 256) { + fprintf(stderr, "warning: extended palette size too large (%d)\n", extsize); + } + + for(i=0; i 255) r = 255; + if(g > 255) g = 255; + if(b > 255) b = 255; + + fprintf(fp, "#%02x%02x%02x\n", r, g, b); + } + } + fclose(fp); + return 0; +} + int proc_tile(const char *fname) { int i; @@ -141,6 +237,7 @@ char *outfname, *cptr; FILE *fp; const char *magic = "TILEIMAG"; + int zidx = -1; outfname = alloca(strlen(fname) + 4); strcpy(outfname, fname); @@ -149,6 +246,12 @@ } strcat(outfname, ".til"); + cptr = outfname + strlen(outfname) - 1; + while(cptr >= outfname && !isdigit(*cptr)) --cptr; + if(cptr >= outfname) { + zidx = *cptr - '0'; + } + printf("processing tile: %s -> %s\n", fname, outfname); if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) { @@ -168,6 +271,12 @@ pptr = pixels; for(i=0; i 0 && idx != key) { + /* shift the indices to the appropriate copy of the palette */ + idx += zidx * palsize; + } + fputc(idx, fp); pptr += 3; }