RDI/src/RDI.cpp
JackCarterSmith 05b3c1e88a
HOB file management
HOB file handler prototype

Mesh building should be moved to RSPModel lib

Tree rendering unicode chars fix


Updated version detection


HOB file handler




Debug HOB handler

Pointer probably deallocated, need to check it

Fix HOB loader and disposer


Using HOB instance instead of static methods


Review DLL support for MSVC build


Vertices values calculation fix


Added export obj method to debug tool


Missed levels name separation


Cleaned model processing

Multithreading branch reported to later
2023-02-03 18:12:04 +01:00

161 lines
4.1 KiB
C++

/**
* @file RDI.cpp
* @date 22/01/2023
* @author JackCarterSmith
* @copyright GPL-v3.0
* @brief Rogue Data Interface library main entry abstraction file.
*
*/
#if defined(RDI_DLL)
# define RDI_DLLBUILD
#endif
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <stdexcept>
#include <RSPModel.h> // Only for version getting, no processing.
#include "config.h"
#include "Erso.hpp"
#include "DatFileEntry.hpp"
#include "Krennic.hpp"
#include <FileHandler/HOB.h>
#include "RDI.hpp"
using namespace RDI::DatFile;
/*
* Internal modules instance
*/
static RDI::Erso *ErsoModule = nullptr;
static RDI::Krennic *KrennicModule = nullptr;
/*
* Libs interface
*/
const std::string RDI::RDI_getLibVersion() noexcept { return PRG_VERSION; }
void RDI::RDI_Init( std::string roguePath ) {
#ifndef NDEBUG
std::cout << std::endl << "Running RDI v" << std::string(RDI::RDI_getLibVersion()) << std::endl;
std::cout << "> RSPModelLib v" << std::string(RSPModel_getVersion()) << std::endl;
std::cout << "> RSPTerrainLib v" << "N/A" << std::endl;
std::cout << "> RSPTextureLib v" << "N/A" << std::endl;
#endif
// Create new instance of Erso module
// Load and extract datas files from DATA.DAT
if (ErsoModule == nullptr) {
#ifndef NDEBUG
std::cout << "[RDI][DBG] Loading Erso module..." << std::endl;
#endif
ErsoModule = new RDI::Erso(roguePath);
}
// Create new instance of Krennic module
// Process datas from Erso and build new dataset to be used outside this library
if (ErsoModule != nullptr && KrennicModule == nullptr) {
#ifndef NDEBUG
std::cout << "[RDI][DBG] Loading Krennic module..." << std::endl;
#endif
KrennicModule = new RDI::Krennic(ErsoModule);
}
}
const unsigned char RDI::RDI_getSectionCount() {
if (ErsoModule == nullptr) return 0;
else return ErsoModule->getDataSectionCount();
}
const std::string RDI::RDI_getSectionName( unsigned char id ) {
if (ErsoModule == nullptr) return "";
else return ErsoModule->getDataSectionName(id);
}
const unsigned int RDI::RDI_getSectionOffset( unsigned char id ) {
if (ErsoModule == nullptr) return 0;
else return ErsoModule->getDataSectionOffset(id);
}
const unsigned int RDI::RDI_getDirectoryElementCount( std::string path ) {
DatFileEntryDirectory* result = nullptr;
if (path.empty()) return 0;
result = dynamic_cast<DatFileEntryDirectory *>(ErsoModule->getElement(boost::filesystem::path(path)));
if (result == nullptr) return 0;
else return result->getSize();
}
const std::vector<std::string> RDI::RDI_getDirectoryElements( std::string path ) {
DatFileEntryDirectory* de = nullptr;
std::vector<std::string> elementsNameArray;
elementsNameArray.clear();
if (!path.empty()) {
de = dynamic_cast<DatFileEntryDirectory *>(ErsoModule->getElement(boost::filesystem::path(path)));
if (de != nullptr && de->isDirectory()) {
for (DatFileEntry* de2 : de->getFiles())
elementsNameArray.push_back(de2->getName());
}
}
return elementsNameArray;
}
const bool RDI::RDI_isElementDirectory( std::string path ) {
DatFileEntry* result = nullptr;
if (path.empty()) return false;
result = ErsoModule->getElement(boost::filesystem::path(path));
if (result == nullptr) return false;
else return (result->isDirectory() || result->isRootDirectory());
}
/* -------------------------------------------------------------------------- */
const std::vector<std::string> RDI::RDI_getLevelsName( void ) {
return KrennicModule->getLevelsList();
}
const std::vector<std::string> RDI::RDI_getModelsName( void ) {
return KrennicModule->getModelsList();
}
const std::vector<std::string> RDI::RDI_getTexturesName( void ) {
return KrennicModule->getTexturesList();
}
const std::vector<std::string> RDI::RDI_getMusicsName( void ) {
return KrennicModule->getMusicsList();
}
RDI::HOB* RDI::RDI_getModel( std::string modelName ) {
try {
return KrennicModule->getModel(modelName);
}
catch (std::invalid_argument const &ex) { // Can't find model, incorrect name?
throw std::invalid_argument(ex);
}
}
/* -------------------------------------------------------------------------- */
void RDI::RDI_CleanUp(){
if (KrennicModule) delete KrennicModule;
if (ErsoModule) delete ErsoModule;
}