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

This commit is contained in:
2026-03-24 17:21:37 +00:00
parent d35d7bff69
commit bf56d3377a
4 changed files with 39 additions and 26 deletions
+24 -7
View File
@@ -25,13 +25,13 @@ const char FRAGMENT_SHADER_SOURCE[] = "./source/shader/fragment.glsl";
const char VERTEX_SHADER_SOURCE[] = "./source/shader/vertex.glsl";
const char PROGRAM_NAME[] = "Particle Sim";
const unsigned int THREAD_COUNT = 16;
const unsigned int THREAD_COUNT = 8;
const unsigned int SCR_WIDTH = 2560;
const unsigned int SCR_HEIGHT = 1440;
const char *glsl_version;
const unsigned int PARTICLE_COUNT = 5000;
const unsigned int PARTICLE_COUNT = 8;
GLFWwindow *window;
unsigned int VBO, VAO;
@@ -46,6 +46,9 @@ pthread_mutex_t mutex;
pthread_cond_t cond;
pthread_barrier_t barrier;
// INFO: Debug views toggles
bool viewThreads = 0;
static void cursor_callback(GLFWwindow *w, double xpos, double ypos) {
#ifndef NDEBUG
// Let ImGui eat mouse when cursor is free
@@ -216,11 +219,12 @@ int main() {
g_grid = grid_init();
// Register callbacks AFTER ImGui init so ImGui gets them first via chain
glfwSetCursorPosCallback(window, cursor_callback);
glfwSetScrollCallback(window, scroll_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
// glfwSetCursorPosCallback(window, cursor_callback);
// glfwSetScrollCallback(window, scroll_callback);
// glfwSetMouseButtonCallback(window, mouse_button_callback);
Particle *particles = (Particle *)malloc(sizeof(Particle) * PARTICLE_COUNT);
Color *default_particle_color = (Color *)malloc(sizeof(Color) * PARTICLE_COUNT);
if (particles == NULL) {
snprintf(errLog, 128, "There was a issue allocating memory for the particle list\n");
@@ -240,7 +244,9 @@ int main() {
float y = (float)(rand() % 200) / 100.0f; // Random y between 0 and 2
float z = (float)(rand() % 200) / 100.0f; // Random z between 0 and 2
default_particle_color[i] = {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;
}
/*
@@ -317,7 +323,7 @@ int main() {
for (int i = 0; i < THREAD_COUNT; i++)
alive_count += thread_params[i].alive_count;
collision_update(particles, alive_count, 0.3f);
// collision_update(particles, alive_count, 0.3f);
// Render
glClearColor(0.03f, 0.03f, 0.03f, 1.0f);
@@ -347,11 +353,21 @@ int main() {
ImGui::Text("Alive particles: %d", alive_count);
if (particles)
ImGui::Text("P[0]: %3.2f %3.2f %3.2f, Life: %0.2f", (double)particles[0].position.x, (double)particles[0].position.y, (double)particles[0].position.z,
(double)particles[0].life);
(double)particles[0].life);
ImGui::Separator();
ImGui::Text("Left-click to capture mouse");
ImGui::Text("ESC = release mouse / quit");
ImGui::Text("%s", errLog);
if (ImGui::Checkbox("Thread View", &viewThreads)) {
if (!viewThreads) {
snprintf(errLog, 128, "Switched views to default\n");
for (unsigned long long i = 0; i < PARTICLE_COUNT; i++)
particles[i].color = default_particle_color[i];
} else {
snprintf(errLog, 128, "Switched views to thread view\n");
}
}
ImGui::End();
// Render ImGui
@@ -373,6 +389,7 @@ int main() {
free(threads);
free(thread_params);
free(particles);
free(default_particle_color);
ImGui_ImplGlfw_Shutdown();
ImGui_ImplOpenGL3_Shutdown();