use std::any
This commit is contained in:
@@ -17,6 +17,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user