This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

♻️ Rename "later hooks" to inner hooks

+29 -22
+12 -12
src/video/context.rs
··· 1 1 use super::Animation; 2 2 use super::animation::{AnimationUpdateFunction, LayerAnimationUpdateFunction}; 3 - use super::hooks::{LaterHook, LaterRenderFunction}; 3 + use super::hooks::{InnerHook, InnerHookRenderFunction}; 4 4 use crate::Timestamp; 5 5 use crate::synchronization::audio::{Note, StemAtInstant}; 6 6 use crate::synchronization::sync::SyncData; ··· 17 17 pub bpm: usize, 18 18 pub syncdata: &'a SyncData, 19 19 pub audiofile: PathBuf, 20 - pub later_hooks: Vec<LaterHook<AdditionalContext>>, 20 + pub inner_hooks: Vec<InnerHook<AdditionalContext>>, 21 21 pub extra: AdditionalContext, 22 22 pub duration_override: Option<Duration>, 23 23 pub current_scene: Option<String>, ··· 129 129 pub fn later_frames( 130 130 &mut self, 131 131 delay: usize, 132 - render_function: &'static LaterRenderFunction, 132 + render_function: &'static InnerHookRenderFunction, 133 133 ) { 134 134 let current_frame = self.frame(); 135 135 136 - self.later_hooks.insert( 136 + self.inner_hooks.insert( 137 137 0, 138 - LaterHook { 138 + InnerHook { 139 139 once: true, 140 140 when: Box::new(move |_, context, _previous_beat| { 141 141 context.frame() >= current_frame + delay ··· 148 148 pub fn later_ms( 149 149 &mut self, 150 150 delay: usize, 151 - render_function: &'static LaterRenderFunction, 151 + render_function: &'static InnerHookRenderFunction, 152 152 ) { 153 153 let current_ms = self.ms; 154 154 155 - self.later_hooks.insert( 155 + self.inner_hooks.insert( 156 156 0, 157 - LaterHook { 157 + InnerHook { 158 158 once: true, 159 159 when: Box::new(move |_, context, _previous_beat| { 160 160 context.ms >= current_ms + delay ··· 167 167 pub fn later_beats( 168 168 &mut self, 169 169 delay: f32, 170 - render_function: &'static LaterRenderFunction, 170 + render_function: &'static InnerHookRenderFunction, 171 171 ) { 172 172 let current_beat = self.beat(); 173 173 174 - self.later_hooks.insert( 174 + self.inner_hooks.insert( 175 175 0, 176 - LaterHook { 176 + InnerHook { 177 177 once: true, 178 178 when: Box::new(move |_, context, _previous_beat| { 179 179 context.beat_fractional() >= current_beat as f32 + delay ··· 188 188 let start_ms = self.ms; 189 189 let ms_range = start_ms..(start_ms + duration); 190 190 191 - self.later_hooks.push(LaterHook { 191 + self.inner_hooks.push(InnerHook { 192 192 once: false, 193 193 when: Box::new(move |_, ctx, _| ms_range.contains(&ctx.ms)), 194 194 render_function: Box::new(move |canvas, ms| {
+4 -4
src/video/engine.rs
··· 46 46 fps: self.fps, 47 47 syncdata: &self.syncdata, 48 48 extra: AdditionalContext::default(), 49 - later_hooks: vec![], 49 + inner_hooks: vec![], 50 50 audiofile: self.audiofile.clone(), 51 51 duration_override: self.duration_override, 52 52 scene_started_at_ms: None, ··· 113 113 114 114 let mut later_hooks_to_delete: Vec<usize> = vec![]; 115 115 116 - for (i, hook) in context.later_hooks.iter().enumerate() { 116 + for (i, hook) in context.inner_hooks.iter().enumerate() { 117 117 if (hook.when)(&canvas, &context, previous_rendered_beat) { 118 118 (hook.render_function)(&mut canvas, context.ms)?; 119 119 if hook.once { ··· 125 125 } 126 126 127 127 for i in later_hooks_to_delete { 128 - if i < context.later_hooks.len() { 129 - context.later_hooks.remove(i); 128 + if i < context.inner_hooks.len() { 129 + context.inner_hooks.remove(i); 130 130 } 131 131 } 132 132
+13 -6
src/video/hooks.rs
··· 22 22 dyn Fn(&Canvas, &Context<C>, BeatNumber, FrameNumber) -> bool + Send + Sync; 23 23 24 24 /// Arguments: canvas, context, current milliseconds timestamp 25 - pub type LaterRenderFunction = 25 + pub type InnerHookRenderFunction = 26 26 dyn Fn(&mut Canvas, Millisecond) -> anyhow::Result<()> + Send + Sync; 27 27 28 28 /// Arguments: canvas, context, previous rendered beat 29 - pub type LaterHookCondition<C> = 29 + pub type InnerHookCondition<C> = 30 30 dyn Fn(&Canvas, &Context<C>, BeatNumber) -> bool + Send + Sync; 31 31 32 32 pub struct Hook<C> { ··· 34 34 pub render_function: Box<RenderFunction<C>>, 35 35 } 36 36 37 - pub struct LaterHook<C> { 38 - pub when: Box<LaterHookCondition<C>>, 39 - pub render_function: Box<LaterRenderFunction>, 37 + /// Hooks that are triggered within a regular hook 38 + /// Used to implement animations: they create a inner hook 39 + /// triggered on each frame for a certain duration 40 + pub struct InnerHook<C> { 41 + pub when: Box<InnerHookCondition<C>>, 42 + pub render_function: Box<InnerHookRenderFunction>, 40 43 /// Whether the hook should be run only once 41 44 pub once: bool, 42 45 } ··· 149 152 ) -> Self { 150 153 self.with_hook(Hook { 151 154 when: Box::new(move |_, context, _, previous_rendered_frame| { 152 - context.frame() - previous_rendered_frame >= n 155 + if context.frame() == previous_rendered_frame { 156 + return false; 157 + } 158 + 159 + context.frame() % n == 0 153 160 }), 154 161 render_function: Box::new(render_function), 155 162 })