Compare commits
24 Commits
700e422270
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c107ce732c | |||
| ad658d914c | |||
| f6ad110880 | |||
| cb5762a3fe | |||
| 45f1d0f69d | |||
| dffca865dc | |||
| 32223cfa05 | |||
| 3196f7b81a | |||
| 08bccb1e70 | |||
| 2e0341a12e | |||
| b4309ab4e9 | |||
| 2350592424 | |||
| 9d63e16032 | |||
| 501649d236 | |||
| e139696d6a | |||
| 79f4a5288f | |||
| 80e0709278 | |||
| 9f1e77cb9e | |||
| d3fe8598cd | |||
| 38e398e367 | |||
| 3a82e9b4ec | |||
| 5319e2309b | |||
| f86eb4ab90 | |||
| bab30c6124 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "modules/Archimedes-Modules"]
|
||||
path = modules/Archimedes-Modules
|
||||
url = blunkall:Blunkall-Technologies/Archimedes-Modules
|
||||
@@ -54,7 +54,7 @@
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/ImguiEmbed/*.cpp \
|
||||
modules/examples/TestImgui/*.cpp \
|
||||
modules/Archimedes-Modules/TestImgui/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
@@ -96,7 +96,7 @@
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
src/example_apps/TerminalEmbed/*.cpp \
|
||||
modules/Terminal/*.cpp \
|
||||
modules/Archimedes-Modules/Terminal/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
|
||||
@@ -166,8 +166,8 @@
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DTESTIMGUI_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
@@ -183,6 +183,49 @@
|
||||
|
||||
};
|
||||
|
||||
Calculator = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "Calculator";
|
||||
|
||||
src = ./.;
|
||||
|
||||
imgui = inputs.imgui;
|
||||
|
||||
nativeBuildInputs = with pkgs; [
|
||||
clang
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
glfw
|
||||
glew
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/Calculator/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DCALCULATOR_DYNAMIC \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
-Wall \
|
||||
-o $name
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp $name $out/bin
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
TestClay = pkgs.stdenvNoCC.mkDerivation {
|
||||
|
||||
name = "TestClay";
|
||||
@@ -200,8 +243,8 @@
|
||||
modules/Archimedes-Modules/TestClay/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-DTESTCLAY_DYNAMIC \
|
||||
-Wall \
|
||||
-o $name
|
||||
@@ -230,7 +273,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/ChatServer/*.cpp \
|
||||
modules/Archimedes-Modules/Chat/ChatServer/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
@@ -264,7 +307,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/ChatServerVoice/*.cpp \
|
||||
modules/Archimedes-Modules/ChatVoice/ChatServerVoice/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
@@ -302,7 +345,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/ChatClient/*.cpp \
|
||||
modules/Archimedes-Modules/Chat/ChatClient/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
@@ -313,8 +356,8 @@
|
||||
$imgui/backends/imgui_impl_opengl3.cpp \
|
||||
$imgui/misc/cpp/*.cpp \
|
||||
$imgui/*.cpp \
|
||||
-DRENDERER_OPENGL \
|
||||
-DWINDOW_GLFW \
|
||||
-DRENDERER=1 \
|
||||
-DWINDOW=1 \
|
||||
-fpic -shared \
|
||||
-I include -I $imgui -I . \
|
||||
-lGL -lglfw -lGLEW \
|
||||
@@ -349,7 +392,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Archimedes-Modules/ChatClientVoice/*.cpp \
|
||||
modules/Archimedes-Modules/ChatVoice/ChatClientVoice/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
@@ -395,7 +438,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Terminal/*.cpp \
|
||||
modules/Archimedes-Modules/Terminal/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
@@ -441,7 +484,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
modules/Ollama/*.cpp \
|
||||
modules/Archimedes-Modules/Ollama/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
|
||||
18
flake.lock
generated
18
flake.lock
generated
@@ -3,11 +3,11 @@
|
||||
"clay": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1742509368,
|
||||
"narHash": "sha256-XSaMuWCADZgZnRaGcBgf+u40O6jS5kkpq3Xruy6z+I0=",
|
||||
"lastModified": 1746753934,
|
||||
"narHash": "sha256-7Kx536YsmPTXUjs/jBknGAmqYsqqDh6T11AlarTeGLM=",
|
||||
"owner": "nicbarker",
|
||||
"repo": "clay",
|
||||
"rev": "ad49977f1b37ccd7664333181f30f575d08d3838",
|
||||
"rev": "76265e4c3c97ebe5a4aab081d5c5a05e5a979d5d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -19,11 +19,11 @@
|
||||
"imgui": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1741968903,
|
||||
"narHash": "sha256-4L37NRR+dlkhdxuDjhLR45kgjyZK2uelKBlGZ1nQzgY=",
|
||||
"lastModified": 1747034542,
|
||||
"narHash": "sha256-kVbyG7LXXHIOiI6dlZVID9DLErR+XNoAGp/R82TEpgo=",
|
||||
"owner": "ocornut",
|
||||
"repo": "imgui",
|
||||
"rev": "126d004f9e1eef062bf4b044b3b2faaf58d48c51",
|
||||
"rev": "e33069ce56d07751ca875eb239f41febef0ebcd3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -35,11 +35,11 @@
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1742136038,
|
||||
"narHash": "sha256-DDe16FJk18sadknQKKG/9FbwEro7A57tg9vB5kxZ8kY=",
|
||||
"lastModified": 1746957726,
|
||||
"narHash": "sha256-k9ut1LSfHCr0AW82ttEQzXVCqmyWVA5+SHJkS5ID/Jo=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a1185f4064c18a5db37c5c84e5638c78b46e3341",
|
||||
"rev": "a39ed32a651fdee6842ec930761e31d1f242cb94",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, imgui, clay }@inputs: let
|
||||
outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in {
|
||||
@@ -255,6 +255,8 @@
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
packages.${system}.default = self.Archimedes.examples.MinimalApp;
|
||||
|
||||
apps.${system}.default = {
|
||||
@@ -263,6 +265,4 @@
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#ifdef MODULE_TYPE
|
||||
|
||||
extern "C" {
|
||||
Archimedes::Module* create(Archimedes::App* app, void* handle) {
|
||||
return new MODULE_TYPE(app, handle);
|
||||
return new mtype(app, handle);
|
||||
}
|
||||
}
|
||||
|
||||
#undef MODULE_TYPE
|
||||
#endif
|
||||
|
||||
Submodule modules/Archimedes-Modules deleted from 3c4a75ec21
353
modules/Archimedes-Modules/Calculator/Calculator.cpp
Normal file
353
modules/Archimedes-Modules/Calculator/Calculator.cpp
Normal file
@@ -0,0 +1,353 @@
|
||||
#include "Calculator.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
Calculator::Calculator(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Calculator";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Calculator::~Calculator() {
|
||||
|
||||
if(app) {
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void Calculator::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Calculator!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
}
|
||||
|
||||
void Calculator::run() {
|
||||
|
||||
if(open) {
|
||||
basicCalculator();
|
||||
} else {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Calculator::index(std::string equation, std::unordered_map<unsigned int, std::string>& nodes) {
|
||||
unsigned int idx = 0;
|
||||
|
||||
nodes.clear();
|
||||
|
||||
const static std::string operators[] = {
|
||||
"(",
|
||||
")",
|
||||
"^",
|
||||
"*",
|
||||
"/",
|
||||
"+",
|
||||
"-"
|
||||
};
|
||||
|
||||
for(const std::string& s : operators) {
|
||||
|
||||
while(equation.find(s, idx) != std::string::npos) {
|
||||
int next = equation.find(s, idx);
|
||||
nodes[next] = equation.substr(next, s.length());
|
||||
idx = next + s.length();
|
||||
}
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
|
||||
// -3+8*6-(8+4)^9/5
|
||||
for(unsigned int i = 0; i < equation.length(); i++) {
|
||||
static unsigned int begin = 0, end = 0;
|
||||
if(nodes.find(i) == nodes.end()) {
|
||||
if(nodes.find(i - 1) != nodes.end() || i == 0) {
|
||||
//first digit of expression
|
||||
begin = i;
|
||||
}
|
||||
if(nodes.find(i + 1) != nodes.end() || i == equation.length() - 1) {
|
||||
//character after last digit of expression
|
||||
end = i + 1;
|
||||
nodes[begin] = equation.substr(begin, end - begin);
|
||||
nodes[end - 1] = equation.substr(begin, end - begin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double Calculator::evaluate(std::string equation, std::unordered_map<char, std::string>& evalStr) {
|
||||
|
||||
char op = '^';
|
||||
|
||||
while(equation.find(op) == std::string::npos) {
|
||||
switch(op) {
|
||||
case '^':
|
||||
op = '*';
|
||||
break;
|
||||
case '*':
|
||||
op = '/';
|
||||
break;
|
||||
case '/':
|
||||
op = '+';
|
||||
break;
|
||||
case '+':
|
||||
op = '-';
|
||||
break;
|
||||
case '-':
|
||||
//no operator
|
||||
if(evalStr.find(equation.front()) != evalStr.end()) {
|
||||
return evaluate(evalStr[equation.front()], evalStr);
|
||||
} else {
|
||||
return std::stod(equation);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
//op is now the appropriate operator
|
||||
|
||||
//if either term is a placeholder, evaluate and substitute.
|
||||
double a, b;
|
||||
if(evalStr.find(equation.front()) != evalStr.end()) {
|
||||
a = evaluate(evalStr[equation.front()], evalStr);
|
||||
} else {
|
||||
if(equation.find(op) == 0 && op == '-') {
|
||||
a = 0;
|
||||
} else {
|
||||
a = std::stod(equation.substr(0, equation.find(op)));
|
||||
}
|
||||
}
|
||||
|
||||
if(evalStr.find(equation.back()) != evalStr.end()) {
|
||||
b = evaluate(evalStr[equation.back()], evalStr);
|
||||
} else {
|
||||
b = std::stod(equation.substr(equation.find(op) + 1));
|
||||
}
|
||||
switch(op) {
|
||||
case '^':
|
||||
return pow(a, b);
|
||||
case '*':
|
||||
return a * b;
|
||||
case '/':
|
||||
return a / b;
|
||||
case '+':
|
||||
return a + b;
|
||||
case '-':
|
||||
return a - b;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Calculator::calculate(std::string equation) {
|
||||
|
||||
//PEMDAS
|
||||
while(equation.find(' ') != std::string::npos) {
|
||||
equation.erase(equation.find(' '), 1);
|
||||
}
|
||||
while(equation.find('\t') != std::string::npos) {
|
||||
equation.erase(equation.find('\t'), 1);
|
||||
}
|
||||
while(equation.find('\n') != std::string::npos) {
|
||||
equation.erase(equation.find('\n'), 1);
|
||||
}
|
||||
|
||||
std::unordered_map<unsigned int, std::string> nodes;
|
||||
std::unordered_map<char, std::string> evalStr;
|
||||
std::string eval = "a";
|
||||
|
||||
unsigned int idx = 0;
|
||||
|
||||
index(equation, nodes);
|
||||
|
||||
idx = 0;
|
||||
|
||||
// ()
|
||||
while(equation.find(')', idx) != std::string::npos) {
|
||||
int end = equation.find(')');
|
||||
int begin = equation.rfind('(', end);
|
||||
evalStr[eval.front()] = calculate(equation.substr(begin + 1, (end - begin) - 1));
|
||||
equation.replace(begin, (end - begin) + 1, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
idx = 0;
|
||||
index(equation, nodes);
|
||||
// ^
|
||||
while(equation.find('^', idx) != std::string::npos) {
|
||||
int mid = equation.find('^');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
idx = 0;
|
||||
index(equation, nodes);
|
||||
// * or /
|
||||
while(equation.find('*', idx) != std::string::npos || equation.find('/', idx) != std::string::npos) {
|
||||
if(equation.find('*', idx) < equation.find('/', idx) && equation.find('*', idx) != std::string::npos) {
|
||||
int mid = equation.find('*');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
} else if(equation.find('/', idx) != std::string::npos) {
|
||||
int mid = equation.find('/');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
}
|
||||
idx = 0;
|
||||
index(equation, nodes);
|
||||
// + or -
|
||||
while(equation.find('+', idx) != std::string::npos || equation.find('-', idx) != std::string::npos) {
|
||||
if(equation.find('+', idx) < equation.find('-', idx) && equation.find('+', idx) != std::string::npos) {
|
||||
int mid = equation.find('+');
|
||||
int begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
} else if(equation.find('-', idx) != std::string::npos) {
|
||||
int mid = equation.find('-');
|
||||
int begin = mid;
|
||||
if(nodes.find(mid - 1) != nodes.end()) {
|
||||
begin = equation.find(nodes[mid - 1] + nodes[mid]);
|
||||
}
|
||||
int end = equation.find(nodes[mid] + nodes[mid + 1], begin) + (nodes[mid] + nodes[mid + 1]).length();
|
||||
evalStr[eval.front()] = equation.substr(begin, end - begin);
|
||||
equation.replace(begin, end - begin, eval);
|
||||
eval.front()++;
|
||||
idx = end + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return std::to_string(evaluate(equation, evalStr));
|
||||
}
|
||||
|
||||
|
||||
void Calculator::basicCalculator() {
|
||||
|
||||
static bool b = true;
|
||||
|
||||
static std::string s;
|
||||
|
||||
if(b) {
|
||||
|
||||
ImGui::Begin("Basic Calculator", &open);
|
||||
|
||||
ImGui::Text("%s", s.c_str());
|
||||
|
||||
ImGui::BeginGroup();
|
||||
{
|
||||
if(ImGui::Button("AC")) {
|
||||
s.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("(")) {
|
||||
s += " ( ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button(")")) {
|
||||
s += " ) ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("^")) {
|
||||
s += " ^ ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("=")) {
|
||||
s = calculate(s);
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::BeginGroup();
|
||||
{
|
||||
for(int i = 1; i < 4; i++) {
|
||||
ImGui::BeginGroup();
|
||||
for(int j = 6; j >= 0; j -= 3) {
|
||||
if(ImGui::Button(std::to_string(i + j).c_str())) {
|
||||
s += std::to_string(i + j);
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
if(i < 3) {
|
||||
ImGui::SameLine();
|
||||
}
|
||||
}
|
||||
|
||||
if(ImGui::Button("0")) {
|
||||
s += "0";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button(".")) {
|
||||
s += ".";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("del")) {
|
||||
if(!s.empty()) {
|
||||
if(s.back() == ' ') {
|
||||
s.pop_back();
|
||||
if(s.back() == '(' || s.back() == ')') {
|
||||
parenthesis = !parenthesis;
|
||||
}
|
||||
s.pop_back();
|
||||
s.pop_back();
|
||||
} else {
|
||||
s.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginGroup();
|
||||
|
||||
if(ImGui::Button("+")) {
|
||||
s += " + ";
|
||||
}
|
||||
if(ImGui::Button("-")) {
|
||||
s += " - ";
|
||||
}
|
||||
if(ImGui::Button("*")) {
|
||||
s += " * ";
|
||||
}
|
||||
if(ImGui::Button("/")) {
|
||||
s += " / ";
|
||||
}
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
|
||||
void Calculator::graphingCalculator() {
|
||||
|
||||
}
|
||||
35
modules/Archimedes-Modules/Calculator/Calculator.h
Normal file
35
modules/Archimedes-Modules/Calculator/Calculator.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class Calculator : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Calculator(Archimedes::App*, void*);
|
||||
|
||||
Calculator() { name = "Calculator"; }
|
||||
|
||||
~Calculator();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
private:
|
||||
bool open = true;
|
||||
|
||||
bool parenthesis = true;
|
||||
|
||||
bool graphing = false;
|
||||
|
||||
void basicCalculator();
|
||||
|
||||
std::string calculate(std::string);
|
||||
double evaluate(std::string, std::unordered_map<char, std::string>&);
|
||||
void index(std::string, std::unordered_map<unsigned int, std::string>&);
|
||||
|
||||
void graphingCalculator();
|
||||
|
||||
};
|
||||
|
||||
#ifdef CALCULATOR_DYNAMIC
|
||||
typedef Calculator mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
129
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.cpp
Normal file
129
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include "modules/ClientModule/ClientModule.h"
|
||||
|
||||
#include "ChatClient.h"
|
||||
|
||||
|
||||
ChatClient::ChatClient(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatClient";
|
||||
|
||||
ClientModule* cm = new ClientModule(a, h);
|
||||
deps[*cm] = cm;
|
||||
cm->shouldHandleEvents(ClientModule::CMEventEnum::ConnectionStatusChanged | ClientModule::CMEventEnum::DataSent);
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
|
||||
deps[*im] = im;
|
||||
|
||||
}
|
||||
|
||||
ChatClient::~ChatClient() {
|
||||
if(app) {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void ChatClient::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for ChatClient!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClient!\n";
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
|
||||
void ChatClient::run() {
|
||||
|
||||
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClient!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(open) {
|
||||
static std::string s, addr = "127.0.0.1:9932";
|
||||
|
||||
ImGui::Begin("ChatClient Module", &open);
|
||||
|
||||
ImGui::InputText("Server Address: ", &addr);
|
||||
|
||||
if(cm->isRunning() && cm->isConnected()) {
|
||||
|
||||
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
||||
cm->stopClient();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(ImGui::Button("Connect") && !cm->isRunning()) {
|
||||
static SteamNetworkingIPAddr serverAddr;
|
||||
serverAddr.ParseString(addr.c_str());
|
||||
cm->startClient(serverAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text("%s", messages.c_str());
|
||||
|
||||
ImGui::InputText("Message: ", &s);
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
cm->sendReliable(s.c_str(), (uint32) s.length());
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
} else {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(*cm));
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatClient::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
std::cerr << "Client Recieved: " << s << std::endl;
|
||||
|
||||
messages += "\n\n" + s;
|
||||
|
||||
return true;
|
||||
}
|
||||
/*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
28
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.h
Normal file
28
modules/Archimedes-Modules/Chat/ChatClient/ChatClient.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
|
||||
class ChatClient : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatClient(Archimedes::App* a, void* h);
|
||||
|
||||
ChatClient() { name = "ChatClient"; }
|
||||
|
||||
~ChatClient();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
private:
|
||||
std::string messages = "";
|
||||
bool open = true;
|
||||
};
|
||||
|
||||
#ifdef CHATCLIENT_DYNAMIC
|
||||
typedef ChatClient mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
56
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.cpp
Normal file
56
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "ChatServer.h"
|
||||
|
||||
void ChatServer::onLoad() {
|
||||
ServerModule* sm = (ServerModule*) moduleInstances[ServerModule()];
|
||||
|
||||
sm->startServer(9932);
|
||||
}
|
||||
|
||||
//void ChatServer::run() {}
|
||||
|
||||
bool ChatServer::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
if(s == "/quit") {
|
||||
sm->disconnectClient(e.msg->m_conn);
|
||||
} else if(s == "/shutdown") {
|
||||
sm->stopServer();
|
||||
app->end();
|
||||
}
|
||||
|
||||
std::cerr << "Server Recieved: " << s << std::endl;
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, s.c_str(), s.length());
|
||||
else
|
||||
sm->sendReliable(e.msg->m_conn, "\nMessage sent\n", strlen("\nMessage sent\n"));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
34
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.h
Normal file
34
modules/Archimedes-Modules/Chat/ChatServer/ChatServer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChatServer : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatServer(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatServer";
|
||||
|
||||
ServerModule* sm = new ServerModule(a, h);
|
||||
deps[*sm] = sm;
|
||||
sm->shouldHandleEvents(ServerModule::SMEventEnum::ConnectionStatusChanged | ServerModule::SMEventEnum::DataSent);
|
||||
}
|
||||
|
||||
ChatServer() { name = "ChatServer"; }
|
||||
|
||||
~ChatServer() {
|
||||
if(app) {}
|
||||
}
|
||||
|
||||
void onLoad();
|
||||
|
||||
//void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
};
|
||||
|
||||
#ifdef CHATSERVER_DYNAMIC
|
||||
typedef ChatServer mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -0,0 +1,276 @@
|
||||
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include "modules/ClientModule/ClientModule.h"
|
||||
|
||||
#include "ChatClientVoice.h"
|
||||
|
||||
|
||||
ChatClientVoice::ChatClientVoice(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatClientVoice";
|
||||
|
||||
ClientModule* cm = new ClientModule(a, h);
|
||||
deps[*cm] = cm;
|
||||
cm->shouldHandleEvents(ClientModule::CMEventEnum::ConnectionStatusChanged | ClientModule::CMEventEnum::DataSent);
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
|
||||
deps[*im] = im;
|
||||
|
||||
}
|
||||
|
||||
ChatClientVoice::~ChatClientVoice() {
|
||||
if(app) {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
|
||||
//if(buf)
|
||||
// delete [] buf;
|
||||
}
|
||||
}
|
||||
|
||||
void ChatClientVoice::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for ChatClientVoice!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClientVoice!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(!SDL_Init(SDL_INIT_AUDIO)) {
|
||||
std::cout << "Audio init failed!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
mic = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, NULL, NULL, NULL);
|
||||
SDL_GetAudioStreamFormat(mic, &spec, NULL);
|
||||
speaker = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);
|
||||
|
||||
//buf = new unsigned char[len];
|
||||
|
||||
}
|
||||
|
||||
void ChatClientVoice::run() {
|
||||
|
||||
static ClientModule* cm; { cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
static unsigned char buf[10 * 1024];
|
||||
|
||||
if(!cm) {
|
||||
std::cout << "No ClientModule for ChatClientVoice!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
if(open) {
|
||||
static std::string s, addr = "127.0.0.1:9932";
|
||||
|
||||
ImGui::Begin("ChatClientVoice Module", &open);
|
||||
|
||||
ImGui::InputText("Server Address: ", &addr);
|
||||
|
||||
if(cm->isRunning() && cm->isConnected()) {
|
||||
|
||||
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
||||
cm->sendReliable("srvcmd1", strlen("srvcmd1"));
|
||||
//cm->stopClient();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if(ImGui::Button("Connect") && !cm->isRunning()) {
|
||||
static SteamNetworkingIPAddr serverAddr;
|
||||
serverAddr.ParseString(addr.c_str());
|
||||
cm->startClient(serverAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::Text("%s", messages.c_str());
|
||||
|
||||
ImGui::InputText("Message: ", &s);
|
||||
|
||||
if(cm->isConnected()) {
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
if(s == "/quit") {
|
||||
cm->sendReliable("srvcmd1", strlen("srvcmd1"));
|
||||
cm->stopClient();
|
||||
} else if(s == "/shutdown") {
|
||||
cm->sendReliable("srvcmd2", strlen("srvcmd2"));
|
||||
//cm->stopClient();
|
||||
} else {
|
||||
s.insert(0, "client");
|
||||
cm->sendReliable(s.c_str(), (uint32) s.length());
|
||||
}
|
||||
s.clear();
|
||||
}
|
||||
}
|
||||
|
||||
static float micVol = 1.0f;
|
||||
static float speakerVol = 1.0f;
|
||||
|
||||
static bool micTest = false;
|
||||
|
||||
ImGui::SliderFloat("Mic Volume", &micVol, 0.0f, 1.0f);
|
||||
ImGui::SliderFloat("Speaker Volume", &speakerVol, 0.0f, 1.0f);
|
||||
|
||||
ImGui::Checkbox("Mic test", &micTest);
|
||||
|
||||
if(!SDL_AudioStreamDevicePaused(mic)) {
|
||||
SDL_SetAudioStreamGain(mic, micVol);
|
||||
} else if(micTest) {
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ResumeAudioStreamDevice(mic);
|
||||
SDL_SetAudioStreamGain(mic, micVol);
|
||||
}
|
||||
|
||||
if(!SDL_AudioStreamDevicePaused(speaker)) {
|
||||
SDL_SetAudioStreamGain(speaker, speakerVol);
|
||||
} else if(micTest) {
|
||||
SDL_ClearAudioStream(speaker);
|
||||
SDL_ResumeAudioStreamDevice(speaker);
|
||||
SDL_SetAudioStreamGain(speaker, speakerVol);
|
||||
}
|
||||
|
||||
static int avail = 0;
|
||||
|
||||
if(micTest) {
|
||||
|
||||
avail = SDL_min(len, SDL_GetAudioStreamAvailable(mic));
|
||||
if(avail > 10) {
|
||||
avail = SDL_GetAudioStreamData(mic, buf, avail);
|
||||
SDL_PutAudioStreamData(speaker, buf, avail);
|
||||
}
|
||||
|
||||
} else if(cm->isConnected()){
|
||||
// if not testing, send to server.
|
||||
|
||||
avail = SDL_min(len, SDL_GetAudioStreamAvailable(mic));
|
||||
if(avail > 10) {
|
||||
avail = SDL_GetAudioStreamData(mic, buf, avail);
|
||||
cm->sendReliable(buf, avail);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ImGui::End();
|
||||
} else {
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(*cm));
|
||||
}
|
||||
}
|
||||
|
||||
bool ChatClientVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
static ClientModule* cm;
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
{ cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
static std::string s;
|
||||
|
||||
if(std::string((const char*)e.msg->m_pData, 6) == "client") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
messages += "\n\n" + s;
|
||||
} else if(std::string((const char*)e.msg->m_pData, 6) == "server") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
int serverCode = stoi(s);
|
||||
|
||||
switch(serverCode) {
|
||||
case 0:
|
||||
//start voice
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
SDL_ResumeAudioStreamDevice(mic);
|
||||
SDL_ResumeAudioStreamDevice(speaker);
|
||||
break;
|
||||
case 1:
|
||||
//stop voice and clear
|
||||
SDL_PauseAudioStreamDevice(mic);
|
||||
SDL_PauseAudioStreamDevice(speaker);
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
break;
|
||||
case 2:
|
||||
//disconnect
|
||||
cm->stopClient();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else /*if(std::string((const char*)e.msg->m_pData, 6) == "audio:")*/ {
|
||||
s = "audio data";
|
||||
|
||||
SDL_PutAudioStreamData(speaker, e.msg->m_pData, e.msg->m_cbSize);
|
||||
}
|
||||
|
||||
//std::cerr << "Client Recieved: " << s << std::endl;
|
||||
|
||||
return true;
|
||||
} else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
switch(e.info->m_info.m_eState) {
|
||||
|
||||
case k_ESteamNetworkingConnectionState_None:
|
||||
// NOTE: We will get callbacks here when we destroy connections. You can ignore these.
|
||||
break;
|
||||
|
||||
case k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
{
|
||||
|
||||
SDL_PauseAudioStreamDevice(mic);
|
||||
SDL_PauseAudioStreamDevice(speaker);
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connecting:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connected:
|
||||
//OnConnect
|
||||
break;
|
||||
|
||||
default:
|
||||
// Silences -Wswitch
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_audio.h>
|
||||
|
||||
class ChatClientVoice : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatClientVoice(Archimedes::App* a, void* h);
|
||||
|
||||
ChatClientVoice() { name = "ChatClientVoice"; }
|
||||
|
||||
~ChatClientVoice();
|
||||
|
||||
void onLoad() override;
|
||||
|
||||
void run() override;
|
||||
|
||||
bool onEvent(const Archimedes::Event&) override;
|
||||
|
||||
private:
|
||||
std::string messages = "";
|
||||
bool open = true;
|
||||
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioStream *mic, *speaker;
|
||||
|
||||
const int len = 10 * 1024;
|
||||
};
|
||||
|
||||
#ifdef CHATCLIENTVOICE_DYNAMIC
|
||||
typedef ChatClientVoice mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "ChatServerVoice.h"
|
||||
|
||||
void ChatServerVoice::onLoad() {
|
||||
ServerModule* sm = (ServerModule*) moduleInstances[ServerModule()];
|
||||
|
||||
sm->startServer(9932);
|
||||
}
|
||||
|
||||
//void ChatServerVoice::run() {}
|
||||
|
||||
bool ChatServerVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
static ServerModule* sm;
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
{ sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
static std::string s;
|
||||
|
||||
if(std::string((const char*)e.msg->m_pData, 6) == "client") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, e.msg->m_pData, e.msg->m_cbSize);
|
||||
else
|
||||
sm->sendReliable(e.msg->m_conn, "client\nMessage sent\n", strlen("client\nMessage sent\n"));
|
||||
}
|
||||
|
||||
|
||||
} else if(std::string((const char*)e.msg->m_pData, 6) == "srvcmd") {
|
||||
s = std::string((const char*)e.msg->m_pData + 6, e.msg->m_cbSize - 6);
|
||||
|
||||
int cmdCode = stoi(s);
|
||||
|
||||
switch(cmdCode) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
//disconnect
|
||||
sm->disconnectClient(e.msg->m_conn);
|
||||
break;
|
||||
case 2:
|
||||
for(auto& it : sm->getClients()) {
|
||||
sm->sendReliable(it.first, "server2", strlen("server2"));
|
||||
}
|
||||
sm->stopServer();
|
||||
app->end();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
} else /*if(std::string((const char*)e.msg->m_pData, 6) == "audio:")*/ {
|
||||
s = "audio data";
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, e.msg->m_pData, e.msg->m_cbSize);
|
||||
}
|
||||
}
|
||||
|
||||
//std::cerr << "Server Recieved: " << s << std::endl;
|
||||
|
||||
return true;
|
||||
|
||||
} else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
{ sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
unsigned int numClients;
|
||||
(void)sm->getClients(&numClients);
|
||||
|
||||
switch(e.info->m_info.m_eState) {
|
||||
|
||||
case k_ESteamNetworkingConnectionState_None:
|
||||
// NOTE: We will get callbacks here when we destroy connections. You can ignore these.
|
||||
break;
|
||||
|
||||
case k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
{
|
||||
if(numClients < 2) {
|
||||
for(auto& it : sm->getClients()) {
|
||||
sm->sendReliable(it.first, "server1", strlen("server1"));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connecting:
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connected:
|
||||
//OnConnect
|
||||
|
||||
if(numClients == 2) {
|
||||
for(auto& it : sm->getClients()) {
|
||||
sm->sendReliable(it.first, "server0", strlen("server0"));
|
||||
}
|
||||
} else if(numClients > 2) {
|
||||
|
||||
sm->sendReliable(e.info->m_hConn, "server0", strlen("server0"));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Silences -Wswitch
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChatServerVoice : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChatServerVoice(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChatServerVoice";
|
||||
|
||||
ServerModule* sm = new ServerModule(a, h);
|
||||
deps[*sm] = sm;
|
||||
sm->shouldHandleEvents(ServerModule::SMEventEnum::ConnectionStatusChanged | ServerModule::SMEventEnum::DataSent);
|
||||
}
|
||||
|
||||
ChatServerVoice() { name = "ChatServerVoice"; }
|
||||
|
||||
~ChatServerVoice() {
|
||||
if(app) {}
|
||||
}
|
||||
|
||||
void onLoad();
|
||||
|
||||
//void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
};
|
||||
|
||||
#ifdef CHATSERVERVOICE_DYNAMIC
|
||||
typedef ChatServerVoice mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
46
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.cpp
Normal file
46
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "ChessServer.h"
|
||||
|
||||
void ChessServer::onLoad() {
|
||||
ServerModule* sm = (ServerModule*) moduleInstances[ServerModule()];
|
||||
|
||||
sm->startServer(9932);
|
||||
}
|
||||
|
||||
//void ChessServer::run() {}
|
||||
|
||||
bool ChessServer::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
return true;
|
||||
} else */
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
static std::string s; s = std::string((const char*)e.msg->m_pData, e.msg->m_cbSize);
|
||||
|
||||
|
||||
for(auto& it : sm->getClients()) {
|
||||
if(it.first != e.msg->m_conn)
|
||||
sm->sendReliable(it.first, s.c_str(), s.length());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
|
||||
return false;
|
||||
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
34
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.h
Normal file
34
modules/Archimedes-Modules/Chess/ChessServer/ChessServer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/ServerModule/ServerModule.h"
|
||||
|
||||
class ChessServer : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
|
||||
ChessServer(Archimedes::App* a, void* h) : Module(a, h) {
|
||||
|
||||
name = "ChessServer";
|
||||
|
||||
ServerModule* sm = new ServerModule(a, h);
|
||||
deps[*sm] = sm;
|
||||
sm->shouldHandleEvents(ServerModule::SMEventEnum::ConnectionStatusChanged | ServerModule::SMEventEnum::DataSent);
|
||||
}
|
||||
|
||||
ChessServer() { name = "ChessServer"; }
|
||||
|
||||
~ChessServer() {
|
||||
if(app) {}
|
||||
}
|
||||
|
||||
void onLoad();
|
||||
|
||||
//void run();
|
||||
|
||||
bool onEvent(const Archimedes::Event&);
|
||||
};
|
||||
|
||||
#ifdef CHESSSERVER_DYNAMIC
|
||||
typedef ChessServer mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
126
modules/Archimedes-Modules/Ollama/Ollama.cpp
Normal file
126
modules/Archimedes-Modules/Ollama/Ollama.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "Ollama.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
Ollama::Ollama(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Ollama";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Ollama::~Ollama() {
|
||||
if(app) {
|
||||
if(curl) {
|
||||
curl_easy_cleanup(curl);
|
||||
curl = nullptr;
|
||||
}
|
||||
curl_global_cleanup();
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
static size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::ostream* userp)
|
||||
{
|
||||
userp->write(static_cast<char*>(contents), size * nmemb);
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
void Ollama::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Ollama!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
curl = curl_easy_init();
|
||||
|
||||
}
|
||||
|
||||
void Ollama::run() {
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
|
||||
static std::string s, url = "https://ollama.blunkall.us", response = "";
|
||||
|
||||
static nlohmann::json sendObj;
|
||||
|
||||
static std::ostringstream oss;
|
||||
|
||||
static nlohmann::json jsonObj;
|
||||
|
||||
static std::future<CURLcode> result;
|
||||
|
||||
static bool inFlight = false;
|
||||
|
||||
ImGui::Begin("Ollama Module");
|
||||
|
||||
ImGui::InputText("url: ", &url);
|
||||
|
||||
static const std::string replace = "\\n";
|
||||
static const std::string replace_by = "\n";
|
||||
static std::string print = jsonObj["response"].dump(); print = jsonObj["response"].dump();
|
||||
static auto pos = print.find(replace); pos = print.find(replace);
|
||||
|
||||
while (pos != std::string::npos) {
|
||||
// Replace the substring with the specified string
|
||||
print.replace(pos, replace.size(), replace_by);
|
||||
|
||||
// Find the next occurrence of the substring
|
||||
pos = print.find(replace,
|
||||
pos + replace_by.size());
|
||||
}
|
||||
print = "\n\n\n" + print + "\n\n\n";
|
||||
ImGui::TextWrapped("%s", print.c_str());
|
||||
|
||||
ImGui::InputTextMultiline("prompt: ", &s);
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
sendObj["model"] = "llama3.2";
|
||||
sendObj["stream"] = false;
|
||||
sendObj["prompt"] = s;
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, (url + "/api/generate").c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &oss);
|
||||
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
|
||||
//curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2L);
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS, sendObj.dump().c_str());
|
||||
result = std::async(std::launch::async, curl_easy_perform, curl);
|
||||
inFlight = true;
|
||||
}
|
||||
|
||||
ImGui::Text("ms per frame: %f", 1000 / io.Framerate);
|
||||
|
||||
ImGui::End();
|
||||
|
||||
if(curl) {
|
||||
}
|
||||
|
||||
if(inFlight && result.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
|
||||
CURLcode code = result.get();
|
||||
response = oss.str();
|
||||
oss.str("");
|
||||
|
||||
|
||||
if(code != CURLE_OK) {
|
||||
std::cerr << "curl_easy_perform() failed!: " << curl_easy_strerror(code) << std::endl;
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
return;
|
||||
} else {
|
||||
jsonObj = nlohmann::json::parse(response);
|
||||
|
||||
std::cout << "Full json object:\n" << jsonObj.dump() << std::endl;
|
||||
}
|
||||
inFlight = false;
|
||||
}
|
||||
}
|
||||
26
modules/Archimedes-Modules/Ollama/Ollama.h
Normal file
26
modules/Archimedes-Modules/Ollama/Ollama.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class Ollama : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Ollama(Archimedes::App*, void*);
|
||||
|
||||
Ollama() { name = "Ollama"; }
|
||||
~Ollama();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
CURL* curl;
|
||||
|
||||
};
|
||||
|
||||
#ifdef OLLAMA_DYNAMIC
|
||||
typedef Ollama mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
17
modules/Archimedes-Modules/Print/Print.cpp
Normal file
17
modules/Archimedes-Modules/Print/Print.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "Print.h"
|
||||
|
||||
Print::Print(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "Print";
|
||||
}
|
||||
|
||||
Print::~Print() {
|
||||
if(app) {
|
||||
std::cout << "Print Destroyed!\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Print::run() {
|
||||
std::cout << "Print lib loaded and run!\n";
|
||||
|
||||
app->stopModule(name);
|
||||
}
|
||||
15
modules/Archimedes-Modules/Print/Print.h
Normal file
15
modules/Archimedes-Modules/Print/Print.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class Print : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Print(Archimedes::App*, void*);
|
||||
Print() { name = "Print"; }
|
||||
~Print();
|
||||
void run();
|
||||
};
|
||||
|
||||
#ifdef PRINT_DYNAMIC
|
||||
typedef Print mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
1
modules/Archimedes-Modules/README.md
Normal file
1
modules/Archimedes-Modules/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Example modules for Archimedes
|
||||
93
modules/Archimedes-Modules/Terminal/Terminal.cpp
Normal file
93
modules/Archimedes-Modules/Terminal/Terminal.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pty.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "Terminal.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
|
||||
Terminal::Terminal(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "Terminal";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
Terminal::~Terminal() {
|
||||
if(app) {
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
}
|
||||
|
||||
void Terminal::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for Terminal!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
child_pid = forkpty(&master, nullptr, nullptr, nullptr);
|
||||
|
||||
if(!child_pid) {
|
||||
char* const* args = nullptr;
|
||||
execvp("bash", args);
|
||||
}
|
||||
|
||||
//fcntl(master, F_SETFL, fcntl(master, F_GETFL, 0) | O_NONBLOCK);
|
||||
/*
|
||||
if (master >= 0)
|
||||
(void)write(master, "ls\n", 3);
|
||||
*/
|
||||
}
|
||||
|
||||
void Terminal::run() {
|
||||
|
||||
static fd_set fds;
|
||||
static int rc;
|
||||
static char opArr[150];
|
||||
static std::string input, output;
|
||||
static timeval to; to = { 0, 0 };
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(master, &fds);
|
||||
|
||||
rc = select(master + 1, &fds, NULL, NULL, &to);
|
||||
|
||||
switch(rc) {
|
||||
case -1:
|
||||
std::cerr << "Error " << errno << " on select()\n";
|
||||
exit(1);
|
||||
default:
|
||||
if(FD_ISSET(master, &fds)) {
|
||||
rc = read(master, opArr, 150);
|
||||
if(rc < 0) {
|
||||
//error on read
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
} else {
|
||||
if(input == "clear") output = "";
|
||||
output += opArr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::Begin("Terminal Module");
|
||||
|
||||
ImGui::TextWrapped("%s", output.c_str());
|
||||
ImGui::InputText("input", &input);
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
(void)write(master, (input + "\n").c_str(), input.length() + 1);
|
||||
}
|
||||
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
21
modules/Archimedes-Modules/Terminal/Terminal.h
Normal file
21
modules/Archimedes-Modules/Terminal/Terminal.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class Terminal : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
Terminal(Archimedes::App*, void*);
|
||||
|
||||
Terminal() { name = "Terminal"; }
|
||||
~Terminal();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
private:
|
||||
int child_pid, master;
|
||||
};
|
||||
|
||||
#ifdef TERMINAL_DYNAMIC
|
||||
typedef Terminal mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
35
modules/Archimedes-Modules/TestClay/TestClay.cpp
Normal file
35
modules/Archimedes-Modules/TestClay/TestClay.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "TestClay.h"
|
||||
|
||||
#define CLAY_IMPLIMENTATION
|
||||
#include "clay.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
TestClay::TestClay(void* h, Archimedes::App& a) : Archimedes::GuiModule(h, a) {
|
||||
|
||||
name = "TestClay";
|
||||
}
|
||||
|
||||
TestClay::~TestClay() {
|
||||
}
|
||||
|
||||
void TestClay::onLoad() {
|
||||
|
||||
createWindow();
|
||||
|
||||
window->getRenderer().init();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TestClay::run() {
|
||||
|
||||
window->getRenderer().addRenderCmd([](){
|
||||
|
||||
});
|
||||
|
||||
if(window->shouldClose())
|
||||
app.end();
|
||||
window->doFrame();
|
||||
|
||||
}
|
||||
25
modules/Archimedes-Modules/TestClay/TestClay.h
Normal file
25
modules/Archimedes-Modules/TestClay/TestClay.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
|
||||
class TestClay : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestClay(void*, Archimedes::App&);
|
||||
|
||||
~TestClay();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
extern "C" {
|
||||
Archimedes::Module* create(void* handle, Archimedes::App& app) {
|
||||
return new TestClay(handle, app);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
56
modules/Archimedes-Modules/TestImgui/TestImgui.cpp
Normal file
56
modules/Archimedes-Modules/TestImgui/TestImgui.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "TestImgui.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
TestImgui::TestImgui(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
name = "TestImgui";
|
||||
|
||||
ImguiModule* im = new ImguiModule(a, h);
|
||||
deps[*im] = im;
|
||||
}
|
||||
|
||||
TestImgui::~TestImgui() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
im->releaseContext(ImGui::GetCurrentContext());
|
||||
}
|
||||
|
||||
void TestImgui::onLoad() {
|
||||
|
||||
ImguiModule* im; { im = (ImguiModule*) moduleInstances[ImguiModule()]; }
|
||||
|
||||
if(!im) {
|
||||
std::cout << "No ImguiModule for TestImgui!\n";
|
||||
std::abort();
|
||||
}
|
||||
|
||||
ImGui::SetCurrentContext(im->aquireContext());
|
||||
|
||||
}
|
||||
|
||||
void TestImgui::run() {
|
||||
if(demo)
|
||||
ImGui::ShowDemoWindow(&this->demo);
|
||||
else
|
||||
app->emitEvent(new Archimedes::DoUnloadModuleEvent(name));
|
||||
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
static float f = 0.0f;
|
||||
static int counter = 0;
|
||||
|
||||
ImGui::Begin("TestImgui Module"); // Create a window called "Hello, world!" and append into it.
|
||||
|
||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||
|
||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||
|
||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||
counter++;
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("counter = %d", counter);
|
||||
|
||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
24
modules/Archimedes-Modules/TestImgui/TestImgui.h
Normal file
24
modules/Archimedes-Modules/TestImgui/TestImgui.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
class TestImgui : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestImgui(Archimedes::App*, void*);
|
||||
|
||||
TestImgui() { name = "TestImgui"; }
|
||||
|
||||
~TestImgui();
|
||||
|
||||
void onLoad();
|
||||
|
||||
void run();
|
||||
|
||||
|
||||
private:
|
||||
bool demo = true;
|
||||
};
|
||||
|
||||
#ifdef TESTIMGUI_DYNAMIC
|
||||
typedef TestImgui mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
28
modules/Archimedes-Modules/TestNotCurses/TestNotCurses.cpp
Normal file
28
modules/Archimedes-Modules/TestNotCurses/TestNotCurses.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "TestNotCurses.h"
|
||||
|
||||
TestNotCurses::TestNotCurses(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
name = "TestNotCurses";
|
||||
}
|
||||
|
||||
TestNotCurses::~TestNotCurses() {
|
||||
notcurses_stop(ncInstance);
|
||||
}
|
||||
|
||||
void TestNotCurses::onLoad() {
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
notcurses_options opts;
|
||||
|
||||
ncInstance = notcurses_init(&opts, NULL);
|
||||
|
||||
if(!ncInstance) {
|
||||
app->stopModule(getName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TestNotCurses::run() {
|
||||
|
||||
notcurses_render(ncInstance);
|
||||
}
|
||||
19
modules/Archimedes-Modules/TestNotCurses/TestNotCurses.h
Normal file
19
modules/Archimedes-Modules/TestNotCurses/TestNotCurses.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include <notcurses/notcurses.h>
|
||||
|
||||
class TestNotCurses : public Archimedes::Module {
|
||||
|
||||
public:
|
||||
TestNotCurses(Archimedes::App*, void*);
|
||||
~TestNotCurses();
|
||||
void run();
|
||||
void onLoad();
|
||||
private:
|
||||
notcurses* ncInstance;
|
||||
};
|
||||
|
||||
#ifdef TESTNOTCURSES_DYNAMIC
|
||||
typedef TestNotCurses mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -68,6 +68,6 @@ class ClientModule : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef CLIENTMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ClientModule
|
||||
typedef ClientModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "imgui.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
|
||||
#include "modules/WindowModule/src/WindowModule.h"
|
||||
#include "modules/WindowModule/WindowModule.h"
|
||||
|
||||
#if RENDERER == 1
|
||||
|
||||
@@ -106,7 +106,7 @@ class ImguiModule : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef IMGUIMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ImguiModule
|
||||
typedef ImguiModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "MainGUI.h"
|
||||
#include "modules/ImguiModule/src/ImguiModule.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
|
||||
MainGUI::MainGUI(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
@@ -17,6 +17,6 @@ class MainGUI : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef MAINGUI_DYNAMIC
|
||||
#define MODULE_TYPE MainGUI
|
||||
typedef MainGUI mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,12 @@ class ServerModule : public Archimedes::Module {
|
||||
}
|
||||
}
|
||||
|
||||
std::map<HSteamNetConnection, unsigned int> getClients() const { return clients; }
|
||||
std::map<HSteamNetConnection, unsigned int> getClients(unsigned int* num = nullptr) const {
|
||||
if(num) {
|
||||
*num = numClients;
|
||||
}
|
||||
return clients;
|
||||
}
|
||||
|
||||
void pollIncomingData();
|
||||
|
||||
@@ -88,7 +93,7 @@ class ServerModule : public Archimedes::Module {
|
||||
};
|
||||
|
||||
#ifdef SERVERMODULE_DYNAMIC
|
||||
#define MODULE_TYPE ServerModule
|
||||
typedef ServerModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class WindowModule : public Archimedes::Module {
|
||||
|
||||
|
||||
#ifdef WINDOWMODULE_DYNAMIC
|
||||
#define MODULE_TYPE WindowModule
|
||||
typedef WindowModule mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/examples/TestImgui/src/TestImgui.h"
|
||||
#include "modules/Archimedes-Modules/TestImgui/TestImgui.h"
|
||||
|
||||
class ImguiEmbed : public Archimedes::App {
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#define ENTRYPOINT
|
||||
#include "Archimedes.h"
|
||||
|
||||
#include "modules/Terminal/src/Terminal.h"
|
||||
#include "modules/Archimedes-Modules/Terminal/Terminal.h"
|
||||
|
||||
class TerminalEmbed : public Archimedes::App {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user