From c5e14436a2a2f43737f70f8b3ad09100b419c8eb Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sat, 20 Aug 2022 13:07:29 +0200 Subject: [PATCH 1/3] Facegroup count fix Cause seg.fault with different facegrp/objpart count when exporting. --- RSEModel/src/obj | 2 +- RSEModel/src/obj_exporter.c | 2 +- RSPModelLib/src/hob_parser.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RSEModel/src/obj b/RSEModel/src/obj index 63f5977..59191c2 160000 --- a/RSEModel/src/obj +++ b/RSEModel/src/obj @@ -1 +1 @@ -Subproject commit 63f5977aaed661f6176daca101680bfcd80e80ec +Subproject commit 59191c204ab030aabc34cf758efefdaf2de65401 diff --git a/RSEModel/src/obj_exporter.c b/RSEModel/src/obj_exporter.c index e3e3e4c..1c59024 100644 --- a/RSEModel/src/obj_exporter.c +++ b/RSEModel/src/obj_exporter.c @@ -42,7 +42,7 @@ unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_pat objConstruct = obj_create(NULL); // Build face/surface material group - for ( i = 0; i < hob_objects->face_group_count; i++) { + for ( i = 0; i < hob_objects->object_part_count; i++) { surfID = obj_add_surf(objConstruct); materialID = obj_add_mtrl(objConstruct); diff --git a/RSPModelLib/src/hob_parser.c b/RSPModelLib/src/hob_parser.c index 68ad686..33cb963 100644 --- a/RSPModelLib/src/hob_parser.c +++ b/RSPModelLib/src/hob_parser.c @@ -151,6 +151,7 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe pHobStruct->objects[i].face_group_count = ((T_HOBFILE_FACEGROUP_HEADER *)(pMemfile + pHobStruct->objects[i].object_part_header_offset))->facegroup_count; if (pParams->verbose_mode) printf("[DBG] > Face groups count: %d\n", pHobStruct->objects[i].face_group_count); + //TODO: Caution with obj/facegrp count difference. What is facegroup 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"); -- 2.39.5 From 12d74097675f8f0f0d553d2ab9494818b3c5671c Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Mon, 22 Aug 2022 22:50:34 +0200 Subject: [PATCH 2/3] More clean up Issue with duplicate include/define --- CMakeLists.txt | 2 +- Jenkinsfile | 157 +++++++++++------------ LICENSE-glew.txt => LICENSE-glew | 0 RSPModelLib/CMakeLists.txt | 2 +- RSPModelLib/include/RSPModel.h | 6 +- RSPModelLib/include/RSPModel_datatypes.h | 16 ++- RSPModelLib/include/RSPModel_errordefs.h | 6 +- RSPModelLib/src/hob_parser.h | 6 +- doc/Doxyfile | 2 +- 9 files changed, 103 insertions(+), 94 deletions(-) rename LICENSE-glew.txt => LICENSE-glew (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01f939f..a30a565 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ if(DEFINED ENV{CI}) # Jenkins CI integration mode project(rse-model VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Model" LANGUAGES C) set(RSE_MODEL_NAME $ENV{CI_OUTPUT_NAME}) else() # Standalone project mode, should not be used for release. - project(rse-model VERSION 2.0.0 DESCRIPTION "RogueSquadron Extractor - Model" LANGUAGES C) + project(rse-model VERSION 2.1.0 DESCRIPTION "RogueSquadron Extractor - Model" LANGUAGES C) set(RSE_MODEL_NAME RSEModel) endif() set(RSP_MODEL_LIB_NAME RSPModel${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}) diff --git a/Jenkinsfile b/Jenkinsfile index f2abc2d..f8e4cc0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,80 +1,79 @@ pipeline { - agent any - options { - skipDefaultCheckout(true) - } - environment { - CI_OUTPUT_NAME = "RSEModel" - CI_VERSION = "2.0.0" - CI_BUILD_NUMBER = "$BUILD_NUMBER" - } - stages { - stage('Prepare') { - steps { - cleanWs() - rtConanClient(id: "conan", userHome: "/home/jackcartersmith") - } - } - stage('Build') { - steps { - parallel( - linux: { - dir("linux") { - checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Model'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Model.git']]]) - sh 'git submodule update --init --recursive' - dir("build") { - rtConanRun(clientId: "conan", command: "install .. --build=missing") - } - cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']] - } - }, - windows: { - dir("windows") { - checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Model'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Model.git']]]) - sh 'git submodule update --init --recursive' - dir("build") { - rtConanRun(clientId: "conan", command: "install .. --profile=windows --build=missing") - } - cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']] - } - } - ) - } - } - stage('Deploy') { - steps { - dir("zip_linux") { - sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/RSPModelLib/include .' - } - dir("zip_win") { - sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/RSPModelLib/include .' - } - zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'linux_x64.zip' - sh 'mv linux_x64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip' - zip archive: false, dir: 'zip_win', exclude: '', glob: '', zipFile: 'mingw64.zip' - sh 'mv mingw64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip' - archiveArtifacts(artifacts: '*.zip') - fingerprint(targets: '*.zip') - } - } - stage('Sign') { - steps { - sh 'ls -l' - sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip' - sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip' - archiveArtifacts(artifacts: '*.gpg') - fingerprint(targets: '*.gpg') - } - } - } - /* - post { - always { - cleanWs(cleanWhenNotBuilt: false, - deleteDirs: true, - disableDeferredWipeout: true, - notFailBuild: true) - } - } - */ -} + agent any + options { + skipDefaultCheckout(true) + } + environment { + CI_OUTPUT_NAME = "RSEModel" + CI_VERSION = "2.1.0" + CI_BUILD_NUMBER = "$BUILD_NUMBER" + } + stages { + stage('Prepare') { + steps { + cleanWs() + rtConanClient(id: "conan", userHome: "/home/jackcartersmith") + } + } + stage('Build') { + steps { + parallel( + linux: { + dir("linux") { + checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Model'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Model.git']]]) + sh 'git submodule update --init --recursive' + dir("build") { + rtConanRun(clientId: "conan", command: "install .. --build=missing") + } + cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']] + } + }, + windows: { + dir("windows") { + checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Model'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Model.git']]]) + sh 'git submodule update --init --recursive' + dir("build") { + rtConanRun(clientId: "conan", command: "install .. --profile=windows --build=missing") + } + cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']] + } + } + ) + } + } + stage('Deploy') { + steps { + dir("zip_linux") { + sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/RSPTerrainLib/include .' + } + dir("zip_win") { + sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/RSPTerrainLib/include .' + } + zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'linux_x64.zip' + sh 'mv linux_x64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip' + zip archive: false, dir: 'zip_win', exclude: '', glob: '', zipFile: 'mingw64.zip' + sh 'mv mingw64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip' + archiveArtifacts(artifacts: '*.zip') + fingerprint(targets: '*.zip') + } + } + stage('Sign') { + steps { + sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip' + sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip' + archiveArtifacts(artifacts: '*.gpg') + fingerprint(targets: '*.gpg') + } + } + } + /* + post { + always { + cleanWs(cleanWhenNotBuilt: false, + deleteDirs: true, + disableDeferredWipeout: true, + notFailBuild: true) + } + } + */ +} \ No newline at end of file diff --git a/LICENSE-glew.txt b/LICENSE-glew similarity index 100% rename from LICENSE-glew.txt rename to LICENSE-glew diff --git a/RSPModelLib/CMakeLists.txt b/RSPModelLib/CMakeLists.txt index 9f0beaf..f6c2206 100644 --- a/RSPModelLib/CMakeLists.txt +++ b/RSPModelLib/CMakeLists.txt @@ -22,7 +22,7 @@ file(GLOB RSP_PUBLIC_HRDS ./include/*.h) set(RSP_PUBLIC_HRDS ${RSP_PUBLIC_HRDS} PARENT_SCOPE) -# Building instructions for RSE-Model +# Building instructions for RSP-Model library if(DEFINED ENV{CI}) set(CMAKE_BUILD_TYPE RELEASE) endif() diff --git a/RSPModelLib/include/RSPModel.h b/RSPModelLib/include/RSPModel.h index 9d8e979..c80a5c3 100644 --- a/RSPModelLib/include/RSPModel.h +++ b/RSPModelLib/include/RSPModel.h @@ -10,8 +10,8 @@ #include "RSPModel_datatypes.h" -#ifndef RSPMODEL_H_ -#define RSPMODEL_H_ +#ifndef RSPMODELLIB_H_ +#define RSPMODELLIB_H_ #if defined(_MSC_VER) @@ -118,4 +118,4 @@ RSPMODEL_EXTERN unsigned short RSPModel_objectToD3D( } #endif -#endif /* RSPMODEL_H_ */ +#endif /* RSPMODELLIB_H_ */ diff --git a/RSPModelLib/include/RSPModel_datatypes.h b/RSPModelLib/include/RSPModel_datatypes.h index 284bbef..5646f19 100644 --- a/RSPModelLib/include/RSPModel_datatypes.h +++ b/RSPModelLib/include/RSPModel_datatypes.h @@ -7,8 +7,8 @@ * */ -#ifndef RSPMODEL_DATATYPES_H_ -#define RSPMODEL_DATATYPES_H_ +#ifndef RSPMODELLIB_DATATYPES_H_ +#define RSPMODELLIB_DATATYPES_H_ #ifdef __cplusplus extern "C" { @@ -34,15 +34,25 @@ typedef union u_rspmodel_parameters { // Lib's structure definitions //////////////////////////////////////////////////////////////////////////////// +#ifndef MEMFILE typedef char* MEMFILE; +#endif +#ifndef T_RGBA typedef unsigned int T_RGBA; +#endif +#ifndef T_VECTOR3 typedef struct vector3 { float x,y,z; } T_VECTOR3; +#endif +#ifndef T_VERTEX typedef struct vertex { short x,y,z,w; } T_VERTEX; +#endif +#ifndef T_TEXCOORD typedef struct tex_coord { unsigned short u,v; } T_TEXCOORD; +#endif typedef struct face_flags { unsigned int fUnknown0:1; @@ -119,4 +129,4 @@ typedef struct rspmodel_hob { } #endif -#endif /* RSPMODEL_DATATYPES_H_ */ +#endif /* RSPMODELLIB_DATATYPES_H_ */ diff --git a/RSPModelLib/include/RSPModel_errordefs.h b/RSPModelLib/include/RSPModel_errordefs.h index 6d71ca6..6a36af6 100644 --- a/RSPModelLib/include/RSPModel_errordefs.h +++ b/RSPModelLib/include/RSPModel_errordefs.h @@ -10,8 +10,8 @@ #include -#ifndef RSPMODELLIB_ERRORS_H_ -#define RSPMODELLIB_ERRORS_H_ +#ifndef RSPLIB_ERRORS_H_ +#define RSPLIB_ERRORS_H_ #ifdef __cplusplus extern "C" { @@ -42,4 +42,4 @@ extern "C" { } #endif -#endif /* RSPMODELLIB_ERRORS_H_ */ +#endif /* RSPLIB_ERRORS_H_ */ diff --git a/RSPModelLib/src/hob_parser.h b/RSPModelLib/src/hob_parser.h index fabf751..9bc0926 100644 --- a/RSPModelLib/src/hob_parser.h +++ b/RSPModelLib/src/hob_parser.h @@ -10,8 +10,8 @@ #include "RSPModel_datatypes.h" -#ifndef SRC_HOB_PARSER_H_ -#define SRC_HOB_PARSER_H_ +#ifndef RSPMODELLIB_HOB_PARSER_H_ +#define RSPMODELLIB_HOB_PARSER_H_ /** * @brief Process HOB file stored in memory. @@ -48,4 +48,4 @@ unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams); -#endif /* SRC_HOB_PARSER_H_ */ +#endif /* RSPMODELLIB_HOB_PARSER_H_ */ diff --git a/doc/Doxyfile b/doc/Doxyfile index a529575..e1b5845 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = RSE-Model # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.0.0 +PROJECT_NUMBER = 2.1.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a -- 2.39.5 From f2dc04a99160d586b803c15bf0701cccadc62ef4 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Wed, 24 Aug 2022 18:15:46 +0200 Subject: [PATCH 3/3] Final review --- Jenkinsfile | 4 +- RSEModel/src/RSEModel.c | 52 +++++++------------ .../src/{obj_exporter.c => model_export.c} | 14 ++--- .../src/{obj_exporter.h => model_export.h} | 8 +-- RSEModel/src/options.h | 2 +- RSPModelLib/include/RSPModel.h | 6 +++ RSPModelLib/src/RSPModel.c | 28 +++++++++- RSPModelLib/src/hob_parser.c | 30 +++++------ RSPModelLib/src/hob_parser.h | 4 +- 9 files changed, 83 insertions(+), 65 deletions(-) rename RSEModel/src/{obj_exporter.c => model_export.c} (94%) rename RSEModel/src/{obj_exporter.h => model_export.h} (75%) diff --git a/Jenkinsfile b/Jenkinsfile index f8e4cc0..7e55eb0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,10 +44,10 @@ pipeline { stage('Deploy') { steps { dir("zip_linux") { - sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/RSPTerrainLib/include .' + sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/RSPModelLib/include .' } dir("zip_win") { - sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/RSPTerrainLib/include .' + sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/RSPModelLib/include .' } zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'linux_x64.zip' sh 'mv linux_x64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip' diff --git a/RSEModel/src/RSEModel.c b/RSEModel/src/RSEModel.c index f69e853..cb61d2d 100644 --- a/RSEModel/src/RSEModel.c +++ b/RSEModel/src/RSEModel.c @@ -19,8 +19,7 @@ #include "options.h" #include #include -#include "obj_exporter.h" - +#include "model_export.h" /* @@ -29,8 +28,7 @@ static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* opt_ptr); static void createSubDir(char *dirName); -static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]); -static void cleanUpMemory(T_RSPMODEL_HOB* hobStruct); +static unsigned short checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]); static void dispHelp(); @@ -42,7 +40,7 @@ int main(int argc, char *argv[]) { unsigned char p; // Hello world! - printf("\n*** RogueSquadron Extractor (RSE) - MODEL module - RSPModelLib v%s ***\n", RSPModel_getVersion()); + printf("\n*~[ Rogue Squadron Extractor (RSE) - RSPModelLib v%s ]~*\n", RSPModel_getVersion()); // Check for arguments if (argc < 2) { @@ -76,32 +74,37 @@ static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS 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]); + + // Allocate T_RSPMODEL_HOB structure to store extracted datas. 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], libParams) != RSPLIB_SUCCESS) { - printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]); - free(hobStruct); - return RSPLIB_ERROR_PROCESS; - } + if (hobStruct) { + // Parse data from HOB file and put in T_RSPMODEL_HOB structure. + if (RSPModel_processHOBFile(hobStruct, args_value[file_index], libParams) != RSPLIB_SUCCESS) { + printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]); + RSPModel_freeHOB(hobStruct); + return RSPLIB_ERROR_PROCESS; + } + } else return RSPLIB_ERROR_MEMORY; if (hobStruct->obj_count > 0) { + // Create output folders structure. if (p_opts->output_dir) createSubDir(args_value[file_index]); for ( i = 0; i < hobStruct->obj_count; i++ ) { - if (exportOBJModel(&(hobStruct->objects[i]), args_value[file_index], p_opts) != RSPLIB_SUCCESS) - printf("[ERR] Failed to export %s object in OBJ format!\n", hobStruct->objects[i].name); - else + if (exportOBJModel(&(hobStruct->objects[i]), args_value[file_index], p_opts) == RSPLIB_SUCCESS) printf("[INFO] Successfully exported %s object in OBJ format.\n", hobStruct->objects[i].name); + else + printf("[ERR] Failed to export %s object in OBJ format!\n", hobStruct->objects[i].name); } } } - cleanUpMemory(hobStruct); + RSPModel_freeHOB(hobStruct); return RSPLIB_SUCCESS; } -static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]) { +static unsigned short checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]) { char test[256]; int i; @@ -159,23 +162,6 @@ static void createSubDir(char *dirName) { #endif } -static void cleanUpMemory(T_RSPMODEL_HOB* hobStruct) { - int i,j; - - for ( i=0; iobj_count; i++ ) { - for ( j=0; jobjects[i].face_group_count; j++ ) { - - free(hobStruct->objects[i].object_parts[j].faces); - free(hobStruct->objects[i].object_parts[j].vertices); - } - - free(hobStruct->objects[i].object_parts); - } - - free(hobStruct->objects); - free(hobStruct); -} - static void dispHelp() { printf("\n"); printf("Options:\n -h Print this message\n"); diff --git a/RSEModel/src/obj_exporter.c b/RSEModel/src/model_export.c similarity index 94% rename from RSEModel/src/obj_exporter.c rename to RSEModel/src/model_export.c index 1c59024..d789fee 100644 --- a/RSEModel/src/obj_exporter.c +++ b/RSEModel/src/model_export.c @@ -1,5 +1,5 @@ /** - * @file obj_exporter.c + * @file model_export.c * @date 27/07/2022 * @author JackCarterSmith * @copyright GPL-v3.0 @@ -14,11 +14,11 @@ #include #include #include "obj/obj.h" -#include "obj_exporter.h" +#include "model_export.h" unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts) { - char exportPath[1024]; + char export_path[1024]; char objExport_name[128]; char mtlExport_name[128]; obj* objConstruct = NULL; @@ -32,9 +32,9 @@ unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_pat return RSPLIB_ERROR_ARGS_NULL; #ifdef _WIN32 - snprintf(exportPath, 1024, "%s-out\\", out_path); + snprintf(export_path, 1024, "%s-out\\", out_path); #else - snprintf(exportPath, 1024, "%s-out/", out_path); + snprintf(export_path, 1024, "%s-out/", out_path); #endif snprintf(objExport_name, 128, "%s.obj", hob_objects->name); snprintf(mtlExport_name, 128, "%s.mtl", hob_objects->name); @@ -101,12 +101,12 @@ unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_pat if (p_opts->export_mtl) { if (p_opts->output_dir) - obj_write(objConstruct, objExport_name, mtlExport_name, exportPath, 8); + obj_write(objConstruct, objExport_name, mtlExport_name, export_path, 8); else obj_write(objConstruct, objExport_name, mtlExport_name, NULL, 8); } else { if (p_opts->output_dir) - obj_write(objConstruct, objExport_name, NULL, exportPath, 8); + obj_write(objConstruct, objExport_name, NULL, export_path, 8); else obj_write(objConstruct, objExport_name, NULL, NULL, 8); } diff --git a/RSEModel/src/obj_exporter.h b/RSEModel/src/model_export.h similarity index 75% rename from RSEModel/src/obj_exporter.h rename to RSEModel/src/model_export.h index 035141e..82b5dba 100644 --- a/RSEModel/src/obj_exporter.h +++ b/RSEModel/src/model_export.h @@ -1,5 +1,5 @@ /** - * @file obj_exporter.h + * @file model_export.h * @date 27/07/2022 * @author JackCarterSmith * @copyright GPL-v3.0 @@ -7,8 +7,8 @@ * */ -#ifndef SRC_OBJ_EXPORTER_H_ -#define SRC_OBJ_EXPORTER_H_ +#ifndef MODEL_EXPORT_H_ +#define MODEL_EXPORT_H_ typedef struct t_material { @@ -19,4 +19,4 @@ typedef struct t_material { unsigned char exportOBJModel(T_RSPMODEL_OBJECT* hob_objects, const char *out_path, T_PROG_OPTIONS* p_opts); -#endif /* SRC_OBJ_EXPORTER_H_ */ +#endif /* MODEL_EXPORT_H_ */ diff --git a/RSEModel/src/options.h b/RSEModel/src/options.h index 93e7938..89ad7a6 100644 --- a/RSEModel/src/options.h +++ b/RSEModel/src/options.h @@ -20,7 +20,7 @@ typedef union u_prog_options { unsigned char output_dir:1; //!< Export extracted datas to a sub-directory. unsigned char export_mtl:1; //!< Export materials datas with object. - unsigned short reserved0:11; //!< 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 c80a5c3..f446145 100644 --- a/RSPModelLib/include/RSPModel.h +++ b/RSPModelLib/include/RSPModel.h @@ -114,6 +114,12 @@ RSPMODEL_EXTERN unsigned short RSPModel_objectToD3D( const T_RSPMODEL_OBJECT* objStruct, void* D3DObj ); +/** + * @brief Clean HOB object and it's childrens from memory. + * @param[in] hobStruct Pointer to data to be cleaned up. + */ +RSPMODEL_EXTERN void RSPModel_freeHOB( T_RSPMODEL_HOB* hobStruct ); + #ifdef __cplusplus } #endif diff --git a/RSPModelLib/src/RSPModel.c b/RSPModelLib/src/RSPModel.c index 217235b..795d1c4 100644 --- a/RSPModelLib/src/RSPModel.c +++ b/RSPModelLib/src/RSPModel.c @@ -7,11 +7,12 @@ * */ -#include #include +#include #include #include "config.h" #include "RSPModel_errordefs.h" +#include "RSPModel_datatypes.h" #include "hob_parser.h" #include "RSPModel.h" @@ -55,3 +56,28 @@ unsigned short RSPModel_objectToD3D( const T_RSPMODEL_OBJECT* objStruct, void* D return RSPLIB_SUCCESS; } + +void RSPModel_freeHOB( T_RSPMODEL_HOB* hobStruct ) { + int i,j; + + if (hobStruct == NULL) return; + + if (hobStruct->objects) { + for ( i=0; iobj_count; i++ ) { + if (hobStruct->objects[i].object_parts) { + for ( j=0; jobjects[i].face_group_count; j++ ) { + + if (hobStruct->objects[i].object_parts[j].faces) + free(hobStruct->objects[i].object_parts[j].faces); + + if (hobStruct->objects[i].object_parts[j].vertices) + free(hobStruct->objects[i].object_parts[j].vertices); + } + free(hobStruct->objects[i].object_parts); + } + } + free(hobStruct->objects); + } + + free(hobStruct); +} diff --git a/RSPModelLib/src/hob_parser.c b/RSPModelLib/src/hob_parser.c index 33cb963..f44579e 100644 --- a/RSPModelLib/src/hob_parser.c +++ b/RSPModelLib/src/hob_parser.c @@ -20,18 +20,18 @@ // Private functions declarations //////////////////////////////////////////////////////////////////////////////// -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*); +static unsigned short ExtractObjects(T_RSPMODEL_HOB*, const MEMFILE, const RSPMODEL_PARAMETERS*); +static unsigned short ExtractObjParts(T_RSPMODEL_OBJECT*, const MEMFILE, const RSPMODEL_PARAMETERS*); +static unsigned short ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS*, const MEMFILE, const RSPMODEL_PARAMETERS*); +static unsigned short ExtractObjpart_Face_Colors(T_RSPMODEL_FACE*, const char*); +static unsigned short ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE*, const char*); //////////////////////////////////////////////////////////////////////////////// // Public functions definition //////////////////////////////////////////////////////////////////////////////// -unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) { +unsigned short RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) { unsigned char err = RSPLIB_SUCCESS; if (hobStruct != NULL && pMemFile != NULL) { @@ -42,7 +42,7 @@ unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HO return err; } -unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) { +unsigned short RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) { unsigned char err = RSPLIB_SUCCESS; long fileSize; FILE* fStream = NULL; @@ -94,11 +94,11 @@ unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* ho * * @param[in|out] pHobStruct Take root hob structure to get the T_RSPMODEL_OBJECT buffer and header datas. * @param[in] pMemfile Pointer to an in-memory file location. - * @param[in] verbose + * @param[in] pParams Program option, used to tune parser features. * * @return Error code, RSPLIB_SUCCESS when no error. */ -static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { +static unsigned short 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; @@ -167,11 +167,11 @@ static unsigned int ExtractObjects(T_RSPMODEL_HOB* pHobStruct, const MEMFILE pMe * * @param[in|out] pObject Take object structure to get the T_RSPMODEL_OBJ_PARTS buffer and object datas. * @param[in] pMemfile Pointer to an in-memory file location. - * @param[in] verbose + * @param[in] pParams Program option, used to tune parser features. * * @return Error code, RSPLIB_SUCCESS when no error. */ -static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { +static unsigned short 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; @@ -248,11 +248,11 @@ static unsigned int ExtractObjParts(T_RSPMODEL_OBJECT* pObject, const MEMFILE pM * * @param[in|out] pObjPart Take object sub-part structure to get the T_RSPMODEL_FACE buffer and object sub-part datas. * @param[in] pMemfile Pointer to an in-memory file location. - * @param[in] verbose + * @param[in] pParams Program option, used to tune parser features. * * @return Error code, RSPLIB_SUCCESS when no error. */ -static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const MEMFILE pMemfile, const RSPMODEL_PARAMETERS* pParams) { +static unsigned short 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; @@ -390,7 +390,7 @@ static unsigned int ExtractObjParts_faces(T_RSPMODEL_OBJ_PARTS* pObjPart, const * * @return The size of processed data. Used to count new offset between each face in object sub-part. */ -static inline unsigned int ExtractObjpart_Face_Colors(T_RSPMODEL_FACE* pFace, const char* pFaceMemFileOffset) { +static unsigned short ExtractObjpart_Face_Colors(T_RSPMODEL_FACE* pFace, const char* pFaceMemFileOffset) { unsigned int dynOffset = 0; if (pFace->flags_bits.fSeparateColorVertex) { @@ -423,7 +423,7 @@ static inline unsigned int ExtractObjpart_Face_Colors(T_RSPMODEL_FACE* pFace, co * * @return The size of processed data. Used to count new offset between each face in object sub-part. */ -static inline unsigned int ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE* pFace, const char* pFaceMemFileOffset) { +static unsigned short ExtractObjpart_Face_UVMaps(T_RSPMODEL_FACE* pFace, const char* pFaceMemFileOffset) { unsigned int dynOffset = 0; pFace->tex_coords[0] = ((T_HOBFILE_FACES_VERTEX_TEXTURE *)(pFaceMemFileOffset))->v1_texcoord; diff --git a/RSPModelLib/src/hob_parser.h b/RSPModelLib/src/hob_parser.h index 9bc0926..e112f2e 100644 --- a/RSPModelLib/src/hob_parser.h +++ b/RSPModelLib/src/hob_parser.h @@ -26,7 +26,7 @@ * * @return Processing error code, RSPLIB_SUCCESS if no error. */ -unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, +unsigned short RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams); /** @@ -45,7 +45,7 @@ unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, * * @return Processing error code, RSPLIB_SUCCESS if no error. */ -unsigned char RSP_ModelLib_ParseHOBFile(const char* fileName, +unsigned short RSP_ModelLib_ParseHOBFile(const char* fileName, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams); #endif /* RSPMODELLIB_HOB_PARSER_H_ */ -- 2.39.5