diff --git a/.gitignore b/.gitignore index e3fb55d..35a3473 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ *.stackdump *.log devil1test +demo-extractpld +demo-extracttexture +demo-extractmesh # Test files *.dds diff --git a/Makefile b/Makefile index f945ff5..683df21 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,20 @@ -EX=devil1test +PEX=demo-extractpld +TEX=demo-extracttexture +MEX=demo-extractmesh + CC=gcc CFLAGS= -I"include" -all: main +all: pld texture mesh -main: devil1pld.o devil1tex.o src/devil1geo.o - $(CC) $^ test/main.c $(CFLAGS) -o $(EX) +pld: devil1pld.o devil1tex.o src/devil1geo.o + $(CC) $^ demo/pld.c $(CFLAGS) -o $(PEX) + +texture: devil1pld.o devil1tex.o src/devil1geo.o + $(CC) $^ demo/texture.c $(CFLAGS) -o $(TEX) + +mesh: devil1pld.o devil1tex.o src/devil1geo.o + $(CC) $^ demo/mesh.c $(CFLAGS) -o $(MEX) devil1pld.o: src/devil1pld.c $(CC) -c $^ $(CFLAGS) diff --git a/test/main.c b/demo/common.h similarity index 53% rename from test/main.c rename to demo/common.h index ab0cb5d..245ac2f 100644 --- a/test/main.c +++ b/demo/common.h @@ -86,68 +86,3 @@ bool unpackpld(const char *filedata, return true; } -void exporttextures(const char *filedata, - unsigned int filesize, - const char *filename) { - struct TexturePack *p = NULL; - struct Texture *t = NULL; - struct TextureBatchDescriptor *d = NULL; - char * fmt = NULL; - if (filedata == NULL || filesize == 0) { - return; - } - p = (struct TexturePack*)filedata; - fmt = (char*)malloc(strlen(filename) + 3 + 4); - unsigned int i; - unsigned int j; - unsigned int id = 0; - for (i = 0; i < p -> batchNumber; i++) { - DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize); - t = (struct Texture*) - malloc(sizeof(struct Texture) * (d -> texNumber)); - DEVIL1TEX.gettextures(t, i, filedata, filesize); - for (j = 0; j < d -> texNumber; j++) { - sprintf(fmt, "%s_%d.dds", filename, id); - write(fmt, t[j].data, d -> textureSize); - id++; - } - free(t); - } - free(fmt); - return; -} - -void extractmeshes(const char *filedata, - unsigned int filesize, - const char *filename) { - if (filedata == NULL || filesize <= 0) { - return; - } - struct Header *h = (struct Header*)filedata; - struct MeshHeader *mh = NULL; - struct Mesh m; - m.b = NULL; - unsigned int i; - for (i = 0; i < h -> numMesh; i++) { - DEVIL1GEO.getmeshheader(&mh, i, filedata); - m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch)); - if (m.b != NULL) { - DEVIL1GEO.getmesh(&m, i, filedata); - // do something with mesh e.g write to file. - free(m.b); - } - } // end for -} - -int main(int argc, char ** argv) { - char *f = argv[1]; - unsigned int bufsize = 0; - char *buffer = loadfile(f, &bufsize); -// unpackpld(buffer, bufsize, f); -// exporttextures(buffer, bufsize, f); - extractmeshes(buffer, bufsize, f); - free(buffer); - return 0; -} - - diff --git a/demo/mesh.c b/demo/mesh.c new file mode 100644 index 0000000..0e7025d --- /dev/null +++ b/demo/mesh.c @@ -0,0 +1,38 @@ +#include "common.h" + + +void extractmeshes(const char *filedata, + unsigned int filesize, + const char *filename) { + if (filedata == NULL || filesize <= 0) { + return; + } + struct Header *h = (struct Header*)filedata; + struct MeshHeader *mh = NULL; + struct Mesh m; + m.b = NULL; + unsigned int i; + for (i = 0; i < h -> numMesh; i++) { + DEVIL1GEO.getmeshheader(&mh, i, filedata); + m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch)); + if (m.b != NULL) { + DEVIL1GEO.getmesh(&m, i, filedata); + // do something with mesh e.g write to file. + free(m.b); + } + } // end for +} + + +int main(int argc, char ** argv) { + char *f = argv[1]; + unsigned int bufsize = 0; + char *buffer = loadfile(f, &bufsize); +// unpackpld(buffer, bufsize, f); +// exporttextures(buffer, bufsize, f); + extractmeshes(buffer, bufsize, f); + free(buffer); + return 0; +} + + diff --git a/demo/pld.c b/demo/pld.c new file mode 100644 index 0000000..100f81a --- /dev/null +++ b/demo/pld.c @@ -0,0 +1,11 @@ +#include "common.h" + + +int main(int argc, char ** argv) { + char *f = argv[1]; + unsigned int bufsize = 0; + char *buffer = loadfile(f, &bufsize); + unpackpld(buffer, bufsize, f); + free(buffer); + return 0; +} diff --git a/demo/texture.c b/demo/texture.c new file mode 100644 index 0000000..5cc1004 --- /dev/null +++ b/demo/texture.c @@ -0,0 +1,44 @@ +#include "common.h" + + +void exporttextures(const char *filedata, + unsigned int filesize, + const char *filename) { + struct TexturePack *p = NULL; + struct Texture *t = NULL; + struct TextureBatchDescriptor *d = NULL; + char * fmt = NULL; + if (filedata == NULL || filesize == 0) { + return; + } + p = (struct TexturePack*)filedata; + fmt = (char*)malloc(strlen(filename) + 3 + 4); + unsigned int i; + unsigned int j; + unsigned int id = 0; + for (i = 0; i < p -> batchNumber; i++) { + DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize); + t = (struct Texture*) + malloc(sizeof(struct Texture) * (d -> texNumber)); + DEVIL1TEX.gettextures(t, i, filedata, filesize); + for (j = 0; j < d -> texNumber; j++) { + sprintf(fmt, "%s_%d.dds", filename, id); + write(fmt, t[j].data, d -> textureSize); + id++; + } + free(t); + } + free(fmt); + return; +} + +int main(int argc, char ** argv) { + char *f = argv[1]; + unsigned int bufsize = 0; + char *buffer = loadfile(f, &bufsize); + exporttextures(buffer, bufsize, f); + free(buffer); + return 0; +} + +