introduce active and passive events

This commit is contained in:
2025-04-23 13:51:09 -05:00
parent a3fb96abb7
commit b4ac013f18
17 changed files with 197 additions and 42 deletions

View File

@@ -47,12 +47,12 @@ void MainGUI::run() {
ImGui::InputText("module: ", &s);
if(ImGui::Button("load"))
app->startModule(s);
app->emitEvent(new Archimedes::DoLoadModuleEvent(s));
ImGui::SameLine();
if(ImGui::Button("unload"))
app->stopModule(s);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(s));
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();

View File

@@ -114,7 +114,7 @@ void Ollama::run() {
if(code != CURLE_OK) {
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
return;
} else {
jsonObj = nlohmann::json::parse(response);

View File

@@ -17,7 +17,11 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
}
Terminal::~Terminal() {
if(app) {}
if(app) {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
}
void Terminal::onLoad() {
@@ -29,7 +33,7 @@ void Terminal::onLoad() {
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
ImGui::SetCurrentContext(im->aquireContext());
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
@@ -67,7 +71,7 @@ void Terminal::run() {
rc = read(master, opArr, 150);
if(rc < 0) {
//error on read
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
} else {
if(input == "clear") output = "";
output += opArr;

View File

@@ -55,7 +55,7 @@ bool WindowModule::onEvent(const Archimedes::Event& e) {
window->getSize(renderer->w, renderer->h);
return true;
} else if(type == app->getEventType(Archimedes::WindowCloseEvent())) {
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
return true;
} else if(type == app->getEventType(Archimedes::WindowKeyPressedEvent())) {

View File

@@ -14,8 +14,25 @@ ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
deps[*im] = im;
}
ChatClient::~ChatClient() {
if(app) {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
}
void ChatClient::onLoad() {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) {
std::cout << "No ImguiModule for TestImgui!\n";
std::abort();
}
ImGui::SetCurrentContext(im->aquireContext());
}
@@ -58,7 +75,7 @@ void ChatClient::run() {
ImGui::End();
} else {
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}
}

View File

@@ -12,9 +12,7 @@ class ChatClient : public Archimedes::Module {
ChatClient() { name = "ChatClient"; }
~ChatClient() {
if(app) {}
}
~ChatClient();
void onLoad();

View File

@@ -12,5 +12,5 @@ DependsOnPrint::~DependsOnPrint() {
void DependsOnPrint::run() {
std::cout << "DependsOnPrint lib loaded and run!\n";
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}

View File

@@ -15,5 +15,5 @@ DependsOnPrintStatic::~DependsOnPrintStatic() {
void DependsOnPrintStatic::run() {
std::cout << "DependsOnPrintStatic lib loaded and run!\n";
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}

View File

@@ -10,19 +10,21 @@ TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
}
TestImgui::~TestImgui() {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
void TestImgui::onLoad() {
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) {
std::cout << "No ImguiModule for TestImgui!\n";
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
ImGui::SetCurrentContext(im->aquireContext());
}
@@ -30,7 +32,7 @@ void TestImgui::run() {
if(demo)
ImGui::ShowDemoWindow(&this->demo);
else
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
{
ImGuiIO& io = ImGui::GetIO();

View File

@@ -26,7 +26,7 @@ void TestMenu::run() {
num--;
break;
case 3:
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
break;
case 4:
app->end();