]> 4ch.mooo.com Git - 16.git/commitdiff
polished the map reading system~ i made it ... more robust.... now onwards to far...
authorsparky4 <sparky4@cock.li>
Tue, 26 May 2015 17:31:38 +0000 (12:31 -0500)
committersparky4 <sparky4@cock.li>
Tue, 26 May 2015 17:31:38 +0000 (12:31 -0500)
modified:   0.bat
modified:   makefile
modified:   maptest.exe
modified:   pcxtest.exe
modified:   scroll.exe
modified:   src/lib/mapread.c
modified:   src/lib/mapread.h
modified:   src/maptest.c
modified:   test.exe
modified:   test2.exe

0.bat
makefile
maptest.exe
pcxtest.exe
scroll.exe
src/lib/mapread.c
src/lib/mapread.h
src/maptest.c
test.exe
test2.exe

diff --git a/0.bat b/0.bat
index 24cb25c93b82078d93cfb037f0f7f27db2fc2dd1..067a93aaba8340b9f690bb0c6aa562509f3efb35 100644 (file)
--- a/0.bat
+++ b/0.bat
@@ -1 +1,3 @@
-wmake\ 2scroll.exe > ..\w\r
+wmake clean\r
+@rem wmake\ 2scroll.exe > scroll.out\r
+wmake maptest.exe\ 2maptest.exe > maptest.out\r
index 6f049e2062476dad338c95e79a7a9ef7ac2ac28c..ea954ebc854f39980968dd7723bd8d17cfab5984 100644 (file)
--- a/makefile
+++ b/makefile
@@ -2,8 +2,10 @@
 #-zk0 = kanji support~
 #-zkl = current codepage
 
-OFLAGS=-ot -ox -ob -oh# -or -om -ol -ol+
-FLAGS=-0 -d2 -wo $(OFLAGS) -zkl -zm# -mh# -zdp# -zm# -zp16 -zq
+CFLAGS=-zkl# -zm# -mh# -wo -x# -zdp# -zp16 -zq
+OFLAGS=-ot -ox -ob -oh -or# -om -ol -ol+
+FLAGS=-0 -d2 $(OFLAGS) $(CFLAGS)
+REMOVECOMMAND=del
 DIRSEP=\
 SRC=src$(DIRSEP)\r
 SRCLIB=$(SRC)lib$(DIRSEP)
@@ -63,5 +65,11 @@ jsmn.obj: $(JSMNLIB)jsmn.h $(JSMNLIB)jsmn.c
        wcl $(FLAGS) -c $(JSMNLIB)jsmn.c
 
 clean: .symbolic\r
-       @del *.obj\r
-#      @del *.exe\r
+       @$(REMOVECOMMAND) *.obj
+       @$(REMOVECOMMAND) *.OBJ
+       @$(REMOVECOMMAND) *.out
+       @$(REMOVECOMMAND) *.OUT
+       @$(REMOVECOMMAND) makefi~1
+       @$(REMOVECOMMAND) __WCL__.LNK\r
+       @$(REMOVECOMMAND) *.smp
+       @$(REMOVECOMMAND) *.SMP\r
index 4b25c028ac8b78d2d661b5769962a3fe6bf09187..c140654720855fe57f9945bda55b5dcb64e9d979 100644 (file)
Binary files a/maptest.exe and b/maptest.exe differ
index 6378e10c91abea7f512c6d6a808754173389fbbe..3f18a9304b84fbc9cb582e808eda32d84678873c 100644 (file)
Binary files a/pcxtest.exe and b/pcxtest.exe differ
index b7545fb147155273a2b631c3e2ba4ef423398a4d..d1dae04c537bd04f0e02ba0ed20032ec18b0ca3a 100644 (file)
Binary files a/scroll.exe and b/scroll.exe differ
index 8f84071a6cf11411ae4b0a95ac2d96c54db34aee..aa9761ec623d25ce7c35cd46604c96eef6dc4ddb 100644 (file)
@@ -1,6 +1,6 @@
 #include "src/lib/mapread.h"
 
