Compare commits

...

9 Commits

Author SHA1 Message Date
f277dee1f7 polymorphic windows 2026-02-08 11:57:18 -06:00
bad4bd70bc folders 2026-02-08 00:32:46 -06:00
b97957ec53 use extratools 2026-02-07 12:49:47 -06:00
bedd7a5dfd prepare for audio implimentations 2026-02-07 12:45:55 -06:00
89ea39ee60 add extratools.h 2026-02-07 12:44:07 -06:00
e7544e1cc1 add extratools.h 2026-02-07 12:43:10 -06:00
98f990cb57 add concepts 2026-02-07 11:54:47 -06:00
9b0be39b91 start template refactor 2026-02-07 11:47:06 -06:00
9a89ab3bbc start template refactor 2026-02-07 11:45:43 -06:00
14 changed files with 174 additions and 109 deletions

View File

@@ -279,8 +279,9 @@
sdl3 sdl3
curl curl
glm
nlohmann_json nlohmann_json
stb
gamenetworkingsockets gamenetworkingsockets

8
include/extratools.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef EXTRATOOLS_H
#define EXTRATOOLS_H
#include <glm/glm.hpp>
#include <nlohmann/json.hpp>
#include <curl/curl.h>
#endif

View File

@@ -17,6 +17,7 @@
#include <optional> #include <optional>
#include <chrono> #include <chrono>
//#include <thread> //#include <thread>
#include <concepts>
#include <dlfcn.h> #include <dlfcn.h>

View File

@@ -0,0 +1,22 @@
#ifndef OBJECT_H
#define OBJECT_H
#include "pch.hpp"
#include "extratools.h"
namespace Archimedes {
class Object {
public:
Object() {};
~Object() {};
private:
};
}
#endif

View File

@@ -2,32 +2,35 @@
#define RENDERER_H #define RENDERER_H
#include "pch.hpp" #include "pch.hpp"
#include "RendererOpenGL/RendererOpenGL.h"
#include "RendererSDL3/RendererSDL3.h"
namespace Archimedes { namespace Archimedes {
class VertexArray {};
class IndexArray {};
class Shader {};
class Renderer { class Renderer {
public: public:
int w, h; int w, h;
Renderer() {}
virtual ~Renderer() = 0;
~Renderer() {} virtual bool init() = 0;
bool init(void* ptr) { return r.init(ptr); } virtual void render() = 0;
void render() {
r.render(rc, w, h);
}
std::list<std::function<void()>>& getCmdList() { std::list<std::function<void()>>& getCmdList() {
return rc; return rc;
} }
RendererImpl& getRendererImpl() { return r; }
private: private:
std::list<std::function<void()>> rc; std::list<std::function<void()>> rc;
RendererImpl r;
}; };
} }

View File

@@ -1,17 +1,17 @@
#if RENDERER == 1
#ifndef RENDERER_OPENGL #ifndef RENDERER_OPENGL
#define RENDERER_OPENGL #define RENDERER_OPENGL
#include "pch.hpp" #include "pch.hpp"
#include "utils/Renderer/Renderer.h"
#define GLEW_STATIC #define GLEW_STATIC
#include <GL/glew.h> #include <GL/glew.h>
namespace Archimedes { namespace Archimedes {
class RendererOpenGL { class RendererOpenGL : public Renderer {
public: public:
typedef void renderCmd(); typedef void renderCmd();
@@ -19,7 +19,7 @@ namespace Archimedes {
RendererOpenGL() {}; RendererOpenGL() {};
~RendererOpenGL() {}; ~RendererOpenGL() {};
bool init(void* p) { bool init() {
return glewInit() == GLEW_OK; return glewInit() == GLEW_OK;
}; };
@@ -29,16 +29,10 @@ namespace Archimedes {
glClearColor(0.2, 0.2, 0.4, 1); glClearColor(0.2, 0.2, 0.4, 1);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
for(auto f : cmdList)
f();
} }
void draw() {}
}; };
typedef RendererOpenGL RendererImpl;
} }
#endif #endif
#endif

