# HG changeset patch # User John Tsiombikas # Date 1421512648 -7200 # Node ID 465ca72c9657a77f1faae6a4db84f765e8c762ca initial commit diff -r 000000000000 -r 465ca72c9657 .hgignore --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sat Jan 17 18:37:28 2015 +0200 @@ -0,0 +1,7 @@ +\.o$ +\.d$ +\.swp$ +^orig_data/ +^data/ +^eobish$ +^utils/tileproc$ diff -r 000000000000 -r 465ca72c9657 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sat Jan 17 18:37:28 2015 +0200 @@ -0,0 +1,19 @@ +csrc = $(wildcard src/*.c) +ccsrc = $(wildcard src/*.cc) +obj = $(csrc:.c=.o) $(ccsrc:.cc=.o) +bin = eobish + +CFLAGS = -pedantic -Wall -g `pkg-config --cflags sdl` +CXXFLAGS = $(CFLAGS) +LDFLAGS = `pkg-config --libs sdl` + +$(bin): $(obj) + $(CXX) -o $@ $(obj) $(LDFLAGS) + +.PHONY: clean +clean: + rm -f $(obj) $(bin) + +.PHONY: data +data: + $(MAKE) -C orig_data diff -r 000000000000 -r 465ca72c9657 doc/palette_allocation --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/palette_allocation Sat Jan 17 18:37:28 2015 +0200 @@ -0,0 +1,9 @@ +Palette allocation (32 color blocks) +------------------------------------ + 0 - 31 : UI + 32 - 63 : enemies dark + 64 - 95 : enemies light (original) + 96 - 159: effects +160 - 191: dungeon dark +192 - 223: dungeon mid +224 - 255: dungeon light (original) diff -r 000000000000 -r 465ca72c9657 src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main.cc Sat Jan 17 18:37:28 2015 +0200 @@ -0,0 +1,81 @@ +#include +#include + +static void display(); +static bool proc_event(SDL_Event *ev); +static void set_pal_entry(int idx, int r, int g, int b); + +static SDL_Surface *fbsurf; + +int main(int argc, char **argv) +{ + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); + + if(!(fbsurf = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE))) { + fprintf(stderr, "failed to set video mode\n"); + return 1; + } + set_pal_entry(1, 255, 0, 0); + + for(;;) { + SDL_Event ev; + while(SDL_PollEvent(&ev)) { + if(!proc_event(&ev)) { + goto done; + } + } + + display(); + } + +done: + SDL_Quit(); + return 0; +} + +void display() +{ + if(SDL_MUSTLOCK(fbsurf)) { + SDL_LockSurface(fbsurf); + } + + unsigned char *pixels = (unsigned char*)fbsurf->pixels; + for(int i=0; iw * fbsurf->h; i++) { + *pixels++ = 1; + } + + if(SDL_MUSTLOCK(fbsurf)) { + SDL_UnlockSurface(fbsurf); + } + + SDL_Flip(fbsurf); +} + +static bool proc_event(SDL_Event *ev) +{ + switch(ev->type) { + case SDL_KEYDOWN: + if(ev->key.keysym.sym == SDLK_ESCAPE) { + return false; + } + break; + + default: + break; + } + return true; +} + +static void set_pal_entry(int idx, int r, int g, int b) +{ + SDL_Color col; + col.r = r; + col.g = g; + col.b = b; + + SDL_SetPalette(fbsurf, SDL_LOGPAL | SDL_PHYSPAL, &col, idx, 1); + + /*palette[idx].r = r; + palette[idx].g = g; + palette[idx].b = b;*/ +} diff -r 000000000000 -r 465ca72c9657 utils/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/Makefile Sat Jan 17 18:37:28 2015 +0200 @@ -0,0 +1,8 @@ +CFLAGS = -pedantic -Wall -g + +tileproc: tileproc.o + $(CC) -o $@ $< -limago + +.PHONY: clean +clean: + rm -f *.o diff -r 000000000000 -r 465ca72c9657 utils/tileproc.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/tileproc.c Sat Jan 17 18:37:28 2015 +0200 @@ -0,0 +1,196 @@ +#include +#include +#include +#include +#include +#include +#ifndef WIN32 +#include +#else +#include +#endif +#include + +struct palentry { + float r, g, b; + struct palentry *next; +}; + +int load_palette(const char *fname); +int proc_tile(const char *fname); +float find_nearest(float r, float g, float b); + +struct palentry *palette; +int palsize; + +int main(int argc, char **argv) +{ + int i; + + for(i=1; i> 16) & 0xff; + g = (val >> 8) & 0xff; + b = val & 0xff; + } else { + fprintf(stderr, "unrecognized line \"%s\" in palette file: %s\n", line, fname); + goto fail; + } + + if(!(pent = malloc(sizeof *pent))) { + perror("failed to allocate palette entry"); + goto fail; + } + pent->r = (float)r / 255.0; + pent->g = (float)g / 255.0; + pent->b = (float)b / 255.0; + pent->next = 0; + + if(head) { + tail->next = pent; + tail = pent; + } else { + head = tail = pent; + } + nent++; + } + + /* flatten */ + if(!(newpal = malloc(nent * sizeof *newpal))) { + fprintf(stderr, "failed to allocate %d palette entries: %s\n", nent, strerror(errno)); + goto fail; + } + palette = newpal; + palsize = nent; + + while(head) { + struct palentry *ent = head; + head = head->next; + + *newpal++ = *ent; + free(ent); + } + + printf("loaded palette: %s (%d colors)\n", fname, nent); + + fclose(fp); + return 0; + +fail: + fclose(fp); + while(head) { + void *tmp = head; + head = head->next; + free(tmp); + } + return -1; +} + +int proc_tile(const char *fname) +{ + int i; + int xsz, ysz; + unsigned char *pixels, *pptr; + char *outfname, *cptr; + FILE *fp; + const char *magic = "TILEIMAG"; + + outfname = alloca(strlen(fname) + 4); + strcpy(outfname, fname); + if((cptr = strrchr(outfname, '.'))) { + *cptr = 0; + } + strcat(outfname, ".til"); + + printf("processing tile: %s -> %s\n", fname, outfname); + + if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) { + fprintf(stderr, "failed to load source tile image: %s\n", fname); + return -1; + } + if(!(fp = fopen(outfname, "wb"))) { + fprintf(stderr, "failed to open output tile image for writing: %s: %s\n", outfname, strerror(errno)); + img_free_pixels(pixels); + return -1; + } + /* write header */ + fwrite(magic, 1, 8, fp); + fwrite(&xsz, sizeof xsz, 1, fp); + fwrite(&ysz, sizeof ysz, 1, fp); + + pptr = pixels; + for(i=0; i