Merge branch 'feature/getheaderfns' of scuti/lib3ddevil1 into feature/pythonbinding

This commit is contained in:
suhrke 2018-04-23 18:44:58 -07:00 committed by Gitea
commit a12140f4ac
7 changed files with 45 additions and 12 deletions

View File

@ -65,6 +65,10 @@ class Devil1TEX_FN(ctypes.Structure):
("printbatchdesc", ctypes.CFUNCTYPE( ("printbatchdesc", ctypes.CFUNCTYPE(
None, None,
ctypes.POINTER(TextureBatchDescriptor))), ctypes.POINTER(TextureBatchDescriptor))),
("getheader", ctypes.CFUNCTYPE(
ctypes.c_bool,
ctypes.POINTER(ctypes.POINTER(TexturePack)),
ctypes.c_char_p)),
("getbatchdesc", ctypes.CFUNCTYPE( ("getbatchdesc", ctypes.CFUNCTYPE(
ctypes.c_bool, ctypes.c_bool,
ctypes.POINTER(TextureBatchDescriptor), ctypes.POINTER(TextureBatchDescriptor),
@ -179,6 +183,10 @@ class Devil1GEO_FN(ctypes.Structure):
("printcoordinate", ctypes.CFUNCTYPE( ("printcoordinate", ctypes.CFUNCTYPE(
None, None,
ctypes.POINTER(Coordinate))), ctypes.POINTER(Coordinate))),
("getheader", ctypes.CFUNCTYPE(
None,
ctypes.POINTER(ctypes.POINTER(Header)),
ctypes.c_char_p)),
("getmeshheader", ctypes.CFUNCTYPE( ("getmeshheader", ctypes.CFUNCTYPE(
ctypes.c_bool, ctypes.c_bool,
ctypes.POINTER(MeshHeader), ctypes.POINTER(MeshHeader),

View File

@ -59,10 +59,10 @@ void writemesh(const struct MeshHeader *mh,
void extractmeshes(const char *filedata, void extractmeshes(const char *filedata,
const char *filename, const char *filename,
unsigned int filesize) { unsigned int filesize) {
if (filedata == NULL || filesize <= 0) { struct Header *h = NULL;
if (!(DEVIL1GEO.getheader(&h, filedata))|| filesize <= 0) {
return; return;
} }
struct Header *h = (struct Header*)filedata;
struct MeshHeader *mh = NULL; struct MeshHeader *mh = NULL;
struct Mesh m; struct Mesh m;
m.b = NULL; m.b = NULL;

View File

@ -8,10 +8,9 @@ void extracttextures(const char *filedata,
struct Texture *t = NULL; struct Texture *t = NULL;
struct TextureBatchDescriptor *d = NULL; struct TextureBatchDescriptor *d = NULL;
char * fmt = NULL; char * fmt = NULL;
if (filedata == NULL || filesize == 0) { if (!(DEVIL1TEX.getheader(&p, filedata)) || filesize == 0) {
return; return;
} }
p = (struct TexturePack*)filedata;
fmt = (char*)malloc(strlen(filename) + 3 + 4); fmt = (char*)malloc(strlen(filename) + 3 + 4);
unsigned int i; unsigned int i;
unsigned int j; unsigned int j;

View File

@ -85,6 +85,9 @@ typedef struct {
// input: pointer to struct // input: pointer to struct
void (* const printcoordinate)(struct Coordinate*, unsigned int); void (* const printcoordinate)(struct Coordinate*, unsigned int);
// input: pointer to struct, file data
bool (* const getheader) (struct Header**, const char*);
// input: pointer of pointer to struct, order, file data // input: pointer of pointer to struct, order, file data
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct
bool (* const getmeshheader) (struct MeshHeader**, bool (* const getmeshheader) (struct MeshHeader**,
@ -96,11 +99,11 @@ typedef struct {
unsigned int offset, unsigned int offset,
const char * const); const char * const);
// input: pointer to struct, order, file data // input: pointer to struct, order, file data, file size
bool (* const getmesh) (struct Mesh*, bool (* const getmesh) (struct Mesh*,
unsigned int i, unsigned int i,
const char*, const char*,
unsigned int filesize); unsigned int);
} fn_devil1geo; } fn_devil1geo;
extern fn_devil1geo const DEVIL1GEO; extern fn_devil1geo const DEVIL1GEO;

View File

@ -45,6 +45,9 @@ typedef struct {
// input: pointer to struct // input: pointer to struct
void (* const printbatchdesc)(struct TextureBatchDescriptor*); void (* const printbatchdesc)(struct TextureBatchDescriptor*);
// input: pointer to struct, file data
bool (* const getheader) (struct TexturePack**, const char*);
// input: pointer of pointer to struct, order, file data, file size // input: pointer of pointer to struct, order, file data, file size
// ** = 'pass by reference' of a pointer to struct // ** = 'pass by reference' of a pointer to struct
bool (* const getbatchdesc) (struct TextureBatchDescriptor**, bool (* const getbatchdesc) (struct TextureBatchDescriptor**,

View File

@ -9,6 +9,7 @@ static void printmeshbatch(struct Batch*);
static void printcoordinate(struct Coordinate*, unsigned int); static void printcoordinate(struct Coordinate*, unsigned int);
static bool getgheader(struct Header**, const char*);
static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const); static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
@ -20,6 +21,7 @@ fn_devil1geo const DEVIL1GEO = {printgheader,
printmeshheader, printmeshheader,
printmeshbatch, printmeshbatch,
printcoordinate, printcoordinate,
getgheader,
getmeshheader, getmeshheader,
getmeshbatch, getmeshbatch,
getmesh}; getmesh};
@ -74,14 +76,22 @@ static void printcoordinate(struct Coordinate *p, unsigned int count) {
} }
} }
static bool getgheader(struct Header** h, const char* filedata) {
if (filedata == NULL) {
return false;
}
(*h) = (struct Header*)filedata;
return true;
}
static 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;
if (hs == NULL || filedata == NULL) { struct Header *h = NULL;
if (hs == NULL || !(getgheader(&h, filedata))) {
return done; return done;
} }
struct Header *h = (struct Header*)filedata;
if (h -> numMesh < i) { if (h -> numMesh < i) {
return done; return done;
} }

View File

@ -8,8 +8,10 @@ static void printtph(struct TexturePack*);
// Print Texture Batch Descriptor. // Print Texture Batch Descriptor.
static void printtbd(struct TextureBatchDescriptor*); static void printtbd(struct TextureBatchDescriptor*);
// Get Texture Batch Descriptor. // Get Texture Pack Header
static inline bool getpackheader(struct TexturePack**, const char*);
// Get Texture Batch Descriptor.
static bool gettexdescriptor(struct TextureBatchDescriptor**, static bool gettexdescriptor(struct TextureBatchDescriptor**,
unsigned int, unsigned int,
const char *, const char *,
@ -30,6 +32,7 @@ static bool unpacktexbatch(struct Texture*,
fn_devil1tex const DEVIL1TEX = {printtph, fn_devil1tex const DEVIL1TEX = {printtph,
printtbd, printtbd,
getpackheader,
gettexdescriptor, gettexdescriptor,
gettexbatch, gettexbatch,
unpacktexbatch}; unpacktexbatch};
@ -55,6 +58,14 @@ static void printtbd(struct TextureBatchDescriptor *bd) {
} }
} }
inline static bool getpackheader(struct TexturePack** p, const char *filedata) {
if (filedata == NULL) {
return false;
}
(*p) = (struct TexturePack*)filedata;
return true;
}
static bool gettexdescriptor(struct TextureBatchDescriptor **descriptor, static bool gettexdescriptor(struct TextureBatchDescriptor **descriptor,
unsigned int i, unsigned int i,
const char *filedata, const char *filedata,
@ -75,10 +86,9 @@ static bool gettexbatch(struct TextureBatch **batch,
const char *filedata, const char *filedata,
unsigned int filesize) { unsigned int filesize) {
struct TexturePack *p = NULL; struct TexturePack *p = NULL;
if (filedata == NULL) { // no data to get batch from. if (!(getpackheader(&p, filedata))) {
return false; return false;
} }
p = (struct TexturePack*)filedata;
if (i > p -> batchNumber) { // no such batch in texture pack if (i > p -> batchNumber) { // no such batch in texture pack
return false; return false;
} }