View File

@@ -1,5 +1,3 @@
#if RENDERER == 2
#ifndef RENDERER_SDL3 #ifndef RENDERER_SDL3
#define RENDERER_SDL3 #define RENDERER_SDL3
@@ -38,12 +36,6 @@ namespace Archimedes {
SDL_Renderer* renderer = nullptr; SDL_Renderer* renderer = nullptr;
}; };
typedef RendererSDL3 RendererImpl;
} }
#endif #endif
#endif

View File

@@ -0,0 +1,21 @@
#ifndef RENDERER_CONCEPTS
#define RENDERER_CONCEPTS
#include "pch.hpp"
namespace Archimedes {
class RendererOpenGL;
class RendererSDL3;
template <class RendererImpl>
concept allowed_renderers = requires (RendererImpl r) {
#ifndef CUSTOM_RENDERER
requires std::same_as<RendererImpl, RendererOpenGL>
|| std::same_as<RendererImpl, RendererSDL3>;
#endif
};
}
#endif

View File

@@ -4,8 +4,6 @@
#include "WindowEvents.h" #include "WindowEvents.h"
#include "utils/Renderer/Renderer.h" #include "utils/Renderer/Renderer.h"
#include "WindowGLFW/WindowGLFW.h"
#include "WindowSDL3/WindowSDL3.h"
namespace Archimedes { namespace Archimedes {
@@ -13,34 +11,44 @@ namespace Archimedes {
public: public:
Window(const std::function<void(Event*)>& sendEventFn) : window(this, sendEventFn) {} Window(const std::function<void(Event*)>& sendEventFn) : eventFn(sendEventFn) {}
~Window() {} virtual ~Window() = 0;
bool shouldClose() { return window.shouldClose(); }
void getSize(int& w, int& h) {
window.getSize(w, h);
}
void doFrame() { void doFrame() {
renderer->render(); renderer->render();
window.doFrame(); swapBuffers();
pollEvents();
window.pollEvents(); }
virtual bool shouldClose() = 0;
virtual void swapBuffers() = 0;
virtual void pollEvents() = 0;
virtual void getSize(int& w, int& h) {
w = this->w;
h = this->h;
} }
Renderer* getRenderer() { return renderer; } Renderer* getRenderer() { return renderer; }
void setRenderer(Renderer* r) { renderer = r; } void setRenderer(Renderer* r) { renderer = r; }
WindowImpl& getWindowImpl() { return window; } virtual Window* getWindowImpl() = 0;
protected:
int w, h;
private:
Renderer* renderer; Renderer* renderer;
WindowImpl window; std::function<void(Event*)> eventFn;
}; };
} }

View File

