New library structure prototype WIP

This commit is contained in:
JackCarterSmith 2022-08-20 15:04:13 +02:00
parent 7dc3125504
commit 12e79b048c
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
26 changed files with 3172 additions and 2604 deletions

3
.gitignore vendored
View File

@ -15,7 +15,8 @@
# Precompiled Headers
*.gch
*.pch
src/config.h
RSPTerrainLib/src/config.h
RSETerrain/src/config.h
# Libraries
*.lib

6
.gitmodules vendored
View File

@ -1,3 +1,3 @@
[submodule "src/rlk"]
path = src/rlk
url = https://github.com/rlk/obj.git
[submodule "RSETerrain/src/obj"]
path = RSETerrain/src/obj
url = https://git.jcsmith.fr/jackcartersmith/obj.git

View File

@ -14,72 +14,65 @@ if(DEFINED ENV{MS_COMPATIBLE})
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
endif()
include(CheckIncludeFile)
include(CheckCSourceCompiles)
add_definitions(-DCONF_NO_GL) # Used for obj-lib to not compile GL part
#add_definitions(-DNO_PNG_SUPPORT) # Can be used to disable code support for PNG exporting
# Project definition
if(DEFINED ENV{CI}) # Jenkins CI integration mode
project(rse-terrain VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Terrain" LANGUAGES C)
set(RSE_TER_NAME $ENV{CI_OUTPUT_NAME}-${PROJECT_VERSION})
set(RSE_TERRAIN_NAME $ENV{CI_OUTPUT_NAME})
else() # Standalone project mode, should not be used for release.
project(rse-terrain VERSION 1.0.0 DESCRIPTION "RogueSquadron Extractor - Terrain" LANGUAGES C)
set(RSE_TER_NAME RSE_Terrain-${PROJECT_VERSION})
project(rse-terrain VERSION 2.0.0 DESCRIPTION "RogueSquadron Extractor - Terrain" LANGUAGES C)
set(RSE_TERRAIN_NAME RSETerrain)
endif()
set(RSP_TERRAIN_LIB_NAME RSPTerrain${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
# Compilation option
option(RSPTERRAIN_SHARED "Build shared lib" ON)
# Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPTerrainLib/src/config.h @ONLY)
#configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSETerrain/src/config.h @ONLY)
# Import needed packages and references their include path
find_package(ZLIB 1.2.12 REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
find_package(PNG 1.6.37 REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
#find_package(GLEW REQUIRED) # Enable when GL rendering is ready
#include_directories(${GLEW_INCLUDE_DIR})
# Define src/headers files
FILE(GLOB_RECURSE RSE_TER_SOURCES src/*.c)
FILE(GLOB_RECURSE RSE_TER_HEADERS src/*.h)
SOURCE_GROUP("Source Files" FILES ${RSE_TER_SOURCES})
SOURCE_GROUP("Header Files" FILES ${RSE_TER_HEADERS})
# Building instructions for RSE-Terrain
if(DEFINED ENV{RSE-WS})
set(CMAKE_BUILD_TYPE DEBUG)
endif()
#include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(rse-terrain ${RSE_TER_SOURCES} ${RSE_TER_HEADERS}) # Set the inputs for the compiler (srcs&hrds)
set_property(TARGET rse-terrain PROPERTY C_STANDARD 90)
set_target_properties(rse-terrain PROPERTIES OUTPUT_NAME ${RSE_TER_NAME}) # Define the executable file name
# Link externals libraries to the linker
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
#set_target_properties(rse-terrain PROPERTIES PREFIX "lib")
set_target_properties(rse-terrain PROPERTIES IMPORT_PREFIX "lib")
target_link_libraries(rse-terrain ${ZLIB_LIBRARIES} ${PNG_LIBRARIES} ${GLEW_LIBRARIES})
else()
target_link_libraries(rse-terrain ${ZLIB_LIBRARIES} ${PNG_LIBRARIES} ${GLEW_LIBRARIES} m)
endif()
# The project is divided in two parts:
# - RSPTerrainLib is the parser library for terrain type data, it's take hmp file as input and output extracted datas.
# It is intended to be used by others apps like rendering engine or others.
# - RSETerrain is the standalone application of the library, take hmp file in argument and output OBJ/MTL file.
# Artists or users can directly use this program to retrieve data in common datas format.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
add_subdirectory(RSPTerrainLib)
add_subdirectory(RSETerrain)
# GPG signature custom command
#add_custom_command(
# OUTPUT ""
# COMMAND gpg --batch --detach-sign
# -o ${RSE_TER_NAME}_${CI_SYS_TARGET}.gpg
# ${RSE_TER_NAME}
# DEPENDS ${RSE_TER_NAME}
# -o ${RSE_MOD_NAME}_${CI_SYS_TARGET}.gpg
# ${RSE_MOD_NAME}
# DEPENDS ${RSE_MOD_NAME}
# VERBATIM
#)
# Install project executable
install(TARGETS rse-terrain
RUNTIME DESTINATION bin
)
set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
if(RSPTERRAIN_SHARED)
set(RSE_TERRAIN_TARGETS_LIST rse-terrain rsp-terrain-lib rsp-terrain-libstatic)
else()
set(RSE_TERRAIN_TARGETS_LIST rse-terrain rsp-terrain-libstatic)
endif()
install(TARGETS ${RSE_TERRAIN_TARGETS_LIST}
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
)
# Install library includes
install(FILES ${RSP_PUBLIC_HRDS} DESTINATION ${INSTALL_INC_DIR})
# Install dependancies
install(FILES ${PROJECT_BINARY_DIR}/bin/glew32.dll
DESTINATION ${INSTALL_BIN_DIR})

25
Jenkinsfile vendored
View File

@ -4,8 +4,8 @@ pipeline {
skipDefaultCheckout(true)
}
environment {
CI_OUTPUT_NAME = "RSE_Terrain"
CI_VERSION = "1.0.0"
CI_OUTPUT_NAME = "RSETerrain"
CI_VERSION = "2.0.0"
CI_BUILD_NUMBER = "$BUILD_NUMBER"
}
stages {
@ -23,7 +23,7 @@ pipeline {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Terrain'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Terrain.git']]])
sh 'git submodule update --init --recursive'
dir("build") {
rtConanRun(clientId: "conan", command: "install .. --build missing")
rtConanRun(clientId: "conan", command: "install .. --build=missing")
}
cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']]
}
@ -33,9 +33,9 @@ pipeline {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Terrain'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Terrain.git']]])
sh 'git submodule update --init --recursive'
dir("build") {
rtConanRun(clientId: "conan", command: "install .. --profile windows --build missing")
rtConanRun(clientId: "conan", command: "install .. --profile=windows --build=missing")
}
cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']]
cmakeBuild buildDir: 'build', cmakeArgs: '-DGNU_HOST=x86_64-w64-mingw32 -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_cross_toolchain.cmake', installation: 'latest', steps: [[args: 'all']]
}
}
)
@ -44,24 +44,23 @@ pipeline {
stage('Deploy') {
steps {
dir("zip_linux") {
sh 'cp ../linux/build/${CI_OUTPUT_NAME}-${CI_VERSION}.${BUILD_NUMBER}* .'
sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/RSPTerrainLib/include .'
}
dir("zip_win") {
sh 'cp ../windows/build/${CI_OUTPUT_NAME}-${CI_VERSION}.${BUILD_NUMBER}* ../windows/build/*.dll .'
sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/RSPTerrainLib/include .'
}
zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'x64.zip'
sh 'mv x64.zip ${CI_OUTPUT_NAME}-${CI_VERSION}.${BUILD_NUMBER}_x64.zip'
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'
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}_x64.zip.gpg ${CI_OUTPUT_NAME}-${CI_VERSION}.${BUILD_NUMBER}_x64.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'
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')
}

View File

@ -28,7 +28,7 @@ This module can do:
### Using
`RSE-Terrain_"version" [options] <hob files...>` or you can simply drag&drop HOB files on it.
`RSETerrain [options] <hob files...>` or you can simply drag&drop HOB files on it.
A futur main program can extract all HOB files directly from DAT file.
Due to issue with copyrights, I can't provide samples... You need to extract HOB files yourself.
@ -44,12 +44,10 @@ Due to issue with copyrights, I can't provide samples... You need to extract HOB
### Dependencies
- obj-lib: as obj file exporter. (https://github.com/rlk/obj)
- obj-lib: as obj file exporter. (https://git.jcsmith.fr/jackcartersmith/obj)
### Compiling
:mega: **MSVC compatibility is in progress. Not working for now but you can try to fix error by yourself.**
You can compile on both Windows (MinGW) or native Linux system thanks to CMake, you only need to adjust your dependencies on Windows or use Conan packages manager (https://conan.io).
zlib-dev (zlib1g-dev) and libpng16-dev distrib packages can be used on debian/ubuntu.
@ -80,7 +78,7 @@ We can also use cross-compilation (after installing `mingw64` and `cmake` packag
```shell
mkdir build && cd build
cmake -DGNU_HOST=x86_64-w64-mingw32 \
-DCMAKE_TOOLCHAIN_FILE=../mingw_cross_toolchain.cmake \
-DCMAKE_TOOLCHAIN_FILE=../cmake/mingw_cross_toolchain.cmake \
-D"ZLIB_INCLUDE_DIR=zlib/1.2.11/include" \
-D"ZLIB_LIBRARY=zlib/1.2.11/lib/libzlib.dll.a" \
-D"PNG_PNG_INCLUDE_DIR=libpng/1.6.37/include" \

49
RSETerrain/CMakeLists.txt Normal file
View File

@ -0,0 +1,49 @@
# CMakeLists.txt
####################################################
# Written by JackCarterSmith, 2022
# This code is released under the RSE license.
####################################################
# General configuration
include(CheckIncludeFile)
include(CheckCSourceCompiles)
add_definitions(-DCONF_NO_GL) # Used for obj-lib to not compile GL part
# Import needed packages and references their include path
find_package(ZLIB 1.2.12 REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR})
find_package(PNG 1.6.37 REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
#find_package(GLEW REQUIRED) # Enable when GL rendering is ready
#include_directories(${GLEW_INCLUDE_DIR})
# Define src/headers files
file(GLOB_RECURSE RSE_TERRAIN_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSE_TERRAIN_SOURCES})
# Building instructions for RSE-Terrain
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# Declare standalone application
add_executable(rse-terrain ${RSE_TERRAIN_SOURCES})
set_property(TARGET rse-terrain PROPERTY C_STANDARD 90)
#target_include_directories(rse-terrain PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(rse-terrain PROPERTIES OUTPUT_NAME ${RSE_TERRAIN_NAME})
# Link externals libraries to the linker
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rse-terrain PROPERTIES IMPORT_PREFIX "lib")
target_link_libraries(rse-terrain PRIVATE rsp-terrain-libstatic ${ZLIB_LIBRARIES} ${PNG_LIBRARIES} ${GLEW_LIBRARIES})
else()
target_link_libraries(rse-terrain PRIVATE rsp-terrain-libstatic ${ZLIB_LIBRARIES} ${PNG_LIBRARIES} ${GLEW_LIBRARIES} m)
endif()

1
RSETerrain/src/obj Submodule

@ -0,0 +1 @@
Subproject commit 59191c204ab030aabc34cf758efefdaf2de65401

View File

@ -1,38 +1,38 @@
/**
* \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_
// Number of height values to take for computing terrain (default: 4)
#define TERRAIN_TILE_SAMPLING 4
// Scale value for vertex grid constructor (default: 0.1)
#define TERRAIN_MESH_SCALE 0.1
/// 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 inverted_HM:1; //!< Enable negative heightmap output.
unsigned char reserved0:6; //!< 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_ */
/**
* \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_
// Number of height values to take for computing terrain (default: 4)
#define TERRAIN_TILE_SAMPLING 4
// Scale value for vertex grid constructor (default: 0.1)
#define TERRAIN_MESH_SCALE 0.1
/// 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 inverted_HM:1; //!< Enable negative heightmap output.
unsigned char reserved0:6; //!< 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_ */

View File

@ -0,0 +1,67 @@
# CMakeLists.txt
####################################################
# Written by JackCarterSmith, 2022
# This code is released under the RSE license.
####################################################
# General library configuration
if(DEFINED ENV{MS_COMPATIBLE})
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
endif()
include(CheckIncludeFile)
include(CheckCSourceCompiles)
# Define src/headers files
file(GLOB_RECURSE RSP_TERRAIN_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSP_TERRAIN_SOURCES})
file(GLOB RSP_PUBLIC_HRDS ./include/*.h)
set(RSP_PUBLIC_HRDS ${RSP_PUBLIC_HRDS} PARENT_SCOPE)
# Building instructions for RSP-Terrain library
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# Declare the shared library instance
if(RSPTERRAIN_SHARED)
add_library(rsp-terrain-lib SHARED ${RSP_TERRAIN_SOURCES})
set_property(TARGET rsp-terrain-lib PROPERTY C_STANDARD 90)
target_include_directories(rsp-terrain-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(rsp-terrain-lib PROPERTIES OUTPUT_NAME ${RSP_TERRAIN_LIB_NAME})
set_target_properties(rsp-terrain-lib PROPERTIES DEFINE_SYMBOL RSPTERRAIN_DLL)
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-terrain-lib PROPERTIES PREFIX "lib")
set_target_properties(rsp-terrain-lib PROPERTIES IMPORT_PREFIX "lib")
endif()
endif()
# Declare the static library instance
add_library(rsp-terrain-libstatic STATIC ${RSP_TERRAIN_SOURCES})
set_property(TARGET rsp-terrain-libstatic PROPERTY C_STANDARD 90)
target_include_directories(rsp-terrain-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(NOT MSVC)
set_target_properties(rsp-terrain-libstatic PROPERTIES OUTPUT_NAME "${RSP_TERRAIN_LIB_NAME}")
set_target_properties(rsp-terrain-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(rsp-terrain-libstatic PROPERTIES OUTPUT_NAME "${RSP_TERRAIN_LIB_NAME}_static")
set_target_properties(rsp-terrain-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-terrain-libstatic PROPERTIES PREFIX "lib")
set_target_properties(rsp-terrain-libstatic PROPERTIES IMPORT_PREFIX "lib")
endif()

View File

@ -0,0 +1,121 @@
/**
* @file RSPModel.h
* @date 11/08/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Squadron Parser model library, used to decode decode datas
* from original game file and access them through public interface.
*
*/
#include "RSPModel_datatypes.h"
#ifndef RSPMODEL_H_
#define RSPMODEL_H_
#if defined(_MSC_VER)
# define RSPMODEL_ABI_EXPORT __declspec(dllexport)
# define RSPMODEL_ABI_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
# define RSPMODEL_ABI_EXPORT __attribute__ ((visibility("default")))
# define RSPMODEL_ABI_IMPORT __attribute__ ((visibility("default")))
#else
# define RSPMODEL_ABI_EXPORT
# define RSPMODEL_ABI_IMPORT
#endif
#if defined(RSPMODEL_DLL)
# if defined(WIN32)
# if defined(RSPMODEL_DLLBUILD)
# define RSPMODEL_EXTERN extern RSPMODEL_ABI_EXPORT
# else
# define RSPMODEL_EXTERN extern RSPMODEL_ABI_IMPORT
# endif
# endif
#endif
#ifndef RSPMODEL_EXTERN
# define RSPMODEL_EXTERN extern
#endif
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////
// Library's functions declaration
///////////////////////////////////////////////////////////////////////////////
/**
* @brief Get the current library version.
* @return Char array of the version, escape char included.
*/
RSPMODEL_EXTERN char* RSPModel_getVersion( void );
/**
* @brief Run model parser for the specified file in file system.
* @details Model library can process HOB file from file system. It's a easy
* approach using this library for debugging purpose.
*
* @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,
const RSPMODEL_PARAMETERS params
);
/**
* @brief Run model parser for the specified file in memory.
* @details Model library can process HOB file directly stored in RAM memory,
* you must load the file beforehand through a malloc/memcpy call.
* @warning No controls routines are implemented to verify file length!
*
* @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,
const RSPMODEL_PARAMETERS params
);
/**
* @brief Convert HOB's object datas to GL compatible format.
* @note Only available if GL module as specified at compilation.
*
* @param[in] objStruct Object datas from previously parsed HOB file.
* @param[out] glObj GL structure.
*
* @return Error status, return RSPLIB_SUCCESS in nominal case.
*/
RSPMODEL_EXTERN unsigned short RSPModel_objectToGL(
const T_RSPMODEL_OBJECT* objStruct, void* glObj
);
/**
* @brief Convert HOB's object datas to Direct3D compatible format.
* @note Only available if D3D module as specified at compilation.
*
* @param[in] objStruct Object datas from previously parsed HOB file.
* @param[out] D3DObj Direct3D structure.
*
* @return Error status, return RSPLIB_SUCCESS in nominal case.
*/
RSPMODEL_EXTERN unsigned short RSPModel_objectToD3D(
const T_RSPMODEL_OBJECT* objStruct, void* D3DObj
);
#ifdef __cplusplus
}
#endif
#endif /* RSPMODEL_H_ */

View File

@ -0,0 +1,122 @@
/**
* @file RSPModel_datatypes.h
* @date 11/08/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief RSP Model workflow structures definitions
*
*/
#ifndef RSPMODEL_DATATYPES_H_
#define RSPMODEL_DATATYPES_H_
#ifdef __cplusplus
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
////////////////////////////////////////////////////////////////////////////////
typedef char* MEMFILE;
typedef unsigned int T_RGBA;
typedef struct vector3 { float x,y,z; } T_VECTOR3;
typedef struct vertex { short x,y,z,w; } T_VERTEX;
typedef struct tex_coord { unsigned short u,v; } T_TEXCOORD;
typedef struct face_flags {
unsigned int fUnknown0:1;
unsigned int fUnknown1:1;
unsigned int fHasTexture:1;
unsigned int fIsQuad:1;
unsigned int fSeparateColorVertex:1;
unsigned int fHasColor:1;
unsigned int fHasExtraBytesBeforeColor:1;
unsigned int fUnknown7:1;
unsigned int fUnknown8:1;
unsigned int fUnknown9:1;
unsigned int fUnknown10:1;
unsigned int reserved:21;
} FACE_FLAGS;
typedef struct hob_face {
union {
unsigned int flags;
FACE_FLAGS flags_bits;
};
unsigned char b1;
unsigned char b2;
unsigned char b3;
unsigned char bsize;
unsigned short material_index;
unsigned short indices[4];
T_RGBA vertex_colors[4]; //TODO: convert in R:8_G:8_B:8_A:8 format? Caution with BE/LE conversion
T_TEXCOORD tex_coords[4];
} T_RSPMODEL_FACE;
typedef struct rspmodel_obj_parts {
unsigned int meshdef1_offset;
unsigned int face_block_end_offset;
unsigned int face_block_offset;
unsigned int vertex_block_offset;
unsigned int id;
T_VECTOR3 transform;
unsigned int face_count;
T_RSPMODEL_FACE* faces;
unsigned int vertex_count;
T_VERTEX* vertices;
} T_RSPMODEL_OBJ_PARTS;
typedef struct rspmodel_object {
char name[16];
unsigned int face_group_offset;
unsigned int object_part_header_offset;
unsigned int face_group_header_offset;
unsigned int object_part_count;
unsigned int face_group_count;
T_RSPMODEL_OBJ_PARTS* object_parts;
} T_RSPMODEL_OBJECT;
/**
* @brief Model-Extractor HOB structure of an HOB file content.
* @details Used with malloc to create a clean method of bufferized
* model datas before saving it.
* @todo Export format to use it directly in other program.
*/
typedef struct rspmodel_hob {
unsigned int obj_count;
T_RSPMODEL_OBJECT* objects;
} T_RSPMODEL_HOB;
#ifdef __cplusplus
}
#endif
#endif /* RSPMODEL_DATATYPES_H_ */

View File

@ -0,0 +1,45 @@
/**
* @file RSPModel_errordefs.h
* @date 26/07/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Errors type definition file. Used mostly by methods in this project.
*
*/
#include <stdlib.h>
#ifndef RSPMODELLIB_ERRORS_H_
#define RSPMODELLIB_ERRORS_H_
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////////////
// Errors types definitions
///////////////////////////////////////////////////////////////////////////////
#ifndef NO_ERROR
#define NO_ERROR 0 // In case of dual declaration by GCC
#endif
#define RSPLIB_SUCCESS NO_ERROR //!< All is running good!
#define RSPLIB_ERROR_GENERIC 1 //!< Misuse of the program
#define RSPLIB_ERROR_MEMORY 2 //!< Memory de/allocation failure
#define RSPLIB_ERROR_IO 3 //!< File system access failure
#define RSPLIB_ERROR_PROCESS 4 //!< Internal processing failure
#define RSPLIB_ERROR_ARGS_NULL 16 //!< Method not NULL input expected
#define RSPLIB_ERROR_ARGS_RANGE 17 //!< Method input out of expected range
#define RSPLIB_ERROR_MOD_DISABLED 64 //!< A necessary module hasn't been activated during compilation time
#define RSPLIB_ERROR_REALITY_BRK -1 //!< This error can only appear in alternate reality
#ifdef __cplusplus
}
#endif
#endif /* RSPMODELLIB_ERRORS_H_ */

View File

@ -0,0 +1,168 @@
/**
* \file Terrain-Extractor.c
* \date 31/07/2022
* \author JackCarterSmith
* \copyright GPL-v3.0
* \brief Terrain file (hmp) parser with option to export to both Waveform OBJ format and grey-scale PNG heightmap.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(_WIN32)
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include "errors_types.h"
#include "config.h"
#include "options.h"
#include "hmp_struct.h"
#include "hmp_parser.h"
#include "hmp_export.h"
/*
* Internal functions declarations
*/
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 dispHelp();
/*
* - MAIN -
*/
int main(int argc, char *argv[]) {
T_PROG_OPTIONS _opts;
unsigned char p;
// Hello world!
printf("\n*** RogueSquadron Extractor (RSE) - TERRAIN module - v%s ***\n", VERSION);
// Check for arguments
if (argc < 2) {
printf("\n[ERR] No input file/commands specified!\n");
dispHelp();
return ERROR_ARGS_NULL;
}
// Create options for programs according to user's arguments.
p = checkInputArgs(&_opts, argc, argv);
if ( p == ERROR_GENERIC ) return NO_ERROR;
else if ( p != NO_ERROR ) return p;
return mainProcess(argc, argv, &_opts);
}
/*
* Private functions definition
*/
static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* p_opts) {
unsigned short file_index;
T_TERRAIN* terrainStruct = NULL;
// 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]);
terrainStruct = calloc(1, sizeof(T_TERRAIN));
// Parse data from HOB file and put in T_HOB structure.
if (parseHMPFile(args_value[file_index], terrainStruct, p_opts) != NO_ERROR) {
printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]);
free(terrainStruct);
return ERROR_PROCESS;
}
if (p_opts->output_dir) createSubDir(args_value[file_index]);
#ifndef NO_PNG_SUPPORT
if (exportHeightmapPNG(terrainStruct, args_value[file_index], p_opts) != NO_ERROR)
printf("[ERR] Failed to export heightmap to PNG format!\n");
else
printf("[INFO] Successfully exported heightmap to PNG format.\n");
#endif
if (exportHeightmapOBJ(terrainStruct, args_value[file_index], p_opts) != NO_ERROR)
printf("[ERR] Failed to export terrain in OBJ format!\n");
else
printf("[INFO] Successfully exported terrain in OBJ format.\n");
cleanUpResources(terrainStruct);
}
return NO_ERROR;
}
static unsigned char checkInputArgs(T_PROG_OPTIONS* opt_ptr, int p_arg_nbr, char* p_args[]) {
char test[256];
int i;
// Set default options
opt_ptr->raw = 0;
if (p_arg_nbr > 1) {
for ( i = 1; i < p_arg_nbr; i++) {
strcpy(test, p_args[i]);
if (p_args[i][0] != '-') break;
if (strcmp(p_args[i], "-h") == 0) {
dispHelp();
return ERROR_GENERIC;
} else if (strcmp(p_args[i], "-v") == 0) {
opt_ptr->verbose_mode = 1;
printf("[OPTN] Verbose enabled.\n");
} else if (strcmp(p_args[i], "-vv") == 0) {
opt_ptr->verbose_mode = 1;
opt_ptr->debug_mode = 1;
printf("[OPTN] Debug enabled.\n");
} else if (strcmp(p_args[i], "-vvv") == 0) {
opt_ptr->verbose_mode = 1;
opt_ptr->debug_mode = 1;
opt_ptr->god_mode = 1;
printf("[OPTN] God damn it!\n");
} else if (strcmp(p_args[i], "-subdir") == 0) {
opt_ptr->output_dir = 0;
printf("[OPTN] Export to sub-directory.\n");
} else if (strcmp(p_args[i], "-neg") == 0) {
opt_ptr->inverted_HM = 1;
printf("[OPTN] Negative heightmap output mode.\n");
} else {
printf("[ERR] Unknown option: %s\n", p_args[i]);
}
}
opt_ptr->input_files_cnt = i;
return NO_ERROR;
}
return ERROR_ARGS_NULL;
}
static void createSubDir(char *dirName) {
if (dirName == NULL) return;
char _dir[260]; //TODO: Change directory management
strcpy(_dir, dirName);
strcat(_dir, "-out");
#ifdef _WIN32
CreateDirectory(_dir, NULL);
#else
mkdir(_dir, 0755);
#endif
}
static void dispHelp() {
printf("\n");
printf("Options:\n -h Print this message\n");
printf(" -v -vv Activate verbose console output\n");
printf(" -subdir Export output to a sub-directory\n");
printf(" -neg Negative heightmap output\n");
printf("\n");
printf("Usage: RSE-Terrain_%s [options] <hmp_file>\n", VERSION);
printf("\n");
}

View File

@ -13,4 +13,4 @@ libpng:shared=True
glew:shared=True
[imports]
bin, *.dll -> .
bin, *.dll -> ./bin

6
config.h.in Normal file
View File

@ -0,0 +1,6 @@
#ifndef CONFIG_H_
#define CONFIG_H_
#define PRG_VERSION "@PROJECT_VERSION@"
#endif /* CONFIG_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
#define VERSION "@PROJECT_VERSION@"

@ -1 +0,0 @@
Subproject commit 48a6916526d043691bb3f9e38676fbc99995da10