diff --git a/include/devil1geo.h b/include/devil1geo.h index 048b5e1..00375ad 100644 --- a/include/devil1geo.h +++ b/include/devil1geo.h @@ -72,20 +72,40 @@ struct Mesh { #pragma pack(pop) -void printgheader(struct Header*); +typedef struct { + void (* const printheader) (struct Header*); + void (* const printmeshheader)(struct MeshHeader*); + void (* const printbatch) (struct Batch*); + void (* const printcoordinate)(struct Coordinate*, unsigned int); -void printmeshheader(struct MeshHeader*); + bool (* const getmeshheader) (struct MeshHeader**, + unsigned int i, + const char * const); -void printmeshbatch(struct Batch*); + bool (* const getbatch) (struct Batch*, + unsigned int offset, + const char * const); -void printcoordinate(struct Coordinate*, unsigned int); + bool (* const getmesh) (struct Mesh*, + unsigned int i, + const char* filename); +} fn_devil1geo; +extern fn_devil1geo const DEVIL1GEO; + +static void printgheader(struct Header*); + +static void printmeshheader(struct MeshHeader*); + +static void printmeshbatch(struct Batch*); + +static void printcoordinate(struct Coordinate*, unsigned int); // ** = 'pass by reference' of a pointer to struct -bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); +static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); -bool getmeshbatch(struct Batch*, unsigned int offset, const char * const); +static bool getmeshbatch(struct Batch*, unsigned int offset, const char * const); -bool getmesh(struct Mesh*, unsigned int i, const char* filename); +static bool getmesh(struct Mesh*, unsigned int i, const char* filename); #endif diff --git a/src/devil1geo.c b/src/devil1geo.c index 401eafe..bf3cfb2 100644 --- a/src/devil1geo.c +++ b/src/devil1geo.c @@ -1,7 +1,15 @@ #include "devil1geo.h" #include -void printgheader(struct Header *gh) { +fn_devil1geo const DEVIL1GEO = {printgheader, + printmeshheader, + printmeshbatch, + printcoordinate, + getmeshheader, + getmeshbatch, + getmesh}; + +static void printgheader(struct Header *gh) { if (gh != NULL) { printf("pointer %x\n", gh); printf("number of meshes %x\n", gh -> numMesh); @@ -13,7 +21,7 @@ void printgheader(struct Header *gh) { } } -void printmeshheader(struct MeshHeader *mh) { +static void printmeshheader(struct MeshHeader *mh) { if (mh == NULL) { return; } @@ -24,7 +32,7 @@ void printmeshheader(struct MeshHeader *mh) { printf("flags %x\n\n", mh -> flags); } -void printmeshbatch(struct Batch *b) { +static void printmeshbatch(struct Batch *b) { if (b == NULL) { return; } @@ -41,7 +49,7 @@ void printmeshbatch(struct Batch *b) { printcoordinate(b -> vd.positions, 3); } -void printcoordinate(struct Coordinate *p, unsigned int count) { +static void printcoordinate(struct Coordinate *p, unsigned int count) { if (p == NULL) { return; } @@ -51,7 +59,7 @@ void printcoordinate(struct Coordinate *p, unsigned int count) { } } -bool getmeshheader(struct MeshHeader **hs, +static bool getmeshheader(struct MeshHeader **hs, unsigned int i, const char * const filedata) { bool done = false; @@ -68,7 +76,7 @@ bool getmeshheader(struct MeshHeader **hs, return done; } -bool getmeshbatch(struct Batch *b, +static bool getmeshbatch(struct Batch *b, unsigned int offset, const char * const filedata) { bool done = false; @@ -90,7 +98,7 @@ bool getmeshbatch(struct Batch *b, } // assume client has allocated memory for mesh -bool getmesh(struct Mesh *m, +static bool getmesh(struct Mesh *m, unsigned int i, const char * const filedata) { bool done = false; diff --git a/test/main.c b/test/main.c index ddef757..ab0cb5d 100644 --- a/test/main.c +++ b/test/main.c @@ -129,10 +129,10 @@ void extractmeshes(const char *filedata, m.b = NULL; unsigned int i; for (i = 0; i < h -> numMesh; i++) { - getmeshheader(&mh, i, filedata); + DEVIL1GEO.getmeshheader(&mh, i, filedata); m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch)); if (m.b != NULL) { - getmesh(&m, i, filedata); + DEVIL1GEO.getmesh(&m, i, filedata); // do something with mesh e.g write to file. free(m.b); } @@ -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; }