From 6f915237b4e750cdffbc0d758ffc3d9618668c3a Mon Sep 17 00:00:00 2001 From: _ <_> Date: Wed, 4 Apr 2018 22:14:45 -0700 Subject: [PATCH] Moved loop to its own function - gettextures() --- include/devil1tex.h | 6 ++++++ src/devil1tex.c | 19 +++++++++++++++++++ test/main.c | 14 +------------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/include/devil1tex.h b/include/devil1tex.h index 46183ef..1ae8377 100644 --- a/include/devil1tex.h +++ b/include/devil1tex.h @@ -51,4 +51,10 @@ unsigned int gettexturebatch( struct TextureBatchDescriptor**, const char*, unsigned int); + +void gettextures(struct Texture **, + struct TexturePack*, + struct TextureBatch**, + struct TextureBatchDescriptor**); + #endif diff --git a/src/devil1tex.c b/src/devil1tex.c index 0b5f91e..1729cce 100644 --- a/src/devil1tex.c +++ b/src/devil1tex.c @@ -83,3 +83,22 @@ unsigned int gettexturebatch( return totaltextures; } +void gettextures(struct Texture **t, + struct TexturePack *tp, + struct TextureBatch **tb, + struct TextureBatchDescriptor **bds) { + unsigned int i; + unsigned int j; + // k is access to index of textures. + unsigned int k = 0; + unsigned int offset = 0; + for (i = 0; i < tp -> batchNumber; i++) { + for (j = 0; j < bds[i] -> texNumber; j++) { + printf("texture offsets %x\n", offset + tp -> firstBatchOffset); + t[k] = (struct Texture*)tb + offset; + offset += bds[i] -> textureSize; + k++; + } + } +} + diff --git a/test/main.c b/test/main.c index 2279796..b86d540 100644 --- a/test/main.c +++ b/test/main.c @@ -126,19 +126,7 @@ void unpacktextures(const char *filedata, struct Texture **textures = NULL; textures = (struct Texture**)malloc( sizeof(struct Texture**) * texturecount); - unsigned int i; - unsigned int j; - // k is access to index of textures. - unsigned int k = 0; - unsigned int offset = 0; - for (i = 0; i < tp -> batchNumber; i++) { - for (j = 0; j < descripts[i] -> texNumber; j++) { - printf("texture offsets %x\n", offset + tp -> firstBatchOffset); - textures[k] = (struct Texture*)batches + offset; - offset += descripts[i] -> textureSize; - k++; - } - } + gettextures(textures, tp, batches, descripts); free(textures); free(descripts); free(batches);