make include headers only
This commit is contained in:
@@ -1,124 +0,0 @@
|
||||
#include "App.h"
|
||||
|
||||
Archimedes::App* Archimedes::App::instance = nullptr;
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
|
||||
App::App() {
|
||||
|
||||
if(instance != nullptr) {
|
||||
std::cout << "App already exists\nThere can only be one!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
instance = this;
|
||||
|
||||
}
|
||||
|
||||
App::~App() {
|
||||
|
||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||
void* handle = (*it)->getHandle();
|
||||
delete *it;
|
||||
if(handle)
|
||||
dlclose(handle);
|
||||
it = modules.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
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 nullptr;
|
||||
}
|
||||
|
||||
Module::create_t* create = (Module::create_t*) dlsym(h, "create");
|
||||
char* err = dlerror();
|
||||
if(err) {
|
||||
std::cout << "error finding create function in file: " << lib << std::endl;
|
||||
std::cout << "dlerror(): " << err << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return create(h, Get());
|
||||
}
|
||||
|
||||
std::list<Module*>::iterator App::load(Module* m, std::list<std::string> blacklist = {}) {
|
||||
|
||||
if(!m) {
|
||||
return modules.end();
|
||||
}
|
||||
|
||||
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 modules.end();
|
||||
}
|
||||
}
|
||||
|
||||
blacklist.push_back(m->getName());
|
||||
|
||||
bool skip = false;
|
||||
for(auto it = m->deps.begin(); it != m->deps.end(); it++) {
|
||||
for(std::string s : blacklist) {
|
||||
if(it->first == s)
|
||||
skip = true;
|
||||
}
|
||||
if(skip) {
|
||||
skip = false;
|
||||
continue;
|
||||
} else {
|
||||
if(std::holds_alternative<std::string>(it->second))
|
||||
m->depsInstances[it->first] = load(std::get<std::string>(it->second), blacklist);
|
||||
else
|
||||
m->depsInstances[it->first] = load(std::get<Module*>(it->second), blacklist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
modules.push_back(m);
|
||||
m->setSelf(--modules.end());
|
||||
modules.end()++;
|
||||
/*
|
||||
m->setSelf(modules.end());
|
||||
modules.push_back(m);
|
||||
*/
|
||||
return m->self;
|
||||
}
|
||||
|
||||
std::list<Module*>::iterator App::load(std::string modulePath, std::list<std::string> blacklist = {}) {
|
||||
Module* m = dynamicLoad(modulePath);
|
||||
return load(m, blacklist);
|
||||
}
|
||||
|
||||
|
||||
void App::unload(std::list<Module*>::iterator it) {
|
||||
|
||||
Module* m = *it;
|
||||
void* h = m->getHandle();
|
||||
|
||||
modules.erase(m->self);
|
||||
delete m;
|
||||
|
||||
if(h)
|
||||
dlclose(h);
|
||||
|
||||
}
|
||||
|
||||
void App::stopModule(std::list<Module*>::iterator it) {
|
||||
toClose.push_back(*it);
|
||||
}
|
||||
|
||||
void App::startModule(std::string lib) {
|
||||
toOpen.push_back(lib);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,20 +8,130 @@ namespace Archimedes {
|
||||
|
||||
class App {
|
||||
|
||||
protected:
|
||||
static App* instance;
|
||||
public:
|
||||
App() {
|
||||
if(instance != nullptr) {
|
||||
std::cout << "App already exists\nThere can only be one!\n";
|
||||
std::abort();
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
|
||||
virtual ~App() {
|
||||
|
||||
for(auto it = modules.begin(); it != modules.end(); it++) {
|
||||
void* handle = (*it)->getHandle();
|
||||
delete *it;
|
||||
if(handle)
|
||||
dlclose(handle);
|
||||
it = modules.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static App* Get() { return instance; }
|
||||
|
||||
virtual void handleArgs(const int&, char*[]) = 0;
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
virtual void stopModule(std::list<Module*>::iterator it) { toClose.push_back(*it); }
|
||||
|
||||
virtual void startModule(std::string lib) { toOpen.push_back(lib); }
|
||||
|
||||
void end() { done = true; }
|
||||
|
||||
private:
|
||||
|
||||
bool done = false;
|
||||
|
||||
inline static App* instance = nullptr;
|
||||
|
||||
protected:
|
||||
|
||||
std::list<Module*> modules;
|
||||
std::list<Module*> toClose;
|
||||
std::list<std::string> toOpen;
|
||||
|
||||
Module* dynamicLoad(std::string);
|
||||
virtual std::list<Module*>::iterator load(std::string, std::list<std::string>);
|
||||
virtual std::list<Module*>::iterator load(Module*, std::list<std::string>);
|
||||
virtual Module* dynamicLoad(std::string lib) {
|
||||
|
||||
virtual void unload(std::list<Module*>::iterator);
|
||||
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 nullptr;
|
||||
}
|
||||
|
||||
Module::create_t* create = (Module::create_t*) dlsym(h, "create");
|
||||
char* err = dlerror();
|
||||
if(err) {
|
||||
std::cout << "error finding create function in file: " << lib << std::endl;
|
||||
std::cout << "dlerror(): " << err << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return create(h, Get());
|
||||
}
|
||||
|
||||
virtual std::list<Module*>::iterator load(std::string modulePath, std::list<std::string> blacklist = {}) {
|
||||
Module* m = dynamicLoad(modulePath);
|
||||
return load(m, blacklist);
|
||||
}
|
||||
|
||||
virtual std::list<Module*>::iterator load(Module* m, std::list<std::string> blacklist = {}) {
|
||||
|
||||
if(!m) {
|
||||
return modules.end();
|
||||
}
|
||||
|
||||
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 modules.end();
|
||||
}
|
||||
}
|
||||
|
||||
blacklist.push_back(m->getName());
|
||||
|
||||
bool skip = false;
|
||||
for(auto it = m->deps.begin(); it != m->deps.end(); it++) {
|
||||
for(std::string s : blacklist) {
|
||||
if(it->first == s)
|
||||
skip = true;
|
||||
}
|
||||
if(skip) {
|
||||
skip = false;
|
||||
continue;
|
||||
} else {
|
||||
if(std::holds_alternative<std::string>(it->second))
|
||||
m->depsInstances[it->first] = load(std::get<std::string>(it->second), blacklist);
|
||||
else
|
||||
m->depsInstances[it->first] = load(std::get<Module*>(it->second), blacklist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
modules.push_back(m);
|
||||
m->setSelf(--modules.end());
|
||||
modules.end()++;
|
||||
|
||||
return m->self;
|
||||
}
|
||||
|
||||
virtual void unload(std::list<Module*>::iterator it) {
|
||||
Module* m = *it;
|
||||
void* h = m->getHandle();
|
||||
|
||||
modules.erase(m->self);
|
||||
delete m;
|
||||
|
||||
if(h)
|
||||
dlclose(h);
|
||||
}
|
||||
|
||||
virtual void printHelp() = 0;
|
||||
|
||||
@@ -32,21 +142,6 @@ namespace Archimedes {
|
||||
return l;
|
||||
}
|
||||
|
||||
public:
|
||||
App();
|
||||
virtual ~App();
|
||||
|
||||
static App* Get() { return instance; }
|
||||
|
||||
virtual void handleArgs(const int&, char*[]) = 0;
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
virtual void stopModule(std::list<Module*>::iterator);
|
||||
|
||||
virtual void startModule(std::string);
|
||||
|
||||
void end() { done = true; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,19 +12,17 @@ namespace Archimedes {
|
||||
typedef GuiModule* create_t(void*, App*);
|
||||
|
||||
GuiModule(void* h, App* a) : Module(h, a) {
|
||||
window = new WindowModule(nullptr, a);
|
||||
deps["WindowModule"] = window;
|
||||
windowModule = new WindowModule(nullptr, a);
|
||||
deps["WindowModule"] = windowModule;
|
||||
}
|
||||
virtual ~GuiModule() { if(window) delete window; }
|
||||
virtual ~GuiModule() {}
|
||||
virtual void onLoad() = 0;
|
||||
virtual void run() = 0;
|
||||
|
||||
Window* getWindow() { return window; }
|
||||
void createWindow() { window = new Window(); }
|
||||
Window* getWindow() { return windowModule; }
|
||||
|
||||
protected:
|
||||
WindowModule* window;
|
||||
//Renderer* renderer;
|
||||
WindowModule* windowModule;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#include "Renderer.h"
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
void Renderer::render() {
|
||||
r.render(rc, w, h);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
|
||||
#include "pch.hpp"
|
||||
#include "RendererOpenGL/RendererOpenGL.h"
|
||||
|
||||
namespace Archimedes {
|
||||
@@ -15,7 +15,9 @@ namespace Archimedes {
|
||||
|
||||
void init() { r.init(); }
|
||||
|
||||
void render();
|
||||
void render() {
|
||||
r.render(rc, w, h);
|
||||
}
|
||||
|
||||
std::list<renderCmd*>::iterator addRenderCmd(renderCmd* cmd) {
|
||||
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "Window.h"
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
void Window::doFrame() {
|
||||
|
||||
window.pollEvents();
|
||||
|
||||
window.getSize(renderer.w, renderer.h);
|
||||
|
||||
renderer.render();
|
||||
|
||||
window.doFrame();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,13 +15,24 @@ namespace Archimedes {
|
||||
|
||||
bool shouldClose() { return window.shouldClose(); }
|
||||
|
||||
void doFrame();
|
||||
void doFrame() {
|
||||
|
||||
window.pollEvents();
|
||||
|
||||
window.getSize(renderer->w, renderer->h);
|
||||
|
||||
renderer->render();
|
||||
|
||||
window.doFrame();
|
||||
}
|
||||
|
||||
Renderer* getRenderer() { return renderer; }
|
||||
void setRenderer(Renderer* r) { renderer = r; }
|
||||
|
||||
Renderer& getRenderer() { return renderer; }
|
||||
WindowImpl& getWindowImpl() { return window; }
|
||||
|
||||
private:
|
||||
Renderer renderer;
|
||||
Renderer* renderer;
|
||||
|
||||
WindowImpl window;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user