Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix animation node refcount handling #624

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion guest/rust/api_core/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ impl AnimationPlayer {

/// An animation node. Used in the animation player. It keeps an internal ref count.
#[derive(Debug)]
pub struct AnimationNode(pub EntityId);
pub struct AnimationNode(EntityId);
impl AnimationNode {
/// Use an existing node
pub fn from_entity(entity: EntityId) -> Self {
entity::mutate_component(entity, ref_count(), |x| *x += 1);
Self(entity)
}
}
impl Clone for AnimationNode {
fn clone(&self) -> Self {
entity::mutate_component(self.0, ref_count(), |x| *x += 1);
Expand Down Expand Up @@ -87,6 +94,10 @@ impl PlayClipFromUrlNode {
.spawn();
Self(AnimationNode(node))
}
/// Use an existing node
pub fn from_entity(entity: EntityId) -> Self {
Self(AnimationNode::from_entity(entity))
}
/// Set if the animation should loop or not
pub fn looping(&self, value: bool) {
entity::add_component(self.0 .0, looping(), value);
Expand Down Expand Up @@ -194,6 +205,10 @@ impl BlendNode {
entity::add_component(right.0, parent(), node);
Self(AnimationNode(node))
}
/// Use an existing node
pub fn from_entity(entity: EntityId) -> Self {
Self(AnimationNode::from_entity(entity))
}
/// Set the weight of this blend node.
///
/// If the weight is 0, only the left animation will play.
Expand Down
Loading