@@ -5,7 +5,7 @@
#include "pch.hpp" #include "pch.hpp"
#include "utils/Window/WindowEvents.h" #include "utils/Window/Window.h"
#define GLFW_INCLUDE_NONE #define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
@@ -13,20 +13,13 @@
namespace Archimedes { namespace Archimedes {
class Window; class WindowGLFW : public Window {
class WindowGLFW {
public: public:
WindowGLFW(Window* p, const std::function<void(Event*)>& sendEvent) { WindowGLFW(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
/*if(glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) { data.window = this;
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
}*/
data.window = p;
data.sendEvent = sendEvent; data.sendEvent = sendEvent;
glfwSetErrorCallback([](int e, const char* m){ glfwSetErrorCallback([](int e, const char* m){
@@ -42,31 +35,31 @@ namespace Archimedes {
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif #endif
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL); window = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!w) { if(!w) {
std::cout << "glfwCreateWindow failed!\n"; std::cout << "glfwCreateWindow failed!\n";
glfwTerminate(); glfwTerminate();
std::abort(); std::abort();
} }
glfwMakeContextCurrent(w); glfwMakeContextCurrent(window);
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetWindowUserPointer(w, &data); glfwSetWindowUserPointer(window, &data);
glfwSetWindowSizeCallback(w, [](GLFWwindow* window, int w, int h){ glfwSetWindowSizeCallback(window, [](GLFWwindow* window, int w, int h){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window); WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new ResizeWindowEvent(w, h)); d.sendEvent(new ResizeWindowEvent(w, h));
}); });
glfwSetWindowCloseCallback(w, [](GLFWwindow* window){ glfwSetWindowCloseCallback(window, [](GLFWwindow* window){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window); WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new CloseWindowEvent(d.window)); d.sendEvent(new CloseWindowEvent(d.window));
}); });
glfwSetKeyCallback(w, [](GLFWwindow* window, int key, int scancode, int action, int mods){ glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window); WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
switch(action) { switch(action) {
@@ -82,7 +75,7 @@ namespace Archimedes {
} }
}); });
glfwSetMouseButtonCallback(w, [](GLFWwindow* window, int button, int action, int mods){ glfwSetMouseButtonCallback(window, [](GLFWwindow* window, int button, int action, int mods){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window); WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
switch(action) { switch(action) {
@@ -95,13 +88,13 @@ namespace Archimedes {
} }
}); });
glfwSetScrollCallback(w, [](GLFWwindow* window, double dx, double dy){ glfwSetScrollCallback(window, [](GLFWwindow* window, double dx, double dy){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window); WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new ScrollWindowEvent(dx, dy)); d.sendEvent(new ScrollWindowEvent(dx, dy));
}); });
glfwSetCursorPosCallback(w, [](GLFWwindow* window, double dx, double dy){ glfwSetCursorPosCallback(window, [](GLFWwindow* window, double dx, double dy){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window); WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new MouseMovedWindowEvent(dx, dy)); d.sendEvent(new MouseMovedWindowEvent(dx, dy));
@@ -113,31 +106,31 @@ namespace Archimedes {
} }
bool shouldClose() { void swapBuffers() override { restoreContext(); glfwSwapBuffers(window); };
return glfwWindowShouldClose(w);
void pollEvents() override { glfwPollEvents(); }
bool shouldClose() override {
return glfwWindowShouldClose(window);
} }
void doFrame() { restoreContext(); glfwSwapBuffers(w); } void restoreContext() { glfwMakeContextCurrent(window); }
void pollEvents() { glfwPollEvents(); } void getSize(int& w, int& h) override {
glfwGetFramebufferSize(window, &w, &h);
void restoreContext() { glfwMakeContextCurrent(w); }
void getSize(int& w, int& h) {
glfwGetFramebufferSize(this->w, &w, &h);
} }
GLFWwindow* getWindow() { return w; } GLFWwindow* getWindow() { return window; }
WindowData data; WindowData data;
virtual WindowGLFW* getWindowImpl() override { return this; }
private: private:
GLFWwindow* w; GLFWwindow* window;
}; };
typedef WindowGLFW WindowImpl;
} }
#endif #endif

View File

