mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Added namespace structs for pld's
This commit is contained in:
parent
7964563396
commit
9bfc125158
@ -15,14 +15,21 @@ struct PldHeader {
|
||||
|
||||
// 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
|
||||
typedef struct {
|
||||
bool (* const getheader) (struct PldHeader*, const char*);
|
||||
int (* const sizeofsector)(struct PldHeader*, unsigned int, unsigned int);
|
||||
void (* const printheader) (struct PldHeader*);
|
||||
} namespace_struct;
|
||||
extern namespace_struct const DEVIL1PLD;
|
||||
|
||||
#endif
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "devil1pld.h"
|
||||
#include <stdio.h>
|
||||
|
||||
bool getpldh(struct PldHeader *ph, const char *filedata) {
|
||||
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 +12,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 +29,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;
|
||||
}
|
||||
@ -40,3 +40,5 @@ void printpldh(struct PldHeader *ph) {
|
||||
printf("offset %i = %x\n", i, ph -> offsets[i]);
|
||||
}
|
||||
}
|
||||
|
||||
namespace_struct const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh};
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user