layers are redundant

This commit is contained in:
2025-04-09 14:16:38 -05:00
parent 42b5a53b89
commit 908b00db62
11 changed files with 68 additions and 191 deletions

View File

@@ -3,8 +3,8 @@
#ifdef MODULE_TYPE
extern "C" {
Archimedes::Module* create(void* handle, Archimedes::App* app) {
return new MODULE_TYPE(handle, app);
Archimedes::Module* create(Archimedes::App* app, void* handle) {
return new MODULE_TYPE(app, handle);
}
}

View File

@@ -39,7 +39,7 @@ namespace Archimedes {
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, std::variant<std::string, Module*> m) { toOpen[lib] = m; }
void end() { done = true; }
@@ -57,8 +57,8 @@ namespace Archimedes {
std::list<std::string> runOrder;
std::list<std::string> toClose;
std::list<std::string> toOpen;
std::unordered_map<std::string, std::variant<std::string, Module*>> toOpen;
virtual Module* dynamicLoad(std::string lib) {
void* h = dlopen(lib.c_str(), RTLD_NOW);
@@ -76,7 +76,7 @@ namespace Archimedes {
return nullptr;
}
return create(h, Get());
return create(Get(), h);
}
virtual Module* load(std::string modulePath) {
@@ -144,6 +144,9 @@ namespace Archimedes {
virtual void unload(std::string name) {
if(modules.find(name) == modules.end())
return;
//unload modules that depend on the one we are unloading
for(std::string s : runOrder) {
if(modules[s]->deps.find(name) != modules[s]->deps.end()) {
@@ -155,10 +158,11 @@ namespace Archimedes {
void* h = m->getHandle();
modules[name] = nullptr;
delete m;
if(h)
if(h) {
delete m;
dlclose(h);
}
runOrder.remove(name);
}

View File

@@ -12,14 +12,11 @@ namespace Archimedes {
class GuiModule : public Module {
public:
typedef GuiModule* create_t(void*, App*);
GuiModule(void* h, App* a) : Module(h, a) {
deps["WindowModule"] = new WindowModule(nullptr, a);
GuiModule(App* a, void* h) : Module(a, h) {
WindowModule* wm = new WindowModule(a);
deps[wm->getName()] = wm;
}
virtual ~GuiModule() {}
virtual void onLoad() = 0;
virtual void run() = 0;
};
}

View File

@@ -1,25 +0,0 @@
#ifndef LAYER_H
#define LAYER_H
#include "pch.hpp"
#include "utils/Events/Event.h"
namespace Archimedes {
class Layer {
public:
virtual ~Layer() {}
virtual void onRender() = 0;
virtual void onAttach() = 0;
virtual void onDetach() = 0;
virtual bool onEvent(const Event&) = 0;
};
}
#endif

View File

@@ -1,51 +0,0 @@
#ifndef LAYERSTACK_H
#define LAYERSTACK_H
#include "pch.hpp"
#include "Layer.h"
namespace Archimedes {
class Layerstack {
public:
Layerstack() {}
~Layerstack() {
while(!lstack.empty()) {
pop();
}
}
void push(Layer* l) {
if(l) {
lstack.push_front(l);
l->onAttach();
}
}
void pop() {
Layer* l = lstack.front();
lstack.pop_front();
l->onDetach();
}
void renderAll() {
for(Layer* l : lstack)
l->onRender();
}
void sendEvent(const Event& e) {
for(Layer* l : lstack) {
if(l->onEvent(e)) {
break;
}
}
}
private:
std::list<Layer*> lstack;
};
}
#endif

View File

@@ -7,36 +7,39 @@ namespace Archimedes {
class App;
class Event;
class Module {
friend class App;
public:
typedef Module* create_t(void*, App*);
typedef Module* create_t(App*, void*);
Module(void* h, App* a) : handle(h), app(a) {}
Module(App* a, void* h) : app(a), handle(h) {}
virtual ~Module() {}
virtual void run() = 0;
virtual void onLoad() = 0;
virtual void run() {}
virtual bool onEvent(const Event& e) { return false; }
virtual void onLoad() {};
std::string getName() const { return name; }
void* getHandle() { return handle; }
std::any getData(std::string s) { return data[s.c_str()]; };
//std::any getData(std::string s) { return data[s.c_str()]; };
protected:
std::string name;
void* handle;
App* app;
void* handle;
std::unordered_map<std::string, std::variant<std::string, Module*>> deps;
std::unordered_map<std::string, Module*> depsInstances;
std::unordered_map<std::string, std::any> data;
//std::unordered_map<std::string, std::any> data;
};
}