Skip to content

Improve animations' encoding structure #95

@AzurIce

Description

@AzurIce

Currently, Ranim decide using Method | remove state out of timeline for now.


Currently, Ranim maintains animations with timelines with inner item state tracked by ItemId<T>.

And that makes coding inconvinience:

  • If we want to play an anim, we have to determine which timeline to play, and get the timeline.
  • If we want to get an items state, we have to store it in previous timeline call, or get the timeline first then get its inner state.
  • If we want to insert item (create a new timeline) in the center of whole animation, we'll have to manually sync its time.
  • ...

So, in Ranim v0.2, I'll attempt to get rid of ItemId<T>, as well as timelines.

First, rethink about timeline and ItemId<T>:

  • For animations visualization of preview app, we want that all animations about the same logical item should lay on a single line, so we have timeline to organize animations, and use id to reference them.
  • Since timelines are stored in a vec, they are type erased
  • Since item's state is also maintained in timeline for features like forward, show and hide, we need type info for us to "recover" state's type, so the id turns in a form of TypeId<T>
  • So, when the element animation's output type is changed, the TypeId<T> has to be changed to TypeId<E>. And for safty, TypeId<T> has to be consumed.

That leads to this kind of code:

let r_item_a = r.insert(/* ... */);

let item_a = r.timeline_mut(&r_item_a)
    .play_with(|x| x.anim_a())
    .forward(1.0)
    .play_with(|x| x.anim_b())
    .snapshot();

// Such a pain
let r_item_a_lower_level = r.map(r_item_a, LowerType::from);
r.timeline_mut(&r_item_a)
    .play_with(|x| x.anim_lower_level());
let r_item_a = r.map(r_item_a, || item_a);


let r_item_b = r.insert(/* ... */);

// Another pain
let t = r.timelines().max_total_secs();
r.timeline_mut(r_item_b).forward_to(t);
// Or
// r.timelines_mut().sync();
r.timeline_mut(&r_item_b)
    .play(/* ... */)
    /* ... */;

The ideal design should introduce minimum indirection to both item data manuplating and animations organizing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions