diff --git a/RSEModel/src/RSEModel.c b/RSEModel/src/RSEModel.c index d5d5eb7..9a35fae 100644 --- a/RSEModel/src/RSEModel.c +++ b/RSEModel/src/RSEModel.c @@ -66,16 +66,19 @@ int main(int argc, char *argv[]) { static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* p_opts) { unsigned short file_index; + RSPMODEL_PARAMETERS libParams; T_RSPMODEL_HOB* hobStruct = NULL; int i; + libParams.raw = p_opts->raw & 0x7; + // Manage multiple inputs files for ( file_index = p_opts->input_files_cnt; file_index < args_cnt; file_index++) { printf("\n=============================================\n[INFO] - Parsing file: %s ...\n", args_value[file_index]); hobStruct = calloc(1, sizeof(T_RSPMODEL_HOB)); // Parse data from HOB file and put in T_HOB structure. - if (RSPModel_processHOBFile(hobStruct, args_value[file_index]) != RSPLIB_SUCCESS) { + if (RSPModel_processHOBFile(hobStruct, args_value[file_index], libParams) != RSPLIB_SUCCESS) { printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]); free(hobStruct); return RSPLIB_ERROR_PROCESS; diff --git a/RSEModel/src/options.h b/RSEModel/src/options.h index fd512b2..93e7938 100644 --- a/RSEModel/src/options.h +++ b/RSEModel/src/options.h @@ -14,16 +14,13 @@ typedef union u_prog_options { struct { unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things. + unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things. + unsigned char god_mode:1; //!< Dev only. Output experimental values. unsigned char output_dir:1; //!< Export extracted datas to a sub-directory. unsigned char export_mtl:1; //!< Export materials datas with object. - unsigned char reserved0:5; //!< For future use. - - unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things. - unsigned char god_mode:1; //!< Dev only. Output experimental values. - - unsigned char reserved1:6; //!< For future use. + unsigned short reserved0:11; //!< For future use. unsigned short input_files_cnt; //!< Internal files counters. }; diff --git a/RSPModelLib/include/RSPModel.h b/RSPModelLib/include/RSPModel.h index e739c4b..9d8e979 100644 --- a/RSPModelLib/include/RSPModel.h +++ b/RSPModelLib/include/RSPModel.h @@ -61,11 +61,13 @@ RSPMODEL_EXTERN char* RSPModel_getVersion( void ); * * @param[out] hob HOB structure to be filled with parsed datas. * @param[in] filePath Path to the HOB file in system. + * @param[in] params Parser options. See RSPMODEL_PARAMETERS. * * @return Error status, return RSPLIB_SUCCESS in nominal case. */ RSPMODEL_EXTERN unsigned short RSPModel_processHOBFile( - T_RSPMODEL_HOB* hob, const char* const filePath + T_RSPMODEL_HOB* hob, const char* const filePath, + const RSPMODEL_PARAMETERS params ); /** @@ -77,11 +79,13 @@ RSPMODEL_EXTERN unsigned short RSPModel_processHOBFile( * @param[out] hob HOB structure to be filled with parsed datas. * @param[in] memFilePtr Pointer to the beginning of the file in memory. * @param[in] memFileSize Size of the file in bytes. + * @param[in] params Parser options. See RSPMODEL_PARAMETERS. * * @return Error status, return RSPLIB_SUCCESS in nominal case. */ RSPMODEL_EXTERN unsigned short RSPModel_processHOBFileMemory( - T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize + T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize, + const RSPMODEL_PARAMETERS params ); /** diff --git a/RSPModelLib/include/RSPModel_datatypes.h b/RSPModelLib/include/RSPModel_datatypes.h index 9ff0496..284bbef 100644 --- a/RSPModelLib/include/RSPModel_datatypes.h +++ b/RSPModelLib/include/RSPModel_datatypes.h @@ -14,6 +14,22 @@ extern "C" { #endif +/////////////////////////////////////////////////////////////////////////////// +// Configuration structure +/////////////////////////////////////////////////////////////////////////////// + +typedef union u_rspmodel_parameters { + struct { + unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things. + unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things. + unsigned char god_mode:1; //!< Dev only. Output experimental values. + + unsigned char reserved0:5; //!< For future use. + }; + unsigned char raw; //!< Raw options access for bit-masking or memory copy/compare. +} RSPMODEL_PARAMETERS ; + + //////////////////////////////////////////////////////////////////////////////// // Lib's structure definitions //////////////////////////////////////////////////////////////////////////////// diff --git a/RSPModelLib/src/RSPModel.c b/RSPModelLib/src/RSPModel.c index 40afd48..217235b 100644 --- a/RSPModelLib/src/RSPModel.c +++ b/RSPModelLib/src/RSPModel.c @@ -11,7 +11,6 @@ #include #include #include "config.h" -#include "options.h" #include "RSPModel_errordefs.h" #include "hob_parser.h" #include "RSPModel.h" @@ -21,26 +20,22 @@ char* RSPModel_getVersion( void ) { return PRG_VERSION; } -unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath ) { +unsigned short RSPModel_processHOBFile( T_RSPMODEL_HOB* hob, const char* const filePath, + const RSPMODEL_PARAMETERS params ) { + if ( hob == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL; - T_PROG_OPTIONS canard; - canard.god_mode = 1; - canard.debug_mode = 1; - canard.verbose_mode = 1; - RSP_ModelLib_ParseHOBFile(filePath, hob, &canard); + RSP_ModelLib_ParseHOBFile(filePath, hob, ¶ms); return RSPLIB_SUCCESS; } -unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr, const long memFileSize ) { +unsigned short RSPModel_processHOBFileMemory( T_RSPMODEL_HOB* hob, const void* const memFilePtr, + const long memFileSize, const RSPMODEL_PARAMETERS params ) { + if ( hob == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL; - T_PROG_OPTIONS canard; - canard.god_mode = 1; - canard.debug_mode = 1; - canard.verbose_mode = 1; - RSP_ModelLib_ParseHOBMemFile((MEMFILE)memFilePtr, hob, &canard); + RSP_ModelLib_ParseHOBMemFile((MEMFILE)memFilePtr, hob, ¶ms); return RSPLIB_SUCCESS; } diff --git a/RSPModelLib/src/hob_parser.c b/RSPModelLib/src/hob_parser.c index 891e6d6..68ad686 100644 --- a/RSPModelLib/src/hob_parser.c +++ b/RSPModelLib/src/hob_parser.c @@ -12,7 +12,6 @@ #include #include "RSPModel_errordefs.h" #include "RSPModel_datatypes.h" -#include "options.h" #include "hob_struct.h" #include "hob_parser.h" @@ -21,9 +20,9 @@ // Private functions declarations //////////////////////////////////////////////////////////////////////////////// -static unsigned int ExtractObjects(T_RSPMODEL_HOB*, const MEMFILE, const unsigned char); -static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT*, const MEMFILE, const unsigned char); -static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS*, const MEMFILE, const unsigned char); +static unsigned int ExtractObjects(T_RSPMODEL_HOB*, const MEMFILE, const RSPMODEL_PARAMETERS*); +static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT*, const MEMFILE, const RSPMODEL_PARAMETERS*); +static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS*, const MEMFILE, const RSPMODEL_PARAMETERS*); static inline unsigned int ExtractObjpart_Face_Colors(T_RSPMODEL_FACE*, const char*); static inline unsigned int ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE*, const char*); @@ -32,24 +31,24 @@ static inline unsigned int ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE*, const ch // Public functions definition //////////////////////////////////////////////////////////////////////////////// -unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts) { +unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) { unsigned char err = RSPLIB_SUCCESS; - if (hob_struct != NULL && pMemFile != NULL) { + if (hobStruct != NULL && pMemFile != NULL) { // Do the magic! - err = ExtractObjects(hob_struct, pMemFile, p_opts->verbose_mode + p_opts->debug_mode + p_opts->god_mode); + err = ExtractObjects(hobStruct, pMemFile, pParams); } else err = RSPLIB_ERROR_ARGS_NULL; return err; } -unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts) { +unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) { unsigned char err = RSPLIB_SUCCESS; long fileSize; FILE* fStream = NULL; MEMFILE memFile = NULL; - if (hob_struct != NULL && fileName != NULL) { + if (hobStruct != NULL && fileName != NULL) { // Open file fStream = fopen(fileName, "rb"); @@ -58,7 +57,7 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho fseek(fStream, 0, SEEK_END); fileSize = ftell(fStream); fseek(fStream, 0, SEEK_SET); - if (p_opts->verbose_mode) printf("[DBG] > Input file size: %ld bytes\n", fileSize); + if (pParams->verbose_mode) printf("[DBG] > Input file size: %ld bytes\n", fileSize); memFile = malloc(fileSize + 1); if (memFile != NULL) { @@ -67,18 +66,18 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho fclose(fStream); // Do the magic! - err = ExtractObjects(hob_struct, memFile, p_opts->verbose_mode + p_opts->debug_mode + p_opts->god_mode); + err = ExtractObjects(hobStruct, memFile, pParams); free(memFile); } else { fclose(fStream); err = RSPLIB_ERROR_MEMORY; - if (p_opts->verbose_mode) printf("[ERR] Can't allocate enough memory for file processing!\n"); + if (pParams->verbose_mode) printf("[ERR] Can't allocate enough memory for file processing!\n"); } } else { err = RSPLIB_ERROR_IO; - if (p_opts->verbose_mode) printf("[ERR] Input file %s not found!\n", fileName); + if (pParams->verbose_mode) printf("[ERR] Input file %s not found!\n", fileName); } } else err = RSPLIB_ERROR_ARGS_NULL; @@ -99,7 +98,7 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho * * @return Error code, RSPLIB_SUCCESS when no error. */ -static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMemfile, const unsigned char verbose) { +static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { unsigned int i; if (pHobStruct == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; @@ -117,28 +116,28 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe if (pHobStruct->objects == NULL) return RSPLIB_ERROR_MEMORY; for ( i = 0; i < pHobStruct->obj_count; i++ ) { - if (verbose == 2) printf("\n-=====================-Begin of Object part-======================-\n"); + if (pParams->debug_mode) printf("\n-=====================-Begin of Object part-======================-\n"); // Get object name memcpy(pHobStruct->objects[i].name, ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->object_name, 16); - if (verbose == 1) printf("\n"); + if (pParams->verbose_mode) printf("\n"); printf("[INFO] - Process %s object...\n", pHobStruct->objects[i].name); // Get offsets pHobStruct->objects[i].face_group_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->facegroup_offset; - if (verbose == 1) printf("[DBG] > Face group offset: 0x%X\n", pHobStruct->objects[i].face_group_offset); + if (pParams->verbose_mode) printf("[DBG] > Face group offset: 0x%X\n", pHobStruct->objects[i].face_group_offset); pHobStruct->objects[i].object_part_header_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->object_parts_offset; - if (verbose == 1) printf("[DBG] > Face group header/object parts offset: 0x%X\n", pHobStruct->objects[i].object_part_header_offset); + if (pParams->verbose_mode) printf("[DBG] > Face group header/object parts offset: 0x%X\n", pHobStruct->objects[i].object_part_header_offset); pHobStruct->objects[i].face_group_header_offset = ((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->facegroup_header_2_offset; - if (verbose == 1) printf("[DBG] > Face group header2 offset: 0x%X\n", pHobStruct->objects[i].face_group_header_offset); + if (pParams->verbose_mode) printf("[DBG] > Face group header2 offset: 0x%X\n", pHobStruct->objects[i].face_group_header_offset); - if (verbose == 3) { + if (pParams->god_mode) { printf("[DBG] > Face group unknown1: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset1); printf("[DBG] > Face group unknown2: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset2); printf("[DBG] > Face group unknown3: %d\n",((T_HOBFILE_OBJ_DESCRIPTOR *)(pMemfile + sizeof(T_HOBFILE_HEADER) + sizeof(T_HOBFILE_OBJ_DESCRIPTOR) * i))->unknownOffset3); @@ -148,15 +147,15 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe // Get count and offsets from the facegroup header pHobStruct->objects[i].object_part_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile + pHobStruct->objects[i].object_part_header_offset))->object_part_count; - if (verbose == 1) printf("[DBG] > Object parts count: %d\n", pHobStruct->objects[i].object_part_count); + if (pParams->verbose_mode) printf("[DBG] > Object parts count: %d\n", pHobStruct->objects[i].object_part_count); pHobStruct->objects[i].face_group_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile + pHobStruct->objects[i].object_part_header_offset))->facegroup_count; - if (verbose == 1) printf("[DBG] > Face groups count: %d\n", pHobStruct->objects[i].face_group_count); - if (pHobStruct->objects[i].object_part_count != pHobStruct->objects[i].face_group_count && (verbose == 1)) + if (pParams->verbose_mode) printf("[DBG] > Face groups count: %d\n", pHobStruct->objects[i].face_group_count); + if (pHobStruct->objects[i].object_part_count != pHobStruct->objects[i].face_group_count && (pParams->verbose_mode)) printf("[DBG] > Object parts / facegroup count are different!\n"); // Get facegroup datas - ExtractObjParts(&pHobStruct->objects[i], pMemfile, verbose); + ExtractObjParts(&pHobStruct->objects[i], pMemfile, pParams); } return RSPLIB_SUCCESS; @@ -171,7 +170,7 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe * * @return Error code, RSPLIB_SUCCESS when no error. */ -static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pMemfile, const unsigned char verbose) { +static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { unsigned int i, subpart_offset = 0; if (pObject == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; @@ -180,28 +179,28 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM if (pObject->object_parts == NULL) return RSPLIB_ERROR_MEMORY; for ( i = 0; i < pObject->object_part_count; i++ ) { - if (verbose == 2) printf("\n-----------------------Begin of Mesh part-------------------------\n"); + if (pParams->debug_mode) printf("\n-----------------------Begin of Mesh part-------------------------\n"); subpart_offset = ((T_HOBFILE_FACEGROUP_OFFSET *)(pMemfile + pObject->object_part_header_offset + sizeof(T_HOBFILE_FACEGROUP_HEADER) + sizeof(T_HOBFILE_FACEGROUP_OFFSET) * i))->facegroup_offset; - if (verbose == 1) printf("\n[DBG] > Face group meshdef0 offset: 0x%X\n", subpart_offset); + if (pParams->verbose_mode) printf("\n[DBG] > Face group meshdef0 offset: 0x%X\n", subpart_offset); // Get meshdef0 datas - if (verbose == 3) printf("[DBG] > meshdef0 offset1: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset1); - if (verbose == 3) printf("[DBG] > meshdef0 offset2: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset2); - if (verbose == 1) printf("[DBG] > Prev meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->prev_meshdef0_offset); - if (verbose == 1) printf("[DBG] > Next meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->next_meshdef0_offset); + if (pParams->god_mode) printf("[DBG] > meshdef0 offset1: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset1); + if (pParams->god_mode) printf("[DBG] > meshdef0 offset2: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->offset2); + if (pParams->verbose_mode) printf("[DBG] > Prev meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->prev_meshdef0_offset); + if (pParams->verbose_mode) printf("[DBG] > Next meshdef0 offset: 0x%X\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->next_meshdef0_offset); - if (verbose == 3) printf("[DBG] > meshdef0 unknown3: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown3); - if (verbose == 3) printf("[DBG] > meshdef0 unknown4: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown4); - if (verbose == 3) printf("[DBG] > meshdef0 unknown5: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown5); + if (pParams->god_mode) printf("[DBG] > meshdef0 unknown3: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown3); + if (pParams->god_mode) printf("[DBG] > meshdef0 unknown4: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown4); + if (pParams->god_mode) printf("[DBG] > meshdef0 unknown5: %.8f\n",((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->unknown5); // Get meshdef1 (mesh descriptor) offset pObject->object_parts[i].meshdef1_offset = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->meshdef1_offset_plus_4; - if (verbose == 1) printf("\n[DBG] > Face group meshdef1 offset: 0x%X\n", pObject->object_parts[i].meshdef1_offset); + if (pParams->verbose_mode) printf("\n[DBG] > Face group meshdef1 offset: 0x%X\n", pObject->object_parts[i].meshdef1_offset); if( ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved1 != 0 || ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->reserved2 != 0 ) { - if (verbose == 3) printf("[DBG] > Face group meshdef0: no 0!\n"); + if (pParams->god_mode) printf("[DBG] > Face group meshdef0: no 0!\n"); } if (pObject->object_parts[i].meshdef1_offset > 0) { @@ -212,33 +211,33 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM + pObject->object_parts[i].meshdef1_offset - 4))->vertex_count; pObject->object_parts[i].face_block_offset = ((T_HOBFILE_MESHDEF1 *)(pMemfile + pObject->object_parts[i].meshdef1_offset - 4))->faceblock_offset; - if (verbose == 1) printf("[DBG] > Faces offset: 0x%X\n", pObject->object_parts[i].face_block_offset); + if (pParams->verbose_mode) printf("[DBG] > Faces offset: 0x%X\n", pObject->object_parts[i].face_block_offset); pObject->object_parts[i].vertex_block_offset = ((T_HOBFILE_MESHDEF1 *)(pMemfile + pObject->object_parts[i].meshdef1_offset - 4))->vertexblocks_offset; - if (verbose == 1) printf("[DBG] > Vertex offset: 0x%X\n\n", pObject->object_parts[i].vertex_block_offset); + if (pParams->verbose_mode) printf("[DBG] > Vertex offset: 0x%X\n\n", pObject->object_parts[i].vertex_block_offset); // Get faces datas - ExtractObjParts_faces(&pObject->object_parts[i], pMemfile, verbose); + ExtractObjParts_faces(&pObject->object_parts[i], pMemfile, pParams); } // Get object part ID, used by animation? bones? pObject->object_parts[i].id = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->object_id; - if (verbose == 1) printf("\n[DBG] > Facegroup/object ID: %d\n", pObject->object_parts[i].id); + if (pParams->verbose_mode) printf("\n[DBG] > Facegroup/object ID: %d\n", pObject->object_parts[i].id); // Get the transform matrix, used by at-st and at-at (at this time) pObject->object_parts[i].transform.x = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_x; pObject->object_parts[i].transform.y = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_y; pObject->object_parts[i].transform.z = ((T_HOBFILE_MESHDEF0 *)(pMemfile + subpart_offset))->transform_z; - if (verbose == 3) printf("\n[DBG] > Facegroup/object transform matrix: [%.8f %.8f %.8f]\n", + if (pParams->god_mode) printf("\n[DBG] > Facegroup/object transform matrix: [%.8f %.8f %.8f]\n", pObject->object_parts[i].transform.x, pObject->object_parts[i].transform.y, pObject->object_parts[i].transform.z ); - if (verbose == 2) printf("\n-----------------------End of Mesh part---------------------------\n"); + if (pParams->debug_mode) printf("\n-----------------------End of Mesh part---------------------------\n"); } - if (verbose == 2) printf("\n-=====================-End of Object part-========================-\n"); + if (pParams->debug_mode) printf("\n-=====================-End of Object part-========================-\n"); return RSPLIB_SUCCESS; } @@ -252,24 +251,24 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM * * @return Error code, RSPLIB_SUCCESS when no error. */ -static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const unsigned char verbose) { +static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { unsigned int i, facesExtraOffset = 0; if (pObjPart == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL; if( ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->reserved1 != 0 || ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->reserved2 != 0 ) { - if (verbose == 3) printf("[DBG] > Face block: uncommon zero header!\n"); + if (pParams->god_mode) printf("[DBG] > Face block: uncommon zero header!\n"); } if ( ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->facesOffset != pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK)) { - if (verbose == 3) printf("[DBG] > Face block: uncommon face data offset position!\n"); + if (pParams->god_mode) printf("[DBG] > Face block: uncommon face data offset position!\n"); } pObjPart->face_count = ((T_HOBFILE_FACEBLOCK *)(pMemfile + pObjPart->face_block_offset))->faceCounts; pObjPart->faces = calloc(pObjPart->face_count, sizeof(T_RSPMODEL_FACE)); for ( i = 0; i < pObjPart->face_count; i++ ) { - if (verbose == 2) printf("\n----------------------Begin of FaceGroup part----------------------\n"); + if (pParams->debug_mode) printf("\n----------------------Begin of FaceGroup part----------------------\n"); // Get flags pObjPart->faces[i].flags = ((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset @@ -287,7 +286,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const + sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->faceBlockIntSize * 4; // Multiply by 4 to get the bytes exact number if (((T_HOBFILE_FACES_HEADER *)(pMemfile + pObjPart->face_block_offset + sizeof(T_HOBFILE_FACEBLOCK) + sizeof(T_HOBFILE_FACES_HEADER) * i + facesExtraOffset))->headerSeparator != 0) { - if (verbose == 3) printf("[DBG] > Face header: uncommon separator!\n"); + if (pParams->god_mode) printf("[DBG] > Face header: uncommon separator!\n"); } // Get materials index @@ -316,7 +315,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const + facesExtraOffset); } - if (verbose == 2) { + if (pParams->debug_mode) { printf("[DBG] > Face %d details: flags:0x%X b1:%d b2:%d b3%d bsize:%d\n", i, pObjPart->faces[i].flags, pObjPart->faces[i].b1, pObjPart->faces[i].b2, pObjPart->faces[i].b3, pObjPart->faces[i].bsize); printf("[DBG] - Type is Quad: %d\n", pObjPart->faces[i].flags_bits.fIsQuad); @@ -353,7 +352,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const printf("\n"); } - if (verbose == 2) printf("\n-----------------------End of FaceGroup part-----------------------\n"); + if (pParams->debug_mode) printf("\n-----------------------End of FaceGroup part-----------------------\n"); } // Get vertex datas @@ -373,7 +372,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const pObjPart->vertices[i].w = ((T_HOBFILE_VERTEX *)(pMemfile + pObjPart->vertex_block_offset + sizeof(T_VERTEX) * i))->w; // Always 0??? - if (verbose == 2) printf("[DBG] > Found vertex %d: (%d, %d, %d)\n", i, + if (pParams->debug_mode) printf("[DBG] > Found vertex %d: (%d, %d, %d)\n", i, pObjPart->vertices[i].x, pObjPart->vertices[i].y, pObjPart->vertices[i].z ); } diff --git a/RSPModelLib/src/hob_parser.h b/RSPModelLib/src/hob_parser.h index 1c4e8ec..fabf751 100644 --- a/RSPModelLib/src/hob_parser.h +++ b/RSPModelLib/src/hob_parser.h @@ -7,7 +7,6 @@ * */ -#include "options.h" #include "RSPModel_datatypes.h" @@ -21,14 +20,14 @@ * @note Unmanaged mode * * @param[in] pMemFile Pointer to an in-memory HOB file location. - * @param[out] hob_struct Allocated empty T_RSPMODEL_HOB structure instance to + * @param[out] hobStruct Allocated empty T_RSPMODEL_HOB structure instance to * be filled with HOB datas. - * @param[in] p_opts Parser options. DEPRECATED. + * @param[in] pParams Parser options. See RSPMODEL_PARAMETERS. * * @return Processing error code, RSPLIB_SUCCESS if no error. */ unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, - T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts); + T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams); /** * @brief Process HOB file in file system. @@ -40,13 +39,13 @@ unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, * @note Managed mode * * @param[in] fileName String value of file name/path. - * @param[out] hob_struct Allocated empty T_RSPMODEL_HOB structure instance to + * @param[out] hobStruct Allocated empty T_RSPMODEL_HOB structure instance to * be filled with HOB datas. - * @param[in] p_opts Parser options. DEPRECATED. + * @param[in] pParams Parser options. See RSPMODEL_PARAMETERS. * * @return Processing error code, RSPLIB_SUCCESS if no error. */ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, - T_RSPMODEL_HOB* hob_struct, T_PROG_OPTIONS* p_opts); + T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams); #endif /* SRC_HOB_PARSER_H_ */ diff --git a/RSPModelLib/src/options.h b/RSPModelLib/src/options.h deleted file mode 100644 index a88baae..0000000 --- a/RSPModelLib/src/options.h +++ /dev/null @@ -1,35 +0,0 @@ -/** - * @file options.h - * @date 29/07/2022 - * @author JackCarterSmith - * @copyright GPL-v3.0 - * @brief Shared options structure definition and declaration. - * - */ - -#ifndef OPTIONS_H_ -#define OPTIONS_H_ - -#define RSPMODEL_DLLBUILD - -/// Options structure -typedef union u_prog_options { - struct { - unsigned char verbose_mode:1; //!< Output simple details about ID and other "light" things. - - unsigned char output_dir:1; //!< Export extracted datas to a sub-directory. - unsigned char export_mtl:1; //!< Export materials datas with object. - - unsigned char reserved0:5; //!< For future use. - - unsigned char debug_mode:1; //!< Output all values of faces, indices and vertices and others "heavy" things. - unsigned char god_mode:1; //!< Dev only. Output experimental values. - - unsigned char reserved1:6; //!< For future use. - - unsigned short input_files_cnt; //!< Internal files counters. - }; - unsigned int raw; //!< Raw options access for bit-masking or memory copy/compare. -} T_PROG_OPTIONS ; - -#endif /* OPTIONS_H_ */