[Bf-blender-cvs] [f31ad5d98b3] master: Cleanup: refactoring BKE_nlastrips_add_strip method to Null check. Adding Unit tests for method
Nate Rupsis
noreply at git.blender.org
Thu Feb 2 19:21:01 CET 2023
Commit: f31ad5d98b3aa0697b5b1d477f7d58791ac19f97
Author: Nate Rupsis
Date: Mon Jan 30 14:39:36 2023 -0500
Branches: master
https://developer.blender.org/rBf31ad5d98b3aa0697b5b1d477f7d58791ac19f97
Cleanup: refactoring BKE_nlastrips_add_strip method to Null check. Adding Unit tests for method
Reviewed By: Sybren
Differential Revision: https://developer.blender.org/D17155
===================================================================
M source/blender/blenkernel/BKE_nla.h
M source/blender/blenkernel/intern/nla.c
M source/blender/blenkernel/intern/nla_test.cc
M source/blender/makesrna/intern/rna_nla.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_nla.h b/source/blender/blenkernel/BKE_nla.h
index dd558dc197c..d4d94618cc9 100644
--- a/source/blender/blenkernel/BKE_nla.h
+++ b/source/blender/blenkernel/BKE_nla.h
@@ -133,7 +133,19 @@ void BKE_nlastrips_sort_strips(ListBase *strips);
/**
* Add the given NLA-Strip to the given list of strips, assuming that it
- * isn't currently a member of another list
+ * isn't currently a member of another list, NULL, or conflicting with existing
+ * strips position.
+ */
+void BKE_nlastrips_add_strip_unsafe(ListBase *strips, struct NlaStrip *strip);
+
+/**
+ * @brief NULL checks incoming strip and verifies no overlap / invalid
+ * configuration against other strips in NLA Track.
+ *
+ * @param strips
+ * @param strip
+ * @return true
+ * @return false
*/
bool BKE_nlastrips_add_strip(ListBase *strips, struct NlaStrip *strip);
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index 1ff7fc21b01..defa67ed664 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -764,20 +764,13 @@ void BKE_nlastrips_sort_strips(ListBase *strips)
strips->last = tmp.last;
}
-bool BKE_nlastrips_add_strip(ListBase *strips, NlaStrip *strip)
+void BKE_nlastrips_add_strip_unsafe(ListBase *strips, NlaStrip *strip)
{
NlaStrip *ns;
bool not_added = true;
/* sanity checks */
- if (ELEM(NULL, strips, strip)) {
- return false;
- }
-
- /* check if any space to add */
- if (BKE_nlastrips_has_space(strips, strip->start, strip->end) == 0) {
- return false;
- }
+ BLI_assert(!ELEM(NULL, strips, strip));
/* find the right place to add the strip to the nominated track */
for (ns = strips->first; ns; ns = ns->next) {
@@ -792,8 +785,20 @@ bool BKE_nlastrips_add_strip(ListBase *strips, NlaStrip *strip)
/* just add to the end of the list of the strips then... */
BLI_addtail(strips, strip);
}
+}
+
+/** NULL and Space check before adding in nlastrip */
+bool BKE_nlastrips_add_strip(ListBase *strips, NlaStrip *strip)
+{
+ if (ELEM(NULL, strips, strip)) {
+ return false;
+ }
+
+ if (!BKE_nlastrips_has_space(strips, strip->start, strip->end)) {
+ return false;
+ }
- /* added... */
+ BKE_nlastrips_add_strip_unsafe(strips, strip);
return true;
}
diff --git a/source/blender/blenkernel/intern/nla_test.cc b/source/blender/blenkernel/intern/nla_test.cc
index 2f670ef69e5..b138baaaea0 100644
--- a/source/blender/blenkernel/intern/nla_test.cc
+++ b/source/blender/blenkernel/intern/nla_test.cc
@@ -39,4 +39,28 @@ TEST(nla_strip, BKE_nlastrip_recalculate_blend)
EXPECT_FLOAT_EQ(strip.blendout, 0.1);
}
+TEST(nla_strip, BKE_nlastrips_add_strip)
+{
+ ListBase strips{};
+ NlaStrip strip1{};
+ strip1.start = 0;
+ strip1.end = 10;
+ strips.first = &strip1;
+
+ NlaStrip strip2{};
+ strip2.start = 5;
+ strip2.end = 10;
+
+ /* can't add a null NLA strip to an NLA Track. */
+ EXPECT_FALSE(BKE_nlastrips_add_strip(&strips, NULL));
+
+ /* can't add an NLA strip to an NLA Track that overlaps another NLA strip. */
+ EXPECT_FALSE(BKE_nlastrips_add_strip(&strips, &strip2));
+
+ strip2.start = 15;
+ strip2.end = 20;
+ /* can add an NLA strip to an NLA Track that doesn't overlaps another NLA strip. */
+ EXPECT_TRUE(BKE_nlastrips_add_strip(&strips, &strip2));
+}
+
} // namespace blender::bke::tests
diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c
index b53b055cda8..ffd67b06037 100644
--- a/source/blender/makesrna/intern/rna_nla.c
+++ b/source/blender/makesrna/intern/rna_nla.c
@@ -539,7 +539,7 @@ static NlaStrip *rna_NlaStrip_new(ID *id,
strip->end += (start - strip->start);
strip->start = start;
- if (BKE_nlastrips_add_strip(&track->strips, strip) == 0) {
+ if (BKE_nlastrips_add_strip(&track->strips, strip)) {
BKE_report(
reports,
RPT_ERROR,
More information about the Bf-blender-cvs
mailing list