diff --git a/include/devil1tex.h b/include/devil1tex.h index 1dc4b89..7b1678a 100644 --- a/include/devil1tex.h +++ b/include/devil1tex.h @@ -46,4 +46,7 @@ void gettbd(struct TextureBatchDescriptor**, const char*, unsigned int); +void gettexturebatch(struct TextureBatch**, + const char*, + unsigned int); #endif diff --git a/src/devil1tex.c b/src/devil1tex.c index 8e5ccc4..002b372 100644 --- a/src/devil1tex.c +++ b/src/devil1tex.c @@ -1,5 +1,6 @@ #include "devil1tex.h" #include +#include #include void printtph (struct TexturePack *tp) { @@ -55,3 +56,23 @@ void gettbd (struct TextureBatchDescriptor **descriptors, return; } +void gettexturebatch(struct TextureBatch **tb, + const char *filedata, + unsigned int filesize) { + struct TexturePack *tp = (struct TexturePack*)filedata; + struct TextureBatchDescriptor **bds = NULL; + bds = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber); + gettbd(bds, filedata, filesize); + unsigned int offset = tp -> firstBatchOffset; + unsigned int i; + unsigned int j; + // TextureBatch shares a starting address with the first texture + // and shares the ending address with the last texture. + for (i = 0; i < tp -> batchNumber; i++) { + printf("%x \n", offset); + tb[i] = (struct TextureBatch*)filedata + offset; + // the next texture batch is TextureSize * number of textures away. + offset += bds[i] -> textureSize * (bds[i] -> texNumber); + } + free(bds); +} diff --git a/test/main.c b/test/main.c index 25a8061..2f70e06 100644 --- a/test/main.c +++ b/test/main.c @@ -90,28 +90,30 @@ bool unpackpld (const char *filedata, return status; } - - -int main(int argc, char ** argv) { - char *f = argv[1]; - unsigned int bufsize = 0; - char *buffer = loadfile(f, &bufsize); -// unpackpld(buffer, bufsize, f); - struct TexturePack *tp = NULL; - printf("%d %d %d %d \n", buffer[0], - buffer[1], - buffer[2], - buffer[3]); - tp = (struct TexturePack*)buffer; +/* void unpacktextures(const char *filedata, unsigned int filesize) { + struct TexturePack *tp = (struct TexturePack*)filedata; struct TextureBatchDescriptor **bds = NULL; bds = (struct TextureBatchDescriptor**)malloc(tp -> batchNumber); - gettbd(bds, buffer, bufsize); + gettbd(bds, filedata, filesize); printtph(tp); int i; for (i = 0; i < tp -> batchNumber; i++) { printtbd(bds[i]); } free(bds); + return; +} */ + +int main(int argc, char ** argv) { + char *f = argv[1]; + unsigned int bufsize = 0; + char *buffer = loadfile(f, &bufsize); +// unpackpld(buffer, bufsize, f); +// unpacktextures(buffer, bufsize); + struct TexturePack *tp = (struct TexturePack*)buffer; + struct TextureBatch **batches = NULL; + batches = (struct TextureBatch**)malloc(tp -> batchNumber); + gettexturebatch(batches, buffer, bufsize); free(buffer); return 0; }