yeah you close
This commit is contained in:
@@ -15,17 +15,19 @@ namespace Archimedes {
|
|||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
instance = this;
|
instance = this;
|
||||||
|
roInsert = runOrder.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~App() {
|
virtual ~App() {
|
||||||
|
|
||||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
for(std::string s : runOrder) {
|
||||||
void* handle = (*it)->getHandle();
|
void* handle = modules[s]->getHandle();
|
||||||
delete *it;
|
delete modules[s];
|
||||||
if(handle)
|
if(handle)
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
it = modules.erase(it);
|
modules[s] = nullptr;
|
||||||
}
|
}
|
||||||
|
runOrder.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -35,13 +37,15 @@ namespace Archimedes {
|
|||||||
|
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
virtual void stopModule(std::list<Module*>::iterator it) { toClose.push_back(*it); }
|
virtual void stopModule(std::string lib) { toClose.push_back(lib); }
|
||||||
|
|
||||||
virtual void startModule(std::string lib) { toOpen.push_back(lib); }
|
virtual void startModule(std::string lib) { toOpen.push_back(lib); }
|
||||||
|
|
||||||
void end() { done = true; }
|
void end() { done = true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
std::list<std::string>::iterator roInsert;
|
||||||
|
|
||||||
inline static App* instance = nullptr;
|
inline static App* instance = nullptr;
|
||||||
|
|
||||||
@@ -52,7 +56,7 @@ namespace Archimedes {
|
|||||||
std::unordered_map<std::string, Module*> modules;
|
std::unordered_map<std::string, Module*> modules;
|
||||||
std::list<std::string> runOrder;
|
std::list<std::string> runOrder;
|
||||||
|
|
||||||
std::list<Module*> toClose;
|
std::list<std::string> toClose;
|
||||||
std::list<std::string> toOpen;
|
std::list<std::string> toOpen;
|
||||||
|
|
||||||
virtual Module* dynamicLoad(std::string lib) {
|
virtual Module* dynamicLoad(std::string lib) {
|
||||||
@@ -75,12 +79,12 @@ namespace Archimedes {
|
|||||||
return create(h, Get());
|
return create(h, Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Module* load(std::string modulePath, std::list<std::string>::iterator ins) {
|
virtual Module* load(std::string modulePath) {
|
||||||
Module* m = dynamicLoad(modulePath);
|
Module* m = dynamicLoad(modulePath);
|
||||||
return load(m, ins);
|
return load(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Module* load(Module* m, std::list<std::string>::iterator ins) {
|
virtual Module* load(Module* m) {
|
||||||
|
|
||||||
if(!m) {
|
if(!m) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -97,36 +101,51 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool skip = false;
|
modules[m->getName()] = m;
|
||||||
|
|
||||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||||
|
|
||||||
if(m->deps.find(*it) != m->deps.end()) {
|
if(m->deps.find(*it) != m->deps.end()) {
|
||||||
skip = true;
|
|
||||||
m->depsInstances[*it] = modules[*it];
|
m->depsInstances[*it] = modules[*it];
|
||||||
}
|
//modules should be located after their dependencies
|
||||||
if(skip) {
|
if(std::distance(roInsert, it) <= 0) {
|
||||||
skip = false;
|
roInsert = ++it--;
|
||||||
continue;
|
}
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//insert temporarily to avoid circular dependencies
|
||||||
|
runOrder.insert(roInsert, m->getName());
|
||||||
|
|
||||||
|
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||||
|
|
||||||
|
if(m->deps.find(*it) == m->deps.end()) {
|
||||||
if(std::holds_alternative<std::string>(m->deps[*it]))
|
if(std::holds_alternative<std::string>(m->deps[*it]))
|
||||||
m->depsInstances[*it] = load(std::get<std::string>(m->deps[*it]), ins);
|
m->depsInstances[*it] = load(std::get<std::string>(m->deps[*it]));
|
||||||
else
|
else
|
||||||
m->depsInstances[*it] = load(std::get<Module*>(m->deps[*it]), ins);
|
m->depsInstances[*it] = load(std::get<Module*>(m->deps[*it]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//reinsert once final order has been reached
|
||||||
|
runOrder.remove(m->getName());
|
||||||
|
|
||||||
|
runOrder.insert(roInsert, m->getName());
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void unload(std::list<Module*>::iterator it) {
|
virtual void unload(std::string name) {
|
||||||
Module* m = *it;
|
Module* m = modules[name];
|
||||||
void* h = m->getHandle();
|
void* h = m->getHandle();
|
||||||
|
|
||||||
modules.erase(m->self);
|
modules[name] = nullptr;
|
||||||
delete m;
|
delete m;
|
||||||
|
|
||||||
if(h)
|
if(h)
|
||||||
dlclose(h);
|
dlclose(h);
|
||||||
|
|
||||||
|
runOrder.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void printHelp() = 0;
|
virtual void printHelp() = 0;
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ TestImgui::TestImgui(void* h, Archimedes::App* a) : Archimedes::GuiModule(h, a)
|
|||||||
|
|
||||||
TestImgui::~TestImgui() {
|
TestImgui::~TestImgui() {
|
||||||
|
|
||||||
std::list<Archimedes::Renderer::renderCmd*>* cmdList =
|
std::list<Archimedes::Renderer::renderCmd*>* cmdList =
|
||||||
std::any_cast<std::list<Archimedes::Renderer::renderCmd*>*>(depsInstances["WindowModule"]->getData("renderCmdList"));
|
std::any_cast<std::list<Archimedes::Renderer::renderCmd*>*>(depsInstances["WindowModule"]->getData("renderCmdList"));
|
||||||
cmdList->erase(rcmd);
|
cmdList->erase(rcmd);
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
ImGui_ImplGlfw_Shutdown();
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
|||||||
@@ -2,23 +2,23 @@
|
|||||||
|
|
||||||
void MinimalApp::run() {
|
void MinimalApp::run() {
|
||||||
|
|
||||||
for(auto* m : modules)
|
for(auto m : runOrder)
|
||||||
m->onLoad();
|
modules[m]->onLoad();
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!done && !modules.empty()) {
|
while (!done && !runOrder.empty()) {
|
||||||
|
|
||||||
for(auto* m : modules) {
|
for(auto m : runOrder) {
|
||||||
m->run();
|
modules[m]->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto it = toClose.begin(); it != toClose.end(); it++) {
|
for(auto m : toClose) {
|
||||||
unload(it);
|
unload(m);
|
||||||
}
|
}
|
||||||
toClose.clear();
|
toClose.clear();
|
||||||
|
|
||||||
for(std::string s : toOpen) {
|
for(std::string m : toOpen) {
|
||||||
load(s, modules.begin());
|
load(m);
|
||||||
}
|
}
|
||||||
toOpen.clear();
|
toOpen.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class MinimalApp : public Archimedes::App {
|
|||||||
void handleArgs(const int& argc, char* argv[]) {
|
void handleArgs(const int& argc, char* argv[]) {
|
||||||
if(argc > 1) {
|
if(argc > 1) {
|
||||||
for(int i = 1; i < argc; i++)
|
for(int i = 1; i < argc; i++)
|
||||||
load(dynamicLoad(argv[i]), modules.begin());
|
load(dynamicLoad(argv[i]));
|
||||||
} else {
|
} else {
|
||||||
std::cout << "No modules to load\n";
|
std::cout << "No modules to load\n";
|
||||||
end();
|
end();
|
||||||
|
|||||||
Reference in New Issue
Block a user