Compare commits

..

No commits in common. "master" and "v2.0.1" have entirely different histories.

16 changed files with 167 additions and 511 deletions

5
.gitignore vendored
View File

@ -15,8 +15,8 @@
# Precompiled Headers
*.gch
*.pch
RSPTextureLib/src/config.h
RSETexture/src/config.h
RSPTerrainLib/src/config.h
RSETerrain/src/config.h
# Libraries
*.lib
@ -75,4 +75,3 @@ 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.15)
cmake_policy(VERSION 3.15)
cmake_minimum_required(VERSION 3.12)
cmake_policy(VERSION 3.12)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
if(DEFINED ENV{MS_COMPATIBLE})
set(CMAKE_GNUtoMS ON) # Enable compatibility level to exported libraries
@ -20,20 +20,14 @@ if(DEFINED ENV{CI}) # Jenkins CI integration mode
project(rse-texture VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
set(RSE_TEXTURE_NAME $ENV{CI_OUTPUT_NAME})
else() # Standalone project mode, should not be used for release.
project(rse-texture VERSION 2.1.0 DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
project(rse-texture VERSION 2.0.0 DESCRIPTION "RogueSquadron Extractor - Texture" LANGUAGES C)
set(RSE_TEXTURE_NAME RSETexture)
endif()
set(RSP_TEXTURE_LIB_NAME RSPTexture${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR})
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")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
# Compilation option
option(RSPTEXTURE_SHARED "Build shared lib" ON)
option(RSPTEXTURE_STATIC "Build static lib" ON)
option(BUILD_TOOLS "Build lib tools" ON)
# Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPTextureLib/src/config.h @ONLY)
@ -48,24 +42,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DI
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)
unset(RSE_TEXTURE_TARGETS_LIST)
add_subdirectory(RSPTextureLib)
add_subdirectory(RSETexture)
if(RSPTEXTURE_SHARED)
list(APPEND RSE_TEXTURE_TARGETS_LIST rsp-texture-lib)
endif()
if(RSPTEXTURE_STATIC)
list(APPEND RSE_TEXTURE_TARGETS_LIST rsp-texture-libstatic)
endif()
if(NOT RSE_TEXTURE_TARGETS_LIST)
message(SEND_ERROR
"No library variant selected to build. "
"Please enable at least one of the following options: "
"RSPTEXTURE_STATIC, RSPTEXTURE_SHARED")
endif()
if(BUILD_TOOLS)
list(APPEND RSE_TEXTURE_TARGETS_LIST rse-texture)
endif()
# GPG signature custom command
@ -79,16 +57,22 @@ endif()
#)
# Install dependancies
install(FILES ${PROJECT_BINARY_DIR}/bin/libpng16.dll
DESTINATION ${INSTALL_BIN_DIR})
# Install library includes
install(FILES ${RSP_PUBLIC_HRDS} DESTINATION ${INSTALL_INC_DIR})
# Install project artifacts
# Install project executable
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(RSPTEXTURE_SHARED)
set(RSE_TEXTURE_TARGETS_LIST rse-texture rsp-texture-lib rsp-texture-libstatic)
else()
set(RSE_TEXTURE_TARGETS_LIST rse-texture rsp-texture-libstatic)
endif()
install(TARGETS ${RSE_TEXTURE_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/libpng16.dll
DESTINATION ${INSTALL_BIN_DIR})

15
Jenkinsfile vendored
View File

@ -5,13 +5,14 @@ pipeline {
}
environment {
CI_OUTPUT_NAME = "RSETexture"
CI_VERSION = "2.1.0"
CI_VERSION = "2.0.1"
CI_BUILD_NUMBER = "$BUILD_NUMBER"
}
stages {
stage('Prepare') {
steps {
cleanWs()
rtConanClient(id: "conan", userHome: "/home/jackcartersmith")
}
}
stage('Build') {
@ -21,16 +22,20 @@ pipeline {
dir("linux") {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RSE-Texture'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
sh 'git submodule update --init --recursive'
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 -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release', installation: 'latest', steps: [[args: 'all']]
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-Terrain'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RSE-Texture.git']]])
sh 'git submodule update --init --recursive'
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 -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_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']]
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']]
}
}
)

