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

This commit is contained in:
suhrke 2018-04-19 05:52:07 -07:00 committed by Gitea
commit 6afa14c124
8 changed files with 94 additions and 74 deletions

View File

@ -3,17 +3,17 @@ TEX=demo-extracttexture
MEX=demo-extractmesh MEX=demo-extractmesh
CC=gcc CC=gcc
CFLAGS= -I"include" CFLAGS= -I"include" -Wall
all: pld texture mesh all: pld texture mesh
pld: devil1pld.o devil1tex.o src/devil1geo.o pld: devil1pld.o devil1tex.o devil1geo.o
$(CC) $^ demo/extractpld.c $(CFLAGS) -o $(PEX) $(CC) $^ demo/extractpld.c $(CFLAGS) -o $(PEX)
texture: devil1pld.o devil1tex.o src/devil1geo.o texture: devil1pld.o devil1tex.o devil1geo.o
$(CC) $^ demo/extracttexture.c $(CFLAGS) -o $(TEX) $(CC) $^ demo/extracttexture.c $(CFLAGS) -o $(TEX)
mesh: devil1pld.o devil1tex.o src/devil1geo.o mesh: devil1pld.o devil1tex.o devil1geo.o
$(CC) $^ demo/extractmesh.c $(CFLAGS) -o $(MEX) $(CC) $^ demo/extractmesh.c $(CFLAGS) -o $(MEX)
devil1pld.o: src/devil1pld.c devil1pld.o: src/devil1pld.c

View File

@ -23,7 +23,7 @@ void extracttextures(const char *filedata,
DEVIL1TEX.gettextures(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, (char*)t[j].data, d -> textureSize);
id++; id++;
} }
free(t); free(t);

View File

