Program structure prototype

This commit is contained in:
JackCarterSmith 2022-09-15 20:42:50 +02:00
parent 9e891dd05b
commit dd48841d7f
Signed by: JackCarterSmith
GPG Key ID: 832E52F4E23F8F24
15 changed files with 3081 additions and 2 deletions

1
.gitignore vendored
View File

@ -428,6 +428,7 @@ FodyWeavers.xsd
# ---> C # ---> C
# Prerequisites # Prerequisites
*.d *.d
src/config.h
# Object files # Object files
*.o *.o

151
CMakeLists.txt Normal file
View File

@ -0,0 +1,151 @@
# CMakeLists.txt
####################################################
# Written by JackCarterSmith, 2022
# This code is released under the RDI license.
####################################################
# CMake requirement and general configuration
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
endif()
# Project definition
if(DEFINED ENV{CI}) # Jenkins CI integration mode
project(rdi VERSION $ENV{CI_VERSION}.$ENV{CI_BUILD_NUMBER} DESCRIPTION "Rogue Data Interface" LANGUAGES C CXX)
set(RDI_NAME $ENV{CI_OUTPUT_NAME})
else() # Standalone project mode, should not be used for release.
project(rdi VERSION 1.0.0 DESCRIPTION "Rogue Data Interface" LANGUAGES C CXX)
set(RDI_NAME RDI)
endif()
#set(RDI_LIB_NAME RDI${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR})
set(RDI_LIB_NAME RDI)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_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")
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
# Compilation option
option(RDI_SHARED "Build shared lib" ON)
option(RDI_STATIC "Build static lib" ON)
# Push compile infos to source
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/config.h @ONLY)
# The project is divided in two parts:
# - RDI library to interface with RS3D data files. On windows system, it's can use registry to find RS3D install folder.
# - Some testing and debugging tools (WIP)
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(RDI_TARGETS_LIST)
# Define src/headers files
file(GLOB_RECURSE RDI_LIB_SOURCES ./src/*.cpp ./src/*.c)
source_group("Source Files" FILES ${RDI_LIB_SOURCES})
file(GLOB RSP_LIB_PUBLIC_HRDS ./include/*.h)
# Building instructions for RSP-Texture library
if(DEFINED ENV{CI})
set(CMAKE_BUILD_TYPE RELEASE)
endif()
#if(BUILD_TOOLS)
# set(RDI_TARGETS_LIST rdi-tools)
#endif()
# Declare the shared library instance
if(RDI_SHARED)
add_library(rdi-lib SHARED ${RDI_LIB_SOURCES})
set_property(TARGET rdi-lib PROPERTY C_STANDARD 90)
set_property(TARGET rdi-lib PROPERTY CXX_STANDARD 17)
set_target_properties(rdi-lib PROPERTIES VERSION 1.0.0)
target_include_directories(rdi-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_target_properties(rdi-lib PROPERTIES OUTPUT_NAME "${RDI_LIB_NAME}")
if(WIN32)
# remove lib prefix on windows system when building dll file
set_target_properties(rdi-lib PROPERTIES PREFIX "")
set_target_properties(rdi-lib PROPERTIES DEFINE_SYMBOL RDI_DLL)
endif()
list(APPEND RDI_TARGETS_LIST rdi-lib)
# msvc does not append 'lib' - do it here to have consistent name
if(MSVC)
# only for import library, not the shared one
set_target_properties(rdi-lib PROPERTIES IMPORT_PREFIX "lib")
endif()
endif()
# Declare the static library instance
if(RDI_STATIC)
add_library(rdi-libstatic STATIC ${RDI_LIB_SOURCES})
set_property(TARGET rdi-libstatic PROPERTY C_STANDARD 90)
set_property(TARGET rdi-libstatic PROPERTY CXX_STANDARD 17)
target_include_directories(rdi-libstatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
list(APPEND RDI_TARGETS_LIST rdi-libstatic)
# 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(rdi-libstatic PROPERTIES OUTPUT_NAME "${RDI_LIB_NAME}")
set_target_properties(rdi-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
else()
set_target_properties(rdi-libstatic PROPERTIES OUTPUT_NAME "${RDI_LIB_NAME}_static")
set_target_properties(rdi-libstatic PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()
# MSVC does not append 'lib' - do it here to have consistent name
if(MSVC)
set_target_properties(rdi-libstatic PROPERTIES PREFIX "lib")
endif()
endif()
if(NOT RDI_TARGETS_LIST)
message(SEND_ERROR
"No library variant selected to build. "
"Please enable at least one of the following options: "
"RDI_STATIC, RDI_SHARED")
endif()
# GPG signature custom command
#add_custom_command(
# OUTPUT ""
# COMMAND gpg --batch --detach-sign
# -o ${RSE_MOD_NAME}_${CI_SYS_TARGET}.gpg
# ${RSE_MOD_NAME}
# DEPENDS ${RSE_MOD_NAME}
# VERBATIM
#)
# Install dependancies
#install(FILES ${PROJECT_BINARY_DIR}/bin/libpng16.dll
# DESTINATION ${INSTALL_BIN_DIR})
# Install library includes
install(FILES ${RSP_LIB_PUBLIC_HRDS} DESTINATION ${INSTALL_INC_DIR})
# Install project artifacts
install(TARGETS ${RDI_TARGETS_LIST}
RUNTIME DESTINATION ${INSTALL_BIN_DIR}
LIBRARY DESTINATION ${INSTALL_LIB_DIR}
ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
)

79
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,79 @@
pipeline {
agent any
options {
skipDefaultCheckout(true)
}
environment {
CI_OUTPUT_NAME = "RDI"
CI_VERSION = "1.0.0"
CI_BUILD_NUMBER = "$BUILD_NUMBER"
}
stages {
stage('Prepare') {
steps {
cleanWs()
rtConanClient(id: "conan", userHome: "/home/jackcartersmith")
}
}
stage('Build') {
steps {
parallel(
linux: {
dir("linux") {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RDI'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RDI.git']]])
sh 'git submodule update --init --recursive'
dir("build") {
rtConanRun(clientId: "conan", command: "install .. --build=missing")
}
cmakeBuild buildDir: 'build', installation: 'latest', steps: [[args: 'all']]
}
},
windows: {
dir("windows") {
checkout([$class: 'GitSCM', branches: [[name: '**']], browser: [$class: 'GiteaBrowser', repoUrl: 'https://git.jcsmith.fr/JCS-Prod/RDI'], extensions: [], userRemoteConfigs: [[credentialsId: 'jenkins-ssh', url: 'ssh://git@git.jcsmith.fr:2322/JCS-Prod/RDI.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']]
}
}
)
}
}
stage('Deploy') {
steps {
dir("zip_linux") {
sh 'cp -R ../linux/build/bin ../linux/build/lib ../linux/include .'
}
dir("zip_win") {
sh 'cp -R ../windows/build/bin ../windows/build/lib ../windows/include .'
}
zip archive: false, dir: 'zip_linux', exclude: '', glob: '', zipFile: 'linux_x64.zip'
sh 'mv linux_x64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip'
zip archive: false, dir: 'zip_win', exclude: '', glob: '', zipFile: 'mingw64.zip'
sh 'mv mingw64.zip ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip'
archiveArtifacts(artifacts: '*.zip')
fingerprint(targets: '*.zip')
}
}
stage('Sign') {
steps {
sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_Linux_x86_64.zip'
sh 'gpg --batch --detach-sign -o ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip.gpg ${CI_OUTPUT_NAME}_${CI_VERSION}.${BUILD_NUMBER}_mingw64.zip'
archiveArtifacts(artifacts: '*.gpg')
fingerprint(targets: '*.gpg')
}
}
}
/*
post {
always {
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true)
}
}
*/
}