View File

@ -44,39 +44,45 @@ Due to issue with copyrights, I can't provide samples... You need to extract HMT
Necessary libs (provided only in windows release) for running and for compiling.
- [zlib](https://www.zlib.net/) (1.3.1)
- [libpng](http://www.libpng.org/pub/png/libpng.html) (1.6.43)
- libpng (1.6.37)
### 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 (I've abandonned the support for conan v1 as it's now considered as deprecated).
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).
libpng16-dev distrib package can be used on debian/ubuntu.
To compile, just clone and launch cmake:
```shell
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
cmake .
make
make install
```
If your CMake<3.23, you should use this command for generation instead of preset one:
On Windows system, I can suggest you to use Conan support to help you with dependencies:
`cmake . -S build -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles"`
```shell
mkdir build
cd build
conan install .. --build=missing
cmake .. -G "MinGW Makefiles"
make
```
Beware to use the same release/debug configuration with CMake using Conan! Adjust CMake preset or Conan configuration if necessary.
If you want to do it manually without Conan support, you will probably need to specify the dependency flags for CMake. Ex:
On Windows environment, you can use MinGW `-G "MinGW Makefiles"` or Ninja `-G "Ninja"` as CMake generator.
`cmake.exe -D"ZLIB_INCLUDE_DIR=zlib/1.2.12/include" -D"ZLIB_LIBRARY=zlib/1.2.12/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"`
### Compiling (options)
We can also use cross-compilation (after installing `mingw64` and `cmake` packages on your distrib):
There are a few configurable build options:
- RSPTEXTURE_SHARED Enable the build of shared version of the library ("shared" conan option)
- RSPTEXTURE_STATIC Enable the build of static version of the library ("shared" conan option)
- BUILD_TOOLS Enable the build of the standalone tools (necessary to use the lib directly) ("tools" conan option)
### Compiling (old-way)
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.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" -DRSPTEXTURE_SHARED=ON -DRSPTEXTURE_STATIC=OFF -DBUILD_TOOLS=ON . -G "MinGW Makefiles"`
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.
```shell
mkdir build && cd build
cmake -DGNU_HOST=x86_64-w64-mingw32 \
-DCMAKE_TOOLCHAIN_FILE=../mingw_cross_toolchain.cmake \
-D"ZLIB_INCLUDE_DIR=zlib/1.2.12/include" \
-D"ZLIB_LIBRARY=zlib/1.2.12/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 .
```

View File

@ -10,41 +10,34 @@
include(CheckIncludeFile)
include(CheckCSourceCompiles)
if(BUILD_TOOLS)
# Import needed packages and references their include path
find_package(PNG 1.6.40 REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
# Import needed packages and references their include path
find_package(PNG 1.6.37 REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
# Define src/headers files
file(GLOB_RECURSE RSE_TEXTURE_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSE_TEXTURE_SOURCES})
# Define src/headers files
file(GLOB_RECURSE RSE_TEXTURE_SOURCES ./src/*.c)
source_group("Source Files" FILES ${RSE_TEXTURE_SOURCES})
# Building instructions for RSE-Texture
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# Declare standalone application
add_executable(rse-texture ${RSE_TEXTURE_SOURCES})
set_property(TARGET rse-texture PROPERTY C_STANDARD 90)
#target_include_directories(rse-texture PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(rse-texture PROPERTIES OUTPUT_NAME ${RSE_TEXTURE_NAME})
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rse-texture PROPERTIES IMPORT_PREFIX "lib")
endif()
# Link externals libraries to the linker
if (TARGET PNG::PNG)
if(RSPTEXTURE_SHARED)
target_link_libraries(rse-texture PRIVATE rsp-texture-lib PNG::PNG)
elseif(RSPTEXTURE_STATIC)
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic PNG::PNG)
endif()
endif()
# Building instructions for RSE-Texture
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
# Declare standalone application
add_executable(rse-texture ${RSE_TEXTURE_SOURCES})
set_property(TARGET rse-texture PROPERTY C_STANDARD 90)
#target_include_directories(rse-texture PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
set_target_properties(rse-texture PROPERTIES OUTPUT_NAME ${RSE_TEXTURE_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-texture PROPERTIES IMPORT_PREFIX "lib")
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic ${PNG_LIBRARIES})
else()
target_link_libraries(rse-texture PRIVATE rsp-texture-libstatic ${PNG_LIBRARIES})
endif()

View File

@ -32,18 +32,14 @@ endif()
if(RSPTEXTURE_SHARED)
add_library(rsp-texture-lib SHARED ${RSP_TEXTURE_SOURCES})
set_property(TARGET rsp-texture-lib PROPERTY C_STANDARD 90)
set_target_properties(rsp-texture-lib PROPERTIES VERSION 2.1.0)
target_include_directories(rsp-texture-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(rsp-texture-lib PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")
set_target_properties(rsp-texture-lib PROPERTIES OUTPUT_NAME ${RSP_TEXTURE_LIB_NAME})
set_target_properties(rsp-texture-lib PROPERTIES DEFINE_SYMBOL RSPTEXTURE_DLL)
if(WIN32)
set_target_properties(rsp-texture-lib PROPERTIES DEFINE_SYMBOL RSPTEXTURE_DLL)
endif()
# msvc does not append 'lib' - do it here to have consistent name
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-texture-lib PROPERTIES PREFIX "lib")
set_target_properties(rsp-texture-lib PROPERTIES IMPORT_PREFIX "lib")
endif()
@ -51,52 +47,21 @@ endif()
# Declare the static library instance
if(RSPTEXTURE_STATIC)
add_library(rsp-texture-libstatic STATIC ${RSP_TEXTURE_SOURCES})
set_property(TARGET rsp-texture-libstatic PROPERTY C_STANDARD 90)
add_library(rsp-texture-libstatic STATIC ${RSP_TEXTURE_SOURCES})
set_property(TARGET rsp-texture-libstatic PROPERTY C_STANDARD 90)
target_include_directories(rsp-texture-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(rsp-texture-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
# MSVC doesn't use a different file extension for shared vs. static
# libs. We are able to change OUTPUT_NAME to remove the _static
# for all other platforms.
if(NOT MSVC)
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
# MSVC does not append 'lib' - do it here to have consistent name
if(MSVC)
set_target_properties(rsp-texture-libstatic PROPERTIES PREFIX "lib")
endif()
if(NOT MSVC)
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(rsp-texture-libstatic PROPERTIES OUTPUT_NAME "${RSP_TEXTURE_LIB_NAME}_static")
set_target_properties(rsp-texture-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/create_symlink.cmake)
# Install libraries with OS specific name fix
if(RSPTEXTURE_SHARED)
# Create a symlink for libRSPTexture.dll.a => libRSPTextureXX.dll.a on Cygwin/MinGW
if(CYGWIN OR MINGW)
create_lib_symlink(libRSPTexture${CMAKE_IMPORT_LIBRARY_SUFFIX} TARGET rsp-texture-lib)
install(FILES $<TARGET_LINKER_FILE_DIR:rsp-texture-lib>/libRSPTexture${CMAKE_IMPORT_LIBRARY_SUFFIX}
DESTINATION ${INSTALL_LIB_DIR})
endif()
if(NOT WIN32)
create_lib_symlink(libRSPTexture${CMAKE_SHARED_LIBRARY_SUFFIX} TARGET rsp-texture-lib)
install(FILES $<TARGET_LINKER_FILE_DIR:rsp-texture-lib>/libRSPTexture${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${INSTALL_LIB_DIR})
endif()
endif()
if(RSPTEXTURE_STATIC)
if(NOT WIN32 OR CYGWIN OR MINGW)
create_lib_symlink(libRSPTexture${CMAKE_STATIC_LIBRARY_SUFFIX} TARGET rsp-texture-libstatic)
install(FILES $<TARGET_LINKER_FILE_DIR:rsp-texture-libstatic>/libRSPTexture${CMAKE_STATIC_LIBRARY_SUFFIX}
DESTINATION ${INSTALL_LIB_DIR})
endif()
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(rsp-texture-libstatic PROPERTIES PREFIX "lib")
set_target_properties(rsp-texture-libstatic PROPERTIES IMPORT_PREFIX "lib")
endif()

View File

@ -1,6 +1,6 @@
/**
* @file RSPTexture.h
* @date 14/09/2022
* @date 25/08/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Squadron Parser texture library, used to decode HMT datas
@ -54,12 +54,6 @@ extern "C" {
*/
RSPTEXTURE_EXTERN char* RSPTexture_getVersion( void );
/**
* @brief Constructor for T_RSPTEXTURE_HMT struct
* @return Pointer to a new T_RSPTEXTURE_HMT struct.
*/
RSPTEXTURE_EXTERN T_RSPTEXTURE_HMT* RSPTexture_createHMT( void );
/**
* @brief Run texture parser for the specified file in file system.
* @details Texture library can process HMT file from file system. It's a easy
@ -94,40 +88,6 @@ RSPTEXTURE_EXTERN unsigned short RSPTexture_processHMTFileMemory(
const RSPTEXTURE_PARAMETERS params
);
/**
* @brief Parse HMT materials for specific ID.
* @pre HMT structure should be processed with RSPTexture_processHMTFile()
* or RSPTexture_processHMTMemFile() before.
*
* @param[in] pHmt HMT texture structure to be analyzed.
* @param[in] mat_id ID of the material.
*
* @return Pointer to T_RSPTEXTURE_MATERIAL if found or NULL otherwise.
*/
RSPTEXTURE_EXTERN T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID(
const T_RSPTEXTURE_HMT* pHmt, const unsigned short mat_id
);
/**
* @brief Retrieve material name of a T_RSPTEXTURE_MATERIAL structure.
* @return '0' terminated name string (max: 16 chars).
*/
RSPTEXTURE_EXTERN char* RSPTexture_getMaterialName( const T_RSPTEXTURE_MATERIAL* mat );
/**
* @brief Retrieve opacity value from T_RSPTEXTURE_MATERIAL structure.
* @return Float opacity value.
* @warning Experimental method.
*/
RSPTEXTURE_EXTERN float RSPTexture_getMaterialOpacity( const T_RSPTEXTURE_MATERIAL* mat );
/**
* @brief Retrieve ambient light value from T_RSPTEXTURE_MATERIAL structure.
* @return Float ambient light value.
* @warning Experimental method.
*/
RSPTEXTURE_EXTERN float RSPTexture_getMaterialAmbient( const T_RSPTEXTURE_MATERIAL* mat );
/**
* @brief Clean HMT object and it's childrens from memory.
* @param[in] hmtStruct Pointer to data to be cleaned up.

View File

@ -34,28 +34,25 @@ typedef union u_rsptexture_parameters {
// Lib's structure definitions
////////////////////////////////////////////////////////////////////////////////
#ifndef MEMFILE_DEF
#ifndef MEMFILE
typedef char* MEMFILE;
#define MEMFILE_DEF
#endif
#ifndef T_R8G8B8_DEF
#ifndef T_R8G8B8
typedef struct r8g8b8 { unsigned char r,g,b; } T_R8G8B8;
#define T_R8G8B8_DEF
#endif
#ifndef T_R8G8B8A8_DEF
#ifndef T_R8G8B8A8
typedef struct r8g8b8a8 { unsigned char r,g,b,a; } T_R8G8B8A8;
#define T_R8G8B8A8_DEF
#endif
typedef enum e_mat_type {
RSPTEX_MAT_TYPE_TEXTURED = 1,
RSPTEX_MAT_TYPE_SOLID = 2
} RSPTEX_MAT_TYPE;
typedef unsigned char T_SAMPLE;
typedef struct rsptexture_material {
unsigned char name[17]; // 16 + 1 string ending \0
unsigned short type;
unsigned short texture_index; //TODO: pointer to a T_RSPTEXTURE_TEXTURE element?
} T_RSPTEXTURE_MATERIAL;
typedef struct rsptexture_texture {
unsigned char name[17]; // 16 + 1 string ending \0
unsigned short width;
@ -64,22 +61,15 @@ typedef struct rsptexture_texture {
unsigned char type;
unsigned char sample_bits;
unsigned int palette_entries;
T_R8G8B8A8 alpha_color;
unsigned int palette_offset; //TODO: useless?
unsigned int pixels_offset; //TODO: useless?
T_R8G8B8A8* pixels;
} T_RSPTEXTURE_TEXTURE;
typedef struct rsptexture_material {
unsigned short id;
unsigned char name[17]; // 16 + 1 string ending \0
RSPTEX_MAT_TYPE type;
float opacity; //TODO: temporary, need to be defined
float ambient; //TODO: temporary, need to be defined
T_RSPTEXTURE_TEXTURE* texture;
} T_RSPTEXTURE_MATERIAL;
typedef struct rsptexture_hmt {
unsigned int materials_count;
unsigned int textures_count;

View File

@ -1,16 +1,12 @@
/**
* @file RSPTexture.c
* @date 14/09/2022
* @date 25/08/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief HMT textures datas parser and export to PNG format.
*
*/
#if defined(RSPTEXTURE_DLL)
# define RSPTEXTURE_DLLBUILD
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -21,20 +17,10 @@
#include "RSPTexture.h"
/*
* Libs interface
*/
inline char* RSPTexture_getVersion( void ) {
return PRG_VERSION;
}
/*
* HMT parser
*/
T_RSPTEXTURE_HMT* RSPTexture_createHMT( void ) {
return calloc(1, sizeof(T_RSPTEXTURE_HMT));
}
unsigned short RSPTexture_processHMTFile( T_RSPTEXTURE_HMT* hmtStruct, const char* const filePath,
const RSPTEXTURE_PARAMETERS params ) {
@ -51,35 +37,7 @@ unsigned short RSPTexture_processHMTFileMemory( T_RSPTEXTURE_HMT* hmtStruct, con
return RSP_TextureLib_ParseHMTMemFile((MEMFILE)memFilePtr, hmtStruct, &params);
}
/*
* Material utilities
*/
T_RSPTEXTURE_MATERIAL* RSPTexture_getMaterialFromID( const T_RSPTEXTURE_HMT* pHmt, const unsigned short mat_id ) {
if ( pHmt == NULL ) return NULL;
if ( pHmt->materials == NULL ) return NULL;
return &(pHmt->materials[mat_id]);
}
inline char* RSPTexture_getMaterialName( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return NULL;
return (char*)mat->name;
}
inline float RSPTexture_getMaterialOpacity( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return 1.0;
return mat->opacity;
}
inline float RSPTexture_getMaterialAmbient( const T_RSPTEXTURE_MATERIAL* mat ) {
if ( mat == NULL ) return 1.0;
return mat->ambient;
}
void RSPTexture_freeHMT( T_RSPTEXTURE_HMT* hmtStruct ) {
void RSPTexture_freeHMT(T_RSPTEXTURE_HMT* hmtStruct) {
unsigned int i;
if (hmtStruct == NULL) return;

View File

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

View File

@ -117,14 +117,13 @@ static unsigned short ExtractTextureHMT(T_RSPTEXTURE_HMT* pHmtStruct, const MEMF
if (pParams->verbose_mode) printf("[DBG] > Texture offset: 0x%X\n", pHmtStruct->texture_offset);
printf("\n");
// Get textures if any
if (pHmtStruct->textures_count > 0)
errorCode |= ExtractTextures(pHmtStruct, pMemfile, pParams);
// Get materials if any and link them to texture
// Get materials if any
if (pHmtStruct->materials_count > 0)
errorCode |= ExtractMaterials(pHmtStruct, pMemfile, pParams);
// Get textures if any
if (pHmtStruct->textures_count > 0)
errorCode |= ExtractTextures(pHmtStruct, pMemfile, pParams);
return errorCode;
}
@ -157,35 +156,19 @@ static unsigned short ExtractMaterials(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMe
// Get material datas
pHmt->materials[i].type = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->type;
pHmt->materials[i].id = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->texture_index;
// If material is textured, the linked texture correspond to tex_index in textures array.
if (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED) pHmt->materials[i].texture = pHmt->textures + pHmt->materials[i].id;
else pHmt->materials[i].texture = NULL;
pHmt->materials[i].opacity = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1;
pHmt->materials[i].ambient = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0;
pHmt->materials[i].texture_index = ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->texture_index; // Texture index is only for texture "type" (1)
if (pParams->verbose_mode) {
printf("[INFO] > Material name: %s\n", pHmt->materials[i].name);
printf("[INFO] > Material type: %d\n", pHmt->materials[i].type);
printf("[INFO] > Material id: %d\n", pHmt->materials[i].id);
printf("[INFO] > Material text. index: %d\n", i);
if (pHmt->materials[i].type == RSPTEX_MAT_TYPE_TEXTURED)
printf("[INFO] > Linked texture name: %s (should correspond to material name)\n", pHmt->materials[i].texture->name);
printf("[INFO] > Material text. index: %d (valid if type == 1)\n", pHmt->materials[i].texture_index);
}
/*
* Unassigned generic material datas :
* - Transparent
* - Ambient (global)
* - Diffuse (environnement)
* - Specular (self)
*/
if (pParams->debug_mode) {
printf("[DBG] > Material reserved0: %.8f\n", pHmt->materials[i].ambient);
printf("[DBG] > Material reserved1: %.8f\n", pHmt->materials[i].opacity);
printf("[DBG] > Material reserved0: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved0);
printf("[DBG] > Material reserved1: %.8f\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved1);
printf("[DBG] > Material reserved2 (zero): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
sizeof(T_HMTFILE_HEADER1) + sizeof(T_HMTFILE_MATERIAL) * i))->reserved2);
printf("[DBG] > Material reserved3 (0xA): 0x%X\n", ((T_HMTFILE_MATERIAL *)(pMemfile +
@ -210,7 +193,6 @@ static unsigned short ExtractMaterials(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMe
static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMemfile, const RSPTEXTURE_PARAMETERS* pParams) {
T_R8G8B8* _palette = NULL;
T_SAMPLE* _samples = NULL;
unsigned int palette_offset, pixels_offset;
unsigned int i;
if (pHmt == NULL || pMemfile == NULL) return RSPLIB_ERROR_ARGS_NULL;
@ -263,9 +245,9 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.transparent_color, sizeof(T_R8G8B8A8));
// Get texture datas offsets
pixels_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset +
pHmt->textures[i].pixels_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset +
sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->pixels_offset;
palette_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset +
pHmt->textures[i].palette_offset = ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset +
sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->palette_offset;
// Get texture name
@ -286,8 +268,8 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
printf("[DBG] > Texture unknown0: 0x%X\n", ((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.unknown0);
if (((T_HMTFILE_TEXTURE_HEADER *)(pMemfile + pHmt->texture_offset + sizeof(T_HMTFILE_HEADER2) + sizeof(T_HMTFILE_TEXTURE_HEADER) * i))->tex_format.reserved0 != 1)
printf("[DBG] > Texture: Always 1 different.\n");
printf("[DBG] > Texture palette offset: 0x%X\n", palette_offset);
printf("[DBG] > Texture pixels offset: 0x%X\n", pixels_offset);
printf("[DBG] > Texture palette offset: 0x%X\n", pHmt->textures[i].palette_offset);
printf("[DBG] > Texture pixels offset: 0x%X\n", pHmt->textures[i].pixels_offset);
}
// Retrieve palette datas from HMT file
@ -296,7 +278,7 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
case 256:
_palette = (T_R8G8B8 *)realloc(_palette, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries);
if (_palette)
memcpy(_palette, pMemfile + palette_offset, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries);
memcpy(_palette, pMemfile + pHmt->textures[i].palette_offset, sizeof(T_R8G8B8) * pHmt->textures[i].palette_entries);
else return RSPLIB_ERROR_MEMORY;
break;
default:
@ -307,7 +289,7 @@ static unsigned short ExtractTextures(T_RSPTEXTURE_HMT* pHmt, const MEMFILE pMem
//TODO: better approach?
_samples = (T_SAMPLE *)realloc(_samples, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8);
if (_samples) {
memcpy(_samples, pMemfile + pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8);
memcpy(_samples, pMemfile + pHmt->textures[i].pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / 8);
//if (pHmt->textures[i].type == 2) memcpy(pHmt->textures[i].samples, pMemfile + pHmt->textures[i].pixels_offset, pHmt->textures[i].width * pHmt->textures[i].height * pHmt->textures[i].sample_bits / (8 * 4)); //TODO: manage texture type 2
} else return RSPLIB_ERROR_MEMORY;

View File

@ -46,10 +46,10 @@ typedef struct PACK hmtfile_material {
unsigned short type; // 1 - Material with texture / 2 - Material without texture
unsigned short texture_index;
float reserved0; // misc. Diffuse? Transparent?
float reserved1; // Always 1.0f Ambient?
float reserved0; // misc.
float reserved1; // Always 1.0f
unsigned int reserved2; // Zero Specular?
unsigned int reserved2; // Zero
unsigned int reserved3; // 0x0A
unsigned char name[16];

View File

@ -1,87 +0,0 @@
# Set a variable with CMake code which:
# Creates a symlink from src to dest (if possible) or alternatively
# copies if different.
include(CMakeParseArguments)
function(create_symlink DEST_FILE)
cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})
if(NOT S_TARGET AND NOT S_FILE)
message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument")
endif()
if(S_TARGET AND S_FILE)
message(FATAL_ERROR "create_symlink: Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; can only have one.")
endif()
if(S_FILE)
# If we don't need to symlink something that's coming from a build target,
# we can go ahead and symlink/copy at configure time.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endif()
endif()
if(S_TARGET)
# We need to use generator expressions, which can be a bit tricky, so for
# simplicity make the symlink a POST_BUILD step and use the TARGET
# signature of add_custom_command.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
else()
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E create_symlink $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
endif()
endif()
endfunction()
function(create_lib_symlink DEST_FILE)
cmake_parse_arguments(S "" "FILE;TARGET" "" ${ARGN})
if(NOT S_TARGET AND NOT S_FILE)
message(FATAL_ERROR "create_symlink: Missing TARGET or FILE argument")
endif()
if(S_TARGET AND S_FILE)
message(FATAL_ERROR "create_symlink: Both source file ${S_FILE} and build target ${S_TARGET} arguments are present; can only have one.")
endif()
if(S_FILE)
# If we don't need to symlink something that's coming from a build target,
# we can go ahead and symlink/copy at configure time.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
execute_process(
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
else()
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${S_FILE} ${DEST_FILE}
WORKING_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
endif()
endif()
if(S_TARGET)
# We need to use generator expressions, which can be a bit tricky, so for
# simplicity make the symlink a POST_BUILD step and use the TARGET
# signature of add_custom_command.
if(CMAKE_HOST_WIN32 AND NOT CYGWIN)
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
else()
add_custom_command(TARGET ${S_TARGET} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E create_symlink ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/$<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE})
endif()
endif()
endfunction()

View File

@ -0,0 +1,8 @@
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)

View File

@ -1,126 +0,0 @@
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_texture(ConanFile):
name = "rsptexturelib"
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-Texture"
description = "Rogue Squadron 3D (PC) game textures files (HMT) 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("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-Texture.git", target=".", args=cargs)
# def _patch(self):
# replace_in_file(self, os.path.join(self.source_folder, "RSPTextureLib", "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["RSPTEXTURE_SHARED"] = self.options.shared
tc.cache_variables["RSPTEXTURE_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", "RSETexture")
self.cpp_info.set_property("cmake_target_name", "RSETexture")
self.cpp_info.set_property("cmake_module_target_name", "RSETexture::RSETexture")
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.names["cmake_find_package"] = "RSETexture"
self.cpp_info.names["cmake_find_package_multi"] = "RSETexture"
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 = ["{}RSETexture{}{}".format(prefix, major_min_version, suffix)]

13
conanfile.txt Normal file
View File

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