From 6afdd02c6761456d84b5c4ece4b8de69433f2497 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Wed, 18 Apr 2018 00:14:11 -0700 Subject: [PATCH] Moved pld fn into pld demo, and includes into respective demos --- demo/common.h | 37 +------------------------------------ demo/mesh.c | 2 +- demo/pld.c | 27 +++++++++++++++++++++++++++ demo/texture.c | 2 +- 4 files changed, 30 insertions(+), 38 deletions(-) diff --git a/demo/common.h b/demo/common.h index 245ac2f..9d3d888 100644 --- a/demo/common.h +++ b/demo/common.h @@ -3,17 +3,6 @@ #include #include -#include "devil1pld.h" -#include "devil1tex.h" -#include "devil1geo.h" - - -#define TYPE_ID_LENGTH 4 - - - - - char *loadfile(const char *fname, unsigned int *s) { FILE *f = fopen(fname, "rb"); unsigned int size = 0; // number of elements to buffer; @@ -60,29 +49,5 @@ void write(const char *filename, } } -bool unpackpld(const char *filedata, - unsigned int filesize, - const char *filename) { - if (filedata == NULL || filesize <= 0 || filename == NULL) { - return false; - } - struct PldHeader h; - DEVIL1PLD.getheader(&h, filedata); - char *fn = NULL; - fn = (char*)malloc(strlen(filename) + 3 + 4); - int size = 0; - unsigned int i = 0; - char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'}; - for (i = 0; i < h.numOffset; i++) { - const char * currentfile = filedata + h.offsets[i]; - size = DEVIL1PLD.sizeofsector(&h, i, filesize); - if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0) - sprintf(fn, "%s_%d.txp", filename, i); - else - sprintf(fn, "%s_%d", filename, i); - write(fn, currentfile, size); - } - free(fn); - return true; -} + diff --git a/demo/mesh.c b/demo/mesh.c index 0e7025d..2ce3c6e 100644 --- a/demo/mesh.c +++ b/demo/mesh.c @@ -1,5 +1,5 @@ #include "common.h" - +#include "devil1geo.h" void extractmeshes(const char *filedata, unsigned int filesize, diff --git a/demo/pld.c b/demo/pld.c index 100f81a..34c77ca 100644 --- a/demo/pld.c +++ b/demo/pld.c @@ -1,5 +1,32 @@ #include "common.h" +#include "devil1pld.h" +#define TYPE_ID_LENGTH 4 +bool unpackpld(const char *filedata, + unsigned int filesize, + const char *filename) { + if (filedata == NULL || filesize <= 0 || filename == NULL) { + return false; + } + struct PldHeader h; + DEVIL1PLD.getheader(&h, filedata); + char *fn = NULL; + fn = (char*)malloc(strlen(filename) + 3 + 4); + int size = 0; + unsigned int i = 0; + char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'}; + for (i = 0; i < h.numOffset; i++) { + const char * currentfile = filedata + h.offsets[i]; + size = DEVIL1PLD.sizeofsector(&h, i, filesize); + if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0) + sprintf(fn, "%s_%d.txp", filename, i); + else + sprintf(fn, "%s_%d", filename, i); + write(fn, currentfile, size); + } + free(fn); + return true; +} int main(int argc, char ** argv) { char *f = argv[1]; diff --git a/demo/texture.c b/demo/texture.c index 5cc1004..6645c1a 100644 --- a/demo/texture.c +++ b/demo/texture.c @@ -1,5 +1,5 @@ #include "common.h" - +#include "devil1tex.h" void exporttextures(const char *filedata, unsigned int filesize,