Compare commits
81 Commits
00ef227128
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c107ce732c | |||
| ad658d914c | |||
| f6ad110880 | |||
| cb5762a3fe | |||
| 45f1d0f69d | |||
| dffca865dc | |||
| 32223cfa05 | |||
| 3196f7b81a | |||
| 08bccb1e70 | |||
| 2e0341a12e | |||
| b4309ab4e9 | |||
| 2350592424 | |||
| 9d63e16032 | |||
| 501649d236 | |||
| e139696d6a | |||
| 79f4a5288f | |||
| 80e0709278 | |||
| 9f1e77cb9e | |||
| d3fe8598cd | |||
| 38e398e367 | |||
| 3a82e9b4ec | |||
| 5319e2309b | |||
| f86eb4ab90 | |||
| bab30c6124 | |||
| 700e422270 | |||
| ec4b85587b | |||
| cb56bd302d | |||
| 0e1bae3123 | |||
| 7e4fad568b | |||
| 37383c3ed7 | |||
| 045f97e9b0 | |||
| eac9abc839 | |||
| cc5efa8424 | |||
| 53695cbc60 | |||
| 101fcf4781 | |||
| 421bf37b75 | |||
| 2182abc714 | |||
| b8fba92ea7 | |||
| 21d07cab07 | |||
| 3198b91ebc | |||
| 62b7618ff4 | |||
| 03213c2c15 | |||
| 0fb63352a2 | |||
| b8654659c7 | |||
| 7b4f8e5579 | |||
| f35c58d3d6 | |||
| c2da1944d8 | |||
| 2820387851 | |||
| 853881e5e8 | |||
| 6f4b9b68fd | |||
| ff2a3337b4 | |||
| 83b98db914 | |||
| 047684c51b | |||
| 73ce460446 | |||
| 1a098daf9d | |||
| 2ef95d6e90 | |||
| 74b82845b5 | |||
| 6f322cadb8 | |||
| b4ac013f18 | |||
| a3fb96abb7 | |||
| 8dd0710786 | |||
| 8f528c7f95 | |||
| d253ebb197 | |||
| c6fa731df0 | |||
| a39f43e439 | |||
| 87afa3a0ec | |||
| 600d0f3c81 | |||
| 9147787fd2 | |||
| 24ab4a2f49 | |||
| 5c32a86674 | |||
| a728dc2c15 | |||
| fa4bbbde0c | |||
| 799438ba3e | |||
| 30d80fa0de | |||
| 4f36ce3086 | |||
| 9e62a5847c | |||
| c39b27b0d0 | |||
| a79f40c66c | |||
| a1e9401aaa | |||
| f36f6ae125 | |||
| 2c903c276d |
@@ -6,6 +6,8 @@
|
||||
|
||||
src = ./.;
|
||||
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
@@ -24,6 +26,10 @@
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
|
||||
mkdir -p $dev/include/modules
|
||||
cp -r include/* $dev/include
|
||||
cp -r modules $dev/include/modules
|
||||
'';
|
||||
|
||||
};
|
||||
@@ -48,16 +54,16 @@
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/ImguiEmbed/*.cpp \
|
||||
modules/examples/TestImgui/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/Archimedes-Modules/TestImgui/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -90,16 +96,16 @@
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/TerminalEmbed/*.cpp \
|
||||
modules/Terminal/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/Archimedes-Modules/Terminal/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
|
||||
@@ -12,9 +12,8 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestMenu/src/*.cpp \
|
||||
modules/Archimedes-Modules/TestMenu/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src \
|
||||
-Wall \
|
||||
-DTESTMENU_DYNAMIC \
|
||||
-o $name
|
||||
@@ -43,9 +42,9 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestNotCurses/src/*.cpp \
|
||||
modules/Archimedes-Modules/TestNotCurses/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I include \
|
||||
-Wall \
|
||||
-lnotcurses \
|
||||
-DTESTNOTCURSES_DYNAMIC \
|
||||
@@ -58,6 +57,7 @@
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
Print = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Print";
|
||||
@@ -70,9 +70,9 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/Print/src/*.cpp \
|
||||
modules/Archimedes-Modules/Print/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I include \
|
||||
-Wall \
|
||||
-DPRINT_DYNAMIC \
|
||||
-o $name
|
||||
@@ -97,9 +97,9 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/DependsOnPrint/src/*.cpp \
|
||||
modules/Archimedes-Modules/DependsOnPrint/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I include \
|
||||
-Wall \
|
||||
-DDEPENDSONPRINT_DYNAMIC \
|
||||
-o $name
|
||||
@@ -124,10 +124,10 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/DependsOnPrintStatic/src/*.cpp \
|
||||
modules/examples/Print/src/*.cpp \
|
||||
modules/Archimedes-Modules/DependsOnPrintStatic/*.cpp \
|
||||
modules/Archimedes-Modules/Print/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include -I . \
|
||||
-I include -I . \
|
||||
-DDEPENDSONPRINTSTATIC_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -159,19 +159,61 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestImgui/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/Archimedes-Modules/TestImgui/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DGUIMODULE \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DTESTIMGUI_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
Calculator = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Calculator";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Calculator/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DCALCULATOR_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -198,11 +240,11 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestClay/src/*.cpp \
|
||||
modules/Archimedes-Modules/TestClay/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-I include \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DTESTCLAY_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -214,4 +256,258 @@
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ChatServer = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatServer";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Chat/ChatServer/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-I include -I . \
|
||||
-lGameNetworkingSockets \
|
||||
-DCHATSERVER_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ChatServerVoice = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatServerVoice";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/ChatVoice/ChatServerVoice/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-I include -I . \
|
||||
-lGameNetworkingSockets \
|
||||
-DCHATSERVERVOICE_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ChatClient = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatClient";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Chat/ChatClient/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DCHATCLIENT_DYNAMIC \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ChatClientVoice = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatClientVoice";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
sdl3
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/ChatVoice/ChatClientVoice/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DCHATCLIENTVOICE_DYNAMIC \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_sdl3.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=2 \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lSDL3 -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
Terminal = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Terminal";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Terminal/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DTERMINAL_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
Ollama = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Ollama";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
curl
|
||||
nlohmann_json
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Ollama/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DOLLAMA_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
18
flake.lock
generated
18
flake.lock
generated
@@ -3,11 +3,11 @@
|
||||
"clay": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1742509368,
|
||||
"narHash": "sha256-XSaMuWCADZgZnRaGcBgf+u40O6jS5kkpq3Xruy6z+I0=",
|
||||
"lastModified": 1746753934,
|
||||
"narHash": "sha256-7Kx536YsmPTXUjs/jBknGAmqYsqqDh6T11AlarTeGLM=",
|
||||
"owner": "nicbarker",
|
||||
"repo": "clay",
|
||||
"rev": "ad49977f1b37ccd7664333181f30f575d08d3838",
|
||||
"rev": "76265e4c3c97ebe5a4aab081d5c5a05e5a979d5d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -19,11 +19,11 @@
|
||||
"imgui": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1741968903,
|
||||
"narHash": "sha256-4L37NRR+dlkhdxuDjhLR45kgjyZK2uelKBlGZ1nQzgY=",
|
||||
"lastModified": 1747034542,
|
||||
"narHash": "sha256-kVbyG7LXXHIOiI6dlZVID9DLErR+XNoAGp/R82TEpgo=",
|
||||
"owner": "ocornut",
|
||||
"repo": "imgui",
|
||||
"rev": "126d004f9e1eef062bf4b044b3b2faaf58d48c51",
|
||||
"rev": "e33069ce56d07751ca875eb239f41febef0ebcd3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -35,11 +35,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1742136038,
|
||||
"narHash": "sha256-DDe16FJk18sadknQKKG/9FbwEro7A57tg9vB5kxZ8kY=",
|
||||
"lastModified": 1746957726,
|
||||
"narHash": "sha256-k9ut1LSfHCr0AW82ttEQzXVCqmyWVA5+SHJkS5ID/Jo=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a1185f4064c18a5db37c5c84e5638c78b46e3341",
|
||||
"rev": "a39ed32a651fdee6842ec930761e31d1f242cb94",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
178
flake.nix
178
flake.nix
@@ -13,7 +13,7 @@
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, imgui, clay }@inputs: let
|
||||
outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in {
|
||||
@@ -41,9 +41,9 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/ServerModule/src/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I include \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DSERVERMODULE_DYNAMIC \
|
||||
@@ -74,9 +74,9 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/ClientModule/src/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I include \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DCLIENTMODULE_DYNAMIC \
|
||||
@@ -90,6 +90,7 @@
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
WindowModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "WindowModule";
|
||||
@@ -107,11 +108,11 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-I include \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DWINDOWMODULE_DYNAMIC \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
@@ -144,18 +145,18 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$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 \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -168,6 +169,49 @@
|
||||
|
||||
};
|
||||
|
||||
MainGUIsdl = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "MainGUI";
|
||||
|
||||
src = ./.;
|
||||
|
||||
inherit imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
sdl3
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/MainGUI/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_sdl3.cpp \
|
||||
$imgui/backends/imgui_impl_sdlrenderer3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=2 \
|
||||
-DWINDOW=2 \
|
||||
-DMAINGUI_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lSDL3 \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
|
||||
MainGUI = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "MainGUI";
|
||||
@@ -187,18 +231,18 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/MainGUI/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/MainGUI/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$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 . \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -211,101 +255,9 @@
|
||||
|
||||
};
|
||||
|
||||
Terminal = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Terminal";
|
||||
|
||||
src = ./.;
|
||||
|
||||
inherit imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Terminal/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DTERMINAL_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
Ollama = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Ollama";
|
||||
|
||||
src = ./.;
|
||||
|
||||
inherit imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
curl
|
||||
nlohmann_json
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Ollama/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DOLLAMA_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
packages.${system}.default = self.Archimedes;
|
||||
packages.${system}.default = self.Archimedes.examples.MinimalApp;
|
||||
|
||||
apps.${system}.default = {
|
||||
type = "app";
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#ifdef MODULE_TYPE
|
||||
|
||||
extern "C" {
|
||||
Archimedes::Module* create(Archimedes::App* app, void* handle) {
|
||||
return new MODULE_TYPE(app, handle);
|
||||
return new mtype(app, handle);
|
||||
}
|
||||
}
|
||||
|
||||
#undef MODULE_TYPE
|
||||
#endif
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
#include <any>
|
||||
#include <typeinfo>
|
||||
#include <future>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -60,13 +65,13 @@ namespace Archimedes {
|
||||
|
||||
unsigned int getEventType(std::string event) { return eventTypes[event]; }
|
||||
|
||||
void addEventType(std::string type) {
|
||||
void registerEvent(std::string type) {
|
||||
//only add each type once
|
||||
if(eventTypes.find(type) == eventTypes.end())
|
||||
eventTypes[type] = nextEventType++;
|
||||
}
|
||||
|
||||
void removeEventType(std::string type) {
|
||||
void unregisterEvent(std::string type) {
|
||||
//only erase registered types
|
||||
auto it = eventTypes.find(type);
|
||||
if(it != eventTypes.end())
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -140,17 +189,18 @@ namespace Archimedes {
|
||||
|
||||
void* h = m->getHandle();
|
||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||
if(*it == m->getName()) {
|
||||
if(*it == static_cast<std::string>(*m)) {
|
||||
std::cout << "Module \"" << *it << "\" is already loaded!\n";
|
||||
delete m;
|
||||
if(h) {
|
||||
dlclose(h);
|
||||
}
|
||||
return nullptr;
|
||||
return modules[*it];
|
||||
}
|
||||
}
|
||||
|
||||
modules[m->getName()] = m;
|
||||
if(modules.find(*m) == modules.end())
|
||||
modules[*m] = m;
|
||||
|
||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||
|
||||
@@ -164,7 +214,7 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
//insert temporarily to avoid circular dependencies
|
||||
runOrder.insert(roInsert, m->getName());
|
||||
runOrder.insert(roInsert, *m);
|
||||
|
||||
bool skip = false;
|
||||
for(auto it : m->deps) {
|
||||
@@ -185,17 +235,17 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
//reinsert once final order has been reached
|
||||
runOrder.remove(m->getName());
|
||||
runOrder.remove(*m);
|
||||
|
||||
runOrder.insert(roInsert, m->getName());
|
||||
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;
|
||||
|
||||
51
include/utils/Audio/Audio.h
Normal file
51
include/utils/Audio/Audio.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef AUDIO_H
|
||||
#define AUDIO_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_audio.h>
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Audio {
|
||||
|
||||
public:
|
||||
|
||||
Audio() {
|
||||
if(!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
|
||||
std::abort();
|
||||
}
|
||||
|
||||
pDevices = SDL_GetAudioPlaybackDevices(&pDeviceCount);
|
||||
rDevices = SDL_GetAudioPlaybackDevices(&rDeviceCount);
|
||||
}
|
||||
|
||||
~Audio() {
|
||||
|
||||
for(SDL_AudioStream* s : streams) {
|
||||
DestroyAudioStream(s);
|
||||
}
|
||||
|
||||
SDL_QuitSubsystem(SDL_INIT_AUDIO);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
SDL_AudioDeviceID* pDevices;
|
||||
|
||||
int pDeviceCount = 0;
|
||||
|
||||
SDL_AudioDeviceID* rDevices;
|
||||
|
||||
int rDeviceCount = 0;
|
||||
|
||||
std::vector<SDL_AudioStream*> streams;
|
||||
std::vector<SDL_AudioSpec> specs;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
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:
|
||||
|
||||
Event() {}
|
||||
Event(std::any data) : userData(data) {}
|
||||
|
||||
virtual ~Event() {}
|
||||
|
||||
virtual operator std::string() const = 0;
|
||||
|
||||
std::any userData;
|
||||
};
|
||||
}
|
||||
|
||||
#include "BasicEvents.h"
|
||||
|
||||
#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
|
||||
@@ -19,17 +19,19 @@ namespace Archimedes {
|
||||
|
||||
Module(App* a, void* h) : app(a), handle(h) {}
|
||||
|
||||
Module() : app(nullptr), handle(nullptr) {}
|
||||
|
||||
virtual ~Module() {}
|
||||
|
||||
virtual void run() {}
|
||||
virtual bool onEvent(const Event& e) { return false; }
|
||||
virtual void onLoad() {};
|
||||
|
||||
std::string getName() const { return name; }
|
||||
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;
|
||||
|
||||
@@ -40,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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "pch.hpp"
|
||||
#include "RendererOpenGL/RendererOpenGL.h"
|
||||
#include "RendererSDL3/RendererSDL3.h"
|
||||
|
||||
namespace Archimedes {
|
||||
class Renderer {
|
||||
@@ -12,7 +13,7 @@ namespace Archimedes {
|
||||
|
||||
~Renderer() {}
|
||||
|
||||
bool init() { return r.init(); }
|
||||
bool init(void* ptr) { return r.init(ptr); }
|
||||
|
||||
void render() {
|
||||
r.render(rc, w, h);
|
||||
@@ -22,6 +23,8 @@ namespace Archimedes {
|
||||
return rc;
|
||||
}
|
||||
|
||||
RendererImpl& getRendererImpl() { return r; }
|
||||
|
||||
private:
|
||||
std::list<std::function<void()>> rc;
|
||||
RendererImpl r;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#ifdef RENDERER_OPENGL
|
||||
#undef RENDERER_OPENGL
|
||||
#if RENDERER == 1
|
||||
|
||||
#ifndef RENDERER_OPENGL
|
||||
#define RENDERER_OPENGL
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
@@ -17,7 +19,7 @@ namespace Archimedes {
|
||||
RendererOpenGL() {};
|
||||
~RendererOpenGL() {};
|
||||
|
||||
bool init() {
|
||||
bool init(void* p) {
|
||||
return glewInit() == GLEW_OK;
|
||||
};
|
||||
|
||||
@@ -38,3 +40,5 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
49
include/utils/Renderer/RendererSDL3/RendererSDL3.h
Normal file
49
include/utils/Renderer/RendererSDL3/RendererSDL3.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#if RENDERER == 2
|
||||
|
||||
#ifndef RENDERER_SDL3
|
||||
#define RENDERER_SDL3
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class RendererSDL3 {
|
||||
|
||||
public:
|
||||
typedef void renderCmd();
|
||||
|
||||
RendererSDL3() {};
|
||||
~RendererSDL3() { SDL_DestroyRenderer(renderer); };
|
||||
|
||||
bool init(void* window) {
|
||||
renderer = SDL_CreateRenderer((SDL_Window*) window, nullptr);
|
||||
SDL_SetRenderVSync(renderer, 1);
|
||||
return renderer != nullptr;
|
||||
};
|
||||
|
||||
void render(std::list<std::function<void()>> cmdList, int& w, int& h) {
|
||||
|
||||
//SDL_SetRenderScale(renderer, w, h);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
for(auto f : cmdList)
|
||||
f();
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
SDL_Renderer* renderer = nullptr;
|
||||
};
|
||||
|
||||
typedef RendererSDL3 RendererImpl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -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,21 +13,23 @@ 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();
|
||||
|
||||
window.pollEvents();
|
||||
}
|
||||
|
||||
Renderer* getRenderer() { return renderer; }
|
||||
|
||||
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"
|
||||
|
||||
#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
|
||||
|
||||
173
include/utils/Window/WindowSDL3/WindowSDL3.h
Normal file
173
include/utils/Window/WindowSDL3/WindowSDL3.h
Normal file
@@ -0,0 +1,173 @@
|
||||
#if WINDOW == 2
|
||||
|
||||
#ifndef WINDOW_SDL3
|
||||
#define WINDOW_SDL3
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "utils/Window/WindowEvents.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#if RENDERER == 2
|
||||
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
|
||||
#endif
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Window;
|
||||
|
||||
static bool EventCallback(void* ptr, SDL_Event* e) {
|
||||
|
||||
WindowData& data = *(WindowData*) ptr;
|
||||
|
||||
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:
|
||||
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;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
class WindowSDL3 {
|
||||
|
||||
public:
|
||||
|
||||
WindowSDL3(Window* p, const std::function<void(Event*)>& sendEvent) {
|
||||
|
||||
data.window = p;
|
||||
data.sendEvent = sendEvent;
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
|
||||
std::cerr << "Error: SDL_Init(): " << SDL_GetError() << std::flush;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
#if RENDERER == 1
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||
|
||||
SDL_WindowFlags window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN;
|
||||
#elif RENDERER == 2
|
||||
SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||
#endif
|
||||
|
||||
w = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
|
||||
if (w == nullptr)
|
||||
{
|
||||
std::cerr << "Error: SDL_CreateWindow(): " << SDL_GetError() << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
SDL_SetWindowPosition(w, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
#if RENDERER == 1
|
||||
gl_context = SDL_GL_CreateContext(w);
|
||||
|
||||
if (gl_context == nullptr)
|
||||
{
|
||||
std::cerr << "Error: SDL_GL_CreateContext(): " << SDL_GetError() << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(w, gl_context);
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
#endif
|
||||
SDL_AddEventWatch(EventCallback, &data);
|
||||
|
||||
SDL_ShowWindow(w);
|
||||
}
|
||||
|
||||
~WindowSDL3() {
|
||||
#if RENDERER == 1
|
||||
SDL_GL_DestroyContext(gl_context);
|
||||
#endif
|
||||
SDL_RemoveEventWatch(EventCallback, &data);
|
||||
SDL_DestroyWindow(w);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
bool shouldClose() { return false; }
|
||||
|
||||
void doFrame() {
|
||||
#if RENDERER == 1
|
||||
restoreContext();
|
||||
SDL_GL_SwapWindow(w);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pollEvents() {
|
||||
static SDL_Event e;
|
||||
while(SDL_PollEvent(&e)) {}
|
||||
}
|
||||
#if RENDERER == 1
|
||||
void restoreContext() { SDL_GL_MakeCurrent(w, gl_context); }
|
||||
#endif
|
||||
void getSize(int& w, int& h) {
|
||||
w = this->width;
|
||||
h = this->height;
|
||||
}
|
||||
|
||||
void setSize(int& w, int& h) {
|
||||
this->width = w;
|
||||
this->height = h;
|
||||
}
|
||||
|
||||
SDL_Window* getWindow() { return w; }
|
||||
#if RENDERER == 1
|
||||
SDL_GLContext getContext() { return gl_context; }
|
||||
#endif
|
||||
WindowData data;
|
||||
|
||||
private:
|
||||
SDL_Window* w;
|
||||
int width = 0, height = 0;
|
||||
#if RENDERER == 1
|
||||
SDL_GLContext gl_context;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
typedef WindowSDL3 WindowImpl;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
353
modules/Archimedes-Modules/Calculator/Calculator.cpp
Normal file
353
modules/Archimedes-Modules/Calculator/Calculator.cpp
Normal file
@@ -0,0 +1,353 @@
|
||||
#include "Calculator.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
Calculator::Calculator(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Calculator";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Calculator::~Calculator() {
|
||||
|
||||
if(app) {
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void Calculator::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Calculator!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
}
|
||||
|
||||
void Calculator::run() {
|
||||
|
||||
if(open) {
|
||||
basicCalculator();
|
||||
} else {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Calculator::index(std::string equation, std::unordered_map<unsigned int, std::string>& nodes) {
|
||||
unsigned int idx = 0;
|
||||
|
||||
nodes.clear();
|
||||
|
||||
const static std::string operators[] = {
|
||||
"(",
|
||||
")",
|
||||
"^",
|
||||
"*",
|
||||
"/",
|
||||
"+",
|
||||
"-"
|
||||
};
|
||||
|
||||
for(const std::string& s : operators) {
|
||||
|
||||
while(equation.find(s, idx) != std::string::npos) {
|
||||
int next = equation.find(s, idx);
|
||||
nodes[next] = equation.substr(next, s.length());
|
||||
idx = next + s.length();
|
||||
}
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
|
||||
// -3+8*6-(8+4)^9/5
|
||||
for(unsigned int i = 0; i < equation.length(); i++) {
|
||||
static unsigned int begin = 0, end = 0;
|
||||
if(nodes.find(i) == nodes.end()) {
|
||||
if(nodes.find(i - 1) != nodes.end() || i == 0) {
|
||||
//first digit of expression
|
||||
begin = i;
|
||||
}
|
||||
if(nodes.find(i + 1) != nodes.end() || i == equation.length() - 1) {
|
||||
//character after last digit of expression
|
||||
end = i + 1;
|
||||
nodes[begin] = equation.substr(begin, end - begin);
|
||||
nodes[end - 1] = equation.substr(begin, end - begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double Calculator::evaluate(std::string equation, std::unordered_map<char, std::string>& evalStr) {
|
||||
|
||||
char op = '^';
|
||||
|
||||
while(equation.find(op) == std::string::npos) {
|
||||
switch(op) {
|
||||
case '^':
|
||||
op = '*';
|
||||
break;
|
||||
case '*':
|
||||
op = '/';
|
||||
break;
|
||||
case '/':
|
||||
op = '+';
|
||||
break;
|
||||
case '+':
|
||||
op = '-';
|
||||
break;
|
||||
case '-':
|
||||
//no operator
|
||||
if(evalStr.find(equation.front()) != evalStr.end()) {
|
||||
return evaluate(evalStr[equation.front()], evalStr);
|
||||
} else {
|
||||
return std::stod(equation);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//op is now the appropriate operator
|
||||
|
||||
//if either term is a placeholder, evaluate and substitute.
|
||||
double a, b;
|
||||
if(evalStr.find(equation.front()) != evalStr.end()) {
|
||||
a = evaluate(evalStr[equation.front()], evalStr);
|
||||
} else {
|
||||
if(equation.find(op) == 0 && op == '-') {
|
||||
a = 0;
|
||||
} else {
|
||||
a = std::stod(equation.substr(0, equation.find(op)));
|
||||
}
|
||||
}
|
||||
|
||||
if(evalStr.find(equation.back()) != evalStr.end()) {
|
||||
b = evaluate(evalStr[equation.back()], evalStr);
|
||||
} else {
|
||||
b = std::stod(equation.substr(equation.find(op) + 1));
|
||||
}
|
||||
switch(op) {
|
||||
case '^':
|
||||
return pow(a, b);
|
||||
case '*':
|
||||
return a * b;
|
||||
case '/':
|
||||
return a / b;
|
||||
case '+':
|
||||
return a + b;
|
||||
case '-':
|
||||
return a - b;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Calculator::calculate(std::string equation) {
|
||||
|
||||
//PEMDAS
|
||||
while(equation.find(' ') != std::string::npos) {
|
||||
equation.erase(equation.find(' '), 1);
|
||||
}
|
||||
while(equation.find('\t') != std::string::npos) {
|
||||
equation.erase(equation.find('\t'), 1);
|
||||
}
|
||||
while(equation.find('\n') != std::string::npos) {
|
||||
equation.erase(equation.find('\n'), 1);
|
||||
}
|
||||
|
||||
std::unordered_map<unsigned int, std::string> nodes;
|
||||
std::unordered_map<char, std::string> evalStr;
|
||||
std::string eval = "a";
|
||||
|
||||
unsigned int idx = 0;
|
||||
|
||||
index(equation, nodes);
|
||||
|
||||
idx = 0;
|
||||
|
||||
// ()
|
||||
while(equation.find(')', idx) != std::string::npos) {
|
||||
int end = equation.find(')');
|
||||
int begin = equation.rfind('(', end);
|
||||
evalStr[eval.front()] = calculate(equation.substr(begin + 1, (end - begin) - 1));
|
||||
equation.replace(begin, (end - begin) + 1, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
idx = 0;
|
||||
index(equation, nodes);
|
||||
// ^
|
||||
while(equation.find('^', idx) != std::string::npos) {
|
||||
int mid = equation.find('^');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
idx = 0;
|
||||
index(equation, nodes);
|
||||
// * or /
|
||||
while(equation.find('*', idx) != std::string::npos || equation.find('/', idx) != std::string::npos) {
|
||||
if(equation.find('*', idx) < equation.find('/', idx) && equation.find('*', idx) != std::string::npos) {
|
||||
int mid = equation.find('*');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
} else if(equation.find('/', idx) != std::string::npos) {
|
||||
int mid = equation.find('/');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
}
|
||||
idx = 0;
|
||||
index(equation, nodes);
|
||||
// + or -
|
||||
while(equation.find('+', idx) != std::string::npos || equation.find('-', idx) != std::string::npos) {
|
||||
if(equation.find('+', idx) < equation.find('-', idx) && equation.find('+', idx) != std::string::npos) {
|
||||
int mid = equation.find('+');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
} else if(equation.find('-', idx) != std::string::npos) {
|
||||
int mid = equation.find('-');
|
||||
int begin = mid;
|
||||
if(nodes.find(mid - 1) != nodes.end()) {
|
||||
begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
}
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return std::to_string(evaluate(equation, evalStr));
|
||||
}
|
||||
|
||||
|
||||
void Calculator::basicCalculator() {
|
||||
|
||||
static bool b = true;
|
||||
|
||||
static std::string s;
|
||||
|
||||
if(b) {
|
||||
|
||||
ImGui::Begin("Basic Calculator", &open);
|
||||
|
||||
ImGui::Text("%s", s.c_str());
|
||||
|
||||
ImGui::BeginGroup();
|
||||
{
|
||||
if(ImGui::Button("AC")) {
|
||||
s.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("(")) {
|
||||
s += " ( ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button(")")) {
|
||||
s += " ) ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("^")) {
|
||||
s += " ^ ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("=")) {
|
||||
s = calculate(s);
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::BeginGroup();
|
||||
{
|
||||
for(int i = 1; i < 4; i++) {
|
||||
ImGui::BeginGroup();
|
||||
for(int j = 6; j >= 0; j -= 3) {
|
||||
if(ImGui::Button(std::to_string(i + j).c_str())) {
|
||||
s += std::to_string(i + j);
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
if(i < 3) {
|
||||
ImGui::SameLine();
|
||||
}
|
||||
}
|
||||
|
||||
if(ImGui::Button("0")) {
|
||||
s += "0";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button(".")) {
|
||||
s += ".";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("del")) {
|
||||
if(!s.empty()) {
|
||||
if(s.back() == ' ') {
|
||||
s.pop_back();
|
||||
if(s.back() == '(' || s.back() == ')') {
|
||||
parenthesis = !parenthesis;
|
||||
}
|
||||
s.pop_back();
|
||||
s.pop_back();
|
||||
} else {
|
||||
s.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginGroup();
|
||||
|
||||
if(ImGui::Button("+")) {
|
||||
s += " + ";
|
||||
}
|
||||
if(ImGui::Button("-")) {
|
||||
s += " - ";
|
||||
}
|
||||
if(ImGui::Button("*")) {
|
||||
s += " * ";
|
||||
}
|
||||
if(ImGui::Button("/")) {
|
||||
s += " / ";
|
||||
}
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void Calculator::graphingCalculator() {
|
||||
|
||||
}
|
||||
35
modules/Archimedes-Modules/Calculator/Calculator.h
Normal file
35
modules/Archimedes-Modules/Calculator/Calculator.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class Calculator : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Calculator(Archimedes::App*, void*);
|
||||
|
||||
Calculator() { name = "Calculator"; }
|
||||
|
||||
~Calculator();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
private:
|
||||
bool open = true;
|
||||
|
||||
bool parenthesis = true;
|
||||
|
||||
bool graphing = false;
|
||||
|
||||
void basicCalculator();
|
||||
|
||||
std::string calculate(std::string);
|
||||
double evaluate(std::string, std::unordered_map<char, std::string>&);
|
||||
void index(std::string, std::unordered_map<unsigned int, std::string>&);
|
||||
|
||||
void graphingCalculator();
|
||||
|
||||
};
|
||||
|
||||
#ifdef CALCULATOR_DYNAMIC
|
||||
typedef Calculator mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
129
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.cpp
Normal file
129
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include "modules/ClientModule/ClientModule.h"
|
||||
|
||||
#include "ChatClient.h"
|
||||
|
||||
|
||||
ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatClient";
|
||||
|
||||
ClientModule* cm = new ClientModule(a, h);
|
||||
deps[*cm] = cm;
|
||||
cm->shouldHandleEvents(ClientModule::CMEventEnum::ConnectionStatusChanged | ClientModule::CMEventEnum::DataSent);
|
||||
|
||||
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 = "127.0.0.1:9932";
|
||||
|
||||
ImGui::Begin("ChatClient Module", &open);
|
||||
|
||||
ImGui::InputText("Server Address: ", &addr);
|
||||
|
||||
if(cm->isRunning() && cm->isConnected()) {
|
||||
|
||||
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
||||
cm->stopClient();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(ImGui::Button("Connect") && !cm->isRunning()) {
|
||||
static SteamNetworkingIPAddr serverAddr;
|
||||
serverAddr.ParseString(addr.c_str());
|
||||
cm->startClient(serverAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text("%s", messages.c_str());
|
||||
|
||||
ImGui::InputText("Message: ", &s);
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
cm->sendReliable(s.c_str(), (uint32) s.length());
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
} else {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(*cm));
|
||||
}
|
||||
}
|
||||
|
||||
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(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
std::cerr << "Client Recieved: " << s << std::endl;
|
||||
|
||||
messages += "\n\n" + s;
|
||||
|
||||
return true;
|
||||
}
|
||||
/*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
28
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.h
Normal file
28
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
|
||||
class ChatClient : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatClient(Archimedes::App* a, void* h);
|
||||
|
||||
ChatClient() { name = "ChatClient"; }
|
||||
|
||||
~ChatClient();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
private:
|
||||
std::string messages = "";
|
||||
bool open = true;
|
||||
};
|
||||
|
||||
#ifdef CHATCLIENT_DYNAMIC
|
||||
typedef ChatClient mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
56
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.cpp
Normal file
56
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "ChatServer.h"
|
||||
|
||||
void ChatServer::onLoad() {
|
||||
ServerModule* sm = (ServerModule*) moduleInstances[ServerModule()];
|
||||
|
||||
sm->startServer(9932);
|
||||
}
|
||||
|
||||
//void ChatServer::run() {}
|
||||
|
||||
bool ChatServer::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(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
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()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, s.c_str(), s.length());
|
||||
else
|
||||
sm->sendReliable(e.msg->m_conn, "\nMessage sent\n", strlen("\nMessage sent\n"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
34
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.h
Normal file
34
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChatServer : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatServer(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatServer";
|
||||
|
||||
ServerModule* sm = new ServerModule(a, h);
|
||||
deps[*sm] = sm;
|
||||
sm->shouldHandleEvents(ServerModule::SMEventEnum::ConnectionStatusChanged | ServerModule::SMEventEnum::DataSent);
|
||||
}
|
||||
|
||||
ChatServer() { name = "ChatServer"; }
|
||||
|
||||
~ChatServer() {
|
||||
if(app) {}
|
||||
}
|
||||
|
||||
void onLoad();
|
||||
|
||||
//void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
};
|
||||
|
||||
#ifdef CHATSERVER_DYNAMIC
|
||||
typedef ChatServer mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -0,0 +1,276 @@
|
||||
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include "modules/ClientModule/ClientModule.h"
|
||||
|
||||
#include "ChatClientVoice.h"
|
||||
|
||||
|
||||
ChatClientVoice::ChatClientVoice(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatClientVoice";
|
||||
|
||||
ClientModule* cm = new ClientModule(a, h);
|
||||
deps[*cm] = cm;
|
||||
cm->shouldHandleEvents(ClientModule::CMEventEnum::ConnectionStatusChanged | ClientModule::CMEventEnum::DataSent);
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
|
||||
deps[*im] = im;
|
||||
|
||||
}
|
||||
|
||||
ChatClientVoice::~ChatClientVoice() {
|
||||
if(app) {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
|
||||
//if(buf)
|
||||
// delete [] buf;
|
||||
}
|
||||
}
|
||||
|
||||
void ChatClientVoice::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for ChatClientVoice!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClientVoice!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
std::cout << "Audio init failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
mic = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, NULL, NULL, NULL);
|
||||
SDL_GetAudioStreamFormat(mic, &spec, NULL);
|
||||
speaker = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);
|
||||
|
||||
//buf = new unsigned char[len];
|
||||
|
||||
}
|
||||
|
||||
void ChatClientVoice::run() {
|
||||
|
||||
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
static unsigned char buf[10 * 1024];
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClientVoice!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(open) {
|
||||
static std::string s, addr = "127.0.0.1:9932";
|
||||
|
||||
ImGui::Begin("ChatClientVoice Module", &open);
|
||||
|
||||
ImGui::InputText("Server Address: ", &addr);
|
||||
|
||||
if(cm->isRunning() && cm->isConnected()) {
|
||||
|
||||
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
||||
cm->sendReliable("srvcmd1", strlen("srvcmd1"));
|
||||
//cm->stopClient();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(ImGui::Button("Connect") && !cm->isRunning()) {
|
||||
static SteamNetworkingIPAddr serverAddr;
|
||||
serverAddr.ParseString(addr.c_str());
|
||||
cm->startClient(serverAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text("%s", messages.c_str());
|
||||
|
||||
ImGui::InputText("Message: ", &s);
|
||||
|
||||
if(cm->isConnected()) {
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
if(s == "/quit") {
|
||||
cm->sendReliable("srvcmd1", strlen("srvcmd1"));
|
||||
cm->stopClient();
|
||||
} else if(s == "/shutdown") {
|
||||
cm->sendReliable("srvcmd2", strlen("srvcmd2"));
|
||||
//cm->stopClient();
|
||||
} else {
|
||||
s.insert(0, "client");
|
||||
cm->sendReliable(s.c_str(), (uint32) s.length());
|
||||
}
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
|
||||
static float micVol = 1.0f;
|
||||
static float speakerVol = 1.0f;
|
||||
|
||||
static bool micTest = false;
|
||||
|
||||
ImGui::SliderFloat("Mic Volume", &micVol, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("Speaker Volume", &speakerVol, 0.0f, 1.0f);
|
||||
|
||||
ImGui::Checkbox("Mic test", &micTest);
|
||||
|
||||
if(!SDL_AudioStreamDevicePaused(mic)) {
|
||||
SDL_SetAudioStreamGain(mic, micVol);
|
||||
} else if(micTest) {
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ResumeAudioStreamDevice(mic);
|
||||
SDL_SetAudioStreamGain(mic, micVol);
|
||||
}
|
||||
|
||||
if(!SDL_AudioStreamDevicePaused(speaker)) {
|
||||
SDL_SetAudioStreamGain(speaker, speakerVol);
|
||||
} else if(micTest) {
|
||||
SDL_ClearAudioStream(speaker);
|
||||
SDL_ResumeAudioStreamDevice(speaker);
|
||||
SDL_SetAudioStreamGain(speaker, speakerVol);
|
||||
}
|
||||
|
||||
static int avail = 0;
|
||||
|
||||
if(micTest) {
|
||||
|
||||
avail = SDL_min(len, SDL_GetAudioStreamAvailable(mic));
|
||||
if(avail > 10) {
|
||||
avail = SDL_GetAudioStreamData(mic, buf, avail);
|
||||
SDL_PutAudioStreamData(speaker, buf, avail);
|
||||
}
|
||||
|
||||
} else if(cm->isConnected()){
|
||||
// if not testing, send to server.
|
||||
|
||||
avail = SDL_min(len, SDL_GetAudioStreamAvailable(mic));
|
||||
if(avail > 10) {
|
||||
avail = SDL_GetAudioStreamData(mic, buf, avail);
|
||||
cm->sendReliable(buf, avail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::End();
|
||||
} else {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(*cm));
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatClientVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
static ClientModule* cm;
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
{ cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
static std::string s;
|
||||
|
||||
if(std::string((const char*)e.msg->m_pData, 6) == "client") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
messages += "\n\n" + s;
|
||||
} else if(std::string((const char*)e.msg->m_pData, 6) == "server") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
int serverCode = stoi(s);
|
||||
|
||||
switch(serverCode) {
|
||||
case 0:
|
||||
//start voice
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
SDL_ResumeAudioStreamDevice(mic);
|
||||
SDL_ResumeAudioStreamDevice(speaker);
|
||||
break;
|
||||
case 1:
|
||||
//stop voice and clear
|
||||
SDL_PauseAudioStreamDevice(mic);
|
||||
SDL_PauseAudioStreamDevice(speaker);
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
break;
|
||||
case 2:
|
||||
//disconnect
|
||||
cm->stopClient();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else /*if(std::string((const char*)e.msg->m_pData, 6) == "audio:")*/ {
|
||||
s = "audio data";
|
||||
|
||||
SDL_PutAudioStreamData(speaker, e.msg->m_pData, e.msg->m_cbSize);
|
||||
}
|
||||
|
||||
//std::cerr << "Client Recieved: " << s << std::endl;
|
||||
|
||||
return true;
|
||||
} else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
switch(e.info->m_info.m_eState) {
|
||||
|
||||
case k_ESteamNetworkingConnectionState_None:
|
||||
// NOTE: We will get callbacks here when we destroy connections. You can ignore these.
|
||||
break;
|
||||
|
||||
case k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
{
|
||||
|
||||
SDL_PauseAudioStreamDevice(mic);
|
||||
SDL_PauseAudioStreamDevice(speaker);
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connecting:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connected:
|
||||
//OnConnect
|
||||
break;
|
||||
|
||||
default:
|
||||
// Silences -Wswitch
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_audio.h>
|
||||
|
||||
class ChatClientVoice : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatClientVoice(Archimedes::App* a, void* h);
|
||||
|
||||
ChatClientVoice() { name = "ChatClientVoice"; }
|
||||
|
||||
~ChatClientVoice();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
private:
|
||||
std::string messages = "";
|
||||
bool open = true;
|
||||
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioStream *mic, *speaker;
|
||||
|
||||
const int len = 10 * 1024;
|
||||
};
|
||||
|
||||
#ifdef CHATCLIENTVOICE_DYNAMIC
|
||||
typedef ChatClientVoice mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "ChatServerVoice.h"
|
||||
|
||||
void ChatServerVoice::onLoad() {
|
||||
ServerModule* sm = (ServerModule*) moduleInstances[ServerModule()];
|
||||
|
||||
sm->startServer(9932);
|
||||
}
|
||||
|
||||
//void ChatServerVoice::run() {}
|
||||
|
||||
bool ChatServerVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
static ServerModule* sm;
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
{ sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
static std::string s;
|
||||
|
||||
if(std::string((const char*)e.msg->m_pData, 6) == "client") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, e.msg->m_pData, e.msg->m_cbSize);
|
||||
else
|
||||
sm->sendReliable(e.msg->m_conn, "client\nMessage sent\n", strlen("client\nMessage sent\n"));
|
||||
}
|
||||
|
||||
|
||||
} else if(std::string((const char*)e.msg->m_pData, 6) == "srvcmd") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
int cmdCode = stoi(s);
|
||||
|
||||
switch(cmdCode) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
//disconnect
|
||||
sm->disconnectClient(e.msg->m_conn);
|
||||
break;
|
||||
case 2:
|
||||
for(auto& it : sm->getClients()) {
|
||||
sm->sendReliable(it.first, "server2", strlen("server2"));
|
||||
}
|
||||
sm->stopServer();
|
||||
app->end();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else /*if(std::string((const char*)e.msg->m_pData, 6) == "audio:")*/ {
|
||||
s = "audio data";
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, e.msg->m_pData, e.msg->m_cbSize);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cerr << "Server Recieved: " << s << std::endl;
|
||||
|
||||
return true;
|
||||
|
||||
} else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
{ sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
unsigned int numClients;
|
||||
(void)sm->getClients(&numClients);
|
||||
|
||||
switch(e.info->m_info.m_eState) {
|
||||
|
||||
case k_ESteamNetworkingConnectionState_None:
|
||||
// NOTE: We will get callbacks here when we destroy connections. You can ignore these.
|
||||
break;
|
||||
|
||||
case k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
{
|
||||
if(numClients < 2) {
|
||||
for(auto& it : sm->getClients()) {
|
||||
sm->sendReliable(it.first, "server1", strlen("server1"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connecting:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connected:
|
||||
//OnConnect
|
||||
|
||||
if(numClients == 2) {
|
||||
for(auto& it : sm->getClients()) {
|
||||
sm->sendReliable(it.first, "server0", strlen("server0"));
|
||||
}
|
||||
} else if(numClients > 2) {
|
||||
|
||||
sm->sendReliable(e.info->m_hConn, "server0", strlen("server0"));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Silences -Wswitch
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChatServerVoice : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatServerVoice(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatServerVoice";
|
||||
|
||||
ServerModule* sm = new ServerModule(a, h);
|
||||
deps[*sm] = sm;
|
||||
sm->shouldHandleEvents(ServerModule::SMEventEnum::ConnectionStatusChanged | ServerModule::SMEventEnum::DataSent);
|
||||
}
|
||||
|
||||
ChatServerVoice() { name = "ChatServerVoice"; }
|
||||
|
||||
~ChatServerVoice() {
|
||||
if(app) {}
|
||||
}
|
||||
|
||||
void onLoad();
|
||||
|
||||
//void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
};
|
||||
|
||||
#ifdef CHATSERVERVOICE_DYNAMIC
|
||||
typedef ChatServerVoice mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
46
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.cpp
Normal file
46
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "ChessServer.h"
|
||||
|
||||
void ChessServer::onLoad() {
|
||||
ServerModule* sm = (ServerModule*) moduleInstances[ServerModule()];
|
||||
|
||||
sm->startServer(9932);
|
||||
}
|
||||
|
||||
//void ChessServer::run() {}
|
||||
|
||||
bool ChessServer::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(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, s.c_str(), s.length());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
34
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.h
Normal file
34
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChessServer : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChessServer(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChessServer";
|
||||
|
||||
ServerModule* sm = new ServerModule(a, h);
|
||||
deps[*sm] = sm;
|
||||
sm->shouldHandleEvents(ServerModule::SMEventEnum::ConnectionStatusChanged | ServerModule::SMEventEnum::DataSent);
|
||||
}
|
||||
|
||||
ChessServer() { name = "ChessServer"; }
|
||||
|
||||
~ChessServer() {
|
||||
if(app) {}
|
||||
}
|
||||
|
||||
void onLoad();
|
||||
|
||||
//void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
};
|
||||
|
||||
#ifdef CHESSSERVER_DYNAMIC
|
||||
typedef ChessServer mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Ollama.h"
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -8,15 +8,20 @@ Ollama::Ollama(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "Ollama";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Ollama::~Ollama() {
|
||||
if(app) {
|
||||
if(curl) {
|
||||
curl_easy_cleanup(curl);
|
||||
curl = nullptr;
|
||||
}
|
||||
curl_global_cleanup();
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostream* userp)
|
||||
@@ -27,14 +32,14 @@ static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostr
|
||||
|
||||
void Ollama::onLoad() {
|
||||
|
||||
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Ollama!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->getContext());
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
@@ -109,7 +114,7 @@ void Ollama::run() {
|
||||
|
||||
if(code != CURLE_OK) {
|
||||
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
|
||||
app->stopModule(getName());
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
return;
|
||||
} else {
|
||||
jsonObj = nlohmann::json::parse(response);
|
||||
@@ -8,6 +8,7 @@ class Ollama : public Archimedes::Module {
|
||||
public:
|
||||
Ollama(Archimedes::App*, void*);
|
||||
|
||||
Ollama() { name = "Ollama"; }
|
||||
~Ollama();
|
||||
|
||||
void onLoad();
|
||||
@@ -20,6 +21,6 @@ class Ollama : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef OLLAMA_DYNAMIC
|
||||
#define MODULE_TYPE Ollama
|
||||
typedef Ollama mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -5,8 +5,10 @@ Print::Print(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
}
|
||||
|
||||
Print::~Print() {
|
||||
if(app) {
|
||||
std::cout << "Print Destroyed!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Print::run() {
|
||||
std::cout << "Print lib loaded and run!\n";
|
||||
@@ -4,11 +4,12 @@ class Print : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Print(Archimedes::App*, void*);
|
||||
Print() { name = "Print"; }
|
||||
~Print();
|
||||
void run();
|
||||
};
|
||||
|
||||
#ifdef PRINT_DYNAMIC
|
||||
#define MODULE_TYPE Print
|
||||
typedef Print mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
1
modules/Archimedes-Modules/README.md
Normal file
1
modules/Archimedes-Modules/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Example modules for Archimedes
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "Terminal.h"
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
|
||||
Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
@@ -13,23 +13,27 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "Terminal";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Terminal::~Terminal() {
|
||||
if(app) {
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::onLoad() {
|
||||
|
||||
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Terminal!\n";
|
||||
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(getName());
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
} else {
|
||||
if(input == "clear") output = "";
|
||||
output += opArr;
|
||||
@@ -5,6 +5,7 @@ class Terminal : public Archimedes::Module {
|
||||
public:
|
||||
Terminal(Archimedes::App*, void*);
|
||||
|
||||
Terminal() { name = "Terminal"; }
|
||||
~Terminal();
|
||||
|
||||
void onLoad();
|
||||
@@ -15,6 +16,6 @@ class Terminal : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef TERMINAL_DYNAMIC
|
||||
#define MODULE_TYPE Terminal
|
||||
typedef Terminal mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
|
||||
class TestClay : public Archimedes::GuiModule {
|
||||
class TestClay : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestClay(void*, Archimedes::App&);
|
||||
@@ -1,28 +1,30 @@
|
||||
#include "TestImgui.h"
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "TestImgui";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
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(getName());
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
@@ -5,6 +5,8 @@ class TestImgui : public Archimedes::Module {
|
||||
public:
|
||||
TestImgui(Archimedes::App*, void*);
|
||||
|
||||
TestImgui() { name = "TestImgui"; }
|
||||
|
||||
~TestImgui();
|
||||
|
||||
void onLoad();
|
||||
@@ -17,6 +19,6 @@ class TestImgui : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef TESTIMGUI_DYNAMIC
|
||||
#define MODULE_TYPE TestImgui
|
||||
typedef TestImgui mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -14,6 +14,6 @@ class TestNotCurses : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef TESTNOTCURSES_DYNAMIC
|
||||
#define MODULE_TYPE TestNotCurses
|
||||
typedef TestNotCurses mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
141
modules/ClientModule/ClientModule.cpp
Normal file
141
modules/ClientModule/ClientModule.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "ClientModule.h"
|
||||
|
||||
ClientModule::ClientModule(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "ClientModule";
|
||||
}
|
||||
|
||||
ClientModule::~ClientModule() {
|
||||
if(app) {
|
||||
app->unregisterEvent(Archimedes::DataRecievedEvent());
|
||||
app->unregisterEvent(Archimedes::DataSentEvent());
|
||||
app->unregisterEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||
|
||||
GameNetworkingSockets_Kill();
|
||||
}
|
||||
}
|
||||
|
||||
void ClientModule::onLoad() {
|
||||
|
||||
app->registerEvent(Archimedes::DataSentEvent());
|
||||
app->registerEvent(Archimedes::DataRecievedEvent());
|
||||
app->registerEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||
|
||||
SteamDatagramErrMsg errMsg;
|
||||
if ( !GameNetworkingSockets_Init( nullptr, errMsg ) ) {
|
||||
//FatalError( "GameNetworkingSockets_Init failed. %s", errMsg );
|
||||
std::cerr << "GameNetworkingSockets_Init() Failed: " << errMsg << std::endl;
|
||||
}
|
||||
|
||||
//SteamNetworkingUtils()->SetDebugOutputFunction( k_ESteamNetworkingSocketsDebugOutputType_Msg, DebugOutput );
|
||||
|
||||
interface = SteamNetworkingSockets();
|
||||
|
||||
}
|
||||
|
||||
void ClientModule::startClient(SteamNetworkingIPAddr& serverAddr) {
|
||||
if(!running) {
|
||||
// Start connecting
|
||||
char szAddr[ SteamNetworkingIPAddr::k_cchMaxString ];
|
||||
serverAddr.ToString( szAddr, sizeof(szAddr), true );
|
||||
std::cerr << "Connecting to chat server at " << szAddr << std::endl;
|
||||
SteamNetworkingConfigValue_t opt;
|
||||
opt.SetPtr( k_ESteamNetworkingConfig_Callback_ConnectionStatusChanged, (void*)SteamNetConnectionStatusChangedCallback );
|
||||
connection = interface->ConnectByIPAddress( serverAddr, 1, &opt );
|
||||
if ( connection == k_HSteamNetConnection_Invalid )
|
||||
std::cerr << "Failed to create connection\n";
|
||||
|
||||
running = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ClientModule::stopClient() { running = false; }
|
||||
|
||||
void ClientModule::run() {
|
||||
|
||||
if(running) {
|
||||
pollIncomingData();
|
||||
PollConnectionStateChanges();
|
||||
}
|
||||
}
|
||||
|
||||
bool ClientModule::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
if(eventsToHandle & CMEventEnum::ConnectionStatusChanged && type == app->getEventType(Archimedes::ConnectionStatusChangedEvent())) {
|
||||
|
||||
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
switch(e.info->m_info.m_eState) {
|
||||
|
||||
case k_ESteamNetworkingConnectionState_None:
|
||||
// NOTE: We will get callbacks here when we destroy connections. You can ignore these.
|
||||
break;
|
||||
|
||||
case k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
{
|
||||
// Ignore if they were not previously connected. (If they disconnected
|
||||
// before we accepted the connection.)
|
||||
if ( e.info->m_eOldState == k_ESteamNetworkingConnectionState_Connected )
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( e.info->m_eOldState == k_ESteamNetworkingConnectionState_Connecting );
|
||||
}
|
||||
|
||||
// Clean up the connection. This is important!
|
||||
// The connection is "closed" in the network sense, but
|
||||
// it has not been destroyed. We must close it on our end, too
|
||||
// to finish up. The reason information do not matter in this case,
|
||||
// and we cannot linger because it's already closed on the other end,
|
||||
// so we just pass 0's.
|
||||
//
|
||||
// OnDisconnect
|
||||
interface->CloseConnection( e.info->m_hConn, 0, nullptr, false );
|
||||
connection = k_HSteamNetConnection_Invalid;
|
||||
stopClient();
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connecting:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connected:
|
||||
//OnConnect
|
||||
break;
|
||||
|
||||
default:
|
||||
// Silences -Wswitch
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if(eventsToHandle & CMEventEnum::DataRecieved && type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
return true;
|
||||
} else if(eventsToHandle & CMEventEnum::DataSent && type == app->getEventType(Archimedes::DataSentEvent())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ClientModule::pollIncomingData() {
|
||||
|
||||
while(running && connection != k_HSteamNetConnection_Invalid) {
|
||||
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
||||
int numMsgs = interface->ReceiveMessagesOnConnection( connection, &pIncomingMsg, 1 );
|
||||
if ( numMsgs == 0 )
|
||||
break;
|
||||
if ( numMsgs < 0 )
|
||||
std::cerr << "Error checking for messages" << std::endl;
|
||||
assert( numMsgs == 1 && pIncomingMsg );
|
||||
assert( pIncomingMsg->m_conn == connection );
|
||||
|
||||
app->emitEvent(new Archimedes::DataRecievedEvent(pIncomingMsg));
|
||||
}
|
||||
}
|
||||
73
modules/ClientModule/ClientModule.h
Normal file
73
modules/ClientModule/ClientModule.h
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
#include "utils/Events/NetworkEvents.h"
|
||||
|
||||
class ClientModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
ClientModule(Archimedes::App*, void*);
|
||||
|
||||
ClientModule() { name = "ClientModule"; }
|
||||
|
||||
~ClientModule();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
|
||||
void startClient(SteamNetworkingIPAddr&);
|
||||
void stopClient();
|
||||
|
||||
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; }
|
||||
|
||||
bool isConnected() const { return connection != k_HSteamNetConnection_Invalid; }
|
||||
|
||||
void pollIncomingData();
|
||||
|
||||
void shouldHandleEvents(unsigned int events) { eventsToHandle = events; }
|
||||
|
||||
enum CMEventEnum {
|
||||
None = 0,
|
||||
ConnectionStatusChanged = 1 << 0,
|
||||
DataRecieved = 1 << 1,
|
||||
DataSent = 1 << 2
|
||||
};
|
||||
private:
|
||||
|
||||
unsigned int eventsToHandle = CMEventEnum::ConnectionStatusChanged | CMEventEnum::DataSent | CMEventEnum::DataRecieved;
|
||||
|
||||
bool running = false;
|
||||
|
||||
ISteamNetworkingSockets* interface;
|
||||
HSteamNetConnection connection;
|
||||
|
||||
inline static ClientModule* callbackInstance = nullptr;
|
||||
|
||||
static void SteamNetConnectionStatusChangedCallback( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
callbackInstance->OnSteamNetConnectionStatusChanged( pInfo );
|
||||
}
|
||||
|
||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
|
||||
}
|
||||
|
||||
void PollConnectionStateChanges() {
|
||||
callbackInstance = this;
|
||||
interface->RunCallbacks();
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef CLIENTMODULE_DYNAMIC
|
||||
typedef ClientModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "ClientModule.h"
|
||||
|
||||
ClientModule::ClientModule(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "ClientModule";
|
||||
}
|
||||
|
||||
ClientModule::~ClientModule() {
|
||||
GameNetworkingSockets_Kill();
|
||||
}
|
||||
|
||||
void ClientModule::onLoad() {
|
||||
SteamDatagramErrMsg errMsg;
|
||||
if ( !GameNetworkingSockets_Init( nullptr, errMsg ) ) {
|
||||
//FatalError( "GameNetworkingSockets_Init failed. %s", errMsg );
|
||||
std::cerr << "GameNetworkingSockets_Init() Failed: " << errMsg << std::endl;
|
||||
}
|
||||
|
||||
//g_logTimeZero = SteamNetworkingUtils()->GetLocalTimestamp();
|
||||
|
||||
//SteamNetworkingUtils()->SetDebugOutputFunction( k_ESteamNetworkingSocketsDebugOutputType_Msg, DebugOutput );
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
class ClientModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
ClientModule(Archimedes::App*, void*);
|
||||
~ClientModule();
|
||||
void onLoad();
|
||||
void run();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#ifdef CLIENTMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ClientModule
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
121
modules/ImguiModule/ImguiModule.cpp
Normal file
121
modules/ImguiModule/ImguiModule.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "ImguiModule.h"
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
ImguiModule::ImguiModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "ImguiModule";
|
||||
|
||||
WindowModule* wm = new WindowModule(a, h);
|
||||
deps[*wm] = wm;
|
||||
}
|
||||
|
||||
ImguiModule::~ImguiModule() {
|
||||
|
||||
if(app) {
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
|
||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||
|
||||
#if WINDOW == 2
|
||||
wm->removeEventFn(ecmd_it);
|
||||
#endif
|
||||
|
||||
rendererShutdown();
|
||||
windowShutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
wm->releaseWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
void ImguiModule::onLoad() {
|
||||
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
|
||||
if(!wm) {
|
||||
std::cout << "No WindowModule for ImguiModule!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
window = wm->aquireWindow();
|
||||
|
||||
#if RENDERER == 2
|
||||
renderer = window->getRenderer()->getRendererImpl().renderer;
|
||||
#endif
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
context = ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
||||
|
||||
#ifdef CUSTOMFONT
|
||||
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
|
||||
#endif
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//ImGui::StyleColorsLight();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
if(!windowInit())
|
||||
std::cout << "windowInit failed\n";
|
||||
|
||||
if(!rendererInit()) {
|
||||
std::cout << "rendererInit failed!\n" << std::endl;
|
||||
}
|
||||
|
||||
wm->getRenderer()->getCmdList().push_back([this](){
|
||||
ImGui::Render();
|
||||
|
||||
rendererRenderDrawData();
|
||||
|
||||
rendererNewFrame();
|
||||
windowNewFrame();
|
||||
ImGui::NewFrame();
|
||||
});
|
||||
|
||||
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
||||
|
||||
#if WINDOW == 2
|
||||
ecmd_it = wm->addEventFn([](Archimedes::Event* e){
|
||||
if(e->userData.type() == typeid(SDL_Event*)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(std::any_cast<SDL_Event*>(e->userData));
|
||||
}
|
||||
});
|
||||
#endif
|
||||
|
||||
//Compute first frame ahead of first WindowModule->run()
|
||||
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;
|
||||
}
|
||||
113
modules/ImguiModule/ImguiModule.h
Normal file
113
modules/ImguiModule/ImguiModule.h
Normal file
@@ -0,0 +1,113 @@
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
|
||||
#include "modules/WindowModule/WindowModule.h"
|
||||
|
||||
#if RENDERER == 1
|
||||
|
||||
#include "backends/imgui_impl_opengl3.h"
|
||||
|
||||
#elif RENDERER == 2
|
||||
|
||||
#include "backends/imgui_impl_sdlrenderer3.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:
|
||||
ImguiModule(Archimedes::App*, void*);
|
||||
|
||||
ImguiModule() { name = "ImguiModule"; }
|
||||
|
||||
~ImguiModule();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
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()); }
|
||||
|
||||
#elif RENDERER == 2
|
||||
SDL_Renderer* renderer;
|
||||
auto rendererInit() { return ImGui_ImplSDLRenderer3_Init(renderer); }
|
||||
void rendererShutdown() { ImGui_ImplSDLRenderer3_Shutdown(); }
|
||||
|
||||
void rendererNewFrame() { ImGui_ImplSDLRenderer3_NewFrame(); }
|
||||
void rendererRenderDrawData() { ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData(), renderer); }
|
||||
#endif
|
||||
|
||||
#if WINDOW == 1
|
||||
#if RENDERER == 1
|
||||
auto windowInit() { return ImGui_ImplGlfw_InitForOpenGL(window->getWindowImpl().getWindow(), true); }
|
||||
#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()); }
|
||||
#elif RENDERER == 2
|
||||
auto windowInit() { return ImGui_ImplSDL3_InitForSDLRenderer(window->getWindowImpl().getWindow(), renderer); }
|
||||
#endif
|
||||
|
||||
void windowShutdown() { ImGui_ImplSDL3_Shutdown(); }
|
||||
|
||||
void windowNewFrame() { ImGui_ImplSDL3_NewFrame(); }
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef IMGUIMODULE_DYNAMIC
|
||||
typedef ImguiModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
#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) {
|
||||
|
||||
name = "ImguiModule";
|
||||
|
||||
WindowModule* wm = new WindowModule(a, h);
|
||||
deps[wm->getName()] = wm;
|
||||
}
|
||||
|
||||
ImguiModule::~ImguiModule() {
|
||||
|
||||
WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"];
|
||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void ImguiModule::onLoad() {
|
||||
WindowModule* wm = (WindowModule*) moduleInstances["WindowModule"];
|
||||
|
||||
if(!wm) {
|
||||
std::cout << "No WindowModule for ImguiModule!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
context = ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
|
||||
|
||||
#ifdef CUSTOMFONT
|
||||
io.Fonts->AddFontFromFileTTF(STRINGIZE_VALUE_OF(CUSTOMFONT), 13.0f);
|
||||
#endif
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
//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;
|
||||
}
|
||||
|
||||
|
||||
wm->getRenderer()->getCmdList().push_back([](){
|
||||
ImGui::Render();
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
});
|
||||
|
||||
rcmd_it = --wm->getRenderer()->getCmdList().end()++;
|
||||
|
||||
//Compute first frame ahead of first WindowModule->run()
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef GUIMODULE
|
||||
#define GUIMODULE
|
||||
#endif
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "imgui.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
|
||||
class ImguiModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
ImguiModule(Archimedes::App*, void*);
|
||||
|
||||
~ImguiModule();
|
||||
|
||||
void onLoad();
|
||||
|
||||
bool onEvent(const Archimedes::Event& e) { return false; }
|
||||
|
||||
ImGuiContext* getContext() { return context; }
|
||||
|
||||
private:
|
||||
|
||||
ImGuiContext* context;
|
||||
|
||||
std::list<std::function<void()>>::iterator rcmd_it;
|
||||
};
|
||||
|
||||
#ifdef IMGUIMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ImguiModule
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "MainGUI.h"
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
|
||||
MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
@@ -7,23 +7,27 @@ MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "MainGUI";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[im->getName()] = im;
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
MainGUI::~MainGUI() {
|
||||
|
||||
if(app) {
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void MainGUI::onLoad() {
|
||||
|
||||
ImguiModule* im = (ImguiModule*) moduleInstances["ImguiModule"];
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for MainGUI!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->getContext());
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
}
|
||||
|
||||
@@ -43,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();
|
||||
@@ -5,6 +5,8 @@ class MainGUI : public Archimedes::Module {
|
||||
public:
|
||||
MainGUI(Archimedes::App*, void*);
|
||||
|
||||
MainGUI() { name = "MainGUI"; }
|
||||
|
||||
~MainGUI();
|
||||
|
||||
void onLoad();
|
||||
@@ -15,6 +17,6 @@ class MainGUI : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef MAINGUI_DYNAMIC
|
||||
#define MODULE_TYPE MainGUI
|
||||
typedef MainGUI mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -5,18 +5,20 @@ ServerModule::ServerModule(Archimedes::App* a, void* h) : Archimedes::Module(a,
|
||||
}
|
||||
|
||||
ServerModule::~ServerModule() {
|
||||
app->removeEventType(SMEvent::DataRecievedEvent());
|
||||
app->removeEventType(SMEvent::DataSentEvent());
|
||||
app->removeEventType(SMEvent::ConnectionStatusChangedEvent());
|
||||
if(app) {
|
||||
app->unregisterEvent(Archimedes::DataRecievedEvent());
|
||||
app->unregisterEvent(Archimedes::DataSentEvent());
|
||||
app->unregisterEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||
|
||||
GameNetworkingSockets_Kill();
|
||||
}
|
||||
}
|
||||
|
||||
void ServerModule::onLoad() {
|
||||
|
||||
app->addEventType(SMEvent::DataRecievedEvent());
|
||||
app->addEventType(SMEvent::DataSentEvent());
|
||||
app->addEventType(SMEvent::ConnectionStatusChangedEvent());
|
||||
app->registerEvent(Archimedes::DataRecievedEvent());
|
||||
app->registerEvent(Archimedes::DataSentEvent());
|
||||
app->registerEvent(Archimedes::ConnectionStatusChangedEvent());
|
||||
|
||||
SteamDatagramErrMsg errMsg;
|
||||
|
||||
@@ -28,6 +30,12 @@ void ServerModule::onLoad() {
|
||||
|
||||
interface = SteamNetworkingSockets();
|
||||
|
||||
}
|
||||
|
||||
void ServerModule::startServer(int p) {
|
||||
if(!running) {
|
||||
port = p;
|
||||
|
||||
SteamNetworkingIPAddr serverLocalAddr;
|
||||
serverLocalAddr.Clear();
|
||||
serverLocalAddr.m_port = port;
|
||||
@@ -40,14 +48,21 @@ void ServerModule::onLoad() {
|
||||
pollGroup = interface->CreatePollGroup();
|
||||
if ( pollGroup == k_HSteamNetPollGroup_Invalid )
|
||||
std::cerr << "Failed to listen on port " << port << std::endl;
|
||||
//Printf( "Server listening on port %d\n", port );
|
||||
std::cerr << "Server listening on port " << port << std::endl;
|
||||
|
||||
running = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerModule::stopServer() {
|
||||
disconnectAllClients();
|
||||
running = false;
|
||||
}
|
||||
|
||||
void ServerModule::run() {
|
||||
if(running) {
|
||||
PollIncomingMessages();
|
||||
pollIncomingData();
|
||||
PollConnectionStateChanges();
|
||||
PollLocalUserInput();
|
||||
} else if(port >= 0) {
|
||||
|
||||
interface->CloseListenSocket(listenSock);
|
||||
@@ -56,20 +71,18 @@ void ServerModule::run() {
|
||||
interface->DestroyPollGroup(pollGroup);
|
||||
pollGroup = k_HSteamNetPollGroup_Invalid;
|
||||
|
||||
app->stopModule(getName());
|
||||
port = -1; //just in case
|
||||
port = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerModule::OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
app->emitEvent(new SMEvent::ConnectionStatusChangedEvent(pInfo));
|
||||
}
|
||||
|
||||
bool ServerModule::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
if(eventsToHandle & SMEventEnum::ConnectionStatusChanged && app->getEventType(event) == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event;
|
||||
if(eventsToHandle & SMEventEnum::ConnectionStatusChanged && type == app->getEventType(Archimedes::ConnectionStatusChangedEvent())) {
|
||||
|
||||
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
switch(e.info->m_info.m_eState) {
|
||||
|
||||
@@ -93,18 +106,18 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
// Select appropriate log messages
|
||||
//const char *pszDebugLogAction;
|
||||
if ( e.info->m_info.m_eState == k_ESteamNetworkingConnectionState_ProblemDetectedLocally )
|
||||
/*if ( e.info->m_info.m_eState == k_ESteamNetworkingConnectionState_ProblemDetectedLocally )
|
||||
{
|
||||
//pszDebugLogAction = "problem detected locally";
|
||||
//sprintf( temp, "Alas, %s hath fallen into shadow. (%s)", itClient->second.name.c_str(), e.info->m_info.m_szEndDebug );
|
||||
pszDebugLogAction = "problem detected locally";
|
||||
sprintf( temp, "Alas, %s hath fallen into shadow. (%s)", itClient->second.name.c_str(), e.info->m_info.m_szEndDebug );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Note that here we could check the reason code to see if
|
||||
// it was a "usual" connection or an "unusual" one.
|
||||
//pszDebugLogAction = "closed by peer"; (void)pszDebugLogAction;
|
||||
//sprintf( temp, "%s hath departed", itClient->second.name.c_str() );
|
||||
}
|
||||
pszDebugLogAction = "closed by peer"; (void)pszDebugLogAction;
|
||||
sprintf( temp, "%s hath departed", itClient->second.name.c_str() );
|
||||
}*/
|
||||
|
||||
// Spew something to our own log. Note that because we put their nick
|
||||
// as the connection description, it will show up, along with their
|
||||
@@ -133,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;
|
||||
}
|
||||
|
||||
@@ -154,6 +168,7 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
|
||||
//Printf( "Can't accept connection. (It was already closed?)" );
|
||||
break;
|
||||
}
|
||||
std::cerr << "Connection Accepted!\n";
|
||||
|
||||
// Assign the poll group
|
||||
if ( !interface->SetConnectionPollGroup( e.info->m_hConn, pollGroup ) )
|
||||
@@ -180,12 +195,29 @@ bool ServerModule::onEvent(const Archimedes::Event& event) {
|
||||
}
|
||||
return true;
|
||||
|
||||
} else if(eventsToHandle & SMEventEnum::DataRecieved && app->getEventType(event) == app->getEventType("DataRecievedEvent")) {
|
||||
} else if(eventsToHandle & SMEventEnum::DataRecieved && type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
return true;
|
||||
} else if(eventsToHandle & SMEventEnum::DataSent && app->getEventType(event) == app->getEventType("DataSentEvent")) {
|
||||
} else if(eventsToHandle & SMEventEnum::DataSent && type == app->getEventType(Archimedes::DataSentEvent())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ServerModule::pollIncomingData() {
|
||||
|
||||
while ( running )
|
||||
{
|
||||
ISteamNetworkingMessage *pIncomingMsg = nullptr;
|
||||
int numMsgs = interface->ReceiveMessagesOnPollGroup( pollGroup, &pIncomingMsg, 1 );
|
||||
if ( numMsgs == 0 )
|
||||
break;
|
||||
if ( numMsgs < 0 )
|
||||
std::cerr << "Error checking for messages" << std::endl;
|
||||
assert( numMsgs == 1 && pIncomingMsg );
|
||||
auto itClient = clients.find( pIncomingMsg->m_conn );
|
||||
assert( itClient != clients.end() );
|
||||
|
||||
app->emitEvent(new Archimedes::DataRecievedEvent(pIncomingMsg));
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,20 @@
|
||||
#ifndef SERVERMODULE_H
|
||||
#define SERVERMODULE_H
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
#include "ServerEvents.h"
|
||||
#include "utils/Events/NetworkEvents.h"
|
||||
|
||||
class ServerModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
ServerModule(Archimedes::App*, void*);
|
||||
|
||||
ServerModule() { name = "ServerModule"; }
|
||||
|
||||
~ServerModule();
|
||||
void onLoad();
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
@@ -24,9 +30,35 @@ class ServerModule : public Archimedes::Module {
|
||||
DataSent = 1 << 2
|
||||
};
|
||||
|
||||
bool isRunning() const { return running; }
|
||||
|
||||
void shouldHandleEvents(unsigned int events) { eventsToHandle = events; }
|
||||
|
||||
void sendData() {}
|
||||
void sendReliable(HSteamNetConnection client, const void* data, uint32 byteCount) {
|
||||
interface->SendMessageToConnection(client, data, byteCount, k_nSteamNetworkingSend_Reliable, nullptr);
|
||||
|
||||
}
|
||||
|
||||
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(unsigned int* num = nullptr) const {
|
||||
if(num) {
|
||||
*num = numClients;
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
|
||||
void pollIncomingData();
|
||||
|
||||
private:
|
||||
@@ -48,16 +80,21 @@ class ServerModule : public Archimedes::Module {
|
||||
callbackInstance->OnSteamNetConnectionStatusChanged( pInfo );
|
||||
}
|
||||
|
||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo );
|
||||
|
||||
void OnSteamNetConnectionStatusChanged( SteamNetConnectionStatusChangedCallback_t *pInfo ) {
|
||||
app->emitEvent(new Archimedes::ConnectionStatusChangedEvent(pInfo));
|
||||
}
|
||||
|
||||
std::map<HSteamNetConnection, unsigned int> clients;
|
||||
|
||||
void PollConnectionStateChanges();
|
||||
void PollLocalUserInput();
|
||||
void PollConnectionStateChanges() {
|
||||
callbackInstance = this;
|
||||
interface->RunCallbacks();
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef SERVERMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ServerModule
|
||||
typedef ServerModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,59 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
|
||||
|
||||
namespace SMEvent {
|
||||
class DataRecievedEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
DataRecievedEvent() : clientID(0), buffer(nullptr), size(0) {}
|
||||
|
||||
DataRecievedEvent(unsigned int c, void* buf, unsigned int s) : clientID(c), buffer(buf), size(s) {}
|
||||
|
||||
operator std::string() const { return "DataRecievedEvent"; }
|
||||
|
||||
unsigned int clientID;
|
||||
|
||||
void* buffer;
|
||||
|
||||
unsigned int size;
|
||||
|
||||
};
|
||||
|
||||
class DataSentEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
DataSentEvent() : clientID(0), buffer(nullptr), size(0) {}
|
||||
|
||||
DataSentEvent(unsigned int c, void* buf, unsigned int s) : clientID(c), buffer(buf), size(s) {}
|
||||
|
||||
operator std::string() const { return "DataSentEvent"; }
|
||||
|
||||
unsigned int clientID;
|
||||
|
||||
void* buffer;
|
||||
|
||||
unsigned int size;
|
||||
|
||||
};
|
||||
|
||||
class ConnectionStatusChangedEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
ConnectionStatusChangedEvent() : info(nullptr) {}
|
||||
|
||||
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : info(i) {}
|
||||
|
||||
operator std::string() const { return "ConnectionStatusChangedEvent"; }
|
||||
|
||||
SteamNetConnectionStatusChangedCallback_t* info;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
97
modules/WindowModule/WindowModule.cpp
Normal file
97
modules/WindowModule/WindowModule.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "WindowModule.h"
|
||||
|
||||
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)
|
||||
releaseWindow(window);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowModule::onLoad() {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void WindowModule::run() {
|
||||
|
||||
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;
|
||||
#if WINDOW == 2
|
||||
window->getWindowImpl().setSize(event.width, event.height);
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
87
modules/WindowModule/WindowModule.h
Normal file
87
modules/WindowModule/WindowModule.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef WINDOWMODULE_H
|
||||
#define WINDOWMODULE_H
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
#include "utils/Window/Window.h"
|
||||
|
||||
static_assert(!(WINDOW == 1 && RENDERER == 2), "Window and Renderer are incompatible!\n");
|
||||
|
||||
class WindowModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
WindowModule(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "WindowModule";
|
||||
}
|
||||
|
||||
WindowModule() { name = "WindowModule"; }
|
||||
|
||||
~WindowModule() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event& e) override;
|
||||
|
||||
//interface for other modules
|
||||
|
||||
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(window->getWindowImpl().getWindow())) {
|
||||
std::cout << "Renderer init failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
windowRefs++;
|
||||
#if RENDERER == 1
|
||||
window->getWindowImpl().restoreContext();
|
||||
#endif
|
||||
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:
|
||||
|
||||
int windowRefs = 0;
|
||||
|
||||
std::list<std::function<void(Archimedes::Event*)>> eventFuncs;
|
||||
|
||||
Archimedes::Window* window = nullptr;
|
||||
Archimedes::Renderer* renderer = nullptr;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#ifdef WINDOWMODULE_DYNAMIC
|
||||
typedef WindowModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "WindowModule.h"
|
||||
|
||||
WindowModule::~WindowModule() {
|
||||
if(renderer) {
|
||||
renderer->getCmdList().clear();
|
||||
delete renderer;
|
||||
}
|
||||
if(window) {
|
||||
delete window;
|
||||
}
|
||||
}
|
||||
|
||||
void WindowModule::onLoad() {
|
||||
|
||||
window = new Archimedes::Window();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
window->doFrame();
|
||||
}
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
#ifndef WINDOWMODULE_H
|
||||
#define WINDOWMODULE_H
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
#include "utils/Window/Window.h"
|
||||
|
||||
class WindowModule : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
WindowModule(Archimedes::App* a, void* h = nullptr) : Archimedes::Module(a, h) {
|
||||
name = "WindowModule";
|
||||
}
|
||||
|
||||
|
||||
~WindowModule();
|
||||
|
||||
void run();
|
||||
|
||||
void onLoad();
|
||||
|
||||
//interface for other modules
|
||||
|
||||
Archimedes::Window* getWindow() { return window; }
|
||||
Archimedes::Renderer* getRenderer() { return renderer; }
|
||||
|
||||
private:
|
||||
|
||||
Archimedes::Window* window;
|
||||
Archimedes::Renderer* renderer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#ifdef WINDOWMODULE_DYNAMIC
|
||||
#define MODULE_TYPE WindowModule
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
#include "DependsOnPrint.h"
|
||||
|
||||
DependsOnPrint::DependsOnPrint(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
name = "DependsOnPrint";
|
||||
|
||||
deps["Print"] = "/home/nathan/Projects/Archimedes/result-1/bin/Print";
|
||||
}
|
||||
|
||||
DependsOnPrint::~DependsOnPrint() {
|
||||
std::cout << "DependsOnPrint Destroyed!\n";
|
||||
}
|
||||
|
||||
void DependsOnPrint::run() {
|
||||
std::cout << "DependsOnPrint lib loaded and run!\n";
|
||||
app->stopModule(name);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class DependsOnPrint : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
DependsOnPrint(Archimedes::App*, void*);
|
||||
~DependsOnPrint();
|
||||
void run();
|
||||
void onLoad() {}
|
||||
|
||||
};
|
||||
|
||||
#ifdef DEPENDSONPRINT_DYNAMIC
|
||||
#define MODULE_TYPE DependsOnPrint
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
#include "DependsOnPrintStatic.h"
|
||||
|
||||
#include "modules/examples/Print/src/Print.h"
|
||||
|
||||
DependsOnPrintStatic::DependsOnPrintStatic(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
name = "DependsOnPrintStatic";
|
||||
|
||||
deps["Print"] = new Print(a, h);
|
||||
}
|
||||
|
||||
DependsOnPrintStatic::~DependsOnPrintStatic() {
|
||||
std::cout << "DependsOnPrintStatic Destroyed!\n";
|
||||
}
|
||||
|
||||
void DependsOnPrintStatic::run() {
|
||||
std::cout << "DependsOnPrintStatic lib loaded and run!\n";
|
||||
app->stopModule(name);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class DependsOnPrintStatic : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
DependsOnPrintStatic(Archimedes::App*, void*);
|
||||
~DependsOnPrintStatic();
|
||||
void run();
|
||||
void onLoad() {}
|
||||
|
||||
};
|
||||
|
||||
#ifdef DEPENDSONPRINTSTATIC_DYNAMIC
|
||||
#define MODULE_TYPE DependsOnPrintStatic
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,37 +0,0 @@
|
||||
#include "TestMenu.h"
|
||||
|
||||
TestMenu::TestMenu(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
name = "TestMenu";
|
||||
}
|
||||
|
||||
TestMenu::~TestMenu() {
|
||||
std::cout << "TestMenu Destroyed!\n";
|
||||
}
|
||||
|
||||
void TestMenu::run() {
|
||||
|
||||
std::cout << "Your number is: " << num << "\n"
|
||||
<< "1. Add 1\n"
|
||||
<< "2. Subtract 1\n"
|
||||
<< "3. Unload Module\n\n"
|
||||
<< "4. Quit\n\n";
|
||||
|
||||
std::cin >> choice;
|
||||
|
||||
switch(choice) {
|
||||
case 1:
|
||||
num++;
|
||||
break;
|
||||
case 2:
|
||||
num--;
|
||||
break;
|
||||
case 3:
|
||||
app->stopModule(name);
|
||||
break;
|
||||
case 4:
|
||||
app->end();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class TestMenu : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestMenu(Archimedes::App*, void*);
|
||||
~TestMenu();
|
||||
void run();
|
||||
void onLoad() {}
|
||||
|
||||
private:
|
||||
int choice;
|
||||
int num = 5;
|
||||
};
|
||||
|
||||
#ifdef TESTMENU_DYNAMIC
|
||||
#define MODULE_TYPE TestMenu
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,13 +1,15 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/examples/TestImgui/src/TestImgui.h"
|
||||
#include "modules/Archimedes-Modules/TestImgui/TestImgui.h"
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ void MinimalApp::run() {
|
||||
modules[m]->onLoad();
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
while (!done && !runOrder.empty()) {
|
||||
|
||||
@@ -13,6 +14,8 @@ void MinimalApp::run() {
|
||||
modules[m]->run();
|
||||
}
|
||||
|
||||
handleEvents();
|
||||
|
||||
for(std::string m : toClose) {
|
||||
unload(m);
|
||||
}
|
||||
@@ -34,3 +37,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:
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/Terminal/src/Terminal.h"
|
||||
#include "modules/Archimedes-Modules/Terminal/Terminal.h"
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user