From: sparky4 Date: Mon, 12 Dec 2016 15:35:22 +0000 (-0600) Subject: merged mapread files w X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=66631d5409667cc804fe7e8622342e9b7d5436b5;p=16.git merged mapread files w --- diff --git a/src/lib/mapread.c b/16/src/lib/mapread.c similarity index 100% rename from src/lib/mapread.c rename to 16/src/lib/mapread.c diff --git a/src/lib/mapread.h b/16/src/lib/mapread.h similarity index 100% rename from src/lib/mapread.h rename to 16/src/lib/mapread.h diff --git a/makefile b/makefile index 282b01ef..7e80e902 100755 --- a/makefile +++ b/makefile @@ -106,10 +106,10 @@ LIBFLAGS=$(WLIBQ) -b -n # objects # VGMSNDOBJ = vgmSnd.$(OBJ) 16_snd.$(OBJ) -OLDLIBOBJS=bitmap.$(OBJ) mapread.$(OBJ) 16render.$(OBJ) +OLDLIBOBJS=bitmap.$(OBJ) 16render.$(OBJ) GFXLIBOBJS = 16_vl.$(OBJ) 16text.$(OBJ) bakapee.$(OBJ) 16_scr.$(OBJ) 16_vrs.$(OBJ) 16_sprit.$(OBJ) $(OLDLIBOBJS) -16LIBOBJS = 16_mm.$(OBJ) 16_pm.$(OBJ) 16_ca.$(OBJ) 16_tail.$(OBJ) 16_in.$(OBJ) 16_head.$(OBJ) 16_dbg.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) wcpu.$(OBJ) 16_timer.$(OBJ) jsmn.$(OBJ) -#16planar.$(OBJ) planar.$(OBJ) +16LIBOBJS = 16_mm.$(OBJ) 16_pm.$(OBJ) 16_ca.$(OBJ) 16_tail.$(OBJ) 16_in.$(OBJ) 16_head.$(OBJ) 16_dbg.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) wcpu.$(OBJ) 16_timer.$(OBJ) jsmn.$(OBJ) 16_map.$(OBJ) +#16planar.$(OBJ) planar.$(OBJ) mapread.$(OBJ) DOSLIBOBJ = adlib.$(OBJ) 8254.$(OBJ) 8259.$(OBJ) dos.$(OBJ) cpu.$(OBJ) !ifeq DEBUGSERIAL 1 DOSLIBOBJ += 8250.$(OBJ) diff --git a/src/lib/16_map.c b/src/lib/16_map.c index 1afb7bc8..db65158d 100755 --- a/src/lib/16_map.c +++ b/src/lib/16_map.c @@ -32,6 +32,220 @@ int jsoneq(const char *json, jsmntok_t *tok, const char *s) { return -1; } +//this function is quite messy ^^; sorry! it is a quick and dirty fix~ +word dump(const char *js, jsmntok_t *t, size_t count, word indent, char *js_sv, map_t *map, dword q) { + dword i; + word j;//, k; + bitmap_t bp; + #ifdef DEBUG_JS + if(indent==0) + { + fprintf(stdout, "%s\n", js); + fprintf(stdout, "\n"); + } + #endif + #ifdef DEBUG_DUMPVARS + fprintf(stdout, "t->size=[%d] ", t->size); + fprintf(stdout, "q=[%d] ", q); + fprintf(stdout, "indent= [%d] ", indent); + fprintf(stdout, "js_sv= [%s]\n", js_sv); + #endif + if (count == 0) { + return 0; + } + /* We may want to do strtol() here to get numeric value */ +//0000fprintf(stderr, "t->type=%d\n", t->type); + if (t->type == JSMN_PRIMITIVE) { + if(strstr(js_sv, "data")) + { + /* + here we should recursivly call dump again here to skip over the array until we get the facking width of the map. + so we can initiate the map which allocates the facking map->tiles->data->data properly and THEN we can return + here to read the data.... That is my design for this... wwww + + FUCK well i am stuck.... wwww + */ + map->data[q] = (byte)atoi(js+t->start); + #ifdef DEBUG_MAPDATA + fprintf(stdout, "%d[%d]", q, map->data[q]); + #endif + } + else + if(strstr(js_sv, "height")) + { + map->height = atoi(js+t->start); + #ifdef DEBUG_MAPVAR + fprintf(stdout, "indent= [%d] ", indent); + fprintf(stdout, "h:[%d]\n", map->height); + #endif + }else if(strstr(js_sv, "width")) + { + map->width = atoi(js+t->start); + #ifdef DEBUG_MAPVAR + fprintf(stdout, "indent= [%d] ", indent); + fprintf(stdout, "w:[%d]\n", map->width); + #endif + } + return 1; + /* We may use strndup() to fetch string value */ + } else if (t->type == JSMN_STRING) { + if(jsoneq(js, t, "data") == 0) + { +// fprintf(stdout, "[[[[%d|%d]]]]\n", &(t+1)->size, (t+1)->size); +// fprintf(stdout, "\n%.*s[xx[%d|%d]xx]\n", (t+1)->end - (t+1)->start, js+(t+1)->start, &(t+1)->size, (t+1)->size); + map->data = malloc(sizeof(byte) * (t+1)->size); + map->tiles = malloc(sizeof(tiles_t)); + map->tiles->btdata = malloc(sizeof(bitmap_t)); + //fix this to be far~ +//0000 bp = bitmapLoadPcx("data/ed.pcx"); +// bp = bitmapLoadPcx("data/koishi^^.pcx"); + map->tiles->btdata = &bp; +//---- map->tiles->data = planar_buf_from_bitmap(&bp); + //map->tiles->data->data = malloc((16/**2*/)*16); + //map->tiles->data->width = (16/**2*/); + //map->tiles->data->height= 16; + map->tiles->tileHeight = 16; + map->tiles->tileWidth = 16; + map->tiles->rows = 1; + map->tiles->cols = 1; + map->tiles->debug_text=false; + strcpy(js_sv, "data");//strdup(js+t->start);//, t->end - t->start); + } + else + if (jsoneq(js, t, "height") == 0 && indent<=1) + { + strcpy(js_sv, "height");//strdup(js+t->start);//, t->end - t->start); + }else + if(jsoneq(js, t, "width") == 0 && indent<=1) + { + strcpy(js_sv, "width");//strdup(js+t->start);//, t->end - t->start); + }else strcpy(js_sv, "\0"); + return 1; + } else if (t->type == JSMN_OBJECT) { + //fprintf(stdout, "\n"); + j = 0; + for (i = 0; i < t->size; i++) { + //for (k = 0; k < indent; k++) fprintf(stdout, "\t"); + j += dump(js, t+1+j, count-j, indent+1, js_sv, map, i); + //fprintf(stdout, ": "); + j += dump(js, t+1+j, count-j, indent+1, js_sv, map, i); + //fprintf(stdout, "\n"); + } + return j+1; + } else if (t->type == JSMN_ARRAY) { + j = 0; + //fprintf(stdout, "==\n"); + for (i = 0; i < t->size; i++) { + //for (k = 0; k < indent-1; k++) fprintf(stdout, "\t"); + //fprintf(stdout, "\t-"); + j += dump(js, t+1+j, count-j, indent+1, js_sv, map, i); + //fprintf(stdout, "==\n"); + } + return j+1; + } + return 0; +} + +int loadmap(char *mn, map_t *map) +{ + int r; + static word incr=0; + int eof_expected = 0; + char *js = NULL; + size_t jslen = 0; + char buf[BUFSIZ]; + static char js_ss[16]; + + jsmn_parser p; + jsmntok_t *tok; + size_t tokcount = 2; + + FILE *fh = fopen(mn, "r"); + + /* Prepare parser */ + jsmn_init(&p); + + /* Allocate some tokens as a start */ +//0000fprintf(stderr, "tok malloc\n"); + tok = malloc(sizeof(*tok) * tokcount); + if (tok == NULL) { + fprintf(stderr, "malloc(): errno=%d\n", errno); + return 3; + } + + for (;;) { + /* Read another chunk */ +//0000fprintf(stderr, "read\n"); + r = fread(buf, 1, sizeof(buf), fh); + if (r < 0) { + fprintf(stderr, "fread(): %d, errno=%d\n", r, errno); + return 1; + } + if (r == 0) { + if (eof_expected != 0) { + return 0; + } else { + fprintf(stderr, "fread(): unexpected EOF\n"); + return 2; + } + } +//0000fprintf(stdout, "r= [%d] BUFSIZ=%d\n", r, BUFSIZ); +//0000fprintf(stderr, "js alloc~\n"); + js = realloc(js, jslen + r + 1); + if (js == NULL) { + fprintf(stderr, "*js=%Fp\n", *js); + fprintf(stderr, "realloc(): errno = %d\n", errno); + return 3; + } + strncpy(js + jslen, buf, r); + jslen = jslen + r; + +again: +//0000fprintf(stdout, " parse~ tok=%zu jslen=%zu r=%d _memavl()=%u BUFSIZ=%d~\n", tokcount, jslen, r, _memavl(), BUFSIZ); +//0000fprintf(stdout, "p=[%u] [%u] [%d]\n", p.pos, p.toknext, p.toksuper); +/* + I think it crashes on the line below when it tries to parse the data of huge maps... wwww this is a jsmn problem wwww +*/ + r = jsmn_parse(&p, js, jslen, tok, tokcount); +//0000fprintf(stdout, "r= [%d]\n", r); + if (r < 0) { + if (r == JSMN_ERROR_NOMEM) { + tokcount = tokcount * 2; +//0000fprintf(stderr, "tok realloc~ %zu\n", tokcount); + tok = realloc(tok, sizeof(*tok) * tokcount); + if (tok == NULL) { + fprintf(stderr, "realloc(): errno=%d\n", errno); + return 3; + } + goto again; + } + } else { + //printf("js=%Fp\n", (js)); + //printf("*js=%Fp\n", (*(js))); + //printf("&*js=%s\n", &(*(js))); + //printf("&buf=[%Fp]\n", &buf); + //printf("&buf_seg=[%x]\n", FP_SEG(&buf)); + //printf("&buf_off=[%x]\n", FP_OFF(&buf)); + //printf("&buf_fp=[%Fp]\n", MK_FP(FP_SEG(&buf), FP_OFF(&buf))); + //printf("buf=[\n%s\n]\n", buf); + //printf("buff=[%Fp]\n", buff); + //printf("(*buff)=[%Fp]\n", (*buff)); + //printf("&(*buff)=[\n%s\n]\n", &(*buff)); + #ifdef DEBUG_DUMPVARS + fprintf(stdout, "running dump~\n"); + #endif + dump(js, tok, p.toknext, incr, &js_ss, map, 0); + eof_expected = 1; + } + } + + //free(js); + //free(tok); + //fclose(fh); + + return 0; +} + void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { int i, j, k, indent=0, inner_end; bitmap_t bp; @@ -40,7 +254,7 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { while(idata = malloc(sizeof(byte*) * t[i].size); + map->layerdata = malloc(sizeof(byte*) * t[i].size); inner_end = t[i].end; k = 0; while(t[i].start < inner_end) { @@ -49,11 +263,11 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { #ifdef DEBUG_MAPVAR printf("Layer %d data: [", k); #endif - map->data[k] = malloc(sizeof(byte) * t[i+1].size); + map->layerdata[k] = malloc(sizeof(byte) * t[i+1].size); for(j = 0; j < t[i+1].size; j++) { - map->data[k][j] = (byte)atoi(js + t[i+2+j].start); + map->layerdata[k][j] = (byte)atoi(js + t[i+2+j].start); #ifdef DEBUG_MAPVAR - printf("%d, ", map->data[k][j]); + printf("%d, ", map->layerdata[k][j]); #endif } i += j + 2; @@ -75,17 +289,17 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { while(t[i].start < inner_end) { if(jsoneq(js, &(t[i]), "image") == 0) { //fix this to be far~ - map->tiles[k] = malloc(sizeof(tiles_t)); - map->tiles[k]->btdata = malloc(sizeof(bitmap_t)); - map->tiles[k]->tileHeight = 16; - map->tiles[k]->tileWidth = 16; - map->tiles[k]->rows = 1; - map->tiles[k]->cols = 1; - map->tiles[k]->debug_text=false; + map->layertile[k] = malloc(sizeof(tiles_t)); + map->layertile[k]->btdata = malloc(sizeof(bitmap_t)); + map->layertile[k]->tileHeight = 16; + map->layertile[k]->tileWidth = 16; + map->layertile[k]->rows = 1; + map->layertile[k]->cols = 1; + map->layertile[k]->debug_text=false; //Fix to load tileset specified. //And move to vrs, probably //bp = bitmapLoadPcx("data/ed.pcx"); - map->tiles[k]->btdata = &bp; + map->layertile[k]->btdata = &bp; k++; } i++; @@ -110,7 +324,7 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { } } -int loadmap(char *mn, map_t *map) { +int newloadmap(char *mn, map_t *map) { char *js; jsmn_parser p; diff --git a/src/lib/16_map.h b/src/lib/16_map.h index bac162c9..512a81af 100755 --- a/src/lib/16_map.h +++ b/src/lib/16_map.h @@ -31,14 +31,17 @@ #include "src/lib/16_ca.h" #include "src/lib/16_mm.h" +//#define DEBUG_MAPDATA +//#define DEBUG_MAPVAR +//#define DEBUG_DUMPVARS +//#define DEBUG_JS + //TODO: 16_mm and 16_ca must handle this typedef struct { bitmap_t huge *btdata; //old planar_buf_t huge *data; //old - word tileHeight; - word tileWidth; - unsigned int rows; - unsigned int cols; + word tileHeight, tileWidth; + unsigned int rows, cols; #ifdef __DEBUG__ boolean debug_text; //show the value of the tile! wwww byte *debug_data; @@ -50,12 +53,17 @@ typedef struct { typedef struct { //long planestart[3]; //unsigned planelength[3]; - byte * huge *data; //TODO: 16_mm and 16_ca must handle this - tiles_t **tiles; //TODO: 16_mm and 16_ca must handle this - unsigned int width, height; //this has to be positive + byte *data; //TODO: 16_mm and 16_ca must handle this + byte * huge *layerdata; //TODO: 16_mm and 16_ca must handle this + tiles_t *tiles; //TODO: 16_mm and 16_ca must handle this + tiles_t * huge *layertile; //TODO: 16_mm and 16_ca must handle this + int width, height; //this has to be signed! char name[16]; } map_t; +int jsoneq(const char *json, jsmntok_t *tok, const char *s); +word dump(const char *js, jsmntok_t *t, size_t count, word indent, char *js_sv, map_t *map, dword q); int loadmap(char *mn, map_t *map); +int newloadmap(char *mn, map_t *map); -#endif/*_LIBMAPREAD_H_*/ +#endif/*_16_LIB__H_*/ diff --git a/src/lib/16_scr.h b/src/lib/16_scr.h index 38c72637..9dc7b4a5 100755 --- a/src/lib/16_scr.h +++ b/src/lib/16_scr.h @@ -29,7 +29,7 @@ #include "src/lib/16_vl.h" #include "src/lib/16_in.h" #include "src/lib/bitmap.h" -#include "src/lib/mapread.h" //map is loaded here www +#include "src/lib/16_map.h" //map is loaded here www #include "src/lib/16render.h" //#include "src/lib/16_map.h" //new map stuff #include "src/lib/16_timer.h" diff --git a/src/scroll.c b/src/scroll.c index 4b65b553..41251258 100755 --- a/src/scroll.c +++ b/src/scroll.c @@ -23,7 +23,6 @@ #include "src/lib/16_scr.h" #include "src/lib/16_timer.h" #include "src/lib/wcpu/wcpu.h" -#include "src/lib/mapread.h" #include "src/lib/16_dbg.h" //#define FADE