Compare commits

...

24 Commits

Author SHA1 Message Date
b8654659c7 debug 2025-05-05 13:21:07 -05:00
7b4f8e5579 spellcheck 2025-05-05 13:19:24 -05:00
f35c58d3d6 use std::any 2025-05-05 13:17:38 -05:00
c2da1944d8 sdl event stuff 2025-05-05 11:08:07 -05:00
2820387851 wrap imgui impl funcs 2025-05-04 22:51:45 -05:00
853881e5e8 try WindowSDL3 2025-05-04 22:04:04 -05:00
6f4b9b68fd work on WindowSDL3 2025-05-04 17:59:14 -05:00
ff2a3337b4 network stuff 2025-05-03 15:27:44 -05:00
83b98db914 should allow reconnect on serverside disconnection 2025-05-02 12:23:21 -05:00
047684c51b WindowModule should unload when no window exists during run 2025-05-02 12:18:16 -05:00
73ce460446 weird 2025-05-02 10:47:00 -05:00
1a098daf9d remove debug prints 2025-05-02 10:44:52 -05:00
2ef95d6e90 help 2025-05-02 10:35:11 -05:00
74b82845b5 segfault 2025-05-02 01:16:38 -05:00
6f322cadb8 consolodate NetworkEvents 2025-05-02 00:48:29 -05:00
b4ac013f18 introduce active and passive events 2025-04-23 13:51:09 -05:00
a3fb96abb7 that was dumb 2025-04-21 12:04:14 -05:00
8dd0710786 only delete if ready to unload 2025-04-21 12:02:06 -05:00
8f528c7f95 reload lingering modules by name 2025-04-21 11:53:08 -05:00
d253ebb197 aquire and release 2025-04-20 14:58:39 -05:00
c6fa731df0 ! 2025-04-20 12:42:40 -05:00
a39f43e439 Events 2025-04-19 21:32:57 -05:00
87afa3a0ec WindowEvents 2025-04-19 15:08:39 -05:00
600d0f3c81 add some server commands 2025-04-17 21:59:14 -05:00
36 changed files with 1195 additions and 283 deletions

View File

