engine.cpp minor refactor
This commit is contained in:
parent
eb70e1c0df
commit
d5d0ba8959
@ -125,6 +125,9 @@ std::vector<std::string> PacksManager::assembly(const std::vector<std::string>&
|
|||||||
queue.pop();
|
queue.pop();
|
||||||
|
|
||||||
if (resolve_dependencies(pack, packs, allNames, added, queue, resolveWeaks)) {
|
if (resolve_dependencies(pack, packs, allNames, added, queue, resolveWeaks)) {
|
||||||
|
if (util::contains(added, pack->id)) {
|
||||||
|
throw contentpack_error(pack->id, pack->folder, "pack duplication");
|
||||||
|
}
|
||||||
added.push_back(pack->id);
|
added.push_back(pack->id);
|
||||||
addedInIteration++;
|
addedInIteration++;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -210,18 +210,6 @@ Engine::~Engine() {
|
|||||||
logger.info() << "engine finished";
|
logger.info() << "engine finished";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string checkPacks(
|
|
||||||
const std::unordered_set<std::string>& packs,
|
|
||||||
const std::vector<DependencyPack>& dependencies
|
|
||||||
) {
|
|
||||||
for (const auto& dependency : dependencies) {
|
|
||||||
if (packs.find(dependency.id) == packs.end()) {
|
|
||||||
return dependency.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: refactor this
|
// TODO: refactor this
|
||||||
void Engine::loadContent() {
|
void Engine::loadContent() {
|
||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
@ -233,8 +221,6 @@ void Engine::loadContent() {
|
|||||||
for (auto& pack : contentPacks) {
|
for (auto& pack : contentPacks) {
|
||||||
names.push_back(pack.id);
|
names.push_back(pack.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------
|
|
||||||
PacksManager manager;
|
PacksManager manager;
|
||||||
manager.setSources({
|
manager.setSources({
|
||||||
paths->getWorldFolder()/fs::path("content"),
|
paths->getWorldFolder()/fs::path("content"),
|
||||||
@ -242,38 +228,16 @@ void Engine::loadContent() {
|
|||||||
paths->getResources()/fs::path("content")
|
paths->getResources()/fs::path("content")
|
||||||
});
|
});
|
||||||
manager.scan();
|
manager.scan();
|
||||||
auto allnames = manager.getAllNames();
|
names = manager.assembly(names);
|
||||||
// ---------------------------------------------
|
contentPacks = manager.getAll(names);
|
||||||
|
|
||||||
std::vector<fs::path> resRoots;
|
std::vector<fs::path> resRoots;
|
||||||
std::vector<ContentPack> srcPacks = contentPacks;
|
for (auto& pack : contentPacks) {
|
||||||
contentPacks.clear();
|
|
||||||
|
|
||||||
std::string missingDependency;
|
|
||||||
std::unordered_set<std::string> loadedPacks, existingPacks;
|
|
||||||
for (const auto& item : srcPacks) {
|
|
||||||
existingPacks.insert(item.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: dependency levels
|
|
||||||
while (existingPacks.size() > loadedPacks.size()) {
|
|
||||||
for (auto& pack : srcPacks) {
|
|
||||||
if(loadedPacks.find(pack.id) != loadedPacks.end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
missingDependency = checkPacks(existingPacks, pack.dependencies);
|
|
||||||
if (!missingDependency.empty()) {
|
|
||||||
throw contentpack_error(pack.id, pack.folder, "missing dependency '"+missingDependency+"'");
|
|
||||||
}
|
|
||||||
if (pack.dependencies.empty() || checkPacks(loadedPacks, pack.dependencies).empty()) {
|
|
||||||
loadedPacks.insert(pack.id);
|
|
||||||
resRoots.push_back(pack.folder);
|
resRoots.push_back(pack.folder);
|
||||||
contentPacks.push_back(pack);
|
|
||||||
ContentLoader loader(&pack);
|
ContentLoader loader(&pack);
|
||||||
loader.load(contentBuilder);
|
loader.load(contentBuilder);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
content.reset(contentBuilder.build());
|
content.reset(contentBuilder.build());
|
||||||
resPaths = std::make_unique<ResPaths>(resdir, resRoots);
|
resPaths = std::make_unique<ResPaths>(resdir, resRoots);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user