@@ -5,7 +5,7 @@
#include "pch.hpp" #include "pch.hpp"
#include "utils/Window/WindowEvents.h" #include "utils/Window/Window.h"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
@@ -17,8 +17,6 @@
namespace Archimedes { namespace Archimedes {
class Window;
static bool EventCallback(void* ptr, SDL_Event* e) { static bool EventCallback(void* ptr, SDL_Event* e) {
WindowData& data = *(WindowData*) ptr; WindowData& data = *(WindowData*) ptr;
@@ -66,13 +64,13 @@ namespace Archimedes {
return true; return true;
} }
class WindowSDL3 { class WindowSDL3 : public Window {
public: public:
WindowSDL3(Window* p, const std::function<void(Event*)>& sendEvent) { WindowSDL3(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
data.window = p; data.window = this;
data.sendEvent = sendEvent; data.sendEvent = sendEvent;
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) { if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
@@ -90,16 +88,16 @@ namespace Archimedes {
SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY; SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
#endif #endif
w = SDL_CreateWindow("Archimedes", 1280, 720, window_flags); window = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
if (w == nullptr) if (window == nullptr)
{ {
std::cerr << "Error: SDL_CreateWindow(): " << SDL_GetError() << std::endl; std::cerr << "Error: SDL_CreateWindow(): " << SDL_GetError() << std::endl;
std::abort(); std::abort();
} }
SDL_SetWindowPosition(w, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
#if RENDERER == 1 #if RENDERER == 1
gl_context = SDL_GL_CreateContext(w); gl_context = SDL_GL_CreateContext(window);
if (gl_context == nullptr) if (gl_context == nullptr)
{ {
@@ -107,12 +105,12 @@ namespace Archimedes {
std::abort(); std::abort();
} }
SDL_GL_MakeCurrent(w, gl_context); SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync SDL_GL_SetSwapInterval(1); // Enable vsync
#endif #endif
SDL_AddEventWatch(EventCallback, &data); SDL_AddEventWatch(EventCallback, &data);
SDL_ShowWindow(w); SDL_ShowWindow(window);
} }
~WindowSDL3() { ~WindowSDL3() {
@@ -120,52 +118,52 @@ namespace Archimedes {
SDL_GL_DestroyContext(gl_context); SDL_GL_DestroyContext(gl_context);
#endif #endif
SDL_RemoveEventWatch(EventCallback, &data); SDL_RemoveEventWatch(EventCallback, &data);
SDL_DestroyWindow(w); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();
} }
bool shouldClose() { return false; } bool shouldClose() override { return false; }
void doFrame() { void swapBuffers() override {
#if RENDERER == 1 #if RENDERER == 1
restoreContext(); restoreContext();
SDL_GL_SwapWindow(w); SDL_GL_SwapWindow(window);
#endif #endif
} }
void pollEvents() { void pollEvents() override {
static SDL_Event e; static SDL_Event e;
while(SDL_PollEvent(&e)) {} while(SDL_PollEvent(&e));
} }
WindowSDL3* getWindowImpl() { return this; };
#if RENDERER == 1 #if RENDERER == 1
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); } void restoreContext() { SDL_GL_MakeCurrent(window, gl_context); }
#endif #endif
void getSize(int& w, int& h) { void getSize(int& w, int& h) override {
w = this->width; w = this->w;
h = this->height; h = this->h;
} }
void setSize(int& w, int& h) { void setSize(int& w, int& h) {
this->width = w; this->w = w;
this->height = h; this->h = h;
} }
SDL_Window* getWindow() { return w; } SDL_Window* getWindow() { return window; }
#if RENDERER == 1 #if RENDERER == 1
SDL_GLContext getContext() { return gl_context; } SDL_GLContext getContext() { return gl_context; }
#endif #endif
WindowData data; WindowData data;
private: private:
SDL_Window* w; SDL_Window* window;
int width = 0, height = 0;
#if RENDERER == 1 #if RENDERER == 1
SDL_GLContext gl_context; SDL_GLContext gl_context;
#endif #endif
}; };
typedef WindowSDL3 WindowImpl;
} }
#endif #endif

View File

@@ -0,0 +1,25 @@
#ifndef WINDOW_CONCEPTS
#define WINDOW_CONCEPTS
#include "pch.hpp"
#include "utils/Renderer/concepts.h"
namespace Archimedes {
template <class R>
class WindowGLFW;
template <class R>
class WindowSDL3;
template <class WindowImpl, class R>
concept allowed_windows = requires (WindowImpl a, R b) {
#ifndef CUSTOM_WINDOW
requires std::same_as<WindowImpl, WindowGLFW<R>>
|| std::same_as<WindowImpl, WindowSDL3<R>>;
#endif
};
}
#endif

View File

@@ -1,7 +1,6 @@
#include "Archimedes.h" #include "Archimedes.h"
#include <curl/curl.h> #include "extratools.h"
#include <nlohmann/json.hpp>
class Ollama : public Archimedes::Module { class Ollama : public Archimedes::Module {