View File

@ -1,3 +1,3 @@
# RDI # Rogue Data Interface (RDI)
This is the Rogue Data Interface, a library to make link between old data file from "Rogue Squadron 3D" and new Direct3D/OpenGL components. A library to make link between old data file from "Rogue Squadron 3D" and new Direct3D/OpenGL components.

View File

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

16
conanfile.txt Normal file
View File

@ -0,0 +1,16 @@
[requires]
zlib/1.2.12
libpng/1.6.37
rspmodellib/2.0.0
rspterrainlib/2.0.4
rsptexturelib/2.1.0
[generators]
cmake
cmake_find_package
[options]
libpng:shared=True
[imports]
bin, *.dll -> ./bin

6
config.h.in Normal file
View File

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

2492
doc/Doxyfile Normal file

File diff suppressed because it is too large Load Diff

68
include/RDI.h Normal file
View File

@ -0,0 +1,68 @@
/**
* @file RDI.h
* @date 15/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Data Interface library main entry file.
*
*/
#ifndef RDI_H_
#define RDI_H_
#if defined(_MSC_VER)
# define RDI_ABI_EXPORT __declspec(dllexport)
# define RDI_ABI_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
# define RDI_ABI_EXPORT __attribute__ ((visibility("default")))
# define RDI_ABI_IMPORT __attribute__ ((visibility("default")))
#else
# define RDI_ABI_EXPORT
# define RDI_ABI_IMPORT
#endif
#if defined(RDI_DLL)
# if defined(WIN32)
# if defined(RDI_DLLBUILD)
# define RDI_EXTERN extern RDI_ABI_EXPORT
# else
# define RDI_EXTERN extern RDI_ABI_IMPORT
# endif
# endif
#endif
#ifndef RDI_EXTERN
# define RDI_EXTERN extern
#endif
///////////////////////////////////////////////////////////////////////////////
// Library's functions declaration
///////////////////////////////////////////////////////////////////////////////
namespace RDI
{
/**
* @brief Get the current library version.
* @return Char array of the version, escape char included.
*/
RDI_EXTERN const char* getVersion( void );
/**
* @brief Search for Rogue data file, try to open it and map it in memory.
* @return Error status, return RDI_SUCCESS in nominal case.
*/
RDI_EXTERN unsigned short OpenRogueDat( void );
/**
* @brief Try to open Rogue data file and map it in memory.
*
* @param[in] filePath Path to Rogue data file.
*
* @return Error status, return RDI_SUCCESS in nominal case.
*/
RDI_EXTERN unsigned short OpenRogueDat( const char* filePath );
}
#endif /* RDI_H_ */

