format: reformat project

Signed-off-by: Vyacheslav Ivanov <islavaivanov76@gmail.com>
This commit is contained in:
Vyacheslav Ivanov
2024-08-03 19:53:48 +03:00
committed by Pugemon
parent 736cd175d5
commit bbf33e8e4d
202 changed files with 7389 additions and 5609 deletions
+19 -28
View File
@@ -1,29 +1,21 @@
#ifndef ASSETS_ASSETS_HPP_
#define ASSETS_ASSETS_HPP_
#include "../graphics/core/TextureAnimation.hpp"
#include <string>
#include <memory>
#include <stdexcept>
#include <optional>
#include <functional>
#include <unordered_map>
#include <memory>
#include <optional>
#include <stdexcept>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#include "../graphics/core/TextureAnimation.hpp"
class Assets;
enum class AssetType {
TEXTURE,
SHADER,
FONT,
ATLAS,
LAYOUT,
SOUND,
MODEL
};
enum class AssetType { TEXTURE, SHADER, FONT, ATLAS, LAYOUT, SOUND, MODEL };
namespace assetload {
/// @brief final work to do in the main thread
@@ -31,7 +23,7 @@ namespace assetload {
using setupfunc = std::function<void(const Assets*)>;
template<class T>
template <class T>
void assets_setup(const Assets*);
class error : public std::runtime_error {
@@ -39,12 +31,11 @@ namespace assetload {
std::string filename;
std::string reason;
public:
error(
AssetType type, std::string filename, std::string reason
) : std::runtime_error(filename + ": " + reason),
type(type),
filename(std::move(filename)),
reason(std::move(reason)) {
error(AssetType type, std::string filename, std::string reason)
: std::runtime_error(filename + ": " + reason),
type(type),
filename(std::move(filename)),
reason(std::move(reason)) {
}
AssetType getAssetType() const {
@@ -75,12 +66,12 @@ public:
const std::vector<TextureAnimation>& getAnimations();
void store(const TextureAnimation& animation);
template<class T>
template <class T>
void store(std::unique_ptr<T> asset, const std::string& name) {
assets[typeid(T)][name].reset(asset.release());
}
template<class T>
template <class T>
T* get(const std::string& name) const {
const auto& mapIter = assets.find(typeid(T));
if (mapIter == assets.end()) {
@@ -94,7 +85,7 @@ public:
return static_cast<T*>(found->second.get());
}
template<class T>
template <class T>
std::optional<const assets_map*> getMap() const {
const auto& mapIter = assets.find(typeid(T));
if (mapIter == assets.end()) {
@@ -114,7 +105,7 @@ public:
}
};
template<class T>
template <class T>
void assetload::assets_setup(const Assets* assets) {
if (auto mapPtr = assets->getMap<T>()) {
for (const auto& entry : **mapPtr) {
@@ -123,4 +114,4 @@ void assetload::assets_setup(const Assets* assets) {
}
}
#endif // ASSETS_ASSETS_HPP_
#endif // ASSETS_ASSETS_HPP_
+90 -59
View File
@@ -1,30 +1,29 @@
#include "AssetsLoader.hpp"
#include "Assets.hpp"
#include "assetload_funcs.hpp"
#include "../util/ThreadPool.hpp"
#include "../constants.hpp"
#include "../data/dynamic.hpp"
#include "../debug/Logger.hpp"
#include "../coders/imageio.hpp"
#include "../files/files.hpp"
#include "../files/engine_paths.hpp"
#include "../content/Content.hpp"
#include "../content/ContentPack.hpp"
#include "../voxels/Block.hpp"
#include "../objects/rigging.hpp"
#include "../graphics/core/Texture.hpp"
#include "../logic/scripting/scripting.hpp"
#include <iostream>
#include <memory>
#include <utility>
#include "../coders/imageio.hpp"
#include "../constants.hpp"
#include "../content/Content.hpp"
#include "../content/ContentPack.hpp"
#include "../data/dynamic.hpp"
#include "../debug/Logger.hpp"
#include "../files/engine_paths.hpp"
#include "../files/files.hpp"
#include "../graphics/core/Texture.hpp"
#include "../logic/scripting/scripting.hpp"
#include "../objects/rigging.hpp"
#include "../util/ThreadPool.hpp"
#include "../voxels/Block.hpp"
#include "Assets.hpp"
#include "assetload_funcs.hpp"
static debug::Logger logger("assets-loader");
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
: assets(assets), paths(paths)
{
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
: assets(assets), paths(paths) {
addLoader(AssetType::SHADER, assetload::shader);
addLoader(AssetType::TEXTURE, assetload::texture);
addLoader(AssetType::FONT, assetload::font);
@@ -38,8 +37,13 @@ void AssetsLoader::addLoader(AssetType tag, aloader_func func) {
loaders[tag] = std::move(func);
}
void AssetsLoader::add(AssetType tag, const std::string& filename, const std::string& alias, std::shared_ptr<AssetCfg> settings) {
entries.push(aloader_entry{tag, filename, alias, std::move(settings)});
void AssetsLoader::add(
AssetType tag,
const std::string& filename,
const std::string& alias,
std::shared_ptr<AssetCfg> settings
) {
entries.push(aloader_entry {tag, filename, alias, std::move(settings)});
}
bool AssetsLoader::hasNext() const {
@@ -50,7 +54,7 @@ aloader_func AssetsLoader::getLoader(AssetType tag) {
auto found = loaders.find(tag);
if (found == loaders.end()) {
throw std::runtime_error(
"unknown asset tag "+std::to_string(static_cast<int>(tag))
"unknown asset tag " + std::to_string(static_cast<int>(tag))
);
}
return found->second;
@@ -61,7 +65,8 @@ void AssetsLoader::loadNext() {
logger.info() << "loading " << entry.filename << " as " << entry.alias;
try {
aloader_func loader = getLoader(entry.tag);
auto postfunc = loader(this, paths, entry.filename, entry.alias, entry.config);
auto postfunc =
loader(this, paths, entry.filename, entry.alias, entry.config);
postfunc(assets);
entries.pop();
} catch (std::runtime_error& err) {
@@ -74,16 +79,25 @@ void AssetsLoader::loadNext() {
}
}
void addLayouts(const scriptenv& env, const std::string& prefix, const fs::path& folder, AssetsLoader& loader) {
void addLayouts(
const scriptenv& env,
const std::string& prefix,
const fs::path& folder,
AssetsLoader& loader
) {
if (!fs::is_directory(folder)) {
return;
}
for (auto& entry : fs::directory_iterator(folder)) {
const fs::path& file = entry.path();
if (file.extension().u8string() != ".xml")
continue;
std::string name = prefix+":"+file.stem().u8string();
loader.add(AssetType::LAYOUT, file.u8string(), name, std::make_shared<LayoutCfg>(env));
if (file.extension().u8string() != ".xml") continue;
std::string name = prefix + ":" + file.stem().u8string();
loader.add(
AssetType::LAYOUT,
file.u8string(),
name,
std::make_shared<LayoutCfg>(env)
);
}
}
@@ -91,30 +105,35 @@ void AssetsLoader::tryAddSound(const std::string& name) {
if (name.empty()) {
return;
}
std::string file = SOUNDS_FOLDER+"/"+name;
std::string file = SOUNDS_FOLDER + "/" + name;
add(AssetType::SOUND, file, name);
}
static std::string assets_def_folder(AssetType tag) {
switch (tag) {
case AssetType::FONT: return FONTS_FOLDER;
case AssetType::SHADER: return SHADERS_FOLDER;
case AssetType::TEXTURE: return TEXTURES_FOLDER;
case AssetType::ATLAS: return TEXTURES_FOLDER;
case AssetType::LAYOUT: return LAYOUTS_FOLDER;
case AssetType::SOUND: return SOUNDS_FOLDER;
case AssetType::MODEL: return MODELS_FOLDER;
case AssetType::FONT:
return FONTS_FOLDER;
case AssetType::SHADER:
return SHADERS_FOLDER;
case AssetType::TEXTURE:
return TEXTURES_FOLDER;
case AssetType::ATLAS:
return TEXTURES_FOLDER;
case AssetType::LAYOUT:
return LAYOUTS_FOLDER;
case AssetType::SOUND:
return SOUNDS_FOLDER;
case AssetType::MODEL:
return MODELS_FOLDER;
}
return "<error>";
}
void AssetsLoader::processPreload(
AssetType tag,
const std::string& name,
dynamic::Map* map
AssetType tag, const std::string& name, dynamic::Map* map
) {
std::string defFolder = assets_def_folder(tag);
std::string path = defFolder+"/"+name;
std::string path = defFolder + "/" + name;
if (map == nullptr) {
add(tag, path, name);
return;
@@ -122,9 +141,10 @@ void AssetsLoader::processPreload(
map->str("path", path);
switch (tag) {
case AssetType::SOUND:
add(tag, path, name, std::make_shared<SoundCfg>(
map->get("keep-pcm", false)
));
add(tag,
path,
name,
std::make_shared<SoundCfg>(map->get("keep-pcm", false)));
break;
default:
add(tag, path, name);
@@ -166,7 +186,7 @@ void AssetsLoader::processPreloadConfig(const fs::path& file) {
}
void AssetsLoader::processPreloadConfigs(const Content* content) {
auto preloadFile = paths->getMainRoot()/fs::path("preload.json");
auto preloadFile = paths->getMainRoot() / fs::path("preload.json");
if (fs::exists(preloadFile)) {
processPreloadConfig(preloadFile);
}
@@ -192,7 +212,12 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
loader.tryAddSound(material.breakSound);
}
addLayouts(0, "core", loader.getPaths()->getMainRoot()/fs::path("layouts"), loader);
addLayouts(
0,
"core",
loader.getPaths()->getMainRoot() / fs::path("layouts"),
loader
);
for (auto& entry : content->getPacks()) {
auto pack = entry.second.get();
auto& info = pack->getInfo();
@@ -205,7 +230,9 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
for (auto& bone : skeleton.getBones()) {
auto& model = bone->model.name;
if (!model.empty()) {
loader.add(AssetType::MODEL, MODELS_FOLDER+"/"+model, model);
loader.add(
AssetType::MODEL, MODELS_FOLDER + "/" + model, model
);
}
}
}
@@ -227,8 +254,8 @@ bool AssetsLoader::loadExternalTexture(
assets->store(Texture::from(image.get()), name);
return true;
} catch (const std::exception& err) {
logger.error() << "error while loading external "
<< path.u8string() << ": " << err.what();
logger.error() << "error while loading external "
<< path.u8string() << ": " << err.what();
}
}
}
@@ -245,22 +272,26 @@ public:
LoaderWorker(AssetsLoader* loader) : loader(loader) {
}
assetload::postfunc operator()(const std::shared_ptr<aloader_entry>& entry) override {
assetload::postfunc operator()(const std::shared_ptr<aloader_entry>& entry
) override {
aloader_func loadfunc = loader->getLoader(entry->tag);
return loadfunc(loader, loader->getPaths(), entry->filename, entry->alias, entry->config);
return loadfunc(
loader,
loader->getPaths(),
entry->filename,
entry->alias,
entry->config
);
}
};
std::shared_ptr<Task> AssetsLoader::startTask(runnable onDone) {
auto pool = std::make_shared<
util::ThreadPool<aloader_entry, assetload::postfunc>
>(
"assets-loader-pool",
[=](){return std::make_shared<LoaderWorker>(this);},
[=](assetload::postfunc& func) {
func(assets);
}
);
auto pool =
std::make_shared<util::ThreadPool<aloader_entry, assetload::postfunc>>(
"assets-loader-pool",
[=]() { return std::make_shared<LoaderWorker>(this); },
[=](assetload::postfunc& func) { func(assets); }
);
pool->setOnComplete(std::move(onDone));
while (!entries.empty()) {
const aloader_entry& entry = entries.front();
+24 -23
View File
@@ -1,19 +1,19 @@
#ifndef ASSETS_ASSETS_LOADER_HPP_
#define ASSETS_ASSETS_LOADER_HPP_
#include "Assets.hpp"
#include "../interfaces/Task.hpp"
#include "../typedefs.hpp"
#include "../delegates.hpp"
#include <string>
#include <memory>
#include <filesystem>
#include <functional>
#include <map>
#include <memory>
#include <queue>
#include <string>
#include <utility>
#include "../delegates.hpp"
#include "../interfaces/Task.hpp"
#include "../typedefs.hpp"
#include "Assets.hpp"
namespace dynamic {
class Map;
class List;
@@ -24,28 +24,27 @@ class AssetsLoader;
class Content;
struct AssetCfg {
virtual ~AssetCfg() {}
virtual ~AssetCfg() {
}
};
struct LayoutCfg : AssetCfg {
scriptenv env;
LayoutCfg(scriptenv env) : env(std::move(env)) {}
LayoutCfg(scriptenv env) : env(std::move(env)) {
}
};
struct SoundCfg : AssetCfg {
bool keepPCM;
SoundCfg(bool keepPCM) : keepPCM(keepPCM) {}
SoundCfg(bool keepPCM) : keepPCM(keepPCM) {
}
};
using aloader_func = std::function<assetload::postfunc(
AssetsLoader*,
const ResPaths*,
const std::string&,
const std::string&,
std::shared_ptr<AssetCfg>)
>;
using aloader_func = std::function<
assetload::
postfunc(AssetsLoader*, const ResPaths*, const std::string&, const std::string&, std::shared_ptr<AssetCfg>)>;
struct aloader_entry {
AssetType tag;
@@ -62,7 +61,9 @@ class AssetsLoader {
void tryAddSound(const std::string& name);
void processPreload(AssetType tag, const std::string& name, dynamic::Map* map);
void processPreload(
AssetType tag, const std::string& name, dynamic::Map* map
);
void processPreloadList(AssetType tag, dynamic::List* list);
void processPreloadConfig(const std::filesystem::path& file);
void processPreloadConfigs(const Content* content);
@@ -76,12 +77,12 @@ public:
/// @param alias internal asset name
/// @param settings asset loading settings (based on asset type)
void add(
AssetType tag,
AssetType tag,
const std::string& filename,
const std::string& alias,
std::shared_ptr<AssetCfg> settings=nullptr
std::shared_ptr<AssetCfg> settings = nullptr
);
bool hasNext() const;
/// @throws assetload::error
@@ -104,4 +105,4 @@ public:
);
};
#endif // ASSETS_ASSETS_LOADER_HPP_
#endif // ASSETS_ASSETS_LOADER_HPP_
+78 -86
View File
@@ -1,30 +1,30 @@
#include "assetload_funcs.hpp"
#include "Assets.hpp"
#include "AssetsLoader.hpp"
#include "../data/dynamic.hpp"
#include <filesystem>
#include <iostream>
#include <stdexcept>
#include "../audio/audio.hpp"
#include "../files/files.hpp"
#include "../files/engine_paths.hpp"
#include "../coders/GLSLExtension.hpp"
#include "../coders/commons.hpp"
#include "../coders/imageio.hpp"
#include "../coders/json.hpp"
#include "../coders/obj.hpp"
#include "../coders/GLSLExtension.hpp"
#include "../graphics/core/Shader.hpp"
#include "../graphics/core/Texture.hpp"
#include "../graphics/core/ImageData.hpp"
#include "../constants.hpp"
#include "../data/dynamic.hpp"
#include "../files/engine_paths.hpp"
#include "../files/files.hpp"
#include "../frontend/UiDocument.hpp"
#include "../graphics/core/Atlas.hpp"
#include "../graphics/core/Font.hpp"
#include "../graphics/core/ImageData.hpp"
#include "../graphics/core/Model.hpp"
#include "../graphics/core/Shader.hpp"
#include "../graphics/core/Texture.hpp"
#include "../graphics/core/TextureAnimation.hpp"
#include "../objects/rigging.hpp"
#include "../frontend/UiDocument.hpp"
#include "../constants.hpp"
#include <iostream>
#include <stdexcept>
#include <filesystem>
#include "Assets.hpp"
#include "AssetsLoader.hpp"
namespace fs = std::filesystem;
@@ -37,43 +37,38 @@ static bool animation(
Atlas* dstAtlas
);
assetload::postfunc assetload::texture(
AssetsLoader*,
const ResPaths* paths,
const std::string& filename,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
std::shared_ptr<ImageData> image (
imageio::read(paths->find(filename+".png").u8string()).release()
assetload::postfunc assetload::
texture(AssetsLoader*, const ResPaths* paths, const std::string& filename, const std::string& name, const std::shared_ptr<AssetCfg>&) {
std::shared_ptr<ImageData> image(
imageio::read(paths->find(filename + ".png").u8string()).release()
);
return [name, image](auto assets) {
assets->store(Texture::from(image.get()), name);
};
}
assetload::postfunc assetload::shader(
AssetsLoader*,
const ResPaths* paths,
const std::string& filename,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
fs::path vertexFile = paths->find(filename+".glslv");
fs::path fragmentFile = paths->find(filename+".glslf");
assetload::postfunc assetload::
shader(AssetsLoader*, const ResPaths* paths, const std::string& filename, const std::string& name, const std::shared_ptr<AssetCfg>&) {
fs::path vertexFile = paths->find(filename + ".glslv");
fs::path fragmentFile = paths->find(filename + ".glslf");
std::string vertexSource = files::read_string(vertexFile);
std::string fragmentSource = files::read_string(fragmentFile);
vertexSource = Shader::preprocessor->process(vertexFile, vertexSource);
fragmentSource = Shader::preprocessor->process(fragmentFile, fragmentSource);
fragmentSource =
Shader::preprocessor->process(fragmentFile, fragmentSource);
return [=](auto assets) {
assets->store(Shader::create(
vertexFile.u8string(),
fragmentFile.u8string(),
vertexSource, fragmentSource
), name);
assets->store(
Shader::create(
vertexFile.u8string(),
fragmentFile.u8string(),
vertexSource,
fragmentSource
),
name
);
};
}
@@ -89,19 +84,12 @@ static bool append_atlas(AtlasBuilder& atlas, const fs::path& file) {
return true;
}
assetload::postfunc assetload::atlas(
AssetsLoader*,
const ResPaths* paths,
const std::string& directory,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
assetload::postfunc assetload::
atlas(AssetsLoader*, const ResPaths* paths, const std::string& directory, const std::string& name, const std::shared_ptr<AssetCfg>&) {
AtlasBuilder builder;
for (const auto& file : paths->listdir(directory)) {
if (!imageio::is_read_supported(file.extension().u8string()))
continue;
if (!append_atlas(builder, file))
continue;
if (!imageio::is_read_supported(file.extension().u8string())) continue;
if (!append_atlas(builder, file)) continue;
}
std::set<std::string> names = builder.getNames();
Atlas* atlas = builder.build(2, false).release();
@@ -114,16 +102,11 @@ assetload::postfunc assetload::atlas(
};
}
assetload::postfunc assetload::font(
AssetsLoader*,
const ResPaths* paths,
const std::string& filename,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
assetload::postfunc assetload::
font(AssetsLoader*, const ResPaths* paths, const std::string& filename, const std::string& name, const std::shared_ptr<AssetCfg>&) {
auto pages = std::make_shared<std::vector<std::unique_ptr<ImageData>>>();
for (size_t i = 0; i <= 4; i++) {
std::string pagefile = filename + "_" + std::to_string(i) + ".png";
std::string pagefile = filename + "_" + std::to_string(i) + ".png";
pagefile = paths->find(pagefile).string();
pages->push_back(imageio::read(pagefile));
}
@@ -133,7 +116,9 @@ assetload::postfunc assetload::font(
for (auto& page : *pages) {
textures.emplace_back(Texture::from(page.get()));
}
assets->store(std::make_unique<Font>(std::move(textures), res, 4), name);
assets->store(
std::make_unique<Font>(std::move(textures), res, 4), name
);
};
}
@@ -150,7 +135,7 @@ assetload::postfunc assetload::layout(
assets->store(UiDocument::read(cfg->env, name, file), name);
} catch (const parsing_error& err) {
throw std::runtime_error(
"failed to parse layout XML '"+file+"':\n"+err.errorLog()
"failed to parse layout XML '" + file + "':\n" + err.errorLog()
);
}
};
@@ -171,13 +156,13 @@ assetload::postfunc assetload::sound(
for (size_t i = 0; i < extensions.size(); i++) {
extension = extensions[i];
// looking for 'sound_name' as base sound
auto soundFile = paths->find(file+extension);
auto soundFile = paths->find(file + extension);
if (fs::exists(soundFile)) {
baseSound = audio::load_sound(soundFile, keepPCM);
break;
}
// looking for 'sound_name_0' as base sound
auto variantFile = paths->find(file+"_0"+extension);
auto variantFile = paths->find(file + "_0" + extension);
if (fs::exists(variantFile)) {
baseSound = audio::load_sound(variantFile, keepPCM);
break;
@@ -188,12 +173,14 @@ assetload::postfunc assetload::sound(
}
// loading sound variants
for (uint i = 1; ; i++) {
auto variantFile = paths->find(file+"_"+std::to_string(i)+extension);
for (uint i = 1;; i++) {
auto variantFile =
paths->find(file + "_" + std::to_string(i) + extension);
if (!fs::exists(variantFile)) {
break;
}
baseSound->variants.emplace_back(audio::load_sound(variantFile, keepPCM));
baseSound->variants.emplace_back(audio::load_sound(variantFile, keepPCM)
);
}
auto sound = baseSound.release();
@@ -202,22 +189,19 @@ assetload::postfunc assetload::sound(
};
}
assetload::postfunc assetload::model(
AssetsLoader* loader,
const ResPaths* paths,
const std::string& file,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
auto path = paths->find(file+".obj");
assetload::postfunc assetload::
model(AssetsLoader* loader, const ResPaths* paths, const std::string& file, const std::string& name, const std::shared_ptr<AssetCfg>&) {
auto path = paths->find(file + ".obj");
auto text = files::read_string(path);
try {
auto model = obj::parse(path.u8string(), text).release();
return [=](Assets* assets) {
for (auto& mesh : model->meshes) {
if (mesh.texture.find('$') == std::string::npos) {
auto filename = TEXTURES_FOLDER+"/"+mesh.texture;
loader->add(AssetType::TEXTURE, filename, mesh.texture, nullptr);
auto filename = TEXTURES_FOLDER + "/" + mesh.texture;
loader->add(
AssetType::TEXTURE, filename, mesh.texture, nullptr
);
}
}
assets->store(std::unique_ptr<model::Model>(model), name);
@@ -272,8 +256,10 @@ static TextureAnimation create_animation(
const int extension = 2;
frame.dstPos = glm::ivec2(region.u1 * dstWidth, region.v1 * dstHeight) - extension;
frame.size = glm::ivec2(region.u2 * dstWidth, region.v2 * dstHeight) - frame.dstPos + extension;
frame.dstPos =
glm::ivec2(region.u1 * dstWidth, region.v1 * dstHeight) - extension;
frame.size = glm::ivec2(region.u2 * dstWidth, region.v2 * dstHeight) -
frame.dstPos + extension;
for (const auto& elem : frameList) {
if (!srcAtlas->has(elem.first)) {
@@ -284,7 +270,11 @@ static TextureAnimation create_animation(
if (elem.second > 0) {
frame.duration = static_cast<float>(elem.second) / 1000.0f;
}
frame.srcPos = glm::ivec2(region.u1 * srcWidth, srcHeight - region.v2 * srcHeight) - extension;
frame.srcPos =
glm::ivec2(
region.u1 * srcWidth, srcHeight - region.v2 * srcHeight
) -
extension;
animation.addFrame(frame);
}
return animation;
@@ -303,10 +293,10 @@ inline bool contains(
}
static bool animation(
Assets* assets,
Assets* assets,
const ResPaths* paths,
const std::string& atlasName,
const std::string& directory,
const std::string& atlasName,
const std::string& directory,
const std::string& name,
Atlas* dstAtlas
) {
@@ -316,7 +306,7 @@ static bool animation(
if (!fs::is_directory(folder)) continue;
if (folder.filename().u8string() != name) continue;
if (fs::is_empty(folder)) continue;
AtlasBuilder builder;
append_atlas(builder, paths->find(directory + "/" + name + ".png"));
@@ -326,11 +316,11 @@ static bool animation(
read_anim_file(animFile, frameList);
}
for (const auto& file : paths->listdir(animsDir + "/" + name)) {
if (!frameList.empty() && !contains(frameList, file.stem().u8string())) {
if (!frameList.empty() &&
!contains(frameList, file.stem().u8string())) {
continue;
}
if (!append_atlas(builder, file))
continue;
if (!append_atlas(builder, file)) continue;
}
auto srcAtlas = builder.build(2, true);
if (frameList.empty()) {
@@ -341,7 +331,9 @@ static bool animation(
auto animation = create_animation(
srcAtlas.get(), dstAtlas, name, builder.getNames(), frameList
);
assets->store(std::move(srcAtlas), atlasName + "/" + name + "_animation");
assets->store(
std::move(srcAtlas), atlasName + "/" + name + "_animation"
);
assets->store(animation);
return true;
}
+5 -5
View File
@@ -1,10 +1,10 @@
#ifndef ASSETS_ASSET_LOADERS_HPP_
#define ASSETS_ASSET_LOADERS_HPP_
#include "Assets.hpp"
#include <string>
#include <memory>
#include <string>
#include "Assets.hpp"
class ResPaths;
class Assets;
@@ -30,7 +30,7 @@ namespace assetload {
);
postfunc atlas(
AssetsLoader*,
const ResPaths* paths,
const ResPaths* paths,
const std::string& directory,
const std::string& name,
const std::shared_ptr<AssetCfg>& settings
@@ -65,4 +65,4 @@ namespace assetload {
);
}
#endif // ASSETS_ASSET_LOADERS_HPP_
#endif // ASSETS_ASSET_LOADERS_HPP_