refactor
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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&);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -12,6 +12,8 @@ class ImguiModule : public Archimedes::Module {
|
||||
public:
|
||||
ImguiModule(Archimedes::App*, void*);
|
||||
|
||||
ImguiModule() { name = "ImguiModule"; }
|
||||
|
||||
~ImguiModule();
|
||||
|
||||
void onLoad();
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -5,6 +5,8 @@ class MainGUI : public Archimedes::Module {
|
||||
public:
|
||||
MainGUI(Archimedes::App*, void*);
|
||||
|
||||
MainGUI() { name = "MainGUI"; }
|
||||
|
||||
~MainGUI();
|
||||
|
||||
void onLoad();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -8,6 +8,7 @@ class Ollama : public Archimedes::Module {
|
||||
public:
|
||||
Ollama(Archimedes::App*, void*);
|
||||
|
||||
Ollama() { name = "Ollama"; }
|
||||
~Ollama();
|
||||
|
||||
void onLoad();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,6 +5,7 @@ class Terminal : public Archimedes::Module {
|
||||
public:
|
||||
Terminal(Archimedes::App*, void*);
|
||||
|
||||
Terminal() { name = "Terminal"; }
|
||||
~Terminal();
|
||||
|
||||
void onLoad();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
58
modules/examples/ChatClient/src/ChatClient.cpp
Normal file
58
modules/examples/ChatClient/src/ChatClient.cpp
Normal 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;
|
||||
}
|
||||
27
modules/examples/ChatClient/src/ChatClient.h
Normal file
27
modules/examples/ChatClient/src/ChatClient.h
Normal 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;
|
||||
};
|
||||
@@ -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()]; }
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -4,6 +4,7 @@ class Print : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Print(Archimedes::App*, void*);
|
||||
Print() { name = "Print"; }
|
||||
~Print();
|
||||
void run();
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -5,6 +5,8 @@ class TestImgui : public Archimedes::Module {
|
||||
public:
|
||||
TestImgui(Archimedes::App*, void*);
|
||||
|
||||
TestImgui() { name = "TestImgui"; }
|
||||
|
||||
~TestImgui();
|
||||
|
||||
void onLoad();
|
||||
|
||||
@@ -4,6 +4,7 @@ class TestMenu : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestMenu(Archimedes::App*, void*);
|
||||
TestMenu() { name = "TestMenu"; }
|
||||
~TestMenu();
|
||||
void run();
|
||||
void onLoad() {}
|
||||
|
||||
Reference in New Issue
Block a user