42
src/RDI.cpp Normal file
View File

@ -0,0 +1,42 @@
/**
* @file RDI.cpp
* @date 15/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Data Interface library main entry file.
*
*/
#if defined(RDI_DLL)
# define RDI_DLLBUILD
#endif
#include <iostream>
#include <string>
#include <fstream>
#include "config.h"
#include "RDat.h"
#include "RDI.h"
using namespace std;
using RDI::RDat;
/*
* Libs interface
*/
inline const char* RDI::getVersion( void ) {
return PRG_VERSION;
}
unsigned short OpenRogueDat( void ) {
return 0;
}
unsigned short OpenRogueDat( const char* filePath ){
auto rogueData = new RDat(filePath);
delete rogueData;
return 0;
}

50
src/RDat.cpp Normal file
View File

@ -0,0 +1,50 @@
/**
* @file RDat.cpp
* @date 15/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Dat file class interface.
*
*/
#include <iostream>
#include <fstream>
#include "RDat.h"
using namespace std;
namespace RDI {
RDat::RDat( string fPath ) {
string datFile, hdrFile;
fstream rdf;
streampos size;
datFile = fPath + "/DATA.DAT";
hdrFile = fPath + "/DATA.HDR";
rdf.open(datFile, ios::in | ios::binary);
if (rdf.is_open()) {
size = rdf.tellg();
rDatPtr = new char[size];
rdf.seekg(0, ios::beg);
rdf.read(rDatPtr, size);
rdf.close();
}
rdf.open(hdrFile, ios::in | ios::binary);
if (rdf.is_open()) {
size = rdf.tellg();
rDatPtr = new char[size];
rdf.seekg(0, ios::beg);
rdf.read(rDatPtr, size);
rdf.close();
}
}
RDat::~RDat() {
delete rDatPtr;
}
} /* namespace RDI */

33
src/RDat.h Normal file
View File

@ -0,0 +1,33 @@
/**
* @file RDat.h
* @date 15/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Dat file class interface.
*
*/
#ifndef SRC_RDAT_H_
#define SRC_RDAT_H_
namespace RDI {
typedef char* MEMFILE;
class RDat {
private:
MEMFILE rDatPtr = nullptr;
public:
RDat( std::string fPath );
virtual ~RDat();
MEMFILE getRDat() {
return rDatPtr;
}
};
} /* namespace RDI */
#endif /* SRC_RDAT_H_ */

23
src/datfiles/HMT.cpp Normal file
View File

@ -0,0 +1,23 @@
/**
* @file HMT.cpp
* @date 15/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief HMT file object class.
*
*/
#include "HMT.h"
namespace RDI {
HMT::HMT() {
// TODO Auto-generated constructor stub
}
HMT::~HMT() {
// TODO Auto-generated destructor stub
}
} /* namespace RDI */

23
src/datfiles/HMT.h Normal file
View File

@ -0,0 +1,23 @@
/**
* @file HMT.h
* @date 15/09/2022
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief HMT file object class.
*
*/
#ifndef SRC_DATFILES_HMT_H_
#define SRC_DATFILES_HMT_H_
namespace RDI {
class HMT {
public:
HMT();
virtual ~HMT();
};
} /* namespace RDI */
#endif /* SRC_DATFILES_HMT_H_ */