remove tcp server reference from proj. Saving right before I unleash pthread stuff

This commit is contained in:
2025-08-19 18:37:33 -05:00
parent ba9216a338
commit a7011eee89
3 changed files with 53 additions and 42 deletions

View File

@@ -140,7 +140,6 @@
<ClCompile Include="src\glad.c" />
<ClCompile Include="src\main.cpp" />
<ClCompile Include="src\shaders.cpp" />
<ClCompile Include="src\tcp_server.cpp" />
<ClCompile Include="src\util.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@@ -30,8 +30,5 @@
<ClCompile Include="src\body.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\tcp_server.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -1,3 +1,4 @@
#include <cstring>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/ext/matrix_clip_space.hpp>
@@ -9,6 +10,7 @@
#include <stdlib.h>
#include <pthread.h>
#include <string>
#include <tuple>
#include "util.hpp"
#include "shaders.hpp"
@@ -28,31 +30,58 @@ void process_input() {
glfwSetWindowShouldClose(window, true);
}
static uint shader;
body create_new_sphere() {
body b;
assert(load_body(&b, "Icosphere.obj"));
b.shader = shader;
b.pose = glm::translate(b.pose, glm::vec3(0, 0, 0));
return b;
}
static bool stop = false;
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static std::map<char*, std::pair<body, int>> camera_name_to_bodies;
const float max_hp = 10; // Number of scans (without a particular barcode) for which the sphere will still be visible
array<std::tuple<char*, body, float>> camera_bodies;
enum class LineParserState {
NAME,
X,
Y,
Z
};
// name x y z\n
void process_cin(void* args) {
size_t len = 256;
std::string line;
while (true) {
std::getline(std::cin, line);
array<char*> words = split_str(line.c_str());
assert(words.len == 4);
pthread_mutex_lock(&lock);
for (int i = 0; i < words.len; i++) {
if (camera_name_to_bodies.find(words
}
pthread_mutex_unlock(&lock);
}
}
//void process_cin(void* args) {
// size_t len = 256;
// std::string line;
// while (true) {
// std::getline(std::cin, line);
// array<char*> words = split_str(line.c_str());
// assert(words.len == 4);
// printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
// pthread_mutex_lock(&lock);
// float x = atof(words[1]);
// float y = atof(words[2]);
// float z = atof(words[3]);
// glm::vec3 new_loc = glm::vec3(x, y, z);
// bool found_match = false;
// for (int i = 0; i < camera_bodies.len; i++) {
// if (strcmp(words[0], std::get<0>(camera_bodies[i])) == 0) {
// glm::vec4 &transl = std::get<1>(camera_bodies[i]).pose[4];
// transl = 0.9f*transl + 0.1f*glm::vec4(new_loc, 1); // filter
//
// std::get<1>(camera_bodies[i]).color = glm::vec4(i&0x4, i&0x2, i&0x1, 1);
// std::get<2>(camera_bodies[i]) = max_hp;
// found_match = true;
// } else {
// float &cur_hp = std::get<2>(camera_bodies[i]);
// if (cur_hp > 0) cur_hp -= 1;
// std::get<1>(camera_bodies[i]).color = glm::vec4(i&0x4, i&0x2, i&0x1, cur_hp/max_hp);
// }
// }
// if (!found_match) {
// body b = create_new_sphere();
// int i = camera_bodies.len;
// b.color = glm::vec4(i&0x4, i&0x2, i&0x1, max_hp);
// auto t = std::make_tuple(words[0], b, max_hp);
// append(camera_bodies, t);
// }
// pthread_mutex_unlock(&lock);
// }
//}
static bool mouse_pressed = false;
static bool scroll_pressed = false;
@@ -109,7 +138,7 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {
glm::vec4 k = camera_t[2];
float d = yoffset;
camera_loc += k * (d / 10 * max(glm::length(camera_loc), 1.0f));
camera_loc += k * (d / 10 * glm::max(glm::length(camera_loc), 1.0f));
camera_t = glm::lookAt(camera_loc, focal_point, up);
}
@@ -148,7 +177,6 @@ int main() {
width = 800;
height = 800;
uint shader;
const char* vertex_filepath = "src/shaders/vertex.glsl";
const char* fragment_filepath = "src/shaders/fragment.glsl";
if (!load_shader(&shader, vertex_filepath, fragment_filepath))
@@ -161,18 +189,7 @@ int main() {
glfwSwapBuffers(window); // front buffer is now back
glClear(GL_COLOR_BUFFER_BIT); // Write to back buffer again (former front buf)
body b;
if (!load_body(&b, "Icosphere.obj"))
return -1;
b.shader = shader;
b.pose = glm::translate(b.pose, glm::vec3(0, 0, 0));
b.color = glm::vec4(0.5, 0, 0, 1);
body b2;
if (!load_body(&b2, "Icosphere.obj"))
return -1;
b2.shader = shader;
b2.pose = glm::translate(b.pose, glm::vec3(2, 0, 0));
body b2 = create_new_sphere();
b2.color = glm::vec4(0, 0.5, 0, 1);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -188,12 +205,10 @@ int main() {
while (!glfwWindowShouldClose(window)) {
process_input();
process_cin();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_uniform(shader, "camera_t", camera_t);
set_uniform(shader, "projection_t", projection_t);
draw_body(b);
draw_body(b2);
glfwSwapBuffers(window);