Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -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
; ===============================
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand Down
29 changes: 27 additions & 2 deletions src/framework/core/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
*/

#include "configmanager.h"
#include <INIReader.h>
#include "resourcemanager.h"

ConfigManager g_configs;

void ConfigManager::init() { m_settings = std::make_shared<Config>(); }
void ConfigManager::init() {
m_settings = std::make_shared<Config>();

// Comment out or remove this line to skip loading config.ini.
loadPublicConfig("config.ini");
}

void ConfigManager::terminate()
{
Expand Down Expand Up @@ -116,4 +123,22 @@ bool ConfigManager::unload(const std::string& file)
return false;
}

void ConfigManager::remove(const ConfigPtr& config) { m_configs.remove(config); }
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<int>(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());
}
}
18 changes: 17 additions & 1 deletion src/framework/core/configmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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<ConfigPtr> m_configs;
PublicConfig m_publicConfig;
};

extern ConfigManager g_configs;
14 changes: 12 additions & 2 deletions src/framework/graphics/drawpoolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "graphics.h"
#include "painter.h"
#include "textureatlas.h"
#include <framework/core/configmanager.h>

thread_local static uint8_t CURRENT_POOL = static_cast<uint8_t>(DrawPoolType::LAST);

Expand All @@ -39,8 +40,17 @@ void DrawPoolManager::init(const uint16_t spriteSize)
if (spriteSize != 0)
m_spriteSize = spriteSize;

auto atlasMap = std::make_shared<TextureAtlas>(Fw::TextureAtlasType::MAP, g_graphics.getMaxTextureSize());
auto atlasForeground = std::make_shared<TextureAtlas>(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<TextureAtlas>(Fw::TextureAtlasType::MAP, mapAtlasSize) : nullptr;
auto atlasForeground = foregroundAtlasSize > 0 ? std::make_shared<TextureAtlas>(Fw::TextureAtlasType::FOREGROUND, foregroundAtlasSize, true) : nullptr;

// Create Pools
for (int8_t i = -1; ++i < static_cast<uint8_t>(DrawPoolType::LAST);) {
Expand Down
3 changes: 2 additions & 1 deletion src/framework/graphics/textureatlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "textureatlas.h"

#include "painter.h"
#include <framework/core/configmanager.h>

// Extra padding around smooth textures to avoid sampling artifacts (in pixels)
static constexpr uint8_t SMOOTH_PADDING = 2;
Expand All @@ -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<int>(size, 8192) }) {
m_size({ std::min<int>(size, g_configs.getPublicConfig().graphics.maxAtlasSize) }) {
createNewLayer(false);
if (smoothSupport)
createNewLayer(true);
Expand Down
3 changes: 2 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"bshoshany-thread-pool",
"fmt",
"utfcpp",
"gtest",
"gtest",
{ "name": "inih", "features": ["cpp"] },
{
"name": "luajit",
"platform": "!android & !wasm32"
Expand Down
Loading