Compare commits

...

42 Commits

Author SHA1 Message Date
6c33eada03 triangle 2026-02-11 00:03:05 -06:00
badb3c4ec8 triangle 2026-02-10 23:53:52 -06:00
0244f463c4 triangle? 2026-02-10 23:51:27 -06:00
1f22a661cd the great typo of 2026 2026-02-10 18:21:18 -06:00
80d64f5114 test triangle 2026-02-10 15:40:25 -06:00
3c593edeca test triangle 2026-02-10 14:43:43 -06:00
263f0201ca test triangle 2026-02-10 14:39:45 -06:00
65e15ecfa4 test triangle 2026-02-10 14:35:54 -06:00
7d777c9578 work on renderer 2026-02-10 13:52:56 -06:00
874a8a1115 work on renderer 2026-02-10 13:50:44 -06:00
e4d84686c4 work on renderer 2026-02-10 13:41:49 -06:00
914de55f85 work on renderer 2026-02-10 13:40:44 -06:00
6dba251457 work on renderer 2026-02-10 13:39:42 -06:00
dd1befc2a0 work on renderer 2026-02-10 13:37:49 -06:00
086e5f5126 work on renderer 2026-02-08 17:29:56 -06:00
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
8b0192c9b8 Sketchy Multi Viewports 2026-02-05 23:59:11 -06:00
8581589bfe TestTriangle works 2026-02-04 17:31:17 -06:00
9dfabc6dae TestTriangle works 2026-02-04 15:42:30 -06:00
3f102638b0 work on TestTriangle 2026-02-04 14:37:06 -06:00
5ab345460c TestTriangle 2026-02-04 09:29:15 -06:00
e67df40233 TestTriangle 2026-02-04 09:04:44 -06:00
07b4518cb4 TestTriangle 2026-02-04 08:41:09 -06:00
43d950b035 add triangle test 2026-02-04 08:35:16 -06:00
78a8c9bf95 return to something that works 2026-02-04 00:30:52 -06:00
7a45547ad9 attempt multi-viewports 2026-02-03 21:21:27 -06:00
21080c5c63 debating submodules 2026-02-03 21:17:12 -06:00
68524696df spellcheck 2026-02-03 20:15:15 -06:00
8c0cba9397 ccls 2026-02-03 20:13:10 -06:00
afe6254317 ccls? 2026-02-03 20:04:07 -06:00
e38a83e521 ccls? 2026-02-03 20:01:32 -06:00
7517ee8593 scope 2026-02-03 18:16:37 -06:00
148ed1253c try dev shell 2026-02-03 18:15:37 -06:00
cd19db0b88 flakes shouldn't be executable 2026-02-03 14:35:38 -06:00
36 changed files with 1088 additions and 265 deletions

10
.ccls Normal file
View File

@@ -0,0 +1,10 @@
clang++
-Iinclude
-I.
-Ivendor/imgui
-Ivendor/notcurses/include
-Ivendor/GameNetworkingSockets/include
-DWINDOW_GLFW
-DWINDOW_SDL3
-DRENDERER_OPENGL
-DRENDERER_SDL3

3
.gitignore vendored
View File

