mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-29 10:12:02 +05:30
Merge branch 'scuti/namespaces' of scuti/lib3ddevil1 into master
This commit is contained in:
commit
daaf0a36e2
@ -72,20 +72,40 @@ struct Mesh {
|
||||
|
||||
#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
|
||||
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
|
||||
|
||||
|
@ -13,16 +13,24 @@ struct PldHeader {
|
||||
|
||||
#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.
|
||||
// * = 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
|
||||
// * = 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.
|
||||
// * = pass by reference of a struct PldHeader
|
||||
void printpldh(struct PldHeader*);
|
||||
static void printpldh(struct PldHeader*);
|
||||
|
||||
|
||||
#endif
|
@ -38,32 +38,50 @@ struct TextureBatch {
|
||||
|
||||
#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
|
||||
// -------------------------------------------------------+
|
||||
|
||||
// Print Texture Pack Header.
|
||||
void printtph(struct TexturePack*);
|
||||
static void printtph(struct TexturePack*);
|
||||
|
||||
// Print Texture Batch Descriptor.
|
||||
void printtbd(struct TextureBatchDescriptor*);
|
||||
static void printtbd(struct TextureBatchDescriptor*);
|
||||
|
||||
// Get Texture Batch Descriptor.
|
||||
// ** = 'pass by reference' of a pointer to struct
|
||||
bool gettexdescriptor(struct TextureBatchDescriptor**,
|
||||
static bool gettexdescriptor(struct TextureBatchDescriptor**,
|
||||
unsigned int,
|
||||
const char *,
|
||||
unsigned int);
|
||||
|
||||
// Get Texture Batch.
|
||||
// ** = 'pass by reference' of a pointer to struct
|
||||
bool gettexbatch(struct TextureBatch**,
|
||||
static bool gettexbatch(struct TextureBatch**,
|
||||
unsigned int,
|
||||
const char*,
|
||||
unsigned int);
|
||||
|
||||
// Unpack Texture Batch
|
||||
bool unpacktexbatch(struct Texture*,
|
||||
static bool unpacktexbatch(struct Texture*,
|
||||
unsigned int,
|
||||
const char*,
|
||||
const unsigned int);
|
||||
|
@ -1,7 +1,15 @@
|
||||
#include "devil1geo.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) {
|
||||
printf("pointer %x\n", gh);
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -24,7 +32,7 @@ void printmeshheader(struct MeshHeader *mh) {
|
||||
printf("flags %x\n\n", mh -> flags);
|
||||
}
|
||||
|
||||
void printmeshbatch(struct Batch *b) {
|
||||
static void printmeshbatch(struct Batch *b) {
|
||||
if (b == NULL) {
|
||||
return;
|
||||
}
|
||||
@ -41,7 +49,7 @@ void printmeshbatch(struct Batch *b) {
|
||||
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) {
|
||||
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,
|
||||
const char * const filedata) {
|
||||
bool done = false;
|
||||
@ -68,7 +76,7 @@ bool getmeshheader(struct MeshHeader **hs,
|
||||
return done;
|
||||
}
|
||||
|
||||
bool getmeshbatch(struct Batch *b,
|
||||
static bool getmeshbatch(struct Batch *b,
|
||||
unsigned int offset,
|
||||
const char * const filedata) {
|
||||
bool done = false;
|
||||
@ -90,7 +98,7 @@ bool getmeshbatch(struct Batch *b,
|
||||
}
|
||||
|
||||
// assume client has allocated memory for mesh
|
||||
bool getmesh(struct Mesh *m,
|
||||
static bool getmesh(struct Mesh *m,
|
||||
unsigned int i,
|
||||
const char * const filedata) {
|
||||
bool done = false;
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "devil1pld.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;
|
||||
if (ph != NULL && filedata != NULL) {
|
||||
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
|
||||
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;
|
||||
if (ph == NULL) {
|
||||
fprintf(stderr, "Error: given null pointer\n");
|
||||
@ -29,7 +31,7 @@ int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) {
|
||||
return size;
|
||||
}
|
||||
|
||||
void printpldh(struct PldHeader *ph) {
|
||||
static void printpldh(struct PldHeader *ph) {
|
||||
if (ph == NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -2,7 +2,13 @@
|
||||
#include <stdio.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) {
|
||||
printf("id: \t %c %c %c %c \n", tp -> id[3],
|
||||
tp -> id[2],
|
||||
@ -15,7 +21,7 @@ void printtph (struct TexturePack *tp) {
|
||||
return;
|
||||
}
|
||||
|
||||
void printtbd(struct TextureBatchDescriptor *bd) {
|
||||
static void printtbd(struct TextureBatchDescriptor *bd) {
|
||||
if (bd != NULL) {
|
||||
printf("batch index: \t %i \n", bd -> batchIdx);
|
||||
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,
|
||||
const char *filedata,
|
||||
unsigned int filesize) {
|
||||
@ -38,7 +44,7 @@ bool gettexdescriptor(struct TextureBatchDescriptor **descriptor,
|
||||
return done;
|
||||
}
|
||||
|
||||
bool gettexbatch(struct TextureBatch **batch,
|
||||
static bool gettexbatch(struct TextureBatch **batch,
|
||||
unsigned int i,
|
||||
const char *filedata,
|
||||
unsigned int filesize) {
|
||||
@ -67,7 +73,7 @@ bool gettexbatch(struct TextureBatch **batch,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool unpacktexbatch(struct Texture *t,
|
||||
static bool unpacktexbatch(struct Texture *t,
|
||||
unsigned int i,
|
||||
const char *filedata,
|
||||
const unsigned int filesize) {
|
||||
|
12
test/main.c
12
test/main.c
@ -67,7 +67,7 @@ bool unpackpld(const char *filedata,
|
||||
return false;
|
||||
}
|
||||
struct PldHeader h;
|
||||
getpldh(&h, filedata);
|
||||
DEVIL1PLD.getheader(&h, filedata);
|
||||
char *fn = NULL;
|
||||
fn = (char*)malloc(strlen(filename) + 3 + 4);
|
||||
int size = 0;
|
||||
@ -75,7 +75,7 @@ bool unpackpld(const char *filedata,
|
||||
char textureid[TYPE_ID_LENGTH] = {'\0', '2', '3', 'T'};
|
||||
for (i = 0; i < h.numOffset; 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)
|
||||
sprintf(fn, "%s_%d.txp", filename, i);
|
||||
else
|
||||
@ -102,10 +102,10 @@ void exporttextures(const char *filedata,
|
||||
unsigned int j;
|
||||
unsigned int id = 0;
|
||||
for (i = 0; i < p -> batchNumber; i++) {
|
||||
gettexdescriptor(&d, i, filedata, filesize);
|
||||
DEVIL1TEX.getbatchdesc(&d, i, filedata, filesize);
|
||||
t = (struct Texture*)
|
||||
malloc(sizeof(struct Texture) * (d -> texNumber));
|
||||
unpacktexbatch(t, i, filedata, filesize);
|
||||
DEVIL1TEX.gettextures(t, i, filedata, filesize);
|
||||
for (j = 0; j < d -> texNumber; j++) {
|
||||
sprintf(fmt, "%s_%d.dds", filename, id);
|
||||
write(fmt, t[j].data, d -> textureSize);
|
||||
@ -129,10 +129,10 @@ void extractmeshes(const char *filedata,
|
||||
m.b = NULL;
|
||||
unsigned int 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));
|
||||
if (m.b != NULL) {
|
||||
getmesh(&m, i, filedata);
|
||||
DEVIL1GEO.getmesh(&m, i, filedata);
|
||||
// do something with mesh e.g write to file.
|
||||
free(m.b);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user