diff --git a/include/devil1pld.h b/include/devil1pld.h index 5de204f..ef6abac 100644 --- a/include/devil1pld.h +++ b/include/devil1pld.h @@ -17,8 +17,8 @@ typedef struct { bool (* const getheader) (struct PldHeader*, const char*); int (* const sizeofsector)(struct PldHeader*, unsigned int, unsigned int); void (* const printheader) (struct PldHeader*); -} namespace_struct; -extern namespace_struct const DEVIL1PLD; +} fn_devil1pld; +extern fn_devil1pld const DEVIL1PLD; // input: pointer to a struct, contents of the .pld file. // * = pass by reference of a struct PldHeader diff --git a/include/devil1tex.h b/include/devil1tex.h index db19345..bc37674 100644 --- a/include/devil1tex.h +++ b/include/devil1tex.h @@ -38,32 +38,50 @@ struct TextureBatch { #pragma pack(pop) +typedef struct { + void (* const printheader) (struct TexturePack*); + void (* const printbatchdesc)(struct TextureBatchDescriptor*); + bool (* const getbatchdesc) (struct TextureBatchDescriptor**, + unsigned int, + const char *, + unsigned int); + bool (* const getbatch) (struct TextureBatch**, + unsigned int, + const char*, + unsigned int); + bool (* const gettextures) (struct Texture*, + unsigned int, + const char*, + const unsigned int); +} fn_devil1tex; +extern fn_devil1tex const DEVIL1TEX; + // -------------------------------------------------------+ // Functions // -------------------------------------------------------+ // Print Texture Pack Header. -void printtph(struct TexturePack*); +static void printtph(struct TexturePack*); // Print Texture Batch Descriptor. -void printtbd(struct TextureBatchDescriptor*); +static void printtbd(struct TextureBatchDescriptor*); // Get Texture Batch Descriptor. // ** = 'pass by reference' of a pointer to struct -bool gettexdescriptor(struct TextureBatchDescriptor**, +static bool gettexdescriptor(struct TextureBatchDescriptor**, unsigned int, const char *, unsigned int); // Get Texture Batch. // ** = 'pass by reference' of a pointer to struct -bool gettexbatch(struct TextureBatch**, +static bool gettexbatch(struct TextureBatch**, unsigned int, const char*, unsigned int); // Unpack Texture Batch -bool unpacktexbatch(struct Texture*, +static bool unpacktexbatch(struct Texture*, unsigned int, const char*, const unsigned int); diff --git a/src/devil1pld.c b/src/devil1pld.c index d29aafe..3e3d96f 100644 --- a/src/devil1pld.c +++ b/src/devil1pld.c @@ -1,7 +1,7 @@ #include "devil1pld.h" #include -namespace_struct const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh}; +fn_devil1pld const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh}; static bool getpldh(struct PldHeader *ph, const char *filedata) { bool good = false; diff --git a/src/devil1tex.c b/src/devil1tex.c index 486f068..ed1417d 100644 --- a/src/devil1tex.c +++ b/src/devil1tex.c @@ -2,7 +2,13 @@ #include #include -void printtph (struct TexturePack *tp) { +fn_devil1tex const DEVIL1TEX = {printtph, + printtbd, + gettexdescriptor, + gettexbatch, + unpacktexbatch}; + +static void printtph (struct TexturePack *tp) { if (tp != NULL) { printf("id: \t %c %c %c %c \n", tp -> id[3], tp -> id[2], @@ -15,7 +21,7 @@ void printtph (struct TexturePack *tp) { return; } -void printtbd(struct TextureBatchDescriptor *bd) { +static void printtbd(struct TextureBatchDescriptor *bd) { if (bd != NULL) { printf("batch index: \t %i \n", bd -> batchIdx); printf("hash: \t %u \n", bd -> hash); @@ -23,7 +29,7 @@ void printtbd(struct TextureBatchDescriptor *bd) { } } -bool gettexdescriptor(struct TextureBatchDescriptor **descriptor, +static bool gettexdescriptor(struct TextureBatchDescriptor **descriptor, unsigned int i, const char *filedata, unsigned int filesize) { @@ -38,7 +44,7 @@ bool gettexdescriptor(struct TextureBatchDescriptor **descriptor, return done; } -bool gettexbatch(struct TextureBatch **batch, +static bool gettexbatch(struct TextureBatch **batch, unsigned int i, const char *filedata, unsigned int filesize) { @@ -67,7 +73,7 @@ bool gettexbatch(struct TextureBatch **batch, return true; } -bool unpacktexbatch(struct Texture *t, +static bool unpacktexbatch(struct Texture *t, unsigned int i, const char *filedata, const unsigned int filesize) { diff --git a/test/main.c b/test/main.c index 0b685da..ddef757 100644 --- a/test/main.c +++ b/test/main.c @@ -102,10 +102,10 @@ void exporttextures(const char *filedata, unsigned int j; unsigned int id = 0; for (i = 0; i < p -> batchNumber; i++) { - gettexdescriptor(&d, i, filedata, filesize); + DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize); t = (struct Texture*) malloc(sizeof(struct Texture) * (d -> texNumber)); - unpacktexbatch(t, i, filedata, filesize); + 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); @@ -144,8 +144,8 @@ int main(int argc, char ** argv) { unsigned int bufsize = 0; char *buffer = loadfile(f, &bufsize); // unpackpld(buffer, bufsize, f); -// exporttextures(buffer, bufsize, f); - extractmeshes(buffer, bufsize, f); + exporttextures(buffer, bufsize, f); +// extractmeshes(buffer, bufsize, f); free(buffer); return 0; }