Merge branch 'scuti/namespaces' of scuti/lib3ddevil1 into master

This commit is contained in:
scuti 2018-04-17 20:34:20 -07:00 committed by Gitea
commit daaf0a36e2
7 changed files with 99 additions and 37 deletions

View File

@ -72,20 +72,40 @@ struct Mesh {
#pragma pack(pop) #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 // ** = '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 #endif

View File

@ -13,16 +13,24 @@ struct PldHeader {
#pragma pack(pop) #pragma pack(pop)
typedef struct {
bool (* const getheader) (struct PldHeader*, const char*);
int (* const sizeofsector)(struct PldHeader*, unsigned int, unsigned int);
void (* const printheader) (struct PldHeader*);
} fn_devil1pld;
extern fn_devil1pld const DEVIL1PLD;
// input: pointer to a struct, contents of the .pld file. // input: pointer to a struct, contents of the .pld file.
// * = pass by reference of a struct PldHeader // * = pass by reference of a struct PldHeader
bool getpldh(struct PldHeader*, const char*); static bool getpldh(struct PldHeader*, const char*);
// input: pointer to header, index of offset, filesize // input: pointer to header, index of offset, filesize
// * = pass by reference of a struct PldHeader // * = pass by reference of a struct PldHeader
int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int); static int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int);
// input: a pld header struct. // input: a pld header struct.
// * = pass by reference of a struct PldHeader // * = pass by reference of a struct PldHeader
void printpldh(struct PldHeader*); static void printpldh(struct PldHeader*);
#endif
#endif

View File

