diff --git a/include/devil1tex.h b/include/devil1tex.h index 1ae8377..71ad66e 100644 --- a/include/devil1tex.h +++ b/include/devil1tex.h @@ -52,7 +52,7 @@ unsigned int gettexturebatch( const char*, unsigned int); -void gettextures(struct Texture **, +void gettextures(unsigned int*, struct TexturePack*, struct TextureBatch**, struct TextureBatchDescriptor**); diff --git a/src/devil1tex.c b/src/devil1tex.c index b7285d7..4d06be2 100644 --- a/src/devil1tex.c +++ b/src/devil1tex.c @@ -78,8 +78,8 @@ unsigned int gettexturebatch( } return totaltextures; } - -void gettextures(struct Texture **t, + +void gettextures(unsigned int *t, struct TexturePack *tp, struct TextureBatch **tb, struct TextureBatchDescriptor **bds) { @@ -87,11 +87,11 @@ void gettextures(struct Texture **t, unsigned int j; // k is access to index of textures. unsigned int k = 0; - unsigned int offset = 0; + unsigned int offset = tp -> firstBatchOffset; for (i = 0; i < tp -> batchNumber; i++) { for (j = 0; j < bds[i] -> texNumber; j++) { - printf("texture offsets %x\n", offset + tp -> firstBatchOffset); - t[k] = (struct Texture*)tb + offset; + printf("texture offsets %x\n", offset); + t[k] = offset; offset += bds[i] -> textureSize; k++; } diff --git a/test/main.c b/test/main.c index 2e0f017..24f8841 100644 --- a/test/main.c +++ b/test/main.c @@ -110,7 +110,7 @@ bool unpackpld (const char *filedata, void write(const char *filename, unsigned int id, - struct Texture *t, + const char* t, unsigned int size) { if (filename == NULL) { return; @@ -120,6 +120,10 @@ void write(const char *filename, if (out != NULL) { written = fwrite(t, sizeof(unsigned char), size, out); fclose(out); +/* unsigned int i; + for (i = 0; i < 10; i++) { + printf("w %u \n", *(t + i)); + } */ if (written == 0) { perror("texture write error"); } @@ -140,10 +144,9 @@ void unpacktextures(const char *filedata, descripts, filedata, filesize); - struct Texture **textures = NULL; - textures = (struct Texture**) - malloc(sizeof(struct Texture**) * texturecount); - gettextures(textures, tp, batches, descripts); + unsigned int *tloc = (unsigned int*) + malloc(sizeof(unsigned int) * texturecount); + gettextures(tloc, tp, batches, descripts); // add 3 to buffer for digits, & 4 for file extension char *fmt = (char*)malloc(strlen(filename) + 3 + 4); unsigned int texsize = 0; @@ -151,10 +154,10 @@ void unpacktextures(const char *filedata, for (i = 0; i < texturecount; i++) { texsize = descripts[i/(tp -> batchNumber)] -> textureSize; sprintf(fmt, "test_%d.dds", i); - write(fmt, i, textures[i], texsize); + write(fmt, i, filedata + tloc[i], texsize); } free(fmt); - free(textures); + free(tloc); free(descripts); free(batches); }