Clean up and lib rewrite WIP
This commit is contained in:
parent
12e79b048c
commit
fabc150e31
@ -23,7 +23,6 @@ This module can do:
|
|||||||
|
|
||||||
- Add textures to terrain.
|
- Add textures to terrain.
|
||||||
- Adding LOD method to optimize datas manipulation and rendering.
|
- Adding LOD method to optimize datas manipulation and rendering.
|
||||||
- Rewrite OBJ lib...
|
|
||||||
- Discover all last unknowns fields, etc.
|
- Discover all last unknowns fields, etc.
|
||||||
|
|
||||||
### Using
|
### Using
|
||||||
|
@ -1,121 +0,0 @@
|
|||||||
/**
|
|
||||||
* @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_ */
|
|
@ -1,122 +0,0 @@
|
|||||||
/**
|
|
||||||
* @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_ */
|
|
121
RSPTerrainLib/include/RSPTerrain.h
Normal file
121
RSPTerrainLib/include/RSPTerrain.h
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
/**
|
||||||
|
* @file RSPTerrain.h
|
||||||
|
* @date 22/08/2022
|
||||||
|
* @author JackCarterSmith
|
||||||
|
* @copyright GPL-v3.0
|
||||||
|
* @brief Rogue Squadron Parser terrain library, used to decode decode datas
|
||||||
|
* from original game file and access them through public interface.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "RSPTerrain_datatypes.h"
|
||||||
|
|
||||||
|
#ifndef RSPTERRAINLIB_H_
|
||||||
|
#define RSPTERRAINLIB_H_
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# define RSPTERRAIN_ABI_EXPORT __declspec(dllexport)
|
||||||
|
# define RSPTERRAIN_ABI_IMPORT __declspec(dllimport)
|
||||||
|
#elif __GNUC__ >= 4
|
||||||
|
# define RSPTERRAIN_ABI_EXPORT __attribute__ ((visibility("default")))
|
||||||
|
# define RSPTERRAIN_ABI_IMPORT __attribute__ ((visibility("default")))
|
||||||
|
#else
|
||||||
|
# define RSPTERRAIN_ABI_EXPORT
|
||||||
|
# define RSPTERRAIN_ABI_IMPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(RSPTERRAIN_DLL)
|
||||||
|
# if defined(WIN32)
|
||||||
|
# if defined(RSPTERRAIN_DLLBUILD)
|
||||||
|
# define RSPTERRAIN_EXTERN extern RSPTERRAIN_ABI_EXPORT
|
||||||
|
# else
|
||||||
|
# define RSPTERRAIN_EXTERN extern RSPTERRAIN_ABI_IMPORT
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef RSPTERRAIN_EXTERN
|
||||||
|
# define RSPTERRAIN_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.
|
||||||
|
*/
|
||||||
|
RSPTERRAIN_EXTERN char* RSPTerrain_getVersion( void );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Run terrain parser for the specified file in file system.
|
||||||
|
* @details Model library can process HMP file from file system. It's a easy
|
||||||
|
* approach using this library for debugging purpose.
|
||||||
|
*
|
||||||
|
* @param[out] terrainObj Terrain structure to be filled with parsed datas.
|
||||||
|
* @param[in] filePath Path to the HMP file in system.
|
||||||
|
* @param[in] params Parser options. See RSPMODEL_PARAMETERS.
|
||||||
|
*
|
||||||
|
* @return Error status, return RSPLIB_SUCCESS in nominal case.
|
||||||
|
*/
|
||||||
|
RSPTERRAIN_EXTERN unsigned short RSPTerrain_processHMPFile(
|
||||||
|
T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, const char* const filePath,
|
||||||
|
const RSPTERRAIN_PARAMETERS params
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Run terrain parser for the specified file in memory.
|
||||||
|
* @details Model library can process HMP 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] terrainObj Terrain 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.
|
||||||
|
*/
|
||||||
|
RSPTERRAIN_EXTERN unsigned short RSPTerrain_processHMPFileMemory(
|
||||||
|
T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, const void* const memFilePtr, const long memFileSize,
|
||||||
|
const RSPTERRAIN_PARAMETERS params
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert terrain object to GL compatible format.
|
||||||
|
* @note Only available if GL module as specified at compilation.
|
||||||
|
*
|
||||||
|
* @param[in] terrainObj Terrain datas from previously parsed HMP file.
|
||||||
|
* @param[out] glTerrainObj GL structure.
|
||||||
|
*
|
||||||
|
* @return Error status, return RSPLIB_SUCCESS in nominal case.
|
||||||
|
*/
|
||||||
|
RSPTERRAIN_EXTERN unsigned short RSPTerrain_terrainToGL(
|
||||||
|
const T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, void* glTerrainObj
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert terrain object to Direct3D compatible format.
|
||||||
|
* @note Only available if D3D module as specified at compilation.
|
||||||
|
*
|
||||||
|
* @param[in] terrainObj Terrain datas from previously parsed HMP file.
|
||||||
|
* @param[out] D3DTerrainObj Direct3D structure.
|
||||||
|
*
|
||||||
|
* @return Error status, return RSPLIB_SUCCESS in nominal case.
|
||||||
|
*/
|
||||||
|
RSPTERRAIN_EXTERN unsigned short RSPTerrain_terrainToD3D(
|
||||||
|
const T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, void* D3DTerrainObj
|
||||||
|
);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* RSPTERRAINLIB_H_ */
|
65
RSPTerrainLib/include/RSPTerrain_datatypes.h
Normal file
65
RSPTerrainLib/include/RSPTerrain_datatypes.h
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* @file RSPTerrain_datatypes.h
|
||||||
|
* @date 11/08/2022
|
||||||
|
* @author JackCarterSmith
|
||||||
|
* @copyright GPL-v3.0
|
||||||
|
* @brief RSP Terrain workflow structures definitions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef RSPTERRAINLIB_DATATYPES_H_
|
||||||
|
#define RSPTERRAINLIB_DATATYPES_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Configuration structure
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
typedef union u_rspterrain_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:2; //!< For future use.
|
||||||
|
|
||||||
|
unsigned char inverted_HM:1; //!< Enable negative heightmap output.
|
||||||
|
|
||||||
|
unsigned char reserved1:2; //!< For future use.
|
||||||
|
};
|
||||||
|
unsigned char raw; //!< Raw options access for bit-masking or memory copy/compare.
|
||||||
|
} RSPTERRAIN_PARAMETERS ;
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Lib's structure definitions
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef MEMFILE
|
||||||
|
typedef char* MEMFILE;
|
||||||
|
#endif
|
||||||
|
#ifndef T_VECTOR3
|
||||||
|
typedef struct vector3 { float x,y,z; } T_VECTOR3;
|
||||||
|
#endif
|
||||||
|
#ifndef T_VERTEX
|
||||||
|
typedef T_VECTOR3 T_VERTEX;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct rspterrain_terrain_obj {
|
||||||
|
unsigned short width; // Dimension of the height/vertices map
|
||||||
|
unsigned short height;
|
||||||
|
|
||||||
|
unsigned char** heightmap;
|
||||||
|
|
||||||
|
unsigned int verticesmap_size;
|
||||||
|
T_VERTEX* verticesmap;
|
||||||
|
} T_RSPTERRAIN_TERRAIN_OBJ ;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* RSPTERRAINLIB_DATATYPES_H_ */
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* @file RSPModel_errordefs.h
|
* @file RSPTerrain_errordefs.h
|
||||||
* @date 26/07/2022
|
* @date 22/08/2022
|
||||||
* @author JackCarterSmith
|
* @author JackCarterSmith
|
||||||
* @copyright GPL-v3.0
|
* @copyright GPL-v3.0
|
||||||
* @brief Errors type definition file. Used mostly by methods in this project.
|
* @brief Errors type definition file. Used mostly by methods in this project.
|
||||||
@ -10,8 +10,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef RSPMODELLIB_ERRORS_H_
|
#ifndef RSPLIB_ERRORS_H_
|
||||||
#define RSPMODELLIB_ERRORS_H_
|
#define RSPLIB_ERRORS_H_
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -42,4 +42,4 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* RSPMODELLIB_ERRORS_H_ */
|
#endif /* RSPLIB_ERRORS_H_ */
|
@ -1,28 +0,0 @@
|
|||||||
/*
|
|
||||||
* errors_types.h
|
|
||||||
*
|
|
||||||
* Created on: 26 juil. 2022
|
|
||||||
* Author: JackCarterSmith
|
|
||||||
*/
|
|
||||||
|
|
||||||
//#include "error.h" //TODO: use it as base for error ID
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SRC_ERRORS_TYPES_H_
|
|
||||||
#define SRC_ERRORS_TYPES_H_
|
|
||||||
|
|
||||||
#ifdef NO_ERROR
|
|
||||||
#undef NO_ERROR
|
|
||||||
#endif
|
|
||||||
#define NO_ERROR 0
|
|
||||||
#define ERROR_GENERIC 1
|
|
||||||
#define ERROR_MEMORY 2
|
|
||||||
#define ERROR_IO 3
|
|
||||||
#define ERROR_PROCESS 4
|
|
||||||
|
|
||||||
#define ERROR_ARGS_NULL 10
|
|
||||||
#define ERROR_ARGS_RANGE 11
|
|
||||||
|
|
||||||
#define ERROR_REALITY_BROKED -1
|
|
||||||
|
|
||||||
#endif /* SRC_ERRORS_TYPES_H_ */
|
|
@ -1,168 +1,60 @@
|
|||||||
/**
|
/**
|
||||||
* \file Terrain-Extractor.c
|
* @file RSPTerrain.c
|
||||||
* \date 31/07/2022
|
* @date 22/08/2022
|
||||||
* \author JackCarterSmith
|
* @author JackCarterSmith
|
||||||
* \copyright GPL-v3.0
|
* @copyright GPL-v3.0
|
||||||
* \brief Terrain file (hmp) parser with option to export to both Waveform OBJ format and grey-scale PNG heightmap.
|
* @brief HMP terrain datas parser and export to Waveform OBJ format and greyscale PNG heightmap.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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 "config.h"
|
||||||
#include "options.h"
|
#include "RSPTerrain_errordefs.h"
|
||||||
#include "hmp_struct.h"
|
|
||||||
#include "hmp_parser.h"
|
#include "hmp_parser.h"
|
||||||
#include "hmp_export.h"
|
#include "RSPTerrain.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
char* RSPTerrain_getVersion( void ) {
|
||||||
* Internal functions declarations
|
return PRG_VERSION;
|
||||||
*/
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
unsigned short RSPTerrain_processHMPFile( T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, const char* const filePath,
|
||||||
* Private functions definition
|
const RSPTERRAIN_PARAMETERS params ) {
|
||||||
*/
|
|
||||||
|
|
||||||
static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS* p_opts) {
|
if ( terrainObj == NULL || filePath == NULL ) return RSPLIB_ERROR_ARGS_NULL;
|
||||||
unsigned short file_index;
|
|
||||||
T_TERRAIN* terrainStruct = NULL;
|
|
||||||
|
|
||||||
// Manage multiple inputs files
|
RSP_TerrainLib_ParseHMPFile(filePath, terrainObj, ¶ms);
|
||||||
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]);
|
return RSPLIB_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NO_PNG_SUPPORT
|
unsigned short RSPTerrain_processHMPFileMemory( T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, const void* const memFilePtr,
|
||||||
if (exportHeightmapPNG(terrainStruct, args_value[file_index], p_opts) != NO_ERROR)
|
const long memFileSize, const RSPTERRAIN_PARAMETERS params ) {
|
||||||
printf("[ERR] Failed to export heightmap to PNG format!\n");
|
|
||||||
else
|
if ( terrainObj == NULL || memFilePtr == NULL ) return RSPLIB_ERROR_ARGS_NULL;
|
||||||
printf("[INFO] Successfully exported heightmap to PNG format.\n");
|
|
||||||
|
RSP_TerrainLib_ParseHMPMemFile((MEMFILE)memFilePtr, terrainObj, ¶ms);
|
||||||
|
|
||||||
|
return RSPLIB_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short RSPTerrain_terrainToGL( const T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, void* glTerrainObj ) {
|
||||||
|
#ifndef GL_SUPPORT
|
||||||
|
return RSPLIB_ERROR_MOD_DISABLED;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (exportHeightmapOBJ(terrainStruct, args_value[file_index], p_opts) != NO_ERROR)
|
return RSPLIB_SUCCESS;
|
||||||
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[]) {
|
unsigned short RSPTerrain_terrainToD3D( const T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, void* D3DTerrainObj ) {
|
||||||
char test[256];
|
#ifndef D3D_SUPPORT
|
||||||
int i;
|
return RSPLIB_ERROR_MOD_DISABLED;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Set default options
|
return RSPLIB_SUCCESS;
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
@ -1,20 +1,48 @@
|
|||||||
/**
|
/**
|
||||||
* \file hmp_parser.c
|
* @file hmp_parser.c
|
||||||
* \date 31/07/2022
|
* @date 22/08/2022
|
||||||
* \author JackCarterSmith
|
* @author JackCarterSmith
|
||||||
* \copyright GPL-v3.0
|
* @copyright GPL-v3.0
|
||||||
* \brief Decode terrain file (hmp) structure.
|
* @brief Process HMP file structure and extract its datas.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "errors_types.h"
|
#include "RSPTerrain_errordefs.h"
|
||||||
#include "options.h"
|
#include "RSPTerrain_datatypes.h"
|
||||||
#include "hmp_struct.h"
|
#include "hmp_struct.h"
|
||||||
#include "hmp_parser.h"
|
#include "hmp_parser.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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*);
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Public functions definition
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
unsigned char RSP_ModelLib_ParseHOBMemFile(const MEMFILE pMemFile, T_RSPMODEL_HOB* hobStruct, const RSPMODEL_PARAMETERS* pParams) {
|
||||||
|
unsigned char err = RSPLIB_SUCCESS;
|
||||||
|
|
||||||
|
if (hobStruct != NULL && pMemFile != NULL) {
|
||||||
|
// Do the magic!
|
||||||
|
err = ExtractObjects(hobStruct, pMemFile, pParams);
|
||||||
|
} else err = RSPLIB_ERROR_ARGS_NULL;
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void processTilesToHeightmap(T_TERRAIN* terrain, const T_TILE_INDICES* tiles_indices,
|
static void processTilesToHeightmap(T_TERRAIN* terrain, const T_TILE_INDICES* tiles_indices,
|
||||||
const T_HMPFILE_TILE* tiles, const unsigned char negativeOutput);
|
const T_HMPFILE_TILE* tiles, const unsigned char negativeOutput);
|
||||||
static void processHeighmapToVertices(T_TERRAIN* terrain, const float h_scale);
|
static void processHeighmapToVertices(T_TERRAIN* terrain, const float h_scale);
|
||||||
|
@ -1,18 +1,51 @@
|
|||||||
/**
|
/**
|
||||||
* \file hmp_parser.h
|
* @file hmp_parser.h
|
||||||
* \date 31/07/2022
|
* @date 22/08/2022
|
||||||
* \author JackCarterSmith
|
* @author JackCarterSmith
|
||||||
* \copyright GPL-v3.0
|
* @copyright GPL-v3.0
|
||||||
* \brief Decode terrain file (hmp) structure.
|
* @brief Process HMP file structure and extract its datas.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hmp_struct.h"
|
#include "RSPTerrain_datatypes.h"
|
||||||
|
|
||||||
|
|
||||||
#ifndef SRC_HOB_PARSER_H_
|
#ifndef RSPTERRAINLIB_HMP_PARSER_H_
|
||||||
#define SRC_HOB_PARSER_H_
|
#define RSPTERRAINLIB_HMP_PARSER_H_
|
||||||
|
|
||||||
unsigned char parseHMPFile(const char* fileName, T_TERRAIN* hmp_struct, T_PROG_OPTIONS* p_opts);
|
/**
|
||||||
void cleanUpResources(T_TERRAIN* terrain);
|
* @brief Process HMP file stored in memory.
|
||||||
|
* @details Parser will directly extract tiles count and information stored in
|
||||||
|
* HMP file and store them in T_RSPTERRAIN_TERRAIN_OBJ structure.
|
||||||
|
* @note Unmanaged mode
|
||||||
|
*
|
||||||
|
* @param[in] pMemFile Pointer to an in-memory HOB file location.
|
||||||
|
* @param[out] terrainObj Allocated empty T_RSPTERRAIN_TERRAIN_OBJ structure instance to
|
||||||
|
* be filled with HMP datas.
|
||||||
|
* @param[in] pParams Parser options. See RSPTERRAIN_PARAMETERS.
|
||||||
|
*
|
||||||
|
* @return Processing error code, RSPLIB_SUCCESS if no error.
|
||||||
|
*/
|
||||||
|
unsigned char RSPTerrain_processHMPFileMemory(const MEMFILE pMemFile,
|
||||||
|
T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, const RSPTERRAIN_PARAMETERS* pParams);
|
||||||
|
|
||||||
#endif /* SRC_HOB_PARSER_H_ */
|
/**
|
||||||
|
* @brief Process HMP file in file system.
|
||||||
|
* @details HMP file is dumped in memory before parsing in order to enhance
|
||||||
|
* performance during parser operation and in optic to protect data
|
||||||
|
* stored in the original file (read-only).
|
||||||
|
* Parser will extract tiles count and information stored in HMP file
|
||||||
|
* and store them in T_RSPTERRAIN_TERRAIN_OBJ structure.
|
||||||
|
* @note Managed mode
|
||||||
|
*
|
||||||
|
* @param[in] fileName String value of file name/path.
|
||||||
|
* @param[out] terrainObj Allocated empty T_RSPTERRAIN_TERRAIN_OBJ structure instance to
|
||||||
|
* be filled with HMP datas.
|
||||||
|
* @param[in] pParams Parser options. See RSPTERRAIN_PARAMETERS.
|
||||||
|
*
|
||||||
|
* @return Processing error code, RSPLIB_SUCCESS if no error.
|
||||||
|
*/
|
||||||
|
unsigned char RSP_TerrainLib_ParseHMPFile(const char* fileName,
|
||||||
|
T_RSPTERRAIN_TERRAIN_OBJ* terrainObj, const RSPTERRAIN_PARAMETERS* pParams);
|
||||||
|
|
||||||
|
#endif /* RSPTERRAINLIB_HMP_PARSER_H_ */
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
/*
|
/**
|
||||||
* hmp_struct.h
|
* @file hmp_struct.h
|
||||||
|
* @date 22/08/2022
|
||||||
|
* @author JackCarterSmith
|
||||||
|
* @copyright GPL-v3.0
|
||||||
|
* @brief HMP file mapping definition.
|
||||||
*
|
*
|
||||||
* Created on: 31 juil. 2022
|
|
||||||
* Author: JackCarterSmith
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SRC_HMP_STRUCT_H_
|
#ifndef RSPTERRAINLIB_HMP_STRUCT_H_
|
||||||
#define SRC_HMP_STRUCT_H_
|
#define RSPTERRAINLIB_HMP_STRUCT_H_
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* long = 64bits??? (8 Bytes)
|
* long = 64bits??? (8 Bytes)
|
||||||
* int = 32bits (4 Bytes)
|
* int = 32bits (4 Bytes)
|
||||||
* short = 16bits (2 Bytes)
|
* short = 16bits (2 Bytes)
|
||||||
* car = 8bits (1 Bytes)
|
* char = 8bits (1 Bytes)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
@ -22,24 +24,6 @@
|
|||||||
#define PACK __attribute__((packed))
|
#define PACK __attribute__((packed))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
// HMP file structure
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
typedef struct vector3 { float x,y,z; } T_VECTOR3;
|
|
||||||
typedef T_VECTOR3 T_VERTEX;
|
|
||||||
|
|
||||||
typedef struct terrain {
|
|
||||||
unsigned short width; // Dimension of the height/vertices map
|
|
||||||
unsigned short height;
|
|
||||||
|
|
||||||
unsigned char** heightmap;
|
|
||||||
|
|
||||||
unsigned int verticesmap_size;
|
|
||||||
T_VERTEX* verticesmap;
|
|
||||||
} T_TERRAIN ;
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Declaration of Memory Mapped Structure
|
// Declaration of Memory Mapped Structure
|
||||||
// Caution: the place of variable is important for correct mapping!
|
// Caution: the place of variable is important for correct mapping!
|
||||||
@ -84,4 +68,4 @@ typedef struct PACK hmpfile_tile {
|
|||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* SRC_HMP_STRUCT_H_ */
|
#endif /* RSPTERRAINLIB_HMP_STRUCT_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user