Skip to main content

Player

Struct Player 

Source
pub struct Player { /* private fields */ }
Expand description

Plays one saved scene, one frame at a time.

Implementations§

Source§

impl Player

Source

pub fn new(pkg: Arc<ScenePackage>, theme: Theme, buddy: bool) -> Option<Player>

None if the scene has no such theme.

Examples found in repository?
examples/frame_cost.rs (line 39)
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}
Source

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.

Source

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?
examples/frame_cost.rs (line 40)
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}
Source

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.

Source

pub fn is_journey(&self) -> bool

Whether the scene is a journey (its whole frame moves every tick).

Source

pub fn size(&self) -> (u32, u32)

The size of what this player shows.

Source

pub fn image(&self) -> &IndexedImage

The whole current frame as palette indices (not just the view).

Source

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?
examples/frame_cost.rs (line 55)
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}
Source

pub fn colors(&self) -> &[u32; 256]

The palette as 0RGB, by index.

Source

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.

Source

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?
examples/frame_cost.rs (line 42)
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}
Source

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.

Source

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.

Source

pub fn write_all(&self, buf: &mut [u32])

Writes the whole view.

Auto Trait Implementations§

§

impl Forget for Player

§

impl Freeze for Player

§

impl Move for Player

§

impl RefUnwindSafe for Player

§

impl Send for Player

§

impl Sync for Player

§

impl Unpin for Player

§

impl UnsafeUnpin for Player

§

impl UnwindSafe for Player

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more