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