From 36149cf38e813405cc636ebca68317a7a14859ff Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 21 Jun 2018 16:49:05 +0200 Subject: [PATCH 1/4] rwlib: rw/defines.hpp -> rw/debug.hpp --- rwengine/src/BinaryStream.cpp | 2 +- rwengine/src/TextureArchive.cpp | 2 +- rwengine/src/ai/AIGraph.cpp | 2 +- rwengine/src/ai/CharacterController.cpp | 2 +- rwengine/src/audio/SoundManager.cpp | 2 +- rwengine/src/core/Profiler.hpp | 2 +- rwengine/src/data/AnimGroup.cpp | 2 +- rwengine/src/data/Chase.cpp | 2 +- rwengine/src/data/ModelData.hpp | 2 +- rwengine/src/engine/Animator.hpp | 2 +- rwengine/src/engine/GameData.cpp | 2 +- rwengine/src/engine/GameData.hpp | 2 +- rwengine/src/engine/Garage.hpp | 8 ++++---- rwengine/src/engine/Payphone.cpp | 2 +- rwengine/src/engine/SaveGame.cpp | 2 +- rwengine/src/engine/ScreenText.cpp | 2 +- rwengine/src/loaders/GenericDATLoader.cpp | 2 +- rwengine/src/loaders/LoaderCutsceneDAT.cpp | 2 +- rwengine/src/objects/CharacterObject.cpp | 2 +- rwengine/src/objects/GameObject.hpp | 2 +- rwengine/src/objects/PickupObject.hpp | 2 +- rwengine/src/render/DebugDraw.cpp | 2 +- rwengine/src/render/OpenGLRenderer.cpp | 2 +- rwengine/src/render/WaterRenderer.cpp | 2 +- rwengine/src/script/ScriptFunctions.hpp | 2 +- rwengine/src/script/ScriptTypes.hpp | 2 +- rwgame/GameBase.cpp | 2 +- rwgame/GameConfig.cpp | 2 +- rwgame/MenuSystem.hpp | 2 +- rwgame/states/MenuState.cpp | 2 +- rwlib/CMakeLists.txt | 2 +- rwlib/source/loaders/LoaderDFF.cpp | 2 +- rwlib/source/loaders/LoaderIMG.cpp | 2 +- rwlib/source/loaders/LoaderSDT.cpp | 2 +- rwlib/source/loaders/LoaderTXD.cpp | 2 +- rwlib/source/loaders/RWBinaryStream.hpp | 2 +- rwlib/source/rw/bit_cast.cpp | 2 +- rwlib/source/rw/{defines.hpp => debug.hpp} | 4 ++-- rwlib/source/rw/types.hpp | 2 +- tests/test_Config.cpp | 2 +- 40 files changed, 44 insertions(+), 44 deletions(-) rename rwlib/source/rw/{defines.hpp => debug.hpp} (96%) diff --git a/rwengine/src/BinaryStream.cpp b/rwengine/src/BinaryStream.cpp index 90b89c36..7ca1f157 100644 --- a/rwengine/src/BinaryStream.cpp +++ b/rwengine/src/BinaryStream.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include namespace RW { diff --git a/rwengine/src/TextureArchive.cpp b/rwengine/src/TextureArchive.cpp index 6e25cd68..cdbffee1 100644 --- a/rwengine/src/TextureArchive.cpp +++ b/rwengine/src/TextureArchive.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include "BinaryStream.hpp" diff --git a/rwengine/src/ai/AIGraph.cpp b/rwengine/src/ai/AIGraph.cpp index 9865a76b..29a5b7d0 100644 --- a/rwengine/src/ai/AIGraph.cpp +++ b/rwengine/src/ai/AIGraph.cpp @@ -7,7 +7,7 @@ #include "ai/AIGraphNode.hpp" #include "data/PathData.hpp" -#include +#include #include AIGraph::~AIGraph() { diff --git a/rwengine/src/ai/CharacterController.cpp b/rwengine/src/ai/CharacterController.cpp index e5794699..210e5e26 100644 --- a/rwengine/src/ai/CharacterController.cpp +++ b/rwengine/src/ai/CharacterController.cpp @@ -11,7 +11,7 @@ #include -#include +#include #include "data/WeaponData.hpp" #include "engine/Animator.hpp" diff --git a/rwengine/src/audio/SoundManager.cpp b/rwengine/src/audio/SoundManager.cpp index c8b20ee7..c9a68979 100644 --- a/rwengine/src/audio/SoundManager.cpp +++ b/rwengine/src/audio/SoundManager.cpp @@ -8,7 +8,7 @@ extern "C" { #include } //ab -#include +#include // Rename some functions for older libavcodec/ffmpeg versions (e.g. Ubuntu Trusty) #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1) diff --git a/rwengine/src/core/Profiler.hpp b/rwengine/src/core/Profiler.hpp index 3dedd39d..516db3ec 100644 --- a/rwengine/src/core/Profiler.hpp +++ b/rwengine/src/core/Profiler.hpp @@ -9,7 +9,7 @@ #include #define time_unit std::chrono::microseconds -#include +#include namespace perf { diff --git a/rwengine/src/data/AnimGroup.cpp b/rwengine/src/data/AnimGroup.cpp index 26ffa6d5..35980a16 100644 --- a/rwengine/src/data/AnimGroup.cpp +++ b/rwengine/src/data/AnimGroup.cpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include // The default animations for every cycle diff --git a/rwengine/src/data/Chase.cpp b/rwengine/src/data/Chase.cpp index 90eee3bc..d74cf05c 100644 --- a/rwengine/src/data/Chase.cpp +++ b/rwengine/src/data/Chase.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include "engine/GameWorld.hpp" #include "objects/GameObject.hpp" diff --git a/rwengine/src/data/ModelData.hpp b/rwengine/src/data/ModelData.hpp index b9f3ff84..45dfc599 100644 --- a/rwengine/src/data/ModelData.hpp +++ b/rwengine/src/data/ModelData.hpp @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include diff --git a/rwengine/src/engine/Animator.hpp b/rwengine/src/engine/Animator.hpp index 59842ec9..783e2d24 100644 --- a/rwengine/src/engine/Animator.hpp +++ b/rwengine/src/engine/Animator.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include struct AnimationBone; diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index 33502fea..25c3fbdf 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include "core/Logger.hpp" diff --git a/rwengine/src/engine/GameData.hpp b/rwengine/src/engine/GameData.hpp index 9968a827..7ce57019 100644 --- a/rwengine/src/engine/GameData.hpp +++ b/rwengine/src/engine/GameData.hpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include #include diff --git a/rwengine/src/engine/Garage.hpp b/rwengine/src/engine/Garage.hpp index 04acc452..1cfc263a 100644 --- a/rwengine/src/engine/Garage.hpp +++ b/rwengine/src/engine/Garage.hpp @@ -1,9 +1,9 @@ -#ifndef _RWENGINE_Garage_HPP_ -#define _RWENGINE_Garage_HPP_ +#ifndef _RWENGINE_GARAGE_HPP_ +#define _RWENGINE_GARAGE_HPP_ #include #include -#include +#include class PlayerController; @@ -109,4 +109,4 @@ public: void tick(float dt); }; -#endif \ No newline at end of file +#endif diff --git a/rwengine/src/engine/Payphone.cpp b/rwengine/src/engine/Payphone.cpp index 965dc530..5c653c83 100644 --- a/rwengine/src/engine/Payphone.cpp +++ b/rwengine/src/engine/Payphone.cpp @@ -1,6 +1,6 @@ #include "engine/Payphone.hpp" -#include +#include #include "ai/PlayerController.hpp" diff --git a/rwengine/src/engine/SaveGame.cpp b/rwengine/src/engine/SaveGame.cpp index 9bb0dfe7..d04f1edf 100644 --- a/rwengine/src/engine/SaveGame.cpp +++ b/rwengine/src/engine/SaveGame.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include "data/ZoneData.hpp" #include "engine/GameData.hpp" diff --git a/rwengine/src/engine/ScreenText.cpp b/rwengine/src/engine/ScreenText.cpp index 19c75405..557b87d5 100644 --- a/rwengine/src/engine/ScreenText.cpp +++ b/rwengine/src/engine/ScreenText.cpp @@ -1,6 +1,6 @@ #include "engine/ScreenText.hpp" -#include +#include void ScreenText::tick(float dt) { int millis = dt * 1000; diff --git a/rwengine/src/loaders/GenericDATLoader.cpp b/rwengine/src/loaders/GenericDATLoader.cpp index ac5b6641..408021d5 100644 --- a/rwengine/src/loaders/GenericDATLoader.cpp +++ b/rwengine/src/loaders/GenericDATLoader.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/rwengine/src/loaders/LoaderCutsceneDAT.cpp b/rwengine/src/loaders/LoaderCutsceneDAT.cpp index ce94660a..e2795859 100644 --- a/rwengine/src/loaders/LoaderCutsceneDAT.cpp +++ b/rwengine/src/loaders/LoaderCutsceneDAT.cpp @@ -7,7 +7,7 @@ #include -#include +#include #include "data/CutsceneData.hpp" #include "platform/FileHandle.hpp" diff --git a/rwengine/src/objects/CharacterObject.cpp b/rwengine/src/objects/CharacterObject.cpp index 76313ffb..961f2ee5 100644 --- a/rwengine/src/objects/CharacterObject.cpp +++ b/rwengine/src/objects/CharacterObject.cpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include "ai/CharacterController.hpp" #include "ai/PlayerController.hpp" diff --git a/rwengine/src/objects/GameObject.hpp b/rwengine/src/objects/GameObject.hpp index b4927c34..d85777b2 100644 --- a/rwengine/src/objects/GameObject.hpp +++ b/rwengine/src/objects/GameObject.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include diff --git a/rwengine/src/objects/PickupObject.hpp b/rwengine/src/objects/PickupObject.hpp index 8143a353..0ea822f6 100644 --- a/rwengine/src/objects/PickupObject.hpp +++ b/rwengine/src/objects/PickupObject.hpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include diff --git a/rwengine/src/render/DebugDraw.cpp b/rwengine/src/render/DebugDraw.cpp index 84459acd..be0c4431 100644 --- a/rwengine/src/render/DebugDraw.cpp +++ b/rwengine/src/render/DebugDraw.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include "render/GameRenderer.hpp" diff --git a/rwengine/src/render/OpenGLRenderer.cpp b/rwengine/src/render/OpenGLRenderer.cpp index 2bd4ccc6..d816d455 100644 --- a/rwengine/src/render/OpenGLRenderer.cpp +++ b/rwengine/src/render/OpenGLRenderer.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace { constexpr GLuint kUBOIndexScene = 1; diff --git a/rwengine/src/render/WaterRenderer.cpp b/rwengine/src/render/WaterRenderer.cpp index 59a37eb0..26fed89e 100644 --- a/rwengine/src/render/WaterRenderer.cpp +++ b/rwengine/src/render/WaterRenderer.cpp @@ -4,7 +4,7 @@ #include -#include +#include #include #include "engine/GameData.hpp" diff --git a/rwengine/src/script/ScriptFunctions.hpp b/rwengine/src/script/ScriptFunctions.hpp index 050094f7..9bed45c9 100644 --- a/rwengine/src/script/ScriptFunctions.hpp +++ b/rwengine/src/script/ScriptFunctions.hpp @@ -1,7 +1,7 @@ #ifndef _RWENGINE_SCRIPTFUNCTIONS_HPP_ #define _RWENGINE_SCRIPTFUNCTIONS_HPP_ -#include +#include #include #include diff --git a/rwengine/src/script/ScriptTypes.hpp b/rwengine/src/script/ScriptTypes.hpp index 7d996555..9164e138 100644 --- a/rwengine/src/script/ScriptTypes.hpp +++ b/rwengine/src/script/ScriptTypes.hpp @@ -9,7 +9,7 @@ #include -#include +#include #include "engine/Garage.hpp" diff --git a/rwgame/GameBase.cpp b/rwgame/GameBase.cpp index 6c09a0e9..60bd8146 100644 --- a/rwgame/GameBase.cpp +++ b/rwgame/GameBase.cpp @@ -6,7 +6,7 @@ #include -#include +#include #include "GitSHA1.h" diff --git a/rwgame/GameConfig.cpp b/rwgame/GameConfig.cpp index f4f7fa3f..9ab72e03 100644 --- a/rwgame/GameConfig.cpp +++ b/rwgame/GameConfig.cpp @@ -1,7 +1,7 @@ #include "GameConfig.hpp" #include -#include +#include #include #include diff --git a/rwgame/MenuSystem.hpp b/rwgame/MenuSystem.hpp index df717dd0..cbf9e911 100644 --- a/rwgame/MenuSystem.hpp +++ b/rwgame/MenuSystem.hpp @@ -8,7 +8,7 @@ #include #include -#include +#include /** * Default values for menus that should match the look and feel of the original diff --git a/rwgame/states/MenuState.cpp b/rwgame/states/MenuState.cpp index a682eb30..a32144c9 100644 --- a/rwgame/states/MenuState.cpp +++ b/rwgame/states/MenuState.cpp @@ -3,7 +3,7 @@ #include "game.hpp" #include -#include +#include #include "RWGame.hpp" MenuState::MenuState(RWGame* game) : State(game) { diff --git a/rwlib/CMakeLists.txt b/rwlib/CMakeLists.txt index e249bb92..68582de4 100644 --- a/rwlib/CMakeLists.txt +++ b/rwlib/CMakeLists.txt @@ -20,7 +20,7 @@ SET(RWLIB_SOURCES source/rw/filesystem.hpp source/rw/forward.hpp source/rw/types.hpp - source/rw/defines.hpp + source/rw/debug.hpp source/platform/FileHandle.hpp source/platform/FileIndex.hpp diff --git a/rwlib/source/loaders/LoaderDFF.cpp b/rwlib/source/loaders/LoaderDFF.cpp index fbed416c..2aa3667c 100644 --- a/rwlib/source/loaders/LoaderDFF.cpp +++ b/rwlib/source/loaders/LoaderDFF.cpp @@ -14,7 +14,7 @@ #include "gl/gl_core_3_3.h" #include "loaders/RWBinaryStream.hpp" #include "platform/FileHandle.hpp" -#include "rw/defines.hpp" +#include "rw/debug.hpp" enum DFFChunks { CHUNK_STRUCT = 0x0001, diff --git a/rwlib/source/loaders/LoaderIMG.cpp b/rwlib/source/loaders/LoaderIMG.cpp index e4fa7cf4..208f67d2 100644 --- a/rwlib/source/loaders/LoaderIMG.cpp +++ b/rwlib/source/loaders/LoaderIMG.cpp @@ -3,7 +3,7 @@ #include #include -#include "rw/defines.hpp" +#include "rw/debug.hpp" LoaderIMG::LoaderIMG() : m_version(GTAIIIVC), m_assetCount(0) { } diff --git a/rwlib/source/loaders/LoaderSDT.cpp b/rwlib/source/loaders/LoaderSDT.cpp index a32c5934..50867864 100644 --- a/rwlib/source/loaders/LoaderSDT.cpp +++ b/rwlib/source/loaders/LoaderSDT.cpp @@ -4,7 +4,7 @@ #include #include -#include "rw/defines.hpp" +#include "rw/debug.hpp" LoaderSDT::LoaderSDT() : m_version(GTAIIIVC), m_assetCount(0) { } diff --git a/rwlib/source/loaders/LoaderTXD.cpp b/rwlib/source/loaders/LoaderTXD.cpp index 2edbac60..5183e4c7 100644 --- a/rwlib/source/loaders/LoaderTXD.cpp +++ b/rwlib/source/loaders/LoaderTXD.cpp @@ -10,7 +10,7 @@ #include "gl/gl_core_3_3.h" #include "loaders/RWBinaryStream.hpp" #include "platform/FileHandle.hpp" -#include "rw/defines.hpp" +#include "rw/debug.hpp" GLuint gErrorTextureData[] = {0xFFFF00FF, 0xFF000000, 0xFF000000, 0xFFFF00FF}; GLuint gDebugTextureData[] = {0xFF0000FF, 0xFF00FF00}; diff --git a/rwlib/source/loaders/RWBinaryStream.hpp b/rwlib/source/loaders/RWBinaryStream.hpp index 92b69633..8a16ba20 100644 --- a/rwlib/source/loaders/RWBinaryStream.hpp +++ b/rwlib/source/loaders/RWBinaryStream.hpp @@ -6,7 +6,7 @@ #include -#include "rw/defines.hpp" +#include "rw/debug.hpp" #include "rw/bit_cast.cpp" /** diff --git a/rwlib/source/rw/bit_cast.cpp b/rwlib/source/rw/bit_cast.cpp index 77112900..3870ae58 100644 --- a/rwlib/source/rw/bit_cast.cpp +++ b/rwlib/source/rw/bit_cast.cpp @@ -4,7 +4,7 @@ //Based on https://gist.github.com/socantre/3472964 #include // memcpy #include // is_trivially_copyable -#include "rw/defines.hpp" // RW_ASSERT +#include "rw/debug.hpp" // RW_ASSERT template inline Dest bit_cast(Source const &source) { diff --git a/rwlib/source/rw/defines.hpp b/rwlib/source/rw/debug.hpp similarity index 96% rename from rwlib/source/rw/defines.hpp rename to rwlib/source/rw/debug.hpp index e38afa15..890af825 100644 --- a/rwlib/source/rw/defines.hpp +++ b/rwlib/source/rw/debug.hpp @@ -1,5 +1,5 @@ -#ifndef _LIBRW_DEFINES_HPP_ -#define _LIBRW_DEFINES_HPP_ +#ifndef _LIBRW_DEBUG_HPP_ +#define _LIBRW_DEBUG_HPP_ #if RW_DEBUG #include diff --git a/rwlib/source/rw/types.hpp b/rwlib/source/rw/types.hpp index f23e40cb..d5bde0dd 100644 --- a/rwlib/source/rw/types.hpp +++ b/rwlib/source/rw/types.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #define RW_USING(feature) 1 == feature diff --git a/tests/test_Config.cpp b/tests/test_Config.cpp index 796e1126..d63b5c10 100644 --- a/tests/test_Config.cpp +++ b/tests/test_Config.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #include namespace pt = boost::property_tree; From 4f60dfad43b4b2596674d5aac7b2b9c7f3d00670 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 21 Jun 2018 16:59:48 +0200 Subject: [PATCH 2/4] rwlib: bit_case is a header, not a source file --- rwengine/src/script/SCMFile.hpp | 7 ++++--- rwlib/CMakeLists.txt | 2 +- rwlib/source/loaders/RWBinaryStream.hpp | 2 +- rwlib/source/rw/{bit_cast.cpp => bit_cast.hpp} | 5 ++--- 4 files changed, 8 insertions(+), 8 deletions(-) rename rwlib/source/rw/{bit_cast.cpp => bit_cast.hpp} (76%) diff --git a/rwengine/src/script/SCMFile.hpp b/rwengine/src/script/SCMFile.hpp index d3122c93..7f201af0 100644 --- a/rwengine/src/script/SCMFile.hpp +++ b/rwengine/src/script/SCMFile.hpp @@ -1,13 +1,14 @@ #ifndef _RWENGINE_SCMFILE_HPP_ #define _RWENGINE_SCMFILE_HPP_ +#include "script/ScriptTypes.hpp" + +#include + #include #include #include -#include "script/ScriptTypes.hpp" -#include "rw/bit_cast.cpp" - /** * @brief Handles in-memory SCM file data including section offsets. */ diff --git a/rwlib/CMakeLists.txt b/rwlib/CMakeLists.txt index 68582de4..76e107c0 100644 --- a/rwlib/CMakeLists.txt +++ b/rwlib/CMakeLists.txt @@ -16,7 +16,7 @@ SET(RWLIB_SOURCES source/gl/TextureData.cpp source/rw/abort.cpp - source/rw/bit_cast.cpp + source/rw/bit_cast.hpp source/rw/filesystem.hpp source/rw/forward.hpp source/rw/types.hpp diff --git a/rwlib/source/loaders/RWBinaryStream.hpp b/rwlib/source/loaders/RWBinaryStream.hpp index 8a16ba20..d44224be 100644 --- a/rwlib/source/loaders/RWBinaryStream.hpp +++ b/rwlib/source/loaders/RWBinaryStream.hpp @@ -7,7 +7,7 @@ #include #include "rw/debug.hpp" -#include "rw/bit_cast.cpp" +#include "rw/bit_cast.hpp" /** * @brief Class for working with RenderWare binary streams. diff --git a/rwlib/source/rw/bit_cast.cpp b/rwlib/source/rw/bit_cast.hpp similarity index 76% rename from rwlib/source/rw/bit_cast.cpp rename to rwlib/source/rw/bit_cast.hpp index 3870ae58..d52fcb52 100644 --- a/rwlib/source/rw/bit_cast.cpp +++ b/rwlib/source/rw/bit_cast.hpp @@ -1,10 +1,9 @@ -#ifndef _LIBRW_BIT_CAST_CPP_ -#define _LIBRW_BIT_CAST_CPP_ +#ifndef _LIBRW_BIT_CAST_HPP_ +#define _LIBRW_BIT_CAST_HPP_ //Based on https://gist.github.com/socantre/3472964 #include // memcpy #include // is_trivially_copyable -#include "rw/debug.hpp" // RW_ASSERT template inline Dest bit_cast(Source const &source) { From 062115f6bd95d9fdb046ac611e11788f10aafd98 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 21 Jun 2018 17:43:38 +0200 Subject: [PATCH 3/4] rwgame+rwengine: get background from index + pass as rwfs::path --- rwengine/src/audio/SoundManager.cpp | 16 ++++++++-------- rwengine/src/audio/SoundManager.hpp | 10 ++++++---- rwgame/states/IngameState.cpp | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/rwengine/src/audio/SoundManager.cpp b/rwengine/src/audio/SoundManager.cpp index c9a68979..f6904015 100644 --- a/rwengine/src/audio/SoundManager.cpp +++ b/rwengine/src/audio/SoundManager.cpp @@ -64,7 +64,7 @@ bool SoundManager::initializeAVCodec() { return true; } -void SoundManager::SoundSource::loadFromFile(const std::string& filename) { +void SoundManager::SoundSource::loadFromFile(const rwfs::path& filePath) { // Allocate audio frame AVFrame* frame = av_frame_alloc(); if (!frame) { @@ -74,9 +74,9 @@ void SoundManager::SoundSource::loadFromFile(const std::string& filename) { // Allocate formatting context AVFormatContext* formatContext = nullptr; - if (avformat_open_input(&formatContext, filename.c_str(), nullptr, nullptr) != 0) { + if (avformat_open_input(&formatContext, filePath.string().c_str(), nullptr, nullptr) != 0) { av_frame_free(&frame); - RW_ERROR("Error opening audio file (" << filename << ")"); + RW_ERROR("Error opening audio file (" << filePath << ")"); return; } @@ -93,7 +93,7 @@ void SoundManager::SoundSource::loadFromFile(const std::string& filename) { if (streamIndex < 0) { av_frame_free(&frame); avformat_close_input(&formatContext); - RW_ERROR("Could not find any audio stream in the file " << filename); + RW_ERROR("Could not find any audio stream in the file " << filePath); return; } @@ -196,7 +196,7 @@ bool SoundManager::SoundBuffer::bufferData(SoundSource& soundSource) { } bool SoundManager::loadSound(const std::string& name, - const std::string& fileName) { + const rwfs::path& path) { Sound* sound = nullptr; auto sound_iter = sounds.find(name); @@ -208,7 +208,7 @@ bool SoundManager::loadSound(const std::string& name, std::forward_as_tuple()); sound = &emplaced.first->second; - sound->source.loadFromFile(fileName); + sound->source.loadFromFile(path); sound->isLoaded = sound->buffer.bufferData(sound->source); } @@ -280,8 +280,8 @@ bool SoundManager::playBackground(const std::string& fileName) { } bool SoundManager::loadMusic(const std::string& name, - const std::string& fileName) { - return loadSound(name, fileName); + const rwfs::path& path) { + return loadSound(name, path); } void SoundManager::playMusic(const std::string& name) { diff --git a/rwengine/src/audio/SoundManager.hpp b/rwengine/src/audio/SoundManager.hpp index 62b290eb..e8cc0108 100644 --- a/rwengine/src/audio/SoundManager.hpp +++ b/rwengine/src/audio/SoundManager.hpp @@ -7,6 +7,8 @@ #include #include +#include + #include #include @@ -15,7 +17,7 @@ public: SoundManager(); ~SoundManager(); - bool loadSound(const std::string& name, const std::string& fileName); + bool loadSound(const std::string& name, const rwfs::path& path); bool isLoaded(const std::string& name); void playSound(const std::string& name); void pauseSound(const std::string& name); @@ -26,9 +28,9 @@ public: void pauseAllSounds(); void resumeAllSounds(); - bool playBackground(const std::string& fileName); + bool playBackground(const std::string& name); - bool loadMusic(const std::string& name, const std::string& fileName); + bool loadMusic(const std::string& name, const rwfs::path& path); void playMusic(const std::string& name); void stopMusic(const std::string& name); @@ -40,7 +42,7 @@ private: friend class SoundBuffer; public: - void loadFromFile(const std::string& filename); + void loadFromFile(const rwfs::path& filePath); private: std::vector data; diff --git a/rwgame/states/IngameState.cpp b/rwgame/states/IngameState.cpp index d1606877..6e977307 100644 --- a/rwgame/states/IngameState.cpp +++ b/rwgame/states/IngameState.cpp @@ -106,8 +106,8 @@ void IngameState::startTest() { void IngameState::startGame() { game->startScript("data/main.scm"); game->getScriptVM()->startThread(0); - getWorld()->sound.playBackground(getWorld()->data->getDataPath().string() + - "/audio/City.wav"); // FIXME: use path + auto audioCityPath = getWorld()->data->index.findFilePath("audio/City.wav"); + getWorld()->sound.playBackground(audioCityPath.string()); //FIXME: playBackground should just accept "audio/City.wav" } void IngameState::enter() { From 8aee672466fa7ae99bda6d5a3fbe18b4e34814f9 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 21 Jun 2018 23:41:10 +0200 Subject: [PATCH 4/4] rwlib: refactor FileIndex - make FileIndex const correct (std::map::operator[] modifies the std::map) - use a single map - keys are paths relative in the game data directory + filenames (so paths like "data/main.scm" can be found twice in the map) - normalization of the file paths is done inside FileIndex, so there shouldn't be any ::tolower's anymore. - added a normalizer helper function "normalizeFilePath" - added Documentation --- rwengine/src/engine/GameData.cpp | 10 +- rwengine/src/engine/GameWorld.cpp | 8 +- rwlib/source/platform/FileHandle.hpp | 4 +- rwlib/source/platform/FileIndex.cpp | 136 ++++++++++++++------------- rwlib/source/platform/FileIndex.hpp | 117 ++++++++++++----------- tests/test_FileIndex.cpp | 49 +++++++--- tests/test_Text.cpp | 2 +- 7 files changed, 173 insertions(+), 153 deletions(-) diff --git a/rwengine/src/engine/GameData.cpp b/rwengine/src/engine/GameData.cpp index 25c3fbdf..76586417 100644 --- a/rwengine/src/engine/GameData.cpp +++ b/rwengine/src/engine/GameData.cpp @@ -41,7 +41,6 @@ GameData::GameData(Logger* log, const rwfs::path& path) GameData::~GameData() = default; void GameData::load() { - index.indexGameDirectory(datpath); index.indexTree(datpath); loadIMG("models/gta3.img"); @@ -191,8 +190,7 @@ void GameData::loadCOL(const size_t zone, const std::string& name) { } void GameData::loadIMG(const std::string& name) { - auto syspath = index.findFilePath(name).string(); - index.indexArchive(syspath); + index.indexArchive(name); } void GameData::loadIPL(const std::string& path) { @@ -290,7 +288,7 @@ void GameData::loadHandling(const std::string& path) { } SCMFile* GameData::loadSCM(const std::string& path) { - auto scm_h = index.openFilePath(path); + auto scm_h = index.openFileRaw(path); SCMFile* scm = new SCMFile; scm->loadFile(scm_h->data, scm_h->length); scm_h.reset(); @@ -298,7 +296,7 @@ SCMFile* GameData::loadSCM(const std::string& path) { } void GameData::loadGXT(const std::string& name) { - auto file = index.openFilePath(name); + auto file = index.openFileRaw(name); LoaderGXT loader; @@ -419,7 +417,7 @@ ClumpPtr GameData::loadClump(const std::string& name, const std::string& texture } void GameData::loadModelFile(const std::string& name) { - auto file = index.openFilePath(name); + auto file = index.openFileRaw(name); if (!file) { logger->log("Data", Logger::Error, "Failed to load model file " + name); return; diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 602ffce1..f61cf571 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -691,11 +691,7 @@ void GameWorld::PhysicsTickCallback(btDynamicsWorld* physWorld, } void GameWorld::loadCutscene(const std::string& name) { - std::string lowerName(name); - std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), - ::tolower); - - auto datfile = data->index.openFile(lowerName + ".dat"); + auto datfile = data->index.openFile(name + ".dat"); CutsceneData* cutscene = new CutsceneData; @@ -704,7 +700,7 @@ void GameWorld::loadCutscene(const std::string& name) { loaderdat.load(cutscene->tracks, datfile); } - data->loadIFP(lowerName + ".ifp"); + data->loadIFP(name + ".ifp"); cutsceneAudioLoaded = data->loadAudioStream(name + ".mp3"); diff --git a/rwlib/source/platform/FileHandle.hpp b/rwlib/source/platform/FileHandle.hpp index 4ab1801a..aae88aa6 100644 --- a/rwlib/source/platform/FileHandle.hpp +++ b/rwlib/source/platform/FileHandle.hpp @@ -1,13 +1,11 @@ #ifndef _LIBRW_FILEHANDLE_HPP_ #define _LIBRW_FILEHANDLE_HPP_ -#include - /** * @brief Contains a pointer to a file's contents. */ struct FileContentsInfo { - char* data; + char *data; size_t length; FileContentsInfo(char* mem, size_t len) : data(mem), length(len) { diff --git a/rwlib/source/platform/FileIndex.cpp b/rwlib/source/platform/FileIndex.cpp index c8c575f7..5da3a8a2 100644 --- a/rwlib/source/platform/FileIndex.cpp +++ b/rwlib/source/platform/FileIndex.cpp @@ -1,38 +1,69 @@ #include "platform/FileIndex.hpp" #include +#include #include -#include -#include - -#include +#include +#include +#include "FileHandle.hpp" #include "loaders/LoaderIMG.hpp" -#include "platform/FileHandle.hpp" -void FileIndex::indexGameDirectory(const rwfs::path& base_path) { - gamedatapath_ = base_path; +#include "rw/debug.hpp" - for (const rwfs::path& path : - rwfs::recursive_directory_iterator(base_path)) { +std::string FileIndex::normalizeFilePath(const std::string &filePath) { + std::ostringstream oss; + std::transform(filePath.cbegin(), filePath.cend(), std::ostreambuf_iterator(oss), [](char c) { + if (c == '\\') { + return '/'; + } + return static_cast(std::tolower(c)); + }); + return oss.str(); +} + +void FileIndex::indexTree(const rwfs::path &path) { + // Remove the trailing "/" or "/." from base_path. Boost 1.66 and c++17 have different lexically_relative behavior. + rwfs::path basePath = (path / ".").lexically_normal(); + basePath = basePath.parent_path(); + + for (const rwfs::path &path : + rwfs::recursive_directory_iterator(basePath)) { if (!rwfs::is_regular_file(path)) { continue; } + auto relPath = path.lexically_relative(basePath); + std::string relPathName = normalizeFilePath(relPath.string()); + indexedData_[relPathName] = {IndexedDataType::FILE, path.string(), ""}; - std::string name = path.string(); - std::transform(name.begin(), name.end(), name.begin(), ::tolower); - filesystemfiles_[name] = path; + auto filename = normalizeFilePath(path.filename().string()); + indexedData_[filename] = {IndexedDataType::FILE, path.string(), ""}; } } -FileHandle FileIndex::openFilePath(const std::string& file_path) { - auto datapath = findFilePath(file_path); - std::ifstream dfile(datapath.string(), - std::ios_base::binary | std::ios_base::ate); +const FileIndex::IndexedData *FileIndex::getIndexedDataAt(const std::string &filePath) const { + auto normPath = normalizeFilePath(filePath); + return &indexedData_.at(normPath); +} + +rwfs::path FileIndex::findFilePath(const std::string &filePath) const { + return getIndexedDataAt(filePath)->path; +} + +FileHandle FileIndex::openFileRaw(const std::string &filePath) const { + const auto *indexData = getIndexedDataAt(filePath); + std::ifstream dfile(indexData->path, std::ios::binary); if (!dfile.is_open()) { - throw std::runtime_error("Unable to open file: " + file_path); + throw std::runtime_error("Unable to open file: " + filePath); } +#if RW_DEBUG + if (indexData->type != IndexedDataType::FILE) { + RW_MESSAGE("Reading raw data from archive \"" << filePath << "\""); + } +#endif + + dfile.seekg(0, std::ios::end); auto length = dfile.tellg(); dfile.seekg(0); auto data = new char[length]; @@ -41,84 +72,57 @@ FileHandle FileIndex::openFilePath(const std::string& file_path) { return std::make_shared(data, length); } -void FileIndex::indexTree(const rwfs::path& root) { - for (const rwfs::path& path : rwfs::recursive_directory_iterator(root)) { - if (!rwfs::is_regular_file(path)) { - continue; - } - - std::string directory = path.parent_path().string(); - std::string realName = path.filename().string(); - std::string lowerName = realName; - std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), - ::tolower); - files[lowerName] = {lowerName, realName, directory, ""}; - } -} - -void FileIndex::indexArchive(const std::string& archive) { - // Split directory from archive name - auto archive_path = rwfs::path(archive); - auto directory = archive_path.parent_path(); - auto archive_basename = archive_path.filename(); - auto archive_full_path = directory / archive_basename; +void FileIndex::indexArchive(const std::string &archive) { + rwfs::path path = findFilePath(archive); LoaderIMG img; - if (!img.load(archive_full_path.string())) { - throw std::runtime_error("Failed to load IMG archive: " + - archive_full_path.string()); + if (!img.load(path.string())) { + throw std::runtime_error("Failed to load IMG archive: " + path.string()); } - std::string lowerName; for (size_t i = 0; i < img.getAssetCount(); ++i) { - auto& asset = img.getAssetInfoByIndex(i); + auto &asset = img.getAssetInfoByIndex(i); if (asset.size == 0) continue; - lowerName = asset.name; - std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), - ::tolower); + std::string assetName = normalizeFilePath(asset.name); - files[lowerName] = {lowerName, asset.name, directory.string(), - archive_basename.string()}; + indexedData_[assetName] = {IndexedDataType::ARCHIVE, path.string(), asset.name}; } } -FileHandle FileIndex::openFile(const std::string& filename) { - auto iterator = files.find(filename); - if (iterator == files.end()) { +FileHandle FileIndex::openFile(const std::string &filePath) { + auto cleanFilePath = normalizeFilePath(filePath); + auto indexedDataPos = indexedData_.find(cleanFilePath); + if (indexedDataPos == indexedData_.end()) { return nullptr; } - IndexData& f = iterator->second; - bool isArchive = !f.archive.empty(); + const auto &indexedData = indexedDataPos->second; - auto fsName = f.directory + "/" + f.originalName; - - char* data = nullptr; + char *data = nullptr; size_t length = 0; - if (isArchive) { - fsName = f.directory + "/" + f.archive; - + if (indexedData.type == IndexedDataType::ARCHIVE) { LoaderIMG img; - if (!img.load(fsName)) { - throw std::runtime_error("Failed to load IMG archive: " + fsName); + if (!img.load(indexedData.path)) { + throw std::runtime_error("Failed to load IMG archive: " + indexedData.path); } LoaderIMGFile file; - if (img.findAssetInfo(f.originalName, file)) { + auto filename = rwfs::path(indexedData.assetData).filename().string(); + if (img.findAssetInfo(filename, file)) { length = file.size * 2048; - data = img.loadToMemory(f.originalName); + data = img.loadToMemory(filename); } } else { - std::ifstream dfile(fsName.c_str(), std::ios_base::binary); + std::ifstream dfile(indexedData.path, std::ios::binary); if (!dfile.is_open()) { - throw std::runtime_error("Unable to open file: " + fsName); + throw std::runtime_error("Unable to open file: " + indexedData.path); } - dfile.seekg(0, std::ios_base::end); + dfile.seekg(0, std::ios::end); length = dfile.tellg(); dfile.seekg(0); data = new char[length]; diff --git a/rwlib/source/platform/FileIndex.hpp b/rwlib/source/platform/FileIndex.hpp index e9798aab..9770dc0d 100644 --- a/rwlib/source/platform/FileIndex.hpp +++ b/rwlib/source/platform/FileIndex.hpp @@ -1,91 +1,96 @@ #ifndef _LIBRW_FILEINDEX_HPP_ #define _LIBRW_FILEINDEX_HPP_ -#include -#include -#include -#include +#include "rw/filesystem.hpp" +#include "rw/forward.hpp" + #include -#include -#include - class FileIndex { -private: - /** - * Mapping type (lower case name) => (on disk name) - */ - using FileSystemMap = std::unordered_map; - - rwfs::path gamedatapath_; - FileSystemMap filesystemfiles_; - public: /** - * @brief indexDirectory finds the true case for each file in the tree - * @param base_path + * @brief normalizeString Normalize a file path + * @param filePath the path to normalize + * @return normalized file path + */ + static std::string normalizeFilePath(const std::string &filePath); + + /** + * @brief indexDirectory index all files at path + * @param path the path to index * * This is used to build the mapping of lower-case file paths to the * true case on the file system for platforms where this is an issue. - * */ - void indexGameDirectory(const rwfs::path& base_path); + void indexTree(const rwfs::path &path); /** * @brief findFilePath finds disk path for a game data file - * @param path + * @param filePath the path to find * @return The file path as it exists on disk + * @throws if this FileIndex has not indexed the path */ - rwfs::path findFilePath(std::string path) { - auto backslash = std::string::npos; - while ((backslash = path.find("\\")) != std::string::npos) { - path.replace(backslash, 1, "/"); - } - auto realpath = gamedatapath_ / path; - std::string name = realpath.string(); - std::transform(name.begin(), name.end(), name.begin(), ::tolower); - - return filesystemfiles_[name]; - } + rwfs::path findFilePath(const std::string &filePath) const; /** - * @brief openFilePath opens a file on the disk - * @param file_path - * @return A handle for the file on the disk + * @brief openFileRaw Opens a raw file on the disk + * @param filePath the path to open + * @return FileHandle to the file + * @throws if this FileIndex has not indexed the path */ - FileHandle openFilePath(const std::string& file_path); - - struct IndexData { - /// Lowercase identifying filename - std::string filename; - /// Original filename - std::string originalName; - /// Containing directory - std::string directory; - /// The archive filename (if applicable) - std::string archive; - }; - - /** - * Adds the files contained within the given directory tree to the - * file index. - */ - void indexTree(const rwfs::path& root); + FileHandle openFileRaw(const std::string &filePath) const; /** * Adds the files contained within the given Archive file to the * file index. + * @param filePath path to the archive + * @throws if this FileIndex has not indexed the archive itself */ - void indexArchive(const std::string& archive); + void indexArchive(const std::string &filePath); /** * Returns a FileHandle for the file if it can be found in the * file index, otherwise an empty FileHandle is returned. + * @param filePath name of the file to open + * @return FileHandle to the file, nullptr if this FileINdexed has not indexed the path */ - FileHandle openFile(const std::string& filename); + FileHandle openFile(const std::string &filePath); private: - std::map files; + /** + * @brief Type of the indexed data. + */ + enum IndexedDataType { + /// Is a file on disk + FILE, + /// Is a member of an archive + ARCHIVE, + }; + + /** + * @brief All information of indexed data. + */ + struct IndexedData { + /// Type of indexed data. + IndexedDataType type; + /// Path of indexed data. + std::string path; + /// Extra data of assets (FIXME: use c++17 std::variant or std::option) + std::string assetData; + }; + + /** + * @brief indexedData_ A mapping from filepath (relative to game data path) to an IndexedData item. + */ + std::unordered_map indexedData_; + + /** + * @brief getIndexedDataAt Get IndexedData for filePath + * @param filePath the file path to get the IndexedData for + * @return IndexedData pointer if this FileIndex has indexed the filePath + * @throws If this FileIndex has not indexed filePath + */ + const IndexedData *getIndexedDataAt(const std::string &filePath) const; }; #endif diff --git a/tests/test_FileIndex.cpp b/tests/test_FileIndex.cpp index 2c108b54..7546335d 100644 --- a/tests/test_FileIndex.cpp +++ b/tests/test_FileIndex.cpp @@ -2,23 +2,35 @@ #include #include "test_Globals.hpp" -#include -namespace fs = rwfs; - BOOST_AUTO_TEST_SUITE(FileIndexTests) -#if RW_TEST_WITH_DATA -BOOST_AUTO_TEST_CASE(test_directory_paths) { - FileIndex index; +BOOST_AUTO_TEST_CASE(test_normalizeName) { + std::string ref = "a/b/c"; + { + std::string dirty = "a\\b\\c"; + BOOST_CHECK_EQUAL(ref, FileIndex::normalizeFilePath(dirty)); + } + { + std::string dirty = "A/B/C"; + BOOST_CHECK_EQUAL(ref, FileIndex::normalizeFilePath(dirty)); + } + { + std::string dirty = "A\\B\\C"; + BOOST_CHECK_EQUAL(ref, FileIndex::normalizeFilePath(dirty)); + } +} - index.indexGameDirectory(Global::getGamePath()); +#if RW_TEST_WITH_DATA +BOOST_AUTO_TEST_CASE(test_indexTree) { + FileIndex index; + index.indexTree(Global::getGamePath()); { std::string upperpath{"DATA/CULLZONE.DAT"}; auto truepath = index.findFilePath(upperpath); BOOST_ASSERT(!truepath.empty()); BOOST_CHECK(upperpath != truepath); - fs::path expected{Global::getGamePath()}; + rwfs::path expected{Global::getGamePath()}; expected /= "data/CULLZONE.DAT"; BOOST_CHECK_EQUAL(truepath.string(), expected.string()); } @@ -27,28 +39,35 @@ BOOST_AUTO_TEST_CASE(test_directory_paths) { auto truepath = index.findFilePath(upperpath); BOOST_ASSERT(!truepath.empty()); BOOST_CHECK(upperpath != truepath); - fs::path expected{Global::getGamePath()}; + rwfs::path expected{Global::getGamePath()}; expected /= "data/maps/comnbtm/comNbtm.ipl"; BOOST_CHECK_EQUAL(truepath.string(), expected.string()); } } -BOOST_AUTO_TEST_CASE(test_file) { +BOOST_AUTO_TEST_CASE(test_openFile) { FileIndex index; - index.indexTree(Global::getGamePath() + "/data"); auto handle = index.openFile("cullzone.dat"); BOOST_CHECK(handle != nullptr); } -BOOST_AUTO_TEST_CASE(test_file_archive) { +BOOST_AUTO_TEST_CASE(test_indexArchive) { FileIndex index; + index.indexTree(Global::getGamePath()); - index.indexArchive(Global::getGamePath() + "/models/gta3.img"); + { + auto handle = index.openFile("landstal.dff"); + BOOST_CHECK(handle == nullptr); + } - auto handle = index.openFile("landstal.dff"); - BOOST_CHECK(handle != nullptr); + index.indexArchive("models/gta3.img"); + + { + auto handle = index.openFile("landstal.dff"); + BOOST_CHECK(handle != nullptr); + } } #endif diff --git a/tests/test_Text.cpp b/tests/test_Text.cpp index 3ce4237f..c69654ec 100644 --- a/tests/test_Text.cpp +++ b/tests/test_Text.cpp @@ -11,7 +11,7 @@ BOOST_AUTO_TEST_SUITE(TextTests) #if RW_TEST_WITH_DATA BOOST_AUTO_TEST_CASE(load_test) { { - auto d = Global::get().e->data->index.openFilePath("text/english.gxt"); + auto d = Global::get().e->data->index.openFileRaw("text/english.gxt"); GameTexts texts;