Refactor: replace BLI_BITMAP with blender::BitVector in keyframing.cc
No functional changes. This PR replaces the uses of the C-style `BLI_BITMAP` with `blender::BitVector` in `keyframing.cc`. Note that in `BKE_animsys_nla_remap_keyframe_values` I had to add code that maps from one to the other because I don't feel comfortable ripping out the `BLI_BITMAP` from `NlaEvalChannelSnapshot->remap_domain` Pull Request: https://projects.blender.org/blender/blender/pulls/118957
This commit is contained in:
committed by
Christoph Lendenfeld
parent
3fcd7ccbc0
commit
69943f65c7
@@ -12,7 +12,7 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_bit_span.hh"
|
||||
#include "BLI_vector.hh"
|
||||
#include "DNA_anim_types.h"
|
||||
#include "ED_transform.hh"
|
||||
@@ -206,7 +206,7 @@ int insert_key_action(Main *bmain,
|
||||
Span<float> values,
|
||||
eInsertKeyFlags insert_key_flag,
|
||||
eBezTriple_KeyframeType key_type,
|
||||
const BLI_bitmap *keying_mask);
|
||||
BitSpan keying_mask);
|
||||
|
||||
/**
|
||||
* Insert keys to the ID of the given PointerRNA for the given RNA paths. Tries to create an
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_bit_vector.hh"
|
||||
#include "BLI_dynstr.h"
|
||||
#include "BLI_math_base.h"
|
||||
#include "BLI_utildefines.h"
|
||||
@@ -118,7 +119,7 @@ static void get_keyframe_values_create_reports(ReportList *reports,
|
||||
const int index,
|
||||
const int count,
|
||||
const bool force_all,
|
||||
const BLI_bitmap *successful_remaps)
|
||||
const BitSpan successful_remaps)
|
||||
{
|
||||
|
||||
DynStr *ds_failed_indices = BLI_dynstr_new();
|
||||
@@ -131,7 +132,7 @@ static void get_keyframe_values_create_reports(ReportList *reports,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (BLI_BITMAP_TEST_BOOL(successful_remaps, i)) {
|
||||
if (successful_remaps[i]) {
|
||||
/* `values[i]` successfully remapped. */
|
||||
continue;
|
||||
}
|
||||
@@ -176,7 +177,7 @@ static Vector<float> get_keyframe_values(ReportList *reports,
|
||||
eInsertKeyFlags flag,
|
||||
const AnimationEvalContext *anim_eval_context,
|
||||
bool *r_force_all,
|
||||
BLI_bitmap **r_successful_remaps)
|
||||
blender::BitVector<> &r_successful_remaps)
|
||||
{
|
||||
Vector<float> values;
|
||||
|
||||
@@ -191,7 +192,7 @@ static Vector<float> get_keyframe_values(ReportList *reports,
|
||||
values = get_rna_values(&ptr, prop);
|
||||
}
|
||||
|
||||
*r_successful_remaps = BLI_BITMAP_NEW(values.size(), __func__);
|
||||
r_successful_remaps.resize(values.size());
|
||||
|
||||
/* adjust the value for NLA factors */
|
||||
BKE_animsys_nla_remap_keyframe_values(nla_context,
|
||||
@@ -201,14 +202,14 @@ static Vector<float> get_keyframe_values(ReportList *reports,
|
||||
index,
|
||||
anim_eval_context,
|
||||
r_force_all,
|
||||
*r_successful_remaps);
|
||||
r_successful_remaps);
|
||||
get_keyframe_values_create_reports(reports,
|
||||
ptr,
|
||||
prop,
|
||||
index,
|
||||
values.size(),
|
||||
r_force_all ? *r_force_all : false,
|
||||
*r_successful_remaps);
|
||||
r_successful_remaps);
|
||||
|
||||
return values;
|
||||
}
|
||||
@@ -385,27 +386,17 @@ bool insert_keyframe_direct(ReportList *reports,
|
||||
update_autoflags_fcurve_direct(fcu, prop);
|
||||
|
||||
const int index = fcu->array_index;
|
||||
BLI_bitmap *successful_remaps = nullptr;
|
||||
Vector<float> values = get_keyframe_values(reports,
|
||||
ptr,
|
||||
prop,
|
||||
index,
|
||||
nla_context,
|
||||
flag,
|
||||
anim_eval_context,
|
||||
nullptr,
|
||||
&successful_remaps);
|
||||
BitVector<> successful_remaps;
|
||||
Vector<float> values = get_keyframe_values(
|
||||
reports, ptr, prop, index, nla_context, flag, anim_eval_context, nullptr, successful_remaps);
|
||||
|
||||
float current_value = 0.0f;
|
||||
if (index >= 0 && index < values.size()) {
|
||||
current_value = values[index];
|
||||
}
|
||||
|
||||
const bool curval_valid = BLI_BITMAP_TEST_BOOL(successful_remaps, index);
|
||||
MEM_freeN(successful_remaps);
|
||||
|
||||
/* This happens if NLA rejects this insertion. */
|
||||
if (!curval_valid) {
|
||||
if (!successful_remaps[index]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -538,7 +529,7 @@ int insert_keyframe(Main *bmain,
|
||||
anim_eval_context, &id_ptr, adt, act, &nla_cache, &nla_context);
|
||||
|
||||
bool force_all;
|
||||
BLI_bitmap *successful_remaps = nullptr;
|
||||
BitVector successful_remaps;
|
||||
Vector<float> values = get_keyframe_values(reports,
|
||||
ptr,
|
||||
prop,
|
||||
@@ -547,7 +538,7 @@ int insert_keyframe(Main *bmain,
|
||||
flag,
|
||||
anim_eval_context,
|
||||
&force_all,
|
||||
&successful_remaps);
|
||||
successful_remaps);
|
||||
|
||||
/* Key the entire array. */
|
||||
int key_count = 0;
|
||||
@@ -557,7 +548,7 @@ int insert_keyframe(Main *bmain,
|
||||
int exclude = -1;
|
||||
|
||||
for (array_index = 0; array_index < values.size(); array_index++) {
|
||||
if (!BLI_BITMAP_TEST_BOOL(successful_remaps, array_index)) {
|
||||
if (!successful_remaps[array_index]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -584,7 +575,7 @@ int insert_keyframe(Main *bmain,
|
||||
flag &= ~(INSERTKEY_REPLACE | INSERTKEY_AVAILABLE);
|
||||
|
||||
for (array_index = 0; array_index < values.size(); array_index++) {
|
||||
if (!BLI_BITMAP_TEST_BOOL(successful_remaps, array_index)) {
|
||||
if (!successful_remaps[array_index]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -608,7 +599,7 @@ int insert_keyframe(Main *bmain,
|
||||
/* Simply insert all channels. */
|
||||
else {
|
||||
for (array_index = 0; array_index < values.size(); array_index++) {
|
||||
if (!BLI_BITMAP_TEST_BOOL(successful_remaps, array_index)) {
|
||||
if (!successful_remaps[array_index]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -629,9 +620,7 @@ int insert_keyframe(Main *bmain,
|
||||
}
|
||||
/* Key a single index. */
|
||||
else {
|
||||
if (array_index >= 0 && array_index < values.size() &&
|
||||
BLI_BITMAP_TEST_BOOL(successful_remaps, array_index))
|
||||
{
|
||||
if (array_index >= 0 && array_index < values.size() && successful_remaps[array_index]) {
|
||||
key_count += insert_keyframe_fcurve_value(bmain,
|
||||
reports,
|
||||
&ptr,
|
||||
@@ -647,7 +636,6 @@ int insert_keyframe(Main *bmain,
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(successful_remaps);
|
||||
BKE_animsys_free_nla_keyframing_context_cache(&nla_cache);
|
||||
|
||||
if (key_count > 0) {
|
||||
@@ -863,7 +851,7 @@ int insert_key_action(Main *bmain,
|
||||
const Span<float> values,
|
||||
eInsertKeyFlags insert_key_flag,
|
||||
eBezTriple_KeyframeType key_type,
|
||||
const BLI_bitmap *keying_mask)
|
||||
const BitSpan keying_mask)
|
||||
{
|
||||
BLI_assert(bmain != nullptr);
|
||||
BLI_assert(action != nullptr);
|
||||
@@ -880,7 +868,7 @@ int insert_key_action(Main *bmain,
|
||||
int property_array_index = 0;
|
||||
int inserted_keys = 0;
|
||||
for (float value : values) {
|
||||
if (!BLI_BITMAP_TEST_BOOL(keying_mask, property_array_index)) {
|
||||
if (!keying_mask[property_array_index]) {
|
||||
property_array_index++;
|
||||
continue;
|
||||
}
|
||||
@@ -975,7 +963,7 @@ void insert_key_rna(PointerRNA *rna_pointer,
|
||||
prop);
|
||||
Vector<float> rna_values = get_keyframe_values(&ptr, prop, visual_keyframing);
|
||||
|
||||
BLI_bitmap *successful_remaps = BLI_BITMAP_NEW(rna_values.size(), __func__);
|
||||
BitVector<> successful_remaps(rna_values.size(), false);
|
||||
BKE_animsys_nla_remap_keyframe_values(nla_context,
|
||||
rna_pointer,
|
||||
prop,
|
||||
@@ -995,7 +983,6 @@ void insert_key_rna(PointerRNA *rna_pointer,
|
||||
insert_key_flags,
|
||||
key_type,
|
||||
successful_remaps);
|
||||
MEM_freeN(successful_remaps);
|
||||
}
|
||||
|
||||
if (insert_key_count == 0) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* \ingroup bke
|
||||
*/
|
||||
|
||||
#include "BLI_bitmap.h"
|
||||
#include "BLI_bit_vector.hh"
|
||||
#include "BLI_span.hh"
|
||||
#include "BLI_sys_types.h" /* for bool */
|
||||
|
||||
@@ -265,7 +265,7 @@ void BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context,
|
||||
int index,
|
||||
const struct AnimationEvalContext *anim_eval_context,
|
||||
bool *r_force_all,
|
||||
BLI_bitmap *r_successful_remaps);
|
||||
blender::BitVector<> &r_successful_remaps);
|
||||
|
||||
/**
|
||||
* Free all cached contexts from the list.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_alloca.h"
|
||||
#include "BLI_bit_vector.hh"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_dynstr.h"
|
||||
#include "BLI_listbase.h"
|
||||
@@ -3714,34 +3715,32 @@ void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context,
|
||||
int index,
|
||||
const AnimationEvalContext *anim_eval_context,
|
||||
bool *r_force_all,
|
||||
BLI_bitmap *r_successful_remaps)
|
||||
blender::BitVector<> &r_successful_remaps)
|
||||
{
|
||||
const int count = values.size();
|
||||
BLI_bitmap_set_all(r_successful_remaps, false, count);
|
||||
r_successful_remaps.fill(false);
|
||||
|
||||
if (r_force_all != nullptr) {
|
||||
*r_force_all = false;
|
||||
}
|
||||
|
||||
BLI_bitmap *remap_domain = BLI_BITMAP_NEW(count, __func__);
|
||||
blender::BitVector remap_domain(count, false);
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!ELEM(index, i, -1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BLI_BITMAP_ENABLE(remap_domain, i);
|
||||
remap_domain[i].set();
|
||||
}
|
||||
|
||||
/* No context means no correction. */
|
||||
if (context == nullptr || context->strip.act == nullptr) {
|
||||
BLI_bitmap_copy_all(r_successful_remaps, remap_domain, count);
|
||||
MEM_freeN(remap_domain);
|
||||
r_successful_remaps = remap_domain;
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the strip is not evaluated, it is the same as zero influence. */
|
||||
if (context->eval_strip == nullptr) {
|
||||
MEM_freeN(remap_domain);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3753,14 +3752,12 @@ void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context,
|
||||
if (blend_mode == NLASTRIP_MODE_REPLACE && influence == 1.0f &&
|
||||
BLI_listbase_is_empty(&context->upper_estrips))
|
||||
{
|
||||
BLI_bitmap_copy_all(r_successful_remaps, remap_domain, count);
|
||||
MEM_freeN(remap_domain);
|
||||
r_successful_remaps = remap_domain;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Zero influence is division by zero. */
|
||||
if (influence <= 0.0f) {
|
||||
MEM_freeN(remap_domain);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3778,7 +3775,6 @@ void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context,
|
||||
if (nec->base_snapshot.length != count) {
|
||||
BLI_assert_msg(0, "invalid value count");
|
||||
nlaeval_snapshot_free_data(&blended_snapshot);
|
||||
MEM_freeN(remap_domain);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3795,10 +3791,12 @@ void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context,
|
||||
|
||||
*r_force_all = true;
|
||||
index = -1;
|
||||
BLI_bitmap_set_all(remap_domain, true, 4);
|
||||
remap_domain.fill(true);
|
||||
}
|
||||
|
||||
BLI_bitmap_copy_all(blended_necs->remap_domain.ptr, remap_domain, count);
|
||||
for (const int i : remap_domain.index_range()) {
|
||||
BLI_BITMAP_SET(blended_necs->remap_domain.ptr, i, remap_domain[i]);
|
||||
}
|
||||
|
||||
/* Need to send id_ptr instead of prop_ptr so fcurve RNA paths resolve properly. */
|
||||
PointerRNA id_ptr = RNA_id_pointer_create(prop_ptr->owner_id);
|
||||
@@ -3827,10 +3825,11 @@ void BKE_animsys_nla_remap_keyframe_values(NlaKeyframingContext *context,
|
||||
values[i] = blended_necs->values[i];
|
||||
}
|
||||
|
||||
BLI_bitmap_copy_all(r_successful_remaps, blended_necs->remap_domain.ptr, blended_necs->length);
|
||||
for (int i = 0; i < blended_necs->length; i++) {
|
||||
r_successful_remaps[i].set(BLI_BITMAP_TEST_BOOL(blended_necs->remap_domain.ptr, i));
|
||||
}
|
||||
|
||||
nlaeval_snapshot_free_data(&blended_snapshot);
|
||||
MEM_freeN(remap_domain);
|
||||
}
|
||||
|
||||
void BKE_animsys_free_nla_keyframing_context_cache(ListBase *cache)
|
||||
|
||||
Reference in New Issue
Block a user