refactor
This commit is contained in:
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