-static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
+int jsoneq(const char /*far*/ *json, jsmntok_t /*far*/ *tok, const char *s) {
        if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start &&
                        strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
                return 0;
@@ -9,15 +9,26 @@ static int jsoneq(const char *json, jsmntok_t *tok, const char *s) {
 }
 
 //this function is quite messy ^^; sorry! it is a quick and dirty fix~
-static int dump(const char *js, jsmntok_t *t, size_t count, int indent, /*char *js_sv,*/ map_t *map, int q) {
+int dump(const char /*far*/ *js, jsmntok_t /*far*/ *t, size_t count, int indent, char *js_sv, map_t *map, int q) {
        int i, 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, "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 */
        if (t->type == JSMN_PRIMITIVE) {
-               if(js_sv == "data")
+               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.
@@ -26,29 +37,39 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent, /*char *
 
                                FUCK well i am stuck.... wwww
                        */
-                       map->data[q] = (byte)strtol(js+t->start, (char **)t->end, 10);
-//                     printf("%d[%d]", q, map->data[q]);
+//----                 map->data[q] = (byte)strtol(js+t->start, (char **)t->end, 10);
+                       map->data[q] = (byte)atoi(js+t->start);
+                       #ifdef DEBUG_MAPDATA
+                               fprintf(stdout, "%d[%d]", q, map->data[q]);
+                       #endif
                }
                else
-               if(js_sv == "height")
+               if(strstr(js_sv, "height"))
                {
-                       //map->height = (int)malloc(sizeof(int));
-                       map->height = (int)strtol(js+t->start, (char **)js+t->end, 10);
-                       //printf("h:[%d]\n", map->height);
-               }else if(js_sv == "width")
+//----                 map->height = (unsigned int)strtol(js+t->start, (char **)js+t->end, 10);
+                       map->height = (unsigned int)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 = (int)strtol(js+t->start, (char **)js+t->end, 10);
-//                     printf("w:[%d]\n", map->width);
+//----                 map->width = (unsigned int)strtol(js+t->start, (char **)js+t->end, 10);
+                       map->width = (unsigned int)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 )
+               if(jsoneq(js, t, "data") == 0)
                {
-//                     printf("[[[[%d|%d]]]]\n", &(t+1)->size, (t+1)->size);
-//                     printf("\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));
+//                     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 = /*_f*/malloc(sizeof(byte) * (t+1)->size);
+                       map->tiles = /*_f*/malloc(sizeof(tiles_t));
                        //map->tiles->data = malloc(sizeof(bitmap_t));
                        //fix this
                        bp = bitmapLoadPcx("data/ed.pcx");
@@ -60,52 +81,54 @@ static int dump(const char *js, jsmntok_t *t, size_t count, int indent, /*char *
                        map->tiles->tileWidth = 16;\r
                        map->tiles->rows = 1;\r
                        map->tiles->cols = 1;
-                       js_sv="data";//strdup(js+t->start);//, t->end - t->start);
+                       strcpy(js_sv, "data");//strdup(js+t->start);//, t->end - t->start);
                }
                else
-               if (jsoneq(js, t, "height") == 0 && indent==1)
+               if (jsoneq(js, t, "height") == 0 && indent<=1)
                {
-                       js_sv="height";//strdup(js+t->start);//, t->end - t->start);
-               }else if (jsoneq(js, t, "width") == 0 && indent==1)
+                       strcpy(js_sv, "height");//strdup(js+t->start);//, t->end - t->start);
+               }else if(jsoneq(js, t, "width") == 0 && indent<=1)
                {
-                       js_sv="width";//strdup(js+t->start);//, t->end - t->start);
-               }else js_sv=NULL;
+                       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) {
-               //printf("\n");
+               //fprintf(stdout, "\n");
                j = 0;
                for (i = 0; i < t->size; i++) {
-                       //for (k = 0; k < indent; k++) printf("\t");
-                       j += dump(js, t+1+j, count-j, indent+1, map, i);
-                       //printf(": ");
-                       j += dump(js, t+1+j, count-j, indent+1, map, i);
-                       //printf("\n");
+                       //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;
-               //printf("==\n");
+               //fprintf(stdout, "==\n");
                for (i = 0; i < t->size; i++) {
-                       //for (k = 0; k < indent-1; k++) printf("\t");
-                       //printf("\t-");
-                       j += dump(js, t+1+j, count-j, indent+1, map, i);
-                       //printf("==\n");
+                       //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;
 }
 
-static int loadmap(char *mn, map_t *map)
+int loadmap(char *mn, map_t *map)
 {
        int r;
+       static int incr=0;
        int eof_expected = 0;
-       char *js = NULL;
+       char /*far*/ *js = NULL;
        size_t jslen = 0;
        char buf[BUFSIZ];
+       static char js_ss[16];
 
        jsmn_parser p;
-       jsmntok_t *tok;
+       jsmntok_t /*far*/ *tok;
        size_t tokcount = 2;
 
        FILE *fh = fopen(mn, "r");
@@ -114,7 +137,7 @@ static int loadmap(char *mn, map_t *map)
        jsmn_init(&p);
 
        /* Allocate some tokens as a start */
-       tok = malloc(sizeof(*tok) * tokcount);
+       tok = /*_f*/malloc(sizeof(*tok) * tokcount);
        if (tok == NULL) {
                fprintf(stderr, "malloc(): errno=%d\n", errno);
                return 3;
@@ -136,7 +159,7 @@ static int loadmap(char *mn, map_t *map)
                        }
                }
 
-               js = realloc(js, jslen + r + 1);
+               js = /*_f*/realloc(js, jslen + r + 1);
                if (js == NULL) {
                        fprintf(stderr, "realloc(): errno = %d\n", errno);
                        return 3;
@@ -149,7 +172,7 @@ again:
                if (r < 0) {
                        if (r == JSMN_ERROR_NOMEM) {
                                tokcount = tokcount * 2;
-                               tok = realloc(tok, sizeof(*tok) * tokcount);
+                               tok = /*_f*/realloc(tok, sizeof(*tok) * tokcount);
                                if (tok == NULL) {
                                        fprintf(stderr, "realloc(): errno=%d\n", errno);
                                        return 3;
@@ -157,13 +180,13 @@ again:
                                goto again;
                        }
                } else {
-                       dump(js, tok, p.toknext, 0, map, 0);
+                       dump(js, tok, p.toknext, incr, &js_ss, map, 0);
                        eof_expected = 1;
                }
        }
 
-       free(js);
-       free(tok);
+       /*_f*/free(js);
+       /*_f*/free(tok);
        fclose(fh);
 
        return 0;
index eaca2566bc242e049775479ee896062238e4b2aa..f0e07cc8c6493f8ff2d019204d5ccc110b06c1a3 100644 (file)
@@ -1,16 +1,19 @@
 #ifndef _LIBMAPREAD_H_
 #define _LIBMAPREAD_H_
+//#include <stdlib.h>
+//#include <stdio.h>
 #include <string.h>
 #include <errno.h>
-
-//#include <stdlib.h>
+#include <alloc.h>
 
 #include "src/lib/jsmn/jsmn.h"
 #include "src/lib/modex16.h"
 #include "src/lib/lib_head.h"
 
-//---- temp!
-static char *js_sv;
+//#define DEBUG_MAPDATA
+#define DEBUG_MAPVAR
+//#define DEBUG_DUMPVARS
+#define DEBUG_JS
 
 typedef struct {\r
        bitmap_t *data;
@@ -21,14 +24,14 @@ typedef struct {
 } tiles_t;\r
 \r
 typedef struct {\r
-       byte    *data;\r
+       byte *data;\r
        tiles_t *tiles;\r
-       int width;\r
-       int height;\r
+       unsigned int width;\r
+       unsigned int height;\r
 } map_t;
 
-static int jsoneq(const char *json, jsmntok_t *tok, const char *s);
-static int dump(const char *js, jsmntok_t *t, size_t count, int indent, map_t *map, int q);
-static int loadmap(char *mn, map_t *map);
+int jsoneq(const char /*far*/ *json, jsmntok_t /*far*/ *tok, const char *s);
+int dump(const char /*far*/ *js, jsmntok_t /*far*/ *t, size_t count, int indent, char *js_sv, map_t *map, int q);
+int loadmap(char *mn, map_t *map);
 
 #endif/*_LIBMAPREAD_H_*/
index 48c022d1c9b0c83d6fe9987925206709a73fa219..1f7e03fc232864ddf8fe779a7c661bbca32caa35 100644 (file)
@@ -1,9 +1,25 @@
-#include "src/lib/mapread.c"\r
-\r
+#include "src/lib/mapread.h"\r
+
+#define DUMP
+#define DUMP_MAP
+
 void
 main(int argc, char *argv[])\r
 {\r
        map_t map;
+       short i;
+       //int lm;
        loadmap("data/test.map", &map);
-       fprintf(stderr, "%d\n", map.data[0]);
+       //fprintf(stdout, "loadmap=     %d\n\n", lm);
+       #ifdef DUMP
+       fprintf(stdout, "map.width=     %d\n", map.width);
+       fprintf(stdout, "map.height=    %d\n", map.height);
+       #ifdef DUMP_MAP
+       for(i=0; i<(map.width*map.height); i++)
+       {
+               fprintf(stdout, "%04d[%02d]", i, map.data[i]);
+               if(i && !(i%map.width)) fprintf(stdout, "\n");
+       }
+       #endif
+       #endif
 }\r
index 4faa1ec2eb6b185ed0f0242b9bd4e27e891e5873..3e26ba260344a427ca6f9f472df146a55607aa59 100644 (file)
Binary files a/test.exe and b/test.exe differ
index 05bb136744496e6f50b6fed102246f4f8af1bcff..5475dfeb7d4b81574f9c64604923b8cd26bd0950 100644 (file)
Binary files a/test2.exe and b/test2.exe differ