diff --git a/include/utils/App/App.h b/include/utils/App/App.h index 0c0cc08..c3f278e 100644 --- a/include/utils/App/App.h +++ b/include/utils/App/App.h @@ -140,7 +140,7 @@ namespace Archimedes { void* h = m->getHandle(); for(auto it = runOrder.begin(); it != runOrder.end(); it++) { - if(*it == m->getName()) { + if(*it == static_cast(*m)) { std::cout << "Module \"" << *it << "\" is already loaded!\n"; delete m; if(h) { @@ -150,7 +150,7 @@ namespace Archimedes { } } - modules[m->getName()] = m; + modules[*m] = m; for(auto it = runOrder.begin(); it != runOrder.end(); it++) { @@ -164,7 +164,7 @@ namespace Archimedes { } //insert temporarily to avoid circular dependencies - runOrder.insert(roInsert, m->getName()); + runOrder.insert(roInsert, *m); bool skip = false; for(auto it : m->deps) { @@ -185,9 +185,9 @@ namespace Archimedes { } //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; } diff --git a/modules/ClientModule/src/ClientModule.cpp b/modules/ClientModule/src/ClientModule.cpp index 974810e..b87c612 100644 --- a/modules/ClientModule/src/ClientModule.cpp +++ b/modules/ClientModule/src/ClientModule.cpp @@ -62,7 +62,7 @@ bool ClientModule::onEvent(const Archimedes::Event& 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; @@ -114,9 +114,9 @@ bool ClientModule::onEvent(const Archimedes::Event& event) { } return true; - } else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType("DataRecievedEvent")) { + } else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(CMEvent::DataRecievedEvent())) { return true; - } else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType("DataSentEvent")) { + } else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(CMEvent::DataSentEvent())) { return true; } diff --git a/modules/ClientModule/src/ClientModule.h b/modules/ClientModule/src/ClientModule.h index 512ffb5..baa6115 100644 --- a/modules/ClientModule/src/ClientModule.h +++ b/modules/ClientModule/src/ClientModule.h @@ -9,9 +9,15 @@ class ClientModule : public Archimedes::Module { public: ClientModule(Archimedes::App*, void*); + + ClientModule() { name = "ClientModule"; } + ~ClientModule(); + void onLoad(); + void run(); + bool onEvent(const Archimedes::Event&); void startClient(SteamNetworkingIPAddr&); diff --git a/modules/ImguiModule/src/ImguiModule.cpp b/modules/ImguiModule/src/ImguiModule.cpp index 8ff6dd4..22a0647 100644 --- a/modules/ImguiModule/src/ImguiModule.cpp +++ b/modules/ImguiModule/src/ImguiModule.cpp @@ -14,22 +14,26 @@ ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Mo name = "ImguiModule"; WindowModule* wm = new WindowModule(a, h); - deps[wm->getName()] = wm; + deps[*wm] = wm; } ImguiModule::~ImguiModule() { - - WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"]; - wm->getRenderer()->getCmdList().erase(rcmd_it); - - ImGui_ImplOpenGL3_Shutdown(); - ImGui_ImplGlfw_Shutdown(); - ImGui::DestroyContext(); + + if(app) { + WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; } + + wm->getRenderer()->getCmdList().erase(rcmd_it); + + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + } } void ImguiModule::onLoad() { - WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"]; + WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; } + if(!wm) { std::cout << "No WindowModule for ImguiModule!\n"; std::abort(); diff --git a/modules/ImguiModule/src/ImguiModule.h b/modules/ImguiModule/src/ImguiModule.h index 1898b26..3c85835 100644 --- a/modules/ImguiModule/src/ImguiModule.h +++ b/modules/ImguiModule/src/ImguiModule.h @@ -12,6 +12,8 @@ class ImguiModule : public Archimedes::Module { public: ImguiModule(Archimedes::App*, void*); + ImguiModule() { name = "ImguiModule"; } + ~ImguiModule(); void onLoad(); diff --git a/modules/MainGUI/src/MainGUI.cpp b/modules/MainGUI/src/MainGUI.cpp index 87cdaed..df90d31 100644 --- a/modules/MainGUI/src/MainGUI.cpp +++ b/modules/MainGUI/src/MainGUI.cpp @@ -7,16 +7,17 @@ MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) { name = "MainGUI"; ImguiModule* im = new ImguiModule(a, h); - deps[im->getName()] = im; + deps[*im] = im; } MainGUI::~MainGUI() { + if(app) {} } void MainGUI::onLoad() { - ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"]; + ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; } if(!im) { std::cout << "No ImguiModule for MainGUI!\n"; diff --git a/modules/MainGUI/src/MainGUI.h b/modules/MainGUI/src/MainGUI.h index 5f5c937..7b00974 100644 --- a/modules/MainGUI/src/MainGUI.h +++ b/modules/MainGUI/src/MainGUI.h @@ -5,6 +5,8 @@ class MainGUI : public Archimedes::Module { public: MainGUI(Archimedes::App*, void*); + MainGUI() { name = "MainGUI"; } + ~MainGUI(); void onLoad(); diff --git a/modules/Ollama/src/Ollama.cpp b/modules/Ollama/src/Ollama.cpp index 49ee80c..1c04871 100644 --- a/modules/Ollama/src/Ollama.cpp +++ b/modules/Ollama/src/Ollama.cpp @@ -8,15 +8,17 @@ Ollama::Ollama(Archimedes::App* a, void* h) : Archimedes::Module(a, h) { name = "Ollama"; ImguiModule* im = new ImguiModule(a, h); - deps[im->getName()] = im; + deps[*im] = im; } Ollama::~Ollama() { - if(curl) { - curl_easy_cleanup(curl); - curl = nullptr; + if(app) { + if(curl) { + 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) @@ -27,7 +29,7 @@ static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostr void Ollama::onLoad() { - ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"]; + ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; } if(!im) { std::cout << "No ImguiModule for Ollama!\n"; @@ -109,7 +111,7 @@ void Ollama::run() { if(code != CURLE_OK) { std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl; - app->stopModule(getName()); + app->stopModule(name); return; } else { jsonObj = nlohmann::json::parse(response); diff --git a/modules/Ollama/src/Ollama.h b/modules/Ollama/src/Ollama.h index f32ae25..da683e7 100644 --- a/modules/Ollama/src/Ollama.h +++ b/modules/Ollama/src/Ollama.h @@ -8,6 +8,7 @@ class Ollama : public Archimedes::Module { public: Ollama(Archimedes::App*, void*); + Ollama() { name = "Ollama"; } ~Ollama(); void onLoad(); diff --git a/modules/ServerModule/src/ServerModule.cpp b/modules/ServerModule/src/ServerModule.cpp index 6a7b094..84364a5 100644 --- a/modules/ServerModule/src/ServerModule.cpp +++ b/modules/ServerModule/src/ServerModule.cpp @@ -79,7 +79,7 @@ bool ServerModule::onEvent(const Archimedes::Event& 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; @@ -192,9 +192,9 @@ bool ServerModule::onEvent(const Archimedes::Event& event) { } return true; - } else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType("DataRecievedEvent")) { + } else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(SMEvent::DataRecievedEvent())) { return true; - } else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType("DataSentEvent")) { + } else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(SMEvent::DataSentEvent())) { return true; } diff --git a/modules/Terminal/src/Terminal.cpp b/modules/Terminal/src/Terminal.cpp index 0aefbaf..665ba52 100644 --- a/modules/Terminal/src/Terminal.cpp +++ b/modules/Terminal/src/Terminal.cpp @@ -17,12 +17,12 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) { } Terminal::~Terminal() { - + if(app) {} } void Terminal::onLoad() { - ImguiModule* im = (ImguiModule*) moduleInstances[ImguiModule()]; + ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; } if(!im) { std::cout << "No ImguiModule for Terminal!\n"; @@ -67,7 +67,7 @@ void Terminal::run() { rc = read(master, opArr, 150); if(rc < 0) { //error on read - app->stopModule(getName()); + app->stopModule(name); } else { if(input == "clear") output = ""; output += opArr; diff --git a/modules/Terminal/src/Terminal.h b/modules/Terminal/src/Terminal.h index 4c46ca3..4466c11 100644 --- a/modules/Terminal/src/Terminal.h +++ b/modules/Terminal/src/Terminal.h @@ -5,6 +5,7 @@ class Terminal : public Archimedes::Module { public: Terminal(Archimedes::App*, void*); + Terminal() { name = "Terminal"; } ~Terminal(); void onLoad(); diff --git a/modules/WindowModule/src/WindowModule.cpp b/modules/WindowModule/src/WindowModule.cpp index 830e765..9d5e8c5 100644 --- a/modules/WindowModule/src/WindowModule.cpp +++ b/modules/WindowModule/src/WindowModule.cpp @@ -1,12 +1,14 @@ #include "WindowModule.h" WindowModule::~WindowModule() { - if(renderer) { - renderer->getCmdList().clear(); - delete renderer; - } - if(window) { - delete window; + if(app) { + if(renderer) { + renderer->getCmdList().clear(); + delete renderer; + } + if(window) { + delete window; + } } } diff --git a/modules/WindowModule/src/WindowModule.h b/modules/WindowModule/src/WindowModule.h index 01166c0..550a326 100644 --- a/modules/WindowModule/src/WindowModule.h +++ b/modules/WindowModule/src/WindowModule.h @@ -9,7 +9,7 @@ class WindowModule : public Archimedes::Module { public: - WindowModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) { + WindowModule(Archimedes::App* a, void* h) : Archimedes::Module(a, h) { name = "WindowModule"; } diff --git a/modules/examples/ChatClient/src/ChatClient.cpp b/modules/examples/ChatClient/src/ChatClient.cpp new file mode 100644 index 0000000..8e89023 --- /dev/null +++ b/modules/examples/ChatClient/src/ChatClient.cpp @@ -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; +} diff --git a/modules/examples/ChatClient/src/ChatClient.h b/modules/examples/ChatClient/src/ChatClient.h new file mode 100644 index 0000000..3abfff0 --- /dev/null +++ b/modules/examples/ChatClient/src/ChatClient.h @@ -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; +}; diff --git a/modules/examples/ChatServer/src/ChatServer.cpp b/modules/examples/ChatServer/src/ChatServer.cpp index b338251..70c938d 100644 --- a/modules/examples/ChatServer/src/ChatServer.cpp +++ b/modules/examples/ChatServer/src/ChatServer.cpp @@ -14,7 +14,7 @@ bool ChatServer::onEvent(const Archimedes::Event& event) { return true; } else */ - if(type == app->getEventType("DataRecievedEvent")) { + if(type == app->getEventType(SMEvent::DataRecievedEvent())) { static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; } diff --git a/modules/examples/DependsOnPrintStatic/src/DependsOnPrintStatic.cpp b/modules/examples/DependsOnPrintStatic/src/DependsOnPrintStatic.cpp index 4aa2878..90405ee 100644 --- a/modules/examples/DependsOnPrintStatic/src/DependsOnPrintStatic.cpp +++ b/modules/examples/DependsOnPrintStatic/src/DependsOnPrintStatic.cpp @@ -5,7 +5,8 @@ DependsOnPrintStatic::DependsOnPrintStatic(Archimedes::App* a, void* h) : Module(a, h) { name = "DependsOnPrintStatic"; - deps["Print"] = new Print(a, h); + Print* p = new Print(a, h); + deps[*p] = p; } DependsOnPrintStatic::~DependsOnPrintStatic() { diff --git a/modules/examples/Print/src/Print.cpp b/modules/examples/Print/src/Print.cpp index a2996a4..f988706 100644 --- a/modules/examples/Print/src/Print.cpp +++ b/modules/examples/Print/src/Print.cpp @@ -5,7 +5,9 @@ Print::Print(Archimedes::App* a, void* h) : Archimedes::Module(a, h) { } Print::~Print() { - std::cout << "Print Destroyed!\n"; + if(app) { + std::cout << "Print Destroyed!\n"; + } } void Print::run() { diff --git a/modules/examples/Print/src/Print.h b/modules/examples/Print/src/Print.h index 21bcadb..953f608 100644 --- a/modules/examples/Print/src/Print.h +++ b/modules/examples/Print/src/Print.h @@ -4,6 +4,7 @@ class Print : public Archimedes::Module { public: Print(Archimedes::App*, void*); + Print() { name = "Print"; } ~Print(); void run(); }; diff --git a/modules/examples/TestImgui/src/TestImgui.cpp b/modules/examples/TestImgui/src/TestImgui.cpp index 280600d..7c01bed 100644 --- a/modules/examples/TestImgui/src/TestImgui.cpp +++ b/modules/examples/TestImgui/src/TestImgui.cpp @@ -6,7 +6,7 @@ TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) { name = "TestImgui"; ImguiModule* im = new ImguiModule(a, h); - deps[im->getName()] = im; + deps[*im] = im; } TestImgui::~TestImgui() { @@ -30,7 +30,7 @@ void TestImgui::run() { if(demo) ImGui::ShowDemoWindow(&this->demo); else - app->stopModule(getName()); + app->stopModule(name); { ImGuiIO& io = ImGui::GetIO(); diff --git a/modules/examples/TestImgui/src/TestImgui.h b/modules/examples/TestImgui/src/TestImgui.h index 7584e52..01ba993 100644 --- a/modules/examples/TestImgui/src/TestImgui.h +++ b/modules/examples/TestImgui/src/TestImgui.h @@ -5,6 +5,8 @@ class TestImgui : public Archimedes::Module { public: TestImgui(Archimedes::App*, void*); + TestImgui() { name = "TestImgui"; } + ~TestImgui(); void onLoad(); diff --git a/modules/examples/TestMenu/src/TestMenu.h b/modules/examples/TestMenu/src/TestMenu.h index 155822f..6c257c0 100644 --- a/modules/examples/TestMenu/src/TestMenu.h +++ b/modules/examples/TestMenu/src/TestMenu.h @@ -4,6 +4,7 @@ class TestMenu : public Archimedes::Module { public: TestMenu(Archimedes::App*, void*); + TestMenu() { name = "TestMenu"; } ~TestMenu(); void run(); void onLoad() {}