-
I'm working on an animation library and I'm a bit stumped with options. I've separated the library into its own crate so it can be used for other engines. My issue is the library needs a lifetime for the "state" of the animation (e.g. per entity). The skeleton is a bunch of bone structures and texture positioning, etc. This can be reused by multiple states/entities. The state is (will be) a cached view of the animation, manual bone positions, etc. pub struct SkeletonState<'a> {
skeleton: &'a Skeleton,
// etc
} I have an Having the state in a
Any ideas for a nice way to implement this? I have the sources up but it's a big mess because I'm in the middle of hacking things to work first: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Can your I had a similar problem in Noumenal storing and caching shape data, which can be large and expensive to compute. I chose something like the first option, using type tagged integer handles (enum variants containing a You could use an Arc<()> or something else for memory management. |
Beta Was this translation helpful? Give feedback.
-
I went for option 1 and made a reasonable solution IMO. It's straightforward but thought I'd post it here for anyone that might need it. Separated Now it looks like this: pub struct SkeletonState<'a> {
skeleton: &'a Skeleton,
internal: DetachedSkeletonState,
}
pub fn pose(&mut self) {
self.internal.pose(self.skeleton)
} A library could happily use |
Beta Was this translation helpful? Give feedback.
I went for option 1 and made a reasonable solution IMO. It's straightforward but thought I'd post it here for anyone that might need it.
Separated
SkeletonState
into two structs, one that internally tracks theSkeleton
with the lifetime (SkeletonState
), and another that needs aSkeleton
reference (DetachedSkeletonState
).Now it looks like this:
DetachedSkeletonState
is the second "internal" struct that needsSkeleton
as a reference for its methods.SkeletonState
is kind of like a proxy intoDetachedSkeletonState
A library could …