Compare commits
10 Commits
b4309ab4e9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c107ce732c | |||
| ad658d914c | |||
| f6ad110880 | |||
| cb5762a3fe | |||
| 45f1d0f69d | |||
| dffca865dc | |||
| 32223cfa05 | |||
| 3196f7b81a | |||
| 08bccb1e70 | |||
| 2e0341a12e |
@@ -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 \
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/TestMenu/*.cpp \
|
||||
modules/Archimedes-Modules/TestMenu/*.cpp \
|
||||
-fpic -shared \
|
||||
-Wall \
|
||||
-DTESTMENU_DYNAMIC \
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/TestNotCurses/*.cpp \
|
||||
modules/Archimedes-Modules/TestNotCurses/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include \
|
||||
-Wall \
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/Print/*.cpp \
|
||||
modules/Archimedes-Modules/Print/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include \
|
||||
-Wall \
|
||||
@@ -97,7 +97,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/DependsOnPrint/*.cpp \
|
||||
modules/Archimedes-Modules/DependsOnPrint/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include \
|
||||
-Wall \
|
||||
@@ -124,8 +124,8 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/DependsOnPrintStatic/*.cpp \
|
||||
${inputs.Archimedes-Modules}/Print/*.cpp \
|
||||
modules/Archimedes-Modules/DependsOnPrintStatic/*.cpp \
|
||||
modules/Archimedes-Modules/Print/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include -I . \
|
||||
-DDEPENDSONPRINTSTATIC_DYNAMIC \
|
||||
@@ -159,7 +159,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/TestImgui/*.cpp \
|
||||
modules/Archimedes-Modules/TestImgui/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
@@ -202,7 +202,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/Calculator/*.cpp \
|
||||
modules/Archimedes-Modules/Calculator/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
@@ -240,7 +240,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/TestClay/*.cpp \
|
||||
modules/Archimedes-Modules/TestClay/*.cpp \
|
||||
-fpic -shared \
|
||||
-I include \
|
||||
-DRENDERER=1 \
|
||||
@@ -273,7 +273,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/Chat/ChatServer/*.cpp \
|
||||
modules/Archimedes-Modules/Chat/ChatServer/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
@@ -307,7 +307,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/ChatVoice/ChatServerVoice/*.cpp \
|
||||
modules/Archimedes-Modules/ChatVoice/ChatServerVoice/*.cpp \
|
||||
modules/ServerModule/*.cpp \
|
||||
-fpic -shared \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
@@ -345,7 +345,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/Chat/ChatClient/*.cpp \
|
||||
modules/Archimedes-Modules/Chat/ChatClient/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
@@ -392,7 +392,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/ChatVoice/ChatClientVoice/*.cpp \
|
||||
modules/Archimedes-Modules/ChatVoice/ChatClientVoice/*.cpp \
|
||||
modules/ClientModule/*.cpp \
|
||||
-I ${pkgs.gamenetworkingsockets}/include/GameNetworkingSockets \
|
||||
-lGameNetworkingSockets \
|
||||
@@ -438,7 +438,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/Terminal/*.cpp \
|
||||
modules/Archimedes-Modules/Terminal/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
@@ -484,7 +484,7 @@
|
||||
|
||||
buildPhase = ''
|
||||
clang++ \
|
||||
${inputs.Archimedes-Modules}/Ollama/*.cpp \
|
||||
modules/Archimedes-Modules/Ollama/*.cpp \
|
||||
modules/ImguiModule/*.cpp \
|
||||
modules/WindowModule/*.cpp \
|
||||
$imgui/backends/imgui_impl_glfw.cpp \
|
||||
|
||||
17
flake.lock
generated
17
flake.lock
generated
@@ -1,21 +1,5 @@
|
||||
{
|
||||
"nodes": {
|
||||
"Archimedes-Modules": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1747079936,
|
||||
"narHash": "sha256-+lpnX9reLMTq6WDl4Covcn0jVVE3BX8syiIpo+Kpy/c=",
|
||||
"ref": "refs/heads/master",
|
||||
"rev": "550f20602f514c4396878ca25cc62a9ffead00e8",
|
||||
"revCount": 8,
|
||||
"type": "git",
|
||||
"url": "ssh://gitea@gitea.blunkall.us/Blunkall-Technologies/Archimedes-Modules"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "ssh://gitea@gitea.blunkall.us/Blunkall-Technologies/Archimedes-Modules"
|
||||
}
|
||||
},
|
||||
"clay": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
@@ -67,7 +51,6 @@
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"Archimedes-Modules": "Archimedes-Modules",
|
||||
"clay": "clay",
|
||||
"imgui": "imgui",
|
||||
"nixpkgs": "nixpkgs"
|
||||
|
||||
@@ -11,10 +11,6 @@
|
||||
url = "github:nicbarker/clay";
|
||||
flake = false;
|
||||
};
|
||||
Archimedes-Modules = {
|
||||
url = "git+ssh://gitea@gitea.blunkall.us/Blunkall-Technologies/Archimedes-Modules";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, imgui, clay, ... }@inputs: let
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#include "Calculator.h"
|
||||
#include "modules/ImguiModule/ImguiModule.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
Calculator::Calculator(Archimedes::App* a, void* h) : Archimedes::Module(a, h) {
|
||||
|
||||
@@ -41,6 +44,211 @@ void Calculator::run() {
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -51,58 +259,90 @@ void Calculator::basicCalculator() {
|
||||
|
||||
ImGui::Begin("Basic Calculator", &open);
|
||||
|
||||
ImGui::InputText("equation", &s);
|
||||
ImGui::Text("%s", s.c_str());
|
||||
|
||||
if(ImGui::Button("7")) {
|
||||
s += "7";
|
||||
ImGui::BeginGroup();
|
||||
{
|
||||
if(ImGui::Button("AC")) {
|
||||
s.clear();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("8")) {
|
||||
s += "8";
|
||||
if(ImGui::Button("(")) {
|
||||
s += " ( ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("9")) {
|
||||
s += "9";
|
||||
}
|
||||
if(ImGui::Button("4")) {
|
||||
s += "4";
|
||||
if(ImGui::Button(")")) {
|
||||
s += " ) ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("5")) {
|
||||
s += "5";
|
||||
if(ImGui::Button("^")) {
|
||||
s += " ^ ";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("6")) {
|
||||
s += "6";
|
||||
if(ImGui::Button("=")) {
|
||||
s = calculate(s);
|
||||
}
|
||||
if(ImGui::Button("1")) {
|
||||
s += "1";
|
||||
}
|
||||
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("2")) {
|
||||
s += "2";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("3")) {
|
||||
s += "3";
|
||||
}
|
||||
|
||||
if(ImGui::Button("0")) {
|
||||
s += "1";
|
||||
s += "0";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button(".")) {
|
||||
s += "2";
|
||||
s += ".";
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("")) {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -15,9 +15,18 @@ class Calculator : public Archimedes::Module {
|
||||
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
|
||||
|
||||
@@ -84,7 +84,8 @@ void ChatClientVoice::run() {
|
||||
if(cm->isRunning() && cm->isConnected()) {
|
||||
|
||||
if(ImGui::Button("Disconnect") && cm->isRunning()) {
|
||||
cm->stopClient();
|
||||
cm->sendReliable("srvcmd1", strlen("srvcmd1"));
|
||||
//cm->stopClient();
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -105,11 +106,16 @@ void ChatClientVoice::run() {
|
||||
ImGui::SameLine();
|
||||
|
||||
if(ImGui::Button("send")) {
|
||||
s.insert(s.begin(), 'o');
|
||||
s.insert(s.begin(), ' ');
|
||||
s.insert(s.begin(), '0');
|
||||
s.insert(s.begin(), 'a');
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -130,9 +136,6 @@ void ChatClientVoice::run() {
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ResumeAudioStreamDevice(mic);
|
||||
SDL_SetAudioStreamGain(mic, micVol);
|
||||
} else if(!cm->isConnected()) {
|
||||
SDL_PauseAudioStreamDevice(mic);
|
||||
SDL_ClearAudioStream(mic);
|
||||
}
|
||||
|
||||
if(!SDL_AudioStreamDevicePaused(speaker)) {
|
||||
@@ -141,10 +144,6 @@ void ChatClientVoice::run() {
|
||||
SDL_ClearAudioStream(speaker);
|
||||
SDL_ResumeAudioStreamDevice(speaker);
|
||||
SDL_SetAudioStreamGain(speaker, speakerVol);
|
||||
} else if(!cm->isConnected()) {
|
||||
SDL_PauseAudioStreamDevice(speaker);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
|
||||
}
|
||||
|
||||
static int avail = 0;
|
||||
@@ -152,9 +151,10 @@ void ChatClientVoice::run() {
|
||||
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.
|
||||
@@ -176,6 +176,7 @@ void ChatClientVoice::run() {
|
||||
bool ChatClientVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
unsigned int type = app->getEventType(event);
|
||||
static ClientModule* cm;
|
||||
|
||||
/*if(type == app->getEventType("DataSentEvent")) {
|
||||
//we did this?
|
||||
@@ -186,19 +187,49 @@ bool ChatClientVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
|
||||
{ cm = (ClientModule*) moduleInstances[ClientModule()]; }
|
||||
|
||||
static std::string s;
|
||||
|
||||
if(((char*)e.msg->m_pData)[0] == 'a' && ((char*)e.msg->m_pData)[1] == '0' && ((char*)e.msg->m_pData)[2] == ' ' && ((char*)e.msg->m_pData)[3] == 'o') {
|
||||
s = std::string((const char*)e.msg->m_pData + 4, e.msg->m_cbSize - 4);
|
||||
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 {
|
||||
} 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;
|
||||
//std::cerr << "Client Recieved: " << s << std::endl;
|
||||
|
||||
return true;
|
||||
} else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
@@ -230,11 +261,6 @@ bool ChatClientVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
case k_ESteamNetworkingConnectionState_Connected:
|
||||
//OnConnect
|
||||
SDL_ClearAudioStream(mic);
|
||||
SDL_ClearAudioStream(speaker);
|
||||
SDL_ResumeAudioStreamDevice(mic);
|
||||
SDL_ResumeAudioStreamDevice(speaker);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
@@ -12,7 +12,7 @@ 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;
|
||||
@@ -20,30 +20,48 @@ bool ChatServerVoice::onEvent(const Archimedes::Event& event) {
|
||||
|
||||
if(type == app->getEventType(Archimedes::DataRecievedEvent())) {
|
||||
|
||||
static ServerModule* sm; { sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
{ sm = (ServerModule*) moduleInstances[ServerModule()]; }
|
||||
|
||||
|
||||
Archimedes::DataRecievedEvent& e = (Archimedes::DataRecievedEvent&) event;
|
||||
static std::string s;
|
||||
|
||||
if(((char*)e.msg->m_pData)[0] == 'a' && ((char*)e.msg->m_pData)[1] == '0' && ((char*)e.msg->m_pData)[2] == ' ' && ((char*)e.msg->m_pData)[3] == 'o') {
|
||||
s = std::string((const char*)e.msg->m_pData + 4, e.msg->m_cbSize - 4);
|
||||
|
||||
if(s == "/quit") {
|
||||
sm->disconnectClient(e.msg->m_conn);
|
||||
} else if(s == "/shutdown") {
|
||||
sm->stopServer();
|
||||
app->end();
|
||||
}
|
||||
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, "a0 o\nMessage sent\n", strlen("a0 o\nMessage sent\n"));
|
||||
sm->sendReliable(e.msg->m_conn, "client\nMessage sent\n", strlen("client\nMessage sent\n"));
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
} 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()) {
|
||||
@@ -52,17 +70,62 @@ bool ChatServerVoice::onEvent(const Archimedes::Event& event) {
|
||||
}
|
||||
}
|
||||
|
||||
std::cerr << "Server Recieved: " << s << std::endl;
|
||||
//std::cerr << "Server Recieved: " << s << std::endl;
|
||||
|
||||
return true;
|
||||
|
||||
} /*else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
} else if(type == app->getEventType("ConnectionStatusChangedEvent")) {
|
||||
|
||||
//Archimedes::ConnectionStatusChangedEvent& e = (Archimedes::ConnectionStatusChangedEvent&) event;
|
||||
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,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
|
||||
|
||||
@@ -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->emitEvent(new Archimedes::DoUnloadModuleEvent(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
|
||||
typedef DependsOnPrint mtype;
|
||||
#include "endModule.h"
|
||||
#endif
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "DependsOnPrintStatic.h"
|
||||
|
||||
#include "modules/Archimedes-Modules/Print/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->emitEvent(new Archimedes::DoUnloadModuleEvent(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
|
||||
typedef DependsOnPrintStatic mtype;
|
||||
#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->emitEvent(new Archimedes::DoUnloadModuleEvent(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
|
||||
typedef TestMenu 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user