better already

This commit is contained in:
2025-12-11 06:40:15 +01:00
parent 4930d86e23
commit 06b8cac896
3 changed files with 362 additions and 66 deletions

View File

@@ -2,6 +2,7 @@ use minifb::{Key, Window, WindowOptions};
use std::thread;
use std::time::{Duration, Instant};
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicUsize, Ordering};
use rand::Rng;
use teleprof::instrument;
@@ -9,6 +10,8 @@ const WIDTH: usize = 800;
const HEIGHT: usize = 600;
const BALL_RADIUS: usize = 20;
static COLOR_PICKER_COUNTER: AtomicUsize = AtomicUsize::new(0);
struct Ball {
x: f32,
y: f32,
@@ -94,8 +97,9 @@ fn main_frame(
// If we hit a wall, spawn a thread to pick a new color
if hit_wall {
let ball_clone = Arc::clone(ball);
let id = COLOR_PICKER_COUNTER.fetch_add(1, Ordering::Relaxed);
thread::spawn(move || {
teleprof::set_thread_name("ColorPicker");
teleprof::set_thread_name(format!("ColorPicker-{}", id));
pick_new_color(ball_clone);
});
}