Skip to content

Commit

Permalink
Merge branch 'decouple_colors'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavJCosby committed Dec 13, 2024
2 parents 2e07c17 + c8d7b78 commit 247c8fb
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 704 deletions.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exclude = ["*.gif", "*.cast"]
[features]
default = ["drivers", "scheduler", "spin_sleep", "std"]
drivers = ["compact_str", "sled_driver_macros"]

scheduler = []
named_colors = []
std = ["glam/std", "palette/std"]
Expand All @@ -23,7 +24,6 @@ spin_sleep = ["std", "dep:spin_sleep"]

[dependencies]
glam = { version = "0.29", default-features = false, features = [] }
palette = { version = "0.7", default-features = false, features = ["approx"] }
smallvec = "1.13"
compact_str = { version = "0.8", default-features = false, optional = true }
sled_driver_macros = { version = "0.1.2", optional = true }
Expand All @@ -34,6 +34,9 @@ spin_sleep = { version = "1.2", optional = true }
criterion = { version = "0.5", default-features = false, features = [
"cargo_bench_support",
] }

palette = { version = "0.7", default-features = false }

rand = { version = "0.8", default-features = false, features = [
"std",
"std_rng",
Expand Down
4 changes: 2 additions & 2 deletions benches/comet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ fn trail(c: &mut Criterion) {
let simulated_hz = 60.0;
let total_steps = (simulated_duration * simulated_hz) as usize;
let timestep = Duration::from_secs_f32(1.0 / simulated_hz);
let mut r = 0;
let mut r = 0.0;

c.bench_function("comet", |b| {
b.iter(|| {
for _ in 0..total_steps {
driver.step_by(timestep);

let mut colors = driver.colors_coerced::<u8>();
let mut colors = driver.colors();
r = colors.next().unwrap().red;
}
});
Expand Down
6 changes: 3 additions & 3 deletions benches/drivers/comet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use palette::rgb::Rgb;
use spatial_led::{
color::Rgb,
driver::{Driver, TimeInfo},
driver_macros::*,
Sled, SledResult,
Expand All @@ -19,14 +19,14 @@ const BLUE: Rgb = Rgb::new(0.4, 0.51, 0.93);
const TRAIL_RADIUS: f32 = 1.2;

#[allow(dead_code)]
pub fn build_driver() -> Driver {
pub fn build_driver() -> Driver<Rgb> {
let mut driver = Driver::new();
driver.set_draw_commands(draw);
driver
}

#[draw_commands]
fn draw(sled: &mut Sled, time_info: &TimeInfo) -> SledResult {
fn draw(sled: &mut Sled<Rgb>, time_info: &TimeInfo) -> SledResult {
let elapsed = time_info.elapsed.as_secs_f32();

let inner_time_scale = elapsed / GREEN_RADIUS;
Expand Down
13 changes: 7 additions & 6 deletions benches/drivers/ripples.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use spatial_led::{
color::Rgb,
driver::{BufferContainer, Driver, TimeInfo},
driver_macros::*,
Sled, SledResult, Vec2,
};

use rand::Rng;

use palette::rgb::Rgb;
use std::ops::Range;

const MAX_RIPPLES: usize = 12;
Expand All @@ -14,7 +15,7 @@ const FEATHERING: f32 = 0.15;
const INV_F: f32 = 1.0 / FEATHERING;

#[allow(dead_code)]
pub fn build_driver() -> Driver {
pub fn build_driver() -> Driver<Rgb> {
let mut driver = Driver::new();

driver.set_startup_commands(startup);
Expand All @@ -24,7 +25,7 @@ pub fn build_driver() -> Driver {
}

#[startup_commands]
fn startup(sled: &mut Sled, buffers: &mut BufferContainer) -> SledResult {
fn startup(sled: &mut Sled<Rgb>, buffers: &mut BufferContainer) -> SledResult {
let sled_bounds = sled.domain();

let radii = buffers.create_buffer("radii");
Expand Down Expand Up @@ -55,7 +56,7 @@ fn startup(sled: &mut Sled, buffers: &mut BufferContainer) -> SledResult {
}

#[compute_commands]
fn compute(sled: &Sled, buffers: &mut BufferContainer, time_info: &TimeInfo) -> SledResult {
fn compute(sled: &Sled<Rgb>, buffers: &mut BufferContainer, time_info: &TimeInfo) -> SledResult {
let delta = time_info.delta.as_secs_f32();
let bounds = sled.domain();
for i in 0..MAX_RIPPLES {
Expand Down Expand Up @@ -89,7 +90,7 @@ fn rand_init_radius() -> f32 {
}

#[draw_commands]
fn draw(sled: &mut Sled, buffers: &BufferContainer) -> SledResult {
fn draw(sled: &mut Sled<Rgb>, buffers: &BufferContainer) -> SledResult {
sled.set_all(Rgb::new(0.0, 0.0, 0.0));
let colors = buffers.get_buffer("colors")?;
let positions = buffers.get_buffer("positions")?;
Expand All @@ -108,7 +109,7 @@ fn draw(sled: &mut Sled, buffers: &BufferContainer) -> SledResult {
Ok(())
}

fn draw_ripple_at(sled: &mut Sled, pos: Vec2, radius: f32, color: Rgb) {
fn draw_ripple_at(sled: &mut Sled<Rgb>, pos: Vec2, radius: f32, color: Rgb) {
let inv_radius = 1.0 / radius;
sled.modulate_within_dist_from(radius + FEATHERING, pos, |led| {
let r = led.position().distance(pos);
Expand Down
4 changes: 2 additions & 2 deletions benches/ripples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ fn ripples(c: &mut Criterion) {
let simulated_hz = 60.0;
let total_steps = (simulated_duration * simulated_hz) as usize;
let timestep = Duration::from_secs_f32(1.0 / simulated_hz);
let mut r = 0;
let mut r = 0.0;
c.bench_function("ripples", |b| {
b.iter(|| {
for _ in 0..total_steps {
driver.step_by(timestep);

let mut colors = driver.colors_coerced::<u8>();
let mut colors = driver.colors();
r = colors.next().unwrap().red;
}
});
Expand Down
Loading

0 comments on commit 247c8fb

Please sign in to comment.