Cleanup: Refactor BKE_nlatrack_add to multiple methods to handle adding a new NLA track to the track list. Insert before, after, head, and tail #104929

Merged
Nate Rupsis merged 8 commits from nrupsis/blender:T82241-cleanup-NLATrack_insert into main 2023-03-02 15:02:42 +01:00
3 changed files with 1 additions and 30 deletions
Showing only changes of commit 07acf48e49 - Show all commits

View File

@ -37,7 +37,6 @@ struct PropertyRNA;
/**
* Create new NLA Track.
*
* The returned pointer is owned by the caller.
nrupsis marked this conversation as resolved

This is one of those moments where I'm like.... wait, there was no function for this yet? 🤯

Anyway, also add a sentence like "The caller owns the returned pointer" for extra clarity.

Might also be good to document this with the functions that take such a pointer and add it to some list. What happens to the ownership of that pointer? Does it get owned by the owner of the list?

This is one of those moments where I'm like.... wait, there was no function for this yet? 🤯 Anyway, also add a sentence like "The caller owns the returned pointer" for extra clarity. Might also be good to document this with the functions that take such a pointer and add it to some list. What happens to the ownership of that pointer? Does it get owned by the owner of the list?
*/
struct NlaTrack *BKE_nlatrack_new(void);

View File

@ -429,7 +429,7 @@ NlaTrack *BKE_nlatrack_new_after(ListBase *nla_tracks, struct NlaTrack *prev, bo
{
NlaTrack *new_track = BKE_nlatrack_new();
BKE_nlatrack_insert_after(nla_tracks, prev, is_liboverride);
BKE_nlatrack_insert_after(nla_tracks, prev, new_track, is_liboverride);
return new_track;
}

View File

@ -145,32 +145,4 @@ TEST(nla_track, BKE_nlatrack_new_head)
}
TEST(nla_track, BKE_nlatrack_insert_before)
{
AnimData adt{};
NlaTrack *trackA = BKE_nlatrack_new();
NlaTrack *trackB = BKE_nlatrack_new();
NlaTrack *trackC = BKE_nlatrack_new();
// NlaTrack *trackD = BKE_nlatrack_new(false);
BKE_nlatrack_insert_before(&adt.nla_tracks, NULL, trackA, true);
BKE_nlatrack_insert_before(&adt.nla_tracks, trackA, trackB, true);
// Since Track C isn't library override, it'll get inserted after A
BKE_nlatrack_insert_before(&adt.nla_tracks, trackA, trackC, false);
// BKE_nlatrack_insert_before(&adt.nla_tracks, trackC, trackD);
// Expect B -> A -> C ordering.
EXPECT_EQ(0, BLI_findindex(&adt.nla_tracks, trackB));
EXPECT_EQ(1, BLI_findindex(&adt.nla_tracks, trackA));
EXPECT_EQ(2, BLI_findindex(&adt.nla_tracks, trackC));
// Free the tracks
BKE_nlatrack_remove_and_free(&adt.nla_tracks, trackA, false);
BKE_nlatrack_remove_and_free(&adt.nla_tracks, trackB, false);
BKE_nlatrack_remove_and_free(&adt.nla_tracks, trackC, false);
// BKE_nlatrack_remove_and_free(&adt.nla_tracks, trackD, false);
}
} // namespace blender::bke::tests