move utils to include. utils implimentations should be headers
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#ifndef ARCHIMEDES_H
|
||||
#define ARCHIMEDES_H
|
||||
|
||||
#include "Module.h"
|
||||
#include "GuiModule.h"
|
||||
#include "utils/Module/Module.h"
|
||||
#include "utils/GuiModule/GuiModule.h"
|
||||
#include "App.h"
|
||||
|
||||
#endif
|
||||
|
||||
28
include/utils/GuiModule/GuiModule.h
Normal file
28
include/utils/GuiModule/GuiModule.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef GUIMODULE_H
|
||||
#define GUIMODULE_H
|
||||
|
||||
#include "Module.h"
|
||||
#include "Window/Window.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class GuiModule : public Module {
|
||||
|
||||
public:
|
||||
typedef GuiModule* create_t(void*, App&);
|
||||
|
||||
GuiModule(void* h, App& a) : Module(h, a) {}
|
||||
virtual ~GuiModule() { if(window) delete window; }
|
||||
virtual void onLoad() = 0;
|
||||
virtual void run() = 0;
|
||||
|
||||
Window* getWindow() { return window; }
|
||||
void createWindow() { window = new Window(); }
|
||||
|
||||
protected:
|
||||
Window* window;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
38
include/utils/Module/Module.h
Normal file
38
include/utils/Module/Module.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef MODULE_H
|
||||
#define MODULE_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class App;
|
||||
|
||||
class Module {
|
||||
|
||||
friend class App;
|
||||
|
||||
public:
|
||||
typedef Module* create_t(void*, App&);
|
||||
|
||||
Module(void* h, App& a) : handle(h), app(a) {};
|
||||
virtual ~Module() {}
|
||||
virtual void run() = 0;
|
||||
virtual void onLoad() = 0;
|
||||
|
||||
std::string getName() const { return name; }
|
||||
void* getHandle() { return handle; }
|
||||
|
||||
void setSelf(std::list<Module*>::iterator s) { self = s; }
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
void* handle;
|
||||
std::list<Module*>::iterator self;
|
||||
|
||||
App& app;
|
||||
|
||||
std::unordered_map<std::string, std::string> deps;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
10
include/utils/Renderer/Renderer.cpp
Normal file
10
include/utils/Renderer/Renderer.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "Renderer.h"
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
void Renderer::render() {
|
||||
r.render(rc, w, h);
|
||||
}
|
||||
}
|
||||
28
include/utils/Renderer/Renderer.h
Normal file
28
include/utils/Renderer/Renderer.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
|
||||
#include "RendererOpenGL/RendererOpenGL.h"
|
||||
|
||||
namespace Archimedes {
|
||||
class Renderer {
|
||||
|
||||
public:
|
||||
int w, h;
|
||||
typedef void renderCmd();
|
||||
|
||||
~Renderer() {}
|
||||
|
||||
void init() { r.init(); }
|
||||
|
||||
void render();
|
||||
|
||||
void addRenderCmd(renderCmd* cmd) { rc.push_back(cmd); }
|
||||
|
||||
private:
|
||||
std::list<renderCmd*> rc;
|
||||
RendererImpl r;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
39
include/utils/Renderer/RendererOpenGL/RendererOpenGL.h
Normal file
39
include/utils/Renderer/RendererOpenGL/RendererOpenGL.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifdef RENDERER_OPENGL
|
||||
#undef RENDERER_OPENGL
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class RendererOpenGL {
|
||||
|
||||
public:
|
||||
typedef void renderCmd();
|
||||
|
||||
RendererOpenGL() {};
|
||||
~RendererOpenGL() {};
|
||||
|
||||
void init() { glewInit(); };
|
||||
|
||||
void render(std::list<renderCmd*> cmdList, int& w, int& h) {
|
||||
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
for(auto* f : cmdList)
|
||||
f();
|
||||
cmdList.clear();
|
||||
}
|
||||
};
|
||||
|
||||
typedef RendererOpenGL RendererImpl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
18
include/utils/Window/Window.cpp
Normal file
18
include/utils/Window/Window.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "Window.h"
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
void Window::doFrame() {
|
||||
|
||||
window.pollEvents();
|
||||
|
||||
window.getSize(renderer.w, renderer.h);
|
||||
|
||||
renderer.render();
|
||||
|
||||
window.doFrame();
|
||||
}
|
||||
|
||||
}
|
||||
30
include/utils/Window/Window.h
Normal file
30
include/utils/Window/Window.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
|
||||
#include "Renderer/Renderer.h"
|
||||
#include "WindowGLFW/WindowGLFW.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Window {
|
||||
|
||||
public:
|
||||
|
||||
~Window() {};
|
||||
|
||||
bool shouldClose() { return window.shouldClose(); }
|
||||
|
||||
void doFrame();
|
||||
|
||||
Renderer& getRenderer() { return renderer; }
|
||||
WindowImpl& getWindowImpl() { return window; }
|
||||
|
||||
private:
|
||||
Renderer renderer;
|
||||
|
||||
WindowImpl window;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
65
include/utils/Window/WindowGLFW/WindowGLFW.h
Normal file
65
include/utils/Window/WindowGLFW/WindowGLFW.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
#ifdef WINDOW_GLFW
|
||||
#undef WINDOW_GLFW
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class WindowGLFW {
|
||||
|
||||
public:
|
||||
|
||||
WindowGLFW() {
|
||||
|
||||
glfwSetErrorCallback([](int e, const char* m){
|
||||
std::cout << "GLFW Error: " << m << std::endl;
|
||||
});
|
||||
|
||||
if(!glfwInit()) {
|
||||
std::cout << "glfwInit failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
|
||||
|
||||
if(!w) {
|
||||
glfwTerminate();
|
||||
std::abort();
|
||||
}
|
||||
std::cout << "Window Created!\n";
|
||||
glfwMakeContextCurrent(w);
|
||||
glfwSwapInterval(1);
|
||||
}
|
||||
|
||||
~WindowGLFW() {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
bool shouldClose() {
|
||||
return glfwWindowShouldClose(w);
|
||||
}
|
||||
|
||||
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
|
||||
|
||||
void pollEvents() { glfwPollEvents(); }
|
||||
|
||||
void restoreContext() { glfwMakeContextCurrent(w); }
|
||||
|
||||
void getSize(int& w, int& h) {
|
||||
glfwGetFramebufferSize(this->w, &w, &h);
|
||||
}
|
||||
|
||||
GLFWwindow* getWindow() { return w; }
|
||||
|
||||
private:
|
||||
GLFWwindow* w;
|
||||
};
|
||||
|
||||
typedef WindowGLFW WindowImpl;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user