Compare commits
24 Commits
9147787fd2
...
b8654659c7
| Author | SHA1 | Date | |
|---|---|---|---|
| b8654659c7 | |||
| 7b4f8e5579 | |||
| f35c58d3d6 | |||
| c2da1944d8 | |||
| 2820387851 | |||
| 853881e5e8 | |||
| 6f4b9b68fd | |||
| ff2a3337b4 | |||
| 83b98db914 | |||
| 047684c51b | |||
| 73ce460446 | |||
| 1a098daf9d | |||
| 2ef95d6e90 | |||
| 74b82845b5 | |||
| 6f322cadb8 | |||
| b4ac013f18 | |||
| a3fb96abb7 | |||
| 8dd0710786 | |||
| 8f528c7f95 | |||
| d253ebb197 | |||
| c6fa731df0 | |||
| a39f43e439 | |||
| 87afa3a0ec | |||
| 600d0f3c81 |
63
flake.nix
63
flake.nix
@@ -111,8 +111,8 @@
|
|||||||
modules/WindowModule/src/*.cpp \
|
modules/WindowModule/src/*.cpp \
|
||||||
-fpic -shared \
|
-fpic -shared \
|
||||||
-I src -I include \
|
-I src -I include \
|
||||||
-DRENDERER_OPENGL \
|
-DRENDERER=1 \
|
||||||
-DWINDOW_GLFW \
|
-DWINDOW=1 \
|
||||||
-DWINDOWMODULE_DYNAMIC \
|
-DWINDOWMODULE_DYNAMIC \
|
||||||
-lGL -lglfw -lGLEW \
|
-lGL -lglfw -lGLEW \
|
||||||
-Wall \
|
-Wall \
|
||||||
@@ -151,8 +151,8 @@
|
|||||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||||
$imgui/misc/cpp/*.cpp \
|
$imgui/misc/cpp/*.cpp \
|
||||||
$imgui/*.cpp \
|
$imgui/*.cpp \
|
||||||
-DRENDERER_OPENGL \
|
-DRENDERER=1 \
|
||||||
-DWINDOW_GLFW \
|
-DWINDOW=1 \
|
||||||
-DIMGUIMODULE_DYNAMIC \
|
-DIMGUIMODULE_DYNAMIC \
|
||||||
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
|
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
|
||||||
-fpic -shared \
|
-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 {
|
MainGUI = pkgs.stdenvNoCC.mkDerivation {
|
||||||
|
|
||||||
@@ -195,8 +238,8 @@
|
|||||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||||
$imgui/misc/cpp/*.cpp \
|
$imgui/misc/cpp/*.cpp \
|
||||||
$imgui/*.cpp \
|
$imgui/*.cpp \
|
||||||
-DRENDERER_OPENGL \
|
-DRENDERER=1 \
|
||||||
-DWINDOW_GLFW \
|
-DWINDOW=1 \
|
||||||
-DMAINGUI_DYNAMIC \
|
-DMAINGUI_DYNAMIC \
|
||||||
-fpic -shared \
|
-fpic -shared \
|
||||||
-I src -I include -I $imgui -I . \
|
-I src -I include -I $imgui -I . \
|
||||||
@@ -238,8 +281,8 @@
|
|||||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||||
$imgui/misc/cpp/*.cpp \
|
$imgui/misc/cpp/*.cpp \
|
||||||
$imgui/*.cpp \
|
$imgui/*.cpp \
|
||||||
-DRENDERER_OPENGL \
|
-DRENDERER=1 \
|
||||||
-DWINDOW_GLFW \
|
-DWINDOW=1 \
|
||||||
-DTERMINAL_DYNAMIC \
|
-DTERMINAL_DYNAMIC \
|
||||||
-fpic -shared \
|
-fpic -shared \
|
||||||
-I src -I include -I $imgui -I . \
|
-I src -I include -I $imgui -I . \
|
||||||
@@ -284,8 +327,8 @@
|
|||||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||||
$imgui/misc/cpp/*.cpp \
|
$imgui/misc/cpp/*.cpp \
|
||||||
$imgui/*.cpp \
|
$imgui/*.cpp \
|
||||||
-DRENDERER_OPENGL \
|
-DRENDERER=1 \
|
||||||
-DWINDOW_GLFW \
|
-DWINDOW=1 \
|
||||||
-DOLLAMA_DYNAMIC \
|
-DOLLAMA_DYNAMIC \
|
||||||
-fpic -shared \
|
-fpic -shared \
|
||||||
-I src -I include -I $imgui -I . \
|
-I src -I include -I $imgui -I . \
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <any>
|
||||||
|
#include <typeinfo>
|
||||||
#include <future>
|
#include <future>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|||||||
@@ -17,10 +17,26 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
instance = this;
|
instance = this;
|
||||||
roInsert = runOrder.begin();
|
roInsert = runOrder.begin();
|
||||||
|
|
||||||
|
registerEvent(AnonymousEvent());
|
||||||
|
|
||||||
|
registerEvent(DoLoadModuleEvent());
|
||||||
|
registerEvent(DoUnloadModuleEvent());
|
||||||
|
|
||||||
|
registerEvent(LoadModuleEvent());
|
||||||
|
registerEvent(UnloadModuleEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~App() {
|
virtual ~App() {
|
||||||
|
|
||||||
|
unregisterEvent(AnonymousEvent());
|
||||||
|
|
||||||
|
unregisterEvent(DoLoadModuleEvent());
|
||||||
|
unregisterEvent(DoUnloadModuleEvent());
|
||||||
|
|
||||||
|
unregisterEvent(LoadModuleEvent());
|
||||||
|
unregisterEvent(UnloadModuleEvent());
|
||||||
|
|
||||||
for(std::string s : runOrder) {
|
for(std::string s : runOrder) {
|
||||||
void* handle = modules[s]->getHandle();
|
void* handle = modules[s]->getHandle();
|
||||||
delete modules[s];
|
delete modules[s];
|
||||||
@@ -40,17 +56,6 @@ namespace Archimedes {
|
|||||||
|
|
||||||
virtual void run() = 0;
|
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; }
|
void end() { done = true; }
|
||||||
|
|
||||||
@@ -94,16 +99,48 @@ namespace Archimedes {
|
|||||||
std::list<std::string> toClose;
|
std::list<std::string> toClose;
|
||||||
std::list<std::variant<std::string, Module*>> toOpen;
|
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() {
|
void handleEvents() {
|
||||||
|
static bool handled;
|
||||||
|
|
||||||
while(!events.empty()) {
|
while(!events.empty()) {
|
||||||
|
|
||||||
|
handled = false;
|
||||||
|
|
||||||
for(auto it = runOrder.rbegin(); it != runOrder.rend(); it++) {
|
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();
|
Event* e = events.front();
|
||||||
events.pop_front();
|
events.pop_front();
|
||||||
delete e;
|
delete e;
|
||||||
break;
|
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);
|
return create(Get(), h);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Module* load(std::string modulePath) {
|
virtual Module* reload(std::string lib) {
|
||||||
Module* m = dynamicLoad(modulePath);
|
|
||||||
|
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);
|
return load(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,10 +195,11 @@ namespace Archimedes {
|
|||||||
if(h) {
|
if(h) {
|
||||||
dlclose(h);
|
dlclose(h);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return modules[*it];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(modules.find(*m) == modules.end())
|
||||||
modules[*m] = m;
|
modules[*m] = m;
|
||||||
|
|
||||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||||
@@ -189,13 +239,13 @@ namespace Archimedes {
|
|||||||
|
|
||||||
runOrder.insert(roInsert, *m);
|
runOrder.insert(roInsert, *m);
|
||||||
|
|
||||||
|
emitEvent(new LoadModuleEvent(*m));
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void unload(std::string name) {
|
virtual void unload(std::string name) {
|
||||||
|
|
||||||
std::cout << "Attempting to unload module: " << name << std::endl;
|
|
||||||
|
|
||||||
if(modules.find(name) == modules.end())
|
if(modules.find(name) == modules.end())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -223,7 +273,7 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Successfully unloaded module: " << name << std::endl;
|
emitEvent(new UnloadModuleEvent(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void printHelp() = 0;
|
virtual void printHelp() = 0;
|
||||||
|
|||||||
88
include/utils/Events/BasicEvents.h
Normal file
88
include/utils/Events/BasicEvents.h
Normal 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
|
||||||
@@ -9,11 +9,17 @@ namespace Archimedes {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Event() {}
|
||||||
|
Event(std::any data) : userData(data) {}
|
||||||
|
|
||||||
virtual ~Event() {}
|
virtual ~Event() {}
|
||||||
|
|
||||||
virtual operator std::string() const = 0;
|
virtual operator std::string() const = 0;
|
||||||
|
|
||||||
|
std::any userData;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "BasicEvents.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
59
include/utils/Events/NetworkEvents.h
Normal file
59
include/utils/Events/NetworkEvents.h
Normal 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
|
||||||
@@ -25,13 +25,13 @@ namespace Archimedes {
|
|||||||
|
|
||||||
virtual void run() {}
|
virtual void run() {}
|
||||||
virtual bool onEvent(const Event& e) { return false; }
|
virtual bool onEvent(const Event& e) { return false; }
|
||||||
virtual void onLoad() {};
|
|
||||||
|
virtual void onLoad() {}
|
||||||
|
virtual void onUnload() {}
|
||||||
|
|
||||||
operator std::string() const { return name; }
|
operator std::string() const { return name; }
|
||||||
void* getHandle() { return handle; }
|
void* getHandle() { return handle; }
|
||||||
|
|
||||||
//std::any getData(std::string s) { return data[s.c_str()]; };
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string name;
|
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, std::variant<std::string, Module*>> exts;
|
||||||
std::unordered_map<std::string, Module*> moduleInstances;
|
std::unordered_map<std::string, Module*> moduleInstances;
|
||||||
|
|
||||||
//std::unordered_map<std::string, std::any> data;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#ifdef RENDERER_OPENGL
|
#if RENDERER == 1
|
||||||
#undef RENDERER_OPENGL
|
|
||||||
|
#ifndef RENDERER_OPENGL
|
||||||
|
#define RENDERER_OPENGL
|
||||||
|
|
||||||
#include "pch.hpp"
|
#include "pch.hpp"
|
||||||
|
|
||||||
@@ -38,3 +40,5 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#ifndef WINDOW_H
|
#ifndef WINDOW_H
|
||||||
#define WINDOW_H
|
#define WINDOW_H
|
||||||
|
|
||||||
|
#include "WindowEvents.h"
|
||||||
|
|
||||||
#include "utils/Renderer/Renderer.h"
|
#include "utils/Renderer/Renderer.h"
|
||||||
#include "WindowGLFW/WindowGLFW.h"
|
#include "WindowGLFW/WindowGLFW.h"
|
||||||
|
#include "WindowSDL3/WindowSDL3.h"
|
||||||
|
|
||||||
namespace Archimedes {
|
namespace Archimedes {
|
||||||
|
|
||||||
@@ -11,18 +13,20 @@ namespace Archimedes {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Window() {}
|
Window(const std::function<void(Event*)>& sendEventFn) : window(this, sendEventFn) {}
|
||||||
|
|
||||||
~Window() {}
|
~Window() {}
|
||||||
|
|
||||||
bool shouldClose() { return window.shouldClose(); }
|
bool shouldClose() { return window.shouldClose(); }
|
||||||
|
|
||||||
|
void getSize(int& w, int& h) {
|
||||||
|
window.getSize(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
void doFrame() {
|
void doFrame() {
|
||||||
|
|
||||||
window.pollEvents();
|
window.pollEvents();
|
||||||
|
|
||||||
window.getSize(renderer->w, renderer->h);
|
|
||||||
|
|
||||||
renderer->render();
|
renderer->render();
|
||||||
|
|
||||||
window.doFrame();
|
window.doFrame();
|
||||||
|
|||||||
220
include/utils/Window/WindowEvents.h
Normal file
220
include/utils/Window/WindowEvents.h
Normal 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
|
||||||
@@ -1,18 +1,27 @@
|
|||||||
|
#if WINDOW == 1
|
||||||
|
|
||||||
|
#ifndef WINDOW_GLFW
|
||||||
|
#define WINDOW_GLFW
|
||||||
|
|
||||||
#include "pch.hpp"
|
#include "pch.hpp"
|
||||||
|
|
||||||
#ifdef WINDOW_GLFW
|
#include "utils/Window/WindowEvents.h"
|
||||||
#undef WINDOW_GLFW
|
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
|
||||||
namespace Archimedes {
|
namespace Archimedes {
|
||||||
|
|
||||||
|
class Window;
|
||||||
|
|
||||||
class WindowGLFW {
|
class WindowGLFW {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WindowGLFW() {
|
WindowGLFW(Window* p, const std::function<void(Event*)>& sendEvent) {
|
||||||
|
|
||||||
|
data.window = p;
|
||||||
|
data.sendEvent = sendEvent;
|
||||||
|
|
||||||
glfwSetErrorCallback([](int e, const char* m){
|
glfwSetErrorCallback([](int e, const char* m){
|
||||||
std::cout << "GLFW Error: " << m << std::endl;
|
std::cout << "GLFW Error: " << m << std::endl;
|
||||||
@@ -31,6 +40,60 @@ namespace Archimedes {
|
|||||||
glfwMakeContextCurrent(w);
|
glfwMakeContextCurrent(w);
|
||||||
glfwSwapInterval(1);
|
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() {
|
~WindowGLFW() {
|
||||||
@@ -54,8 +117,11 @@ namespace Archimedes {
|
|||||||
|
|
||||||
GLFWwindow* getWindow() { return w; }
|
GLFWwindow* getWindow() { return w; }
|
||||||
|
|
||||||
|
WindowData data;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* w;
|
GLFWwindow* w;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef WindowGLFW WindowImpl;
|
typedef WindowGLFW WindowImpl;
|
||||||
@@ -63,3 +129,5 @@ namespace Archimedes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
187
include/utils/Window/WindowSDL3/WindowSDL3.h
Normal file
187
include/utils/Window/WindowSDL3/WindowSDL3.h
Normal 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
|
||||||
@@ -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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,9 +6,9 @@ ClientModule::ClientModule(Archimedes::App* a, void* h) : Archimedes::Module(a,
|
|||||||
|
|
||||||
ClientModule::~ClientModule() {
|
ClientModule::~ClientModule() {
|
||||||
if(app) {
|
if(app) {
|
||||||
app->unregisterEvent(CMEvent::DataRecievedEvent());
|
app->unregisterEvent(Archimedes::DataRecievedEvent());
|
||||||
app->unregisterEvent(CMEvent::DataSentEvent());
|
app->unregisterEvent(Archimedes::DataSentEvent());
|
||||||
app->unregisterEvent(CMEvent::ConnectionStatusChangedEvent());
|
app->unregisterEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||||
|
|
||||||
GameNetworkingSockets_Kill();
|
GameNetworkingSockets_Kill();
|
||||||
}
|
}
|
||||||
@@ -16,9 +16,9 @@ ClientModule::~ClientModule() {
|
|||||||
|
|
||||||
void ClientModule::onLoad() {
|
void ClientModule::onLoad() {
|
||||||
|
|
||||||
app->registerEvent(CMEvent::DataSentEvent());
|
app->registerEvent(Archimedes::DataSentEvent());
|
||||||
app->registerEvent(CMEvent::DataRecievedEvent());
|
app->registerEvent(Archimedes::DataRecievedEvent());
|
||||||
app->registerEvent(CMEvent::ConnectionStatusChangedEvent());
|
app->registerEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||||
|
|
||||||
SteamDatagramErrMsg errMsg;
|
SteamDatagramErrMsg errMsg;
|
||||||
if ( !GameNetworkingSockets_Init( nullptr, errMsg ) ) {
|
if ( !GameNetworkingSockets_Init( nullptr, errMsg ) ) {
|
||||||
@@ -62,9 +62,9 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
|
|||||||
|
|
||||||
unsigned int type = app->getEventType(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) {
|
switch(e.info->m_info.m_eState) {
|
||||||
|
|
||||||
@@ -96,6 +96,7 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
|
|||||||
// OnDisconnect
|
// OnDisconnect
|
||||||
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
|
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
|
||||||
connection = k_HSteamNetConnection_Invalid;
|
connection = k_HSteamNetConnection_Invalid;
|
||||||
|
stopClient();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,9 +115,9 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(CMEvent::DataRecievedEvent())) {
|
} else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||||
return true;
|
return true;
|
||||||
} else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(CMEvent::DataSentEvent())) {
|
} else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(Archimedes::DataSentEvent())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +126,7 @@ bool ClientModule::onEvent(const Archimedes::Event& event) {
|
|||||||
|
|
||||||
void ClientModule::pollIncomingData() {
|
void ClientModule::pollIncomingData() {
|
||||||
|
|
||||||
while(running) {
|
while(running && connection != k_HSteamNetConnection_Invalid) {
|
||||||
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
||||||
int numMsgs = interface->ReceiveMessagesOnConnection( connection, &pIncomingMsg, 1 );
|
int numMsgs = interface->ReceiveMessagesOnConnection( connection, &pIncomingMsg, 1 );
|
||||||
if ( numMsgs == 0 )
|
if ( numMsgs == 0 )
|
||||||
@@ -135,6 +136,6 @@ void ClientModule::pollIncomingData() {
|
|||||||
assert( numMsgs == 1 && pIncomingMsg );
|
assert( numMsgs == 1 && pIncomingMsg );
|
||||||
assert( pIncomingMsg->m_conn == connection );
|
assert( pIncomingMsg->m_conn == connection );
|
||||||
|
|
||||||
app->emitEvent(new CMEvent::DataRecievedEvent(pIncomingMsg));
|
app->emitEvent(new Archimedes::DataRecievedEvent(pIncomingMsg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <steam/steamnetworkingsockets.h>
|
#include <steam/steamnetworkingsockets.h>
|
||||||
#include <steam/isteamnetworkingutils.h>
|
#include <steam/isteamnetworkingutils.h>
|
||||||
|
|
||||||
#include "ClientEvents.h"
|
#include "utils/Events/NetworkEvents.h"
|
||||||
|
|
||||||
class ClientModule : public Archimedes::Module {
|
class ClientModule : public Archimedes::Module {
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ class ClientModule : public Archimedes::Module {
|
|||||||
|
|
||||||
void sendReliable(const void* data, uint32 byteCount) {
|
void sendReliable(const void* data, uint32 byteCount) {
|
||||||
interface->SendMessageToConnection(connection, data, byteCount, k_nSteamNetworkingSend_Reliable, nullptr);
|
interface->SendMessageToConnection(connection, data, byteCount, k_nSteamNetworkingSend_Reliable, nullptr);
|
||||||
|
app->emitEvent(new Archimedes::DataSentEvent(data, byteCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isRunning() const { return running; }
|
bool isRunning() const { return running; }
|
||||||
@@ -58,7 +58,7 @@ class ClientModule : public Archimedes::Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||||
app->emitEvent(new CMEvent::ConnectionStatusChangedEvent(pInfo));
|
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PollConnectionStateChanges() {
|
void PollConnectionStateChanges() {
|
||||||
|
|||||||
@@ -1,12 +1,5 @@
|
|||||||
#include "ImguiModule.h"
|
#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"
|
#include "pch.hpp"
|
||||||
|
|
||||||
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
|
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
|
||||||
@@ -24,9 +17,15 @@ ImguiModule::~ImguiModule() {
|
|||||||
|
|
||||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
#if WINDOW == 2
|
||||||
ImGui_ImplGlfw_Shutdown();
|
wm->removeEventFn(ecmd_it);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rendererShutdown();
|
||||||
|
windowShutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
wm->releaseWindow(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +38,8 @@ void ImguiModule::onLoad() {
|
|||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window = wm->aquireWindow();
|
||||||
|
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
context = ImGui::CreateContext();
|
context = ImGui::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
@@ -56,27 +57,61 @@ void ImguiModule::onLoad() {
|
|||||||
//ImGui::StyleColorsLight();
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
// Setup Platform/Renderer backends
|
||||||
if(!ImGui_ImplGlfw_InitForOpenGL(wm->getWindow()->getWindowImpl().getWindow(), true))
|
if(!windowInit())
|
||||||
std::cout << "GLFWImpl failed\n";
|
std::cout << "windowInit failed\n";
|
||||||
if(!ImGui_ImplOpenGL3_Init("#version 330")) {
|
|
||||||
std::cout << "ImGui_ImplOpenGL3_Init failed!\n" << std::endl;
|
if(!rendererInit()) {
|
||||||
|
std::cout << "rendererInit failed!\n" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wm->getRenderer()->getCmdList().push_back([this](){
|
||||||
wm->getRenderer()->getCmdList().push_back([](){
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
rendererRenderDrawData();
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
rendererNewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
windowNewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
});
|
});
|
||||||
|
|
||||||
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
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()
|
//Compute first frame ahead of first WindowModule->run()
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
rendererNewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
windowNewFrame();
|
||||||
ImGui::NewFrame();
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,29 @@
|
|||||||
#ifndef GUIMODULE
|
|
||||||
#define GUIMODULE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "misc/cpp/imgui_stdlib.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 {
|
class ImguiModule : public Archimedes::Module {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -16,20 +33,68 @@ class ImguiModule : public Archimedes::Module {
|
|||||||
|
|
||||||
~ImguiModule();
|
~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:
|
private:
|
||||||
|
|
||||||
|
int contextRefs = 0;
|
||||||
|
|
||||||
ImGuiContext* context;
|
ImGuiContext* context;
|
||||||
|
|
||||||
|
Archimedes::Window* window;
|
||||||
|
|
||||||
std::list<std::function<void()>>::iterator rcmd_it;
|
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
|
#ifdef IMGUIMODULE_DYNAMIC
|
||||||
#define MODULE_TYPE ImguiModule
|
#define MODULE_TYPE ImguiModule
|
||||||
#include "endModule.h"
|
#include "endModule.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
|||||||
|
|
||||||
MainGUI::~MainGUI() {
|
MainGUI::~MainGUI() {
|
||||||
|
|
||||||
if(app) {}
|
if(app) {
|
||||||
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||||
|
im->releaseContext(ImGui::GetCurrentContext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainGUI::onLoad() {
|
void MainGUI::onLoad() {
|
||||||
@@ -24,7 +27,7 @@ void MainGUI::onLoad() {
|
|||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCurrentContext(im->getContext());
|
ImGui::SetCurrentContext(im->aquireContext());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,12 +47,12 @@ void MainGUI::run() {
|
|||||||
ImGui::InputText("module: ", &s);
|
ImGui::InputText("module: ", &s);
|
||||||
|
|
||||||
if(ImGui::Button("load"))
|
if(ImGui::Button("load"))
|
||||||
app->startModule(s);
|
app->emitEvent(new Archimedes::DoLoadModuleEvent(s));
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
if(ImGui::Button("unload"))
|
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::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ Ollama::~Ollama() {
|
|||||||
curl = nullptr;
|
curl = nullptr;
|
||||||
}
|
}
|
||||||
curl_global_cleanup();
|
curl_global_cleanup();
|
||||||
|
|
||||||
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||||
|
im->releaseContext(ImGui::GetCurrentContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +39,7 @@ void Ollama::onLoad() {
|
|||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCurrentContext(im->getContext());
|
ImGui::SetCurrentContext(im->aquireContext());
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
@@ -111,7 +114,7 @@ void Ollama::run() {
|
|||||||
|
|
||||||
if(code != CURLE_OK) {
|
if(code != CURLE_OK) {
|
||||||
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
|
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
|
||||||
app->stopModule(name);
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
jsonObj = nlohmann::json::parse(response);
|
jsonObj = nlohmann::json::parse(response);
|
||||||
|
|||||||
@@ -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;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,9 +6,9 @@ ServerModule::ServerModule(Archimedes::App* a, void* h) : Archimedes::Module(a,
|
|||||||
|
|
||||||
ServerModule::~ServerModule() {
|
ServerModule::~ServerModule() {
|
||||||
if(app) {
|
if(app) {
|
||||||
app->unregisterEvent(SMEvent::DataRecievedEvent());
|
app->unregisterEvent(Archimedes::DataRecievedEvent());
|
||||||
app->unregisterEvent(SMEvent::DataSentEvent());
|
app->unregisterEvent(Archimedes::DataSentEvent());
|
||||||
app->unregisterEvent(SMEvent::ConnectionStatusChangedEvent());
|
app->unregisterEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||||
|
|
||||||
GameNetworkingSockets_Kill();
|
GameNetworkingSockets_Kill();
|
||||||
}
|
}
|
||||||
@@ -16,9 +16,9 @@ ServerModule::~ServerModule() {
|
|||||||
|
|
||||||
void ServerModule::onLoad() {
|
void ServerModule::onLoad() {
|
||||||
|
|
||||||
app->registerEvent(SMEvent::DataRecievedEvent());
|
app->registerEvent(Archimedes::DataRecievedEvent());
|
||||||
app->registerEvent(SMEvent::DataSentEvent());
|
app->registerEvent(Archimedes::DataSentEvent());
|
||||||
app->registerEvent(SMEvent::ConnectionStatusChangedEvent());
|
app->registerEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||||
|
|
||||||
SteamDatagramErrMsg errMsg;
|
SteamDatagramErrMsg errMsg;
|
||||||
|
|
||||||
@@ -55,6 +55,7 @@ void ServerModule::startServer(int p) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ServerModule::stopServer() {
|
void ServerModule::stopServer() {
|
||||||
|
disconnectAllClients();
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,9 +80,9 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
|
|||||||
|
|
||||||
unsigned int type = app->getEventType(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) {
|
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,
|
// and we cannot linger because it's already closed on the other end,
|
||||||
// so we just pass 0's.
|
// so we just pass 0's.
|
||||||
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
|
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
|
||||||
|
std::cerr << "Connection Closed.\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,9 +195,9 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(SMEvent::DataRecievedEvent())) {
|
} else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||||
return true;
|
return true;
|
||||||
} else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(SMEvent::DataSentEvent())) {
|
} else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(Archimedes::DataSentEvent())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +218,6 @@ void ServerModule::pollIncomingData() {
|
|||||||
auto itClient = clients.find( pIncomingMsg->m_conn );
|
auto itClient = clients.find( pIncomingMsg->m_conn );
|
||||||
assert( itClient != clients.end() );
|
assert( itClient != clients.end() );
|
||||||
|
|
||||||
app->emitEvent(new SMEvent::DataRecievedEvent(pIncomingMsg));
|
app->emitEvent(new Archimedes::DataRecievedEvent(pIncomingMsg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <steam/steamnetworkingsockets.h>
|
#include <steam/steamnetworkingsockets.h>
|
||||||
#include <steam/isteamnetworkingutils.h>
|
#include <steam/isteamnetworkingutils.h>
|
||||||
|
|
||||||
#include "ServerEvents.h"
|
#include "utils/Events/NetworkEvents.h"
|
||||||
|
|
||||||
class ServerModule : public Archimedes::Module {
|
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; }
|
std::map<HSteamNetConnection, unsigned int> getClients() const { return clients; }
|
||||||
|
|
||||||
void pollIncomingData();
|
void pollIncomingData();
|
||||||
@@ -63,7 +76,7 @@ class ServerModule : public Archimedes::Module {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||||
app->emitEvent(new SMEvent::ConnectionStatusChangedEvent(pInfo));
|
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<HSteamNetConnection, unsigned int> clients;
|
std::map<HSteamNetConnection, unsigned int> clients;
|
||||||
|
|||||||
@@ -17,7 +17,11 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Terminal::~Terminal() {
|
Terminal::~Terminal() {
|
||||||
if(app) {}
|
if(app) {
|
||||||
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||||
|
|
||||||
|
im->releaseContext(ImGui::GetCurrentContext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::onLoad() {
|
void Terminal::onLoad() {
|
||||||
@@ -29,7 +33,7 @@ void Terminal::onLoad() {
|
|||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCurrentContext(im->getContext());
|
ImGui::SetCurrentContext(im->aquireContext());
|
||||||
|
|
||||||
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
|
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
@@ -67,7 +71,7 @@ void Terminal::run() {
|
|||||||
rc = read(master, opArr, 150);
|
rc = read(master, opArr, 150);
|
||||||
if(rc < 0) {
|
if(rc < 0) {
|
||||||
//error on read
|
//error on read
|
||||||
app->stopModule(name);
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
} else {
|
} else {
|
||||||
if(input == "clear") output = "";
|
if(input == "clear") output = "";
|
||||||
output += opArr;
|
output += opArr;
|
||||||
|
|||||||
@@ -2,38 +2,93 @@
|
|||||||
|
|
||||||
WindowModule::~WindowModule() {
|
WindowModule::~WindowModule() {
|
||||||
if(app) {
|
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) {
|
if(renderer) {
|
||||||
renderer->getCmdList().clear();
|
renderer->getCmdList().clear();
|
||||||
delete renderer;
|
delete renderer;
|
||||||
}
|
}
|
||||||
if(window) {
|
|
||||||
delete window;
|
if(window)
|
||||||
}
|
releaseWindow(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowModule::onLoad() {
|
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();
|
renderer = new Archimedes::Renderer();
|
||||||
|
|
||||||
window->setRenderer(renderer);
|
|
||||||
|
|
||||||
//renderer = window->getRenderer();
|
|
||||||
|
|
||||||
if(!renderer->init()) {
|
|
||||||
std::cout << "Renderer init failed!\n";
|
|
||||||
std::abort();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowModule::run() {
|
void WindowModule::run() {
|
||||||
|
|
||||||
if(window->shouldClose()) {
|
if(window)
|
||||||
app->end();
|
|
||||||
}
|
|
||||||
|
|
||||||
window->doFrame();
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,21 +15,62 @@ class WindowModule : public Archimedes::Module {
|
|||||||
|
|
||||||
WindowModule() { name = "WindowModule"; }
|
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
|
//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; }
|
Archimedes::Renderer* getRenderer() { return renderer; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Archimedes::Window* window;
|
int windowRefs = 0;
|
||||||
Archimedes::Renderer* renderer;
|
|
||||||
|
std::list<std::function<void(Archimedes::Event*)>> eventFuncs;
|
||||||
|
|
||||||
|
Archimedes::Window* window = nullptr;
|
||||||
|
Archimedes::Renderer* renderer = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,8 @@
|
|||||||
|
|
||||||
|
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||||
|
|
||||||
|
#include "modules/ClientModule/src/ClientModule.h"
|
||||||
|
|
||||||
#include "ChatClient.h"
|
#include "ChatClient.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -12,19 +17,48 @@ ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
|
|||||||
ImguiModule* im = new ImguiModule(a, h);
|
ImguiModule* im = new ImguiModule(a, h);
|
||||||
|
|
||||||
deps[*im] = im;
|
deps[*im] = im;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatClient::~ChatClient() {
|
||||||
|
if(app) {
|
||||||
|
|
||||||
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||||
|
|
||||||
|
im->releaseContext(ImGui::GetCurrentContext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatClient::onLoad() {
|
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() {
|
void ChatClient::run() {
|
||||||
|
|
||||||
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||||
|
|
||||||
|
if(!cm) {
|
||||||
|
std::cout << "No ClientModule for ChatClient!\n";
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
|
|
||||||
if(open) {
|
if(open) {
|
||||||
static std::string s, addr;
|
static std::string s, addr = "127.0.0.1:9932";
|
||||||
|
|
||||||
ImGui::Begin("ChatClient Module", &open);
|
ImGui::Begin("ChatClient Module", &open);
|
||||||
|
|
||||||
@@ -58,7 +92,7 @@ void ChatClient::run() {
|
|||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
} else {
|
} 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);
|
unsigned int type = app->getEventType(event);
|
||||||
|
|
||||||
|
|
||||||
/*if(type == app->getEventType("DataSentEvent")) {
|
/*if(type == app->getEventType("DataSentEvent")) {
|
||||||
//we did this?
|
//we did this?
|
||||||
return true;
|
return true;
|
||||||
} else */
|
} 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);
|
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")) {
|
/*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||||
|
|
||||||
//CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event;
|
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#include "Archimedes.h"
|
#include "Archimedes.h"
|
||||||
|
|
||||||
#include "modules/ClientModule/src/ClientModule.h"
|
|
||||||
|
|
||||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
|
||||||
|
|
||||||
class ChatClient : public Archimedes::Module {
|
class ChatClient : public Archimedes::Module {
|
||||||
|
|
||||||
@@ -12,15 +9,13 @@ class ChatClient : public Archimedes::Module {
|
|||||||
|
|
||||||
ChatClient() { name = "ChatClient"; }
|
ChatClient() { name = "ChatClient"; }
|
||||||
|
|
||||||
~ChatClient() {
|
~ChatClient();
|
||||||
if(app) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
void onLoad();
|
void onLoad() override;
|
||||||
|
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
bool onEvent(const Archimedes::Event&);
|
bool onEvent(const Archimedes::Event&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string messages = "";
|
std::string messages = "";
|
||||||
|
|||||||
@@ -18,14 +18,21 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
|
|||||||
return true;
|
return true;
|
||||||
} else */
|
} else */
|
||||||
|
|
||||||
if(type == app->getEventType(SMEvent::DataRecievedEvent())) {
|
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||||
|
|
||||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
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);
|
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;
|
std::cerr << "Server Recieved: " << s << std::endl;
|
||||||
|
|
||||||
for(auto& it : sm->getClients()) {
|
for(auto& it : sm->getClients()) {
|
||||||
@@ -39,7 +46,7 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
|
|||||||
|
|
||||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||||
|
|
||||||
//SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event;
|
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -12,5 +12,5 @@ DependsOnPrint::~DependsOnPrint() {
|
|||||||
|
|
||||||
void DependsOnPrint::run() {
|
void DependsOnPrint::run() {
|
||||||
std::cout << "DependsOnPrint lib loaded and run!\n";
|
std::cout << "DependsOnPrint lib loaded and run!\n";
|
||||||
app->stopModule(name);
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,5 +15,5 @@ DependsOnPrintStatic::~DependsOnPrintStatic() {
|
|||||||
|
|
||||||
void DependsOnPrintStatic::run() {
|
void DependsOnPrintStatic::run() {
|
||||||
std::cout << "DependsOnPrintStatic lib loaded and run!\n";
|
std::cout << "DependsOnPrintStatic lib loaded and run!\n";
|
||||||
app->stopModule(name);
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,18 +11,20 @@ TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
|||||||
|
|
||||||
TestImgui::~TestImgui() {
|
TestImgui::~TestImgui() {
|
||||||
|
|
||||||
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||||
|
im->releaseContext(ImGui::GetCurrentContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestImgui::onLoad() {
|
void TestImgui::onLoad() {
|
||||||
|
|
||||||
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
|
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||||
|
|
||||||
if(!im) {
|
if(!im) {
|
||||||
std::cout << "No ImguiModule for TestImgui!\n";
|
std::cout << "No ImguiModule for TestImgui!\n";
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetCurrentContext(im->getContext());
|
ImGui::SetCurrentContext(im->aquireContext());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ void TestImgui::run() {
|
|||||||
if(demo)
|
if(demo)
|
||||||
ImGui::ShowDemoWindow(&this->demo);
|
ImGui::ShowDemoWindow(&this->demo);
|
||||||
else
|
else
|
||||||
app->stopModule(name);
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
|
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void TestMenu::run() {
|
|||||||
num--;
|
num--;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
app->stopModule(name);
|
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
app->end();
|
app->end();
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ class ImguiEmbed : public Archimedes::App {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void printHelp() {};
|
void printHelp() override {};
|
||||||
|
|
||||||
|
bool onEvent(const Archimedes::Event&) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImguiEmbed() {
|
ImguiEmbed() {
|
||||||
@@ -17,9 +19,9 @@ class ImguiEmbed : public Archimedes::App {
|
|||||||
};
|
};
|
||||||
~ImguiEmbed() {};
|
~ImguiEmbed() {};
|
||||||
|
|
||||||
void handleArgs(const int& argc, char* argv[]) {};
|
void handleArgs(const int& argc, char* argv[]) override {};
|
||||||
|
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,16 +5,18 @@ class MinimalApp : public Archimedes::App {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void printHelp() {};
|
void printHelp() override {};
|
||||||
|
|
||||||
|
bool onEvent(const Archimedes::Event&) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MinimalApp() {};
|
MinimalApp() {};
|
||||||
~MinimalApp() {};
|
~MinimalApp() {};
|
||||||
|
|
||||||
void handleArgs(const int& argc, char* argv[]) {
|
void handleArgs(const int& argc, char* argv[]) override {
|
||||||
if(argc > 1) {
|
if(argc > 1) {
|
||||||
for(int i = 1; i < argc; i++) {
|
for(int i = 1; i < argc; i++) {
|
||||||
load(dynamicLoad(argv[i]));
|
load(argv[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::cout << "No modules to load\n";
|
std::cout << "No modules to load\n";
|
||||||
@@ -22,7 +24,7 @@ class MinimalApp : public Archimedes::App {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ class TerminalEmbed : public Archimedes::App {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void printHelp() {};
|
void printHelp() override {};
|
||||||
|
|
||||||
|
bool onEvent(const Archimedes::Event&) override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TerminalEmbed() {
|
TerminalEmbed() {
|
||||||
@@ -17,9 +19,9 @@ class TerminalEmbed : public Archimedes::App {
|
|||||||
};
|
};
|
||||||
~TerminalEmbed() {};
|
~TerminalEmbed() {};
|
||||||
|
|
||||||
void handleArgs(const int& argc, char* argv[]) {};
|
void handleArgs(const int& argc, char* argv[]) override {};
|
||||||
|
|
||||||
void run();
|
void run() override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user