diff --git a/config.ini b/config.ini new file mode 100644 index 0000000000..8af213bef4 --- /dev/null +++ b/config.ini @@ -0,0 +1,15 @@ +; Put public-facing settings here, such as graphics definitions supported by the client. +; This section can also expose options intended for modding, including font customization. + +[graphics] + +; ===== Atlas configuration ===== +; maxAtlasSize: hard cap for atlas textures (in pixels). +maxAtlasSize = 8192 + +; Atlas sizes (in pixels): +; 0 = auto-detect based on the maximum texture size supported by the GPU +; -1 = disable the atlas +mapAtlasSize = 0 +foregroundAtlasSize = 2048 +; =============================== \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e14d51ceb..7b2cdbcd2b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -132,6 +132,7 @@ find_package(ZLIB REQUIRED) find_package(httplib CONFIG REQUIRED) find_package(fmt CONFIG REQUIRED) find_package(utf8cpp REQUIRED) +find_package(unofficial-inih CONFIG REQUIRED) find_path(CPPCODEC_INCLUDE_DIRS "cppcodec/base32_crockford.hpp") @@ -388,6 +389,9 @@ if (WASM) endif() add_library(otclient_core STATIC ${SOURCE_FILES}) + +target_link_libraries(otclient_core PRIVATE unofficial::inih::inireader) + if(NOT MSVC) target_link_options(otclient_core PUBLIC -flto=auto) endif() diff --git a/src/framework/core/configmanager.cpp b/src/framework/core/configmanager.cpp index 11663a938b..970d195ad9 100644 --- a/src/framework/core/configmanager.cpp +++ b/src/framework/core/configmanager.cpp @@ -21,10 +21,17 @@ */ #include "configmanager.h" +#include +#include "resourcemanager.h" ConfigManager g_configs; -void ConfigManager::init() { m_settings = std::make_shared(); } +void ConfigManager::init() { + m_settings = std::make_shared(); + + // Comment out or remove this line to skip loading config.ini. + loadPublicConfig("config.ini"); +} void ConfigManager::terminate() { @@ -116,4 +123,22 @@ bool ConfigManager::unload(const std::string& file) return false; } -void ConfigManager::remove(const ConfigPtr& config) { m_configs.remove(config); } \ No newline at end of file +void ConfigManager::remove(const ConfigPtr& config) { m_configs.remove(config); } + +void ConfigManager::loadPublicConfig(const std::string& fileName) { + try { + auto content = g_resources.readFileContents(fileName); + INIReader reader(content.c_str(), content.size()); + + if (reader.ParseError() < 0) { + g_logger.error("Failed to read config otml '{}''", fileName); + return; + } + + m_publicConfig.graphics.maxAtlasSize = std::max(2048, reader.GetInteger("graphics", "maxAtlasSize", m_publicConfig.graphics.maxAtlasSize)); + m_publicConfig.graphics.mapAtlasSize = reader.GetInteger("graphics", "mapAtlasSize", m_publicConfig.graphics.mapAtlasSize); + m_publicConfig.graphics.foregroundAtlasSize = reader.GetInteger("graphics", "foregroundAtlasSize", m_publicConfig.graphics.foregroundAtlasSize); + } catch (const std::exception& e) { + g_logger.error("Failed to parse public config '{}': {}", fileName, e.what()); + } +} \ No newline at end of file diff --git a/src/framework/core/configmanager.h b/src/framework/core/configmanager.h index bb542a06d7..507463f5bb 100644 --- a/src/framework/core/configmanager.h +++ b/src/framework/core/configmanager.h @@ -24,7 +24,19 @@ #include "config.h" - // @bindsingleton g_configs +struct GraphicsConfig +{ + uint16_t maxAtlasSize = 8192; + int16_t mapAtlasSize = 0; + int16_t foregroundAtlasSize = 2048; +}; + +struct PublicConfig +{ + GraphicsConfig graphics; +}; + +// @bindsingleton g_configs class ConfigManager { public: @@ -41,11 +53,15 @@ class ConfigManager bool unload(const std::string& file); void remove(const ConfigPtr& config); + const PublicConfig& getPublicConfig() const { return m_publicConfig; } + void loadPublicConfig(const std::string& file); + protected: ConfigPtr m_settings; private: std::list m_configs; + PublicConfig m_publicConfig; }; extern ConfigManager g_configs; diff --git a/src/framework/graphics/drawpoolmanager.cpp b/src/framework/graphics/drawpoolmanager.cpp index c5ed0c4ea1..2efc3e829b 100644 --- a/src/framework/graphics/drawpoolmanager.cpp +++ b/src/framework/graphics/drawpoolmanager.cpp @@ -25,6 +25,7 @@ #include "graphics.h" #include "painter.h" #include "textureatlas.h" +#include thread_local static uint8_t CURRENT_POOL = static_cast(DrawPoolType::LAST); @@ -39,8 +40,17 @@ void DrawPoolManager::init(const uint16_t spriteSize) if (spriteSize != 0) m_spriteSize = spriteSize; - auto atlasMap = std::make_shared(Fw::TextureAtlasType::MAP, g_graphics.getMaxTextureSize()); - auto atlasForeground = std::make_shared(Fw::TextureAtlasType::FOREGROUND, 2048, true); + auto mapAtlasSize = g_configs.getPublicConfig().graphics.mapAtlasSize; + auto foregroundAtlasSize = g_configs.getPublicConfig().graphics.foregroundAtlasSize; + + if (mapAtlasSize == 0) + mapAtlasSize = g_graphics.getMaxTextureSize(); + + if (foregroundAtlasSize == 0) + foregroundAtlasSize = g_graphics.getMaxTextureSize(); + + auto atlasMap = mapAtlasSize > 0 ? std::make_shared(Fw::TextureAtlasType::MAP, mapAtlasSize) : nullptr; + auto atlasForeground = foregroundAtlasSize > 0 ? std::make_shared(Fw::TextureAtlasType::FOREGROUND, foregroundAtlasSize, true) : nullptr; // Create Pools for (int8_t i = -1; ++i < static_cast(DrawPoolType::LAST);) { diff --git a/src/framework/graphics/textureatlas.cpp b/src/framework/graphics/textureatlas.cpp index bcd678ebee..bfc405a3a6 100644 --- a/src/framework/graphics/textureatlas.cpp +++ b/src/framework/graphics/textureatlas.cpp @@ -2,6 +2,7 @@ #include "textureatlas.h" #include "painter.h" +#include // Extra padding around smooth textures to avoid sampling artifacts (in pixels) static constexpr uint8_t SMOOTH_PADDING = 2; @@ -15,7 +16,7 @@ static constexpr int MIN_PADDED_ATLAS_TEXTURE_SIZE = 4 + SMOOTH_PADDING * 2; TextureAtlas::TextureAtlas(Fw::TextureAtlasType type, int size, bool smoothSupport) : m_type(type), - m_size({ std::min(size, 8192) }) { + m_size({ std::min(size, g_configs.getPublicConfig().graphics.maxAtlasSize) }) { createNewLayer(false); if (smoothSupport) createNewLayer(true); diff --git a/vcpkg.json b/vcpkg.json index e13cbae3a8..b6e0e73671 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -23,7 +23,8 @@ "bshoshany-thread-pool", "fmt", "utfcpp", - "gtest", + "gtest", + { "name": "inih", "features": ["cpp"] }, { "name": "luajit", "platform": "!android & !wasm32"