Compare commits

...

6 Commits

Author SHA1 Message Date
cac6f188e3
Conan asspain
All checks were successful
JCS-Prod/RSE-Terrain/pipeline/head This commit looks good
2025-02-01 16:34:06 +01:00
d15c58ef2e
Final work on Conan v2 support
All checks were successful
JCS-Prod/RSE-Terrain/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Terrain/pipeline/head This commit looks good
2024-09-22 14:22:36 +02:00
753089aec8
Validated conan v2 migration
All checks were successful
JCS-Prod/RSE-Terrain/pipeline/head This commit looks good
2024-05-19 10:22:42 +02:00
ebfd3faeaa
Fix HMP deallocation
All checks were successful
JCS-Prod/RSE-Terrain/pipeline/head This commit looks good
2023-02-05 15:26:49 +01:00
94ac7205c8
Fix incorrect parsing order
All checks were successful
JCS-Prod/RSE-Terrain/pipeline/pr-master This commit looks good
JCS-Prod/RSE-Terrain/pipeline/head This commit looks good
2023-02-05 14:51:35 +01:00
cd750ed787
Add lighting parameters to parser 2023-02-05 14:51:20 +01:00
14 changed files with 267 additions and 120 deletions

1
.gitignore vendored
View File

@ -75,3 +75,4 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json

View File

