From 91aacafecbc7b831cc0f766e2a405a52421dbbe7 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Mon, 6 May 2024 01:36:21 +0300 Subject: [PATCH] hpp++ --- src/assets/AssetsLoader.cpp | 2 +- src/assets/AssetsLoader.h | 113 ------------------ src/assets/AssetsLoader.hpp | 113 ++++++++++++++++++ src/assets/assetload_funcs.cpp | 4 +- src/coders/GLSLExtension.cpp | 10 +- .../{GLSLExtension.h => GLSLExtension.hpp} | 6 +- src/engine.cpp | 4 +- src/graphics/core/Shader.cpp | 2 +- src/logic/scripting/lua/libpack.cpp | 6 +- src/logic/scripting/lua/libworld.cpp | 3 +- 10 files changed, 133 insertions(+), 130 deletions(-) delete mode 100644 src/assets/AssetsLoader.h create mode 100644 src/assets/AssetsLoader.hpp rename src/coders/{GLSLExtension.h => GLSLExtension.hpp} (90%) diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp index 374c67d5..412afc04 100644 --- a/src/assets/AssetsLoader.cpp +++ b/src/assets/AssetsLoader.cpp @@ -1,4 +1,4 @@ -#include "AssetsLoader.h" +#include "AssetsLoader.hpp" #include "Assets.h" #include "assetload_funcs.hpp" diff --git a/src/assets/AssetsLoader.h b/src/assets/AssetsLoader.h deleted file mode 100644 index 937bc1b6..00000000 --- a/src/assets/AssetsLoader.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef ASSETS_ASSETS_LOADER_H -#define ASSETS_ASSETS_LOADER_H - -#include "Assets.h" -#include "../interfaces/Task.hpp" -#include "../typedefs.h" -#include "../delegates.h" - -#include -#include -#include -#include -#include -#include - -namespace dynamic { - class Map; - class List; -} - -enum class AssetType { - texture, - shader, - font, - atlas, - layout, - sound -}; - -class ResPaths; -class AssetsLoader; -class Content; - -struct AssetCfg { - virtual ~AssetCfg() {} -}; - -struct LayoutCfg : AssetCfg { - scriptenv env; - - LayoutCfg(scriptenv env) : env(env) {} -}; - -struct SoundCfg : AssetCfg { - bool keepPCM; - - SoundCfg(bool keepPCM) : keepPCM(keepPCM) {} -}; - -using aloader_func = std::function) ->; - -struct aloader_entry { - AssetType tag; - const std::string filename; - const std::string alias; - std::shared_ptr config; -}; - -class AssetsLoader { - Assets* assets; - std::map loaders; - std::queue entries; - const ResPaths* paths; - - void tryAddSound(std::string name); - - void processPreload(AssetType tag, const std::string& name, dynamic::Map* map); - void processPreloadList(AssetType tag, dynamic::List* list); - void processPreloadConfig(std::filesystem::path file); - void processPreloadConfigs(const Content* content); -public: - AssetsLoader(Assets* assets, const ResPaths* paths); - void addLoader(AssetType tag, aloader_func func); - - /// @brief Enqueue asset load - /// @param tag asset type - /// @param filename asset file path - /// @param alias internal asset name - /// @param settings asset loading settings (based on asset type) - void add( - AssetType tag, - const std::string filename, - const std::string alias, - std::shared_ptr settings=nullptr - ); - - bool hasNext() const; - bool loadNext(); - - std::shared_ptr startTask(runnable onDone); - - const ResPaths* getPaths() const; - aloader_func getLoader(AssetType tag); - - /// @brief Enqueue core and content assets - /// @param loader target loader - /// @param content engine content - static void addDefaults(AssetsLoader& loader, const Content* content); - - static bool loadExternalTexture( - Assets* assets, - const std::string& name, - std::vector alternatives - ); -}; - -#endif // ASSETS_ASSETS_LOADER_H diff --git a/src/assets/AssetsLoader.hpp b/src/assets/AssetsLoader.hpp new file mode 100644 index 00000000..5138563f --- /dev/null +++ b/src/assets/AssetsLoader.hpp @@ -0,0 +1,113 @@ +#ifndef ASSETS_ASSETS_LOADER_HPP_ +#define ASSETS_ASSETS_LOADER_HPP_ + +#include "Assets.h" +#include "../interfaces/Task.hpp" +#include "../typedefs.h" +#include "../delegates.h" + +#include +#include +#include +#include +#include +#include + +namespace dynamic { + class Map; + class List; +} + +enum class AssetType { + texture, + shader, + font, + atlas, + layout, + sound +}; + +class ResPaths; +class AssetsLoader; +class Content; + +struct AssetCfg { + virtual ~AssetCfg() {} +}; + +struct LayoutCfg : AssetCfg { + scriptenv env; + + LayoutCfg(scriptenv env) : env(env) {} +}; + +struct SoundCfg : AssetCfg { + bool keepPCM; + + SoundCfg(bool keepPCM) : keepPCM(keepPCM) {} +}; + +using aloader_func = std::function) +>; + +struct aloader_entry { + AssetType tag; + const std::string filename; + const std::string alias; + std::shared_ptr config; +}; + +class AssetsLoader { + Assets* assets; + std::map loaders; + std::queue entries; + const ResPaths* paths; + + void tryAddSound(std::string name); + + void processPreload(AssetType tag, const std::string& name, dynamic::Map* map); + void processPreloadList(AssetType tag, dynamic::List* list); + void processPreloadConfig(std::filesystem::path file); + void processPreloadConfigs(const Content* content); +public: + AssetsLoader(Assets* assets, const ResPaths* paths); + void addLoader(AssetType tag, aloader_func func); + + /// @brief Enqueue asset load + /// @param tag asset type + /// @param filename asset file path + /// @param alias internal asset name + /// @param settings asset loading settings (based on asset type) + void add( + AssetType tag, + const std::string filename, + const std::string alias, + std::shared_ptr settings=nullptr + ); + + bool hasNext() const; + bool loadNext(); + + std::shared_ptr startTask(runnable onDone); + + const ResPaths* getPaths() const; + aloader_func getLoader(AssetType tag); + + /// @brief Enqueue core and content assets + /// @param loader target loader + /// @param content engine content + static void addDefaults(AssetsLoader& loader, const Content* content); + + static bool loadExternalTexture( + Assets* assets, + const std::string& name, + std::vector alternatives + ); +}; + +#endif // ASSETS_ASSETS_LOADER_HPP_ diff --git a/src/assets/assetload_funcs.cpp b/src/assets/assetload_funcs.cpp index 18379942..c830c7b5 100644 --- a/src/assets/assetload_funcs.cpp +++ b/src/assets/assetload_funcs.cpp @@ -1,13 +1,13 @@ #include "assetload_funcs.hpp" #include "Assets.h" -#include "AssetsLoader.h" +#include "AssetsLoader.hpp" #include "../audio/audio.hpp" #include "../files/files.h" #include "../files/engine_paths.h" #include "../coders/imageio.hpp" #include "../coders/json.h" -#include "../coders/GLSLExtension.h" +#include "../coders/GLSLExtension.hpp" #include "../graphics/core/Shader.hpp" #include "../graphics/core/Texture.hpp" #include "../graphics/core/ImageData.hpp" diff --git a/src/coders/GLSLExtension.cpp b/src/coders/GLSLExtension.cpp index 0aa9dacb..210b7ada 100644 --- a/src/coders/GLSLExtension.cpp +++ b/src/coders/GLSLExtension.cpp @@ -1,12 +1,14 @@ -#include "GLSLExtension.h" -#include -#include -#include +#include "GLSLExtension.hpp" + #include "../util/stringutil.h" #include "../typedefs.h" #include "../files/files.h" #include "../files/engine_paths.h" +#include +#include +#include + namespace fs = std::filesystem; void GLSLExtension::setVersion(std::string version) { diff --git a/src/coders/GLSLExtension.h b/src/coders/GLSLExtension.hpp similarity index 90% rename from src/coders/GLSLExtension.h rename to src/coders/GLSLExtension.hpp index b5344f67..2a106d38 100644 --- a/src/coders/GLSLExtension.h +++ b/src/coders/GLSLExtension.hpp @@ -1,5 +1,5 @@ -#ifndef CODERS_GLSL_EXTESION_H_ -#define CODERS_GLSL_EXTESION_H_ +#ifndef CODERS_GLSL_EXTESION_HPP_ +#define CODERS_GLSL_EXTESION_HPP_ #include #include @@ -35,4 +35,4 @@ public: ); }; -#endif // CODERS_GLSL_EXTESION_H_ +#endif // CODERS_GLSL_EXTESION_HPP_ diff --git a/src/engine.cpp b/src/engine.cpp index 138717fa..b50da984 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -3,9 +3,9 @@ #define GLEW_STATIC #include "debug/Logger.hpp" -#include "assets/AssetsLoader.h" +#include "assets/AssetsLoader.hpp" #include "audio/audio.hpp" -#include "coders/GLSLExtension.h" +#include "coders/GLSLExtension.hpp" #include "coders/imageio.hpp" #include "coders/json.h" #include "coders/toml.hpp" diff --git a/src/graphics/core/Shader.cpp b/src/graphics/core/Shader.cpp index 10531c34..b6bb6802 100644 --- a/src/graphics/core/Shader.cpp +++ b/src/graphics/core/Shader.cpp @@ -11,7 +11,7 @@ #include #include -#include "../../coders/GLSLExtension.h" +#include "../../coders/GLSLExtension.hpp" namespace fs = std::filesystem; diff --git a/src/logic/scripting/lua/libpack.cpp b/src/logic/scripting/lua/libpack.cpp index bc5a4c1f..a2d043c7 100644 --- a/src/logic/scripting/lua/libpack.cpp +++ b/src/logic/scripting/lua/libpack.cpp @@ -1,8 +1,9 @@ #include "api_lua.hpp" #include "lua_commons.hpp" + #include "../scripting.h" #include "../../../engine.h" -#include "../../../assets/AssetsLoader.h" +#include "../../../assets/AssetsLoader.hpp" #include "../../../files/engine_paths.h" #include "../../../files/WorldFiles.h" #include "../../../world/Level.h" @@ -15,8 +16,7 @@ static int l_pack_get_folder(lua_State* L) { std::string packName = lua_tostring(L, 1); if (packName == "core") { - auto folder = scripting::engine->getPaths() - ->getResources().u8string()+"/"; + auto folder = scripting::engine->getPaths()->getResources().u8string()+"/"; lua_pushstring(L, folder.c_str()); return 1; } diff --git a/src/logic/scripting/lua/libworld.cpp b/src/logic/scripting/lua/libworld.cpp index b753b0bc..8606c863 100644 --- a/src/logic/scripting/lua/libworld.cpp +++ b/src/logic/scripting/lua/libworld.cpp @@ -1,8 +1,9 @@ #include "lua_commons.hpp" #include "api_lua.hpp" + #include "../scripting.h" #include "../../../assets/Assets.h" -#include "../../../assets/AssetsLoader.h" +#include "../../../assets/AssetsLoader.hpp" #include "../../../files/engine_paths.h" #include "../../../world/Level.h" #include "../../../world/World.h"