weird clang bug where it doesn't generate append func for call in main.cpp. I copied the dll to get past the build error
This commit is contained in:
@@ -116,7 +116,7 @@
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>pthreadVC3d.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>ext\pthreads4w-code\build\Debug\pthreadVC3d.lib;glfw3.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
@@ -145,4 +145,10 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
<ItemGroup>
|
||||
<PthreadDLL Include="ext\pthreads4w-code\build\Debug\pthreadVC3d.dll" />
|
||||
</ItemGroup>
|
||||
<Target Name="CopyFiles">
|
||||
<Copy SourceFiles="@(PthreadDLL)" DestinationFolder="$(TargetDir)" />
|
||||
</Target>
|
||||
</Project>
|
||||
90
src/main.cpp
90
src/main.cpp
@@ -5,7 +5,6 @@
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/vector_float3.hpp>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
@@ -42,46 +41,45 @@ body create_new_sphere() {
|
||||
static bool stop = false;
|
||||
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
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;
|
||||
std::vector<std::tuple<char*, body, float>> camera_bodies; // I would use my array here, but was getting a linking error
|
||||
|
||||
//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);
|
||||
// }
|
||||
//}
|
||||
void *process_cin(void* args) {
|
||||
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.size(); 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.size();
|
||||
b.color = glm::vec4(i&0x4, i&0x2, i&0x1, max_hp);
|
||||
auto t = std::make_tuple(words[0], b, max_hp);
|
||||
camera_bodies.push_back(t);
|
||||
}
|
||||
pthread_mutex_unlock(&lock);
|
||||
}
|
||||
}
|
||||
|
||||
static bool mouse_pressed = false;
|
||||
static bool scroll_pressed = false;
|
||||
@@ -199,10 +197,12 @@ int main() {
|
||||
glDisable(GL_CULL_FACE);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
float time;
|
||||
glm::mat4 projection_t
|
||||
= glm::perspective(glm::radians(60.0f), (float)width / (float)height, 0.1f, 1300.0f);
|
||||
|
||||
pthread_t thread_id;
|
||||
pthread_create(&thread_id, NULL, process_cin, NULL);
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
process_input();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@@ -211,6 +211,14 @@ int main() {
|
||||
|
||||
draw_body(b2);
|
||||
|
||||
pthread_mutex_lock(&lock);
|
||||
|
||||
for (int i = 0; i < camera_bodies.size(); i++) {
|
||||
draw_body(std::get<1>(camera_bodies[i]));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&lock);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user