add 'separate' atlas type & get rid of assets loading entries duplicates

This commit is contained in:
MihailRis
2024-11-20 04:30:19 +03:00
parent 0144709e03
commit 784f93666c
3 changed files with 42 additions and 2 deletions
+14
View File
@@ -43,7 +43,11 @@ void AssetsLoader::add(
const std::string& alias, const std::string& alias,
std::shared_ptr<AssetCfg> settings std::shared_ptr<AssetCfg> settings
) { ) {
if (enqueued.find({tag, alias}) != enqueued.end()){
return;
}
entries.push(aloader_entry {tag, filename, alias, std::move(settings)}); entries.push(aloader_entry {tag, filename, alias, std::move(settings)});
enqueued.insert({tag, alias});
} }
bool AssetsLoader::hasNext() const { bool AssetsLoader::hasNext() const {
@@ -148,6 +152,16 @@ void AssetsLoader::processPreload(
std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM))); std::make_shared<SoundCfg>(map.at("keep-pcm").get(keepPCM)));
break; break;
} }
case AssetType::ATLAS: {
std::string typeName = "atlas";
map.at("type").get(typeName);
auto type = AtlasType::ATLAS;
if (typeName == "separate") {
type = AtlasType::SEPARATE;
}
add(tag, path, name, std::make_shared<AtlasCfg>(type));
break;
}
default: default:
add(tag, path, name); add(tag, path, name);
break; break;
+13
View File
@@ -3,6 +3,7 @@
#include <filesystem> #include <filesystem>
#include <functional> #include <functional>
#include <map> #include <map>
#include <set>
#include <memory> #include <memory>
#include <queue> #include <queue>
#include <string> #include <string>
@@ -37,6 +38,17 @@ struct SoundCfg : AssetCfg {
} }
}; };
enum class AtlasType {
ATLAS, SEPARATE
};
struct AtlasCfg : AssetCfg {
AtlasType type;
AtlasCfg(AtlasType type) : type(type) {
}
};
using aloader_func = std::function< using aloader_func = std::function<
assetload:: assetload::
postfunc(AssetsLoader*, const ResPaths*, const std::string&, const std::string&, std::shared_ptr<AssetCfg>)>; postfunc(AssetsLoader*, const ResPaths*, const std::string&, const std::string&, std::shared_ptr<AssetCfg>)>;
@@ -52,6 +64,7 @@ class AssetsLoader {
Assets* assets; Assets* assets;
std::map<AssetType, aloader_func> loaders; std::map<AssetType, aloader_func> loaders;
std::queue<aloader_entry> entries; std::queue<aloader_entry> entries;
std::set<std::pair<AssetType, std::string>> enqueued;
const ResPaths* paths; const ResPaths* paths;
void tryAddSound(const std::string& name); void tryAddSound(const std::string& name);
+15 -2
View File
@@ -103,12 +103,25 @@ static bool append_atlas(AtlasBuilder& atlas, const fs::path& file) {
} }
assetload::postfunc assetload::atlas( assetload::postfunc assetload::atlas(
AssetsLoader*, AssetsLoader* loader,
const ResPaths* paths, const ResPaths* paths,
const std::string& directory, const std::string& directory,
const std::string& name, const std::string& name,
const std::shared_ptr<AssetCfg>& const std::shared_ptr<AssetCfg>& config
) { ) {
auto atlasConfig = std::dynamic_pointer_cast<AtlasCfg>(config);
if (atlasConfig && atlasConfig->type == AtlasType::SEPARATE) {
for (const auto& file : paths->listdir(directory)) {
if (!imageio::is_read_supported(file.extension().u8string()))
continue;
loader->add(
AssetType::TEXTURE,
directory + "/" + file.stem().u8string(),
name + "/" + file.stem().u8string()
);
}
return [](auto){};
}
AtlasBuilder builder; AtlasBuilder builder;
for (const auto& file : paths->listdir(directory)) { for (const auto& file : paths->listdir(directory)) {
if (!imageio::is_read_supported(file.extension().u8string())) continue; if (!imageio::is_read_supported(file.extension().u8string())) continue;