From 9f7ffee2115e5b995c5470117e426d2c89b58979 Mon Sep 17 00:00:00 2001 From: sparky4 Date: Wed, 15 Feb 2017 11:48:53 -0600 Subject: [PATCH] LAYERING WORKS NOW! --- MAPTEST.L16 | 170 +++++++++++++++++++++++++++++++++++++--------- src/lib/16_map.c | 16 +++-- src/lib/16_map.h | 2 +- src/lib/16_tdef.h | 77 ++++++++++----------- src/maptest.c | 33 ++++----- 5 files changed, 199 insertions(+), 99 deletions(-) diff --git a/MAPTEST.L16 b/MAPTEST.L16 index 8d927558..0ea99ec9 100755 --- a/MAPTEST.L16 +++ b/MAPTEST.L16 @@ -1,37 +1,143 @@ Layer 0 data: [ --./0,////////0-----------------------./01234,-,-,,--------------------------123456780-,-,,--------------------------56789:;<,---14-77-----------------------9:;<,,0,,,,,44-77/------------------------------,,,,44----------------------------------,,,,------------------------------------,,,,--------/--------------------------------,------/---------------------------------------/---------------------------------------/-----------------------------------////-./0/////--------------------------/----123422222///---------------------//-----567822222222///-----------------/-------9:;,ì>,ì>,l>,Œ<,Œ>,Ð<, +Œ<,,1,ì¬@,Ì@,˜0-üì2-ü>1-üì@, @,,A, +LA,lA,ìA,Œ<,Œ<,Œ<,Œ<,å/-üŒ<,Œ<, +Œ<,<,+óŒ<,Œ<,Œ<,Œ<,Œ<,Œ<,Œ<,Œ<, +Œ<,Œ<,Œ<,Œ<,Œ<,Œ=,Œ<,,C,ìŒ<,Œ<, +¬=,Œ<,Œ<,Œ<,Œ<,,B,Œ<,Œ<,Œ<,Œ<, +Œ<,Œ<,Œ<,Œ<,Œ<,Œ<,Œ<,Œ<,Œ<,Œ<, +Œ<,Œ<,Œ<,Œ<,Œ<,Œ<,,,,,,,,,,,,,,,,, +,,,,,,,,Œ<,0,môŒ<,Œ<,Œ<,Œ<,Œ<,Œ<, +Œ<,Œ<,¬>,Ì>,,,,,,,oôL@,,,,,,,,,,,,, +,,,,,,,,ÌB,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,¤/,,,,,, +Rü,¬.,,L,,V,V,9HLeLeLeLeLe4:4:˜R5;9H t t + |9H t,,,,,,,,,,,/|,,<,,,D,,,,,,,,,,,,,, +3,,/5\,,,,,vú7,,,,,,.,,---,----J,j,D<,Œ +5}7,,,,,,,,,,,<>,,,,,,,,,,,,,,,,»Z,ì,,,, ] diff --git a/src/lib/16_map.c b/src/lib/16_map.c index 45b0166d..f74f46ca 100755 --- a/src/lib/16_map.c +++ b/src/lib/16_map.c @@ -257,7 +257,7 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { while(ilayerdata = 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) { @@ -268,11 +268,11 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) { #ifdef DEBUG_MAPDATA printf("Layer %d data: [\n", k); #endif - map->layerdata[k] = malloc(sizeof(byte) * t[i+1].size); - //for backwards compatibility for rest of code - map->data = map->layerdata[k]; + map->layerdata[k].data = malloc(sizeof(byte) * t[i+1].size); +// 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][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); @@ -310,9 +310,15 @@ 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->MAPTILESPTK->tileHeight = atoi(js + t[i+1].start); +#ifdef DEBUG_MAPVAR + printf("Tile Height: %d\n", map->MAPTILESPTK->tileHeight); +#endif i++; }else if(jsoneq(js, &(t[i]), "tilewidth") == 0) { map->MAPTILESPTK->tileWidth = atoi(js + t[i+1].start); +#ifdef DEBUG_MAPVAR + printf("Tile Width: %d\n", map->MAPTILESPTK->tileWidth); +#endif i++; } i++; diff --git a/src/lib/16_map.h b/src/lib/16_map.h index ef1c5c7f..e8290486 100755 --- a/src/lib/16_map.h +++ b/src/lib/16_map.h @@ -33,7 +33,7 @@ #include "src/lib/16_mm.h" #include "src/lib/16_pm.h" -#define DEBUG_MAPDATA +//#define DEBUG_MAPDATA //#define DEBUG_MAPVAR //#define DEBUG_DUMPVARS //#define DEBUG_JS diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h index e99be1de..1aa2d52e 100755 --- a/src/lib/16_tdef.h +++ b/src/lib/16_tdef.h @@ -64,11 +64,37 @@ typedef struct { byte *palette; } planar_buf_t; +//from 16_sprit.h +#ifdef __WATCOMC__ +typedef struct sprite +{ + // VRS container from which we will extract animation and image data + struct vrs_container *spritesheet; + // Container for a vrl sprite + struct vrl_container *sprite_vrl_cont; + // Current sprite id + int curr_spri_id; + // Index of a current sprite in an animation sequence + int curr_anim_spri; + // Current animation sequence + struct vrs_animation_list_entry_t *curr_anim_list; + // Index of current animation in relevant VRS offsets table + int curr_anim; + // Delay in time units untill we should change sprite + int delay; + // Position of sprite on screen + int x, y; +} sprite_t; +#endif + //===========================================================================// //TODO: 16_mm and 16_ca must handle this typedef struct { - bitmap_t far *pcximg; //I will probibaly use this --sparky4 + bitmap_t far *pcximg; // old +#ifdef __WATCOMC__ + sprite_t *spri; // I will probibaly use this --sparky4 +#endif //planar_buf_t far *pbdata; //old word tileHeight, tileWidth; //defined by mapfile unsigned int rows, cols; @@ -77,29 +103,21 @@ typedef struct { //TODO: 16_mm and 16_ca must handle this //TODO: add variables from 16_ca -//#define __NEWMAPTILEDATAVARS__ +typedef struct { + byte *data; //TODO: 16_mm and 16_ca must handle this +} mapl_t; //map layer array type def + #define MAPLAYERS 4 -#ifdef __NEWMAPTILEDATAVARS__ -#define MAPTILESPTR layertile[0] -#define MAPTILESPTK layertile[k] -#define MAPDATAPTR layerdata[0] -#define MAPDATAPTK layerdata[k] -#else + +#define MAPDATAPTR layerdata[0].data +#define MAPDATAPTK layerdata[k].data #define MAPTILESPTR tiles//layertile[0] #define MAPTILESPTK tiles//layertile[k] -#define MAPDATAPTR data//layerdata[0] -#define MAPDATAPTK data//layerdata[k] -#endif typedef struct { //long planestart[3]; //unsigned planelength[3]; - byte *data; //TODO: 16_mm and 16_ca must handle this - byte far *layerdata[MAPLAYERS]; // mapdata for multilayer (map index values for rendering which image on the tile) -#ifndef __NEWMAPTILEDATAVARS__ - tiles_t *tiles; //TODO: 16_mm and 16_ca must handle this -#else - tiles_t far *layertile[MAPLAYERS]; // tilesets for layers (currently ony 4 can be loaded wwww) -#endif + mapl_t layerdata[MAPLAYERS]; // mapdata for multilayer (map index values for rendering which image on the tile) + tiles_t *tiles; //TODO: 16_mm and 16_ca must handle this // tilesets for layers (currently ony 4 can be loaded wwww) int width, height; //this has to be signed! byte name[16]; } map_t; @@ -136,29 +154,6 @@ typedef struct { sword delta; // How much should we shift the page for smooth scrolling } page_t; -//from 16_sprit.h -#ifdef __WATCOMC__ -typedef struct sprite -{ - // VRS container from which we will extract animation and image data - struct vrs_container *spritesheet; - // Container for a vrl sprite - struct vrl_container *sprite_vrl_cont; - // Current sprite id - int curr_spri_id; - // Index of a current sprite in an animation sequence - int curr_anim_spri; - // Current animation sequence - struct vrs_animation_list_entry_t *curr_anim_list; - // Index of current animation in relevant VRS offsets table - int curr_anim; - // Delay in time units untill we should change sprite - int delay; - // Position of sprite on screen - int x, y; -} sprite_t; -#endif - //newer structs typedef struct { diff --git a/src/maptest.c b/src/maptest.c index 2aa6bc3f..8c1549ac 100755 --- a/src/maptest.c +++ b/src/maptest.c @@ -28,14 +28,12 @@ void main(int argc, char *argv[]) { static global_game_variables_t gvar; - map_t map; + static map_t map; #ifdef DUMP #ifdef DUMP_MAP short i; -#ifdef __NEWMAPTILEDATAVARS__ word k; #endif -#endif #endif char *fmt = "Memory available = %u\n"; char *fmt0 = "Largest Contiguous Block of Memory available = %u\n"; @@ -51,48 +49,43 @@ main(int argc, char *argv[]) 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(); + getch(); //loadmap("data/test.map", &map); //newloadmap("data/test.map", &map); -#ifndef __NEWMAPTILEDATAVARS__ - CA_loadmap("data/test.map", &map, &gvar); -#else +// CA_loadmap("data/test.map", &map, &gvar); CA_loadmap("data/newtest.map", &map, &gvar); -#endif - #ifdef DUMP +#ifdef DUMP fprintf(stdout, "map.width= %d\n", map.width); fprintf(stdout, "map.height= %d\n", map.height); - #ifdef DUMP_MAP + getch(); +#ifdef DUMP_MAP //if(map.width*map.height != 1200) -#ifdef __NEWMAPTILEDATAVARS__ for(k=0;k