This commit is contained in:
2025-05-02 10:35:11 -05:00
parent 74b82845b5
commit 2ef95d6e90
6 changed files with 85 additions and 10 deletions

View File

@@ -107,7 +107,36 @@ namespace Archimedes {
virtual void startModule(std::variant<std::string, Module*> m) { toOpen.push_back(m); }
virtual bool onEvent(const Event&) = 0;
virtual bool onEvent(const Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
}
return false;
}
void handleEvents() {
static bool handled;
@@ -129,6 +158,7 @@ namespace Archimedes {
}
if(!handled) {
std::cout << "here?\n";
if(this->onEvent(*events.front())) {
Event* e = events.front();
events.pop_front();
@@ -173,7 +203,8 @@ namespace Archimedes {
virtual Module* load(std::string moduleNameOrPath) {
Module* m = dynamicLoad(moduleNameOrPath);
return m != nullptr ? load(m) : reload(moduleNameOrPath);
//return m != nullptr ? load(m) : reload(moduleNameOrPath);
return load(m);
}
virtual Module* load(Module* m) {
@@ -182,6 +213,8 @@ namespace Archimedes {
return nullptr;
}
std::cout << "Load: " << (std::string) *m << "1\n";
void* h = m->getHandle();
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
if(*it == static_cast<std::string>(*m)) {
@@ -193,10 +226,14 @@ namespace Archimedes {
return modules[*it];
}
}
std::cout << "Load: " << (std::string) *m << "2\n";
if(modules.find(*m) == modules.end())
modules[*m] = m;
std::cout << "Load: " << (std::string) *m << "3\n";
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
if(m->deps.find(*it) != m->deps.end()) {
@@ -208,6 +245,8 @@ namespace Archimedes {
}
}
std::cout << "Load: " << (std::string) *m << "4\n";
//insert temporarily to avoid circular dependencies
runOrder.insert(roInsert, *m);
@@ -229,12 +268,21 @@ namespace Archimedes {
m->moduleInstances[it.first] = load(std::get<Module*>(it.second));
}
std::cout << "Load: " << (std::string) *m << "5\n";
//reinsert once final order has been reached
runOrder.remove(*m);
std::cout << "Load: " << (std::string) *m << "6\n";
runOrder.insert(roInsert, *m);
std::cout << "Load: " << (std::string) *m << "7\n";
emitEvent(new LoadModuleEvent(*m));
std::cout << "Load: " << (std::string) *m << "8\n";
return m;
}

View File

@@ -39,7 +39,11 @@ void ImguiModule::onLoad() {
std::abort();
}
std::cout << "onLoad: " << name << "1\n";
window = wm->aquireWindow();
std::cout << "onLoad: " << name << "2\n";
IMGUI_CHECKVERSION();
context = ImGui::CreateContext();
@@ -57,13 +61,19 @@ void ImguiModule::onLoad() {
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
std::cout << "onLoad: " << name << "3\n";
// Setup Platform/Renderer backends
if(!ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true))
std::cout << "GLFWImpl failed\n";
std::cout << "onLoad: " << name << "3.5\n";
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
}
std::cout << "onLoad: " << name << "4\n";
wm->getRenderer()->getCmdList().push_back([](){
ImGui::Render();
@@ -75,12 +85,16 @@ void ImguiModule::onLoad() {
ImGui::NewFrame();
});
std::cout << "onLoad: " << name << "5\n";
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
std::cout << "onLoad: " << name << "6\n";
//Compute first frame ahead of first WindowModule->run()
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
std::cout << "ImguiModule loaded\n";
}
bool ImguiModule::onEvent(const Archimedes::Event &event) {

View File

@@ -20,7 +20,7 @@ WindowModule::~WindowModule() {
}
if(window)
delete window;
releaseWindow(window);
}
}

View File

@@ -1,3 +1,8 @@
#include "modules/ImguiModule/src/ImguiModule.h"
#include "modules/ClientModule/src/ClientModule.h"
#include "ChatClient.h"
@@ -5,6 +10,8 @@ ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
name = "ChatClient";
std::cout << name;
ClientModule* cm = new ClientModule(a, h);
deps[*cm] = cm;
cm->shouldHandleEvents(ClientModule::CMEventEnum::ConnectionStatusChanged | ClientModule::CMEventEnum::DataSent);
@@ -12,6 +19,8 @@ ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
ImguiModule* im = new ImguiModule(a, h);
deps[*im] = im;
std::cout << " created!\n";
}
ChatClient::~ChatClient() {
@@ -30,12 +39,18 @@ void ChatClient::onLoad() {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) {
std::cout << "No ClientModule for ChatClient!\n";
std::cout << "No ImguiModule for ChatClient!\n";
std::abort();
}
ImGui::SetCurrentContext(im->aquireContext());
ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
if(!cm) {
std::cout << "No ClientModule for ChatClient!\n";
std::abort();
}
}
void ChatClient::run() {

View File

@@ -1,8 +1,5 @@
#include "Archimedes.h"
#include "modules/ClientModule/src/ClientModule.h"
#include "modules/ImguiModule/src/ImguiModule.h"
class ChatClient : public Archimedes::Module {
@@ -14,11 +11,11 @@ class ChatClient : public Archimedes::Module {
~ChatClient();
void onLoad();
void onLoad() override;
void run();
void run() override;
bool onEvent(const Archimedes::Event&);
bool onEvent(const Archimedes::Event&) override;
private:
std::string messages = "";

View File

@@ -3,6 +3,7 @@
void MinimalApp::run() {
for(std::string m : runOrder) {
std::cout << "onLoad: " << m << std::endl;
modules[m]->onLoad();
}