@@ -1 +1,2 @@
vendor/*
vendor/
.ccls-cache/

View File

@@ -11,14 +11,11 @@
nativeBuildInputs = with pkgs; [
clang
];
/*buildInputs = with pkgs; [
];*/
buildPhase = ''
clang++ \
src/example_apps/MinimalApp/MinimalApp.cpp \
-I src -I include \
-I include \
-Wall \
-o $name
'';
@@ -33,7 +30,51 @@
'';
};
TriangleEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
src = ./.;
imgui = inputs.imgui;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
];
buildPhase = ''
clang++ \
src/example_apps/TriangleEmbed/*.cpp \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-I include -I . \
-lEGL -lGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
name = "Archimedes";
@@ -54,7 +95,7 @@
buildPhase = ''
clang++ \
src/example_apps/ImguiEmbed/*.cpp \
modules/Archimedes-Modules/TestImgui/*.cpp \
modules/MainGUI/*.cpp \
modules/WindowModule/*.cpp \
modules/ImguiModule/*.cpp \
$imgui/backends/imgui_impl_glfw.cpp \
@@ -64,7 +105,7 @@
-DRENDERER=1 \
-DWINDOW=1 \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lEGL -lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -106,7 +147,7 @@
-DRENDERER=1 \
-DWINDOW=1 \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';

View File

@@ -140,6 +140,81 @@
};
TestTrianglesdl = pkgs.stdenvNoCC.mkDerivation {
name = "TestTriangle";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
sdl3
glew
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER=1 \
-DWINDOW=2 \
-DTESTTRIANGLE_DYNAMIC \
-fpic -shared \
-I include -I . \
-lEGL -lSDL3 -lGLEW \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestTriangle = pkgs.stdenvNoCC.mkDerivation {
name = "TestTriangle";
src = ./.;
nativeBuildInputs = with pkgs; [
clang
];
buildInputs = with pkgs; [
glfw
glew
glm
nlohmann_json
curl
];
buildPhase = ''
clang++ \
modules/Archimedes-Modules/TestTriangle/*.cpp \
modules/WindowModule/*.cpp \
-DRENDERER_OPENGL=1 \
-DWINDOW_GLFW=1 \
-DTESTTRIANGLE_DYNAMIC \
-fpic -shared \
-I include -I . \
-lEGL -lglfw -lGLEW \
$(curl-config --cflags) \
$(curl-config --libs) \
-Wall \
-o $name
'';
installPhase = ''
mkdir -p $out/bin
cp $name $out/bin
'';
};
TestImgui = pkgs.stdenvNoCC.mkDerivation {
name = "TestImgui";

25
flake.lock generated Executable file → Normal file
View File

@@ -35,11 +35,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1769900590,
"narHash": "sha256-I7Lmgj3owOTBGuauy9FL6qdpeK2umDoe07lM4V+PnyA=",
"lastModified": 1770136044,
"narHash": "sha256-tlFqNG/uzz2++aAmn4v8J0vAkV3z7XngeIIB3rM3650=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "41e216c0ca66c83b12ab7a98cc326b5db01db646",
"rev": "e576e3c9cf9bad747afcddd9e34f51d18c855b4e",
"type": "github"
},
"original": {
@@ -49,11 +49,28 @@
"type": "github"
}
},
"nixpkgs-old": {
"locked": {
"lastModified": 1720535198,
"narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"clay": "clay",
"imgui": "imgui",
"nixpkgs": "nixpkgs"
"nixpkgs": "nixpkgs",
"nixpkgs-old": "nixpkgs-old"
}
}
},

41
flake.nix Executable file → Normal file
View File

@@ -3,6 +3,7 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
nixpkgs-old.url = "github:nixos/nixpkgs/nixos-23.11"; # Until Dear ImGUI has multi viewports on wayland
imgui = {
url = "github:ocornut/imgui?ref=docking";
flake = false;
@@ -15,15 +16,17 @@
outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
pkgs-old = import inputs.nixpkgs-old { inherit system; };
viewport-overlay = final: prev: { glfw = pkgs-old.glfw; };
pkgs = import nixpkgs { inherit system; overlays = [ viewport-overlay ]; };
in {
Archimedes = {
examples = import ./ExampleApps.nix { inherit inputs; inherit pkgs; };
examples = import ./ExampleApps.nix { inherit inputs pkgs; };
};
Modules = {
examples = import ./ExampleModules.nix { inherit inputs; inherit pkgs; };
examples = import ./ExampleModules.nix { inherit inputs pkgs; };
ServerModule = pkgs.stdenvNoCC.mkDerivation {
@@ -114,7 +117,7 @@
-DRENDERER=1 \
-DWINDOW=1 \
-DWINDOWMODULE_DYNAMIC \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -157,7 +160,7 @@
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -243,7 +246,7 @@
-DMAINGUI_DYNAMIC \
-fpic -shared \
-I include -I $imgui -I . \
-lEGL -lglfw -lGLEW \
-lGL -lglfw -lGLEW \
-Wall \
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
'';
@@ -264,5 +267,31 @@
program = "${self.Archimedes.examples.MinimalApp}/bin/Archimedes";
};
devShells.${system} = {
default = pkgs.mkShellNoCC {
packages = with pkgs; [
clang
glfw
glew
sdl3
curl
glm
nlohmann_json
stb
gamenetworkingsockets
];
shellHook = ''
'';
};
};
};
}

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

@@ -2,6 +2,7 @@
#define PCH_HPP
#include <iostream>
#include <fstream>
#include <cstring>
#include <cassert>
#include <list>
@@ -17,6 +18,7 @@
#include <optional>
#include <chrono>
//#include <thread>
#include <concepts>
#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

@@ -0,0 +1,184 @@
#ifndef RENDERTARGET_H
#define RENDERTARGET_H
#include "pch.hpp"
#include "extratools.h"
namespace Archimedes {
class LayoutElement {
public:
LayoutElement(unsigned int type, size_t count) : type(type), count(count) {}
~LayoutElement() {}
unsigned int getType() const { return type; }
size_t getSize() const { return size; }
size_t getCount() const { return count; }
private:
unsigned int type;
size_t size;
size_t count;
};
class VertexLayout {
public:
VertexLayout() {}
~VertexLayout() {}
const std::vector<LayoutElement>& getElements() const { return elements; }
private:
std::vector<LayoutElement> elements;
};
class VertexBuffer {
public:
VertexBuffer(const void* data, size_t size) : data(data), size(size) {
}
~VertexBuffer() {}
const void* getData() const { return data; }
size_t getSize() const { return size; }
unsigned int id;
private:
const void* data;
size_t size;
};
class VertexArray {
public:
VertexArray() {
}
~VertexArray() {}
unsigned int id;
private:
};
class IndexArray {
public:
IndexArray(const unsigned int* indices, size_t count) : indices(indices), count(count) {
}
~IndexArray() {}
const void* getIndicies() const { return indices; }
size_t getCount() const { return count; }
unsigned int id;
private:
const unsigned int* indices;
size_t count;
};
class Shader {
public:
enum class LoadType {
FromSource,
FromBin,
FromFileSource,
FromFileBin
};
Shader(const std::string& vs, const std::string& fs, LoadType loadType) : loadType(loadType) {
switch(loadType) {
case LoadType::FromSource:
this->vs = vs;
this->fs = fs;
break;
case LoadType::FromBin:
break;
case LoadType::FromFileSource:
this->vs = readSourceFile(vs);
this->fs = readSourceFile(fs);
break;
case LoadType::FromFileBin:
break;
default:
break;
}
}
~Shader() {}
std::string getVSource() const { return vs; }
std::string getFSource() const { return fs; }
unsigned int id;
private:
LoadType loadType;
std::string vs;
std::string fs;
std::string readSourceFile(const std::string& path) {
std::ifstream file(path);
if(!file.is_open()) {
return "";
}
std::string s;
while(!file.eof()) {
file >> s;
}
return s;
}
};
class RenderTarget {
public:
RenderTarget(const void* data, size_t size, unsigned int* indices, size_t count, VertexLayout layout, const std::string& vs, const std::string& fs)
: vertexBuffer(data, size),
indexArray(indices, count),
layout(layout),
shader(vs, fs, Shader::LoadType::FromFileSource) {
}
RenderTarget(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s)
: vertexBuffer(vb),
indexArray(ia),
layout(vl),
shader(s) {
}
~RenderTarget() {}
//private:
VertexBuffer vertexBuffer;
VertexArray vertexArray;
VertexLayout layout;
IndexArray indexArray;
Shader shader;
};
}
#endif

View File

@@ -2,32 +2,45 @@
#define RENDERER_H
#include "pch.hpp"
#include "RendererOpenGL/RendererOpenGL.h"
#include "RendererSDL3/RendererSDL3.h"
#include "extratools.h"
#include "RenderTarget.h"
namespace Archimedes {
class Renderer {
public:
int w, h;
~Renderer() {}
glm::vec4 clearColor = { 0.0f, 0.0f, 0.0f, 0.0f };
Renderer() : w(0), h(0) {}
bool init(void* ptr) { return r.init(ptr); }
virtual ~Renderer() {}
void render() {
r.render(rc, w, h);
}
virtual bool init() = 0;
std::list<std::function<void()>>& getCmdList() {
return rc;
}
virtual void render() = 0;
virtual Shader createShader(const std::string& vs, const std::string& fs, const Shader::LoadType& lt) = 0;
virtual RenderTarget* createRenderTarget(
const void* data,
size_t size,
unsigned int* indices,
size_t count,
VertexLayout layout,
const std::string& vs,
const std::string& fs,
const Shader::LoadType& lt
) = 0;
virtual void draw(const RenderTarget*) = 0;
RendererImpl& getRendererImpl() { return r; }
virtual Renderer* getRendererImpl() = 0;
private:
std::list<std::function<void()>> rc;
RendererImpl r;
};
}

View File

@@ -0,0 +1,143 @@
#ifdef RENDERER_OPENGL
#ifndef RENDERER_OPENGL_H
#define RENDERER_OPENGL_H
#include "pch.hpp"
#include "utils/Renderer/Renderer.h"
#define GLEW_STATIC
#include <GL/glew.h>
namespace Archimedes {
class RendererOpenGL : public Renderer {
public:
typedef void renderCmd();
RendererOpenGL() {};
~RendererOpenGL() {};
bool init() override {
return glewInit() == GLEW_OK;
};
void render() override {
glViewport(0, 0, w, h);
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
glClear(GL_COLOR_BUFFER_BIT);
}
Shader createShader(const std::string& vs, const std::string& fs, const Shader::LoadType& lt) override {
Shader shader(vs, fs, lt);
std::string vss = shader.getVSource();
std::string fss = shader.getFSource();
const char* vsc = vss.c_str();
const char* fsc = fss.c_str();
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vsc, NULL);
glCompileShader(vertexShader);
// check for shader compile errors
int success;
char infoLog[512];
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}
// fragment shader
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fsc, NULL);
glCompileShader(fragmentShader);
// check for shader compile errors
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
if (!success)
{
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
}
// link shaders
unsigned int shaderProgram = glCreateProgram();
glAttachShader(shaderProgram, vertexShader);
glAttachShader(shaderProgram, fragmentShader);
glLinkProgram(shaderProgram);
// check for linking errors
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
}
glDeleteShader(vertexShader);
glDeleteShader(fragmentShader);
shader.id = shaderProgram;
return shader;
}
RenderTarget* createRenderTarget(const void* data, size_t size, unsigned int* indices, size_t count, VertexLayout layout, const std::string& vs, const std::string& fs, const Shader::LoadType& lt) override {
VertexBuffer vb(data, size);
IndexArray ia(indices, count);
Shader s = createShader(vs, fs, lt);
auto rt = new RenderTarget(vb, ia, layout, s);
glGenVertexArrays(1, &rt->vertexArray.id);
glGenBuffers(1, &rt->vertexBuffer.id);
glBindVertexArray(rt->vertexArray.id);
glBindBuffer(GL_ARRAY_BUFFER, rt->vertexBuffer.id);
glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, data, GL_STATIC_DRAW);
glGenBuffers(1, &rt->indexArray.id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rt->indexArray.id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), indices, GL_STATIC_DRAW);
glUseProgram(s.id);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return rt;
};
void draw(const RenderTarget* rt) override {
glUseProgram(rt->shader.id);
glBindVertexArray(rt->vertexArray.id);
glDrawElements(GL_TRIANGLES, rt->indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
}
RendererOpenGL* getRendererImpl() override { return this; }
};
}
#endif
#endif

View File

@@ -1,7 +1,6 @@
#if RENDERER == 2
#ifndef RENDERER_SDL3
#define RENDERER_SDL3
#ifdef RENDERER_SDL3
#ifndef RENDERER_SDL3_H
#define RENDERER_SDL3_H
#include "pch.hpp"
@@ -38,12 +37,7 @@ namespace Archimedes {
SDL_Renderer* renderer = nullptr;
};
typedef RendererSDL3 RendererImpl;
}
#endif
#endif

View File

@@ -1,44 +0,0 @@
#if RENDERER == 1
#ifndef RENDERER_OPENGL
#define RENDERER_OPENGL
#include "pch.hpp"
#define GLEW_STATIC
#include <GL/glew.h>
namespace Archimedes {
class RendererOpenGL {
public:
typedef void renderCmd();
RendererOpenGL() {};
~RendererOpenGL() {};
bool init(void* p) {
return glewInit() == GLEW_OK;
};
void render(std::list<std::function<void()>> cmdList, int& w, int& h) {
glViewport(0, 0, w, h);
glClear(GL_COLOR_BUFFER_BIT);
for(auto f : cmdList)
f();
}
};
typedef RendererOpenGL RendererImpl;
}
#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 "utils/Renderer/Renderer.h"
#include "WindowGLFW/WindowGLFW.h"
#include "WindowSDL3/WindowSDL3.h"
namespace Archimedes {
@@ -13,34 +11,46 @@ namespace Archimedes {
public:
Window(const std::function<void(Event*)>& sendEventFn) : window(this, sendEventFn) {}
Window(const std::function<void(Event*)>& sendEventFn) : eventFn(sendEventFn) {}
~Window() {}
virtual ~Window() {};
bool shouldClose() { return window.shouldClose(); }
void getSize(int& w, int& h) {
window.getSize(w, h);
}
void doFrame() {
renderer->render();
swapBuffers();
window.doFrame();
renderer->render();
window.pollEvents();
pollEvents();
}
virtual bool shouldClose() = 0;
virtual void swapBuffers() = 0;
virtual void pollEvents() = 0;
virtual void restoreContext() = 0;
virtual void getSize(int& w, int& h) {
w = this->w;
h = this->h;
}
Renderer* getRenderer() { return renderer; }
void setRenderer(Renderer* r) { renderer = r; }
WindowImpl& getWindowImpl() { return window; }
virtual Window* getWindowImpl() = 0;
protected:
int w, h;
private:
Renderer* renderer;
WindowImpl window;
std::function<void(Event*)> eventFn;
};
}

View File

@@ -1,11 +1,10 @@
#if WINDOW == 1
#ifndef WINDOW_GLFW
#define WINDOW_GLFW
#ifdef WINDOW_GLFW
#ifndef WINDOW_GLFW_H
#define WINDOW_GLFW_H
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include "utils/Window/Window.h"
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
@@ -13,20 +12,13 @@
namespace Archimedes {
class Window;
class WindowGLFW {
class WindowGLFW : public Window {
public:
WindowGLFW(Window* p, const std::function<void(Event*)>& sendEvent) {
WindowGLFW(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
/*if(glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
}*/
data.window = p;
data.window = this;
data.sendEvent = sendEvent;
glfwSetErrorCallback([](int e, const char* m){
@@ -37,31 +29,39 @@ namespace Archimedes {
std::cout << "glfwInit failed!\n";
std::abort();
}
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
#ifdef RENDERER_OPENGL
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
#endif
if(!w) {
window = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
if(!window) {
std::cout << "glfwCreateWindow failed!\n";
glfwTerminate();
std::abort();
}
glfwMakeContextCurrent(w);
glfwMakeContextCurrent(window);
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);
d.sendEvent(new ResizeWindowEvent(w, h));
});
glfwSetWindowCloseCallback(w, [](GLFWwindow* window){
glfwSetWindowCloseCallback(window, [](GLFWwindow* window){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(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);
switch(action) {
@@ -77,7 +77,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);
switch(action) {
@@ -90,13 +90,13 @@ namespace Archimedes {
}
});
glfwSetScrollCallback(w, [](GLFWwindow* window, double dx, double dy){
glfwSetScrollCallback(window, [](GLFWwindow* window, double dx, double dy){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
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);
d.sendEvent(new MouseMovedWindowEvent(dx, dy));
@@ -108,33 +108,32 @@ namespace Archimedes {
}
bool shouldClose() {
return glfwWindowShouldClose(w);
void swapBuffers() override { restoreContext(); glfwSwapBuffers(window); };
void pollEvents() override { glfwPollEvents(); }
bool shouldClose() override {
return glfwWindowShouldClose(window);
}
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
void restoreContext() override { glfwMakeContextCurrent(window); }
void pollEvents() { glfwPollEvents(); }
void restoreContext() { glfwMakeContextCurrent(w); }
void getSize(int& w, int& h) {
glfwGetFramebufferSize(this->w, &w, &h);
void getSize(int& w, int& h) override {
glfwGetFramebufferSize(window, &w, &h);
}
GLFWwindow* getWindow() { return w; }
GLFWwindow* getWindow() { return window; }
WindowData data;
virtual WindowGLFW* getWindowImpl() override { return this; }
private:
GLFWwindow* w;
GLFWwindow* window;
};
typedef WindowGLFW WindowImpl;
}
#endif
#endif

View File

@@ -1,15 +1,14 @@
#if WINDOW == 2
#ifndef WINDOW_SDL3
#define WINDOW_SDL3
#ifdef WINDOW_SDL3
#ifndef WINDOW_SDL3_H
#define WINDOW_SDL3_H
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include "utils/Window/Window.h"
#include <SDL3/SDL.h>
#if RENDERER == 2
#ifdef RENDERER_OPENGL
#include <SDL3/SDL_opengl.h>
@@ -17,8 +16,6 @@
namespace Archimedes {
class Window;
static bool EventCallback(void* ptr, SDL_Event* e) {
WindowData& data = *(WindowData*) ptr;
@@ -66,13 +63,13 @@ namespace Archimedes {
return true;
}
class WindowSDL3 {
class WindowSDL3 : public Window {
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;
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
@@ -80,26 +77,27 @@ namespace Archimedes {
std::abort();
}
#if RENDERER == 1
#ifdef RENDERER_OPENGL
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
#elif RENDERER == 2
#endif
#ifdef RENDERER_SDL3
SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
#endif
w = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
if (w == nullptr)
window = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
if (window == nullptr)
{
std::cerr << "Error: SDL_CreateWindow(): " << SDL_GetError() << std::endl;
std::abort();
}
SDL_SetWindowPosition(w, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
#if RENDERER == 1
gl_context = SDL_GL_CreateContext(w);
#ifdef RENDERER_OPENGL
gl_context = SDL_GL_CreateContext(window);
if (gl_context == nullptr)
{
@@ -107,67 +105,66 @@ namespace Archimedes {
std::abort();
}
SDL_GL_MakeCurrent(w, gl_context);
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1); // Enable vsync
#endif
SDL_AddEventWatch(EventCallback, &data);
SDL_ShowWindow(w);
SDL_ShowWindow(window);
}
~WindowSDL3() {
#if RENDERER == 1
#ifdef RENDERER_OPENGL
SDL_GL_DestroyContext(gl_context);
#endif
SDL_RemoveEventWatch(EventCallback, &data);
SDL_DestroyWindow(w);
SDL_DestroyWindow(window);
SDL_Quit();
}
bool shouldClose() { return false; }
bool shouldClose() override { return false; }
void doFrame() {
#if RENDERER == 1
void swapBuffers() override {
#ifdef RENDERER_OPENGL
restoreContext();
SDL_GL_SwapWindow(w);
SDL_GL_SwapWindow(window);
#endif
}
void pollEvents() {
void pollEvents() override {
static SDL_Event e;
while(SDL_PollEvent(&e)) {}
while(SDL_PollEvent(&e));
}
#if RENDERER == 1
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); }
WindowSDL3* getWindowImpl() override { return this; };
#ifdef RENDERER_OPENGL
void restoreContext() override { SDL_GL_MakeCurrent(window, gl_context); }
#endif
void getSize(int& w, int& h) {
w = this->width;
h = this->height;
void getSize(int& w, int& h) override {
w = this->w;
h = this->h;
}
void setSize(int& w, int& h) {
this->width = w;
this->height = h;
this->w = w;
this->h = h;
}
SDL_Window* getWindow() { return w; }
#if RENDERER == 1
SDL_Window* getWindow() { return window; }
#ifdef RENDERER_OPENGL
SDL_GLContext getContext() { return gl_context; }
#endif
WindowData data;
private:
SDL_Window* w;
int width = 0, height = 0;
#if RENDERER == 1
SDL_Window* window;
#ifdef RENDERER_OPENGL
SDL_GLContext gl_context;
#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

@@ -151,6 +151,8 @@ double Calculator::evaluate(std::string equation, std::unordered_map<char, std::
default:
break;
}
return 0;
}
std::string Calculator::calculate(std::string equation) {

View File

@@ -17,7 +17,7 @@ class Calculator : public Archimedes::Module {
bool parenthesis = true;
bool graphing = false;
//bool graphing = false;
void basicCalculator();

View File

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

View File

@@ -17,7 +17,7 @@ void TestNotCurses::onLoad() {
ncInstance = notcurses_init(&opts, NULL);
if(!ncInstance) {
app->stopModule(getName());
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
return;
}
}

View File

@@ -0,0 +1,69 @@
// This only works with opengl!!!!
#include "TestTriangle.h"
TestTriangle::TestTriangle(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
name = "TestTriangle";
WindowModule* wm = new WindowModule(a, h);
deps[*wm] = wm;
}
TestTriangle::~TestTriangle() {
if(app) {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
/*
#if WINDOW == 2
wm->removeEventFn(ecmd_it);
#endif
*/
wm->releaseWindow(window);
delete rt;
}
}
void TestTriangle::onLoad() {
// get window
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
if(!wm) {
std::cout << "No WindowModule TestTriangle!\n";
std::abort();
}
window = wm->aquireWindow();
window->getRenderer()->clearColor = { 0.2, 0.2, 0.4, 0.7 };
rt = window->getRenderer()->createRenderTarget(
vertices,
9 * sizeof(float),
indices,
3,
Archimedes::VertexLayout(),
vertexShaderSource,
fragmentShaderSource,
Archimedes::Shader::LoadType::FromSource
);
}
void TestTriangle::run() {
window->getRenderer()->render();
window->getRenderer()->draw(rt);
window->swapBuffers();
window->pollEvents();
}
bool TestTriangle::onEvent(const Archimedes::Event& e) {
return false;
}

View File

@@ -0,0 +1,65 @@
// This only works with opengl!!!!
#include "Archimedes.h"
#include "modules/WindowModule/WindowModule.h"
#define GLEW_STATIC
#include <GL/glew.h>
class TestTriangle : public Archimedes::Module {
public:
TestTriangle(Archimedes::App*, void*);
TestTriangle() { name = "TestTriangle"; }
~TestTriangle();
void onLoad() override;
void run() override;
bool onEvent(const Archimedes::Event& e) override;
private:
Archimedes::Window* window;
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"void main()\n"
"{\n"
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
"}\n\0";
Archimedes::RenderTarget* rt;
float vertices[9] = {
-0.5f, -0.5f, 0.0f, // left
0.5f, -0.5f, 0.0f, // right
0.0f, 0.5f, 0.0f // top
};
unsigned int indices[3] = {
0, // left
1, // right
2 // top
};
unsigned int vao, vbo, ibo, shaderProgram;
};
#ifdef TESTTRIANGLE_DYNAMIC
typedef TestTriangle mtype;
#include "endModule.h"
#endif

View File

@@ -15,9 +15,7 @@ ImguiModule::~ImguiModule() {
if(app) {
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
wm->getRenderer()->getCmdList().erase(rcmd_it);
#if WINDOW == 2
#ifdef WINDOW_SDL3
wm->removeEventFn(ecmd_it);
#endif
@@ -40,8 +38,8 @@ void ImguiModule::onLoad() {
window = wm->aquireWindow();
#if RENDERER == 2
renderer = window->getRenderer()->getRendererImpl().renderer;
#ifdef RENDERER_SDL3
renderer = window->getRenderer()->getRendererImpl()->renderer;
#endif
IMGUI_CHECKVERSION();
@@ -51,8 +49,8 @@ void ImguiModule::onLoad() {
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
#ifdef CUSTOMFONT
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
#endif
@@ -60,6 +58,18 @@ void ImguiModule::onLoad() {
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// Setup scaling
ImGuiStyle& style = ImGui::GetStyle();
io.ConfigDpiScaleFonts = true; // [Experimental] Automatically overwrite style.FontScaleDpi in Begin() when Monitor DPI changes. This will scale fonts but _NOT_ scale sizes/padding for now.
io.ConfigDpiScaleViewports = true; // [Experimental] Scale Dear ImGui and Platform Windows when Monitor DPI changes.
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
// Setup Platform/Renderer backends
if(!windowInit())
std::cout << "windowInit failed\n";
@@ -68,18 +78,6 @@ void ImguiModule::onLoad() {
std::cout << "rendererInit failed!\n" << std::endl;
}
wm->getRenderer()->getCmdList().push_back([this](){
ImGui::Render();
rendererRenderDrawData();
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
});
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
#if WINDOW == 2
ecmd_it = wm->addEventFn([](Archimedes::Event* e){
if(e->userData.type() == typeid(SDL_Event*)) {
@@ -92,30 +90,26 @@ void ImguiModule::onLoad() {
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}
void ImguiModule::run() {
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
ImGui::Render();
rendererRenderDrawData();
if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
window->getWindowImpl()->restoreContext();
}
};
bool ImguiModule::onEvent(const Archimedes::Event &e) {
/*
#if WINDOW == 2
if(e.userData != nullptr) {
unsigned int type = app->getEventType(e);
if(type == app->getEventType(Archimedes::ResizeWindowEvent())
|| type == app->getEventType(Archimedes::CloseWindowEvent())
|| type == app->getEventType(Archimedes::KeyPressedWindowEvent())
|| type == app->getEventType(Archimedes::KeyReleasedWindowEvent())
|| type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())
|| type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())
|| type == app->getEventType(Archimedes::ScrollWindowEvent())
|| type == app->getEventType(Archimedes::MouseMovedWindowEvent())
|| type == app->getEventType(Archimedes::FocusedWindowEvent())
|| type == app->getEventType(Archimedes::FocusLostWindowEvent())
|| type == app->getEventType(Archimedes::MovedWindowEvent())) {
ImGui_ImplSDL3_ProcessEvent((SDL_Event*) e.userData);
}
}
#endif
*/
return false;
}

View File

@@ -6,22 +6,24 @@
#include "modules/WindowModule/WindowModule.h"
#if RENDERER == 1
#ifdef RENDERER_OPENGL
#include "backends/imgui_impl_opengl3.h"
#elif RENDERER == 2
#endif
#ifdef RENDERER_SDL3
#include "backends/imgui_impl_sdlrenderer3.h"
#endif
#if WINDOW == 1
#ifdef WINDOW_GLFW
#include "backends/imgui_impl_glfw.h"
#include <GLFW/glfw3.h>
#elif WINDOW == 2
#endif
#ifdef WINDOW_SDL3
#include "backends/imgui_impl_sdl3.h"
#include <SDL3/SDL.h>
@@ -38,6 +40,8 @@ class ImguiModule : public Archimedes::Module {
~ImguiModule();
void onLoad() override;
void run() override;
bool onEvent(const Archimedes::Event&) override;
@@ -66,14 +70,14 @@ class ImguiModule : public Archimedes::Module {
std::list<std::function<void(Archimedes::Event*)>>::iterator ecmd_it;
#if RENDERER == 1
#ifdef RENDERER_OPENGL
auto rendererInit() { return ImGui_ImplOpenGL3_Init("#version 330"); }
void rendererShutdown() { ImGui_ImplOpenGL3_Shutdown(); }
void rendererNewFrame() { ImGui_ImplOpenGL3_NewFrame(); }
void rendererRenderDrawData() { ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); }
#elif RENDERER == 2
#endif
#ifdef RENDERER_SDL3
SDL_Renderer* renderer;
auto rendererInit() { return ImGui_ImplSDLRenderer3_Init(renderer); }
void rendererShutdown() { ImGui_ImplSDLRenderer3_Shutdown(); }
@@ -82,19 +86,22 @@ class ImguiModule : public Archimedes::Module {
void rendererRenderDrawData() { ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), renderer); }
#endif
#if WINDOW == 1
#if RENDERER == 1
auto windowInit() { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); }
#ifdef WINDOW_GLFW
#ifdef RENDERER_OPENGL
auto windowInit() { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl()->getWindow(), true); }
#endif
void windowShutdown() { ImGui_ImplGlfw_Shutdown(); }
void windowNewFrame() { ImGui_ImplGlfw_NewFrame(); }
#elif WINDOW == 2
#if RENDERER == 1
#endif
#ifdef WINDOW_SDL3
#ifdef RENDERER_OPENGL
auto windowInit() { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext()); }
#elif RENDERER == 2
#endif
#ifdef RENDERER_SDL3
auto windowInit() { return ImGui_ImplSDL3_InitForSDLRenderer(window->getWindowImpl().getWindow(), renderer); }
#endif

View File

@@ -56,6 +56,8 @@ void MainGUI::run() {
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();
ImGui::ShowDemoWindow();
} else {
app->end();
}

View File

@@ -15,7 +15,6 @@ WindowModule::~WindowModule() {
app->unregisterEvent(Archimedes::MovedWindowEvent());
if(renderer) {
renderer->getCmdList().clear();
delete renderer;
}
@@ -38,15 +37,16 @@ void WindowModule::onLoad() {
app->registerEvent(Archimedes::FocusLostWindowEvent());
app->registerEvent(Archimedes::MovedWindowEvent());
renderer = new Archimedes::Renderer();
renderer = new Archimedes::RendererOpenGL();
}
void WindowModule::run() {
if(window)
window->doFrame();
else
if(window) {
//window->doFrame();
} else {
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}
}
bool WindowModule::onEvent(const Archimedes::Event& e) {

View File

@@ -3,10 +3,8 @@
#include "Archimedes.h"
#include "utils/Renderer/Renderer.h"
#include "utils/Window/Window.h"
static_assert(!(WINDOW == 1 && RENDERER == 2), "Window and Renderer are incompatible!\n");
#include "utils/Renderer/RendererImpl/RendererOpenGL/RendererOpenGL.h"
#include "utils/Window/WindowImpl/WindowGLFW/WindowGLFW.h"
class WindowModule : public Archimedes::Module {
@@ -30,7 +28,7 @@ class WindowModule : public Archimedes::Module {
Archimedes::Window* aquireWindow() {
if(!window) {
window = new Archimedes::Window([this](Archimedes::Event* e) {
window = new Archimedes::WindowGLFW([this](Archimedes::Event* e) {
for(std::function<void(Archimedes::Event*)> f : eventFuncs)
f(e);
app->emitEvent(e);
@@ -39,15 +37,15 @@ class WindowModule : public Archimedes::Module {
window->setRenderer(renderer);
if(!renderer->init(window->getWindowImpl().getWindow())) {
if(!renderer->init()) {
std::cout << "Renderer init failed!\n";
std::abort();
}
}
windowRefs++;
#if RENDERER == 1
window->getWindowImpl().restoreContext();
#ifdef RENDERER_OPENGL
window->getWindowImpl()->restoreContext();
#endif
return window;
}
@@ -73,8 +71,8 @@ class WindowModule : public Archimedes::Module {
std::list<std::function<void(Archimedes::Event*)>> eventFuncs;
Archimedes::Window* window = nullptr;
Archimedes::Renderer* renderer = nullptr;
Archimedes::WindowGLFW* window = nullptr;
Archimedes::RendererOpenGL* renderer = nullptr;
};

View File

@@ -1,31 +1,71 @@
#include "ImguiEmbed.h"
bool ImguiEmbed::onEvent(const Archimedes::Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
return true;
}
return false;
}
void ImguiEmbed::run() {
for(auto m : runOrder)
for(std::string m : runOrder) {
modules[m]->onLoad();
}
// Main loop
while (!done && !runOrder.empty()) {
for(auto m : runOrder) {
for(std::string m : runOrder) {
modules[m]->run();
}
for(auto m : toClose) {
handleEvents();
for(std::string m : toClose) {
unload(m);
}
toClose.clear();
for(auto m : toOpen) {
static Archimedes::Module* n;
if(std::holds_alternative<std::string>(m)) {
load(std::get<std::string>(m))->onLoad();
n = load(std::get<std::string>(m));
} else {
load(std::get<Archimedes::Module*>(m))->onLoad();
n = load(std::get<Archimedes::Module*>(m));
}
if(n) {
n->onLoad();
n = nullptr;
}
}
toOpen.clear();
}
}

View File

@@ -1,7 +1,7 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/Archimedes-Modules/TestImgui/TestImgui.h"
#include "modules/MainGUI/MainGUI.h"
class ImguiEmbed : public Archimedes::App {
@@ -13,7 +13,7 @@ class ImguiEmbed : public Archimedes::App {
public:
ImguiEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new TestImgui(Get(), nullptr);
Archimedes::Module* m = (Archimedes::Module*) new MainGUI(Get(), nullptr);
load(m);
};

View File

@@ -0,0 +1,71 @@
#include "TriangleEmbed.h"
bool TriangleEmbed::onEvent(const Archimedes::Event& event) {
unsigned int type = getEventType(event);
if(type == getEventType(Archimedes::DoLoadModuleEvent())) {
Archimedes::DoLoadModuleEvent& e = (Archimedes::DoLoadModuleEvent&) event;
startModule(e.module);
return true;
} else if(type == getEventType(Archimedes::DoUnloadModuleEvent())) {
Archimedes::DoUnloadModuleEvent& e = (Archimedes::DoUnloadModuleEvent&) event;
stopModule(e.module);
return true;
} else if(type == getEventType(Archimedes::LoadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
return true;
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
return true;
}
return false;
}
void TriangleEmbed::run() {
for(std::string m : runOrder) {
modules[m]->onLoad();
}
// Main loop
while (!done && !runOrder.empty()) {
for(std::string m : runOrder) {
modules[m]->run();
}
handleEvents();
for(std::string m : toClose) {
unload(m);
}
toClose.clear();
for(auto m : toOpen) {
static Archimedes::Module* n;
if(std::holds_alternative<std::string>(m)) {
n = load(std::get<std::string>(m));
} else {
n = load(std::get<Archimedes::Module*>(m));
}
if(n) {
n->onLoad();
n = nullptr;
}
}
toOpen.clear();
}
}

View File

@@ -0,0 +1,29 @@
#define ENTRYPOINT
#include "Archimedes.h"
#include "modules/Archimedes-Modules/TestTriangle/TestTriangle.h"
class TriangleEmbed : public Archimedes::App {
private:
void printHelp() override {};
bool onEvent(const Archimedes::Event&) override;
public:
TriangleEmbed() {
Archimedes::Module* m = (Archimedes::Module*) new TestTriangle(Get(), nullptr);
load(m);
};
~TriangleEmbed() {};
void handleArgs(const int& argc, char* argv[]) override {};
void run() override;
};
#define APP_TYPE TriangleEmbed
#include "endApp.h"