@@ -111,8 +111,8 @@
modules/WindowModule/src/*.cpp \
-fpic -shared \
-I src -I include \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-DRENDERER=1 \
-DWINDOW=1 \
-DWINDOWMODULE_DYNAMIC \
-lGL -lglfw -lGLEW \
-Wall \
@@ -151,8 +151,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-DRENDERER=1 \
-DWINDOW=1 \
-DIMGUIMODULE_DYNAMIC \
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
-fpic -shared \
@@ -168,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 {
@@ -195,8 +238,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-DRENDERER=1 \
-DWINDOW=1 \
-DMAINGUI_DYNAMIC \
-fpic -shared \
-I src -I include -I $imgui -I . \
@@ -238,8 +281,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-DRENDERER=1 \
-DWINDOW=1 \
-DTERMINAL_DYNAMIC \
-fpic -shared \
-I src -I include -I $imgui -I . \
@@ -284,8 +327,8 @@
$imgui/backends/imgui_impl_opengl3.cpp \
$imgui/misc/cpp/*.cpp \
$imgui/*.cpp \
-DRENDERER_OPENGL \
-DWINDOW_GLFW \
-DRENDERER=1 \
-DWINDOW=1 \
-DOLLAMA_DYNAMIC \
-fpic -shared \
-I src -I include -I $imgui -I . \

View File

@@ -8,7 +8,8 @@
#include <array>
#include <vector>
#include <variant>
#include <any>
#include <typeinfo>
#include <future>
#include <unordered_map>
#include <map>

View File

@@ -17,10 +17,26 @@ namespace Archimedes {
}
instance = this;
roInsert = runOrder.begin();
registerEvent(AnonymousEvent());
registerEvent(DoLoadModuleEvent());
registerEvent(DoUnloadModuleEvent());
registerEvent(LoadModuleEvent());
registerEvent(UnloadModuleEvent());
}
virtual ~App() {
unregisterEvent(AnonymousEvent());
unregisterEvent(DoLoadModuleEvent());
unregisterEvent(DoUnloadModuleEvent());
unregisterEvent(LoadModuleEvent());
unregisterEvent(UnloadModuleEvent());
for(std::string s : runOrder) {
void* handle = modules[s]->getHandle();
delete modules[s];
@@ -40,17 +56,6 @@ namespace Archimedes {
virtual void run() = 0;
virtual void stopModule(std::string lib) {
//unload modules that depend on the one we are unloading
for(std::string s : runOrder) {
if(modules[s]->deps.find(lib) != modules[s]->deps.end()) {
stopModule(s);
}
}
toClose.push_back(lib);
}
virtual void startModule(std::variant<std::string, Module*> m) { toOpen.push_back(m); }
void end() { done = true; }
@@ -94,16 +99,48 @@ namespace Archimedes {
std::list<std::string> toClose;
std::list<std::variant<std::string, Module*>> toOpen;
virtual void stopModule(std::string lib) {
//unload modules that depend on the one we are unloading
for(std::string s : runOrder) {
if(modules[s]->deps.find(lib) != modules[s]->deps.end()) {
stopModule(s);
}
}
toClose.push_back(lib);
}
virtual void startModule(std::variant<std::string, Module*> m) { toOpen.push_back(m); }
virtual bool onEvent(const Event& event) = 0;
void handleEvents() {
static bool handled;
while(!events.empty()) {
handled = false;
for(auto it = runOrder.rbegin(); it != runOrder.rend(); it++) {
if(modules[*it]->onEvent(*events.front())) {
handled = modules[*it]->onEvent(*events.front());
if(handled) {
Event* e = events.front();
events.pop_front();
delete e;
break;
}
}
if(!handled) {
if(this->onEvent(*events.front())) {
Event* e = events.front();
events.pop_front();
delete e;
} else {
std::cout << "Error: Unhandled Event: " << (std::string) *events.front() << std::endl;
}
}
}
}
@@ -127,8 +164,20 @@ namespace Archimedes {
return create(Get(), h);
}
virtual Module* load(std::string modulePath) {
Module* m = dynamicLoad(modulePath);
virtual Module* reload(std::string lib) {
for(std::string s : runOrder) {
if(s == lib) {
return modules[lib];
}
}
return modules.find(lib) != modules.end() ? load(modules[lib]) : nullptr;
}
virtual Module* load(std::string moduleNameOrPath) {
Module* m = dynamicLoad(moduleNameOrPath);
//return m != nullptr ? load(m) : reload(moduleNameOrPath);
return load(m);
}
@@ -146,10 +195,11 @@ namespace Archimedes {
if(h) {
dlclose(h);
}
return nullptr;
return modules[*it];
}
}
if(modules.find(*m) == modules.end())
modules[*m] = m;
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
@@ -189,13 +239,13 @@ namespace Archimedes {
runOrder.insert(roInsert, *m);
emitEvent(new LoadModuleEvent(*m));
return m;
}
virtual void unload(std::string name) {
std::cout << "Attempting to unload module: " << name << std::endl;
if(modules.find(name) == modules.end())
return;
@@ -223,7 +273,7 @@ namespace Archimedes {
}
}
std::cout << "Successfully unloaded module: " << name << std::endl;
emitEvent(new UnloadModuleEvent(name));
}
virtual void printHelp() = 0;

View File

@@ -0,0 +1,88 @@
#ifndef BASICEVENTS_H
#define BASICEVENTS_H
#include "Event.h"
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() {}
LoadModuleEvent(std::string n) : module(n) {}
~LoadModuleEvent() {}
operator std::string() const override { return "LoadModuleEvent"; }
std::string module;
};
class DoLoadModuleEvent : public Event {
public:
DoLoadModuleEvent() {}
DoLoadModuleEvent(std::variant<std::string, Module*> n) : module(n) {}
~DoLoadModuleEvent() {}
operator std::string() const override { return "DoLoadModuleEvent"; }
std::variant<std::string, Module*> module;
};
class UnloadModuleEvent : public Event {
public:
UnloadModuleEvent() {}
UnloadModuleEvent(std::string n) : module(n) {}
~UnloadModuleEvent() {}
operator std::string() const override { return "UnloadModuleEvent"; }
std::string module;
};
class DoUnloadModuleEvent : public Event {
public:
DoUnloadModuleEvent() {}
DoUnloadModuleEvent(std::string n) : module(n) {}
~DoUnloadModuleEvent() {}
operator std::string() const override { return "DoUnloadModuleEvent"; }
std::string module;
};
}
#endif

View File

@@ -9,11 +9,17 @@ namespace Archimedes {
public:
Event() {}
Event(std::any data) : userData(data) {}
virtual ~Event() {}
virtual operator std::string() const = 0;
std::any userData;
};
}
#include "BasicEvents.h"
#endif

View File

@@ -0,0 +1,59 @@
#ifndef NETWORKEVENTS_H
#define NETWORKEVENTS_H
#include "Event.h"
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
namespace Archimedes {
class DataRecievedEvent : public Event {
public:
DataRecievedEvent() : Event(nullptr), msg(nullptr) {}
DataRecievedEvent(ISteamNetworkingMessage* m) : Event(nullptr), msg(m) {}
~DataRecievedEvent() {
if(msg)
msg->Release();
}
operator std::string() const override { return "DataRecievedEvent"; }
ISteamNetworkingMessage* msg;
};
class DataSentEvent : public Event {
public:
DataSentEvent() : Event(nullptr), msg(nullptr) {}
DataSentEvent(const void* m, uint32 l) : Event(nullptr), msg(m), length(l) {}
operator std::string() const override { return "DataSentEvent"; }
const void* msg;
uint32 length;
};
class ConnectionStatusChangedEvent : public Event {
public:
ConnectionStatusChangedEvent() : Event(nullptr), info(nullptr) {}
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : Event(nullptr), info(i) {}
operator std::string() const override { return "ConnectionStatusChangedEvent"; }
SteamNetConnectionStatusChangedCallback_t* info;
};
}
#endif

View File

@@ -25,13 +25,13 @@ namespace Archimedes {
virtual void run() {}
virtual bool onEvent(const Event& e) { return false; }
virtual void onLoad() {};
virtual void onLoad() {}
virtual void onUnload() {}
operator std::string() const { return name; }
void* getHandle() { return handle; }
//std::any getData(std::string s) { return data[s.c_str()]; };
protected:
std::string name;
@@ -42,7 +42,6 @@ namespace Archimedes {
std::unordered_map<std::string, std::variant<std::string, Module*>> exts;
std::unordered_map<std::string, Module*> moduleInstances;
//std::unordered_map<std::string, std::any> data;
};
}

View File

@@ -1,5 +1,7 @@
#ifdef RENDERER_OPENGL
#undef RENDERER_OPENGL
#if RENDERER == 1
#ifndef RENDERER_OPENGL
#define RENDERER_OPENGL
#include "pch.hpp"
@@ -38,3 +40,5 @@ namespace Archimedes {
}
#endif
#endif

View File

@@ -1,9 +1,11 @@
#ifndef WINDOW_H
#define WINDOW_H
#include "WindowEvents.h"
#include "utils/Renderer/Renderer.h"
#include "WindowGLFW/WindowGLFW.h"
#include "WindowSDL3/WindowSDL3.h"
namespace Archimedes {
@@ -11,18 +13,20 @@ namespace Archimedes {
public:
Window() {}
Window(const std::function<void(Event*)>& sendEventFn) : window(this, sendEventFn) {}
~Window() {}
bool shouldClose() { return window.shouldClose(); }
void getSize(int& w, int& h) {
window.getSize(w, h);
}
void doFrame() {
window.pollEvents();
window.getSize(renderer->w, renderer->h);
renderer->render();
window.doFrame();

View File

@@ -0,0 +1,220 @@
#ifndef WINDOWEVENTS_H
#define WINDOWEVENTS_H
#include "utils/Events/Event.h"
//implimentation independent events
namespace Archimedes {
class Window;
struct WindowData {
Window* window;
std::list<Event*> eventList;
std::function<void(Event*)> sendEvent;
};
class ResizeWindowEvent : public Event {
public:
ResizeWindowEvent() : width(0), height(0) {}
ResizeWindowEvent(int w, int h) : width(w), height(h) {}
ResizeWindowEvent(int w, int h, std::any userData) : Event(userData), width(w), height(h) {}
~ResizeWindowEvent() {
}
operator std::string() const override { return "Archimedes::ResizeWindowEvent"; }
int width, height;
};
class CloseWindowEvent : public Event {
public:
CloseWindowEvent() : Event(nullptr), window(nullptr) {}
CloseWindowEvent(const Window* w) : window(w) {}
CloseWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
~CloseWindowEvent() {
}
operator std::string() const override { return "Archimedes::CloseWindowEvent"; }
const Window* window;
};
class KeyPressedWindowEvent : public Event {
public:
KeyPressedWindowEvent() : key(0), repeat(0) {}
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() {
}
operator std::string() const override { return "Archimedes::KeyPressedWindowEvent"; }
unsigned int key;
unsigned int repeat;
};
class KeyReleasedWindowEvent : public Event {
public:
KeyReleasedWindowEvent() : Event(nullptr), key(0) {}
KeyReleasedWindowEvent(unsigned int k) : key(k) {}
KeyReleasedWindowEvent(unsigned int k, std::any userData) : Event(userData), key(k) {}
~KeyReleasedWindowEvent() {
}
operator std::string() const override { return "Archimedes::KeyReleasedWindowEvent"; }
unsigned int key;
};
class MouseButtonPressedWindowEvent : public Event {
public:
MouseButtonPressedWindowEvent() : button(0) {}
MouseButtonPressedWindowEvent(unsigned int b) : button(b) {}
MouseButtonPressedWindowEvent(unsigned int b, std::any userData) : Event(userData), button(b) {}
~MouseButtonPressedWindowEvent() {
}
operator std::string() const override { return "Archimedes::MouseButtonPressedWindowEvent"; }
unsigned int button;
};
class MouseButtonReleasedWindowEvent : public Event {
public:
MouseButtonReleasedWindowEvent() : button(0) {}
MouseButtonReleasedWindowEvent(unsigned int b) : button(b) {}
MouseButtonReleasedWindowEvent(unsigned int b, std::any userData) : Event(userData), button(b) {}
~MouseButtonReleasedWindowEvent() {
}
operator std::string() const override { return "Archimedes::MouseButtonReleasedWindowEvent"; }
unsigned int button;
};
class ScrollWindowEvent : public Event {
public:
ScrollWindowEvent() : dx(0), dy(0) {}
ScrollWindowEvent(double x, double y) : dx(x), dy(y) {}
ScrollWindowEvent(double x, double y, std::any userData) : Event(userData), dx(x), dy(y) {}
~ScrollWindowEvent() {
}
operator std::string() const override { return "Archimedes::ScrollWindowEvent"; }
double dx, dy;
};
class MouseMovedWindowEvent : public Event {
public:
MouseMovedWindowEvent() : x(0), y(0) {}
MouseMovedWindowEvent(double x, double y) : x(x), y(y) {}
MouseMovedWindowEvent(double x, double y, std::any userData) : Event(userData), x(x), y(y) {}
~MouseMovedWindowEvent() {
}
operator std::string() const override { return "Archimedes::MouseMovedWindowEvent"; }
double x, y;
};
class FocusedWindowEvent : public Event {
public:
FocusedWindowEvent() : window(nullptr) {}
FocusedWindowEvent(const Window* w) : window(w) {}
FocusedWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
~FocusedWindowEvent() {
}
operator std::string() const override { return "Archimedes::FocusedWindowEvent"; }
const Window* window;
};
class FocusLostWindowEvent : public Event {
public:
FocusLostWindowEvent() : window(nullptr) {}
FocusLostWindowEvent(const Window* w) : window(w) {}
FocusLostWindowEvent(const Window* w, std::any userData) : Event(userData), window(w) {}
~FocusLostWindowEvent() {
}
operator std::string() const override { return "Archimedes::FocusLostWindowEvent"; }
const Window* window;
};
class MovedWindowEvent : public Event {
public:
MovedWindowEvent() : x(0), y(0) {}
MovedWindowEvent(int x, int y) : x(x), y(y) {}
MovedWindowEvent(int x, int y, std::any userData) : Event(userData), x(x), y(y) {}
~MovedWindowEvent() {
}
operator std::string() const override { return "Archimedes::MovedWindowEvent"; }
int x, y;
};
}
#endif

View File

@@ -1,18 +1,27 @@
#if WINDOW == 1
#ifndef WINDOW_GLFW
#define WINDOW_GLFW
#include "pch.hpp"
#ifdef WINDOW_GLFW
#undef WINDOW_GLFW
#include "utils/Window/WindowEvents.h"
#include <GLFW/glfw3.h>
namespace Archimedes {
class Window;
class WindowGLFW {
public:
WindowGLFW() {
WindowGLFW(Window* p, const std::function<void(Event*)>& sendEvent) {
data.window = p;
data.sendEvent = sendEvent;
glfwSetErrorCallback([](int e, const char* m){
std::cout << "GLFW Error: " << m << std::endl;
@@ -31,6 +40,60 @@ namespace Archimedes {
glfwMakeContextCurrent(w);
glfwSwapInterval(1);
glfwSetWindowUserPointer(w, &data);
glfwSetWindowSizeCallback(w, [](GLFWwindow* window, int w, int h){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new ResizeWindowEvent(w, h));
});
glfwSetWindowCloseCallback(w, [](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){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
switch(action) {
case GLFW_PRESS:
d.sendEvent(new KeyPressedWindowEvent(key, 0));
break;
case GLFW_RELEASE:
d.sendEvent(new KeyReleasedWindowEvent(key));
break;
case GLFW_REPEAT:
d.sendEvent(new KeyPressedWindowEvent(key, 1));
break;
}
});
glfwSetMouseButtonCallback(w, [](GLFWwindow* window, int button, int action, int mods){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
switch(action) {
case GLFW_PRESS:
d.sendEvent(new MouseButtonPressedWindowEvent(button));
break;
case GLFW_RELEASE:
d.sendEvent(new MouseButtonReleasedWindowEvent(button));
break;
}
});
glfwSetScrollCallback(w, [](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){
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
d.sendEvent(new MouseMovedWindowEvent(dx, dy));
});
}
~WindowGLFW() {
@@ -54,8 +117,11 @@ namespace Archimedes {
GLFWwindow* getWindow() { return w; }
WindowData data;
private:
GLFWwindow* w;
};
typedef WindowGLFW WindowImpl;
@@ -63,3 +129,5 @@ namespace Archimedes {
}
#endif
#endif

View File

@@ -0,0 +1,187 @@
#if WINDOW == 2
#ifndef WINDOW_SDL3
#define WINDOW_SDL3
#include "pch.hpp"
#include "utils/Window/WindowEvents.h"
#include <SDL3/SDL.h>
#include <SDL3/SDL_opengl.h>
namespace Archimedes {
class Window;
class WindowSDL3 {
public:
WindowSDL3(Window* p, const std::function<void(Event*)>& sendEvent) {
data.window = p;
data.sendEvent = sendEvent;
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
w = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
if (w == nullptr)
{
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
std::abort();
}
SDL_SetWindowPosition(w, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
gl_context = SDL_GL_CreateContext(w);
if (gl_context == nullptr)
{
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
std::abort();
}
/*SDL_AddEventWatch([](void* ptr, SDL_Event* e) -> bool {
WindowData& data = (WindowData&) *ptr;
switch(e.type) {
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
case SDL_EVENT_QUIT:
data.sendEvent(new CloseWindowEvent(data.window, (void*) &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, (void*) &e));
break;
case SDL_EVENT_WINDOW_MOUSE_ENTER:
case SDL_EVENT_WINDOW_FOCUS_GAINED:
data.sendEvent(new FocusedWindowEvent(data.window, (void*) &e));
break;
case SDL_EVENT_WINDOW_MOUSE_LEAVE:
case SDL_EVENT_WINDOW_FOCUS_LOST:
data.sendEvent(new FocusLostWindowEvent(data.window, (void*) &e));
break;
case SDL_EVENT_KEY_DOWN:
data.sendEvent(new KeyPressedWindowEvent(e.key.key, e.key.repeat ? 1 : 0, (void*) &e));
break;
case SDL_EVENT_KEY_UP:
data.sendEvent(new KeyReleasedWindowEvent(e.key.key, (void*) &e));
break;
case SDL_EVENT_TEXT_EDITING:
break;
case SDL_EVENT_TEXT_INPUT:
break;
case SDL_EVENT_MOUSE_MOTION:
data.sendEvent(new MouseMovedWindowEvent(e.motion.x, e.motion.y, (void*) &e));
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
data.sendEvent(new MouseButtonPressedWindowEvent(e.button.button, (void*) &e));
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
data.sendEvent(new MouseButtonReleasedWindowEvent(e.button.button, (void*) &e));
break;
case SDL_EVENT_MOUSE_WHEEL:
data.sendEvent(new ScrollWindowEvent(e.wheel.x, e.wheel.y, (void*) &e));
break;
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;
}
}
}
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); }
void getSize(int& w, int& h) {
w = this->width;
h = this->height;
}
SDL_Window* getWindow() { return w; }
SDL_GLContext getContext() { return gl_context; }
WindowData data;
private:
SDL_Window* w;
int width = 0, height = 0;
SDL_GLContext gl_context;
SDL_Event e;
};
typedef WindowSDL3 WindowImpl;
}
#endif
#endif

View File

@@ -1,55 +0,0 @@
#include "Archimedes.h"
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
namespace CMEvent {
class DataRecievedEvent : public Archimedes::Event {
public:
DataRecievedEvent() : msg(nullptr) {}
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
~DataRecievedEvent() {
if(msg)
msg->Release();
}
operator std::string() const { return "CMEvent::DataRecievedEvent"; }
ISteamNetworkingMessage* msg;
};
class DataSentEvent : public Archimedes::Event {
public:
DataSentEvent() : msg(nullptr) {}
DataSentEvent(ISteamNetworkingMessage* m) : msg(m) {}
operator std::string() const { return "CMEvent::DataSentEvent"; }
ISteamNetworkingMessage* msg;
};
class ConnectionStatusChangedEvent : public Archimedes::Event {
public:
ConnectionStatusChangedEvent() : info(nullptr) {}
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : info(i) {}
operator std::string() const { return "CMEvent::ConnectionStatusChangedEvent"; }
SteamNetConnectionStatusChangedCallback_t* info;
};
}

View File

@@ -6,9 +6,9 @@ ClientModule::ClientModule(Archimedes::App* a, void* h) : Archimedes::Module(a,
ClientModule::~ClientModule() {
if(app) {
app->unregisterEvent(CMEvent::DataRecievedEvent());
app->unregisterEvent(CMEvent::DataSentEvent());
app->unregisterEvent(CMEvent::ConnectionStatusChangedEvent());
app->unregisterEvent(Archimedes::DataRecievedEvent());
app->unregisterEvent(Archimedes::DataSentEvent());
app->unregisterEvent(Archimedes::ConnectionStatusChangedEvent());
GameNetworkingSockets_Kill();
}
@@ -16,9 +16,9 @@ ClientModule::~ClientModule() {
void ClientModule::onLoad() {
app->registerEvent(CMEvent::DataSentEvent());
app->registerEvent(CMEvent::DataRecievedEvent());
app->registerEvent(CMEvent::ConnectionStatusChangedEvent());
app->registerEvent(Archimedes::DataSentEvent());
app->registerEvent(Archimedes::DataRecievedEvent());
app->registerEvent(Archimedes::ConnectionStatusChangedEvent());
SteamDatagramErrMsg errMsg;
if ( !GameNetworkingSockets_Init( nullptr, errMsg ) ) {
@@ -62,9 +62,9 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
unsigned int type = app->getEventType(event);
if(eventsToHandle & CMEventEnum::ConnectionStatusChanged && type == app->getEventType(CMEvent::ConnectionStatusChangedEvent())) {
if(eventsToHandle & CMEventEnum::ConnectionStatusChanged && type == app->getEventType(Archimedes::ConnectionStatusChangedEvent())) {
CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event;
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
switch(e.info->m_info.m_eState) {
@@ -96,6 +96,7 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
// OnDisconnect
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
connection = k_HSteamNetConnection_Invalid;
stopClient();
break;
}
@@ -114,9 +115,9 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
}
return true;
} else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(CMEvent::DataRecievedEvent())) {
} else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(Archimedes::DataRecievedEvent())) {
return true;
} else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(CMEvent::DataSentEvent())) {
} else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(Archimedes::DataSentEvent())) {
return true;
}
@@ -125,7 +126,7 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
void ClientModule::pollIncomingData() {
while(running) {
while(running && connection != k_HSteamNetConnection_Invalid) {
ISteamNetworkingMessage *pIncomingMsg = nullptr;
int numMsgs = interface->ReceiveMessagesOnConnection( connection, &pIncomingMsg, 1 );
if ( numMsgs == 0 )
@@ -135,6 +136,6 @@ void ClientModule::pollIncomingData() {
assert( numMsgs == 1 && pIncomingMsg );
assert( pIncomingMsg->m_conn == connection );
app->emitEvent(new CMEvent::DataRecievedEvent(pIncomingMsg));
app->emitEvent(new Archimedes::DataRecievedEvent(pIncomingMsg));
}
}

View File

@@ -3,7 +3,7 @@
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
#include "ClientEvents.h"
#include "utils/Events/NetworkEvents.h"
class ClientModule : public Archimedes::Module {
@@ -25,7 +25,7 @@ class ClientModule : public Archimedes::Module {
void sendReliable(const void* data, uint32 byteCount) {
interface->SendMessageToConnection(connection, data, byteCount, k_nSteamNetworkingSend_Reliable, nullptr);
app->emitEvent(new Archimedes::DataSentEvent(data, byteCount));
}
bool isRunning() const { return running; }
@@ -58,7 +58,7 @@ class ClientModule : public Archimedes::Module {
}
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
app->emitEvent(new CMEvent::ConnectionStatusChangedEvent(pInfo));
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
}
void PollConnectionStateChanges() {

View File

@@ -1,12 +1,5 @@
#include "ImguiModule.h"
#include "modules/WindowModule/src/WindowModule.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#include <GLFW/glfw3.h>
#include "pch.hpp"
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
@@ -24,9 +17,15 @@ ImguiModule::~ImguiModule() {
wm->getRenderer()->getCmdList().erase(rcmd_it);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
#if WINDOW == 2
wm->removeEventFn(ecmd_it);
#endif
rendererShutdown();
windowShutdown();
ImGui::DestroyContext();
wm->releaseWindow(window);
}
}
@@ -39,6 +38,8 @@ void ImguiModule::onLoad() {
std::abort();
}
window = wm->aquireWindow();
IMGUI_CHECKVERSION();
context = ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
@@ -56,27 +57,61 @@ void ImguiModule::onLoad() {
//ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true))
std::cout << "GLFWImpl failed\n";
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
if(!windowInit())
std::cout << "windowInit failed\n";
if(!rendererInit()) {
std::cout << "rendererInit failed!\n" << std::endl;
}
wm->getRenderer()->getCmdList().push_back([](){
wm->getRenderer()->getCmdList().push_back([this](){
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
rendererRenderDrawData();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
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*)) {
ImGui_ImplSDL3_ProcessEvent(std::any_cast<SDL_Event*>(e->userData));
}
});
#endif
//Compute first frame ahead of first WindowModule->run()
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
rendererNewFrame();
windowNewFrame();
ImGui::NewFrame();
}
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

@@ -1,12 +1,29 @@
#ifndef GUIMODULE
#define GUIMODULE
#endif
#include "Archimedes.h"
#include "imgui.h"
#include "misc/cpp/imgui_stdlib.h"
#include "modules/WindowModule/src/WindowModule.h"
#if RENDERER == 1
#include "backends/imgui_impl_opengl3.h"
#endif
#if WINDOW == 1
#include "backends/imgui_impl_glfw.h"
#include <GLFW/glfw3.h>
#elif WINDOW == 2
#include "backends/imgui_impl_sdl3.h"
#include <SDL3/SDL.h>
#endif
class ImguiModule : public Archimedes::Module {
public:
@@ -16,20 +33,68 @@ class ImguiModule : public Archimedes::Module {
~ImguiModule();
void onLoad();
void onLoad() override;
bool onEvent(const Archimedes::Event& e) { return false; }
bool onEvent(const Archimedes::Event&) override;
ImGuiContext* getContext() { return context; }
ImGuiContext* aquireContext() {
contextRefs++;
return context;
}
void releaseContext(ImGuiContext* ctxt) {
if(ctxt == context && context != nullptr) {
if(--contextRefs == 0) {
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}
}
}
private:
int contextRefs = 0;
ImGuiContext* context;
Archimedes::Window* window;
std::list<std::function<void()>>::iterator rcmd_it;
std::list<std::function<void(Archimedes::Event*)>>::iterator ecmd_it;
#if RENDERER == 1
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()); }
#endif
#if WINDOW == 1
#if RENDERER == 1
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
auto windowInit() { return ImGui_ImplSDL3_InitForOpenGL(window->getWindowImpl().getWindow(), window->getWindowImpl().getContext()); }
#endif
void windowShutdown() { ImGui_ImplSDL3_Shutdown(); }
void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); }
#endif
};
#ifdef IMGUIMODULE_DYNAMIC
#define MODULE_TYPE ImguiModule
#include "endModule.h"
#endif

View File

@@ -12,7 +12,10 @@ MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
MainGUI::~MainGUI() {
if(app) {}
if(app) {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
}
void MainGUI::onLoad() {
@@ -24,7 +27,7 @@ void MainGUI::onLoad() {
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
ImGui::SetCurrentContext(im->aquireContext());
}
@@ -44,12 +47,12 @@ void MainGUI::run() {
ImGui::InputText("module: ", &s);
if(ImGui::Button("load"))
app->startModule(s);
app->emitEvent(new Archimedes::DoLoadModuleEvent(s));
ImGui::SameLine();
if(ImGui::Button("unload"))
app->stopModule(s);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(s));
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();

View File

@@ -18,6 +18,9 @@ Ollama::~Ollama() {
curl = nullptr;
}
curl_global_cleanup();
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
}
@@ -36,7 +39,7 @@ void Ollama::onLoad() {
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
ImGui::SetCurrentContext(im->aquireContext());
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
@@ -111,7 +114,7 @@ void Ollama::run() {
if(code != CURLE_OK) {
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
return;
} else {
jsonObj = nlohmann::json::parse(response);

View File

@@ -1,60 +0,0 @@
#include "Archimedes.h"
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
namespace SMEvent {
class DataRecievedEvent : public Archimedes::Event {
public:
DataRecievedEvent() : msg(nullptr) {}
~DataRecievedEvent() {
if(msg)
msg->Release();
}
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
operator std::string() const { return "SMEvent::DataRecievedEvent"; }
ISteamNetworkingMessage* msg;
};
class DataSentEvent : public Archimedes::Event {
public:
DataSentEvent() : msg(nullptr) {}
~DataSentEvent() {
if(msg)
msg->Release();
}
DataSentEvent(ISteamNetworkingMessage* m) : msg(m) {}
operator std::string() const { return "SMEvent::DataSentEvent"; }
ISteamNetworkingMessage* msg;
};
class ConnectionStatusChangedEvent : public Archimedes::Event {
public:
ConnectionStatusChangedEvent() : info(nullptr) {}
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : info(i) {}
operator std::string() const { return "SMEvent::ConnectionStatusChangedEvent"; }
SteamNetConnectionStatusChangedCallback_t* info;
};
}

View File

@@ -6,9 +6,9 @@ ServerModule::ServerModule(Archimedes::App* a, void* h) : Archimedes::Module(a,
ServerModule::~ServerModule() {
if(app) {
app->unregisterEvent(SMEvent::DataRecievedEvent());
app->unregisterEvent(SMEvent::DataSentEvent());
app->unregisterEvent(SMEvent::ConnectionStatusChangedEvent());
app->unregisterEvent(Archimedes::DataRecievedEvent());
app->unregisterEvent(Archimedes::DataSentEvent());
app->unregisterEvent(Archimedes::ConnectionStatusChangedEvent());
GameNetworkingSockets_Kill();
}
@@ -16,9 +16,9 @@ ServerModule::~ServerModule() {
void ServerModule::onLoad() {
app->registerEvent(SMEvent::DataRecievedEvent());
app->registerEvent(SMEvent::DataSentEvent());
app->registerEvent(SMEvent::ConnectionStatusChangedEvent());
app->registerEvent(Archimedes::DataRecievedEvent());
app->registerEvent(Archimedes::DataSentEvent());
app->registerEvent(Archimedes::ConnectionStatusChangedEvent());
SteamDatagramErrMsg errMsg;
@@ -55,6 +55,7 @@ void ServerModule::startServer(int p) {
}
void ServerModule::stopServer() {
disconnectAllClients();
running = false;
}
@@ -79,9 +80,9 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
unsigned int type = app->getEventType(event);
if(eventsToHandle & SMEventEnum::ConnectionStatusChanged && type == app->getEventType(SMEvent::ConnectionStatusChangedEvent())) {
if(eventsToHandle & SMEventEnum::ConnectionStatusChanged && type == app->getEventType(Archimedes::ConnectionStatusChangedEvent())) {
SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event;
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
switch(e.info->m_info.m_eState) {
@@ -145,6 +146,7 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
// and we cannot linger because it's already closed on the other end,
// so we just pass 0's.
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
std::cerr << "Connection Closed.\n";
break;
}
@@ -193,9 +195,9 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
}
return true;
} else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(SMEvent::DataRecievedEvent())) {
} else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(Archimedes::DataRecievedEvent())) {
return true;
} else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(SMEvent::DataSentEvent())) {
} else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(Archimedes::DataSentEvent())) {
return true;
}
@@ -216,6 +218,6 @@ void ServerModule::pollIncomingData() {
auto itClient = clients.find( pIncomingMsg->m_conn );
assert( itClient != clients.end() );
app->emitEvent(new SMEvent::DataRecievedEvent(pIncomingMsg));
app->emitEvent(new Archimedes::DataRecievedEvent(pIncomingMsg));
}
}

View File

@@ -6,7 +6,7 @@
#include <steam/steamnetworkingsockets.h>
#include <steam/isteamnetworkingutils.h>
#include "ServerEvents.h"
#include "utils/Events/NetworkEvents.h"
class ServerModule : public Archimedes::Module {
@@ -39,6 +39,19 @@ class ServerModule : public Archimedes::Module {
}
void disconnectClient(HSteamNetConnection c) {
if(clients.find(c) != clients.end()) {
interface->CloseConnection(c, 0, nullptr, false);
clients.erase(c);
}
}
void disconnectAllClients() {
while(!clients.empty()) {
disconnectClient(clients.begin()->first);
}
}
std::map<HSteamNetConnection, unsigned int> getClients() const { return clients; }
void pollIncomingData();
@@ -63,7 +76,7 @@ class ServerModule : public Archimedes::Module {
}
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
app->emitEvent(new SMEvent::ConnectionStatusChangedEvent(pInfo));
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
}
std::map<HSteamNetConnection, unsigned int> clients;

View File

@@ -17,7 +17,11 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
}
Terminal::~Terminal() {
if(app) {}
if(app) {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
}
void Terminal::onLoad() {
@@ -29,7 +33,7 @@ void Terminal::onLoad() {
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
ImGui::SetCurrentContext(im->aquireContext());
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
@@ -67,7 +71,7 @@ void Terminal::run() {
rc = read(master, opArr, 150);
if(rc < 0) {
//error on read
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
} else {
if(input == "clear") output = "";
output += opArr;

View File

@@ -2,38 +2,93 @@
WindowModule::~WindowModule() {
if(app) {
app->unregisterEvent(Archimedes::ResizeWindowEvent());
app->unregisterEvent(Archimedes::CloseWindowEvent());
app->unregisterEvent(Archimedes::KeyPressedWindowEvent());
app->unregisterEvent(Archimedes::KeyReleasedWindowEvent());
app->unregisterEvent(Archimedes::MouseButtonPressedWindowEvent());
app->unregisterEvent(Archimedes::MouseButtonReleasedWindowEvent());
app->unregisterEvent(Archimedes::ScrollWindowEvent());
app->unregisterEvent(Archimedes::MouseMovedWindowEvent());
app->unregisterEvent(Archimedes::FocusedWindowEvent());
app->unregisterEvent(Archimedes::FocusLostWindowEvent());
app->unregisterEvent(Archimedes::MovedWindowEvent());
if(renderer) {
renderer->getCmdList().clear();
delete renderer;
}
if(window) {
delete window;
}
if(window)
releaseWindow(window);
}
}
void WindowModule::onLoad() {
window = new Archimedes::Window();
app->registerEvent(Archimedes::ResizeWindowEvent());
app->registerEvent(Archimedes::CloseWindowEvent());
app->registerEvent(Archimedes::KeyPressedWindowEvent());
app->registerEvent(Archimedes::KeyReleasedWindowEvent());
app->registerEvent(Archimedes::MouseButtonPressedWindowEvent());
app->registerEvent(Archimedes::MouseButtonReleasedWindowEvent());
app->registerEvent(Archimedes::ScrollWindowEvent());
app->registerEvent(Archimedes::MouseMovedWindowEvent());
app->registerEvent(Archimedes::FocusedWindowEvent());
app->registerEvent(Archimedes::FocusLostWindowEvent());
app->registerEvent(Archimedes::MovedWindowEvent());
renderer = new Archimedes::Renderer();
window->setRenderer(renderer);
//renderer = window->getRenderer();
if(!renderer->init()) {
std::cout << "Renderer init failed!\n";
std::abort();
}
}
void WindowModule::run() {
if(window->shouldClose()) {
app->end();
}
if(window)
window->doFrame();
else
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}
bool WindowModule::onEvent(const Archimedes::Event& e) {
unsigned int type = app->getEventType(e);
if(type == app->getEventType(Archimedes::ResizeWindowEvent())) {
Archimedes::ResizeWindowEvent& event = (Archimedes::ResizeWindowEvent&) e;
renderer->w = event.width;
renderer->h = event.height;
return true;
} else if(type == app->getEventType(Archimedes::CloseWindowEvent())) {
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
return true;
} else if(type == app->getEventType(Archimedes::KeyPressedWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::KeyReleasedWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::ScrollWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::MouseMovedWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::FocusedWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::FocusLostWindowEvent())) {
return true;
} else if(type == app->getEventType(Archimedes::MovedWindowEvent())) {
return true;
}
return false;
}

View File

@@ -15,21 +15,62 @@ class WindowModule : public Archimedes::Module {
WindowModule() { name = "WindowModule"; }
~WindowModule();
~WindowModule() override;
void run();
void run() override;
void onLoad();
void onLoad() override;
bool onEvent(const Archimedes::Event& e) override;
//interface for other modules
Archimedes::Window* getWindow() { return window; }
Archimedes::Window* aquireWindow() {
if(!window) {
window = new Archimedes::Window([this](Archimedes::Event* e) {
for(std::function<void(Archimedes::Event*)> f : eventFuncs)
f(e);
app->emitEvent(e);
});
window->setRenderer(renderer);
if(!renderer->init()) {
std::cout << "Renderer init failed!\n";
std::abort();
}
}
windowRefs++;
window->getWindowImpl().restoreContext();
return window;
}
void releaseWindow(Archimedes::Window* w) {
if(w == window && window != nullptr) {
if(--windowRefs == 0) {
delete window;
window = nullptr;
}
}
}
auto addEventFn(const std::function<void(Archimedes::Event*)>& fn) { eventFuncs.push_back(fn); return --eventFuncs.end()++; }
void removeEventFn(std::list<std::function<void(Archimedes::Event*)>>::iterator it) { eventFuncs.erase(it); }
Archimedes::Renderer* getRenderer() { return renderer; }
private:
Archimedes::Window* window;
Archimedes::Renderer* renderer;
int windowRefs = 0;
std::list<std::function<void(Archimedes::Event*)>> eventFuncs;
Archimedes::Window* window = nullptr;
Archimedes::Renderer* renderer = nullptr;
};

View File

@@ -1,3 +1,8 @@
#include "modules/ImguiModule/src/ImguiModule.h"
#include "modules/ClientModule/src/ClientModule.h"
#include "ChatClient.h"
@@ -12,19 +17,48 @@ ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
ImguiModule* im = new ImguiModule(a, h);
deps[*im] = im;
}
ChatClient::~ChatClient() {
if(app) {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
}
void ChatClient::onLoad() {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) {
std::cout << "No ImguiModule for ChatClient!\n";
std::abort();
}
ImGui::SetCurrentContext(im->aquireContext());
ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
if(!cm) {
std::cout << "No ClientModule for ChatClient!\n";
std::abort();
}
}
void ChatClient::run() {
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
if(!cm) {
std::cout << "No ClientModule for ChatClient!\n";
std::abort();
}
if(open) {
static std::string s, addr;
static std::string s, addr = "127.0.0.1:9932";
ImGui::Begin("ChatClient Module", &open);
@@ -58,7 +92,7 @@ void ChatClient::run() {
ImGui::End();
} else {
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(*cm));
}
}
@@ -66,15 +100,14 @@ bool ChatClient::onEvent(const Archimedes::Event& event) {
unsigned int type = app->getEventType(event);
/*if(type == app->getEventType("DataSentEvent")) {
//we did this?
return true;
} else */
if(type == app->getEventType(CMEvent::DataRecievedEvent())) {
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
CMEvent::DataRecievedEvent& e = (CMEvent::DataRecievedEvent&) event;
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
@@ -86,7 +119,7 @@ bool ChatClient::onEvent(const Archimedes::Event& event) {
}
/*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
//CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event;
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
return false;

View File

@@ -1,8 +1,5 @@
#include "Archimedes.h"
#include "modules/ClientModule/src/ClientModule.h"
#include "modules/ImguiModule/src/ImguiModule.h"
class ChatClient : public Archimedes::Module {
@@ -12,15 +9,13 @@ class ChatClient : public Archimedes::Module {
ChatClient() { name = "ChatClient"; }
~ChatClient() {
if(app) {}
}
~ChatClient();
void onLoad();
void onLoad() override;
void run();
void run() override;
bool onEvent(const Archimedes::Event&);
bool onEvent(const Archimedes::Event&) override;
private:
std::string messages = "";

View File

@@ -18,14 +18,21 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
return true;
} else */
if(type == app->getEventType(SMEvent::DataRecievedEvent())) {
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
SMEvent::DataRecievedEvent& e = (SMEvent::DataRecievedEvent&) event;
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
if(s == "/quit") {
sm->disconnectClient(e.msg->m_conn);
} else if(s == "/shutdown") {
sm->stopServer();
app->end();
}
std::cerr << "Server Recieved: " << s << std::endl;
for(auto& it : sm->getClients()) {
@@ -39,7 +46,7 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
//SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event;
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
return false;

View File

@@ -12,5 +12,5 @@ DependsOnPrint::~DependsOnPrint() {
void DependsOnPrint::run() {
std::cout << "DependsOnPrint lib loaded and run!\n";
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}

View File

@@ -15,5 +15,5 @@ DependsOnPrintStatic::~DependsOnPrintStatic() {
void DependsOnPrintStatic::run() {
std::cout << "DependsOnPrintStatic lib loaded and run!\n";
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
}

View File

@@ -11,18 +11,20 @@ TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
TestImgui::~TestImgui() {
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
im->releaseContext(ImGui::GetCurrentContext());
}
void TestImgui::onLoad() {
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
if(!im) {
std::cout << "No ImguiModule for TestImgui!\n";
std::abort();
}
ImGui::SetCurrentContext(im->getContext());
ImGui::SetCurrentContext(im->aquireContext());
}
@@ -30,7 +32,7 @@ void TestImgui::run() {
if(demo)
ImGui::ShowDemoWindow(&this->demo);
else
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
{
ImGuiIO& io = ImGui::GetIO();

View File

@@ -26,7 +26,7 @@ void TestMenu::run() {
num--;
break;
case 3:
app->stopModule(name);
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
break;
case 4:
app->end();

View File

@@ -7,7 +7,9 @@ class ImguiEmbed : public Archimedes::App {
private:
void printHelp() {};
void printHelp() override {};
bool onEvent(const Archimedes::Event&) override;
public:
ImguiEmbed() {
@@ -17,9 +19,9 @@ class ImguiEmbed : public Archimedes::App {
};
~ImguiEmbed() {};
void handleArgs(const int& argc, char* argv[]) {};
void handleArgs(const int& argc, char* argv[]) override {};
void run();
void run() override;
};

View File

@@ -36,3 +36,36 @@ void MinimalApp::run() {
}
}
bool MinimalApp::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;
}

View File

@@ -5,16 +5,18 @@ class MinimalApp : public Archimedes::App {
private:
void printHelp() {};
void printHelp() override {};
bool onEvent(const Archimedes::Event&) override;
public:
MinimalApp() {};
~MinimalApp() {};
void handleArgs(const int& argc, char* argv[]) {
void handleArgs(const int& argc, char* argv[]) override {
if(argc > 1) {
for(int i = 1; i < argc; i++) {
load(dynamicLoad(argv[i]));
load(argv[i]);
}
} else {
std::cout << "No modules to load\n";
@@ -22,7 +24,7 @@ class MinimalApp : public Archimedes::App {
}
};
void run();
void run() override;
};

View File

@@ -7,7 +7,9 @@ class TerminalEmbed : public Archimedes::App {
private:
void printHelp() {};
void printHelp() override {};
bool onEvent(const Archimedes::Event&) override;
public:
TerminalEmbed() {
@@ -17,9 +19,9 @@ class TerminalEmbed : public Archimedes::App {
};
~TerminalEmbed() {};
void handleArgs(const int& argc, char* argv[]) {};
void handleArgs(const int& argc, char* argv[]) override {};
void run();
void run() override;
};