From cc553739d8db796238f0bd6ec7a28218bdee593b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 21 Aug 2025 12:00:55 +0000 Subject: [PATCH] Cleanup: various minor changes BKE_object_modifier_update_subframe - Rename `parent_recursion` to `parent_recursion_limit`. - Use a define for the recursion default. - Use const arguments. --- source/blender/blenkernel/BKE_object.hh | 13 ++++++++-- .../blender/blenkernel/intern/dynamicpaint.cc | 2 +- source/blender/blenkernel/intern/fluid.cc | 9 +++++-- source/blender/blenkernel/intern/object.cc | 24 +++++++++---------- .../depsgraph/intern/depsgraph_physics.cc | 10 ++++---- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/source/blender/blenkernel/BKE_object.hh b/source/blender/blenkernel/BKE_object.hh index e734708aaf3..dd680b24bcd 100644 --- a/source/blender/blenkernel/BKE_object.hh +++ b/source/blender/blenkernel/BKE_object.hh @@ -650,6 +650,15 @@ void BKE_object_groups_clear(Main *bmain, Scene *scene, Object *object); */ KDTree_3d *BKE_object_as_kdtree(Object *ob, int *r_tot); +/** + * The number of times to recurse parents for evaluation. + * + * NOTE(@ideasman42): This value was picked to avoid infinite recursion. + * 5 is arbitrary but changing it would change behavior in some corner cases. + * See code comments in #BKE_object_modifier_update_subframe_only_callback for details. + */ +#define OBJECT_MODIFIER_UPDATE_SUBFRAME_RECURSION_DEFAULT 5 + /** * \note this function should eventually be replaced by depsgraph functionality. * Avoid calling this in new code unless there is a very good reason for it! @@ -658,9 +667,9 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update_mesh, - int parent_recursion, + int parent_recursion_limit, float frame, - int type); + int /*ModifierType*/ modifier_type); bool BKE_object_empty_image_frame_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d); bool BKE_object_empty_image_data_is_visible_in_view3d(const Object *ob, const RegionView3D *rv3d); diff --git a/source/blender/blenkernel/intern/dynamicpaint.cc b/source/blender/blenkernel/intern/dynamicpaint.cc index 60348a67009..5d4c5726ea3 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.cc +++ b/source/blender/blenkernel/intern/dynamicpaint.cc @@ -103,7 +103,7 @@ static int neighStraightX[8] = {1, 0, -1, 0, 1, -1, -1, 1}; static int neighStraightY[8] = {0, 1, 0, -1, 1, 1, -1, -1}; /* subframe_updateObject() flags */ -#define SUBFRAME_RECURSION 5 +#define SUBFRAME_RECURSION OBJECT_MODIFIER_UPDATE_SUBFRAME_RECURSION_DEFAULT /* #surface_getBrushFlags() return values. */ #define BRUSH_USES_VELOCITY (1 << 0) /* Brush mesh ray-cast status. */ diff --git a/source/blender/blenkernel/intern/fluid.cc b/source/blender/blenkernel/intern/fluid.cc index 6de050599de..987262c65ed 100644 --- a/source/blender/blenkernel/intern/fluid.cc +++ b/source/blender/blenkernel/intern/fluid.cc @@ -1259,8 +1259,13 @@ static void compute_obstaclesemission(Scene *scene, * BLI_mutex_lock() called in manta_step(), so safe to update subframe here * TODO(sebbas): Using BKE_scene_ctime_get(scene) instead of new DEG_get_ctime(depsgraph) * as subframes don't work with the latter yet. */ - BKE_object_modifier_update_subframe( - depsgraph, scene, effecobj, true, 5, BKE_scene_ctime_get(scene), eModifierType_Fluid); + BKE_object_modifier_update_subframe(depsgraph, + scene, + effecobj, + true, + OBJECT_MODIFIER_UPDATE_SUBFRAME_RECURSION_DEFAULT, + BKE_scene_ctime_get(scene), + eModifierType_Fluid); if (subframes) { obstacles_from_mesh(effecobj, fds, fes, &bb_temp, subframe_dt); diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc index 0e5a6c3c92f..37c3125fa64 100644 --- a/source/blender/blenkernel/intern/object.cc +++ b/source/blender/blenkernel/intern/object.cc @@ -5216,15 +5216,15 @@ static void object_cacheIgnoreClear(Object *ob, const bool state) bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, Scene *scene, Object *ob, - bool update_mesh, - int parent_recursion, - float frame, - int type) + const bool update_mesh, + const int parent_recursion_limit, + const float frame, + const /*ModifierType*/ int modifier_type) { const bool flush_to_original = DEG_is_active(depsgraph); - ModifierData *md = BKE_modifiers_findby_type(ob, (ModifierType)type); + ModifierData *md = BKE_modifiers_findby_type(ob, ModifierType(modifier_type)); - if (type == eModifierType_DynamicPaint) { + if (modifier_type == eModifierType_DynamicPaint) { DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md; /* if other is dynamic paint canvas, don't update */ @@ -5232,7 +5232,7 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, return true; } } - else if (type == eModifierType_Fluid) { + else if (modifier_type == eModifierType_Fluid) { FluidModifierData *fmd = (FluidModifierData *)md; if (fmd && (fmd->type & MOD_FLUID_TYPE_DOMAIN) != 0) { @@ -5241,16 +5241,16 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, } /* if object has parents, update them too */ - if (parent_recursion) { - int recursion = parent_recursion - 1; + if (parent_recursion_limit) { + const int recursion = parent_recursion_limit - 1; bool no_update = false; if (ob->parent) { no_update |= BKE_object_modifier_update_subframe( - depsgraph, scene, ob->parent, false, recursion, frame, type); + depsgraph, scene, ob->parent, false, recursion, frame, modifier_type); } if (ob->track) { no_update |= BKE_object_modifier_update_subframe( - depsgraph, scene, ob->track, false, recursion, frame, type); + depsgraph, scene, ob->track, false, recursion, frame, modifier_type); } /* Skip sub-frame if object is parented to vertex of a dynamic paint canvas. */ @@ -5266,7 +5266,7 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, LISTBASE_FOREACH (bConstraintTarget *, ct, &targets) { if (ct->tar) { BKE_object_modifier_update_subframe( - depsgraph, scene, ct->tar, false, recursion, frame, type); + depsgraph, scene, ct->tar, false, recursion, frame, modifier_type); } } /* free temp targets */ diff --git a/source/blender/depsgraph/intern/depsgraph_physics.cc b/source/blender/depsgraph/intern/depsgraph_physics.cc index 3901628727a..aca8653431e 100644 --- a/source/blender/depsgraph/intern/depsgraph_physics.cc +++ b/source/blender/depsgraph/intern/depsgraph_physics.cc @@ -101,12 +101,14 @@ void DEG_add_collision_relations(DepsNodeHandle *handle, if (ob1 == object) { continue; } - if (filter_function == nullptr || - filter_function(ob1, BKE_modifiers_findby_type(ob1, (ModifierType)modifier_type))) + if (filter_function && + !filter_function(ob1, BKE_modifiers_findby_type(ob1, (ModifierType)modifier_type))) { - DEG_add_object_pointcache_relation(handle, ob1, DEG_OB_COMP_TRANSFORM, name); - DEG_add_object_pointcache_relation(handle, ob1, DEG_OB_COMP_GEOMETRY, name); + continue; } + + DEG_add_object_pointcache_relation(handle, ob1, DEG_OB_COMP_TRANSFORM, name); + DEG_add_object_pointcache_relation(handle, ob1, DEG_OB_COMP_GEOMETRY, name); } }