From 8016deae86509f854e4f689faea830d5ad4bf5d8 Mon Sep 17 00:00:00 2001 From: <> Date: Sat, 7 Apr 2018 04:39:16 -0700 Subject: [PATCH] Moved out for loop & fixed getting mesh headers --- include/devil1geo.h | 4 +++- src/devil1geo.c | 42 ++++++++++++++++++++++++++++++++++++++++++ test/main.c | 16 +++++++--------- 3 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/devil1geo.c diff --git a/include/devil1geo.h b/include/devil1geo.h index 9f62e84..87bf242 100644 --- a/include/devil1geo.h +++ b/include/devil1geo.h @@ -71,7 +71,9 @@ struct Mesh { void printgheader(struct Header*); -bool getmeshheaders(struct MeshHeader **, const char *, unsigned int); +void printmeshheader(struct MeshHeader*); + +bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); #endif diff --git a/src/devil1geo.c b/src/devil1geo.c new file mode 100644 index 0000000..0cc7add --- /dev/null +++ b/src/devil1geo.c @@ -0,0 +1,42 @@ +#include "devil1geo.h" +#include + +void printgheader(struct Header *gh) { + if (gh != NULL) { + printf("pointer %x\n", gh); + printf("number of meshes %x\n", gh -> numMesh); + printf("unknown number B %x\n", gh -> unknownNumberB); + printf("unknown number C %x\n", gh -> unknownNumberC); + printf("unknown number D %x\n", gh -> unknownNumberD); + printf("padding %x\n", gh -> padding); + printf("unknown offset %x\n", gh -> unknownOffset); + } +} + +void printmeshheader(struct MeshHeader *mh) { + if (mh == NULL) { + return; + } + printf("number of batches %x\n", mh -> numBatch); + printf("number of vertices %x\n", mh -> numVertex); + printf("unknown %x\n", mh -> u); + printf("batch offset %x\n", mh -> offsetBatches); + printf("flags %x\n\n", mh -> flags); +} + +bool getmeshheader(struct MeshHeader **hs, + unsigned int i, + const char * const filedata) { + bool done = false; + if (hs == NULL || filedata == NULL) { + return done; + } + struct Header *h = (struct Header*)filedata; + if (h -> numMesh < i) { + return done; + } + unsigned int pos = sizeof(struct MeshHeader) * i + sizeof(struct Header); + (*hs) = (struct MeshHeader*)(filedata + pos); + done = true; + return done; +} diff --git a/test/main.c b/test/main.c index 6a89535..e008c14 100644 --- a/test/main.c +++ b/test/main.c @@ -111,17 +111,15 @@ void extractmeshes(const char* filedata, if (filedata == NULL || filesize <= 0) { return; } - struct Header *h = NULL; - h = (struct Header*)filedata; - printf("pointer %x\n", h); - printgheader(h); - struct MeshHeader **mh = NULL; - mh = (struct MeshHeader**) - malloc(sizeof(struct MeshHeader*) * h -> numMesh); - getmeshheaders(mh, filedata, filesize); + struct Header *h = (struct Header*)filedata; + struct MeshHeader *mh = NULL; unsigned int i; + bool ok; for (i = 0; i < h -> numMesh; i++) { - printf("returning %x \n", mh[i]); + ok = getmeshheader(&mh, i, filedata); + if (ok) { + printmeshheader(mh); + } } }