use std::any
This commit is contained in:
124
flake.nix
124
flake.nix
@@ -91,42 +91,6 @@
|
||||
|
||||
};
|
||||
|
||||
WindowModuleSDL = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "WindowModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
sdl3
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=2 \
|
||||
-DWINDOWMODULE_DYNAMIC \
|
||||
-lGL -lGLEW \
|
||||
-lSDL3 \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
WindowModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "WindowModule";
|
||||
@@ -162,51 +126,6 @@
|
||||
|
||||
};
|
||||
|
||||
ImguiModuleSDL = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ImguiModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
sdl3
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
${imgui}/backends/imgui_impl_sdl3.cpp \
|
||||
${imgui}/backends/imgui_impl_opengl3.cpp \
|
||||
${imgui}/misc/cpp/*.cpp \
|
||||
${imgui}/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=2 \
|
||||
-DIMGUIMODULE_DYNAMIC \
|
||||
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
|
||||
-fpic -shared \
|
||||
-I src -I include -I ${imgui} -I . \
|
||||
-lGL -lGLEW \
|
||||
-lSDL3 \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
|
||||
ImguiModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ImguiModule";
|
||||
@@ -249,6 +168,49 @@
|
||||
'';
|
||||
|
||||
};
|
||||
MainGUIsdl = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "MainGUI";
|
||||
|
||||
src = ./.;
|
||||
|
||||
inherit imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
sdl3
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/MainGUI/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
$imgui/backends/imgui_impl_sdl3.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=2 \
|
||||
-DMAINGUI_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-lGL -lSDL3 -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
|
||||
MainGUI = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
#include <any>
|
||||
#include <typeinfo>
|
||||
#include <future>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Archimedes {
|
||||
instance = this;
|
||||
roInsert = runOrder.begin();
|
||||
|
||||
registerEvent(AnonymousEvent());
|
||||
|
||||
registerEvent(DoLoadModuleEvent());
|
||||
registerEvent(DoUnloadModuleEvent());
|
||||
|
||||
@@ -27,6 +29,8 @@ namespace Archimedes {
|
||||
|
||||
virtual ~App() {
|
||||
|
||||
unregisterEvent(AnonymousEvent());
|
||||
|
||||
unregisterEvent(DoLoadModuleEvent());
|
||||
unregisterEvent(DoUnloadModuleEvent());
|
||||
|
||||
|
||||
@@ -7,13 +7,27 @@ namespace Archimedes {
|
||||
|
||||
class Module;
|
||||
|
||||
class AnonymousEvent : public Event {
|
||||
|
||||
public:
|
||||
|
||||
AnonymousEvent() {}
|
||||
|
||||
AnonymousEvent(std::any data) : Event(data) {}
|
||||
|
||||
~AnonymousEvent() {}
|
||||
|
||||
operator std::string() const override { return "AnonymousEvent"; }
|
||||
|
||||
};
|
||||
|
||||
class LoadModuleEvent : public Event {
|
||||
|
||||
public:
|
||||
|
||||
LoadModuleEvent() : Event(nullptr) {}
|
||||
LoadModuleEvent() {}
|
||||
|
||||
LoadModuleEvent(std::string n) : Event(nullptr), module(n) {}
|
||||
LoadModuleEvent(std::string n) : module(n) {}
|
||||
|
||||
~LoadModuleEvent() {}
|
||||
|
||||
@@ -27,9 +41,9 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
DoLoadModuleEvent() : Event(nullptr) {}
|
||||
DoLoadModuleEvent() {}
|
||||
|
||||
DoLoadModuleEvent(std::variant<std::string, Module*> n) : Event(nullptr), module(n) {}
|
||||
DoLoadModuleEvent(std::variant<std::string, Module*> n) : module(n) {}
|
||||
|
||||
~DoLoadModuleEvent() {}
|
||||
|
||||
@@ -43,9 +57,9 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
UnloadModuleEvent() : Event(nullptr) {}
|
||||
UnloadModuleEvent() {}
|
||||
|
||||
UnloadModuleEvent(std::string n) : Event(nullptr), module(n) {}
|
||||
UnloadModuleEvent(std::string n) : module(n) {}
|
||||
|
||||
~UnloadModuleEvent() {}
|
||||
|
||||
@@ -58,9 +72,9 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
DoUnloadModuleEvent() : Event(nullptr) {}
|
||||
DoUnloadModuleEvent() {}
|
||||
|
||||
DoUnloadModuleEvent(std::string n) : Event(nullptr), module(n) {}
|
||||
DoUnloadModuleEvent(std::string n) : module(n) {}
|
||||
|
||||
~DoUnloadModuleEvent() {}
|
||||
|
||||
|
||||
@@ -9,13 +9,14 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
Event(void* ptr) : userData(ptr) {}
|
||||
Event() {}
|
||||
Event(std::any data) : userData(data) {}
|
||||
|
||||
virtual ~Event() {}
|
||||
|
||||
virtual operator std::string() const = 0;
|
||||
|
||||
void* userData;
|
||||
std::any userData;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
ResizeWindowEvent() : Event(nullptr), width(0), height(0) {}
|
||||
ResizeWindowEvent() : width(0), height(0) {}
|
||||
|
||||
ResizeWindowEvent(int w, int h, void* userData = nullptr) : Event(userData), width(w), height(h) {}
|
||||
ResizeWindowEvent(int w, int h) : width(w), height(h) {}
|
||||
ResizeWindowEvent(int w, int h, std::any userData) : Event(userData), width(w), height(h) {}
|
||||
|
||||
~ResizeWindowEvent() {
|
||||
|
||||
@@ -39,7 +40,8 @@ namespace Archimedes {
|
||||
|
||||
CloseWindowEvent() : Event(nullptr), window(nullptr) {}
|
||||
|
||||
CloseWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {}
|
||||
CloseWindowEvent(const Window* w) : window(w) {}
|
||||
CloseWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
|
||||
|
||||
~CloseWindowEvent() {
|
||||
|
||||
@@ -54,9 +56,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
KeyPressedWindowEvent() : Event(nullptr), key(0), repeat(0) {}
|
||||
KeyPressedWindowEvent() : key(0), repeat(0) {}
|
||||
|
||||
KeyPressedWindowEvent(unsigned int k, unsigned int r, void* userData = nullptr) : Event(userData), key(k), repeat(r) {}
|
||||
KeyPressedWindowEvent(unsigned int k, unsigned int r) : key(k), repeat(r) {}
|
||||
KeyPressedWindowEvent(unsigned int k, unsigned int r, std::any userData) : Event(userData), key(k), repeat(r) {}
|
||||
|
||||
~KeyPressedWindowEvent() {
|
||||
|
||||
@@ -74,7 +77,8 @@ namespace Archimedes {
|
||||
|
||||
KeyReleasedWindowEvent() : Event(nullptr), key(0) {}
|
||||
|
||||
KeyReleasedWindowEvent(unsigned int k, void* userData = nullptr) : Event(userData), key(k) {}
|
||||
KeyReleasedWindowEvent(unsigned int k) : key(k) {}
|
||||
KeyReleasedWindowEvent(unsigned int k, std::any userData) : Event(userData), key(k) {}
|
||||
|
||||
~KeyReleasedWindowEvent() {
|
||||
|
||||
@@ -89,9 +93,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
MouseButtonPressedWindowEvent() : Event(nullptr), button(0) {}
|
||||
MouseButtonPressedWindowEvent() : button(0) {}
|
||||
|
||||
MouseButtonPressedWindowEvent(unsigned int b, void* userData = nullptr) : Event(userData), button(b) {}
|
||||
MouseButtonPressedWindowEvent(unsigned int b) : button(b) {}
|
||||
MouseButtonPressedWindowEvent(unsigned int b, std::any userData) : Event(userData), button(b) {}
|
||||
|
||||
~MouseButtonPressedWindowEvent() {
|
||||
|
||||
@@ -106,9 +111,9 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
MouseButtonReleasedWindowEvent() : Event(nullptr), button(0) {}
|
||||
MouseButtonReleasedWindowEvent() : button(0) {}
|
||||
|
||||
MouseButtonReleasedWindowEvent(unsigned int b, void* userData = nullptr) : Event(userData), button(b) {}
|
||||
MouseButtonReleasedWindowEvent(unsigned int b) : button(b) {}
|
||||
|
||||
~MouseButtonReleasedWindowEvent() {
|
||||
|
||||
@@ -123,9 +128,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
ScrollWindowEvent() : Event(nullptr), dx(0), dy(0) {}
|
||||
ScrollWindowEvent() : dx(0), dy(0) {}
|
||||
|
||||
ScrollWindowEvent(double x, double y, void* userData = nullptr) : Event(userData), dx(x), dy(y) {}
|
||||
ScrollWindowEvent(double x, double y) : dx(x), dy(y) {}
|
||||
ScrollWindowEvent(double x, double y, std::any userData) : Event(userData), dx(x), dy(y) {}
|
||||
|
||||
~ScrollWindowEvent() {
|
||||
|
||||
@@ -140,9 +146,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
MouseMovedWindowEvent() : Event(nullptr), x(0), y(0) {}
|
||||
MouseMovedWindowEvent() : x(0), y(0) {}
|
||||
|
||||
MouseMovedWindowEvent(double x, double y, void* userData = nullptr) : Event(userData), x(x), y(y) {}
|
||||
MouseMovedWindowEvent(double x, double y) : x(x), y(y) {}
|
||||
MouseMovedWindowEvent(double x, double y, std::any userData) : Event(userData), x(x), y(y) {}
|
||||
|
||||
~MouseMovedWindowEvent() {
|
||||
|
||||
@@ -157,9 +164,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
FocusedWindowEvent() : Event(nullptr), window(nullptr) {}
|
||||
FocusedWindowEvent() : window(nullptr) {}
|
||||
|
||||
FocusedWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {}
|
||||
FocusedWindowEvent(const Window* w) : window(w) {}
|
||||
FocusedWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
|
||||
|
||||
~FocusedWindowEvent() {
|
||||
|
||||
@@ -174,9 +182,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
FocusLostWindowEvent() : Event(nullptr), window(nullptr) {}
|
||||
FocusLostWindowEvent() : window(nullptr) {}
|
||||
|
||||
FocusLostWindowEvent(const Window* w, void* userData = nullptr) : Event(userData), window(w) {}
|
||||
FocusLostWindowEvent(const Window* w) : window(w) {}
|
||||
FocusLostWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
|
||||
|
||||
~FocusLostWindowEvent() {
|
||||
|
||||
@@ -191,9 +200,10 @@ namespace Archimedes {
|
||||
|
||||
public:
|
||||
|
||||
MovedWindowEvent() : Event(nullptr), x(0), y(0) {}
|
||||
MovedWindowEvent() : x(0), y(0) {}
|
||||
|
||||
MovedWindowEvent(int x, int y, void* userData = nullptr) : Event(userData), x(x), y(y) {}
|
||||
MovedWindowEvent(int x, int y) : x(x), y(y) {}
|
||||
MovedWindowEvent(int x, int y, std::any userData) : Event(userData), x(x), y(y) {}
|
||||
|
||||
~MovedWindowEvent() {
|
||||
|
||||
|
||||
@@ -48,31 +48,6 @@ namespace Archimedes {
|
||||
|
||||
WindowData& data = (WindowData&) *ptr;
|
||||
|
||||
switch(e->type) {
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}, &data);*/
|
||||
|
||||
|
||||
SDL_GL_MakeCurrent(w, gl_context);
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
SDL_ShowWindow(w);
|
||||
}
|
||||
|
||||
~WindowSDL3() {
|
||||
SDL_GL_DestroyContext(gl_context);
|
||||
SDL_DestroyWindow(w);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
bool shouldClose() { return false; }
|
||||
|
||||
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
|
||||
|
||||
void pollEvents() {
|
||||
while(SDL_PollEvent(&e)) {
|
||||
switch(e.type) {
|
||||
|
||||
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
|
||||
@@ -117,6 +92,69 @@ namespace Archimedes {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, &data);*/
|
||||
|
||||
|
||||
SDL_GL_MakeCurrent(w, gl_context);
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
SDL_ShowWindow(w);
|
||||
}
|
||||
|
||||
~WindowSDL3() {
|
||||
SDL_GL_DestroyContext(gl_context);
|
||||
SDL_DestroyWindow(w);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
bool shouldClose() { return false; }
|
||||
|
||||
void doFrame() { restoreContext(); SDL_GL_SwapWindow(w); }
|
||||
|
||||
void pollEvents() {
|
||||
while(SDL_PollEvent(&e)) {
|
||||
switch(e.type) {
|
||||
|
||||
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
|
||||
case SDL_EVENT_QUIT:
|
||||
data.sendEvent(new CloseWindowEvent(data.window, &e));
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_RESIZED:
|
||||
width = e.window.data1;
|
||||
height = e.window.data2;
|
||||
data.sendEvent(new ResizeWindowEvent(e.window.data1, e.window.data2, &e));
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_MOUSE_ENTER:
|
||||
case SDL_EVENT_WINDOW_FOCUS_GAINED:
|
||||
data.sendEvent(new FocusedWindowEvent(data.window, &e));
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
|
||||
case SDL_EVENT_WINDOW_FOCUS_LOST:
|
||||
data.sendEvent(new FocusLostWindowEvent(data.window, &e));
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0, &e));
|
||||
break;
|
||||
case SDL_EVENT_KEY_UP:
|
||||
data.sendEvent(new KeyReleasedWindowEvent(e.key.key, &e));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y, &e));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button, &e));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||
data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button, &e));
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y, &e));
|
||||
break;
|
||||
default:
|
||||
data.sendEvent(new AnonymousEvent(&e));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,22 +78,8 @@ void ImguiModule::onLoad() {
|
||||
|
||||
#if WINDOW == 2
|
||||
ecmd_it = wm->addEventFn([this](Archimedes::Event* e){
|
||||
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);
|
||||
}
|
||||
if(e->userData.type() == std::typeid(SDL_Event*)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(std::any_cast<SDL_Event*>(e.userData));
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
@@ -62,6 +62,8 @@ bool MinimalApp::onEvent(const Archimedes::Event& event) {
|
||||
return true;
|
||||
} else if(type == getEventType(Archimedes::UnloadModuleEvent())) {
|
||||
|
||||
return true;
|
||||
} else if(type == getEventType(Archimedes::AnonymousEvent())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user