@ -7,8 +7,8 @@
# CMake requirement and general configuration
cmake_minimum_required(VERSION 3.12)
cmake_policy(VERSION 3.12)
cmake_minimum_required(VERSION 3.15)
cmake_policy(VERSION 3.15)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
if(DEFINED ENV{MS_COMPATIBLE})
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
@ -20,11 +20,10 @@ 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_TERRAIN_NAME $ENV{CI_OUTPUT_NAME})
else() # Standalone project mode, should not be used for release.
project(rse-terrain VERSION 2.0.0 DESCRIPTION "RogueSquadron Extractor - Terrain" LANGUAGES C)
project(rse-terrain VERSION 2.1.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")
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")

15
Jenkinsfile vendored
View File

@ -5,14 +5,13 @@ pipeline {
}
environment {
CI_OUTPUT_NAME = "RSETerrain"
CI_VERSION = "2.0.4"
CI_VERSION = "2.1.0"
CI_BUILD_NUMBER = "$BUILD_NUMBER"
}
stages {
stage('Prepare') {
steps {
cleanWs()
rtConanClient(id: "conan", userHome: "/home/jackcartersmith")
}
}
stage('Build') {
@ -22,20 +21,16 @@ pipeline {
dir("linux") {
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")
}
cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']]
sh 'conan install . -of build -s build_type=Release -o "&:tools=True" -pr:b=default -pr:h=default --build=missing'
cmakeBuild buildDir: 'build', cmakeArgs: '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DRSPTERRAIN_SHARED=ON -DRSPTERRAIN_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release', installation: 'latest', steps: [[args: 'all']]
}
},
windows: {
dir("windows") {
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 .. -pr:b=default -pr:h=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']]
sh 'conan install . -of build -s build_type=Release -o "&:tools=True" -pr:b=default -pr:h=windows --build=missing'
cmakeBuild buildDir: 'build', cmakeArgs: '-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DRSPTERRAIN_SHARED=ON -DRSPTERRAIN_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc -DCMAKE_RC_COMPILER=x86_64-w64-mingw32-windres', installation: 'latest', steps: [[args: 'all']]
}
}
)

View File

@ -43,46 +43,33 @@ Due to issue with copyrights, I can't provide samples... You need to extract HOB
### Dependencies
- libpng (1.6.37)
- obj-lib: as obj file exporter. (https://git.jcsmith.fr/jackcartersmith/obj)
- [zlib](https://www.zlib.net/) (1.3.1)
- [libpng](http://www.libpng.org/pub/png/libpng.html) (1.6.43)
- [obj-lib](https://git.jcsmith.fr/jackcartersmith/obj "obj file exporter")
### Compiling
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).
You can compile on both Windows (MinGW) or native Linux environment thanks to CMake, you only need to adjust your dependencies on Windows or use Conan packages manager (https://conan.io).
libpng16-dev distrib package can be used on debian/ubuntu.
To compile, just clone (**don't forget git submodules**) and launch cmake:
### Compiling
I've a preference for compiling libraries by hand, mainly for backward compatibility, but I recommend using Conan packages manager (https://conan.io) for simplicity. (**Don't forget git submodules**)
```shell
cmake .
make
make install
conan install . -of build -b missing -s build_type=Release -o tools=True -pr:b=default -pr:h=default
cmake --preset conan-release -G "Unix Makefiles"
cmake --build --preset conan-release
```
On Windows system, I can suggest you to use Conan support to help you with dependencies:
On Windows environment, you can use MinGW `-G "MinGW Makefiles"` or Ninja `-G "Ninja"` as CMake generator.
```shell
mkdir build
cd build
conan install .. --build=missing
cmake .. -G "MinGW Makefiles"
make
```
### Compiling (HARDCORE)
If you want to do it manually without Conan support, you will probably need to specify the dependency flags for CMake. Ex:
If you want to do it manually without Conan, you will probably need to specify the dependency flags for CMake. Ex:
`cmake.exe -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" -D"PNG_LIBRARY=libpng/1.6.37/lib/libpng.dll.a" . -G "MinGW Makefiles"`
`cmake.exe -D"ZLIB_INCLUDE_DIR=zlib/1.3.1/include" -D"ZLIB_LIBRARY=zlib/1.3.1/lib/libzlib.dll.a" -D"PNG_PNG_INCLUDE_DIR=libpng/1.6.43/include" -D"PNG_LIBRARY=libpng/1.6.43/lib/libpng.dll.a" . -G "MinGW Makefiles"`
We can also use cross-compilation (after installing `mingw64` and `cmake` packages on your distrib):
```shell
mkdir build && cd build
cmake -DGNU_HOST=x86_64-w64-mingw32 \
-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" \
-D"PNG_LIBRARY=libpng/1.6.37/lib/libpng.dll.a" \
..
cmake --build .
```
I've tested cross-compilation too, but since I want to check that Conan is working properly at each release, I've integrated it into the Jenkins flow using Conan for the cross-abstraction.

View File

@ -12,7 +12,7 @@ include(CheckCSourceCompiles)
if(BUILD_TOOLS)
# Import needed packages and references their include path
find_package(PNG 1.6.37 REQUIRED)
find_package(PNG 1.6.40 REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIR})
@ -44,9 +44,13 @@ if(BUILD_TOOLS)
endif()
# Link externals libraries to the linker
if(RSPTERRAIN_SHARED)
target_link_libraries(rse-terrain PRIVATE rsp-terrain-lib ${PNG_LIBRARIES} ${GLEW_LIBRARIES} ${AUX_LIBS})
elseif(RSPTERRAIN_STATIC)
target_link_libraries(rse-terrain PRIVATE rsp-terrain-libstatic ${PNG_LIBRARIES} ${GLEW_LIBRARIES} ${AUX_LIBS})
if (TARGET GLEW::GLEW)
if (TARGET PNG::PNG)
if(RSPTERRAIN_SHARED)
target_link_libraries(rse-terrain PRIVATE rsp-terrain-lib PNG::PNG GLEW::GLEW ${AUX_LIBS})
elseif(RSPTERRAIN_STATIC)
target_link_libraries(rse-terrain PRIVATE rsp-terrain-libstatic PNG::PNG GLEW::GLEW ${AUX_LIBS})
endif()
endif()
endif()
endif()

View File

@ -85,6 +85,7 @@ static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS
if (RSPTerrain_processHMPFile(hmpStruct, args_value[file_index], libParams) != RSPLIB_SUCCESS) {
printf("[ERR] Failed to parse datas from %s\n", args_value[file_index]);
RSPTerrain_freeHMP(hmpStruct);
free(hmpStruct);
return RSPLIB_ERROR_PROCESS;
}
} else return RSPLIB_ERROR_MEMORY;
@ -107,6 +108,7 @@ static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS
RSPTerrain_freeHeightmap(terrainHM);
} else {
RSPTerrain_freeHMP(hmpStruct);
free(hmpStruct);
return RSPLIB_ERROR_MEMORY;
}
@ -126,11 +128,13 @@ static unsigned int mainProcess(int args_cnt, char* args_value[], T_PROG_OPTIONS
RSPTerrain_freeMesh(terrainMesh);
} else {
RSPTerrain_freeHMP(hmpStruct);
free(hmpStruct);
return RSPLIB_ERROR_MEMORY;
}
//#endif
RSPTerrain_freeHMP(hmpStruct);
free(hmpStruct);
}
return RSPLIB_SUCCESS;

View File

@ -1,6 +1,6 @@
/**
* @file RSPTerrain_datatypes.h
* @date 11/08/2022
* @date 05/02/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief RSP Terrain workflow structures definitions
@ -51,20 +51,23 @@ typedef char* MEMFILE;
#define MEMFILE_DEF
#endif
#ifndef T_R8G8B8A8_DEF
typedef struct r8g8b8a8 { unsigned char r,g,b,a; } T_R8G8B8A8;
#define T_R8G8B8A8_DEF
#endif
#ifndef T_R8G8B8_F_DEF
typedef struct r8g8b8_f { float r,g,b; } T_R8G8B8_F;
#define T_R8G8B8_F_DEF
#endif
#ifndef HEIGHTMAP_T_DEF
typedef unsigned char** HEIGHTMAP_T;
#define HEIGHTMAP_T_DEF
#endif
#ifndef T_VECTOR3_DEF
typedef struct vector3 { float x,y,z; } T_VECTOR3;
#define T_VECTOR3_DEF
#endif
#ifndef T_VERTEX_DEF
typedef T_VECTOR3 T_VERTEX;
#define T_VERTEX_DEF
#endif
typedef struct rspterrain_vector3 { float x,y,z; } T_RSPTERRAIN_VECTOR3;
typedef T_RSPTERRAIN_VECTOR3 T_RSPTERRAIN_VERTEX;
typedef struct rspterrain_heightmap {
unsigned short width;
@ -78,7 +81,7 @@ typedef struct rspterrain_mesh {
unsigned short height;
unsigned int vertices_count;
T_VERTEX* verticesmap;
T_RSPTERRAIN_VERTEX* verticesmap;
} T_RSPTERRAIN_MESH ;
typedef struct rspterrain_tile {
@ -97,6 +100,7 @@ typedef struct rspterrain_obj {
float height_scale;
unsigned short tiles_count;
unsigned short textures_count;
T_RSPTERRAIN_TILE* tilesmap;
} T_RSPTERRAIN_HMP ;

View File

@ -1,6 +1,6 @@
/**
* @file RSPTerrain.c
* @date 22/08/2022
* @date 05/02/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief HMP terrain datas parser and export to Waveform OBJ format and greyscale PNG heightmap.
@ -74,8 +74,6 @@ void RSPTerrain_freeHMP(T_RSPTERRAIN_HMP* hmpStruct) {
if (hmpStruct == NULL) return;
if (hmpStruct->tilesmap) free(hmpStruct->tilesmap);
free(hmpStruct);
}
void RSPTerrain_freeHeightmap(T_RSPTERRAIN_HEIGHTMAP* heightmap) {
@ -85,14 +83,10 @@ void RSPTerrain_freeHeightmap(T_RSPTERRAIN_HEIGHTMAP* heightmap) {
for ( i = 0; i < heightmap->width * RSPTERRAINLIB_TILE_SAMPLING; i++ )
if (heightmap->heightmap[i]) free(heightmap->heightmap[i]);
free(heightmap);
}
void RSPTerrain_freeMesh(T_RSPTERRAIN_MESH* mesh) {
if (mesh == NULL) return;
if (mesh->verticesmap) free(mesh->verticesmap);
free(mesh);
}

View File

@ -63,28 +63,28 @@ unsigned short RSP_TerrainLib_ConstructMesh(T_RSPTERRAIN_MESH* pMesh, const T_RS
pMesh->vertices_count = vertices_width * vertices_height;
// Build vertex list of the terrain
pMesh->verticesmap = (T_VERTEX *)malloc(pMesh->vertices_count * sizeof(T_VERTEX));
pMesh->verticesmap = (T_RSPTERRAIN_VERTEX *)malloc(pMesh->vertices_count * sizeof(T_RSPTERRAIN_VERTEX));
if (pMesh->verticesmap) {
// Select tile
for ( j = 0; j < pHmpStruct->height; j++ ) {
for ( i = 0; i < pHmpStruct->width; i++ ) {
for ( i = 0; i < pHmpStruct->height; i++ ) {
for ( j = 0; j < pHmpStruct->width; j++ ) {
k = i * RSPTERRAINLIB_TILE_SAMPLING + j * RSPTERRAINLIB_TILE_SAMPLING * vertices_width;
k = j * RSPTERRAINLIB_TILE_SAMPLING + i * RSPTERRAINLIB_TILE_SAMPLING * vertices_width;
for ( n = 0; n < RSPTERRAINLIB_TILE_SAMPLING; n++ ) {
for ( m = 0; m < RSPTERRAINLIB_TILE_SAMPLING; m++ ) {
// Terrain center defined as mesh center -- sould not be used for game application
tmp_x = -(vertices_width / 2);
tmp_x = meshScale * (tmp_x + i * RSPTERRAINLIB_TILE_SAMPLING + m);
tmp_x = meshScale * (tmp_x + j * RSPTERRAINLIB_TILE_SAMPLING + m);
pMesh->verticesmap[k + n*vertices_width + m].x = tmp_x;
tmp_z = -(vertices_height / 2);
tmp_z = meshScale * (tmp_z + j * RSPTERRAINLIB_TILE_SAMPLING + n);
tmp_z = meshScale * (tmp_z + i * RSPTERRAINLIB_TILE_SAMPLING + n);
pMesh->verticesmap[k + n*vertices_width + m].z = tmp_z;
// Convert read scale to display scale, don't known the real operation in game
pMesh->verticesmap[k + n*vertices_width + m].y = pHmpStruct->tilesmap[j * pHmpStruct->height + i].height_values[m][n] * (pHmpStruct->height_scale * 2.0 / 10.0);
pMesh->verticesmap[k + n*vertices_width + m].y = pHmpStruct->tilesmap[i * pHmpStruct->width + j].height_values[m][n] * (pHmpStruct->height_scale * 2.0 / 10.0);
}
}
}

View File

@ -1,6 +1,6 @@
/**
* @file hmp_parser.c
* @date 22/08/2022
* @date 05/02/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Process HMP file structure and extract its datas.
@ -21,8 +21,8 @@
////////////////////////////////////////////////////////////////////////////////
static unsigned short extractTerrainHMP(T_RSPTERRAIN_HMP*, const MEMFILE, const RSPTERRAIN_PARAMETERS*);
static unsigned short resolveTilesMap(T_RSPTERRAIN_HMP* pHmpStruct, const T_TILE_INDICES* tiles_indices,
const T_HMPFILE_TILE* tiles, const RSPTERRAIN_PARAMETERS* pParams);
static unsigned short resolveTilesMap(T_RSPTERRAIN_HMP* pHmpStruct, const T_TILE_INDICES* const tiles_indices,
const T_HMPFILE_TILE* const tiles, const RSPTERRAIN_PARAMETERS* constpParams);
////////////////////////////////////////////////////////////////////////////////
@ -100,14 +100,17 @@ static unsigned short extractTerrainHMP(T_RSPTERRAIN_HMP* pHmpStruct, const MEMF
unsigned short errorCode = RSPLIB_SUCCESS;
T_TILE_INDICES* tiles_indices = NULL;
T_HMPFILE_TILE* tiles = NULL;
unsigned int tiles_offset = 0;
unsigned int tiles_offset = 0, lso_offset = 0;
if (pHmpStruct == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
// Get header infos
pHmpStruct->height_scale = ((T_HMPFILE_HEADER *)pMemfile)->height_scale;
tiles_offset = ((T_HMPFILE_HEADER *)pMemfile)->tiles_start_offset;
lso_offset = ((T_HMPFILE_HEADER *)pMemfile)->lighting_datas_offset;
pHmpStruct->tiles_count = ((T_HMPFILE_HEADER *)pMemfile)->tiles_count;
pHmpStruct->textures_count = ((T_HMPFILE_HEADER *)pMemfile)->textures_count;
pHmpStruct->width = ((T_HMPFILE_HEADER *)pMemfile)->width_BLK;
pHmpStruct->height = ((T_HMPFILE_HEADER *)pMemfile)->height_BLK;
@ -115,26 +118,26 @@ static unsigned short extractTerrainHMP(T_RSPTERRAIN_HMP* pHmpStruct, const MEMF
printf("[DBG] > Height scale: %.8f\n", pHmpStruct->height_scale);
printf("[DBG] > Tiles count: %d\n", pHmpStruct->tiles_count);
printf("[DBG] > Tiles offset: 0x%X\n", tiles_offset);
printf("[DBG] > LSO offset: 0x%X\n", lso_offset);
printf("[DBG] > Terrain size: %dx%d\n", pHmpStruct->width, pHmpStruct->height);
printf("\n");
}
if (pParams->god_mode) {
printf("[DBG] > Unknown0: %d\n", ((T_HMPFILE_HEADER *)pHmpStruct)->unknown0);
printf("[DBG] > Unknown1: %d\n", ((T_HMPFILE_HEADER *)pHmpStruct)->unknown1);
printf("\n");
}
// Get tiles indices
tiles_indices = (T_TILE_INDICES *)malloc(pHmpStruct->width * pHmpStruct->height * sizeof(T_TILE_INDICES));
memcpy(tiles_indices,
pMemfile + sizeof(T_HMPFILE_HEADER),
pHmpStruct->width * pHmpStruct->height * sizeof(unsigned short));
if (tiles_indices) {
memcpy(tiles_indices,
pMemfile + sizeof(T_HMPFILE_HEADER),
pHmpStruct->width * pHmpStruct->height * sizeof(T_TILE_INDICES));
}
// Get tiles datas
tiles = (T_HMPFILE_TILE *)malloc(pHmpStruct->tiles_count * sizeof(T_HMPFILE_TILE));
memcpy(tiles,
pMemfile + tiles_offset,
((T_HMPFILE_HEADER *)pMemfile)->tiles_count * sizeof(T_HMPFILE_TILE));
if (tiles) {
memcpy(tiles,
pMemfile + tiles_offset,
pHmpStruct->tiles_count * sizeof(T_HMPFILE_TILE));
}
if (tiles && tiles_indices) {
// Reconstruct tiles map from tiles datas and tiles indices
@ -157,22 +160,22 @@ static unsigned short extractTerrainHMP(T_RSPTERRAIN_HMP* pHmpStruct, const MEMF
*
* @return Error code, RSPLIB_SUCCESS when no error.
*/
static unsigned short resolveTilesMap(T_RSPTERRAIN_HMP* pHmpStruct, const T_TILE_INDICES* tiles_indices,
const T_HMPFILE_TILE* tiles, const RSPTERRAIN_PARAMETERS* pParams) {
static unsigned short resolveTilesMap(T_RSPTERRAIN_HMP* pHmpStruct, const T_TILE_INDICES* const tiles_indices,
const T_HMPFILE_TILE* const tiles, const RSPTERRAIN_PARAMETERS* pParams) {
T_TILE_INDICES tiles_idx;
unsigned int i,j,k,l,remap_index;
// Build tilesmap array to contain height values
pHmpStruct->tilesmap = malloc(pHmpStruct->width * pHmpStruct->height * sizeof(T_RSPTERRAIN_TILE));
pHmpStruct->tilesmap = (T_RSPTERRAIN_TILE *)malloc(pHmpStruct->width * pHmpStruct->height * sizeof(T_RSPTERRAIN_TILE));
if (pHmpStruct->tilesmap == NULL) return RSPLIB_ERROR_MEMORY;
// Fetch tile from ID
for ( i = 0; i < pHmpStruct->height; i++ ) {
for ( j = 0; j < pHmpStruct->width; j++ ) {
remap_index = pParams->invertZ ? i * pHmpStruct->height + (pHmpStruct->width-1 - j) : i * pHmpStruct->height + j;
tiles_idx = tiles_indices[i * pHmpStruct->height + j];
remap_index = pParams->invertZ ? i * pHmpStruct->width + (pHmpStruct->width - 1 - j) : i * pHmpStruct->width + j;
tiles_idx = tiles_indices[i * pHmpStruct->width + j];
// Get tiles pseudodatas
pHmpStruct->tilesmap[remap_index].texmap_id = tiles[tiles_idx].texmap_id;

View File

@ -1,6 +1,6 @@
/**
* @file hmp_struct.h
* @date 22/08/2022
* @date 05/02/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief HMP file mapping definition.
@ -33,6 +33,13 @@
#pragma pack(push, 1)
#endif
/*
* - Global HMP file structure-
* +------------------+-----------------------------------------+----------------------+----------------------------+
* | T_HMPFILE_HEADER | (width_BLK*height_BLK) * T_TILE_INDICES | T_HMPFILE_LIGHTDATAS | obj_count * T_HMPFILE_TILE |
* +------------------+-----------------------------------------+----------------------+----------------------------+
*
*/
typedef struct PACK hmpfile_header {
unsigned int reserved0; //12B of zeros
unsigned int reserved1;
@ -43,15 +50,58 @@ typedef struct PACK hmpfile_header {
float reserved4; // Always 0x3F000000
unsigned short tiles_count;
unsigned short unknown0;
unsigned short textures_count;
/*
* #Thanaclara
* *textures_count* note - Some levels contain tiles with an animation for a texture.
* This animation consists of multiple textures, or "frames" for the animation.
* However each animation counts only as 1 towards the terrain texture count.
* An example of an animated terrain texture is a tile that is textured to look like water.
*/
unsigned int tiles_start_offset;
unsigned int unknown1; // Offset to some datas?
unsigned int lighting_datas_offset;
unsigned short width_BLK;
unsigned short height_BLK;
} T_HMPFILE_HEADER;
typedef struct PACK global_light_obj {
T_R8G8B8A8 shadow_color;
T_R8G8B8A8 world_light_color;
T_R8G8B8_F terrain_light_color;
unsigned int reserved0; // 4B of zeros
T_RSPTERRAIN_VECTOR3 terrain_light_normal;
unsigned int reserved1; // 4B of zeros
} T_HMPFILE_GLOBALLIGHT;
typedef struct PACK light_shadow_obj {
/*
* In light mode higher values = brighter light
* Shadow mode is inverted, higher values = darker shadows
* but the inversion also extends to the shadow color (i.e if you
* want to make a blue shadow you would need to set the blue
* channel to 0.0f and the red and green channel to 255.0f
*/
T_R8G8B8_F light_color;
unsigned char activated;
unsigned char shadow_mode;
unsigned char intensity_boost;
unsigned char unknown0;
T_RSPTERRAIN_VECTOR3 light_position;
float light_scale;
} T_HMPFILE_LSO;
typedef struct PACK lighting_datas {
// Lights and shadows object count
unsigned int ls_obj_count;
T_HMPFILE_GLOBALLIGHT global_light;
T_HMPFILE_LSO* pLSO; // array size = (ls_obj_count - 1) because global_light count as a light element
} T_HMPFILE_LIGHTDATAS;
typedef unsigned short T_TILE_INDICES;
typedef struct PACK hmpfile_tile {

View File

@ -1,8 +0,0 @@
SET(CMAKE_SYSTEM_NAME Windows)
IF("${GNU_HOST}" STREQUAL "")
SET(GNU_HOST i586-mingw32msvc)
ENDIF()
# Prefix detection only works with compiler id "GNU"
SET(CMAKE_C_COMPILER ${GNU_HOST}-gcc)
# CMake doesn't automatically look for prefixed 'windres', do it manually:
SET(CMAKE_RC_COMPILER ${GNU_HOST}-windres)

129
conanfile.py Normal file
View File

@ -0,0 +1,129 @@
import os
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake
from conan.tools.files import copy
from conan.tools.scm import Git, Version
required_conan_version = ">=2.3"
class rse_terrain(ConanFile):
name = "rspterrainlib"
package_type = "library"
version = "2.1.0"
revision_mode = "scm"
license = "GPL-3.0"
author = "JackCarterSmith <jackcartersmith@jcsmith.fr>"
url = "https://git.jcsmith.fr/JCS-Prod/RSE-Terrain"
description = "Rogue Squadron 3D (PC) game terrain files (hmp) extractor"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps"
options = {
"shared": [True, False],
"tools": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": True,
"tools": False,
"fPIC": True
}
@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]
#def validate(self):
# if self.settings.os == "Macos":
# raise ConanInvalidConfiguration("MacOS not supported")
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
self.options["libpng"].shared = True
self.options["libpng"].sse = True
if self.options.shared:
self.options.rm_safe("fPIC")
def requirements(self):
if self.options.tools:
self.requires("glew/2.2.0")
self.requires("zlib/1.3.1")
self.requires("libpng/1.6.43")
def source(self):
git = Git(self)
cargs = ['--single-branch', '--recursive', '--depth', '1', '--branch', 'v' + self.version]
git.clone(url="https://git.jcsmith.fr/JCS-Prod/RSE-Terrain.git", target=".", args=cargs)
# def _patch(self):
# replace_in_file(self, os.path.join(self.source_folder, "RSPTerrainLib", "CMakeLists.txt"),
# 'set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")',
# 'set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")')
def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
# def layout(self):
# cmake_layout(self, src_folder='.', build_folder='build')
def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["RSPTERRAIN_SHARED"] = self.options.shared
tc.cache_variables["RSPTERRAIN_STATIC"] = not self.options.shared
tc.cache_variables["BUILD_TOOLS"] = self.options.tools
#tc.cache_variables["BUILD_DEBUG"] = self.settings.build_type == "Debug"
tc.generate()
#cmdeps = CMakeDeps(self)
#cmpdeps.set_property("zlib", "cmake_find_mode", "both")
#cmpdeps.set_property("libpng", "cmake_find_mode", "both")
#if self.options.shared:
#cmdeps.configuration = "ReleaseShared"
#cmdeps.generate()
for dep in self.dependencies.values():
if len(dep.cpp_info.bindirs) > 0:
if self.settings.os == "Windows":
if self._is_msvc:
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin", str(self.settings.build_type)))
else:
copy(self, "*.dll", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))
else:
copy(self, "*.so", dep.cpp_info.bindirs[0], os.path.join(self.build_folder, "bin"))
def build(self):
cmbuilder = CMake(self)
#self._patch()
cmbuilder.configure()
cmbuilder.build()
def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, pattern="*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
copy(self, pattern="*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.so", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.lib", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"), keep_path=False)
copy(self, pattern="*.dll", src=self.build_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "RSETerrain")
self.cpp_info.set_property("cmake_target_name", "RSETerrain")
self.cpp_info.set_property("cmake_module_target_name", "RSETerrain::RSETerrain")
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.names["cmake_find_package"] = "RSETerrain"
self.cpp_info.names["cmake_find_package_multi"] = "RSETerrain"
self.cpp_info.includedirs = ["include"]
prefix = "lib" if self._is_msvc else ""
#suffix = "d" if self.settings.build_type == "Debug" else ""
suffix = ""
major_min_version = f"{Version(self.version).major}{Version(self.version).minor}"
self.cpp_info.libs = ["{}RSETerrain{}{}".format(prefix, major_min_version, suffix)]
if self.settings.os in ["Linux", "Android", "FreeBSD", "SunOS", "AIX"]:
self.cpp_info.system_libs.append("m")

View File

@ -1,15 +0,0 @@
[requires]
zlib/1.2.12
libpng/1.6.37
glew/2.2.0
[generators]
cmake
cmake_find_package
[options]
libpng:shared=True
glew:shared=True
[imports]
bin, *.dll -> ./bin