This commit is contained in:
2025-04-17 14:58:22 -05:00
parent f36f6ae125
commit a1e9401aaa
23 changed files with 157 additions and 44 deletions

View File

@@ -140,7 +140,7 @@ namespace Archimedes {
void* h = m->getHandle(); void* h = m->getHandle();
for(auto it = runOrder.begin(); it != runOrder.end(); it++) { for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
if(*it == m->getName()) { if(*it == static_cast<std::string>(*m)) {
std::cout << "Module \"" << *it << "\" is already loaded!\n"; std::cout << "Module \"" << *it << "\" is already loaded!\n";
delete m; delete m;
if(h) { if(h) {
@@ -150,7 +150,7 @@ namespace Archimedes {
} }
} }
modules[m->getName()] = m; modules[*m] = m;
for(auto it = runOrder.begin(); it != runOrder.end(); it++) { for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
@@ -164,7 +164,7 @@ namespace Archimedes {
} }
//insert temporarily to avoid circular dependencies //insert temporarily to avoid circular dependencies
runOrder.insert(roInsert, m->getName()); runOrder.insert(roInsert, *m);
bool skip = false; bool skip = false;
for(auto it : m->deps) { for(auto it : m->deps) {
@@ -185,9 +185,9 @@ namespace Archimedes {
} }
//reinsert once final order has been reached //reinsert once final order has been reached
runOrder.remove(m->getName()); runOrder.remove(*m);
runOrder.insert(roInsert, m->getName()); runOrder.insert(roInsert, *m);
return m; return m;
} }

View File

@@ -62,7 +62,7 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
unsigned int type = app->getEventType(event); unsigned int type = app->getEventType(event);
if(eventsToHandle & CMEventEnum::ConnectionStatusChanged && type == app->getEventType("ConnectionStatusChangedEvent")) { if(eventsToHandle & CMEventEnum::ConnectionStatusChanged && type == app->getEventType(CMEvent::ConnectionStatusChangedEvent())) {
CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event; CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event;
@@ -114,9 +114,9 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
} }
return true; return true;
} else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType("DataRecievedEvent")) { } else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(CMEvent::DataRecievedEvent())) {
return true; return true;
} else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType("DataSentEvent")) { } else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(CMEvent::DataSentEvent())) {
return true; return true;
} }

View File