@ -38,32 +38,50 @@ struct TextureBatch {
#pragma pack(pop) #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 // Functions
// -------------------------------------------------------+ // -------------------------------------------------------+
// Print Texture Pack Header. // Print Texture Pack Header.
void printtph(struct TexturePack*); static void printtph(struct TexturePack*);
// Print Texture Batch Descriptor. // Print Texture Batch Descriptor.
void printtbd(struct TextureBatchDescriptor*); static void printtbd(struct TextureBatchDescriptor*);
// Get Texture Batch Descriptor. // Get Texture Batch Descriptor.
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct
bool gettexdescriptor(struct TextureBatchDescriptor**, static bool gettexdescriptor(struct TextureBatchDescriptor**,
unsigned int, unsigned int,
const char *, const char *,
unsigned int); unsigned int);
// Get Texture Batch. // Get Texture Batch.
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct
bool gettexbatch(struct TextureBatch**, static bool gettexbatch(struct TextureBatch**,
unsigned int, unsigned int,
const char*, const char*,
unsigned int); unsigned int);
// Unpack Texture Batch // Unpack Texture Batch
bool unpacktexbatch(struct Texture*, static bool unpacktexbatch(struct Texture*,
unsigned int, unsigned int,
const char*, const char*,
const unsigned int); const unsigned int);

View File

@ -1,7 +1,15 @@
#include "devil1geo.h" #include "devil1geo.h"
#include <stdio.h> #include <stdio.h>
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) { if (gh != NULL) {
printf("pointer %x\n", gh); printf("pointer %x\n", gh);
printf("number of meshes %x\n", gh -> numMesh); 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) { if (mh == NULL) {
return; return;
} }
@ -24,7 +32,7 @@ void printmeshheader(struct MeshHeader *mh) {
printf("flags %x\n\n", mh -> flags); printf("flags %x\n\n", mh -> flags);
} }
void printmeshbatch(struct Batch *b) { static void printmeshbatch(struct Batch *b) {
if (b == NULL) { if (b == NULL) {
return; return;
} }
@ -41,7 +49,7 @@ void printmeshbatch(struct Batch *b) {
printcoordinate(b -> vd.positions, 3); 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) { if (p == NULL) {
return; 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, unsigned int i,
const char * const filedata) { const char * const filedata) {
bool done = false; bool done = false;
@ -68,7 +76,7 @@ bool getmeshheader(struct MeshHeader **hs,
return done; return done;
} }
bool getmeshbatch(struct Batch *b, static bool getmeshbatch(struct Batch *b,
unsigned int offset, unsigned int offset,
const char * const filedata) { const char * const filedata) {
bool done = false; bool done = false;
@ -90,7 +98,7 @@ bool getmeshbatch(struct Batch *b,
} }
// assume client has allocated memory for mesh // assume client has allocated memory for mesh
bool getmesh(struct Mesh *m, static bool getmesh(struct Mesh *m,
unsigned int i, unsigned int i,
const char * const filedata) { const char * const filedata) {
bool done = false; bool done = false;

View File

@ -1,7 +1,9 @@
#include "devil1pld.h" #include "devil1pld.h"
#include <stdio.h> #include <stdio.h>
bool getpldh(struct PldHeader *ph, const char *filedata) { fn_devil1pld const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh};
static bool getpldh(struct PldHeader *ph, const char *filedata) {
bool good = false; bool good = false;
if (ph != NULL && filedata != NULL) { if (ph != NULL && filedata != NULL) {
ph -> numOffset = (int32_t)filedata[0]; ph -> numOffset = (int32_t)filedata[0];
@ -12,7 +14,7 @@ bool getpldh(struct PldHeader *ph, const char *filedata) {
} }
// determine the size of the i-th pld structure // determine the size of the i-th pld structure
int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) { static int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) {
unsigned int size = -1; unsigned int size = -1;
if (ph == NULL) { if (ph == NULL) {
fprintf(stderr, "Error: given null pointer\n"); fprintf(stderr, "Error: given null pointer\n");
@ -29,7 +31,7 @@ int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) {
return size; return size;
} }
void printpldh(struct PldHeader *ph) { static void printpldh(struct PldHeader *ph) {
if (ph == NULL) { if (ph == NULL) {
return; return;
} }

View File

@ -2,7 +2,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
void printtph (struct TexturePack *tp) { fn_devil1tex const DEVIL1TEX = {printtph,
printtbd,
gettexdescriptor,
gettexbatch,
unpacktexbatch};
static void printtph (struct TexturePack *tp) {
if (tp != NULL) { if (tp != NULL) {
printf("id: \t %c %c %c %c \n", tp -> id[3], printf("id: \t %c %c %c %c \n", tp -> id[3],
tp -> id[2], tp -> id[2],
@ -15,7 +21,7 @@ void printtph (struct TexturePack *tp) {
return; return;
} }
void printtbd(struct TextureBatchDescriptor *bd) { static void printtbd(struct TextureBatchDescriptor *bd) {
if (bd != NULL) { if (bd != NULL) {
printf("batch index: \t %i \n", bd -> batchIdx); printf("batch index: \t %i \n", bd -> batchIdx);
printf("hash: \t %u \n", bd -> hash); 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, unsigned int i,
const char *filedata, const char *filedata,
unsigned int filesize) { unsigned int filesize) {
@ -38,7 +44,7 @@ bool gettexdescriptor(struct TextureBatchDescriptor **descriptor,
return done; return done;
} }
bool gettexbatch(struct TextureBatch **batch, static bool gettexbatch(struct TextureBatch **batch,
unsigned int i, unsigned int i,
const char *filedata, const char *filedata,
unsigned int filesize) { unsigned int filesize) {
@ -67,7 +73,7 @@ bool gettexbatch(struct TextureBatch **batch,
return true; return true;
} }
bool unpacktexbatch(struct Texture *t, static bool unpacktexbatch(struct Texture *t,
unsigned int i, unsigned int i,
const char *filedata, const char *filedata,
const unsigned int filesize) { const unsigned int filesize) {

View File

@ -67,7 +67,7 @@ bool unpackpld(const char *filedata,
return false; return false;
} }
struct PldHeader h; struct PldHeader h;
getpldh(&h, filedata); DEVIL1PLD.getheader(&h, filedata);
char *fn = NULL; char *fn = NULL;
fn = (char*)malloc(strlen(filename) + 3 + 4); fn = (char*)malloc(strlen(filename) + 3 + 4);
int size = 0; int size = 0;
@ -75,7 +75,7 @@ bool unpackpld(const char *filedata,
char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'}; char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'};
for (i = 0; i < h.numOffset; i++) { for (i = 0; i < h.numOffset; i++) {
const char * currentfile = filedata + h.offsets[i]; const char * currentfile = filedata + h.offsets[i];
size = sizeofpldstruct(&h, i, filesize); size = DEVIL1PLD.sizeofsector(&h, i, filesize);
if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0) if (strncmp( currentfile, textureid, TYPE_ID_LENGTH ) == 0)
sprintf(fn, "%s_%d.txp", filename, i); sprintf(fn, "%s_%d.txp", filename, i);
else else
@ -102,10 +102,10 @@ void exporttextures(const char *filedata,
unsigned int j; unsigned int j;
unsigned int id = 0; unsigned int id = 0;
for (i = 0; i < p -> batchNumber; i++) { for (i = 0; i < p -> batchNumber; i++) {
gettexdescriptor(&d, i, filedata, filesize); DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
t = (struct Texture*) t = (struct Texture*)
malloc(sizeof(struct Texture) * (d -> texNumber)); malloc(sizeof(struct Texture) * (d -> texNumber));
unpacktexbatch(t, i, filedata, filesize); DEVIL1TEX.gettextures(t, i, filedata, filesize);
for (j = 0; j < d -> texNumber; j++) { for (j = 0; j < d -> texNumber; j++) {
sprintf(fmt, "%s_%d.dds", filename, id); sprintf(fmt, "%s_%d.dds", filename, id);
write(fmt, t[j].data, d -> textureSize); write(fmt, t[j].data, d -> textureSize);
@ -129,10 +129,10 @@ void extractmeshes(const char *filedata,
m.b = NULL; m.b = NULL;
unsigned int i; unsigned int i;
for (i = 0; i < h -> numMesh; 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)); m.b = (struct Batch*)malloc(sizeof(struct Batch) * (mh -> numBatch));
if (m.b != NULL) { if (m.b != NULL) {
getmesh(&m, i, filedata); DEVIL1GEO.getmesh(&m, i, filedata);
// do something with mesh e.g write to file. // do something with mesh e.g write to file.
free(m.b); free(m.b);
} }