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\glad.c" />
<ClCompile Include="src\main.cpp" /> <ClCompile Include="src\main.cpp" />
<ClCompile Include="src\shaders.cpp" /> <ClCompile Include="src\shaders.cpp" />
<ClCompile Include="src\tcp_server.cpp" />
<ClCompile Include="src\util.cpp" /> <ClCompile Include="src\util.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

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

View File

@@ -1,3 +1,4 @@
#include <cstring>
#include <glad/glad.h> #include <glad/glad.h>
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <glm/ext/matrix_clip_space.hpp> #include <glm/ext/matrix_clip_space.hpp>
@@ -9,6 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <pthread.h> #include <pthread.h>
#include <string> #include <string>
#include <tuple>
#include "util.hpp" #include "util.hpp"
#include "shaders.hpp" #include "shaders.hpp"
@@ -28,31 +30,58 @@ void process_input() {
glfwSetWindowShouldClose(window, true); 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 bool stop = false;
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; 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 { //void process_cin(void* args) {
NAME, // size_t len = 256;
X, // std::string line;
Y, // while (true) {
Z // std::getline(std::cin, line);
}; // array<char*> words = split_str(line.c_str());
// name x y z\n // assert(words.len == 4);
void process_cin(void* args) { // printf("Received: %s, %s, %s, %s\n", words[0], words[1], words[2], words[3]); // echo for debugging
size_t len = 256; // pthread_mutex_lock(&lock);
std::string line; // float x = atof(words[1]);
while (true) { // float y = atof(words[2]);
std::getline(std::cin, line); // float z = atof(words[3]);
array<char*> words = split_str(line.c_str()); // glm::vec3 new_loc = glm::vec3(x, y, z);
assert(words.len == 4); // bool found_match = false;
pthread_mutex_lock(&lock); // for (int i = 0; i < camera_bodies.len; i++) {
for (int i = 0; i < words.len; i++) { // if (strcmp(words[0], std::get<0>(camera_bodies[i])) == 0) {
if (camera_name_to_bodies.find(words // glm::vec4 &transl = std::get<1>(camera_bodies[i]).pose[4];
} // transl = 0.9f*transl + 0.1f*glm::vec4(new_loc, 1); // filter
pthread_mutex_unlock(&lock); //
} // 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 mouse_pressed = false;
static bool scroll_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]; glm::vec4 k = camera_t[2];
float d = yoffset; 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); camera_t = glm::lookAt(camera_loc, focal_point, up);
} }
@@ -148,7 +177,6 @@ int main() {
width = 800; width = 800;
height = 800; height = 800;
uint shader;
const char* vertex_filepath = "src/shaders/vertex.glsl"; const char* vertex_filepath = "src/shaders/vertex.glsl";
const char* fragment_filepath = "src/shaders/fragment.glsl"; const char* fragment_filepath = "src/shaders/fragment.glsl";
if (!load_shader(&shader, vertex_filepath, fragment_filepath)) if (!load_shader(&shader, vertex_filepath, fragment_filepath))
@@ -161,18 +189,7 @@ int main() {
glfwSwapBuffers(window); // front buffer is now back glfwSwapBuffers(window); // front buffer is now back
glClear(GL_COLOR_BUFFER_BIT); // Write to back buffer again (former front buf) glClear(GL_COLOR_BUFFER_BIT); // Write to back buffer again (former front buf)
body b; body b2 = create_new_sphere();
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));
b2.color = glm::vec4(0, 0.5, 0, 1); b2.color = glm::vec4(0, 0.5, 0, 1);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
@@ -188,12 +205,10 @@ int main() {
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
process_input(); process_input();
process_cin();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_uniform(shader, "camera_t", camera_t); set_uniform(shader, "camera_t", camera_t);
set_uniform(shader, "projection_t", projection_t); set_uniform(shader, "projection_t", projection_t);
draw_body(b);
draw_body(b2); draw_body(b2);
glfwSwapBuffers(window); glfwSwapBuffers(window);