work on ServerModule

This commit is contained in:
2025-04-16 01:26:56 -05:00
parent f94cb10412
commit 00ef227128
6 changed files with 228 additions and 36 deletions

View File

@@ -3,6 +3,7 @@
#include "pch.hpp"
#include "utils/Module/Module.h"
#include "utils/Events/Event.h"
namespace Archimedes {
@@ -55,9 +56,22 @@ namespace Archimedes {
bool isDone() const { return done; }
std::unordered_map<std::string, unsigned int> getEventTypes() const { return eventTypes; }
void emitEvent(Event* e) { events.push_back(e); }
void addEventType(std::string type) { eventTypes[type] = nextEventType++; }
unsigned int getEventType(std::string event) { return eventTypes[event]; }
void addEventType(std::string type) {
//only add each type once
if(eventTypes.find(type) == eventTypes.end())
eventTypes[type] = nextEventType++;
}
void removeEventType(std::string type) {
//only erase registered types
auto it = eventTypes.find(type);
if(it != eventTypes.end())
eventTypes.erase(it);
}
private:
@@ -73,10 +87,25 @@ namespace Archimedes {
std::unordered_map<std::string, Module*> modules;
std::unordered_map<std::string, unsigned int> eventTypes;
std::list<Event*> events;
std::list<std::string> runOrder;
std::list<std::string> toClose;
std::list<std::variant<std::string, Module*>> toOpen;
void handleEvents() {
while(!events.empty()) {
for(auto it = runOrder.rbegin(); it != runOrder.rend(); it++) {
if(modules[*it]->onEvent(*events.front())) {
Event* e = events.front();
events.pop_front();
delete e;
break;
}
}
}
}
virtual Module* dynamicLoad(std::string lib) {
@@ -169,18 +198,12 @@ namespace Archimedes {
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()) {
unload(s);
}
}
*/
Module* m = modules[name];
void* h = m->getHandle();
modules[name] = nullptr;
modules.erase(name);
runOrder.remove(name);