ImguiEmbed
This commit is contained in:
44
flake.nix
44
flake.nix
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
Archimedes = {
|
Archimedes = {
|
||||||
examples = {
|
examples = {
|
||||||
minimal = pkgs.stdenvNoCC.mkDerivation {
|
MinimalApp = pkgs.stdenvNoCC.mkDerivation {
|
||||||
|
|
||||||
name = "Archimedes";
|
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
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,19 +21,19 @@ namespace Archimedes {
|
|||||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||||
void* handle = (*it)->getHandle();
|
void* handle = (*it)->getHandle();
|
||||||
delete *it;
|
delete *it;
|
||||||
dlclose(handle);
|
if(handle)
|
||||||
|
dlclose(handle);
|
||||||
it = modules.erase(it);
|
it = modules.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Module* App::dynamicLoad(std::string lib) {
|
||||||
bool App::load(std::string lib, std::list<std::string> blacklist = {}) {
|
|
||||||
|
|
||||||
void* h = dlopen(lib.c_str(), RTLD_NOW);
|
void* h = dlopen(lib.c_str(), RTLD_NOW);
|
||||||
|
|
||||||
if(!h) {
|
if(!h) {
|
||||||
std::cout << "could not open lib at: \"" << lib.c_str() << "\"\nError: " << dlerror() << std::endl;
|
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");
|
Module::create_t* create = (Module::create_t*) dlsym(h, "create");
|
||||||
@@ -41,15 +41,25 @@ namespace Archimedes {
|
|||||||
if(err) {
|
if(err) {
|
||||||
std::cout << "error finding create function in file: " << lib << std::endl;
|
std::cout << "error finding create function in file: " << lib << std::endl;
|
||||||
std::cout << "dlerror(): " << err << 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++) {
|
for(auto it = blacklist.begin(); it != blacklist.end(); it++) {
|
||||||
if(*it == m->getName()) {
|
if(*it == m->getName()) {
|
||||||
std::cout << "Module \"" << *it << "\" is already loaded!\n";
|
std::cout << "Module \"" << *it << "\" is already loaded!\n";
|
||||||
delete m;
|
delete m;
|
||||||
dlclose(h);
|
if(h)
|
||||||
|
dlclose(h);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +76,7 @@ namespace Archimedes {
|
|||||||
skip = false;
|
skip = false;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
load(it->second, blacklist);
|
load(dynamicLoad(it->second), blacklist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +96,8 @@ namespace Archimedes {
|
|||||||
modules.erase(m->self);
|
modules.erase(m->self);
|
||||||
delete m;
|
delete m;
|
||||||
|
|
||||||
dlclose(h);
|
if(h)
|
||||||
|
dlclose(h);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ namespace Archimedes {
|
|||||||
std::list<Module*> toClose;
|
std::list<Module*> toClose;
|
||||||
std::list<std::string> toOpen;
|
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 unload(std::list<Module*>::iterator);
|
||||||
|
|
||||||
virtual void printHelp() = 0;
|
virtual void printHelp() = 0;
|
||||||
|
|||||||
26
src/example_apps/ImguiEmbed/ImguiEmbed.cpp
Normal file
26
src/example_apps/ImguiEmbed/ImguiEmbed.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
src/example_apps/ImguiEmbed/ImguiEmbed.h
Normal file
30
src/example_apps/ImguiEmbed/ImguiEmbed.h
Normal 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(); }
|
||||||
@@ -18,7 +18,7 @@ void MinimalApp::run() {
|
|||||||
toClose.clear();
|
toClose.clear();
|
||||||
|
|
||||||
for(std::string s : toOpen) {
|
for(std::string s : toOpen) {
|
||||||
load(s, getBlacklist());
|
load(dynamicLoad(s), getBlacklist());
|
||||||
}
|
}
|
||||||
toOpen.clear();
|
toOpen.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user