mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
PacksManager added to engine
This commit is contained in:
parent
3655464b6f
commit
f9d391e05a
9 changed files with 93 additions and 67 deletions
|
|
@ -113,21 +113,6 @@ void ContentPack::scanFolder(
|
|||
}
|
||||
}
|
||||
|
||||
void ContentPack::scan(
|
||||
fs::path rootfolder,
|
||||
EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs
|
||||
) {
|
||||
scanFolder(paths->getResources()/fs::path("content"), packs);
|
||||
scanFolder(paths->getUserfiles()/fs::path("content"), packs);
|
||||
scanFolder(rootfolder, packs);
|
||||
}
|
||||
|
||||
void ContentPack::scan(EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs) {
|
||||
scan(paths->getWorldFolder()/fs::path("content"), paths, packs);
|
||||
}
|
||||
|
||||
std::vector<std::string> ContentPack::worldPacksList(fs::path folder) {
|
||||
fs::path listfile = folder / fs::path("packs.list");
|
||||
if (!fs::is_regular_file(listfile)) {
|
||||
|
|
@ -154,20 +139,6 @@ fs::path ContentPack::findPack(const EnginePaths* paths, fs::path worldDir, std:
|
|||
return folder;
|
||||
}
|
||||
|
||||
void ContentPack::readPacks(const EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs,
|
||||
const std::vector<std::string>& packnames,
|
||||
fs::path worldDir) {
|
||||
for (const auto& name : packnames) {
|
||||
fs::path packfolder = ContentPack::findPack(paths, worldDir, name);
|
||||
if (!fs::is_directory(packfolder)) {
|
||||
throw contentpack_error(name, packfolder,
|
||||
"could not to find pack '"+name+"'");
|
||||
}
|
||||
packs.push_back(ContentPack::read(packfolder));
|
||||
}
|
||||
}
|
||||
|
||||
ContentPackRuntime::ContentPackRuntime(
|
||||
ContentPack info,
|
||||
std::unique_ptr<scripting::Environment> env
|
||||
|
|
|
|||
|
|
@ -63,16 +63,6 @@ struct ContentPack {
|
|||
fs::path folder,
|
||||
std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
static void scan(
|
||||
fs::path folder,
|
||||
EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs
|
||||
);
|
||||
static void scan(
|
||||
EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs
|
||||
);
|
||||
|
||||
static std::vector<std::string> worldPacksList(fs::path folder);
|
||||
|
||||
|
|
@ -81,13 +71,6 @@ struct ContentPack {
|
|||
fs::path worldDir,
|
||||
std::string name
|
||||
);
|
||||
|
||||
static void readPacks(
|
||||
const EnginePaths* paths,
|
||||
std::vector<ContentPack>& packs,
|
||||
const std::vector<std::string>& names,
|
||||
fs::path worldDir
|
||||
);
|
||||
};
|
||||
|
||||
struct ContentPackStats {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ void PacksManager::scan() {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> PacksManager::getAllNames() {
|
||||
std::vector<std::string> PacksManager::getAllNames() const {
|
||||
std::vector<std::string> names;
|
||||
for (auto& entry : packs) {
|
||||
names.push_back(entry.first);
|
||||
|
|
@ -32,8 +32,20 @@ std::vector<std::string> PacksManager::getAllNames() {
|
|||
return names;
|
||||
}
|
||||
|
||||
static contentpack_error on_circular_dependency(std::queue<ContentPack*>& queue) {
|
||||
ContentPack* lastPack = queue.back();
|
||||
std::vector<ContentPack> PacksManager::getAll(const std::vector<std::string>& names) const {
|
||||
std::vector<ContentPack> packsList;
|
||||
for (auto& name : names) {
|
||||
auto found = packs.find(name);
|
||||
if (found == packs.end()) {
|
||||
throw contentpack_error(name, fs::path(""), "pack not found");
|
||||
}
|
||||
packsList.push_back(found->second);
|
||||
}
|
||||
return packsList;
|
||||
}
|
||||
|
||||
static contentpack_error on_circular_dependency(std::queue<const ContentPack*>& queue) {
|
||||
const ContentPack* lastPack = queue.back();
|
||||
// circular dependency
|
||||
std::stringstream ss;
|
||||
ss << "circular dependency: " << lastPack->id;
|
||||
|
|
@ -55,11 +67,11 @@ static contentpack_error on_circular_dependency(std::queue<ContentPack*>& queue)
|
|||
/// @return true if all dependencies are already added or not found (optional/weak)
|
||||
/// @throws contentpack_error if required dependency is not found
|
||||
static bool resolve_dependencies (
|
||||
ContentPack* pack,
|
||||
std::unordered_map<std::string, ContentPack>& packs,
|
||||
const ContentPack* pack,
|
||||
const std::unordered_map<std::string, ContentPack>& packs,
|
||||
std::vector<std::string>& allNames,
|
||||
std::vector<std::string>& added,
|
||||
std::queue<ContentPack*>& queue,
|
||||
std::queue<const ContentPack*>& queue,
|
||||
bool resolveWeaks
|
||||
) {
|
||||
bool satisfied = true;
|
||||
|
|
@ -91,11 +103,11 @@ static bool resolve_dependencies (
|
|||
return satisfied;
|
||||
}
|
||||
|
||||
std::vector<std::string> PacksManager::assembly(const std::vector<std::string>& names) {
|
||||
std::vector<std::string> PacksManager::assembly(const std::vector<std::string>& names) const {
|
||||
std::vector<std::string> allNames = names;
|
||||
std::vector<std::string> added;
|
||||
std::queue<ContentPack*> queue;
|
||||
std::queue<ContentPack*> queue2;
|
||||
std::queue<const ContentPack*> queue;
|
||||
std::queue<const ContentPack*> queue2;
|
||||
|
||||
for (auto& name : names) {
|
||||
auto found = packs.find(name);
|
||||
|
|
|
|||
|
|
@ -23,14 +23,19 @@ public:
|
|||
void scan();
|
||||
|
||||
/// @brief Get all found packs
|
||||
std::vector<std::string> getAllNames();
|
||||
std::vector<std::string> getAllNames() const;
|
||||
|
||||
/// @brief Get packs by names (id)
|
||||
/// @param names pack names
|
||||
/// @throws contentpack_error if pack not found
|
||||
std::vector<ContentPack> getAll(const std::vector<std::string>& names) const;
|
||||
|
||||
/// @brief Resolve all dependencies and fix packs order
|
||||
/// @param names required packs (method can add extra packs)
|
||||
/// @return resulting ordered vector of pack names
|
||||
/// @throws contentpack_error if required dependency not found or
|
||||
/// circular dependency detected
|
||||
std::vector<std::string> assembly(const std::vector<std::string>& names);
|
||||
std::vector<std::string> assembly(const std::vector<std::string>& names) const;
|
||||
};
|
||||
|
||||
#endif // CONTENT_PACKS_MANAGER_H_
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue