From cccf74b8d5b618b293330755da222138dcf619cc Mon Sep 17 00:00:00 2001 From: sparky4 Date: Fri, 17 Feb 2017 09:50:21 -0600 Subject: [PATCH] cannot work on this much more i gotta do school project and final --- MAPTEST.L16 | 13 +++++++++ data/test.map | 4 +-- data/test.tmx | 12 ++++++-- src/lib/16_map.c | 70 +++++++++++++++++++++++++---------------------- src/lib/16_map.h | 4 +-- src/lib/16_tdef.h | 2 +- src/lib/16_vrs.c | 58 --------------------------------------- src/lib/16_vrs.h | 1 - src/maptest.c | 13 +++------ 9 files changed, 70 insertions(+), 107 deletions(-) create mode 100755 MAPTEST.L16 diff --git a/MAPTEST.L16 b/MAPTEST.L16 new file mode 100755 index 00000000..b9b35136 --- /dev/null +++ b/MAPTEST.L16 @@ -0,0 +1,13 @@ +objects detected +Object 4's name: (name size is 5)[ +'trunk' +] +'{ + + }'Object 4's name: (name size is 5)[ +'stump' +] +'{ + + }'map.width= 40 +map.height= 30 diff --git a/data/test.map b/data/test.map index 03307bad..0b1757c8 100755 --- a/data/test.map +++ b/data/test.map @@ -43,7 +43,7 @@ "name":"trunk", "properties": { - + "walkable":"0" }, "type":"nonc", "visible":true, @@ -56,7 +56,7 @@ "name":"stump", "properties": { - + "walkable":"0" }, "type":"nonc", "visible":true, diff --git a/data/test.tmx b/data/test.tmx index 5ccdb602..fee932f3 100755 --- a/data/test.tmx +++ b/data/test.tmx @@ -109,7 +109,15 @@ - - + + + + + + + + + + diff --git a/src/lib/16_map.c b/src/lib/16_map.c index 931afe43..26167781 100755 --- a/src/lib/16_map.c +++ b/src/lib/16_map.c @@ -46,23 +46,20 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { inner_end = t[i].end; k = 0; while(t[i].start < inner_end) { -#ifdef DEBUG_DUMPVARS - printf("t[%d].start=%d, %d\n", i, t[i].start, inner_end); -#endif +//#define DEBUG_DUMPVARS +//#ifdef DEBUG_DUMPVARS +// printf("t[%d].start=%d, %d\n", i, t[i].start, inner_end); +//#endif if(!objlay){ if(jsoneq(js, &(t[i]), "data") == 0) { #ifdef DEBUG_MAPDATA printf("Layer %d data: (size is %d)[\n", k, t[i+1].size); #endif map->layerdata[k].data = malloc(sizeof(byte) * t[i+1].size);//TODO: USE MM_ CA_ AND PM_ -// map->data = (map->layerdata[k].data); //for backwards compatibility for rest of code for(j = 0; j < t[i+1].size; j++) { - //map->layerdata[k][j] = (byte)atoi(js + t[i+2+j].start); map->layerdata[k].data[j] = (byte)atoi(js + t[i+2+j].start); #ifdef DEBUG_MAPDATA - //printf("[%d,%d]%d", k, j, map->MAPDATAPTK[j]); - printf("%c", map->MAPDATAPTK[j]+44); - //fprintf(stdout, "%c", map->data[j]+44); + printf("%c", map->layerdata[k].data[j]+44); #endif } i += j + 2; @@ -70,13 +67,13 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { puts("\n]"); #endif }else if(jsoneq(js, &(t[i]), "name") == 0) { -#ifdef DEBUG_MAPDATA +#ifdef DEBUG_MAPVARS printf("Layer %d's name: (size is %d)[\n", k, MAPLNAMESIZE); #endif - map->layerdata[k].layername = malloc(sizeof(byte) * MAPLNAMESIZE);//TODO: USE MM_ CA_ AND PM_ - strncpy(map->layerdata[k].layername, js+t[i+1].start, MAPLNAMESIZE); - if(map->layerdata[k].layername[MAPLNAMESIZE]!=0) map->layerdata[k].layername[MAPLNAMESIZE]='\0'; - if(strstr(map->layerdata[k].layername, "ob")) objlay=1; + //map->layerdata[k].layername = malloc(sizeof(byte) * MAPLNAMESIZE);//TODO: USE MM_ CA_ AND PM_ + strncpy(&(map->layerdata[k].layername), js+t[i+1].start, MAPLNAMESIZE); + if((map->layerdata[k].layername[MAPLNAMESIZE])!=0) map->layerdata[k].layername[MAPLNAMESIZE]='\0'; + if(strstr(&map->layerdata[k].layername, "ob")) objlay=1; #ifdef DEBUG_MAPDATA printf("%s", map->layerdata[k].layername); printf("\n]\n"); @@ -84,24 +81,33 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { k++; } }else{ //objlay - if(jsoneq(js, &(t[i]), "objects") == 0) { -#ifdef DEBUG_MAPDATA - printf("objects detected\n"); + if(jsoneq(js, &(t[i]), "objects") == 0) { +#ifdef DEBUG_OBVARS + printf("objects detected\n"); #endif -// map->layerdata[k].layername = mAlloc(sizeof(byte) * MAPLNAMESIZE);//TODO: USE MM_ CA_ AND PM_ -// strncpy(map->layerdata[k].layername, js+t[i+1].start, MAPLNAMESIZE);//TODO: USE MM_ CA_ AND PM_ -// if(map->layerdata[k].layername[MAPLNAMESIZE]!=0) map->layerdata[k].layername[MAPLNAMESIZE]='\0'; - }else if(jsoneq(js, &(t[i]), "name") == 0) { -#ifdef DEBUG_MAPDATA - printf("Object %d's name: (size is %d)[\n", k, MAPLNAMESIZE); - printf("'%.*s'", t[i+1].end - t[i+1].start, js+t[i+1].start); - printf("\n]\n"); +#ifdef DEBUG_OBVARS + #endif +// map->layerdata[k].layername = mAlloc(sizeof(byte) * MAPLNAMESIZE);//TODO: USE MM_ CA_ AND PM_ +// strncpy(map->layerdata[k].layername, js+t[i+1].start, MAPLNAMESIZE);//TODO: USE MM_ CA_ AND PM_ +// if(map->layerdata[k].layername[MAPLNAMESIZE]!=0) map->layerdata[k].layername[MAPLNAMESIZE]='\0'; + }else if(jsoneq(js, &(t[i]), "name") == 0) { +#ifdef DEBUG_OBVARS + printf("Object %d's name: ", k);//, MAPLNAMESIZE + printf("'%.*s'\n", t[i+1].end - t[i+1].start, js+t[i+1].start); +#endif + }else if(jsoneq(js, &(t[i]), "properties") == 0) { +#ifdef DEBUG_OBVARS + printf(" properties: %.*s\n", t[i+1].end - t[i+1].start, js+t[i+1].start); +#endif + }else if(jsoneq(js, &(t[i]), "walkable") == 0) { + printf(" walkable: %d\n", atoi(js + t[i+1].start)); } - } - i++; - } - } + + }//end objlay + i++;//next token + }//tokens + }//layers if(jsoneq(js, &(t[i]), "tilesets") == 0) { @@ -124,13 +130,13 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { i++; }else if(jsoneq(js, &(t[i]), "tileheight") == 0) { map->tiles->tileHeight = atoi(js + t[i+1].start); -#ifdef DEBUG_MAPVAR +#ifdef DEBUG_MAPVARS printf("Tile Height: %d\n", map->tiles->tileHeight); #endif i++; }else if(jsoneq(js, &(t[i]), "tilewidth") == 0) { map->tiles->tileWidth = atoi(js + t[i+1].start); -#ifdef DEBUG_MAPVAR +#ifdef DEBUG_MAPVARS printf("Tile Width: %d\n", map->tiles->tileWidth); #endif i++; @@ -142,14 +148,14 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { if (jsoneq(js, &(t[i]), "height") == 0 && indent<=1) { map->height = atoi(js + t[i+1].start); -#ifdef DEBUG_MAPVAR +#ifdef DEBUG_MAPVARS printf("Height: %d\n", map->height); #endif i++; } else if(jsoneq(js, &(t[i]), "width") == 0 && indent<=1) { map->width = atoi(js + t[i+1].start); -#ifdef DEBUG_MAPVAR +#ifdef DEBUG_MAPVARS printf("Width: %d\n", map->width); #endif i++; diff --git a/src/lib/16_map.h b/src/lib/16_map.h index e8290486..8ea0ec19 100755 --- a/src/lib/16_map.h +++ b/src/lib/16_map.h @@ -34,8 +34,8 @@ #include "src/lib/16_pm.h" //#define DEBUG_MAPDATA -//#define DEBUG_MAPVAR -//#define DEBUG_DUMPVARS +//#define DEBUG_MAPVARS +#define DEBUG_OBVARS //#define DEBUG_JS //typedefs moved to 16_tdef.h diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h index ec92baaa..9df1eee9 100755 --- a/src/lib/16_tdef.h +++ b/src/lib/16_tdef.h @@ -104,7 +104,7 @@ typedef struct { //TODO: 16_mm and 16_ca must handle this //TODO: add variables from 16_ca typedef struct { - byte *layername; + byte layername[8]; byte *data; //TODO: 16_mm and 16_ca must handle this } mapl_t; //map layer array type def diff --git a/src/lib/16_vrs.c b/src/lib/16_vrs.c index f77c7e3c..efb62ba8 100755 --- a/src/lib/16_vrs.c +++ b/src/lib/16_vrs.c @@ -78,64 +78,6 @@ void VRS_OpenVRS(char *filename, entity_t *enti, boolean rlsw, global_game_varia enti->spri.sprite_vrl_cont = malloc(sizeof(struct vrl_container)); } -// Read .vrs file into far memory -int read_vrs(global_game_variables_t *gvar, char *filename, struct vrs_container *vrs_cont){ - int fd; - dword size; - byte far *buffer; - vrl1_vgax_offset_t **vrl_line_offsets; - uint32_t far *vrl_headers_offsets; - uint16_t far *vrl_id_iter; - uint32_t vrl_size; - int num_of_vrl=0, i; - struct vrl1_vgax_header far *curr_vrl; - int success=1; - - // Open filename, get size of file, - // populate the vrs_container if all tests pass - fd = open(filename, O_RDONLY|O_BINARY); - // Insert sanity cheks later - size = lseek(fd, 0, SEEK_END); - buffer = malloc(size); - lseek(fd, 0, SEEK_SET); - read(fd, buffer, size); - close(fd); - if(!success) - { - Quit (gvar, "Unable to load file"); - } - vrs_cont->data_size = size - sizeof(struct vrs_header); - vrs_cont->buffer = buffer; - - // Calculate vrl offsets - - // Count sprites - vrl_id_iter = (uint16_t far *)(buffer + vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST]); - while(vrl_id_iter[num_of_vrl]){ - num_of_vrl++; - } - // Allocate memory for vrl line offsets table - vrl_line_offsets = malloc(sizeof(vrl1_vgax_offset_t *)*num_of_vrl); - - vrl_headers_offsets = (uint32_t far *)(buffer + vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_VRS_LIST]); - // Calculate line offsets for each vrl - for(i = 0; i < num_of_vrl; i++){ - curr_vrl = (struct vrl1_vgax_header far *)(buffer + vrl_headers_offsets[i]); - - // Calc. vrl size as (next_offset - curr_offset) - if (i != num_of_vrl - 1){ - vrl_size = vrl_headers_offsets[i+1] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header); - } - // If it's the last vrl, size is (next_vrs_struct_offset - curr_offset) - else{ - vrl_size = vrs_cont->vrs_hdr->offset_table[VRS_HEADER_OFFSET_SPRITE_ID_LIST] - vrl_headers_offsets[i] - sizeof(struct vrl1_vgax_header); - } - vrl_line_offsets[i] = vrl1_vgax_genlineoffsets(curr_vrl, (byte *)curr_vrl + sizeof(struct vrl1_vgax_header), vrl_size); - } - vrs_cont->vrl_line_offsets = vrl_line_offsets; - return 0; -} - // Seek and return a specified .vrl blob from .vrs blob in far memory int get_vrl_by_id(struct vrs_container far *vrs_cont, uint16_t id, struct vrl_container *vrl_cont){ uint16_t far *ids; diff --git a/src/lib/16_vrs.h b/src/lib/16_vrs.h index 068f569f..9a089f47 100755 --- a/src/lib/16_vrs.h +++ b/src/lib/16_vrs.h @@ -64,7 +64,6 @@ struct vrl_container{ void VRS_ReadVRS(char *filename, entity_t *enti, global_game_variables_t *gvar); void VRS_LoadVRS(char *filename, entity_t *enti, global_game_variables_t *gvar); void VRS_OpenVRS(char *filename, entity_t *enti, boolean rlsw, global_game_variables_t *gvar); -//int read_vrs(global_game_variables_t *gvar, char *filename, struct vrs_container *vrs_cont); /* Seek and return a specified .vrl blob from .vrs blob in memory * In: diff --git a/src/maptest.c b/src/maptest.c index a605a8ef..11097deb 100755 --- a/src/maptest.c +++ b/src/maptest.c @@ -22,7 +22,7 @@ #include "src/lib/16_map.h" #define DUMP -#define DUMP_MAP +//#define DUMP_MAP void main(int argc, char *argv[]) @@ -37,23 +37,20 @@ main(int argc, char *argv[]) #endif char *fmt = "Memory available = %u\n"; char *fmt0 = "Largest Contiguous Block of Memory available = %u\n"; - byte *datboi = "oh shit waddup!\n"; + //byte *datboi = "oh shit waddup!\n"; MM_Startup(&gvar); PM_Startup(&gvar); //printf("pmstarted ok\n"); - //PM_CheckMainMem(&gvar); + PM_CheckMainMem(&gvar); PM_UnlockMainMem(&gvar); CA_Startup(&gvar); fprintf(stderr, fmt, _memavl()); fprintf(stderr, fmt0, _memmax()); fprintf(stderr, "Size of map var = %u\n", _msize(&(gvar.ca.camap.mapsegs))); - //fprintf(stderr, "program always crashes for some reason....\n"); //getch(); - //loadmap("data/test.map", &map); - //newloadmap("data/test.map", &map); CA_loadmap("data/test.map", &map, &gvar); #ifdef DUMP fprintf(stdout, "map.width= %d\n", map.width); @@ -86,9 +83,7 @@ main(int argc, char *argv[]) fprintf(stdout, "&map.height==%Fp\n", map.height); fprintf(stdout, "&map.data==%Fp\n", map.data);*/ #endif - fprintf(stderr, "here comes dat boi!\n"); - getch(); - fprintf(stderr, "%s", datboi); + //fprintf(stderr, "here comes dat boi!\n"); getch(); fprintf(stderr, "%s", datboi); MM_FreePtr(&(gvar.ca.camap.mapsegs), &gvar); PM_Shutdown(&gvar); CA_Shutdown(&gvar); -- 2.39.5