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
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#104929
Loading…
Reference in New Issue
No description provided.
Delete Branch "nrupsis/blender:T82241-cleanup-NLATrack_insert"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR removes the BKE_nlatrack_add, and adds new:
methods to easily add new NLA tracks in relation to the existing track list.
Having those functions is way clearer than the old
BKE_nlatrack_add
. I also like how this separates the code from theAnimData
struct.Pondering further on the API, I'm not a fan of
bool
parameters. Having to addbool is_liboverride
everywhere seems like an invasion of one Blender feature into another, and creates way too tight coupling. What would you think of an approach like this?BKE_nlatrack_new()
a parameterbool is_liboverride
, so that it can properly set (or not) theNLATRACK_OVERRIDELIBRARY_LOCAL
flag.bool BKE_nlatrack_is_liboverride(const struct NlaTrack *nla_track)
that uses this flag to determine whether or not it's a liboverride.struct NlaTrack *new_track
, remove thebool is_liboverride
and callBKE_nlatrack_is_liboverride()
instead.The
bool is_liboverride
argument is also rather un-documented, which the above should partially address by simply removing it altogether ;-) Where it is still left, be sure to document well what is actually "being the override".@ -37,1 +37,4 @@
/**
* Create new NLA Track.
*/
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?
@ -93,0 +130,4 @@
* Calls #BKE_nlatrack_new to create a new NLA track, inserts it as the head of the
* NLA track list with #BKE_nlatrack_new_before_and_set_active, and sets it as active.
*/
struct NlaTrack *BKE_nlatrack_new_head_and_set_active(ListBase *nla_tracks, bool is_liboverride);
API-wise I think it's nicer to separate the
BKE_nlatrack_new_xxx
functions from the_and_set_active
part. Having the functions a bit more atomic makes the calling part a bit more verbose, but I think it's a good call. Also the fact that the unit test doesn't cover the "and set active" part of the functionality might be an indication that the function is doing too much.Considering we already have the
BKE_nlatrack_set_active method
, it would be easy to refactor that.Would it be worth modifying:
BKE_nlatrack_new_before_and_set_active
->BKE_nlatrack_new_before
BKE_nlatrack_new_after_and_set_active
->BKE_nlatrack_new_after
etc?
The only difference between these modified methods, and
BKE_nlatrack_insert_before
/ after, is that we callBKE_nlatrack_new
. Would it also be worth removing those compositional methods and leaving it on the user to create a new NLA Track?Alternatively, we can create a unit test for
BKE_nlatrack_set_active
, and from the documentation forBKE_nlatrack_new_before_and_set_active
, etc reference that method?Hmmm that does make me think (in both directions -- i.e. doubting myself whether my original comment maybe pushed things too far, or whether we should push it even further than that). I think the important aspect here is that (as least AFAIK) an NLA track by itself doesn't do much. It should be in the NLA and not left 'floating' somewhere on the heap. As such, I think composite functions 'create & put in a useful place' are still good to keep around.
'Being the active one' makes no sense if it's a track by itself -- it only has meaning in the context of a list of tracks. You wouldn't use
BKE_nlatrack_set_active()
withoutBKE_nlatrack_new_before()
, but I can see a use forBKE_nlatrack_new_before()
withoutBKE_nlatrack_set_active()
.Would that be a good enough reason to keep the 'new-and-insert' composites, and pull out the 'set active' part?
I've had a lot of back and forth on this myself.
I think ultimately you're right. The
and_set_active
aspect of these methods are doing too much. I think having it be the responsibility of the caller isn't too much to ask for, especially if it's how we do it everywhere, it'll be easy to understand the pattern.I also think the
BKE_nlatrack_new_before/after/head/tail
methods are a good way of easily understanding where a new track is going to placed. In theory, it could also allow us to add some more "placement" option when adding in new tracks (without needing them active), but unsure if we'd ever want that.@ -354,0 +354,4 @@
{
if (is_liboverride) {
/** Currently, all library override tracks are assumed to be grouped together at the start of
No need to use doxygen (
/**
) inside functions.@ -354,0 +360,4 @@
BKE_nlatrack_insert_after(nla_tracks, next, new_track, is_liboverride);
return;
}
}
These nested conditions are getting complicated. The "So we can only add" seems to suggest that if this is not the case, the track cannot be added. However, there is no
return
then, so that means that it gets added as usual.On one hand it's good that the track always gets added, because that's what this function is for, but I'm not 100% convinced it's the right thing to do here.
It would also be good to have the special-casing for liboverrides documented in the header file.
@ -354,0 +381,4 @@
struct NlaTrack *new_track,
bool is_liboverride)
{
BLI_assert(!ELEM(NULL, nla_tracks, new_track));
I think it's better to separate those out, so that when things go wrong it's clear which pointer was
NULL
:@ -116,4 +114,38 @@ TEST(nla_track, BKE_nlatrack_remove_and_free)
EXPECT_EQ(-1, BLI_findindex(&adt.nla_tracks, track1));
}
TEST(nla_track, BKE_nlatrack_new_tail_and_set_active)
There should be separate tests for situations with liboverride tracks. The code to handle those is quite complex, so should be covered by tests.
@ -576,1 +576,3 @@
NlaTrack *new_track = BKE_nlatrack_add(adt, track, ID_IS_OVERRIDE_LIBRARY(id));
NlaTrack *new_track;
if (track != NULL) {
Flip the condition and the
if
/else
bodies. That removes a negation, making the code slightly simpler.I love this idea. I was actually wondering how I could have removed
is_liboverride
all together. But without being familiar with the override system, i figured I'd do more harm than good 😁But I like this approach.
After and offline conversation with @dr.sybren, we've determined that the existing code / functionality around the NLA Track overrides needs to be reevaluated.
It's outside the scope of this patch, and I've created a design task to review / refactor: #105272
@ -93,0 +113,4 @@
/**
* Calls #BKE_nlatrack_new to create a new NLA track, inserts it before the
* given NLA track with #BKE_nlatrack_insert_before, and sets it as active.
No longer sets as active ;-)
👍