heavy refactoring

This commit is contained in:
2025-04-02 11:50:32 -05:00
parent c3685d2b30
commit 44ef73395c
18 changed files with 132 additions and 93 deletions

View File

@@ -7,8 +7,9 @@
#include <array>
#include <vector>
#include <variant>
#include <any>
#include <unordered_map>
#include <functional>
#include <optional>
//#include <chrono>
//#include <thread>

View File

@@ -49,7 +49,9 @@ namespace Archimedes {
bool done = false;
std::list<Module*> modules;
std::unordered_map<std::string, Module*> modules;
std::list<std::string> runOrder;
std::list<Module*> toClose;
std::list<std::string> toOpen;
@@ -73,53 +75,47 @@ namespace Archimedes {
return create(h, Get());
}
virtual std::list<Module*>::iterator load(std::string modulePath, std::list<std::string> blacklist = {}) {
virtual Module* load(std::string modulePath, std::list<std::string>::iterator ins) {
Module* m = dynamicLoad(modulePath);
return load(m, blacklist);
return load(m, ins);
}
virtual std::list<Module*>::iterator load(Module* m, std::list<std::string> blacklist = {}) {
virtual Module* load(Module* m, std::list<std::string>::iterator ins) {
if(!m) {
return modules.end();
return nullptr;
}
void* h = m->getHandle();
for(auto it = blacklist.begin(); it != blacklist.end(); it++) {
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
if(*it == m->getName()) {
std::cout << "Module \"" << *it << "\" is already loaded!\n";
delete m;
if(h)
dlclose(h);
return modules.end();
return nullptr;
}
}
blacklist.push_back(m->getName());
bool skip = false;
for(auto it = m->deps.begin(); it != m->deps.end(); it++) {
for(std::string s : blacklist) {
if(it->first == s)
skip = true;
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
if(m->deps.find(*it) != m->deps.end()) {
skip = true;
m->depsInstances[*it] = modules[*it];
}
if(skip) {
skip = false;
continue;
} else {
if(std::holds_alternative<std::string>(it->second))
m->depsInstances[it->first] = load(std::get<std::string>(it->second), blacklist);
if(std::holds_alternative<std::string>(m->deps[*it]))
m->depsInstances[*it] = load(std::get<std::string>(m->deps[*it]), ins);
else
m->depsInstances[it->first] = load(std::get<Module*>(it->second), blacklist);
m->depsInstances[*it] = load(std::get<Module*>(m->deps[*it]), ins);
}
}
modules.push_back(m);
m->setSelf(--modules.end());
modules.end()++;
return m->self;
return m;
}
virtual void unload(std::list<Module*>::iterator it) {
@@ -135,13 +131,6 @@ namespace Archimedes {
virtual void printHelp() = 0;
std::list<std::string> getBlacklist() {
std::list<std::string> l;
for(Module* m : modules)
l.push_back(m->getName());
return l;
}
};
}

View File

@@ -3,7 +3,9 @@
#include "utils/Module/Module.h"
#ifndef WINDOWMODULE_STATIC
#define WINDOWMODULE_STATIC
#endif
#include "modules/WindowModule/src/WindowModule.h"
namespace Archimedes {
@@ -14,15 +16,15 @@ namespace Archimedes {
typedef GuiModule* create_t(void*, App*);
GuiModule(void* h, App* a) : Module(h, a) {
windowModule = new WindowModule(nullptr, a);
deps["WindowModule"] = windowModule;
//wm = new WindowModule(nullptr, a);
deps["WindowModule"] = new WindowModule(nullptr, a);
}
virtual ~GuiModule() {}
virtual void onLoad() = 0;
virtual void run() = 0;
protected:
WindowModule* windowModule;
//WindowModule* wm;
};
}

View File

@@ -25,17 +25,18 @@ namespace Archimedes {
std::string getName() const { return name; }
void* getHandle() { return handle; }
void setSelf(std::list<Module*>::iterator s) { self = s; }
std::any getData(std::string s) { return data[s.c_str()]; };
protected:
std::string name;
void* handle;
std::list<Module*>::iterator self;
App* app;
std::unordered_map<std::string, std::variant<std::string, Module*>> deps;
std::unordered_map<std::string, std::list<Module*>::iterator> depsInstances;
std::unordered_map<std::string, Module*> depsInstances;
std::unordered_map<std::string, std::any> data;
};
}

View File

@@ -13,21 +13,14 @@ namespace Archimedes {
~Renderer() {}
void init() { r.init(); }
bool init() { return r.init(); }
void render() {
r.render(rc, w, h);
}
std::list<renderCmd*>::iterator addRenderCmd(renderCmd* cmd) {
auto it = rc.end();
rc.push_back(cmd);
return it;
}
void removeRenderCmd(std::list<renderCmd*>::iterator cmd) {
rc.erase(cmd);
std::list<renderCmd*>& getCmdList() {
return rc;
}
private:

View File

@@ -17,7 +17,9 @@ namespace Archimedes {
RendererOpenGL() {};
~RendererOpenGL() {};
void init() { glewInit(); };
bool init() {
return glewInit() == GLEW_OK;
};
void render(std::list<renderCmd*> cmdList, int& w, int& h) {

View File

@@ -11,7 +11,9 @@ namespace Archimedes {
public:
~Window() {};
Window() { renderer = new Renderer(); }
~Window() { delete renderer; }
bool shouldClose() { return window.shouldClose(); }
@@ -27,7 +29,7 @@ namespace Archimedes {
}
Renderer* getRenderer() { return renderer; }
void setRenderer(Renderer* r) { renderer = r; }
//void setRenderer(Renderer* r) { renderer = r; }
WindowImpl& getWindowImpl() { return window; }

View File

@@ -31,6 +31,7 @@ namespace Archimedes {
std::cout << "Window Created!\n";
glfwMakeContextCurrent(w);
glfwSwapInterval(1);
}
~WindowGLFW() {