@ -73,39 +73,35 @@ struct Mesh {
#pragma pack(pop) #pragma pack(pop)
typedef struct { typedef struct {
// input: pointer to struct
void (* const printheader) (struct Header*); void (* const printheader) (struct Header*);
// input: pointer to struct
void (* const printmeshheader)(struct MeshHeader*); void (* const printmeshheader)(struct MeshHeader*);
// input: pointer to struct
void (* const printbatch) (struct Batch*); void (* const printbatch) (struct Batch*);
// input: pointer to struct
void (* const printcoordinate)(struct Coordinate*, unsigned int); void (* const printcoordinate)(struct Coordinate*, unsigned int);
// input: pointer of pointer to struct, order, file data
// ** = 'pass by reference' of a pointer to struct
bool (* const getmeshheader) (struct MeshHeader**, bool (* const getmeshheader) (struct MeshHeader**,
unsigned int i, unsigned int i,
const char * const); const char * const);
// input: pointer to struct, offset of file data batch is at, file data
bool (* const getbatch) (struct Batch*, bool (* const getbatch) (struct Batch*,
unsigned int offset, unsigned int offset,
const char * const); const char * const);
// input: pointer to struct, order, file data
bool (* const getmesh) (struct Mesh*, bool (* const getmesh) (struct Mesh*,
unsigned int i, unsigned int i,
const char* filename); const char*);
} fn_devil1geo; } fn_devil1geo;
extern fn_devil1geo const 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
static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
static bool getmeshbatch(struct Batch*, unsigned int offset, const char * const);
static bool getmesh(struct Mesh*, unsigned int i, const char* filename);
#endif #endif

View File

@ -14,23 +14,19 @@ struct PldHeader {
#pragma pack(pop) #pragma pack(pop)
typedef struct { 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
static bool getpldh(struct PldHeader*, const char*); bool (* const getheader) (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
static int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int); int (* const sizeofsector)(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
static void printpldh(struct PldHeader*); void (* const printheader) (struct PldHeader*);
} fn_devil1pld;
extern fn_devil1pld const DEVIL1PLD;
#endif #endif

View File

@ -39,16 +39,27 @@ struct TextureBatch {
#pragma pack(pop) #pragma pack(pop)
typedef struct { typedef struct {
// input: pointer to struct
void (* const printheader) (struct TexturePack*); void (* const printheader) (struct TexturePack*);
// input: pointer to struct
void (* const printbatchdesc)(struct TextureBatchDescriptor*); void (* const printbatchdesc)(struct TextureBatchDescriptor*);
// input: pointer of pointer to struct, order, file data, file size
// ** = 'pass by reference' of a pointer to struct
bool (* const getbatchdesc) (struct TextureBatchDescriptor**, bool (* const getbatchdesc) (struct TextureBatchDescriptor**,
unsigned int, unsigned int,
const char *, const char *,
unsigned int); unsigned int);
// input: pointer of pointer to struct, order, file data, file size
// ** = 'pass by reference' of a pointer to struct
bool (* const getbatch) (struct TextureBatch**, bool (* const getbatch) (struct TextureBatch**,
unsigned int, unsigned int,
const char*, const char*,
unsigned int); unsigned int);
// input: pointer to struct, order, file data, file size
bool (* const gettextures) (struct Texture*, bool (* const gettextures) (struct Texture*,
unsigned int, unsigned int,
const char*, const char*,
@ -56,34 +67,4 @@ typedef struct {
} fn_devil1tex; } fn_devil1tex;
extern fn_devil1tex const DEVIL1TEX; extern fn_devil1tex const DEVIL1TEX;
// -------------------------------------------------------+
// Functions
// -------------------------------------------------------+
// Print Texture Pack Header.
static void printtph(struct TexturePack*);
// Print Texture Batch Descriptor.
static void printtbd(struct TextureBatchDescriptor*);
// Get Texture Batch Descriptor.
// ** = 'pass by reference' of a pointer to struct
static bool gettexdescriptor(struct TextureBatchDescriptor**,
unsigned int,
const char *,
unsigned int);
// Get Texture Batch.
// ** = 'pass by reference' of a pointer to struct
static bool gettexbatch(struct TextureBatch**,
unsigned int,
const char*,
unsigned int);
// Unpack Texture Batch
static bool unpacktexbatch(struct Texture*,
unsigned int,
const char*,
const unsigned int);
#endif #endif

View File

@ -1,6 +1,21 @@
#include "devil1geo.h" #include "devil1geo.h"
#include <stdio.h> #include <stdio.h>
static void printgheader(struct Header*);
static void printmeshheader(struct MeshHeader*);
static void printmeshbatch(struct Batch*);
static void printcoordinate(struct Coordinate*, unsigned int);
static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * const);
static bool getmeshbatch(struct Batch*, unsigned int offset, const char * const);
static bool getmesh(struct Mesh*, unsigned int i, const char*);
fn_devil1geo const DEVIL1GEO = {printgheader, fn_devil1geo const DEVIL1GEO = {printgheader,
printmeshheader, printmeshheader,
printmeshbatch, printmeshbatch,
@ -11,13 +26,13 @@ fn_devil1geo const DEVIL1GEO = {printgheader,
static void printgheader(struct Header *gh) { static void printgheader(struct Header *gh) {
if (gh != NULL) { if (gh != NULL) {
printf("pointer %x\n", gh); printf("pointer %p\n", gh);
printf("number of meshes %x\n", gh -> numMesh); printf("number of meshes %x\n", gh -> numMesh);
printf("unknown number B %x\n", gh -> unknownNumberB); printf("unknown number B %x\n", gh -> unknownNumberB);
printf("unknown number C %x\n", gh -> unknownNumberC); printf("unknown number C %x\n", gh -> unknownNumberC);
printf("unknown number D %x\n", gh -> unknownNumberD); printf("unknown number D %x\n", gh -> unknownNumberD);
printf("padding %x\n", gh -> padding); printf("padding %x\n", gh -> padding);
printf("unknown offset %x\n", gh -> unknownOffset); printf("unknown offset %lx\n", gh -> unknownOffset);
} }
} }
@ -25,11 +40,11 @@ static void printmeshheader(struct MeshHeader *mh) {
if (mh == NULL) { if (mh == NULL) {
return; return;
} }
printf("number of batches %x\n", mh -> numBatch); printf("number of batches %x\n", mh -> numBatch);
printf("number of vertices %x\n", mh -> numVertex); printf("number of vertices %x\n", mh -> numVertex);
printf("unknown %x\n", mh -> u); printf("unknown %x\n", mh -> u);
printf("batch offset %x\n", mh -> offsetBatches); printf("batch offset %lx\n", mh -> offsetBatches);
printf("flags %x\n\n", mh -> flags); printf("flags %lx\n\n", mh -> flags);
} }
static void printmeshbatch(struct Batch *b) { static void printmeshbatch(struct Batch *b) {
@ -40,12 +55,12 @@ static void printmeshbatch(struct Batch *b) {
printf("number of vertices %x\n", bd -> numVertex); printf("number of vertices %x\n", bd -> numVertex);
printf("unknown byte %x\n", bd -> uB); printf("unknown byte %x\n", bd -> uB);
printf("padding %x\n", bd -> padding); printf("padding %x\n", bd -> padding);
printf("offsetPositions %x\n", bd -> offsetPositions); printf("offsetPositions %lx\n", bd -> offsetPositions);
printf("offsetNormals %x\n", bd -> offsetNormals); printf("offsetNormals %lx\n", bd -> offsetNormals);
printf("offsetUVs %x\n", bd -> offsetUVs); printf("offsetUVs %lx\n", bd -> offsetUVs);
printf("offsetBoneIndexes %x\n", bd -> offsetBoneIndexes); printf("offsetBoneIndexes %lx\n", bd -> offsetBoneIndexes);
printf("offsetBoneWeights %x\n", bd -> offsetBoneWeights); printf("offsetBoneWeights %lx\n", bd -> offsetBoneWeights);
printf("offsets %x\n\n", bd -> offsets[0]); printf("offsets %lx\n\n", bd -> offsets[0]);
printcoordinate(b -> vd.positions, 3); printcoordinate(b -> vd.positions, 3);
} }

View File

@ -1,6 +1,12 @@
#include "devil1pld.h" #include "devil1pld.h"
#include <stdio.h> #include <stdio.h>
static bool getpldh(struct PldHeader*, const char*);
static int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int);
static void printpldh(struct PldHeader*);
fn_devil1pld const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh}; fn_devil1pld const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh};
static bool getpldh(struct PldHeader *ph, const char *filedata) { static bool getpldh(struct PldHeader *ph, const char *filedata) {
@ -36,7 +42,7 @@ static void printpldh(struct PldHeader *ph) {
return; return;
} }
printf("number of offsets = %i\n", ph -> numOffset); printf("number of offsets = %i\n", ph -> numOffset);
printf("offsets = %x\n", ph -> offsets); printf("offsets = %p\n", ph -> offsets);
unsigned int i; unsigned int i;
for (i = 0; i < ph -> numOffset; i++) { for (i = 0; i < ph -> numOffset; i++) {
printf("offset %i = %x\n", i, ph -> offsets[i]); printf("offset %i = %x\n", i, ph -> offsets[i]);

View File

@ -2,6 +2,32 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
// Print Texture Pack Header.
static void printtph(struct TexturePack*);
// Print Texture Batch Descriptor.
static void printtbd(struct TextureBatchDescriptor*);
// Get Texture Batch Descriptor.
static bool gettexdescriptor(struct TextureBatchDescriptor**,
unsigned int,
const char *,
unsigned int);
// Get Texture Batch.
static bool gettexbatch(struct TextureBatch**,
unsigned int,
const char*,
unsigned int);
// Unpack Texture Batch
static bool unpacktexbatch(struct Texture*,
unsigned int,
const char*,
const unsigned int);
fn_devil1tex const DEVIL1TEX = {printtph, fn_devil1tex const DEVIL1TEX = {printtph,
printtbd, printtbd,
gettexdescriptor, gettexdescriptor,