mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
Add namespace structs for geometry
This commit is contained in:
parent
48f255eb36
commit
6babd59d56
@ -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
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
@ -144,8 +144,8 @@ int main(int argc, char ** argv) {
|
|||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buffer = loadfile(f, &bufsize);
|
char *buffer = loadfile(f, &bufsize);
|
||||||
// unpackpld(buffer, bufsize, f);
|
// unpackpld(buffer, bufsize, f);
|
||||||
exporttextures(buffer, bufsize, f);
|
// exporttextures(buffer, bufsize, f);
|
||||||
// extractmeshes(buffer, bufsize, f);
|
extractmeshes(buffer, bufsize, f);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user