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 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() { void handleEvents() {
static bool handled; static bool handled;
@@ -129,6 +158,7 @@ namespace Archimedes {
} }
if(!handled) { if(!handled) {
std::cout << "here?\n";
if(this->onEvent(*events.front())) { if(this->onEvent(*events.front())) {
Event* e = events.front(); Event* e = events.front();
events.pop_front(); events.pop_front();
@@ -173,7 +203,8 @@ namespace Archimedes {
virtual Module* load(std::string moduleNameOrPath) { virtual Module* load(std::string moduleNameOrPath) {
Module* m = dynamicLoad(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) { virtual Module* load(Module* m) {
@@ -182,6 +213,8 @@ namespace Archimedes {
return nullptr; return nullptr;
} }
std::cout << "Load: " << (std::string) *m << "1\n";
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 == static_cast<std::string>(*m)) { if(*it == static_cast<std::string>(*m)) {
@@ -194,9 +227,13 @@ namespace Archimedes {
} }
} }
std::cout << "Load: " << (std::string) *m << "2\n";
if(modules.find(*m) == modules.end()) if(modules.find(*m) == modules.end())
modules[*m] = m; modules[*m] = m;
std::cout << "Load: " << (std::string) *m << "3\n";
for(auto it = runOrder.begin(); it != runOrder.end(); it++) { for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
if(m->deps.find(*it) != m->deps.end()) { 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 //insert temporarily to avoid circular dependencies
runOrder.insert(roInsert, *m); runOrder.insert(roInsert, *m);
@@ -229,12 +268,21 @@ namespace Archimedes {
m->moduleInstances[it.first] = load(std::get<Module*>(it.second)); 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 //reinsert once final order has been reached
runOrder.remove(*m); runOrder.remove(*m);
std::cout << "Load: " << (std::string) *m << "6\n";
runOrder.insert(roInsert, *m); runOrder.insert(roInsert, *m);
std::cout << "Load: " << (std::string) *m << "7\n";
emitEvent(new LoadModuleEvent(*m)); emitEvent(new LoadModuleEvent(*m));
std::cout << "Load: " << (std::string) *m << "8\n";
return m; return m;
} }

View File

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

View File

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

View File

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

View File

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