feat: thread view - change between Normal colors and Thread ID color view

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2026-03-24 20:02:28 +00:00
parent bf56d3377a
commit 9042e053c8
3 changed files with 29 additions and 17 deletions

BIN
psystem

Binary file not shown.

View File

View File

@ -31,7 +31,7 @@ const unsigned int SCR_WIDTH = 2560;
const unsigned int SCR_HEIGHT = 1440; const unsigned int SCR_HEIGHT = 1440;
const char *glsl_version; const char *glsl_version;
const unsigned int PARTICLE_COUNT = 8; const unsigned int PARTICLE_COUNT = 10000;
GLFWwindow *window; GLFWwindow *window;
unsigned int VBO, VAO; unsigned int VBO, VAO;
@ -48,6 +48,7 @@ pthread_barrier_t barrier;
// INFO: Debug views toggles // INFO: Debug views toggles
bool viewThreads = 0; bool viewThreads = 0;
bool enablePhysics = 1;
static void cursor_callback(GLFWwindow *w, double xpos, double ypos) { static void cursor_callback(GLFWwindow *w, double xpos, double ypos) {
#ifndef NDEBUG #ifndef NDEBUG
@ -246,7 +247,7 @@ int main() {
default_particle_color[i] = {x, y, z, 255.0f}; default_particle_color[i] = {x, y, z, 255.0f};
particles[i] = particle_init({x, y, z}, {x, y, z, 255.0f}); particles[i] = particle_init({x, y, z}, {x, y, z, 255.0f});
particles[i].radius = (float)(rand() % 50) / 1000.0f; particles[i].radius = (float)((rand() % 5) + 5) / 1000.0f;
} }
/* /*
@ -309,21 +310,23 @@ int main() {
glm::mat4 projection = camera_projection(camera, aspect); glm::mat4 projection = camera_projection(camera, aspect);
glm::mat4 mvp = projection * view; // model is identity glm::mat4 mvp = projection * view; // model is identity
pthread_mutex_lock(&mutex); if (enablePhysics) {
for (int i = 0; i < THREAD_COUNT; i++) { pthread_mutex_lock(&mutex);
thread_params[i].time = delta_time; for (int i = 0; i < THREAD_COUNT; i++) {
thread_params[i].run = 1; thread_params[i].time = delta_time;
thread_params[i].run = 1;
}
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
pthread_barrier_wait(&barrier);
alive_count = 0;
for (int i = 0; i < THREAD_COUNT; i++)
alive_count += thread_params[i].alive_count;
// collision_update(particles, alive_count, 0.3f);
} }
pthread_cond_broadcast(&cond);
pthread_mutex_unlock(&mutex);
pthread_barrier_wait(&barrier);
alive_count = 0;
for (int i = 0; i < THREAD_COUNT; i++)
alive_count += thread_params[i].alive_count;
// collision_update(particles, alive_count, 0.3f);
// Render // Render
glClearColor(0.03f, 0.03f, 0.03f, 1.0f); glClearColor(0.03f, 0.03f, 0.03f, 1.0f);
@ -368,6 +371,15 @@ int main() {
snprintf(errLog, 128, "Switched views to thread view\n"); snprintf(errLog, 128, "Switched views to thread view\n");
} }
} }
if (ImGui::Checkbox("Enable Physics", &enablePhysics)) {
if (!enablePhysics) {
snprintf(errLog, 128, "Disabled phyics\n");
} else {
snprintf(errLog, 128, "Enable physics\n");
}
}
ImGui::End(); ImGui::End();
// Render ImGui // Render ImGui
@ -389,7 +401,7 @@ int main() {
free(threads); free(threads);
free(thread_params); free(thread_params);
free(particles); free(particles);
free(default_particle_color); free(default_particle_color);
ImGui_ImplGlfw_Shutdown(); ImGui_ImplGlfw_Shutdown();
ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplOpenGL3_Shutdown();