From 41d7c7879ddfd9630e1063f3a9d5810c811a2282 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sat, 22 Feb 2025 00:24:37 +0100 Subject: [PATCH 01/15] Clang warning fixes --- CMakeLists.txt | 13 +++--- apps/_template/main.cpp | 2 +- apps/asteroids/components/SoundEntities.h | 4 +- apps/asteroids/events/Collision.h | 2 +- apps/asteroids/events/LaserFired.h | 2 +- apps/asteroids/main.cpp | 2 +- apps/asteroids/systems/Asteroids.h | 8 ++-- apps/asteroids/systems/Background.cpp | 4 +- apps/asteroids/systems/Background.h | 2 +- apps/asteroids/systems/Collisions.hpp | 2 +- apps/asteroids/systems/DynamicsSystem.hpp | 2 +- apps/asteroids/systems/Lasers.h | 3 +- apps/asteroids/systems/Player.h | 2 +- apps/asteroids/systems/RenderSystem.hpp | 2 +- apps/asteroids/systems/ScriptSystem.hpp | 4 +- apps/asteroids/systems/SoundSystem.hpp | 3 +- apps/galaxy/behaviors/MakeDrone.hpp | 6 ++- apps/galaxy/behaviors/utils/Context.hpp | 2 +- apps/galaxy/behaviors/utils/PortInjection.hpp | 6 +-- apps/galaxy/components/Faction.hpp | 2 +- apps/galaxy/components/StarSystem.hpp | 8 ++-- apps/galaxy/events/DroneEvents.hpp | 2 +- apps/galaxy/events/UIEvents.hpp | 2 +- apps/galaxy/gui/MainMenuWidget.hpp | 2 +- apps/galaxy/gui/menus/OptionsMenu.hpp | 2 +- apps/galaxy/systems/DroneSystem.cpp | 12 ++--- apps/galaxy/systems/DroneSystem.hpp | 2 +- .../productionSandbox/ProductionLine.hpp | 8 ++-- .../resourceLoaderSandbox/CMakeLists.txt | 2 +- apps/sandboxes/resourceLoaderSandbox/main.cpp | 23 +++++----- cmake/deps_cpm.cmake | 12 ++--- cmake/deps_cpm_sdl.cmake | 1 + libs/pgEngine/core/App.hpp | 2 +- libs/pgEngine/core/AppConfig.hpp | 2 +- libs/pgEngine/core/FrameStamp.hpp | 6 +-- libs/pgEngine/core/Gui.hpp | 2 +- libs/pgEngine/core/State.hpp | 40 ++++++++--------- libs/pgEngine/factories/Factories.cpp | 5 ++- libs/pgEngine/factories/Factories.hpp | 12 ++--- libs/pgEngine/font/Font.hpp | 2 +- libs/pgEngine/gui/GuiElements.hpp | 2 +- libs/pgEngine/gui/ImGuiScopedWrappers.hpp | 4 +- libs/pgEngine/math/Bounds.hpp | 2 +- libs/pgEngine/math/BoundsOperations.hpp | 2 +- libs/pgEngine/math/Box.hpp | 2 +- libs/pgEngine/math/ComputationalGeometry.hpp | 4 +- libs/pgEngine/math/QuadtreeVisitor.hpp | 2 +- libs/pgEngine/math/Random.hpp | 2 +- libs/pgEngine/math/Transform.hpp | 2 +- libs/pgEngine/math/VecUtils.hpp | 2 +- libs/pgEngine/primitives/BackgoundSprite.hpp | 2 +- libs/pgEngine/primitives/FramedSprite.hpp | 8 ++-- libs/pgEngine/primitives/Renderable.hpp | 36 +++++++++------ libs/pgEngine/primitives/Sprite.cpp | 2 +- libs/pgEngine/primitives/Sprite.hpp | 2 +- libs/pgEngine/scripting/PythonScripter.hpp | 2 +- libs/pgFoundation/Lifetime.hpp | 6 +-- libs/pgFoundation/MemStream.hpp | 7 ++- libs/pgFoundation/NamedTypeRegistrar.hpp | 2 +- libs/pgFoundation/NamedTypeRegistry.hpp | 2 +- libs/pgFoundation/VirtualFS.hpp | 11 +++++ libs/pgFoundation/imgui/Spinner.hpp | 6 +-- libs/pgGame/CMakeLists.txt | 2 +- libs/pgGame/components/Drawable.hpp | 2 +- libs/pgGame/components/GameState.hpp | 2 +- libs/pgGame/components/WindowDetails.hpp | 2 +- libs/pgGame/config/GameConfig.hpp | 2 +- libs/pgGame/config/GenericConfig.hpp | 2 +- libs/pgGame/core/Game.cpp | 20 ++++----- libs/pgGame/core/Game.hpp | 17 +++---- libs/pgGame/core/GameExceptions.hpp | 2 +- libs/pgGame/core/InputEventDispatcher.hpp | 2 +- libs/pgGame/core/KeyStateMap.hpp | 12 ++--- libs/pgGame/core/RegistryHelper.hpp | 2 +- libs/pgGame/core/Scene.hpp | 13 +++--- libs/pgGame/core/SingletonInterface.hpp | 2 +- libs/pgGame/core/VFSDataProvider.cpp | 45 ++++++++++--------- libs/pgGame/core/VFSDataProvider.hpp | 30 ++++++------- libs/pgGame/events/GameEvents.hpp | 2 +- libs/pgGame/systems/SystemsRegistry.hpp | 2 +- libs/pgOrbit/Constants.hpp | 2 +- libs/pgOrbit/FloatingPointType.hpp | 2 +- libs/pgOrbit/OrbitCreator.hpp | 2 +- libs/pgOrbit/OrbitalParameters.hpp | 2 +- libs/pgOrbit/StarParameters.hpp | 18 ++++---- 85 files changed, 276 insertions(+), 241 deletions(-) create mode 100644 libs/pgFoundation/VirtualFS.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f62ea18..61745a89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,14 +3,17 @@ project(2dPlayground) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED True) - +#some global compiler settings +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + add_compile_options(/W4 /WX) + add_compile_options(/bigobj) +else() + #add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-c++98-compat -Wno-c++98-compat-pedantic) + add_compile_options(-Wall -Wno-c++98-compat -Wno-c++98-compat-pedantic) +endif() #options option(ENABLE_COVERAGE "Enable coverage" OFF) option(ENABLE_SANDBOXES "Enable sandbox projects" OFF) -#bigobj -if (MSVC) - add_compile_options(/bigobj) -endif() #add cmake script to download conan-cmake integrations #include(cmake/conan_config.cmake) diff --git a/apps/_template/main.cpp b/apps/_template/main.cpp index 4fed4e7c..e2a0960b 100644 --- a/apps/_template/main.cpp +++ b/apps/_template/main.cpp @@ -61,4 +61,4 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { textdemo_main(); return 0; -} \ No newline at end of file +} diff --git a/apps/asteroids/components/SoundEntities.h b/apps/asteroids/components/SoundEntities.h index b77d97ba..62984be5 100644 --- a/apps/asteroids/components/SoundEntities.h +++ b/apps/asteroids/components/SoundEntities.h @@ -4,8 +4,8 @@ namespace asteroids { // struct Sound { - std::string identifier; //< usually the path or some resource identifier - float gain{1.0f}; //< range 0.0f to 1.0f + std::string identifier; ///< usually the path or some resource identifier + float gain{1.0f}; ///< range 0.0f to 1.0f float pitch{1.0f}; bool loop{false}; } // namespace asteroids \ No newline at end of file diff --git a/apps/asteroids/events/Collision.h b/apps/asteroids/events/Collision.h index 362fef47..7ded9faf 100644 --- a/apps/asteroids/events/Collision.h +++ b/apps/asteroids/events/Collision.h @@ -15,4 +15,4 @@ struct Collision : public pgf::TypeRegistrar entt::entity c1; entt::entity c2; }; -}} // namespace asteroids::events \ No newline at end of file +}} // namespace asteroids::events diff --git a/apps/asteroids/events/LaserFired.h b/apps/asteroids/events/LaserFired.h index 12b515e9..e179d3fa 100644 --- a/apps/asteroids/events/LaserFired.h +++ b/apps/asteroids/events/LaserFired.h @@ -11,4 +11,4 @@ struct LaserFired : pgf::TypeRegistrar pg::fVec2 offset; entt::entity shooter; }; -}} // namespace asteroids::events \ No newline at end of file +}} // namespace asteroids::events diff --git a/apps/asteroids/main.cpp b/apps/asteroids/main.cpp index a28af207..8da0eda9 100644 --- a/apps/asteroids/main.cpp +++ b/apps/asteroids/main.cpp @@ -66,4 +66,4 @@ catch (...) std::print("Unhandled exception\n"); errorTrace::printErrorTrace(); return -1; -} \ No newline at end of file +} diff --git a/apps/asteroids/systems/Asteroids.h b/apps/asteroids/systems/Asteroids.h index 567358ad..07895fe9 100644 --- a/apps/asteroids/systems/Asteroids.h +++ b/apps/asteroids/systems/Asteroids.h @@ -43,9 +43,9 @@ class Asteroids : public pg::game::SystemInterface /** * @brief Creates an asteroid entity in the game. * - * @param position The initial position of the asteroid. - * @param velocity The initial velocity of the asteroid. - * @param size The size of the asteroid. This affects the sprite used, as well as the hitpoints and damage of the + * /param position The initial position of the asteroid. + * /param velocity The initial velocity of the asteroid. + * /param size The size of the asteroid. This affects the sprite used, as well as the hitpoints and damage of the * asteroid. */ void createAsteroid(const pg::fVec2& position, const pg::fVec2& velocity, Size size); @@ -60,4 +60,4 @@ class Asteroids : public pg::game::SystemInterface std::deque collisions; }; -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/Background.cpp b/apps/asteroids/systems/Background.cpp index 0c404312..8c74cc24 100644 --- a/apps/asteroids/systems/Background.cpp +++ b/apps/asteroids/systems/Background.cpp @@ -9,7 +9,7 @@ void asteroids::Background::handle(const pg::FrameStamp&) { // TODO: base scrolling speed on the player's velocity - auto view = _game.getGlobalRegistry().view(); + // auto view = _game.getGlobalRegistry().view(); } void asteroids::Background::setup(std::string_view /*scene_id*/) @@ -18,9 +18,7 @@ void asteroids::Background::setup(std::string_view /*scene_id*/) auto background = registry.create(); auto backgroundImg = pg::SpriteFactory::makeSprite(_game.getApp().getRenderer(), "../data/spr_stars01.png"); - auto windowDetails = _game.getCurrentScene().getSingleton(); // TODO add entities as references to the classes - auto backgroundRect = pg::iVec2{windowDetails.windowRect.w, windowDetails.windowRect.h}; registry.emplace(background, std::make_unique(std::move(backgroundImg))); registry.emplace(background); diff --git a/apps/asteroids/systems/Background.h b/apps/asteroids/systems/Background.h index 92e74f58..28aabf31 100644 --- a/apps/asteroids/systems/Background.h +++ b/apps/asteroids/systems/Background.h @@ -18,4 +18,4 @@ class Background : public pg::game::SystemInterface void handle(const pg::FrameStamp& frameStamp); }; -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/Collisions.hpp b/apps/asteroids/systems/Collisions.hpp index 72007c1b..581faf14 100644 --- a/apps/asteroids/systems/Collisions.hpp +++ b/apps/asteroids/systems/Collisions.hpp @@ -18,4 +18,4 @@ class Collisions : public pg::game::SystemInterface void handleCollision(entt::entity id1, entt::entity id2, float intrusion); }; -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/DynamicsSystem.hpp b/apps/asteroids/systems/DynamicsSystem.hpp index 2102a995..3b278530 100644 --- a/apps/asteroids/systems/DynamicsSystem.hpp +++ b/apps/asteroids/systems/DynamicsSystem.hpp @@ -9,4 +9,4 @@ class DynamicsSystem : public pg::game::SystemInterface void setup(std::string_view scene_id) override; void handle(const pg::FrameStamp& frameStamp) override; }; -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/Lasers.h b/apps/asteroids/systems/Lasers.h index f84ed331..33d492f1 100644 --- a/apps/asteroids/systems/Lasers.h +++ b/apps/asteroids/systems/Lasers.h @@ -22,5 +22,4 @@ class Lasers : public pg::game::SystemInterface private: std::vector queued; }; - -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/Player.h b/apps/asteroids/systems/Player.h index e32099f7..7a68e729 100644 --- a/apps/asteroids/systems/Player.h +++ b/apps/asteroids/systems/Player.h @@ -19,4 +19,4 @@ class Player : public pg::game::SystemInterface void handle(const pg::FrameStamp& frameStamp); }; -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/RenderSystem.hpp b/apps/asteroids/systems/RenderSystem.hpp index f781c9e0..9fb94e1f 100644 --- a/apps/asteroids/systems/RenderSystem.hpp +++ b/apps/asteroids/systems/RenderSystem.hpp @@ -18,4 +18,4 @@ class RenderSystem : public pg::game::SystemInterface void handle(const pg::FrameStamp& frameStamp); }; -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/asteroids/systems/ScriptSystem.hpp b/apps/asteroids/systems/ScriptSystem.hpp index 7b0e2d1b..3d6409f9 100644 --- a/apps/asteroids/systems/ScriptSystem.hpp +++ b/apps/asteroids/systems/ScriptSystem.hpp @@ -14,14 +14,14 @@ class ScriptSystem : public pg::game::SystemInterface virtual ~ScriptSystem() = default; - void setup(std::string_view scene_id) override + void setup(std::string_view /*scene_id*/) override { _scripter = std::make_unique( pg::scripting::PythonScripter::scriptFromFile("../data/scripts/test.py")); _scripter->addModule("mymodule"); } - void handle(const pg::FrameStamp& frameStamp) override { _scripter->run(); } + void handle(const pg::FrameStamp& /*frameStamp*/) override { _scripter->run(); } private: std::unique_ptr _scripter; diff --git a/apps/asteroids/systems/SoundSystem.hpp b/apps/asteroids/systems/SoundSystem.hpp index d2ce0485..d1457138 100644 --- a/apps/asteroids/systems/SoundSystem.hpp +++ b/apps/asteroids/systems/SoundSystem.hpp @@ -32,5 +32,4 @@ class SoundSystem : public pg::game::SystemInterface std::unique_ptr _soundEngine; std::unique_ptr _bgPlayer; }; - -} // namespace asteroids \ No newline at end of file +} // namespace asteroids diff --git a/apps/galaxy/behaviors/MakeDrone.hpp b/apps/galaxy/behaviors/MakeDrone.hpp index 678394f2..a0b008d7 100644 --- a/apps/galaxy/behaviors/MakeDrone.hpp +++ b/apps/galaxy/behaviors/MakeDrone.hpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include namespace behavior { @@ -72,8 +74,8 @@ class MakeDrone : public BehaviorActionNode pg::game::addComponent( game.getGlobalRegistry(), entity, galaxy::Behavior{std::move(behavior_tree), {}}); - - game.getDispatcher().trigger({.entity = entity, .transform = transform.pos}); + game.getDispatcher().trigger( + galaxy::events::DroneCreatedEvent{.entity = entity, .faction = faction, .transform = transform.pos}); return BT::NodeStatus::SUCCESS; } diff --git a/apps/galaxy/behaviors/utils/Context.hpp b/apps/galaxy/behaviors/utils/Context.hpp index 3d04cb02..c5e48db3 100644 --- a/apps/galaxy/behaviors/utils/Context.hpp +++ b/apps/galaxy/behaviors/utils/Context.hpp @@ -21,4 +21,4 @@ struct Context }; using ContextPtr = std::shared_ptr; -} // namespace behavior \ No newline at end of file +} // namespace behavior diff --git a/apps/galaxy/behaviors/utils/PortInjection.hpp b/apps/galaxy/behaviors/utils/PortInjection.hpp index 95350fa8..2cf7eaf3 100644 --- a/apps/galaxy/behaviors/utils/PortInjection.hpp +++ b/apps/galaxy/behaviors/utils/PortInjection.hpp @@ -48,11 +48,11 @@ class PortInjector { for (const auto& port : forcedInput) { - if (!config.input_ports.contains(port)) { config.input_ports.insert({port, ""}); }; + if (!config.input_ports.contains(port)) { config.input_ports.insert({port, ""}); } } for (const auto& port : forcedOutput) { - if (!config.output_ports.contains(port)) { config.output_ports.insert({port, ""}); }; + if (!config.output_ports.contains(port)) { config.output_ports.insert({port, ""}); } } } @@ -64,4 +64,4 @@ class PortInjector std::unordered_set forcedOutput; }; -} // namespace behavior \ No newline at end of file +} // namespace behavior diff --git a/apps/galaxy/components/Faction.hpp b/apps/galaxy/components/Faction.hpp index 93b15212..fff08967 100644 --- a/apps/galaxy/components/Faction.hpp +++ b/apps/galaxy/components/Faction.hpp @@ -6,4 +6,4 @@ struct Faction { std::string name; }; -} // namespace galaxy \ No newline at end of file +} // namespace galaxy diff --git a/apps/galaxy/components/StarSystem.hpp b/apps/galaxy/components/StarSystem.hpp index 2911a975..3fbe36f7 100644 --- a/apps/galaxy/components/StarSystem.hpp +++ b/apps/galaxy/components/StarSystem.hpp @@ -9,10 +9,10 @@ namespace galaxy { enum class ColonizationStatus { - Unexplored, //< No one has been here yet - Planned, //< A probe has been sent to this system - Explored, //< A probe has been here and sent back data - Colonized, //< A probe has established production facilities and started building more probes + Unexplored, ///< No one has been here yet + Planned, ///< A probe has been sent to this system + Explored, ///< A probe has been here and sent back data + Colonized, ///< A probe has established production facilities and started building more probes }; struct StarSystemState diff --git a/apps/galaxy/events/DroneEvents.hpp b/apps/galaxy/events/DroneEvents.hpp index 02530395..be60a063 100644 --- a/apps/galaxy/events/DroneEvents.hpp +++ b/apps/galaxy/events/DroneEvents.hpp @@ -38,4 +38,4 @@ struct DroneDestroyedEvent : pgf::TypeRegistrarget(), + ImGui::Image(reinterpret_cast(_dot_texture.get()->get()), ImVec2(static_cast(size_x), static_cast(size_y))); // TODO: style from config pgf::gui::StyleStack stack; diff --git a/apps/galaxy/gui/menus/OptionsMenu.hpp b/apps/galaxy/gui/menus/OptionsMenu.hpp index 8645c065..b691f6b0 100644 --- a/apps/galaxy/gui/menus/OptionsMenu.hpp +++ b/apps/galaxy/gui/menus/OptionsMenu.hpp @@ -293,4 +293,4 @@ static bool optionsMenu(galaxy::config::Galaxy& galaxy_config, return save; } -} // namespace galaxy::gui \ No newline at end of file +} // namespace galaxy::gui diff --git a/apps/galaxy/systems/DroneSystem.cpp b/apps/galaxy/systems/DroneSystem.cpp index 542072c2..38c40ddf 100644 --- a/apps/galaxy/systems/DroneSystem.cpp +++ b/apps/galaxy/systems/DroneSystem.cpp @@ -108,12 +108,12 @@ void galaxy::DroneSystem::createFactions(const pg::FrameStamp& frameStamp) system_faction.name = faction.name; starsystem.colonizationStatus = galaxy::ColonizationStatus::Colonized; // event - _game.getDispatcher().enqueue({ - .system_entity = starsystem_entity, - .owner_faction = faction.name, - .status = ColonizationStatus::Colonized, - .old_status = ColonizationStatus::Unexplored, - }); + _game.getDispatcher().enqueue( + {.system_entity = starsystem_entity, + .owner_faction = faction.name, + .status = ColonizationStatus::Colonized, + .old_status = ColonizationStatus::Unexplored, + .previous_owner = ""}); // setup port connections // defaults diff --git a/apps/galaxy/systems/DroneSystem.hpp b/apps/galaxy/systems/DroneSystem.hpp index b5e1834d..a426a91e 100644 --- a/apps/galaxy/systems/DroneSystem.hpp +++ b/apps/galaxy/systems/DroneSystem.hpp @@ -23,4 +23,4 @@ class DroneSystem : public pg::game::SystemInterface behavior::ContextPtr ctx{}; }; -} // namespace galaxy \ No newline at end of file +} // namespace galaxy diff --git a/apps/sandboxes/productionSandbox/ProductionLine.hpp b/apps/sandboxes/productionSandbox/ProductionLine.hpp index 39b536e0..384ca52d 100644 --- a/apps/sandboxes/productionSandbox/ProductionLine.hpp +++ b/apps/sandboxes/productionSandbox/ProductionLine.hpp @@ -18,10 +18,10 @@ class ProductionLine public: enum class State { - EMPTY_QUEUE, //< currently no items in queue - WAITING_FOR_RESOURCES, //< currently produced item waits for resources - FINISHED, //< item production finished - RUNNING, //< currently producing + EMPTY_QUEUE, ///< currently no items in queue + WAITING_FOR_RESOURCES, ///< currently produced item waits for resources + FINISHED, ///< item production finished + RUNNING, ///< currently producing }; ProductionLine(Storage& input_storage, Storage& output_storage, float capacity = 1.0) diff --git a/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt b/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt index c6ededad..cecc18ec 100644 --- a/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt +++ b/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt @@ -11,7 +11,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC pgEngine::pgEngine pgGame::pgGame - vfspp + #vfspp ) if (ENABLE_COVERAGE) diff --git a/apps/sandboxes/resourceLoaderSandbox/main.cpp b/apps/sandboxes/resourceLoaderSandbox/main.cpp index a5aac717..87f83fd1 100644 --- a/apps/sandboxes/resourceLoaderSandbox/main.cpp +++ b/apps/sandboxes/resourceLoaderSandbox/main.cpp @@ -26,17 +26,18 @@ class memstream : public std::istream int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) try { - auto rootFS = std::make_unique(R"(..\data\music\cylinders\Chris Zabriskie - Cylinders.zip)"); - rootFS->Initialize(); - - auto vfs = std::make_unique(); - vfs->AddFileSystem("/music", std::move(rootFS)); - - auto f = - vfs->OpenFile({"/music/Chris Zabriskie - Cylinders - 01 Cylinder One.mp3"}, {vfspp::IFile::FileMode::Read}); - // soundEngineX::loader::load() - auto buffer = std::vector(f->Size()); - f->Read(buffer, buffer.size()); + // auto rootFS = std::make_unique(R"(..\data\music\cylinders\Chris Zabriskie - + // Cylinders.zip)"); rootFS->Initialize(); + // + // auto vfs = std::make_unique(); + // vfs->AddFileSystem("/music", std::move(rootFS)); + // + // auto f = + // vfs->OpenFile({"/music/Chris Zabriskie - Cylinders - 01 Cylinder One.mp3"}, + // {vfspp::IFile::FileMode::Read}); + // // soundEngineX::loader::load() + // auto buffer = std::vector(f->Size()); + // f->Read(buffer, buffer.size()); } catch (const std::exception& e) diff --git a/cmake/deps_cpm.cmake b/cmake/deps_cpm.cmake index 73d6dd42..da4d0f36 100644 --- a/cmake/deps_cpm.cmake +++ b/cmake/deps_cpm.cmake @@ -140,7 +140,7 @@ CPMAddPackage( NAME spdlog GITHUB_REPOSITORY gabime/spdlog - GIT_TAG v1.13.0 + GIT_TAG v1.15.1 OPTIONS "SPDLOG_BUILD_EXAMPLES OFF" "SPDLOG_BUILD_TESTS OFF" @@ -184,11 +184,11 @@ set_target_properties(imgui PROPERTIES FOLDER third-party) # optoinal IDE dir #alias add_library(imgui::imgui ALIAS imgui) #endif() -CPMAddPackage( - NAME vfspp - GITHUB_REPOSITORY nextgeniuspro/vfspp - GIT_TAG v2.0.0 -) +#CPMAddPackage( +# NAME vfspp +# GITHUB_REPOSITORY nextgeniuspro/vfspp +# GIT_TAG v2.0.0 +#) if(SCRIPTING) CPMAddPackage( diff --git a/cmake/deps_cpm_sdl.cmake b/cmake/deps_cpm_sdl.cmake index b2148d0a..b4a16cc2 100644 --- a/cmake/deps_cpm_sdl.cmake +++ b/cmake/deps_cpm_sdl.cmake @@ -9,6 +9,7 @@ CPMAddPackage( NAME SDL2 GITHUB_REPOSITORY libsdl-org/SDL GIT_TAG release-2.26.2 + SYSTEM OPTIONS "SDL2_DISABLE_INSTALL ON" "SDL_SHARED OFF" diff --git a/libs/pgEngine/core/App.hpp b/libs/pgEngine/core/App.hpp index 72940cc1..20929cf1 100644 --- a/libs/pgEngine/core/App.hpp +++ b/libs/pgEngine/core/App.hpp @@ -53,4 +53,4 @@ class SDLApp sdl::EventHandler eventHandler; FPSCounter fpsCounter; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/core/AppConfig.hpp b/libs/pgEngine/core/AppConfig.hpp index 26dad5fd..b2d768da 100644 --- a/libs/pgEngine/core/AppConfig.hpp +++ b/libs/pgEngine/core/AppConfig.hpp @@ -13,4 +13,4 @@ struct WindowConfig std::string windowName{"GameWindow"}; }; -} // namespace pg::config \ No newline at end of file +} // namespace pg::config diff --git a/libs/pgEngine/core/FrameStamp.hpp b/libs/pgEngine/core/FrameStamp.hpp index 6a594fea..b8c2580c 100644 --- a/libs/pgEngine/core/FrameStamp.hpp +++ b/libs/pgEngine/core/FrameStamp.hpp @@ -56,8 +56,8 @@ struct FrameStamp std::chrono::duration_cast(std::chrono::years(1)).count(); auto days = std::chrono::duration_cast(secs) % std::chrono::duration_cast(std::chrono::months(1)).count(); - auto hours = std::chrono::duration_cast(secs) % - std::chrono::duration_cast(std::chrono::days(1)).count(); + // auto hours = std::chrono::duration_cast(secs) % + // std::chrono::duration_cast(std::chrono::days(1)).count(); return std::format("{}y.{:02}m.{:02}d.{:05}s", years.count(), months.count(), @@ -66,4 +66,4 @@ struct FrameStamp std::chrono::duration_cast(std::chrono::days(1)).count()); } }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/core/Gui.hpp b/libs/pgEngine/core/Gui.hpp index f9bc49cb..5ef5d4d3 100644 --- a/libs/pgEngine/core/Gui.hpp +++ b/libs/pgEngine/core/Gui.hpp @@ -25,4 +25,4 @@ class Gui pg::SDLApp& app; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/core/State.hpp b/libs/pgEngine/core/State.hpp index a7e84709..0612068b 100644 --- a/libs/pgEngine/core/State.hpp +++ b/libs/pgEngine/core/State.hpp @@ -24,21 +24,21 @@ class BlendModeState : public RendererState { public: BlendModeState(SDL_BlendMode blendMode) - : blendMode(blendMode) + : _blendMode(blendMode) { } void apply(sdl::Renderer& renderer) override { - renderer.getDrawBlendMode(&prevBlendMode); - renderer.setDrawBlendMode(blendMode); + renderer.getDrawBlendMode(&_prevBlendMode); + renderer.setDrawBlendMode(_blendMode); } - void restore(sdl::Renderer& renderer) override { renderer.setDrawBlendMode(prevBlendMode); } + void restore(sdl::Renderer& renderer) override { renderer.setDrawBlendMode(_prevBlendMode); } private: - SDL_BlendMode prevBlendMode; - const SDL_BlendMode blendMode; + SDL_BlendMode _prevBlendMode{}; + const SDL_BlendMode _blendMode; }; class ColorState : public RendererState @@ -73,45 +73,45 @@ class TextureColorState : public TextureState { public: TextureColorState(const Color& color) - : color(color) + : _color(color) { } void apply(sdl::Renderer&, sdl::Texture& texture) override { - texture.getColorMod(&prevColor[0], &prevColor[1], &prevColor[2]); - texture.setColorMod(color[0], color[1], color[2]); + texture.getColorMod(&_prevColor[0], &_prevColor[1], &_prevColor[2]); + texture.setColorMod(_color[0], _color[1], _color[2]); } void restore(sdl::Renderer&, sdl::Texture& texture) override { - texture.setColorMod(prevColor[0], prevColor[1], prevColor[2]); + texture.setColorMod(_prevColor[0], _prevColor[1], _prevColor[2]); } private: - Color prevColor; - const Color color; + Color _prevColor; + const Color _color; }; class TextureBlendModeState : public TextureState { public: TextureBlendModeState(SDL_BlendMode blendMode) - : blendMode(blendMode) + : _blendMode(blendMode) { } void apply(sdl::Renderer&, sdl::Texture& texture) override { - texture.getBlendMode(&storeBlendMode); - texture.setBlendMode(blendMode); + texture.getBlendMode(&_storeBlendMode); + texture.setBlendMode(_blendMode); } - void restore(sdl::Renderer&, sdl::Texture& texture) override { texture.setBlendMode(storeBlendMode); } + void restore(sdl::Renderer&, sdl::Texture& texture) override { texture.setBlendMode(_storeBlendMode); } private: - SDL_BlendMode storeBlendMode; - const SDL_BlendMode blendMode; + SDL_BlendMode _storeBlendMode; + const SDL_BlendMode _blendMode; }; class TextureAlphaState : public TextureState @@ -150,7 +150,7 @@ class RendererDelegegateState : public RendererState { } - void apply(sdl::Renderer& renderer) override { storeFunc(renderer, storedState); }; + void apply(sdl::Renderer& renderer) override { storeFunc(renderer, storedState); } void restore(sdl::Renderer& renderer) override { restoreFunc(renderer, storedState); } @@ -160,4 +160,4 @@ class RendererDelegegateState : public RendererState std::any storedState; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/factories/Factories.cpp b/libs/pgEngine/factories/Factories.cpp index a8d496fd..df811356 100644 --- a/libs/pgEngine/factories/Factories.cpp +++ b/libs/pgEngine/factories/Factories.cpp @@ -17,8 +17,9 @@ auto pg::SpriteFactory::loadFromFile(const std::string& path) -> SDL_Surface* auto pg::SpriteFactory::loadFromBuffer(const std::vector& buffer) -> SDL_Surface* { std::lock_guard lock(_loaderMutex); - SDL_RWops* rw = SDL_RWFromMem((void*)buffer.data(), static_cast(buffer.size())); - auto img = IMG_Load_RW(rw, 1); + SDL_RWops* rw = + SDL_RWFromMem(reinterpret_cast(const_cast(buffer.data())), static_cast(buffer.size())); + auto img = IMG_Load_RW(rw, 1); return img; } diff --git a/libs/pgEngine/factories/Factories.hpp b/libs/pgEngine/factories/Factories.hpp index 9581350e..43e72507 100644 --- a/libs/pgEngine/factories/Factories.hpp +++ b/libs/pgEngine/factories/Factories.hpp @@ -27,12 +27,12 @@ class SpriteFactory static Sprite makeTextSprite(sdl::Renderer& renderer, SDLFont& font, std::string_view text); /** - * @brief - * @param renderer - * @param width num of horizontal frames - * @param height num of vertical frames - * @param resource_name - * @return + * /brief + * /param renderer + * /param width num of horizontal frames + * /param height num of vertical frames + * /param resource_name + * /return */ static FramedSprite makeFramedSprite( sdl::Renderer& renderer, diff --git a/libs/pgEngine/font/Font.hpp b/libs/pgEngine/font/Font.hpp index 3d8eb5a1..0b0f009f 100644 --- a/libs/pgEngine/font/Font.hpp +++ b/libs/pgEngine/font/Font.hpp @@ -18,4 +18,4 @@ class SDLFont private: TTF_Font* font{}; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/gui/GuiElements.hpp b/libs/pgEngine/gui/GuiElements.hpp index bd393d21..2d5560ae 100644 --- a/libs/pgEngine/gui/GuiElements.hpp +++ b/libs/pgEngine/gui/GuiElements.hpp @@ -122,4 +122,4 @@ static ImVec2 enforceMinimumSize(int& size_x, int& size_y, int min_x, int min_y) return ImVec2((window_size.x - size_x) / 2, (window_size.y - size_y) / 2); } -} // namespace pg::gui \ No newline at end of file +} // namespace pg::gui diff --git a/libs/pgEngine/gui/ImGuiScopedWrappers.hpp b/libs/pgEngine/gui/ImGuiScopedWrappers.hpp index c7ab1826..3b5c2e3c 100644 --- a/libs/pgEngine/gui/ImGuiScopedWrappers.hpp +++ b/libs/pgEngine/gui/ImGuiScopedWrappers.hpp @@ -85,5 +85,5 @@ using PopUpModal = ScopedBeginEnd,*/ ParameterInstance>; -using PushItemWidth = VoidScopedBeginEnd>; -} // namespace pgf::gui \ No newline at end of file +using PushItemWidth = VoidScopedBeginEnd>; +} // namespace pgf::gui diff --git a/libs/pgEngine/math/Bounds.hpp b/libs/pgEngine/math/Bounds.hpp index 068887d3..daa53a56 100644 --- a/libs/pgEngine/math/Bounds.hpp +++ b/libs/pgEngine/math/Bounds.hpp @@ -13,4 +13,4 @@ struct BoundingSphere float radius; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/math/BoundsOperations.hpp b/libs/pgEngine/math/BoundsOperations.hpp index 0fd56f6c..9f2de1a5 100644 --- a/libs/pgEngine/math/BoundsOperations.hpp +++ b/libs/pgEngine/math/BoundsOperations.hpp @@ -19,4 +19,4 @@ static auto intersects(const BoundingSphere sphere1, return intrusion < 0.0f ? std::optional{intrusion} : std::nullopt; } -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/math/Box.hpp b/libs/pgEngine/math/Box.hpp index 80a19b80..58c9b3fc 100644 --- a/libs/pgEngine/math/Box.hpp +++ b/libs/pgEngine/math/Box.hpp @@ -70,4 +70,4 @@ class Box }; using fBox = Box; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/math/ComputationalGeometry.hpp b/libs/pgEngine/math/ComputationalGeometry.hpp index 107fba29..0dba5abd 100644 --- a/libs/pgEngine/math/ComputationalGeometry.hpp +++ b/libs/pgEngine/math/ComputationalGeometry.hpp @@ -128,8 +128,8 @@ std::vector convexHull(const std::vector& points) /** * @brief merge consecutive co-linear points - * @param points A vector of points, asserted to be in order - * @param pg::dotError allowed error in the pg::dot-product + * /param points A vector of points, asserted to be in order + * /param pg::dotError allowed error in the pg::dot-product * @todo this is not working as intended, as it removes too many points at to steep angles * @return */ diff --git a/libs/pgEngine/math/QuadtreeVisitor.hpp b/libs/pgEngine/math/QuadtreeVisitor.hpp index ebec0ea9..f3ee126e 100644 --- a/libs/pgEngine/math/QuadtreeVisitor.hpp +++ b/libs/pgEngine/math/QuadtreeVisitor.hpp @@ -42,7 +42,7 @@ class CollectChildrenVisitor : public CellVisitor CellVisitor::traverse(c); } - virtual void done(T& c) {} + virtual void done(T& /*c*/) {} ResultVector results; }; diff --git a/libs/pgEngine/math/Random.hpp b/libs/pgEngine/math/Random.hpp index 51d8d366..de5f195c 100644 --- a/libs/pgEngine/math/Random.hpp +++ b/libs/pgEngine/math/Random.hpp @@ -58,4 +58,4 @@ inline T randomBetween(T min, T max, const SeedGenerator& gen = SeedGenerator()) // static_cast(b * radius * std::sin(2.0f * std::numbers::pi * a / b))}; // } -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/math/Transform.hpp b/libs/pgEngine/math/Transform.hpp index 00ab35d9..52c11a29 100644 --- a/libs/pgEngine/math/Transform.hpp +++ b/libs/pgEngine/math/Transform.hpp @@ -31,4 +31,4 @@ struct GenTransform2D using Transform2D = GenTransform2D; using PrecTransform2D = GenTransform2D; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/math/VecUtils.hpp b/libs/pgEngine/math/VecUtils.hpp index 9cbb50a6..4a9b5194 100644 --- a/libs/pgEngine/math/VecUtils.hpp +++ b/libs/pgEngine/math/VecUtils.hpp @@ -51,4 +51,4 @@ inline std::vector splitVector(const pg::fVec2& original, int numFrag return fragments; } -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/primitives/BackgoundSprite.hpp b/libs/pgEngine/primitives/BackgoundSprite.hpp index 4193246f..2e9d2f76 100644 --- a/libs/pgEngine/primitives/BackgoundSprite.hpp +++ b/libs/pgEngine/primitives/BackgoundSprite.hpp @@ -39,4 +39,4 @@ class ScrollingSprite : public Sprite } }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/primitives/FramedSprite.hpp b/libs/pgEngine/primitives/FramedSprite.hpp index 4663af61..e7c02798 100644 --- a/libs/pgEngine/primitives/FramedSprite.hpp +++ b/libs/pgEngine/primitives/FramedSprite.hpp @@ -37,8 +37,10 @@ class FramedSprite : public pg::Sprite SDL_FRect dest_rect = {calcPos[0], calcPos[1], (dims[0] * t.scale[0] / width), (dims[1] * t.scale[1] / height)}; int x = _currentFrame % width; int y = _currentFrame / width; - SDL_Rect src_rect = { - x * (int)fdimensions[0], y * (int)fdimensions[1], (dims[0] / width) + width, (dims[1] / height)}; + SDL_Rect src_rect = {x * static_cast(fdimensions[0]), + y * static_cast(fdimensions[1]), + (dims[0] / width) + width, + (dims[1] / height)}; states.apply(r.renderer); states.apply(r.renderer, tex); @@ -56,4 +58,4 @@ class FramedSprite : public pg::Sprite uint16_t height; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/primitives/Renderable.hpp b/libs/pgEngine/primitives/Renderable.hpp index dfcdc150..06f18678 100644 --- a/libs/pgEngine/primitives/Renderable.hpp +++ b/libs/pgEngine/primitives/Renderable.hpp @@ -60,7 +60,7 @@ class Renderer void clear() { renderer.clear(); } - void present() { renderer.present(); }; + void present() { renderer.present(); } void apply(States& states) { states.apply(renderer); } @@ -70,6 +70,12 @@ class Renderer class Renderable { public: + Renderable() = default; + Renderable(Renderable&&) = default; + Renderable& operator=(Renderable&&) = default; + Renderable(const Renderable&) = default; + Renderable& operator=(const Renderable&) = default; + virtual ~Renderable() = default; virtual void draw(Renderer& r, const Transform2D& t, const States& rendererStates) = 0; @@ -159,7 +165,9 @@ class Point : Renderable { public: Point(fVec2&& pos) - : _pos(std::move(pos)) {}; + : _pos(std::move(pos)) + { + } void draw(Renderer& r, const Transform2D& transform, const States& rendererStates) override; @@ -201,38 +209,38 @@ class BoxPrimitive : public Renderable { public: BoxPrimitive(const fBox& box, Color color = {255, 255, 255, 255}) - : box(box) - , color(color) + : _box(box) + , _color(color) { } void draw(Renderer& r, const Transform2D& transform, const States&) override { // transform the box - auto b = box; - b.pos -= (box.midpoint()); + auto b = _box; + b.pos -= (_box.midpoint()); b.pos *= transform.scale; b.dim *= transform.scale; b.pos += transform.pos; // TODO: this seems awkward - b.pos += (box.midpoint() * transform.scale); + b.pos += (_box.midpoint() * transform.scale); auto rect = (SDL_FRect{b.left(), b.top(), b.width(), b.height()}); // r.setDrawColor(255, 255, 255, 255); - ScopedColor sc{r.renderer, color}; + ScopedColor sc{r.renderer, _color}; // draw the polygon SDL_RenderDrawRectF(r.renderer.get(), &rect); } private: - const fBox box; - const Color color; + const fBox _box; + const Color _color; }; class Points : public Renderable { public: Points(std::vector&& points) - : points(points) + : _points(points) { } @@ -241,11 +249,11 @@ class Points : public Renderable r.renderer.setDrawColor(white.r, white.g, white.b, white.a); // draw the polygon - r.renderer.drawPoints(std::bit_cast(points.data()), static_cast(points.size())); + r.renderer.drawPoints(std::bit_cast(_points.data()), static_cast(_points.size())); } private: - std::vector points; + std::vector _points; }; class RefPoints : public Renderable @@ -331,4 +339,4 @@ class CircleSector : public LineStrip setPoints(std::move(points)); } }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/primitives/Sprite.cpp b/libs/pgEngine/primitives/Sprite.cpp index 98486b5c..beac5044 100644 --- a/libs/pgEngine/primitives/Sprite.cpp +++ b/libs/pgEngine/primitives/Sprite.cpp @@ -45,4 +45,4 @@ void pg::Sprites::draw(pg::Renderer& r, const pg::Transform2D& t, const States& } states.restore(r.renderer); states.restore(r.renderer, tex); -} \ No newline at end of file +} diff --git a/libs/pgEngine/primitives/Sprite.hpp b/libs/pgEngine/primitives/Sprite.hpp index 37883b3b..f76a1b84 100644 --- a/libs/pgEngine/primitives/Sprite.hpp +++ b/libs/pgEngine/primitives/Sprite.hpp @@ -37,4 +37,4 @@ struct Sprites : public pg::Sprite private: InstanceTransforms instanceTransforms; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgEngine/scripting/PythonScripter.hpp b/libs/pgEngine/scripting/PythonScripter.hpp index b4f846a5..79d99f1e 100644 --- a/libs/pgEngine/scripting/PythonScripter.hpp +++ b/libs/pgEngine/scripting/PythonScripter.hpp @@ -23,4 +23,4 @@ class PythonScripter ScriptLines _script; Modules _modules; }; -} // namespace pg::scripting \ No newline at end of file +} // namespace pg::scripting diff --git a/libs/pgFoundation/Lifetime.hpp b/libs/pgFoundation/Lifetime.hpp index 857c4e17..c06ecd95 100644 --- a/libs/pgFoundation/Lifetime.hpp +++ b/libs/pgFoundation/Lifetime.hpp @@ -4,8 +4,8 @@ namespace pg { /** * Lifetime scope wrapper for objects with explicit make and destroy functions - * @tparam Make - * @tparam Destroy + * /param Construct + * /param Destroy */ template class Lifetime @@ -20,4 +20,4 @@ class Lifetime Lifetime& operator=(const Lifetime&) = delete; Lifetime operator=(Lifetime&&) = delete; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgFoundation/MemStream.hpp b/libs/pgFoundation/MemStream.hpp index 5a9c591b..11c9a703 100644 --- a/libs/pgFoundation/MemStream.hpp +++ b/libs/pgFoundation/MemStream.hpp @@ -1,4 +1,5 @@ #pragma once +#include namespace pg::foundation { @@ -40,7 +41,9 @@ class OwningMemBuf : public MemBuf public: OwningMemBuf(std::vector&& buffer) : MemBuf(buffer.data(), buffer.size()) - , _buffer(std::move(buffer)){}; + , _buffer(std::move(buffer)) + { + } private: std::vector _buffer; @@ -74,4 +77,4 @@ class OwningMemStream : public std::istream OwningMemBuf _buffer; }; -} // namespace pg::foundation \ No newline at end of file +} // namespace pg::foundation diff --git a/libs/pgFoundation/NamedTypeRegistrar.hpp b/libs/pgFoundation/NamedTypeRegistrar.hpp index 5c133173..56cd999a 100644 --- a/libs/pgFoundation/NamedTypeRegistrar.hpp +++ b/libs/pgFoundation/NamedTypeRegistrar.hpp @@ -28,4 +28,4 @@ struct TypeRegistrar { constexpr TypeRegistrar() { registerEvent(name); } }; -} // namespace pgf \ No newline at end of file +} // namespace pgf diff --git a/libs/pgFoundation/NamedTypeRegistry.hpp b/libs/pgFoundation/NamedTypeRegistry.hpp index 427959f7..7afddfe3 100644 --- a/libs/pgFoundation/NamedTypeRegistry.hpp +++ b/libs/pgFoundation/NamedTypeRegistry.hpp @@ -24,4 +24,4 @@ class NamedTypeRegistry private: static inline std::unordered_map _registry; }; -} // namespace pgf \ No newline at end of file +} // namespace pgf diff --git a/libs/pgFoundation/VirtualFS.hpp b/libs/pgFoundation/VirtualFS.hpp new file mode 100644 index 00000000..65e04e64 --- /dev/null +++ b/libs/pgFoundation/VirtualFS.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace pg::foundation { +class VirtualFileSystem +{ +public: + VirtualFileSystem() = default; + ~VirtualFileSystem() = default; +}; + +}; // namespace pg::foundation diff --git a/libs/pgFoundation/imgui/Spinner.hpp b/libs/pgFoundation/imgui/Spinner.hpp index 653220ca..33ffd06b 100644 --- a/libs/pgFoundation/imgui/Spinner.hpp +++ b/libs/pgFoundation/imgui/Spinner.hpp @@ -43,9 +43,9 @@ static inline bool BufferingBar(const char* label, const float b = speed * 0.333f; const float c = speed * 0.666f; - const float o1 = (circleWidth + r) * (t + a - speed * (int)((t + a) / speed)) / speed; - const float o2 = (circleWidth + r) * (t + b - speed * (int)((t + b) / speed)) / speed; - const float o3 = (circleWidth + r) * (t + c - speed * (int)((t + c) / speed)) / speed; + const float o1 = (circleWidth + r) * (t + a - speed * static_cast((t + a) / speed)) / speed; + const float o2 = (circleWidth + r) * (t + b - speed * static_cast((t + b) / speed)) / speed; + const float o3 = (circleWidth + r) * (t + c - speed * static_cast((t + c) / speed)) / speed; window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o1, bb.Min.y + r), r, bg_col); window->DrawList->AddCircleFilled(ImVec2(pos.x + circleEnd - o2, bb.Min.y + r), r, bg_col); diff --git a/libs/pgGame/CMakeLists.txt b/libs/pgGame/CMakeLists.txt index bb65e085..3081bf65 100644 --- a/libs/pgGame/CMakeLists.txt +++ b/libs/pgGame/CMakeLists.txt @@ -31,7 +31,7 @@ target_link_libraries(${PROJECT_NAME} pgf::pgf PRIVATE pgEngine::pgEngine - vfspp::vfspp + #vfspp::vfspp ) diff --git a/libs/pgGame/components/Drawable.hpp b/libs/pgGame/components/Drawable.hpp index fc535e64..dadfebd6 100644 --- a/libs/pgGame/components/Drawable.hpp +++ b/libs/pgGame/components/Drawable.hpp @@ -24,4 +24,4 @@ struct GuiDrawable int32_t order{0}; bool active{true}; }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/components/GameState.hpp b/libs/pgGame/components/GameState.hpp index c2a935e4..a7ed2d7e 100644 --- a/libs/pgGame/components/GameState.hpp +++ b/libs/pgGame/components/GameState.hpp @@ -13,4 +13,4 @@ struct GameState PauseState pauseState{PauseState::Paused}; float timeScale{1.0f}; }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/components/WindowDetails.hpp b/libs/pgGame/components/WindowDetails.hpp index 94e55085..5908961b 100644 --- a/libs/pgGame/components/WindowDetails.hpp +++ b/libs/pgGame/components/WindowDetails.hpp @@ -9,4 +9,4 @@ struct WindowDetails SDL_Rect windowRect; }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/config/GameConfig.hpp b/libs/pgGame/config/GameConfig.hpp index ce6068af..60d6babe 100644 --- a/libs/pgGame/config/GameConfig.hpp +++ b/libs/pgGame/config/GameConfig.hpp @@ -31,4 +31,4 @@ struct GameConfig } }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/config/GenericConfig.hpp b/libs/pgGame/config/GenericConfig.hpp index 4eba30df..8ce01cbb 100644 --- a/libs/pgGame/config/GenericConfig.hpp +++ b/libs/pgGame/config/GenericConfig.hpp @@ -71,4 +71,4 @@ class GenericConfig config[ctx + "::" + key] = value; } }; -}} // namespace pg::game \ No newline at end of file +}} // namespace pg::game diff --git a/libs/pgGame/core/Game.cpp b/libs/pgGame/core/Game.cpp index c2240434..cd954138 100644 --- a/libs/pgGame/core/Game.cpp +++ b/libs/pgGame/core/Game.cpp @@ -74,7 +74,7 @@ game::Game::Game(pg::game::GameConfig&& config) , _windowDetails(_gameConfig.getWindowRect()) , _sdlApp(_gameConfig.windowConfig) , _inputEventDispatcher(_sdlApp.getEventHandler(), {}) - , _vfs(std::make_unique()) + , _vfs(std::make_unique()) , _resourceManager([this](const pg::foundation::URI& uri) -> pg::foundation::DataProviderPtr { return std::make_unique(uri, _vfs, _gameConfig.resourcePrefix); }) @@ -85,21 +85,21 @@ game::Game::Game(pg::game::GameConfig&& config) switch (vfsConfig.type) { case pg::game::VFSConfig::VFSType::PHYSICAL: { - auto fs = std::make_shared(vfsConfig.root); - fs->Initialize(); - _vfs->AddFileSystem(vfsConfig.alias, fs); + // auto fs = std::make_shared(vfsConfig.root); + // fs->Initialize(); + // _vfs->AddFileSystem(vfsConfig.alias, fs); break; } case pg::game::VFSConfig::VFSType::ZIP: { - auto fs = std::make_shared(vfsConfig.root); - fs->Initialize(); - _vfs->AddFileSystem(vfsConfig.alias, fs); + // auto fs = std::make_shared(vfsConfig.root); + // fs->Initialize(); + // _vfs->AddFileSystem(vfsConfig.alias, fs); break; } case pg::game::VFSConfig::VFSType::MEMORY: { - auto fs = std::make_shared(); - fs->Initialize(); - _vfs->AddFileSystem(vfsConfig.alias, fs); + // auto fs = std::make_shared(); + // fs->Initialize(); + // _vfs->AddFileSystem(vfsConfig.alias, fs); break; } } diff --git a/libs/pgGame/core/Game.hpp b/libs/pgGame/core/Game.hpp index b605fd47..64b181dc 100644 --- a/libs/pgGame/core/Game.hpp +++ b/libs/pgGame/core/Game.hpp @@ -2,7 +2,7 @@ #include #include #include - +#include #include #include @@ -26,9 +26,9 @@ #include #include -namespace vfspp { -class VirtualFileSystem; -} // namespace vfspp +// namespace vfspp { +// class VirtualFileSystem; +// } // namespace vfspp namespace pg::game { @@ -43,8 +43,9 @@ class GamePimpl virtual ~GamePimpl() = default; GamePimpl(Game& game, GameState& gameState) - : _game(game) - , _gameState(gameState) + : _gameState(gameState) + , _game(game) + { } @@ -64,7 +65,7 @@ class Game : public SingletonInterface using Scenes = std::unordered_map>; using Systems = Scene::Systems; using ResourceManager = foundation::ResourceManager; - using VFSPtr = std::shared_ptr; + using VFSPtr = std::shared_ptr; private: pg::game::GameConfig _gameConfig; @@ -184,4 +185,4 @@ inline std::shared_ptr Game::getResource(const std::string& uri) { return _resourceManager.load(uri, getApp().getRenderer()); } -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/core/GameExceptions.hpp b/libs/pgGame/core/GameExceptions.hpp index 39140ef8..226d41d6 100644 --- a/libs/pgGame/core/GameExceptions.hpp +++ b/libs/pgGame/core/GameExceptions.hpp @@ -6,4 +6,4 @@ class ResourceNotFoundException : public std::runtime_error { using std::runtime_error::runtime_error; }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/core/InputEventDispatcher.hpp b/libs/pgGame/core/InputEventDispatcher.hpp index 8c53004d..5a2b6cba 100644 --- a/libs/pgGame/core/InputEventDispatcher.hpp +++ b/libs/pgGame/core/InputEventDispatcher.hpp @@ -120,4 +120,4 @@ class InputEventDispatcher : public InputEventHandlerInterface EventHandlers eventHandlers; std::set activeHandlers; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgGame/core/KeyStateMap.hpp b/libs/pgGame/core/KeyStateMap.hpp index 52b53a31..4a50932f 100644 --- a/libs/pgGame/core/KeyStateMap.hpp +++ b/libs/pgGame/core/KeyStateMap.hpp @@ -56,17 +56,17 @@ class KeyStateMap : public InputEventHandlerInterface /** * Register a callback that will be issued immediately when the key is pressed or released * - * @param code - * @param callback + * /param code + * /param callback */ void registerDirectCallback(SDL_Keycode code, DirectCallback&& callback); /** * Register a callback that will queued and issued when evaluateCallbacks is called * - * @param code - * @param callback - * @param once if true, the callback will not report another key press until key is released before again + * /param code + * /param callback + * /param once if true, the callback will not report another key press until key is released before again */ void registerKeyCallback(SDL_Keycode code, Callback&& callback, bool once = false); @@ -115,4 +115,4 @@ class KeyStateMap : public InputEventHandlerInterface MouseWheelCallback mouseWheelCallback; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgGame/core/RegistryHelper.hpp b/libs/pgGame/core/RegistryHelper.hpp index 565fe706..27f857fb 100644 --- a/libs/pgGame/core/RegistryHelper.hpp +++ b/libs/pgGame/core/RegistryHelper.hpp @@ -45,4 +45,4 @@ auto makeEntity(entt::registry& registry, Components&&... components) return id; } -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/core/Scene.hpp b/libs/pgGame/core/Scene.hpp index e6cc6b9e..16617bfd 100644 --- a/libs/pgGame/core/Scene.hpp +++ b/libs/pgGame/core/Scene.hpp @@ -13,9 +13,9 @@ namespace pg::game { struct SceneConfig { - std::string scene_id; //< name of the scene - std::vector systems; //< systems associated with this scene - std::string followUpScene; //< scene to switch to after this scene + std::string scene_id; ///< name of the scene + std::vector systems; ///< systems associated with this scene + std::string followUpScene; ///< scene to switch to after this scene }; /** @@ -36,8 +36,9 @@ class Scene : public SingletonInterface virtual ~Scene() { stop(); } - virtual void preFrame(FrameStamp&) {}; - virtual void postFrame(FrameStamp&) {}; + virtual void preFrame(FrameStamp&) {} + + virtual void postFrame(FrameStamp&) {} const Systems& getSystems() const; @@ -87,4 +88,4 @@ class Scene : public SingletonInterface entt::dispatcher _dispatcher; }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgGame/core/SingletonInterface.hpp b/libs/pgGame/core/SingletonInterface.hpp index d7ab7a96..bf8166c9 100644 --- a/libs/pgGame/core/SingletonInterface.hpp +++ b/libs/pgGame/core/SingletonInterface.hpp @@ -137,4 +137,4 @@ class SingletonInterface entt::registry& registry() { return static_cast(this)->getRegistry(); } }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgGame/core/VFSDataProvider.cpp b/libs/pgGame/core/VFSDataProvider.cpp index 652b7958..ea12e352 100644 --- a/libs/pgGame/core/VFSDataProvider.cpp +++ b/libs/pgGame/core/VFSDataProvider.cpp @@ -10,28 +10,31 @@ void pg::VFSDataProvider::close() {} std::istream& pg::VFSDataProvider::asStream() { - auto buffer = std::vector(_file->Size()); - _file->Read(buffer, buffer.size()); - - _stream = std::make_shared(std::move(buffer)); - return *_stream; + // auto buffer = std::vector(_file->Size()); + // _file->Read(buffer, buffer.size()); + // + // _stream = std::make_shared(std::move(buffer)); + throw std::runtime_error("Not implemented"); + // return *_stream; } std::vector pg::VFSDataProvider::asBuffer() { - auto buffer = std::vector(_file->Size()); - _file->Read(buffer, buffer.size()); - return std::vector(buffer.begin(), buffer.end()); + // auto buffer = std::vector(_file->Size()); + // _file->Read(buffer, buffer.size()); + // return std::vector(buffer.begin(), buffer.end()); + throw std::runtime_error("Not implemented"); } void pg::VFSDataProvider::toBuffer(std::vector& buffer, size_t max_ch) { - if (max_ch == 0) { max_ch = _file->Size(); } - auto buffer_ = std::vector(std::min(_file->Size(), max_ch)); - - _file->Read(buffer_, buffer_.size()); - buffer.resize(buffer_.size()); - std::copy(buffer_.begin(), buffer_.end(), buffer.begin()); + // if (max_ch == 0) { max_ch = _file->Size(); } + // auto buffer_ = std::vector(std::min(_file->Size(), max_ch)); + // + // _file->Read(buffer_, buffer_.size()); + // buffer.resize(buffer_.size()); + // std::copy(buffer_.begin(), buffer_.end(), buffer.begin()); + throw std::runtime_error("Not implemented"); } char pg::VFSDataProvider::readNext() @@ -41,14 +44,16 @@ char pg::VFSDataProvider::readNext() std::span pg::VFSDataProvider::asSpan() { - thread_local auto buffer = std::vector(); - buffer.resize(size()); - - _file->Read(buffer, buffer.size()); - return std::span(reinterpret_cast(buffer.data()), buffer.size()); + // thread_local auto buffer = std::vector(); + // buffer.resize(size()); + // + // _file->Read(buffer, buffer.size()); + // return std::span(reinterpret_cast(buffer.data()), buffer.size()); + throw std::runtime_error("Not implemented"); } size_t pg::VFSDataProvider::size() { - return _file->Size(); + // return _file->Size(); + throw std::runtime_error("Not implemented"); } diff --git a/libs/pgGame/core/VFSDataProvider.hpp b/libs/pgGame/core/VFSDataProvider.hpp index 803c8e4d..2fc20933 100644 --- a/libs/pgGame/core/VFSDataProvider.hpp +++ b/libs/pgGame/core/VFSDataProvider.hpp @@ -1,29 +1,29 @@ #pragma once -#include #include +#include namespace pg { class VFSDataProvider : public foundation::DataProvider { - std::shared_ptr _vfs; - std::shared_ptr _stream; - vfspp::IFilePtr _file; - std::string _localPrefix; + std::shared_ptr _vfs; + std::shared_ptr _stream; + // vfspp::IFilePtr _file; + std::string _localPrefix; public: - VFSDataProvider(const foundation::URI& uri, - std::shared_ptr vfs, - std::string local_prefix = "") + VFSDataProvider(const foundation::URI& uri, + std::shared_ptr vfs, + std::string local_prefix = "") : DataProvider(uri) , _vfs(std::move(vfs)) - , _file(_vfs->OpenFile({getUri()}, {vfspp::IFile::FileMode::Read})) + //, _file(_vfs->OpenFile({getUri()}, {vfspp::IFile::FileMode::Read})) , _localPrefix(local_prefix) { - if (!_file && !_localPrefix.empty()) - { - _file = _vfs->OpenFile({_localPrefix, getUri(), false}, {vfspp::IFile::FileMode::Read}); - } - if (!_file) { throw std::runtime_error("Cannot open VFS file: " + std::string{getUri()}); } + // if (!_file && !_localPrefix.empty()) + // { + // _file = _vfs->OpenFile({_localPrefix, getUri(), false}, {vfspp::IFile::FileMode::Read}); + // } + // if (!_file) { throw std::runtime_error("Cannot open VFS file: " + std::string{getUri()}); } } ~VFSDataProvider() override; @@ -36,4 +36,4 @@ class VFSDataProvider : public foundation::DataProvider std::span asSpan() override; size_t size() override; }; -} // namespace pg \ No newline at end of file +} // namespace pg diff --git a/libs/pgGame/events/GameEvents.hpp b/libs/pgGame/events/GameEvents.hpp index 39edb3b5..1f40be4e 100644 --- a/libs/pgGame/events/GameEvents.hpp +++ b/libs/pgGame/events/GameEvents.hpp @@ -30,4 +30,4 @@ struct TimeScaleEvent : pgf::TypeRegistrar { float time_scale; }; -} // namespace pg::game::events \ No newline at end of file +} // namespace pg::game::events diff --git a/libs/pgGame/systems/SystemsRegistry.hpp b/libs/pgGame/systems/SystemsRegistry.hpp index 9e566cb2..303f9ee9 100644 --- a/libs/pgGame/systems/SystemsRegistry.hpp +++ b/libs/pgGame/systems/SystemsRegistry.hpp @@ -47,4 +47,4 @@ class SystemsFactory static inline Factory _factory; static inline SharedSystems _sharedSystems; }; -} // namespace pg::game \ No newline at end of file +} // namespace pg::game diff --git a/libs/pgOrbit/Constants.hpp b/libs/pgOrbit/Constants.hpp index 0414edc4..6799381b 100644 --- a/libs/pgOrbit/Constants.hpp +++ b/libs/pgOrbit/Constants.hpp @@ -5,4 +5,4 @@ static constexpr double AU = 1.495978707e11; //> Astronomical unit( (m) static constexpr double LY = 9.461e15; //> Light year (m) static constexpr double G = 6.67430e-11; //> Newtons gravitational constant (m^3*kg^-1*s^-2) -}} // namespace pgOrbit::constants \ No newline at end of file +}} // namespace pgOrbit::constants diff --git a/libs/pgOrbit/FloatingPointType.hpp b/libs/pgOrbit/FloatingPointType.hpp index 90f8491f..ddf5ec51 100644 --- a/libs/pgOrbit/FloatingPointType.hpp +++ b/libs/pgOrbit/FloatingPointType.hpp @@ -1,3 +1,3 @@ #pragma once template -concept FloatingPoint = std::is_same_v || std::is_same_v; \ No newline at end of file +concept FloatingPoint = std::is_same_v || std::is_same_v; diff --git a/libs/pgOrbit/OrbitCreator.hpp b/libs/pgOrbit/OrbitCreator.hpp index 20f72c51..1746f5e5 100644 --- a/libs/pgOrbit/OrbitCreator.hpp +++ b/libs/pgOrbit/OrbitCreator.hpp @@ -191,4 +191,4 @@ class OrbitCreator float _luminosity; OrbitCreatorConfig _config; }; -} // namespace pgOrbit \ No newline at end of file +} // namespace pgOrbit diff --git a/libs/pgOrbit/OrbitalParameters.hpp b/libs/pgOrbit/OrbitalParameters.hpp index 4ad88084..8bfb8fa4 100644 --- a/libs/pgOrbit/OrbitalParameters.hpp +++ b/libs/pgOrbit/OrbitalParameters.hpp @@ -18,4 +18,4 @@ struct OrbitalParameters practice the mean longitude does not correspond to any one physical angle.**/ }; -} // namespace pgOrbit \ No newline at end of file +} // namespace pgOrbit diff --git a/libs/pgOrbit/StarParameters.hpp b/libs/pgOrbit/StarParameters.hpp index ac1b14ba..814716cc 100644 --- a/libs/pgOrbit/StarParameters.hpp +++ b/libs/pgOrbit/StarParameters.hpp @@ -12,15 +12,15 @@ using StarClassParameter = std::array; enum class SpectralType { - O, //< Blue - B, //< Blue-white - A, //< White - F, //< Yellow-white - G, //< Yellow - K, //< Orange - M, //< Red - BrownDwarf, //< Brown dwarf - WhiteDwarf, //< White dwarf + O, ///< Blue + B, ///< Blue-white + A, ///< White + F, ///< Yellow-white + G, ///< Yellow + K, ///< Orange + M, ///< Red + BrownDwarf, ///< Brown dwarf + WhiteDwarf, ///< White dwarf BlackHole, NeutronStar, Unknown, From 44f3aa6840bb4145a2506c6ee4cdf3c7060c72e0 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sun, 23 Feb 2025 23:09:59 +0100 Subject: [PATCH 02/15] fixes and cleanup --- apps/galaxy/systems/DroneSystem.cpp | 13 ++-- apps/sandboxes/resourceLoaderSandbox/main.cpp | 71 ++++++++++--------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/apps/galaxy/systems/DroneSystem.cpp b/apps/galaxy/systems/DroneSystem.cpp index 38c40ddf..8b18f3c1 100644 --- a/apps/galaxy/systems/DroneSystem.cpp +++ b/apps/galaxy/systems/DroneSystem.cpp @@ -108,12 +108,13 @@ void galaxy::DroneSystem::createFactions(const pg::FrameStamp& frameStamp) system_faction.name = faction.name; starsystem.colonizationStatus = galaxy::ColonizationStatus::Colonized; // event - _game.getDispatcher().enqueue( - {.system_entity = starsystem_entity, - .owner_faction = faction.name, - .status = ColonizationStatus::Colonized, - .old_status = ColonizationStatus::Unexplored, - .previous_owner = ""}); + _game.getDispatcher().enqueue({ + .system_entity = starsystem_entity, + .previous_owner = "", + .owner_faction = faction.name, + .status = ColonizationStatus::Colonized, + .old_status = ColonizationStatus::Unexplored, + }); // setup port connections // defaults diff --git a/apps/sandboxes/resourceLoaderSandbox/main.cpp b/apps/sandboxes/resourceLoaderSandbox/main.cpp index 87f83fd1..bcb214fb 100644 --- a/apps/sandboxes/resourceLoaderSandbox/main.cpp +++ b/apps/sandboxes/resourceLoaderSandbox/main.cpp @@ -1,47 +1,50 @@ -#include - -// for testing - -class membuf : public std::basic_streambuf -{ -public: - membuf(const uint8_t* p, size_t l) { setg((char*)p, (char*)p, (char*)p + l); } -}; - -class memstream : public std::istream -{ -public: - memstream(const uint8_t* p, size_t l) - : std::istream(&_buffer) - , _buffer(p, l) - { - rdbuf(&_buffer); - } - -private: - membuf _buffer; -}; +#include +#include +#include +#include +#include int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) try { - // auto rootFS = std::make_unique(R"(..\data\music\cylinders\Chris Zabriskie - - // Cylinders.zip)"); rootFS->Initialize(); + physfspp::VirtualFileSystem vfs("sandbox"); + + vfs.mount(R"(..\data\music\cylinders\Chris Zabriskie - Cylinders.zip)", + "/music", + physfspp::VirtualFileSystem::AppendMode::Append); + vfs.mount(R"(..\data\music\cylinders)", "/test", physfspp::VirtualFileSystem::AppendMode::Append); + vfs.setWriteDir("../data/"); + + auto f = vfs.open("/music/Chris Zabriskie - Cylinders - 08 Cylinder Eight.mp3", + physfspp::VirtualFileSystem::FileOpenMode::Read); + + auto ifs = physfspp::IFStream(f); + auto out = vfs.open("/test.txt", physfspp::VirtualFileSystem::FileOpenMode::Write); + + std::vector buffer(f.length()); + ifs.read(reinterpret_cast(buffer.data()), buffer.size()); + // std::ofstream of("../data/sandbox.mp3", std::ios::binary); + // of.write(reinterpret_cast(buffer.data()), buffer.size()); + + auto ofs = physfspp::OFStream(out); + ofs.write(reinterpret_cast(buffer.data()), buffer.size()); + // auto rootFS = std::make_unique(R"(..\data\music\cylinders\Chris Zabriskie - + // Cylinders.zip)"); rootFS->Initialize(); // - // auto vfs = std::make_unique(); - // vfs->AddFileSystem("/music", std::move(rootFS)); + // auto vfs = std::make_unique(); + // vfs->AddFileSystem("/music", std::move(rootFS)); // - // auto f = - // vfs->OpenFile({"/music/Chris Zabriskie - Cylinders - 01 Cylinder One.mp3"}, - // {vfspp::IFile::FileMode::Read}); - // // soundEngineX::loader::load() - // auto buffer = std::vector(f->Size()); - // f->Read(buffer, buffer.size()); + // auto f = + // vfs->OpenFile({"/music/Chris Zabriskie - Cylinders - 01 Cylinder One.mp3"}, + // {vfspp::IFile::FileMode::Read}); + // // soundEngineX::loader::load() + // auto buffer = std::vector(f->Size()); + // f->Read(buffer, buffer.size()); } catch (const std::exception& e) { std::cerr << "Terminated: " << e.what() << std::endl; return -1; -} \ No newline at end of file +} From 549b4f96e89cca8683b21effa5f739d849d794b2 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sun, 23 Feb 2025 23:11:26 +0100 Subject: [PATCH 03/15] Fix pgFoundation library type --- libs/pgFoundation/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/pgFoundation/CMakeLists.txt b/libs/pgFoundation/CMakeLists.txt index db6bff0b..7f5a8644 100644 --- a/libs/pgFoundation/CMakeLists.txt +++ b/libs/pgFoundation/CMakeLists.txt @@ -1,6 +1,6 @@ project(pgFoundation) -add_library(${PROJECT_NAME} STATIC) +add_library(${PROJECT_NAME} INTERFACE) add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) #set language to cXX #Interface only library @@ -25,8 +25,8 @@ target_link_libraries(${PROJECT_NAME} target_include_directories( ${PROJECT_NAME} - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} +# PRIVATE +# ${CMAKE_CURRENT_SOURCE_DIR} INTERFACE $ $ From 784de5eff6b760b238908ad7aaac5ad8026c5a01 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sun, 23 Feb 2025 23:12:15 +0100 Subject: [PATCH 04/15] minimal C++ WIP wrapper for PhysicalFS --- .../resourceLoaderSandbox/CMakeLists.txt | 3 +- cmake/deps_cpm.cmake | 7 +- libs/CMakeLists.txt | 3 +- libs/PhysFSPP/CMakeLists.txt | 37 ++++++ libs/PhysFSPP/PhysFSPP.cpp | 1 + libs/PhysFSPP/PhysFSPP.hpp | 65 ++++++++++ libs/PhysFSPP/PhysFSPP_Exceptions.hpp | 20 ++++ libs/PhysFSPP/PhysFSPP_File.cpp | 1 + libs/PhysFSPP/PhysFSPP_File.hpp | 53 ++++++++ libs/PhysFSPP/PhysFSPP_Stream.cpp | 37 ++++++ libs/PhysFSPP/PhysFSPP_Stream.hpp | 54 +++++++++ libs/PhysFSPP/PhysFSPP_StreamBuf.hpp | 113 ++++++++++++++++++ libs/PhysFSPP/PhysFSPP_Types.hpp | 7 ++ 13 files changed, 398 insertions(+), 3 deletions(-) create mode 100644 libs/PhysFSPP/CMakeLists.txt create mode 100644 libs/PhysFSPP/PhysFSPP.cpp create mode 100644 libs/PhysFSPP/PhysFSPP.hpp create mode 100644 libs/PhysFSPP/PhysFSPP_Exceptions.hpp create mode 100644 libs/PhysFSPP/PhysFSPP_File.cpp create mode 100644 libs/PhysFSPP/PhysFSPP_File.hpp create mode 100644 libs/PhysFSPP/PhysFSPP_Stream.cpp create mode 100644 libs/PhysFSPP/PhysFSPP_Stream.hpp create mode 100644 libs/PhysFSPP/PhysFSPP_StreamBuf.hpp create mode 100644 libs/PhysFSPP/PhysFSPP_Types.hpp diff --git a/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt b/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt index cecc18ec..7134a4e1 100644 --- a/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt +++ b/apps/sandboxes/resourceLoaderSandbox/CMakeLists.txt @@ -1,6 +1,6 @@ project(resourceLoaderSandBox) -add_executable(${PROJECT_NAME} main.cpp) +add_executable(${PROJECT_NAME}) target_sources(${PROJECT_NAME} PUBLIC @@ -11,6 +11,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC pgEngine::pgEngine pgGame::pgGame + PhysFSPP::PhysFSPP #vfspp ) diff --git a/cmake/deps_cpm.cmake b/cmake/deps_cpm.cmake index da4d0f36..4ae39c4a 100644 --- a/cmake/deps_cpm.cmake +++ b/cmake/deps_cpm.cmake @@ -15,7 +15,12 @@ CPMAddPackage( GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_TAG v2.13.6 ) - +CPMAddPackage( + NAME phyfs + GIT_REPOSITORY https://github.com/icculus/physfs + GIT_TAG release-3.2.0 + SYSTEM ON +) CPMAddPackage( #zeromq NAME ZeroMQ diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 07a1b756..4b94abdf 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(pgEngine) add_subdirectory(pgGame) add_subdirectory(pgFoundation) -add_subdirectory(pgOrbit) \ No newline at end of file +add_subdirectory(pgOrbit) +add_subdirectory(PhysFSPP) \ No newline at end of file diff --git a/libs/PhysFSPP/CMakeLists.txt b/libs/PhysFSPP/CMakeLists.txt new file mode 100644 index 00000000..a8ca42c1 --- /dev/null +++ b/libs/PhysFSPP/CMakeLists.txt @@ -0,0 +1,37 @@ +project(PhysFSPP) + + +add_library(${PROJECT_NAME} STATIC) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) + +target_sources(${PROJECT_NAME} + PRIVATE + PhysFSPP.cpp + PhysFSPP_File.cpp + PhysFSPP_Stream.cpp + + PUBLIC + PhysFSPP.hpp + PhysFSPP_File.hpp + PhysFSPP_Stream.hpp + PhysFSPP_StreamBuf.hpp + PhysFSPP_Types.hpp + PhysFSPP_Exceptions.hpp + + +) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + PhysFS::PhysFS-static + PRIVATE +) + +target_include_directories( + ${PROJECT_NAME} + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC + $ + $ +) diff --git a/libs/PhysFSPP/PhysFSPP.cpp b/libs/PhysFSPP/PhysFSPP.cpp new file mode 100644 index 00000000..ccae65dd --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/libs/PhysFSPP/PhysFSPP.hpp b/libs/PhysFSPP/PhysFSPP.hpp new file mode 100644 index 00000000..5e1370ee --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP.hpp @@ -0,0 +1,65 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace physfspp { + +class VirtualFileSystem +{ +public: + enum class AppendMode + { + Append, + Prepend, + }; + enum class FileOpenMode + { + Read, + Write, + Append, + }; + + VirtualFileSystem(const std::string& arg0) { PHYSFS_init(arg0.c_str()); } + + ~VirtualFileSystem() { PHYSFS_deinit(); } + + void mount(const std::string& path, const std::string& mountPoint, AppendMode appendMode) + { + handleError(PHYSFS_mount(path.c_str(), mountPoint.c_str(), appendMode == AppendMode::Append ? 1 : 0)); + } + + void setWriteDir(const std::string& path) { handleError(PHYSFS_setWriteDir(path.c_str())); } + + FileHandle open(const std::string& path, FileOpenMode fileOpenMode = FileOpenMode::Read) + { + PHYSFS_File* f = nullptr; + switch (fileOpenMode) + { + case FileOpenMode::Read: + f = PHYSFS_openRead(path.c_str()); + break; + case FileOpenMode::Write: + f = PHYSFS_openWrite(path.c_str()); + break; + case FileOpenMode::Append: + f = PHYSFS_openAppend(path.c_str()); + break; + default: + throw VirtualFileSystemException("Invalid file open mode"); + } + + if (f == nullptr) { throw VirtualFileSystemException(PHYSFS_getLastError()); } + return FileHandle{f}; + } + +private: + void handleError(int res) + { + if (res == 0) { throw VirtualFileSystemException(PHYSFS_getLastError()); } + } +}; +} // namespace physfspp diff --git a/libs/PhysFSPP/PhysFSPP_Exceptions.hpp b/libs/PhysFSPP/PhysFSPP_Exceptions.hpp new file mode 100644 index 00000000..f998a415 --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_Exceptions.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace physfspp { +class VirtualFileSystemException : public std::exception +{ +public: + VirtualFileSystemException(const std::string& message) + : m_message(message) + { + } + + const char* what() const noexcept override { return m_message.c_str(); } + +private: + std::string m_message; +}; +} // namespace physfspp \ No newline at end of file diff --git a/libs/PhysFSPP/PhysFSPP_File.cpp b/libs/PhysFSPP/PhysFSPP_File.cpp new file mode 100644 index 00000000..578a9ec9 --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_File.cpp @@ -0,0 +1 @@ +#include "PhysFSPP_File.hpp" diff --git a/libs/PhysFSPP/PhysFSPP_File.hpp b/libs/PhysFSPP/PhysFSPP_File.hpp new file mode 100644 index 00000000..d79c7a1b --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_File.hpp @@ -0,0 +1,53 @@ +#pragma once + +#include +#include + +namespace physfspp { +class FileHandle +{ +public: + explicit FileHandle(PHYSFS_File* file) + : m_file(file) + { + } + + // only allow move + FileHandle(const FileHandle&) = default; + FileHandle& operator=(const FileHandle&) = default; + FileHandle(FileHandle&&) = delete; + FileHandle& operator=(FileHandle&&) = delete; + + ~FileHandle() + { + // if (m_file != nullptr) { PHYSFS_close(m_file); } + } + + // length of file + int64_t length() const { return PHYSFS_fileLength(m_file); } + + // seek to a position + void seek(size_t pos) { PHYSFS_seek(m_file, pos); } + + // tell the current position + int64_t tell() const { return PHYSFS_tell(m_file); } + + // close + void close() + { + if (m_file != nullptr) { PHYSFS_close(m_file); } + m_file = nullptr; + } + + bool eof() const { return PHYSFS_eof(m_file) != 0; } + + // read + int64_t read(void* buffer, size_t objSize) const { return PHYSFS_readBytes(m_file, buffer, objSize); } + + // write + int64_t write(const void* buffer, size_t objSize) const { return PHYSFS_writeBytes(m_file, buffer, objSize); } + +private: + PHYSFS_File* m_file{nullptr}; +}; +} // namespace physfspp diff --git a/libs/PhysFSPP/PhysFSPP_Stream.cpp b/libs/PhysFSPP/PhysFSPP_Stream.cpp new file mode 100644 index 00000000..21b617a9 --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_Stream.cpp @@ -0,0 +1,37 @@ +#include "PhysFSPP_Stream.hpp" +#include + +physfspp::IFStream::IFStream(physfspp::FileHandle file) + : StreamBase(file) + , std::istream(&getBuf()) +{ +} + +physfspp::IFStream::~IFStream() +{ + // flush(); +} + +physfspp::OFStream::OFStream(physfspp::FileHandle file) + + : StreamBase(file) + , std::ostream(&getBuf()) + +{ +} + +physfspp::OFStream::~OFStream() +{ + flush(); +} + +physfspp::FStream::FStream(physfspp::FileHandle file) + : StreamBase(file) + , std::iostream(&getBuf()) +{ +} + +physfspp::FStream::~FStream() +{ + flush(); +} diff --git a/libs/PhysFSPP/PhysFSPP_Stream.hpp b/libs/PhysFSPP/PhysFSPP_Stream.hpp new file mode 100644 index 00000000..ebd3eac2 --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_Stream.hpp @@ -0,0 +1,54 @@ +#pragma once +#include +#include + +#include +#include + +namespace physfspp { + +namespace { +class StreamBase +{ + using Buffer = StreamBuf<2048>; + +public: + StreamBase(FileHandle file) + : _file(file) + , _rdBuf(std::make_unique(_file)) + { + } + + virtual ~StreamBase() { _file.close(); }; + + size_t length() { return _file.length(); } + + Buffer& getBuf() { return *_rdBuf; } + +private: + FileHandle _file; + std::unique_ptr _rdBuf; +}; +} // namespace + +class IFStream : public StreamBase, public std::istream +{ +public: + IFStream(FileHandle); + ~IFStream() override; +}; + +class OFStream : public StreamBase, public std::ostream +{ +public: + OFStream(FileHandle); + ~OFStream() override; +}; + +class FStream : public StreamBase, public std::iostream +{ +public: + FStream(FileHandle); + ~FStream() override; +}; +} // namespace physfspp \ No newline at end of file diff --git a/libs/PhysFSPP/PhysFSPP_StreamBuf.hpp b/libs/PhysFSPP/PhysFSPP_StreamBuf.hpp new file mode 100644 index 00000000..c790d1e6 --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_StreamBuf.hpp @@ -0,0 +1,113 @@ +#pragma once + +#include +#include + +namespace physfspp { +template +class StreamBuf : public std::streambuf +{ +public: + StreamBuf(FileHandle file) + : _file(file) + { + auto end = buffer.data() + BufferSize; + setg(end, end, end); + setp(buffer.data(), end); + } + + ~StreamBuf() override { sync(); } + + StreamBuf(const StreamBuf& other) = delete; + StreamBuf& operator=(const StreamBuf& other) = delete; + + StreamBuf(StreamBuf&&) = delete; + StreamBuf& operator=(StreamBuf&&) = delete; + +private: + int_type underflow() override + { + if (_file.eof()) { return traits_type::eof(); } + + const auto bytesRead = _file.read(buffer.data(), BufferSize); + + if (bytesRead < 1) { return traits_type::eof(); } + setg(buffer.data(), buffer.data(), buffer.data() + bytesRead); + return (unsigned char)*gptr(); + } + + pos_type seekoff(off_type pos, std::ios_base::seekdir dir, std::ios_base::openmode mode) override + { + switch (dir) + { + case std::ios_base::beg: + _file.seek(pos); + break; + case std::ios_base::cur: + // subtract characters currently in buffer from seek position + _file.seek((_file.tell() + pos) - (egptr() - gptr())); + break; + case std::ios_base::end: + _file.seek(_file.length() + pos); + break; + default: + break; + } + + if (mode & std::ios_base::in) { setg(egptr(), egptr(), egptr()); } + + if (mode & std::ios_base::out) { setp(buffer.data(), buffer.data()); } + return _file.tell(); + } + + pos_type seekpos(pos_type pos, std::ios_base::openmode mode) override + { + _file.seek(pos); + if (mode & std::ios_base::in) { setg(egptr(), egptr(), egptr()); } + + if (mode & std::ios_base::out) { setp(buffer.data(), buffer.data()); } + + return _file.tell(); + } + + int_type overflow(int_type c = traits_type::eof()) override + { + // Write buffer + if (flush() < 0) { return traits_type::eof(); } + + setp(buffer.data(), buffer.data() + BufferSize); // reset the put pointers + + if (c != traits_type::eof()) + { + *pptr() = (char)c; // Add the overflow character to the put buffer + pbump(1); // increment the put pointer by one + } + + return c; + } + + int sync() override + { + const auto result = flush(); + setp(buffer.data(), buffer.data() + BufferSize); // reset the put pointers + + return result; + } + + int flush() const + { + const auto len = pptr() - pbase(); + if (len == 0) + { + return 0; // nothing to do + } + + if (_file.write(pbase(), len) < len) { return -1; } + + return 0; + } + + std::array buffer; + FileHandle _file; +}; +} // namespace physfspp \ No newline at end of file diff --git a/libs/PhysFSPP/PhysFSPP_Types.hpp b/libs/PhysFSPP/PhysFSPP_Types.hpp new file mode 100644 index 00000000..4ba39dae --- /dev/null +++ b/libs/PhysFSPP/PhysFSPP_Types.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace physfspp { + +} // namespace physfspp From f402046f382a604f7f8cb1f843667d5afe290899 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Tue, 25 Feb 2025 23:20:48 +0100 Subject: [PATCH 05/15] moved to new VirtualFileSystem implementation --- apps/galaxy/main.cpp | 9 ++---- apps/sandboxes/resourceLoaderSandbox/main.cpp | 14 --------- libs/PhysFSPP/PhysFSPP.hpp | 3 +- libs/pgFoundation/VirtualFS.hpp | 11 ------- libs/pgGame/CMakeLists.txt | 1 + libs/pgGame/config/GameConfig.hpp | 11 ++----- libs/pgGame/core/Game.cpp | 24 ++------------- libs/pgGame/core/Game.hpp | 6 ++-- libs/pgGame/core/VFSDataProvider.cpp | 30 ++++++++----------- libs/pgGame/core/VFSDataProvider.hpp | 17 +++++------ 10 files changed, 33 insertions(+), 93 deletions(-) delete mode 100644 libs/pgFoundation/VirtualFS.hpp diff --git a/apps/galaxy/main.cpp b/apps/galaxy/main.cpp index 5a83b8f6..a1b12650 100644 --- a/apps/galaxy/main.cpp +++ b/apps/galaxy/main.cpp @@ -13,13 +13,10 @@ try game_config.windowConfig.size = {800, 600}; game_config.windowConfig.windowName = "Galaxy"; + game_config.vfsConfigs.push_back({.root = "../data", .alias = "data"}); + game_config.vfsConfigs.push_back({.root = "../data", .alias = "::resources"}); game_config.vfsConfigs.push_back( - {.root = "../data", .alias = "data", .type = pg::game::VFSConfig::VFSType::PHYSICAL}); - game_config.vfsConfigs.push_back( - {.root = "../data", .alias = "::resources", .type = pg::game::VFSConfig::VFSType::PHYSICAL}); - game_config.vfsConfigs.push_back({.root = "../data/music/cylinders/Chris Zabriskie - Cylinders.zip", - .alias = "music/soundtracks/cylinders", - .type = pg::game::VFSConfig::VFSType::ZIP}); + {.root = "../data/music/cylinders/Chris Zabriskie - Cylinders.zip", .alias = "music/soundtracks/cylinders"}); { galaxy::GalacticCore gc(std::move(game_config)); gc.setup(); diff --git a/apps/sandboxes/resourceLoaderSandbox/main.cpp b/apps/sandboxes/resourceLoaderSandbox/main.cpp index bcb214fb..e9ff133b 100644 --- a/apps/sandboxes/resourceLoaderSandbox/main.cpp +++ b/apps/sandboxes/resourceLoaderSandbox/main.cpp @@ -24,23 +24,9 @@ try std::vector buffer(f.length()); ifs.read(reinterpret_cast(buffer.data()), buffer.size()); - // std::ofstream of("../data/sandbox.mp3", std::ios::binary); - // of.write(reinterpret_cast(buffer.data()), buffer.size()); auto ofs = physfspp::OFStream(out); ofs.write(reinterpret_cast(buffer.data()), buffer.size()); - // auto rootFS = std::make_unique(R"(..\data\music\cylinders\Chris Zabriskie - - // Cylinders.zip)"); rootFS->Initialize(); - // - // auto vfs = std::make_unique(); - // vfs->AddFileSystem("/music", std::move(rootFS)); - // - // auto f = - // vfs->OpenFile({"/music/Chris Zabriskie - Cylinders - 01 Cylinder One.mp3"}, - // {vfspp::IFile::FileMode::Read}); - // // soundEngineX::loader::load() - // auto buffer = std::vector(f->Size()); - // f->Read(buffer, buffer.size()); } catch (const std::exception& e) diff --git a/libs/PhysFSPP/PhysFSPP.hpp b/libs/PhysFSPP/PhysFSPP.hpp index 5e1370ee..5fd9ac93 100644 --- a/libs/PhysFSPP/PhysFSPP.hpp +++ b/libs/PhysFSPP/PhysFSPP.hpp @@ -4,7 +4,6 @@ #include #include #include -#include namespace physfspp { @@ -23,7 +22,7 @@ class VirtualFileSystem Append, }; - VirtualFileSystem(const std::string& arg0) { PHYSFS_init(arg0.c_str()); } + VirtualFileSystem(const std::string& arg0 = {}) { PHYSFS_init(arg0.c_str()); } ~VirtualFileSystem() { PHYSFS_deinit(); } diff --git a/libs/pgFoundation/VirtualFS.hpp b/libs/pgFoundation/VirtualFS.hpp deleted file mode 100644 index 65e04e64..00000000 --- a/libs/pgFoundation/VirtualFS.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace pg::foundation { -class VirtualFileSystem -{ -public: - VirtualFileSystem() = default; - ~VirtualFileSystem() = default; -}; - -}; // namespace pg::foundation diff --git a/libs/pgGame/CMakeLists.txt b/libs/pgGame/CMakeLists.txt index 3081bf65..fe5fc593 100644 --- a/libs/pgGame/CMakeLists.txt +++ b/libs/pgGame/CMakeLists.txt @@ -29,6 +29,7 @@ target_link_libraries(${PROJECT_NAME} EnTT::EnTT spdlog::spdlog pgf::pgf + PhysFSPP::PhysFSPP PRIVATE pgEngine::pgEngine #vfspp::vfspp diff --git a/libs/pgGame/config/GameConfig.hpp b/libs/pgGame/config/GameConfig.hpp index 60d6babe..176a4fce 100644 --- a/libs/pgGame/config/GameConfig.hpp +++ b/libs/pgGame/config/GameConfig.hpp @@ -4,18 +4,11 @@ namespace pg::game { struct VFSConfig { - enum class VFSType - { - PHYSICAL, - ZIP, - MEMORY - }; using Root = std::string; using Alias = std::string; - Root root; - Alias alias; - VFSType type{VFSType::PHYSICAL}; + Root root; // root path + Alias alias; // alias/mount point }; struct GameConfig diff --git a/libs/pgGame/core/Game.cpp b/libs/pgGame/core/Game.cpp index cd954138..d8d25929 100644 --- a/libs/pgGame/core/Game.cpp +++ b/libs/pgGame/core/Game.cpp @@ -74,7 +74,7 @@ game::Game::Game(pg::game::GameConfig&& config) , _windowDetails(_gameConfig.getWindowRect()) , _sdlApp(_gameConfig.windowConfig) , _inputEventDispatcher(_sdlApp.getEventHandler(), {}) - , _vfs(std::make_unique()) + , _vfs(std::make_unique()) , _resourceManager([this](const pg::foundation::URI& uri) -> pg::foundation::DataProviderPtr { return std::make_unique(uri, _vfs, _gameConfig.resourcePrefix); }) @@ -82,27 +82,7 @@ game::Game::Game(pg::game::GameConfig&& config) // register all vfs's for (const auto& vfsConfig : _gameConfig.vfsConfigs) { - switch (vfsConfig.type) - { - case pg::game::VFSConfig::VFSType::PHYSICAL: { - // auto fs = std::make_shared(vfsConfig.root); - // fs->Initialize(); - // _vfs->AddFileSystem(vfsConfig.alias, fs); - break; - } - case pg::game::VFSConfig::VFSType::ZIP: { - // auto fs = std::make_shared(vfsConfig.root); - // fs->Initialize(); - // _vfs->AddFileSystem(vfsConfig.alias, fs); - break; - } - case pg::game::VFSConfig::VFSType::MEMORY: { - // auto fs = std::make_shared(); - // fs->Initialize(); - // _vfs->AddFileSystem(vfsConfig.alias, fs); - break; - } - } + _vfs->mount(vfsConfig.root, vfsConfig.alias, physfspp::VirtualFileSystem::AppendMode::Append); } _gui = std::make_unique(getApp()); diff --git a/libs/pgGame/core/Game.hpp b/libs/pgGame/core/Game.hpp index 64b181dc..ad7ba315 100644 --- a/libs/pgGame/core/Game.hpp +++ b/libs/pgGame/core/Game.hpp @@ -2,7 +2,7 @@ #include #include #include -#include + #include #include @@ -15,6 +15,8 @@ #include #include +#include + #include #include #include @@ -65,7 +67,7 @@ class Game : public SingletonInterface using Scenes = std::unordered_map>; using Systems = Scene::Systems; using ResourceManager = foundation::ResourceManager; - using VFSPtr = std::shared_ptr; + using VFSPtr = std::shared_ptr; private: pg::game::GameConfig _gameConfig; diff --git a/libs/pgGame/core/VFSDataProvider.cpp b/libs/pgGame/core/VFSDataProvider.cpp index ea12e352..78e21c23 100644 --- a/libs/pgGame/core/VFSDataProvider.cpp +++ b/libs/pgGame/core/VFSDataProvider.cpp @@ -1,6 +1,7 @@ #include "VFSDataProvider.hpp" #include +#include pg::VFSDataProvider::~VFSDataProvider() {} @@ -10,36 +11,29 @@ void pg::VFSDataProvider::close() {} std::istream& pg::VFSDataProvider::asStream() { - // auto buffer = std::vector(_file->Size()); - // _file->Read(buffer, buffer.size()); - // - // _stream = std::make_shared(std::move(buffer)); - throw std::runtime_error("Not implemented"); - // return *_stream; + auto file = _vfs->open(getUri()); + _stream = std::make_unique(file); + return *_stream; } std::vector pg::VFSDataProvider::asBuffer() { - // auto buffer = std::vector(_file->Size()); - // _file->Read(buffer, buffer.size()); - // return std::vector(buffer.begin(), buffer.end()); - throw std::runtime_error("Not implemented"); + auto file = _vfs->open(getUri()); + auto buffer = std::vector(file.length()); + file.read(reinterpret_cast(buffer.data()), buffer.size()); + return buffer; } void pg::VFSDataProvider::toBuffer(std::vector& buffer, size_t max_ch) { - // if (max_ch == 0) { max_ch = _file->Size(); } - // auto buffer_ = std::vector(std::min(_file->Size(), max_ch)); - // - // _file->Read(buffer_, buffer_.size()); - // buffer.resize(buffer_.size()); - // std::copy(buffer_.begin(), buffer_.end(), buffer.begin()); - throw std::runtime_error("Not implemented"); + auto file = _vfs->open(getUri()); + buffer.resize(std::min(max_ch, static_cast(file.length()))); + file.read(reinterpret_cast(buffer.data()), buffer.size()); } char pg::VFSDataProvider::readNext() { - return 0; + throw std::runtime_error("Not implemented"); } std::span pg::VFSDataProvider::asSpan() diff --git a/libs/pgGame/core/VFSDataProvider.hpp b/libs/pgGame/core/VFSDataProvider.hpp index 2fc20933..9f33980e 100644 --- a/libs/pgGame/core/VFSDataProvider.hpp +++ b/libs/pgGame/core/VFSDataProvider.hpp @@ -1,22 +1,21 @@ #pragma once #include -#include +#include +#include namespace pg { class VFSDataProvider : public foundation::DataProvider { - std::shared_ptr _vfs; - std::shared_ptr _stream; - // vfspp::IFilePtr _file; - std::string _localPrefix; + std::shared_ptr _vfs; + std::shared_ptr _stream; + std::string _localPrefix; public: - VFSDataProvider(const foundation::URI& uri, - std::shared_ptr vfs, - std::string local_prefix = "") + VFSDataProvider(const foundation::URI& uri, + std::shared_ptr vfs, + std::string local_prefix = "") : DataProvider(uri) , _vfs(std::move(vfs)) - //, _file(_vfs->OpenFile({getUri()}, {vfspp::IFile::FileMode::Read})) , _localPrefix(local_prefix) { // if (!_file && !_localPrefix.empty()) From e1781a923263edc704bca3afbeb7b9cdf7367271 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Tue, 24 Jun 2025 23:35:38 +0200 Subject: [PATCH 06/15] adapted paths and removed unused parameters --- CMakeLists.txt | 3 ++- apps/asteroids/main.cpp | 3 ++- apps/asteroids/systems/Lasers.cpp | 2 +- apps/asteroids/systems/Player.cpp | 2 +- libs/pgGame/config/GameConfig.hpp | 1 - libs/pgGame/core/Game.cpp | 3 +-- libs/pgGame/core/VFSDataProvider.hpp | 11 +---------- 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 61745a89..bc5cfe15 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) #some global compiler settings if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - add_compile_options(/W4 /WX) + #add_compile_options(/W4 /WX) + add_compile_options(/W3) add_compile_options(/bigobj) else() #add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-c++98-compat -Wno-c++98-compat-pedantic) diff --git a/apps/asteroids/main.cpp b/apps/asteroids/main.cpp index 8da0eda9..3880a18d 100644 --- a/apps/asteroids/main.cpp +++ b/apps/asteroids/main.cpp @@ -19,7 +19,8 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) try { - pg::game::Game game({.vfsConfigs{{.root = "../data", .alias = "data"}}, .resourcePrefix = "data"}); + pg::game::Game game( + {.vfsConfigs{{.root = "../data", .alias = "data"}, {.root = "../data/Meteors", .alias = "Meteors"}}}); pg::game::SystemsFactory::registerSystem("lasers"); pg::game::SystemsFactory::registerSystem("player"); diff --git a/apps/asteroids/systems/Lasers.cpp b/apps/asteroids/systems/Lasers.cpp index 8979210f..2ec920b0 100644 --- a/apps/asteroids/systems/Lasers.cpp +++ b/apps/asteroids/systems/Lasers.cpp @@ -14,7 +14,7 @@ void asteroids::Lasers::setup(std::string_view /*scene_id*/) void asteroids::Lasers::createShot(const events::LaserFired& event) { auto& renderer = _game.getApp().getRenderer(); - auto sprite = _game.getResource("laserBlue01.png", renderer); + auto sprite = _game.getResource("data/laserBlue01.png", renderer); pg::game::Drawable d(sprite); // determine shoot position diff --git a/apps/asteroids/systems/Player.cpp b/apps/asteroids/systems/Player.cpp index 8b8f93a4..4ace75af 100644 --- a/apps/asteroids/systems/Player.cpp +++ b/apps/asteroids/systems/Player.cpp @@ -15,7 +15,7 @@ void asteroids::Player::setup(std::string_view /*scene_id*/) auto& registry = _game.getGlobalRegistry(); auto& keyStateMap = _game.getCurrentScene().getKeyStateMap(); - auto sprite = _game.getResource("playerShip1_blue.png"); + auto sprite = _game.getResource("data/playerShip1_blue.png"); auto windowDetails = _game.getCurrentScene().getSingleton(); auto player = pg::game::makeEntity( diff --git a/libs/pgGame/config/GameConfig.hpp b/libs/pgGame/config/GameConfig.hpp index 176a4fce..d3d70ce6 100644 --- a/libs/pgGame/config/GameConfig.hpp +++ b/libs/pgGame/config/GameConfig.hpp @@ -16,7 +16,6 @@ struct GameConfig GenericConfig options; pg::config::WindowConfig windowConfig; std::vector vfsConfigs; - std::string resourcePrefix; SDL_Rect getWindowRect() { diff --git a/libs/pgGame/core/Game.cpp b/libs/pgGame/core/Game.cpp index d8d25929..13910e4b 100644 --- a/libs/pgGame/core/Game.cpp +++ b/libs/pgGame/core/Game.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -76,7 +75,7 @@ game::Game::Game(pg::game::GameConfig&& config) , _inputEventDispatcher(_sdlApp.getEventHandler(), {}) , _vfs(std::make_unique()) , _resourceManager([this](const pg::foundation::URI& uri) -> pg::foundation::DataProviderPtr { - return std::make_unique(uri, _vfs, _gameConfig.resourcePrefix); + return std::make_unique(uri, _vfs); }) { // register all vfs's diff --git a/libs/pgGame/core/VFSDataProvider.hpp b/libs/pgGame/core/VFSDataProvider.hpp index 9f33980e..5f7234d6 100644 --- a/libs/pgGame/core/VFSDataProvider.hpp +++ b/libs/pgGame/core/VFSDataProvider.hpp @@ -8,21 +8,12 @@ class VFSDataProvider : public foundation::DataProvider { std::shared_ptr _vfs; std::shared_ptr _stream; - std::string _localPrefix; public: - VFSDataProvider(const foundation::URI& uri, - std::shared_ptr vfs, - std::string local_prefix = "") + VFSDataProvider(const foundation::URI& uri, std::shared_ptr vfs) : DataProvider(uri) , _vfs(std::move(vfs)) - , _localPrefix(local_prefix) { - // if (!_file && !_localPrefix.empty()) - // { - // _file = _vfs->OpenFile({_localPrefix, getUri(), false}, {vfspp::IFile::FileMode::Read}); - // } - // if (!_file) { throw std::runtime_error("Cannot open VFS file: " + std::string{getUri()}); } } ~VFSDataProvider() override; From 84fc6db64d3c32c741c2da556fe6138cc81e8e80 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sun, 28 Dec 2025 16:42:24 +0100 Subject: [PATCH 07/15] CMakePresets minimal fixes --- CMakePresets.json | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index ddf2a4fa..92b948d3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,7 +15,7 @@ "installDir": "${sourceDir}/out/install/${presetName}", "cacheVariables": { "CPM_SOURCE_CACHE": "${sourceDir}/out/.cache/cpm/", - //"ENABLE_SANDBOXES": "ON" + "ENABLE_SANDBOXES": "ON" } }, { @@ -114,8 +114,7 @@ "CMAKE_C_COMPILER": "cl", "CMAKE_CXX_COMPILER": "cl", "CMAKE_BUILD_TYPE": "Release", - "ENABLE_DEVELOPER_MODE": "OFF", - + "ENABLE_DEVELOPER_MODE": "OFF" } }, { @@ -126,7 +125,7 @@ "cacheVariables": { "CMAKE_C_COMPILER": "clang-cl", "CMAKE_CXX_COMPILER": "clang-cl", - "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_BUILD_TYPE": "Debug" }, "vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { From 1adc03e8e326134db163831aba0175dcca874a00 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sun, 28 Dec 2025 17:07:30 +0100 Subject: [PATCH 08/15] version bump of worflows --- .github/workflows/checks.yml | 2 +- .github/workflows/cmake.yml | 12 +++++++++--- cmake/deps_cpm.cmake | 2 ++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index bfff3e7e..b3ddcf46 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -7,7 +7,7 @@ jobs: cpp-linter: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: cpp-linter/cpp-linter-action@v2 id: linter env: diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e3515a71..49dfb4a1 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -24,15 +24,21 @@ jobs: steps: - name: Set up cache id: cache-cpm - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/cpm-cache key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }} restore-keys: | ${{ runner.os }}-cpm- - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y ninja-build + - name: Setup GCC - uses: pkgxdev/setup@v1 + uses: pkgxdev/setup@v2 with: +: gcc@14 diff --git a/cmake/deps_cpm.cmake b/cmake/deps_cpm.cmake index 4ae39c4a..2b45fe43 100644 --- a/cmake/deps_cpm.cmake +++ b/cmake/deps_cpm.cmake @@ -20,6 +20,8 @@ CPMAddPackage( GIT_REPOSITORY https://github.com/icculus/physfs GIT_TAG release-3.2.0 SYSTEM ON + OPTIONS "PHYSFS_BUILD_DOCS OFF" + "PHYSFS_TARGETNAME_UNINSTALL uninstall-physfs" ) CPMAddPackage( #zeromq From 38d2025536258b3dde614b2b3a59ee5d37168bb8 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Sun, 28 Dec 2025 20:21:14 +0100 Subject: [PATCH 09/15] fix PhysFSPP --- libs/PhysFSPP/PhysFSPP.hpp | 5 +++++ libs/PhysFSPP/PhysFSPP_File.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/libs/PhysFSPP/PhysFSPP.hpp b/libs/PhysFSPP/PhysFSPP.hpp index 5fd9ac93..9fbbbea5 100644 --- a/libs/PhysFSPP/PhysFSPP.hpp +++ b/libs/PhysFSPP/PhysFSPP.hpp @@ -1,5 +1,10 @@ #pragma once +/* + PhysFSPP: A C++ wrapper for PhysicsFS + Copyright (C) 2024 psyinf (S.Messerschmidt) +*/ + #include #include #include diff --git a/libs/PhysFSPP/PhysFSPP_File.hpp b/libs/PhysFSPP/PhysFSPP_File.hpp index d79c7a1b..b09ab781 100644 --- a/libs/PhysFSPP/PhysFSPP_File.hpp +++ b/libs/PhysFSPP/PhysFSPP_File.hpp @@ -2,6 +2,7 @@ #include #include +#include namespace physfspp { class FileHandle From 08352b28e60b7d34ef06c4ccc832a7bfdc3b2818 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Mon, 29 Dec 2025 17:48:05 +0100 Subject: [PATCH 10/15] build pipeline improvements --- .github/workflows/checks.yml | 5 +- .github/workflows/cmake.yml | 96 ++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index b3ddcf46..fae09c61 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -3,11 +3,13 @@ name: cpp-linter on: pull_request: types: [assigned, opened, synchronize, reopened] + jobs: cpp-linter: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: cpp-linter/cpp-linter-action@v2 id: linter env: @@ -16,7 +18,8 @@ jobs: style: file lines-changed-only: true tidy-checks: -* - version: 16 # todo find minimal viable version + version: 18 + - name: Fail fast?! if: steps.linter.outputs.checks-failed > 0 run: echo "Some files failed the linting checks!" diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 49dfb4a1..717f98ee 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -5,54 +5,88 @@ on: branches: [ "main" ] pull_request: branches: [ "main" ] + concurrency: group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }} cancel-in-progress: true env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) - BUILD_TYPE: Release - CONAN_USER_HOME: "${{ github.workspace }}/release/" - CONAN_USER_HOME_SHORT: "${{ github.workspace }}/release/short" + CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm-cache + jobs: build: strategy: + fail-fast: false matrix: - #version: [10, 12, 14] - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] + build_type: [Debug, Release] + include: + - os: ubuntu-latest + preset: unixlike-gcc-debug + preset_release: unixlike-gcc-release + - os: macos-latest + preset: unixlike-clang-debug + preset_release: unixlike-clang-release + runs-on: ${{ matrix.os }} + steps: - - name: Set up cache - id: cache-cpm + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up CPM cache uses: actions/cache@v4 with: - path: ~/cpm-cache - key: ${{ runner.os }}-cpm-${{ hashFiles('**/') }} - restore-keys: | - ${{ runner.os }}-cpm- - - uses: actions/checkout@v4 - - - name: Install system dependencies + path: ${{ env.CPM_SOURCE_CACHE }} + key: ${{ runner.os }}-cpm-${{ hashFiles('**/CMakeLists.txt', 'cmake/**/*.cmake') }} + restore-keys: | + ${{ runner.os }}-cpm- + + - name: Set up build cache + uses: actions/cache@v4 + with: + path: | + out/build/${{ matrix.build_type == 'Debug' && matrix.preset || matrix.preset_release }} + key: ${{ runner.os }}-build-${{ matrix.build_type }}-${{ hashFiles('**/*.cpp', '**/*.hpp', '**/*.h', '**/*.c') }} + restore-keys: | + ${{ runner.os }}-build-${{ matrix.build_type }}- + ${{ runner.os }}-build- + + - name: Install dependencies (Ubuntu) + if: runner.os == 'Linux' run: | sudo apt-get update - sudo apt-get install -y ninja-build - - - name: Setup GCC - uses: pkgxdev/setup@v2 - with: - +: gcc@14 + sudo apt-get install -y ninja-build gcc-14 g++-14 + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 100 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 100 + + - name: Install dependencies (macOS) + if: runner.os == 'macOS' + run: brew install ninja - name: Configure CMake - # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. - # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCPM_SOURCE_CACHE=~/cpm-cache - + run: | + if [ "${{ matrix.build_type }}" == "Debug" ]; then + cmake --preset=${{ matrix.preset }} + else + cmake --preset=${{ matrix.preset_release }} + fi + shell: bash + - name: Build - # Build your program with the given configuration - run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} + run: | + if [ "${{ matrix.build_type }}" == "Debug" ]; then + cmake --build --preset=${{ matrix.preset }} + else + cmake --build --preset=${{ matrix.preset_release }} + fi + shell: bash - name: Test - working-directory: ${{github.workspace}}/build - # Execute tests defined by the CMake configuration. - # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail - run: ctest -C ${{env.BUILD_TYPE}} + run: | + if [ "${{ matrix.build_type }}" == "Debug" ]; then + ctest --preset=test-${{ matrix.preset }} + else + ctest --preset=test-${{ matrix.preset_release }} + fi + shell: bash From 5e5cf6bf26cf4b2a402a1e9e37904a24a280988c Mon Sep 17 00:00:00 2001 From: psy_inf Date: Mon, 29 Dec 2025 17:48:31 +0100 Subject: [PATCH 11/15] adapted to deprecated funtions in PhysFS --- libs/PhysFSPP/PhysFSPP.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/PhysFSPP/PhysFSPP.hpp b/libs/PhysFSPP/PhysFSPP.hpp index 9fbbbea5..1260e1d4 100644 --- a/libs/PhysFSPP/PhysFSPP.hpp +++ b/libs/PhysFSPP/PhysFSPP.hpp @@ -56,14 +56,14 @@ class VirtualFileSystem throw VirtualFileSystemException("Invalid file open mode"); } - if (f == nullptr) { throw VirtualFileSystemException(PHYSFS_getLastError()); } + if (f == nullptr) { throw VirtualFileSystemException(PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); } return FileHandle{f}; } private: void handleError(int res) { - if (res == 0) { throw VirtualFileSystemException(PHYSFS_getLastError()); } + if (res == 0) { throw VirtualFileSystemException(PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); } } }; } // namespace physfspp From 896cd76bf282ef54088d1246239d986c39039549 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Mon, 29 Dec 2025 17:49:19 +0100 Subject: [PATCH 12/15] move to 4.7.0 btcpp --- apps/galaxy/behaviors/GetTargetsAvailable.hpp | 1 + cmake/deps_cpm.cmake | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/galaxy/behaviors/GetTargetsAvailable.hpp b/apps/galaxy/behaviors/GetTargetsAvailable.hpp index 22c32854..819d42e3 100644 --- a/apps/galaxy/behaviors/GetTargetsAvailable.hpp +++ b/apps/galaxy/behaviors/GetTargetsAvailable.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace BT { diff --git a/cmake/deps_cpm.cmake b/cmake/deps_cpm.cmake index 2b45fe43..61e6cfa7 100644 --- a/cmake/deps_cpm.cmake +++ b/cmake/deps_cpm.cmake @@ -59,7 +59,8 @@ set (BTCPP_EXTRA_LIBRARIES libzmq-static) CPMAddPackage( Name btcpp GITHUB_REPOSITORY BehaviorTree/BehaviorTree.CPP - GIT_TAG a44619cd8871c484f5c4b24f9958302455f19211 + GIT_TAG 4.7.0 + #a44619cd8871c484f5c4b24f9958302455f19211 SYSTEM TRUE OPTIONS "BTCPP_SHARED_LIBS OFF" @@ -68,6 +69,7 @@ CPMAddPackage( "BTCPP_UNIT_TESTS OFF" "BTCPP_GROOT_INTERFACE ON" "BTCPP_SQLITE_LOGGING OFF" + "BUILD_TESTING OFF" ) From 211f970b34ac11cd836babbda6515b93d9315d74 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Tue, 30 Dec 2025 17:56:49 +0100 Subject: [PATCH 13/15] adapt warnings setup for gcc adapt to fixed constnes --- CMakeLists.txt | 5 +++-- libs/pgEngine/CMakeLists.txt | 3 ++- libs/pgGame/core/VFSDataProvider.cpp | 2 +- libs/pgGame/core/VFSDataProvider.hpp | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bc5cfe15..870fef48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") #add_compile_options(/W4 /WX) add_compile_options(/W3) add_compile_options(/bigobj) -else() - #add_compile_options(-Wall -Wextra -Wpedantic -Werror -Wno-c++98-compat -Wno-c++98-compat-pedantic) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") add_compile_options(-Wall -Wno-c++98-compat -Wno-c++98-compat-pedantic) +else() + add_compile_options(-Wall) endif() #options option(ENABLE_COVERAGE "Enable coverage" OFF) diff --git a/libs/pgEngine/CMakeLists.txt b/libs/pgEngine/CMakeLists.txt index 07f18c54..79100a11 100644 --- a/libs/pgEngine/CMakeLists.txt +++ b/libs/pgEngine/CMakeLists.txt @@ -75,4 +75,5 @@ target_include_directories( ) target_compile_options(${PROJECT_NAME} PRIVATE $<$:/W4>) -target_compile_options(${PROJECT_NAME} PRIVATE $<$>:-Wall -Wextra -pedantic -Wno-c++98-compat>) +target_compile_options(${PROJECT_NAME} PRIVATE $<$>:-Wall -Wextra -pedantic>) +target_compile_options(${PROJECT_NAME} PRIVATE $<$:-Wno-c++98-compat>) diff --git a/libs/pgGame/core/VFSDataProvider.cpp b/libs/pgGame/core/VFSDataProvider.cpp index 78e21c23..a367fb43 100644 --- a/libs/pgGame/core/VFSDataProvider.cpp +++ b/libs/pgGame/core/VFSDataProvider.cpp @@ -46,7 +46,7 @@ std::span pg::VFSDataProvider::asSpan() throw std::runtime_error("Not implemented"); } -size_t pg::VFSDataProvider::size() +size_t pg::VFSDataProvider::size() const { // return _file->Size(); throw std::runtime_error("Not implemented"); diff --git a/libs/pgGame/core/VFSDataProvider.hpp b/libs/pgGame/core/VFSDataProvider.hpp index 5f7234d6..1899fe52 100644 --- a/libs/pgGame/core/VFSDataProvider.hpp +++ b/libs/pgGame/core/VFSDataProvider.hpp @@ -24,6 +24,6 @@ class VFSDataProvider : public foundation::DataProvider void toBuffer(std::vector& buffer, size_t max_ch) override; char readNext() override; std::span asSpan() override; - size_t size() override; + size_t size() const override; }; } // namespace pg From 843bf4ece7c339578fba2868d235d66ebc7a220e Mon Sep 17 00:00:00 2001 From: psy_inf Date: Tue, 30 Dec 2025 18:24:35 +0100 Subject: [PATCH 14/15] adapt warnings setup for gcc adapt to fixed constnes --- libs/pgEngine/math/VecOps.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/pgEngine/math/VecOps.hpp b/libs/pgEngine/math/VecOps.hpp index aa223edd..a3d8ad08 100644 --- a/libs/pgEngine/math/VecOps.hpp +++ b/libs/pgEngine/math/VecOps.hpp @@ -3,6 +3,7 @@ #include #include +#include namespace pg { From 3efa71734560c8cc2b4d8a3e7241b411a45223a4 Mon Sep 17 00:00:00 2001 From: psy_inf Date: Tue, 30 Dec 2025 22:47:23 +0100 Subject: [PATCH 15/15] fixed warnings for externals fix build and link of tests --- CMakeLists.txt | 4 ++- cmake/disable_3rd_party_warnings.cmake | 39 ++++++++++++++++++++++++-- tests/CMakeLists.txt | 13 ++++++++- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 870fef48..2f781044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,6 @@ include(cmake/stacktrace.cmake) include(cmake/setup_cpm.cmake) include(cmake/deps_cpm.cmake) include(cmake/disable_3rd_party_warnings.cmake) -make_all_targets_system() enable_testing() @@ -35,6 +34,9 @@ add_subdirectory(libs) add_subdirectory(apps) add_subdirectory(tests) add_subdirectory(tools) + +# Apply system includes to all external dependencies after they're all loaded +make_all_targets_system() install(DIRECTORY data/ DESTINATION diff --git a/cmake/disable_3rd_party_warnings.cmake b/cmake/disable_3rd_party_warnings.cmake index 38b3c15e..33277cef 100644 --- a/cmake/disable_3rd_party_warnings.cmake +++ b/cmake/disable_3rd_party_warnings.cmake @@ -1,3 +1,19 @@ +# Store warning suppression flags for external dependencies +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(EXTERNAL_PROJECT_COMPILE_OPTIONS + -Wno-deprecated-declarations # For std::aligned_storage in BehaviorTree.cpp + -Wno-dangling-pointer # For FreeType pointer warnings + -Wno-misleading-indentation # For miniz.h in SDL_image + -Wno-unused-but-set-variable # For stb_image unused variables + -Wno-stringop-overflow # For stb_image string operations + -Wno-stringop-truncation # For PhysFS strncpy + -Wno-conversion # For OpenAL bitfield conversions + -Wno-sign-compare # For soundEngine size comparisons + -Wno-unknown-pragmas # For MSVC pragmas in soundEngine + -Wno-unused-variable # For unused variables in soundEngine + ) +endif() + function(get_all_targets var) set(targets) get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR}) @@ -18,8 +34,25 @@ function(make_all_targets_system) get_all_targets(all_targets) foreach(target ${all_targets}) - get_property(${target}_include_dirs TARGET ${target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - set_property(TARGET ${target} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${${target}_include_dirs}) - set_target_properties(${target} PROPERTIES SYSTEM TRUE) + get_target_property(target_type ${target} TYPE) + get_target_property(target_source_dir ${target} SOURCE_DIR) + + # Check if target is from CPM cache (external dependency) + string(FIND "${target_source_dir}" "/.cache/cpm/" is_external) + + # Skip INTERFACE and UTILITY targets + if(NOT target_type MATCHES "INTERFACE_LIBRARY|UTILITY") + # Mark as system includes + get_property(${target}_include_dirs TARGET ${target} PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + if(${target}_include_dirs) + set_property(TARGET ${target} PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${${target}_include_dirs}) + endif() + set_target_properties(${target} PROPERTIES SYSTEM TRUE) + + # Apply warning suppression to external targets + if(is_external GREATER -1 AND EXTERNAL_PROJECT_COMPILE_OPTIONS) + target_compile_options(${target} PRIVATE ${EXTERNAL_PROJECT_COMPILE_OPTIONS}) + endif() + endif() endforeach() endfunction() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e024b6e9..fa1a5a3f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,18 @@ if(BUILD_TESTING) get_filename_component( target ${testsourcefile} NAME_WE ) add_executable( ${target} ${testsourcefile} ) # Make sure YourLib is linked to each app - set_target_properties(${target} PROPERTIES CXX_EXTENSIONS OFF) + set_target_properties(${target} PROPERTIES + CXX_EXTENSIONS OFF + BUILD_RPATH "${CMAKE_BINARY_DIR}/_deps/openal-build" + # The main project globally skips RPATH; keep it enabled for tests so bundled OpenAL is found + SKIP_RPATH FALSE + SKIP_BUILD_RPATH FALSE + INSTALL_RPATH_USE_LINK_PATH TRUE + ) + if(UNIX AND NOT APPLE) + # Ensure the built OpenAL shared library is discoverable at runtime for test binaries + target_link_options(${target} PRIVATE -Wl,-rpath,${CMAKE_BINARY_DIR}/_deps/openal-build) + endif() target_compile_features(${target} PUBLIC cxx_std_20) target_compile_options(${target} PRIVATE ${DEFAULT_COMPILER_OPTIONS_AND_WARNINGS}) target_link_libraries(${target} PRIVATE testMain pgEngine::pgEngine pgGame::pgGame nlohmann_json::nlohmann_json INTERFACE pgOrbit::pgOrbit)