Compare commits
137 Commits
9147787fd2
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| f75a438422 | |||
| 7a2131fc93 | |||
| a5c21ea30d | |||
| ce43c56ea6 | |||
| 74c980adb0 | |||
| fec99fc737 | |||
| da1292d9e5 | |||
| e9f1f49416 | |||
| fda88a906b | |||
| 5fd5eb892b | |||
| 6abcaeb0d1 | |||
| a422e5cfa2 | |||
| c25ed1949d | |||
| 2899932f7f | |||
| 0ab0f4af47 | |||
| d6f8036175 | |||
| f01bd49fb1 | |||
| 874de65dba | |||
| f9f311c82b | |||
| ec8a9c9f4f | |||
| 6c33eada03 | |||
| badb3c4ec8 | |||
| 0244f463c4 | |||
| 1f22a661cd | |||
| 80d64f5114 | |||
| 3c593edeca | |||
| 263f0201ca | |||
| 65e15ecfa4 | |||
| 7d777c9578 | |||
| 874a8a1115 | |||
| e4d84686c4 | |||
| 914de55f85 | |||
| 6dba251457 | |||
| dd1befc2a0 | |||
| 086e5f5126 | |||
| f277dee1f7 | |||
| bad4bd70bc | |||
| b97957ec53 | |||
| bedd7a5dfd | |||
| 89ea39ee60 | |||
| e7544e1cc1 | |||
| 98f990cb57 | |||
| 9b0be39b91 | |||
| 9a89ab3bbc | |||
| 8b0192c9b8 | |||
| 8581589bfe | |||
| 9dfabc6dae | |||
| 3f102638b0 | |||
| 5ab345460c | |||
| e67df40233 | |||
| 07b4518cb4 | |||
| 43d950b035 | |||
| 78a8c9bf95 | |||
| 7a45547ad9 | |||
| 21080c5c63 | |||
| 68524696df | |||
| 8c0cba9397 | |||
| afe6254317 | |||
| e38a83e521 | |||
| 7517ee8593 | |||
| 148ed1253c | |||
| cd19db0b88 | |||
| 246db7fc73 | |||
| 1cea44a84a | |||
| eaaa30ca90 | |||
| 889b852f5f | |||
| 9716a8ec46 | |||
| 7a73c3fc72 | |||
| c069267c7e | |||
| 6459d880c3 | |||
| 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 |
10
.ccls
Normal file
10
.ccls
Normal file
@@ -0,0 +1,10 @@
|
||||
clang++
|
||||
-Isrc/include
|
||||
-Isrc
|
||||
-Ivendor/imgui
|
||||
-Ivendor/notcurses/include
|
||||
-Ivendor/GameNetworkingSockets/include
|
||||
-DWINDOW_GLFW
|
||||
-DWINDOW_SDL3
|
||||
-DRENDERER_OPENGL
|
||||
-DRENDERER_SDL3
|
||||
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
vendor/
|
||||
.ccls-cache/
|
||||
imgui.ini
|
||||
result*
|
||||
115
ExampleApps.nix
115
ExampleApps.nix
@@ -1,115 +0,0 @@
|
||||
{ inputs, pkgs, ... }: {
|
||||
|
||||
MinimalApp = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
/*buildInputs = with pkgs; [
|
||||
];*/
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/MinimalApp/MinimalApp.cpp \
|
||||
-I src -I include \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/ImguiEmbed/*.cpp \
|
||||
modules/examples/TestImgui/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.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 . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
TerminalEmbed = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/TerminalEmbed/*.cpp \
|
||||
modules/Terminal/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.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 . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
{ inputs, pkgs, ... }: {
|
||||
|
||||
TestMenu = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "TestMenu";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestMenu/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src \
|
||||
-Wall \
|
||||
-DTESTMENU_DYNAMIC \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
TestNotCurses = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "TestNotCurses";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
notcurses
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestNotCurses/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-Wall \
|
||||
-lnotcurses \
|
||||
-DTESTNOTCURSES_DYNAMIC \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
Print = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Print";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/Print/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-Wall \
|
||||
-DPRINT_DYNAMIC \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
DependsOnPrint = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "DependsOnPrint";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/DependsOnPrint/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-Wall \
|
||||
-DDEPENDSONPRINT_DYNAMIC \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
DependsOnPrintStatic = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "DependsOnPrintStatic";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/DependsOnPrintStatic/src/*.cpp \
|
||||
modules/examples/Print/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include -I . \
|
||||
-DDEPENDSONPRINTSTATIC_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
TestImgui = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "TestImgui";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestImgui/src/*.cpp \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DTESTIMGUI_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
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
TestClay = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "TestClay";
|
||||
|
||||
src = ./.;
|
||||
|
||||
clay = inputs.clay;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/TestClay/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DTESTCLAY_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ChatServer = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatServer";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/examples/ChatServer/src/*.cpp \
|
||||
modules/ServerModule/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-I src -I include -I . \
|
||||
-lGameNetworkingSockets \
|
||||
-DCHATSERVER_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/examples/ChatClient/src/*.cpp \
|
||||
modules/ClientModule/src/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DCHATCLIENT_DYNAMIC \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
modules/ImguiModule/src/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-fpic -shared \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
}
|
||||
17
dev/overlays.nix
Normal file
17
dev/overlays.nix
Normal file
@@ -0,0 +1,17 @@
|
||||
{ self, inputs, ... }: {
|
||||
|
||||
flake.overlays.glfw-old = (final: prev: let
|
||||
pkgs-old = import inputs.nixpkgs-old { system = prev.stdenv.hostPlatform.system; };
|
||||
in { glfw = pkgs-old.glfw; });
|
||||
|
||||
perSystem = { lib, system, pkgs, ... }: {
|
||||
_module.args.pkgs = import inputs.nixpkgs {
|
||||
inherit system;
|
||||
overlays = [
|
||||
self.overlays.glfw-old
|
||||
];
|
||||
|
||||
config = {};
|
||||
};
|
||||
};
|
||||
}
|
||||
110
dev/shells.nix
Normal file
110
dev/shells.nix
Normal file
@@ -0,0 +1,110 @@
|
||||
{ ... }: {
|
||||
|
||||
perSystem = { config, system, pkgs, self', inputs', ... }: {
|
||||
|
||||
devShells = {
|
||||
bash = pkgs.mkShellNoCC {
|
||||
|
||||
packages = with pkgs; [
|
||||
clang
|
||||
|
||||
glfw
|
||||
glew
|
||||
|
||||
sdl3
|
||||
|
||||
curl
|
||||
glm
|
||||
nlohmann_json
|
||||
stb
|
||||
|
||||
gamenetworkingsockets
|
||||
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
nvim-bash = pkgs.mkShellNoCC {
|
||||
|
||||
packages = with pkgs; [
|
||||
clang
|
||||
|
||||
glfw
|
||||
glew
|
||||
|
||||
sdl3
|
||||
|
||||
curl
|
||||
glm
|
||||
nlohmann_json
|
||||
stb
|
||||
|
||||
gamenetworkingsockets
|
||||
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
exec nvim
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
zsh = pkgs.mkShellNoCC {
|
||||
|
||||
packages = with pkgs; [
|
||||
clang
|
||||
|
||||
glfw
|
||||
glew
|
||||
|
||||
sdl3
|
||||
|
||||
curl
|
||||
glm
|
||||
nlohmann_json
|
||||
stb
|
||||
|
||||
gamenetworkingsockets
|
||||
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export SHELL=$(realpath `which zsh`)
|
||||
exec zsh
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
nvim-zsh = pkgs.mkShellNoCC {
|
||||
|
||||
packages = with pkgs; [
|
||||
clang
|
||||
|
||||
glfw
|
||||
glew
|
||||
|
||||
sdl3
|
||||
|
||||
curl
|
||||
glm
|
||||
nlohmann_json
|
||||
stb
|
||||
|
||||
gamenetworkingsockets
|
||||
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export SHELL=$(realpath `which zsh`)
|
||||
exec nvim
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
default = self'.devShells.bash;
|
||||
};
|
||||
};
|
||||
}
|
||||
6
dev/systems.nix
Normal file
6
dev/systems.nix
Normal file
@@ -0,0 +1,6 @@
|
||||
{ ... }: {
|
||||
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
];
|
||||
}
|
||||
89
flake.lock
generated
Executable file → Normal file
89
flake.lock
generated
Executable file → Normal file
@@ -3,11 +3,11 @@
|
||||
"clay": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1742509368,
|
||||
"narHash": "sha256-XSaMuWCADZgZnRaGcBgf+u40O6jS5kkpq3Xruy6z+I0=",
|
||||
"lastModified": 1767081147,
|
||||
"narHash": "sha256-DbNZXjHAl2cmsWtDyw8BpW6dF7VoWHZ9EvQytSpqaKI=",
|
||||
"owner": "nicbarker",
|
||||
"repo": "clay",
|
||||
"rev": "ad49977f1b37ccd7664333181f30f575d08d3838",
|
||||
"rev": "76ec3632d80c145158136fd44db501448e7b17c4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -16,14 +16,32 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1769996383,
|
||||
"narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "57928607ea566b5db3ad13af0e57e921e6b12381",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"imgui": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1741968903,
|
||||
"narHash": "sha256-4L37NRR+dlkhdxuDjhLR45kgjyZK2uelKBlGZ1nQzgY=",
|
||||
"lastModified": 1770923283,
|
||||
"narHash": "sha256-EOhlmnhoJRNjU7o7aCXnRrOw7JM0nq0VWDVnUJ6A6Xo=",
|
||||
"owner": "ocornut",
|
||||
"repo": "imgui",
|
||||
"rev": "126d004f9e1eef062bf4b044b3b2faaf58d48c51",
|
||||
"rev": "3fb22b836ba968c62d280d9de079ec5ed7fcd1b5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -33,18 +51,64 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"import-tree": {
|
||||
"locked": {
|
||||
"lastModified": 1771045967,
|
||||
"narHash": "sha256-oYO4poyw0Sb/db2PigqugMlDwsvwLg6CSpFrMUWxA3Q=",
|
||||
"owner": "vic",
|
||||
"repo": "import-tree",
|
||||
"rev": "c968d3b54d12cf5d9c13f16f7c545a06c9d1fde6",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "vic",
|
||||
"repo": "import-tree",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1742136038,
|
||||
"narHash": "sha256-DDe16FJk18sadknQKKG/9FbwEro7A57tg9vB5kxZ8kY=",
|
||||
"lastModified": 1770770419,
|
||||
"narHash": "sha256-iKZMkr6Cm9JzWlRYW/VPoL0A9jVKtZYiU4zSrVeetIs=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a1185f4064c18a5db37c5c84e5638c78b46e3341",
|
||||
"rev": "6c5e707c6b5339359a9a9e215c5e66d6d802fd7a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-24.11",
|
||||
"ref": "nixos-25.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"lastModified": 1769909678,
|
||||
"narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=",
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"rev": "72716169fe93074c333e8d0173151350670b824c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "nixpkgs.lib",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-old": {
|
||||
"locked": {
|
||||
"lastModified": 1720535198,
|
||||
"narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-23.11",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
@@ -52,8 +116,11 @@
|
||||
"root": {
|
||||
"inputs": {
|
||||
"clay": "clay",
|
||||
"flake-parts": "flake-parts",
|
||||
"imgui": "imgui",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"import-tree": "import-tree",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"nixpkgs-old": "nixpkgs-old"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
313
flake.nix
Executable file → Normal file
313
flake.nix
Executable file → Normal file
@@ -2,7 +2,8 @@
|
||||
description = "Build Project Archimedes";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
|
||||
nixpkgs-old.url = "github:nixos/nixpkgs/nixos-23.11"; # Until Dear ImGUI has multi viewports on wayland
|
||||
imgui = {
|
||||
url = "github:ocornut/imgui?ref=docking";
|
||||
flake = false;
|
||||
@@ -11,307 +12,17 @@
|
||||
url = "github:nicbarker/clay";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
|
||||
import-tree.url = "github:vic/import-tree";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, imgui, clay }@inputs: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in {
|
||||
outputs = { self, flake-parts, import-tree, ... } @ inputs:
|
||||
flake-parts.lib.mkFlake {
|
||||
inputs = inputs // {
|
||||
src = ./src;
|
||||
};
|
||||
} (import-tree [ ./src ./dev ]);
|
||||
|
||||
Archimedes = {
|
||||
examples = import ./ExampleApps.nix { inherit inputs; inherit pkgs; };
|
||||
};
|
||||
|
||||
Modules = {
|
||||
examples = import ./ExampleModules.nix { inherit inputs; inherit pkgs; };
|
||||
|
||||
ServerModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ServerModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/ServerModule/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DSERVERMODULE_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ClientModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ClientModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
gamenetworkingsockets
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/ClientModule/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
-DCLIENTMODULE_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
WindowModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "WindowModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/WindowModule/src/*.cpp \
|
||||
-fpic -shared \
|
||||
-I src -I include \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DWINDOWMODULE_DYNAMIC \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
ImguiModule = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ImguiModule";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
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 \
|
||||
-DIMGUIMODULE_DYNAMIC \
|
||||
-DCUSTOMFONT=${pkgs.fira-code}/share/fonts/truetype/FiraCode-VF.ttf \
|
||||
-fpic -shared \
|
||||
-I src -I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
MainGUI = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "MainGUI";
|
||||
|
||||
src = ./.;
|
||||
|
||||
inherit imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/MainGUI/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 \
|
||||
-DMAINGUI_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
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
apps.${system}.default = {
|
||||
type = "app";
|
||||
program = "${self.Archimedes.examples.MinimalApp}/bin/Archimedes";
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#ifdef MODULE_TYPE
|
||||
|
||||
extern "C" {
|
||||
Archimedes::Module* create(Archimedes::App* app, void* handle) {
|
||||
return new MODULE_TYPE(app, handle);
|
||||
}
|
||||
}
|
||||
|
||||
#undef MODULE_TYPE
|
||||
#endif
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include "pch.hpp"
|
||||
#include "RendererOpenGL/RendererOpenGL.h"
|
||||
|
||||
namespace Archimedes {
|
||||
class Renderer {
|
||||
|
||||
public:
|
||||
int w, h;
|
||||
|
||||
~Renderer() {}
|
||||
|
||||
bool init() { return r.init(); }
|
||||
|
||||
void render() {
|
||||
r.render(rc, w, h);
|
||||
}
|
||||
|
||||
std::list<std::function<void()>>& getCmdList() {
|
||||
return rc;
|
||||
}
|
||||
|
||||
private:
|
||||
std::list<std::function<void()>> rc;
|
||||
RendererImpl r;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,40 +0,0 @@
|
||||
#ifdef RENDERER_OPENGL
|
||||
#undef RENDERER_OPENGL
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class RendererOpenGL {
|
||||
|
||||
public:
|
||||
typedef void renderCmd();
|
||||
|
||||
RendererOpenGL() {};
|
||||
~RendererOpenGL() {};
|
||||
|
||||
bool init() {
|
||||
return glewInit() == GLEW_OK;
|
||||
};
|
||||
|
||||
void render(std::list<std::function<void()>> cmdList, int& w, int& h) {
|
||||
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
for(auto f : cmdList)
|
||||
f();
|
||||
}
|
||||
};
|
||||
|
||||
typedef RendererOpenGL RendererImpl;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
#include "WindowGLFW/WindowGLFW.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Window {
|
||||
|
||||
public:
|
||||
|
||||
Window() {}
|
||||
|
||||
~Window() {}
|
||||
|
||||
bool shouldClose() { return window.shouldClose(); }
|
||||
|
||||
void doFrame() {
|
||||
|
||||
window.pollEvents();
|
||||
|
||||
window.getSize(renderer->w, renderer->h);
|
||||
|
||||
renderer->render();
|
||||
|
||||
window.doFrame();
|
||||
}
|
||||
|
||||
Renderer* getRenderer() { return renderer; }
|
||||
void setRenderer(Renderer* r) { renderer = r; }
|
||||
|
||||
WindowImpl& getWindowImpl() { return window; }
|
||||
|
||||
private:
|
||||
Renderer* renderer;
|
||||
|
||||
WindowImpl window;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,65 +0,0 @@
|
||||
#include "pch.hpp"
|
||||
|
||||
#ifdef WINDOW_GLFW
|
||||
#undef WINDOW_GLFW
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class WindowGLFW {
|
||||
|
||||
public:
|
||||
|
||||
WindowGLFW() {
|
||||
|
||||
glfwSetErrorCallback([](int e, const char* m){
|
||||
std::cout << "GLFW Error: " << m << std::endl;
|
||||
});
|
||||
|
||||
if(!glfwInit()) {
|
||||
std::cout << "glfwInit failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
w = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
|
||||
|
||||
if(!w) {
|
||||
glfwTerminate();
|
||||
std::abort();
|
||||
}
|
||||
glfwMakeContextCurrent(w);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
}
|
||||
|
||||
~WindowGLFW() {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
bool shouldClose() {
|
||||
return glfwWindowShouldClose(w);
|
||||
}
|
||||
|
||||
void doFrame() { restoreContext(); glfwSwapBuffers(w); }
|
||||
|
||||
void pollEvents() { glfwPollEvents(); }
|
||||
|
||||
void restoreContext() { glfwMakeContextCurrent(w); }
|
||||
|
||||
void getSize(int& w, int& h) {
|
||||
glfwGetFramebufferSize(this->w, &w, &h);
|
||||
}
|
||||
|
||||
GLFWwindow* getWindow() { return w; }
|
||||
|
||||
private:
|
||||
GLFWwindow* w;
|
||||
};
|
||||
|
||||
typedef WindowGLFW WindowImpl;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,55 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
|
||||
|
||||
namespace CMEvent {
|
||||
class DataRecievedEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
DataRecievedEvent() : msg(nullptr) {}
|
||||
|
||||
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
|
||||
|
||||
~DataRecievedEvent() {
|
||||
if(msg)
|
||||
msg->Release();
|
||||
}
|
||||
|
||||
operator std::string() const { return "CMEvent::DataRecievedEvent"; }
|
||||
|
||||
ISteamNetworkingMessage* msg;
|
||||
|
||||
};
|
||||
|
||||
class DataSentEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
DataSentEvent() : msg(nullptr) {}
|
||||
|
||||
DataSentEvent(ISteamNetworkingMessage* m) : msg(m) {}
|
||||
|
||||
operator std::string() const { return "CMEvent::DataSentEvent"; }
|
||||
|
||||
ISteamNetworkingMessage* msg;
|
||||
};
|
||||
|
||||
class ConnectionStatusChangedEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
ConnectionStatusChangedEvent() : info(nullptr) {}
|
||||
|
||||
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : info(i) {}
|
||||
|
||||
operator std::string() const { return "CMEvent::ConnectionStatusChangedEvent"; }
|
||||
|
||||
SteamNetConnectionStatusChangedCallback_t* info;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,82 +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] = wm;
|
||||
}
|
||||
|
||||
ImguiModule::~ImguiModule() {
|
||||
|
||||
if(app) {
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
|
||||
wm->getRenderer()->getCmdList().erase(rcmd_it);
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
}
|
||||
|
||||
void ImguiModule::onLoad() {
|
||||
|
||||
WindowModule* wm; { 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,35 +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() { name = "ImguiModule"; }
|
||||
|
||||
~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,60 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
|
||||
|
||||
namespace SMEvent {
|
||||
class DataRecievedEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
DataRecievedEvent() : msg(nullptr) {}
|
||||
|
||||
~DataRecievedEvent() {
|
||||
if(msg)
|
||||
msg->Release();
|
||||
}
|
||||
|
||||
DataRecievedEvent(ISteamNetworkingMessage* m) : msg(m) {}
|
||||
|
||||
operator std::string() const { return "SMEvent::DataRecievedEvent"; }
|
||||
|
||||
ISteamNetworkingMessage* msg;
|
||||
|
||||
};
|
||||
|
||||
class DataSentEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
DataSentEvent() : msg(nullptr) {}
|
||||
|
||||
~DataSentEvent() {
|
||||
if(msg)
|
||||
msg->Release();
|
||||
}
|
||||
|
||||
DataSentEvent(ISteamNetworkingMessage* m) : msg(m) {}
|
||||
|
||||
operator std::string() const { return "SMEvent::DataSentEvent"; }
|
||||
|
||||
ISteamNetworkingMessage* msg;
|
||||
};
|
||||
|
||||
class ConnectionStatusChangedEvent : public Archimedes::Event {
|
||||
|
||||
public:
|
||||
|
||||
ConnectionStatusChangedEvent() : info(nullptr) {}
|
||||
|
||||
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : info(i) {}
|
||||
|
||||
operator std::string() const { return "SMEvent::ConnectionStatusChangedEvent"; }
|
||||
|
||||
SteamNetConnectionStatusChangedCallback_t* info;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "WindowModule.h"
|
||||
|
||||
WindowModule::~WindowModule() {
|
||||
if(app) {
|
||||
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,42 +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) : Archimedes::Module(a, h) {
|
||||
name = "WindowModule";
|
||||
}
|
||||
|
||||
WindowModule() { 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,19 +0,0 @@
|
||||
#include "DependsOnPrintStatic.h"
|
||||
|
||||
#include "modules/examples/Print/src/Print.h"
|
||||
|
||||
DependsOnPrintStatic::DependsOnPrintStatic(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
name = "DependsOnPrintStatic";
|
||||
|
||||
Print* p = new Print(a, h);
|
||||
deps[*p] = p;
|
||||
}
|
||||
|
||||
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,20 +0,0 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class TestMenu : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestMenu(Archimedes::App*, void*);
|
||||
TestMenu() { name = "TestMenu"; }
|
||||
~TestMenu();
|
||||
void run();
|
||||
void onLoad() {}
|
||||
|
||||
private:
|
||||
int choice;
|
||||
int num = 5;
|
||||
};
|
||||
|
||||
#ifdef TESTMENU_DYNAMIC
|
||||
#define MODULE_TYPE TestMenu
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,31 +1,71 @@
|
||||
#include "ImguiEmbed.h"
|
||||
|
||||
bool ImguiEmbed::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;
|
||||
}
|
||||
|
||||
void ImguiEmbed::run() {
|
||||
|
||||
for(auto m : runOrder)
|
||||
for(std::string m : runOrder) {
|
||||
modules[m]->onLoad();
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
while (!done && !runOrder.empty()) {
|
||||
|
||||
for(auto m : runOrder) {
|
||||
for(std::string m : runOrder) {
|
||||
modules[m]->run();
|
||||
}
|
||||
|
||||
for(auto m : toClose) {
|
||||
handleEvents();
|
||||
|
||||
for(std::string m : toClose) {
|
||||
unload(m);
|
||||
}
|
||||
toClose.clear();
|
||||
|
||||
for(auto m : toOpen) {
|
||||
static Archimedes::Module* n;
|
||||
if(std::holds_alternative<std::string>(m)) {
|
||||
load(std::get<std::string>(m))->onLoad();
|
||||
n = load(std::get<std::string>(m));
|
||||
} else {
|
||||
load(std::get<Archimedes::Module*>(m))->onLoad();
|
||||
n = load(std::get<Archimedes::Module*>(m));
|
||||
}
|
||||
if(n) {
|
||||
n->onLoad();
|
||||
n = nullptr;
|
||||
}
|
||||
}
|
||||
toOpen.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/examples/TestImgui/src/TestImgui.h"
|
||||
#include "modules/MainGUI/MainGUI.h"
|
||||
|
||||
class ImguiEmbed : public Archimedes::App {
|
||||
|
||||
private:
|
||||
|
||||
void printHelp() {};
|
||||
void printHelp() override {};
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
public:
|
||||
ImguiEmbed() {
|
||||
Archimedes::Module* m = (Archimedes::Module*) new TestImgui(Get(), nullptr);
|
||||
Archimedes::Module* m = (Archimedes::Module*) new MainGUI(Get(), nullptr);
|
||||
|
||||
load(m);
|
||||
};
|
||||
~ImguiEmbed() {};
|
||||
|
||||
void handleArgs(const int& argc, char* argv[]) {};
|
||||
void handleArgs(const int& argc, char* argv[]) override {};
|
||||
|
||||
void run();
|
||||
void run() override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
55
src/example_apps/ImguiEmbed/default.nix
Normal file
55
src/example_apps/ImguiEmbed/default.nix
Normal file
@@ -0,0 +1,55 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
perSystem = { lib, system, pkgs, ... }: {
|
||||
|
||||
|
||||
packages.exampleApps_ImguiEmbed = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
glm
|
||||
nlohmann_json
|
||||
curl
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
$src/example_apps/ImguiEmbed/*.cpp \
|
||||
$src/modules/MainGUI/*.cpp \
|
||||
$src/modules/WindowModule/*.cpp \
|
||||
$src/modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-I $src/include -I $imgui -I $src \
|
||||
-lEGL -lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ void MinimalApp::run() {
|
||||
modules[m]->onLoad();
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
while (!done && !runOrder.empty()) {
|
||||
|
||||
@@ -36,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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
38
src/example_apps/MinimalApp/default.nix
Normal file
38
src/example_apps/MinimalApp/default.nix
Normal file
@@ -0,0 +1,38 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.exampleApps_MinimalApp = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
$src/example_apps/MinimalApp/MinimalApp.cpp \
|
||||
-I $src/include \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
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
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
71
src/example_apps/SandboxEmbed/SandboxEmbed.cpp
Normal file
71
src/example_apps/SandboxEmbed/SandboxEmbed.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "SandboxEmbed.h"
|
||||
|
||||
bool SandboxEmbed::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;
|
||||
}
|
||||
|
||||
void SandboxEmbed::run() {
|
||||
|
||||
for(std::string m : runOrder) {
|
||||
modules[m]->onLoad();
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
while (!done && !runOrder.empty()) {
|
||||
|
||||
for(std::string m : runOrder) {
|
||||
modules[m]->run();
|
||||
}
|
||||
|
||||
handleEvents();
|
||||
|
||||
for(std::string m : toClose) {
|
||||
unload(m);
|
||||
}
|
||||
toClose.clear();
|
||||
|
||||
for(auto m : toOpen) {
|
||||
static Archimedes::Module* n;
|
||||
if(std::holds_alternative<std::string>(m)) {
|
||||
n = load(std::get<std::string>(m));
|
||||
} else {
|
||||
n = load(std::get<Archimedes::Module*>(m));
|
||||
}
|
||||
if(n) {
|
||||
n->onLoad();
|
||||
n = nullptr;
|
||||
}
|
||||
}
|
||||
toOpen.clear();
|
||||
}
|
||||
}
|
||||
29
src/example_apps/SandboxEmbed/SandboxEmbed.h
Normal file
29
src/example_apps/SandboxEmbed/SandboxEmbed.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/Archimedes-Modules/Sandbox/Sandbox.h"
|
||||
|
||||
class SandboxEmbed : public Archimedes::App {
|
||||
|
||||
private:
|
||||
|
||||
void printHelp() override {};
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
public:
|
||||
SandboxEmbed() {
|
||||
Archimedes::Module* m = (Archimedes::Module*) new Sandbox(Get(), nullptr);
|
||||
|
||||
load(m);
|
||||
};
|
||||
~SandboxEmbed() {};
|
||||
|
||||
void handleArgs(const int& argc, char* argv[]) override {};
|
||||
|
||||
void run() override;
|
||||
|
||||
};
|
||||
|
||||
#define APP_TYPE SandboxEmbed
|
||||
#include "endApp.h"
|
||||
56
src/example_apps/SandboxEmbed/default.nix
Normal file
56
src/example_apps/SandboxEmbed/default.nix
Normal file
@@ -0,0 +1,56 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.exampleApps_Sandbox = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
glm
|
||||
nlohmann_json
|
||||
curl
|
||||
|
||||
stb
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
example_apps/SandboxEmbed/*.cpp \
|
||||
modules/Archimedes-Modules/Sandbox/*.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=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-I include -I $imgui -I . \
|
||||
-lEGL -lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
}; };
|
||||
|
||||
|
||||
}
|
||||
@@ -12,6 +12,8 @@ void TerminalEmbed::run() {
|
||||
modules[m]->run();
|
||||
}
|
||||
|
||||
handleEvents();
|
||||
|
||||
for(auto m : toClose) {
|
||||
unload(m);
|
||||
}
|
||||
@@ -29,3 +31,36 @@ void TerminalEmbed::run() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool TerminalEmbed::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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
54
src/example_apps/TerminalEmbed/default.nix
Normal file
54
src/example_apps/TerminalEmbed/default.nix
Normal file
@@ -0,0 +1,54 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.exampleApps_TerminalEmbed = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
curl
|
||||
glm
|
||||
nlohmann_json
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
example_apps/TerminalEmbed/*.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=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
71
src/example_apps/TriangleEmbed/TriangleEmbed.cpp
Normal file
71
src/example_apps/TriangleEmbed/TriangleEmbed.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "TriangleEmbed.h"
|
||||
|
||||
bool TriangleEmbed::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;
|
||||
}
|
||||
|
||||
void TriangleEmbed::run() {
|
||||
|
||||
for(std::string m : runOrder) {
|
||||
modules[m]->onLoad();
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
while (!done && !runOrder.empty()) {
|
||||
|
||||
for(std::string m : runOrder) {
|
||||
modules[m]->run();
|
||||
}
|
||||
|
||||
handleEvents();
|
||||
|
||||
for(std::string m : toClose) {
|
||||
unload(m);
|
||||
}
|
||||
toClose.clear();
|
||||
|
||||
for(auto m : toOpen) {
|
||||
static Archimedes::Module* n;
|
||||
if(std::holds_alternative<std::string>(m)) {
|
||||
n = load(std::get<std::string>(m));
|
||||
} else {
|
||||
n = load(std::get<Archimedes::Module*>(m));
|
||||
}
|
||||
if(n) {
|
||||
n->onLoad();
|
||||
n = nullptr;
|
||||
}
|
||||
}
|
||||
toOpen.clear();
|
||||
}
|
||||
}
|
||||
29
src/example_apps/TriangleEmbed/TriangleEmbed.h
Normal file
29
src/example_apps/TriangleEmbed/TriangleEmbed.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/Archimedes-Modules/TestTriangle/TestTriangle.h"
|
||||
|
||||
class TriangleEmbed : public Archimedes::App {
|
||||
|
||||
private:
|
||||
|
||||
void printHelp() override {};
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
public:
|
||||
TriangleEmbed() {
|
||||
Archimedes::Module* m = (Archimedes::Module*) new TestTriangle(Get(), nullptr);
|
||||
|
||||
load(m);
|
||||
};
|
||||
~TriangleEmbed() {};
|
||||
|
||||
void handleArgs(const int& argc, char* argv[]) override {};
|
||||
|
||||
void run() override;
|
||||
|
||||
};
|
||||
|
||||
#define APP_TYPE TriangleEmbed
|
||||
#include "endApp.h"
|
||||
49
src/example_apps/TriangleEmbed/default.nix
Normal file
49
src/example_apps/TriangleEmbed/default.nix
Normal file
@@ -0,0 +1,49 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.exampleApps_TriangleEmbed = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Archimedes";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
glm
|
||||
nlohmann_json
|
||||
curl
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
example_apps/TriangleEmbed/*.cpp \
|
||||
modules/Archimedes-Modules/TestTriangle/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
-DRENDERER_OPENGL=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-I include -I . \
|
||||
-lEGL -lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
}; };
|
||||
|
||||
|
||||
}
|
||||
5
src/include/endModule.h
Normal file
5
src/include/endModule.h
Normal file
@@ -0,0 +1,5 @@
|
||||
extern "C" {
|
||||
Archimedes::Module* create(Archimedes::App* app, void* handle) {
|
||||
return new mtype(app, handle);
|
||||
}
|
||||
}
|
||||
12
src/include/extratools.h
Normal file
12
src/include/extratools.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef EXTRATOOLS_H
|
||||
#define EXTRATOOLS_H
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#endif
|
||||
@@ -2,13 +2,16 @@
|
||||
#define PCH_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <list>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <variant>
|
||||
|
||||
#include <any>
|
||||
#include <typeinfo>
|
||||
#include <future>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
@@ -16,6 +19,7 @@
|
||||
#include <optional>
|
||||
#include <chrono>
|
||||
//#include <thread>
|
||||
#include <concepts>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
@@ -17,10 +17,26 @@ namespace Archimedes {
|
||||
}
|
||||
instance = this;
|
||||
roInsert = runOrder.begin();
|
||||
|
||||
registerEvent(AnonymousEvent());
|
||||
|
||||
registerEvent(DoLoadModuleEvent());
|
||||
registerEvent(DoUnloadModuleEvent());
|
||||
|
||||
registerEvent(LoadModuleEvent());
|
||||
registerEvent(UnloadModuleEvent());
|
||||
}
|
||||
|
||||
virtual ~App() {
|
||||
|
||||
unregisterEvent(AnonymousEvent());
|
||||
|
||||
unregisterEvent(DoLoadModuleEvent());
|
||||
unregisterEvent(DoUnloadModuleEvent());
|
||||
|
||||
unregisterEvent(LoadModuleEvent());
|
||||
unregisterEvent(UnloadModuleEvent());
|
||||
|
||||
for(std::string s : runOrder) {
|
||||
void* handle = modules[s]->getHandle();
|
||||
delete modules[s];
|
||||
@@ -40,17 +56,6 @@ namespace Archimedes {
|
||||
|
||||
virtual void run() = 0;
|
||||
|
||||
virtual void stopModule(std::string lib) {
|
||||
//unload modules that depend on the one we are unloading
|
||||
for(std::string s : runOrder) {
|
||||
if(modules[s]->deps.find(lib) != modules[s]->deps.end()) {
|
||||
stopModule(s);
|
||||
}
|
||||
}
|
||||
toClose.push_back(lib);
|
||||
}
|
||||
|
||||
virtual void startModule(std::variant<std::string, Module*> m) { toOpen.push_back(m); }
|
||||
|
||||
void end() { done = true; }
|
||||
|
||||
@@ -94,16 +99,48 @@ namespace Archimedes {
|
||||
std::list<std::string> toClose;
|
||||
std::list<std::variant<std::string, Module*>> toOpen;
|
||||
|
||||
virtual void stopModule(std::string lib) {
|
||||
//unload modules that depend on the one we are unloading
|
||||
for(std::string s : runOrder) {
|
||||
if(modules[s]->deps.find(lib) != modules[s]->deps.end()) {
|
||||
stopModule(s);
|
||||
}
|
||||
}
|
||||
toClose.push_back(lib);
|
||||
}
|
||||
|
||||
virtual void startModule(std::variant<std::string, Module*> m) { toOpen.push_back(m); }
|
||||
|
||||
virtual bool onEvent(const Event& event) = 0;
|
||||
|
||||
void handleEvents() {
|
||||
static bool handled;
|
||||
|
||||
while(!events.empty()) {
|
||||
|
||||
handled = false;
|
||||
|
||||
for(auto it = runOrder.rbegin(); it != runOrder.rend(); it++) {
|
||||
if(modules[*it]->onEvent(*events.front())) {
|
||||
|
||||
handled = modules[*it]->onEvent(*events.front());
|
||||
|
||||
if(handled) {
|
||||
Event* e = events.front();
|
||||
events.pop_front();
|
||||
delete e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!handled) {
|
||||
if(this->onEvent(*events.front())) {
|
||||
Event* e = events.front();
|
||||
events.pop_front();
|
||||
delete e;
|
||||
} else {
|
||||
std::cout << "Error: Unhandled Event: " << (std::string) *events.front() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +164,20 @@ namespace Archimedes {
|
||||
return create(Get(), h);
|
||||
}
|
||||
|
||||
virtual Module* load(std::string modulePath) {
|
||||
Module* m = dynamicLoad(modulePath);
|
||||
virtual Module* reload(std::string lib) {
|
||||
|
||||
for(std::string s : runOrder) {
|
||||
if(s == lib) {
|
||||
return modules[lib];
|
||||
}
|
||||
}
|
||||
|
||||
return modules.find(lib) != modules.end() ? load(modules[lib]) : nullptr;
|
||||
}
|
||||
|
||||
virtual Module* load(std::string moduleNameOrPath) {
|
||||
Module* m = dynamicLoad(moduleNameOrPath);
|
||||
//return m != nullptr ? load(m) : reload(moduleNameOrPath);
|
||||
return load(m);
|
||||
}
|
||||
|
||||
@@ -146,11 +195,12 @@ namespace Archimedes {
|
||||
if(h) {
|
||||
dlclose(h);
|
||||
}
|
||||
return nullptr;
|
||||
return modules[*it];
|
||||
}
|
||||
}
|
||||
|
||||
modules[*m] = m;
|
||||
|
||||
if(modules.find(*m) == modules.end())
|
||||
modules[*m] = m;
|
||||
|
||||
for(auto it = runOrder.begin(); it != runOrder.end(); it++) {
|
||||
|
||||
@@ -189,13 +239,13 @@ namespace Archimedes {
|
||||
|
||||
runOrder.insert(roInsert, *m);
|
||||
|
||||
emitEvent(new LoadModuleEvent(*m));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
virtual void unload(std::string name) {
|
||||
|
||||
std::cout << "Attempting to unload module: " << name << std::endl;
|
||||
|
||||
if(modules.find(name) == modules.end())
|
||||
return;
|
||||
|
||||
@@ -217,13 +267,13 @@ namespace Archimedes {
|
||||
}
|
||||
|
||||
delete m;
|
||||
|
||||
|
||||
if(closable) {
|
||||
dlclose(h);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "Successfully unloaded module: " << name << std::endl;
|
||||
emitEvent(new UnloadModuleEvent(name));
|
||||
}
|
||||
|
||||
virtual void printHelp() = 0;
|
||||
51
src/include/utils/Audio/Audio.h
Normal file
51
src/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
src/include/utils/Events/BasicEvents.h
Normal file
88
src/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
src/include/utils/Events/NetworkEvents.h
Normal file
59
src/include/utils/Events/NetworkEvents.h
Normal file
@@ -0,0 +1,59 @@
|
||||
#ifndef NETWORKEVENTS_H
|
||||
#define NETWORKEVENTS_H
|
||||
|
||||
#include "Event.h"
|
||||
|
||||
#include <steam/steamnetworkingsockets.h>
|
||||
#include <steam/isteamnetworkingutils.h>
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class DataRecievedEvent : public Event {
|
||||
|
||||
public:
|
||||
|
||||
DataRecievedEvent() : Event(nullptr), msg(nullptr) {}
|
||||
|
||||
DataRecievedEvent(ISteamNetworkingMessage* m) : Event(nullptr), msg(m) {}
|
||||
|
||||
~DataRecievedEvent() {
|
||||
if(msg)
|
||||
msg->Release();
|
||||
}
|
||||
|
||||
operator std::string() const override { return "DataRecievedEvent"; }
|
||||
|
||||
ISteamNetworkingMessage* msg;
|
||||
|
||||
};
|
||||
|
||||
class DataSentEvent : public Event {
|
||||
|
||||
public:
|
||||
|
||||
DataSentEvent() : Event(nullptr), msg(nullptr) {}
|
||||
|
||||
DataSentEvent(const void* m, uint32 l) : Event(nullptr), msg(m), length(l) {}
|
||||
|
||||
operator std::string() const override { return "DataSentEvent"; }
|
||||
|
||||
const void* msg;
|
||||
uint32 length;
|
||||
};
|
||||
|
||||
class ConnectionStatusChangedEvent : public Event {
|
||||
|
||||
public:
|
||||
|
||||
ConnectionStatusChangedEvent() : Event(nullptr), info(nullptr) {}
|
||||
|
||||
ConnectionStatusChangedEvent(SteamNetConnectionStatusChangedCallback_t* i) : Event(nullptr), info(i) {}
|
||||
|
||||
operator std::string() const override { return "ConnectionStatusChangedEvent"; }
|
||||
|
||||
SteamNetConnectionStatusChangedCallback_t* info;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -25,13 +25,13 @@ namespace Archimedes {
|
||||
|
||||
virtual void run() {}
|
||||
virtual bool onEvent(const Event& e) { return false; }
|
||||
virtual void onLoad() {};
|
||||
|
||||
virtual void onLoad() {}
|
||||
virtual void onUnload() {}
|
||||
|
||||
operator std::string() const { return name; }
|
||||
void* getHandle() { return handle; }
|
||||
|
||||
//std::any getData(std::string s) { return data[s.c_str()]; };
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
|
||||
@@ -42,7 +42,6 @@ namespace Archimedes {
|
||||
std::unordered_map<std::string, std::variant<std::string, Module*>> exts;
|
||||
std::unordered_map<std::string, Module*> moduleInstances;
|
||||
|
||||
//std::unordered_map<std::string, std::any> data;
|
||||
};
|
||||
}
|
||||
|
||||
32
src/include/utils/Objects/Body.h
Normal file
32
src/include/utils/Objects/Body.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef BODY_H
|
||||
#define BODY_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Body : public Object {
|
||||
|
||||
public:
|
||||
Body(RenderTarget rt, glm::mat4 t = glm::mat4(1.0f)) : Object(t), mesh(rt) {};
|
||||
|
||||
Body(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, std::optional<Texture> tex = std::nullopt, RenderMode rm = RenderMode::Triangles, glm::mat4 t = glm::mat4(1.0f))
|
||||
: Object(t), mesh(vb, ia, vl, s, tex, rm) {}
|
||||
|
||||
Body() : Object(glm::mat4(1.0f)) {}
|
||||
|
||||
~Body() {};
|
||||
|
||||
RenderTarget& getMesh() { return mesh; }
|
||||
|
||||
private:
|
||||
|
||||
RenderTarget mesh;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
30
src/include/utils/Objects/Camera.h
Normal file
30
src/include/utils/Objects/Camera.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Camera : public Object {
|
||||
|
||||
public:
|
||||
Camera() : Object(glm::mat4(1.0f)) {}
|
||||
|
||||
Camera(glm::mat4 t)
|
||||
: Object(t) {}
|
||||
|
||||
~Camera() {};
|
||||
|
||||
const glm::mat4& getPerspective() { return perspective; }
|
||||
void setPerspective(const glm::mat4 m) { perspective = m; }
|
||||
|
||||
private:
|
||||
glm::mat4 perspective = glm::mat4(1.0f);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
82
src/include/utils/Objects/Object.h
Normal file
82
src/include/utils/Objects/Object.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef OBJECT_H
|
||||
#define OBJECT_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "utils/Renderer/RenderTarget.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Object {
|
||||
|
||||
public:
|
||||
|
||||
Object(glm::mat4 t)
|
||||
: worldTransform(t) {}
|
||||
|
||||
~Object() {};
|
||||
|
||||
///scales an object absolutely
|
||||
///scale factors less than zero do nothing
|
||||
float scaleTo(float s) {
|
||||
if(s > 0) {
|
||||
worldTransform = glm::scale(worldTransform, glm::vec3(s / scale));
|
||||
scale = s;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
float scaleRel(float s) {
|
||||
return scaleTo(scale * s);
|
||||
}
|
||||
|
||||
float scaleAdd(float s) {
|
||||
return scaleTo(scale + s);
|
||||
}
|
||||
|
||||
glm::vec3 moveTo(glm::vec3 pos) {
|
||||
worldTransform = glm::translate(worldTransform, pos - position);
|
||||
position = pos;
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
glm::vec3 moveRel(glm::vec3 pos) {
|
||||
return moveTo(pos + position);
|
||||
}
|
||||
|
||||
glm::vec3 rotateTo(glm::vec3 angles) {
|
||||
worldTransform = glm::rotate(worldTransform, angles.x - rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
worldTransform = glm::rotate(worldTransform, angles.y - rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
worldTransform = glm::rotate(worldTransform, angles.z - rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
rotation = angles;
|
||||
|
||||
return rotation;
|
||||
}
|
||||
|
||||
glm::vec3 rotateRel(glm::vec3 angles) {
|
||||
return rotateTo(angles + rotation);
|
||||
}
|
||||
|
||||
glm::vec3& getPosition() { return position; }
|
||||
glm::vec3& getRotation() { return rotation; }
|
||||
float& getScale() { return scale; }
|
||||
|
||||
const glm::mat4& getTransform() { return worldTransform; }
|
||||
void setTransform(const glm::mat4 m) { worldTransform = m; }
|
||||
|
||||
private:
|
||||
|
||||
glm::vec3 position = glm::vec3(0);
|
||||
glm::vec3 rotation = glm::vec3(0);
|
||||
float scale = 1.0f;
|
||||
|
||||
glm::mat4 worldTransform = glm::mat4(1.0f);
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
321
src/include/utils/Renderer/RenderTarget.h
Normal file
321
src/include/utils/Renderer/RenderTarget.h
Normal file
@@ -0,0 +1,321 @@
|
||||
#ifndef RENDERTARGET_H
|
||||
#define RENDERTARGET_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
enum class RenderMode {
|
||||
Points,
|
||||
Lines,
|
||||
ConnectedLines,
|
||||
ConnectedLinesLooped,
|
||||
Triangles,
|
||||
Quads,
|
||||
Polygon
|
||||
};
|
||||
|
||||
class Texture {
|
||||
|
||||
public:
|
||||
Texture() {}
|
||||
Texture(std::vector<unsigned char> bin, size_t width, size_t height)
|
||||
: bin(bin), width(width), height(height) {}
|
||||
|
||||
~Texture() {}
|
||||
|
||||
const void* getBin() { return bin.data(); }
|
||||
|
||||
void setActive(bool b) { active = b; }
|
||||
const bool getActive() const { return active; }
|
||||
|
||||
size_t getWidth() { return width; }
|
||||
size_t getHeight() { return height; }
|
||||
|
||||
unsigned int id;
|
||||
|
||||
private:
|
||||
std::vector<unsigned char> bin;
|
||||
|
||||
bool active = false;
|
||||
size_t width, height;
|
||||
};
|
||||
|
||||
class LayoutElement {
|
||||
|
||||
public:
|
||||
|
||||
enum class Type {
|
||||
Float,
|
||||
UInt,
|
||||
Int,
|
||||
Double
|
||||
};
|
||||
|
||||
LayoutElement(Type type, size_t count, size_t stride, size_t offset)
|
||||
: type(type), count(count), stride(stride), offset(offset) {}
|
||||
|
||||
~LayoutElement() {}
|
||||
|
||||
Type getType() const { return type; }
|
||||
|
||||
size_t getCount() const { return count; }
|
||||
|
||||
size_t getStride() const { return stride; }
|
||||
|
||||
size_t getOffset() const { return offset; }
|
||||
|
||||
private:
|
||||
|
||||
Type type;
|
||||
size_t count;
|
||||
size_t stride;
|
||||
size_t offset;
|
||||
};
|
||||
|
||||
class VertexLayout {
|
||||
|
||||
public:
|
||||
VertexLayout() {}
|
||||
VertexLayout(std::vector<LayoutElement> elements) : elements(elements) {}
|
||||
~VertexLayout() {}
|
||||
|
||||
std::vector<LayoutElement>& getElements() { return elements; }
|
||||
|
||||
private:
|
||||
std::vector<LayoutElement> elements;
|
||||
};
|
||||
|
||||
class VertexBuffer {
|
||||
|
||||
public:
|
||||
VertexBuffer(const std::vector<float> data) : data(data) {
|
||||
}
|
||||
|
||||
VertexBuffer() {}
|
||||
|
||||
~VertexBuffer() {}
|
||||
|
||||
void setActive(bool b) { active = b; }
|
||||
const bool getActive() const { return active; }
|
||||
|
||||
const void* getData() const { return data.data(); }
|
||||
size_t getSize() const { return data.size() * sizeof(float); }
|
||||
|
||||
unsigned int id;
|
||||
private:
|
||||
bool active = false;
|
||||
std::vector<float> data;
|
||||
};
|
||||
|
||||
class VertexArray {
|
||||
|
||||
public:
|
||||
VertexArray() {
|
||||
}
|
||||
|
||||
~VertexArray() {}
|
||||
|
||||
void setActive(bool b) { active = b; }
|
||||
const bool getActive() const { return active; }
|
||||
|
||||
unsigned int id;
|
||||
private:
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
class IndexArray {
|
||||
|
||||
public:
|
||||
IndexArray(const std::vector<unsigned int> indices) : indices(indices) {
|
||||
}
|
||||
|
||||
IndexArray() {}
|
||||
|
||||
~IndexArray() {}
|
||||
|
||||
void setActive(bool b) { active = b; }
|
||||
const bool getActive() const { return active; }
|
||||
|
||||
const void* getIndicies() const { return indices.data(); }
|
||||
size_t getCount() const { return indices.size(); }
|
||||
|
||||
unsigned int id;
|
||||
private:
|
||||
bool active = false;
|
||||
std::vector<unsigned int> indices;
|
||||
};
|
||||
|
||||
class Shader {
|
||||
|
||||
public:
|
||||
enum class LoadType {
|
||||
FromSource,
|
||||
FromBin,
|
||||
FromFileSource,
|
||||
FromFileBin
|
||||
};
|
||||
|
||||
Shader() {}
|
||||
|
||||
Shader(const std::string& vs, const std::string& fs, LoadType loadType) {
|
||||
init(vs, fs, loadType);
|
||||
}
|
||||
|
||||
~Shader() {}
|
||||
|
||||
void init(const std::string& vs, const std::string& fs, LoadType loadType) {
|
||||
switch(loadType) {
|
||||
case LoadType::FromSource:
|
||||
this->shader = source { vs, fs };
|
||||
break;
|
||||
case LoadType::FromBin:
|
||||
break;
|
||||
case LoadType::FromFileSource:
|
||||
this->shader = source {
|
||||
readSourceFile(vs),
|
||||
readSourceFile(fs)
|
||||
};
|
||||
break;
|
||||
case LoadType::FromFileBin:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void init(const std::vector<unsigned char>& vs, const std::vector<unsigned char>& fs, LoadType loadType) {
|
||||
switch(loadType) {
|
||||
case LoadType::FromSource:
|
||||
break;
|
||||
case LoadType::FromBin:
|
||||
this->shader = bin { vs, fs };
|
||||
break;
|
||||
case LoadType::FromFileSource:
|
||||
break;
|
||||
case LoadType::FromFileBin:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void setActive(bool b) { active = b; }
|
||||
const bool getActive() const { return active; }
|
||||
|
||||
std::string getVSource() const { return std::get<source>(shader).vertex; }
|
||||
std::string getFSource() const { return std::get<source>(shader).fragment; }
|
||||
|
||||
std::vector<unsigned char>& getVbin() { return std::get<bin>(shader).vertex; }
|
||||
std::vector<unsigned char>& getFbin() { return std::get<bin>(shader).fragment; }
|
||||
|
||||
unsigned int id;
|
||||
private:
|
||||
|
||||
struct source {
|
||||
std::string vertex;
|
||||
std::string fragment;
|
||||
};
|
||||
|
||||
struct bin {
|
||||
std::vector<unsigned char> vertex;
|
||||
std::vector<unsigned char> fragment;
|
||||
};
|
||||
|
||||
std::variant<source, bin> shader;
|
||||
|
||||
bool active = false;
|
||||
|
||||
std::string readSourceFile(const std::string& path) {
|
||||
|
||||
std::ifstream file(path);
|
||||
|
||||
if(!file.is_open()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string s;
|
||||
|
||||
while(!file.eof()) {
|
||||
file >> s;
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
std::vector<unsigned char> readBinFile(const std::string& path) {
|
||||
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
|
||||
if(!file.is_open()) {
|
||||
return std::vector<unsigned char>();
|
||||
}
|
||||
|
||||
std::vector<unsigned char> s;
|
||||
|
||||
s.reserve(10000);
|
||||
|
||||
while(!file.eof()) {
|
||||
s.push_back(file.get());
|
||||
}
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class RenderTarget {
|
||||
|
||||
public:
|
||||
|
||||
RenderTarget(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, std::optional<Texture> t = std::nullopt, RenderMode rm = RenderMode::Triangles)
|
||||
: vertexBuffer(vb),
|
||||
indexArray(ia),
|
||||
layout(vl),
|
||||
shader(s),
|
||||
texture(t),
|
||||
renderMode(rm) {
|
||||
|
||||
}
|
||||
|
||||
RenderTarget() {}
|
||||
|
||||
~RenderTarget() {}
|
||||
|
||||
void setup(VertexBuffer vb, IndexArray ia, VertexLayout vl, Shader s, std::optional<Texture> t = std::nullopt, RenderMode rm = RenderMode::Triangles) {
|
||||
vertexBuffer = vb;
|
||||
indexArray = ia;
|
||||
layout = vl;
|
||||
shader = s;
|
||||
texture = t;
|
||||
renderMode = rm;
|
||||
}
|
||||
|
||||
void setActive(bool b) { active = b; }
|
||||
const bool getActive() const { return active; }
|
||||
|
||||
//private:
|
||||
|
||||
VertexBuffer vertexBuffer;
|
||||
|
||||
VertexArray vertexArray;
|
||||
|
||||
IndexArray indexArray;
|
||||
|
||||
VertexLayout layout;
|
||||
|
||||
Shader shader;
|
||||
|
||||
std::optional<Texture> texture;
|
||||
|
||||
RenderMode renderMode;
|
||||
|
||||
bool active = false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
54
src/include/utils/Renderer/Renderer.h
Normal file
54
src/include/utils/Renderer/Renderer.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "extratools.h"
|
||||
|
||||
#include "RenderTarget.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Renderer {
|
||||
|
||||
public:
|
||||
|
||||
|
||||
int w, h;
|
||||
|
||||
glm::vec4 clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
Renderer() : w(0), h(0) {}
|
||||
|
||||
virtual ~Renderer() {}
|
||||
|
||||
virtual bool init() = 0;
|
||||
|
||||
virtual void render() = 0;
|
||||
|
||||
virtual void setupShader(Shader& shader) = 0;
|
||||
|
||||
virtual void setupTexture(Texture& texture) = 0;
|
||||
|
||||
virtual void updateTexture(Texture& texture) = 0;
|
||||
|
||||
virtual void setupRenderTarget(RenderTarget& rt) = 0;
|
||||
|
||||
virtual void updateRenderTarget(RenderTarget& rt) = 0;
|
||||
|
||||
virtual void freeRenderTarget(RenderTarget& rt) = 0;
|
||||
|
||||
virtual void draw(
|
||||
const RenderTarget& rt,
|
||||
const glm::mat4 world = glm::mat4(1.0f),
|
||||
const glm::mat4 view = glm::mat4(1.0f),
|
||||
const glm::mat4 proj = glm::mat4(1.0f),
|
||||
const glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f }
|
||||
) = 0;
|
||||
|
||||
virtual Renderer* getRendererImpl() = 0;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,278 @@
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
#ifndef RENDERER_OPENGL_H
|
||||
#define RENDERER_OPENGL_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
|
||||
#define GLEW_STATIC
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class RendererOpenGL : public Renderer {
|
||||
|
||||
public:
|
||||
typedef void renderCmd();
|
||||
|
||||
RendererOpenGL() {};
|
||||
~RendererOpenGL() {};
|
||||
|
||||
bool init() override {
|
||||
bool ok = glewInit() == GLEW_OK;
|
||||
|
||||
if(ok) {
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
return ok;
|
||||
};
|
||||
|
||||
void render() override {
|
||||
|
||||
glViewport(0, 0, w, h);
|
||||
glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
}
|
||||
|
||||
void setupShader(Shader& shader) override {
|
||||
|
||||
std::string vss = shader.getVSource();
|
||||
std::string fss = shader.getFSource();
|
||||
|
||||
const char* vsc = vss.c_str();
|
||||
const char* fsc = fss.c_str();
|
||||
|
||||
unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
glShaderSource(vertexShader, 1, &vsc, NULL);
|
||||
glCompileShader(vertexShader);
|
||||
// check for shader compile errors
|
||||
int success;
|
||||
char infoLog[512];
|
||||
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// fragment shader
|
||||
unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(fragmentShader, 1, &fsc, NULL);
|
||||
glCompileShader(fragmentShader);
|
||||
// check for shader compile errors
|
||||
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
// link shaders
|
||||
unsigned int shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
glAttachShader(shaderProgram, fragmentShader);
|
||||
glLinkProgram(shaderProgram);
|
||||
// check for linking errors
|
||||
glGetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
|
||||
if (!success) {
|
||||
glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);
|
||||
std::cout << "ERROR::SHADER::PROGRAM::LINKING_FAILED\n" << infoLog << std::endl;
|
||||
}
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
shader.id = shaderProgram;
|
||||
|
||||
}
|
||||
|
||||
void setupTexture(Texture& texture) override {
|
||||
glGenTextures(1, &texture.id);
|
||||
updateTexture(texture);
|
||||
}
|
||||
|
||||
void updateTexture(Texture& texture) override {
|
||||
glBindTexture(GL_TEXTURE_2D, texture.id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture.getWidth(), texture.getHeight(), 0, GL_ALPHA, GL_UNSIGNED_BYTE, texture.getBin());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
void setupRenderTarget(RenderTarget& rt) override {
|
||||
|
||||
glGenVertexArrays(1, &rt.vertexArray.id);
|
||||
|
||||
glGenBuffers(1, &rt.vertexBuffer.id);
|
||||
|
||||
glGenBuffers(1, &rt.indexArray.id);
|
||||
|
||||
|
||||
rt.vertexArray.setActive(true);
|
||||
rt.vertexBuffer.setActive(true);
|
||||
rt.indexArray.setActive(true);
|
||||
|
||||
if(rt.texture.has_value()) {
|
||||
glGenTextures(1, &rt.texture.value().id);
|
||||
rt.texture.value().setActive(true);
|
||||
}
|
||||
|
||||
|
||||
updateRenderTarget(rt);
|
||||
|
||||
rt.setActive(true);
|
||||
};
|
||||
|
||||
void updateRenderTarget(RenderTarget& rt) override {
|
||||
|
||||
if(rt.vertexArray.getActive()) {
|
||||
|
||||
glBindVertexArray(rt.vertexArray.id);
|
||||
|
||||
if(rt.vertexBuffer.getActive()) {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, rt.vertexBuffer.id);
|
||||
glBufferData(GL_ARRAY_BUFFER, rt.vertexBuffer.getSize(), rt.vertexBuffer.getData(), GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
|
||||
if(rt.indexArray.getActive()) {
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, rt.indexArray.id);
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, rt.indexArray.getCount() * sizeof(unsigned int), rt.indexArray.getIndicies(), GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
if(rt.texture.has_value()) {
|
||||
if(rt.texture.value().getActive()) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, rt.texture.value().id);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, rt.texture.value().getWidth(), rt.texture.value().getHeight(), 0, GL_RED, GL_UNSIGNED_BYTE, rt.texture.value().getBin());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
}
|
||||
}
|
||||
|
||||
if(rt.shader.getActive()) {
|
||||
glUseProgram(rt.shader.id);
|
||||
}
|
||||
|
||||
|
||||
unsigned int i = 0;
|
||||
for(LayoutElement e : rt.layout.getElements()) {
|
||||
|
||||
switch(e.getType()) {
|
||||
case LayoutElement::Type::Float:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_FLOAT, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
case LayoutElement::Type::Double:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_DOUBLE, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
case LayoutElement::Type::Int:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_INT, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
case LayoutElement::Type::UInt:
|
||||
glVertexAttribPointer(i, e.getCount(), GL_UNSIGNED_INT, GL_FALSE, e.getStride(), (void*)e.getOffset());
|
||||
glEnableVertexAttribArray(i);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
void freeRenderTarget(RenderTarget& rt) override {
|
||||
|
||||
glDeleteVertexArrays(1, &rt.vertexArray.id);
|
||||
glDeleteBuffers(1, &rt.vertexBuffer.id);
|
||||
glDeleteBuffers(1, &rt.indexArray.id);
|
||||
|
||||
rt.vertexArray.setActive(false);
|
||||
rt.vertexBuffer.setActive(false);
|
||||
rt.indexArray.setActive(false);
|
||||
|
||||
rt.setActive(false);
|
||||
};
|
||||
|
||||
void draw(
|
||||
const RenderTarget& rt,
|
||||
const glm::mat4 world = glm::mat4(1.0f),
|
||||
const glm::mat4 view = glm::mat4(1.0f),
|
||||
const glm::mat4 proj = glm::mat4(1.0f),
|
||||
const glm::vec4 color = { 1.0f, 0.0f, 1.0f, 1.0f }
|
||||
) override {
|
||||
|
||||
glUseProgram(rt.shader.id);
|
||||
|
||||
unsigned int modelLoc = glGetUniformLocation(rt.shader.id, "model");
|
||||
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(world));
|
||||
|
||||
unsigned int viewLoc = glGetUniformLocation(rt.shader.id, "view");
|
||||
glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));
|
||||
|
||||
unsigned int projLoc = glGetUniformLocation(rt.shader.id, "proj");
|
||||
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(proj));
|
||||
|
||||
unsigned int colorLoc = glGetUniformLocation(rt.shader.id, "color");
|
||||
glUniform4f(colorLoc, color.r, color.g, color.b, color.a);
|
||||
|
||||
|
||||
if(rt.texture.has_value()) {
|
||||
if(rt.texture.value().getActive()) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, rt.texture.value().id);
|
||||
|
||||
glUniform1i(glGetUniformLocation(rt.shader.id, "tex"), 0);
|
||||
}
|
||||
}
|
||||
|
||||
glBindVertexArray(rt.vertexArray.id);
|
||||
|
||||
switch(rt.renderMode) {
|
||||
case RenderMode::Triangles:
|
||||
glDrawElements(GL_TRIANGLES, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
case RenderMode::Lines:
|
||||
glDrawElements(GL_LINES, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
case RenderMode::ConnectedLines:
|
||||
glDrawElements(GL_LINE_STRIP, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
case RenderMode::ConnectedLinesLooped:
|
||||
glDrawElements(GL_LINE_LOOP, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
case RenderMode::Quads:
|
||||
glDrawElements(GL_QUADS, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
case RenderMode::Polygon:
|
||||
glDrawElements(GL_POLYGON, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
case RenderMode::Points:
|
||||
glDrawElements(GL_POINTS, rt.indexArray.getCount(), GL_UNSIGNED_INT, nullptr);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
RendererOpenGL* getRendererImpl() override { return this; }
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifdef RENDERER_SDL3
|
||||
#ifndef RENDERER_SDL3_H
|
||||
#define RENDERER_SDL3_H
|
||||
|
||||
#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;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
66
src/include/utils/Window/Window.h
Normal file
66
src/include/utils/Window/Window.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef WINDOW_H
|
||||
#define WINDOW_H
|
||||
|
||||
#include "WindowEvents.h"
|
||||
|
||||
#include "utils/Renderer/Renderer.h"
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Window {
|
||||
|
||||
public:
|
||||
|
||||
Window(const std::function<void(Event*)>& sendEventFn) : eventFn(sendEventFn) {}
|
||||
|
||||
virtual ~Window() {};
|
||||
|
||||
|
||||
void doFrame() {
|
||||
|
||||
swapBuffers();
|
||||
|
||||
renderer->render();
|
||||
|
||||
pollEvents();
|
||||
|
||||
}
|
||||
|
||||
virtual bool shouldClose() = 0;
|
||||
|
||||
virtual void swapBuffers() = 0;
|
||||
|
||||
virtual void pollEvents() = 0;
|
||||
|
||||
virtual void restoreContext() = 0;
|
||||
|
||||
virtual void getSize(int& w, int& h) {
|
||||
w = this->w;
|
||||
h = this->h;
|
||||
}
|
||||
|
||||
virtual void setSize(const int& w, const int& h) {
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
}
|
||||
|
||||
Renderer* getRenderer() { return renderer; }
|
||||
void setRenderer(Renderer* r) {
|
||||
renderer = r;
|
||||
renderer->w = w;
|
||||
renderer->h = h;
|
||||
}
|
||||
|
||||
virtual Window* getWindowImpl() = 0;
|
||||
|
||||
protected:
|
||||
|
||||
int w, h;
|
||||
|
||||
Renderer* renderer;
|
||||
|
||||
std::function<void(Event*)> eventFn;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
220
src/include/utils/Window/WindowEvents.h
Normal file
220
src/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
|
||||
146
src/include/utils/Window/WindowImpl/WindowGLFW/WindowGLFW.h
Normal file
146
src/include/utils/Window/WindowImpl/WindowGLFW/WindowGLFW.h
Normal file
@@ -0,0 +1,146 @@
|
||||
#ifdef WINDOW_GLFW
|
||||
#ifndef WINDOW_GLFW_H
|
||||
#define WINDOW_GLFW_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "utils/Window/Window.h"
|
||||
|
||||
#define GLFW_INCLUDE_NONE
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class WindowGLFW : public Window {
|
||||
|
||||
public:
|
||||
|
||||
WindowGLFW(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
|
||||
|
||||
data.window = this;
|
||||
data.sendEvent = sendEvent;
|
||||
|
||||
glfwSetErrorCallback([](int e, const char* m){
|
||||
std::cout << "GLFW Error " << e << ": " << m << std::endl;
|
||||
});
|
||||
|
||||
if(!glfwInit()) {
|
||||
std::cout << "glfwInit failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
#ifdef RENDERER_OPENGL
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, 1);
|
||||
#endif
|
||||
|
||||
window = glfwCreateWindow(640, 480, "Archimedes", NULL, NULL);
|
||||
|
||||
if(!window) {
|
||||
std::cout << "glfwCreateWindow failed!\n";
|
||||
glfwTerminate();
|
||||
std::abort();
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(1);
|
||||
|
||||
glfwSetWindowUserPointer(window, &data);
|
||||
|
||||
glfwSetWindowSizeCallback(window, [](GLFWwindow* window, int w, int h){
|
||||
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
|
||||
|
||||
d.sendEvent(new ResizeWindowEvent(w, h));
|
||||
});
|
||||
|
||||
glfwSetWindowCloseCallback(window, [](GLFWwindow* window){
|
||||
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
|
||||
|
||||
d.sendEvent(new CloseWindowEvent(d.window));
|
||||
});
|
||||
|
||||
glfwSetKeyCallback(window, [](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(window, [](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(window, [](GLFWwindow* window, double dx, double dy){
|
||||
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
|
||||
|
||||
d.sendEvent(new ScrollWindowEvent(dx, dy));
|
||||
});
|
||||
|
||||
glfwSetCursorPosCallback(window, [](GLFWwindow* window, double dx, double dy){
|
||||
WindowData& d = *(WindowData*) glfwGetWindowUserPointer(window);
|
||||
|
||||
d.sendEvent(new MouseMovedWindowEvent(dx, dy));
|
||||
});
|
||||
}
|
||||
|
||||
~WindowGLFW() {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
void swapBuffers() override { restoreContext(); glfwSwapBuffers(window); };
|
||||
|
||||
void pollEvents() override { glfwPollEvents(); }
|
||||
|
||||
bool shouldClose() override {
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void setSize(const int& w, const int& h) override {
|
||||
this->w = w;
|
||||
this->h = h;
|
||||
|
||||
glfwSetWindowSize(window, w, h);
|
||||
}
|
||||
|
||||
void restoreContext() override { glfwMakeContextCurrent(window); }
|
||||
|
||||
void getSize(int& w, int& h) override {
|
||||
glfwGetFramebufferSize(window, &w, &h);
|
||||
}
|
||||
|
||||
GLFWwindow* getWindow() { return window; }
|
||||
|
||||
WindowData data;
|
||||
|
||||
virtual WindowGLFW* getWindowImpl() override { return this; }
|
||||
|
||||
private:
|
||||
GLFWwindow* window;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
161
src/include/utils/Window/WindowImpl/WindowSDL3/WindowSDL3.h
Normal file
161
src/include/utils/Window/WindowImpl/WindowSDL3/WindowSDL3.h
Normal file
@@ -0,0 +1,161 @@
|
||||
#ifdef WINDOW_SDL3
|
||||
#ifndef WINDOW_SDL3_H
|
||||
#define WINDOW_SDL3_H
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "utils/Window/Window.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
|
||||
#endif
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
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 Window {
|
||||
|
||||
public:
|
||||
|
||||
WindowSDL3(const std::function<void(Event*)>& sendEvent) : Window(sendEvent) {
|
||||
|
||||
data.window = this;
|
||||
data.sendEvent = sendEvent;
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
|
||||
std::cerr << "Error: SDL_Init(): " << SDL_GetError() << std::flush;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
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;
|
||||
#endif
|
||||
#ifdef RENDERER_SDL3
|
||||
SDL_WindowFlags window_flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN | SDL_WINDOW_HIGH_PIXEL_DENSITY;
|
||||
#endif
|
||||
|
||||
window = SDL_CreateWindow("Archimedes", 1280, 720, window_flags);
|
||||
if (window == nullptr)
|
||||
{
|
||||
std::cerr << "Error: SDL_CreateWindow(): " << SDL_GetError() << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
gl_context = SDL_GL_CreateContext(window);
|
||||
|
||||
if (gl_context == nullptr)
|
||||
{
|
||||
std::cerr << "Error: SDL_GL_CreateContext(): " << SDL_GetError() << std::endl;
|
||||
std::abort();
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(window, gl_context);
|
||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||
#endif
|
||||
SDL_AddEventWatch(EventCallback, &data);
|
||||
|
||||
SDL_ShowWindow(window);
|
||||
}
|
||||
|
||||
~WindowSDL3() {
|
||||
#ifdef RENDERER_OPENGL
|
||||
SDL_GL_DestroyContext(gl_context);
|
||||
#endif
|
||||
SDL_RemoveEventWatch(EventCallback, &data);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
bool shouldClose() override { return false; }
|
||||
|
||||
void swapBuffers() override {
|
||||
#ifdef RENDERER_OPENGL
|
||||
restoreContext();
|
||||
SDL_GL_SwapWindow(window);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pollEvents() override {
|
||||
static SDL_Event e;
|
||||
while(SDL_PollEvent(&e));
|
||||
}
|
||||
|
||||
WindowSDL3* getWindowImpl() override { return this; };
|
||||
|
||||
#ifdef RENDERER_OPENGL
|
||||
void restoreContext() override { SDL_GL_MakeCurrent(window, gl_context); }
|
||||
#endif
|
||||
|
||||
SDL_Window* getWindow() { return window; }
|
||||
#ifdef RENDERER_OPENGL
|
||||
SDL_GLContext getContext() { return gl_context; }
|
||||
#endif
|
||||
WindowData data;
|
||||
|
||||
private:
|
||||
SDL_Window* window;
|
||||
#ifdef RENDERER_OPENGL
|
||||
SDL_GLContext gl_context;
|
||||
#endif
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
355
src/modules/Archimedes-Modules/Calculator/Calculator.cpp
Normal file
355
src/modules/Archimedes-Modules/Calculator/Calculator.cpp
Normal file
@@ -0,0 +1,355 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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
src/modules/Archimedes-Modules/Calculator/Calculator.h
Normal file
35
src/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
|
||||
56
src/modules/Archimedes-Modules/Calculator/default.nix
Normal file
56
src/modules/Archimedes-Modules/Calculator/default.nix
Normal file
@@ -0,0 +1,56 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.Calculator = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Calculator";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
glm
|
||||
nlohmann_json
|
||||
curl
|
||||
];
|
||||
|
||||
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_OPENGL=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-DCALCULATOR_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lEGL -lGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include "modules/ClientModule/ClientModule.h"
|
||||
|
||||
#include "ChatClient.h"
|
||||
|
||||
|
||||
@@ -12,19 +17,48 @@ ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
|
||||
deps[*im] = im;
|
||||
|
||||
}
|
||||
|
||||
ChatClient::~ChatClient() {
|
||||
if(app) {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void ChatClient::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for ChatClient!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClient!\n";
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatClient::run() {
|
||||
|
||||
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClient!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(open) {
|
||||
static std::string s, addr;
|
||||
static std::string s, addr = "127.0.0.1:9932";
|
||||
|
||||
ImGui::Begin("ChatClient Module", &open);
|
||||
|
||||
@@ -58,7 +92,7 @@ void ChatClient::run() {
|
||||
|
||||
ImGui::End();
|
||||
} else {
|
||||
app->stopModule(name);
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(*cm));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,15 +100,14 @@ bool ChatClient::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(CMEvent::DataRecievedEvent())) {
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
CMEvent::DataRecievedEvent& e = (CMEvent::DataRecievedEvent&) event;
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
@@ -86,7 +119,7 @@ bool ChatClient::onEvent(const Archimedes::Event& event) {
|
||||
}
|
||||
/*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//CMEvent::ConnectionStatusChangedEvent& e = (CMEvent::ConnectionStatusChangedEvent&) event;
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ClientModule/src/ClientModule.h"
|
||||
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
|
||||
class ChatClient : public Archimedes::Module {
|
||||
|
||||
@@ -12,15 +9,13 @@ class ChatClient : public Archimedes::Module {
|
||||
|
||||
ChatClient() { name = "ChatClient"; }
|
||||
|
||||
~ChatClient() {
|
||||
if(app) {}
|
||||
}
|
||||
~ChatClient();
|
||||
|
||||
void onLoad();
|
||||
void onLoad() override;
|
||||
|
||||
void run();
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
private:
|
||||
std::string messages = "";
|
||||
@@ -28,6 +23,6 @@ class ChatClient : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef CHATCLIENT_DYNAMIC
|
||||
#define MODULE_TYPE ChatClient
|
||||
typedef ChatClient mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
54
src/modules/Archimedes-Modules/Chat/ChatClient/default.nix
Normal file
54
src/modules/Archimedes-Modules/Chat/ChatClient/default.nix
Normal file
@@ -0,0 +1,54 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.ChatClient = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatClient";
|
||||
|
||||
src = inputs.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 . \
|
||||
-lEGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -18,14 +18,21 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(SMEvent::DataRecievedEvent())) {
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
SMEvent::DataRecievedEvent& e = (SMEvent::DataRecievedEvent&) event;
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
if(s == "/quit") {
|
||||
sm->disconnectClient(e.msg->m_conn);
|
||||
} else if(s == "/shutdown") {
|
||||
sm->stopServer();
|
||||
app->end();
|
||||
}
|
||||
|
||||
std::cerr << "Server Recieved: " << s << std::endl;
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
@@ -39,7 +46,7 @@ bool ChatServer::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//SMEvent::ConnectionStatusChangedEvent& e = (SMEvent::ConnectionStatusChangedEvent&) event;
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/src/ServerModule.h"
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChatServer : public Archimedes::Module {
|
||||
|
||||
@@ -29,6 +29,6 @@ class ChatServer : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef CHATSERVER_DYNAMIC
|
||||
#define MODULE_TYPE ChatServer
|
||||
typedef ChatServer mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
41
src/modules/Archimedes-Modules/Chat/ChatServer/default.nix
Normal file
41
src/modules/Archimedes-Modules/Chat/ChatServer/default.nix
Normal file
@@ -0,0 +1,41 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.ChatServer = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatServer";
|
||||
|
||||
src = inputs.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
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -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,54 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.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 . \
|
||||
-lEGL -lSDL3 -lGLEW \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,41 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.ChatServerVoice = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatServerVoice";
|
||||
|
||||
src = inputs.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
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
54
src/modules/Archimedes-Modules/Chess/ChessClient/default.nix
Normal file
54
src/modules/Archimedes-Modules/Chess/ChessClient/default.nix
Normal file
@@ -0,0 +1,54 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.ChessClient = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatClient";
|
||||
|
||||
src = inputs.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 . \
|
||||
-lEGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
41
src/modules/Archimedes-Modules/Chess/ChessServer/default.nix
Normal file
41
src/modules/Archimedes-Modules/Chess/ChessServer/default.nix
Normal file
@@ -0,0 +1,41 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.ChessServer = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "ChatServer";
|
||||
|
||||
src = inputs.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
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
1
src/modules/Archimedes-Modules/Example_Modules.md
Normal file
1
src/modules/Archimedes-Modules/Example_Modules.md
Normal file
@@ -0,0 +1 @@
|
||||
Example modules for Archimedes
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Ollama.h"
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
@@ -18,6 +18,9 @@ Ollama::~Ollama() {
|
||||
curl = nullptr;
|
||||
}
|
||||
curl_global_cleanup();
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +39,7 @@ void Ollama::onLoad() {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->getContext());
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
@@ -111,7 +114,7 @@ void Ollama::run() {
|
||||
|
||||
if(code != CURLE_OK) {
|
||||
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
|
||||
app->stopModule(name);
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
return;
|
||||
} else {
|
||||
jsonObj = nlohmann::json::parse(response);
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "extratools.h"
|
||||
|
||||
class Ollama : public Archimedes::Module {
|
||||
|
||||
@@ -21,6 +20,6 @@ class Ollama : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef OLLAMA_DYNAMIC
|
||||
#define MODULE_TYPE Ollama
|
||||
typedef Ollama mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
55
src/modules/Archimedes-Modules/Ollama/default.nix
Normal file
55
src/modules/Archimedes-Modules/Ollama/default.nix
Normal file
@@ -0,0 +1,55 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.Ollama = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Ollama";
|
||||
|
||||
src = inputs.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 . \
|
||||
-lEGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -13,5 +13,5 @@ Print::~Print() {
|
||||
void Print::run() {
|
||||
std::cout << "Print lib loaded and run!\n";
|
||||
|
||||
app->stopModule(name);
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
}
|
||||
@@ -10,6 +10,6 @@ class Print : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef PRINT_DYNAMIC
|
||||
#define MODULE_TYPE Print
|
||||
typedef Print mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
34
src/modules/Archimedes-Modules/Print/default.nix
Normal file
34
src/modules/Archimedes-Modules/Print/default.nix
Normal file
@@ -0,0 +1,34 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.Print = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Print";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Print/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include \
|
||||
-Wall \
|
||||
-DPRINT_DYNAMIC \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
453
src/modules/Archimedes-Modules/Sandbox/JObject.h
Normal file
453
src/modules/Archimedes-Modules/Sandbox/JObject.h
Normal file
@@ -0,0 +1,453 @@
|
||||
|
||||
#include "pch.hpp"
|
||||
|
||||
#include "utils/Objects/Body.h"
|
||||
|
||||
#include <stb/stb_truetype.h>
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
namespace Archimedes {
|
||||
|
||||
class Text {
|
||||
|
||||
unsigned int tex;
|
||||
|
||||
std::vector<unsigned char> ttf;
|
||||
|
||||
stbtt_bakedchar bcdata[96];
|
||||
|
||||
std::string fontPath;
|
||||
|
||||
std::string vs = "#version 430 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"layout (location = 1) in vec2 aTex;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform mat4 view;\n"
|
||||
"uniform mat4 proj;\n"
|
||||
"out vec2 TexCoord;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = proj * view * model * vec4(aPos.x, 1.0f - aPos.y, aPos.z, 1.0);\n"
|
||||
" TexCoord = aTex;\n"
|
||||
"}\0";
|
||||
|
||||
std::string fs = "#version 430 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"in vec2 TexCoord;\n"
|
||||
"uniform sampler2D tex;\n"
|
||||
"uniform vec4 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = vec4(color.rgb, texture(tex, TexCoord).r);\n"
|
||||
"}\n\0";
|
||||
|
||||
|
||||
public:
|
||||
Shader shader;
|
||||
Texture texture;
|
||||
|
||||
float fontSize = 200.0f;
|
||||
|
||||
Text() {}
|
||||
~Text() {}
|
||||
|
||||
|
||||
void textInit(std::string p) {
|
||||
|
||||
fontPath = p;
|
||||
|
||||
|
||||
unsigned char temp_bitmap[1024*1024];
|
||||
|
||||
std::ifstream file(fontPath, std::ios::binary);
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
auto&& size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
ttf.reserve(size);
|
||||
|
||||
if(!file.is_open()) {
|
||||
std::cout << "ttf won't open!\n";
|
||||
}
|
||||
|
||||
while(!file.eof()) {
|
||||
|
||||
ttf.push_back(file.get());
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
stbtt_BakeFontBitmap(ttf.data(),0, fontSize, temp_bitmap,1024,1024, 32,96, bcdata);
|
||||
|
||||
std::vector<unsigned char> bin;
|
||||
bin.reserve(1024 * 1024);
|
||||
|
||||
for(unsigned char c : temp_bitmap) {
|
||||
bin.push_back(c);
|
||||
}
|
||||
|
||||
texture = Texture(bin, 1024, 1024);
|
||||
|
||||
shader = Shader(vs, fs, Shader::LoadType::FromSource);
|
||||
}
|
||||
|
||||
Body* genText(std::vector<std::string> texts) {
|
||||
|
||||
std::vector<float> v;
|
||||
std::vector<unsigned int> i;
|
||||
|
||||
float x = 0, y = 0, oX = 0, dY = fontSize;
|
||||
|
||||
unsigned int k = 0;
|
||||
|
||||
for(std::string text : texts) {
|
||||
for(unsigned int j = 0; j < text.length(); j++) {
|
||||
if (text[j] >= 32) {
|
||||
stbtt_aligned_quad q;
|
||||
stbtt_GetBakedQuad(bcdata, 1024,1024, text[j]-32, &x,&y,&q,0);//1=opengl & d3d10+,0=d3d9
|
||||
|
||||
//bcdata[text[j]-32].xadvance
|
||||
v.push_back(q.x0);
|
||||
v.push_back(q.y0);
|
||||
v.push_back(0.0f);
|
||||
|
||||
v.push_back(q.s0);
|
||||
v.push_back(q.t0);
|
||||
|
||||
|
||||
|
||||
v.push_back(q.x1);
|
||||
v.push_back(q.y0);
|
||||
v.push_back(0.0f);
|
||||
|
||||
v.push_back(q.s1);
|
||||
v.push_back(q.t0);
|
||||
|
||||
|
||||
|
||||
|
||||
v.push_back(q.x1);
|
||||
v.push_back(q.y1);
|
||||
v.push_back(0.0f);
|
||||
|
||||
v.push_back(q.s1);
|
||||
v.push_back(q.t1);
|
||||
|
||||
|
||||
|
||||
|
||||
v.push_back(q.x0);
|
||||
v.push_back(q.y1);
|
||||
v.push_back(0.0f);
|
||||
|
||||
v.push_back(q.s0);
|
||||
v.push_back(q.t1);
|
||||
|
||||
i.push_back(k * 4);
|
||||
i.push_back(k * 4 + 1);
|
||||
i.push_back(k * 4 + 2);
|
||||
i.push_back(k * 4 + 2);
|
||||
i.push_back(k * 4 + 3);
|
||||
i.push_back(k * 4);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
|
||||
x = oX;
|
||||
y += dY;
|
||||
}
|
||||
|
||||
|
||||
return new Body(
|
||||
VertexBuffer(v),
|
||||
IndexArray(i),
|
||||
VertexLayout({
|
||||
LayoutElement(LayoutElement::Type::Float, 3, 5 * sizeof(float), 0),
|
||||
LayoutElement(LayoutElement::Type::Float, 2, 5 * sizeof(float), 3 * sizeof(float))
|
||||
}),
|
||||
shader,
|
||||
texture,
|
||||
RenderMode::Triangles,
|
||||
glm::scale(glm::mat4(1.0f), glm::vec3(0.2f))
|
||||
);
|
||||
}
|
||||
|
||||
float textWidth(std::string str, float height) {
|
||||
|
||||
float w = 0;
|
||||
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
stbtt_bakedchar c = bcdata[str[i]];
|
||||
w += c.xadvance;
|
||||
}
|
||||
|
||||
return w * height / fontSize;
|
||||
}
|
||||
};
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
class JObject {
|
||||
|
||||
public:
|
||||
JObject() {}
|
||||
|
||||
void load(std::string pathJSON, std::string pathFont) {
|
||||
std::ifstream file(pathJSON);
|
||||
if (!file.is_open()) goodJSON = false;
|
||||
document = json::parse(file);
|
||||
file.close();
|
||||
goodJSON = true;
|
||||
templates = document["Templates"];
|
||||
objects = document["Objects"];
|
||||
setup = document["Set Up"];
|
||||
cameras = document["Cameras"];
|
||||
lights = document["Lights"];
|
||||
actions = document["Actions"];
|
||||
|
||||
text.textInit(pathFont);
|
||||
}
|
||||
|
||||
bool isValid() const { return goodJSON; }
|
||||
|
||||
Body* createCircle(json& element, std::string name) {
|
||||
std::vector<float> v;
|
||||
std::vector<unsigned int> i;
|
||||
|
||||
float d = element["diameter"];
|
||||
|
||||
for(int it = 0; it < resolution; it++) {
|
||||
v.push_back(d / 2.0f * glm::cos(it * 2.0f * glm::pi<float>() / resolution));
|
||||
v.push_back(d / 2.0f * glm::sin(it * 2.0f * glm::pi<float>() / resolution));
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(it);
|
||||
}
|
||||
|
||||
return new Body(
|
||||
VertexBuffer(v),
|
||||
IndexArray(i),
|
||||
layout,
|
||||
shader,
|
||||
std::nullopt,
|
||||
RenderMode::ConnectedLinesLooped
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Body* createSquare(json& element, std::string name) {
|
||||
std::vector<float> v;
|
||||
std::vector<unsigned int> i;
|
||||
|
||||
float width = element["width"];
|
||||
|
||||
v.push_back(width / 2.0f);
|
||||
v.push_back(width / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(0);
|
||||
|
||||
v.push_back(-width / 2.0f);
|
||||
v.push_back(width / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(1);
|
||||
|
||||
v.push_back(-width / 2.0f);
|
||||
v.push_back(-width / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(2);
|
||||
|
||||
v.push_back(width / 2.0f);
|
||||
v.push_back(-width / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(3);
|
||||
|
||||
return new Body(
|
||||
VertexBuffer(v),
|
||||
IndexArray(i),
|
||||
layout,
|
||||
shader,
|
||||
std::nullopt,
|
||||
RenderMode::ConnectedLinesLooped
|
||||
);
|
||||
}
|
||||
|
||||
Body* createRect(json& element, std::string name) {
|
||||
std::vector<float> v;
|
||||
std::vector<unsigned int> i;
|
||||
|
||||
float width = element["width"];
|
||||
float height = element["height"];
|
||||
|
||||
v.push_back(width / 2.0f);
|
||||
v.push_back(height / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(0);
|
||||
|
||||
v.push_back(-width / 2.0f);
|
||||
v.push_back(height / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(1);
|
||||
|
||||
v.push_back(-width / 2.0f);
|
||||
v.push_back(-height / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(2);
|
||||
|
||||
v.push_back(width / 2.0f);
|
||||
v.push_back(-height / 2.0f);
|
||||
v.push_back(0.0f);
|
||||
|
||||
i.push_back(3);
|
||||
|
||||
return new Body(
|
||||
VertexBuffer(v),
|
||||
IndexArray(i),
|
||||
layout,
|
||||
shader,
|
||||
std::nullopt,
|
||||
RenderMode::ConnectedLinesLooped
|
||||
);
|
||||
}
|
||||
|
||||
Body* createPoly(json& element, std::string name) {
|
||||
std::vector<float> v;
|
||||
std::vector<unsigned int> i;
|
||||
|
||||
json coords = element["coords"];
|
||||
|
||||
unsigned int j = 0;
|
||||
for(json::const_iterator it = coords.cbegin(); it != coords.cend(); it++) {
|
||||
json c = *it;
|
||||
v.push_back(c["x"]);
|
||||
v.push_back(c["y"]);
|
||||
v.push_back(c["z"]);
|
||||
|
||||
i.push_back(j++);
|
||||
}
|
||||
|
||||
return new Body(
|
||||
VertexBuffer(v),
|
||||
IndexArray(i),
|
||||
layout,
|
||||
shader,
|
||||
std::nullopt,
|
||||
RenderMode::ConnectedLinesLooped
|
||||
);
|
||||
}
|
||||
|
||||
Body* createText(json& element, std::string name) {
|
||||
//do something
|
||||
json lines = element["text"];
|
||||
|
||||
std::vector<std::string> theText;
|
||||
for (json::const_iterator it = lines.cbegin(); it != lines.cend(); it++)
|
||||
{
|
||||
std::string line = *it;
|
||||
theText.push_back(line);
|
||||
}
|
||||
|
||||
return text.genText(theText);
|
||||
}
|
||||
|
||||
void buildObjects() {
|
||||
|
||||
|
||||
for (json::const_iterator it = objects.cbegin(); it != objects.cend(); it++)
|
||||
{
|
||||
json element = *it;
|
||||
std::string name = element["name"];
|
||||
std::string type = element["type"];
|
||||
if (type == "CIRCLE") {
|
||||
objectMap[name] = createCircle(element, name);
|
||||
}
|
||||
if (type == "SQUARE") {
|
||||
objectMap[name] = createSquare(element, name);
|
||||
}
|
||||
if (type == "RECTANGLE") {
|
||||
objectMap[name] = createRect(element, name);
|
||||
}
|
||||
if (type == "POLYGON") {
|
||||
objectMap[name] = createPoly(element, name);
|
||||
}
|
||||
if (type == "TEXT") {
|
||||
objectMap[name] = createText(element, name);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void objectActions()
|
||||
{
|
||||
for (json::const_iterator it = setup.cbegin(); it != setup.cend(); it++)
|
||||
{
|
||||
json element = *it;
|
||||
std::string name = element["name"];
|
||||
Body* o = objectMap[name];
|
||||
if (o == nullptr) continue;
|
||||
if (element.contains("moveto"))
|
||||
{
|
||||
json moveTo = element["moveto"];
|
||||
float x = moveTo["x"];
|
||||
float y = moveTo["y"];
|
||||
float z = moveTo["z"];
|
||||
o->moveTo(glm::vec3(x, y, z));
|
||||
}
|
||||
if (element.contains("moveby"))
|
||||
{
|
||||
json moveBy = element["moveby"];
|
||||
float x = moveBy["x"];
|
||||
float y = moveBy["y"];
|
||||
float z = moveBy["z"];
|
||||
o->moveRel(glm::vec3(x, y, z));
|
||||
}
|
||||
if (element.contains("rotateto"))
|
||||
{
|
||||
json rotateTo = element["rotateto"];
|
||||
float p = rotateTo["pitch"];
|
||||
float y = rotateTo["yaw"];
|
||||
float r = rotateTo["roll"];
|
||||
o->rotateTo(glm::vec3(p, y, r));
|
||||
}
|
||||
if (element.contains("rotateby"))
|
||||
{
|
||||
json rotateBy = element["rotateby"];
|
||||
float p = rotateBy["pitch"];
|
||||
float y = rotateBy["yaw"];
|
||||
float r = rotateBy["roll"];
|
||||
o->rotateRel(glm::vec3(p, y, r));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::unordered_map<std::string, Body*> objectMap;
|
||||
Shader shader;
|
||||
|
||||
Text text;
|
||||
private:
|
||||
|
||||
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 0, 0)
|
||||
});
|
||||
|
||||
std::unordered_map<std::string, Body> templateMap;
|
||||
|
||||
bool goodJSON = false;
|
||||
|
||||
|
||||
unsigned int resolution = 50;
|
||||
|
||||
json document, templates, objects, setup, cameras, lights, actions;
|
||||
};
|
||||
}
|
||||
|
||||
309
src/modules/Archimedes-Modules/Sandbox/Sandbox.cpp
Normal file
309
src/modules/Archimedes-Modules/Sandbox/Sandbox.cpp
Normal file
@@ -0,0 +1,309 @@
|
||||
// This only works with opengl!!!!
|
||||
|
||||
|
||||
#include "Sandbox.h"
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb/stb_truetype.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb/stb_image_write.h>
|
||||
|
||||
Sandbox::Sandbox(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Sandbox";
|
||||
|
||||
WindowModule* wm = new WindowModule(a, h);
|
||||
deps[*wm] = wm;
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Sandbox::~Sandbox() {
|
||||
|
||||
if(app) {
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
|
||||
wm->releaseWindow(window);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Sandbox::onLoad() {
|
||||
// get window
|
||||
WindowModule* wm; { wm = (WindowModule*) moduleInstances[WindowModule()]; }
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!wm) {
|
||||
std::cout << "No WindowModule for Sandbox!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Sandbox!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
window = wm->aquireWindow();
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
window->getRenderer()->clearColor = { 0.2, 0.2, 0.4, 0.7 };
|
||||
|
||||
|
||||
cubeShader = Archimedes::Shader(cubeVS, cubeFS, Archimedes::Shader::LoadType::FromSource);
|
||||
|
||||
window->getRenderer()->setupShader(cubeShader);
|
||||
|
||||
cube = Archimedes::Body(
|
||||
Archimedes::VertexBuffer(vertices),
|
||||
Archimedes::IndexArray(indices),
|
||||
layout,
|
||||
cubeShader
|
||||
);
|
||||
|
||||
window->getRenderer()->setupRenderTarget(cube.getMesh());
|
||||
|
||||
grid = Archimedes::Body(
|
||||
Archimedes::VertexBuffer(gridVertices),
|
||||
Archimedes::IndexArray(gridIndices),
|
||||
layout,
|
||||
cubeShader
|
||||
);
|
||||
|
||||
window->getRenderer()->setupRenderTarget(grid.getMesh());
|
||||
|
||||
|
||||
int w, h;
|
||||
window->getSize(w, h);
|
||||
app->emitEvent(new Archimedes::ResizeWindowEvent(w, h));
|
||||
|
||||
hexagon = readOBJ("/home/nathan/Projects/tests/buildzone/hexagon_pad.obj", cubeShader);
|
||||
|
||||
window->getRenderer()->setupRenderTarget(hexagon.getMesh());
|
||||
|
||||
|
||||
hexagon.scaleTo(0.01f);
|
||||
|
||||
|
||||
camera.setTransform(glm::lookAt(
|
||||
glm::vec3(0.0f, 0.0f, 3.0f),
|
||||
glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||
));
|
||||
|
||||
camera.setPerspective(glm::perspective(glm::radians(45.0f), (float)w/(float)h, 0.1f, 100.0f));
|
||||
//camera.setPerspective(glm::ortho(-(float)w / 2.0f, (float)w / 2.0f, -(float)h / 2.0f, (float)h / 2.0f, 0.1f, 100.0f));
|
||||
}
|
||||
|
||||
void Sandbox::run() {
|
||||
|
||||
static float scale = 1.0f, scalePrev = 1.0f;
|
||||
|
||||
static glm::vec3 pos(0), rot(0);
|
||||
static glm::vec3 posPrev(0), rotPrev(0);
|
||||
|
||||
static glm::vec3 camPos(0.0f, 0.0f, 3.0f), camRot(0.0f, glm::pi<float>(), 0.0f);
|
||||
static glm::vec3 camPosPrev(0.0f, 0.0f, 3.0f), camRotPrev(0.0f, glm::pi<float>(), 0.0f);
|
||||
|
||||
static glm::vec4 color = { 0.4f, 3.0f, 0.4f, 1.0f };
|
||||
|
||||
static int w, h;
|
||||
window->getSize(w, h);
|
||||
//camPos = camera.moveRel(camPos - camPosPrev);
|
||||
//camRot = camera.rotateRel(camRot - camRotPrev);
|
||||
|
||||
camera.setTransform(glm::lookAt(
|
||||
camPos,
|
||||
camPos + glm::normalize(glm::vec3(glm::cos(camRot.x) * glm::sin(camRot.y), glm::sin(camRot.x), glm::cos(camRot.x) * glm::cos(camRot.y))),
|
||||
glm::vec3(0.0f, 1.0f, 0.0f)
|
||||
));
|
||||
|
||||
camPosPrev = camPos;
|
||||
camRotPrev = camRot;
|
||||
|
||||
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
static glm::vec4& clearColor = window->getRenderer()->clearColor;
|
||||
|
||||
ImGui::Begin("Sandbox Module");
|
||||
|
||||
ImGui::Text("Pick a clear color!");
|
||||
|
||||
ImGui::SliderFloat("clear r", &clearColor.r, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("clear g", &clearColor.g, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("clear b", &clearColor.b, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("clear a", &clearColor.a, 0.0f, 1.0f);
|
||||
|
||||
if(jObject.isValid()) {
|
||||
ImGui::Text("Object Properties");
|
||||
|
||||
static std::string object = jObject.objectMap.begin()->first;
|
||||
|
||||
if(ImGui::BeginCombo("Object", object.c_str())) {
|
||||
for (auto it : jObject.objectMap)
|
||||
{
|
||||
|
||||
const bool is_selected = (object == it.first);
|
||||
if (ImGui::Selectable(it.first.c_str(), is_selected)) {
|
||||
object = it.first;
|
||||
}
|
||||
|
||||
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
for (auto it : jObject.objectMap) {
|
||||
if(it.second != nullptr) {
|
||||
window->getRenderer()->draw(
|
||||
it.second->getMesh(),
|
||||
it.second->getTransform(),
|
||||
camera.getTransform(),
|
||||
camera.getPerspective(),
|
||||
color
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::SliderFloat("pitch", &rot.x, -glm::pi<float>(), glm::pi<float>());
|
||||
ImGui::SliderFloat("yaw", &rot.y, -glm::pi<float>(), glm::pi<float>());
|
||||
ImGui::SliderFloat("roll", &rot.z, -glm::pi<float>(), glm::pi<float>());
|
||||
|
||||
ImGui::SliderFloat("scale", &scale, 0.001f, 10.0f);
|
||||
|
||||
ImGui::SliderFloat("x", &pos.x, -10.0f, 10.0f);
|
||||
ImGui::SliderFloat("y", &pos.y, -10.0f, 10.0f);
|
||||
ImGui::SliderFloat("z", &pos.z, -10.0f, 10.0f);
|
||||
|
||||
ImGui::SliderFloat("r", &color.r, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("g", &color.g, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("b", &color.b, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("a", &color.a, 0.0f, 1.0f);
|
||||
|
||||
if(ImGui::Button("Apply") && jObject.objectMap[object] != nullptr) {
|
||||
pos = jObject.objectMap[object]->moveRel(pos - posPrev);
|
||||
rot = jObject.objectMap[object]->rotateRel(rot - rotPrev);
|
||||
//scale = jObject.objectMap[object]->scaleRel(scale / scalePrev);
|
||||
jObject.objectMap[object]->scaleTo(scale / (float)h);
|
||||
|
||||
|
||||
posPrev = pos;
|
||||
rotPrev = rot;
|
||||
//scalePrev = scale;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
static std::string pathJSON = "/home/nathan/Projects/tests/buildzone/test.json";
|
||||
static std::string pathFont = "/nix/store/05zf1s3wlw0k90l34iaby4ysrafv6w95-nerd-fonts-fira-code-3.4.0+6.2/share/fonts/truetype/NerdFonts/FiraCode/FiraCodeNerdFontMono-Regular.ttf";
|
||||
ImGui::InputText("JSON Path", &pathJSON);
|
||||
ImGui::InputText("Font Path", &pathFont);
|
||||
if(ImGui::Button("load")) {
|
||||
|
||||
jObject.shader = cubeShader;
|
||||
|
||||
jObject.load(pathJSON, pathFont);
|
||||
|
||||
window->getRenderer()->setupShader(jObject.text.shader);
|
||||
//window->getRenderer()->setupTexture(jObject.text.texture);
|
||||
|
||||
jObject.buildObjects();
|
||||
|
||||
for(auto o : jObject.objectMap) {
|
||||
if(o.second != nullptr) {
|
||||
o.second->scaleTo(1.0f / (float)h);
|
||||
window->getRenderer()->setupRenderTarget(o.second->getMesh());
|
||||
}
|
||||
}
|
||||
|
||||
jObject.objectActions();
|
||||
}
|
||||
}
|
||||
|
||||
static bool show_obj = true;
|
||||
ImGui::Checkbox("show obj", &show_obj);
|
||||
if(show_obj) {
|
||||
window->getRenderer()->draw(
|
||||
hexagon.getMesh(),
|
||||
hexagon.getTransform(),
|
||||
camera.getTransform(),
|
||||
camera.getPerspective(),
|
||||
color
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::Text("Camera Properties");
|
||||
|
||||
ImGui::SliderFloat("cam pitch", &camRot.x, -glm::pi<float>(), glm::pi<float>());
|
||||
ImGui::SliderFloat("cam yaw", &camRot.y, 0, 2 * glm::pi<float>());
|
||||
ImGui::SliderFloat("cam roll", &camRot.z, -glm::pi<float>(), glm::pi<float>());
|
||||
|
||||
ImGui::SliderFloat("cam x", &camPos.x, -10.0f, 10.0f);
|
||||
ImGui::SliderFloat("cam y", &camPos.y, -10.0f, 10.0f);
|
||||
ImGui::SliderFloat("cam z", &camPos.z, -10.0f, 10.0f);
|
||||
|
||||
|
||||
if(ImGui::Button("Reset Window Size")) {
|
||||
app->emitEvent(new Archimedes::ResizeWindowEvent(500, 500));
|
||||
}
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
bool Sandbox::onEvent(const Archimedes::Event& e) {
|
||||
|
||||
unsigned int type = app->getEventType(e);
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
|
||||
if(type == app->getEventType(Archimedes::ResizeWindowEvent())) {
|
||||
Archimedes::ResizeWindowEvent event = (Archimedes::ResizeWindowEvent&) e;
|
||||
|
||||
camera.setPerspective(glm::perspective(glm::radians(45.0f), (float)event.width/(float)event.height, 0.1f, 100.0f));
|
||||
|
||||
} else if(type == app->getEventType(Archimedes::KeyPressedWindowEvent()) && !io.WantCaptureKeyboard) {
|
||||
|
||||
return false;
|
||||
} else if(type == app->getEventType(Archimedes::KeyReleasedWindowEvent()) && !io.WantCaptureKeyboard) {
|
||||
|
||||
return false;
|
||||
} else if(type == app->getEventType(Archimedes::MouseButtonPressedWindowEvent()) && !io.WantCaptureMouse) {
|
||||
|
||||
return false;
|
||||
} else if(type == app->getEventType(Archimedes::MouseButtonReleasedWindowEvent()) && !io.WantCaptureMouse) {
|
||||
|
||||
return false;
|
||||
} else if(type == app->getEventType(Archimedes::ScrollWindowEvent()) && !io.WantCaptureMouse) {
|
||||
|
||||
Archimedes::ScrollWindowEvent event = (Archimedes::ScrollWindowEvent&) e;
|
||||
|
||||
//cube.rotateRel(glm::vec3(glm::pi<float>() * event.dy / 50.0f, 0.0f, 0.0f));
|
||||
|
||||
//cube.rotateRel(glm::vec3(0.0f, glm::pi<float>() * event.dx / 50.0f, 0.0f));
|
||||
|
||||
hexagon.scaleAdd(0.001f * event.dy);
|
||||
|
||||
return true;
|
||||
} else if(type == app->getEventType(Archimedes::MouseMovedWindowEvent()) && !io.WantCaptureMouse) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
228
src/modules/Archimedes-Modules/Sandbox/Sandbox.h
Normal file
228
src/modules/Archimedes-Modules/Sandbox/Sandbox.h
Normal file
@@ -0,0 +1,228 @@
|
||||
// This only works with opengl!!!!
|
||||
|
||||
#ifndef JOBJECT_H
|
||||
#define JOBJECT_H
|
||||
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/WindowModule/WindowModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include "utils/Objects/Body.h"
|
||||
#include "utils/Objects/Camera.h"
|
||||
|
||||
#include "JObject.h"
|
||||
|
||||
class Sandbox : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Sandbox(Archimedes::App*, void*);
|
||||
|
||||
Sandbox() { name = "Sandbox"; }
|
||||
|
||||
~Sandbox();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event& e) override;
|
||||
|
||||
private:
|
||||
|
||||
Archimedes::Window* window;
|
||||
|
||||
std::string cubeVS = "#version 430 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform mat4 view;\n"
|
||||
"uniform mat4 proj;\n"
|
||||
"uniform vec4 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = proj * view * model * vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||
"}\0";
|
||||
|
||||
std::string cubeFS = "#version 430 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform mat4 model;\n"
|
||||
"uniform mat4 view;\n"
|
||||
"uniform mat4 proj;\n"
|
||||
"uniform vec4 color;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = color;\n"
|
||||
"}\n\0";
|
||||
|
||||
Archimedes::JObject jObject;
|
||||
|
||||
Archimedes::Shader cubeShader, gridShader;
|
||||
Archimedes::Body cube, grid, hexagon;
|
||||
|
||||
Archimedes::VertexLayout layout = Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 0, 0)
|
||||
});
|
||||
|
||||
Archimedes::Camera camera;
|
||||
|
||||
std::vector<float> gridVertices = {
|
||||
-1.0f, 0.0f, 1.0f,
|
||||
1.0f, 0.0f, 1.0f,
|
||||
1.0f, 0.0f, -1.0f,
|
||||
-1.0f, 0.0f, -1.0f,
|
||||
};
|
||||
|
||||
std::vector<unsigned int> gridIndices = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
0
|
||||
};
|
||||
|
||||
std::vector<float> vertices = {
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
|
||||
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
|
||||
};
|
||||
|
||||
std::vector<unsigned int> indices = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
3,
|
||||
0,
|
||||
|
||||
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
4,
|
||||
|
||||
|
||||
0,
|
||||
1,
|
||||
5,
|
||||
5,
|
||||
4,
|
||||
0,
|
||||
|
||||
|
||||
3,
|
||||
2,
|
||||
6,
|
||||
6,
|
||||
7,
|
||||
3,
|
||||
|
||||
|
||||
0,
|
||||
3,
|
||||
7,
|
||||
7,
|
||||
4,
|
||||
0,
|
||||
|
||||
|
||||
1,
|
||||
2,
|
||||
6,
|
||||
6,
|
||||
5,
|
||||
1,
|
||||
|
||||
};
|
||||
|
||||
Archimedes::Body readOBJ(std::string path, Archimedes::Shader shader) {
|
||||
|
||||
std::ifstream file(path);
|
||||
|
||||
if(!file.is_open()) return Archimedes::Body();
|
||||
|
||||
std::string s;
|
||||
|
||||
std::vector<float> verticies;
|
||||
std::vector<unsigned int> indicies;
|
||||
|
||||
verticies.reserve(3 * 100);
|
||||
indicies.reserve(100);
|
||||
|
||||
unsigned int i = 0;
|
||||
unsigned int j = 0;
|
||||
|
||||
float point;
|
||||
unsigned int idx;
|
||||
|
||||
while(!file.eof()) {
|
||||
getline(file, s, ' ');
|
||||
|
||||
//std::cout << "\nline start: " << s << std::endl;
|
||||
|
||||
if(s == "v") {
|
||||
file >> point;
|
||||
verticies.push_back(point);
|
||||
//std::cout << "point1: " << point << std::endl;
|
||||
|
||||
file >> point;
|
||||
verticies.push_back(point);
|
||||
//std::cout << "point2: " << point << std::endl;
|
||||
|
||||
file >> point;
|
||||
verticies.push_back(point);
|
||||
//std::cout << "point3: " << point << std::endl;
|
||||
|
||||
//std::cout << "index: " << j << std::endl;
|
||||
|
||||
getline(file, s);
|
||||
//file.ignore();
|
||||
} else if(s == "f") {
|
||||
|
||||
file >> idx;
|
||||
indicies.push_back(--idx);
|
||||
file.ignore(5, ' ');
|
||||
|
||||
file >> idx;
|
||||
indicies.push_back(--idx);
|
||||
file.ignore(5, ' ');
|
||||
|
||||
file >> idx;
|
||||
indicies.push_back(--idx);
|
||||
getline(file, s);
|
||||
|
||||
} else {
|
||||
getline(file, s);
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
return Archimedes::Body(
|
||||
Archimedes::VertexBuffer(verticies),
|
||||
Archimedes::IndexArray(indicies),
|
||||
Archimedes::VertexLayout({
|
||||
Archimedes::LayoutElement(Archimedes::LayoutElement::Type::Float, 3, 3 * sizeof(float), 0),
|
||||
}),
|
||||
shader
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#ifdef SANDBOX_DYNAMIC
|
||||
typedef Sandbox mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
58
src/modules/Archimedes-Modules/Sandbox/default.nix
Normal file
58
src/modules/Archimedes-Modules/Sandbox/default.nix
Normal file
@@ -0,0 +1,58 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.Sandbox = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Sandbox";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
glm
|
||||
curl
|
||||
nlohmann_json
|
||||
|
||||
stb
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Sandbox/*.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=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-DSANDBOX_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lEGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -17,7 +17,11 @@ Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
}
|
||||
|
||||
Terminal::~Terminal() {
|
||||
if(app) {}
|
||||
if(app) {
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::onLoad() {
|
||||
@@ -29,7 +33,7 @@ void Terminal::onLoad() {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->getContext());
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
|
||||
|
||||
@@ -67,7 +71,7 @@ void Terminal::run() {
|
||||
rc = read(master, opArr, 150);
|
||||
if(rc < 0) {
|
||||
//error on read
|
||||
app->stopModule(name);
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
} else {
|
||||
if(input == "clear") output = "";
|
||||
output += opArr;
|
||||
@@ -16,6 +16,6 @@ class Terminal : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef TERMINAL_DYNAMIC
|
||||
#define MODULE_TYPE Terminal
|
||||
typedef Terminal mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
56
src/modules/Archimedes-Modules/Terminal/default.nix
Normal file
56
src/modules/Archimedes-Modules/Terminal/default.nix
Normal file
@@ -0,0 +1,56 @@
|
||||
{ inputs, ... }: {
|
||||
|
||||
|
||||
perSystem = { system, pkgs, self', ... }: {
|
||||
packages.Terminal = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Terminal";
|
||||
|
||||
src = inputs.src;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
|
||||
curl
|
||||
glm
|
||||
nlohmann_json
|
||||
];
|
||||
|
||||
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_OPENGL=1 \
|
||||
-DWINDOW_GLFW=1 \
|
||||
-DTERMINAL_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lEGL -lglfw -lGLEW \
|
||||
$(curl-config --cflags) \
|
||||
$(curl-config --libs) \
|
||||
-Wall \
|
||||
-o $name -DIMGUI_IMPL_GLFW_DISABLE_X11
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user