@@ -9,9 +9,15 @@ class ClientModule : public Archimedes::Module {
public: public:
ClientModule(Archimedes::App*, void*); ClientModule(Archimedes::App*, void*);
ClientModule() { name = "ClientModule"; }
~ClientModule(); ~ClientModule();
void onLoad(); void onLoad();
void run(); void run();
bool onEvent(const Archimedes::Event&); bool onEvent(const Archimedes::Event&);
void startClient(SteamNetworkingIPAddr&); void startClient(SteamNetworkingIPAddr&);

View File

@@ -14,21 +14,25 @@ ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Mo
name = "ImguiModule"; name = "ImguiModule";
WindowModule* wm = new WindowModule(a, h); WindowModule* wm = new WindowModule(a, h);
deps[wm->getName()] = wm; deps[*wm] = wm;
} }
ImguiModule::~ImguiModule() { ImguiModule::~ImguiModule() {
WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"]; if(app) {
wm->getRenderer()->getCmdList().erase(rcmd_it); WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
ImGui_ImplOpenGL3_Shutdown(); wm->getRenderer()->getCmdList().erase(rcmd_it);
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext(); ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
} }
void ImguiModule::onLoad() { void ImguiModule::onLoad() {
WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"];
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
if(!wm) { if(!wm) {
std::cout << "No WindowModule for ImguiModule!\n"; std::cout << "No WindowModule for ImguiModule!\n";

View File

@@ -12,6 +12,8 @@ class ImguiModule : public Archimedes::Module {
public: public:
ImguiModule(Archimedes::App*, void*); ImguiModule(Archimedes::App*, void*);
ImguiModule() { name = "ImguiModule"; }
~ImguiModule(); ~ImguiModule();
void onLoad(); void onLoad();

View File

@@ -7,16 +7,17 @@ MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "MainGUI"; name = "MainGUI";
ImguiModule* im = new ImguiModule(a, h); ImguiModule* im = new ImguiModule(a, h);
deps[im->getName()] = im; deps[*im] = im;
} }
MainGUI::~MainGUI() { MainGUI::~MainGUI() {
if(app) {}
} }
void MainGUI::onLoad() { void MainGUI::onLoad() {
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"]; ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) { if(!im) {
std::cout << "No ImguiModule for MainGUI!\n"; std::cout << "No ImguiModule for MainGUI!\n";

View File

@@ -5,6 +5,8 @@ class MainGUI : public Archimedes::Module {
public: public:
MainGUI(Archimedes::App*, void*); MainGUI(Archimedes::App*, void*);
MainGUI() { name = "MainGUI"; }
~MainGUI(); ~MainGUI();
void onLoad(); void onLoad();

View File

@@ -8,15 +8,17 @@ Ollama::Ollama(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "Ollama"; name = "Ollama";
ImguiModule* im = new ImguiModule(a, h); ImguiModule* im = new ImguiModule(a, h);
deps[im->getName()] = im; deps[*im] = im;
} }
Ollama::~Ollama() { Ollama::~Ollama() {
if(curl) { if(app) {
curl_easy_cleanup(curl); if(curl) {
curl = nullptr; curl_easy_cleanup(curl);
curl = nullptr;
}
curl_global_cleanup();
} }
curl_global_cleanup();
} }
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostream* userp) static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostream* userp)
@@ -27,7 +29,7 @@ static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostr
void Ollama::onLoad() { void Ollama::onLoad() {
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"]; ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) { if(!im) {
std::cout << "No ImguiModule for Ollama!\n"; std::cout << "No ImguiModule for Ollama!\n";
@@ -109,7 +111,7 @@ void Ollama::run() {
if(code != CURLE_OK) { if(code != CURLE_OK) {
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl; std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
app->stopModule(getName()); app->stopModule(name);
return; return;
} else { } else {
jsonObj = nlohmann::json::parse(response); jsonObj = nlohmann::json::parse(response);

View File

@@ -8,6 +8,7 @@ class Ollama : public Archimedes::Module {
public: public:
Ollama(Archimedes::App*, void*); Ollama(Archimedes::App*, void*);
Ollama() { name = "Ollama"; }
~Ollama(); ~Ollama();
void onLoad(); void onLoad();

View File

@@ -79,7 +79,7 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
unsigned int type = app->getEventType(event); unsigned int type = app->getEventType(event);
if(eventsToHandle & SMEventEnum::ConnectionStatusChanged && type == app->getEventType("ConnectionStatusChangedEvent")) { if(eventsToHandle & SMEventEnum::ConnectionStatusChanged && type == app->getEventType(SMEvent::ConnectionStatusChangedEvent())) {
SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event; SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event;
@@ -192,9 +192,9 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
} }
return true; return true;
} else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType("DataRecievedEvent")) { } else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(SMEvent::DataRecievedEvent())) {
return true; return true;
} else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType("DataSentEvent")) { } else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(SMEvent::DataSentEvent())) {
return true; return true;
} }

View File

@@ -17,12 +17,12 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
} }
Terminal::~Terminal() { Terminal::~Terminal() {
if(app) {}
} }
void Terminal::onLoad() { void Terminal::onLoad() {
ImguiModule* im = (ImguiModule*) moduleInstances[ImguiModule()]; ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) { if(!im) {
std::cout << "No ImguiModule for Terminal!\n"; std::cout << "No ImguiModule for Terminal!\n";
@@ -67,7 +67,7 @@ void Terminal::run() {
rc = read(master, opArr, 150); rc = read(master, opArr, 150);
if(rc < 0) { if(rc < 0) {
//error on read //error on read
app->stopModule(getName()); app->stopModule(name);
} else { } else {
if(input == "clear") output = ""; if(input == "clear") output = "";
output += opArr; output += opArr;

View File

@@ -5,6 +5,7 @@ class Terminal : public Archimedes::Module {
public: public:
Terminal(Archimedes::App*, void*); Terminal(Archimedes::App*, void*);
Terminal() { name = "Terminal"; }
~Terminal(); ~Terminal();
void onLoad(); void onLoad();

View File

@@ -1,12 +1,14 @@
#include "WindowModule.h" #include "WindowModule.h"
WindowModule::~WindowModule() { WindowModule::~WindowModule() {
if(renderer) { if(app) {
renderer->getCmdList().clear(); if(renderer) {
delete renderer; renderer->getCmdList().clear();
} delete renderer;
if(window) { }
delete window; if(window) {
delete window;
}
} }
} }

View File

@@ -9,7 +9,7 @@
class WindowModule : public Archimedes::Module { class WindowModule : public Archimedes::Module {
public: public:
WindowModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) { WindowModule(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "WindowModule"; name = "WindowModule";
} }

View File

@@ -0,0 +1,58 @@
#include "ChatClient.h"
ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
name = "ChatClient";
ClientModule* cm = new ClientModule(a, h);
deps[*cm] = cm;
cm->shouldHandleEvents(ClientModule::CMEventEnum::ConnectionStatusChanged | ClientModule::CMEventEnum::DataSent);
ImguiModule* im = new ImguiModule(a, h);
deps[*im] = im;
}
void ChatClient::onLoad() {
}
void ChatClient::run() {
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
(void)cm;
}
bool ChatClient::onEvent(const Archimedes::Event& event) {
unsigned int type = app->getEventType(event);
/*if(type == app->getEventType("DataSentEvent")) {
//we did this?
return true;
} else */
if(type == app->getEventType(CMEvent::DataRecievedEvent())) {
CMEvent::DataRecievedEvent& e = (CMEvent::DataRecievedEvent&) event;
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
std::cerr << "Data Recieved: " << s << std::endl;
messages += "\n\n" + s;
}
/*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
//CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event;
return false;
}*/
return false;
}

View File

@@ -0,0 +1,27 @@
#include "Archimedes.h"
#include "modules/ClientModule/src/ClientModule.h"
#include "modules/ImguiModule/src/ImguiModule.h"
class ChatClient : public Archimedes::Module {
public:
ChatClient(Archimedes::App* a, void* h);
ChatClient() { name = "ChatClient"; }
~ChatClient() {
if(app) {}
}
void onLoad();
void run();
bool onEvent(const Archimedes::Event&);
private:
std::string messages;
};

View File

@@ -14,7 +14,7 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
return true; return true;
} else */ } else */
if(type == app->getEventType("DataRecievedEvent")) { if(type == app->getEventType(SMEvent::DataRecievedEvent())) {
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; } static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }

View File

@@ -5,7 +5,8 @@
DependsOnPrintStatic::DependsOnPrintStatic(Archimedes::App* a, void* h) : Module(a, h) { DependsOnPrintStatic::DependsOnPrintStatic(Archimedes::App* a, void* h) : Module(a, h) {
name = "DependsOnPrintStatic"; name = "DependsOnPrintStatic";
deps["Print"] = new Print(a, h); Print* p = new Print(a, h);
deps[*p] = p;
} }
DependsOnPrintStatic::~DependsOnPrintStatic() { DependsOnPrintStatic::~DependsOnPrintStatic() {

View File

@@ -5,7 +5,9 @@ Print::Print(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
} }
Print::~Print() { Print::~Print() {
std::cout << "Print Destroyed!\n"; if(app) {
std::cout << "Print Destroyed!\n";
}
} }
void Print::run() { void Print::run() {

View File

@@ -4,6 +4,7 @@ class Print : public Archimedes::Module {
public: public:
Print(Archimedes::App*, void*); Print(Archimedes::App*, void*);
Print() { name = "Print"; }
~Print(); ~Print();
void run(); void run();
}; };

View File

@@ -6,7 +6,7 @@ TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "TestImgui"; name = "TestImgui";
ImguiModule* im = new ImguiModule(a, h); ImguiModule* im = new ImguiModule(a, h);
deps[im->getName()] = im; deps[*im] = im;
} }
TestImgui::~TestImgui() { TestImgui::~TestImgui() {
@@ -30,7 +30,7 @@ void TestImgui::run() {
if(demo) if(demo)
ImGui::ShowDemoWindow(&this->demo); ImGui::ShowDemoWindow(&this->demo);
else else
app->stopModule(getName()); app->stopModule(name);
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();

View File

@@ -5,6 +5,8 @@ class TestImgui : public Archimedes::Module {
public: public:
TestImgui(Archimedes::App*, void*); TestImgui(Archimedes::App*, void*);
TestImgui() { name = "TestImgui"; }
~TestImgui(); ~TestImgui();
void onLoad(); void onLoad();

View File

@@ -4,6 +4,7 @@ class TestMenu : public Archimedes::Module {
public: public:
TestMenu(Archimedes::App*, void*); TestMenu(Archimedes::App*, void*);
TestMenu() { name = "TestMenu"; }
~TestMenu(); ~TestMenu();
void run(); void run();
void onLoad() {} void onLoad() {}