-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
108 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use anyhow::Result; | ||
use std::collections::HashMap; | ||
use std::fmt::{Debug, Formatter}; | ||
use std::ops::Deref; | ||
use std::rc::Rc; | ||
use usvg::PathData; | ||
|
||
use crate::animation::Animation; | ||
|
||
#[derive(Debug)] | ||
pub struct AnimationManager { | ||
reference: HashMap<String, Rc<PathData>>, | ||
animations: Vec<Box<dyn Animation>>, | ||
} | ||
|
||
impl Debug for dyn Animation { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
todo!() | ||
} | ||
} | ||
|
||
impl AnimationManager { | ||
pub fn new() -> AnimationManager { | ||
AnimationManager { | ||
reference: HashMap::new(), | ||
animations: Vec::new(), | ||
} | ||
} | ||
|
||
#[inline] | ||
pub fn add_reference(&mut self, id: String, path: Rc<PathData>) { | ||
self.reference.insert(id, path); | ||
} | ||
|
||
#[inline] | ||
pub fn add_animation<T: Animation + 'static>(&mut self, animation: T) { | ||
self.animations.push(Box::new(animation)) | ||
} | ||
|
||
#[inline] | ||
pub fn update(&mut self, frame_count: usize) -> Result<()> { | ||
for animation in &mut self.animations { | ||
let id = animation.object_id(); | ||
let rc = self.reference.get(id); | ||
|
||
if let Some(pd) = rc { | ||
unsafe { | ||
let _ = animation.update(pd.clone(), &frame_count)?; | ||
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
use anyhow::Result; | ||
use std::rc::Rc; | ||
use usvg::PathData; | ||
|
||
pub mod curves; | ||
pub mod manager; | ||
pub mod position_animation; | ||
|
||
pub trait Animation { | ||
// TODO maybe add internal frame_count state in the animation to track the frame number | ||
/// Called once every frame | ||
unsafe fn update(&mut self, frame_count: usize) -> Result<()>; | ||
unsafe fn update(&mut self, path: Rc<PathData>, frame_count: &usize) -> Result<()>; | ||
|
||
fn object_id(&self) -> &str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters