pub struct Player { /* private fields */ }Expand description
Plays one saved scene, one frame at a time.
Implementations§
Source§impl Player
impl Player
Sourcepub fn new(pkg: Arc<ScenePackage>, theme: Theme, buddy: bool) -> Option<Player>
pub fn new(pkg: Arc<ScenePackage>, theme: Theme, buddy: bool) -> Option<Player>
None if the scene has no such theme.
Examples found in repository?
13fn main() {
14 let mut args = std::env::args().skip(1);
15 let (w, h) = args
16 .next()
17 .and_then(|s| {
18 let (a, b) = s.split_once('x')?;
19 Some((a.parse().ok()?, b.parse().ok()?))
20 })
21 .unwrap_or((3024u32, 1964u32));
22 let fps: u64 = args.next().and_then(|a| a.parse().ok()).unwrap_or(12);
23 for activity in [
24 "warm_hands",
25 "stroll",
26 "stargaze",
27 "hike_ridge",
28 "broom_journey",
29 ] {
30 let ctx = ContentContext {
31 enabled_activities: vec![activity.into()],
32 ..ContentContext::default()
33 };
34 let r = compose(40, Aspect::from_size(w, h), &ctx);
35 let made = Instant::now();
36 let pkg = Arc::new(ScenePackage::capture(&r, w, h).expect("scene"));
37 let capture = made.elapsed();
38 let theme = pkg.themes()[0];
39 let mut player = Player::new(pkg.clone(), theme, true).expect("theme");
40 player.set_smooth(true);
41 let t0 = pkg.hero_ms(theme).unwrap_or(0);
42 player.advance(t0);
43 let frames = 10 * fps;
44 let (mut advance, mut pack, mut pixels) = (Duration::ZERO, Duration::ZERO, 0u64);
45 let mut packed: Vec<u8> = Vec::new();
46 for k in 1..=frames {
47 let t = t0 + k * 1000 / fps;
48 let a = Instant::now();
49 let rects = player.advance(t);
50 let b = Instant::now();
51 packed.clear();
52 for r in clairlune_live::gpu::merge_spans(&rects) {
53 let pitch = (r.w as usize).div_ceil(256) * 256;
54 for y in r.y..r.y + r.h {
55 packed.extend_from_slice(player.index_row(r.x, y, r.w));
56 let len = packed.len();
57 packed.resize(len + pitch - r.w as usize, 0);
58 }
59 pixels += u64::from(r.w * r.h);
60 }
61 pack += b.elapsed();
62 advance += b - a;
63 }
64 let per = |d: Duration| d.as_secs_f64() * 1e3 / frames as f64;
65 let cpu = (advance + pack).as_secs_f64() / 10.0 * 100.0;
66 println!(
67 "{activity:<14} {w}x{h} at {fps} fps: advance {:.2} ms, pack {:.2} ms, {:.0} kpx/frame, ~{cpu:.1} % of a core (capture {:.0} ms)",
68 per(advance),
69 per(pack),
70 pixels as f64 / frames as f64 / 1e3,
71 capture.as_secs_f64() * 1e3
72 );
73 }
74}Sourcepub fn new_view(
pkg: Arc<ScenePackage>,
theme: Theme,
buddy: bool,
view: PixelRect,
) -> Option<Player>
pub fn new_view( pkg: Arc<ScenePackage>, theme: Theme, buddy: bool, view: PixelRect, ) -> Option<Player>
A player showing only view of the scene’s frame (span mode: each
monitor shows its part of one scene). Every method then works in the
view’s own coordinates. None if the scene has no such theme or the
view isn’t inside the frame.
Sourcepub fn set_smooth(&mut self, on: bool)
pub fn set_smooth(&mut self, on: bool)
Particles at sub-cell positions (Clock::Smooth), for presenters on
a GPU: a higher frame rate then moves them smoothly. Off by default,
so the first frame is the still exactly; the CPU fallback keeps it
off (PLAN.md section 4.4).
Examples found in repository?
13fn main() {
14 let mut args = std::env::args().skip(1);
15 let (w, h) = args
16 .next()
17 .and_then(|s| {
18 let (a, b) = s.split_once('x')?;
19 Some((a.parse().ok()?, b.parse().ok()?))
20 })
21 .unwrap_or((3024u32, 1964u32));
22 let fps: u64 = args.next().and_then(|a| a.parse().ok()).unwrap_or(12);
23 for activity in [
24 "warm_hands",
25 "stroll",
26 "stargaze",
27 "hike_ridge",
28 "broom_journey",
29 ] {
30 let ctx = ContentContext {
31 enabled_activities: vec![activity.into()],
32 ..ContentContext::default()
33 };
34 let r = compose(40, Aspect::from_size(w, h), &ctx);
35 let made = Instant::now();
36 let pkg = Arc::new(ScenePackage::capture(&r, w, h).expect("scene"));
37 let capture = made.elapsed();
38 let theme = pkg.themes()[0];
39 let mut player = Player::new(pkg.clone(), theme, true).expect("theme");
40 player.set_smooth(true);
41 let t0 = pkg.hero_ms(theme).unwrap_or(0);
42 player.advance(t0);
43 let frames = 10 * fps;
44 let (mut advance, mut pack, mut pixels) = (Duration::ZERO, Duration::ZERO, 0u64);
45 let mut packed: Vec<u8> = Vec::new();
46 for k in 1..=frames {
47 let t = t0 + k * 1000 / fps;
48 let a = Instant::now();
49 let rects = player.advance(t);
50 let b = Instant::now();
51 packed.clear();
52 for r in clairlune_live::gpu::merge_spans(&rects) {
53 let pitch = (r.w as usize).div_ceil(256) * 256;
54 for y in r.y..r.y + r.h {
55 packed.extend_from_slice(player.index_row(r.x, y, r.w));
56 let len = packed.len();
57 packed.resize(len + pitch - r.w as usize, 0);
58 }
59 pixels += u64::from(r.w * r.h);
60 }
61 pack += b.elapsed();
62 advance += b - a;
63 }
64 let per = |d: Duration| d.as_secs_f64() * 1e3 / frames as f64;
65 let cpu = (advance + pack).as_secs_f64() / 10.0 * 100.0;
66 println!(
67 "{activity:<14} {w}x{h} at {fps} fps: advance {:.2} ms, pack {:.2} ms, {:.0} kpx/frame, ~{cpu:.1} % of a core (capture {:.0} ms)",
68 per(advance),
69 per(pack),
70 pixels as f64 / frames as f64 / 1e3,
71 capture.as_secs_f64() * 1e3
72 );
73 }
74}Sourcepub fn with_view(&self, view: PixelRect) -> Option<Player>
pub fn with_view(&self, view: PixelRect) -> Option<Player>
Another player of the same scene at the same moment, showing view
of it (one scene on several screens, each showing its part). None
if the view isn’t inside the frame.
Sourcepub fn is_journey(&self) -> bool
pub fn is_journey(&self) -> bool
Whether the scene is a journey (its whole frame moves every tick).
Sourcepub fn image(&self) -> &IndexedImage
pub fn image(&self) -> &IndexedImage
The whole current frame as palette indices (not just the view).
Sourcepub fn index_row(&self, x: u32, y: u32, w: u32) -> &[u8] ⓘ
pub fn index_row(&self, x: u32, y: u32, w: u32) -> &[u8] ⓘ
Palette indices of w pixels of row y from column x, in the
view’s coordinates.
Examples found in repository?
13fn main() {
14 let mut args = std::env::args().skip(1);
15 let (w, h) = args
16 .next()
17 .and_then(|s| {
18 let (a, b) = s.split_once('x')?;
19 Some((a.parse().ok()?, b.parse().ok()?))
20 })
21 .unwrap_or((3024u32, 1964u32));
22 let fps: u64 = args.next().and_then(|a| a.parse().ok()).unwrap_or(12);
23 for activity in [
24 "warm_hands",
25 "stroll",
26 "stargaze",
27 "hike_ridge",
28 "broom_journey",
29 ] {
30 let ctx = ContentContext {
31 enabled_activities: vec![activity.into()],
32 ..ContentContext::default()
33 };
34 let r = compose(40, Aspect::from_size(w, h), &ctx);
35 let made = Instant::now();
36 let pkg = Arc::new(ScenePackage::capture(&r, w, h).expect("scene"));
37 let capture = made.elapsed();
38 let theme = pkg.themes()[0];
39 let mut player = Player::new(pkg.clone(), theme, true).expect("theme");
40 player.set_smooth(true);
41 let t0 = pkg.hero_ms(theme).unwrap_or(0);
42 player.advance(t0);
43 let frames = 10 * fps;
44 let (mut advance, mut pack, mut pixels) = (Duration::ZERO, Duration::ZERO, 0u64);
45 let mut packed: Vec<u8> = Vec::new();
46 for k in 1..=frames {
47 let t = t0 + k * 1000 / fps;
48 let a = Instant::now();
49 let rects = player.advance(t);
50 let b = Instant::now();
51 packed.clear();
52 for r in clairlune_live::gpu::merge_spans(&rects) {
53 let pitch = (r.w as usize).div_ceil(256) * 256;
54 for y in r.y..r.y + r.h {
55 packed.extend_from_slice(player.index_row(r.x, y, r.w));
56 let len = packed.len();
57 packed.resize(len + pitch - r.w as usize, 0);
58 }
59 pixels += u64::from(r.w * r.h);
60 }
61 pack += b.elapsed();
62 advance += b - a;
63 }
64 let per = |d: Duration| d.as_secs_f64() * 1e3 / frames as f64;
65 let cpu = (advance + pack).as_secs_f64() / 10.0 * 100.0;
66 println!(
67 "{activity:<14} {w}x{h} at {fps} fps: advance {:.2} ms, pack {:.2} ms, {:.0} kpx/frame, ~{cpu:.1} % of a core (capture {:.0} ms)",
68 per(advance),
69 per(pack),
70 pixels as f64 / frames as f64 / 1e3,
71 capture.as_secs_f64() * 1e3
72 );
73 }
74}Sourcepub fn now_ms(&self) -> u64
pub fn now_ms(&self) -> u64
Scene time now: the hero time plus the time since playback started. A pause only stops drawing; the next frame shows the time it is.
Sourcepub fn advance(&mut self, t_ms: u64) -> Vec<PixelRect>
pub fn advance(&mut self, t_ms: u64) -> Vec<PixelRect>
Moves to t_ms; returns the rectangles that changed, in the view’s
coordinates (changes outside the view are left out).
Examples found in repository?
13fn main() {
14 let mut args = std::env::args().skip(1);
15 let (w, h) = args
16 .next()
17 .and_then(|s| {
18 let (a, b) = s.split_once('x')?;
19 Some((a.parse().ok()?, b.parse().ok()?))
20 })
21 .unwrap_or((3024u32, 1964u32));
22 let fps: u64 = args.next().and_then(|a| a.parse().ok()).unwrap_or(12);
23 for activity in [
24 "warm_hands",
25 "stroll",
26 "stargaze",
27 "hike_ridge",
28 "broom_journey",
29 ] {
30 let ctx = ContentContext {
31 enabled_activities: vec![activity.into()],
32 ..ContentContext::default()
33 };
34 let r = compose(40, Aspect::from_size(w, h), &ctx);
35 let made = Instant::now();
36 let pkg = Arc::new(ScenePackage::capture(&r, w, h).expect("scene"));
37 let capture = made.elapsed();
38 let theme = pkg.themes()[0];
39 let mut player = Player::new(pkg.clone(), theme, true).expect("theme");
40 player.set_smooth(true);
41 let t0 = pkg.hero_ms(theme).unwrap_or(0);
42 player.advance(t0);
43 let frames = 10 * fps;
44 let (mut advance, mut pack, mut pixels) = (Duration::ZERO, Duration::ZERO, 0u64);
45 let mut packed: Vec<u8> = Vec::new();
46 for k in 1..=frames {
47 let t = t0 + k * 1000 / fps;
48 let a = Instant::now();
49 let rects = player.advance(t);
50 let b = Instant::now();
51 packed.clear();
52 for r in clairlune_live::gpu::merge_spans(&rects) {
53 let pitch = (r.w as usize).div_ceil(256) * 256;
54 for y in r.y..r.y + r.h {
55 packed.extend_from_slice(player.index_row(r.x, y, r.w));
56 let len = packed.len();
57 packed.resize(len + pitch - r.w as usize, 0);
58 }
59 pixels += u64::from(r.w * r.h);
60 }
61 pack += b.elapsed();
62 advance += b - a;
63 }
64 let per = |d: Duration| d.as_secs_f64() * 1e3 / frames as f64;
65 let cpu = (advance + pack).as_secs_f64() / 10.0 * 100.0;
66 println!(
67 "{activity:<14} {w}x{h} at {fps} fps: advance {:.2} ms, pack {:.2} ms, {:.0} kpx/frame, ~{cpu:.1} % of a core (capture {:.0} ms)",
68 per(advance),
69 per(pack),
70 pixels as f64 / frames as f64 / 1e3,
71 capture.as_secs_f64() * 1e3
72 );
73 }
74}Sourcepub fn write(&self, buf: &mut [u32], rects: &[PixelRect])
pub fn write(&self, buf: &mut [u32], rects: &[PixelRect])
Writes those rectangles (view coordinates) of the current frame into a 0RGB buffer of the view’s size.
Sourcepub fn rect_pixels(&self, r: &PixelRect, out: &mut Vec<u32>)
pub fn rect_pixels(&self, r: &PixelRect, out: &mut Vec<u32>)
One rectangle (view coordinates) of the current frame as 0RGB pixels, row by row.