ImguiEmbed

This commit is contained in:
2025-03-29 23:23:49 -05:00
parent e087ac70d1
commit 0c67caf827
6 changed files with 123 additions and 12 deletions

View File

@@ -20,7 +20,7 @@
Archimedes = {
examples = {
minimal = pkgs.stdenvNoCC.mkDerivation {
MinimalApp = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
@@ -48,6 +48,48 @@
'';
};
ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = ./.;
inherit imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
];
buildPhase = ''
clang++ \
src/example_apps/ImguiEmbed/*.cpp \
modules/GUImodules/TestImgui/src/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/*.cpp \
include/utils/App/App.cpp \
include/utils/Renderer/*.cpp \
include/utils/Window/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-I src -I include -I $imgui -I . \
-lGL -lglfw -lGLEW \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
};
};

View File

@@ -21,19 +21,19 @@ namespace Archimedes {
for(auto it = modules.begin(); it != modules.end(); it++) {
void* handle = (*it)->getHandle();
delete *it;
if(handle)
dlclose(handle);
it = modules.erase(it);
}
}
bool App::load(std::string lib, std::list<std::string> blacklist = {}) {
Module* App::dynamicLoad(std::string lib) {
void* h = dlopen(lib.c_str(), RTLD_NOW);
if(!h) {
std::cout << "could not open lib at: \"" << lib.c_str() << "\"\nError: " << dlerror() << std::endl;
return false;
return nullptr;
}
Module::create_t* create = (Module::create_t*) dlsym(h, "create");
@@ -41,14 +41,24 @@ namespace Archimedes {
if(err) {
std::cout << "error finding create function in file: " << lib << std::endl;
std::cout << "dlerror(): " << err << std::endl;
return nullptr;
}
Module* m = create(h, App::Get());
return create(h, Get());
}
bool App::load(Module* m, std::list<std::string> blacklist = {}) {
if(!m) {
return false;
}
void* h = m->getHandle();
for(auto it = blacklist.begin(); it != blacklist.end(); it++) {
if(*it == m->getName()) {
std::cout << "Module \"" << *it << "\" is already loaded!\n";
delete m;
if(h)
dlclose(h);
return false;
}
@@ -66,7 +76,7 @@ namespace Archimedes {
skip = false;
continue;
} else {
load(it->second, blacklist);
load(dynamicLoad(it->second), blacklist);
}
}
@@ -86,6 +96,7 @@ namespace Archimedes {
modules.erase(m->self);
delete m;
if(h)
dlclose(h);
}

View File

@@ -17,7 +17,9 @@ namespace Archimedes {
std::list<Module*> toClose;
std::list<std::string> toOpen;
virtual bool load(std::string, std::list<std::string>);
Module* dynamicLoad(std::string);
virtual bool load(Module*, std::list<std::string>);
virtual void unload(std::list<Module*>::iterator);
virtual void printHelp() = 0;

View File

@@ -0,0 +1,26 @@
#include "ImguiEmbed.h"
void ImguiEmbed::run() {
for(auto* m : modules)
m->onLoad();
// Main loop
while (!done && !modules.empty()) {
for(auto* m : modules) {
m->run();
}
for(auto it = toClose.begin(); it != toClose.end(); it++) {
unload(it);
}
toClose.clear();
for(std::string s : toOpen) {
load(dynamicLoad(s), getBlacklist());
}
toOpen.clear();
}
}

View File

@@ -0,0 +1,30 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/GUImodules/TestImgui/src/TestImgui.h"
class ImguiEmbed : public Archimedes::App {
private:
void printHelp() {};
public:
ImguiEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new TestImgui(nullptr, Get());
load(m, {});
};
~ImguiEmbed() {};
void handleArgs(const int& argc, char* argv[]) {};
void run();
//void stopModule(std::list<Archimedes::Module*>::iterator);
//void startModule(std::string);
};
Archimedes::App* MakeApp() { return new ImguiEmbed(); }

View File

@@ -18,7 +18,7 @@ void MinimalApp::run() {
toClose.clear();
for(std::string s : toOpen) {
load(s, getBlacklist());
load(dynamicLoad(s), getBlacklist());
}
toOpen.clear();
}