mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-29 10:12:02 +05:30
Merged a/iosanitycheck into master
This commit is contained in:
commit
f77c2f8920
@ -45,6 +45,7 @@ void write(const char *filename,
|
|||||||
fclose(out);
|
fclose(out);
|
||||||
if (written == 0) {
|
if (written == 0) {
|
||||||
perror("write error");
|
perror("write error");
|
||||||
|
exit(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,6 +62,7 @@ void append(const char *filename, const char *t, unsigned size) {
|
|||||||
fclose(out);
|
fclose(out);
|
||||||
if (written == 0) {
|
if (written == 0) {
|
||||||
perror("write error");
|
perror("write error");
|
||||||
|
exit(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,22 +25,22 @@ void writemesh(const struct MeshHeader *mh,
|
|||||||
|
|
||||||
// batch data the same treatment.
|
// batch data the same treatment.
|
||||||
struct BatchData * newBatches = malloc(newmh.numBatch * sizeof(struct BatchData));
|
struct BatchData * newBatches = malloc(newmh.numBatch * sizeof(struct BatchData));
|
||||||
uint64_t previousBatch = 0;
|
uint64_t endOfPrevious = 0;
|
||||||
for (int i = 0; i < newmh.numBatch; i++) {
|
for (int i = 0; i < newmh.numBatch; i++) {
|
||||||
newBatches[i] = (m -> b) -> bd[i];
|
newBatches[i] = (m -> b) -> bd[i];
|
||||||
unsigned int nVertices = m -> b -> bd[i].numVertex;
|
unsigned int nVertices = m -> b -> bd[i].numVertex;
|
||||||
if (previousBatch == 0) {
|
if (endOfPrevious == 0) {
|
||||||
newBatches[i].offsetPositions = newmh.offsetBatches + ( newmh.numBatch * sizeof(struct BatchData));
|
newBatches[i].offsetPositions = newmh.offsetBatches + ( newmh.numBatch * sizeof(struct BatchData));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newBatches[i].offsetPositions = previousBatch;
|
newBatches[i].offsetPositions = endOfPrevious;
|
||||||
}
|
}
|
||||||
newBatches[i].offsetNormals = newBatches[i].offsetPositions + (sizeof(struct Coordinate) * nVertices);
|
newBatches[i].offsetNormals = newBatches[i].offsetPositions + (sizeof(struct Coordinate) * nVertices);
|
||||||
newBatches[i].offsetUVs = newBatches[i].offsetNormals + (sizeof(struct Coordinate) * nVertices);
|
newBatches[i].offsetUVs = newBatches[i].offsetNormals + (sizeof(struct Coordinate) * nVertices);
|
||||||
newBatches[i].offsetBoneIndexes = newBatches[i].offsetUVs + (sizeof(struct UVs) * nVertices);
|
newBatches[i].offsetBoneIndexes = newBatches[i].offsetUVs + (sizeof(struct UVs) * nVertices);
|
||||||
newBatches[i].offsetBoneWeights = newBatches[i].offsetBoneIndexes + (sizeof(struct BoneIndexes) * nVertices);
|
newBatches[i].offsetBoneWeights = newBatches[i].offsetBoneIndexes + (sizeof(struct BoneIndexes) * nVertices);
|
||||||
append(fn, (char*)(&newBatches[i]), sizeof(struct BatchData));
|
append(fn, (char*)(&newBatches[i]), sizeof(struct BatchData));
|
||||||
previousBatch = newBatches[i].offsetBoneWeights + (sizeof(struct BoneWeights) * nVertices);;
|
endOfPrevious = newBatches[i].offsetBoneWeights + (sizeof(struct BoneWeights) * nVertices);;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < newmh.numBatch; i++) {
|
for (int i = 0; i < newmh.numBatch; i++) {
|
||||||
@ -57,8 +57,8 @@ void writemesh(const struct MeshHeader *mh,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void extractmeshes(const char *filedata,
|
void extractmeshes(const char *filedata,
|
||||||
unsigned int filesize,
|
const char *filename,
|
||||||
const char *filename) {
|
unsigned int filesize) {
|
||||||
if (filedata == NULL || filesize <= 0) {
|
if (filedata == NULL || filesize <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ void extractmeshes(const char *filedata,
|
|||||||
DEVIL1GEO.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) {
|
||||||
DEVIL1GEO.getmesh(&m, i, filedata);
|
DEVIL1GEO.getmesh(&m, i, filedata, filesize);
|
||||||
writemesh(mh, &m, filename, i);
|
writemesh(mh, &m, filename, i);
|
||||||
free(m.b);
|
free(m.b);
|
||||||
}
|
}
|
||||||
@ -83,7 +83,7 @@ int main(int argc, char ** argv) {
|
|||||||
char *f = argv[1];
|
char *f = argv[1];
|
||||||
unsigned int bufsize = 0;
|
unsigned int bufsize = 0;
|
||||||
char *buffer = loadfile(f, &bufsize);
|
char *buffer = loadfile(f, &bufsize);
|
||||||
extractmeshes(buffer, bufsize, f);
|
extractmeshes(buffer, f, bufsize);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,8 @@ typedef struct {
|
|||||||
// input: pointer to struct, order, file data
|
// 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*);
|
const char*,
|
||||||
|
unsigned int filesize);
|
||||||
} fn_devil1geo;
|
} fn_devil1geo;
|
||||||
extern fn_devil1geo const DEVIL1GEO;
|
extern fn_devil1geo const DEVIL1GEO;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ static bool getmeshheader(struct MeshHeader**, unsigned int i, const char * cons
|
|||||||
|
|
||||||
static bool getmeshbatch(struct Batch*, unsigned int offset, const char * const);
|
static bool getmeshbatch(struct Batch*, unsigned int offset, const char * const);
|
||||||
|
|
||||||
static bool getmesh(struct Mesh*, unsigned int i, const char*);
|
static bool getmesh(struct Mesh*, unsigned int i, const char*, unsigned int filesize);
|
||||||
|
|
||||||
fn_devil1geo const DEVIL1GEO = {printgheader,
|
fn_devil1geo const DEVIL1GEO = {printgheader,
|
||||||
printmeshheader,
|
printmeshheader,
|
||||||
@ -115,7 +115,8 @@ static bool getmeshbatch(struct Batch *b,
|
|||||||
// assume client has allocated memory for mesh
|
// assume client has allocated memory for mesh
|
||||||
static 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,
|
||||||
|
unsigned int filesize) {
|
||||||
bool done = false;
|
bool done = false;
|
||||||
if (m == NULL || filedata == NULL || m -> b == NULL) {
|
if (m == NULL || filedata == NULL || m -> b == NULL) {
|
||||||
return done;
|
return done;
|
||||||
@ -127,6 +128,9 @@ static bool getmesh(struct Mesh *m,
|
|||||||
struct Batch b;
|
struct Batch b;
|
||||||
for (j = 0; j < mh -> numBatch; j++) {
|
for (j = 0; j < mh -> numBatch; j++) {
|
||||||
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
unsigned int offset = mh->offsetBatches + j * sizeof(struct BatchData);
|
||||||
|
if (offset > filesize) {
|
||||||
|
return done;
|
||||||
|
}
|
||||||
getmeshbatch(&b, offset, filedata);
|
getmeshbatch(&b, offset, filedata);
|
||||||
// printmeshbatch(&b);
|
// printmeshbatch(&b);
|
||||||
m -> b[j] = b;
|
m -> b[j] = b;
|
||||||
|
@ -14,8 +14,10 @@ static bool getpldh(struct PldHeader *ph, const char *filedata) {
|
|||||||
if (ph != NULL && filedata != NULL) {
|
if (ph != NULL && filedata != NULL) {
|
||||||
ph -> numOffset = (int32_t)filedata[0];
|
ph -> numOffset = (int32_t)filedata[0];
|
||||||
ph -> offsets = (uint32_t*)(filedata + sizeof(int32_t));
|
ph -> offsets = (uint32_t*)(filedata + sizeof(int32_t));
|
||||||
|
if ( ph->numOffset > 0 ) {
|
||||||
good = true;
|
good = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return good;
|
return good;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ static bool gettexdescriptor(struct TextureBatchDescriptor **descriptor,
|
|||||||
bool done = false;
|
bool done = false;
|
||||||
unsigned int offset = sizeof(struct TexturePack);
|
unsigned int offset = sizeof(struct TexturePack);
|
||||||
offset += sizeof(struct TextureBatchDescriptor) * i;
|
offset += sizeof(struct TextureBatchDescriptor) * i;
|
||||||
if (filedata != NULL) {
|
if (filedata != NULL && offset <= filesize) {
|
||||||
*descriptor = (struct TextureBatchDescriptor*)(filedata + offset);
|
*descriptor = (struct TextureBatchDescriptor*)(filedata + offset);
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user