diff options
author | YimingWu <xp8110@outlook.com> | 2019-05-06 05:09:12 +0300 |
---|---|---|
committer | YimingWu <xp8110@outlook.com> | 2019-05-06 05:09:12 +0300 |
commit | 2753611c4e2482885021416f1b2af46250fd09dd (patch) | |
tree | 47df66cf547affa1d388c3b154d5f5817af59819 /source/blender/blenkernel | |
parent | fbb5edf974f87894baa2cfd1a36878d5dce5be01 (diff) | |
parent | 90f8f5cb06efc3255257b1fcb0811dfab76cc146 (diff) |
Merge branch 'master' into soc-2018-npr
Diffstat (limited to 'source/blender/blenkernel')
149 files changed, 4208 insertions, 2824 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 4fc519ecd6d..f835f4332ed 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -134,8 +134,9 @@ struct DerivedMesh { * \warning Typical access is done via #getLoopTriArray, #getNumLoopTri. */ struct { - /* WARNING! swapping between array (ready-to-be-used data) and array_wip (where data is actually computed) - * shall always be protected by same lock as one used for looptris computing. */ + /* WARNING! swapping between array (ready-to-be-used data) and array_wip + * (where data is actually computed) shall always be protected by same + * lock as one used for looptris computing. */ struct MLoopTri *array, *array_wip; int num; int num_alloc; diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 0503efb1661..583a90b2dee 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -95,7 +95,8 @@ void BKE_animdata_merge_copy(struct Main *bmain, /* ************************************* */ /* KeyingSets API */ -/* Used to create a new 'custom' KeyingSet for the user, that will be automatically added to the stack */ +/* Used to create a new 'custom' KeyingSet for the user, + * that will be automatically added to the stack */ struct KeyingSet *BKE_keyingset_add( struct ListBase *list, const char idname[], const char name[], short flag, short keyingflag); diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 267617e154f..b5da30e725d 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -144,8 +144,9 @@ void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, float outmat[4][4]); void BKE_pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[3][3], bool use_compat); +void BKE_pchan_rot_to_mat3(const struct bPoseChannel *pchan, float mat[3][3]); void BKE_pchan_apply_mat4(struct bPoseChannel *pchan, float mat[4][4], bool use_comat); -void BKE_pchan_to_mat4(struct bPoseChannel *pchan, float chan_mat[4][4]); +void BKE_pchan_to_mat4(const struct bPoseChannel *pchan, float chan_mat[4][4]); void BKE_pchan_calc_mat(struct bPoseChannel *pchan); /* Simple helper, computes the offset bone matrix. */ diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 2433b856697..e01f6a6b751 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -27,7 +27,7 @@ * \note Use #STRINGIFY() rather than defining with quotes. */ #define BLENDER_VERSION 280 -#define BLENDER_SUBVERSION 58 +#define BLENDER_SUBVERSION 60 /** Several breakages with 280, e.g. collections vs layers. */ #define BLENDER_MINVERSION 280 #define BLENDER_MINSUBVERSION 0 diff --git a/source/blender/blenkernel/BKE_bvhutils.h b/source/blender/blenkernel/BKE_bvhutils.h index 1d40ba0bc78..4b64b6fa269 100644 --- a/source/blender/blenkernel/BKE_bvhutils.h +++ b/source/blender/blenkernel/BKE_bvhutils.h @@ -84,11 +84,12 @@ typedef struct BVHTreeFromMesh { /** * Builds a bvh tree where nodes are the relevant elements of the given mesh. - * Configures BVHTreeFromMesh. + * Configures #BVHTreeFromMesh. * * The tree is build in mesh space coordinates, this means special care must be made on queries * so that the coordinates and rays are first translated on the mesh local coordinates. - * Reason for this is that bvh_from_mesh_* can use a cache in some cases and so it becomes possible to reuse a BVHTree. + * Reason for this is that bvh_from_mesh_* can use a cache in some cases and so it + * becomes possible to reuse a #BVHTree. * * free_bvhtree_from_mesh should be called when the tree is no longer needed. */ diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h index b991ac24284..257975e3c17 100644 --- a/source/blender/blenkernel/BKE_cachefile.h +++ b/source/blender/blenkernel/BKE_cachefile.h @@ -29,8 +29,10 @@ extern "C" { #endif struct CacheFile; +struct CacheReader; struct Depsgraph; struct Main; +struct Object; struct Scene; void BKE_cachefiles_init(void); @@ -52,24 +54,27 @@ void BKE_cachefile_make_local(struct Main *bmain, struct CacheFile *cache_file, const bool lib_local); -void BKE_cachefile_reload(const struct Main *bmain, struct CacheFile *cache_file); +void BKE_cachefile_reload(struct Depsgraph *depsgraph, struct CacheFile *cache_file); -void BKE_cachefile_ensure_handle(const struct Main *bmain, struct CacheFile *cache_file); - -void BKE_cachefile_update_frame(struct Main *bmain, - struct Depsgraph *depsgraph, - struct Scene *scene, - const float ctime, - const float fps); +void BKE_cachefile_eval(struct Main *bmain, + struct Depsgraph *depsgraph, + struct CacheFile *cache_file); bool BKE_cachefile_filepath_get(const struct Main *bmain, + const struct Depsgraph *depsgrah, const struct CacheFile *cache_file, - float frame, char r_filename[1024]); -float BKE_cachefile_time_offset(struct CacheFile *cache_file, const float time, const float fps); +float BKE_cachefile_time_offset(const struct CacheFile *cache_file, + const float time, + const float fps); -void BKE_cachefile_clean(struct Main *bmain, struct CacheFile *cache_file); +/* Modifiers and constraints open and free readers through these. */ +void BKE_cachefile_reader_open(struct CacheFile *cache_file, + struct CacheReader **reader, + struct Object *object, + const char *object_path); +void BKE_cachefile_reader_free(struct CacheFile *cache_file, struct CacheReader **reader); #ifdef __cplusplus } diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h index 9ad3657284d..8fe3bd77a26 100644 --- a/source/blender/blenkernel/BKE_constraint.h +++ b/source/blender/blenkernel/BKE_constraint.h @@ -101,13 +101,22 @@ typedef struct bConstraintTypeInfo { void (*id_looper)(struct bConstraint *con, ConstraintIDFunc func, void *userdata); /** copy any special data that is allocated separately (optional) */ void (*copy_data)(struct bConstraint *con, struct bConstraint *src); - /** set settings for data that will be used for bConstraint.data (memory already allocated using MEM_callocN) */ + /** + * Set settings for data that will be used for #bConstraint.data + * (memory already allocated using #MEM_callocN). + */ void (*new_data)(void *cdata); /* target handling function pointers */ - /** for multi-target constraints: return that list; otherwise make a temporary list (returns number of targets) */ + /** + * For multi-target constraints: return that list; + * otherwise make a temporary list (returns number of targets). + */ int (*get_constraint_targets)(struct bConstraint *con, struct ListBase *list); - /** for single-target constraints only: flush data back to source data, and the free memory used */ + /** + * For single-target constraints only: + * flush data back to source data, and the free memory used. + */ void (*flush_constraint_targets)(struct bConstraint *con, struct ListBase *list, bool no_copy); /* evaluation */ diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index e4dc8ffae02..f354e5e6de3 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -113,7 +113,8 @@ bool CustomData_has_referenced(const struct CustomData *data); * implemented for mloopuv/mloopcol, for now.*/ void CustomData_data_copy_value(int type, const void *source, void *dest); -/* Same as above, but doing advanced mixing. Only available for a few types of data (like colors...). */ +/* Same as above, but doing advanced mixing. + * Only available for a few types of data (like colors...). */ void CustomData_data_mix_value( int type, const void *source, void *dest, const int mixmode, const float mixfactor); @@ -478,8 +479,8 @@ typedef void (*cd_datatransfer_interp)(const struct CustomDataTransferLayerMap * const float mix_factor); /** - * Fake CD_LAYERS (those are actually 'real' data stored directly into elements' structs, or otherwise not (directly) - * accessible to usual CDLayer system). */ + * Fake CD_LAYERS (those are actually 'real' data stored directly into elements' structs, + * or otherwise not (directly) accessible to usual CDLayer system). */ enum { CD_FAKE = 1 << 8, @@ -531,23 +532,29 @@ typedef struct CustomDataTransferLayerMap { int data_type; int mix_mode; float mix_factor; - const float * - mix_weights; /* If non-NULL, array of weights, one for each dest item, replaces mix_factor. */ - - const void * - data_src; /* Data source array (can be regular CD data, vertices/edges/etc., keyblocks...). */ - void *data_dst; /* Data dest array (same type as dat_src). */ - int data_src_n; /* Index to affect in data_src (used e.g. for vgroups). */ - int data_dst_n; /* Index to affect in data_dst (used e.g. for vgroups). */ - size_t elem_size; /* Size of one element of data_src/data_dst. */ - - size_t data_size; /* Size of actual data we transfer. */ - size_t - data_offset; /* Offset of actual data we transfer (in element contained in data_src/dst). */ - uint64_t data_flag; /* For bitflag transfer, flag(s) to affect in transferred data. */ - - void * - interp_data; /* Opaque pointer, to be used by specific interp callback (e.g. transformspace for normals). */ + /** If non-NULL, array of weights, one for each dest item, replaces mix_factor. */ + const float *mix_weights; + + /** Data source array (can be regular CD data, vertices/edges/etc., keyblocks...). */ + const void *data_src; + /** Data dest array (same type as dat_src). */ + void *data_dst; + /** Index to affect in data_src (used e.g. for vgroups). */ + int data_src_n; + /** Index to affect in data_dst (used e.g. for vgroups). */ + int data_dst_n; + /** Size of one element of data_src/data_dst. */ + size_t elem_size; + + /** Size of actual data we transfer. */ + size_t data_size; + /** Offset of actual data we transfer (in element contained in data_src/dst). */ + size_t data_offset; + /** For bitflag transfer, flag(s) to affect in transferred data. */ + uint64_t data_flag; + + /** Opaque pointer, to be used by specific interp callback (e.g. transformspace for normals). */ + void *interp_data; cd_datatransfer_interp interp; } CustomDataTransferLayerMap; diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index 510e989a087..fd7fa632999 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -109,7 +109,8 @@ void defvert_normalize_lock_map(struct MDeformVert *dvert, const bool *lock_flags, const int defbase_tot); -/* Utilities to 'extract' a given vgroup into a simple float array, for verts, but also edges/polys/loops. */ +/* Utilities to 'extract' a given vgroup into a simple float array, + * for verts, but also edges/polys/loops. */ void BKE_defvert_extract_vgroup_to_vertweights(struct MDeformVert *dvert, const int defgroup, const int num_verts, diff --git a/source/blender/blenkernel/BKE_dynamicpaint.h b/source/blender/blenkernel/BKE_dynamicpaint.h index 9f4f2862c95..c4f05d404ce 100644 --- a/source/blender/blenkernel/BKE_dynamicpaint.h +++ b/source/blender/blenkernel/BKE_dynamicpaint.h @@ -83,13 +83,11 @@ void dynamicPaint_freeBrush(struct DynamicPaintModifierData *pmd); void dynamicPaint_freeSurfaceData(struct DynamicPaintSurface *surface); void dynamicPaint_cacheUpdateFrames(struct DynamicPaintSurface *surface); -bool dynamicPaint_surfaceHasColorPreview(struct DynamicPaintSurface *surface); bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, struct Object *ob, int output); void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface); void dynamicPaintSurface_setUniqueName(struct DynamicPaintSurface *surface, const char *basename); -void dynamicPaint_resetPreview(struct DynamicPaintCanvasSettings *canvas); struct DynamicPaintSurface *get_activeSurface(struct DynamicPaintCanvasSettings *canvas); /* image sequence baking */ diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h index 15b59993d77..94e8f4304b8 100644 --- a/source/blender/blenkernel/BKE_effect.h +++ b/source/blender/blenkernel/BKE_effect.h @@ -154,8 +154,14 @@ int get_effector_data(struct EffectorCache *eff, int real_velocity); /* required for particle_system.c */ -//void do_physical_effector(struct EffectorData *eff, struct EffectorPoint *point, float *total_force); -//float effector_falloff(struct EffectorData *eff, struct EffectorPoint *point, struct EffectorWeights *weights); +#if 0 +void do_physical_effector(struct EffectorData *eff, + struct EffectorPoint *point, + float *total_force); +float effector_falloff(struct EffectorData *eff, + struct EffectorPoint *point, + struct EffectorWeights *weights); +#endif /* EffectedPoint->flag */ #define PE_WIND_AS_SPEED 1 diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h index 5e45faf1d0b..c1232addee3 100644 --- a/source/blender/blenkernel/BKE_fcurve.h +++ b/source/blender/blenkernel/BKE_fcurve.h @@ -128,29 +128,38 @@ float evaluate_driver(struct PathResolvedRNA *anim_rna, */ typedef struct FModifierTypeInfo { /* admin/ident */ - short type; /* FMODIFIER_TYPE_### */ - short size; /* size in bytes of the struct */ - short acttype; /* eFMI_Action_Types */ - short requires; /* eFMI_Requirement_Flags */ - char name[64]; /* name of modifier in interface */ - char structName[64]; /* name of struct for SDNA */ - uint storage_size; /* size of buffer that can be reused between time and value evaluation */ + /** #FMODIFIER_TYPE_* */ + short type; + /** size in bytes of the struct. */ + short size; + /** #eFMI_Action_Types. */ + short acttype; + /** #eFMI_Requirement_Flags. */ + short requires; + /** name of modifier in interface. */ + char name[64]; + /** name of struct for SDNA. */ + char structName[64]; + /** Size of buffer that can be reused between time and value evaluation. */ + uint storage_size; /* data management function pointers - special handling */ - /* free any data that is allocated separately (optional) */ + /** Free any data that is allocated separately (optional). */ void (*free_data)(struct FModifier *fcm); - /* copy any special data that is allocated separately (optional) */ + /** Copy any special data that is allocated separately (optional). */ void (*copy_data)(struct FModifier *fcm, const struct FModifier *src); - /* set settings for data that will be used for FCuModifier.data (memory already allocated using MEM_callocN) */ + /** + * Set settings for data that will be used for FCuModifier.data + * (memory already allocated using #MEM_callocN). */ void (*new_data)(void *mdata); - /* verifies that the modifier settings are valid */ + /** Verifies that the modifier settings are valid */ void (*verify_data)(struct FModifier *fcm); /* evaluation */ - /* evaluate time that the modifier requires the F-Curve to be evaluated at */ + /** Evaluate time that the modifier requires the F-Curve to be evaluated at */ float (*evaluate_modifier_time)( struct FCurve *fcu, struct FModifier *fcm, float cvalue, float evaltime, void *storage); - /* evaluate the modifier for the given time and 'accumulated' value */ + /** Evaluate the modifier for the given time and 'accumulated' value */ void (*evaluate_modifier)( struct FCurve *fcu, struct FModifier *fcm, float *cvalue, float evaltime, void *storage); } FModifierTypeInfo; @@ -223,7 +232,8 @@ int BKE_fcm_envelope_find_index(struct FCM_EnvelopeData *array, /* ************** F-Curves API ******************** */ -/* threshold for binary-searching keyframes - threshold here should be good enough for now, but should become userpref */ +/* threshold for binary-searching keyframes - threshold here should be good enough for now, + * but should become userpref */ #define BEZT_BINARYSEARCH_THRESH 0.01f /* was 0.00001, but giving errors */ /* -------- Data Management -------- */ @@ -243,7 +253,8 @@ struct FCurve *iter_step_fcurve(struct FCurve *fcu_iter, const char rna_path[]); struct FCurve *id_data_find_fcurve( ID *id, void *data, struct StructRNA *type, const char *prop_name, int index, bool *r_driven); -/* Get list of LinkData's containing pointers to the F-Curves which control the types of data indicated +/* Get list of LinkData's containing pointers to the F-Curves which control the types of data + * indicated * e.g. numMatches = list_find_data_fcurves(matches, &act->curves, "pose.bones[", "MyFancyBone"); */ int list_find_data_fcurves(ListBase *dst, @@ -259,7 +270,8 @@ struct FCurve *rna_get_fcurve(struct PointerRNA *ptr, struct bAction **r_action, bool *r_driven, bool *r_special); -/* Same as above, but takes a context data, temp hack needed for complex paths like texture ones. */ +/* Same as above, but takes a context data, + * temp hack needed for complex paths like texture ones. */ struct FCurve *rna_get_fcurve_context_ui(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h index 128ff39de7a..4655abf6e02 100644 --- a/source/blender/blenkernel/BKE_gpencil_modifier.h +++ b/source/blender/blenkernel/BKE_gpencil_modifier.h @@ -38,8 +38,8 @@ struct Object; struct Scene; struct ViewLayer; struct bArmature; -struct - bContext; /* NOTE: bakeModifier() - called from UI - needs to create new datablocks, hence the need for this */ +/* NOTE: bakeModifier() called from UI: needs to create new datablocks, hence the need for this. */ +struct bContext; struct bGPDframe; struct bGPDlayer; struct bGPDstroke; diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h index 98fb59814fa..cc6c43c51f6 100644 --- a/source/blender/blenkernel/BKE_layer.h +++ b/source/blender/blenkernel/BKE_layer.h @@ -68,7 +68,6 @@ struct ViewLayer *BKE_view_layer_find_from_collection(const struct Scene *scene, struct Base *BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob); void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer); -void BKE_view_layer_base_select(struct Base *selbase); void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, struct Base *selbase); void BKE_view_layer_copy_data(struct Scene *scene_dst, diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 82ae832c73e..54b9fdac5b4 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -34,13 +34,13 @@ extern "C" { * WARNING: description below is ideal goal, current status of naming does not yet * fully follow it (this is WIP). * - * BKE_id_ should be used for rather high-level operations, that involve Main database and - * relations with other IDs, and can be considered as 'safe' (as in, in themselves, they leave - * affected IDs/Main in a consistent status). + * - BKE_id_ should be used for rather high-level operations, that involve Main database and + * relations with other IDs, and can be considered as 'safe' + * (as in, in themselves, they leave affected IDs/Main in a consistent status). * - * BKE_libblock_ should be used for lower level operations, that perform some parts of BKE_id_ ones, - * but will generally not ensure caller that affected data is in a consistent state - * by their own execution alone. + * - BKE_libblock_ should be used for lower level operations, + * that perform some parts of BKE_id_ ones, but will generally not ensure caller that affected + * data is in a consistent state by their own execution alone. * * Consequently, external code should not typically use BKE_libblock_ functions, * except in some specific cases requiring advanced (and potentially dangerous) handling. @@ -72,44 +72,47 @@ void *BKE_id_new_nomain(const short type, const char *name); */ enum { /* *** Generic options (should be handled by all ID types copying, ID creation, etc.). *** */ - /* Create datablock outside of any main database - similar to 'localize' functions of materials etc. */ + /** Create datablock outside of any main database - + * similar to 'localize' functions of materials etc. */ LIB_ID_CREATE_NO_MAIN = 1 << 0, - /* Do not affect user refcount of datablocks used by new one (which also gets zero usercount then). + /** Do not affect user refcount of datablocks used by new one + * (which also gets zero usercount then). * Implies LIB_ID_CREATE_NO_MAIN. */ LIB_ID_CREATE_NO_USER_REFCOUNT = 1 << 1, - /* Assume given 'newid' already points to allocated memory for whole datablock (ID + data) - USE WITH CAUTION! + /** Assume given 'newid' already points to allocated memory for whole datablock + * (ID + data) - USE WITH CAUTION! * Implies LIB_ID_CREATE_NO_MAIN. */ LIB_ID_CREATE_NO_ALLOCATE = 1 << 2, - /* Do not tag new ID for update in depsgraph. */ + /** Do not tag new ID for update in depsgraph. */ LIB_ID_CREATE_NO_DEG_TAG = 1 << 8, /* *** Specific options to some ID types or usages. *** */ /* *** May be ignored by unrelated ID copying functions. *** */ - /* Object only, needed by make_local code. */ + /** Object only, needed by make_local code. */ LIB_ID_COPY_NO_PROXY_CLEAR = 1 << 16, - /* Do not copy preview data, when supported. */ + /** Do not copy preview data, when supported. */ LIB_ID_COPY_NO_PREVIEW = 1 << 17, - /* Copy runtime data caches. */ + /** Copy runtime data caches. */ LIB_ID_COPY_CACHES = 1 << 18, - /* Don't copy id->adt, used by ID datablock localization routines. */ + /** Don't copy id->adt, used by ID datablock localization routines. */ LIB_ID_COPY_NO_ANIMDATA = 1 << 19, - /* Mesh: Reference CD data layers instead of doing real copy - USE WITH CAUTION! */ + /** Mesh: Reference CD data layers instead of doing real copy - USE WITH CAUTION! */ LIB_ID_COPY_CD_REFERENCE = 1 << 20, /* *** XXX Hackish/not-so-nice specific behaviors needed for some corner cases. *** */ /* *** Ideally we should not have those, but we need them for now... *** */ - /* EXCEPTION! Deep-copy actions used by animdata of copied ID. */ + /** EXCEPTION! Deep-copy actions used by animdata of copied ID. */ LIB_ID_COPY_ACTIONS = 1 << 24, - /* Keep the library pointer when copying datablock outside of bmain. */ + /** Keep the library pointer when copying datablock outside of bmain. */ LIB_ID_COPY_KEEP_LIB = 1 << 25, - /* EXCEPTION! Deep-copy shapekeys used by copied obdata ID. */ + /** EXCEPTION! Deep-copy shapekeys used by copied obdata ID. */ LIB_ID_COPY_SHAPEKEY = 1 << 26, /* *** Helper 'defines' gathering most common flag sets. *** */ - /* Shapekeys are not real ID's, more like local data to geometry IDs... */ + /** Shapekeys are not real ID's, more like local data to geometry IDs... */ LIB_ID_COPY_DEFAULT = LIB_ID_COPY_SHAPEKEY, - /* Generate a local copy, outside of bmain, to work on (used by COW e.g.). */ + /** Generate a local copy, outside of bmain, to work on (used by COW e.g.). */ LIB_ID_COPY_LOCALIZE = LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_CREATE_NO_DEG_TAG | LIB_ID_COPY_NO_PREVIEW | LIB_ID_COPY_CACHES, }; diff --git a/source/blender/blenkernel/BKE_library_query.h b/source/blender/blenkernel/BKE_library_query.h index caa36742f76..94e7830aabe 100644 --- a/source/blender/blenkernel/BKE_library_query.h +++ b/source/blender/blenkernel/BKE_library_query.h @@ -38,9 +38,12 @@ enum { */ IDWALK_CB_INDIRECT_USAGE = (1 << 2), - /** That ID is used as mere sub-data by its owner + /** + * That ID is used as mere sub-data by its owner * (only case currently: those f***ing nodetrees in materials etc.). - * This means callback shall not *do* anything, only use this as informative data if it needs it. */ + * This means callback shall not *do* anything, + * only use this as informative data if it needs it. + */ IDWALK_CB_PRIVATE = (1 << 3), /** That ID is not really used by its owner, it's just an internal hint/helper. diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h index da104c4c205..41ac8c8c8e6 100644 --- a/source/blender/blenkernel/BKE_library_remap.h +++ b/source/blender/blenkernel/BKE_library_remap.h @@ -29,29 +29,44 @@ extern "C" { /* Also IDRemap->flag. */ enum { - /* Do not remap indirect usages of IDs (that is, when user is some linked data). */ + /** Do not remap indirect usages of IDs (that is, when user is some linked data). */ ID_REMAP_SKIP_INDIRECT_USAGE = 1 << 0, - /* This flag should always be set, *except for 'unlink' scenarios* (only relevant when new_id == NULL). - * Basically, when unset, NEVER_NULL ID usages will keep pointing to old_id, but (if needed) old_id user count - * will still be decremented. This is mandatory for 'delete ID' case, but in all other situation this would lead - * to invalid user counts! */ + /** + * This flag should always be set, *except for 'unlink' scenarios* + * (only relevant when new_id == NULL). + * Basically, when unset, NEVER_NULL ID usages will keep pointing to old_id, but (if needed) + * old_id user count will still be decremented. + * This is mandatory for 'delete ID' case, + * but in all other situation this would lead to invalid user counts! + */ ID_REMAP_SKIP_NEVER_NULL_USAGE = 1 << 1, - /* This tells the callback func to flag with LIB_DOIT all IDs using target one with a 'never NULL' pointer - * (like e.g. Object->data). */ + /** + * This tells the callback func to flag with #LIB_DOIT all IDs + * using target one with a 'never NULL' pointer (like e.g. #Object.data). + */ ID_REMAP_FLAG_NEVER_NULL_USAGE = 1 << 2, - /* This tells the callback func to force setting IDs using target one with a 'never NULL' pointer to NULL. - * WARNING! Use with extreme care, this will leave database in broken state and can cause crashes very easily! */ + /** + * This tells the callback func to force setting IDs + * using target one with a 'never NULL' pointer to NULL. + * \warning Use with extreme care, this will leave database in broken state + * and can cause crashes very easily! + */ ID_REMAP_FORCE_NEVER_NULL_USAGE = 1 << 3, - /* Do not consider proxy/_group pointers of local objects as indirect usages... - * Our oh-so-beloved proxies again... Do not consider data used by local proxy object as indirect usage. - * This is needed e.g. in reload scenario, since we have to ensure remapping of Armature data of local proxy - * is also performed. Usual nightmare... */ + /** + * Do not consider proxy/_group pointers of local objects as indirect usages... + * Our oh-so-beloved proxies again... + * Do not consider data used by local proxy object as indirect usage. + * This is needed e.g. in reload scenario, + * since we have to ensure remapping of Armature data of local proxy + * is also performed. Usual nightmare... + */ ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE = 1 << 4, - /* Do not remap static override pointers. */ + /** Do not remap static override pointers. */ ID_REMAP_SKIP_STATIC_OVERRIDE = 1 << 5, }; -/* Note: Requiring new_id to be non-null, this *may* not be the case ultimately, but makes things simpler for now. */ +/* Note: Requiring new_id to be non-null, this *may* not be the case ultimately, + * but makes things simpler for now. */ void BKE_libblock_remap_locked(struct Main *bmain, void *old_idv, void *new_idv, diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index b8721f61371..1c987d5eb8e 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -57,7 +57,8 @@ typedef struct BlendThumbnail { /* Structs caching relations between data-blocks in a given Main. */ typedef struct MainIDRelationsEntry { struct MainIDRelationsEntry *next; - /* WARNING! for user_to_used, that pointer is really an ID** one, but for used_to_user, it’s only an ID* one! */ + /* WARNING! for user_to_used, + * that pointer is really an ID** one, but for used_to_user, it’s only an ID* one! */ struct ID **id_pointer; int usage_flag; /* Using IDWALK_ enums, in BKE_library_query.h */ } MainIDRelationsEntry; @@ -121,9 +122,11 @@ typedef struct Main { ListBase cachefiles; ListBase workspaces; - /* Must be generated, used and freed by same code - never assume this is valid data unless you know - * when, who and how it was created. - * Used by code doing a lot of remapping etc. at once to speed things up. */ + /** + * Must be generated, used and freed by same code - never assume this is valid data unless you + * know when, who and how it was created. + * Used by code doing a lot of remapping etc. at once to speed things up. + */ struct MainIDRelations *relations; struct MainLock *lock; @@ -165,7 +168,9 @@ struct GSet *BKE_main_gset_create(struct Main *bmain, struct GSet *gset); } \ ((void)0) -/* DO NOT use break statement with that macro, use FOREACH_MAIN_LISTBASE and FOREACH_MAIN_LISTBASE_ID instead +/** + * DO NOT use break statement with that macro, + * use #FOREACH_MAIN_LISTBASE and #FOREACH_MAIN_LISTBASE_ID instead * if you need that kind of control flow. */ #define FOREACH_MAIN_ID_BEGIN(_bmain, _id) \ { \ diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 37c502b3b0c..9d8b9218a79 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -113,7 +113,7 @@ void free_matcopybuf(void); void copy_matcopybuf(struct Main *bmain, struct Material *ma); void paste_matcopybuf(struct Main *bmain, struct Material *ma); -/* Evaluation. */ +/* Dependency graph evaluation. */ struct Depsgraph; diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index d4ad0e771d3..ecee00b1b3f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -123,10 +123,12 @@ struct Mesh *BKE_mesh_new_nomain_from_template(const struct Mesh *me_src, int loops_len, int polys_len); -/* Performs copy for use during evaluation, optional referencing original arrays to reduce memory. */ +/* Performs copy for use during evaluation, + * optional referencing original arrays to reduce memory. */ struct Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference); -/* These functions construct a new Mesh, contrary to BKE_mesh_from_nurbs which modifies ob itself. */ +/* These functions construct a new Mesh, + * contrary to BKE_mesh_from_nurbs which modifies ob itself. */ struct Mesh *BKE_mesh_new_nomain_from_curve(struct Object *ob); struct Mesh *BKE_mesh_new_nomain_from_curve_displist(struct Object *ob, struct ListBase *dispbase); @@ -214,8 +216,8 @@ struct Mesh *BKE_mesh_new_from_object(struct Depsgraph *depsgraph, const bool calc_undeformed); struct Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph, struct Scene *scene, - struct Object *ob, - struct ModifierData *md, + struct Object *ob_eval, + struct ModifierData *md_eval, int build_shapekey_layers); /* Copies a nomain-Mesh into an existing Mesh. */ @@ -671,6 +673,7 @@ enum { BKE_MESH_BATCH_DIRTY_ALL = 0, BKE_MESH_BATCH_DIRTY_MAYBE_ALL, BKE_MESH_BATCH_DIRTY_SELECT, + BKE_MESH_BATCH_DIRTY_SELECT_PAINT, BKE_MESH_BATCH_DIRTY_SHADING, BKE_MESH_BATCH_DIRTY_SCULPT_COORDS, BKE_MESH_BATCH_DIRTY_UVEDIT_ALL, diff --git a/source/blender/blenkernel/BKE_mesh_remap.h b/source/blender/blenkernel/BKE_mesh_remap.h index 54f263a8bfb..36cc5bedb79 100644 --- a/source/blender/blenkernel/BKE_mesh_remap.h +++ b/source/blender/blenkernel/BKE_mesh_remap.h @@ -54,10 +54,12 @@ void BKE_mesh_remap_item_define_invalid(MeshPairRemap *map, const int index); /* TODO: * Add other 'from/to' mapping sources, like e.g. using an UVMap, etc. - * http://blenderartists.org/forum/showthread.php?346458-Move-Vertices-to-the-location-of-the-Reference-Mesh-based-on-the-UV-Position + * https://blenderartists.org/t/619105 + * * We could also use similar topology mappings inside a same mesh * (cf. Campbell's 'select face islands from similar topology' wip work). - * Also, users will have to check, whether we can get rid of some modes here, not sure all will be useful! + * Also, users will have to check, whether we can get rid of some modes here, + * not sure all will be useful! */ enum { MREMAP_USE_VERT = 1 << 4, @@ -104,13 +106,15 @@ enum { /* Nearest edge of nearest poly (using mid-point). */ MREMAP_MODE_EDGE_POLY_NEAREST = MREMAP_MODE_EDGE | MREMAP_USE_POLY | MREMAP_USE_NEAREST, - /* Cast a set of rays from along dest edge, interpolating its vertices' normals, and use hit source edges. */ + /* Cast a set of rays from along dest edge, + * interpolating its vertices' normals, and use hit source edges. */ MREMAP_MODE_EDGE_EDGEINTERP_VNORPROJ = MREMAP_MODE_EDGE | MREMAP_USE_VERT | MREMAP_USE_NORPROJ | MREMAP_USE_INTERP, /* ***** Target's loops ***** */ - /* Note: when islands are given to loop mapping func, all loops from the same destination face will always be mapped - * to loops of source faces within a same island, regardless of mapping mode. */ + /* Note: when islands are given to loop mapping func, + * all loops from the same destination face will always be mapped + * to loops of source faces within a same island, regardless of mapping mode. */ MREMAP_MODE_LOOP = 1 << 26, /* Best normal-matching loop from nearest vert. */ @@ -138,7 +142,8 @@ enum { /* Source poly from best normal-matching dest poly. */ MREMAP_MODE_POLY_NOR = MREMAP_MODE_POLY | MREMAP_USE_POLY | MREMAP_USE_NORMAL, - /* Project dest poly onto source mesh using its normal, and use interpolation of all intersecting source polys. */ + /* Project dest poly onto source mesh using its normal, + * and use interpolation of all intersecting source polys. */ MREMAP_MODE_POLY_POLYINTERP_PNORPROJ = MREMAP_MODE_POLY | MREMAP_USE_POLY | MREMAP_USE_NORPROJ | MREMAP_USE_INTERP, diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 5b6f3cf17c4..a34f570ad1f 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -83,8 +83,8 @@ typedef enum { */ eModifierTypeFlag_RequiresOriginalData = (1 << 5), - /* For modifiers that support pointcache, so we can check to see if it has files we need to deal with - */ + /* For modifiers that support pointcache, + * so we can check to see if it has files we need to deal with. */ eModifierTypeFlag_UsesPointCache = (1 << 6), /* For physics modifiers, max one per type */ diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 43ee284a201..9425f396bc5 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -116,7 +116,8 @@ bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip, struct MovieClipUser *user, struct ImBuf *ibuf); -/* Evaluation. */ +/* Dependency graph evaluation. */ + void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, struct MovieClip *clip); void BKE_movieclip_eval_selection_update(struct Depsgraph *depsgraph, struct MovieClip *clip); diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 682d0b981fa..b760be29dae 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -218,7 +218,7 @@ typedef struct bNodeType { /// Called when the node is updated in the editor. void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node); /// Check and update if internal ID data has changed. - void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id); + void (*group_update_func)(struct bNodeTree *ntree, struct bNode *node); /// Initialize a new node instance of this type after creation. void (*initfunc)(struct bNodeTree *ntree, struct bNode *node); @@ -395,15 +395,14 @@ struct bNode *ntreeFindType(const struct bNodeTree *ntree, int type); bool ntreeHasType(const struct bNodeTree *ntree, int type); bool ntreeHasTree(const struct bNodeTree *ntree, const struct bNodeTree *lookup); void ntreeUpdateTree(struct Main *main, struct bNodeTree *ntree); -/* XXX Currently each tree update call does call to ntreeVerifyNodes too. - * Some day this should be replaced by a decent depsgraph automatism! - */ -void ntreeVerifyNodes(struct Main *main, struct ID *id); +void ntreeUpdateAllNew(struct Main *main); +void ntreeUpdateAllUsers(struct Main *main, struct ID *id); void ntreeGetDependencyList(struct bNodeTree *ntree, struct bNode ***deplist, int *totnodes); -/* XXX old trees handle output flags automatically based on special output node types and last active selection. - * new tree types have a per-output socket flag to indicate the final output to use explicitly. +/* XXX old trees handle output flags automatically based on special output + * node types and last active selection. + * New tree types have a per-output socket flag to indicate the final output to use explicitly. */ void ntreeSetOutput(struct bNodeTree *ntree); @@ -736,10 +735,10 @@ void node_type_label( struct bNodeType *ntype, void (*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen)); void node_type_update(struct bNodeType *ntype, - void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), - void (*verifyfunc)(struct bNodeTree *ntree, - struct bNode *node, - struct ID *id)); + void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node)); +void node_type_group_update(struct bNodeType *ntype, + void (*group_update_func)(struct bNodeTree *ntree, + struct bNode *node)); void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction initexecfunc, @@ -777,16 +776,20 @@ void BKE_node_tree_unlink_id(ID *id, struct bNodeTree *ntree); /* -------------------------------------------------------------------- */ /** \name Node Tree Iterator * - * Utility macro for visiting every node tree in the library data, including local bNodeTree blocks in other IDs. - * This avoids the need for callback functions and allows executing code in a single inner code block. + * Utility macro for visiting every node tree in the library data, + * including local bNodeTree blocks in other IDs. + * This avoids the need for callback functions and allows executing code + * in a single inner code block. * * Variables: * - * nodetree: The actual bNodeTree data block. - * Check nodetree->idname or nodetree->typeinfo to use only specific types. + * - nodetree: + * The actual bNodeTree data block. + * Check nodetree->idname or nodetree->typeinfo to use only specific types. * - * id: The owner of the bNodeTree data block. - * Same as nodetree if it's a linkable node tree from the library. + * - id: + * The owner of the bNodeTree data block. + * Same as nodetree if it's a linkable node tree from the library. * * Examples: * @@ -854,7 +857,8 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, /* note: types are needed to restore callbacks, don't change values */ /* range 1 - 100 is reserved for common nodes */ -/* using toolbox, we add node groups by assuming the values below don't exceed NODE_GROUP_MENU for now */ +/* using toolbox, we add node groups by assuming the values below + * don't exceed NODE_GROUP_MENU for now. */ //#define SH_NODE_OUTPUT 1 diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h index ab7ca44368c..49b35bfccc1 100644 --- a/source/blender/blenkernel/BKE_object.h +++ b/source/blender/blenkernel/BKE_object.h @@ -153,7 +153,7 @@ struct Object *BKE_object_duplicate(struct Main *bmain, void BKE_object_obdata_size_init(struct Object *ob, const float scale); void BKE_object_scale_to_mat3(struct Object *ob, float mat[3][3]); -void BKE_object_rot_to_mat3(struct Object *ob, float mat[3][3], bool use_drot); +void BKE_object_rot_to_mat3(const struct Object *ob, float mat[3][3], bool use_drot); void BKE_object_mat3_to_rot(struct Object *ob, float mat[3][3], bool use_compat); void BKE_object_to_mat3(struct Object *ob, float mat[3][3]); void BKE_object_to_mat4(struct Object *ob, float mat[4][4]); diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index b0fbf07d467..56c92b731b7 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -145,6 +145,7 @@ void BKE_paint_runtime_init(const struct ToolSettings *ts, struct Paint *paint); void BKE_paint_cavity_curve_preset(struct Paint *p, int preset); eObjectMode BKE_paint_object_mode_from_paintmode(ePaintMode mode); +bool BKE_paint_ensure_from_paintmode(struct Scene *sce, ePaintMode mode); struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode); const struct EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode); const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode); diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h index feb40d86151..f9bd722f8ba 100644 --- a/source/blender/blenkernel/BKE_particle.h +++ b/source/blender/blenkernel/BKE_particle.h @@ -201,21 +201,24 @@ typedef struct ParticleCollisionElement { short inv_nor, inside; } ParticleCollisionElement; -/* container for moving data between deflet_particle and particle_intersect_face */ +/** Container for moving data between deflet_particle and particle_intersect_face. */ typedef struct ParticleCollision { struct Object *current; struct Object *hit; struct Object *skip[PARTICLE_COLLISION_MAX_COLLISIONS + 1]; struct Object *emitter; - struct CollisionModifierData *md; // collision modifier for current object; + /** Collision modifier for current object. */ + struct CollisionModifierData *md; - float f; // time factor of previous collision, needed for substracting face velocity + /** Time factor of previous collision, needed for substracting face velocity. */ + float f; float fac1, fac2; float cfra, old_cfra; - float original_ray_length; //original length of co2-co1, needed for collision time evaluation + /** Original length of co2-co1, needed for collision time evaluation. */ + float original_ray_length; int skip_count; diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 6df6d36aceb..9b15462de6b 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -40,6 +40,7 @@ struct MPoly; struct MVert; struct PBVH; struct PBVHNode; +struct GPU_PBVH_Buffers; typedef struct PBVH PBVH; typedef struct PBVHNode PBVHNode; @@ -48,6 +49,21 @@ typedef struct { float (*co)[3]; } PBVHProxyNode; +typedef enum { + PBVH_Leaf = 1, + + PBVH_UpdateNormals = 2, + PBVH_UpdateBB = 4, + PBVH_UpdateOriginalBB = 8, + PBVH_UpdateDrawBuffers = 16, + PBVH_UpdateRedraw = 32, + + PBVH_RebuildDrawBuffers = 64, + PBVH_FullyHidden = 128, + + PBVH_UpdateTopology = 256, +} PBVHNodeFlags; + /* Callbacks */ /* returns 1 if the search should continue from this node, 0 otherwise */ @@ -151,13 +167,15 @@ bool BKE_pbvh_node_find_nearest_to_ray(PBVH *bvh, void BKE_pbvh_draw_cb(PBVH *bvh, float (*planes)[4], float (*fnors)[3], - bool fast, - bool wires, - bool only_mask, bool show_vcol, - void (*draw_fn)(void *user_data, struct GPUBatch *batch), + void (*draw_fn)(void *user_data, struct GPU_PBVH_Buffers *buffers), void *user_data); +void BKE_pbvh_draw_debug_cb( + PBVH *bvh, + void (*draw_fn)(void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag), + void *user_data); + /* PBVH Access */ typedef enum { PBVH_FACES, @@ -202,21 +220,6 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh, /* Node Access */ -typedef enum { - PBVH_Leaf = 1, - - PBVH_UpdateNormals = 2, - PBVH_UpdateBB = 4, - PBVH_UpdateOriginalBB = 8, - PBVH_UpdateDrawBuffers = 16, - PBVH_UpdateRedraw = 32, - - PBVH_RebuildDrawBuffers = 64, - PBVH_FullyHidden = 128, - - PBVH_UpdateTopology = 256, -} PBVHNodeFlags; - void BKE_pbvh_node_mark_update(PBVHNode *node); void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node); void BKE_pbvh_node_mark_redraw(PBVHNode *node); @@ -400,8 +403,8 @@ void BKE_pbvh_node_get_bm_orco_data(PBVHNode *node, bool BKE_pbvh_node_vert_update_check_any(PBVH *bvh, PBVHNode *node); -//void BKE_pbvh_node_BB_reset(PBVHNode *node); -//void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]); +// void BKE_pbvh_node_BB_reset(PBVHNode *node); +// void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]); bool pbvh_has_mask(PBVH *bvh); void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color); diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index 8a8ae3e2566..6ce60081f5b 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -167,7 +167,8 @@ typedef struct PTCacheID { void (*interpolate_extra_data)( void *calldata, struct PTCacheMem *pm, float cfra, float cfra1, float cfra2); - /* total number of simulated points (the cfra parameter is just for using same function pointer with totwrite) */ + /* Total number of simulated points + * (the cfra parameter is just for using same function pointer with totwrite). */ int (*totpoint)(void *calldata, int cfra); /* report error if number of points does not match */ void (*error)(void *calldata, const char *message); @@ -265,8 +266,8 @@ typedef struct PTCacheEdit { struct ParticleSystemModifierData *psmd; struct ParticleSystemModifierData *psmd_eval; struct KDTree_3d *emitter_field; - float * - emitter_cosnos; /* localspace face centers and normals (average of its verts), from the derived mesh */ + /* Localspace face centers and normals (average of its verts), from the derived mesh. */ + float *emitter_cosnos; int *mirror_cache; struct ParticleCacheKey **pathcache; /* path cache (runtime) */ diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h index 72bc95028da..c940e646d95 100644 --- a/source/blender/blenkernel/BKE_rigidbody.h +++ b/source/blender/blenkernel/BKE_rigidbody.h @@ -106,7 +106,8 @@ void BKE_rigidbody_remove_constraint(struct Scene *scene, struct Object *ob); (rbo->flag & RBO_FLAG_DISABLED))) ? \ (0.0f) : \ (rbo->mass)) -/* get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, convex hull always uses custom margin */ +/* Get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, + * convex hull always uses custom margin. */ #define RBO_GET_MARGIN(rbo) \ ((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || \ rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? \ diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h index 6cd71604561..3b5db883cf3 100644 --- a/source/blender/blenkernel/BKE_scene.h +++ b/source/blender/blenkernel/BKE_scene.h @@ -102,7 +102,6 @@ int BKE_scene_base_iter_next(struct Depsgraph *depsgraph, void BKE_scene_base_flag_to_objects(struct ViewLayer *view_layer); void BKE_scene_object_base_flag_sync_from_base(struct Base *base); -void BKE_scene_object_base_flag_sync_from_object(struct Base *base); void BKE_scene_set_background(struct Main *bmain, struct Scene *sce); struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name); @@ -241,6 +240,14 @@ void BKE_scene_cursor_quat_to_rot(struct View3DCursor *cursor, const float quat[4], bool use_compat); +/* Dependency graph evaluation. */ + +/* Evaluate parts of sequences which needs to be done as a part of a dependency graph evaluation. + * This does NOT include actual rendering of the strips, but rather makes them up-to-date for + * animation playback and makes them ready for the sequencer's rendering pipeline to render them. + */ +void BKE_scene_eval_sequencer_sequences(struct Depsgraph *depsgraph, struct Scene *scene); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 6a9711dd316..93c9c41e482 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -182,7 +182,8 @@ typedef struct ARegionType { int prefsizex, prefsizey; /* default keymaps to add */ int keymapflag; - /* return without drawing. lock is set by region definition, and copied to do_lock by render. can become flag */ + /* return without drawing. + * lock is set by region definition, and copied to do_lock by render. can become flag. */ short do_lock, lock; /* call cursor function on each move event */ short event_cursor; @@ -337,7 +338,8 @@ struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *ar); void BKE_area_region_free(struct SpaceType *st, struct ARegion *ar); void BKE_area_region_panels_free(struct ListBase *panels); void BKE_screen_area_free(struct ScrArea *sa); -/* Gizmo-maps of a region need to be freed with the region. Uses callback to avoid low-level call. */ +/* Gizmo-maps of a region need to be freed with the region. + * Uses callback to avoid low-level call. */ void BKE_region_callback_free_gizmomap_set(void (*callback)(struct wmGizmoMap *)); void BKE_region_callback_refresh_tag_gizmomap_set(void (*callback)(struct wmGizmoMap *)); diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h index 820f28fb363..170ab657388 100644 --- a/source/blender/blenkernel/BKE_sequencer.h +++ b/source/blender/blenkernel/BKE_sequencer.h @@ -100,9 +100,8 @@ typedef struct SeqRenderData { /* special case for OpenGL render */ struct GPUOffScreen *gpu_offscreen; - struct GPUFX *gpu_fx; - int gpu_samples; - bool gpu_full_samples; + // int gpu_samples; + // bool gpu_full_samples; } SeqRenderData; void BKE_sequencer_new_render_data(struct Main *bmain, @@ -302,46 +301,33 @@ void BKE_sequencer_proxy_set(struct Sequence *seq, bool value); * Sequencer memory cache management functions * ********************************************************************** */ -typedef enum { - SEQ_STRIPELEM_IBUF, - SEQ_STRIPELEM_IBUF_COMP, - SEQ_STRIPELEM_IBUF_STARTSTILL, - SEQ_STRIPELEM_IBUF_ENDSTILL, -} eSeqStripElemIBuf; +#define SEQ_CACHE_COST_MAX 10.0f -void BKE_sequencer_cache_destruct(void); -void BKE_sequencer_cache_cleanup(void); - -/* returned ImBuf is properly refed and has to be freed */ struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context, struct Sequence *seq, float cfra, - eSeqStripElemIBuf type); - -/* passed ImBuf is properly refed, so ownership is *not* - * transferred to the cache. - * you can pass the same ImBuf multiple times to the cache without problems. - */ - + int type); void BKE_sequencer_cache_put(const SeqRenderData *context, struct Sequence *seq, float cfra, - eSeqStripElemIBuf type, - struct ImBuf *nval); - -void BKE_sequencer_cache_cleanup_sequence(struct Sequence *seq); - -struct ImBuf *BKE_sequencer_preprocessed_cache_get(const SeqRenderData *context, - struct Sequence *seq, - float cfra, - eSeqStripElemIBuf type); -void BKE_sequencer_preprocessed_cache_put(const SeqRenderData *context, - struct Sequence *seq, - float cfra, - eSeqStripElemIBuf type, - struct ImBuf *ibuf); -void BKE_sequencer_preprocessed_cache_cleanup(void); -void BKE_sequencer_preprocessed_cache_cleanup_sequence(struct Sequence *seq); + int type, + struct ImBuf *nval, + float cost); +bool BKE_sequencer_cache_put_if_possible(const SeqRenderData *context, + struct Sequence *seq, + float cfra, + int type, + struct ImBuf *nval, + float cost); +void BKE_sequencer_cache_free_temp_cache(struct Scene *scene, short id, int cfra); +void BKE_sequencer_cache_destruct(struct Scene *scene); +void BKE_sequencer_cache_cleanup_all(struct Main *bmain); +void BKE_sequencer_cache_cleanup(struct Scene *scene); +void BKE_sequencer_cache_cleanup_sequence(struct Scene *scene, struct Sequence *seq); +void BKE_sequencer_cache_iterate( + struct Scene *scene, + void *userdata, + bool callback(void *userdata, struct Sequence *seq, int cfra, int cache_type, float cost)); /* ********************************************************************** * seqeffects.c @@ -500,19 +486,9 @@ struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seqbasep, struct SeqLoadInfo *seq_load); -/* view3d draw callback, run when not in background view */ -/* NOTE: Keep in sync with V3D_OFSDRAW_* flags. */ -enum { - SEQ_OFSDRAW_NONE = (0), - SEQ_OFSDRAW_USE_BACKGROUND = (1 << 0), - SEQ_OFSDRAW_USE_FULL_SAMPLE = (1 << 1), - SEQ_OFSDRAW_USE_GPENCIL = (1 << 2), - SEQ_OFSDRAW_USE_SOLID_TEX = (1 << 2), - SEQ_OFSDRAW_USE_CAMERA_DOF = (1 << 3), -}; - typedef struct ImBuf *(*SequencerDrawView)(struct Depsgraph *depsgraph, struct Scene *scene, + struct View3DShading *shading_override, int drawtype, struct Object *camera, int width, @@ -590,6 +566,6 @@ void BKE_sequencer_color_balance_apply(struct StripColorBalance *cb, bool make_float, struct ImBuf *mask_input); -void BKE_sequencer_all_free_anim_ibufs(struct Main *bmain, int cfra); +void BKE_sequencer_all_free_anim_ibufs(struct Scene *scene, int cfra); #endif /* __BKE_SEQUENCER_H__ */ diff --git a/source/blender/blenkernel/BKE_shrinkwrap.h b/source/blender/blenkernel/BKE_shrinkwrap.h index d97525d4094..8993654254e 100644 --- a/source/blender/blenkernel/BKE_shrinkwrap.h +++ b/source/blender/blenkernel/BKE_shrinkwrap.h @@ -112,7 +112,8 @@ void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd, int numVerts); /* - * This function casts a ray in the given BVHTree.. but it takes into consideration the space_transform, that is: + * This function casts a ray in the given BVHTree. + * but it takes into consideration the space_transform, that is: * * if transf was configured with "SPACE_TRANSFORM_SETUP( &transf, ob1, ob2 )" * then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space @@ -129,7 +130,8 @@ bool BKE_shrinkwrap_project_normal(char options, struct ShrinkwrapTreeData *tree, BVHTreeRayHit *hit); -/* Maps the point to the nearest surface, either by simple nearest, or by target normal projection. */ +/* Maps the point to the nearest surface, either by simple nearest, + * or by target normal projection. */ void BKE_shrinkwrap_find_nearest_surface(struct ShrinkwrapTreeData *tree, struct BVHTreeNearest *nearest, float co[3], diff --git a/source/blender/blenkernel/BKE_softbody.h b/source/blender/blenkernel/BKE_softbody.h index 049950f2a03..e0a8b7f9d5d 100644 --- a/source/blender/blenkernel/BKE_softbody.h +++ b/source/blender/blenkernel/BKE_softbody.h @@ -37,8 +37,8 @@ typedef struct BodyPoint { int *springs; float choke, choke2, frozen; float colball; - short loc_flag; //reserved by locale module specific states - //char octantflag; + short loc_flag; // reserved by locale module specific states + // char octantflag; float mass; float springweight; } BodyPoint; diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 91e23d35f0e..f526dd579ce 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -32,6 +32,7 @@ struct Main; struct Sequence; struct bSound; +struct Depsgraph; typedef struct SoundWaveform { int length; @@ -71,10 +72,17 @@ void BKE_sound_cache(struct bSound *sound); void BKE_sound_delete_cache(struct bSound *sound); +void BKE_sound_reset_runtime(struct bSound *sound); void BKE_sound_load(struct Main *main, struct bSound *sound); +void BKE_sound_ensure_loaded(struct Main *bmain, struct bSound *sound); void BKE_sound_free(struct bSound *sound); +/* Is used by sequencer to temporarily load audio to access information about channels and + * duration. */ +void BKE_sound_load_audio(struct Main *main, struct bSound *sound); +void BKE_sound_free_audio(struct bSound *sound); + void BKE_sound_copy_data(struct Main *bmain, struct bSound *sound_dst, const struct bSound *sound_src, @@ -86,7 +94,9 @@ void BKE_sound_make_local(struct Main *bmain, struct bSound *sound, const bool l AUD_Device *BKE_sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume); #endif +void BKE_sound_reset_scene_runtime(struct Scene *scene); void BKE_sound_create_scene(struct Scene *scene); +void BKE_sound_ensure_scene(struct Scene *scene); void BKE_sound_destroy_scene(struct Scene *scene); @@ -134,6 +144,10 @@ void BKE_sound_stop_scene(struct Scene *scene); void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene); +/* Use this after original scene's frame has been changed. It will take care of doing all the + * updates required for BKE_sound_seek_scene(). */ +void BKE_sound_update_and_seek(struct Main *bmain, struct Depsgraph *depsgraph); + float BKE_sound_sync_scene(struct Scene *scene); int BKE_sound_scene_playing(struct Scene *scene); @@ -150,4 +164,15 @@ float BKE_sound_get_length(struct bSound *sound); char **BKE_sound_get_device_names(void); +typedef void (*SoundJackSyncCallback)(struct Main *bmain, int mode, float time); + +void BKE_sound_jack_sync_callback_set(SoundJackSyncCallback callback); +void BKE_sound_jack_scene_update(struct Scene *scene, int mode, float time); + +/* Dependency graph evaluation. */ + +struct Depsgraph; + +void BKE_sound_evaluate(struct Depsgraph *depsgraph, struct Main *bmain, struct bSound *sound); + #endif /* __BKE_SOUND_H__ */ diff --git a/source/blender/blenkernel/BKE_undo_system.h b/source/blender/blenkernel/BKE_undo_system.h index fc6fc6ff336..d4cb9331605 100644 --- a/source/blender/blenkernel/BKE_undo_system.h +++ b/source/blender/blenkernel/BKE_undo_system.h @@ -92,7 +92,8 @@ typedef struct UndoType { /** * When NULL, we don't consider this undo type for context checks. * Operators must explicitly set the undo type and handle adding the undo step. - * This is needed when tools operate on data which isn't the primary mode (eg, paint-curve in sculpt mode). + * This is needed when tools operate on data which isn't the primary mode + * (eg, paint-curve in sculpt mode). */ bool (*poll)(struct bContext *C); diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h index 17973265390..4f9ff61c9a6 100644 --- a/source/blender/blenkernel/BKE_unit.h +++ b/source/blender/blenkernel/BKE_unit.h @@ -63,7 +63,7 @@ double bUnit_BaseScalar(int system, int type); bool bUnit_IsValid(int system, int type); /* loop over scales, could add names later */ -//double bUnit_Iter(void **unit, char **name, int system, int type); +// double bUnit_Iter(void **unit, char **name, int system, int type); void bUnit_GetSystem(int system, int type, void const **r_usys_pt, int *r_len); int bUnit_GetBaseUnit(const void *usys_pt); diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index cd612cd9d8c..e564e91749c 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -24,29 +24,29 @@ set(INC ../blenlib ../blenloader ../blentranslation + ../bmesh ../depsgraph ../draw + ../gpencil_modifiers ../gpu ../ikplugin ../imbuf ../makesdna ../makesrna - ../bmesh ../modifiers - ../gpencil_modifiers - ../shader_fx ../nodes ../physics + ../shader_fx ../render/extern/include ../../../intern/ghost - ../../../intern/guardedalloc ../../../intern/glew-mx + ../../../intern/guardedalloc ../../../intern/iksolver/extern - ../../../intern/memutil - ../../../intern/mikktspace ../../../intern/atomic ../../../intern/clog ../../../intern/libmv + ../../../intern/memutil + ../../../intern/mikktspace ../../../intern/opensubdiv ../../../extern/curve_fit_nd ../../../intern/smoke/extern diff --git a/source/blender/blenkernel/intern/CCGSubSurf_intern.h b/source/blender/blenkernel/intern/CCGSubSurf_intern.h index f89545e802e..41a34b65381 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf_intern.h +++ b/source/blender/blenkernel/intern/CCGSubSurf_intern.h @@ -269,7 +269,10 @@ struct CCGSubSurf { #define EDGE_getNo(e, lvl, x) ccg_edge_getNo(e, lvl, x, vertDataSize, normalDataOffset) #define FACE_getIFNo(f, lvl, S, x, y) \ ccg_face_getIFNo(f, lvl, S, x, y, subdivLevels, vertDataSize, normalDataOffset) -//#define FACE_calcIFNo(f, lvl, S, x, y, no) _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize) +#if 0 +# define FACE_calcIFNo(f, lvl, S, x, y, no) \ + _face_calcIFNo(f, lvl, S, x, y, no, subdivLevels, vertDataSize) +#endif #define FACE_getIENo(f, lvl, S, x) \ ccg_face_getIENo(f, lvl, S, x, subdivLevels, vertDataSize, normalDataOffset) #define FACE_getIECo(f, lvl, S, x) ccg_face_getIECo(f, lvl, S, x, subdivLevels, vertDataSize) diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index e70fcfe75c1..959435ad486 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -246,8 +246,8 @@ static const MLoopTri *dm_getLoopTriArray(DerivedMesh *dm) } else { BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE); - /* We need to ensure array is still NULL inside mutex-protected code, some other thread might have already - * recomputed those looptris. */ + /* We need to ensure array is still NULL inside mutex-protected code, + * some other thread might have already recomputed those looptris. */ if (dm->looptris.array == NULL) { dm->recalcLoopTri(dm); } @@ -485,7 +485,8 @@ void DM_ensure_normals(DerivedMesh *dm) /** * Ensure the array is large enough * - * \note This function must always be thread-protected by caller. It should only be used by internal code. + * \note This function must always be thread-protected by caller. + * It should only be used by internal code. */ void DM_ensure_looptri_data(DerivedMesh *dm) { @@ -1039,16 +1040,28 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input, /* Compute normals. */ const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 || (dataMask->lmask & CD_MASK_NORMAL) != 0); - /* Some modifiers may need this info from their target (other) object, simpler to generate it here as well. + /* Some modifiers may need this info from their target (other) object, + * simpler to generate it here as well. * Note that they will always be generated when no loop normals are comptuted, * since they are needed by drawing code. */ const bool do_poly_normals = ((dataMask->pmask & CD_MASK_NORMAL) != 0); if (do_loop_normals) { - /* In case we also need poly normals, add the layer here, then BKE_mesh_calc_normals_split() will fill it. */ + /* In case we also need poly normals, add the layer and compute them here + * (BKE_mesh_calc_normals_split() assumes that if that data exists, it is always valid). */ if (do_poly_normals) { if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) { - CustomData_add_layer(&mesh_final->pdata, CD_NORMAL, CD_CALLOC, NULL, mesh_final->totpoly); + float(*polynors)[3] = CustomData_add_layer( + &mesh_final->pdata, CD_NORMAL, CD_CALLOC, NULL, mesh_final->totpoly); + BKE_mesh_calc_normals_poly(mesh_final->mvert, + NULL, + mesh_final->totvert, + mesh_final->mloop, + mesh_final->mpoly, + mesh_final->totloop, + mesh_final->totpoly, + polynors, + false); } } /* Compute loop normals (note: will compute poly and vert normals as well, if needed!) */ @@ -1076,8 +1089,9 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input, } } - /* Some modifiers, like datatransfer, may generate those data as temp layer, we do not want to keep them, - * as they are used by display code when available (i.e. even if autosmooth is disabled). */ + /* Some modifiers, like data-transfer, may generate those data as temp layer, + * we do not want to keep them, as they are used by display code when available + * (i.e. even if autosmooth is disabled). */ if (!do_loop_normals && CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) { CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, mesh_final->totloop); } @@ -1354,7 +1368,8 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph, CustomData_add_layer( &mesh_final->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh_final->totpoly); - /* Not worth parallelizing this, gives less than 0.1% overall speedup in best of best cases... */ + /* Not worth parallelizing this, + * gives less than 0.1% overall speedup in best of best cases... */ range_vn_i( CustomData_get_layer(&mesh_final->vdata, CD_ORIGINDEX), mesh_final->totvert, 0); range_vn_i( @@ -1574,11 +1589,13 @@ static void editbmesh_calc_modifier_final_normals(const Mesh *mesh_input, { const bool do_loop_normals = ((mesh_input->flag & ME_AUTOSMOOTH) != 0 || (dataMask->lmask & CD_MASK_NORMAL) != 0); - /* Some modifiers may need this info from their target (other) object, simpler to generate it here as well. */ + /* Some modifiers may need this info from their target (other) object, + * simpler to generate it here as well. */ const bool do_poly_normals = ((dataMask->pmask & CD_MASK_NORMAL) != 0); if (do_loop_normals) { - /* In case we also need poly normals, add the layer here, then BKE_mesh_calc_normals_split() will fill it. */ + /* In case we also need poly normals, add the layer here, + * then BKE_mesh_calc_normals_split() will fill it. */ if (do_poly_normals) { if (!CustomData_has_layer(&mesh_final->pdata, CD_NORMAL)) { CustomData_add_layer(&mesh_final->pdata, CD_NORMAL, CD_CALLOC, NULL, mesh_final->totpoly); @@ -2009,7 +2026,10 @@ static void mesh_build_data(struct Depsgraph *depsgraph, * but this avoids waiting on first stroke) */ /* XXX Disabled for now. * This can create horrible nasty bugs by generating re-entrant call of mesh_get_eval_final! */ - // BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, false, false); +#if 0 + BKE_sculpt_update_mesh_elements( + depsgraph, scene, scene->toolsettings->sculpt, ob, false, false); +#endif } mesh_runtime_check_normals_valid(ob->runtime.mesh_eval); @@ -2433,7 +2453,8 @@ static void mesh_init_origspace(Mesh *mesh) } invert_v2(scale); - /* Finally, transform all vcos_2d into ((0, 0), (1, 1)) square and assign them as origspace. */ + /* Finally, transform all vcos_2d into ((0, 0), (1, 1)) + * square and assign them as origspace. */ for (j = 0; j < mp->totloop; j++, lof++) { add_v2_v2v2(lof->uv, vcos_2d[j], translate); mul_v2_v2(lof->uv, scale); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 8e9158b8433..9b321ff4e44 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -115,8 +115,10 @@ void BKE_action_free(bAction *act) /* .................................. */ /** - * Only copy internal data of Action ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Action ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -139,8 +141,11 @@ void BKE_action_copy_data(Main *UNUSED(bmain), for (fcu_src = act_src->curves.first; fcu_src; fcu_src = fcu_src->next) { /* duplicate F-Curve */ - fcu_dst = copy_fcurve( - fcu_src); /* XXX TODO pass subdata flag? But surprisingly does not seem to be doing any ID refcounting... */ + + /* XXX TODO pass subdata flag? + * But surprisingly does not seem to be doing any ID refcounting... */ + fcu_dst = copy_fcurve(fcu_src); + BLI_addtail(&act_dst->curves, fcu_dst); /* fix group links (kindof bad list-in-list search, but this is the most reliable way) */ @@ -309,12 +314,13 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) /* firstly, link this F-Curve to the group */ agrp->channels.first = agrp->channels.last = fcurve; - /* step through the groups preceding this one, finding the F-Curve there to attach this one after */ + /* Step through the groups preceding this one, + * finding the F-Curve there to attach this one after. */ for (grp = agrp->prev; grp; grp = grp->prev) { - /* if this group has F-Curves, we want weave the given one in right after the last channel there, - * but via the Action's list not this group's list + /* if this group has F-Curves, we want weave the given one in right after the last channel + * there, but via the Action's list not this group's list * - this is so that the F-Curve is in the right place in the Action, - * but won't be included in the previous group + * but won't be included in the previous group. */ if (grp->channels.last) { /* once we've added, break here since we don't need to search any further... */ @@ -323,9 +329,9 @@ void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve) } } - /* if grp is NULL, that means we fell through, and this F-Curve should be added as the new first - * since group is (effectively) the first group. Thus, the existing first F-Curve becomes the - * second in the chain, etc. etc. + /* If grp is NULL, that means we fell through, and this F-Curve should be added as the new + * first since group is (effectively) the first group. Thus, the existing first F-Curve becomes + * the second in the chain, etc. etc. */ if (grp == NULL) { BLI_insertlinkbefore(&act->curves, act->curves.first, fcurve); @@ -606,7 +612,8 @@ void BKE_pose_copy_data_ex(bPose **dst, &listb, &pchan->constraints, flag, true); // BKE_constraints_copy NULLs listb pchan->constraints = listb; - /* XXX: This is needed for motionpath drawing to work. Dunno why it was setting to null before... */ + /* XXX: This is needed for motionpath drawing to work. + * Dunno why it was setting to null before... */ pchan->mpath = animviz_copy_motionpath(pchan->mpath); } @@ -1287,7 +1294,8 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan, for (fcu = act->curves.first; fcu; fcu = fcu->next) { const char *bPtr = NULL, *pPtr = NULL; - /* if enough flags have been found, we can stop checking unless we're also getting the curves */ + /* If enough flags have been found, + * we can stop checking unless we're also getting the curves. */ if ((flags == ACT_TRANS_ALL) && (curves == NULL)) { break; } @@ -1531,14 +1539,12 @@ void what_does_obaction( } BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr)); - BLI_strncpy( - workob->id.name, - "OB<ConstrWorkOb>", - sizeof( - workob->id - .name)); /* we don't use real object name, otherwise RNA screws with the real thing */ - - /* if we're given a group to use, it's likely to be more efficient (though a bit more dangerous) */ + + /* we don't use real object name, otherwise RNA screws with the real thing */ + BLI_strncpy(workob->id.name, "OB<ConstrWorkOb>", sizeof(workob->id.name)); + + /* If we're given a group to use, it's likely to be more efficient + * (though a bit more dangerous). */ if (agrp) { /* specifically evaluate this group only */ PointerRNA id_ptr; diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c index e74af25a4a1..6b8f8e5303e 100644 --- a/source/blender/blenkernel/intern/anim.c +++ b/source/blender/blenkernel/intern/anim.c @@ -202,7 +202,8 @@ bMotionPath *animviz_verify_motionpaths(ReportList *reports, mpath = *dst; - /* path is "valid" if length is valid, but must also be of the same length as is being requested */ + /* Path is "valid" if length is valid, + * but must also be of the same length as is being requested. */ if ((mpath->start_frame != mpath->end_frame) && (mpath->length > 0)) { /* outer check ensures that we have some curve data for this path */ if (mpath->length == expected_length) { @@ -309,7 +310,8 @@ void calc_curvepath(Object *ob, ListBase *nurbs) tot = cycl ? bl->nr : bl->nr - 1; path->len = tot + 1; - /* exception: vector handle paths and polygon paths should be subdivided at least a factor resolu */ + /* Exception: vector handle paths and polygon paths should be subdivided + * at least a factor resolution. */ if (path->len < nu->resolu * SEGMENTSU(nu)) { path->len = nu->resolu * SEGMENTSU(nu); } @@ -478,7 +480,7 @@ int where_on_path(Object *ob, * which used to temporary set CU_FOLLOW flag for the curve and no * longer does it (because of threading issues of such a thing. */ - //if (cu->flag & CU_FOLLOW) { + // if (cu->flag & CU_FOLLOW) { key_curve_tangent_weights(1.0f - fac, data, KEY_BSPLINE); diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index e8bcb664c6e..cc5cd3b03ae 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -179,7 +179,8 @@ AnimData *BKE_animdata_add_id(ID *id) /* Action Setter --------------------------------------- */ -/* Called when user tries to change the active action of an AnimData block (via RNA, Outliner, etc.) */ +/** Called when user tries to change the active action of an AnimData block + * (via RNA, Outliner, etc.) */ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act) { AnimData *adt = BKE_animdata_from_id(id); @@ -283,7 +284,8 @@ void BKE_animdata_free(ID *id, const bool do_id_user) /** * Make a copy of the given AnimData - to be used when copying datablocks. - * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \param flag: Control ID pointers management, + * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h * \return The copied animdata. */ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag) @@ -325,7 +327,8 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag) } /** - * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \param flag: Control ID pointers management, + * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h * \return true is succesfully copied. */ bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag) @@ -572,7 +575,8 @@ void BKE_animdata_separate_by_basepath(Main *bmain, ID *srcID, ID *dstID, ListBa /* active action */ if (srcAdt->action) { - /* set up an action if necessary, and name it in a similar way so that it can be easily found again */ + /* Set up an action if necessary, + * and name it in a similar way so that it can be easily found again. */ if (dstAdt->action == NULL) { dstAdt->action = BKE_action_add(bmain, srcAdt->action->id.name + 2); } @@ -629,7 +633,8 @@ void BKE_animdata_separate_by_basepath(Main *bmain, ID *srcID, ID *dstID, ListBa * they will get picked up by the dependency system. * * \param C: Context pointer - for getting active data - * \param[in,out] ptr RNA pointer for property's datablock. May be modified as result of path remapping. + * \param[in,out] ptr: RNA pointer for property's datablock. + * May be modified as result of path remapping. * \param prop: RNA definition of property to add for * \return MEM_alloc'd string representing the path to the property from the given #PointerRNA */ @@ -670,7 +675,8 @@ char *BKE_animdata_driver_path_hack(bContext *C, /* Path Validation -------------------------------------------- */ -/* Check if a given RNA Path is valid, by tracing it from the given ID, and seeing if we can resolve it */ +/* Check if a given RNA Path is valid, by tracing it from the given ID, + * and seeing if we can resolve it. */ static bool check_rna_path_is_valid(ID *owner_id, const char *path) { PointerRNA id_ptr, ptr; @@ -766,7 +772,8 @@ static bool fcurves_path_rename_fix(ID *owner_id, fcu->rna_path = rna_path_rename_fix( owner_id, prefix, oldKey, newKey, fcu->rna_path, verify_paths); /* if path changed and the F-Curve is grouped, check if its group also needs renaming - * (i.e. F-Curve is first of a bone's F-Curves; hence renaming this should also trigger rename) */ + * (i.e. F-Curve is first of a bone's F-Curves; + * hence renaming this should also trigger rename) */ if (fcu->rna_path != old_path) { bActionGroup *agrp = fcu->grp; is_changed = true; @@ -1456,7 +1463,8 @@ KS_Path *BKE_keyingset_find_path(KeyingSet *ks, /* Defining Tools --------------------------- */ -/* Used to create a new 'custom' KeyingSet for the user, that will be automatically added to the stack */ +/* Used to create a new 'custom' KeyingSet for the user, + * that will be automatically added to the stack */ KeyingSet *BKE_keyingset_add( ListBase *list, const char idname[], const char name[], short flag, short keyingflag) { @@ -1471,8 +1479,8 @@ KeyingSet *BKE_keyingset_add( ks->flag = flag; ks->keyingflag = keyingflag; - ks->keyingoverride = - keyingflag; /* NOTE: assume that if one is set one way, the other should be too, so that it'll work */ + /* NOTE: assume that if one is set one way, the other should be too, so that it'll work */ + ks->keyingoverride = keyingflag; /* add KeyingSet to list */ BLI_addtail(list, ks); @@ -1824,31 +1832,50 @@ bool BKE_animsys_execute_fcurve(PointerRNA *ptr, FCurve *fcu, float curval) return ok; } +static bool animsys_construct_orig_pointer_rna(const PointerRNA *ptr, PointerRNA *ptr_orig) +{ + *ptr_orig = *ptr; + /* NOTE: nlastrip_evaluate_controls() creates PointerRNA with ID of NULL. Technically, this is + * not a valid pointer, but there are exceptions in various places of this file which handles + * such pointers. + * We do special trickery here as well, to quickly go from evaluated to original NlaStrip. */ + if (ptr->id.data == NULL) { + if (ptr->type != &RNA_NlaStrip) { + return false; + } + NlaStrip *strip = ((NlaStrip *)ptr_orig->data); + if (strip->orig_strip == NULL) { + return false; + } + ptr_orig->data = strip->orig_strip; + } + else { + ptr_orig->id.data = ((ID *)ptr_orig->id.data)->orig_id; + ptr_orig->data = ptr_orig->id.data; + } + return true; +} + static void animsys_write_orig_anim_rna(PointerRNA *ptr, const char *rna_path, int array_index, float value) { - /* Pointer is expected to be an ID pointer, if it's not -- we are doomed. - * - * NOTE: It is possible to have animation data on NLA strip, see T57360. - * TODO(sergey): Find solution for those cases. - */ - if (ptr->id.data == NULL) { + PointerRNA ptr_orig; + if (!animsys_construct_orig_pointer_rna(ptr, &ptr_orig)) { return; } - PointerRNA orig_ptr = *ptr; - orig_ptr.id.data = ((ID *)orig_ptr.id.data)->orig_id; - orig_ptr.data = orig_ptr.id.data; PathResolvedRNA orig_anim_rna; - /* TODO(sergey): Is there a faster way to get anim_rna of original ID? */ - if (animsys_store_rna_setting(&orig_ptr, rna_path, array_index, &orig_anim_rna)) { + /* TODO(sergey): Should be possible to cache resolved path in dependency graph somehow. */ + if (animsys_store_rna_setting(&ptr_orig, rna_path, array_index, &orig_anim_rna)) { animsys_write_rna_setting(&orig_anim_rna, value); } } -/* Evaluate all the F-Curves in the given list - * This performs a set of standard checks. If extra checks are required, separate code should be used +/** + * Evaluate all the F-Curves in the given list + * This performs a set of standard checks. If extra checks are required, + * separate code should be used. */ static void animsys_evaluate_fcurves(Depsgraph *depsgraph, PointerRNA *ptr, @@ -1898,9 +1925,8 @@ static void animsys_evaluate_drivers(PointerRNA *ptr, AnimData *adt, float ctime /* XXX driver recalc flag is not set yet by depsgraph! */ if ((driver) && !(driver->flag & DRIVER_FLAG_INVALID)) { /* evaluate this using values set already in other places - * NOTE: for 'layering' option later on, we should check if we should remove old value before adding - * new to only be done when drivers only changed */ - + * NOTE: for 'layering' option later on, we should check if we should remove old value + * before adding new to only be done when drivers only changed. */ PathResolvedRNA anim_rna; if (animsys_store_rna_setting(ptr, fcu->rna_path, fcu->array_index, &anim_rna)) { const float curval = calculate_fcurve(&anim_rna, fcu, ctime); @@ -1937,7 +1963,8 @@ static void action_idcode_patch_check(ID *id, bAction *act) /* the actual checks... hopefully not too much of a performance hit in the long run... */ if (act->idroot == 0) { - /* use the current root if not set already (i.e. newly created actions and actions from 2.50-2.57 builds) + /* use the current root if not set already + * (i.e. newly created actions and actions from 2.50-2.57 builds). * - this has problems if there are 2 users, and the first one encountered is the invalid one * in which case, the user will need to manually fix this (?) */ @@ -2067,9 +2094,9 @@ static void nlastrip_evaluate_controls(Depsgraph *depsgraph, NlaStrip *strip, fl strip->strip_time = nlastrip_get_frame(strip, ctime, NLATIME_CONVERT_EVAL); } - /* if user can control the evaluation time (using F-Curves), consider the option which allows this time to be clamped - * to lie within extents of the action-clip, so that a steady changing rate of progress through several cycles of the clip - * can be achieved easily + /* if user can control the evaluation time (using F-Curves), consider the option which allows + * this time to be clamped to lie within extents of the action-clip, so that a steady changing + * rate of progress through several cycles of the clip can be achieved easily. */ /* NOTE: if we add any more of these special cases, we better group them up nicely... */ if ((strip->flag & NLASTRIP_FLAG_USR_TIME) && (strip->flag & NLASTRIP_FLAG_USR_TIME_CYCLIC)) { @@ -2160,7 +2187,8 @@ NlaEvalStrip *nlastrips_ctime_get_strip( * - skip if no influence (i.e. same effect as muting the strip) * - negative influence is not supported yet... how would that be defined? */ - /* TODO: this sounds a bit hacky having a few isolated F-Curves stuck on some data it operates on... */ + /* TODO: this sounds a bit hacky having a few isolated F-Curves + * stuck on some data it operates on... */ nlastrip_evaluate_controls(depsgraph, estrip, ctime); if (estrip->influence <= 0.0f) { return NULL; @@ -2331,7 +2359,8 @@ static NlaEvalChannelSnapshot *nlaeval_snapshot_find_channel(NlaEvalSnapshot *sn return &nec->base_snapshot; } -/* Retrieve or create the channel value snapshot, copying from the other snapshot (or default values) */ +/* Retrieve or create the channel value snapshot, copying from the other snapshot + * (or default values) */ static NlaEvalChannelSnapshot *nlaeval_snapshot_ensure_channel(NlaEvalSnapshot *snapshot, NlaEvalChannel *nec) { @@ -2959,7 +2988,8 @@ static void nlaeval_snapshot_mix_and_free(NlaEvalData *nlaeval, } /* ---------------------- */ -/* F-Modifier stack joining/separation utilities - should we generalise these for BLI_listbase.h interface? */ +/* F-Modifier stack joining/separation utilities - + * should we generalize these for BLI_listbase.h interface? */ /* Temporarily join two lists of modifiers together, storing the result in a third list */ static void nlaeval_fmodifiers_join_stacks(ListBase *result, ListBase *list1, ListBase *list2) @@ -2979,8 +3009,9 @@ static void nlaeval_fmodifiers_join_stacks(ListBase *result, ListBase *list1, Li result->last = list1->last; } else { - /* list1 should be added first, and list2 second, with the endpoints of these being the endpoints for result - * - the original lists must be left unchanged though, as we need that fact for restoring + /* list1 should be added first, and list2 second, + * with the endpoints of these being the endpoints for result + * - the original lists must be left unchanged though, as we need that fact for restoring. */ result->first = list1->first; result->last = list2->last; @@ -3058,7 +3089,8 @@ static void nlastrip_evaluate_actionclip(PointerRNA *ptr, .influence = strip->influence, }; - /* evaluate all the F-Curves in the action, saving the relevant pointers to data that will need to be used */ + /* Evaluate all the F-Curves in the action, + * saving the relevant pointers to data that will need to be used. */ for (fcu = strip->act->curves.first; fcu; fcu = fcu->next) { float value = 0.0f; @@ -3071,18 +3103,20 @@ static void nlastrip_evaluate_actionclip(PointerRNA *ptr, } /* evaluate the F-Curve's value for the time given in the strip - * NOTE: we use the modified time here, since strip's F-Curve Modifiers are applied on top of this + * NOTE: we use the modified time here, since strip's F-Curve Modifiers + * are applied on top of this. */ value = evaluate_fcurve(fcu, evaltime); /* apply strip's F-Curve Modifiers on this value - * NOTE: we apply the strip's original evaluation time not the modified one (as per standard F-Curve eval) + * NOTE: we apply the strip's original evaluation time not the modified one + * (as per standard F-Curve eval) */ evaluate_value_fmodifiers(&storage, &tmp_modifiers, fcu, &value, strip->strip_time); - /* get an NLA evaluation channel to work with, and accumulate the evaluated value with the value(s) - * stored in this channel if it has been used already - */ + /* Get an NLA evaluation channel to work with, + * and accumulate the evaluated value with the value(s) + * stored in this channel if it has been used already. */ NlaEvalChannel *nec = nlaevalchan_verify(ptr, channels, fcu->rna_path); nlaeval_blend_value(&blend, nec, fcu->array_index, value); @@ -3208,10 +3242,13 @@ void nlastrip_evaluate(Depsgraph *depsgraph, { NlaStrip *strip = nes->strip; - /* to prevent potential infinite recursion problems (i.e. transition strip, beside meta strip containing a transition - * several levels deep inside it), we tag the current strip as being evaluated, and clear this when we leave + /* To prevent potential infinite recursion problems + * (i.e. transition strip, beside meta strip containing a transition + * several levels deep inside it), + * we tag the current strip as being evaluated, and clear this when we leave. */ - /* TODO: be careful with this flag, since some edit tools may be running and have set this while animplayback was running */ + /* TODO: be careful with this flag, since some edit tools may be running and have + * set this while animplayback was running */ if (strip->flag & NLASTRIP_FLAG_EDIT_TOUCHED) { return; } @@ -3365,9 +3402,10 @@ static void animsys_evaluate_nla_domain(PointerRNA *ptr, NlaEvalData *channels, /** * NLA Evaluation function - values are calculated and stored in temporary "NlaEvalChannels" * - * \param[out] echannels Evaluation channels with calculated values - * \param[out] r_context If not NULL, data about the currently edited strip is stored here and excluded from value calculation. - * \return false if NLA evaluation isn't actually applicable + * \param[out] echannels: Evaluation channels with calculated values + * \param[out] r_context: If not NULL, + * data about the currently edited strip is stored here and excluded from value calculation. + * \return false if NLA evaluation isn't actually applicable. */ static bool animsys_evaluate_nla(Depsgraph *depsgraph, NlaEvalData *echannels, @@ -3391,7 +3429,8 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, /* 1. get the stack of strips to evaluate at current time (influence calculated here) */ for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next, track_index++) { - /* stop here if tweaking is on and this strip is the tweaking track (it will be the first one that's 'disabled')... */ + /* stop here if tweaking is on and this strip is the tweaking track + * (it will be the first one that's 'disabled')... */ if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED)) { break; } @@ -3452,7 +3491,8 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, /* set settings of dummy NLA strip from AnimData settings */ dummy_strip->act = adt->action; - /* action range is calculated taking F-Modifiers into account (which making new strips doesn't do due to the troublesome nature of that) */ + /* action range is calculated taking F-Modifiers into account + * (which making new strips doesn't do due to the troublesome nature of that) */ calc_action_range(dummy_strip->act, &dummy_strip->actstart, &dummy_strip->actend, 1); dummy_strip->start = dummy_strip->actstart; dummy_strip->end = (IS_EQF(dummy_strip->actstart, dummy_strip->actend)) ? @@ -3469,14 +3509,16 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, dummy_strip->extendmode = adt->act_extendmode; } - /* Unless extendmode is Nothing (might be useful for flattening NLA evaluation), disable range. */ + /* Unless extendmode is Nothing (might be useful for flattening NLA evaluation), + * disable range. */ if (dummy_strip->extendmode != NLASTRIP_EXTEND_NOTHING) { dummy_strip->flag |= NLASTRIP_FLAG_NO_TIME_MAP; } dummy_strip->influence = adt->act_influence; - /* NOTE: must set this, or else the default setting overrides, and this setting doesn't work */ + /* NOTE: must set this, or else the default setting overrides, + * and this setting doesn't work. */ dummy_strip->flag |= NLASTRIP_FLAG_USR_INFLUENCE; } @@ -3486,7 +3528,8 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, } /* If computing the context for keyframing, store data there instead of the list. */ else { - /* The extend mode here effectively controls whether it is possible to keyframe beyond the ends. */ + /* The extend mode here effectively controls + * whether it is possible to key-frame beyond the ends. */ dummy_strip->extendmode = is_inplace_tweak ? NLASTRIP_EXTEND_NOTHING : NLASTRIP_EXTEND_HOLD; @@ -3513,7 +3556,8 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, return true; } - /* 2. for each strip, evaluate then accumulate on top of existing channels, but don't set values yet */ + /* 2. for each strip, evaluate then accumulate on top of existing channels, + * but don't set values yet. */ for (nes = estrips.first; nes; nes = nes->next) { nlastrip_evaluate(depsgraph, ptr, echannels, NULL, nes, &echannels->eval_snapshot); } @@ -3564,9 +3608,10 @@ static void animsys_calculate_nla(Depsgraph *depsgraph, * Prepare data necessary to compute correct keyframe values for NLA strips * with non-Replace mode or influence different from 1. * - * @param cache List used to cache contexts for reuse when keying multiple channels in one operation. - * @param ptr RNA pointer to the Object with the animation. - * @return Keyframing context, or NULL if not necessary. + * \param cache List used to cache contexts for reuse when keying + * multiple channels in one operation. + * \param ptr RNA pointer to the Object with the animation. + * \return Keyframing context, or NULL if not necessary. */ NlaKeyframingContext *BKE_animsys_get_nla_keyframing_context(struct ListBase *cache, struct Depsgraph *depsgraph, @@ -3607,13 +3652,14 @@ NlaKeyframingContext *BKE_animsys_get_nla_keyframing_context(struct ListBase *ca /** * Apply correction from the NLA context to the values about to be keyframed. * - * @param context Context to use (may be NULL). - * @param prop_ptr Property about to be keyframed. - * @param[in,out] values Array of property values to adjust. - * @param count Number of values in the array. - * @param index Index of the element about to be updated, or -1. - * @param[out] r_force_all Set to true if all channels must be inserted. May be NULL. - * @return False if correction fails due to a division by zero, or null r_force_all when all channels are required. + * \param context Context to use (may be NULL). + * \param prop_ptr Property about to be keyframed. + * \param[in,out] values Array of property values to adjust. + * \param count Number of values in the array. + * \param index Index of the element about to be updated, or -1. + * \param[out] r_force_all Set to true if all channels must be inserted. May be NULL. + * \return False if correction fails due to a division by zero, + * or null r_force_all when all channels are required. */ bool BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context, struct PointerRNA *prop_ptr, @@ -3757,17 +3803,21 @@ static void animsys_evaluate_overrides(PointerRNA *ptr, AnimData *adt) * 3) Drivers/expressions are evaluated on top of this, in an order where dependencies are * resolved nicely. * Note: it may be necessary to have some tools to handle the cases where some higher-level - * drivers are added and cause some problematic dependencies that didn't exist in the local levels... + * drivers are added and cause some problematic dependencies that + * didn't exist in the local levels... * * --------------< always executed >------------------ * * Maintenance of editability of settings (XXX): - * In order to ensure that settings that are animated can still be manipulated in the UI without requiring - * that keyframes are added to prevent these values from being overwritten, we use 'overrides'. + * - In order to ensure that settings that are animated can still be manipulated in the UI without + * requiring that keyframes are added to prevent these values from being overwritten, + * we use 'overrides'. * * Unresolved things: - * - Handling of multi-user settings (i.e. time-offset, group-instancing) -> big cache grids or nodal system? but stored where? - * - Multiple-block dependencies (i.e. drivers for settings are in both local and higher levels) -> split into separate lists? + * - Handling of multi-user settings (i.e. time-offset, group-instancing) -> big cache grids + * or nodal system? but stored where? + * - Multiple-block dependencies + * (i.e. drivers for settings are in both local and higher levels) -> split into separate lists? * * Current Status: * - Currently (as of September 2009), overrides we haven't needed to (fully) implement overrides. @@ -3856,10 +3906,10 @@ void BKE_animsys_evaluate_all_animation(Main *main, } /* macros for less typing - * - only evaluate animation data for id if it has users (and not just fake ones) - * - whether animdata exists is checked for by the evaluation function, though taking - * this outside of the function may make things slightly faster? - */ + * - only evaluate animation data for id if it has users (and not just fake ones) + * - whether animdata exists is checked for by the evaluation function, though taking + * this outside of the function may make things slightly faster? + */ #define EVAL_ANIM_IDS(first, aflag) \ for (id = first; id; id = id->next) { \ if (ID_REAL_USERS(id) > 0) { \ @@ -3870,11 +3920,11 @@ void BKE_animsys_evaluate_all_animation(Main *main, (void)0 /* another macro for the "embedded" nodetree cases - * - this is like EVAL_ANIM_IDS, but this handles the case "embedded nodetrees" - * (i.e. scene/material/texture->nodetree) which we need a special exception - * for, otherwise they'd get skipped - * - ntp = "node tree parent" = datablock where node tree stuff resides - */ + * - this is like EVAL_ANIM_IDS, but this handles the case "embedded nodetrees" + * (i.e. scene/material/texture->nodetree) which we need a special exception + * for, otherwise they'd get skipped + * - ntp = "node tree parent" = datablock where node tree stuff resides + */ #define EVAL_ANIM_NODETREE_IDS(first, NtId_Type, aflag) \ for (id = first; id; id = id->next) { \ if (ID_REAL_USERS(id) > 0) { \ @@ -4044,9 +4094,9 @@ void BKE_animsys_eval_driver(Depsgraph *depsgraph, /* XXX driver recalc flag is not set yet by depsgraph! */ if ((driver_orig) && !(driver_orig->flag & DRIVER_FLAG_INVALID)) { /* evaluate this using values set already in other places - * NOTE: for 'layering' option later on, we should check if we should remove old value before adding - * new to only be done when drivers only changed */ - //printf("\told val = %f\n", fcu->curval); + * NOTE: for 'layering' option later on, we should check if we should remove old value before + * adding new to only be done when drivers only changed */ + // printf("\told val = %f\n", fcu->curval); PathResolvedRNA anim_rna; if (animsys_store_rna_setting(&id_ptr, fcu->rna_path, fcu->array_index, &anim_rna)) { diff --git a/source/blender/blenkernel/intern/appdir.c b/source/blender/blenkernel/intern/appdir.c index 0986596f97c..2b4123c74e2 100644 --- a/source/blender/blenkernel/intern/appdir.c +++ b/source/blender/blenkernel/intern/appdir.c @@ -55,8 +55,9 @@ # ifdef WITH_BINRELOC # include "binreloc.h" # endif -# include <unistd.h> /* mkdtemp on OSX (and probably all *BSD?), not worth making specific check for this OS. */ -#endif /* WIN32 */ +/* mkdtemp on OSX (and probably all *BSD?), not worth making specific check for this OS. */ +# include <unistd.h> +#endif /* WIN32 */ /* local */ static CLG_LogRef LOG = {"bke.appdir"}; @@ -156,7 +157,7 @@ static bool test_path(char *targetpath, #ifdef PATH_DEBUG printf("\t%s missing: %s\n", __func__, targetpath); #endif - //targetpath[0] = '\0'; + // targetpath[0] = '\0'; return false; } } @@ -222,9 +223,11 @@ static bool get_path_local(char *targetpath, relfolder[0] = '\0'; } - /* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */ + /* Try EXECUTABLE_DIR/2.5x/folder_name - + * new default directory for local blender installed files. */ #ifdef __APPLE__ - /* due new codesign situation in OSX > 10.9.5 we must move the blender_version dir with contents to Resources */ + /* Due new codesign situation in OSX > 10.9.5 + * we must move the blender_version dir with contents to Resources. */ char osx_resourses[FILE_MAX]; BLI_snprintf(osx_resourses, sizeof(osx_resourses), "%s../Resources", bprogdir); /* Remove the '/../' added above. */ diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index 531c1795497..60446bf60b6 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -169,9 +169,33 @@ static void copy_bonechildren(Bone *bone_dst, } } +static void copy_bonechildren_custom_handles(Bone *bone_dst, bArmature *arm_dst, GHash **bone_hash) +{ + Bone *bone_dst_child; + + /* Lazily create the name -> bone hashtable. */ + if ((bone_dst->bbone_prev || bone_dst->bbone_next) && *bone_hash == NULL) { + *bone_hash = BKE_armature_bone_from_name_map(arm_dst); + } + + if (bone_dst->bbone_prev) { + bone_dst->bbone_prev = BLI_ghash_lookup(*bone_hash, bone_dst->bbone_prev->name); + } + if (bone_dst->bbone_next) { + bone_dst->bbone_next = BLI_ghash_lookup(*bone_hash, bone_dst->bbone_next->name); + } + + for (bone_dst_child = bone_dst->childbase.first; bone_dst_child; + bone_dst_child = bone_dst_child->next) { + copy_bonechildren_custom_handles(bone_dst_child, arm_dst, bone_hash); + } +} + /** - * Only copy internal data of Armature ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Armature ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -200,6 +224,17 @@ void BKE_armature_copy_data(Main *UNUSED(bmain), arm_dst->act_bone = bone_dst_act; + /* Fix custom handle references. */ + GHash *bone_hash = NULL; /* lazily created */ + + for (bone_dst = arm_dst->bonebase.first; bone_dst; bone_dst = bone_dst->next) { + copy_bonechildren_custom_handles(bone_dst, arm_dst, &bone_hash); + } + + if (bone_hash) { + BLI_ghash_free(bone_hash, NULL, NULL); + } + arm_dst->edbo = NULL; arm_dst->act_edbone = NULL; } @@ -463,7 +498,8 @@ static void equalize_cubic_bezier(const float control[4][3], r_t_points[final_segments] = 1.0f; } -/* Evaluate bezier position and tangent at a specific parameter value using the De Casteljau algorithm. */ +/* Evaluate bezier position and tangent at a specific parameter value + * using the De Casteljau algorithm. */ static void evaluate_cubic_bezier(const float control[4][3], float t, float r_pos[3], @@ -809,9 +845,10 @@ void BKE_pchan_bbone_handles_compute(const BBoneSplineParameters *param, *r_roll2 += param->roll2; /* Extra curve x / y */ - /* NOTE: Scale correction factors here are to compensate for some random floating-point glitches - * when scaling up the bone or it's parent by a factor of approximately 8.15/6, which results - * in the bone length getting scaled up too (from 1 to 8), causing the curve to flatten out. + /* NOTE: + * Scale correction factors here are to compensate for some random floating-point glitches + * when scaling up the bone or it's parent by a factor of approximately 8.15/6, which results + * in the bone length getting scaled up too (from 1 to 8), causing the curve to flatten out. */ const float xscale_correction = (param->do_scale) ? param->scale[0] : 1.0f; const float yscale_correction = (param->do_scale) ? param->scale[2] : 1.0f; @@ -1059,7 +1096,8 @@ void BKE_pchan_bbone_segments_cache_copy(bPoseChannel *pchan, bPoseChannel *pcha } } -/** Calculate index and blend factor for the two B-Bone segment nodes affecting the point at 0 <= pos <= 1. */ +/** Calculate index and blend factor for the two B-Bone segment nodes + * affecting the point at 0 <= pos <= 1. */ void BKE_pchan_bbone_deform_segment_index(const bPoseChannel *pchan, float pos, int *r_index, @@ -1255,6 +1293,211 @@ static void pchan_bone_deform(bPoseChannel *pchan, (*contrib) += weight; } +typedef struct ArmatureUserdata { + Object *armOb; + Object *target; + const Mesh *mesh; + float (*vertexCos)[3]; + float (*defMats)[3][3]; + float (*prevCos)[3]; + + bool use_envelope; + bool use_quaternion; + bool invert_vgroup; + bool use_dverts; + + int armature_def_nr; + + int target_totvert; + MDeformVert *dverts; + + int defbase_tot; + bPoseChannel **defnrToPC; + + float premat[4][4]; + float postmat[4][4]; +} ArmatureUserdata; + +static void armature_vert_task(void *__restrict userdata, + const int i, + const ParallelRangeTLS *__restrict UNUSED(tls)) +{ + const ArmatureUserdata *data = userdata; + float(*const vertexCos)[3] = data->vertexCos; + float(*const defMats)[3][3] = data->defMats; + float(*const prevCos)[3] = data->prevCos; + const bool use_envelope = data->use_envelope; + const bool use_quaternion = data->use_quaternion; + const bool use_dverts = data->use_dverts; + const int armature_def_nr = data->armature_def_nr; + + MDeformVert *dvert; + DualQuat sumdq, *dq = NULL; + bPoseChannel *pchan; + float *co, dco[3]; + float sumvec[3], summat[3][3]; + float *vec = NULL, (*smat)[3] = NULL; + float contrib = 0.0f; + float armature_weight = 1.0f; /* default to 1 if no overall def group */ + float prevco_weight = 1.0f; /* weight for optional cached vertexcos */ + + if (use_quaternion) { + memset(&sumdq, 0, sizeof(DualQuat)); + dq = &sumdq; + } + else { + sumvec[0] = sumvec[1] = sumvec[2] = 0.0f; + vec = sumvec; + + if (defMats) { + zero_m3(summat); + smat = summat; + } + } + + if (use_dverts || armature_def_nr != -1) { + if (data->mesh) { + BLI_assert(i < data->mesh->totvert); + dvert = data->mesh->dvert + i; + } + else if (data->dverts && i < data->target_totvert) { + dvert = data->dverts + i; + } + else { + dvert = NULL; + } + } + else { + dvert = NULL; + } + + if (armature_def_nr != -1 && dvert) { + armature_weight = defvert_find_weight(dvert, armature_def_nr); + + if (data->invert_vgroup) { + armature_weight = 1.0f - armature_weight; + } + + /* hackish: the blending factor can be used for blending with prevCos too */ + if (prevCos) { + prevco_weight = armature_weight; + armature_weight = 1.0f; + } + } + + /* check if there's any point in calculating for this vert */ + if (armature_weight == 0.0f) { + return; + } + + /* get the coord we work on */ + co = prevCos ? prevCos[i] : vertexCos[i]; + + /* Apply the object's matrix */ + mul_m4_v3(data->premat, co); + + if (use_dverts && dvert && dvert->totweight) { /* use weight groups ? */ + MDeformWeight *dw = dvert->dw; + int deformed = 0; + unsigned int j; + float acum_weight = 0; + for (j = dvert->totweight; j != 0; j--, dw++) { + const int index = dw->def_nr; + if (index >= 0 && index < data->defbase_tot && (pchan = data->defnrToPC[index])) { + float weight = dw->weight; + Bone *bone = pchan->bone; + + deformed = 1; + + if (bone && bone->flag & BONE_MULT_VG_ENV) { + weight *= distfactor_to_bone( + co, bone->arm_head, bone->arm_tail, bone->rad_head, bone->rad_tail, bone->dist); + } + + /* check limit of weight */ + if (data->target->type == OB_GPENCIL) { + if (acum_weight + weight >= 1.0f) { + weight = 1.0f - acum_weight; + } + acum_weight += weight; + } + + pchan_bone_deform(pchan, weight, vec, dq, smat, co, &contrib); + + /* if acumulated weight limit exceed, exit loop */ + if ((data->target->type == OB_GPENCIL) && (acum_weight >= 1.0f)) { + break; + } + } + } + /* if there are vertexgroups but not groups with bones + * (like for softbody groups) */ + if (deformed == 0 && use_envelope) { + for (pchan = data->armOb->pose->chanbase.first; pchan; pchan = pchan->next) { + if (!(pchan->bone->flag & BONE_NO_DEFORM)) { + contrib += dist_bone_deform(pchan, vec, dq, smat, co); + } + } + } + } + else if (use_envelope) { + for (pchan = data->armOb->pose->chanbase.first; pchan; pchan = pchan->next) { + if (!(pchan->bone->flag & BONE_NO_DEFORM)) { + contrib += dist_bone_deform(pchan, vec, dq, smat, co); + } + } + } + + /* actually should be EPSILON? weight values and contrib can be like 10e-39 small */ + if (contrib > 0.0001f) { + if (use_quaternion) { + normalize_dq(dq, contrib); + + if (armature_weight != 1.0f) { + copy_v3_v3(dco, co); + mul_v3m3_dq(dco, (defMats) ? summat : NULL, dq); + sub_v3_v3(dco, co); + mul_v3_fl(dco, armature_weight); + add_v3_v3(co, dco); + } + else { + mul_v3m3_dq(co, (defMats) ? summat : NULL, dq); + } + + smat = summat; + } + else { + mul_v3_fl(vec, armature_weight / contrib); + add_v3_v3v3(co, vec, co); + } + + if (defMats) { + float pre[3][3], post[3][3], tmpmat[3][3]; + + copy_m3_m4(pre, data->premat); + copy_m3_m4(post, data->postmat); + copy_m3_m3(tmpmat, defMats[i]); + + if (!use_quaternion) { /* quaternion already is scale corrected */ + mul_m3_fl(smat, armature_weight / contrib); + } + + mul_m3_series(defMats[i], post, smat, pre, tmpmat); + } + } + + /* always, check above code */ + mul_m4_v3(data->postmat, co); + + /* interpolate with previous modifier position using weight group */ + if (prevCos) { + float mw = 1.0f - prevco_weight; + vertexCos[i][0] = prevco_weight * vertexCos[i][0] + mw * co[0]; + vertexCos[i][1] = prevco_weight * vertexCos[i][1] + mw * co[1]; + vertexCos[i][2] = prevco_weight * vertexCos[i][2] + mw * co[2]; + } +} + void armature_deform_verts(Object *armOb, Object *target, const Mesh *mesh, @@ -1267,10 +1510,9 @@ void armature_deform_verts(Object *armOb, bGPDstroke *gps) { bArmature *arm = armOb->data; - bPoseChannel *pchan, **defnrToPC = NULL; + bPoseChannel **defnrToPC = NULL; MDeformVert *dverts = NULL; bDeformGroup *dg; - float obinv[4][4], premat[4][4], postmat[4][4]; const bool use_envelope = (deformflag & ARM_DEF_ENVELOPE) != 0; const bool use_quaternion = (deformflag & ARM_DEF_QUATERNION) != 0; const bool invert_vgroup = (deformflag & ARM_DEF_INVERT_VGROUP) != 0; @@ -1291,11 +1533,6 @@ void armature_deform_verts(Object *armOb, BLI_assert(0); } - invert_m4_m4(obinv, target->obmat); - copy_m4_m4(premat, target->obmat); - mul_m4_m4m4(postmat, obinv, armOb->obmat); - invert_m4_m4(premat, postmat); - /* get the def_nr for the overall armature vertex group if present */ armature_def_nr = defgroup_name_index(target, defgrp_name); @@ -1354,172 +1591,32 @@ void armature_deform_verts(Object *armOb, } } - for (i = 0; i < numVerts; i++) { - MDeformVert *dvert; - DualQuat sumdq, *dq = NULL; - float *co, dco[3]; - float sumvec[3], summat[3][3]; - float *vec = NULL, (*smat)[3] = NULL; - float contrib = 0.0f; - float armature_weight = 1.0f; /* default to 1 if no overall def group */ - float prevco_weight = 1.0f; /* weight for optional cached vertexcos */ - - if (use_quaternion) { - memset(&sumdq, 0, sizeof(DualQuat)); - dq = &sumdq; - } - else { - sumvec[0] = sumvec[1] = sumvec[2] = 0.0f; - vec = sumvec; - - if (defMats) { - zero_m3(summat); - smat = summat; - } - } - - if (use_dverts || armature_def_nr != -1) { - if (mesh) { - BLI_assert(i < mesh->totvert); - dvert = mesh->dvert + i; - } - else if (dverts && i < target_totvert) { - dvert = dverts + i; - } - else { - dvert = NULL; - } - } - else { - dvert = NULL; - } - - if (armature_def_nr != -1 && dvert) { - armature_weight = defvert_find_weight(dvert, armature_def_nr); - - if (invert_vgroup) { - armature_weight = 1.0f - armature_weight; - } - - /* hackish: the blending factor can be used for blending with prevCos too */ - if (prevCos) { - prevco_weight = armature_weight; - armature_weight = 1.0f; - } - } - - /* check if there's any point in calculating for this vert */ - if (armature_weight == 0.0f) { - continue; - } - - /* get the coord we work on */ - co = prevCos ? prevCos[i] : vertexCos[i]; - - /* Apply the object's matrix */ - mul_m4_v3(premat, co); - - if (use_dverts && dvert && dvert->totweight) { /* use weight groups ? */ - MDeformWeight *dw = dvert->dw; - int deformed = 0; - unsigned int j; - float acum_weight = 0; - for (j = dvert->totweight; j != 0; j--, dw++) { - const int index = dw->def_nr; - if (index >= 0 && index < defbase_tot && (pchan = defnrToPC[index])) { - float weight = dw->weight; - Bone *bone = pchan->bone; - - deformed = 1; - - if (bone && bone->flag & BONE_MULT_VG_ENV) { - weight *= distfactor_to_bone( - co, bone->arm_head, bone->arm_tail, bone->rad_head, bone->rad_tail, bone->dist); - } - - /* check limit of weight */ - if (target->type == OB_GPENCIL) { - if (acum_weight + weight >= 1.0f) { - weight = 1.0f - acum_weight; - } - acum_weight += weight; - } - - pchan_bone_deform(pchan, weight, vec, dq, smat, co, &contrib); - - /* if acumulated weight limit exceed, exit loop */ - if ((target->type == OB_GPENCIL) && (acum_weight >= 1.0f)) { - break; - } - } - } - /* if there are vertexgroups but not groups with bones - * (like for softbody groups) */ - if (deformed == 0 && use_envelope) { - for (pchan = armOb->pose->chanbase.first; pchan; pchan = pchan->next) { - if (!(pchan->bone->flag & BONE_NO_DEFORM)) { - contrib += dist_bone_deform(pchan, vec, dq, smat, co); - } - } - } - } - else if (use_envelope) { - for (pchan = armOb->pose->chanbase.first; pchan; pchan = pchan->next) { - if (!(pchan->bone->flag & BONE_NO_DEFORM)) { - contrib += dist_bone_deform(pchan, vec, dq, smat, co); - } - } - } - - /* actually should be EPSILON? weight values and contrib can be like 10e-39 small */ - if (contrib > 0.0001f) { - if (use_quaternion) { - normalize_dq(dq, contrib); - - if (armature_weight != 1.0f) { - copy_v3_v3(dco, co); - mul_v3m3_dq(dco, (defMats) ? summat : NULL, dq); - sub_v3_v3(dco, co); - mul_v3_fl(dco, armature_weight); - add_v3_v3(co, dco); - } - else { - mul_v3m3_dq(co, (defMats) ? summat : NULL, dq); - } - - smat = summat; - } - else { - mul_v3_fl(vec, armature_weight / contrib); - add_v3_v3v3(co, vec, co); - } - - if (defMats) { - float pre[3][3], post[3][3], tmpmat[3][3]; - - copy_m3_m4(pre, premat); - copy_m3_m4(post, postmat); - copy_m3_m3(tmpmat, defMats[i]); - - if (!use_quaternion) { /* quaternion already is scale corrected */ - mul_m3_fl(smat, armature_weight / contrib); - } + ArmatureUserdata data = {.armOb = armOb, + .target = target, + .mesh = mesh, + .vertexCos = vertexCos, + .defMats = defMats, + .prevCos = prevCos, + .use_envelope = use_envelope, + .use_quaternion = use_quaternion, + .invert_vgroup = invert_vgroup, + .use_dverts = use_dverts, + .armature_def_nr = armature_def_nr, + .target_totvert = target_totvert, + .dverts = dverts, + .defbase_tot = defbase_tot, + .defnrToPC = defnrToPC}; + + float obinv[4][4]; + invert_m4_m4(obinv, target->obmat); - mul_m3_series(defMats[i], post, smat, pre, tmpmat); - } - } + mul_m4_m4m4(data.postmat, obinv, armOb->obmat); + invert_m4_m4(data.premat, data.postmat); - /* always, check above code */ - mul_m4_v3(postmat, co); - - /* interpolate with previous modifier position using weight group */ - if (prevCos) { - float mw = 1.0f - prevco_weight; - vertexCos[i][0] = prevco_weight * vertexCos[i][0] + mw * co[0]; - vertexCos[i][1] = prevco_weight * vertexCos[i][1] + mw * co[1]; - vertexCos[i][2] = prevco_weight * vertexCos[i][2] + mw * co[2]; - } - } + ParallelRangeSettings settings; + BLI_parallel_range_settings_defaults(&settings); + settings.min_iter_per_thread = 32; + BLI_task_parallel_range(0, numVerts, &data, armature_vert_task, &settings); if (defnrToPC) { MEM_freeN(defnrToPC); @@ -1588,13 +1685,14 @@ void BKE_bone_offset_matrix_get(const Bone *bone, float offs_bone[4][4]) offs_bone[3][1] += bone->parent->length; } -/* Construct the matrices (rot/scale and loc) to apply the PoseChannels into the armature (object) space. +/* Construct the matrices (rot/scale and loc) + * to apply the PoseChannels into the armature (object) space. * I.e. (roughly) the "pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b)" in the * pose_mat(b)= pose_mat(b-1) * yoffs(b-1) * d_root(b) * bone_mat(b) * chan_mat(b) * ...function. * - * This allows to get the transformations of a bone in its object space, *before* constraints (and IK) - * get applied (used by pose evaluation code). + * This allows to get the transformations of a bone in its object space, + * *before* constraints (and IK) get applied (used by pose evaluation code). * And reverse: to find pchan transformations needed to place a bone at a given loc/rot/scale * in object space (used by interactive transform, and snapping code). * @@ -1695,7 +1793,8 @@ void BKE_bone_parent_transform_calc_from_matrices(int bone_flag, else if (bone_flag & (BONE_HINGE | BONE_NO_SCALE)) { mul_m4_m4m4(r_bpt->loc_mat, parent_pose_mat, offs_bone); } - /* Else (i.e. default, usual case), just use the same matrix for rotation/scaling, and location. */ + /* Else (i.e. default, usual case), + * just use the same matrix for rotation/scaling, and location. */ else { copy_m4_m4(r_bpt->loc_mat, r_bpt->rotscale_mat); } @@ -1833,6 +1932,33 @@ void BKE_pchan_mat3_to_rot(bPoseChannel *pchan, float mat[3][3], bool use_compat } /** + * Same as #BKE_object_rot_to_mat3(). + */ +void BKE_pchan_rot_to_mat3(const bPoseChannel *pchan, float mat[3][3]) +{ + /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ + if (pchan->rotmode > 0) { + /* euler rotations (will cause gimble lock, + * but this can be alleviated a bit with rotation orders) */ + eulO_to_mat3(mat, pchan->eul, pchan->rotmode); + } + else if (pchan->rotmode == ROT_MODE_AXISANGLE) { + /* axis-angle - not really that great for 3D-changing orientations */ + axis_angle_to_mat3(mat, pchan->rotAxis, pchan->rotAngle); + } + else { + /* quats are normalized before use to eliminate scaling issues */ + float quat[4]; + + /* NOTE: we now don't normalize the stored values anymore, + * since this was kindof evil in some cases but if this proves to be too problematic, + * switch back to the old system of operating directly on the stored copy. */ + normalize_qt_qt(quat, pchan->quat); + quat_to_mat3(mat, quat); + } +} + +/** * Apply a 4x4 matrix to the pose bone, * similar to #BKE_object_apply_mat4(). */ @@ -1902,7 +2028,8 @@ void BKE_rotMode_change_values( quat_to_axis_angle(axis, angle, quat); } - /* when converting to axis-angle, we need a special exception for the case when there is no axis */ + /* When converting to axis-angle, + * we need a special exception for the case when there is no axis. */ if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) { /* for now, rotate around y-axis then (so that it simply becomes the roll) */ axis[1] = 1.0f; @@ -1957,50 +2084,72 @@ void mat3_vec_to_roll(const float mat[3][3], const float vec[3], float *r_roll) } /* Calculates the rest matrix of a bone based on its vector and a roll around that vector. */ -/* Given v = (v.x, v.y, v.z) our (normalized) bone vector, we want the rotation matrix M - * from the Y axis (so that M * (0, 1, 0) = v). - * -> The rotation axis a lays on XZ plane, and it is orthonormal to v, hence to the projection of v onto XZ plane. - * -> a = (v.z, 0, -v.x) +/** + * Given `v = (v.x, v.y, v.z)` our (normalized) bone vector, we want the rotation matrix M + * from the Y axis (so that `M * (0, 1, 0) = v`). + * - The rotation axis a lays on XZ plane, and it is orthonormal to v, + * hence to the projection of v onto XZ plane. + * - `a = (v.z, 0, -v.x)` + * * We know a is eigenvector of M (so M * a = a). - * Finally, we have w, such that M * w = (0, 1, 0) (i.e. the vector that will be aligned with Y axis once transformed). + * Finally, we have w, such that M * w = (0, 1, 0) + * (i.e. the vector that will be aligned with Y axis once transformed). * We know w is symmetric to v by the Y axis. - * -> w = (-v.x, v.y, -v.z) + * - `w = (-v.x, v.y, -v.z)` * * Solving this, we get (x, y and z being the components of v): + * <pre> * ┌ (x^2 * y + z^2) / (x^2 + z^2), x, x * z * (y - 1) / (x^2 + z^2) ┐ * M = │ x * (y^2 - 1) / (x^2 + z^2), y, z * (y^2 - 1) / (x^2 + z^2) │ * └ x * z * (y - 1) / (x^2 + z^2), z, (x^2 + z^2 * y) / (x^2 + z^2) ┘ + * </pre> * - * This is stable as long as v (the bone) is not too much aligned with +/-Y (i.e. x and z components - * are not too close to 0). + * This is stable as long as v (the bone) is not too much aligned with +/-Y + * (i.e. x and z components are not too close to 0). + * + * Since v is normalized, we have `x^2 + y^2 + z^2 = 1`, + * hence `x^2 + z^2 = 1 - y^2 = (1 - y)(1 + y)`. * - * Since v is normalized, we have x^2 + y^2 + z^2 = 1, hence x^2 + z^2 = 1 - y^2 = (1 - y)(1 + y). * This allows to simplifies M like this: + * <pre> * ┌ 1 - x^2 / (1 + y), x, -x * z / (1 + y) ┐ * M = │ -x, y, -z │ * └ -x * z / (1 + y), z, 1 - z^2 / (1 + y) ┘ + * </pre> * - * Written this way, we see the case v = +Y is no more a singularity. The only one remaining is the bone being - * aligned with -Y. + * Written this way, we see the case v = +Y is no more a singularity. + * The only one + * remaining is the bone being aligned with -Y. * - * Let's handle the asymptotic behavior when bone vector is reaching the limit of y = -1. Each of the four corner - * elements can vary from -1 to 1, depending on the axis a chosen for doing the rotation. And the "rotation" here - * is in fact established by mirroring XZ plane by that given axis, then inversing the Y-axis. - * For sufficiently small x and z, and with y approaching -1, all elements but the four corner ones of M - * will degenerate. So let's now focus on these corner elements. + * Let's handle + * the asymptotic behavior when bone vector is reaching the limit of y = -1. + * Each of the four corner elements can vary from -1 to 1, + * depending on the axis a chosen for doing the rotation. + * And the "rotation" here is in fact established by mirroring XZ plane by that given axis, + * then inversing the Y-axis. + * For sufficiently small x and z, and with y approaching -1, + * all elements but the four corner ones of M will degenerate. + * So let's now focus on these corner elements. * - * We rewrite M so that it only contains its four corner elements, and combine the 1 / (1 + y) factor: + * We rewrite M so that it only contains its four corner elements, + * and combine the `1 / (1 + y)` factor: + * <pre> * ┌ 1 + y - x^2, -x * z ┐ * M* = 1 / (1 + y) * │ │ * └ -x * z, 1 + y - z^2 ┘ + * </pre> + * + * When y is close to -1, computing 1 / (1 + y) will cause severe numerical instability, + * so we ignore it and normalize M instead. + * We know `y^2 = 1 - (x^2 + z^2)`, and `y < 0`, hence `y = -sqrt(1 - (x^2 + z^2))`. * - * When y is close to -1, computing 1 / (1 + y) will cause severe numerical instability, so we ignore it and - * normalize M instead. We know y^2 = 1 - (x^2 + z^2), and y < 0, hence y = -sqrt(1 - (x^2 + z^2)). * Since x and z are both close to 0, we apply the binomial expansion to the first order: - * y = -sqrt(1 - (x^2 + z^2)) = -1 + (x^2 + z^2) / 2. Which gives: + * `y = -sqrt(1 - (x^2 + z^2)) = -1 + (x^2 + z^2) / 2`. Which gives: + * <pre> * ┌ z^2 - x^2, -2 * x * z ┐ * M* = 1 / (x^2 + z^2) * │ │ * └ -2 * x * z, x^2 - z^2 ┘ + * </pre> */ void vec_roll_to_mat3_normalized(const float nor[3], const float roll, float mat[3][3]) { @@ -2200,13 +2349,14 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected } } - /* constraints - proxy constraints are flushed... local ones are added after - * 1. extract constraints not from proxy (CONSTRAINT_PROXY_LOCAL) from pchan's constraints - * 2. copy proxy-pchan's constraints on-to new - * 3. add extracted local constraints back on top + /* Constraints - proxy constraints are flushed... local ones are added after + * 1: extract constraints not from proxy (CONSTRAINT_PROXY_LOCAL) from pchan's constraints. + * 2: copy proxy-pchan's constraints on-to new. + * 3: add extracted local constraints back on top. * - * Note for BKE_constraints_copy: when copying constraints, disable 'do_extern' otherwise - * we get the libs direct linked in this blend. + * Note for BKE_constraints_copy: + * When copying constraints, disable 'do_extern' otherwise + * we get the libs direct linked in this blend. */ BKE_constraints_proxylocal_extract(&proxylocal_constraints, &pchan->constraints); BKE_constraints_copy(&pchanw.constraints, &pchanp->constraints, false); @@ -2295,7 +2445,8 @@ static int rebuild_pose_bone(bPose *pose, Bone *bone, bPoseChannel *parchan, int } /** - * Clear pointers of object's pose (needed in remap case, since we cannot always wait for a complete pose rebuild). + * Clear pointers of object's pose + * (needed in remap case, since we cannot always wait for a complete pose rebuild). */ void BKE_pose_clear_pointers(bPose *pose) { @@ -2381,7 +2532,8 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ /* synchronize protected layers with proxy */ /* HACK! To preserve 2.7x behavior that you always can pose even locked bones, * do not do any restoration if this is a COW temp copy! */ - /* Switched back to just NO_MAIN tag, for some reasons (c) using COW tag was working this morning, but not anymore... */ + /* Switched back to just NO_MAIN tag, for some reasons (c) + * using COW tag was working this morning, but not anymore... */ if (ob->proxy != NULL && (ob->id.tag & LIB_TAG_NO_MAIN) == 0) { BKE_object_copy_proxy_drivers(ob, ob->proxy); pose_proxy_synchronize(ob, ob->proxy, arm->layer_protected); @@ -2392,7 +2544,8 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ pose->flag &= ~POSE_RECALC; pose->flag |= POSE_WAS_REBUILT; - /* Rebuilding poses forces us to also rebuild the dependency graph, since there is one node per pose/bone... */ + /* Rebuilding poses forces us to also rebuild the dependency graph, + * since there is one node per pose/bone. */ if (bmain != NULL) { DEG_relations_tag_update(bmain); } @@ -2401,7 +2554,7 @@ void BKE_pose_rebuild(Main *bmain, Object *ob, bArmature *arm, const bool do_id_ /* ********************** THE POSE SOLVER ******************* */ /* loc/rot/size to given mat4 */ -void BKE_pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) +void BKE_pchan_to_mat4(const bPoseChannel *pchan, float chan_mat[4][4]) { float smat[3][3]; float rmat[3][3]; @@ -2410,26 +2563,8 @@ void BKE_pchan_to_mat4(bPoseChannel *pchan, float chan_mat[4][4]) /* get scaling matrix */ size_to_mat3(smat, pchan->size); - /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ - if (pchan->rotmode > 0) { - /* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */ - eulO_to_mat3(rmat, pchan->eul, pchan->rotmode); - } - else if (pchan->rotmode == ROT_MODE_AXISANGLE) { - /* axis-angle - not really that great for 3D-changing orientations */ - axis_angle_to_mat3(rmat, pchan->rotAxis, pchan->rotAngle); - } - else { - /* quats are normalized before use to eliminate scaling issues */ - float quat[4]; - - /* NOTE: we now don't normalize the stored values anymore, since this was kindof evil in some cases - * but if this proves to be too problematic, switch back to the old system of operating directly on - * the stored copy - */ - normalize_qt_qt(quat, pchan->quat); - quat_to_mat3(rmat, quat); - } + /* get rotation matrix */ + BKE_pchan_rot_to_mat3(pchan, rmat); /* calculate matrix of bone (as 3x3 matrix, but then copy the 4x4) */ mul_m3_m3m3(tmat, rmat, smat); @@ -2548,7 +2683,8 @@ void BKE_pose_where_is(struct Depsgraph *depsgraph, Scene *scene, Object *ob) return; } if ((ob->pose == NULL) || (ob->pose->flag & POSE_RECALC)) { - /* WARNING! passing NULL bmain here means we won't tag depsgraph's as dirty - hopefully this is OK. */ + /* WARNING! passing NULL bmain here means we won't tag depsgraph's as dirty - + * hopefully this is OK. */ BKE_pose_rebuild(NULL, ob, arm, true); } @@ -2615,7 +2751,8 @@ static int minmax_armature(Object *ob, float r_min[3], float r_max[3]) { bPoseChannel *pchan; - /* For now, we assume BKE_pose_where_is has already been called (hence we have valid data in pachan). */ + /* For now, we assume BKE_pose_where_is has already been called + * (hence we have valid data in pachan). */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { minmax_v3v3_v3(r_min, r_max, pchan->pose_head); minmax_v3v3_v3(r_min, r_max, pchan->pose_tail); diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c index 5af818b9a91..c71c2dc86cf 100644 --- a/source/blender/blenkernel/intern/armature_update.c +++ b/source/blender/blenkernel/intern/armature_update.c @@ -165,7 +165,8 @@ static void splineik_init_tree_from_pchan(Scene *UNUSED(scene), CLAMP_MIN(ikData->points[segcount], 0.0f); /* make a new Spline-IK chain, and store it in the IK chains */ - /* TODO: we should check if there is already an IK chain on this, since that would take precedence... */ + /* TODO: we should check if there is already an IK chain on this, + * since that would take precedence... */ { /* make new tree */ tSplineIK_Tree *tree = MEM_callocN(sizeof(tSplineIK_Tree), "SplineIK Tree"); @@ -199,7 +200,8 @@ static void splineik_init_tree(Scene *scene, Object *ob, float UNUSED(ctime)) { bPoseChannel *pchan; - /* find the tips of Spline IK chains, which are simply the bones which have been tagged as such */ + /* find the tips of Spline IK chains, + * which are simply the bones which have been tagged as such */ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { if (pchan->constflag & PCHAN_HAS_SPLINEIK) { splineik_init_tree_from_pchan(scene, ob, pchan); @@ -330,9 +332,9 @@ static void splineik_evaluate_bone( } } - /* step 2: determine the implied transform from these endpoints - * - splineVec: the vector direction that the spline applies on the bone - * - scaleFac: the factor that the bone length is scaled by to get the desired amount + /* Step 2: determine the implied transform from these endpoints. + * - splineVec: the vector direction that the spline applies on the bone. + * - scaleFac: the factor that the bone length is scaled by to get the desired amount. */ sub_v3_v3v3(splineVec, poseTail, poseHead); scaleFac = len_v3(splineVec) / pchan->bone->length; @@ -340,8 +342,10 @@ static void splineik_evaluate_bone( /* Adjust the scale factor towards the neutral state when rolling off the curve end. */ scaleFac = interpf(scaleFac, baseScale, tailBlendFac); - /* step 3: compute the shortest rotation needed to map from the bone rotation to the current axis - * - this uses the same method as is used for the Damped Track Constraint (see the code there for details) + /* Step 3: compute the shortest rotation needed + * to map from the bone rotation to the current axis. + * - this uses the same method as is used for the Damped Track Constraint + * (see the code there for details). */ { float dmat[3][3], rmat[3][3]; @@ -353,7 +357,8 @@ static void splineik_evaluate_bone( mul_m3_m4m4(basePoseMat, state->locrot_offset, pchan->pose_mat); normalize_m3_m3(rmat, basePoseMat); - /* also, normalize the orientation imposed by the bone, now that we've extracted the scale factor */ + /* Also, normalize the orientation imposed by the bone, + * now that we've extracted the scale factor. */ normalize_v3(splineVec); /* calculate smallest axis-angle rotation necessary for getting from the @@ -375,12 +380,12 @@ static void splineik_evaluate_bone( */ axis_angle_to_mat3(dmat, raxis, rangle); - /* combine these rotations so that the y-axis of the bone is now aligned as the spline dictates, - * while still maintaining roll control from the existing bone animation - */ + /* Combine these rotations so that the y-axis of the bone is now aligned as the + * spline dictates, while still maintaining roll control from the existing bone animation. */ mul_m3_m3m3(poseMat, dmat, rmat); - normalize_m3( - poseMat); /* attempt to reduce shearing, though I doubt this'll really help too much now... */ + + /* attempt to reduce shearing, though I doubt this'll really help too much now... */ + normalize_m3(poseMat); mul_m3_m3m3(basePoseMat, dmat, basePoseMat); @@ -539,7 +544,8 @@ static void splineik_execute_tree( while ((tree = pchan_root->siktree.first) != NULL) { int i; - /* Firstly, calculate the bone matrix the standard way, since this is needed for roll control. */ + /* Firstly, calculate the bone matrix the standard way, + * since this is needed for roll control. */ for (i = tree->chainlen - 1; i >= 0; i--) { BKE_pose_where_is_bone(depsgraph, scene, ob, tree->chain[i], ctime, 1); } @@ -549,8 +555,8 @@ static void splineik_execute_tree( if (splineik_evaluate_init(tree, &state)) { /* Walk over each bone in the chain, calculating the effects of spline IK - * - the chain is traversed in the opposite order to storage order (i.e. parent to children) - * so that dependencies are correct + * - the chain is traversed in the opposite order to storage order (i.e. parent to children) + * so that dependencies are correct */ for (i = tree->chainlen - 1; i >= 0; i--) { bPoseChannel *pchan = tree->chain[i]; diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 789d7a6a05d..48b271cf277 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -75,7 +75,9 @@ void BKE_blender_free(void) { /* samples are in a global list..., also sets G_MAIN->sound->sample NULL */ - BKE_studiolight_free(); /* needs to run before main free as wm is still referenced for icons preview jobs */ + /* Needs to run before main free as wm is still referenced for icons preview jobs. */ + BKE_studiolight_free(); + BKE_main_free(G_MAIN); G_MAIN = NULL; @@ -95,7 +97,6 @@ void BKE_blender_free(void) BLI_callback_global_finalize(); - BKE_sequencer_cache_destruct(); IMB_moviecache_destruct(); free_nodesystem(); diff --git a/source/blender/blenkernel/intern/blender_copybuffer.c b/source/blender/blenkernel/intern/blender_copybuffer.c index c801c1780c8..32c6f74dc2d 100644 --- a/source/blender/blenkernel/intern/blender_copybuffer.c +++ b/source/blender/blenkernel/intern/blender_copybuffer.c @@ -110,7 +110,8 @@ bool BKE_copybuffer_read(Main *bmain_dst, } /** - * \return Number of IDs directly pasted from the buffer (does not includes indirectly pulled out ones). + * \return Number of IDs directly pasted from the buffer + * (does not includes indirectly pulled out ones). */ int BKE_copybuffer_paste(bContext *C, const char *libname, diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index 383d8e6bf61..d1a3045a829 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -152,7 +152,8 @@ static void setup_app_data(bContext *C, /* no load screens? */ if (mode != LOAD_UI) { /* Logic for 'track_undo_scene' is to keep using the scene which the active screen has, - * as long as the scene associated with the undo operation is visible in one of the open windows. + * as long as the scene associated with the undo operation is visible + * in one of the open windows. * * - 'curscreen->scene' - scene the user is currently looking at. * - 'bfd->curscene' - scene undo-step was created in. diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c index fc3e12accea..becef327fab 100644 --- a/source/blender/blenkernel/intern/boids.c +++ b/source/blender/blenkernel/intern/boids.c @@ -230,7 +230,7 @@ static int rule_avoid_collision(BoidRule *rule, int n, neighbors = 0, nearest = 0; int ret = 0; - //check deflector objects first + // check deflector objects first if (acbr->options & BRULE_ACOLL_WITH_DEFLECTORS && bbd->sim->colliders) { ParticleCollision col; BVHTreeRayHit hit; @@ -292,7 +292,7 @@ static int rule_avoid_collision(BoidRule *rule, } } - //check boids in own system + // check boids in own system if (acbr->options & BRULE_ACOLL_WITH_BOIDS) { neighbors = BLI_kdtree_3d_range_search_with_len_squared_cb(bbd->sim->psys->tree, pa->prev_state.co, @@ -820,11 +820,11 @@ static boid_rule_cb boid_rules[] = { rule_follow_leader, rule_average_speed, rule_fight, - //rule_help, - //rule_protect, - //rule_hide, - //rule_follow_path, - //rule_follow_wall, + // rule_help, + // rule_protect, + // rule_hide, + // rule_follow_path, + // rule_follow_wall, }; static void set_boid_values(BoidValues *val, BoidSettings *boids, ParticleData *pa) @@ -1069,7 +1069,7 @@ static BoidState *get_boid_state(BoidSettings *boids, ParticleData *pa) return state; } -//static int boid_condition_is_true(BoidCondition *cond) +// static int boid_condition_is_true(BoidCondition *cond) //{ // /* TODO */ // return 0; @@ -1085,7 +1085,7 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) BoidParticle *bpa = pa->boid; ParticleSystem *psys = bbd->sim->psys; int rand; - //BoidCondition *cond; + // BoidCondition *cond; if (bpa->data.health <= 0.0f) { pa->alive = PARS_DYING; @@ -1093,9 +1093,9 @@ void boid_brain(BoidBrainData *bbd, int p, ParticleData *pa) return; } - //planned for near future - //cond = state->conditions.first; - //for (; cond; cond=cond->next) { + // planned for near future + // cond = state->conditions.first; + // for (; cond; cond=cond->next) { // if (boid_condition_is_true(cond)) { // pa->boid->state_id = cond->state_id; // state = get_boid_state(boids, pa); @@ -1420,7 +1420,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) madd_v3_v3fl(pa->state.vel, acc, dtime); - //if (bpa->data.mode != eBoidMode_InAir) + // if (bpa->data.mode != eBoidMode_InAir) bpa->ground = boid_find_ground(bbd, pa, ground_co, ground_nor); /* change modes, constrain movement & keep track of down vector */ @@ -1506,20 +1506,20 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa) } case eBoidMode_Climbing: { boid_climb(boids, pa, ground_co, ground_nor); - //float nor[3]; - //copy_v3_v3(nor, ground_nor); + // float nor[3]; + // copy_v3_v3(nor, ground_nor); ///* gather apparent gravity to r_ve */ - //madd_v3_v3fl(pa->r_ve, ground_nor, -1.0); - //normalize_v3(pa->r_ve); + // madd_v3_v3fl(pa->r_ve, ground_nor, -1.0); + // normalize_v3(pa->r_ve); ///* raise boid it's size from surface */ - //mul_v3_fl(nor, pa->size * boids->height); - //add_v3_v3v3(pa->state.co, ground_co, nor); + // mul_v3_fl(nor, pa->size * boids->height); + // add_v3_v3v3(pa->state.co, ground_co, nor); ///* remove normal component from velocity */ - //project_v3_v3v3(v, pa->state.vel, ground_nor); - //sub_v3_v3v3(pa->state.vel, pa->state.vel, v); + // project_v3_v3v3(v, pa->state.vel, ground_nor); + // sub_v3_v3v3(pa->state.vel, pa->state.vel, v); break; } case eBoidMode_OnLand: { diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index dcca6e2bf84..e28f1fc566f 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -148,7 +148,8 @@ void BKE_brush_init(Brush *brush) } /** - * \note Resulting brush will have two users: one as a fake user, another is assumed to be used by the caller. + * \note Resulting brush will have two users: one as a fake user, + * another is assumed to be used by the caller. */ Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode) { @@ -584,8 +585,10 @@ struct Brush *BKE_brush_first_search(struct Main *bmain, const eObjectMode ob_mo } /** - * Only copy internal data of Brush ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Brush ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/bvhutils.c b/source/blender/blenkernel/intern/bvhutils.c index ab7baf6ce7a..8600d60c5c6 100644 --- a/source/blender/blenkernel/intern/bvhutils.c +++ b/source/blender/blenkernel/intern/bvhutils.c @@ -568,7 +568,8 @@ BVHTree *bvhtree_from_editmesh_verts(BVHTreeFromEditMesh *data, * Builds a bvh tree where nodes are the given vertices (note: does not copy given mverts!). * \param vert_allocated: if true, vert freeing will be done when freeing data. * \param verts_mask: if not null, true elements give which vert to add to BVH tree. - * \param verts_num_active: if >= 0, number of active verts to add to BVH tree (else will be computed from mask). + * \param verts_num_active: if >= 0, number of active verts to add to BVH tree + * (else will be computed from mask). */ BVHTree *bvhtree_from_mesh_verts_ex(BVHTreeFromMesh *data, const MVert *vert, @@ -758,7 +759,8 @@ BVHTree *bvhtree_from_editmesh_edges(BVHTreeFromEditMesh *data, * \param vert, vert_allocated: if true, elem freeing will be done when freeing data. * \param edge, edge_allocated: if true, elem freeing will be done when freeing data. * \param edges_mask: if not null, true elements give which vert to add to BVH tree. - * \param edges_num_active: if >= 0, number of active edges to add to BVH tree (else will be computed from mask). + * \param edges_num_active: if >= 0, number of active edges to add to BVH tree + * (else will be computed from mask). */ BVHTree *bvhtree_from_mesh_edges_ex(BVHTreeFromMesh *data, const MVert *vert, @@ -860,11 +862,13 @@ static void bvhtree_from_mesh_faces_setup_data(BVHTreeFromMesh *data, } /** - * Builds a bvh tree where nodes are the given tessellated faces (note: does not copy given mfaces!). + * Builds a bvh tree where nodes are the given tessellated faces + * (note: does not copy given mfaces!). * \param vert_allocated: if true, vert freeing will be done when freeing data. * \param face_allocated: if true, face freeing will be done when freeing data. * \param faces_mask: if not null, true elements give which faces to add to BVH tree. - * \param faces_num_active: if >= 0, number of active faces to add to BVH tree (else will be computed from mask). + * \param faces_num_active: if >= 0, number of active faces to add to BVH tree + * (else will be computed from mask). */ BVHTree *bvhtree_from_mesh_faces_ex(BVHTreeFromMesh *data, const MVert *vert, diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 4fe8cabde65..44e951a43da 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -21,18 +21,21 @@ * \ingroup bke */ +#include <string.h> + #include "DNA_anim_types.h" #include "DNA_cachefile_types.h" #include "DNA_constraint_types.h" #include "DNA_object_types.h" #include "DNA_scene_types.h" +#include "BLI_utildefines.h" #include "BLI_fileops.h" +#include "BLI_ghash.h" #include "BLI_listbase.h" #include "BLI_path_util.h" #include "BLI_string.h" #include "BLI_threads.h" -#include "BLI_utildefines.h" #include "BKE_animsys.h" #include "BKE_cachefile.h" @@ -41,10 +44,13 @@ #include "BKE_modifier.h" #include "BKE_scene.h" +#include "DEG_depsgraph_query.h" + #ifdef WITH_ALEMBIC # include "ABC_alembic.h" #endif +/* TODO: make this per cache file to avoid global locks. */ static SpinLock spin; void BKE_cachefiles_init(void) @@ -57,6 +63,94 @@ void BKE_cachefiles_exit(void) BLI_spin_end(&spin); } +void BKE_cachefile_reader_open(CacheFile *cache_file, + struct CacheReader **reader, + Object *object, + const char *object_path) +{ +#ifdef WITH_ALEMBIC + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); + + if (cache_file->handle == NULL) { + return; + } + + /* Open Alembic cache reader. */ + *reader = CacheReader_open_alembic_object(cache_file->handle, *reader, object, object_path); + + /* Multiple modifiers and constraints can call this function concurrently. */ + BLI_spin_lock(&spin); + if (*reader) { + /* Register in set so we can free it when the cache file changes. */ + if (cache_file->handle_readers == NULL) { + cache_file->handle_readers = BLI_gset_ptr_new("CacheFile.handle_readers"); + } + BLI_gset_reinsert(cache_file->handle_readers, reader, NULL); + } + else if (cache_file->handle_readers) { + /* Remove in case CacheReader_open_alembic_object free the existing reader. */ + BLI_gset_remove(cache_file->handle_readers, reader, NULL); + } + BLI_spin_unlock(&spin); +#else + UNUSED_VARS(cache_file, reader, object, object_path); +#endif +} + +void BKE_cachefile_reader_free(CacheFile *cache_file, struct CacheReader **reader) +{ +#ifdef WITH_ALEMBIC + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); + + if (*reader != NULL) { + CacheReader_free(*reader); + *reader = NULL; + + /* Multiple modifiers and constraints can call this function concurrently. */ + BLI_spin_lock(&spin); + if (cache_file->handle_readers) { + BLI_gset_remove(cache_file->handle_readers, reader, NULL); + } + BLI_spin_unlock(&spin); + } +#else + UNUSED_VARS(cache_file, reader); +#endif +} + +static void cachefile_handle_free(CacheFile *cache_file) +{ +#ifdef WITH_ALEMBIC + /* Free readers in all modifiers and constraints that use the handle, before + * we free the handle itself. */ + BLI_spin_lock(&spin); + if (cache_file->handle_readers) { + GSetIterator gs_iter; + GSET_ITER (gs_iter, cache_file->handle_readers) { + struct CacheReader **reader = BLI_gsetIterator_getKey(&gs_iter); + if (*reader != NULL) { + CacheReader_free(*reader); + *reader = NULL; + } + } + + BLI_gset_free(cache_file->handle_readers, NULL); + cache_file->handle_readers = NULL; + } + BLI_spin_unlock(&spin); + + /* Free handle. */ + if (cache_file->handle) { + ABC_free_handle(cache_file->handle); + cache_file->handle = NULL; + } + + cache_file->handle_filepath[0] = '\0'; +#else + UNUSED_VARS(cache_file); +#endif +} + void *BKE_cachefile_add(Main *bmain, const char *name) { CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name, 0); @@ -68,43 +162,31 @@ void *BKE_cachefile_add(Main *bmain, const char *name) void BKE_cachefile_init(CacheFile *cache_file) { - cache_file->handle = NULL; cache_file->filepath[0] = '\0'; cache_file->override_frame = false; cache_file->frame = 0.0f; cache_file->is_sequence = false; cache_file->scale = 1.0f; - cache_file->handle_mutex = BLI_mutex_alloc(); BLI_listbase_clear(&cache_file->object_paths); + + cache_file->handle = NULL; + cache_file->handle_filepath[0] = '\0'; + cache_file->handle_readers = NULL; } /** Free (or release) any data used by this cachefile (does not free the cachefile itself). */ void BKE_cachefile_free(CacheFile *cache_file) { BKE_animdata_free((ID *)cache_file, false); - - if (cache_file->id.tag & LIB_TAG_NO_MAIN) { - /* CoW/no-main copies reuse the existing ArchiveReader and mutex */ - return; - } - - if (cache_file->handle) { -#ifdef WITH_ALEMBIC - ABC_free_handle(cache_file->handle); -#endif - cache_file->handle = NULL; - } - if (cache_file->handle_mutex) { - BLI_mutex_free(cache_file->handle_mutex); - cache_file->handle_mutex = NULL; - } - + cachefile_handle_free(cache_file); BLI_freelistN(&cache_file->object_paths); } /** - * Only copy internal data of CacheFile ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of CacheFile ID from source to already + * allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -115,13 +197,8 @@ void BKE_cachefile_copy_data(Main *UNUSED(bmain), const CacheFile *UNUSED(cache_file_src), const int UNUSED(flag)) { - if (cache_file_dst->id.tag & LIB_TAG_NO_MAIN) { - /* CoW/no-main copies reuse the existing ArchiveReader and mutex */ - return; - } - cache_file_dst->handle = NULL; - cache_file_dst->handle_mutex = NULL; + cache_file_dst->handle_readers = NULL; BLI_duplicatelist(&cache_file_dst->object_paths, &cache_file_dst->object_paths); } @@ -137,72 +214,51 @@ void BKE_cachefile_make_local(Main *bmain, CacheFile *cache_file, const bool lib BKE_id_make_local_generic(bmain, &cache_file->id, true, lib_local); } -void BKE_cachefile_reload(const Main *bmain, CacheFile *cache_file) +void BKE_cachefile_reload(Depsgraph *depsgraph, CacheFile *cache_file) { - char filepath[FILE_MAX]; - - BLI_strncpy(filepath, cache_file->filepath, sizeof(filepath)); - BLI_path_abs(filepath, ID_BLEND_PATH(bmain, &cache_file->id)); - -#ifdef WITH_ALEMBIC - if (cache_file->handle) { - ABC_free_handle(cache_file->handle); + /* To force reload, free the handle and tag depsgraph to load it again. */ + CacheFile *cache_file_eval = (CacheFile *)DEG_get_evaluated_id(depsgraph, &cache_file->id); + if (cache_file_eval) { + cachefile_handle_free(cache_file_eval); } - cache_file->handle = ABC_create_handle(filepath, &cache_file->object_paths); -#endif + DEG_id_tag_update(&cache_file->id, ID_RECALC_COPY_ON_WRITE); } -void BKE_cachefile_ensure_handle(const Main *bmain, CacheFile *cache_file) +void BKE_cachefile_eval(Main *bmain, Depsgraph *depsgraph, CacheFile *cache_file) { - BLI_spin_lock(&spin); - if (cache_file->handle_mutex == NULL) { - cache_file->handle_mutex = BLI_mutex_alloc(); - } - BLI_spin_unlock(&spin); - - BLI_mutex_lock(cache_file->handle_mutex); + BLI_assert(cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE); - if (cache_file->handle == NULL) { - /* Assigning to a CoW copy is a bad idea; assign to the original instead. */ - BLI_assert((cache_file->id.tag & LIB_TAG_COPIED_ON_WRITE) == 0); - BKE_cachefile_reload(bmain, cache_file); + /* Compute filepath. */ + char filepath[FILE_MAX]; + if (!BKE_cachefile_filepath_get(bmain, depsgraph, cache_file, filepath)) { + return; } - BLI_mutex_unlock(cache_file->handle_mutex); -} - -void BKE_cachefile_update_frame( - Main *bmain, struct Depsgraph *depsgraph, Scene *scene, const float ctime, const float fps) -{ - CacheFile *cache_file; - char filename[FILE_MAX]; - - for (cache_file = bmain->cachefiles.first; cache_file; cache_file = cache_file->id.next) { - /* TODO: dependency graph should be updated to do drivers on cachefile. - * Execute drivers only, as animation has already been done. */ - BKE_animsys_evaluate_animdata( - depsgraph, scene, &cache_file->id, cache_file->adt, ctime, ADT_RECALC_DRIVERS); - - if (!cache_file->is_sequence) { - continue; - } + /* Test if filepath change or if we can keep the existing handle. */ + if (STREQ(cache_file->handle_filepath, filepath)) { + return; + } - const float time = BKE_cachefile_time_offset(cache_file, ctime, fps); + cachefile_handle_free(cache_file); + BLI_freelistN(&cache_file->object_paths); - if (BKE_cachefile_filepath_get(bmain, cache_file, time, filename)) { - BKE_cachefile_clean(bmain, cache_file); #ifdef WITH_ALEMBIC - ABC_free_handle(cache_file->handle); - cache_file->handle = ABC_create_handle(filename, NULL); + cache_file->handle = ABC_create_handle(filepath, &cache_file->object_paths); + BLI_strncpy(cache_file->handle_filepath, filepath, FILE_MAX); #endif - } + + if (DEG_is_active(depsgraph)) { + /* Flush object paths back to original datablock for UI. */ + CacheFile *cache_file_orig = (CacheFile *)DEG_get_original_id(&cache_file->id); + BLI_freelistN(&cache_file_orig->object_paths); + BLI_duplicatelist(&cache_file_orig->object_paths, &cache_file->object_paths); } } bool BKE_cachefile_filepath_get(const Main *bmain, + const Depsgraph *depsgraph, const CacheFile *cache_file, - float frame, char r_filepath[FILE_MAX]) { BLI_strncpy(r_filepath, cache_file->filepath, FILE_MAX); @@ -212,6 +268,11 @@ bool BKE_cachefile_filepath_get(const Main *bmain, int frame_len; if (cache_file->is_sequence && BLI_path_frame_get(r_filepath, &fframe, &frame_len)) { + Scene *scene = DEG_get_evaluated_scene(depsgraph); + const float ctime = BKE_scene_frame_get(scene); + const float fps = (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base); + const float frame = BKE_cachefile_time_offset(cache_file, ctime, fps); + char ext[32]; BLI_path_frame_strip(r_filepath, ext); BLI_path_frame(r_filepath, frame, frame_len); @@ -224,47 +285,9 @@ bool BKE_cachefile_filepath_get(const Main *bmain, return true; } -float BKE_cachefile_time_offset(CacheFile *cache_file, const float time, const float fps) +float BKE_cachefile_time_offset(const CacheFile *cache_file, const float time, const float fps) { const float time_offset = cache_file->frame_offset / fps; const float frame = (cache_file->override_frame ? cache_file->frame : time); return cache_file->is_sequence ? frame : frame / fps - time_offset; } - -/* TODO(kevin): replace this with some depsgraph mechanism, or something similar. */ -void BKE_cachefile_clean(struct Main *bmain, CacheFile *cache_file) -{ - for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { - ModifierData *md = modifiers_findByType(ob, eModifierType_MeshSequenceCache); - - if (md) { - MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; - - if (cache_file == mcmd->cache_file) { -#ifdef WITH_ALEMBIC - if (mcmd->reader != NULL) { - CacheReader_free(mcmd->reader); - } -#endif - mcmd->reader = NULL; - } - } - - for (bConstraint *con = ob->constraints.first; con; con = con->next) { - if (con->type != CONSTRAINT_TYPE_TRANSFORM_CACHE) { - continue; - } - - bTransformCacheConstraint *data = con->data; - - if (cache_file == data->cache_file) { -#ifdef WITH_ALEMBIC - if (data->reader != NULL) { - CacheReader_free(data->reader); - } -#endif - data->reader = NULL; - } - } - } -} diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 59811cfe373..25399d342e1 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -88,8 +88,10 @@ void *BKE_camera_add(Main *bmain, const char *name) } /** - * Only copy internal data of Camera ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Camera ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index ea3834be68a..667219e0eec 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -385,7 +385,8 @@ static void cdDM_foreachMappedLoop(DerivedMesh *dm, void *userData, DMForeachFlag flag) { - /* We can't use dm->getLoopDataLayout(dm) here, we want to always access dm->loopData, EditDerivedBMesh would + /* We can't use dm->getLoopDataLayout(dm) here, + * we want to always access dm->loopData, EditDerivedBMesh would * return loop data from bmesh itself. */ const float(*lnors)[3] = (flag & DM_FOREACH_USE_NORMAL) ? DM_get_loop_data_layer(dm, CD_NORMAL) : NULL; @@ -633,7 +634,8 @@ DerivedMesh *CDDM_from_mesh_ex(Mesh *mesh, if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) { dm->dirty |= DM_DIRTY_NORMALS; } - /* TODO DM_DIRTY_TESS_CDLAYERS ? Maybe not though, since we probably want to switch to looptris ? */ + /* TODO DM_DIRTY_TESS_CDLAYERS ? Maybe not though, + * since we probably want to switch to looptris? */ CustomData_merge(&mesh->vdata, &dm->vertData, cddata_masks.vmask, alloctype, mesh->totvert); CustomData_merge(&mesh->edata, &dm->edgeData, cddata_masks.emask, alloctype, mesh->totedge); diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 6db5745dd42..fcc0e1856af 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -432,9 +432,9 @@ void clothModifier_do(ClothModifierData *clmd, else if (cache_result == PTCACHE_READ_OLD) { BKE_cloth_solver_set_positions(clmd); } - else if (/*ob->id.lib ||*/ ( - cache->flag & - PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */ + else if ( + /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */ + /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* if baked and nothing in cache, do nothing */ BKE_ptcache_invalidate(cache); return; @@ -722,7 +722,8 @@ static void cloth_apply_vgroup(ClothModifierData *clmd, Mesh *mesh) } if (clmd->sim_parms->vgroup_shrink > 0) { if (dvert->dw[j].def_nr == (clmd->sim_parms->vgroup_shrink - 1)) { - /* Used for linear interpolation between min and max shrink factor based on weight. */ + /* Used for linear interpolation between min and max + * shrink factor based on weight. */ verts->shrink_factor = dvert->dw[j].weight; } } @@ -1148,7 +1149,8 @@ static void cloth_update_springs(ClothModifierData *clmd) spring->lin_stiffness = (v1->bend_stiff + v2->bend_stiff) / 2.0f; } else if (spring->type == CLOTH_SPRING_TYPE_GOAL) { - /* Warning: Appending NEW goal springs does not work because implicit solver would need reset! */ + /* Warning: Appending NEW goal springs does not work + * because implicit solver would need reset! */ /* Activate / Deactivate existing springs */ if ((!(cloth->verts[spring->ij].flags & CLOTH_VERT_FLAG_PINNED)) && diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 16b330d9e7f..d33d4e344b5 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -188,8 +188,10 @@ bool BKE_collection_delete(Main *bmain, Collection *collection, bool hierarchy) /***************************** Collection Copy *******************************/ /** - * Only copy internal data of Collection ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Collection ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -248,7 +250,8 @@ static Collection *collection_duplicate_recursive(Main *bmain, collection_new = (Collection *)collection_old->id.newid; } - /* Optionally add to parent (we always want to do that, even if collection_old had already been duplicated). */ + /* Optionally add to parent (we always want to do that, + * even if collection_old had already been duplicated). */ if (parent != NULL) { if (collection_child_add(parent, collection_new, 0, true)) { /* Put collection right after existing one. */ @@ -263,14 +266,15 @@ static Collection *collection_duplicate_recursive(Main *bmain, } /* If we are not doing any kind of deep-copy, we can return immediately. - * False do_full_process means collection_old had already been duplicated, no need to redo some deep-copy on it. */ + * False do_full_process means collection_old had already been duplicated, + * no need to redo some deep-copy on it. */ if (!do_hierarchy || !do_full_process) { return collection_new; } if (do_objects) { - /* We can loop on collection_old's objects, that list is currently identical the collection_new' objects, - * and won't be changed here. */ + /* We can loop on collection_old's objects, that list is currently identical the collection_new + * objects, and won't be changed here. */ for (CollectionObject *cob = collection_old->gobject.first; cob; cob = cob->next) { Object *ob_old = cob->ob; Object *ob_new = (Object *)ob_old->id.newid; @@ -285,8 +289,8 @@ static Collection *collection_duplicate_recursive(Main *bmain, } } - /* We can loop on collection_old's children, that list is currently identical the collection_new' children, - * and won't be changed here. */ + /* We can loop on collection_old's children, + * that list is currently identical the collection_new' children, and won't be changed here. */ for (CollectionChild *child = collection_old->children.first; child; child = child->next) { Collection *child_collection_old = child->collection; @@ -314,13 +318,15 @@ Collection *BKE_collection_copy(Main *bmain, Collection *parent, Collection *col * * If \a do_hierarchy and \a do_deep_copy are false, this is a regular (shallow) ID copy. * - * \warning If any 'deep copy' behavior is enabled, this functions will clear all \a bmain id.idnew pointers. + * \warning If any 'deep copy' behavior is enabled, + * this functions will clear all \a bmain id.idnew pointers. * * \param do_hierarchy If true, it will recursively make shallow copies of children collections. * \param do_objects If true, it will also make duplicates of objects. * This one does nothing if \a do_hierarchy is not set. - * \param do_obdata If true, it will also make deep duplicates of objects, using behavior defined in user settings - * (U.dupflag). This one does nothing if \a do_hierarchy and \a do_objects are not set. + * \param do_obdata If true, it will also make deep duplicates of objects, + * using behavior defined in user settings (U.dupflag). + * This one does nothing if \a do_hierarchy and \a do_objects are not set. */ Collection *BKE_collection_duplicate(Main *bmain, Collection *parent, @@ -835,7 +841,8 @@ static void collection_missing_parents_remove(Collection *collection) * * \note caller must ensure #BKE_main_collection_sync_remap() is called afterwards! * - * \param collection: may be \a NULL, in which case whole \a bmain database of collections is checked. + * \param collection: may be \a NULL, + * in which case whole \a bmain database of collections is checked. */ void BKE_collections_child_remove_nulls(Main *bmain, Collection *collection) { diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index a8ca6d40b51..ff6258ac339 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -539,7 +539,8 @@ static int cloth_collision_response_static(ClothModifierData *clmd, sub_v3_v3v3(relativeVelocity, v2, v1); - /* Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). */ + /* Calculate the normal component of the relative velocity + * (actually only the magnitude - the direction is stored in 'normal'). */ magrelVel = dot_v3v3(relativeVelocity, collpair->normal); /* If magrelVel < 0 the edges are approaching each other. */ @@ -557,7 +558,8 @@ static int cloth_collision_response_static(ClothModifierData *clmd, sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); /* Decrease in magnitude of relative tangential velocity due to coulomb friction - * in original formula "magrelVel" should be the "change of relative velocity in normal direction". */ + * in original formula "magrelVel" should be the + * "change of relative velocity in normal direction". */ magtangent = min_ff(collob->pd->pdef_cfrict * 0.01f * magrelVel, len_v3(vrel_t_pre)); /* Apply friction impulse. */ @@ -720,7 +722,8 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, sub_v3_v3v3(relativeVelocity, v2, v1); - /* Calculate the normal component of the relative velocity (actually only the magnitude - the direction is stored in 'normal'). */ + /* Calculate the normal component of the relative velocity + * (actually only the magnitude - the direction is stored in 'normal'). */ magrelVel = dot_v3v3(relativeVelocity, collpair->normal); /* TODO: Impulses should be weighed by mass as this is self col, @@ -740,7 +743,8 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, sub_v3_v3v3(vrel_t_pre, relativeVelocity, temp); /* Decrease in magnitude of relative tangential velocity due to coulomb friction - * in original formula "magrelVel" should be the "change of relative velocity in normal direction". */ + * in original formula "magrelVel" should be the + * "change of relative velocity in normal direction". */ magtangent = min_ff(clmd->coll_parms->self_friction * 0.01f * magrelVel, len_v3(vrel_t_pre)); /* Apply friction impulse. */ @@ -1548,7 +1552,8 @@ static CollPair *cloth_point_collpair(float p1[3], return collpair; } -//Determines collisions on overlap, collisions are written to collpair[i] and collision+number_collision_found is returned +/* Determines collisions on overlap, + * collisions are written to collpair[i] and collision+number_collision_found is returned. */ static CollPair *cloth_point_collision(ModifierData *md1, ModifierData *md2, BVHTreeOverlap *overlap, @@ -1696,8 +1701,11 @@ void cloth_find_point_contacts(Depsgraph *depsgraph, clmd, collmd, &ct->collisions, &collisions_index, result, overlap, epsilon, dt); ct->totcollisions = (int)(collisions_index - ct->collisions); - // resolve nearby collisions - // ret += cloth_points_objcollisions_resolve(clmd, collmd, collob->pd, collisions[i], collisions_index[i], dt); + /* Resolve nearby collisions. */ +#if 0 + ret += cloth_points_objcollisions_resolve( + clmd, collmd, collob->pd, collisions[i], collisions_index[i], dt); +#endif } if (overlap) { diff --git a/source/blender/blenkernel/intern/colorband.c b/source/blender/blenkernel/intern/colorband.c index 3d13c16d595..8701f06d9dd 100644 --- a/source/blender/blenkernel/intern/colorband.c +++ b/source/blender/blenkernel/intern/colorband.c @@ -420,8 +420,9 @@ bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4]) cbd1 = coba->data; - /* Note: when ipotype >= COLBAND_INTERP_B_SPLINE, we cannot do early-out with a constant color before - * first color stop and after last one, because interpolation starts before and ends after those... */ + /* Note: when ipotype >= COLBAND_INTERP_B_SPLINE, + * we cannot do early-out with a constant color before first color stop and after last one, + * because interpolation starts before and ends after those... */ ipotype = (coba->color_mode == COLBAND_BLEND_RGB) ? coba->ipotype : COLBAND_INTERP_LINEAR; if (coba->tot == 1) { diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index d6b68121c94..0e29f165992 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -120,7 +120,8 @@ void BKE_constraint_unique_name(bConstraint *con, ListBase *list) /* ----------------- Evaluation Loop Preparation --------------- */ /* package an object/bone for use in constraint evaluation */ -/* This function MEM_calloc's a bConstraintOb struct, that will need to be freed after evaluation */ +/* This function MEM_calloc's a bConstraintOb struct, + * that will need to be freed after evaluation */ bConstraintOb *BKE_constraints_make_evalob( Depsgraph *depsgraph, Scene *scene, Object *ob, void *subdata, short datatype) { @@ -210,10 +211,10 @@ void BKE_constraints_clear_evalob(bConstraintOb *cob) /* calculate delta of constraints evaluation */ invert_m4_m4(imat, cob->startmat); - /* XXX This would seem to be in wrong order. However, it does not work in 'right' order - would be nice to - * understand why premul is needed here instead of usual postmul? - * In any case, we **do not get a delta** here (e.g. startmat & matrix having same location, still gives - * a 'delta' with non-null translation component :/ ).*/ + /* XXX This would seem to be in wrong order. However, it does not work in 'right' order - + * would be nice to understand why premul is needed here instead of usual postmul? + * In any case, we **do not get a delta** here (e.g. startmat & matrix having same location, + * still gives a 'delta' with non-null translation component :/ ).*/ mul_m4_m4m4(delta, cob->matrix, imat); /* copy matrices back to source */ @@ -352,8 +353,9 @@ void BKE_constraint_mat_convertspace( */ /* XXX This is actually an ugly hack, local space of a parent-less object *is* the same as * global space! - * Think what we want actually here is some kind of 'Final Space', i.e. once transformations - * are applied - users are often confused about this too, this is not consistent with bones + * Think what we want actually here is some kind of 'Final Space', i.e + * . once transformations are applied - users are often confused about this too, + * this is not consistent with bones * local space either... Meh :| * --mont29 */ @@ -1139,7 +1141,8 @@ static void trackto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar float size[3], vec[3]; float totmat[3][3]; - /* Get size property, since ob->scale is only the object's own relative size, not its global one */ + /* Get size property, since ob->scale is only the object's own relative size, + * not its global one. */ mat4_to_size(size, cob->matrix); /* Clear the object's rotation */ @@ -1357,12 +1360,11 @@ static void followpath_get_tarmat(struct Depsgraph *UNUSED(depsgraph), Nurb *nu = cu->nurb.first; curvetime = cu->ctime - data->offset; - /* ctime is now a proper var setting of Curve which gets set by Animato like any other var that's animated, - * but this will only work if it actually is animated... + /* ctime is now a proper var setting of Curve which gets set by Animato like any other var + * that's animated, but this will only work if it actually is animated... * - * we divide the curvetime calculated in the previous step by the length of the path, to get a time - * factor, which then gets clamped to lie within 0.0 - 1.0 range - */ + * we divide the curvetime calculated in the previous step by the length of the path, + * to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range. */ curvetime /= cu->pathlen; if (nu && nu->flagu & CU_NURB_CYCLIC) { @@ -1806,9 +1808,10 @@ static void rotlike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar copy_v3_v3(loc, cob->matrix[3]); mat4_to_size(size, cob->matrix); - /* to allow compatible rotations, must get both rotations in the order of the owner... */ + /* To allow compatible rotations, must get both rotations in the order of the owner... */ mat4_to_eulO(obeul, cob->rotOrder, cob->matrix); - /* we must get compatible eulers from the beginning because some of them can be modified below (see bug #21875) */ + /* We must get compatible eulers from the beginning because + * some of them can be modified below (see bug T21875). */ mat4_to_compatible_eulO(eul, obeul, cob->rotOrder, ct->matrix); if ((data->flag & ROTLIKE_X) == 0) { @@ -1850,7 +1853,8 @@ static void rotlike_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar } } - /* good to make eulers compatible again, since we don't know how much they were changed above */ + /* Good to make eulers compatible again, + * since we don't know how much they were changed above. */ compatible_eul(eul, obeul); loc_eulO_size_to_mat4(cob->matrix, loc, eul, size, cob->rotOrder); } @@ -2575,9 +2579,9 @@ static void actcon_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bPose pose = {{0}}; bPoseChannel *pchan, *tchan; - /* make a copy of the bone of interest in the temp pose before evaluating action, so that it can get set - * - we need to manually copy over a few settings, including rotation order, otherwise this fails - */ + /* make a copy of the bone of interest in the temp pose before evaluating action, + * so that it can get set - we need to manually copy over a few settings, + * including rotation order, otherwise this fails. */ pchan = cob->pchan; tchan = BKE_pose_channel_verify(&pose, pchan->name); @@ -3559,7 +3563,8 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar offset = curveMin[clamp_axis] - ceilf((curveMin[clamp_axis] - ownLoc[clamp_axis]) / len) * len; - /* now, we calculate as per normal, except using offset instead of curveMin[clamp_axis] */ + /* Now, we calculate as per normal, + * except using offset instead of curveMin[clamp_axis]. */ curvetime = (ownLoc[clamp_axis] - offset) / (len); } else if (ownLoc[clamp_axis] > curveMax[clamp_axis]) { @@ -3567,7 +3572,8 @@ static void clampto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *tar offset = curveMax[clamp_axis] + (int)((ownLoc[clamp_axis] - curveMax[clamp_axis]) / len) * len; - /* now, we calculate as per normal, except using offset instead of curveMax[clamp_axis] */ + /* Now, we calculate as per normal, + * except using offset instead of curveMax[clamp_axis]. */ curvetime = (ownLoc[clamp_axis] - offset) / (len); } else { @@ -3689,11 +3695,10 @@ static void transform_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t mat4_to_size(dvec, ct->matrix); if (is_negative_m4(ct->matrix)) { - /* Bugfix [#27886] - * We can't be sure which axis/axes are negative, though we know that something is negative. - * Assume we don't care about negativity of separate axes. <--- This is a limitation that - * riggers will have to live with for now. - */ + /* Bugfix T27886: (this is a limitation that riggers will have to live with for now). + * We can't be sure which axis/axes are negative, + * though we know that something is negative. + * Assume we don't care about negativity of separate axes. */ negate_v3(dvec); } from_min = data->from_min_scale; @@ -3932,9 +3937,10 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *UNUSED(depsgraph), break; } - /* transform normal into requested space */ - /* Note that in this specific case, we need to keep scaling in non-parented 'local2world' object - * case, because SpaceTransform also takes it into account when handling normals. See T42447. */ + /* Transform normal into requested space */ + /* Note that in this specific case, we need to keep scaling in non-parented 'local2world' + * object case, because SpaceTransform also takes it into account when handling normals. + * See T42447. */ unit_m4(mat); BKE_constraint_mat_convertspace( cob->ob, cob->pchan, mat, CONSTRAINT_SPACE_LOCAL, scon->projAxisSpace, true); @@ -4829,13 +4835,9 @@ static void transformcache_evaluate(bConstraint *con, bConstraintOb *cob, ListBa const float frame = DEG_get_ctime(cob->depsgraph); const float time = BKE_cachefile_time_offset(cache_file, frame, FPS); - /* Must always load ABC handle on original. */ - CacheFile *cache_file_orig = (CacheFile *)DEG_get_original_id(&cache_file->id); - BKE_cachefile_ensure_handle(G.main, cache_file_orig); - - if (!data->reader) { - data->reader = CacheReader_open_alembic_object( - cache_file_orig->handle, data->reader, cob->ob, data->object_path); + if (!data->reader || !STREQ(data->reader_object_path, data->object_path)) { + STRNCPY(data->reader_object_path, data->object_path); + BKE_cachefile_reader_open(cache_file, &data->reader, cob->ob, data->object_path); } ABC_get_transform(data->reader, cob->matrix, time, cache_file->scale); @@ -4853,12 +4855,8 @@ static void transformcache_copy(bConstraint *con, bConstraint *srccon) BLI_strncpy(dst->object_path, src->object_path, sizeof(dst->object_path)); dst->cache_file = src->cache_file; - -#ifdef WITH_ALEMBIC - if (dst->reader) { - CacheReader_incref(dst->reader); - } -#endif + dst->reader = NULL; + dst->reader_object_path[0] = '\0'; } static void transformcache_free(bConstraint *con) @@ -4866,10 +4864,8 @@ static void transformcache_free(bConstraint *con) bTransformCacheConstraint *data = con->data; if (data->reader) { -#ifdef WITH_ALEMBIC - CacheReader_free(data->reader); -#endif - data->reader = NULL; + BKE_cachefile_reader_free(data->cache_file, &data->reader); + data->reader_object_path[0] = '\0'; } } @@ -5225,7 +5221,8 @@ static void con_extern_cb(bConstraint *UNUSED(con), } } -/* helper for BKE_constraints_copy(), to be used for making sure that usercounts of copied ID's are fixed up */ +/* helper for BKE_constraints_copy(), + * to be used for making sure that usercounts of copied ID's are fixed up */ static void con_fix_copied_refs_cb(bConstraint *UNUSED(con), ID **idpoin, bool is_reference, @@ -5460,7 +5457,8 @@ static bConstraint *constraint_find_original_for_update(bConstraintOb *cob, bCon /* -------- Constraints and Proxies ------- */ -/* Rescue all constraints tagged as being CONSTRAINT_PROXY_LOCAL (i.e. added to bone that's proxy-synced in this file) */ +/* Rescue all constraints tagged as being CONSTRAINT_PROXY_LOCAL + * (i.e. added to bone that's proxy-synced in this file) */ void BKE_constraints_proxylocal_extract(ListBase *dst, ListBase *src) { bConstraint *con, *next; @@ -5502,8 +5500,8 @@ bool BKE_constraints_proxylocked_owner(Object *ob, bPoseChannel *pchan) /* -------- Target-Matrix Stuff ------- */ /* This function is a relic from the prior implementations of the constraints system, when all - * constraints either had one or no targets. It used to be called during the main constraint solving - * loop, but is now only used for the remaining cases for a few constraints. + * constraints either had one or no targets. It used to be called during the main constraint + * solving loop, but is now only used for the remaining cases for a few constraints. * * None of the actual calculations of the matrices should be done here! Also, this function is * not to be used by any new constraints, particularly any that have multiple targets. @@ -5694,9 +5692,9 @@ void BKE_constraints_solve(struct Depsgraph *depsgraph, } /* Interpolate the enforcement, to blend result of constraint into final owner transform - * - all this happens in worldspace to prevent any weirdness creeping in ([#26014] and [#25725]), - * since some constraints may not convert the solution back to the input space before blending - * but all are guaranteed to end up in good "worldspace" result + * - all this happens in worldspace to prevent any weirdness creeping in + * (T26014 and T25725), since some constraints may not convert the solution back to the input + * space before blending but all are guaranteed to end up in good "worldspace" result. */ /* Note: all kind of stuff here before (caused trouble), much easier to just interpolate, * or did I miss something? -jahka (r.32105) */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 293d2c34b07..dc677449a4c 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -196,8 +196,10 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type) } /** - * Only copy internal data of Curve ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Curve ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -337,7 +339,8 @@ void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3]) BoundBox *BKE_curve_boundbox_get(Object *ob) { - /* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */ + /* This is Object-level data access, + * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */ if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) { Curve *cu = ob->data; float min[3], max[3]; @@ -2962,8 +2965,11 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) bev = &ob->runtime.curve_cache->bev; +#if 0 /* do we need to calculate the radius for each point? */ - /* do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : 1; */ + do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : + 1; +#endif /* STEP 1: MAKE POLYS */ @@ -2974,7 +2980,6 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render) } for (; nu; nu = nu->next) { - if (nu->hide && is_editmode) { continue; } @@ -3896,7 +3901,8 @@ static bool tridiagonal_solve_with_limits( all = true; } while (overshoot && !locked); - /* if no handles overshot and were locked, see if it may be a good idea to unlock some handles */ + /* If no handles overshot and were locked, + * see if it may be a good idea to unlock some handles. */ if (!locked) { for (int i = 0; i < solve_count; i++) { // to definitely avoid infinite loops limit this to 2 times @@ -3922,6 +3928,8 @@ static bool tridiagonal_solve_with_limits( return true; } +/* Keep ascii art. */ +/* clang-format off */ /* * This function computes the handles of a series of auto bezier points * on the basis of 'no acceleration discontinuities' at the points. @@ -3949,30 +3957,31 @@ static bool tridiagonal_solve_with_limits( * |-------t1---------t2--------- ~ --------tN-------------------> time (co 0) * Mathematical basis: * - * 1. Handle lengths on either side of each point are connected by a factor - * ensuring continuity of the first derivative: + * 1. Handle lengths on either side of each point are connected by a factor + * ensuring continuity of the first derivative: * - * l[i] = t[i+1]/t[i] + * l[i] = t[i+1]/t[i] * - * 2. The tridiagonal system is formed by the following equation, which is derived - * by differentiating the bezier curve and specifies second derivative continuity - * at every point: + * 2. The tridiagonal system is formed by the following equation, which is derived + * by differentiating the bezier curve and specifies second derivative continuity + * at every point: * - * l[i]^2 * h[i-1] + (2*l[i]+2) * h[i] + 1/l[i+1] * h[i+1] = (y[i]-y[i-1])*l[i]^2 + y[i+1]-y[i] + * l[i]^2 * h[i-1] + (2*l[i]+2) * h[i] + 1/l[i+1] * h[i+1] = (y[i]-y[i-1])*l[i]^2 + y[i+1]-y[i] * - * 3. If this point is adjacent to a manually set handle with X size not equal to 1/3 - * of the horizontal interval, this equation becomes slightly more complex: + * 3. If this point is adjacent to a manually set handle with X size not equal to 1/3 + * of the horizontal interval, this equation becomes slightly more complex: * - * l[i]^2 * h[i-1] + (3*(1-R[i-1])*l[i] + 3*(1-L[i+1])) * h[i] + 1/l[i+1] * h[i+1] = (y[i]-y[i-1])*l[i]^2 + y[i+1]-y[i] + * l[i]^2 * h[i-1] + (3*(1-R[i-1])*l[i] + 3*(1-L[i+1])) * h[i] + 1/l[i+1] * h[i+1] = (y[i]-y[i-1])*l[i]^2 + y[i+1]-y[i] * - * The difference between equations amounts to this, and it's obvious that when R[i-1] - * and L[i+1] are both 1/3, it becomes zero: + * The difference between equations amounts to this, and it's obvious that when R[i-1] + * and L[i+1] are both 1/3, it becomes zero: * - * ( (1-3*R[i-1])*l[i] + (1-3*L[i+1]) ) * h[i] + * ( (1-3*R[i-1])*l[i] + (1-3*L[i+1]) ) * h[i] * - * 4. The equations for zero acceleration border conditions are basically the above - * equation with parts omitted, so the handle size correction also applies. + * 4. The equations for zero acceleration border conditions are basically the above + * equation with parts omitted, so the handle size correction also applies. */ +/* clang-format on */ static void bezier_eq_continuous( float *a, float *b, float *c, float *d, float *dy, float *l, int i) diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index c2ef575d086..22bc44a88d8 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -159,7 +159,8 @@ typedef struct LayerTypeInfo { /** a function to determine file size */ size_t (*filesize)(CDataFile *cdf, const void *data, int count); - /** a function to determine max allowed number of layers, should be NULL or return -1 if no limit */ + /** a function to determine max allowed number of layers, + * should be NULL or return -1 if no limit */ int (*layers_max)(void); } LayerTypeInfo; @@ -324,7 +325,8 @@ static void layerInterp_normal(const void **sources, void *dest) { /* Note: This is linear interpolation, which is not optimal for vectors. - * Unfortunately, spherical interpolation of more than two values is hairy, so for now it will do... */ + * Unfortunately, spherical interpolation of more than two values is hairy, + * so for now it will do... */ float no[3] = {0.0f}; while (count--) { @@ -923,7 +925,8 @@ static void layerCopyValue_mloopuv(const void *source, const MLoopUV *luv1 = source; MLoopUV *luv2 = dest; - /* We only support a limited subset of advanced mixing here - namely the mixfactor interpolation. */ + /* We only support a limited subset of advanced mixing here - + * namely the mixfactor interpolation. */ if (mixmode == CDT_MIX_NOMIX) { copy_v2_v2(luv2->uv, luv1->uv); @@ -1429,7 +1432,8 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { /* 14: CD_ORCO */ {sizeof(float) * 3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 15: CD_MTEXPOLY */ /* DEPRECATED */ - /* note, when we expose the UV Map / TexFace split to the user, change this back to face Texture */ + /* note, when we expose the UV Map / TexFace split to the user, + * change this back to face Texture. */ {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL}, /* 16: CD_MLOOPUV */ {sizeof(MLoopUV), @@ -2197,7 +2201,8 @@ void CustomData_set_layer_stencil(CustomData *data, int type, int n) } } -/* for using with an index from CustomData_get_active_layer_index and CustomData_get_render_layer_index */ +/* For using with an index from CustomData_get_active_layer_index and + * CustomData_get_render_layer_index. */ void CustomData_set_layer_active_index(CustomData *data, int type, int n) { int i; @@ -2877,8 +2882,8 @@ void CustomData_interp(const CustomData *source, /** * Swap data inside each item, for all layers. - * This only applies to item types that may store several sub-item data (e.g. corner data [UVs, VCol, ...] of - * tessellated faces). + * This only applies to item types that may store several sub-item data + * (e.g. corner data [UVs, VCol, ...] of tessellated faces). * * \param corner_indices: A mapping 'new_index -> old_index' of sub-item data. */ @@ -3502,7 +3507,9 @@ void CustomData_bmesh_copy_data(const CustomData *source, } } -/*Bmesh Custom Data Functions. Should replace editmesh ones with these as well, due to more efficient memory alloc*/ +/* BMesh Custom Data Functions. + * Should replace edit-mesh ones with these as well, due to more efficient memory alloc. + */ void *CustomData_bmesh_get(const CustomData *data, void *block, int type) { int layer_index; @@ -3965,15 +3972,20 @@ void CustomData_file_write_info(int type, const char **r_struct_name, int *r_str * Prepare given custom data for file writing. * * \param data: the customdata to tweak for .blend file writing (modified in place). - * \param r_write_layers: contains a reduced set of layers to be written to file, use it with writestruct_at_address() - * (caller must free it if != \a write_layers_buff). + * \param r_write_layers: contains a reduced set of layers to be written to file, + * use it with writestruct_at_address() + * (caller must free it if != \a write_layers_buff). + * * \param write_layers_buff: an optional buffer for r_write_layers (to avoid allocating it). * \param write_layers_size: the size of pre-allocated \a write_layer_buff. * - * \warning After this func has ran, given custom data is no more valid from Blender PoV (its totlayer is invalid). - * This func shall always be called with localized data (as it is in write_meshes()). - * \note data->typemap is not updated here, since it is always rebuilt on file read anyway. This means written - * typemap does not match written layers (as returned by \a r_write_layers). Trivial to fix is ever needed. + * \warning After this func has ran, given custom data is no more valid from Blender PoV + * (its totlayer is invalid). This func shall always be called with localized data + * (as it is in write_meshes()). + * + * \note data->typemap is not updated here, since it is always rebuilt on file read anyway. + * This means written typemap does not match written layers (as returned by \a r_write_layers). + * Trivial to fix is ever needed. */ void CustomData_file_write_prepare(CustomData *data, CustomDataLayer **r_write_layers, @@ -4164,9 +4176,11 @@ bool CustomData_verify_versions(struct CustomData *data, int index) if (!typeInfo->defaultname && (index > 0) && data->layers[index - 1].type == layer->type) { keeplayer = false; /* multiple layers of which we only support one */ } - /* This is a pre-emptive fix for cases that should not happen (layers that should not be written - * in .blend files), but can happen due to bugs (see e.g. T62318). - * Also for forward compatibility, in future, we may put into .blend file some currently un-written data types, + /* This is a pre-emptive fix for cases that should not happen + * (layers that should not be written in .blend files), + * but can happen due to bugs (see e.g. T62318). + * Also for forward compatibility, in future, + * we may put into `.blend` file some currently un-written data types, * this should cover that case as well. * Better to be safe here, and fix issue on the fly rather than crash... */ /* 0 structnum is used in writing code to tag layer types that should not be written. */ @@ -4189,7 +4203,8 @@ bool CustomData_verify_versions(struct CustomData *data, int index) } /** - * Validate and fix data of \a layer, if possible (needs relevant callback in layer's type to be defined). + * Validate and fix data of \a layer, + * if possible (needs relevant callback in layer's type to be defined). * * \return True if some errors were found. */ @@ -4449,7 +4464,7 @@ void CustomData_external_remove(CustomData *data, ID *id, int type, int totelem) { CustomDataExternal *external = data->external; CustomDataLayer *layer; - //char filename[FILE_MAX]; + // char filename[FILE_MAX]; int layer_index; // i, remove_file; layer_index = CustomData_get_active_layer_index(data, type); @@ -4511,7 +4526,7 @@ static void copy_bit_flag(void *dst, const void *src, const size_t data_size, co COPY_BIT_FLAG(uint64_t, dst, src, flag); break; default: - //CLOG_ERROR(&LOG, "Unknown flags-container size (%zu)", datasize); + // CLOG_ERROR(&LOG, "Unknown flags-container size (%zu)", datasize); break; } @@ -4530,7 +4545,7 @@ static bool check_bit_flag(const void *data, const size_t data_size, const uint6 case 8: return ((*((uint64_t *)data) & ((uint64_t)flag)) != 0); default: - //CLOG_ERROR(&LOG, "Unknown flags-container size (%zu)", datasize); + // CLOG_ERROR(&LOG, "Unknown flags-container size (%zu)", datasize); return false; } } @@ -4543,9 +4558,9 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye const float mix_factor) { /* Fake interpolation, we actually copy highest weighted source to dest. - * Note we also handle bitflags here, in which case we rather choose to transfer value of elements totaling + * Note we also handle bitflags here, + * in which case we rather choose to transfer value of elements totaling * more than 0.5 of weight. */ - int best_src_idx = 0; const int data_type = laymap->data_type; @@ -4581,7 +4596,8 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye int i; if (data_flag) { - /* Boolean case, we can 'interpolate' in two groups, and choose value from highest weighted group. */ + /* Boolean case, we can 'interpolate' in two groups, + * and choose value from highest weighted group. */ float tot_weight_true = 0.0f; int item_true_idx = -1, item_false_idx = -1; @@ -4626,7 +4642,8 @@ static void customdata_data_transfer_interp_generic(const CustomDataTransferLaye } if (data_flag) { - /* Bool flags, only copy if dest data is set (resp. unset) - only 'advanced' modes we can support here! */ + /* Bool flags, only copy if dest data is set (resp. unset) - + * only 'advanced' modes we can support here! */ if (mix_factor >= 0.5f && ((mix_mode == CDT_MIX_TRANSFER) || (mix_mode == CDT_MIX_REPLACE_ABOVE_THRESHOLD && check_bit_flag(data_dst, data_size, data_flag)) || diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c index a57db5a7cbe..98c6d519d17 100644 --- a/source/blender/blenkernel/intern/data_transfer.c +++ b/source/blender/blenkernel/intern/data_transfer.c @@ -90,7 +90,8 @@ void BKE_object_data_transfer_dttypes_to_cdmask(const int dtdata_types, } } -/* Check what can do each layer type (if it is actually handled by transferdata, if it supports advanced mixing... */ +/* Check what can do each layer type + * (if it is actually handled by transferdata, if it supports advanced mixing... */ bool BKE_object_data_transfer_get_dttypes_capacity(const int dtdata_types, bool *r_advanced_mixing, bool *r_threshold) @@ -340,6 +341,10 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src), const bool changed) { if (dtdata_type == DT_TYPE_LNOR) { + if (!changed) { + return; + } + /* Bake edited destination loop normals into custom normals again. */ MVert *verts_dst = me_dst->mvert; const int num_verts_dst = me_dst->totvert; @@ -358,10 +363,6 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src), BLI_assert(poly_nors_dst); - if (!changed) { - return; - } - if (!custom_nors_dst) { custom_nors_dst = CustomData_add_layer( ldata_dst, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, num_loops_dst); @@ -458,7 +459,8 @@ static void data_transfer_interp_char(const CustomDataTransferLayerMap *laymap, *data_dst = (char)(val_src * 255.0f); } -/* Helpers to match sources and destinations data layers (also handles 'conversions' in CD_FAKE cases). */ +/* Helpers to match sources and destinations data layers + * (also handles 'conversions' in CD_FAKE cases). */ void data_transfer_layersmapping_add_item(ListBase *r_map, const int cddata_type, @@ -537,12 +539,13 @@ static void data_transfer_layersmapping_add_item_cd(ListBase *r_map, interp_data); } -/* Note: All those layer mapping handlers return false *only* if they were given invalid parameters. - * This means that even if they do nothing, they will return true if all given parameters were OK. - * Also, r_map may be NULL, in which case they will 'only' create/delete destination layers according - * to given parameters. +/** + * \note + * All those layer mapping handlers return false *only* if they were given invalid parameters. + * This means that even if they do nothing, they will return true if all given parameters were OK. + * Also, r_map may be NULL, in which case they will 'only' create/delete destination layers + * according to given parameters. */ - static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map, const int cddata_type, const int mix_mode, @@ -582,7 +585,7 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map /* Find last source actually used! */ while (idx_src-- && !use_layers_src[idx_src]) { - ; + /* pass */ } idx_src++; @@ -609,7 +612,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map continue; } data_src = CustomData_get_layer_n(cd_src, cddata_type, idx_src); - /* If dest is a evaluated mesh (fro; ;odifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ if (use_dupref_dst) { data_dst = CustomData_duplicate_referenced_layer_n( cd_dst, cddata_type, idx_src, num_elem_dst); @@ -654,7 +658,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name); } else { - /* If we are not allowed to create missing dst data layers, just skip matching src one. */ + /* If we are not allowed to create missing dst data layers, + * just skip matching src one. */ continue; } } @@ -662,7 +667,8 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map data_dst_to_delete[idx_dst] = false; } if (r_map) { - /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ if (use_dupref_dst) { data_dst = CustomData_duplicate_referenced_layer_n( cd_dst, cddata_type, idx_dst, num_elem_dst); @@ -683,9 +689,10 @@ static bool data_transfer_layersmapping_cdlayers_multisrc_to_dst(ListBase *r_map } if (data_dst_to_delete) { - /* Note: This won't affect newly created layers, if any, since tot_dst has not been updated! - * Also, looping backward ensures us we do not suffer from index shifting when deleting a layer. - */ + /* Note: + * This won't affect newly created layers, if any, since tot_dst has not been updated! + * Also, looping backward ensures us we do not suffer + * from index shifting when deleting a layer. */ for (idx_dst = tot_dst; idx_dst--;) { if (data_dst_to_delete[idx_dst]) { CustomData_free_layer(cd_dst, cddata_type, num_elem_dst, idx_dst); @@ -737,7 +744,8 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map, data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst); } else if (use_dupref_dst && r_map) { - /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ data_dst = CustomData_duplicate_referenced_layer(cd_dst, cddata_type, num_elem_dst); } @@ -771,7 +779,8 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map, if (tolayers >= 0) { /* Real-layer index */ idx_dst = tolayers; - /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ if (use_dupref_dst && r_map) { data_dst = CustomData_duplicate_referenced_layer_n( cd_dst, cddata_type, idx_dst, num_elem_dst); @@ -788,7 +797,8 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map, data_dst = CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst); } else { - /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ if (use_dupref_dst && r_map) { data_dst = CustomData_duplicate_referenced_layer_n( cd_dst, cddata_type, idx_dst, num_elem_dst); @@ -810,7 +820,8 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map, CustomData_add_layer(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst); } } - /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ if (use_dupref_dst && r_map) { data_dst = CustomData_duplicate_referenced_layer_n( cd_dst, cddata_type, idx_dst, num_elem_dst); @@ -828,7 +839,8 @@ static bool data_transfer_layersmapping_cdlayers(ListBase *r_map, CustomData_add_layer_named(cd_dst, cddata_type, CD_CALLOC, NULL, num_elem_dst, name); idx_dst = CustomData_get_named_layer(cd_dst, cddata_type, name); } - /* If dest is a evaluated mesh (from modifier), we do not want to overwrite cdlayers of orig mesh! */ + /* If dest is a evaluated mesh (from modifier), + * we do not want to overwrite cdlayers of orig mesh! */ if (use_dupref_dst && r_map) { data_dst = CustomData_duplicate_referenced_layer_n( cd_dst, cddata_type, idx_dst, num_elem_dst); @@ -1002,7 +1014,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, return ret; } else if (cddata_type == CD_FAKE_SHAPEKEY) { - /* TODO: leaving shapekeys aside for now, quite specific case, since we can't access them from MVert :/ */ + /* TODO: leaving shapekeys aside for now, quite specific case, + * since we can't access them from MVert :/ */ return false; } } @@ -1127,7 +1140,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, cddata_type = CD_MLOOPUV; } else if (cddata_type == CD_FAKE_LNOR) { - /* Preprocess should have generated it, Postprocess will convert it back to CD_CUSTOMLOOPNORMAL. */ + /* Pre-process should have generated it, + * Post-process will convert it back to CD_CUSTOMLOOPNORMAL. */ cddata_type = CD_NORMAL; interp_data = space_transform; interp = customdata_data_transfer_interp_normal_normals; @@ -1224,8 +1238,8 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, /** * Transfer data *layout* of selected types from source to destination object. * By default, it only creates new data layers if needed on \a ob_dst. - * If \a use_delete is true, it will also delete data layers on \a ob_dst that do not match those from \a ob_src, - * to get (as much as possible) exact copy of source data layout. + * If \a use_delete is true, it will also delete data layers on \a ob_dst that do not match those + * from \a ob_src, to get (as much as possible) exact copy of source data layout. */ void BKE_object_data_transfer_layout(struct Depsgraph *depsgraph, Scene *scene, diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c index 57ab0a9c94e..a964cab3fa5 100644 --- a/source/blender/blenkernel/intern/deform.c +++ b/source/blender/blenkernel/intern/deform.c @@ -646,11 +646,11 @@ float defvert_array_find_weight_safe(const struct MDeformVert *dvert, const int index, const int defgroup) { - /* Invalid defgroup index means the vgroup selected is invalid, does not exist, in that case it is OK to return 1.0 + /* Invalid defgroup index means the vgroup selected is invalid, + * does not exist, in that case it is OK to return 1.0 * (i.e. maximum weight, as if no vgroup was selected). * But in case of valid defgroup and NULL dvert data pointer, it means that vgroup **is** valid, - * and just totally empty, so we shall return '0.0' value then! - */ + * and just totally empty, so we shall return '0.0' value then! */ if (defgroup == -1) { return 1.0f; } @@ -1124,7 +1124,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map, /* Find last source actually used! */ idx_src = num_layers_src; while (idx_src-- && !use_layers_src[idx_src]) { - ; + /* pass */ } idx_src++; @@ -1258,12 +1258,13 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map, const size_t elem_size = sizeof(*((MDeformVert *)NULL)); - /* Note: VGroups are a bit hairy, since their layout is defined on object level (ob->defbase), while their actual - * data is a (mesh) CD layer. - * This implies we may have to handle data layout itself while having NULL data itself, - * and even have to support NULL data_src in transfer data code (we always create a data_dst, though). + /* Note: + * VGroups are a bit hairy, since their layout is defined on object level (ob->defbase), + * while their actual data is a (mesh) CD layer. + * This implies we may have to handle data layout itself while having NULL data itself, + * and even have to support NULL data_src in transfer data code + * (we always create a data_dst, though). */ - if (BLI_listbase_is_empty(&ob_src->defbase)) { if (use_delete) { BKE_object_defgroup_remove_all(ob_dst); diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index e3ee28ed022..c228595b6e8 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -1028,7 +1028,10 @@ static void curve_calc_modifiers_post(Depsgraph *depsgraph, } /* If we need normals, no choice, have to convert to mesh now. */ - if (mti->dependsOnNormals != NULL && mti->dependsOnNormals(md) && modified == NULL) { + bool need_normal = mti->dependsOnNormals != NULL && mti->dependsOnNormals(md); + /* XXX 2.8 : now that batch cache is stored inside the ob->data + * we need to create a Mesh for each curve that uses modifiers. */ + if (modified == NULL /* && need_normal */) { if (vertCos != NULL) { displist_apply_allverts(dispbase, vertCos); } @@ -1046,7 +1049,7 @@ static void curve_calc_modifiers_post(Depsgraph *depsgraph, if (!vertCos) { vertCos = BKE_mesh_vertexCos_get(modified, &totvert); } - if (mti->dependsOnNormals != NULL && mti->dependsOnNormals(md)) { + if (need_normal) { BKE_mesh_ensure_normals(modified); } mti->deformVerts(md, &mectx_deform, modified, vertCos, totvert); @@ -1095,7 +1098,7 @@ static void curve_calc_modifiers_post(Depsgraph *depsgraph, vertCos = NULL; } - if (mti->dependsOnNormals != NULL && mti->dependsOnNormals(md)) { + if (need_normal) { BKE_mesh_ensure_normals(modified); } mesh_applied = mti->applyModifier(md, &mectx_apply, modified); diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 7fef07346c3..93b6fd34a8f 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -153,12 +153,17 @@ typedef struct Bounds3D { typedef struct VolumeGrid { int dim[3]; - Bounds3D grid_bounds; /* whole grid bounds */ - - Bounds3D *bounds; /* (x*y*z) precalculated grid cell bounds */ - int *s_pos; /* (x*y*z) t_index begin id */ - int *s_num; /* (x*y*z) number of t_index points */ - int *t_index; /* actual surface point index, access: (s_pos + s_num) */ + /** whole grid bounds */ + Bounds3D grid_bounds; + + /** (x*y*z) precalculated grid cell bounds */ + Bounds3D *bounds; + /** (x*y*z) t_index begin id */ + int *s_pos; + /** (x*y*z) number of t_index points */ + int *s_num; + /** actual surface point index, access: (s_pos + s_num) */ + int *t_index; int *temp_t_index; } VolumeGrid; @@ -168,51 +173,67 @@ typedef struct Vec3f { } Vec3f; typedef struct BakeAdjPoint { - float dir[3]; /* vector pointing towards this neighbor */ - float dist; /* distance to */ + /** vector pointing towards this neighbor */ + float dir[3]; + /** distance to */ + float dist; } BakeAdjPoint; -/* Surface data used while processing a frame */ +/** Surface data used while processing a frame */ typedef struct PaintBakeNormal { - float invNorm[3]; /* current pixel world-space inverted normal */ - float normal_scale; /* normal directional scale for displace mapping */ + /** current pixel world-space inverted normal */ + float invNorm[3]; + /** normal directional scale for displace mapping */ + float normal_scale; } PaintBakeNormal; -/* Temp surface data used to process a frame */ +/** Temp surface data used to process a frame */ typedef struct PaintBakeData { /* point space data */ PaintBakeNormal *bNormal; - int *s_pos; /* index to start reading point sample realCoord */ - int *s_num; /* num of realCoord samples */ - Vec3f * - realCoord; /* current pixel center world-space coordinates for each sample ordered as (s_pos + s_num) */ + /** index to start reading point sample realCoord */ + int *s_pos; + /** num of realCoord samples */ + int *s_num; + /** current pixel center world-space coordinates for each sample ordered as (s_pos + s_num) */ + Vec3f *realCoord; Bounds3D mesh_bounds; float dim[3]; /* adjacency info */ - BakeAdjPoint *bNeighs; /* current global neighbor distances and directions, if required */ + /** current global neighbor distances and directions, if required */ + BakeAdjPoint *bNeighs; double average_dist; /* space partitioning */ - VolumeGrid *grid; /* space partitioning grid to optimize brush checks */ + /** space partitioning grid to optimize brush checks */ + VolumeGrid *grid; /* velocity and movement */ - Vec3f *velocity; /* speed vector in global space movement per frame, if required */ + /** speed vector in global space movement per frame, if required */ + Vec3f *velocity; Vec3f *prev_velocity; - float *brush_velocity; /* special temp data for post-p velocity based brushes like smudge - * 3 float dir vec + 1 float str */ - MVert *prev_verts; /* copy of previous frame vertices. used to observe surface movement */ - float prev_obmat[4][4]; /* previous frame object matrix */ - int clear; /* flag to check if surface was cleared/reset -> have to redo velocity etc. */ + /** special temp data for post-p velocity based brushes like smudge + * 3 float dir vec + 1 float str */ + float *brush_velocity; + /** copy of previous frame vertices. used to observe surface movement. */ + MVert *prev_verts; + /** Previous frame object matrix. */ + float prev_obmat[4][4]; + /** flag to check if surface was cleared/reset -> have to redo velocity etc. */ + int clear; } PaintBakeData; -/* UV Image sequence format point */ +/** UV Image sequence format point */ typedef struct PaintUVPoint { /* Pixel / mesh data */ - unsigned int tri_index, pixel_index; /* tri index on domain derived mesh */ - unsigned int v1, v2, v3; /* vertex indexes */ - - unsigned int - neighbour_pixel; /* If this pixel isn't uv mapped to any face, but it's neighboring pixel is */ + /** tri index on domain derived mesh */ + unsigned int tri_index; + unsigned int pixel_index; + /* vertex indexes */ + unsigned int v1, v2, v3; + + /** If this pixel isn't uv mapped to any face, but it's neighboring pixel is. */ + unsigned int neighbour_pixel; } PaintUVPoint; typedef struct ImgSeqFormatData { @@ -225,14 +246,20 @@ typedef struct ImgSeqFormatData { #define ADJ_BORDER_PIXEL (1 << 1) typedef struct PaintAdjData { - int * - n_target; /* array of neighboring point indexes, for single sample use (n_index + neigh_num) */ - int *n_index; /* index to start reading n_target for each point */ - int *n_num; /* num of neighs for each point */ - int *flags; /* vertex adjacency flags */ - int total_targets; /* size of n_target */ - int *border; /* indices of border pixels (only for texture paint) */ - int total_border; /* size of border */ + /** Array of neighboring point indexes, for single sample use (n_index + neigh_num). */ + int *n_target; + /** Index to start reading n_target for each point. */ + int *n_index; + /** Num of neighs for each point. */ + int *n_num; + /** Vertex adjacency flags. */ + int *flags; + /** Size of n_target. */ + int total_targets; + /** Indices of border pixels (only for texture paint). */ + int *border; + /** Size of border. */ + int total_border; } PaintAdjData; /************************* Runtime evaluation store ***************************/ @@ -302,56 +329,12 @@ static int dynamicPaint_surfaceNumOfPoints(DynamicPaintSurface *surface) return 0; } -/* checks whether surface's format/type has realtime preview */ -bool dynamicPaint_surfaceHasColorPreview(DynamicPaintSurface *surface) -{ - if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ) { - return false; - } - else if (surface->format == MOD_DPAINT_SURFACE_F_VERTEX) { - return !ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE); - } - - return true; -} - /* get currently active surface (in user interface) */ DynamicPaintSurface *get_activeSurface(DynamicPaintCanvasSettings *canvas) { return BLI_findlink(&canvas->surfaces, canvas->active_sur); } -/* set preview to first previewable surface */ -void dynamicPaint_resetPreview(DynamicPaintCanvasSettings *canvas) -{ - DynamicPaintSurface *surface = canvas->surfaces.first; - bool done = false; - - for (; surface; surface = surface->next) { - if (!done && dynamicPaint_surfaceHasColorPreview(surface)) { - surface->flags |= MOD_DPAINT_PREVIEW; - done = true; - } - else { - surface->flags &= ~MOD_DPAINT_PREVIEW; - } - } -} - -/* set preview to defined surface */ -static void dynamicPaint_setPreview(DynamicPaintSurface *t_surface) -{ - DynamicPaintSurface *surface = t_surface->canvas->surfaces.first; - for (; surface; surface = surface->next) { - if (surface == t_surface) { - surface->flags |= MOD_DPAINT_PREVIEW; - } - else { - surface->flags &= ~MOD_DPAINT_PREVIEW; - } - } -} - bool dynamicPaint_outputLayerExists(struct DynamicPaintSurface *surface, Object *ob, int output) { const char *name; @@ -471,14 +454,6 @@ void dynamicPaintSurface_updateType(struct DynamicPaintSurface *surface) } surface_setUniqueOutputName(surface, surface->output_name, 0); - - /* update preview */ - if (dynamicPaint_surfaceHasColorPreview(surface)) { - dynamicPaint_setPreview(surface); - } - else { - dynamicPaint_resetPreview(surface->canvas); - } } static int surface_totalSamples(DynamicPaintSurface *surface) @@ -1079,8 +1054,8 @@ DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *c /* Set initial values */ surface->flags = MOD_DPAINT_ANTIALIAS | MOD_DPAINT_MULALPHA | MOD_DPAINT_DRY_LOG | - MOD_DPAINT_DISSOLVE_LOG | MOD_DPAINT_ACTIVE | MOD_DPAINT_PREVIEW | - MOD_DPAINT_OUT1 | MOD_DPAINT_USE_DRYING; + MOD_DPAINT_DISSOLVE_LOG | MOD_DPAINT_ACTIVE | MOD_DPAINT_OUT1 | + MOD_DPAINT_USE_DRYING; surface->effect = 0; surface->effect_ui = 1; @@ -1280,7 +1255,6 @@ void dynamicPaint_Modifier_copy(const struct DynamicPaintModifierData *pmd, t_surface->disp_type = surface->disp_type; t_surface->image_fileformat = surface->image_fileformat; t_surface->effect_ui = surface->effect_ui; - t_surface->preview_id = surface->preview_id; t_surface->init_color_type = surface->init_color_type; t_surface->flags = surface->flags; t_surface->effect = surface->effect; @@ -1323,7 +1297,6 @@ void dynamicPaint_Modifier_copy(const struct DynamicPaintModifierData *pmd, BLI_strncpy(t_surface->output_name, surface->output_name, sizeof(t_surface->output_name)); BLI_strncpy(t_surface->output_name2, surface->output_name2, sizeof(t_surface->output_name2)); } - dynamicPaint_resetPreview(tpmd->canvas); } else if (tpmd->brush) { DynamicPaintBrushSettings *brush = pmd->brush, *t_brush = tpmd->brush; @@ -1841,7 +1814,6 @@ typedef struct DynamicPaintModifierApplyData { float (*fcolor)[4]; MLoopCol *mloopcol; MLoopCol *mloopcol_wet; - MLoopCol *mloopcol_preview; } DynamicPaintModifierApplyData; static void dynamic_paint_apply_surface_displace_cb(void *__restrict userdata, @@ -1906,7 +1878,6 @@ static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, const ParallelRangeTLS *__restrict UNUSED(tls)) { const DynamicPaintModifierApplyData *data = userdata; - Object *ob = data->ob; const MLoop *mloop = data->mloop; const MPoly *mpoly = data->mpoly; @@ -1917,11 +1888,6 @@ static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, MLoopCol *mloopcol = data->mloopcol; MLoopCol *mloopcol_wet = data->mloopcol_wet; - MLoopCol *mloopcol_preview = data->mloopcol_preview; - - const Material *material = mloopcol_preview ? - give_current_material(ob, mpoly[p_index].mat_nr + 1) : - NULL; for (int j = 0; j < mpoly[p_index].totloop; j++) { const int l_index = mpoly[p_index].loopstart + j; @@ -1940,37 +1906,6 @@ static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, mloopcol_wet[l_index].b = c; mloopcol_wet[l_index].a = 255; } - - /* viewport preview */ - if (mloopcol_preview) { - if (surface->preview_id == MOD_DPAINT_SURFACE_PREV_PAINT) { - float c[3]; - - /* Apply material color as base vertex color for preview */ - mloopcol_preview[l_index].a = 255; - if (material) { - c[0] = material->r; - c[1] = material->g; - c[2] = material->b; - } - else { /* default gray */ - c[0] = 0.65f; - c[1] = 0.65f; - c[2] = 0.65f; - } - /* mix surface color */ - interp_v3_v3v3(c, c, fcolor[v_index], fcolor[v_index][3]); - - rgb_float_to_uchar((unsigned char *)&mloopcol_preview[l_index].r, c); - } - else { - const char c = unit_float_to_uchar_clamp(pPoint[v_index].wetness); - mloopcol_preview[l_index].r = c; - mloopcol_preview[l_index].g = c; - mloopcol_preview[l_index].b = c; - mloopcol_preview[l_index].a = 255; - } - } } } @@ -2056,22 +1991,11 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * &result->ldata, CD_MLOOPCOL, CD_CALLOC, NULL, totloop, surface->output_name2); } - /* Save preview results to weight layer to be able to share same drawing methods */ - MLoopCol *mloopcol_preview = NULL; - if (surface->flags & MOD_DPAINT_PREVIEW) { - mloopcol_preview = CustomData_get_layer(&result->ldata, CD_PREVIEW_MLOOPCOL); - if (!mloopcol_preview) { - mloopcol_preview = CustomData_add_layer( - &result->ldata, CD_PREVIEW_MLOOPCOL, CD_CALLOC, NULL, totloop); - } - } - data.ob = ob; data.mloop = mloop; data.mpoly = mpoly; data.mloopcol = mloopcol; data.mloopcol_wet = mloopcol_wet; - data.mloopcol_preview = mloopcol_preview; { ParallelRangeSettings settings; @@ -2084,7 +2008,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * MEM_freeN(fcolor); /* Mark tessellated CD layers as dirty. */ - //result->dirty |= DM_DIRTY_TESS_CDLAYERS; + // result->dirty |= DM_DIRTY_TESS_CDLAYERS; } /* vertex group paint */ else if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { @@ -2092,15 +2016,6 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * MDeformVert *dvert = CustomData_get_layer(&result->vdata, CD_MDEFORMVERT); float *weight = (float *)sData->type_data; - /* viewport preview */ - if (surface->flags & MOD_DPAINT_PREVIEW) { - /* Save preview results to weight layer to be - * able to share same drawing methods. - * Note this func also sets DM_DIRTY_TESS_CDLAYERS flag! */ - //TODO port this function - //DM_update_weight_mcol(ob, result, 0, weight, 0, NULL); - } - /* apply weights into a vertex group, if doesn't exists add a new layer */ if (defgrp_index != -1 && !dvert && (surface->output_name[0] != '\0')) { dvert = CustomData_add_layer( @@ -2151,7 +2066,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * } if (update_normals) { - //result->dirty |= DM_DIRTY_NORMALS; + // result->dirty |= DM_DIRTY_NORMALS; } } /* make a copy of mesh to use as brush data */ @@ -2303,11 +2218,11 @@ Mesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, } } -/***************************** Image Sequence / UV Image Surface Calls ******************************/ +/* -------------------------------------------------------------------- */ +/** \name Image Sequence / UV Image Surface Calls + * \{ */ -/* - * Create a surface for uv image sequence format - */ +/* Create a surface for uv image sequence format. */ #define JITTER_SAMPLES \ { \ 0.0f, 0.0f, -0.2f, -0.4f, 0.2f, 0.4f, 0.4f, -0.2f, -0.4f, 0.3f, \ @@ -2585,7 +2500,8 @@ static int dynamic_paint_find_neighbour_pixel(const DynamicPaintCreateUVSurfaceD const PaintUVPoint *tPoint = &tempPoints[x + w * y]; /* UV neighbor */ const PaintUVPoint *cPoint = &tempPoints[px + w * py]; /* Origin point */ - /* Check if shifted point is on same face -> it's a correct neighbor (and if it isn't marked as an "edge pixel") */ + /* Check if shifted point is on same face -> it's a correct neighbor + * (and if it isn't marked as an "edge pixel") */ if ((tPoint->tri_index == cPoint->tri_index) && (tPoint->neighbour_pixel == -1)) { return (x + w * y); } @@ -2680,7 +2596,8 @@ static void dynamic_paint_find_island_border(const DynamicPaintCreateUVSurfaceDa const int vert0 = mloop[loop_idx[(edge_idx + 0)]].v; const int vert1 = mloop[loop_idx[(edge_idx + 1) % 3]].v; - /* Use a pre-computed vert-to-looptri mapping, speeds up things a lot compared to looping over all loopti. */ + /* Use a pre-computed vert-to-looptri mapping, + * speeds up things a lot compared to looping over all loopti. */ const MeshElemMap *map = &bdata->vert_to_looptri_map[vert0]; bool found_other = false; @@ -2822,7 +2739,8 @@ static bool dynamicPaint_pointHasNeighbor(PaintAdjData *ed, int index, int neigh return false; } -/* Makes the adjacency data symmetric, except for border pixels. I.e. if A is neighbor of B, B is neighbor of A. */ +/* Makes the adjacency data symmetric, except for border pixels. + * I.e. if A is neighbor of B, B is neighbor of A. */ static bool dynamicPaint_symmetrizeAdjData(PaintAdjData *ed, int active_points) { int *new_n_index = MEM_callocN(sizeof(int) * active_points, "Surface Adj Index"); @@ -3112,7 +3030,8 @@ int dynamicPaint_createUVSurface(Scene *scene, } for (int i = 0; i < 8; i++) { - /* Try to find a neighboring pixel in defined direction. If not found, -1 is returned */ + /* Try to find a neighboring pixel in defined direction. + * If not found, -1 is returned */ const int n_target = dynamic_paint_find_neighbour_pixel( &data, vert_to_looptri_map, w, h, tx, ty, i); @@ -3522,10 +3441,13 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, IMB_freeImBuf(ibuf); } +/** \} */ + /***************************** Ray / Nearest Point Utils ******************************/ -/* A modified callback to bvh tree raycast. The tree must have been built using bvhtree_from_mesh_looptri. - * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. +/* A modified callback to bvh tree raycast. + * The tree must have been built using bvhtree_from_mesh_looptri. + * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. * * To optimize brush detection speed this doesn't calculate hit coordinates or normal. */ @@ -3555,7 +3477,8 @@ static void mesh_tris_spherecast_dp(void *userdata, } } -/* A modified callback to bvh tree nearest point. The tree must have been built using bvhtree_from_mesh_looptri. +/* A modified callback to bvh tree nearest point. + * The tree must have been built using bvhtree_from_mesh_looptri. * userdata must be a BVHMeshCallbackUserdata built from the same mesh as the tree. * * To optimize brush detection speed this doesn't calculate hit normal. @@ -4960,7 +4883,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, cons 0, sData->total_points, sData, dynamic_paint_prepare_adjacency_cb, &settings); /* calculate average values (single thread). - * Note: tried to put this in threaded callback (using _finalize feature), but gave ~30% slower result! */ + * Note: tried to put this in threaded callback (using _finalize feature), + * but gave ~30% slower result! */ bData->average_dist = 0.0; for (index = 0; index < sData->total_points; index++) { int numOfNeighs = adj_data->n_num[index]; @@ -4972,7 +4896,8 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, cons bData->average_dist /= adj_data->total_targets; } -/* find two adjacency points (closest_id) and influence (closest_d) to move paint towards when affected by a force */ +/* Find two adjacency points (closest_id) and influence (closest_d) + * to move paint towards when affected by a force. */ static void surface_determineForceTargetPoints(const PaintSurfaceData *sData, const int index, const float force[3], @@ -5462,13 +5387,13 @@ static void dynamic_paint_effect_drip_cb(void *__restrict userdata, const unsigned int n_trgt = (unsigned int)n_target[n_idx]; /* Sort of spinlock, but only for given ePoint. - * Since the odds a same ePoint is modified at the same time by several threads is very low, this is - * much more efficient than a global spin lock. */ + * Since the odds a same ePoint is modified at the same time by several threads is very low, + * this is much more efficient than a global spin lock. */ const unsigned int epointlock_idx = n_trgt / 8; const uint8_t epointlock_bitmask = 1 << (n_trgt & 7); /* 7 == 0b111 */ while (atomic_fetch_and_or_uint8(&point_locks[epointlock_idx], epointlock_bitmask) & epointlock_bitmask) { - ; + /* pass */ } PaintPoint *ePoint = &((PaintPoint *)sData->type_data)[n_trgt]; @@ -5494,8 +5419,8 @@ static void dynamic_paint_effect_drip_cb(void *__restrict userdata, CLAMP_MAX(ePoint->e_color[3], pPoint_prev->e_color[3]); } - /* Decrease paint wetness on current point - * (just store diff here, that way we can only lock current point once at the end to apply it). */ + /* Decrease paint wetness on current point (just store diff here, + * that way we can only lock current point once at the end to apply it). */ ppoint_wetness_diff += (ePoint->wetness - e_wet); #ifndef NDEBUG @@ -5515,7 +5440,7 @@ static void dynamic_paint_effect_drip_cb(void *__restrict userdata, const uint8_t ppointlock_bitmask = 1 << (index & 7); /* 7 == 0b111 */ while (atomic_fetch_and_or_uint8(&point_locks[ppointlock_idx], ppointlock_bitmask) & ppointlock_bitmask) { - ; + /* pass */ } pPoint->wetness -= ppoint_wetness_diff; @@ -5923,10 +5848,10 @@ static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, /* reduce wet layer alpha by dry factor */ pPoint->e_color[3] *= dry_ratio; - /* now calculate new alpha for dry layer that keeps final blended color unchanged */ + /* Now calculate new alpha for dry layer that keeps final blended color unchanged. */ pPoint->color[3] = (f_color[3] - pPoint->e_color[3]) / (1.0f - pPoint->e_color[3]); - /* for each rgb component, calculate a new dry layer color that keeps the final blend color - * with these new alpha values. (wet layer color doesn't change)*/ + /* For each rgb component, calculate a new dry layer color that keeps the final blend + * color with these new alpha values. (wet layer color doesn't change). */ if (pPoint->color[3]) { for (i = 0; i < 3; i++) { pPoint->color[i] = (f_color[i] * f_color[3] - diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 794b1d669d2..06f297b23e0 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -399,7 +399,7 @@ static void statvis_calc_sharp(BMEditMesh *em, BMIter iter; BMesh *bm = em->bm; BMEdge *e; - //float f_no[3]; + // float f_no[3]; const float minmax_irange = 1.0f / (max - min); int i; diff --git a/source/blender/blenkernel/intern/editmesh.c b/source/blender/blenkernel/intern/editmesh.c index 12f70eed2c6..130f4ae88f1 100644 --- a/source/blender/blenkernel/intern/editmesh.c +++ b/source/blender/blenkernel/intern/editmesh.c @@ -233,11 +233,11 @@ void BKE_editmesh_lnorspace_update(BMEditMesh *em) BMesh *bm = em->bm; /* We need to create clnors data if none exist yet, otherwise there is no way to edit them. - * Similar code to MESH_OT_customdata_custom_splitnormals_add operator, we want to keep same shading - * in case we were using autosmooth so far... - * Note: there is a problem here, which is that if someone starts a normal editing operation on previously - * autosmooth-ed mesh, and cancel that operation, generated clnors data remain, with related sharp edges - * (and hence autosmooth is 'lost'). + * Similar code to MESH_OT_customdata_custom_splitnormals_add operator, + * we want to keep same shading in case we were using autosmooth so far. + * Note: there is a problem here, which is that if someone starts a normal editing operation on + * previously autosmooth-ed mesh, and cancel that operation, generated clnors data remain, + * with related sharp edges (and hence autosmooth is 'lost'). * Not sure how critical this is, and how to fix that issue? */ if (!CustomData_has_layer(&bm->ldata, CD_CUSTOMLOOPNORMAL)) { Mesh *me = em->ob->data; diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c index 6a644b2ed4b..df2fb8c8348 100644 --- a/source/blender/blenkernel/intern/editmesh_tangent.c +++ b/source/blender/blenkernel/intern/editmesh_tangent.c @@ -104,7 +104,7 @@ static void emdm_ts_GetPosition(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData; const BMLoop **lt; const BMLoop *l; @@ -138,7 +138,7 @@ static void emdm_ts_GetTextureCoordinate(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData; const BMLoop **lt; const BMLoop *l; @@ -176,7 +176,7 @@ static void emdm_ts_GetNormal(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData; const BMLoop **lt; const BMLoop *l; @@ -221,7 +221,7 @@ static void emdm_ts_SetTSpace(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData; const BMLoop **lt; const BMLoop *l; @@ -276,7 +276,8 @@ static void emDM_calc_loop_tangents_thread(TaskPool *__restrict UNUSED(pool), /** * \see #BKE_mesh_calc_loop_tangent, same logic but used arrays instead of #BMesh data. * - * \note This function is not so normal, its using `bm->ldata` as input, but output's to `dm->loopData`. + * \note This function is not so normal, its using `bm->ldata` as input, + * but output's to `dm->loopData`. * This is done because #CD_TANGENT is cache data used only for drawing. */ void BKE_editmesh_loop_tangent_calc(BMEditMesh *em, @@ -382,9 +383,8 @@ void BKE_editmesh_loop_tangent_calc(BMEditMesh *em, mesh2tangent->num_face_as_quad_map = num_face_as_quad_map; #endif mesh2tangent->precomputedFaceNormals = poly_normals; - /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled), - * have to check this is valid... - */ + /* Note, we assume we do have tessellated loop normals at this point + * (in case it is object-enabled), have to check this is valid. */ mesh2tangent->precomputedLoopNormals = loop_normals; mesh2tangent->cd_loop_uv_offset = CustomData_get_n_offset(&bm->ldata, CD_MLOOPUV, n); diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c index 1105d210e13..51715c3a223 100644 --- a/source/blender/blenkernel/intern/effect.c +++ b/source/blender/blenkernel/intern/effect.c @@ -646,8 +646,8 @@ int get_effector_data(EffectorCache *eff, float cfra = DEG_get_ctime(eff->depsgraph); int ret = 0; - /* In case surface object is in Edit mode when loading the .blend, surface modifier is never executed - * and bvhtree never built, see T48415. */ + /* In case surface object is in Edit mode when loading the .blend, + * surface modifier is never executed and bvhtree never built, see T48415. */ if (eff->pd && eff->pd->shape == PFIELD_SHAPE_SURFACE && eff->surmd && eff->surmd->bvhtree) { /* closest point in the object surface is an effector */ float vec[3]; @@ -698,7 +698,7 @@ int get_effector_data(EffectorCache *eff, ret = psys_get_particle_state(&sim, *efd->index, &state, 0); /* TODO */ - //if (eff->pd->forcefiled == PFIELD_HARMONIC && ret==0) { + // if (eff->pd->forcefiled == PFIELD_HARMONIC && ret==0) { // if (pa->dietime < eff->psys->cfra) // eff->flag |= PE_VELOCITY_TO_IMPULSE; //} @@ -750,7 +750,8 @@ int get_effector_data(EffectorCache *eff, sub_v3_v3v3(efd->vec_to_point, point->loc, efd->loc); efd->distance = len_v3(efd->vec_to_point); - /* rest length for harmonic effector, will have to see later if this could be extended to other effectors */ + /* Rest length for harmonic effector, + * will have to see later if this could be extended to other effectors. */ if (eff->pd && eff->pd->forcefield == PFIELD_HARMONIC && eff->pd->f_size) { mul_v3_fl(efd->vec_to_point, (efd->distance - eff->pd->f_size) / efd->distance); } diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index f4ac586d9c4..8c95e4c7ff3 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -230,7 +230,8 @@ FCurve *id_data_find_fcurve( return fcu; } -/* Find the F-Curve affecting the given RNA-access path + index, in the list of F-Curves provided */ +/* Find the F-Curve affecting the given RNA-access path + index, + * in the list of F-Curves provided. */ FCurve *list_find_fcurve(ListBase *list, const char rna_path[], const int array_index) { FCurve *fcu; @@ -277,7 +278,10 @@ FCurve *iter_step_fcurve(FCurve *fcu_iter, const char rna_path[]) return NULL; } -/* Get list of LinkData's containing pointers to the F-Curves which control the types of data indicated +/** + * Get list of LinkData's containing pointers to the F-Curves + * which control the types of data indicated. + * * Lists... * - dst: list of LinkData's matching the criteria returned. * List must be freed after use, and is assumed to be empty when passed. @@ -380,9 +384,9 @@ FCurve *rna_get_fcurve_context_ui(bContext *C, /* there must be some RNA-pointer + property combon */ if (prop && tptr.id.data && RNA_property_animateable(&tptr, prop)) { AnimData *adt = BKE_animdata_from_id(tptr.id.data); - int step = - C ? 2 : - 1; /* Always 1 in case we have no context (can't check in 'ancestors' of given RNA ptr). */ + int step = ( + /* Always 1 in case we have no context (can't check in 'ancestors' of given RNA ptr). */ + C ? 2 : 1); char *path = NULL; if (!adt && C) { @@ -451,7 +455,8 @@ FCurve *rna_get_fcurve_context_ui(bContext *C, /* ----------------- Finding Keyframes/Extents -------------------------- */ -/* Binary search algorithm for finding where to insert BezTriple, with optional argument for precision required. +/* Binary search algorithm for finding where to insert BezTriple, + * with optional argument for precision required. * Returns the index to insert at (data already at that index will be offset if replace is 0) */ static int binarysearch_bezt_index_ex( @@ -648,8 +653,8 @@ bool calc_fcurve_bounds(FCurve *fcu, if (include_handles) { /* left handle - only if applicable - * NOTE: for the very first keyframe, the left handle actually has no bearings on anything - */ + * NOTE: for the very first keyframe, + * the left handle actually has no bearings on anything. */ if (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ)) { yminv = min_ff(yminv, bezt->vec[0][1]); ymaxv = max_ff(ymaxv, bezt->vec[0][1]); @@ -999,13 +1004,15 @@ eFCU_Cycle_Type BKE_fcurve_get_cycle_type(FCurve *fcu) return FCU_CYCLE_NONE; } -/* Checks if the F-Curve has a Cycles modifier with simple settings that warrant transition smoothing */ +/* Checks if the F-Curve has a Cycles modifier with simple settings + * that warrant transition smoothing. */ bool BKE_fcurve_is_cyclic(FCurve *fcu) { return BKE_fcurve_get_cycle_type(fcu) != FCU_CYCLE_NONE; } -/* Shifts 'in' by the difference in coordinates between 'to' and 'from', using 'out' as the output buffer. +/* Shifts 'in' by the difference in coordinates between 'to' and 'from', + * using 'out' as the output buffer. * When 'to' and 'from' are end points of the loop, this moves the 'in' point one loop cycle. */ static BezTriple *cycle_offset_triple( @@ -1240,7 +1247,10 @@ static ID *dtar_id_ensure_proxy_from(ID *id) return id; } -/* Helper function to obtain a value using RNA from the specified source (for evaluating drivers) */ +/** + * Helper function to obtain a value using RNA from the specified source + * (for evaluating drivers). + */ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar) { PointerRNA id_ptr, ptr; @@ -1879,12 +1889,14 @@ void driver_variable_name_validate(DriverVar *dvar) } /* 1) Must start with a letter */ - /* XXX: We assume that valid unicode letters in other languages are ok too, hence the blacklisting */ + /* XXX: We assume that valid unicode letters in other languages are ok too, + * hence the blacklisting. */ if (IN_RANGE_INCL(dvar->name[0], '0', '9')) { dvar->flag |= DVAR_FLAG_INVALID_START_NUM; } else if (dvar->name[0] == '_') { - /* NOTE: We don't allow names to start with underscores (i.e. it helps when ruling out security risks) */ + /* NOTE: We don't allow names to start with underscores + * (i.e. it helps when ruling out security risks) */ dvar->flag |= DVAR_FLAG_INVALID_START_CHAR; } @@ -1984,7 +1996,8 @@ void fcurve_free_driver(FCurve *fcu) BLI_expr_pylike_free(driver->expr_simple); - /* free driver itself, then set F-Curve's point to this to NULL (as the curve may still be used) */ + /* Free driver itself, then set F-Curve's point to this to NULL + * (as the curve may still be used). */ MEM_freeN(driver); fcu->driver = NULL; } @@ -2005,9 +2018,9 @@ ChannelDriver *fcurve_copy_driver(const ChannelDriver *driver) ndriver->expr_simple = NULL; /* copy variables */ - BLI_listbase_clear( - &ndriver - ->variables); /* to get rid of refs to non-copied data (that's still used on original) */ + + /* to get rid of refs to non-copied data (that's still used on original) */ + BLI_listbase_clear(&ndriver->variables); driver_variables_copy(&ndriver->variables, &driver->variables); /* return the new driver */ @@ -2603,15 +2616,14 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime /* Use binary search to find appropriate keyframes... * * The threshold here has the following constraints: - * - 0.001 is too coarse -> We get artifacts with 2cm driver movements at 1BU = 1m (see T40332) - * - 0.00001 is too fine -> Weird errors, like selecting the wrong keyframe range (see T39207), occur. - * This lower bound was established in b888a32eee8147b028464336ad2404d8155c64dd + * - 0.001 is too coarse: + * We get artifacts with 2cm driver movements at 1BU = 1m (see T40332) + * + * - 0.00001 is too fine: + * Weird errors, like selecting the wrong keyframe range (see T39207), occur. + * This lower bound was established in b888a32eee8147b028464336ad2404d8155c64dd. */ a = binarysearch_bezt_index_ex(bezts, evaltime, fcu->totvert, 0.0001, &exact); - if (G.debug & G_DEBUG) { - printf( - "eval fcurve '%s' - %f => %u/%u, %d\n", fcu->rna_path, evaltime, a, fcu->totvert, exact); - } if (exact) { /* index returned must be interpreted differently when it sits on top of an existing keyframe @@ -2628,7 +2640,8 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime prevbezt = (a > 0) ? (bezt - 1) : bezt; } - /* use if the key is directly on the frame, rare cases this is needed else we get 0.0 instead. */ + /* use if the key is directly on the frame, + * rare cases this is needed else we get 0.0 instead. */ /* XXX: consult T39207 for examples of files where failure of these checks can cause issues */ if (exact) { cvalue = prevbezt->vec[1][1]; @@ -3013,9 +3026,9 @@ float evaluate_fcurve_driver(PathResolvedRNA *anim_rna, BLI_assert(fcu->driver != NULL); float cvalue = 0.0f; - /* if there is a driver (only if this F-Curve is acting as 'driver'), evaluate it to find value to use as "evaltime" - * since drivers essentially act as alternative input (i.e. in place of 'time') for F-Curves - */ + /* If there is a driver (only if this F-Curve is acting as 'driver'), + * evaluate it to find value to use as "evaltime" since drivers essentially act as alternative + * input (i.e. in place of 'time') for F-Curves. */ if (fcu->driver) { /* evaltime now serves as input for the curve */ evaltime = evaluate_driver(anim_rna, fcu->driver, driver_orig, evaltime); @@ -3032,12 +3045,12 @@ float evaluate_fcurve_driver(PathResolvedRNA *anim_rna, /* if there are range-restrictions, we must definitely block [#36950] */ if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) == 0 || ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime))) { - /* within range: here it probably doesn't matter, though we'd want to check on additive... */ + /* Within range: here it probably doesn't matter, + * though we'd want to check on additive. */ } else { - /* outside range: modifier shouldn't contribute to the curve here, though it does in other areas, - * so neither should the driver! - */ + /* Outside range: modifier shouldn't contribute to the curve here, + * though it does in other areas, so neither should the driver! */ do_linear = false; } } diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c index 79808d20193..c6188642e41 100644 --- a/source/blender/blenkernel/intern/fmodifier.c +++ b/source/blender/blenkernel/intern/fmodifier.c @@ -95,8 +95,10 @@ static FModifierTypeInfo FMI_MODNAME = { /* Generators available: * 1) simple polynomial generator: - * - Expanded form - (y = C[0]*(x^(n)) + C[1]*(x^(n-1)) + ... + C[n]) - * - Factorized form - (y = (C[0][0]*x + C[0][1]) * (C[1][0]*x + C[1][1]) * ... * (C[n][0]*x + C[n][1])) + * - Expanded form: + * (y = C[0]*(x^(n)) + C[1]*(x^(n-1)) + ... + C[n]) + * - Factorized form: + * (y = (C[0][0]*x + C[0][1]) * (C[1][0]*x + C[1][1]) * ... * (C[n][0]*x + C[n][1])) */ static void fcm_generator_free(FModifier *fcm) @@ -217,9 +219,9 @@ static void fcm_generator_evaluate( float value = 1.0f, *cp = NULL; unsigned int i; - /* for each coefficient pair, solve for that bracket before accumulating in value by multiplying */ - for (cp = data->coefficients, i = 0; (cp) && (i < (unsigned int)data->poly_order); - cp += 2, i++) { + /* For each coefficient pair, + * solve for that bracket before accumulating in value by multiplying. */ + for (cp = data->coefficients, i = 0; (cp) && (i < (uint)data->poly_order); cp += 2, i++) { value *= (cp[0] * evaltime + cp[1]); } @@ -594,14 +596,14 @@ int BKE_fcm_envelope_find_index(FCM_EnvelopeData array[], /* This modifier changes evaltime to something that exists within the curve's frame-range, * then re-evaluates modifier stack up to this point using the new time. This re-entrant behavior - * is very likely to be more time-consuming than the original approach... (which was tightly integrated into - * the calculation code...). + * is very likely to be more time-consuming than the original approach... + * (which was tightly integrated into the calculation code...). * - * NOTE: this needs to be at the start of the stack to be of use, as it needs to know the extents of the - * keyframes/sample-data. + * NOTE: this needs to be at the start of the stack to be of use, + * as it needs to know the extents of the keyframes/sample-data. * - * Possible TODO - store length of cycle information that can be initialized from the extents of the - * keyframes/sample-data, and adjusted as appropriate. + * Possible TODO - store length of cycle information that can be initialized from the extents of + * the keyframes/sample-data, and adjusted as appropriate. */ /* temp data used during evaluation */ @@ -740,9 +742,10 @@ static float fcm_cycles_time( } /* calculate where in the cycle we are (overwrite evaltime to reflect this) */ else if ((mode == FCM_EXTRAPOLATE_MIRROR) && ((int)(cycle + 1) % 2)) { - /* when 'mirror' option is used and cycle number is odd, this cycle is played in reverse + /* When 'mirror' option is used and cycle number is odd, this cycle is played in reverse * - for 'before' extrapolation, we need to flip in a different way, otherwise values past - * then end of the curve get referenced (result of fmod will be negative, and with different phase) + * then end of the curve get referenced + * (result of fmod will be negative, and with different phase). */ if (side < 0) { evaltime = prevkey[0] - cyct; @@ -891,7 +894,7 @@ static void fcm_python_evaluate(FCurve *UNUSED(fcu), void *UNUSED(storage)) { #ifdef WITH_PYTHON - //FMod_Python *data = (FMod_Python *)fcm->data; + // FMod_Python *data = (FMod_Python *)fcm->data; /* FIXME... need to implement this modifier... * It will need it execute a script using the custom properties @@ -1455,9 +1458,9 @@ float evaluate_time_fmodifiers(FModifiersStackStorage *storage, continue; } - /* if modifier cannot be applied on this frame (whatever scale it is on, it won't affect the results) - * hence we shouldn't bother seeing what it would do given the chance - */ + /* If modifier cannot be applied on this frame + * (whatever scale it is on, it won't affect the results) + * hence we shouldn't bother seeing what it would do given the chance. */ if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) == 0 || ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime))) { /* only evaluate if there's a callback for this */ @@ -1508,7 +1511,8 @@ void evaluate_value_fmodifiers(FModifiersStackStorage *storage, continue; } - /* only evaluate if there's a callback for this, and if F-Modifier can be evaluated on this frame */ + /* Only evaluate if there's a callback for this, + * and if F-Modifier can be evaluated on this frame. */ if ((fcm->flag & FMODIFIER_FLAG_RANGERESTRICT) == 0 || ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime))) { if (fmi->evaluate_modifier) { diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 9ee8ecd1b64..70a8f4f124c 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -674,7 +674,8 @@ enum { * Descent: the recommended distance below the baseline to fit most characters. * * We obtain ascent and descent from the font itself (FT_Face->ascender / face->height). - * And in some cases it is even the same value as FT_Face->bbox.yMax/yMin (font top and bottom respectively). + * And in some cases it is even the same value as FT_Face->bbox.yMax/yMin + * (font top and bottom respectively). * * The em_height here is relative to FT_Face->bbox. */ @@ -1405,7 +1406,8 @@ static bool vfont_to_curve(Object *ob, } if (ob == NULL || info->mat_nr > (ob->totcol)) { - /* CLOG_ERROR(&LOG, "Illegal material index (%d) in text object, setting to 0", info->mat_nr); */ + // CLOG_ERROR( + // &LOG, "Illegal material index (%d) in text object, setting to 0", info->mat_nr); info->mat_nr = 0; } /* We do not want to see any character for \n or \r */ @@ -1625,7 +1627,8 @@ bool BKE_vfont_to_curve_nubase(Object *ob, int mode, ListBase *r_nubase) return BKE_vfont_to_curve_ex(ob, ob->data, mode, r_nubase, NULL, NULL, NULL, NULL); } -/** Warning: expects to have access to evaluated data (i.e. passed object should be evaluated one...). */ +/** Warning: expects to have access to evaluated data + * (i.e. passed object should be evaluated one...). */ bool BKE_vfont_to_curve(Object *ob, int mode) { Curve *cu = ob->data; diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index e45a4f4d649..439005ca1b4 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -622,8 +622,10 @@ bGPDlayer *BKE_gpencil_layer_duplicate(const bGPDlayer *gpl_src) } /** - * Only copy internal data of GreasePencil ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of GreasePencil ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -1107,7 +1109,8 @@ Material *BKE_gpencil_object_material_new(Main *bmain, Object *ob, const char *n /* Returns the material for a brush with respect to its pinned state. */ Material *BKE_gpencil_object_material_get_from_brush(Object *ob, Brush *brush) { - if ((brush) && (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) { + if ((brush) && (brush->gpencil_settings) && + (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED)) { Material *ma = BKE_gpencil_brush_material_get(brush); return ma; } @@ -1159,7 +1162,10 @@ Material *BKE_gpencil_object_material_ensure_from_active_input_brush(Main *bmain return BKE_gpencil_object_material_ensure_from_active_input_material(bmain, ob); } -/* Guaranteed to return a material assigned to object. Returns never NULL. Only use this for materials unrelated to user input */ +/** + * Guaranteed to return a material assigned to object. Returns never NULL. + * Only use this for materials unrelated to user input. + */ Material *BKE_gpencil_object_material_ensure_from_active_input_material(Main *bmain, Object *ob) { Material *ma = give_current_material(ob, ob->actcol); @@ -1416,9 +1422,11 @@ bool BKE_gpencil_smooth_stroke(bGPDstroke *gps, int i, float inf) } /* Compute smoothed coordinate by taking the ones nearby */ - /* XXX: This is potentially slow, and suffers from accumulation error as earlier points are handled before later ones */ + /* XXX: This is potentially slow, + * and suffers from accumulation error as earlier points are handled before later ones. */ { - // XXX: this is hardcoded to look at 2 points on either side of the current one (i.e. 5 items total) + /* XXX: this is hardcoded to look at 2 points on either side of the current one + * (i.e. 5 items total). */ const int steps = 2; const float average_fac = 1.0f / (float)(steps * 2 + 1); int step; @@ -1427,8 +1435,9 @@ bool BKE_gpencil_smooth_stroke(bGPDstroke *gps, int i, float inf) madd_v3_v3fl(sco, &pt->x, average_fac); /* n-steps before/after current point */ - // XXX: review how the endpoints are treated by this algorithm - // XXX: falloff measures should also introduce some weighting variations, so that further-out points get less weight + /* XXX: review how the endpoints are treated by this algorithm. */ + /* XXX: falloff measures should also introduce some weighting variations, + * so that further-out points get less weight. */ for (step = 1; step <= steps; step++) { bGPDspoint *pt1, *pt2; int before = i - step; diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c index 08162276a64..8a5a36481cf 100644 --- a/source/blender/blenkernel/intern/icons.c +++ b/source/blender/blenkernel/intern/icons.c @@ -300,7 +300,10 @@ PreviewImage *BKE_previewimg_copy(const PreviewImage *prv) return prv_img; } -/** Duplicate preview image from \a id and clear icon_id, to be used by datablock copy functions. */ +/** + * Duplicate preview image from \a id and clear icon_id, + * to be used by datablock copy functions. + */ void BKE_previewimg_id_copy(ID *new_id, const ID *old_id) { PreviewImage **old_prv_p = BKE_previewimg_id_get_p(old_id); @@ -534,8 +537,9 @@ void BKE_icon_changed(const int icon_id) BLI_assert(icon->id_type != 0); BLI_assert(icon->obj_type == ICON_DATA_ID); - /* Do not enforce creation of previews for valid ID types using BKE_previewimg_id_ensure() here , - * we only want to ensure *existing* preview images are properly tagged as changed/invalid, that's all. */ + /* Do not enforce creation of previews for valid ID types using BKE_previewimg_id_ensure() + * here, we only want to ensure *existing* preview images are properly tagged as + * changed/invalid, that's all. */ PreviewImage **p_prv = BKE_previewimg_id_get_p((ID *)icon->obj); /* If we have previews, they all are now invalid changed. */ @@ -676,7 +680,8 @@ int BKE_icon_preview_ensure(ID *id, PreviewImage *preview) return 0; } - /* Ensure we synchronize ID icon_id with its previewimage if available, and generate suitable 'ID' icon. */ + /* Ensure we synchronize ID icon_id with its previewimage if available, + * and generate suitable 'ID' icon. */ if (id) { id->icon_id = preview->icon_id; return icon_id_ensure_create_icon(id); diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index aebed7e0e91..39e72d7e3a8 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -665,13 +665,14 @@ void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overw * * The sanity check just means the property is not added to the group if another property * exists with the same name; the client code using ID properties then needs to detect this - * (the function that adds new properties to groups, IDP_AddToGroup, returns false if a property can't - * be added to the group, and true if it can) and free the property. + * (the function that adds new properties to groups, #IDP_AddToGroup, + * returns false if a property can't be added to the group, and true if it can) + * and free the property. * * Currently the code to free ID properties is designed to leave the actual struct * you pass it un-freed, this is needed for how the system works. This means - * to free an ID property, you first call IDP_FreeProperty then MEM_freeN the - * struct. In the future this will just be IDP_FreeProperty and the code will + * to free an ID property, you first call #IDP_FreeProperty then #MEM_freeN the struct. + * In the future this will just be #IDP_FreeProperty and the code will * be reorganized to work properly. */ bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) @@ -787,7 +788,8 @@ IDProperty *IDP_CopyProperty(const IDProperty *prop) } /* Updates ID pointers after an object has been copied */ -/* TODO Nuke this once its only user has been correctly converted to use generic ID management from BKE_library! */ +/* TODO Nuke this once its only user has been correctly converted + * to use generic ID management from BKE_library! */ void IDP_RelinkProperty(struct IDProperty *prop) { if (!prop) { diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index eaf90bd4ebb..f23c58befdf 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -383,8 +383,10 @@ static void copy_image_packedfiles(ListBase *lb_dst, const ListBase *lb_src) } /** - * Only copy internal data of Image ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Image ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -5311,9 +5313,11 @@ bool BKE_image_remove_renderslot(Image *ima, ImageUser *iuser, int index) next_slot = current_slot; } - /* If the slot to be removed is the slot with the last render, make another slot the last render slot. */ + /* If the slot to be removed is the slot with the last render, + * make another slot the last render slot. */ if (remove_slot == current_last_slot) { - /* Choose the currently selected slot unless that one is being removed, in that case take the next one. */ + /* Choose the currently selected slot unless that one is being removed, + * in that case take the next one. */ RenderSlot *next_last_slot; if (current_slot == remove_slot) { next_last_slot = next_slot; diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index d641229d5e0..63ef1458de8 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -337,7 +337,8 @@ static const char *constraint_adrcodes_to_paths(int adrcode, int *array_index) switch (adrcode) { case CO_ENFORCE: return "influence"; - case CO_HEADTAIL: // XXX this needs to be wrapped in RNA.. probably then this path will be invalid + case CO_HEADTAIL: + /* XXX this needs to be wrapped in RNA.. probably then this path will be invalid. */ return "data.head_tail"; } @@ -510,10 +511,10 @@ static const char *texture_adrcodes_to_paths(int adrcode, int *array_index) return "turbulence"; case TE_NDEPTH: // XXX texture RNA undefined - //poin= &(tex->noisedepth); *type= IPO_SHORT; break; + // poin= &(tex->noisedepth); *type= IPO_SHORT; break; break; case TE_NTYPE: // XXX texture RNA undefined - //poin= &(tex->noisetype); *type= IPO_SHORT; break; + // poin= &(tex->noisetype); *type= IPO_SHORT; break; break; case TE_N_BAS1: @@ -685,12 +686,13 @@ static const char *camera_adrcodes_to_paths(int adrcode, int *array_index) /* result depends on adrcode */ switch (adrcode) { case CAM_LENS: -#if 0 // XXX this cannot be resolved easily... perhaps we assume camera is perspective (works for most cases... +#if 0 /* XXX this cannot be resolved easily... \ + * perhaps we assume camera is perspective (works for most cases... */ if (ca->type == CAM_ORTHO) return "ortho_scale"; else return "lens"; -#else // XXX lazy hack for now... +#else // XXX lazy hack for now... return "lens"; #endif // XXX this cannot be resolved easily @@ -775,7 +777,8 @@ static const char *sound_adrcodes_to_paths(int adrcode, int *array_index) return "volume"; case SND_PITCH: return "pitch"; - /* XXX Joshua -- I had wrapped panning in rna, but someone commented out, calling it "unused" */ + /* XXX Joshua -- I had wrapped panning in rna, + * but someone commented out, calling it "unused" */ #if 0 case SND_PANNING: return "panning"; @@ -912,14 +915,17 @@ static const char *particle_adrcodes_to_paths(int adrcode, int *array_index) /* ------- */ -/* Allocate memory for RNA-path for some property given a blocktype, adrcode, and 'root' parts of path +/* Allocate memory for RNA-path for some property given a blocktype, adrcode, + * and 'root' parts of path. + * * Input: - * - id - the datablock that the curve's IPO block is attached to and/or which the new paths will start from - * - blocktype, adrcode - determines setting to get - * - actname, constname,seq - used to build path + * - id - the datablock that the curve's IPO block + * is attached to and/or which the new paths will start from + * - blocktype, adrcode - determines setting to get + * - actname, constname, seq - used to build path * Output: - * - array_index - index in property's array (if applicable) to use - * - return - the allocated path... + * - array_index - index in property's array (if applicable) to use + * - return - the allocated path... */ static char *get_rna_access(ID *id, int blocktype, @@ -995,7 +1001,7 @@ static char *get_rna_access(ID *id, /* XXX problematic blocktypes */ case ID_SEQ: /* sequencer strip */ - //SEQ_FAC1: + // SEQ_FAC1: switch (adrcode) { case SEQ_FAC1: propname = "effect_fader"; @@ -1022,7 +1028,8 @@ static char *get_rna_access(ID *id, } /* check if any property found - * - blocktype < 0 is special case for a specific type of driver, where we don't need a property name... + * - blocktype < 0 is special case for a specific type of driver, + * where we don't need a property name... */ if ((propname == NULL) && (blocktype > 0)) { /* nothing was found, so exit */ @@ -1053,7 +1060,8 @@ static char *get_rna_access(ID *id, buf[0] = '\0'; /* empty string */ } else if ((blocktype == ID_KE) && STREQ(actname, "Shape")) { - /* Actionified "Shape" IPO's - these are forced onto object level via the action container there... */ + /* Actionified "Shape" IPO's - + * these are forced onto object level via the action container there... */ strcpy(buf, "data.shape_keys"); } else { @@ -1257,7 +1265,8 @@ static void fcurve_add_to_list( } /* add F-Curve to group */ - /* WARNING: this func should only need to look at the stuff we initialized, if not, things may crash */ + /* WARNING: this func should only need to look at the stuff we initialized, + * if not, things may crash. */ action_groups_add_channel(&tmp_act, agrp, fcu); if (agrp->flag & AGRP_MUTED) { /* flush down */ @@ -1276,11 +1285,14 @@ static void fcurve_add_to_list( } } -/* Convert IPO-Curve to F-Curve (including Driver data), and free any of the old data that +/** + * Convert IPO-Curve to F-Curve (including Driver data), and free any of the old data that * is not relevant, BUT do not free the IPO-Curve itself... - * actname: name of Action-Channel (if applicable) that IPO-Curve's IPO-block belonged to - * constname: name of Constraint-Channel (if applicable) that IPO-Curve's IPO-block belonged to - * seq: sequencer-strip (if applicable) that IPO-Curve's IPO-block belonged to + * + * \param actname: name of Action-Channel (if applicable) that IPO-Curve's IPO-block belonged to. + * \param constname: name of Constraint-Channel (if applicable) + * that IPO-Curve's IPO-block belonged to \a seq. + * \param seq: sequencer-strip (if applicable) that IPO-Curve's IPO-block belonged to. */ static void icu_to_fcurves(ID *id, ListBase *groups, @@ -1385,9 +1397,11 @@ static void icu_to_fcurves(ID *id, fcurve->rna_path = BLI_strdup(abp->path); fcurve->array_index = abp->array_index; - /* convert keyframes - * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time - * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet) + /* Convert keyframes: + * - Beztriples and bpoints are mutually exclusive, + * so we won't have both at the same time. + * - Beztriples are more likely to be encountered as they are keyframes + * (the other type wasn't used yet). */ fcurve->totvert = icu->totvert; @@ -1428,9 +1442,10 @@ static void icu_to_fcurves(ID *id, } } else if (icu->bp) { - /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */ - //BPoint *bp; - //FPoint *fpt; + /* TODO: need to convert from BPoint type to the more compact FPoint type... + * but not priority, since no data used this. */ + // BPoint *bp; + // FPoint *fpt; } /* add new F-Curve to list */ @@ -1449,9 +1464,10 @@ static void icu_to_fcurves(ID *id, fcu->flag |= FCURVE_DISABLED; } - /* convert keyframes - * - beztriples and bpoints are mutually exclusive, so we won't have both at the same time - * - beztriples are more likely to be encountered as they are keyframes (the other type wasn't used yet) + /* Convert keyframes: + * - Beztriples and bpoints are mutually exclusive, so we won't have both at the same time. + * - Beztriples are more likely to be encountered as they are keyframes + * (the other type wasn't used yet). */ fcu->totvert = icu->totvert; @@ -1490,7 +1506,7 @@ static void icu_to_fcurves(ID *id, */ if (((icu->blocktype == ID_OB) && ELEM(icu->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) || ((icu->blocktype == ID_PO) && ELEM(icu->adrcode, AC_EUL_X, AC_EUL_Y, AC_EUL_Z))) { - const float fac = (float)M_PI / 18.0f; //10.0f * M_PI/180.0f; + const float fac = (float)M_PI / 18.0f; // 10.0f * M_PI/180.0f; dst->vec[0][1] *= fac; dst->vec[1][1] *= fac; @@ -1548,9 +1564,10 @@ static void icu_to_fcurves(ID *id, } } else if (icu->bp) { - /* TODO: need to convert from BPoint type to the more compact FPoint type... but not priority, since no data used this */ - //BPoint *bp; - //FPoint *fpt; + /* TODO: need to convert from BPoint type to the more compact FPoint type... + * but not priority, since no data used this */ + // BPoint *bp; + // FPoint *fpt; } /* add new F-Curve to list */ @@ -1602,10 +1619,11 @@ static void ipo_to_animato(ID *id, /* loop over IPO-Curves, freeing as we progress */ for (icu = ipo->curve.first; icu; icu = icu->next) { /* Since an IPO-Curve may end up being made into many F-Curves (i.e. bitflag curves), - * we figure out the best place to put the channel, then tell the curve-converter to just dump there - */ + * we figure out the best place to put the channel, + * then tell the curve-converter to just dump there. */ if (icu->driver) { - /* Blender 2.4x allowed empty drivers, but we don't now, since they cause more trouble than they're worth */ + /* Blender 2.4x allowed empty drivers, + * but we don't now, since they cause more trouble than they're worth. */ if ((icu->driver->ob) || (icu->driver->type == IPO_DRIVER_TYPE_PYTHON)) { icu_to_fcurves(id, NULL, drivers, icu, actname, constname, seq, ipo->muteipo); } @@ -1734,9 +1752,9 @@ static void ipo_to_animdata( BLI_listbase_count(&ipo->curve)); } - /* Convert curves to animato system (separated into separate lists of F-Curves for animation and drivers), - * and the try to put these lists in the right places, but do not free the lists here - */ + /* Convert curves to animato system + * (separated into separate lists of F-Curves for animation and drivers), + * and the try to put these lists in the right places, but do not free the lists here. */ // XXX there shouldn't be any need for the groups, so don't supply pointer for that now... ipo_to_animato(id, ipo, actname, constname, seq, NULL, &anim, &drivers); @@ -1819,7 +1837,8 @@ static void nlastrips_to_animdata(ID *id, ListBase *strips) /* convert Action data (if not yet converted), storing the results in the same Action */ action_to_animato(id, as->act, &as->act->groups, &as->act->curves, &adt->drivers); - /* create a new-style NLA-strip which references this Action, then copy over relevant settings */ + /* Create a new-style NLA-strip which references this Action, + * then copy over relevant settings. */ { /* init a new strip, and assign the action to it * - no need to muck around with the user-counts, since this is just @@ -2295,12 +2314,12 @@ void do_versions_ipos_to_animato(Main *bmain) /* --------- Unconverted Animation Data ------------------ */ /* For Animation data which may not be directly connected (i.e. not linked) to any other * data, we need to perform a separate pass to make sure that they are converted to standalone - * Actions which may then be able to be reused. This does mean that we will be going over data that's - * already been converted, but there are no problems with that. + * Actions which may then be able to be reused. This does mean that we will be going over data + * that's already been converted, but there are no problems with that. * * The most common case for this will be Action Constraints, or IPO's with Fake-Users. - * We collect all drivers that were found into a temporary collection, and free them in one go, as they're - * impossible to resolve. + * We collect all drivers that were found into a temporary collection, and free them in one go, + * as they're impossible to resolve. */ /* actions */ diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index e0246f874f3..61de6a8c06a 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -151,8 +151,10 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */ } /** - * Only copy internal data of ShapeKey ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of ShapeKey ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -2254,8 +2256,9 @@ void BKE_keyblock_update_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3]) /* ==========================================================*/ -/** Move shape key from org_index to new_index. Safe, clamps index to valid range, updates reference keys, - * the object's active shape index, the 'frame' value in case of absolute keys, etc. +/** Move shape key from org_index to new_index. Safe, clamps index to valid range, + * updates reference keys, the object's active shape index, + * the 'frame' value in case of absolute keys, etc. * Note indices are expected in real values (not 'fake' shapenr +1 ones). * * \param org_index: if < 0, current object's active shape will be used as skey to move. @@ -2283,8 +2286,8 @@ bool BKE_keyblock_move(Object *ob, int org_index, int new_index) rev = ((new_index - org_index) < 0) ? true : false; - /* We swap 'org' element with its previous/next neighbor (depending on direction of the move) repeatedly, - * until we reach final position. + /* We swap 'org' element with its previous/next neighbor (depending on direction of the move) + * repeatedly, until we reach final position. * This allows us to only loop on the list once! */ for (kb = (rev ? key->block.last : key->block.first), i = (rev ? totkey - 1 : 0); kb; kb = (rev ? kb->prev : kb->next), rev ? i-- : i++) { @@ -2321,7 +2324,8 @@ bool BKE_keyblock_move(Object *ob, int org_index, int new_index) } } - /* Need to update active shape number if it's affected, same principle as for relative indices above. */ + /* Need to update active shape number if it's affected, + * same principle as for relative indices above. */ if (org_index == act_index) { ob->shapenr = new_index + 1; } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 5570d39f43f..b8178bec52f 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -32,6 +32,7 @@ #include "BLI_listbase.h" #include "BLI_bitmap.h" #include "BLI_math.h" +#include "BLI_task.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" @@ -268,8 +269,10 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name) } /** - * Only copy internal data of Lattice ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Lattice ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -681,8 +684,8 @@ static bool calc_curve_deform( if (cd->no_rot_axis) { /* set by caller */ - /* this is not exactly the same as 2.4x, since the axis is having rotation removed rather than - * changing the axis before calculating the tilt but serves much the same purpose */ + /* This is not exactly the same as 2.4x, since the axis is having rotation removed rather + * than changing the axis before calculating the tilt but serves much the same purpose. */ float dir_flat[3] = {0, 0, 0}, q[4]; copy_v3_v3(dir_flat, dir); dir_flat[cd->no_rot_axis - 1] = 0.0f; @@ -699,8 +702,10 @@ static bool calc_curve_deform( * * The way 'co' is copied to 'cent' may seem to have no meaning, but it does. * - * Use a curve modifier to stretch a cube out, color each side RGB, positive side light, negative dark. - * view with X up (default), from the angle that you can see 3 faces RGB colors (light), anti-clockwise + * Use a curve modifier to stretch a cube out, color each side RGB, + * positive side light, negative dark. + * view with X up (default), from the angle that you can see 3 faces RGB colors (light), + * anti-clockwise * Notice X,Y,Z Up all have light colors and each ordered CCW. * * Now for Neg Up XYZ, the colors are all dark, and ordered clockwise - Campbell @@ -874,6 +879,31 @@ void curve_deform_vector( mul_m4_v3(cd.objectspace, vec); } +typedef struct LatticeDeformUserdata { + LatticeDeformData *lattice_deform_data; + float (*vertexCos)[3]; + MDeformVert *dvert; + int defgrp_index; + float fac; +} LatticeDeformUserdata; + +static void lattice_deform_vert_task(void *__restrict userdata, + const int index, + const ParallelRangeTLS *__restrict UNUSED(tls)) +{ + const LatticeDeformUserdata *data = userdata; + + if (data->dvert != NULL) { + const float weight = defvert_find_weight(data->dvert + index, data->defgrp_index); + if (weight > 0.0f) { + calc_latt_deform(data->lattice_deform_data, data->vertexCos[index], weight * data->fac); + } + } + else { + calc_latt_deform(data->lattice_deform_data, data->vertexCos[index], data->fac); + } +} + void lattice_deform_verts(Object *laOb, Object *target, Mesh *mesh, @@ -885,7 +915,6 @@ void lattice_deform_verts(Object *laOb, LatticeDeformData *lattice_deform_data; MDeformVert *dvert = NULL; int defgrp_index = -1; - int a; if (laOb->type != OB_LATTICE) { return; @@ -912,20 +941,18 @@ void lattice_deform_verts(Object *laOb, } } } - if (dvert) { - MDeformVert *dvert_iter; - for (a = 0, dvert_iter = dvert; a < numVerts; a++, dvert_iter++) { - const float weight = defvert_find_weight(dvert_iter, defgrp_index); - if (weight > 0.0f) { - calc_latt_deform(lattice_deform_data, vertexCos[a], weight * fac); - } - } - } - else { - for (a = 0; a < numVerts; a++) { - calc_latt_deform(lattice_deform_data, vertexCos[a], fac); - } - } + + LatticeDeformUserdata data = {.lattice_deform_data = lattice_deform_data, + .vertexCos = vertexCos, + .dvert = dvert, + .defgrp_index = defgrp_index, + .fac = fac}; + + ParallelRangeSettings settings; + BLI_parallel_range_settings_defaults(&settings); + settings.min_iter_per_thread = 32; + BLI_task_parallel_range(0, numVerts, &data, lattice_deform_vert_task, &settings); + end_latt_deform(lattice_deform_data); } @@ -1061,7 +1088,8 @@ void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]) void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob) { Lattice *lt = ob->data; - /* Get vertex coordinates from the original copy; otherwise we get already-modified coordinates. */ + /* Get vertex coordinates from the original copy; + * otherwise we get already-modified coordinates. */ Object *ob_orig = DEG_get_original_object(ob); VirtualModifierData virtualModifierData; ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index f0c2c1e5477..fc349e62809 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -35,7 +35,6 @@ #include "BKE_main.h" #include "BKE_node.h" #include "BKE_object.h" -#include "BKE_scene.h" #include "DNA_ID.h" #include "DNA_space_types.h" @@ -91,7 +90,9 @@ static Base *object_base_new(Object *ob) { Base *base = MEM_callocN(sizeof(Base), "Object Base"); base->object = ob; - BKE_scene_object_base_flag_sync_from_object(base); + if (ob->base_flag & BASE_SELECTED) { + base->flag |= BASE_SELECTED; + } return base; } @@ -345,19 +346,14 @@ void BKE_view_layer_base_deselect_all(ViewLayer *view_layer) } } -void BKE_view_layer_base_select(Base *selbase) +void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Base *selbase) { + view_layer->basact = selbase; if ((selbase->flag & BASE_SELECTABLE) != 0) { selbase->flag |= BASE_SELECTED; } } -void BKE_view_layer_base_select_and_set_active(struct ViewLayer *view_layer, Base *selbase) -{ - view_layer->basact = selbase; - BKE_view_layer_base_select(selbase); -} - /**************************** Copy View Layer and Layer Collections ***********************/ static void layer_collections_copy_data(ViewLayer *view_layer_dst, @@ -1100,7 +1096,8 @@ static void layer_collection_bases_hide_recursive(ViewLayer *view_layer, LayerCo /** * Hide/show all the elements of a collection. - * Don't change the collection children enable/disable state, but it may change it for the collection itself. + * Don't change the collection children enable/disable state, + * but it may change it for the collection itself. * * Return true if depsgraph needs update. */ diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index ca73415b962..ad0c405ab28 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -170,11 +170,14 @@ void id_lib_extern(ID *id) } } -/* ensure we have a real user */ -/* Note: Now that we have flags, we could get rid of the 'fake_user' special case, flags are enough to ensure - * we always have a real user. - * However, ID_REAL_USERS is used in several places outside of core library.c, so think we can wait later - * to make this change... */ +/** + * Ensure we have a real user + * + * \note Now that we have flags, we could get rid of the 'fake_user' special case, + * flags are enough to ensure we always have a real user. + * However, #ID_REAL_USERS is used in several places outside of core library.c, + * so think we can wait later to make this change. + */ void id_us_ensure_real(ID *id) { if (id) { @@ -254,7 +257,8 @@ void id_us_min(ID *id) } if ((id->us == limit) && (id->tag & LIB_TAG_EXTRAUSER)) { - /* We need an extra user here, but never actually incremented user count for it so far, do it now. */ + /* We need an extra user here, but never actually incremented user count for it so far, + * do it now. */ id_us_ensure_real(id); } } @@ -293,7 +297,8 @@ static int id_expand_local_callback(void *UNUSED(user_data), return IDWALK_RET_NOP; } - /* Can happen that we get unlinkable ID here, e.g. with shapekey referring to itself (through drivers)... + /* Can happen that we get un-linkable ID here, e.g. with shape-key referring to itself + * (through drivers)... * Just skip it, shape key can only be either indirectly linked, or fully local, period. * And let's curse one more time that stupid useless shapekey ID type! */ if (*id_pointer && *id_pointer != id_self && BKE_idcode_is_linkable(GS((*id_pointer)->name))) { @@ -304,7 +309,8 @@ static int id_expand_local_callback(void *UNUSED(user_data), } /** - * Expand ID usages of given id as 'extern' (and no more indirect) linked data. Used by ID copy/make_local functions. + * Expand ID usages of given id as 'extern' (and no more indirect) linked data. + * Used by ID copy/make_local functions. */ void BKE_id_expand_local(Main *bmain, ID *id) { @@ -335,7 +341,8 @@ void BKE_id_make_local_generic(Main *bmain, /* - only lib users: do nothing (unless force_local is set) * - only local users: set flag * - mixed: make copy - * In case we make a whole lib's content local, we always want to localize, and we skip remapping (done later). + * In case we make a whole lib's content local, + * we always want to localize, and we skip remapping (done later). */ if (!ID_IS_LINKED(id)) { @@ -352,7 +359,8 @@ void BKE_id_make_local_generic(Main *bmain, else { ID *id_new; - /* Should not fail in expected usecases, but a few ID types cannot be copied (LIB, WM, SCR...). */ + /* Should not fail in expected use cases, + * but a few ID types cannot be copied (LIB, WM, SCR...). */ if (BKE_id_copy(bmain, id, &id_new)) { id_new->us = 0; @@ -380,13 +388,15 @@ void BKE_id_make_local_generic(Main *bmain, * * \note Always set ID->newid pointer in case it gets duplicated... * - * \param lib_local: Special flag used when making a whole library's content local, it needs specific handling. + * \param lib_local: Special flag used when making a whole library's content local, + * it needs specific handling. * * \return true if the block can be made local. */ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local) { - /* We don't care whether ID is directly or indirectly linked in case we are making a whole lib local... */ + /* We don't care whether ID is directly or indirectly linked + * in case we are making a whole lib local... */ if (!lib_local && (id->tag & LIB_TAG_INDIRECT)) { return false; } @@ -601,15 +611,18 @@ bool BKE_id_copy_is_allowed(const ID *id) /** * Generic entry point for copying a datablock (new API). * - * \note Copy is only affecting given data-block (no ID used by copied one will be affected, besides usercount). - * There is only one exception, if LIB_ID_COPY_ACTIONS is defined, actions used by animdata will be duplicated. + * \note Copy is only affecting given data-block + * (no ID used by copied one will be affected, besides usercount). + * There is only one exception, if #LIB_ID_COPY_ACTIONS is defined, + * actions used by animdata will be duplicated. * * \note Usercount of new copy is always set to 1. * * \param bmain: Main database, may be NULL only if LIB_ID_CREATE_NO_MAIN is specified. * \param id: Source datablock. * \param r_newid: Pointer to new (copied) ID pointer. - * \param flag: Set of copy options, see DNA_ID.h enum for details (leave to zero for default, full copy). + * \param flag: Set of copy options, see DNA_ID.h enum for details + * (leave to zero for default, full copy). * \return False when copying that ID type is not supported, true otherwise. */ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) @@ -848,7 +861,8 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) PointerRNA idptr; if (id) { - /* if property isn't editable, we're going to have an extra block hanging around until we save */ + /* If property isn't editable, + * we're going to have an extra block hanging around until we save. */ if (RNA_property_editable(ptr, prop)) { Main *bmain = CTX_data_main(C); /* copy animation actions too */ @@ -1372,7 +1386,9 @@ void *BKE_id_new(Main *bmain, const short type, const char *name) return id; } -/** Generic helper to create a new temporary empty datablock of given type, *outside* of any Main database. +/** + * Generic helper to create a new temporary empty datablock of given type, + * *outside* of any Main database. * * \param name: can be NULL, in which case we get default name for this ID type. */ void *BKE_id_new_nomain(const short type, const char *name) @@ -1743,7 +1759,8 @@ void id_clear_lib_data_ex(Main *bmain, ID *id, const bool id_in_mainlist) } } - /* Internal bNodeTree blocks inside datablocks also stores id->lib, make sure this stays in sync. */ + /* Internal bNodeTree blocks inside datablocks also stores id->lib, + * make sure this stays in sync. */ if ((ntree = ntreeFromID(id))) { id_clear_lib_data_ex(bmain, &ntree->id, false); /* Datablocks' nodetree is never in Main. */ } @@ -1788,14 +1805,15 @@ static void library_make_local_copying_check(ID *id, /* Our oh-so-beloved 'from' pointers... */ if (entry->usage_flag & IDWALK_CB_LOOPBACK) { - /* We totally disregard Object->proxy_from 'usage' here, this one would only generate fake positives. */ + /* We totally disregard Object->proxy_from 'usage' here, + * this one would only generate fake positives. */ if (GS(par_id->name) == ID_OB) { BLI_assert(((Object *)par_id)->proxy_from == (Object *)id); continue; } - /* Shapekeys are considered 'private' to their owner ID here, and never tagged (since they cannot be linked), - * so we have to switch effective parent to their owner. */ + /* Shapekeys are considered 'private' to their owner ID here, and never tagged + * (since they cannot be linked), * so we have to switch effective parent to their owner. */ if (GS(par_id->name) == ID_KE) { par_id = ((Key *)par_id)->from; } @@ -1809,8 +1827,9 @@ static void library_make_local_copying_check(ID *id, if (BLI_gset_haskey(loop_tags, par_id)) { /* We are in a 'dependency loop' of IDs, this does not say us anything, skip it. * Note that this is the situation that can lead to archipelagoes of linked data-blocks - * (since all of them have non-local users, they would all be duplicated, leading to a loop of unused - * linked data-blocks that cannot be freed since they all use each other...). */ + * (since all of them have non-local users, they would all be duplicated, + * leading to a loop of unused linked data-blocks that cannot be freed since they all use + * each other...). */ continue; } /* Else, recursively check that user ID. */ @@ -1818,10 +1837,12 @@ static void library_make_local_copying_check(ID *id, } if (par_id->tag & LIB_TAG_DOIT) { - /* This user will be fully local in future, so far so good, nothing to do here but check next user. */ + /* This user will be fully local in future, so far so good, + * nothing to do here but check next user. */ } else { - /* This user won't be fully local in future, so current ID won't be either. And we are done checking it. */ + /* This user won't be fully local in future, so current ID won't be either. + * And we are done checking it. */ id->tag &= ~LIB_TAG_DOIT; break; } @@ -1835,15 +1856,16 @@ static void library_make_local_copying_check(ID *id, * \param bmain: Almost certainly global main. * \param lib: If not NULL, only make local datablocks from this library. * \param untagged_only: If true, only make local datablocks not tagged with LIB_TAG_PRE_EXISTING. - * \param set_fake: If true, set fake user on all localized datablocks (except group and objects ones). + * \param set_fake: If true, set fake user on all localized data-blocks + * (except group and objects ones). */ -/* Note: Old (2.77) version was simply making (tagging) datablocks as local, without actually making any check whether - * they were also indirectly used or not... +/* Note: Old (2.77) version was simply making (tagging) data-blocks as local, + * without actually making any check whether * they were also indirectly used or not... * - * Current version uses regular id_make_local callback, with advanced pre-processing step to detect all cases of - * IDs currently indirectly used, but which will be used by local data only once this function is finished. - * This allows to avoid any unneeded duplication of IDs, and hence all time lost afterwards to remove - * orphaned linked data-blocks... + * Current version uses regular id_make_local callback, with advanced pre-processing step to detect + * all cases of IDs currently indirectly used, but which will be used by local data only once this + * function is finished. This allows to avoid any unneeded duplication of IDs, and hence all time + * lost afterwards to remove orphaned linked data-blocks... */ void BKE_library_make_local(Main *bmain, const Library *lib, @@ -1874,8 +1896,8 @@ void BKE_library_make_local(Main *bmain, for (int a = set_listbasepointers(bmain, lbarray); a--;) { ID *id = lbarray[a]->first; - /* Do not explicitly make local non-linkable IDs (shapekeys, in fact), they are assumed to be handled - * by real datablocks responsible of them. */ + /* Do not explicitly make local non-linkable IDs (shapekeys, in fact), + * they are assumed to be handled by real datablocks responsible of them. */ const bool do_skip = (id && !BKE_idcode_is_linkable(GS(id->name))); for (; id; id = id->next) { @@ -1889,14 +1911,17 @@ void BKE_library_make_local(Main *bmain, if (id->lib == NULL) { id->tag &= ~(LIB_TAG_EXTERN | LIB_TAG_INDIRECT | LIB_TAG_NEW); } - /* The check on the fourth line (LIB_TAG_PRE_EXISTING) is done so its possible to tag data you don't want to - * be made local, used for appending data, so any libdata already linked wont become local (very nasty + /* The check on the fourth line (LIB_TAG_PRE_EXISTING) is done so it's possible to tag data + * you don't want to be made local, used for appending data, + * so any libdata already linked wont become local (very nasty * to discover all your links are lost after appending). * Also, never ever make proxified objects local, would not make any sense. */ /* Some more notes: * - Shapekeys are never tagged here (since they are not linkable). - * - Nodetrees used in materials etc. have to be tagged manually, since they do not exist in Main (!). - * This is ok-ish on 'make local' side of things (since those are handled by their 'owner' IDs), + * - Nodetrees used in materials etc. have to be tagged manually, + * since they do not exist in Main (!). + * This is ok-ish on 'make local' side of things + * (since those are handled by their 'owner' IDs), * but complicates slightly the pre-processing of relations between IDs at step 2... */ else if (!do_skip && id->tag & (LIB_TAG_EXTERN | LIB_TAG_INDIRECT | LIB_TAG_NEW) && ELEM(lib, NULL, id->lib) && @@ -1905,8 +1930,9 @@ void BKE_library_make_local(Main *bmain, BLI_linklist_prepend_arena(&todo_ids, id, linklist_mem); id->tag |= LIB_TAG_DOIT; - /* Tag those nasty non-ID nodetrees, but do not add them to todo list, making them local is handled - * by 'owner' ID. This is needed for library_make_local_copying_check() to work OK at step 2. */ + /* Tag those nasty non-ID nodetrees, + * but do not add them to todo list, making them local is handled by 'owner' ID. + * This is needed for library_make_local_copying_check() to work OK at step 2. */ if (ntree != NULL) { ntree->tag |= LIB_TAG_DOIT; } @@ -1923,8 +1949,9 @@ void BKE_library_make_local(Main *bmain, TIMEIT_VALUE_PRINT(make_local); #endif - /* Step 2: Check which datablocks we can directly make local (because they are only used by already, or future, - * local data), others will need to be duplicated. */ + /* Step 2: Check which datablocks we can directly make local + * (because they are only used by already, or future, local data), + * others will need to be duplicated. */ GSet *loop_tags = BLI_gset_ptr_new(__func__); for (LinkNode *it = todo_ids; it; it = it->next) { library_make_local_copying_check(it->link, loop_tags, bmain->relations, done_ids); @@ -1942,15 +1969,17 @@ void BKE_library_make_local(Main *bmain, #endif /* Step 3: Make IDs local, either directly (quick and simple), or using generic process, - * which involves more complex checks and might instead create a local copy of original linked ID. */ + * which involves more complex checks and might instead + * create a local copy of original linked ID. */ for (LinkNode *it = todo_ids, *it_next; it; it = it_next) { it_next = it->next; ID *id = it->link; if (id->tag & LIB_TAG_DOIT) { - /* We know all users of this object are local or will be made fully local, even if currently there are - * some indirect usages. So instead of making a copy that we'll likely get rid of later, directly make - * that data block local. Saves a tremendous amount of time with complex scenes... */ + /* We know all users of this object are local or will be made fully local, even if currently + * there are some indirect usages. So instead of making a copy that we'll likely get rid of + * later, directly make that data block local. + * Saves a tremendous amount of time with complex scenes... */ id_clear_lib_data_ex(bmain, id, true); BKE_id_expand_local(bmain, id); id->tag &= ~LIB_TAG_DOIT; @@ -1986,16 +2015,19 @@ void BKE_library_make_local(Main *bmain, TIMEIT_VALUE_PRINT(make_local); #endif - /* At this point, we are done with directly made local IDs. Now we have to handle duplicated ones, since their + /* At this point, we are done with directly made local IDs. + * Now we have to handle duplicated ones, since their * remaining linked original counterpart may not be needed anymore... */ todo_ids = NULL; - /* Step 4: We have to remap local usages of old (linked) ID to new (local) ID in a separated loop, + /* Step 4: We have to remap local usages of old (linked) ID to new (local) + * ID in a separated loop, * as lbarray ordering is not enough to ensure us we did catch all dependencies * (e.g. if making local a parent object before its child...). See T48907. */ - /* TODO This is now the biggest step by far (in term of processing time). We may be able to gain here by - * using again main->relations mapping, but... this implies BKE_libblock_remap & co to be able to update - * main->relations on the fly. Have to think about it a bit more, and see whether new code is OK first, anyway. */ + /* TODO This is now the biggest step by far (in term of processing time). + * We may be able to gain here by using again main->relations mapping, but... + * this implies BKE_libblock_remap & co to be able to update main->relations on the fly. + * Have to think about it a bit more, and see whether new code is OK first, anyway. */ for (LinkNode *it = copied_ids; it; it = it->next) { ID *id = it->link; @@ -2076,10 +2108,11 @@ void BKE_library_make_local(Main *bmain, #endif /* This is probably more of a hack than something we should do here, but... - * Issue is, the whole copying + remapping done in complex cases above may leave pose channels of armatures - * in complete invalid state (more precisely, the bone pointers of the pchans - very crappy cross-datablocks - * relationship), se we tag it to be fully recomputed, but this does not seems to be enough in some cases, - * and evaluation code ends up trying to evaluate a not-yet-updated armature object's deformations. + * Issue is, the whole copying + remapping done in complex cases above may leave pose-channels of + * armatures in complete invalid state (more precisely, the bone pointers of the pose-channels - + * very crappy cross-data-blocks relationship), se we tag it to be fully recomputed, + * but this does not seems to be enough in some cases, and evaluation code ends up trying to + * evaluate a not-yet-updated armature object's deformations. * Try "make all local" in 04_01_H.lighting.blend from Agent327 without this, e.g. */ for (Object *ob = bmain->objects.first; ob; ob = ob->id.next) { if (ob->data != NULL && ob->type == OB_ARMATURE && ob->pose != NULL && @@ -2160,7 +2193,8 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name) * * \note Result is unique to a given ID type in a given Main database. * - * \param name: An allocated string of minimal length MAX_ID_FULL_NAME, will be filled with generated string. + * \param name: An allocated string of minimal length #MAX_ID_FULL_NAME, + * will be filled with generated string. */ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id) { @@ -2179,12 +2213,14 @@ void BKE_id_full_name_get(char name[MAX_ID_FULL_NAME], const ID *id) } /** - * Generate full name of the data-block (without ID code, but with library if any), with a 3-character prefix prepended - * indicating whether it comes from a library, is overriding, has a fake or no user, etc. + * Generate full name of the data-block (without ID code, but with library if any), + * with a 3-character prefix prepended indicating whether it comes from a library, + * is overriding, has a fake or no user, etc. * * \note Result is unique to a given ID type in a given Main database. * - * \param name: An allocated string of minimal length MAX_ID_FULL_NAME_UI, will be filled with generated string. + * \param name: An allocated string of minimal length #MAX_ID_FULL_NAME_UI, + * will be filled with generated string. */ void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const ID *id) { @@ -2232,8 +2268,8 @@ void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath) * outliner, and its not really supported but allow from here for now * since making local could cause this to be directly linked - campbell */ - /* Never make paths relative to parent lib - reading code (blenloader) always set *all* lib->name relative to - * current main, not to their parent for indirectly linked ones. */ + /* Never make paths relative to parent lib - reading code (blenloader) always set *all* + * lib->name relative to current main, not to their parent for indirectly linked ones. */ const char *basepath = BKE_main_blendfile_path(bmain); BLI_path_abs(lib->filepath, basepath); } diff --git a/source/blender/blenkernel/intern/library_idmap.c b/source/blender/blenkernel/intern/library_idmap.c index d520df31a75..cc7e2e31d07 100644 --- a/source/blender/blenkernel/intern/library_idmap.c +++ b/source/blender/blenkernel/intern/library_idmap.c @@ -182,7 +182,8 @@ ID *BKE_main_idmap_lookup(struct IDNameLib_Map *id_map, ID *BKE_main_idmap_lookup_id(struct IDNameLib_Map *id_map, const ID *id) { /* When used during undo/redo, this function cannot assume that given id points to valid memory - * (i.e. has not been freed), so it has to check that it does exist in 'old' (aka current) Main database. + * (i.e. has not been freed), + * so it has to check that it does exist in 'old' (aka current) Main database. * Otherwise, we cannot provide new ID pointer that way (would crash accessing freed memory * when trying to get ID name). */ diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c index 30307eb1266..231e0b8ee60 100644 --- a/source/blender/blenkernel/intern/library_override.c +++ b/source/blender/blenkernel/intern/library_override.c @@ -55,7 +55,8 @@ static void bke_override_property_operation_copy(IDOverrideStaticPropertyOperati static void bke_override_property_clear(IDOverrideStaticProperty *op); static void bke_override_property_operation_clear(IDOverrideStaticPropertyOperation *opop); -/* Temp, for until static override is ready and tested enough to go 'public', we hide it by default in UI and such. */ +/* Temp, for until static override is ready and tested enough to go 'public', + * we hide it by default in UI and such. */ static bool _override_static_enabled = false; void BKE_override_static_enable(const bool do_enable) @@ -80,7 +81,7 @@ IDOverrideStatic *BKE_override_static_init(ID *local_id, ID *reference_id) for (ancestor_id = reference_id; ancestor_id != NULL && ancestor_id->override_static != NULL && ancestor_id->override_static->reference != NULL; ancestor_id = ancestor_id->override_static->reference) { - ; + /* pass */ } if (ancestor_id != NULL && ancestor_id->override_static != NULL) { @@ -189,7 +190,8 @@ ID *BKE_override_static_create_from_id(Main *bmain, ID *reference_id) ID *local_id = override_static_create_from(bmain, reference_id); - /* Remapping, we obviously only want to affect local data (and not our own reference pointer to overridden ID). */ + /* Remapping, we obviously only want to affect local data + * (and not our own reference pointer to overridden ID). */ BKE_libblock_remap( bmain, reference_id, local_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE); @@ -198,8 +200,8 @@ ID *BKE_override_static_create_from_id(Main *bmain, ID *reference_id) /** Create overridden local copies of all tagged data-blocks in given Main. * - * \note Set id->newid of overridden libs with newly created overrides, caller is responsible to clean those pointers - * before/after usage as needed. + * \note Set id->newid of overridden libs with newly created overrides, + * caller is responsible to clean those pointers before/after usage as needed. * * \return \a true on success, \a false otherwise. */ @@ -474,11 +476,11 @@ void BKE_override_static_property_operation_delete( /** * Check that status of local data-block is still valid against current reference one. * - * It means that all overridable, but not overridden, properties' local values must be equal to reference ones. - * Clears LIB_TAG_OVERRIDE_OK if they do not. + * It means that all overridable, but not overridden, properties' local values must be equal to + * reference ones. Clears #LIB_TAG_OVERRIDE_OK if they do not. * - * This is typically used to detect whether some property has been changed in local and a new IDOverrideProperty - * (of IDOverridePropertyOperation) has to be added. + * This is typically used to detect whether some property has been changed in local and a new + * #IDOverrideProperty (of #IDOverridePropertyOperation) has to be added. * * \return true if status is OK, false otherwise. */ bool BKE_override_static_status_check_local(Main *bmain, ID *local) @@ -521,7 +523,8 @@ bool BKE_override_static_status_check_local(Main *bmain, ID *local) * It means that all non-overridden properties' local values must be equal to reference ones. * Clears LIB_TAG_OVERRIDE_OK if they do not. * - * This is typically used to detect whether some reference has changed and local needs to be updated against it. + * This is typically used to detect whether some reference has changed and local + * needs to be updated against it. * * \return true if status is OK, false otherwise. */ bool BKE_override_static_status_check_reference(Main *bmain, ID *local) @@ -569,12 +572,13 @@ bool BKE_override_static_status_check_reference(Main *bmain, ID *local) * Compares local and reference data-blocks and create new override operations as needed, * or reset to reference values if overriding is not allowed. * - * \note Defining override operations is only mandatory before saving a .blend file on disk (not for undo!). + * \note Defining override operations is only mandatory before saving a `.blend` file on disk + * (not for undo!). * Knowing that info at runtime is only useful for UI/UX feedback. * - * \note This is by far the biggest operation (the more time-consuming) of the three so far, since it has to go over - * all properties in depth (all overridable ones at least). Generating diff values and applying overrides - * are much cheaper. + * \note This is by far the biggest operation (the more time-consuming) of the three so far, + * since it has to go over all properties in depth (all overridable ones at least). + * Generating diff values and applying overrides are much cheaper. * * \return true if new overriding op was created, or some local data was reset. */ bool BKE_override_static_operations_create(Main *bmain, ID *local, const bool force_auto) @@ -642,19 +646,20 @@ void BKE_override_static_update(Main *bmain, ID *local) BKE_override_static_update(bmain, local->override_static->reference); } - /* We want to avoid having to remap here, however creating up-to-date override is much simpler if based - * on reference than on current override. + /* We want to avoid having to remap here, however creating up-to-date override is much simpler + * if based on reference than on current override. * So we work on temp copy of reference, and 'swap' its content with local. */ /* XXX We need a way to get off-Main copies of IDs (similar to localized mats/texts/ etc.)! - * However, this is whole bunch of code work in itself, so for now plain stupid ID copy will do, - * as innefficient as it is. :/ - * Actually, maybe not! Since we are swapping with original ID's local content, we want to keep - * usercount in correct state when freeing tmp_id (and that usercounts of IDs used by 'new' local data - * also remain correct). */ - /* This would imply change in handling of usercout all over RNA (and possibly all over Blender code). - * Not impossible to do, but would rather see first if extra useless usual user handling is actually - * a (performances) issue here. */ + * However, this is whole bunch of code work in itself, so for now plain stupid ID copy will + * do, as inn-efficient as it is. :/ + * Actually, maybe not! Since we are swapping with original ID's local content, we want to + * keep user-count in correct state when freeing tmp_id + * (and that user-counts of IDs used by 'new' local data also remain correct). */ + /* This would imply change in handling of usercout all over RNA + * (and possibly all over Blender code). + * Not impossible to do, but would rather see first if extra useless usual user handling + * is actually a (performances) issue here. */ ID *tmp_id; BKE_id_copy(bmain, local->override_static->reference, &tmp_id); @@ -674,11 +679,12 @@ void BKE_override_static_update(Main *bmain, ID *local) RNA_struct_override_apply( bmain, &rnaptr_dst, &rnaptr_src, rnaptr_storage, local->override_static); - /* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa. So when we'll free tmp_id, - * we'll actually free old, outdated data from local. */ + /* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa. + * So when we'll free tmp_id, we'll actually free old, outdated data from local. */ BKE_id_swap(bmain, local, tmp_id); - /* Again, horribly innefficient in our case, we need something off-Main (aka moar generic nolib copy/free stuff)! */ + /* Again, horribly inn-efficient in our case, we need something off-Main + * (aka more generic nolib copy/free stuff)! */ /* XXX And crashing in complex cases (e.g. because depsgraph uses same data...). */ BKE_id_free_ex(bmain, tmp_id, LIB_ID_FREE_NO_UI_USER, true); @@ -711,18 +717,21 @@ void BKE_main_override_static_update(Main *bmain) FOREACH_MAIN_ID_END; } -/*********************************************************************************************************************** - * Storage (how to wtore overriding data into .blend files). +/** + * Storage (how to store overriding data into `.blend` files). * * Basically: - * I) Only 'differential' storage needs special handling here. All others (replacing values or - * inserting/removing items from a collection) can be handled with simply storing current content of local data-block. - * II) We store the differential value into a second 'ghost' data-block, which is an empty ID of same type as local one, - * where we only define values that need differential data. + * 1) Only 'differential' storage needs special handling here. All others (replacing values or + * inserting/removing items from a collection) can be handled with simply storing current + * content of local data-block. + * 2) We store the differential value into a second 'ghost' data-block, + * which is an empty ID of same type as local one, + * where we only define values that need differential data. * - * This avoids us having to modify 'real' data-block at write time (and restoring it afterwards), which is inneficient, - * and potentially dangerous (in case of concurrent access...), while not using much extra memory in typical cases. - * It also ensures stored data-block always contains exact same data as "desired" ones (kind of "baked" data-blocks). + * This avoids us having to modify 'real' data-block at write time (and restoring it afterwards), + * which is inneficient, and potentially dangerous (in case of concurrent access...), while not + * using much extra memory in typical cases. It also ensures stored data-block always contains + * exact same data as "desired" ones (kind of "baked" data-blocks). */ /** Initialize an override storage. */ @@ -734,7 +743,8 @@ OverrideStaticStorage *BKE_override_static_operations_store_initialize(void) /** * Generate suitable 'write' data (this only affects differential override operations). * - * Note that \a local ID is no more modified by this call, all extra data are stored in its temp \a storage_id copy. */ + * Note that \a local ID is no more modified by this call, + * all extra data are stored in its temp \a storage_id copy. */ ID *BKE_override_static_operations_store_start(Main *bmain, OverrideStaticStorage *override_storage, ID *local) @@ -756,11 +766,13 @@ ID *BKE_override_static_operations_store_start(Main *bmain, TIMEIT_START_AVERAGED(BKE_override_operations_store_start); #endif - /* XXX TODO We may also want a specialized handling of things here too, to avoid copying heavy never-overridable - * data (like Mesh geometry etc.)? And also maybe avoid lib refcounting completely (shallow copy...). */ - /* This would imply change in handling of usercout all over RNA (and possibly all over Blender code). - * Not impossible to do, but would rather see first is extra useless usual user handling is actually - * a (performances) issue here, before doing it. */ + /* XXX TODO We may also want a specialized handling of things here too, to avoid copying heavy + * never-overridable data (like Mesh geometry etc.)? And also maybe avoid lib reference-counting + * completely (shallow copy...). */ + /* This would imply change in handling of user-count all over RNA + * (and possibly all over Blender code). + * Not impossible to do, but would rather see first is extra useless usual user handling is + * actually a (performances) issue here, before doing it. */ BKE_id_copy((Main *)override_storage, local, &storage_id); if (storage_id != NULL) { @@ -790,15 +802,15 @@ void BKE_override_static_operations_store_end(OverrideStaticStorage *UNUSED(over { BLI_assert(local->override_static != NULL); - /* Nothing else to do here really, we need to keep all temp override storage data-blocks in memory until - * whole file is written anyway (otherwise we'd get mem pointers overlap...). */ + /* Nothing else to do here really, we need to keep all temp override storage data-blocks in + * memory until whole file is written anyway (otherwise we'd get mem pointers overlap...). */ local->override_static->storage = NULL; } void BKE_override_static_operations_store_finalize(OverrideStaticStorage *override_storage) { - /* We cannot just call BKE_main_free(override_storage), not until we have option to make 'ghost' copies of IDs - * without increasing usercount of used data-blocks... */ + /* We cannot just call BKE_main_free(override_storage), not until we have option to make 'ghost' + * copies of IDs without increasing usercount of used data-blocks. */ ID *id; FOREACH_MAIN_ID_BEGIN (override_storage, id) { diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index 92ed6ea4e04..d0515d8783d 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -352,8 +352,8 @@ static void library_foreach_ID_as_subdata_link(ID **id_pp, BLI_assert(id == *id_pp); if (flag & IDWALK_RECURSE) { - /* Defer handling into main loop, recursively calling BKE_library_foreach_ID_link in IDWALK_RECURSE case is - * troublesome, see T49553. */ + /* Defer handling into main loop, recursively calling BKE_library_foreach_ID_link in + * IDWALK_RECURSE case is troublesome, see T49553. */ if (BLI_gset_add(data->ids_handled, id)) { BLI_LINKSTACK_PUSH(data->ids_todo, id); } @@ -402,8 +402,8 @@ static void library_foreach_ID_link(Main *bmain, /* inherit_data is non-NULL when this function is called for some sub-data ID * (like root nodetree of a material). - * In that case, we do not want to generate those 'generic flags' from our current sub-data ID (the node tree), - * but re-use those generated for the 'owner' ID (the material)... */ + * In that case, we do not want to generate those 'generic flags' from our current sub-data ID + * (the node tree), but re-use those generated for the 'owner' ID (the material). */ if (inherit_data == NULL) { data.cb_flag = ID_IS_LINKED(id) ? IDWALK_CB_INDIRECT_USAGE : 0; /* When an ID is not in Main database, it should never refcount IDs it is using. @@ -416,10 +416,11 @@ static void library_foreach_ID_link(Main *bmain, } if (bmain != NULL && bmain->relations != NULL && (flag & IDWALK_READONLY)) { - /* Note that this is minor optimization, even in worst cases (like id being an object with lots of - * drivers and constraints and modifiers, or material etc. with huge node tree), - * but we might as well use it (Main->relations is always assumed valid, it's responsibility of code - * creating it to free it, especially if/when it starts modifying Main database). */ + /* Note that this is minor optimization, even in worst cases (like id being an object with + * lots of drivers and constraints and modifiers, or material etc. with huge node tree), + * but we might as well use it (Main->relations is always assumed valid, + * it's responsibility of code creating it to free it, + * especially if/when it starts modifying Main database). */ MainIDRelationsEntry *entry = BLI_ghash_lookup(bmain->relations->id_user_to_used, id); for (; entry != NULL; entry = entry->next) { FOREACH_CALLBACK_INVOKE_ID_PP(&data, entry->id_pointer, entry->usage_flag); @@ -594,8 +595,8 @@ static void library_foreach_ID_link(Main *bmain, CALLBACK_INVOKE(object->proxy_group, IDWALK_CB_NOP); /* Special case! - * Since this field is set/owned by 'user' of this ID (and not ID itself), it is only indirect usage - * if proxy object is linked... Twisted. */ + * Since this field is set/owned by 'user' of this ID (and not ID itself), + * it is only indirect usage if proxy object is linked... Twisted. */ if (object->proxy_from) { data.cb_flag = ID_IS_LINKED(object->proxy_from) ? IDWALK_CB_INDIRECT_USAGE : 0; } @@ -1018,7 +1019,8 @@ static void library_foreach_ID_link(Main *bmain, bScreen *screen = BKE_workspace_layout_screen_get(layout); /* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer. - * However we can't access layout->screen here since we are outside the workspace project. */ + * However we can't access layout->screen here + * since we are outside the workspace project. */ CALLBACK_INVOKE(screen, IDWALK_CB_USER); /* allow callback to set a different screen */ BKE_workspace_layout_screen_set(layout, screen); @@ -1096,11 +1098,12 @@ void BKE_library_update_ID_link_user(ID *id_dst, ID *id_src, const int cb_flag) /** * Say whether given \a id_type_owner can use (in any way) a datablock of \a id_type_used. * - * This is a 'simplified' abstract version of #BKE_library_foreach_ID_link() above, quite useful to reduce - * useless iterations in some cases. + * This is a 'simplified' abstract version of #BKE_library_foreach_ID_link() above, + * quite useful to reduce* useless iterations in some cases. */ -/* XXX This has to be fully rethink, basing check on ID type is not really working anymore (and even worth once - * IDProps will support ID pointers), we'll have to do some quick checks on IDs themselves... */ +/* XXX This has to be fully rethink, basing check on ID type is not really working anymore + * (and even worth once IDProps will support ID pointers), + * we'll have to do some quick checks on IDs themselves... */ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used) { /* any type of ID can be used in custom props. */ @@ -1120,7 +1123,8 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used) } if (BKE_animdata_from_id(id_owner)) { - return true; /* AnimationData can use virtually any kind of datablocks, through drivers especially. */ + /* AnimationData can use virtually any kind of datablocks, through drivers especially. */ + return true; } switch ((ID_Type)id_type_owner) { @@ -1267,8 +1271,8 @@ static int foreach_libblock_id_users_callback(void *user_data, /** * Return the number of times given \a id_user uses/references \a id_used. * - * \note This only checks for pointer references of an ID, shallow usages (like e.g. by RNA paths, as done - * for FCurves) are not detected at all. + * \note This only checks for pointer references of an ID, shallow usages + * (like e.g. by RNA paths, as done for FCurves) are not detected at all. * * \param id_user: the ID which is supposed to use (reference) \a id_used. * \param id_used: the ID which is supposed to be used (referenced) by \a id_user. @@ -1339,7 +1343,8 @@ bool BKE_library_ID_is_indirectly_used(Main *bmain, void *idv) } /** - * Combine #BKE_library_ID_is_locally_used() and #BKE_library_ID_is_indirectly_used() in a single call. + * Combine #BKE_library_ID_is_locally_used() and #BKE_library_ID_is_indirectly_used() + * in a single call. */ void BKE_library_ID_test_usages(Main *bmain, void *idv, bool *is_used_local, bool *is_used_linked) { @@ -1390,7 +1395,8 @@ static int foreach_libblock_used_linked_data_tag_clear_cb(void *user_data, return IDWALK_RET_NOP; } - /* If checked id is used by an assumed used ID, then it is also used and not part of any linked archipelago. */ + /* If checked id is used by an assumed used ID, + * then it is also used and not part of any linked archipelago. */ if (!(self_id->tag & LIB_TAG_DOIT) && ((*id_p)->tag & LIB_TAG_DOIT)) { (*id_p)->tag &= ~LIB_TAG_DOIT; *is_changed = true; @@ -1401,12 +1407,13 @@ static int foreach_libblock_used_linked_data_tag_clear_cb(void *user_data, } /** - * Detect orphaned linked data blocks (i.e. linked data not used (directly or indirectly) in any way by any local data), - * including complex cases like 'linked archipelagoes', i.e. linked datablocks that use each other in loops, - * which prevents their deletion by 'basic' usage checks... + * Detect orphaned linked data blocks (i.e. linked data not used (directly or indirectly) + * in any way by any local data), including complex cases like 'linked archipelagoes', i.e. + * linked datablocks that use each other in loops, + * which prevents their deletion by 'basic' usage checks. * - * \param do_init_tag: if \a true, all linked data are checked, if \a false, only linked datablocks already tagged with - * LIB_TAG_DOIT are checked. + * \param do_init_tag: if \a true, all linked data are checked, if \a false, + * only linked datablocks already tagged with #LIB_TAG_DOIT are checked. */ void BKE_library_unused_linked_data_set_tag(Main *bmain, const bool do_init_tag) { @@ -1439,9 +1446,11 @@ void BKE_library_unused_linked_data_set_tag(Main *bmain, const bool do_init_tag) /** * Untag linked data blocks used by other untagged linked datablocks. - * Used to detect datablocks that we can forcefully make local (instead of copying them to later get rid of original): - * All datablocks we want to make local are tagged by caller, after this function has ran caller knows datablocks still - * tagged can directly be made local, since they are only used by other datablocks that will also be made fully local. + * Used to detect datablocks that we can forcefully make local + * (instead of copying them to later get rid of original): + * All datablocks we want to make local are tagged by caller, + * after this function has ran caller knows datablocks still tagged can directly be made local, + * since they are only used by other datablocks that will also be made fully local. */ void BKE_library_indirectly_used_data_tag_clear(Main *bmain) { diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c index 7657b47bcf5..3b6f11935d1 100644 --- a/source/blender/blenkernel/intern/library_remap.c +++ b/source/blender/blenkernel/intern/library_remap.c @@ -185,7 +185,8 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id } if (*id_p && (*id_p == old_id)) { - /* Better remap to NULL than not remapping at all, then we can handle it as a regular remap-to-NULL case... */ + /* Better remap to NULL than not remapping at all, + * then we can handle it as a regular remap-to-NULL case. */ if ((cb_flag & IDWALK_CB_NEVER_SELF) && (new_id == id_self)) { new_id = NULL; } @@ -194,8 +195,8 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id const bool is_indirect = (cb_flag & IDWALK_CB_INDIRECT_USAGE) != 0; const bool skip_indirect = (id_remap_data->flag & ID_REMAP_SKIP_INDIRECT_USAGE) != 0; /* Note: proxy usage implies LIB_TAG_EXTERN, so on this aspect it is direct, - * on the other hand since they get reset to lib data on file open/reload it is indirect too... - * Edit Mode is also a 'skip direct' case. */ + * on the other hand since they get reset to lib data on file open/reload it is indirect too. + * Edit Mode is also a 'skip direct' case. */ const bool is_obj = (GS(id->name) == ID_OB); const bool is_obj_proxy = (is_obj && (((Object *)id)->proxy || ((Object *)id)->proxy_group)); const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id)); @@ -280,8 +281,8 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id } else if (cb_flag & IDWALK_CB_USER_ONE) { id_us_ensure_real(new_id); - /* We cannot affect old_id->us directly, LIB_TAG_EXTRAUSER(_SET) are assumed to be set as needed, - * that extra user is processed in final handling... */ + /* We cannot affect old_id->us directly, LIB_TAG_EXTRAUSER(_SET) + * are assumed to be set as needed, that extra user is processed in final handling. */ } if (!is_indirect || is_obj_proxy) { id_remap_data->status |= ID_REMAP_IS_LINKED_DIRECT; @@ -300,15 +301,16 @@ static void libblock_remap_data_preprocess(IDRemap *r_id_remap_data) if (!old_id || GS(old_id->name) == ID_AR) { Object *ob = (Object *)r_id_remap_data->id; /* Object's pose holds reference to armature bones... sic */ - /* Note that in theory, we should have to bother about linked/non-linked/never-null/etc. flags/states. - * Fortunately, this is just a tag, so we can accept to 'over-tag' a bit for pose recalc, and avoid - * another complex and risky condition nightmare like the one we have in + /* Note that in theory, we should have to bother about + * linked/non-linked/never-null/etc. flags/states. + * Fortunately, this is just a tag, so we can accept to 'over-tag' a bit for pose recalc, + * and avoid another complex and risky condition nightmare like the one we have in * foreach_libblock_remap_callback()... */ if (ob->pose && (!old_id || ob->data == old_id)) { BLI_assert(ob->type == OB_ARMATURE); ob->pose->flag |= POSE_RECALC; - /* We need to clear pose bone pointers immediately, things like undo writefile may be called - * before pose is actually recomputed, can lead to segfault... */ + /* We need to clear pose bone pointers immediately, things like undo writefile may be + * called before pose is actually recomputed, can lead to segfault... */ BKE_pose_clear_pointers(ob->pose); } } @@ -319,7 +321,10 @@ static void libblock_remap_data_preprocess(IDRemap *r_id_remap_data) } } -/* Can be called with both old_ob and new_ob being NULL, this means we have to check whole Main database then. */ +/** + * Can be called with both old_ob and new_ob being NULL, + * this means we have to check whole Main database then. + */ static void libblock_remap_data_postprocess_object_update(Main *bmain, Object *old_ob, Object *new_ob) @@ -358,8 +363,8 @@ static void libblock_remap_data_postprocess_collection_update(Main *bmain, { if (new_collection == NULL) { /* XXX Complex cases can lead to NULL pointers in other collections than old_collection, - * and BKE_main_collection_sync_remap() does not tolerate any of those, so for now always check whole - * existing collections for NULL pointers. + * and BKE_main_collection_sync_remap() does not tolerate any of those, so for now always check + * whole existing collections for NULL pointers. * I'd consider optimizing that whole collection remapping process a TODO for later. */ BKE_collections_child_remove_nulls(bmain, NULL /*old_collection*/); } @@ -387,15 +392,8 @@ static void libblock_remap_data_postprocess_obdata_relink(Main *bmain, Object *o static void libblock_remap_data_postprocess_nodetree_update(Main *bmain, ID *new_id) { - /* Verify all nodetree user nodes. */ - ntreeVerifyNodes(bmain, new_id); - - /* Update node trees as necessary. */ - FOREACH_NODETREE_BEGIN (bmain, ntree, id) { - /* make an update call for the tree */ - ntreeUpdateTree(bmain, ntree); - } - FOREACH_NODETREE_END; + /* Update all group nodes using a node group. */ + ntreeUpdateAllUsers(bmain, new_id); } /** @@ -403,18 +401,22 @@ static void libblock_remap_data_postprocess_nodetree_update(Main *bmain, ID *new * * Behavior differs depending on whether given \a id is NULL or not: * - \a id NULL: \a old_id must be non-NULL, \a new_id may be NULL (unlinking \a old_id) or not - * (remapping \a old_id to \a new_id). The whole \a bmain database is checked, and all pointers to \a old_id + * (remapping \a old_id to \a new_id). + * The whole \a bmain database is checked, and all pointers to \a old_id * are remapped to \a new_id. * - \a id is non-NULL: - * + If \a old_id is NULL, \a new_id must also be NULL, and all ID pointers from \a id are cleared (i.e. \a id - * does not references any other datablock anymore). + * + If \a old_id is NULL, \a new_id must also be NULL, + * and all ID pointers from \a id are cleared + * (i.e. \a id does not references any other datablock anymore). * + If \a old_id is non-NULL, behavior is as with a NULL \a id, but only within given \a id. * * \param bmain: the Main data storage to operate on (must never be NULL). - * \param id: the datablock to operate on (can be NULL, in which case we operate over all IDs from given bmain). + * \param id: the datablock to operate on + * (can be NULL, in which case we operate over all IDs from given bmain). * \param old_id: the datablock to dereference (may be NULL if \a id is non-NULL). * \param new_id: the new datablock to replace \a old_id references with (may be NULL). - * \param r_id_remap_data: if non-NULL, the IDRemap struct to use (uselful to retrieve info about remapping process). + * \param r_id_remap_data: if non-NULL, the IDRemap struct to use + * (uselful to retrieve info about remapping process). */ ATTR_NONNULL(1) static void libblock_remap_data( @@ -448,14 +450,15 @@ static void libblock_remap_data( NULL, id, foreach_libblock_remap_callback, (void *)r_id_remap_data, foreach_id_flags); } else { - /* Note that this is a very 'brute force' approach, maybe we could use some depsgraph to only process - * objects actually using given old_id... sounds rather unlikely currently, though, so this will do for now. */ + /* Note that this is a very 'brute force' approach, + * maybe we could use some depsgraph to only process objects actually using given old_id... + * sounds rather unlikely currently, though, so this will do for now. */ ID *id_curr; FOREACH_MAIN_ID_BEGIN (bmain, id_curr) { if (BKE_library_id_can_use_idtype(id_curr, GS(old_id->name))) { - /* Note that we cannot skip indirect usages of old_id here (if requested), we still need to check it for - * the user count handling... + /* Note that we cannot skip indirect usages of old_id here (if requested), + * we still need to check it for the user count handling... * XXX No more true (except for debug usage of those skipping counters). */ r_id_remap_data->id = id_curr; libblock_remap_data_preprocess(r_id_remap_data); @@ -469,8 +472,9 @@ static void libblock_remap_data( FOREACH_MAIN_ID_END; } - /* XXX We may not want to always 'transfer' fakeuser from old to new id... Think for now it's desired behavior - * though, we can always add an option (flag) to control this later if needed. */ + /* XXX We may not want to always 'transfer' fakeuser from old to new id... + * Think for now it's desired behavior though, + * we can always add an option (flag) to control this later if needed. */ if (old_id && (old_id->flag & LIB_FAKEUSER)) { id_fake_user_clear(old_id); id_fake_user_set(new_id); @@ -515,7 +519,8 @@ void BKE_libblock_remap_locked(Main *bmain, void *old_idv, void *new_idv, const } /* We assume editors do not hold references to their IDs... This is false in some cases - * (Image is especially tricky here), editors' code is to handle refcount (id->us) itself then. */ + * (Image is especially tricky here), + * editors' code is to handle refcount (id->us) itself then. */ if (remap_editor_id_reference_cb) { remap_editor_id_reference_cb(old_id, new_id); } @@ -523,9 +528,9 @@ void BKE_libblock_remap_locked(Main *bmain, void *old_idv, void *new_idv, const skipped_direct = id_remap_data.skipped_direct; skipped_refcounted = id_remap_data.skipped_refcounted; - /* If old_id was used by some ugly 'user_one' stuff (like Image or Clip editors...), and user count has actually - * been incremented for that, we have to decrease once more its user count... unless we had to skip - * some 'user_one' cases. */ + /* If old_id was used by some ugly 'user_one' stuff (like Image or Clip editors...), and user + * count has actually been incremented for that, we have to decrease once more its user count... + * unless we had to skip some 'user_one' cases. */ if ((old_id->tag & LIB_TAG_EXTRAUSER_SET) && !(id_remap_data.status & ID_REMAP_IS_USER_ONE_SKIPPED)) { id_us_clear_real(old_id); @@ -552,8 +557,8 @@ void BKE_libblock_remap_locked(Main *bmain, void *old_idv, void *new_idv, const } /* Some after-process updates. - * This is a bit ugly, but cannot see a way to avoid it. Maybe we should do a per-ID callback for this instead? - */ + * This is a bit ugly, but cannot see a way to avoid it. + * Maybe we should do a per-ID callback for this instead? */ switch (GS(old_id->name)) { case ID_OB: libblock_remap_data_postprocess_object_update(bmain, (Object *)old_id, (Object *)new_id); @@ -597,10 +602,11 @@ void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, const short r } /** - * Unlink given \a id from given \a bmain (does not touch to indirect, i.e. library, usages of the ID). + * Unlink given \a id from given \a bmain + * (does not touch to indirect, i.e. library, usages of the ID). * - * \param do_flag_never_null: If true, all IDs using \a idv in a 'non-NULL' way are flagged by \a LIB_TAG_DOIT flag - * (quite obviously, 'non-NULL' usages can never be unlinked by this function...). + * \param do_flag_never_null: If true, all IDs using \a idv in a 'non-NULL' way are flagged by + * #LIB_TAG_DOIT flag (quite obviously, 'non-NULL' usages can never be unlinked by this function). */ void BKE_libblock_unlink(Main *bmain, void *idv, @@ -655,7 +661,8 @@ void BKE_libblock_relink_ex( libblock_remap_data(bmain, id, old_id, new_id, remap_flags, NULL); /* Some after-process updates. - * This is a bit ugly, but cannot see a way to avoid it. Maybe we should do a per-ID callback for this instead? + * This is a bit ugly, but cannot see a way to avoid it. + * Maybe we should do a per-ID callback for this instead? */ switch (GS(id->name)) { case ID_SCE: { @@ -714,9 +721,12 @@ static int id_relink_to_newid_looper(void *UNUSED(user_data), return IDWALK_RET_NOP; } -/** Similar to libblock_relink_ex, but is remapping IDs to their newid value if non-NULL, in given \a id. +/** + * Similar to #libblock_relink_ex, + * but is remapping IDs to their newid value if non-NULL, in given \a id. * - * Very specific usage, not sure we'll keep it on the long run, currently only used in Object/Collection duplication code... + * Very specific usage, not sure we'll keep it on the long run, + * currently only used in Object/Collection duplication code... */ void BKE_libblock_relink_to_newid(ID *id) { @@ -738,7 +748,8 @@ void BKE_libblock_free_data(ID *id, const bool do_id_user) BKE_override_static_free(&id->override_static); } - /* XXX TODO remove animdata handling from each type's freeing func, and do it here, like for copy! */ + /* XXX TODO remove animdata handling from each type's freeing func, + * and do it here, like for copy! */ } void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) @@ -865,13 +876,14 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag)) * At that point, given id is assumed to not be used by any other data-block already * (might not be actually true, in case e.g. several inter-related IDs get freed together...). * However, they might still be using (referencing) other IDs, this code takes care of it if - * \a LIB_TAG_NO_USER_REFCOUNT is not defined. + * #LIB_TAG_NO_USER_REFCOUNT is not defined. * - * \param bmain: Main database containing the freed ID, can be NULL in case it's a temp ID outside of any Main. + * \param bmain: #Main database containing the freed #ID, + * can be NULL in case it's a temp ID outside of any #Main. * \param idv: Pointer to ID to be freed. * \param flag: Set of \a LIB_ID_FREE_... flags controlling/overriding usual freeing process, * 0 to get default safe behavior. - * \param use_flag_from_idtag: Still use freeing info flags from given ID datablock, + * \param use_flag_from_idtag: Still use freeing info flags from given #ID datablock, * even if some overriding ones are passed in \a flag parameter. */ void BKE_id_free_ex(Main *bmain, void *idv, int flag, const bool use_flag_from_idtag) @@ -962,7 +974,8 @@ void BKE_id_free_ex(Main *bmain, void *idv, int flag, const bool use_flag_from_i * * See #BKE_id_free_ex description for full details. * - * \param bmain: Main database containing the freed ID, can be NULL in case it's a temp ID outside of any Main. + * \param bmain: Main database containing the freed ID, + * can be NULL in case it's a temp ID outside of any Main. * \param idv: Pointer to ID to be freed. */ void BKE_id_free(Main *bmain, void *idv) @@ -971,7 +984,8 @@ void BKE_id_free(Main *bmain, void *idv) } /** - * Not really a freeing function by itself, it decrements usercount of given id, and only frees it if it reaches 0. + * Not really a freeing function by itself, + * it decrements usercount of given id, and only frees it if it reaches 0. */ void BKE_id_free_us(Main *bmain, void *idv) /* test users */ { @@ -979,12 +993,13 @@ void BKE_id_free_us(Main *bmain, void *idv) /* test users */ id_us_min(id); - /* XXX This is a temp (2.77) hack so that we keep same behavior as in 2.76 regarding collections when deleting an object. - * Since only 'user_one' usage of objects is collections, and only 'real user' usage of objects is scenes, - * removing that 'user_one' tag when there is no more real (scene) users of an object ensures it gets - * fully unlinked. + /* XXX This is a temp (2.77) hack so that we keep same behavior as in 2.76 regarding collections + * when deleting an object. Since only 'user_one' usage of objects is collections, + * and only 'real user' usage of objects is scenes, removing that 'user_one' tag when there + * is no more real (scene) users of an object ensures it gets fully unlinked. * But only for local objects, not linked ones! - * Otherwise, there is no real way to get rid of an object anymore - better handling of this is TODO. + * Otherwise, there is no real way to get rid of an object anymore - + * better handling of this is TODO. */ if ((GS(id->name) == ID_OB) && (id->us == 1) && (id->lib == NULL)) { id_us_clear_real(id); @@ -1041,8 +1056,9 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion) if ((id->tag & tag) || (id->lib != NULL && (id->lib->id.tag & tag))) { BLI_remlink(lb, id); BLI_addtail(&tagged_deleted_ids, id); - /* Do not tag as no_main now, we want to unlink it first (lower-level ID management code - * has some specific handling of 'nom main' IDs that would be a problem in that case). */ + /* Do not tag as no_main now, we want to unlink it first (lower-level ID management + * code has some specific handling of 'nom main' + * IDs that would be a problem in that case). */ id->tag |= tag; keep_looping = true; } @@ -1054,24 +1070,28 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion) } for (id = last_remapped_id->next; id; id = id->next) { /* Will tag 'never NULL' users of this ID too. - * Note that we cannot use BKE_libblock_unlink() here, since it would ignore indirect (and proxy!) + * Note that we cannot use BKE_libblock_unlink() here, + * since it would ignore indirect (and proxy!) * links, this can lead to nasty crashing here in second, actual deleting loop. * Also, this will also flag users of deleted data that cannot be unlinked * (object using deleted obdata, etc.), so that they also get deleted. */ BKE_libblock_remap_locked( bmain, id, NULL, ID_REMAP_FLAG_NEVER_NULL_USAGE | ID_REMAP_FORCE_NEVER_NULL_USAGE); - /* Since we removed ID from Main, we also need to unlink its own other IDs usages ourself. */ + /* Since we removed ID from Main, + * we also need to unlink its own other IDs usages ourself. */ BKE_libblock_relink_ex(bmain, id, NULL, NULL, true); /* Now we can safely mark that ID as not being in Main database anymore. */ id->tag |= LIB_TAG_NO_MAIN; - /* This is needed because we may not have remapped usages of that ID by other deleted ones. */ - // id->us = 0; /* Is it actually? */ + /* This is needed because we may not have remapped usages + * of that ID by other deleted ones. */ + // id->us = 0; /* Is it actually? */ } } } else { /* First tag all datablocks directly from target lib. - * Note that we go forward here, since we want to check dependencies before users (e.g. meshes before objects). + * Note that we go forward here, since we want to check dependencies before users + * (e.g. meshes before objects). * Avoids to have to loop twice. */ for (i = 0; i < base_count; i++) { ListBase *lb = lbarray[i]; @@ -1084,8 +1104,9 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion) id->tag |= tag; /* Will tag 'never NULL' users of this ID too. - * Note that we cannot use BKE_libblock_unlink() here, since it would ignore indirect (and proxy!) - * links, this can lead to nasty crashing here in second, actual deleting loop. + * Note that we cannot use BKE_libblock_unlink() here, since it would ignore indirect + * (and proxy!) links, this can lead to nasty crashing here in second, + * actual deleting loop. * Also, this will also flag users of deleted data that cannot be unlinked * (object using deleted obdata, etc.), so that they also get deleted. */ BKE_libblock_remap_locked( @@ -1096,8 +1117,9 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion) } BKE_main_unlock(bmain); - /* In usual reversed order, such that all usage of a given ID, even 'never NULL' ones, have been already cleared - * when we reach it (e.g. Objects being processed before meshes, they'll have already released their 'reference' + /* In usual reversed order, such that all usage of a given ID, even 'never NULL' ones, + * have been already cleared when we reach it + * (e.g. Objects being processed before meshes, they'll have already released their 'reference' * over meshes when we come to freeing obdata). */ for (i = do_tagged_deletion ? 1 : base_count; i--;) { ListBase *lb = lbarray[i]; diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index 0a7cb2a30a0..05b2eb82daf 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -96,8 +96,10 @@ Light *BKE_light_add(Main *bmain, const char *name) } /** - * Only copy internal data of Light ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Light ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c index 6b1951498cc..5e6d298adbf 100644 --- a/source/blender/blenkernel/intern/lightprobe.c +++ b/source/blender/blenkernel/intern/lightprobe.c @@ -60,8 +60,10 @@ void *BKE_lightprobe_add(Main *bmain, const char *name) } /** - * Only copy internal data of LightProbe ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of LightProbe ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 4d159adbb57..31e6d2e89e5 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -151,8 +151,10 @@ void BKE_linestyle_free(FreestyleLineStyle *linestyle) } /** - * Only copy internal data of Linestyle ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Linestyle ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/main.c b/source/blender/blenkernel/intern/main.c index 8ae5ed7fbdd..e50e37c5428 100644 --- a/source/blender/blenkernel/intern/main.c +++ b/source/blender/blenkernel/intern/main.c @@ -56,7 +56,8 @@ void BKE_main_free(Main *mainvar) ListBase *lbarray[MAX_LIBARRAY]; int a; - /* Since we are removing whole main, no need to bother 'properly' (and slowly) removing each ID from it. */ + /* Since we are removing whole main, no need to bother 'properly' + * (and slowly) removing each ID from it. */ const int free_flag = (LIB_ID_FREE_NO_MAIN | LIB_ID_FREE_NO_UI_USER | LIB_ID_FREE_NO_USER_REFCOUNT | LIB_ID_FREE_NO_DEG_TAG); @@ -285,7 +286,8 @@ void BKE_main_relations_free(Main *bmain) /** * Create a GSet storing all IDs present in given \a bmain, by their pointers. * - * \param gset: If not NULL, given GSet will be extended with IDs from given \a bmain, instead of creating a new one. + * \param gset: If not NULL, given GSet will be extended with IDs from given \a bmain, + * instead of creating a new one. */ GSet *BKE_main_gset_create(Main *bmain, GSet *gset) { @@ -348,8 +350,8 @@ ImBuf *BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data) } if (data) { - /* Note: we cannot use IMB_allocFromBuffer(), since it tries to dupalloc passed buffer, which will fail - * here (we do not want to pass the first two ints!). */ + /* Note: we cannot use IMB_allocFromBuffer(), since it tries to dupalloc passed buffer, + * which will fail here (we do not want to pass the first two ints!). */ img = IMB_allocImBuf( (unsigned int)data->width, (unsigned int)data->height, 32, IB_rect | IB_metadata); memcpy(img->rect, data->rect, BLEN_THUMB_MEMSIZE(data->width, data->height) - sizeof(*data)); @@ -381,7 +383,8 @@ const char *BKE_main_blendfile_path(const Main *bmain) /** * Return filepath of global main #G_MAIN. * - * \warning Usage is not recommended, you should always try to get a valid Main pointer from context... + * \warning Usage is not recommended, + * you should always try to get a valid Main pointer from context... */ const char *BKE_main_blendfile_path_from_global(void) { diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index c925ebe26cf..9a9b3757ef2 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -273,7 +273,10 @@ MaskSpline *BKE_mask_spline_add(MaskLayer *masklay) spline->tot_point = 1; /* cyclic shapes are more usually used */ - // spline->flag |= MASK_SPLINE_CYCLIC; // disable because its not so nice for drawing. could be done differently + /* Disable because its not so nice for drawing. could be done differently. */ +#if 0 + spline->flag |= MASK_SPLINE_CYCLIC; +#endif spline->weight_interp = MASK_SPLINE_INTERP_EASE; @@ -863,8 +866,10 @@ Mask *BKE_mask_copy_nolib(Mask *mask) } /** - * Only copy internal data of Mask ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Mask ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -1223,7 +1228,7 @@ static void mask_calc_point_handle(MaskSplinePoint *point, { BezTriple *bezt = &point->bezt; BezTriple *bezt_prev = NULL, *bezt_next = NULL; - //int handle_type = bezt->h1; + // int handle_type = bezt->h1; if (point_prev) { bezt_prev = &point_prev->bezt; @@ -1802,7 +1807,8 @@ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay, if (BKE_mask_layer_shape_spline_from_index(masklay, index, &spline, &spline_point_index)) { /* sanity check */ - /* the point has already been removed in this array so subtract one when comparing with the shapes */ + /* The point has already been removed in this array + * so subtract one when comparing with the shapes. */ int tot = BKE_mask_layer_shape_totvert(masklay) - 1; /* for interpolation */ diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index 31cb0e54785..fe6ef2e047d 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -20,14 +20,16 @@ /** \file * \ingroup bke * - * This module exposes a rasterizer that works as a black box - implementation details are confined to this file, + * This module exposes a rasterizer that works as a black box - implementation details + * are confined to this file. * * The basic method to access is: * - create & initialize a handle from a #Mask datablock. * - execute pixel lookups. * - free the handle. * - * This file is admittedly a bit confusticated, in quite few areas speed was chosen over readability, + * This file is admittedly a bit confusticated, + * in quite few areas speed was chosen over readability, * though it is commented - so shouldn't be so hard to see what's going on. * Implementation: * @@ -35,12 +37,16 @@ * * Initially 'kdopbvh' was used but this ended up being too slow. * - * To gain some extra speed we take advantage of a few shortcuts that can be made rasterizing masks specifically. - * - all triangles are known to be completely white - so no depth check is done on triangle intersection. - * - all quads are known to be feather outlines - the 1 and 0 depths are known by the vertex order in the quad, - * - there is no color - just a value for each mask pixel. - * - the mask spacial structure always maps to space 0-1 on X and Y axis. - * - bucketing is used to speed up lookups for geometry. + * To gain some extra speed we take advantage of a few shortcuts + * that can be made rasterizing masks specifically. + * + * - All triangles are known to be completely white - + * so no depth check is done on triangle intersection. + * - All quads are known to be feather outlines - + * the 1 and 0 depths are known by the vertex order in the quad, + * - There is no color - just a value for each mask pixel. + * - The mask spacial structure always maps to space 0-1 on X and Y axis. + * - Bucketing is used to speed up lookups for geometry. * * Other Details: * - used unsigned values all over for some extra speed on some arch's. @@ -48,7 +54,8 @@ * - initializing the spacial structure doesn't need to be as optimized as pixel lookups are. * - mask lookups need not be pixel aligned so any sub-pixel values from x/y (0 - 1), can be found. * (perhaps masks can be used as a vector texture in 3D later on) - * Currently, to build the spacial structure we have to calculate the total number of faces ahead of time. + * Currently, to build the spacial structure we have to calculate + * the total number of faces ahead of time. * * This is getting a bit complicated with the addition of unfilled splines and end capping - * If large changes are needed here we would be better off using an iterable @@ -504,16 +511,18 @@ static void layer_bucket_init(MaskRasterLayer *layer, const float pixel_size) for (yi = yi_min; yi <= yi_max; yi++) { unsigned int bucket_index = (layer->buckets_x * yi) + xi_min; for (xi = xi_min; xi <= xi_max; xi++, bucket_index++) { - // unsigned int bucket_index = (layer->buckets_x * yi) + xi; /* correct but do in outer loop */ + /* correct but do in outer loop */ + // unsigned int bucket_index = (layer->buckets_x * yi) + xi; BLI_assert(xi < layer->buckets_x); BLI_assert(yi < layer->buckets_y); BLI_assert(bucket_index < bucket_tot); - /* check if the bucket intersects with the face */ - /* note: there is a trade off here since checking box/tri intersections isn't - * as optimal as it could be, but checking pixels against faces they will never intersect - * with is likely the greater slowdown here - so check if the cell intersects the face */ + /* Check if the bucket intersects with the face. */ + /* Note: there is a trade off here since checking box/tri intersections isn't as + * optimal as it could be, but checking pixels against faces they will never + * intersect with is likely the greater slowdown here - + * so check if the cell intersects the face. */ if (layer_bucket_isect_test(layer, face_index, xi, @@ -1160,7 +1169,15 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, MEM_freeN(open_spline_ranges); - // fprintf(stderr, "%u %u (%u %u), %u\n", face_index, sf_tri_tot + tot_feather_quads, sf_tri_tot, tot_feather_quads, tot_boundary_used - tot_boundary_found); +#if 0 + fprintf(stderr, + "%u %u (%u %u), %u\n", + face_index, + sf_tri_tot + tot_feather_quads, + sf_tri_tot, + tot_feather_quads, + tot_boundary_used - tot_boundary_found); +#endif #ifdef USE_SCANFILL_EDGE_WORKAROUND BLI_assert(face_index + (tot_boundary_used - tot_boundary_found) == @@ -1232,7 +1249,7 @@ static float maskrasterize_layer_z_depth_quad( { float w[4]; barycentric_weights_v2_quad(v1, v2, v3, v4, pt, w); - //return (v1[2] * w[0]) + (v2[2] * w[1]) + (v3[2] * w[2]) + (v4[2] * w[3]); + // return (v1[2] * w[0]) + (v2[2] * w[1]) + (v3[2] * w[2]) + (v4[2] * w[3]); return w[2] + w[3]; /* we can make this assumption for small speedup */ } @@ -1270,7 +1287,7 @@ static float maskrasterize_layer_isect(unsigned int *face, /* needs work */ #if 1 /* quad check fails for bow-tie, so keep using 2 tri checks */ - //if (isect_point_quad_v2(xy, cos[face[0]], cos[face[1]], cos[face[2]], cos[face[3]])) + // if (isect_point_quad_v2(xy, cos[face[0]], cos[face[1]], cos[face[2]], cos[face[3]])) if (isect_point_tri_v2(xy, cos[face[0]], cos[face[1]], cos[face[2]]) || isect_point_tri_v2(xy, cos[face[0]], cos[face[2]], cos[face[3]])) { return maskrasterize_layer_z_depth_quad( diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 599dc1e15d5..75b9e355df9 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -169,8 +169,10 @@ Material *BKE_material_add_gpencil(Main *bmain, const char *name) } /** - * Only copy internal data of Material ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Material ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 0980089a1f7..d6fa071009e 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -99,8 +99,10 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name) } /** - * Only copy internal data of MetaBall ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of MetaBall ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -238,7 +240,8 @@ BoundBox *BKE_mball_boundbox_get(Object *ob) return ob->runtime.bb; } - /* This should always only be called with evaluated objects, but currently RNA is a problem here... */ + /* This should always only be called with evaluated objects, + * but currently RNA is a problem here... */ if (ob->runtime.curve_cache != NULL) { BKE_mball_texspace_calc(ob); } @@ -283,12 +286,15 @@ float *BKE_mball_make_orco(Object *ob, ListBase *dispbase) /* Note on mball basis stuff 2.5x (this is a can of worms) * This really needs a rewrite/refactor its totally broken in anything other then basic cases - * Multiple Scenes + Set Scenes & mixing mball basis SHOULD work but fails to update the depsgraph on rename - * and linking into scenes or removal of basis mball. so take care when changing this code. + * Multiple Scenes + Set Scenes & mixing mball basis SHOULD work but fails to update the depsgraph + * on rename and linking into scenes or removal of basis mball. + * So take care when changing this code. * - * Main idiot thing here is that the system returns find_basis_mball() objects which fail a is_basis_mball() test. + * Main idiot thing here is that the system returns find_basis_mball() + * objects which fail a is_basis_mball() test. * - * Not only that but the depsgraph and their areas depend on this behavior!, so making small fixes here isn't worth it. + * Not only that but the depsgraph and their areas depend on this behavior!, + * so making small fixes here isn't worth it. * - Campbell */ @@ -360,8 +366,8 @@ bool BKE_mball_is_any_unselected(const MetaBall *mb) /* \brief copy some properties from object to other metaball object with same base name * - * When some properties (wiresize, threshold, update flags) of metaball are changed, then this properties - * are copied to all metaballs in same "group" (metaballs with same base name: MBall, + * When some properties (wiresize, threshold, update flags) of metaball are changed, then this + * properties are copied to all metaballs in same "group" (metaballs with same base name: MBall, * MBall.001, MBall.002, etc). The most important is to copy properties to the base metaball, * because this metaball influence polygonisation of metaballs. */ void BKE_mball_properties_copy(Scene *scene, Object *active_object) @@ -427,7 +433,8 @@ Object *BKE_mball_basis_find(Scene *scene, Object *basis) if (ob != bob) { BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); - /* object ob has to be in same "group" ... it means, that it has to have same base of its name */ + /* Object ob has to be in same "group" ... it means, + * that it has to have same base of its name. */ if (STREQ(obname, basisname)) { if (obnr < basisnr) { basis = ob; diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c index b008eca2258..1218e78c6f0 100644 --- a/source/blender/blenkernel/intern/mball_tessellate.c +++ b/source/blender/blenkernel/intern/mball_tessellate.c @@ -1291,7 +1291,14 @@ static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Obje /* Rotation of MetaElem is stored in quat */ quat_to_mat4(rot, ml->quat); - /* basis object space -> world -> ml object space -> position -> rotation -> ml local space */ + /* Matrix multiply is as follows: + * basis object space -> + * world -> + * ml object space -> + * position -> + * rotation -> + * ml local space + */ mul_m4_series((float(*)[4])new_ml->mat, obinv, bob->obmat, pos, rot); /* ml local space -> basis object space */ invert_m4_m4((float(*)[4])new_ml->imat, (float(*)[4])new_ml->mat); @@ -1324,7 +1331,8 @@ static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Obje } /* untransformed Bounding Box of MetaElem */ - /* TODO, its possible the elem type has been changed and the exp* values can use a fallback */ + /* TODO, its possible the elem type has been changed and the exp* + * values can use a fallback. */ copy_v3_fl3(new_ml->bb->vec[0], -expx, -expy, -expz); /* 0 */ copy_v3_fl3(new_ml->bb->vec[1], +expx, -expy, -expz); /* 1 */ copy_v3_fl3(new_ml->bb->vec[2], +expx, +expy, -expz); /* 2 */ @@ -1424,8 +1432,9 @@ void BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob, ListBa if (process.totelem > 0) { build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, &process.allbb); - /* don't polygonize metaballs with too high resolution (base mball to small) - * note: Eps was 0.0001f but this was giving problems for blood animation for durian, using 0.00001f */ + /* Don't polygonize metaballs with too high resolution (base mball to small) + * note: Eps was 0.0001f but this was giving problems for blood animation for durian, + * using 0.00001f. */ if (ob->scale[0] > 0.00001f * (process.allbb.max[0] - process.allbb.min[0]) || ob->scale[1] > 0.00001f * (process.allbb.max[1] - process.allbb.min[1]) || ob->scale[2] > 0.00001f * (process.allbb.max[2] - process.allbb.min[2])) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 117567621c9..56832c1724a 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -536,8 +536,10 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name) } /** - * Only copy internal data of Mesh ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Mesh ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -926,7 +928,8 @@ void BKE_mesh_texspace_calc(Mesh *me) BoundBox *BKE_mesh_boundbox_get(Object *ob) { - /* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */ + /* This is Object-level data access, + * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */ if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) { Mesh *me = ob->data; float min[3], max[3]; @@ -1064,7 +1067,8 @@ int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr) nr--; } - /* check corrupt cases, bow-tie geometry, cant handle these because edge data wont exist so just return 0 */ + /* Check corrupt cases, bow-tie geometry, + * cant handle these because edge data wont exist so just return 0. */ if (nr == 3) { if ( /* real edges */ @@ -1363,7 +1367,8 @@ void BKE_mesh_transform(Mesh *me, float mat[4][4], bool do_keys) } /* don't update normals, caller can do this explicitly. - * We do update loop normals though, those may not be auto-generated (see e.g. STL import script)! */ + * We do update loop normals though, those may not be auto-generated + * (see e.g. STL import script)! */ if (lnors) { float m3[3][3]; @@ -1640,8 +1645,9 @@ void BKE_mesh_apply_vert_normals(Mesh *mesh, short (*vertNormals)[3]) /** * Compute 'split' (aka loop, or per face corner's) normals. * - * \param r_lnors_spacearr: Allows to get computed loop normal space array. That data, among other things, - * contains 'smooth fan' info, useful e.g. to split geometry along sharp edges... + * \param r_lnors_spacearr: Allows to get computed loop normal space array. + * That data, among other things, contains 'smooth fan' info, useful e.g. + * to split geometry along sharp edges... */ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr) { @@ -1651,7 +1657,8 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spac bool free_polynors = false; /* Note that we enforce computing clnors when the clnor space array is requested by caller here. - * However, we obviously only use the autosmooth angle threshold only in case autosmooth is enabled. */ + * However, we obviously only use the autosmooth angle threshold + * only in case autosmooth is enabled. */ const bool use_split_normals = (r_lnors_spacearr != NULL) || ((mesh->flag & ME_AUTOSMOOTH) != 0); const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : (float)M_PI; @@ -1668,7 +1675,8 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spac clnors = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); if (CustomData_has_layer(&mesh->pdata, CD_NORMAL)) { - /* This assume that layer is always up to date, not sure this is the case (esp. in Edit mode?)... */ + /* This assume that layer is always up to date, not sure this is the case + * (esp. in Edit mode?)... */ polynors = CustomData_get_layer(&mesh->pdata, CD_NORMAL); free_polynors = false; } @@ -1738,8 +1746,9 @@ static int split_faces_prepare_new_verts(const Mesh *mesh, SplitFaceNewVert **new_verts, MemArena *memarena) { - /* This is now mandatory, trying to do the job in simple way without that data is doomed to fail, even when only - * dealing with smooth/flat faces one can find cases that no simple algorithm can handle properly. */ + /* This is now mandatory, trying to do the job in simple way without that data is doomed to fail, + * even when only dealing with smooth/flat faces one can find cases that no simple algorithm + * can handle properly. */ BLI_assert(lnors_spacearr != NULL); const int loops_len = mesh->totloop; @@ -1785,8 +1794,9 @@ static int split_faces_prepare_new_verts(const Mesh *mesh, if (!vert_used) { BLI_BITMAP_ENABLE(verts_used, vert_idx); /* We need to update that vertex's normal here, we won't go over it again. */ - /* This is important! *DO NOT* set vnor to final computed lnor, vnor should always be defined to - * 'automatic normal' value computed from its polys, not some custom normal. + /* This is important! *DO NOT* set vnor to final computed lnor, + * vnor should always be defined to 'automatic normal' value computed from its polys, + * not some custom normal. * Fortunately, that's the loop normal space's 'lnor' reference vector. ;) */ normal_float_to_short_v3(mvert[vert_idx].no, (*lnor_space)->vec_lnor); } @@ -1938,8 +1948,9 @@ void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals) mesh, &lnors_spacearr, &new_verts, memarena); if (num_new_verts > 0) { - /* Reminder: beyond this point, there is no way out, mesh is in invalid state (due to early-reassignment of - * loops' vertex and edge indices to new, to-be-created split ones). */ + /* Reminder: beyond this point, there is no way out, mesh is in invalid state + * (due to early-reassignment of loops' vertex and edge indices to new, + * to-be-created split ones). */ const int num_new_edges = split_faces_prepare_new_edges(mesh, &new_edges, memarena); /* We can have to split a vertex without having to add a single new edge... */ diff --git a/source/blender/blenkernel/intern/mesh_convert.c b/source/blender/blenkernel/intern/mesh_convert.c index 93017e77d36..3f4e504867c 100644 --- a/source/blender/blenkernel/intern/mesh_convert.c +++ b/source/blender/blenkernel/intern/mesh_convert.c @@ -656,7 +656,8 @@ void BKE_mesh_from_nurbs_displist(Main *bmain, cu->mat = NULL; cu->totcol = 0; - /* Do not decrement ob->data usercount here, it's done at end of func with BKE_id_free_us() call. */ + /* Do not decrement ob->data usercount here, + * it's done at end of func with BKE_id_free_us() call. */ ob->data = me; ob->type = OB_MESH; @@ -1036,9 +1037,10 @@ Mesh *BKE_mesh_new_from_object(Depsgraph *depsgraph, BKE_id_free(NULL, tmpobj); - /* XXX The curve to mesh conversion is convoluted... But essentially, BKE_mesh_from_nurbs_displist() - * already transfers the ownership of materials from the temp copy of the Curve ID to the new - * Mesh ID, so we do not want to increase materials' usercount later. */ + /* XXX The curve to mesh conversion is convoluted... + * But essentially, BKE_mesh_from_nurbs_displist() + * already transfers the ownership of materials from the temp copy of the Curve ID to the + * new Mesh ID, so we do not want to increase materials' usercount later. */ do_mat_id_data_us = false; break; @@ -1236,25 +1238,26 @@ static void add_shapekey_layers(Mesh *mesh_dest, Mesh *mesh_src) Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph, Scene *scene, - Object *ob, - ModifierData *md, + Object *ob_eval, + ModifierData *md_eval, int build_shapekey_layers) { - Mesh *me = ob->runtime.mesh_orig ? ob->runtime.mesh_orig : ob->data; - const ModifierTypeInfo *mti = modifierType_getInfo(md->type); + Mesh *me = ob_eval->runtime.mesh_orig ? ob_eval->runtime.mesh_orig : ob_eval->data; + const ModifierTypeInfo *mti = modifierType_getInfo(md_eval->type); Mesh *result; KeyBlock *kb; - ModifierEvalContext mectx = {depsgraph, ob, 0}; + ModifierEvalContext mectx = {depsgraph, ob_eval, 0}; - if (!(md->mode & eModifierMode_Realtime)) { + if (!(md_eval->mode & eModifierMode_Realtime)) { return NULL; } - if (mti->isDisabled && mti->isDisabled(scene, md, 0)) { + if (mti->isDisabled && mti->isDisabled(scene, md_eval, 0)) { return NULL; } - if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr - 1))) { + if (build_shapekey_layers && me->key && + (kb = BLI_findlink(&me->key->block, ob_eval->shapenr - 1))) { BKE_keyblock_convert_to_mesh(kb, me); } @@ -1262,8 +1265,8 @@ Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph, int numVerts; float(*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts); - mti->deformVerts(md, &mectx, NULL, deformedVerts, numVerts); BKE_id_copy_ex(NULL, &me->id, (ID **)&result, LIB_ID_COPY_LOCALIZE); + mti->deformVerts(md_eval, &mectx, result, deformedVerts, numVerts); BKE_mesh_apply_vert_coords(result, deformedVerts); if (build_shapekey_layers) { @@ -1280,7 +1283,7 @@ Mesh *BKE_mesh_create_derived_for_modifier(struct Depsgraph *depsgraph, add_shapekey_layers(mesh_temp, me); } - result = mti->applyModifier(md, &mectx, mesh_temp); + result = mti->applyModifier(md_eval, &mectx, mesh_temp); ASSERT_IS_VALID_MESH(result); if (mesh_temp != result) { @@ -1361,7 +1364,8 @@ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, bool take_ownership) { /* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */ - /* TODO(Sybren): the above claim came from DM_to_mesh(); check whether it is still true with Mesh */ + /* TODO(Sybren): the above claim came from DM_to_mesh(); + * check whether it is still true with Mesh */ Mesh tmp = *mesh_dst; int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly; int did_shapekeys = 0; @@ -1429,8 +1433,8 @@ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, /* not all DerivedMeshes store their verts/edges/faces in CustomData, so * we set them here in case they are missing */ - /* TODO(Sybren): we could probably replace CD_ASSIGN with alloctype and always directly pass mesh_src->mxxx, - * instead of using a ternary operator. */ + /* TODO(Sybren): we could probably replace CD_ASSIGN with alloctype and + * always directly pass mesh_src->mxxx, instead of using a ternary operator. */ if (!CustomData_has_layer(&tmp.vdata, CD_MVERT)) { CustomData_add_layer(&tmp.vdata, CD_MVERT, diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 800d61a6a66..d889fca3a3a 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -168,7 +168,8 @@ void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, if (!pnors) { pnors = MEM_calloc_arrayN((size_t)numPolys, sizeof(float[3]), __func__); } - /* if (!fnors) fnors = MEM_calloc_arrayN(numFaces, sizeof(float[3]), "face nors mesh.c"); */ /* NO NEED TO ALLOC YET */ + /* NO NEED TO ALLOC YET */ + /* if (!fnors) fnors = MEM_calloc_arrayN(numFaces, sizeof(float[3]), "face nors mesh.c"); */ if (only_face_normals == false) { /* vertex normals are optional, they require some extra calculations, @@ -366,7 +367,8 @@ void BKE_mesh_calc_normals_poly(MVert *mverts, BLI_task_parallel_range(0, numPolys, &data, mesh_calc_normals_poly_prepare_cb, &settings); /* Actually accumulate weighted loop normals into vertex ones. */ - /* Unfortunately, not possible to thread that (not in a reasonable, totally lock- and barrier-free fashion), + /* Unfortunately, not possible to thread that + * (not in a reasonable, totally lock- and barrier-free fashion), * since several loops will point to the same vertex... */ for (int lidx = 0; lidx < numLoops; lidx++) { add_v3_v3(vnors[mloop[lidx].v], data.lnors_weighted[lidx]); @@ -424,7 +426,8 @@ void BKE_mesh_ensure_normals_for_display(Mesh *mesh) } } -/* Note that this does not update the CD_NORMAL layer, but does update the normals in the CD_MVERT layer. */ +/* Note that this does not update the CD_NORMAL layer, + * but does update the normals in the CD_MVERT layer. */ void BKE_mesh_calc_normals(Mesh *mesh) { #ifdef DEBUG_TIME @@ -609,7 +612,8 @@ MLoopNorSpace *BKE_lnor_space_create(MLoopNorSpaceArray *lnors_spacearr) /* Should only be called once. * Beware, this modifies ref_vec and other_vec in place! - * In case no valid space can be generated, ref_alpha and ref_beta are set to zero (which means 'use auto lnors'). + * In case no valid space can be generated, ref_alpha and ref_beta are set to zero + * (which means 'use auto lnors'). */ void BKE_lnor_space_define(MLoopNorSpace *lnor_space, const float lnor[3], @@ -646,8 +650,10 @@ void BKE_lnor_space_define(MLoopNorSpace *lnor_space, BLI_stack_discard(edge_vectors); nbr++; } - /* Note: In theory, this could be 'nbr > 2', but there is one case where we only have two edges for - * two loops: a smooth vertex with only two edges and two faces (our Monkey's nose has that, e.g.). */ + /* Note: In theory, this could be 'nbr > 2', + * but there is one case where we only have two edges for two loops: + * a smooth vertex with only two edges and two faces (our Monkey's nose has that, e.g.). + */ BLI_assert(nbr >= 2); /* This piece of code shall only be called for more than one loop... */ lnor_space->ref_alpha = alpha / (float)nbr; } @@ -683,10 +689,11 @@ void BKE_lnor_space_define(MLoopNorSpace *lnor_space, /** * Add a new given loop to given lnor_space. - * Depending on \a lnor_space->data_type, we expect \a bm_loop to be a pointer to BMLoop struct (in case of BMLOOP_PTR), - * or NULL (in case of LOOP_INDEX), loop index is then stored in pointer. - * If \a is_single is set, the BMLoop or loop index is directly stored in \a lnor_space->loops pointer (since there - * is only one loop in this fan), else it is added to the linked list of loops in the fan. + * Depending on \a lnor_space->data_type, we expect \a bm_loop to be a pointer to BMLoop struct + * (in case of BMLOOP_PTR), or NULL (in case of LOOP_INDEX), loop index is then stored in pointer. + * If \a is_single is set, the BMLoop or loop index is directly stored in \a lnor_space->loops + * pointer (since there is only one loop in this fan), + * else it is added to the linked list of loops in the fan. */ void BKE_lnor_space_add_loop(MLoopNorSpaceArray *lnors_spacearr, MLoopNorSpace *lnor_space, @@ -775,7 +782,8 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, alpha = saacosf(cos_alpha); if (alpha > lnor_space->ref_alpha) { - /* Note we could stick to [0, pi] range here, but makes decoding more complex, not worth it. */ + /* Note we could stick to [0, pi] range here, + * but makes decoding more complex, not worth it. */ r_clnor_data[0] = unit_float_to_short(-(pi2 - alpha) / (pi2 - lnor_space->ref_alpha)); } else { @@ -812,17 +820,20 @@ void BKE_lnor_space_custom_normal_to_data(MLoopNorSpace *lnor_space, typedef struct LoopSplitTaskData { /* Specific to each instance (each task). */ - MLoopNorSpace * - lnor_space; /* We have to create those outside of tasks, since afaik memarena is not threadsafe. */ + + /** We have to create those outside of tasks, since afaik memarena is not threadsafe. */ + MLoopNorSpace *lnor_space; float (*lnor)[3]; const MLoop *ml_curr; const MLoop *ml_prev; int ml_curr_index; int ml_prev_index; - const int *e2l_prev; /* Also used a flag to switch between single or fan process! */ + /** Also used a flag to switch between single or fan process! */ + const int *e2l_prev; int mp_index; - /* This one is special, it's owned and managed by worker tasks, avoid to have to create it for each fan! */ + /** This one is special, it's owned and managed by worker tasks, + * avoid to have to create it for each fan! */ BLI_Stack *edge_vectors; char pad_c; @@ -830,8 +841,8 @@ typedef struct LoopSplitTaskData { typedef struct LoopSplitTaskDataCommon { /* Read/write. - * Note we do not need to protect it, though, since two different tasks will *always* affect different - * elements in the arrays. */ + * Note we do not need to protect it, though, since two different tasks will *always* affect + * different elements in the arrays. */ MLoopNorSpaceArray *lnors_spacearr; float (*loopnors)[3]; short (*clnors_data)[2]; @@ -895,8 +906,8 @@ static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data, loop_to_poly[ml_curr_index] = mp_index; - /* Pre-populate all loop normals as if their verts were all-smooth, this way we don't have to compute - * those later! + /* Pre-populate all loop normals as if their verts were all-smooth, + * this way we don't have to compute those later! */ if (loopnors) { normal_short_to_float_v3(loopnors[ml_curr_index], mverts[ml_curr->v].no); @@ -916,8 +927,8 @@ static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data, /* Second loop using this edge, time to test its sharpness. * An edge is sharp if it is tagged as such, or its face is not smooth, - * or both poly have opposed (flipped) normals, i.e. both loops on the same edge share the same vertex, - * or angle between both its polys' normals is above split_angle value. + * or both poly have opposed (flipped) normals, i.e. both loops on the same edge share the + * same vertex, or angle between both its polys' normals is above split_angle value. */ if (!(mp->flag & ME_SMOOTH) || (medges[ml_curr->e].flag & ME_SHARP) || ml_curr->v == mloops[e2l[0]].v || is_angle_sharp) { @@ -964,7 +975,8 @@ static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data, /** Define sharp edges as needed to mimic 'autosmooth' from angle threshold. * - * Used when defining an empty custom loop normals data layer, to keep same shading as with autosmooth! + * Used when defining an empty custom loop normals data layer, + * to keep same shading as with autosmooth! */ void BKE_edges_sharp_from_angle_set(const struct MVert *mverts, const int UNUSED(numVerts), @@ -1079,7 +1091,13 @@ static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopS */ copy_v3_v3(*lnor, polynors[mp_index]); - // printf("BASIC: handling loop %d / edge %d / vert %d / poly %d\n", ml_curr_index, ml_curr->e, ml_curr->v, mp_index); +#if 0 + printf("BASIC: handling loop %d / edge %d / vert %d / poly %d\n", + ml_curr_index, + ml_curr->e, + ml_curr->v, + mp_index); +#endif /* If needed, generate this (simple!) lnor space. */ if (lnors_spacearr) { @@ -1100,7 +1118,8 @@ static void split_loop_nor_single_do(LoopSplitTaskDataCommon *common_data, LoopS normalize_v3(vec_prev); BKE_lnor_space_define(lnor_space, *lnor, vec_curr, vec_prev, NULL); - /* We know there is only one loop in this space, no need to create a linklist in this case... */ + /* We know there is only one loop in this space, + * no need to create a linklist in this case... */ BKE_lnor_space_add_loop(lnors_spacearr, lnor_space, ml_curr_index, NULL, true); if (clnors_data) { @@ -1138,10 +1157,10 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli /* Gah... We have to fan around current vertex, until we find the other non-smooth edge, * and accumulate face normals into the vertex! - * Note in case this vertex has only one sharp edges, this is a waste because the normal is the same as - * the vertex normal, but I do not see any easy way to detect that (would need to count number - * of sharp edges per vertex, I doubt the additional memory usage would be worth it, especially as - * it should not be a common case in real-life meshes anyway). + * Note in case this vertex has only one sharp edges, this is a waste because the normal is the + * same as the vertex normal, but I do not see any easy way to detect that (would need to count + * number of sharp edges per vertex, I doubt the additional memory usage would be worth it, + * especially as it should not be a common case in real-life meshes anyway). */ const unsigned int mv_pivot_index = ml_curr->v; /* The vertex we are "fanning" around! */ const MVert *mv_pivot = &mverts[mv_pivot_index]; @@ -1193,8 +1212,8 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli while (true) { const MEdge *me_curr = &medges[mlfan_curr->e]; /* Compute edge vectors. - * NOTE: We could pre-compute those into an array, in the first iteration, instead of computing them - * twice (or more) here. However, time gained is not worth memory and time lost, + * NOTE: We could pre-compute those into an array, in the first iteration, instead of computing + * them twice (or more) here. However, time gained is not worth memory and time lost, * given the fact that this code should not be called that much in real-life meshes... */ { @@ -1293,13 +1312,14 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli printf("Invalid clnors in this fan!\n"); } while ((clnor = BLI_SMALLSTACK_POP(clnors))) { - //print_v2("org clnor", clnor); + // print_v2("org clnor", clnor); clnor[0] = (short)clnors_avg[0]; clnor[1] = (short)clnors_avg[1]; } - //print_v2("new clnors", clnors_avg); + // print_v2("new clnors", clnors_avg); } - /* Extra bonus: since smallstack is local to this func, no more need to empty it at all cost! */ + /* Extra bonus: since smallstack is local to this func, + * no more need to empty it at all cost! */ BKE_lnor_space_custom_data_to_normal(lnor_space, *clnor_ref, lnor); } @@ -1314,7 +1334,8 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data, LoopSpli copy_v3_v3(nor, lnor); } } - /* Extra bonus: since smallstack is local to this func, no more need to empty it at all cost! */ + /* Extra bonus: since smallstack is local to this func, + * no more need to empty it at all cost! */ } } @@ -1367,7 +1388,8 @@ static void loop_split_worker(TaskPool *__restrict pool, void *taskdata, int UNU } /* Check whether gievn loop is part of an unknown-so-far cyclic smooth fan, or not. - * Needed because cyclic smooth fans have no obvious 'entry point', and yet we need to walk them once, and only once. */ + * Needed because cyclic smooth fans have no obvious 'entry point', + * and yet we need to walk them once, and only once. */ static bool loop_split_generator_check_cyclic_smooth_fan(const MLoop *mloops, const MPoly *mpolys, const int (*edge_to_loops)[2], @@ -1425,8 +1447,8 @@ static bool loop_split_generator_check_cyclic_smooth_fan(const MLoop *mloops, /* Smooth loop/edge... */ else if (BLI_BITMAP_TEST(skip_loops, mlfan_vert_index)) { if (mlfan_vert_index == ml_curr_index) { - /* We walked around a whole cyclic smooth fan without finding any already-processed loop, means we can - * use initial ml_curr/ml_prev edge as start for this smooth fan. */ + /* We walked around a whole cyclic smooth fan without finding any already-processed loop, + * means we can use initial ml_curr/ml_prev edge as start for this smooth fan. */ return true; } /* ... already checked in some previous looping, we can abort. */ @@ -1464,7 +1486,8 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common LoopSplitTaskData *data_buff = NULL; int data_idx = 0; - /* Temp edge vectors stack, only used when computing lnor spacearr (and we are not multi-threading). */ + /* Temp edge vectors stack, only used when computing lnor spacearr + * (and we are not multi-threading). */ BLI_Stack *edge_vectors = NULL; #ifdef DEBUG_TIME @@ -1477,8 +1500,8 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common } } - /* We now know edges that can be smoothed (with their vector, and their two loops), and edges that will be hard! - * Now, time to generate the normals. + /* We now know edges that can be smoothed (with their vector, and their two loops), + * and edges that will be hard! Now, time to generate the normals. */ for (mp = mpolys, mp_index = 0; mp_index < numPolys; mp++, mp_index++) { float(*lnors)[3]; @@ -1494,17 +1517,25 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common const int *e2l_curr = edge_to_loops[ml_curr->e]; const int *e2l_prev = edge_to_loops[ml_prev->e]; - // printf("Checking loop %d / edge %u / vert %u (sharp edge: %d, skiploop: %d)...", - // ml_curr_index, ml_curr->e, ml_curr->v, IS_EDGE_SHARP(e2l_curr), BLI_BITMAP_TEST_BOOL(skip_loops, ml_curr_index)); +#if 0 + printf("Checking loop %d / edge %u / vert %u (sharp edge: %d, skiploop: %d)...", + ml_curr_index, + ml_curr->e, + ml_curr->v, + IS_EDGE_SHARP(e2l_curr), + BLI_BITMAP_TEST_BOOL(skip_loops, ml_curr_index)); +#endif /* A smooth edge, we have to check for cyclic smooth fan case. - * If we find a new, never-processed cyclic smooth fan, we can do it now using that loop/edge as - * 'entry point', otherwise we can skip it. */ + * If we find a new, never-processed cyclic smooth fan, we can do it now using that loop/edge + * as 'entry point', otherwise we can skip it. */ + /* Note: In theory, we could make loop_split_generator_check_cyclic_smooth_fan() store - * mlfan_vert_index'es and edge indexes in two stacks, to avoid having to fan again around the vert during - * actual computation of clnor & clnorspace. However, this would complicate the code, add more memory usage, - * and despite its logical complexity, loop_manifold_fan_around_vert_next() is quite cheap in term of - * CPU cycles, so really think it's not worth it. */ + * mlfan_vert_index'es and edge indexes in two stacks, to avoid having to fan again around + * the vert during actual computation of clnor & clnorspace. However, this would complicate + * the code, add more memory usage, and despite its logical complexity, + * loop_manifold_fan_around_vert_next() is quite cheap in term of CPU cycles, + * so really think it's not worth it. */ if (!IS_EDGE_SHARP(e2l_curr) && (BLI_BITMAP_TEST(skip_loops, ml_curr_index) || !loop_split_generator_check_cyclic_smooth_fan(mloops, mpolys, @@ -1551,10 +1582,11 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common } } /* We *do not need* to check/tag loops as already computed! - * Due to the fact a loop only links to one of its two edges, a same fan *will never be walked - * more than once!* - * Since we consider edges having neighbor polys with inverted (flipped) normals as sharp, we are sure - * that no fan will be skipped, even only considering the case (sharp curr_edge, smooth prev_edge), + * Due to the fact a loop only links to one of its two edges, + * a same fan *will never be walked more than once!* + * Since we consider edges having neighbor polys with inverted + * (flipped) normals as sharp, we are sure that no fan will be skipped, + * even only considering the case (sharp curr_edge, smooth prev_edge), * and not the alternative (smooth curr_edge, sharp prev_edge). * All this due/thanks to link between normals and loop ordering (i.e. winding). */ @@ -1590,7 +1622,8 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common } } - /* Last block of data... Since it is calloc'ed and we use first NULL item as stopper, everything is fine. */ + /* Last block of data... Since it is calloc'ed and we use first NULL item as stopper, + * everything is fine. */ if (pool && data_idx) { BLI_task_pool_push(pool, loop_split_worker, data_buff, true, TASK_PRIORITY_LOW); } @@ -1607,7 +1640,8 @@ static void loop_split_generator(TaskPool *pool, LoopSplitTaskDataCommon *common /** * Compute split normals, i.e. vertex normals associated with each poly (hence 'loop normals'). - * Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry (splitting edges). + * Useful to materialize sharp edges (or non-smooth faces) without actually modifying the geometry + * (splitting edges). */ void BKE_mesh_normals_loop_split(const MVert *mverts, const int UNUSED(numVerts), @@ -1625,14 +1659,17 @@ void BKE_mesh_normals_loop_split(const MVert *mverts, short (*clnors_data)[2], int *r_loop_to_poly) { - /* For now this is not supported. If we do not use split normals, we do not generate anything fancy! */ + /* For now this is not supported. + * If we do not use split normals, we do not generate anything fancy! */ BLI_assert(use_split_normals || !(r_lnors_spacearr)); if (!use_split_normals) { /* In this case, we simply fill lnors with vnors (or fnors for flat faces), quite simple! * Note this is done here to keep some logic and consistency in this quite complex code, - * since we may want to use lnors even when mesh's 'autosmooth' is disabled (see e.g. mesh mapping code). - * As usual, we could handle that on case-by-case basis, but simpler to keep it well confined here. + * since we may want to use lnors even when mesh's 'autosmooth' is disabled + * (see e.g. mesh mapping code). + * As usual, we could handle that on case-by-case basis, + * but simpler to keep it well confined here. */ int mp_index; @@ -1657,15 +1694,20 @@ void BKE_mesh_normals_loop_split(const MVert *mverts, return; } - /* Mapping edge -> loops. - * If that edge is used by more than two loops (polys), it is always sharp (and tagged as such, see below). - * We also use the second loop index as a kind of flag: smooth edge: > 0, - * sharp edge: < 0 (INDEX_INVALID || INDEX_UNSET), - * unset: INDEX_UNSET - * Note that currently we only have two values for second loop of sharp edges. However, if needed, we can - * store the negated value of loop index instead of INDEX_INVALID to retrieve the real value later in code). - * Note also that lose edges always have both values set to 0! - */ + /** + * Mapping edge -> loops. + * If that edge is used by more than two loops (polys), + * it is always sharp (and tagged as such, see below). + * We also use the second loop index as a kind of flag: + * + * - smooth edge: > 0. + * - sharp edge: < 0 (INDEX_INVALID || INDEX_UNSET). + * - unset: INDEX_UNSET. + * + * Note that currently we only have two values for second loop of sharp edges. + * However, if needed, we can store the negated value of loop index instead of INDEX_INVALID + * to retrieve the real value later in code). + * Note also that lose edges always have both values set to 0! */ int(*edge_to_loops)[2] = MEM_calloc_arrayN((size_t)numEdges, sizeof(*edge_to_loops), __func__); /* Simple mapping from a loop to its polygon index. */ @@ -1750,12 +1792,12 @@ void BKE_mesh_normals_loop_split(const MVert *mverts, /** * Compute internal representation of given custom normals (as an array of float[2]). - * It also makes sure the mesh matches those custom normals, by setting sharp edges flag as needed to get a - * same custom lnor for all loops sharing a same smooth fan. + * It also makes sure the mesh matches those custom normals, by setting sharp edges flag as needed + * to get a same custom lnor for all loops sharing a same smooth fan. * If use_vertices if true, r_custom_loopnors is assumed to be per-vertex, not per-loop * (this allows to set whole vert's normals at once, useful in some cases). - * r_custom_loopnors is expected to have normalized normals, or zero ones, in which case they will be replaced - * by default loop/vertex normal. + * r_custom_loopnors is expected to have normalized normals, or zero ones, + * in which case they will be replaced by default loop/vertex normal. */ static void mesh_normals_loop_custom_set(const MVert *mverts, const int numVerts, @@ -1770,17 +1812,19 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, short (*r_clnors_data)[2], const bool use_vertices) { - /* We *may* make that poor BKE_mesh_normals_loop_split() even more complex by making it handling that - * feature too, would probably be more efficient in absolute. + /* We *may* make that poor BKE_mesh_normals_loop_split() even more complex by making it handling + * that feature too, would probably be more efficient in absolute. * However, this function *is not* performance-critical, since it is mostly expected to be called - * by io addons when importing custom normals, and modifier (and perhaps from some editing tools later?). + * by io addons when importing custom normals, and modifier + * (and perhaps from some editing tools later?). * So better to keep some simplicity here, and just call BKE_mesh_normals_loop_split() twice! */ MLoopNorSpaceArray lnors_spacearr = {NULL}; BLI_bitmap *done_loops = BLI_BITMAP_NEW((size_t)numLoops, __func__); float(*lnors)[3] = MEM_calloc_arrayN((size_t)numLoops, sizeof(*lnors), __func__); int *loop_to_poly = MEM_malloc_arrayN((size_t)numLoops, sizeof(int), __func__); - /* In this case we always consider split nors as ON, and do not want to use angle to define smooth fans! */ + /* In this case we always consider split nors as ON, + * and do not want to use angle to define smooth fans! */ const bool use_split_normals = true; const float split_angle = (float)M_PI; int i; @@ -1822,12 +1866,12 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, BLI_assert(lnors_spacearr.data_type == MLNOR_SPACEARR_LOOP_INDEX); - /* Now, check each current smooth fan (one lnor space per smooth fan!), and if all its matching custom lnors - * are not (enough) equal, add sharp edges as needed. - * This way, next time we run BKE_mesh_normals_loop_split(), we'll get lnor spacearr/smooth fans matching - * given custom lnors. - * Note this code *will never* unsharp edges! - * And quite obviously, when we set custom normals per vertices, running this is absolutely useless. + /* Now, check each current smooth fan (one lnor space per smooth fan!), + * and if all its matching custom lnors are not (enough) equal, add sharp edges as needed. + * This way, next time we run BKE_mesh_normals_loop_split(), we'll get lnor spacearr/smooth fans + * matching given custom lnors. + * Note this code *will never* unsharp edges! And quite obviously, + * when we set custom normals per vertices, running this is absolutely useless. */ if (!use_vertices) { for (i = 0; i < numLoops; i++) { @@ -1845,13 +1889,13 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, if (!BLI_BITMAP_TEST(done_loops, i)) { /* Notes: - * * In case of mono-loop smooth fan, we have nothing to do. - * * Loops in this linklist are ordered (in reversed order compared to how they were discovered by - * BKE_mesh_normals_loop_split(), but this is not a problem). Which means if we find a - * mismatching clnor, we know all remaining loops will have to be in a new, different smooth fan/ - * lnor space. - * * In smooth fan case, we compare each clnor against a ref one, to avoid small differences adding - * up into a real big one in the end! + * * In case of mono-loop smooth fan, we have nothing to do. + * * Loops in this linklist are ordered (in reversed order compared to how they were + * discovered by BKE_mesh_normals_loop_split(), but this is not a problem). + * Which means if we find a mismatching clnor, + * we know all remaining loops will have to be in a new, different smooth fan/lnor space. + * * In smooth fan case, we compare each clnor against a ref one, + * to avoid small differences adding up into a real big one in the end! */ if (lnors_spacearr.lspacearr[i]->flags & MLNOR_SPACE_IS_SINGLE) { BLI_BITMAP_ENABLE(done_loops, i); @@ -1874,8 +1918,8 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, else if (dot_v3v3(org_nor, nor) < LNOR_SPACE_TRIGO_THRESHOLD) { /* Current normal differs too much from org one, we have to tag the edge between * previous loop's face and current's one as sharp. - * We know those two loops do not point to the same edge, since we do not allow reversed winding - * in a same smooth fan. + * We know those two loops do not point to the same edge, + * since we do not allow reversed winding in a same smooth fan. */ const MPoly *mp = &mpolys[loop_to_poly[lidx]]; const MLoop *mlp = @@ -1890,7 +1934,8 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, BLI_BITMAP_ENABLE(done_loops, lidx); } - /* We also have to check between last and first loops, otherwise we may miss some sharp edges here! + /* We also have to check between last and first loops, + * otherwise we may miss some sharp edges here! * This is just a simplified version of above while loop. * See T45984. */ loops = lnors_spacearr.lspacearr[i]->loops; @@ -1932,7 +1977,8 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, BLI_bitmap_set_all(done_loops, true, (size_t)numLoops); } - /* And we just have to convert plain object-space custom normals to our lnor space-encoded ones. */ + /* And we just have to convert plain object-space custom normals to our + * lnor space-encoded ones. */ for (i = 0; i < numLoops; i++) { if (!lnors_spacearr.lspacearr[i]) { BLI_BITMAP_DISABLE(done_loops, i); @@ -1943,9 +1989,9 @@ static void mesh_normals_loop_custom_set(const MVert *mverts, } if (BLI_BITMAP_TEST_BOOL(done_loops, i)) { - /* Note we accumulate and average all custom normals in current smooth fan, to avoid getting different - * clnors data (tiny differences in plain custom normals can give rather huge differences in - * computed 2D factors). + /* Note we accumulate and average all custom normals in current smooth fan, + * to avoid getting different clnors data (tiny differences in plain custom normals can + * give rather huge differences in computed 2D factors). */ LinkNode *loops = lnors_spacearr.lspacearr[i]->loops; if (lnors_spacearr.lspacearr[i]->flags & MLNOR_SPACE_IS_SINGLE) { @@ -2092,7 +2138,8 @@ static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const } /** - * Higher level functions hiding most of the code needed around call to #BKE_mesh_normals_loop_custom_set(). + * Higher level functions hiding most of the code needed around call to + * #BKE_mesh_normals_loop_custom_set(). * * \param r_custom_loopnors is not const, since code will replace zero_v3 normals there * with automatically computed vectors. @@ -2103,7 +2150,8 @@ void BKE_mesh_set_custom_normals(Mesh *mesh, float (*r_custom_loopnors)[3]) } /** - * Higher level functions hiding most of the code needed around call to #BKE_mesh_normals_loop_custom_from_vertices_set(). + * Higher level functions hiding most of the code needed around call to + * #BKE_mesh_normals_loop_custom_from_vertices_set(). * * \param r_custom_loopnors is not const, since code will replace zero_v3 normals there * with automatically computed vectors. @@ -2327,7 +2375,8 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const } /** - * Calculate the volume and volume-weighted centroid of the volume formed by the polygon and the origin. + * Calculate the volume and volume-weighted centroid of the volume + * formed by the polygon and the origin. * Results will be negative if the origin is "outside" the polygon * (+ve normal side), but the polygon may be non-planar with no effect. * @@ -2339,8 +2388,8 @@ float BKE_mesh_calc_poly_area(const MPoly *mpoly, const MLoop *loopstart, const * - Volume is 6x actual volume, and centroid is 4x actual volume-weighted centroid * (so division can be done once at the end). * - Results will have bias if polygon is non-planar. - * - The resulting volume will only be correct if the mesh is manifold and has consistent face winding - * (non-contiguous face normals or holes in the mesh surface). + * - The resulting volume will only be correct if the mesh is manifold and has consistent + * face winding (non-contiguous face normals or holes in the mesh surface). */ static float mesh_calc_poly_volume_centroid(const MPoly *mpoly, const MLoop *loopstart, @@ -2369,7 +2418,8 @@ static float mesh_calc_poly_volume_centroid(const MPoly *mpoly, * of the triangle and the origin as the fourth vertex. * The centroid is simply the average of the 4 vertices. * - * Note that the vector is 4x the actual centroid so the division can be done once at the end. */ + * Note that the vector is 4x the actual centroid + * so the division can be done once at the end. */ for (uint j = 0; j < 3; j++) { r_cent[j] += tetra_volume * (v_pivot[j] + v_step1[j] + v_step2[j]); } @@ -2541,7 +2591,8 @@ bool BKE_mesh_center_of_surface(const Mesh *me, float r_cent[3]) } /** - * \note Mesh must be manifold with consistent face-winding, see #mesh_calc_poly_volume_centroid for details. + * \note Mesh must be manifold with consistent face-winding, + * see #mesh_calc_poly_volume_centroid for details. */ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3]) { @@ -2565,7 +2616,8 @@ bool BKE_mesh_center_of_volume(const Mesh *me, float r_cent[3]) /* otherwise we get NAN for 0 polys */ if (total_volume != 0.0f) { /* multiply by 0.25 to get the correct centroid */ - /* no need to divide volume by 6 as the centroid is weighted by 6x the volume, so it all cancels out */ + /* no need to divide volume by 6 as the centroid is weighted by 6x the volume, + * so it all cancels out. */ mul_v3_fl(r_cent, 0.25f / total_volume); } @@ -2774,9 +2826,11 @@ void BKE_mesh_loops_to_mface_corners( /** * Convert all CD layers from loop/poly to tessface data. * - * \param loopindices: is an array of an int[4] per tessface, mapping tessface's verts to loops indices. + * \param loopindices: is an array of an int[4] per tessface, + * mapping tessface's verts to loops indices. * - * \note when mface is not NULL, mface[face_index].v4 is used to test quads, else, loopindices[face_index][3] is used. + * \note when mface is not NULL, mface[face_index].v4 + * is used to test quads, else, loopindices[face_index][3] is used. */ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, @@ -2785,9 +2839,10 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, unsigned int (*loopindices)[4], const int num_faces) { - /* Note: performances are sub-optimal when we get a NULL mface, we could be ~25% quicker with dedicated code... - * Issue is, unless having two different functions with nearly the same code, there's not much ways to solve - * this. Better imho to live with it for now. :/ --mont29 + /* Note: performances are sub-optimal when we get a NULL mface, + * we could be ~25% quicker with dedicated code... + * Issue is, unless having two different functions with nearly the same code, + * there's not much ways to solve this. Better imho to live with it for now. :/ --mont29 */ const int numUV = CustomData_number_of_layers(ldata, CD_MLOOPUV); const int numCol = CustomData_number_of_layers(ldata, CD_MLOOPCOL); @@ -2878,9 +2933,10 @@ void BKE_mesh_tangent_loops_to_tessdata(CustomData *fdata, const int num_faces, const char *layer_name) { - /* Note: performances are sub-optimal when we get a NULL mface, we could be ~25% quicker with dedicated code... - * Issue is, unless having two different functions with nearly the same code, there's not much ways to solve - * this. Better imho to live with it for now. :/ --mont29 + /* Note: performances are sub-optimal when we get a NULL mface, + * we could be ~25% quicker with dedicated code... + * Issue is, unless having two different functions with nearly the same code, + * there's not much ways to solve this. Better imho to live with it for now. :/ --mont29 */ float(*ftangents)[4] = NULL; @@ -2920,7 +2976,8 @@ void BKE_mesh_tangent_loops_to_tessdata(CustomData *fdata, /** * Recreate tessellation. * - * \param do_face_nor_copy: Controls whether the normals from the poly are copied to the tessellated faces. + * \param do_face_nor_copy: Controls whether the normals from the poly + * are copied to the tessellated faces. * * \return number of tessellation faces. */ @@ -3150,9 +3207,11 @@ int BKE_mesh_recalc_tessellation(CustomData *fdata, /* NOTE: quad detection issue - fourth vertidx vs fourth loopidx: * Polygons take care of their loops ordering, hence not of their vertices ordering. - * Currently, our tfaces' fourth vertex index might be 0 even for a quad. However, we know our fourth loop index is - * never 0 for quads (because they are sorted for polygons, and our quads are still mere copies of their polygons). - * So we pass NULL as MFace pointer, and BKE_mesh_loops_to_tessdata will use the fourth loop index as quad test. + * Currently, our tfaces' fourth vertex index might be 0 even for a quad. However, + * we know our fourth loop index is never 0 for quads (because they are sorted for polygons, + * and our quads are still mere copies of their polygons). + * So we pass NULL as MFace pointer, and BKE_mesh_loops_to_tessdata + * will use the fourth loop index as quad test. * ... */ BKE_mesh_loops_to_tessdata(fdata, ldata, NULL, mface_to_poly_map, lindices, totface); @@ -3451,15 +3510,17 @@ void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh) BKE_mesh_update_customdata_pointers(mesh, true); } -/* the same as BKE_mesh_convert_mfaces_to_mpolys but oriented to be used in do_versions from readfile.c +/** + * The same as #BKE_mesh_convert_mfaces_to_mpolys + * but oriented to be used in #do_versions from readfile.c * the difference is how active/render/clone/stencil indices are handled here * * normally thay're being set from pdata which totally makes sense for meshes which are already * converted to bmesh structures, but when loading older files indices shall be updated in other * way around, so newly added pdata and ldata would have this indices set based on fdata layer * - * this is normally only needed when reading older files, in all other cases BKE_mesh_convert_mfaces_to_mpolys - * shall be always used + * this is normally only needed when reading older files, + * in all other cases #BKE_mesh_convert_mfaces_to_mpolys shall be always used */ void BKE_mesh_do_versions_convert_mfaces_to_mpolys(Mesh *mesh) { @@ -3544,7 +3605,8 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id, for (i = 0; i < totedge_i; i++, me++) { BLI_edgehash_insert(eh, me->v1, me->v2, POINTER_FROM_UINT(i)); - /* unrelated but avoid having the FGON flag enabled, so we can reuse it later for something else */ + /* unrelated but avoid having the FGON flag enabled, + * so we can reuse it later for something else */ me->flag &= ~ME_FGON; } @@ -3673,7 +3735,8 @@ void BKE_mesh_polygon_flip_ex(MPoly *mpoly, /* Note that we keep same start vertex for flipped face. */ /* We also have to update loops edge - * (they will get their original 'other edge', that is, the original edge of their original previous loop)... */ + * (they will get their original 'other edge', that is, + * the original edge of their original previous loop)... */ unsigned int prev_edge_index = mloop[loopstart].e; mloop[loopstart].e = mloop[loopend].e; diff --git a/source/blender/blenkernel/intern/mesh_iterators.c b/source/blender/blenkernel/intern/mesh_iterators.c index 1f8436408fb..df6517066b8 100644 --- a/source/blender/blenkernel/intern/mesh_iterators.c +++ b/source/blender/blenkernel/intern/mesh_iterators.c @@ -99,7 +99,8 @@ void BKE_mesh_foreach_mapped_loop(Mesh *mesh, void *userData, MeshForeachFlag flag) { - /* We can't use dm->getLoopDataLayout(dm) here, we want to always access dm->loopData, EditDerivedBMesh would + /* We can't use dm->getLoopDataLayout(dm) here, + * we want to always access dm->loopData, EditDerivedBMesh would * return loop data from bmesh itself. */ const float(*lnors)[3] = (flag & MESH_FOREACH_USE_NORMAL) ? CustomData_get_layer(&mesh->ldata, CD_NORMAL) : diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c index 69ed804a75c..40e300e6e2d 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.c +++ b/source/blender/blenkernel/intern/mesh_mapping.c @@ -42,8 +42,8 @@ * \{ */ /* ngon version wip, based on BM_uv_vert_map_create */ -/* this replaces the non bmesh function (in trunk) which takes MTFace's, if we ever need it back we could - * but for now this replaces it because its unused. */ +/* this replaces the non bmesh function (in trunk) which takes MTFace's, + * if we ever need it back we could but for now this replaces it because its unused. */ UvVertMap *BKE_mesh_uv_vert_map_create(const MPoly *mpoly, const MLoop *mloop, @@ -251,7 +251,8 @@ static void mesh_vert_poly_or_loop_map_create(MeshElemMap **r_map, } /** - * Generates a map where the key is the vertex and the value is a list of polys that use that vertex as a corner. + * Generates a map where the key is the vertex and the value + * is a list of polys that use that vertex as a corner. * The lists are allocated from one memory pool. */ void BKE_mesh_vert_poly_map_create(MeshElemMap **r_map, @@ -266,7 +267,8 @@ void BKE_mesh_vert_poly_map_create(MeshElemMap **r_map, } /** - * Generates a map where the key is the vertex and the value is a list of loops that use that vertex as a corner. + * Generates a map where the key is the vertex and the value + * is a list of loops that use that vertex as a corner. * The lists are allocated from one memory pool. */ void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map, @@ -281,7 +283,8 @@ void BKE_mesh_vert_loop_map_create(MeshElemMap **r_map, } /** - * Generates a map where the key is the edge and the value is a list of looptris that use that edge. + * Generates a map where the key is the edge and the value + * is a list of looptris that use that edge. * The lists are allocated from one memory pool. */ void BKE_mesh_vert_looptri_map_create(MeshElemMap **r_map, @@ -329,7 +332,8 @@ void BKE_mesh_vert_looptri_map_create(MeshElemMap **r_map, } /** - * Generates a map where the key is the vertex and the value is a list of edges that use that vertex as an endpoint. + * Generates a map where the key is the vertex and the value + * is a list of edges that use that vertex as an endpoint. * The lists are allocated from one memory pool. */ void BKE_mesh_vert_edge_map_create( @@ -372,7 +376,8 @@ void BKE_mesh_vert_edge_map_create( } /** - * A version of #BKE_mesh_vert_edge_map_create that references connected vertices directly (not their edges). + * A version of #BKE_mesh_vert_edge_map_create that references connected vertices directly + * (not their edges). */ void BKE_mesh_vert_edge_vert_map_create( MeshElemMap **r_map, int **r_mem, const MEdge *medge, int totvert, int totedge) @@ -472,7 +477,8 @@ void BKE_mesh_edge_loop_map_create(MeshElemMap **r_map, } /** - * Generates a map where the key is the edge and the value is a list of polygons that use that edge. + * Generates a map where the key is the edge and the value + * is a list of polygons that use that edge. * The lists are allocated from one memory pool. */ void BKE_mesh_edge_poly_map_create(MeshElemMap **r_map, @@ -739,7 +745,8 @@ static void poly_edge_loop_islands_calc(const MEdge *medge, num_edgeborders++; } if (use_bitflags) { - /* Find contiguous smooth groups already assigned, these are the values we can't reuse! */ + /* Find contiguous smooth groups already assigned, + * these are the values we can't reuse! */ for (; i--; p++) { int bit = poly_groups[*p]; if (!ELEM(bit, 0, poly_group_id, poly_group_id_overflowed) && @@ -751,8 +758,9 @@ static void poly_edge_loop_islands_calc(const MEdge *medge, } } } - /* And now, we have all our poly from current group in poly_stack (from 0 to (ps_end_idx - 1)), as well as - * all smoothgroups bits we can't use in bit_poly_group_mask. + /* And now, we have all our poly from current group in poly_stack + * (from 0 to (ps_end_idx - 1)), + * as well as all smoothgroups bits we can't use in bit_poly_group_mask. */ if (use_bitflags) { int i, *p, gid_bit = 0; @@ -764,8 +772,9 @@ static void poly_edge_loop_islands_calc(const MEdge *medge, } if (UNLIKELY(gid_bit > 31)) { /* All bits used in contiguous smooth groups, we can't do much! - * Note: this is *very* unlikely - theoretically, four groups are enough, I don't think we can reach - * this goal with such a simple algo, but I don't think either we'll never need all 32 groups! + * Note: this is *very* unlikely - theoretically, four groups are enough, + * I don't think we can reach this goal with such a simple algo, + * but I don't think either we'll never need all 32 groups! */ printf( "Warning, could not find an available id for current smooth group, faces will me " @@ -821,7 +830,8 @@ static bool poly_is_island_boundary_smooth_cb(const MPoly *mp, const int nbr_egde_users, void *UNUSED(user_data)) { - /* Edge is sharp if its poly is sharp, or edge itself is sharp, or edge is not used by exactly two polygons. */ + /* Edge is sharp if its poly is sharp, or edge itself is sharp, + * or edge is not used by exactly two polygons. */ return (!(mp->flag & ME_SMOOTH) || (me->flag & ME_SHARP) || (nbr_egde_users != 2)); } @@ -829,9 +839,9 @@ static bool poly_is_island_boundary_smooth_cb(const MPoly *mp, * Calculate smooth groups from sharp edges. * * \param r_totgroup: The total number of groups, 1 or more. - * \return Polygon aligned array of group index values (bitflags if use_bitflags is true), starting at 1 - * (0 being used as 'invalid' flag). - * Note it's callers's responsibility to MEM_freeN returned array. + * \return Polygon aligned array of group index values (bitflags if use_bitflags is true), + * starting at 1 (0 being used as 'invalid' flag). + * Note it's callers's responsibility to MEM_freeN returned array. */ int *BKE_mesh_calc_smoothgroups(const MEdge *medge, const int totedge, @@ -972,10 +982,11 @@ void BKE_mesh_loop_islands_add(MeshIslandStore *island_store, sizeof(*innrcut->indices) * (size_t)num_innercut_items); } -/* TODO: I'm not sure edge seam flag is enough to define UV islands? Maybe we should also consider UVmaps values +/* TODO: I'm not sure edge seam flag is enough to define UV islands? + * Maybe we should also consider UVmaps values * themselves (i.e. different UV-edges for a same mesh-edge => boundary edge too?). - * Would make things much more complex though, and each UVMap would then need its own mesh mapping, - * not sure we want that at all! + * Would make things much more complex though, + * and each UVMap would then need its own mesh mapping, not sure we want that at all! */ typedef struct MeshCheckIslandBoundaryUv { const MLoop *loops; @@ -1052,8 +1063,9 @@ static bool mesh_calc_islands_loop_poly_uv(MVert *UNUSED(verts), int *loop_indices; int num_pidx, num_lidx; - /* Those are used to detect 'inner cuts', i.e. edges that are borders, and yet have two or more polys of - * a same group using them (typical case: seam used to unwrap properly a cylinder). */ + /* Those are used to detect 'inner cuts', i.e. edges that are borders, + * and yet have two or more polys of a same group using them + * (typical case: seam used to unwrap properly a cylinder). */ BLI_bitmap *edge_borders = NULL; int num_edge_borders = 0; char *edge_border_count = NULL; @@ -1175,7 +1187,8 @@ static bool mesh_calc_islands_loop_poly_uv(MVert *UNUSED(verts), } /** - * Calculate 'generic' UV islands, i.e. based only on actual geometry data (edge seams), not some UV layers coordinates. + * Calculate 'generic' UV islands, i.e. based only on actual geometry data (edge seams), + * not some UV layers coordinates. */ bool BKE_mesh_calc_islands_loop_poly_edgeseam(MVert *verts, const int totvert, @@ -1195,12 +1208,14 @@ bool BKE_mesh_calc_islands_loop_poly_edgeseam(MVert *verts, * Calculate UV islands. * * \note If no MLoopUV layer is passed, we only consider edges tagged as seams as UV boundaries. - * This has the advantages of simplicity, and being valid/common to all UV maps. - * However, it means actual UV islands without matching UV seams will not be handled correctly... - * If a valid UV layer is passed as \a luvs parameter, UV coordinates are also used to detect islands boundaries. + * This has the advantages of simplicity, and being valid/common to all UV maps. + * However, it means actual UV islands without matching UV seams will not be handled correctly... + * If a valid UV layer is passed as \a luvs parameter, + * UV coordinates are also used to detect islands boundaries. * * \note All this could be optimized... - * Not sure it would be worth the more complex code, though, those loops are supposed to be really quick to do... + * Not sure it would be worth the more complex code, though, + * those loops are supposed to be really quick to do... */ bool BKE_mesh_calc_islands_loop_poly_uvmap(MVert *verts, const int totvert, diff --git a/source/blender/blenkernel/intern/mesh_merge.c b/source/blender/blenkernel/intern/mesh_merge.c index 31988c7b566..71cc20c78b7 100644 --- a/source/blender/blenkernel/intern/mesh_merge.c +++ b/source/blender/blenkernel/intern/mesh_merge.c @@ -41,8 +41,8 @@ * Poly compare with vtargetmap * Function used by #BKE_mesh_merge_verts. * The function compares poly_source after applying vtargetmap, with poly_target. - * The two polys are identical if they share the same vertices in the same order, or in reverse order, - * but starting position loopstart may be different. + * The two polys are identical if they share the same vertices in the same order, + * or in reverse order, but starting position loopstart may be different. * The function is called with direct_reverse=1 for same order (i.e. same normal), * and may be called again with direct_reverse=-1 for reverse order. * \return 1 if polys are identical, 0 if polys are different. @@ -159,7 +159,8 @@ static int cddm_poly_compare(MLoop *mloop_array, break; } - /* Adjust i_loop_target for cycling around and for direct/reverse order defined by delta = +1 or -1 */ + /* Adjust i_loop_target for cycling around and for direct/reverse order + * defined by delta = +1 or -1 */ i_loop_target_adjusted = (i_loop_target_start + direct_reverse * i_loop_target_offset) % mpoly_target->totloop; if (i_loop_target_adjusted < 0) { @@ -213,8 +214,8 @@ static bool poly_gset_compare_fn(const void *k1, const void *k2) * \param vtargetmap: The table that maps vertices to target vertices. a value of -1 * indicates a vertex is a target, and is to be kept. * This array is aligned with 'mesh->totvert' - * \warning \a vtargetmap must **not** contain any chained mapping (v1 -> v2 -> v3 etc.), this is not supported - * and will likely generate corrupted geometry. + * \warning \a vtargetmap must **not** contain any chained mapping (v1 -> v2 -> v3 etc.), + * this is not supported and will likely generate corrupted geometry. * * \param tot_vtargetmap: The number of non '-1' values in vtargetmap. (not the size) * @@ -230,10 +231,12 @@ static bool poly_gset_compare_fn(const void *k1, const void *k2) * Indeed it could be that all of a poly's vertices are merged, * but merged to vertices that do not make up a single poly, * in which case the original poly should not be dumped. - * Actually this later behavior could apply to the Mirror Modifier as well, but the additional checks are - * costly and not necessary in the case of mirror, because each vertex is only merged to its own mirror. + * Actually this later behavior could apply to the Mirror Modifier as well, + * but the additional checks are costly and not necessary in the case of mirror, + * because each vertex is only merged to its own mirror. * - * \note #BKE_mesh_recalc_tessellation has to run on the returned DM if you want to access tessfaces. + * \note #BKE_mesh_recalc_tessellation has to run on the returned DM + * if you want to access tessfaces. */ Mesh *BKE_mesh_merge_verts(Mesh *mesh, const int *vtargetmap, @@ -258,9 +261,9 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, STACK_DECLARE(mvert); STACK_DECLARE(oldv); - /* Note: create (totedge + totloop) elements because partially invalid polys due to merge may require - * generating new edges, and while in 99% cases we'll still end with less final edges than totedge, - * cases can be forged that would end requiring more... */ + /* Note: create (totedge + totloop) elements because partially invalid polys due to merge may + * require generating new edges, and while in 99% cases we'll still end with less final edges + * than totedge, cases can be forged that would end requiring more. */ MEdge *med, *medge = MEM_malloc_arrayN((totedge + totloop), sizeof(*medge), __func__); int *olde = MEM_malloc_arrayN((totedge + totloop), sizeof(*olde), __func__); int *newe = MEM_malloc_arrayN((totedge + totloop), sizeof(*newe), __func__); @@ -354,7 +357,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, if (merge_mode == MESH_MERGE_VERTS_DUMP_IF_EQUAL) { /* In this mode, we need to determine, whenever a poly' vertices are all mapped */ /* if the targets already make up a poly, in which case the new poly is dropped */ - /* This poly equality check is rather complex. We use a BLI_ghash to speed it up with a first level check */ + /* This poly equality check is rather complex. + * We use a BLI_ghash to speed it up with a first level check */ PolyKey *mpgh; poly_keys = MEM_malloc_arrayN(totpoly, sizeof(PolyKey), __func__); poly_gset = BLI_gset_new_ex(poly_gset_hash_fn, poly_gset_compare_fn, __func__, totpoly); @@ -484,7 +488,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, BLI_assert((mlv == v1 && next_mlv == v2) || (mlv == v2 && next_mlv == v1)); } #endif - /* A loop is only valid if its matching edge is, and it's not reusing a vertex already used by this poly. */ + /* A loop is only valid if its matching edge is, + * and it's not reusing a vertex already used by this poly. */ if (LIKELY((newe[ml->e] != -1) && ((mv[mlv].flag & ME_VERT_TMP_TAG) == 0))) { mv[mlv].flag |= ME_VERT_TMP_TAG; @@ -505,7 +510,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, STACK_PUSH(medge, mesh->medge[last_valid_ml->e]); medge[new_eidx].v1 = last_valid_ml->v; medge[new_eidx].v2 = ml->v; - /* DO NOT change newe mapping, could break actual values due to some deleted original edges. */ + /* DO NOT change newe mapping, + * could break actual values due to some deleted original edges. */ *val_p = POINTER_FROM_INT(new_eidx); created_edges++; @@ -525,8 +531,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, } c++; - /* We absolutely HAVE to handle edge index remapping here, otherwise potential newly created edges - * in that part of code make remapping later totally unreliable. */ + /* We absolutely HAVE to handle edge index remapping here, otherwise potential newly + * created edges in that part of code make remapping later totally unreliable. */ BLI_assert(newe[ml->e] != -1); last_valid_ml->e = newe[ml->e]; } @@ -558,7 +564,8 @@ Mesh *BKE_mesh_merge_verts(Mesh *mesh, STACK_PUSH(medge, mesh->medge[last_valid_ml->e]); medge[new_eidx].v1 = last_valid_ml->v; medge[new_eidx].v2 = first_valid_ml->v; - /* DO NOT change newe mapping, could break actual values due to some deleted original edges. */ + /* DO NOT change newe mapping, + * could break actual values due to some deleted original edges. */ *val_p = POINTER_FROM_INT(new_eidx); created_edges++; diff --git a/source/blender/blenkernel/intern/mesh_remap.c b/source/blender/blenkernel/intern/mesh_remap.c index 6799c6f5c43..db158ca8fb2 100644 --- a/source/blender/blenkernel/intern/mesh_remap.c +++ b/source/blender/blenkernel/intern/mesh_remap.c @@ -124,9 +124,11 @@ static bool mesh_remap_bvhtree_query_raycast(BVHTreeFromMesh *treedata, * Compute a value of the difference between both given meshes. * The smaller the result, the better the match. * - * We return the inverse of the average of the inversed shortest distance from each dst vertex to src ones. - * In other words, beyond a certain (relatively small) distance, all differences have more or less the same weight - * in final result, which allows to reduce influence of a few high differences, in favor of a global good matching. + * We return the inverse of the average of the inversed + * shortest distance from each dst vertex to src ones. + * In other words, beyond a certain (relatively small) distance, all differences have more or less + * the same weight in final result, which allows to reduce influence of a few high differences, + * in favor of a global good matching. */ float BKE_mesh_remap_calc_difference_from_mesh(const SpaceTransform *space_transform, const MVert *verts_dst, @@ -164,20 +166,24 @@ float BKE_mesh_remap_calc_difference_from_mesh(const SpaceTransform *space_trans result = ((float)numverts_dst / result) - 1.0f; - // printf("%s: Computed difference between meshes (the lower the better): %f\n", __func__, result); +#if 0 + printf("%s: Computed difference between meshes (the lower the better): %f\n", __func__, result); +#endif return result; } -/* This helper computes the eigen values & vectors for covariance matrix of all given vertices coordinates. +/* This helper computes the eigen values & vectors for + * covariance matrix of all given vertices coordinates. * * Those vectors define the 'average ellipsoid' of the mesh (i.e. the 'best fitting' ellipsoid * containing 50% of the vertices). * - * Note that it will not perform fantastic in case two or more eigen values are equal (e.g. a cylinder or - * parallelepiped with a square section give two identical eigenvalues, a sphere or tetrahedron give - * three identical ones, etc.), since you cannot really define all axes in those cases. We default to dummy - * generated orthogonal vectors in this case, instead of using eigen vectors. + * Note that it will not perform fantastic in case two or more eigen values are equal + * (e.g. a cylinder or parallelepiped with a square section give two identical eigenvalues, + * a sphere or tetrahedron give three identical ones, etc.), since you cannot really define all + * axes in those cases. We default to dummy generated orthogonal vectors in this case, + * instead of using eigen vectors. */ static void mesh_calc_eigen_matrix(const MVert *verts, const float (*vcos)[3], @@ -207,8 +213,8 @@ static void mesh_calc_eigen_matrix(const MVert *verts, } unit_m4(r_mat); - /* Note: here we apply sample correction to covariance matrix, since we consider the vertices as a sample - * of the whole 'surface' population of our mesh... */ + /* Note: here we apply sample correction to covariance matrix, since we consider the vertices + * as a sample of the whole 'surface' population of our mesh. */ BLI_covariance_m3_v3n(vcos, numverts, true, covmat, center); if (cos) { @@ -247,8 +253,9 @@ static void mesh_calc_eigen_matrix(const MVert *verts, float evi = eigen_val[i]; /* Protect against 1D/2D degenerated cases! */ - /* Note: not sure why we need square root of eigen values here (which are equivalent to singular values, - * as far as I have understood), but it seems to heavily reduce (if not completely nullify) + /* Note: not sure why we need square root of eigen values here + * (which are equivalent to singular values, as far as I have understood), + * but it seems to heavily reduce (if not completely nullify) * the error due to non-uniform scalings... */ evi = (evi < 1e-6f && evi > -1e-6f) ? ((evi < 0.0f) ? -1e-3f : 1e-3f) : sqrtf_signed(evi); mul_v3_fl(eigen_vec[i], evi); @@ -266,7 +273,8 @@ void BKE_mesh_remap_find_best_match_from_mesh(const MVert *verts_dst, Mesh *me_src, SpaceTransform *r_space_transform) { - /* Note that those are done so that we successively get actual mirror matrix (by multiplication of columns)... */ + /* Note that those are done so that we successively get actual mirror matrix + * (by multiplication of columns). */ const float mirrors[][3] = { {-1.0f, 1.0f, 1.0f}, /* -> -1, 1, 1 */ {1.0f, -1.0f, 1.0f}, /* -> -1, -1, 1 */ @@ -323,7 +331,7 @@ void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(const int UNUSED(ver const int UNUSED(edge_mode), const int loop_mode, const int UNUSED(poly_mode), - CustomData_MeshMasks *cddata_mask) + CustomData_MeshMasks *r_cddata_mask) { /* vert, edge and poly mapping modes never need extra cddata from source object. */ const bool need_lnors_src = (loop_mode & MREMAP_USE_LOOP) && (loop_mode & MREMAP_USE_NORMAL); @@ -331,10 +339,10 @@ void BKE_mesh_remap_calc_source_cddata_masks_from_map_modes(const int UNUSED(ver ((loop_mode & MREMAP_USE_POLY) && (loop_mode & MREMAP_USE_NORMAL)); if (need_lnors_src) { - cddata_mask->lmask |= CD_MASK_NORMAL; + r_cddata_mask->lmask |= CD_MASK_NORMAL; } if (need_pnors_src) { - cddata_mask->pmask |= CD_MASK_NORMAL; + r_cddata_mask->pmask |= CD_MASK_NORMAL; } } @@ -457,16 +465,20 @@ typedef struct IslandResult { float hit_point[3]; } IslandResult; -/* Note about all bvh/raycasting stuff below: - * * We must use our ray radius as BVH epsilon too, else rays not hitting anything but 'passing near' an item - * would be missed (since BVH handling would not detect them, 'refining' callbacks won't be executed, - * even though they would return a valid hit). - * * However, in 'islands' case where each hit gets a weight, 'precise' hits should have a better weight than - * 'approximate' hits. To address that, we simplify things with: - * ** A first raycast with default, given rayradius; - * ** If first one fails, we do more raycasting with bigger radius, but if hit is found - * it will get smaller weight. - * This only concerns loops, currently (because of islands), and 'sampled' edges/polys norproj. +/** + * \note About all bvh/raycasting stuff below: + * + * * We must use our ray radius as BVH epsilon too, else rays not hitting anything but + * 'passing near' an item would be missed (since BVH handling would not detect them, + * 'refining' callbacks won't be executed, even though they would return a valid hit). + * * However, in 'islands' case where each hit gets a weight, 'precise' hits should have a better + * weight than 'approximate' hits. + * To address that, we simplify things with: + * * A first raycast with default, given rayradius; + * * If first one fails, we do more raycasting with bigger radius, but if hit is found + * it will get smaller weight. + * + * This only concerns loops, currently (because of islands), and 'sampled' edges/polys norproj. */ /* At most n raycasts per 'real' ray. */ @@ -794,8 +806,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode, } } - /* Now, check all source edges of closest sources vertices, and select the one giving the smallest - * total verts-to-verts distance. */ + /* Now, check all source edges of closest sources vertices, + * and select the one giving the smallest total verts-to-verts distance. */ for (j = 2; j--;) { const unsigned int vidx_dst = j ? e_dst->v1 : e_dst->v2; const float first_dist = v_dst_to_src_map[vidx_dst].hit_dist; @@ -1012,8 +1024,8 @@ void BKE_mesh_remap_calc_edges_from_mesh(const int mode, w /= MREMAP_RAYCAST_APPROXIMATE_FAC; } } - /* A sampling is valid (as in, its result can be considered as valid sources) only if at least - * half of the rays found a source! */ + /* A sampling is valid (as in, its result can be considered as valid sources) + * only if at least half of the rays found a source! */ if (totweights > ((float)grid_size / 2.0f)) { for (j = 0; j < (int)numedges_src; j++) { if (!weights[j]) { @@ -1204,7 +1216,8 @@ static void mesh_island_to_astar_graph(MeshIslandStore *islands, #undef POLY_COMPLETE /* Our 'f_cost' callback func, to find shortest poly-path between two remapped-loops. - * Note we do not want to make innercuts 'walls' here, just detect when the shortest path goes by those. */ + * Note we do not want to make innercuts 'walls' here, + * just detect when the shortest path goes by those. */ static float mesh_remap_calc_loops_astar_f_cost(BLI_AStarGraph *as_graph, BLI_AStarSolution *as_solution, BLI_AStarGNLink *link, @@ -1224,8 +1237,8 @@ static float mesh_remap_calc_loops_astar_f_cost(BLI_AStarGraph *as_graph, } /* Our heuristic part of current f_cost is distance from next node to destination one. - * It is guaranteed to be less than (or equal to) actual shortest poly-path between next node and destination one. - */ + * It is guaranteed to be less than (or equal to) + * actual shortest poly-path between next node and destination one. */ co_next = (float *)as_graph->nodes[node_idx_next].custom_data; co_dest = (float *)as_graph->nodes[node_idx_dst].custom_data; return (link ? (as_solution->g_costs[node_idx_curr] + link->cost) : 0.0f) + @@ -1601,8 +1614,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, for (pidx_dst = 0, mp_dst = polys_dst; pidx_dst < numpolys_dst; pidx_dst++, mp_dst++) { float pnor_dst[3]; - /* Only in use_from_vert case, we may need polys' centers as fallback in case we cannot decide which - * corner to use from normals only. */ + /* Only in use_from_vert case, we may need polys' centers as fallback + * in case we cannot decide which corner to use from normals only. */ float pcent_dst[3]; bool pcent_dst_valid = false; @@ -1763,8 +1776,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, /* Fallback to 'nearest' hit here, loops usually comes in 'face group', not good to * have only part of one dest face's loops to map to source. * Note that since we give this a null weight, if whole weight for a given face - * is null, it means none of its loop mapped to this source island, hence we can skip it - * later. + * is null, it means none of its loop mapped to this source island, + * hence we can skip it later. */ copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co); nearest.index = -1; @@ -1821,12 +1834,14 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, /* We have to first select the 'best source island' for given dst poly and its loops. * Then, we have to check that poly does not 'spread' across some island's limits * (like inner seams for UVs, etc.). - * Note we only still partially support that kind of situation here, i.e. polys spreading over actual cracks - * (like a narrow space without faces on src, splitting a 'tube-like' geometry). That kind of situation - * should be relatively rare, though. + * Note we only still partially support that kind of situation here, i.e. + * Polys spreading over actual cracks + * (like a narrow space without faces on src, splitting a 'tube-like' geometry). + * That kind of situation should be relatively rare, though. */ - /* XXX This block in itself is big and complex enough to be a separate function but... it uses a bunch - * of locale vars. Not worth sending all that through parameters (for now at least). */ + /* XXX This block in itself is big and complex enough to be a separate function but... + * it uses a bunch of locale vars. + * Not worth sending all that through parameters (for now at least). */ { BLI_AStarGraph *as_graph = NULL; int *poly_island_index_map = NULL; @@ -1896,7 +1911,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (POINTER_AS_INT(as_solution.custom_data) && (as_solution.steps > 0)) { /* Find first 'cutting edge' on path, and bring back lidx_src on poly just * before that edge. - * Note we could try to be much smarter (like e.g. storing a whole poly's indices, + * Note we could try to be much smarter, g.g. Storing a whole poly's indices, * and making decision (on which side of cutting edge(s!) to be) on the end, * but this is one more level of complexity, better to first see if * simple solution works! @@ -1922,7 +1937,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, ml_dst = &loops_dst[lidx_dst]; copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co); - /* We do our transform here, since we may do several raycast/nearest queries. */ + /* We do our transform here, + * since we may do several raycast/nearest queries. */ if (space_transform) { BLI_space_transform_apply(space_transform, tmp_co); } @@ -1952,7 +1968,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, } else { /* No source for this loop in this island. */ - /* TODO: would probably be better to get a source at all cost in best island anyway? */ + /* TODO: would probably be better to get a source + * at all cost in best island anyway? */ mesh_remap_item_define(r_map, lidx_dst, FLT_MAX, best_island_index, 0, NULL, NULL); } } @@ -1985,8 +2002,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, if (POINTER_AS_INT(as_solution.custom_data) && (as_solution.steps > 0)) { /* Find first 'cutting edge' on path, and bring back lidx_src on poly just * before that edge. - * Note we could try to be much smarter (like e.g. storing a whole poly's indices, - * and making decision (one which side of cutting edge(s!) to be on the end, + * Note we could try to be much smarter: e.g. Storing a whole poly's indices, + * and making decision (one which side of cutting edge(s)!) to be on the end, * but this is one more level of complexity, better to first see if * simple solution works! */ @@ -2012,7 +2029,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, ml_dst = &loops_dst[lidx_dst]; copy_v3_v3(tmp_co, verts_dst[ml_dst->v].co); - /* We do our transform here, since we may do several raycast/nearest queries. */ + /* We do our transform here, + * since we may do several raycast/nearest queries. */ if (space_transform) { BLI_space_transform_apply(space_transform, tmp_co); } @@ -2100,7 +2118,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, } else { /* No source for this loop in this island. */ - /* TODO: would probably be better to get a source at all cost in best island anyway? */ + /* TODO: would probably be better to get a source + * at all cost in best island anyway? */ mesh_remap_item_define(r_map, lidx_dst, FLT_MAX, best_island_index, 0, NULL, NULL); } } @@ -2283,7 +2302,8 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, } } else if (mode == MREMAP_MODE_POLY_POLYINTERP_PNORPROJ) { - /* We cast our rays randomly, with a pseudo-even distribution (since we spread across tessellated tris, + /* We cast our rays randomly, with a pseudo-even distribution + * (since we spread across tessellated tris, * with additional weighting based on each tri's relative area). */ RNG *rng = BLI_rng_new(0); @@ -2399,8 +2419,8 @@ void BKE_mesh_remap_calc_polys_from_mesh(const int mode, float *v3 = poly_vcos_2d[tri_vidx_2d[j][2]]; int rays_num; - /* All this allows us to get 'absolute' number of rays for each tri, avoiding accumulating - * errors over iterations, and helping better even distribution. */ + /* All this allows us to get 'absolute' number of rays for each tri, + * avoiding accumulating errors over iterations, and helping better even distribution. */ done_area += area_tri_v2(v1, v2, v3); rays_num = max_ii( (int)((float)tot_rays * done_area * poly_area_2d_inv + 0.5f) - done_rays, 0); diff --git a/source/blender/blenkernel/intern/mesh_runtime.c b/source/blender/blenkernel/intern/mesh_runtime.c index c82126c39d0..06abd80b86f 100644 --- a/source/blender/blenkernel/intern/mesh_runtime.c +++ b/source/blender/blenkernel/intern/mesh_runtime.c @@ -78,7 +78,8 @@ void BKE_mesh_runtime_clear_cache(Mesh *mesh) /** * Ensure the array is large enough * - * \note This function must always be thread-protected by caller. It should only be used by internal code. + * \note This function must always be thread-protected by caller. + * It should only be used by internal code. */ static void mesh_ensure_looptri_data(Mesh *mesh) { @@ -149,8 +150,8 @@ const MLoopTri *BKE_mesh_runtime_looptri_ensure(Mesh *mesh) } else { BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE); - /* We need to ensure array is still NULL inside mutex-protected code, some other thread might have already - * recomputed those looptris. */ + /* We need to ensure array is still NULL inside mutex-protected code, + * some other thread might have already recomputed those looptris. */ if (mesh->runtime.looptris.array == NULL) { BKE_mesh_runtime_looptri_recalc(mesh); } diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c index d6d39ca0f1d..19d94be9b6e 100644 --- a/source/blender/blenkernel/intern/mesh_tangent.c +++ b/source/blender/blenkernel/intern/mesh_tangent.c @@ -116,7 +116,8 @@ static void set_tspace(const SMikkTSpaceContext *pContext, } /** - * Compute simplified tangent space normals, i.e. tangent vector + sign of bi-tangent one, which combined with + * Compute simplified tangent space normals, i.e. + * tangent vector + sign of bi-tangent one, which combined with * split normals can be used to recreate the full tangent space. * Note: * The mesh should be made of only tris and quads! */ @@ -284,7 +285,7 @@ static void dm_ts_GetPosition(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLMeshToTangent *pMesh = pContext->m_pUserData; const MLoopTri *lt; uint loop_index; @@ -318,7 +319,7 @@ static void dm_ts_GetTextureCoordinate(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLMeshToTangent *pMesh = pContext->m_pUserData; const MLoopTri *lt; uint loop_index; @@ -357,7 +358,7 @@ static void dm_ts_GetNormal(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *)pContext->m_pUserData; const MLoopTri *lt; uint loop_index; @@ -420,7 +421,7 @@ static void dm_ts_SetTSpace(const SMikkTSpaceContext *pContext, const int face_num, const int vert_index) { - //assert(vert_index >= 0 && vert_index < 4); + // assert(vert_index >= 0 && vert_index < 4); SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *)pContext->m_pUserData; const MLoopTri *lt; uint loop_index; @@ -487,7 +488,8 @@ void BKE_mesh_add_loop_tangent_named_layer_for_uv(CustomData *uv_data, } /** - * Here we get some useful information such as active uv layer name and search if it is already in tangent_names. + * Here we get some useful information such as active uv layer name and + * search if it is already in tangent_names. * Also, we calculate tangent_mask that works as a descriptor of tangents state. * If tangent_mask has changed, then recalculate tangents. */ @@ -677,9 +679,8 @@ void BKE_mesh_calc_loop_tangent_ex(const MVert *mvert, mesh2tangent->mpoly = mpoly; mesh2tangent->mloop = mloop; mesh2tangent->looptri = looptri; - /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled), - * have to check this is valid... - */ + /* Note, we assume we do have tessellated loop normals at this point + * (in case it is object-enabled), have to check this is valid. */ mesh2tangent->precomputedLoopNormals = loop_normals; mesh2tangent->precomputedFaceNormals = poly_normals; diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index e2515665728..dac12233539 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -573,8 +573,9 @@ bool BKE_mesh_validate_arrays(Mesh *mesh, sp->numverts = mp->totloop; sp->loopstart = mp->loopstart; - /* Ideally we would only have to do that once on all vertices before we start checking each poly, but - * several polys can use same vert, so we have to ensure here all verts of current poly are cleared. */ + /* Ideally we would only have to do that once on all vertices + * before we start checking each poly, but several polys can use same vert, + * so we have to ensure here all verts of current poly are cleared. */ for (j = 0, ml = &mloops[sp->loopstart]; j < mp->totloop; j++, ml++) { if (ml->v < totvert) { mverts[ml->v].flag &= ~ME_VERT_TMP_TAG; @@ -638,7 +639,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh, if (IS_REMOVED_EDGE(me) || !((me->v1 == v1 && me->v2 == v2) || (me->v1 == v2 && me->v2 == v1))) { /* The pointed edge is invalid (tagged as removed, or vert idx mismatch), - * and we already know from previous test that a valid one exists, use it (if allowed)! */ + * and we already know from previous test that a valid one exists, + * use it (if allowed)! */ if (do_fixes) { int prev_e = ml->e; ml->e = POINTER_AS_INT(BLI_edgehash_lookup(edge_hash, v1, v2)); @@ -676,7 +678,8 @@ bool BKE_mesh_validate_arrays(Mesh *mesh, const int *p1_v = sp->verts, *p2_v = prev_sp->verts; if (sp->invalid) { - /* break, because all known invalid polys have been put at the end by qsort with search_poly_cmp. */ + /* Break, because all known invalid polys have been put at the end + * by qsort with search_poly_cmp. */ break; } diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index b244a69ec09..9bc9865631f 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -36,6 +36,7 @@ #include "DNA_armature_types.h" #include "DNA_mesh_types.h" #include "DNA_object_types.h" +#include "DNA_scene_types.h" #include "BLI_utildefines.h" #include "BLI_listbase.h" @@ -501,7 +502,8 @@ bool modifiers_isParticleEnabled(Object *ob) /** * Check whether is enabled. * - * \param scene: Current scene, may be NULL, in which case isDisabled callback of the modifier is never called. + * \param scene: Current scene, may be NULL, + * in which case isDisabled callback of the modifier is never called. */ bool modifier_isEnabled(const struct Scene *scene, ModifierData *md, int required_mode) { @@ -656,7 +658,7 @@ Object *modifiers_isDeformedByArmature(Object *ob) for (; md; md = md->next) { if (md->type == eModifierType_Armature) { amd = (ArmatureModifierData *)md; - if (amd->object && (amd->object->flag & SELECT)) { + if (amd->object && (amd->object->base_flag & BASE_SELECTED)) { return amd->object; } } @@ -679,7 +681,7 @@ Object *modifiers_isDeformedByMeshDeform(Object *ob) for (; md; md = md->next) { if (md->type == eModifierType_MeshDeform) { mdmd = (MeshDeformModifierData *)md; - if (mdmd->object && (mdmd->object->flag & SELECT)) { + if (mdmd->object && (mdmd->object->base_flag & BASE_SELECTED)) { return mdmd->object; } } @@ -705,7 +707,7 @@ Object *modifiers_isDeformedByLattice(Object *ob) for (; md; md = md->next) { if (md->type == eModifierType_Lattice) { lmd = (LatticeModifierData *)md; - if (lmd->object && (lmd->object->flag & SELECT)) { + if (lmd->object && (lmd->object->base_flag & BASE_SELECTED)) { return lmd->object; } } @@ -731,7 +733,7 @@ Object *modifiers_isDeformedByCurve(Object *ob) for (; md; md = md->next) { if (md->type == eModifierType_Curve) { cmd = (CurveModifierData *)md; - if (cmd->object && (cmd->object->flag & SELECT)) { + if (cmd->object && (cmd->object->base_flag & BASE_SELECTED)) { return cmd->object; } } @@ -929,7 +931,8 @@ void modwrap_deformVertsEM(ModifierData *md, /** * Get evaluated mesh for other evaluated object, which is used as an operand for the modifier, * e.g. second operand for boolean modifier. - * Note that modifiers in stack always get fully evaluated COW ID pointers, never original ones. Makes things simpler. + * Note that modifiers in stack always get fully evaluated COW ID pointers, + * never original ones. Makes things simpler. * * \param get_cage_mesh Return evaluated mesh with only deforming modifiers applied * (i.e. mesh topology remains the same as original one, a.k.a. 'cage' mesh). @@ -942,8 +945,8 @@ Mesh *BKE_modifier_get_evaluated_mesh_from_evaluated_object(Object *ob_eval, if ((ob_eval->type == OB_MESH) && (ob_eval->mode & OB_MODE_EDIT)) { /* In EditMode, evaluated mesh is stored in BMEditMesh, not the object... */ BMEditMesh *em = BKE_editmesh_from_object(ob_eval); - if (em != - NULL) { /* em might not exist yet in some cases, just after loading a .blend file, see T57878. */ + /* 'em' might not exist yet in some cases, just after loading a .blend file, see T57878. */ + if (em != NULL) { me = (get_cage_mesh && em->mesh_eval_cage != NULL) ? em->mesh_eval_cage : em->mesh_eval_final; } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 1a61fa2c537..8d149af6a1f 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -1619,8 +1619,10 @@ void BKE_movieclip_free(MovieClip *clip) } /** - * Only copy internal data of MovieClip ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of MovieClip ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 6af92422b30..e3953af7cbf 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -1712,7 +1712,8 @@ void multires_free(Multires *mr) lvl = lvl->next; } - /* mr->verts may be NULL when loading old files, see direct_link_mesh() in readfile.c, and T43560. */ + /* mr->verts may be NULL when loading old files, + * see direct_link_mesh() in readfile.c, and T43560. */ MEM_SAFE_FREE(mr->verts); BLI_freelistN(&mr->levels); diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c index 6953339f287..15e53e12ece 100644 --- a/source/blender/blenkernel/intern/nla.c +++ b/source/blender/blenkernel/intern/nla.c @@ -90,7 +90,7 @@ void BKE_nlastrip_free(ListBase *strips, NlaStrip *strip, bool do_id_user) } /* free remapping info */ - //if (strip->remap) + // if (strip->remap) // BKE_animremap_free(); /* free own F-Curves */ @@ -163,7 +163,8 @@ void BKE_nla_tracks_free(ListBase *tracks, bool do_id_user) * Copy NLA strip * * \param use_same_action: When true, the existing action is used (instead of being duplicated) - * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... + * flags in BKE_library.h */ NlaStrip *BKE_nlastrip_copy(Main *bmain, NlaStrip *strip, @@ -216,7 +217,8 @@ NlaStrip *BKE_nlastrip_copy(Main *bmain, /** * Copy a single NLA Track. - * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... + * flags in BKE_library.h */ NlaTrack *BKE_nlatrack_copy(Main *bmain, NlaTrack *nlt, @@ -249,7 +251,8 @@ NlaTrack *BKE_nlatrack_copy(Main *bmain, /** * Copy all NLA data. - * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h + * \param flag: Control ID pointers management, see LIB_ID_CREATE_.../LIB_ID_COPY_... + * flags in BKE_library.h */ void BKE_nla_tracks_copy(Main *bmain, ListBase *dst, ListBase *src, const int flag) { @@ -354,7 +357,8 @@ NlaStrip *BKE_nlastrip_new(bAction *act) return strip; } -/* Add new NLA-strip to the top of the NLA stack - i.e. into the last track if space, or a new one otherwise */ +/* Add new NLA-strip to the top of the NLA stack - i.e. + * into the last track if space, or a new one otherwise. */ NlaStrip *BKE_nlastack_add_strip(AnimData *adt, bAction *act) { NlaStrip *strip; @@ -467,10 +471,9 @@ static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short } else { /* if (mode == NLATIME_CONVERT_EVAL) */ if (IS_EQF((float)cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) { - /* this case prevents the motion snapping back to the first frame at the end of the strip - * by catching the case where repeats is a whole number, which means that the end of the strip - * could also be interpreted as the end of the start of a repeat - */ + /* This case prevents the motion snapping back to the first frame at the end of the strip + * by catching the case where repeats is a whole number, which means that the end of the + * strip could also be interpreted as the end of the start of a repeat. */ return strip->actstart; } else { @@ -490,10 +493,9 @@ static float nlastrip_get_frame_actionclip(NlaStrip *strip, float cframe, short } else { /* if (mode == NLATIME_CONVERT_EVAL) */ if (IS_EQF(cframe, strip->end) && IS_EQF(strip->repeat, floorf(strip->repeat))) { - /* this case prevents the motion snapping back to the first frame at the end of the strip - * by catching the case where repeats is a whole number, which means that the end of the strip - * could also be interpreted as the end of the start of a repeat - */ + /* This case prevents the motion snapping back to the first frame at the end of the strip + * by catching the case where repeats is a whole number, which means that the end of the + * strip could also be interpreted as the end of the start of a repeat. */ return strip->actend; } else { @@ -544,7 +546,8 @@ static float nlastrip_get_frame_transition(NlaStrip *strip, float cframe, short float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode) { switch (strip->type) { - case NLASTRIP_TYPE_META: /* meta - for now, does the same as transition (is really just an empty container) */ + case NLASTRIP_TYPE_META: /* Meta - for now, does the same as transition + * (is really just an empty container). */ case NLASTRIP_TYPE_TRANSITION: /* transition */ return nlastrip_get_frame_transition(strip, cframe, mode); @@ -589,10 +592,10 @@ float BKE_nla_tweakedit_remap(AnimData *adt, float cframe, short mode) } strip = adt->actstrip; - /* sanity checks - * - in rare cases, we may not be able to find this strip for some reason (internal error) - * - for now, if the user has defined a curve to control the time, this correction cannot be performed - * reliably... + /* Sanity checks: + * - In rare cases, we may not be able to find this strip for some reason (internal error) + * - For now, if the user has defined a curve to control the time, this correction cannot be + * performed reliably. */ if ((strip == NULL) || (strip->flag & NLASTRIP_FLAG_USR_TIME)) { return cframe; @@ -943,7 +946,8 @@ void BKE_nlameta_flush_transforms(NlaStrip *mstrip) p1 = (strip->start - oStart) / oLen; p2 = (strip->end - oStart) / oLen; - /* apply new strip endpoints using the proportions, then wait for second pass to flush scale properly */ + /* Apply new strip endpoints using the proportions, + * then wait for second pass to flush scale properly. */ strip->start = (p1 * nLen) + mstrip->start; strip->end = (p2 * nLen) + mstrip->start; } @@ -1252,7 +1256,8 @@ bool BKE_nlastrip_within_bounds(NlaStrip *strip, float min, float max) return true; } -/* Ensure that strip doesn't overlap those around it after resizing by offsetting those which follow */ +/* Ensure that strip doesn't overlap those around it after resizing + * by offsetting those which follow. */ static void nlastrip_fix_resize_overlaps(NlaStrip *strip) { /* next strips - do this first, since we're often just getting longer */ @@ -1613,13 +1618,15 @@ void BKE_nlastrip_validate_name(AnimData *adt, NlaStrip *strip) continue; } - /* use the name of the strip as the key, and the strip as the value, since we're mostly interested in the keys */ + /* Use the name of the strip as the key, and the strip as the value, + * since we're mostly interested in the keys. */ BLI_ghash_insert(gh, tstrip->name, tstrip); } } - /* if the hash-table has a match for this name, try other names... - * - in an extreme case, it might not be able to find a name, but then everything else in Blender would fail too :) + /* If the hash-table has a match for this name, try other names... + * - In an extreme case, it might not be able to find a name, + * but then everything else in Blender would fail too :). */ BLI_uniquename_cb(nla_editbone_name_check, (void *)gh, @@ -1651,7 +1658,8 @@ static void nlastrip_get_endpoint_overlaps(NlaStrip *strip, */ /* TODO: this scheme could get quite slow for doing this on many strips... */ for (nls = track->strips.first; nls; nls = nls->next) { - /* check if strip overlaps (extends over or exactly on) the entire range of the strip we're validating */ + /* Check if strip overlaps (extends over or exactly on) + * the entire range of the strip we're validating. */ if ((nls->start <= strip->start) && (nls->end >= strip->end)) { *start = NULL; *end = NULL; @@ -1750,7 +1758,8 @@ void BKE_nla_validate_state(AnimData *adt) return; } - /* adjust blending values for auto-blending, and also do an initial pass to find the earliest strip */ + /* Adjust blending values for auto-blending, + * and also do an initial pass to find the earliest strip. */ for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) { for (strip = nlt->strips.first; strip; strip = strip->next) { /* auto-blending first */ @@ -1849,7 +1858,8 @@ bool BKE_nla_action_stash(AnimData *adt) nlt = BKE_nlatrack_add(adt, prev_track); BLI_assert(nlt != NULL); - /* we need to ensure that if there wasn't any previous instance, it must go to tbe bottom of the stack */ + /* We need to ensure that if there wasn't any previous instance, + * it must go to tbe bottom of the stack. */ if (prev_track == NULL) { BLI_remlink(&adt->nla_tracks, nlt); BLI_addhead(&adt->nla_tracks, nlt); @@ -1955,9 +1965,9 @@ void BKE_nla_action_pushdown(AnimData *adt) * mode accordingly */ if (nlastrip_is_first(adt, strip) == 0) { - /* not first, so extend mode can only be NLASTRIP_EXTEND_HOLD_FORWARD not NLASTRIP_EXTEND_HOLD, - * so that it doesn't override strips in previous tracks - */ + /* Not first, so extend mode can only be: + * NLASTRIP_EXTEND_HOLD_FORWARD not NLASTRIP_EXTEND_HOLD, + * so that it doesn't override strips in previous tracks. */ /* FIXME: this needs to be more automated, since user can rearrange strips */ if (strip->extendmode == NLASTRIP_EXTEND_HOLD) { strip->extendmode = NLASTRIP_EXTEND_HOLD_FORWARD; @@ -2004,9 +2014,10 @@ bool BKE_nla_tweakmode_enter(AnimData *adt) } } - /* There are situations where we may have multiple strips selected and we want to enter tweakmode on all - * of those at once. Usually in those cases, it will usually just be a single strip per AnimData. - * In such cases, compromise and take the last selected track and/or last selected strip [#28468] + /* There are situations where we may have multiple strips selected and we want to enter tweakmode + * on all of those at once. Usually in those cases, + * it will usually just be a single strip per AnimData. + * In such cases, compromise and take the last selected track and/or last selected strip, T28468. */ if (activeTrack == NULL) { /* try last selected track for active strip */ @@ -2022,7 +2033,8 @@ bool BKE_nla_tweakmode_enter(AnimData *adt) } } if ((activeTrack) && (activeStrip == NULL)) { - /* no active strip in active or last selected track; compromise for first selected (assuming only single)... */ + /* No active strip in active or last selected track; + * compromise for first selected (assuming only single). */ for (strip = activeTrack->strips.first; strip; strip = strip->next) { if (strip->flag & (NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_ACTIVE)) { activeStrip = strip; @@ -2071,10 +2083,12 @@ bool BKE_nla_tweakmode_enter(AnimData *adt) } /* handle AnimData level changes: - * - 'real' active action to temp storage (no need to change user-counts) - * - action of active strip set to be the 'active action', and have its usercount incremented - * - editing-flag for this AnimData block should also get turned on (for more efficient restoring) - * - take note of the active strip for mapping-correction of keyframes in the action being edited + * - 'real' active action to temp storage (no need to change user-counts). + * - Action of active strip set to be the 'active action', and have its usercount incremented. + * - Editing-flag for this AnimData block should also get turned on + * (for more efficient restoring). + * - Take note of the active strip for mapping-correction of keyframes + * in the action being edited. */ adt->tmpact = adt->action; adt->action = activeStrip->act; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 8a3f973ae5f..3adb6cfe960 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -126,8 +126,9 @@ static void node_init(const struct bContext *C, bNodeTree *ntree, bNode *node) /* initialize the node name with the node label. * note: do this after the initfunc so nodes get their data set which may be used in naming * (node groups for example) */ - /* XXX Do not use nodeLabel() here, it returns translated content for UI, which should *only* be used - * in UI, *never* in data... Data have their own translation option! + /* XXX Do not use nodeLabel() here, it returns translated content for UI, + * which should *only* be used in UI, *never* in data... + * Data have their own translation option! * This solution may be a bit rougher than nodeLabel()'s returned string, but it's simpler * than adding "do_translate" flags to this func (and labelfunc() as well). */ BLI_strncpy(node->name, DATA_(ntype->ui_name), NODE_MAXSTR); @@ -284,7 +285,8 @@ static void update_typeinfo(Main *bmain, } /* Try to initialize all typeinfo in a node tree. - * NB: In general undefined typeinfo is a perfectly valid case, the type may just be registered later. + * NB: In general undefined typeinfo is a perfectly valid case, + * the type may just be registered later. * In that case the update_typeinfo function will set typeinfo on registration * and do necessary updates. */ @@ -339,8 +341,8 @@ void ntreeTypeAdd(bNodeTreeType *nt) { BLI_ghash_insert(nodetreetypes_hash, nt->idname, nt); /* XXX pass Main to register function? */ - /* Probably not. It is pretty much expected we want to update G_MAIN her I think - or we'd want to update *all* - * active Mains, which we cannot do anyway currently. */ + /* Probably not. It is pretty much expected we want to update G_MAIN here I think - + * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, nt, NULL, NULL, false); } @@ -349,8 +351,8 @@ static void ntree_free_type(void *treetype_v) { bNodeTreeType *treetype = treetype_v; /* XXX pass Main to unregister function? */ - /* Probably not. It is pretty much expected we want to update G_MAIN her I think - or we'd want to update *all* - * active Mains, which we cannot do anyway currently. */ + /* Probably not. It is pretty much expected we want to update G_MAIN here I think - + * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, treetype, NULL, NULL, true); MEM_freeN(treetype); } @@ -401,8 +403,8 @@ static void node_free_type(void *nodetype_v) { bNodeType *nodetype = nodetype_v; /* XXX pass Main to unregister function? */ - /* Probably not. It is pretty much expected we want to update G_MAIN her I think - or we'd want to update *all* - * active Mains, which we cannot do anyway currently. */ + /* Probably not. It is pretty much expected we want to update G_MAIN here I think - + * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, NULL, nodetype, NULL, true); /* XXX deprecated */ @@ -423,8 +425,8 @@ void nodeRegisterType(bNodeType *nt) BLI_ghash_insert(nodetypes_hash, nt->idname, nt); /* XXX pass Main to register function? */ - /* Probably not. It is pretty much expected we want to update G_MAIN her I think - or we'd want to update *all* - * active Mains, which we cannot do anyway currently. */ + /* Probably not. It is pretty much expected we want to update G_MAIN here I think - + * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, NULL, nt, NULL, false); } @@ -462,8 +464,8 @@ static void node_free_socket_type(void *socktype_v) { bNodeSocketType *socktype = socktype_v; /* XXX pass Main to unregister function? */ - /* Probably not. It is pretty much expected we want to update G_MAIN her I think - or we'd want to update *all* - * active Mains, which we cannot do anyway currently. */ + /* Probably not. It is pretty much expected we want to update G_MAIN here I think - + * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, NULL, NULL, socktype, true); MEM_freeN(socktype); @@ -473,8 +475,8 @@ void nodeRegisterSocketType(bNodeSocketType *st) { BLI_ghash_insert(nodesockettypes_hash, (void *)st->idname, st); /* XXX pass Main to register function? */ - /* Probably not. It is pretty much expected we want to update G_MAIN her I think - or we'd want to update *all* - * active Mains, which we cannot do anyway currently. */ + /* Probably not. It is pretty much expected we want to update G_MAIN here I think - + * or we'd want to update *all* active Mains, which we cannot do anyway currently. */ update_typeinfo(G_MAIN, NULL, NULL, NULL, st, false); } @@ -931,7 +933,8 @@ void nodeChainIter(const bNodeTree *ntree, continue; } if (link->tonode && link->fromnode) { - /* is the link part of the chain meaning node_start == fromnode (or tonode for reversed case)? */ + /* Is the link part of the chain meaning node_start == fromnode + * (or tonode for reversed case)? */ if ((reversed && (link->tonode == node_start)) || (!reversed && link->fromnode == node_start)) { if (!callback(link->fromnode, link->tonode, userdata, reversed)) { @@ -945,7 +948,8 @@ void nodeChainIter(const bNodeTree *ntree, } /** - * Iterate over all parents of \a node, executing \a callback for each parent (which can return false to end iterator) + * Iterate over all parents of \a node, executing \a callback for each parent + * (which can return false to end iterator) * * \note Recursive */ @@ -1370,8 +1374,10 @@ bNodeTree *ntreeAddTree(Main *bmain, const char *name, const char *idname) } /** - * Only copy internal data of NodeTree ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of NodeTree ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -1716,7 +1722,8 @@ void BKE_node_preview_merge_tree(bNodeTree *to_ntree, bNodeTree *from_ntree, boo BKE_node_instance_hash_insert(to_ntree->previews, key, preview); } - /* Note: NULL free function here, because pointers have already been moved over to to_ntree->previews! */ + /* Note: NULL free function here, + * because pointers have already been moved over to to_ntree->previews! */ BKE_node_instance_hash_free(from_ntree->previews, NULL); from_ntree->previews = NULL; } @@ -1741,9 +1748,9 @@ void BKE_node_preview_set_pixel( rgba_float_to_uchar(tar, col); } } - //else printf("prv out bound x y %d %d\n", x, y); + // else printf("prv out bound x y %d %d\n", x, y); } - //else printf("prv out bound x y %d %d\n", x, y); + // else printf("prv out bound x y %d %d\n", x, y); } } @@ -2269,25 +2276,6 @@ static bNodeSocket *make_socket_interface(bNodeTree *ntree, else { BLI_snprintf(sock->identifier, MAX_NAME, "Output_%d", own_index); } -#ifdef USE_NODE_COMPAT_CUSTOMNODES - /* XXX forward compatibility: - * own_index is deprecated, but needs to be set here. - * Node sockets generally use the identifier string instead now, - * but reconstructing own_index in writefile.c would require parsing the identifier string. - */ - -# if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) || defined(__clang__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -# endif - - sock->own_index = own_index; - -# if (defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 406)) || defined(__clang__) -# pragma GCC diagnostic pop -# endif - -#endif /* USE_NODE_COMPAT_CUSTOMNODES */ sock->limit = (in_out == SOCK_IN ? 1 : 0xFFF); @@ -3225,16 +3213,44 @@ static void ntree_validate_links(bNodeTree *ntree) } } -void ntreeVerifyNodes(struct Main *main, struct ID *id) +void ntreeUpdateAllNew(Main *main) { + /* Update all new node trees on file read or append, to add/remove sockets + * in groups nodes if the group changed, and handle any update flags that + * might have been set in file reading or versioning. */ FOREACH_NODETREE_BEGIN (main, ntree, owner_id) { - bNode *node; + if (owner_id->tag & LIB_TAG_NEW) { + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->typeinfo->group_update_func) { + node->typeinfo->group_update_func(ntree, node); + } + } - for (node = ntree->nodes.first; node; node = node->next) { - if (node->typeinfo->verifyfunc) { - node->typeinfo->verifyfunc(ntree, node, id); + ntreeUpdateTree(NULL, ntree); + } + } + FOREACH_NODETREE_END; +} + +void ntreeUpdateAllUsers(Main *main, ID *ngroup) +{ + /* Update all users of ngroup, to add/remove sockets as needed. */ + FOREACH_NODETREE_BEGIN (main, ntree, owner_id) { + bool need_update = false; + + for (bNode *node = ntree->nodes.first; node; node = node->next) { + if (node->id == ngroup) { + if (node->typeinfo->group_update_func) { + node->typeinfo->group_update_func(ntree, node); + } + + need_update = true; } } + + if (need_update) { + ntreeUpdateTree(NULL, ntree); + } } FOREACH_NODETREE_END; } @@ -3283,7 +3299,7 @@ void ntreeUpdateTree(Main *bmain, bNodeTree *ntree) /* XXX hack, should be done by depsgraph!! */ if (bmain) { - ntreeVerifyNodes(bmain, &ntree->id); + ntreeUpdateAllUsers(bmain, &ntree->id); } if (ntree->update & (NTREE_UPDATE_LINKS | NTREE_UPDATE_NODES)) { @@ -3600,13 +3616,15 @@ void node_type_label( } void node_type_update(struct bNodeType *ntype, - void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node), - void (*verifyfunc)(struct bNodeTree *ntree, - struct bNode *node, - struct ID *id)) + void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node)) { ntype->updatefunc = updatefunc; - ntype->verifyfunc = verifyfunc; +} + +void node_type_group_update(struct bNodeType *ntype, + void (*group_update_func)(struct bNodeTree *ntree, struct bNode *node)) +{ + ntype->group_update_func = group_update_func; } void node_type_exec(struct bNodeType *ntype, diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index a623baf7b71..38a8ad2769a 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -223,7 +223,8 @@ void BKE_object_modifier_hook_reset(Object *ob, HookModifierData *hmd) if (hmd->subtarget[0] && pchan) { float imat[4][4], mat[4][4]; - /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ + /* Calculate the world-space matrix for the pose-channel target first, + * then carry on as usual. */ mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat); invert_m4_m4(imat, mat); @@ -247,7 +248,8 @@ void BKE_object_modifier_gpencil_hook_reset(Object *ob, HookGpencilModifierData if (hmd->subtarget[0] && pchan) { float imat[4][4], mat[4][4]; - /* calculate the world-space matrix for the pose-channel target first, then carry on as usual */ + /* Calculate the world-space matrix for the pose-channel target first, + * then carry on as usual. */ mul_m4_m4m4(mat, hmd->object->obmat, pchan->pose_mat); invert_m4_m4(imat, mat); @@ -1159,7 +1161,8 @@ static void copy_object_pose(Object *obn, const Object *ob, const int flag) chan->flag &= ~(POSE_LOC | POSE_ROT | POSE_SIZE); - /* XXX Remapping object pointing onto itself should be handled by generic BKE_library_remap stuff, but... + /* XXX Remapping object pointing onto itself should be handled by generic + * BKE_library_remap stuff, but... * the flush_constraint_targets callback am not sure about, so will delay that for now. */ for (con = chan->constraints.first; con; con = con->next) { const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con); @@ -1334,8 +1337,10 @@ void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src) } /** - * Only copy internal data of Object ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Object ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -1438,7 +1443,8 @@ void BKE_object_copy_data(Main *bmain, Object *ob_dst, const Object *ob_src, con copy_object_lod(ob_dst, ob_src, flag_subdata); - /* Do not copy object's preview (mostly due to the fact renderers create temp copy of objects). */ + /* Do not copy object's preview + * (mostly due to the fact renderers create temp copy of objects). */ if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */ BKE_previewimg_id_copy(&ob_dst->id, &ob_src->id); } @@ -1461,11 +1467,13 @@ Object *BKE_object_copy(Main *bmain, const Object *ob) /** Perform deep-copy of object and its 'children' data-blocks (obdata, materials, actions, etc.). * - * \param dupflag Controls which sub-data are also duplicated (see #eDupli_ID_Flags in DNA_userdef_types.h). + * \param dupflag Controls which sub-data are also duplicated + * (see #eDupli_ID_Flags in DNA_userdef_types.h). * - * \note This function does not do any remapping to new IDs, caller must do it (\a #BKE_libblock_relink_to_newid()). - * \note Caller MUST free \a newid pointers itself (#BKE_main_id_clear_newpoins()) and call updates of DEG too - * (#DAG_relations_tag_update()). + * \note This function does not do any remapping to new IDs, caller must do it + * (\a #BKE_libblock_relink_to_newid()). + * \note Caller MUST free \a newid pointers itself (#BKE_main_id_clear_newpoins()) and call updates + * of DEG too (#DAG_relations_tag_update()). */ Object *BKE_object_duplicate(Main *bmain, const Object *ob, const int dupflag) { @@ -1643,7 +1651,7 @@ Object *BKE_object_duplicate(Main *bmain, const Object *ob, const int dupflag) } break; case OB_LIGHTPROBE: - if (dupflag != 0) { + if (dupflag & USER_DUP_LIGHTPROBE) { ID_NEW_REMAP_US2(obn->data) else { @@ -1665,7 +1673,7 @@ Object *BKE_object_duplicate(Main *bmain, const Object *ob, const int dupflag) } break; case OB_GPENCIL: - if (dupflag != 0) { + if (dupflag & USER_DUP_GPENCIL) { ID_NEW_REMAP_US2(obn->data) else { @@ -1731,7 +1739,8 @@ void BKE_object_make_local_ex(Main *bmain, /* - only lib users: do nothing (unless force_local is set) * - only local users: set flag * - mixed: make copy - * In case we make a whole lib's content local, we always want to localize, and we skip remapping (done later). + * In case we make a whole lib's content local, + * we always want to localize, and we skip remapping (done later). */ if (!ID_IS_LINKED(ob)) { @@ -1844,10 +1853,12 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target) } } -/* proxy rule: lib_object->proxy_from == the one we borrow from, set temporally while object_update */ -/* local_object->proxy == pointer to library object, saved in files and read */ -/* local_object->proxy_group == pointer to collection dupli-object, saved in files and read */ - +/** + * Proxy rule: + * - lib_object->proxy_from == the one we borrow from, set temporally while object_update. + * - local_object->proxy == pointer to library object, saved in files and read. + * - local_object->proxy_group == pointer to collection dupli-object, saved in files and read. + */ void BKE_object_make_proxy(Main *bmain, Object *ob, Object *target, Object *cob) { /* paranoia checks */ @@ -2005,7 +2016,7 @@ void BKE_object_scale_to_mat3(Object *ob, float mat[3][3]) size_to_mat3(mat, vec); } -void BKE_object_rot_to_mat3(Object *ob, float mat[3][3], bool use_drot) +void BKE_object_rot_to_mat3(const Object *ob, float mat[3][3], bool use_drot) { float rmat[3][3], dmat[3][3]; @@ -2015,7 +2026,8 @@ void BKE_object_rot_to_mat3(Object *ob, float mat[3][3], bool use_drot) /* rotations may either be quats, eulers (with various rotation orders), or axis-angle */ if (ob->rotmode > 0) { - /* euler rotations (will cause gimble lock, but this can be alleviated a bit with rotation orders) */ + /* Euler rotations + * (will cause gimble lock, but this can be alleviated a bit with rotation orders). */ eulO_to_mat3(rmat, ob->rot, ob->rotmode); eulO_to_mat3(dmat, ob->drot, ob->rotmode); } @@ -2242,11 +2254,11 @@ static bool ob_parcurve(Object *ob, Object *par, float mat[4][4]) return false; } - /* ctime is now a proper var setting of Curve which gets set by Animato like any other var that's animated, - * but this will only work if it actually is animated... + /* ctime is now a proper var setting of Curve which gets set by Animato like any other var + * that's animated, but this will only work if it actually is animated. * - * we divide the curvetime calculated in the previous step by the length of the path, to get a time - * factor, which then gets clamped to lie within 0.0 - 1.0 range + * We divide the curvetime calculated in the previous step by the length of the path, + * to get a time factor, which then gets clamped to lie within 0.0 - 1.0 range. */ if (cu->pathlen) { ctime = cu->ctime / cu->pathlen; @@ -2491,7 +2503,8 @@ void BKE_object_get_parent_matrix(Object *ob, Object *par, float parentmat[4][4] } /** - * \param r_originmat: Optional matrix that stores the space the object is in (without its own matrix applied) + * \param r_originmat: Optional matrix that stores the space the object is in + * (without its own matrix applied) */ static void solve_parenting( Object *ob, Object *par, float obmat[4][4], float r_originmat[3][3], const bool set_origin) @@ -2614,7 +2627,8 @@ void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *o unit_m4(workob->parentinv); unit_m4(workob->constinv); - /* Since this is used while calculating parenting, at this moment ob_eval->parent is still NULL. */ + /* Since this is used while calculating parenting, + * at this moment ob_eval->parent is still NULL. */ workob->parent = DEG_get_evaluated_object(depsgraph, ob->parent); workob->trackflag = ob->trackflag; @@ -2636,8 +2650,10 @@ void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *o * Applies the global transformation \a mat to the \a ob using a relative parent space if supplied. * * \param mat: the global transformation mat that the object should be set object to. - * \param parent: the parent space in which this object will be set relative to (should probably always be parent_eval). - * \param use_compat: true to ensure that rotations are set using the min difference between the old and new orientation. + * \param parent: the parent space in which this object will be set relative to + * (should probably always be parent_eval). + * \param use_compat: true to ensure that rotations are set using the + * min difference between the old and new orientation. */ void BKE_object_apply_mat4_ex( Object *ob, float mat[4][4], Object *parent, float parentinv[4][4], const bool use_compat) @@ -3177,14 +3193,19 @@ static void object_handle_update_proxy(Depsgraph *depsgraph, } } -/* proxy rule: lib_object->proxy_from == the one we borrow from, only set temporal and cleared here */ -/* local_object->proxy == pointer to library object, saved in files and read */ - -/* function below is polluted with proxy exceptions, cleanup will follow! */ - -/* the main object update call, for object matrix, constraints, keys and displist (modifiers) */ -/* requires flags to be set! */ -/* Ideally we shouldn't have to pass the rigid body world, but need bigger restructuring to avoid id */ +/** + * Proxy rule: + * - lib_object->proxy_from == the one we borrow from, only set temporal and cleared here. + * - local_object->proxy == pointer to library object, saved in files and read. + * + * Function below is polluted with proxy exceptions, cleanup will follow! + * + * The main object update call, for object matrix, constraints, keys and displist (modifiers) + * requires flags to be set! + * + * Ideally we shouldn't have to pass the rigid body world, + * but need bigger restructuring to avoid id. + */ void BKE_object_handle_update_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c index 751110affaf..0ce6094771c 100644 --- a/source/blender/blenkernel/intern/object_deform.c +++ b/source/blender/blenkernel/intern/object_deform.c @@ -347,7 +347,8 @@ static void object_defgroup_remove_edit_mode(Object *ob, bDeformGroup *dg) BLI_assert(def_nr != -1); - /* Make sure that no verts are using this group - if none were removed, we can skip next per-vert update. */ + /* Make sure that no verts are using this group - if none were removed, + * we can skip next per-vert update. */ if (!BKE_object_defgroup_clear(ob, dg, false)) { /* Nothing to do. */ } @@ -577,7 +578,7 @@ bool *BKE_object_defgroup_lock_flags_get(Object *ob, const int defbase_tot) { bool is_locked = false; int i; - //int defbase_tot = BLI_listbase_count(&ob->defbase); + // int defbase_tot = BLI_listbase_count(&ob->defbase); bool *lock_flags = MEM_mallocN(defbase_tot * sizeof(bool), "defflags"); bDeformGroup *defgroup; @@ -601,7 +602,7 @@ bool *BKE_object_defgroup_validmap_get(Object *ob, const int defbase_tot) bool *defgroup_validmap; GHash *gh; int i, step1 = 1; - //int defbase_tot = BLI_listbase_count(&ob->defbase); + // int defbase_tot = BLI_listbase_count(&ob->defbase); VirtualModifierData virtualModifierData; if (BLI_listbase_is_empty(&ob->defbase)) { @@ -692,7 +693,9 @@ bool *BKE_object_defgroup_selected_get(Object *ob, int defbase_tot, int *r_dg_fl return dg_selection; } -/* Marks mirror vgroups in output and counts them. Output and counter assumed to be already initialized. +/** + * Marks mirror vgroups in output and counts them. + * Output and counter assumed to be already initialized. * Designed to be usable after BKE_object_defgroup_selected_get to extend selection to mirror. */ void BKE_object_defgroup_mirror_selection(struct Object *ob, diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c index 00ef5d9c469..8080834a53a 100644 --- a/source/blender/blenkernel/intern/object_dupli.c +++ b/source/blender/blenkernel/intern/object_dupli.c @@ -122,7 +122,8 @@ static void copy_dupli_context( { *r_ctx = *ctx; - /* XXX annoying, previously was done by passing an ID* argument, this at least is more explicit */ + /* XXX annoying, previously was done by passing an ID* argument, + * this at least is more explicit. */ if (ctx->gen->type == OB_DUPLICOLLECTION) { r_ctx->collection = ctx->object->instance_collection; } @@ -525,7 +526,8 @@ static void make_duplis_font(const DupliContext *ctx) for (a = 0; a < text_len; a++, ct++) { /* XXX That G.main is *really* ugly, but not sure what to do here... - * Definitively don't think it would be safe to put back Main *bmain pointer in DupliContext as done in 2.7x? */ + * Definitively don't think it would be safe to put back Main *bmain pointer + * in DupliContext as done in 2.7x? */ ob = find_family_object(G.main, cu->family, family_len, (unsigned int)text[a], family_gh); if (ob) { vec[0] = fsize * (ct->xof - xof); @@ -988,7 +990,8 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem copy_v3_v3(vec, obmat[3]); zero_v3(obmat[3]); - /* particle rotation uses x-axis as the aligned axis, so pre-rotate the object accordingly */ + /* Particle rotation uses x-axis as the aligned axis, + * so pre-rotate the object accordingly. */ if ((part->draw & PART_DRAW_ROTATE_OB) == 0) { float xvec[3], q[4], size_mat[4][4], original_size[3]; diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 66a3b418f3a..183bc968897 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -369,14 +369,6 @@ void BKE_object_eval_transform_all(Depsgraph *depsgraph, Scene *scene, Object *o BKE_object_eval_transform_final(depsgraph, object); } -void BKE_object_eval_update_shading(Depsgraph *depsgraph, Object *object) -{ - DEG_debug_print_eval(depsgraph, __func__, object->id.name, object); - if (object->type == OB_MESH) { - BKE_mesh_batch_cache_dirty_tag(object->data, BKE_MESH_BATCH_DIRTY_SHADING); - } -} - void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data) { DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data); diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index 606df3a7a96..b5df7d5fe9b 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -116,7 +116,8 @@ typedef struct Ocean { /* two dimensional arrays of float */ double *_disp_y; /* init w sim w via plan? */ double *_N_x; /* init w sim w via plan? */ - /* all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/ + /* all member of this array has same values, + * so convert this array to a float to reduce memory usage (MEM01). */ /*float * _N_y; */ double _N_y; /* sim w ********* can be rearranged? */ double *_N_z; /* init w sim w via plan? */ @@ -148,9 +149,9 @@ static float nextfr(RNG *rng, float min, float max) static float gaussRand(RNG *rng) { - /* Note: to avoid numerical problems with very small numbers, we make these variables singe-precision floats, - * but later we call the double-precision log() and sqrt() functions instead of logf() and sqrtf(). - */ + /* Note: to avoid numerical problems with very small numbers, we make these variables + * singe-precision floats, but later we call the double-precision log() and sqrt() functions + * instead of logf() and sqrtf(). */ float x; float y; float length2; @@ -464,9 +465,8 @@ void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x BKE_ocean_eval_uv_catrom(oc, ocr, x / oc->_Lx, z / oc->_Lz); } -/* note that this doesn't wrap properly for i, j < 0, but its not really meant for that being just a way to get - * the raw data out to save in some image format. - */ +/* note that this doesn't wrap properly for i, j < 0, but its not really meant for that being + * just a way to get the raw data out to save in some image format. */ void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j) { BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ); @@ -519,7 +519,8 @@ static void ocean_compute_htilda(void *__restrict userdata, int j; - /* note the <= _N/2 here, see the fftw doco about the mechanics of the complex->real fft storage */ + /* note the <= _N/2 here, see the fftw doco + * about the mechanics of the complex->real fft storage. */ for (j = 0; j <= o->_N / 2; ++j) { fftw_complex exp_param1; fftw_complex exp_param2; @@ -770,11 +771,12 @@ void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount BLI_rw_mutex_lock(&o->oceanmutex, THREAD_LOCK_WRITE); - /* Note about multi-threading here: we have to run a first set of computations (htilda one) before we can run - * all others, since they all depend on it. - * So we make a first parallelized forloop run for htilda, and then pack all other computations into - * a set of parallel tasks. - * This is not optimal in all cases, but remains reasonably simple and should be OK most of the time. */ + /* Note about multi-threading here: we have to run a first set of computations (htilda one) + * before we can run all others, since they all depend on it. + * So we make a first parallelized forloop run for htilda, + * and then pack all other computations into a set of parallel tasks. + * This is not optimal in all cases, + * but remains reasonably simple and should be OK most of the time. */ /* compute a new htilda */ ParallelRangeSettings settings; @@ -1342,7 +1344,8 @@ void BKE_ocean_simulate_cache(struct OceanCache *och, int frame) return; } - /* use default color spaces since we know for sure cache files were saved with default settings too */ + /* Use default color spaces since we know for sure cache + * files were saved with default settings too. */ cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE); och->ibufs_disp[f] = IMB_loadiffname(string, 0, NULL); @@ -1374,7 +1377,7 @@ void BKE_ocean_bake(struct Ocean *o, int res_x = och->resolution_x; int res_y = och->resolution_y; char string[FILE_MAX]; - //RNG *rng; + // RNG *rng; if (!o) { return; @@ -1387,7 +1390,7 @@ void BKE_ocean_bake(struct Ocean *o, prev_foam = NULL; } - //rng = BLI_rng_new(0); + // rng = BLI_rng_new(0); /* setup image format */ imf.imtype = R_IMF_IMTYPE_OPENEXR; @@ -1429,9 +1432,9 @@ void BKE_ocean_bake(struct Ocean *o, /* pr = pr * och->foam_fade; */ /* overall fade */ - /* remember ocean coord sys is Y up! - * break up the foam where height (Y) is low (wave valley), and X and Z displacement is greatest - */ + /* Remember ocean coord sys is Y up! + * break up the foam where height (Y) is low (wave valley), + * and X and Z displacement is greatest. */ neg_disp = ocr.disp[1] < 0.0f ? 1.0f + ocr.disp[1] : 1.0f; neg_disp = neg_disp < 0.0f ? 0.0f : neg_disp; @@ -1494,12 +1497,12 @@ void BKE_ocean_bake(struct Ocean *o, if (prev_foam) { MEM_freeN(prev_foam); } - //BLI_rng_free(rng); + // BLI_rng_free(rng); return; } } - //BLI_rng_free(rng); + // BLI_rng_free(rng); if (prev_foam) { MEM_freeN(prev_foam); } diff --git a/source/blender/blenkernel/intern/packedFile.c b/source/blender/blenkernel/intern/packedFile.c index 29e9295df1d..dd91878a15b 100644 --- a/source/blender/blenkernel/intern/packedFile.c +++ b/source/blender/blenkernel/intern/packedFile.c @@ -181,7 +181,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char return NULL; } - //XXX waitcursor(1); + // XXX waitcursor(1); /* convert relative filenames to absolute filenames */ @@ -216,7 +216,7 @@ PackedFile *newPackedFile(ReportList *reports, const char *filename, const char close(file); } - //XXX waitcursor(0); + // XXX waitcursor(0); return (pf); } @@ -281,7 +281,7 @@ int writePackedFile(ReportList *reports, /* void *data; */ if (guimode) { - } //XXX waitcursor(1); + } // XXX waitcursor(1); BLI_strncpy(name, filename, sizeof(name)); BLI_path_abs(name, ref_file_name); @@ -336,7 +336,7 @@ int writePackedFile(ReportList *reports, } if (guimode) { - } //XXX waitcursor(0); + } // XXX waitcursor(0); return (ret_value); } @@ -407,7 +407,8 @@ int checkPackedFile(const char *ref_file_name, const char *filename, PackedFile * It returns a char *to the existing file name / new file name or NULL when * there was an error or when the user decides to cancel the operation. * - * \warning 'abs_name' may be relative still! (use a "//" prefix) be sure to run #BLI_path_abs on it first. + * \warning 'abs_name' may be relative still! (use a "//" prefix) + * be sure to run #BLI_path_abs on it first. */ char *unpackFile(ReportList *reports, const char *ref_file_name, diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 7e8e724cfcc..b594232193d 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -82,8 +82,11 @@ static eOverlayControlFlags overlay_flags = 0; void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex) { Paint *p = BKE_paint_get_active(scene, view_layer); - Brush *br = p->brush; + if (!p) { + return; + } + Brush *br = p->brush; if (!br) { return; } @@ -140,6 +143,40 @@ void BKE_paint_reset_overlay_invalid(eOverlayControlFlags flag) overlay_flags &= ~(flag); } +bool BKE_paint_ensure_from_paintmode(Scene *sce, ePaintMode mode) +{ + ToolSettings *ts = sce->toolsettings; + Paint **paint_ptr = NULL; + + switch (mode) { + case PAINT_MODE_SCULPT: + paint_ptr = (Paint **)&ts->sculpt; + break; + case PAINT_MODE_VERTEX: + paint_ptr = (Paint **)&ts->vpaint; + break; + case PAINT_MODE_WEIGHT: + paint_ptr = (Paint **)&ts->wpaint; + break; + case PAINT_MODE_TEXTURE_2D: + case PAINT_MODE_TEXTURE_3D: + break; + case PAINT_MODE_SCULPT_UV: + paint_ptr = (Paint **)&ts->uvsculpt; + break; + case PAINT_MODE_GPENCIL: + paint_ptr = (Paint **)&ts->gp_paint; + break; + case PAINT_MODE_INVALID: + break; + } + if (paint_ptr && (*paint_ptr == NULL)) { + BKE_paint_ensure(ts, paint_ptr); + return true; + } + return false; +} + Paint *BKE_paint_get_active_from_paintmode(Scene *sce, ePaintMode mode) { if (sce) { @@ -182,6 +219,7 @@ const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode) case PAINT_MODE_TEXTURE_3D: return rna_enum_brush_image_tool_items; case PAINT_MODE_SCULPT_UV: + return rna_enum_brush_uv_sculpt_tool_items; return NULL; case PAINT_MODE_GPENCIL: return rna_enum_brush_gpencil_types_items; @@ -203,6 +241,8 @@ const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode) case PAINT_MODE_TEXTURE_2D: case PAINT_MODE_TEXTURE_3D: return "image_tool"; + case PAINT_MODE_SCULPT_UV: + return "uv_sculpt_tool"; case PAINT_MODE_GPENCIL: return "gpencil_tool"; default: @@ -229,10 +269,7 @@ Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer) case OB_MODE_PAINT_GPENCIL: return &ts->gp_paint->paint; case OB_MODE_EDIT: - if (ts->use_uv_sculpt) { - return &ts->uvsculpt->paint; - } - return &ts->imapaint.paint; + return &ts->uvsculpt->paint; default: break; } @@ -264,7 +301,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C) if (sima->mode == SI_MODE_PAINT) { return &ts->imapaint.paint; } - else if (ts->use_uv_sculpt) { + else if (sima->mode == SI_MODE_UV) { return &ts->uvsculpt->paint; } } @@ -287,7 +324,6 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) SpaceImage *sima; if (sce && view_layer) { - ToolSettings *ts = sce->toolsettings; Object *obact = NULL; if (view_layer->basact && view_layer->basact->object) { @@ -299,7 +335,7 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) if (sima->mode == SI_MODE_PAINT) { return PAINT_MODE_TEXTURE_2D; } - else if (ts->use_uv_sculpt) { + else if (sima->mode == SI_MODE_UV) { return PAINT_MODE_SCULPT_UV; } } @@ -318,10 +354,7 @@ ePaintMode BKE_paintmode_get_active_from_context(const bContext *C) case OB_MODE_TEXTURE_PAINT: return PAINT_MODE_TEXTURE_3D; case OB_MODE_EDIT: - if (ts->use_uv_sculpt) { - return PAINT_MODE_SCULPT_UV; - } - return PAINT_MODE_TEXTURE_2D; + return PAINT_MODE_SCULPT_UV; default: return PAINT_MODE_TEXTURE_2D; } @@ -355,6 +388,8 @@ ePaintMode BKE_paintmode_get_from_tool(const struct bToolRef *tref) switch (tref->mode) { case SI_MODE_PAINT: return PAINT_MODE_TEXTURE_2D; + case SI_MODE_UV: + return PAINT_MODE_SCULPT_UV; } } @@ -395,15 +430,14 @@ void BKE_paint_runtime_init(const ToolSettings *ts, Paint *paint) paint->runtime.tool_offset = offsetof(Brush, weightpaint_tool); paint->runtime.ob_mode = OB_MODE_WEIGHT_PAINT; } + else if (paint == &ts->uvsculpt->paint) { + paint->runtime.tool_offset = offsetof(Brush, uv_sculpt_tool); + paint->runtime.ob_mode = OB_MODE_EDIT; + } else if (paint == &ts->gp_paint->paint) { paint->runtime.tool_offset = offsetof(Brush, gpencil_tool); paint->runtime.ob_mode = OB_MODE_PAINT_GPENCIL; } - else if (paint == &ts->uvsculpt->paint) { - /* We don't use these yet. */ - paint->runtime.tool_offset = 0; - paint->runtime.ob_mode = 0; - } else { BLI_assert(0); } @@ -421,9 +455,10 @@ uint BKE_paint_get_brush_tool_offset_from_paintmode(const ePaintMode mode) return offsetof(Brush, vertexpaint_tool); case PAINT_MODE_WEIGHT: return offsetof(Brush, weightpaint_tool); + case PAINT_MODE_SCULPT_UV: + return offsetof(Brush, uv_sculpt_tool); case PAINT_MODE_GPENCIL: return offsetof(Brush, gpencil_tool); - case PAINT_MODE_SCULPT_UV: case PAINT_MODE_INVALID: break; /* We don't use these yet. */ } @@ -447,8 +482,10 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name) } /** - * Only copy internal data of PaintCurve ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of PaintCurve ID from source to + * already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -504,7 +541,7 @@ void BKE_paint_curve_clamp_endpoint_add_index(PaintCurve *pc, const int add_inde pc->add_index = (add_index || pc->tot_points == 1) ? (add_index + 1) : 0; } -/* remove colour from palette. Must be certain color is inside the palette! */ +/** Remove color from palette. Must be certain color is inside the palette! */ void BKE_palette_color_remove(Palette *palette, PaletteColor *color) { if (BLI_listbase_count_at_most(&palette->colors, palette->active_color) == @@ -534,8 +571,10 @@ Palette *BKE_palette_add(Main *bmain, const char *name) } /** - * Only copy internal data of Palette ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Palette ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -938,7 +977,8 @@ void BKE_sculptsession_bm_to_me(Object *ob, bool reorder) if (ob && ob->sculpt) { sculptsession_bm_to_me_update_data_only(ob, reorder); - /* ensure the objects evaluated mesh doesn't hold onto arrays now realloc'd in the mesh [#34473] */ + /* Ensure the objects evaluated mesh doesn't hold onto arrays + * now realloc'd in the mesh T34473. */ DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } } @@ -1134,7 +1174,10 @@ void BKE_sculpt_update_mesh_elements( if (!CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK)) { #if 1 BKE_sculpt_mask_layers_ensure(ob, mmd); -#else /* if we wanted to support adding mask data while multi-res painting, we would need to do this */ +#else + /* If we wanted to support adding mask data while multi-res painting, + * we would need to do this. */ + if ((ED_sculpt_mask_layers_ensure(ob, mmd) & ED_SCULPT_MASK_LAYER_CALC_LOOP)) { /* remake the derived mesh */ ob->recalc |= ID_RECALC_GEOMETRY; diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c index 942d5e758f3..fbf586e3f49 100644 --- a/source/blender/blenkernel/intern/paint_toolslots.c +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -70,6 +70,7 @@ void BKE_paint_toolslots_init_from_main(struct Main *bmain) paint_toolslots_init(bmain, &ts->sculpt->paint); paint_toolslots_init(bmain, &ts->vpaint->paint); paint_toolslots_init(bmain, &ts->wpaint->paint); + paint_toolslots_init(bmain, &ts->uvsculpt->paint); paint_toolslots_init(bmain, &ts->gp_paint->paint); } } diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 986e47894ca..c6cc72ba989 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -477,7 +477,9 @@ static void fluid_free_settings(SPHFluidSettings *fluid) } } -/** Free (or release) any data used by this particle settings (does not free the partsett itself). */ +/** + * Free (or release) any data used by this particle settings (does not free the partsett itself). + */ void BKE_particlesettings_free(ParticleSettings *part) { int a; @@ -603,7 +605,8 @@ void psys_free_particles(ParticleSystem *psys) PARTICLE_P; if (psys->particles) { - /* Even though psys->part should never be NULL, this can happen as an exception during deletion. + /* Even though psys->part should never be NULL, + * this can happen as an exception during deletion. * See ID_REMAP_SKIP/FORCE/FLAG_NEVER_NULL_USAGE in BKE_library_remap. */ if (psys->part && psys->part->type == PART_HAIR) { LOOP_PARTICLES @@ -846,8 +849,12 @@ typedef struct ParticleInterpolationData { float birthtime, dietime; int bspline; } ParticleInterpolationData; -/* Assumes pointcache->mem_cache exists, so for disk cached particles call psys_make_temp_pointcache() before use */ -/* It uses ParticleInterpolationData->pm to store the current memory cache frame so it's thread safe. */ +/** + * Assumes pointcache->mem_cache exists, so for disk cached particles + * call #psys_make_temp_pointcache() before use. + * It uses #ParticleInterpolationData.pm to store the current memory cache frame + * so it's thread safe. + */ static void get_pointcache_keys_for_time(Object *UNUSED(ob), PointCache *cache, PTCacheMem **cur, @@ -1194,7 +1201,8 @@ static void do_particle_interpolation(ParticleSystem *psys, interp_qt_qtqt(result->rot, keys[1].rot, keys[2].rot, keytime); } - /* now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between [0, 1]->[k2, k3] (k1 & k4 used for cardinal & bspline interpolation)*/ + /* Now we should have in chronologiacl order k1<=k2<=t<=k3<=k4 with keytime between + * [0, 1]->[k2, k3] (k1 & k4 used for cardinal & bspline interpolation). */ psys_interpolate_particle((pind->keyed || pind->cache || point_vel) ? -1 /* signal for cubic interpolation */ : @@ -1538,7 +1546,7 @@ int psys_particle_dm_face_lookup(Mesh *mesh_final, if (osface_final == NULL) { /* Assume we don't need osface_final data, and we get a direct 1-1 mapping... */ if (findex_orig < totface_final) { - //printf("\tNO CD_ORIGSPACE, assuming not needed\n"); + // printf("\tNO CD_ORIGSPACE, assuming not needed\n"); return findex_orig; } else { @@ -1574,7 +1582,8 @@ int psys_particle_dm_face_lookup(Mesh *mesh_final, } else { /* if we have no node, try every face */ for (int findex_dst = 0; findex_dst < totface_final; findex_dst++) { - /* If current tessface from 'final' DM and orig tessface (given by index) map to the same orig poly... */ + /* If current tessface from 'final' DM and orig tessface (given by index) + * map to the same orig poly. */ if (BKE_mesh_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, findex_dst) == pindex_orig) { faceuv = osface_final[findex_dst].uv; @@ -2090,7 +2099,7 @@ int do_guides(Depsgraph *depsgraph, add_v3_v3(vec_to_point, guidevec); - //sub_v3_v3v3(pa_loc, pa_loc, pa_zero); + // sub_v3_v3v3(pa_loc, pa_loc, pa_zero); madd_v3_v3fl(effect, vec_to_point, data->strength); madd_v3_v3fl(veffect, guidedir, data->strength); totstrength += data->strength; @@ -2106,7 +2115,7 @@ int do_guides(Depsgraph *depsgraph, mul_v3_fl(effect, 1.0f / totstrength); } CLAMP(totstrength, 0.0f, 1.0f); - //add_v3_v3(effect, pa_zero); + // add_v3_v3(effect, pa_zero); interp_v3_v3v3(state->co, state->co, effect, totstrength); normalize_v3(veffect); @@ -2245,7 +2254,8 @@ void psys_find_parents(ParticleSimulationData *sim, const bool use_render_params psys_particle_on_emitter( sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco); - /* Check if particle doesn't exist because of texture influence. Insert only existing particles into kdtree. */ + /* Check if particle doesn't exist because of texture influence. + * Insert only existing particles into kdtree. */ get_cpa_texture(sim->psmd->mesh_final, psys, part, @@ -2463,7 +2473,8 @@ static void psys_thread_create_path(ParticleTask *task, const ParticleCacheKey *key_w_last = pcache_key_segment_endpoint_safe(key[w]); float d; if (part->flag & PART_CHILD_LONG_HAIR) { - /* For long hair use tip distance/root distance as parting factor instead of root to tip angle. */ + /* For long hair use tip distance/root distance as parting + * factor instead of root to tip angle. */ float d1 = len_v3v3(key[0]->co, key[w]->co); float d2 = len_v3v3(key_0_last->co, key_w_last->co); @@ -2676,7 +2687,8 @@ static void psys_thread_create_path(ParticleTask *task, pa = &psys->particles[cpa->parent]; par = pcache[cpa->parent]; - /* If particle is unexisting, try to pick a viable parent from particles used for interpolation. */ + /* If particle is unexisting, try to pick a viable parent from particles + * used for interpolation. */ for (k = 0; k < 4 && pa && (pa->flag & PARS_UNEXIST); k++) { if (cpa->pa[k] >= 0) { pa = &psys->particles[cpa->pa[k]]; @@ -3741,8 +3753,10 @@ void BKE_particlesettings_twist_curve_init(ParticleSettings *part) } /** - * Only copy internal data of ParticleSettings ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of ParticleSettings ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -4324,7 +4338,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, } } else if (totchild) { - //invert_m4_m4(imat, ob->obmat); + // invert_m4_m4(imat, ob->obmat); /* interpolate childcache directly if it exists */ if (psys->childcache) { @@ -4368,10 +4382,11 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, psys_particle_on_emitter( psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa->fuv, foffset, co, 0, 0, 0, orco); - /* we need to save the actual root position of the child for positioning it accurately to the surface of the emitter */ - //copy_v3_v3(cpa_1st, co); + /* We need to save the actual root position of the child for + * positioning it accurately to the surface of the emitter. */ + // copy_v3_v3(cpa_1st, co); - //mul_m4_v3(ob->obmat, cpa_1st); + // mul_m4_v3(ob->obmat, cpa_1st); pa = psys->particles + cpa->parent; @@ -4455,7 +4470,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, w++; } /* apply offset for correct positioning */ - //add_v3_v3(state->co, cpa_1st); + // add_v3_v3(state->co, cpa_1st); } else { /* offset the child from the parent position */ @@ -4614,7 +4629,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta /* let's interpolate to try to be as accurate as possible */ if (pa->state.time + 2.f >= state->time && pa->prev_state.time - 2.f <= state->time) { if (pa->prev_state.time >= pa->state.time || pa->prev_state.time < 0.f) { - /* prev_state is wrong so let's not use it, this can happen at frames 1, 0 or particle birth */ + /* prev_state is wrong so let's not use it, + * this can happen at frames 1, 0 or particle birth. */ dfra = state->time - pa->state.time; copy_particle_key(state, &pa->state, 1); @@ -4655,7 +4671,8 @@ int psys_get_particle_state(ParticleSimulationData *sim, int p, ParticleKey *sta madd_v3_v3v3fl(state->co, state->co, state->vel, dfra / frs_sec); } else { - /* extrapolating over big ranges is not accurate so let's just give something close to reasonable back */ + /* Extrapolating over big ranges is not accurate + * so let's just give something close to reasonable back. */ copy_particle_key(state, &pa->state, 0); } } diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index 45aa55a401b..070c3c7a566 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -909,14 +909,14 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, !CustomData_get_layer(&final_mesh->fdata, CD_ORIGINDEX)) { printf( "Can't create particles with the current modifier stack, disable destructive modifiers\n"); - // XXX error("Can't paint with the current modifier stack, disable destructive modifiers"); + // XXX error("Can't paint with the current modifier stack, disable destructive modifiers"); return 0; } - /* XXX This distribution code is totally broken in case from == PART_FROM_CHILD, it's always using finaldm - * even if use_modifier_stack is unset... But making things consistent here break all existing edited - * hair systems, so better wait for complete rewrite. - */ + /* XXX This distribution code is totally broken in case from == PART_FROM_CHILD, + * it's always using finaldm even if use_modifier_stack is unset... + * But making things consistent here break all existing edited + * hair systems, so better wait for complete rewrite. */ psys_thread_context_init(ctx, sim); @@ -1170,7 +1170,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, int i_mapped = 0; for (i = 0; i < totelem && element_weight[i] == 0.0f; i++) { - ; + /* pass */ } element_sum[i_mapped] = element_weight[i] * inv_totweight; element_map[i_mapped] = i; @@ -1204,9 +1204,10 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, double step, pos; step = (totpart < 2) ? 0.5 : 1.0 / (double)totpart; - /* This is to address tricky issues with vertex-emitting when user tries (and expects) exact 1-1 vert/part - * distribution (see T47983 and its two example files). It allows us to consider pos as - * 'midpoint between v and v+1' (or 'p and p+1', depending whether we have more vertices than particles or not), + /* This is to address tricky issues with vertex-emitting when user tries + * (and expects) exact 1-1 vert/part distribution (see T47983 and its two example files). + * It allows us to consider pos as 'midpoint between v and v+1' + * (or 'p and p+1', depending whether we have more vertices than particles or not), * and avoid stumbling over float impression in element_sum. * Note: moved face and volume distribution to this as well (instead of starting at zero), * for the same reasons, see T52682. */ @@ -1215,7 +1216,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, for (i = 0, p = 0; p < totpart; p++, pos += step) { for (; (i < totmapped - 1) && (pos > (double)element_sum[i]); i++) { - ; + /* pass */ } particle_element[p] = element_map[i]; diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 38183f97b72..cba15aed55f 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -567,7 +567,7 @@ void psys_thread_context_free(ParticleThreadContext *ctx) if (ctx->seams) { MEM_freeN(ctx->seams); } - //if (ctx->vertpart) MEM_freeN(ctx->vertpart); + // if (ctx->vertpart) MEM_freeN(ctx->vertpart); BLI_kdtree_3d_free(ctx->tree); if (ctx->clumpcurve != NULL) { @@ -619,7 +619,7 @@ void initialize_particle(ParticleSimulationData *sim, ParticleData *pa) pa->hair_index = 0; /* we can't reset to -1 anymore since we've figured out correct index in distribute_particles */ /* usage other than straight after distribute has to handle this index by itself - jahka*/ - //pa->num_dmcache = DMCACHE_NOTFOUND; /* assume we don't have a derived mesh face */ + // pa->num_dmcache = DMCACHE_NOTFOUND; /* assume we don't have a derived mesh face */ } static void initialize_all_particles(ParticleSimulationData *sim) @@ -791,8 +791,15 @@ void psys_get_birth_coords( /* -tangent */ if (use_tangents) { - //float phase=vg_rot?2.0f*(psys_particle_value_from_verts(sim->psmd->dm,part->from,pa,vg_rot)-0.5f):0.0f; +#if 0 + float phase = vg_rot ? + 2.0f * + (psys_particle_value_from_verts(sim->psmd->dm, part->from, pa, vg_rot) - + 0.5f) : + 0.0f; +#else float phase = 0.0f; +#endif mul_v3_fl(vtan, -cosf((float)M_PI * (part->tanphase + phase))); fac = -sinf((float)M_PI * (part->tanphase + phase)); madd_v3_v3fl(vtan, utan, fac); @@ -1554,12 +1561,13 @@ static void integrate_particle( } } -/********************************************************************************************************* - * SPH fluid physics +/* -------------------------------------------------------------------- */ +/** \name SPH fluid physics * * In theory, there could be unlimited implementation of SPH simulators * - * This code uses in some parts adapted algorithms from the pseudo code as outlined in the Research paper: + * This code uses in some parts adapted algorithms + * from the pseudo code as outlined in the Research paper: * * Titled: Particle-based Viscoelastic Fluid Simulation. * Authors: Simon Clavet, Philippe Beaudoin and Pierre Poulin @@ -1567,7 +1575,8 @@ static void integrate_particle( * * Presented at Siggraph, (2005) * - * ********************************************************************************************************/ + * \{ */ + #define PSYS_FLUID_SPRINGS_INITIAL_SIZE 256 static ParticleSpring *sph_spring_add(ParticleSystem *psys, ParticleSpring *spring) { @@ -2199,7 +2208,7 @@ static void sph_integrate(ParticleSimulationData *sim, sphdata->pa = pa; sphdata->mass = pa_mass; sphdata->pass = 0; - //sphdata.element_size and sphdata.flow are set in the callback. + // sphdata.element_size and sphdata.flow are set in the callback. /* restore previous state and treat gravity & effectors as external acceleration*/ sub_v3_v3v3(effector_acceleration, pa->state.vel, pa->prev_state.vel); @@ -2210,6 +2219,8 @@ static void sph_integrate(ParticleSimulationData *sim, integrate_particle(part, pa, dtime, effector_acceleration, sphdata->force_cb, sphdata); } +/** \} */ + /************************************************/ /* Basic physics */ /************************************************/ @@ -2289,7 +2300,7 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa mul_v3_fl(pa->state.vel, 1.f - part->dampfac * efdata.ptex.damp * 25.f * dtime); } - //copy_v3_v3(pa->state.ave, states->ave); + // copy_v3_v3(pa->state.ave, states->ave); /* finally we do guides */ time = (cfra - pa->time) / pa->lifetime; @@ -2435,7 +2446,8 @@ static void collision_interpolate_element(ParticleCollisionElement *pce, { /* t is the current time for newton rhapson */ /* fac is the starting factor for current collision iteration */ - /* the col->fac's are factors for the particle subframe step start and end during collision modifier step */ + /* The col->fac's are factors for the particle subframe step start + * and end during collision modifier step. */ float f = fac + t * (1.f - fac); float mul = col->fac1 + f * (col->fac2 - col->fac1); if (pce->tot > 0) { @@ -2928,7 +2940,8 @@ static int collision_response(ParticleSimulationData *sim, /* get exact velocity right before collision */ madd_v3_v3v3fl(v0, col->ve1, col->acc, dt1); - /* convert collider velocity from 1/framestep to 1/s TODO: here we assume 1 frame step for collision modifier */ + /* Convert collider velocity from 1/framestep to 1/s TODO: + * here we assume 1 frame step for collision modifier. */ mul_v3_fl(pce->vel, col->inv_timestep); /* calculate tangential particle velocity */ @@ -2983,8 +2996,10 @@ static int collision_response(ParticleSimulationData *sim, } } - /* stickiness was possibly added before, so cancel that before calculating new normal velocity */ - /* otherwise particles go flying out of the surface because of high reversed sticky velocity */ + /* Stickiness was possibly added before, + * so cancel that before calculating new normal velocity. + * Otherwise particles go flying out of the surface + * because of high reversed sticky velocity. */ if (v0_dot < 0.0f) { v0_dot += pd->pdef_stickness; if (v0_dot > 0.0f) { @@ -3578,7 +3593,8 @@ static void save_hair(ParticleSimulationData *sim, float UNUSED(cfra)) pa->totkey++; - /* root is always in the origin of hair space so we set it to be so after the last key is saved*/ + /* Root is always in the origin of hair space + * so we set it to be so after the last key is saved. */ if (pa->totkey == psys->part->hair_step + 1) { zero_v3(root->co); } @@ -4185,7 +4201,7 @@ static void particles_fluid_step(ParticleSimulationData *sim, float wrf; gzread(gzf, &wrf, sizeof(wrf)); pa->state.co[j] = wrf; - //fprintf(stderr,"Rj%d ",j); + // fprintf(stderr,"Rj%d ",j); } for (j = 0; j < 3; j++) { float wrf; @@ -4200,7 +4216,18 @@ static void particles_fluid_step(ParticleSimulationData *sim, pa->dietime = sim->scene->r.efra + 1; pa->lifetime = sim->scene->r.efra; pa->alive = PARS_ALIVE; - //if (a < 25) fprintf(stderr,"FSPARTICLE debug set %s, a%d = %f,%f,%f, life=%f\n", filename, a, pa->co[0],pa->co[1],pa->co[2], pa->lifetime ); +# if 0 + if (a < 25) { + fprintf(stderr, + "FSPARTICLE debug set %s, a%d = %f,%f,%f, life=%f\n", + filename, + a, + pa->co[0], + pa->co[1], + pa->co[2], + pa->lifetime); + } +# endif } else { // skip... @@ -4759,7 +4786,8 @@ void particle_system_update(struct Depsgraph *depsgraph, } } - /* save matrix for duplicators, at rendertime the actual dupliobject's matrix is used so don't update! */ + /* Save matrix for duplicators, + * at rendertime the actual dupliobject's matrix is used so don't update! */ invert_m4_m4(psys->imat, ob->obmat); BKE_particle_batch_cache_dirty_tag(psys, BKE_PARTICLE_BATCH_DIRTY_ALL); diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index 0a82d086862..f1d5347c48b 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -154,12 +154,12 @@ static void update_node_vb(PBVH *bvh, PBVHNode *node) node->vb = vb; } -//void BKE_pbvh_node_BB_reset(PBVHNode *node) +// void BKE_pbvh_node_BB_reset(PBVHNode *node) //{ // BB_reset(&node->vb); //} // -//void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]) +// void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]) //{ // BB_expand(&node->vb, co); //} @@ -181,10 +181,10 @@ static int partition_indices(int *prim_indices, int lo, int hi, int axis, float int i = lo, j = hi; for (;;) { for (; prim_bbc[prim_indices[i]].bcentroid[axis] < mid; i++) { - ; + /* pass */ } for (; mid < prim_bbc[prim_indices[j]].bcentroid[axis]; j--) { - ; + /* pass */ } if (!(i < j)) { @@ -216,18 +216,18 @@ static int partition_indices_material(PBVH *bvh, int lo, int hi) for (;;) { if (bvh->looptri) { for (; face_materials_match(first, &mpoly[looptri[indices[i]].poly]); i++) { - ; + /* pass */ } for (; !face_materials_match(first, &mpoly[looptri[indices[j]].poly]); j--) { - ; + /* pass */ } } else { for (; grid_materials_match(first, &flagmats[indices[i]]); i++) { - ; + /* pass */ } for (; !grid_materials_match(first, &flagmats[indices[j]]); j--) { - ; + /* pass */ } } @@ -1038,9 +1038,10 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, const int v = vtri[j]; if (bvh->verts[v].flag & ME_VERT_PBVH_UPDATE) { - /* Note: This avoids `lock, add_v3_v3, unlock` and is five to ten times quicker than a spinlock. - * Not exact equivalent though, since atomicity is only ensured for one component - * of the vector at a time, but here it shall not make any sensible difference. */ + /* Note: This avoids `lock, add_v3_v3, unlock` + * and is five to ten times quicker than a spinlock. + * Not exact equivalent though, since atomicity is only ensured for one component + * of the vector at a time, but here it shall not make any sensible difference. */ for (int k = 3; k--;) { atomic_add_and_fetch_fl(&vnors[v][k], fn[k]); } @@ -1924,8 +1925,8 @@ void BKE_pbvh_raycast_project_ray_root( BKE_pbvh_node_get_BB(bvh->nodes, bb_min_root, bb_max_root); } - /* slightly offset min and max in case we have a zero width node (due to a plane mesh for instance), - * or faces very close to the bounding box boundary. */ + /* Slightly offset min and max in case we have a zero width node + * (due to a plane mesh for instance), or faces very close to the bounding box boundary. */ mid_v3_v3v3(bb_center, bb_max_root, bb_min_root); /* diff should be same for both min/max since it's calculated from center */ sub_v3_v3v3(bb_diff, bb_max_root, bb_center); @@ -2201,26 +2202,17 @@ bool BKE_pbvh_node_planes_exclude_AABB(PBVHNode *node, void *data) return test_planes_aabb(bb_min, bb_max, data) != ISECT_INSIDE; } -struct PBVHNodeDrawCallbackData { - void (*draw_fn)(void *user_data, GPUBatch *batch); +typedef struct PBVHNodeDrawCallbackData { + void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers); void *user_data; - bool fast; - bool only_mask; /* Only draw nodes that have mask data. */ - bool wires; -}; +} PBVHNodeDrawCallbackData; static void pbvh_node_draw_cb(PBVHNode *node, void *data_v) { - struct PBVHNodeDrawCallbackData *data = data_v; + PBVHNodeDrawCallbackData *data = data_v; if (!(node->flag & PBVH_FullyHidden)) { - GPUBatch *batch = GPU_pbvh_buffers_batch_get(node->draw_buffers, data->fast, data->wires); - bool show_mask = GPU_pbvh_buffers_has_mask(node->draw_buffers); - if (!data->only_mask || show_mask) { - if (batch != NULL) { - data->draw_fn(data->user_data, batch); - } - } + data->draw_fn(data->user_data, node->draw_buffers); } } @@ -2230,20 +2222,10 @@ static void pbvh_node_draw_cb(PBVHNode *node, void *data_v) void BKE_pbvh_draw_cb(PBVH *bvh, float (*planes)[4], float (*fnors)[3], - bool fast, - bool wires, - bool only_mask, bool show_vcol, - void (*draw_fn)(void *user_data, GPUBatch *batch), + void (*draw_fn)(void *user_data, GPU_PBVH_Buffers *buffers), void *user_data) { - struct PBVHNodeDrawCallbackData draw_data = { - .only_mask = only_mask, - .fast = fast, - .wires = wires, - .draw_fn = draw_fn, - .user_data = user_data, - }; PBVHNode **nodes; int totnode; @@ -2260,6 +2242,11 @@ void BKE_pbvh_draw_cb(PBVH *bvh, MEM_freeN(nodes); } + PBVHNodeDrawCallbackData draw_data = { + .draw_fn = draw_fn, + .user_data = user_data, + }; + if (planes) { BKE_pbvh_search_callback( bvh, BKE_pbvh_node_planes_contain_AABB, planes, pbvh_node_draw_cb, &draw_data); @@ -2267,10 +2254,18 @@ void BKE_pbvh_draw_cb(PBVH *bvh, else { BKE_pbvh_search_callback(bvh, NULL, NULL, pbvh_node_draw_cb, &draw_data); } -#if 0 - if (G.debug_value == 14) - pbvh_draw_BB(bvh); -#endif +} + +void BKE_pbvh_draw_debug_cb( + PBVH *bvh, + void (*draw_fn)(void *user_data, const float bmin[3], const float bmax[3], PBVHNodeFlags flag), + void *user_data) +{ + for (int a = 0; a < bvh->totnode; a++) { + PBVHNode *node = &bvh->nodes[a]; + + draw_fn(user_data, node->vb.bmin, node->vb.bmax, node->flag); + } } void BKE_pbvh_grids_update( @@ -2341,7 +2336,8 @@ void BKE_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3], const int totvert) /* unneeded deformation -- duplicate verts/faces to avoid this */ pbvh->verts = MEM_dupallocN(pbvh->verts); - /* No need to dupalloc pbvh->looptri, this one is 'totally owned' by pbvh, it's never some mesh data. */ + /* No need to dupalloc pbvh->looptri, this one is 'totally owned' by pbvh, + * it's never some mesh data. */ pbvh->deformed = true; } diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index bc84b3737aa..25f9948a835 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -1916,7 +1916,8 @@ void BKE_pbvh_build_bmesh(PBVH *bvh, /* start recursion, assign faces to nodes accordingly */ pbvh_bmesh_node_limit_ensure_fast(bvh, nodeinfo, bbc_array, &rootnode, arena); - /* we now have all faces assigned to a node, next we need to assign those to the gsets of the nodes */ + /* We now have all faces assigned to a node, + * next we need to assign those to the gsets of the nodes. */ /* Start with all faces in the root node */ bvh->nodes = MEM_callocN(sizeof(PBVHNode), "PBVHNode"); diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index c07ae89e250..a55d0be4f95 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -293,7 +293,8 @@ static int ptcache_particle_write(int index, void *psys_v, void **data, int cfra PTCACHE_DATA_FROM(data, BPHYS_DATA_BOIDS, &boid->data); } - /* return flag 1+1=2 for newly born particles to copy exact birth location to previously cached frame */ + /* Return flag 1+1=2 for newly born particles + * to copy exact birth location to previously cached frame. */ return 1 + (pa->state.time >= pa->time && pa->prev_state.time <= pa->time); } static void ptcache_particle_read( @@ -630,7 +631,7 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v) unsigned int in_len = sizeof(float) * (unsigned int)res; unsigned char *out = (unsigned char *)MEM_callocN(LZO_OUT_LEN(in_len) * 4, "pointcache_lzo_buffer"); - //int mode = res >= 1000000 ? 2 : 1; + // int mode = res >= 1000000 ? 2 : 1; int mode = 1; // light if (sds->cache_comp == SM_CACHE_HEAVY) { mode = 2; // heavy @@ -703,7 +704,7 @@ static int ptcache_smoke_write(PTCacheFile *pf, void *smoke_v) smoke_turbulence_get_res(sds->wt, res_big_array); res_big = res_big_array[0] * res_big_array[1] * res_big_array[2]; - //mode = res_big >= 1000000 ? 2 : 1; + // mode = res_big >= 1000000 ? 2 : 1; mode = 1; // light if (sds->cache_high_comp == SM_CACHE_HEAVY) { mode = 2; // heavy @@ -2285,7 +2286,7 @@ static int ptcache_file_compressed_write( r = LzmaCompress(out, &out_len, in, - in_len, //assume sizeof(char)==1.... + in_len, // assume sizeof(char)==1.... props, &sizeOfIt, 5, diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index b5960962e17..ad15214c3b8 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -114,7 +114,8 @@ void BKE_rigidbody_free_world(Scene *scene) } if (is_orig && rbw->shared->physics_world) { - /* free physics references, we assume that all physics objects in will have been added to the world */ + /* Free physics references, + * we assume that all physics objects in will have been added to the world. */ if (rbw->constraints) { FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->constraints, object) { if (object->rigidbody_constraint) { @@ -685,7 +686,8 @@ static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, bool } /* make sure collision shape exists */ - /* FIXME we shouldn't always have to rebuild collision shapes when rebuilding objects, but it's needed for constraints to update correctly */ + /* FIXME we shouldn't always have to rebuild collision shapes when rebuilding objects, + * but it's needed for constraints to update correctly. */ if (rbo->shared->physics_shape == NULL || rebuild) { rigidbody_validate_sim_shape(ob, true); } @@ -990,8 +992,12 @@ static void rigidbody_validate_sim_constraint(RigidBodyWorld *rbw, Object *ob, b /* --------------------- */ -/* Create physics sim world given RigidBody world settings */ -// NOTE: this does NOT update object references that the scene uses, in case those aren't ready yet! +/** + * Create physics sim world given RigidBody world settings + * + * \note this does NOT update object references that the scene uses, + * in case those aren't ready yet! + */ void BKE_rigidbody_validate_sim_world(Scene *scene, RigidBodyWorld *rbw, bool rebuild) { /* sanity checks */ @@ -1411,6 +1417,10 @@ static void rigidbody_update_sim_ob( return; } + ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); + Base *base = BKE_view_layer_base_find(view_layer, ob); + const bool is_selected = base ? (base->flag & BASE_SELECTED) != 0 : false; + if (rbo->shape == RB_SHAPE_TRIMESH && rbo->flag & RBO_FLAG_USE_DEFORM) { Mesh *mesh = ob->runtime.mesh_deform_eval; if (mesh) { @@ -1437,14 +1447,15 @@ static void rigidbody_update_sim_ob( RBO_GET_MARGIN(rbo) * MIN3(scale[0], scale[1], scale[2])); } - /* make transformed objects temporarily kinmatic so that they can be moved by the user during simulation */ - if (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ) { + /* Make transformed objects temporarily kinmatic + * so that they can be moved by the user during simulation. */ + if (is_selected && (G.moving & G_TRANSFORM_OBJ)) { RB_body_set_kinematic_state(rbo->shared->physics_object, true); RB_body_set_mass(rbo->shared->physics_object, 0.0f); } /* update rigid body location and rotation for kinematic bodies */ - if (rbo->flag & RBO_FLAG_KINEMATIC || (ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) { + if (rbo->flag & RBO_FLAG_KINEMATIC || (is_selected && (G.moving & G_TRANSFORM_OBJ))) { RB_body_activate(rbo->shared->physics_object); RB_body_set_loc_rot(rbo->shared->physics_object, loc, rot); } @@ -1463,15 +1474,16 @@ static void rigidbody_update_sim_ob( float eff_loc[3], eff_vel[3]; /* create dummy 'point' which represents last known position of object as result of sim */ - // XXX: this can create some inaccuracies with sim position, but is probably better than using unsimulated vals? + /* XXX: this can create some inaccuracies with sim position, + * but is probably better than using unsimulated vals? */ RB_body_get_position(rbo->shared->physics_object, eff_loc); RB_body_get_linear_velocity(rbo->shared->physics_object, eff_vel); pd_point_from_loc(scene, eff_loc, eff_vel, 0, &epoint); - /* calculate net force of effectors, and apply to sim object - * - we use 'central force' since apply force requires a "relative position" which we don't have... - */ + /* Calculate net force of effectors, and apply to sim object: + * - we use 'central force' since apply force requires a "relative position" + * which we don't have... */ BKE_effectors_apply(effectors, NULL, effector_weights, &epoint, eff_force, NULL); if (G.f & G_DEBUG) { printf("\tapplying force (%f,%f,%f) to '%s'\n", @@ -1541,13 +1553,15 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, if (ob->type == OB_MESH) { /* validate that we've got valid object set up here... */ RigidBodyOb *rbo = ob->rigidbody_object; - /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ + /* Update transformation matrix of the object + * so we don't get a frame of lag for simple animations. */ BKE_object_where_is_calc_time(depsgraph, scene, ob, ctime); /* TODO remove this whole block once we are sure we never get NULL rbo here anymore. */ /* This cannot be done in CoW evaluation context anymore... */ if (rbo == NULL) { - BLI_assert(!"CoW object part of RBW object collection without RB object data, should not happen.\n"); + BLI_assert(!"CoW object part of RBW object collection without RB object data, " + "should not happen.\n"); /* Since this object is included in the sim group but doesn't have * rigid body settings (perhaps it was added manually), add! * - assume object to be active? That is the default for newly added settings... @@ -1563,7 +1577,8 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, if (rebuild) { /* World has been rebuilt so rebuild object */ /* TODO(Sybren): rigidbody_validate_sim_object() can call rigidbody_validate_sim_shape(), - * but neither resets the RBO_FLAG_NEEDS_RESHAPE flag nor calls RB_body_set_collision_shape(). + * but neither resets the RBO_FLAG_NEEDS_RESHAPE flag nor + * calls RB_body_set_collision_shape(). * This results in the collision shape being created twice, which is unnecessary. */ rigidbody_validate_sim_object(rbw, ob, true); } @@ -1575,7 +1590,8 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, /* mesh/shape data changed, so force shape refresh */ rigidbody_validate_sim_shape(ob, true); /* now tell RB sim about it */ - // XXX: we assume that this can only get applied for active/passive shapes that will be included as rigidbodies + /* XXX: we assume that this can only get applied for active/passive shapes + * that will be included as rigidbodies. */ RB_body_set_collision_shape(rbo->shared->physics_object, rbo->shared->physics_shape); } } @@ -1595,13 +1611,15 @@ static void rigidbody_update_simulation(Depsgraph *depsgraph, FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->constraints, ob) { /* validate that we've got valid object set up here... */ RigidBodyCon *rbc = ob->rigidbody_constraint; - /* update transformation matrix of the object so we don't get a frame of lag for simple animations */ + /* Update transformation matrix of the object + * so we don't get a frame of lag for simple animations. */ BKE_object_where_is_calc_time(depsgraph, scene, ob, ctime); /* TODO remove this whole block once we are sure we never get NULL rbo here anymore. */ /* This cannot be done in CoW evaluation context anymore... */ if (rbc == NULL) { - BLI_assert(!"CoW object part of RBW constraints collection without RB constraint data, should not happen.\n"); + BLI_assert(!"CoW object part of RBW constraints collection without RB constraint data, " + "should not happen.\n"); /* Since this object is included in the group but doesn't have * constraint settings (perhaps it was added manually), add! */ @@ -1663,7 +1681,7 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime) /* use rigid body transform after cache start frame if objects is not being transformed */ if (BKE_rigidbody_check_sim_running(rbw, ctime) && - !(ob->flag & SELECT && G.moving & G_TRANSFORM_OBJ)) { + !(ob->base_flag & BASE_SELECTED && G.moving & G_TRANSFORM_OBJ)) { float mat[4][4], size_mat[4][4], size[3]; normalize_qt(rbo->orn); // RB_TODO investigate why quaternion isn't normalized at this point @@ -1748,7 +1766,8 @@ void BKE_rigidbody_aftertrans_update( } RB_body_set_loc_rot(rbo->shared->physics_object, rbo->pos, rbo->orn); } - // RB_TODO update rigid body physics object's loc/rot for dynamic objects here as well (needs to be done outside bullet's update loop) + /* RB_TODO update rigid body physics object's loc/rot for dynamic objects here as well + * (needs to be done outside bullet's update loop). */ } void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) @@ -1773,7 +1792,8 @@ void BKE_rigidbody_rebuild_world(Depsgraph *depsgraph, Scene *scene, float ctime BKE_ptcache_id_time(&pid, scene, ctime, &startframe, &endframe, NULL); cache = rbw->shared->pointcache; - /* flag cache as outdated if we don't have a world or number of objects in the simulation has changed */ + /* Flag cache as outdated if we don't have a world or number of objects + * in the simulation has changed. */ int n = 0; FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->group, object) { (void)object; @@ -1854,7 +1874,8 @@ void BKE_rigidbody_do_simulation(Depsgraph *depsgraph, Scene *scene, float ctime /* calculate how much time elapsed since last step in seconds */ timestep = 1.0f / (float)FPS * (ctime - rbw->ltime) * rbw->time_scale; - /* step simulation by the requested timestep, steps per second are adjusted to take time scale into account */ + /* Step simulation by the requested timestep, + * steps per second are adjusted to take time scale into account. */ RB_dworld_step_simulation(rbw->shared->physics_world, timestep, INT_MAX, diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index bc67046b9a9..8a70db8704f 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -37,6 +37,7 @@ #include "DNA_scene_types.h" #include "DNA_screen_types.h" #include "DNA_sequence_types.h" +#include "DNA_sound_types.h" #include "DNA_space_types.h" #include "DNA_view3d_types.h" #include "DNA_windowmanager_types.h" @@ -225,8 +226,10 @@ void BKE_toolsettings_free(ToolSettings *toolsettings) } /** - * Only copy internal data of Scene ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Scene ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -306,8 +309,7 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons flag_subdata); } - /* before scene copy */ - BKE_sound_create_scene(sce_dst); + BKE_sound_reset_scene_runtime(sce_dst); /* Copy sequencer, this is local data! */ if (sce_src->ed) { @@ -397,8 +399,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) sce_copy->r.ffcodecdata.properties = IDP_CopyProperty(sce->r.ffcodecdata.properties); } - /* before scene copy */ - BKE_sound_create_scene(sce_copy); + BKE_sound_reset_scene_runtime(sce_copy); /* grease pencil */ sce_copy->gpd = NULL; @@ -412,7 +413,7 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type) id_us_min(&sce_copy->id); id_us_ensure_real(&sce_copy->id); - /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks... */ + /* Extra actions, most notably SCE_FULL_COPY also duplicates several 'children' datablocks. */ if (type == SCE_COPY_FULL) { /* Copy Freestyle LineStyle datablocks. */ @@ -564,7 +565,7 @@ void BKE_scene_init(Scene *sce) sce->cursor.rotation_quaternion[0] = 1.0f; sce->cursor.rotation_axis[1] = 1.0f; - sce->r.mode = R_OSA; + sce->r.mode = 0; sce->r.cfra = 1; sce->r.sfra = 1; sce->r.efra = 250; @@ -765,9 +766,9 @@ void BKE_scene_init(Scene *sce) BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic)); BLI_rctf_init(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f); - sce->r.osa = 8; - /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */ + /* Note; in header_info.c the scene copy happens..., + * if you add more to renderdata it has to be checked there. */ /* multiview - stereo */ BKE_scene_add_render_view(sce, STEREO_LEFT_NAME); @@ -778,7 +779,7 @@ void BKE_scene_init(Scene *sce) srv = sce->r.views.last; BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix)); - BKE_sound_create_scene(sce); + BKE_sound_reset_scene_runtime(sce); /* color management */ colorspace_name = IMB_colormanagement_role_colorspace_name_get(COLOR_ROLE_DEFAULT_SEQUENCER); @@ -902,6 +903,9 @@ void BKE_scene_init(Scene *sce) sce->display.matcap_ssao_attenuation = 1.0f; sce->display.matcap_ssao_samples = 16; + sce->display.render_aa = SCE_DISPLAY_AA_SAMPLES_8; + sce->display.viewport_aa = SCE_DISPLAY_AA_FXAA; + /* OpenGL Render. */ BKE_screen_view3d_shading_init(&sce->display.shading); @@ -1029,7 +1033,8 @@ Object *BKE_scene_object_find_by_name(Scene *scene, const char *name) } /** - * Sets the active scene, mainly used when running in background mode (``--scene`` command line argument). + * Sets the active scene, mainly used when running in background mode + * (``--scene`` command line argument). * This is also called to set the scene directly, bypassing windowing code. * Otherwise #WM_window_set_active_scene is used when changing scenes by the user. */ @@ -1054,7 +1059,8 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) BKE_scene_object_base_flag_sync_from_base(base); } } - /* no full animation update, this to enable render code to work (render code calls own animation updates) */ + /* No full animation update, this to enable render code to work + * (render code calls own animation updates). */ } /* called from creator_args.c */ @@ -1071,7 +1077,8 @@ Scene *BKE_scene_set_name(Main *bmain, const char *name) return NULL; } -/* Used by metaballs, return *all* objects (including duplis) existing in the scene (including scene's sets) */ +/* Used by metaballs, return *all* objects (including duplis) + * existing in the scene (including scene's sets). */ int BKE_scene_base_iter_next( Depsgraph *depsgraph, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob) { @@ -1357,8 +1364,10 @@ bool BKE_scene_validate_setscene(Main *bmain, Scene *sce) return true; } -/* This function is needed to cope with fractional frames - including two Blender rendering features - * mblur (motion blur that renders 'subframes' and blurs them together), and fields rendering. +/** + * This function is needed to cope with fractional frames - including two Blender rendering + * features mblur (motion blur that renders 'subframes' and blurs them together), + * and fields rendering. */ float BKE_scene_frame_get(const Scene *scene) { @@ -1521,6 +1530,13 @@ static void prepare_mesh_for_viewport_render(Main *bmain, const ViewLayer *view_ } } +static void scene_update_sound(Depsgraph *depsgraph, Main *bmain) +{ + Scene *scene = DEG_get_evaluated_scene(depsgraph); + BKE_sound_ensure_scene(scene); + BKE_sound_update_scene(bmain, scene); +} + /* TODO(sergey): This actually should become view_layer_graph or so. * Same applies to update_for_newframe. */ @@ -1549,10 +1565,9 @@ void BKE_scene_graph_update_tagged(Depsgraph *depsgraph, Main *bmain) * by depgraph or manual, no layer check here, gets correct flushed. */ DEG_evaluate_on_refresh(depsgraph); - /* Update sound system animation (TODO, move to depsgraph). */ - BKE_sound_update_scene(bmain, scene); - - /* Notify python about depsgraph update */ + /* Update sound system. */ + scene_update_sound(depsgraph, bmain); + /* Notify python about depsgraph update. */ if (run_callbacks) { BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_DEPSGRAPH_UPDATE_POST); } @@ -1580,15 +1595,6 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain) BKE_image_editors_update_frame(bmain, scene->r.cfra); BKE_sound_set_cfra(scene->r.cfra); DEG_graph_relations_update(depsgraph, bmain, scene, view_layer); - /* Update animated cache files for modifiers. - * - * TODO(sergey): Make this a depsgraph node? - */ - BKE_cachefile_update_frame(bmain, - depsgraph, - scene, - ctime, - (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base)); #ifdef POSE_ANIMATION_WORKAROUND scene_armature_depsgraph_workaround(bmain, depsgraph); #endif @@ -1596,8 +1602,8 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain) * by depgraph or manual, no layer check here, gets correct flushed. */ DEG_evaluate_on_framechange(bmain, depsgraph, ctime); - /* Update sound system animation (TODO, move to depsgraph). */ - BKE_sound_update_scene(bmain, scene); + /* Update sound system animation. */ + scene_update_sound(depsgraph, bmain); /* Notify editors and python about recalc. */ BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST); /* Inform editors about possible changes. */ @@ -1608,8 +1614,8 @@ void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph, Main *bmain) /** Ensures given scene/view_layer pair has a valid, up-to-date depsgraph. * - * \warning Sets matching depsgraph as active, so should only be called from the active editing context - * (usually, from operators). + * \warning Sets matching depsgraph as active, + * so should only be called from the active editing context (usually, from operators). */ void BKE_scene_view_layer_graph_evaluated_ensure(Main *bmain, Scene *scene, ViewLayer *view_layer) { @@ -1766,31 +1772,20 @@ void BKE_scene_base_flag_to_objects(ViewLayer *view_layer) } } +/** + * Synchronize object base flags + * + * This is usually handled by the depsgraph. + * However, in rare occasions we need to use the latest object flags + * before depsgraph is fully updated. + * + * It should (ideally) only run for copy-on-written objects since this is + * runtime data generated per-viewlayer. + */ void BKE_scene_object_base_flag_sync_from_base(Base *base) { Object *ob = base->object; - - ob->flag = base->flag; - - if ((base->flag & BASE_SELECTED) != 0) { - ob->flag |= SELECT; - } - else { - ob->flag &= ~SELECT; - } -} - -void BKE_scene_object_base_flag_sync_from_object(Base *base) -{ - Object *ob = base->object; - base->flag = ob->flag; - - if ((ob->flag & SELECT) != 0 && (base->flag & BASE_SELECTABLE) != 0) { - base->flag |= BASE_SELECTED; - } - else { - base->flag &= ~BASE_SELECTED; - } + ob->base_flag = base->flag; } void BKE_scene_disable_color_management(Scene *scene) @@ -1859,8 +1854,9 @@ int BKE_render_preview_pixel_size(const RenderData *r) return r->preview_pixel_size; } -/* Apply the needed correction factor to value, based on unit_type (only length-related are affected currently) - * and unit->scale_length. +/** + * Apply the needed correction factor to value, based on unit_type + * (only length-related are affected currently) and unit->scale_length. */ double BKE_scene_unit_scale(const UnitSettings *unit, const int unit_type, double value) { @@ -2321,7 +2317,8 @@ TransformOrientation *BKE_scene_transform_orientation_find(const Scene *scene, c } /** - * \return the index that \a orientation has within \a scene's transform-orientation list or -1 if not found. + * \return the index that \a orientation has within \a scene's transform-orientation list + * or -1 if not found. */ int BKE_scene_transform_orientation_get_index(const Scene *scene, const TransformOrientation *orientation) @@ -2418,3 +2415,23 @@ void BKE_scene_cursor_quat_to_rot(View3DCursor *cursor, const float quat[4], boo } /** \} */ + +/* Dependency graph evaluation. */ + +void BKE_scene_eval_sequencer_sequences(Depsgraph *depsgraph, Scene *scene) +{ + DEG_debug_print_eval(depsgraph, __func__, scene->id.name, scene); + if (scene->ed == NULL) { + return; + } + BKE_sound_ensure_scene(scene); + Sequence *seq; + SEQ_BEGIN (scene->ed, seq) { + if (seq->sound != NULL && seq->scene_sound == NULL) { + seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene, seq); + } + } + SEQ_END; + BKE_sequencer_update_muting(scene->ed); + BKE_sequencer_update_sound_bounds_all(scene); +} diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index a3ec3364436..9799f7c2943 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -308,7 +308,8 @@ void BKE_spacedata_draw_locks(int set) } /** - * Version of #BKE_area_find_region_type that also works if \a slink is not the active space of \a sa. + * Version of #BKE_area_find_region_type that also works if \a slink + * is not the active space of \a sa. */ ARegion *BKE_spacedata_find_region_type(const SpaceLink *slink, const ScrArea *sa, int region_type) { diff --git a/source/blender/blenkernel/intern/seqcache.c b/source/blender/blenkernel/intern/seqcache.c index b022819ca8c..1c0aa63f590 100644 --- a/source/blender/blenkernel/intern/seqcache.c +++ b/source/blender/blenkernel/intern/seqcache.c @@ -21,49 +21,84 @@ */ #include <stddef.h> - -#include "BLI_sys_types.h" /* for intptr_t */ +#include <memory.h> #include "MEM_guardedalloc.h" #include "DNA_sequence_types.h" #include "DNA_scene_types.h" -#include "IMB_moviecache.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" +#include "BLI_mempool.h" +#include "BLI_threads.h" #include "BLI_listbase.h" +#include "BLI_ghash.h" #include "BKE_sequencer.h" #include "BKE_scene.h" +#include "BKE_main.h" + +/* ***************************** Sequencer cache design notes ****************************** + * + * Cache key members: + * is_temp_cache - this cache entry will be freed before rendering next frame + * creator_id - ID of thread that created entry + * cost - In short: render time divided by playback frame rate + * link_prev/next - link to another entry created during rendering of the frame + * + * Linking: We use links to reduce number of iterations needed to manage cache. + * Entries are linked in order as they are put into cache. + * Only pernament (is_temp_cache = 0) cache entries are linked. + * Putting SEQ_CACHE_STORE_FINAL_OUT will reset linking + * + * Function: + * All images created during rendering are added to cache, even if the cache is already full. + * This is because: + * - one image may be needed multiple times during rendering. + * - keeping the last rendered frame allows us for faster re-render when user edits strip in stack + * - we can decide if we keep frame only when it's completely rendered. Otherwise we risk having + * "holes" in the cache, which can be annoying + * If the cache is full all entries for pending frame will have is_temp_cache set. + * + * Only entire frame can be freed to release resources for new entries (recycling). + * Once again, this is to reduce number of iterations, but also more controllable than removing + * entries one by one in reverse order to their creation. + * + * User can exclude caching of some images. Such entries will have is_temp_cache set. + */ + +typedef struct SeqCache { + struct GHash *hash; + ThreadMutex iterator_mutex; + struct BLI_mempool *keys_pool; + struct BLI_mempool *items_pool; + struct SeqCacheKey *last_key; + size_t memory_used; +} SeqCache; + +typedef struct SeqCacheItem { + struct SeqCache *cache_owner; + struct ImBuf *ibuf; +} SeqCacheItem; typedef struct SeqCacheKey { + struct SeqCache *cache_owner; + void *userkey; + struct SeqCacheKey *link_prev; /* Used for linking intermediate items to final frame */ + struct SeqCacheKey *link_next; /* Used for linking intermediate items to final frame */ struct Sequence *seq; SeqRenderData context; float cfra; - eSeqStripElemIBuf type; + float nfra; + float cost; + bool is_temp_cache; + short creator_id; + int type; } SeqCacheKey; -typedef struct SeqPreprocessCacheElem { - struct SeqPreprocessCacheElem *next, *prev; - - struct Sequence *seq; - SeqRenderData context; - eSeqStripElemIBuf type; - - ImBuf *ibuf; -} SeqPreprocessCacheElem; - -typedef struct SeqPreprocessCache { - int cfra; - ListBase elems; -} SeqPreprocessCache; - -static struct MovieCache *moviecache = NULL; -static struct SeqPreprocessCache *preprocess_cache = NULL; - -static void preprocessed_cache_destruct(void); +static ThreadMutex cache_create_lock = BLI_MUTEX_INITIALIZER; static bool seq_cmp_render_data(const SeqRenderData *a, const SeqRenderData *b) { @@ -88,209 +123,536 @@ static unsigned int seq_hash_render_data(const SeqRenderData *a) return rval; } -static unsigned int seqcache_hashhash(const void *key_) +static unsigned int seq_cache_hashhash(const void *key_) { const SeqCacheKey *key = key_; unsigned int rval = seq_hash_render_data(&key->context); - rval ^= *(const unsigned int *)&key->cfra; + rval ^= *(const unsigned int *)&key->nfra; rval += key->type; rval ^= ((intptr_t)key->seq) << 6; return rval; } -static bool seqcache_hashcmp(const void *a_, const void *b_) +static bool seq_cache_hashcmp(const void *a_, const void *b_) { const SeqCacheKey *a = a_; const SeqCacheKey *b = b_; - return ((a->seq != b->seq) || (a->cfra != b->cfra) || (a->type != b->type) || + return ((a->seq != b->seq) || (a->nfra != b->nfra) || (a->type != b->type) || seq_cmp_render_data(&a->context, &b->context)); } -void BKE_sequencer_cache_destruct(void) +static SeqCache *seq_cache_get_from_scene(Scene *scene) { - if (moviecache) { - IMB_moviecache_free(moviecache); + if (scene && scene->ed && scene->ed->cache) { + return scene->ed->cache; } - preprocessed_cache_destruct(); + return NULL; +} + +static void seq_cache_lock(Scene *scene) +{ + SeqCache *cache = seq_cache_get_from_scene(scene); + + if (cache) { + BLI_mutex_lock(&cache->iterator_mutex); + } } -void BKE_sequencer_cache_cleanup(void) +static void seq_cache_unlock(Scene *scene) { - if (moviecache) { - IMB_moviecache_free(moviecache); - moviecache = IMB_moviecache_create( - "seqcache", sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp); + SeqCache *cache = seq_cache_get_from_scene(scene); + + if (cache) { + BLI_mutex_unlock(&cache->iterator_mutex); } +} - BKE_sequencer_preprocessed_cache_cleanup(); +static void seq_cache_keyfree(void *val) +{ + SeqCacheKey *key = val; + BLI_mempool_free(key->cache_owner->keys_pool, key); } -static bool seqcache_key_check_seq(ImBuf *UNUSED(ibuf), void *userkey, void *userdata) +static void seq_cache_valfree(void *val) { - SeqCacheKey *key = (SeqCacheKey *)userkey; - Sequence *seq = (Sequence *)userdata; + SeqCacheItem *item = (SeqCacheItem *)val; + SeqCache *cache = item->cache_owner; + + if (item->ibuf) { + cache->memory_used -= IMB_get_size_in_memory(item->ibuf); + IMB_freeImBuf(item->ibuf); + } - return key->seq == seq; + BLI_mempool_free(item->cache_owner->items_pool, item); } -void BKE_sequencer_cache_cleanup_sequence(Sequence *seq) +static void seq_cache_put(SeqCache *cache, SeqCacheKey *key, ImBuf *ibuf) { - if (moviecache) { - IMB_moviecache_cleanup(moviecache, seqcache_key_check_seq, seq); + SeqCacheItem *item; + item = BLI_mempool_alloc(cache->items_pool); + item->cache_owner = cache; + item->ibuf = ibuf; + + if (BLI_ghash_reinsert(cache->hash, key, item, seq_cache_keyfree, seq_cache_valfree)) { + IMB_refImBuf(ibuf); + cache->last_key = key; + cache->memory_used += IMB_get_size_in_memory(ibuf); } } -struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context, - Sequence *seq, - float cfra, - eSeqStripElemIBuf type) +static ImBuf *seq_cache_get(SeqCache *cache, void *key) { - if (moviecache && seq) { - SeqCacheKey key; + SeqCacheItem *item = BLI_ghash_lookup(cache->hash, key); - key.seq = seq; - key.context = *context; - key.cfra = cfra - seq->start; - key.type = type; + if (item && item->ibuf) { + IMB_refImBuf(item->ibuf); - return IMB_moviecache_get(moviecache, &key); + return item->ibuf; } return NULL; } -void BKE_sequencer_cache_put( - const SeqRenderData *context, Sequence *seq, float cfra, eSeqStripElemIBuf type, ImBuf *i) +static void seq_cache_relink_keys(SeqCacheKey *link_next, SeqCacheKey *link_prev) +{ + if (link_next) { + link_next->link_prev = link_prev; + } + if (link_prev) { + link_prev->link_next = link_next; + } +} + +static SeqCacheKey *seq_cache_choose_key(Scene *scene, SeqCacheKey *lkey, SeqCacheKey *rkey) { - SeqCacheKey key; + SeqCacheKey *finalkey = NULL; + + if (rkey && lkey) { + if (lkey->cfra > rkey->cfra) { + SeqCacheKey *swapkey = lkey; + lkey = rkey; + rkey = swapkey; + } + + int l_diff = scene->r.cfra - lkey->cfra; + int r_diff = rkey->cfra - scene->r.cfra; + + if (l_diff > r_diff) { + finalkey = lkey; + } + else { + finalkey = rkey; + } + } + else { + if (lkey) { + finalkey = lkey; + } + else { + finalkey = rkey; + } + } + return finalkey; +} - if (i == NULL || context->skip_cache) { +static void seq_cache_recycle_linked(Scene *scene, SeqCacheKey *base) +{ + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { return; } - if (!moviecache) { - moviecache = IMB_moviecache_create( - "seqcache", sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp); + SeqCacheKey *next = base->link_next; + + while (base) { + SeqCacheKey *prev = base->link_prev; + BLI_ghash_remove(cache->hash, base, seq_cache_keyfree, seq_cache_valfree); + base = prev; + } + + base = next; + while (base) { + next = base->link_next; + BLI_ghash_remove(cache->hash, base, seq_cache_keyfree, seq_cache_valfree); + base = next; + } +} + +static SeqCacheKey *seq_cache_get_item_for_removal(Scene *scene) +{ + SeqCache *cache = seq_cache_get_from_scene(scene); + SeqCacheKey *finalkey = NULL; + /*leftmost key*/ + SeqCacheKey *lkey = NULL; + /*rightmost key*/ + SeqCacheKey *rkey = NULL; + SeqCacheKey *key = NULL; + + GHashIterator gh_iter; + BLI_ghashIterator_init(&gh_iter, cache->hash); + int total_count = 0; + int cheap_count = 0; + + while (!BLI_ghashIterator_done(&gh_iter)) { + key = BLI_ghashIterator_getKey(&gh_iter); + SeqCacheItem *item = BLI_ghashIterator_getValue(&gh_iter); + BLI_ghashIterator_step(&gh_iter); + + /* this shouldn't happen, but better be safe than sorry */ + if (!item->ibuf) { + seq_cache_recycle_linked(scene, key); + /* can not continue iterating after linked remove */ + BLI_ghashIterator_init(&gh_iter, cache->hash); + continue; + } + + if (key->is_temp_cache || key->link_next != NULL) { + continue; + } + + total_count++; + + if (key->cost <= scene->ed->recycle_max_cost) { + cheap_count++; + if (lkey) { + if (key->cfra < lkey->cfra) { + lkey = key; + } + } + else { + lkey = key; + } + if (rkey) { + if (key->cfra > rkey->cfra) { + rkey = key; + } + } + else { + rkey = key; + } + } + } + + finalkey = seq_cache_choose_key(scene, lkey, rkey); + return finalkey; +} + +/* Find only "base" keys + * Sources(other types) for a frame must be freed all at once + */ +static bool seq_cache_recycle_item(Scene *scene) +{ + size_t memory_total = ((size_t)U.memcachelimit) * 1024 * 1024; + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { + return false; } - key.seq = seq; - key.context = *context; - key.cfra = cfra - seq->start; - key.type = type; + seq_cache_lock(scene); + + while (cache->memory_used > memory_total) { + SeqCacheKey *finalkey = seq_cache_get_item_for_removal(scene); - IMB_moviecache_put(moviecache, &key, i); + if (finalkey) { + seq_cache_recycle_linked(scene, finalkey); + } + else { + seq_cache_unlock(scene); + return false; + } + } + seq_cache_unlock(scene); + return true; } -void BKE_sequencer_preprocessed_cache_cleanup(void) +static void seq_cache_set_temp_cache_linked(Scene *scene, SeqCacheKey *base) { - SeqPreprocessCacheElem *elem; + SeqCache *cache = seq_cache_get_from_scene(scene); - if (!preprocess_cache) { + if (!cache || !base) { return; } - for (elem = preprocess_cache->elems.first; elem; elem = elem->next) { - IMB_freeImBuf(elem->ibuf); + SeqCacheKey *next = base->link_next; + + while (base) { + SeqCacheKey *prev = base->link_prev; + base->is_temp_cache = true; + base = prev; } - BLI_freelistN(&preprocess_cache->elems); - BLI_listbase_clear(&preprocess_cache->elems); + base = next; + while (base) { + next = base->link_next; + base->is_temp_cache = true; + base = next; + } } -static void preprocessed_cache_destruct(void) +static void BKE_sequencer_cache_create(Scene *scene) { - if (!preprocess_cache) { + BLI_mutex_lock(&cache_create_lock); + if (scene->ed->cache == NULL) { + SeqCache *cache = MEM_callocN(sizeof(SeqCache), "SeqCache"); + cache->keys_pool = BLI_mempool_create(sizeof(SeqCacheKey), 0, 64, BLI_MEMPOOL_NOP); + cache->items_pool = BLI_mempool_create(sizeof(SeqCacheItem), 0, 64, BLI_MEMPOOL_NOP); + cache->hash = BLI_ghash_new(seq_cache_hashhash, seq_cache_hashcmp, "SeqCache hash"); + cache->last_key = NULL; + BLI_mutex_init(&cache->iterator_mutex); + scene->ed->cache = cache; + } + BLI_mutex_unlock(&cache_create_lock); +} + +/* ***************************** API ****************************** */ + +void BKE_sequencer_cache_free_temp_cache(Scene *scene, short id, int cfra) +{ + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { return; } - BKE_sequencer_preprocessed_cache_cleanup(); + seq_cache_lock(scene); - MEM_freeN(preprocess_cache); - preprocess_cache = NULL; + GHashIterator gh_iter; + BLI_ghashIterator_init(&gh_iter, cache->hash); + while (!BLI_ghashIterator_done(&gh_iter)) { + SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter); + BLI_ghashIterator_step(&gh_iter); + + if (key->is_temp_cache && key->creator_id == id && key->cfra != cfra) { + BLI_ghash_remove(cache->hash, key, seq_cache_keyfree, seq_cache_valfree); + } + } + seq_cache_unlock(scene); } -ImBuf *BKE_sequencer_preprocessed_cache_get(const SeqRenderData *context, - Sequence *seq, - float cfra, - eSeqStripElemIBuf type) +void BKE_sequencer_cache_destruct(Scene *scene) { - SeqPreprocessCacheElem *elem; + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { + return; + } - if (!preprocess_cache) { - return NULL; + BLI_ghash_free(cache->hash, seq_cache_keyfree, seq_cache_valfree); + BLI_mempool_destroy(cache->keys_pool); + BLI_mempool_destroy(cache->items_pool); + BLI_mutex_end(&cache->iterator_mutex); + MEM_freeN(cache); + scene->ed->cache = NULL; +} + +void BKE_sequencer_cache_cleanup_all(Main *bmain) +{ + for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) { + BKE_sequencer_cache_cleanup(scene); + } +} +void BKE_sequencer_cache_cleanup(Scene *scene) +{ + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { + return; } - if (preprocess_cache->cfra != cfra) { - return NULL; + seq_cache_lock(scene); + + GHashIterator gh_iter; + BLI_ghashIterator_init(&gh_iter, cache->hash); + while (!BLI_ghashIterator_done(&gh_iter)) { + SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter); + + BLI_ghashIterator_step(&gh_iter); + BLI_ghash_remove(cache->hash, key, seq_cache_keyfree, seq_cache_valfree); } + cache->last_key = NULL; + seq_cache_unlock(scene); +} - for (elem = preprocess_cache->elems.first; elem; elem = elem->next) { - if (elem->seq != seq) { - continue; - } +void BKE_sequencer_cache_cleanup_sequence(Scene *scene, Sequence *seq) +{ + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { + return; + } - if (elem->type != type) { - continue; - } + seq_cache_lock(scene); - if (seq_cmp_render_data(&elem->context, context) != 0) { - continue; + GHashIterator gh_iter; + BLI_ghashIterator_init(&gh_iter, cache->hash); + while (!BLI_ghashIterator_done(&gh_iter)) { + SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter); + BLI_ghashIterator_step(&gh_iter); + + if (key->seq == seq) { + /* Relink keys, so we don't end up with orphaned keys */ + if (key->link_next || key->link_prev) { + seq_cache_relink_keys(key->link_next, key->link_prev); + } + + BLI_ghash_remove(cache->hash, key, seq_cache_keyfree, seq_cache_valfree); } + } + cache->last_key = NULL; + seq_cache_unlock(scene); +} + +struct ImBuf *BKE_sequencer_cache_get(const SeqRenderData *context, + Sequence *seq, + float cfra, + int type) +{ + Scene *scene = context->scene; - IMB_refImBuf(elem->ibuf); - return elem->ibuf; + if (!scene->ed->cache) { + BKE_sequencer_cache_create(scene); + return NULL; } - return NULL; + seq_cache_lock(scene); + SeqCache *cache = seq_cache_get_from_scene(scene); + ImBuf *ibuf = NULL; + + if (cache && seq) { + SeqCacheKey key; + + key.seq = seq; + key.context = *context; + key.nfra = cfra - seq->start; + key.type = type; + + ibuf = seq_cache_get(cache, &key); + } + seq_cache_unlock(scene); + + return ibuf; } -void BKE_sequencer_preprocessed_cache_put( - const SeqRenderData *context, Sequence *seq, float cfra, eSeqStripElemIBuf type, ImBuf *ibuf) +bool BKE_sequencer_cache_put_if_possible( + const SeqRenderData *context, Sequence *seq, float cfra, int type, ImBuf *ibuf, float cost) { - SeqPreprocessCacheElem *elem; + Scene *scene = context->scene; - if (!preprocess_cache) { - preprocess_cache = MEM_callocN(sizeof(SeqPreprocessCache), "sequencer preprocessed cache"); + if (seq_cache_recycle_item(scene)) { + BKE_sequencer_cache_put(context, seq, cfra, type, ibuf, cost); + return true; } else { - if (preprocess_cache->cfra != cfra) { - BKE_sequencer_preprocessed_cache_cleanup(); - } + seq_cache_set_temp_cache_linked(scene, scene->ed->cache->last_key); + scene->ed->cache->last_key = NULL; + return false; } +} + +void BKE_sequencer_cache_put( + const SeqRenderData *context, Sequence *seq, float cfra, int type, ImBuf *i, float cost) +{ + Scene *scene = context->scene; + short creator_id = 0; - elem = MEM_callocN(sizeof(SeqPreprocessCacheElem), "sequencer preprocessed cache element"); + if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) { + return; + } - elem->seq = seq; - elem->type = type; - elem->context = *context; - elem->ibuf = ibuf; + /* Prevent reinserting, it breaks cache key linking */ + ImBuf *test = BKE_sequencer_cache_get(context, seq, cfra, type); + if (test) { + IMB_freeImBuf(test); + return; + } - preprocess_cache->cfra = cfra; + if (!scene->ed->cache) { + BKE_sequencer_cache_create(scene); + } - IMB_refImBuf(ibuf); + seq_cache_lock(scene); - BLI_addtail(&preprocess_cache->elems, elem); + SeqCache *cache = seq_cache_get_from_scene(scene); + int flag; + + if (seq->cache_flag & SEQ_CACHE_OVERRIDE) { + flag = seq->cache_flag; + flag |= scene->ed->cache_flag & SEQ_CACHE_STORE_FINAL_OUT; + } + else { + flag = scene->ed->cache_flag; + } + + if (cost > SEQ_CACHE_COST_MAX) { + cost = SEQ_CACHE_COST_MAX; + } + + SeqCacheKey *key; + key = BLI_mempool_alloc(cache->keys_pool); + key->cache_owner = cache; + key->seq = seq; + key->context = *context; + key->cfra = cfra; + key->nfra = cfra - seq->start; + key->type = type; + key->cost = cost; + key->cache_owner = cache; + key->link_prev = NULL; + key->link_next = NULL; + key->is_temp_cache = true; + key->creator_id = creator_id; + + /* Item stored for later use */ + if (flag & type) { + key->is_temp_cache = false; + key->link_prev = cache->last_key; + } + + SeqCacheKey *temp_last_key = cache->last_key; + seq_cache_put(cache, key, i); + + /* Restore pointer to previous item as this one will be freed when stack is rendered */ + if (key->is_temp_cache) { + cache->last_key = temp_last_key; + } + + /* Set last_key's reference to this key so we can look up chain backwards + * Item is already put in cache, so cache->last_key points to current key; + */ + if (flag & type && temp_last_key) { + temp_last_key->link_next = cache->last_key; + } + + /* Reset linking */ + if (key->type == SEQ_CACHE_STORE_FINAL_OUT) { + cache->last_key = NULL; + } + + seq_cache_unlock(scene); } -void BKE_sequencer_preprocessed_cache_cleanup_sequence(Sequence *seq) +void BKE_sequencer_cache_iterate( + struct Scene *scene, + void *userdata, + bool callback(void *userdata, struct Sequence *seq, int cfra, int cache_type, float cost)) { - SeqPreprocessCacheElem *elem, *elem_next; - - if (!preprocess_cache) { + SeqCache *cache = seq_cache_get_from_scene(scene); + if (!cache) { return; } - for (elem = preprocess_cache->elems.first; elem; elem = elem_next) { - elem_next = elem->next; + seq_cache_lock(scene); + GHashIterator gh_iter; + BLI_ghashIterator_init(&gh_iter, cache->hash); + bool interrupt = false; - if (elem->seq == seq) { - IMB_freeImBuf(elem->ibuf); + while (!BLI_ghashIterator_done(&gh_iter) && !interrupt) { + SeqCacheKey *key = BLI_ghashIterator_getKey(&gh_iter); + BLI_ghashIterator_step(&gh_iter); - BLI_freelinkN(&preprocess_cache->elems, elem); - } + interrupt = callback(userdata, key->seq, key->cfra, key->type, key->cost); } + + cache->last_key = NULL; + seq_cache_unlock(scene); } diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index b2d5609ad07..74541c13c4f 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -27,7 +27,7 @@ #include <stddef.h> #include <stdlib.h> #include <string.h> -#include <math.h> +#include <time.h> #include "MEM_guardedalloc.h" @@ -273,7 +273,8 @@ static void BKE_sequence_free_ex(Scene *scene, * also invalidate cache for all dependent sequences * * be _very_ careful here, invalidating cache loops over the scene sequences and - * assumes the listbase is valid for all strips, this may not be the case if lists are being freed. + * assumes the listbase is valid for all strips, + * this may not be the case if lists are being freed. * this is optional BKE_sequence_invalidate_cache */ if (do_cache) { @@ -463,6 +464,11 @@ Editing *BKE_sequencer_editing_ensure(Scene *scene) ed = scene->ed = MEM_callocN(sizeof(Editing), "addseq"); ed->seqbasep = &ed->seqbase; + ed->cache = NULL; + ed->cache_flag = SEQ_CACHE_STORE_FINAL_OUT; + ed->cache_flag |= SEQ_CACHE_VIEW_FINAL_OUT; + ed->cache_flag |= SEQ_CACHE_VIEW_ENABLE; + ed->recycle_max_cost = 10.0f; } return scene->ed; @@ -477,8 +483,7 @@ void BKE_sequencer_editing_free(Scene *scene, const bool do_id_user) return; } - /* this may not be the active scene!, could be smarter about this */ - BKE_sequencer_cache_cleanup(); + BKE_sequencer_cache_destruct(scene); SEQ_BEGIN (ed, seq) { /* handle cache freeing above */ @@ -630,8 +635,6 @@ void BKE_sequencer_new_render_data(Main *bmain, r_context->is_proxy_render = false; r_context->view_id = 0; r_context->gpu_offscreen = NULL; - r_context->gpu_samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0; - r_context->gpu_full_samples = (r_context->gpu_samples) && (scene->r.scemode & R_FULL_SAMPLE); } /* ************************* iterator ************************** */ @@ -805,10 +808,7 @@ void BKE_sequence_calc_disp(Scene *scene, Sequence *seq) seq->handsize = (float)((seq->enddisp - seq->startdisp) / 25); } - if (ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SCENE)) { - BKE_sequencer_update_sound_bounds(scene, seq); - } - else if (seq->type == SEQ_TYPE_META) { + if (seq->type == SEQ_TYPE_META) { seq_update_sound_bounds_recursive(scene, seq); } } @@ -1307,7 +1307,7 @@ ListBase *BKE_sequence_seqbase_get(Sequence *seq, int *r_offset) break; } case SEQ_TYPE_SCENE: { - if (seq->flag & SEQ_SCENE_STRIPS) { + if (seq->flag & SEQ_SCENE_STRIPS && seq->scene) { Editing *ed = BKE_sequencer_editing_get(seq->scene, false); if (ed) { seqbase = &ed->seqbase; @@ -2342,7 +2342,7 @@ static void color_balance_byte_byte(StripColorBalance *cb_, int height, float mul) { - //unsigned char cb_tab[3][256]; + // unsigned char cb_tab[3][256]; unsigned char *cp = rect; unsigned char *e = cp + width * 4 * height; unsigned char *m = mask_rect; @@ -2638,7 +2638,7 @@ bool BKE_sequencer_input_have_to_preprocess(const SeqRenderData *context, { float mul; - if (context->is_proxy_render) { + if (context && context->is_proxy_render) { return false; } @@ -2787,7 +2787,7 @@ static ImBuf *input_preprocess(const SeqRenderData *context, } if (ibuf->x != context->rectx || ibuf->y != context->recty) { - if (scene->r.mode & R_OSA) { + if (scene->display.render_aa > SCE_DISPLAY_AA_FXAA) { IMB_scaleImBuf(ibuf, (short)context->rectx, (short)context->recty); } else { @@ -2808,54 +2808,6 @@ static ImBuf *input_preprocess(const SeqRenderData *context, return ibuf; } -static ImBuf *copy_from_ibuf_still(const SeqRenderData *context, Sequence *seq, float nr) -{ - ImBuf *rval = NULL; - ImBuf *ibuf = NULL; - - if (nr == 0) { - ibuf = BKE_sequencer_cache_get(context, seq, seq->start, SEQ_STRIPELEM_IBUF_STARTSTILL); - } - else if (nr == seq->len - 1) { - ibuf = BKE_sequencer_cache_get(context, seq, seq->start, SEQ_STRIPELEM_IBUF_ENDSTILL); - } - - if (ibuf) { - rval = IMB_dupImBuf(ibuf); - IMB_metadata_copy(rval, ibuf); - IMB_freeImBuf(ibuf); - } - - return rval; -} - -static void copy_to_ibuf_still(const SeqRenderData *context, Sequence *seq, float nr, ImBuf *ibuf) -{ - /* warning: ibuf may be NULL if the video fails to load */ - if (nr == 0 || nr == seq->len - 1) { - /* we have to store a copy, since the passed ibuf - * could be preprocessed afterwards (thereby silently - * changing the cached image... */ - ImBuf *oibuf = ibuf; - ibuf = IMB_dupImBuf(oibuf); - - if (ibuf) { - IMB_metadata_copy(ibuf, oibuf); - sequencer_imbuf_assign_spaces(context->scene, ibuf); - } - - if (nr == 0) { - BKE_sequencer_cache_put(context, seq, seq->start, SEQ_STRIPELEM_IBUF_STARTSTILL, ibuf); - } - - if (nr == seq->len - 1) { - BKE_sequencer_cache_put(context, seq, seq->start, SEQ_STRIPELEM_IBUF_ENDSTILL, ibuf); - } - - IMB_freeImBuf(ibuf); - } -} - /*********************** strip rendering functions *************************/ typedef struct RenderEffectInitData { @@ -3061,7 +3013,7 @@ static ImBuf *seq_render_effect_strip_impl(const SeqRenderData *context, static ImBuf *seq_render_image_strip(const SeqRenderData *context, Sequence *seq, - float nr, + float UNUSED(nr), float cfra) { ImBuf *ibuf = NULL; @@ -3137,8 +3089,8 @@ static ImBuf *seq_render_image_strip(const SeqRenderData *context, BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibufs_arr[i], false); if (i != context->view_id) { - copy_to_ibuf_still(&localcontext, seq, nr, ibufs_arr[i]); - BKE_sequencer_cache_put(&localcontext, seq, cfra, SEQ_STRIPELEM_IBUF, ibufs_arr[i]); + BKE_sequencer_cache_put( + &localcontext, seq, cfra, SEQ_CACHE_STORE_PREPROCESSED, ibufs_arr[i], 0); } } } @@ -3252,8 +3204,8 @@ static ImBuf *seq_render_movie_strip(const SeqRenderData *context, BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf_arr[i], false); } if (i != context->view_id) { - copy_to_ibuf_still(&localcontext, seq, nr, ibuf_arr[i]); - BKE_sequencer_cache_put(&localcontext, seq, cfra, SEQ_STRIPELEM_IBUF, ibuf_arr[i]); + BKE_sequencer_cache_put( + &localcontext, seq, cfra, SEQ_CACHE_STORE_PREPROCESSED, ibuf_arr[i], 0); } } @@ -3497,9 +3449,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, const bool is_rendering = G.is_rendering; const bool is_background = G.background; - const bool do_seq_gl = is_rendering ? 0 /* (context->scene->r.seq_flag & R_SEQ_GL_REND) */ : - (context->scene->r.seq_prev_type) != OB_RENDER; - // bool have_seq = false; /* UNUSED */ + const bool do_seq_gl = is_rendering ? 0 : (context->scene->r.seq_prev_type) != OB_RENDER; bool have_comp = false; bool use_gpencil = true; /* do we need to re-evaluate the frame after rendering? */ @@ -3515,7 +3465,9 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, scene = seq->scene; frame = (double)scene->r.sfra + (double)nr + (double)seq->anim_startofs; - // have_seq = (scene->r.scemode & R_DOSEQ) && scene->ed && scene->ed->seqbase.first); /* UNUSED */ +#if 0 /* UNUSED */ + have_seq = (scene->r.scemode & R_DOSEQ) && scene->ed && scene->ed->seqbase.first); +#endif have_comp = (scene->r.scemode & R_DOCOMP) && scene->use_nodes && scene->nodetree; /* Get view layer for the strip. */ @@ -3562,15 +3514,13 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, char err_out[256] = "unknown"; const int width = (scene->r.xsch * scene->r.size) / 100; const int height = (scene->r.ysch * scene->r.size) / 100; - const bool use_background = (scene->r.alphamode == R_ADDSKY); const char *viewname = BKE_scene_multiview_render_view_name_get(&scene->r, context->view_id); - unsigned int draw_flags = SEQ_OFSDRAW_NONE; - draw_flags |= (use_gpencil) ? SEQ_OFSDRAW_USE_GPENCIL : 0; - draw_flags |= (use_background) ? SEQ_OFSDRAW_USE_BACKGROUND : 0; - draw_flags |= (context->gpu_full_samples) ? SEQ_OFSDRAW_USE_FULL_SAMPLE : 0; - draw_flags |= (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) ? SEQ_OFSDRAW_USE_SOLID_TEX : 0; - draw_flags |= (context->scene->r.seq_flag & R_SEQ_CAMERA_DOF) ? SEQ_OFSDRAW_USE_CAMERA_DOF : 0; + unsigned int draw_flags = V3D_OFSDRAW_NONE; + draw_flags |= (use_gpencil) ? V3D_OFSDRAW_SHOW_ANNOTATION : 0; + draw_flags |= (context->scene->r.seq_flag & R_SEQ_OVERRIDE_SCENE_SETTINGS) ? + V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS : + 0; /* for old scene this can be uninitialized, * should probably be added to do_versions at some point if the functionality stays */ @@ -3585,6 +3535,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, /* set for OpenGL render (NULL when scrubbing) */ depsgraph, scene, + &context->scene->display.shading, context->scene->r.seq_prev_type, camera, width, @@ -3592,7 +3543,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, IB_rect, draw_flags, scene->r.alphamode, - context->gpu_samples, + 0, /* no aa samples */ viewname, context->gpu_offscreen, err_out); @@ -3653,8 +3604,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, } if (i != context->view_id) { - copy_to_ibuf_still(&localcontext, seq, nr, ibufs_arr[i]); - BKE_sequencer_cache_put(&localcontext, seq, cfra, SEQ_STRIPELEM_IBUF, ibufs_arr[i]); + BKE_sequencer_cache_put(&localcontext, seq, cfra, SEQ_CACHE_STORE_RAW, ibufs_arr[i], 0); } RE_ReleaseResultImage(re); @@ -3684,7 +3634,7 @@ finally: #ifdef DURIAN_CAMERA_SWITCH /* stooping to new low's in hackyness :( */ - scene->r.mode &= ~(orig_data.mode & R_NO_CAMERA_SWITCH); + scene->r.mode &= orig_data.mode | ~R_NO_CAMERA_SWITCH; #endif return ibuf; @@ -3706,6 +3656,12 @@ static ImBuf *do_render_strip_seqbase(const SeqRenderData *context, seqbase = BKE_sequence_seqbase_get(seq, &offset); if (seqbase && !BLI_listbase_is_empty(seqbase)) { + + if (seq->flag & SEQ_SCENE_STRIPS && seq->scene) { + BKE_animsys_evaluate_all_animation( + context->bmain, context->depsgraph, seq->scene, nr + offset); + } + meta_ibuf = seq_render_strip_stack(context, state, seqbase, @@ -3764,6 +3720,7 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, */ SeqRenderData local_context = *context; local_context.scene = seq->scene; + local_context.skip_cache = true; ibuf = do_render_strip_seqbase(&local_context, state, seq, nr, use_preprocess); @@ -3774,13 +3731,11 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, else { /* scene can be NULL after deletions */ ibuf = seq_render_scene_strip(context, seq, nr, cfra); + } - /* Scene strips update all animation, so we need to restore original state.*/ - BKE_animsys_evaluate_all_animation( - context->bmain, context->depsgraph, context->scene, cfra); + /* Scene strips update all animation, so we need to restore original state.*/ + BKE_animsys_evaluate_all_animation(context->bmain, context->depsgraph, context->scene, cfra); - copy_to_ibuf_still(context, seq, nr, ibuf); - } break; } @@ -3817,13 +3772,11 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, case SEQ_TYPE_IMAGE: { ibuf = seq_render_image_strip(context, seq, nr, cfra); - copy_to_ibuf_still(context, seq, nr, ibuf); break; } case SEQ_TYPE_MOVIE: { ibuf = seq_render_movie_strip(context, seq, nr, cfra); - copy_to_ibuf_still(context, seq, nr, ibuf); break; } @@ -3839,8 +3792,6 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, if (ibuf->rect_float) { BKE_sequencer_imbuf_to_sequencer_space(context->scene, ibuf, false); } - - copy_to_ibuf_still(context, seq, nr, ibuf); } break; @@ -3849,8 +3800,6 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, case SEQ_TYPE_MASK: { /* ibuf is always new */ ibuf = seq_render_mask_strip(context, seq, nr); - - copy_to_ibuf_still(context, seq, nr, ibuf); break; } } @@ -3862,6 +3811,26 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, return ibuf; } +/* Estimate time spent by the program rendering the strip */ +static clock_t seq_estimate_render_cost_begin(void) +{ + return clock(); +} + +static float seq_estimate_render_cost_end(Scene *scene, clock_t begin) +{ + clock_t end = clock(); + float time_spent = (float)(end - begin); + float time_max = (1.0f / scene->r.frs_sec) * CLOCKS_PER_SEC; + + if (time_max != 0) { + return time_spent / time_max; + } + else { + return 1; + } +} + static ImBuf *seq_render_strip(const SeqRenderData *context, SeqRenderState *state, Sequence *seq, @@ -3870,37 +3839,32 @@ static ImBuf *seq_render_strip(const SeqRenderData *context, ImBuf *ibuf = NULL; bool use_preprocess = false; bool is_proxy_image = false; - float nr = give_stripelem_index(seq, cfra); /* all effects are handled similarly with the exception of speed effect */ int type = (seq->type & SEQ_TYPE_EFFECT && seq->type != SEQ_TYPE_SPEED) ? SEQ_TYPE_EFFECT : seq->type; bool is_preprocessed = !ELEM( type, SEQ_TYPE_IMAGE, SEQ_TYPE_MOVIE, SEQ_TYPE_SCENE, SEQ_TYPE_MOVIECLIP); - ibuf = BKE_sequencer_cache_get(context, seq, cfra, SEQ_STRIPELEM_IBUF); + clock_t begin = seq_estimate_render_cost_begin(); - if (ibuf == NULL) { - ibuf = copy_from_ibuf_still(context, seq, nr); + ibuf = BKE_sequencer_cache_get(context, seq, cfra, SEQ_CACHE_STORE_PREPROCESSED); + if (ibuf == NULL) { + ibuf = BKE_sequencer_cache_get(context, seq, cfra, SEQ_CACHE_STORE_RAW); if (ibuf == NULL) { - ibuf = BKE_sequencer_preprocessed_cache_get(context, seq, cfra, SEQ_STRIPELEM_IBUF); + /* MOVIECLIPs have their own proxy management */ + if (seq->type != SEQ_TYPE_MOVIECLIP) { + ibuf = seq_proxy_fetch(context, seq, cfra); + is_proxy_image = (ibuf != NULL); + } if (ibuf == NULL) { - /* MOVIECLIPs have their own proxy management */ - if (seq->type != SEQ_TYPE_MOVIECLIP) { - ibuf = seq_proxy_fetch(context, seq, cfra); - is_proxy_image = (ibuf != NULL); - } - - if (ibuf == NULL) { - ibuf = do_render_strip_uncached(context, state, seq, cfra); - } + ibuf = do_render_strip_uncached(context, state, seq, cfra); + } - if (ibuf) { - if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_MOVIECLIP)) { - is_proxy_image = (context->preview_render_size != 100); - } - BKE_sequencer_preprocessed_cache_put(context, seq, cfra, SEQ_STRIPELEM_IBUF, ibuf); + if (ibuf) { + if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_MOVIECLIP)) { + is_proxy_image = (context->preview_render_size != 100); } } } @@ -3908,30 +3872,29 @@ static ImBuf *seq_render_strip(const SeqRenderData *context, if (ibuf) { use_preprocess = BKE_sequencer_input_have_to_preprocess(context, seq, cfra); } - } - else { - /* currently, we cache preprocessed images in SEQ_STRIPELEM_IBUF, - * but not(!) on SEQ_STRIPELEM_IBUF_ENDSTILL and ..._STARTSTILL - * so, no need in check for preprocess here - */ - } - if (ibuf == NULL) { - ibuf = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect); - sequencer_imbuf_assign_spaces(context->scene, ibuf); - } + if (ibuf == NULL) { + ibuf = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect); + sequencer_imbuf_assign_spaces(context->scene, ibuf); + } - if (context->is_proxy_render == false && - (ibuf->x != context->rectx || ibuf->y != context->recty)) { - use_preprocess = true; - } + if (context->is_proxy_render == false && + (ibuf->x != context->rectx || ibuf->y != context->recty)) { + use_preprocess = true; + } - if (use_preprocess) { - ibuf = input_preprocess(context, seq, cfra, ibuf, is_proxy_image, is_preprocessed); - } + if (use_preprocess) { + float cost = seq_estimate_render_cost_end(context->scene, begin); + BKE_sequencer_cache_put(context, seq, cfra, SEQ_CACHE_STORE_RAW, ibuf, cost); - BKE_sequencer_cache_put(context, seq, cfra, SEQ_STRIPELEM_IBUF, ibuf); + /* reset timer so we can get partial render time */ + begin = seq_estimate_render_cost_begin(); + ibuf = input_preprocess(context, seq, cfra, ibuf, is_proxy_image, is_preprocessed); + } + float cost = seq_estimate_render_cost_end(context->scene, begin); + BKE_sequencer_cache_put(context, seq, cfra, SEQ_CACHE_STORE_PREPROCESSED, ibuf, cost); + } return ibuf; } @@ -4012,6 +3975,7 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, int count; int i; ImBuf *out = NULL; + clock_t begin; count = get_shown_sequences(seqbasep, cfra, chanshown, (Sequence **)&seq_arr); @@ -4019,73 +3983,11 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, return NULL; } -#if 0 /* commentind since this breaks keyframing, since it resets the value on draw */ - if (scene->r.cfra != cfra) { - /* XXX for prefetch and overlay offset!..., very bad!!! */ - AnimData *adt = BKE_animdata_from_id(&scene->id); - BKE_animsys_evaluate_animdata(scene, &scene->id, adt, cfra, ADT_RECALC_ANIM); - } -#endif - - out = BKE_sequencer_cache_get(context, seq_arr[count - 1], cfra, SEQ_STRIPELEM_IBUF_COMP); - - if (out) { - return out; - } - - if (count == 1) { - Sequence *seq = seq_arr[0]; - - /* Some of the blend modes are unclear how to apply with only single input, - * or some of them will just produce an empty result.. - */ - if (ELEM(seq->blend_mode, SEQ_BLEND_REPLACE, SEQ_TYPE_CROSS, SEQ_TYPE_ALPHAOVER)) { - int early_out; - if (seq->blend_mode == SEQ_BLEND_REPLACE) { - early_out = EARLY_NO_INPUT; - } - else { - early_out = seq_get_early_out_for_blend_mode(seq); - } - - if (ELEM(early_out, EARLY_NO_INPUT, EARLY_USE_INPUT_2)) { - out = seq_render_strip(context, state, seq, cfra); - } - else if (early_out == EARLY_USE_INPUT_1) { - out = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect); - } - else { - out = seq_render_strip(context, state, seq, cfra); - - if (early_out == EARLY_DO_EFFECT) { - ImBuf *ibuf1 = IMB_allocImBuf( - context->rectx, context->recty, 32, out->rect_float ? IB_rectfloat : IB_rect); - ImBuf *ibuf2 = out; - - out = seq_render_strip_stack_apply_effect(context, seq, cfra, ibuf1, ibuf2); - if (out) { - IMB_metadata_copy(out, ibuf2); - } - - IMB_freeImBuf(ibuf1); - IMB_freeImBuf(ibuf2); - } - } - } - else { - out = seq_render_strip(context, state, seq, cfra); - } - - BKE_sequencer_cache_put(context, seq, cfra, SEQ_STRIPELEM_IBUF_COMP, out); - - return out; - } - for (i = count - 1; i >= 0; i--) { int early_out; Sequence *seq = seq_arr[i]; - out = BKE_sequencer_cache_get(context, seq, cfra, SEQ_STRIPELEM_IBUF_COMP); + out = BKE_sequencer_cache_get(context, seq, cfra, SEQ_CACHE_STORE_COMPOSITE); if (out) { break; @@ -4109,15 +4011,19 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, break; case EARLY_DO_EFFECT: if (i == 0) { + begin = seq_estimate_render_cost_begin(); + ImBuf *ibuf1 = IMB_allocImBuf(context->rectx, context->recty, 32, IB_rect); ImBuf *ibuf2 = seq_render_strip(context, state, seq, cfra); out = seq_render_strip_stack_apply_effect(context, seq, cfra, ibuf1, ibuf2); + float cost = seq_estimate_render_cost_end(context->scene, begin); + BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_CACHE_STORE_COMPOSITE, out, cost); + IMB_freeImBuf(ibuf1); IMB_freeImBuf(ibuf2); } - break; } if (out) { @@ -4125,11 +4031,9 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, } } - BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_STRIPELEM_IBUF_COMP, out); - i++; - for (; i < count; i++) { + begin = seq_estimate_render_cost_begin(); Sequence *seq = seq_arr[i]; if (seq_get_early_out_for_blend_mode(seq) == EARLY_DO_EFFECT) { @@ -4142,7 +4046,8 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, IMB_freeImBuf(ibuf2); } - BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_STRIPELEM_IBUF_COMP, out); + float cost = seq_estimate_render_cost_end(context->scene, begin); + BKE_sequencer_cache_put(context, seq_arr[i], cfra, SEQ_CACHE_STORE_COMPOSITE, out, cost); } return out; @@ -4155,7 +4060,8 @@ static ImBuf *seq_render_strip_stack(const SeqRenderData *context, ImBuf *BKE_sequencer_give_ibuf(const SeqRenderData *context, float cfra, int chanshown) { - Editing *ed = BKE_sequencer_editing_get(context->scene, false); + Scene *scene = context->scene; + Editing *ed = BKE_sequencer_editing_get(scene, false); ListBase *seqbasep; if (ed == NULL) { @@ -4173,8 +4079,29 @@ ImBuf *BKE_sequencer_give_ibuf(const SeqRenderData *context, float cfra, int cha SeqRenderState state; sequencer_state_init(&state); + ImBuf *out = NULL; + Sequence *seq_arr[MAXSEQ + 1]; + int count; - return seq_render_strip_stack(context, &state, seqbasep, cfra, chanshown); + count = get_shown_sequences(seqbasep, cfra, chanshown, seq_arr); + + if (count) { + out = BKE_sequencer_cache_get(context, seq_arr[count - 1], cfra, SEQ_CACHE_STORE_FINAL_OUT); + } + + BKE_sequencer_cache_free_temp_cache(context->scene, 0, cfra); + + clock_t begin = seq_estimate_render_cost_begin(); + float cost = 0; + + if (count && !out) { + out = seq_render_strip_stack(context, &state, seqbasep, cfra, chanshown); + cost = seq_estimate_render_cost_end(context->scene, begin); + BKE_sequencer_cache_put_if_possible( + context, seq_arr[count - 1], cfra, SEQ_CACHE_STORE_FINAL_OUT, out, cost); + } + + return out; } ImBuf *BKE_sequencer_give_ibuf_seqbase(const SeqRenderData *context, @@ -4193,7 +4120,9 @@ ImBuf *BKE_sequencer_give_ibuf_direct(const SeqRenderData *context, float cfra, SeqRenderState state; sequencer_state_init(&state); - return seq_render_strip(context, &state, seq, cfra); + ImBuf *ibuf = seq_render_strip(context, &state, seq, cfra); + + return ibuf; } /* *********************** threading api ******************* */ @@ -4206,8 +4135,8 @@ static pthread_mutex_t queue_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t wakeup_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t wakeup_cond = PTHREAD_COND_INITIALIZER; -//static pthread_mutex_t prefetch_ready_lock = PTHREAD_MUTEX_INITIALIZER; -//static pthread_cond_t prefetch_ready_cond = PTHREAD_COND_INITIALIZER; +// static pthread_mutex_t prefetch_ready_lock = PTHREAD_MUTEX_INITIALIZER; +// static pthread_cond_t prefetch_ready_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t frame_done_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t frame_done_cond = PTHREAD_COND_INITIALIZER; @@ -4365,7 +4294,7 @@ bool BKE_sequence_check_depend(Sequence *seq, Sequence *cur) return true; } -static void sequence_do_invalidate_dependent(Sequence *seq, ListBase *seqbase) +static void sequence_do_invalidate_dependent(Scene *scene, Sequence *seq, ListBase *seqbase) { Sequence *cur; @@ -4375,12 +4304,11 @@ static void sequence_do_invalidate_dependent(Sequence *seq, ListBase *seqbase) } if (BKE_sequence_check_depend(seq, cur)) { - BKE_sequencer_cache_cleanup_sequence(cur); - BKE_sequencer_preprocessed_cache_cleanup_sequence(cur); + BKE_sequencer_cache_cleanup_sequence(scene, cur); } if (cur->seqbase.first) { - sequence_do_invalidate_dependent(seq, &cur->seqbase); + sequence_do_invalidate_dependent(scene, seq, &cur->seqbase); } } } @@ -4388,7 +4316,7 @@ static void sequence_do_invalidate_dependent(Sequence *seq, ListBase *seqbase) static void sequence_invalidate_cache(Scene *scene, Sequence *seq, bool invalidate_self, - bool invalidate_preprocess) + bool UNUSED(invalidate_preprocess)) { Editing *ed = scene->ed; @@ -4399,7 +4327,7 @@ static void sequence_invalidate_cache(Scene *scene, * re-open the animation. */ BKE_sequence_free_anim(seq); - BKE_sequencer_cache_cleanup_sequence(seq); + BKE_sequencer_cache_cleanup_sequence(scene, seq); } /* if invalidation is invoked from sequence free routine, effectdata would be NULL here */ @@ -4407,16 +4335,12 @@ static void sequence_invalidate_cache(Scene *scene, BKE_sequence_effect_speed_rebuild_map(scene, seq, true); } - if (invalidate_preprocess) { - BKE_sequencer_preprocessed_cache_cleanup_sequence(seq); - } - /* invalidate cache for all dependent sequences */ /* NOTE: can not use SEQ_BEGIN/SEQ_END here because that macro will change sequence's depth, * which makes transformation routines work incorrect */ - sequence_do_invalidate_dependent(seq, &ed->seqbase); + sequence_do_invalidate_dependent(scene, seq, &ed->seqbase); } void BKE_sequence_invalidate_cache(Scene *scene, Sequence *seq) @@ -4438,7 +4362,7 @@ void BKE_sequencer_free_imbuf(Scene *scene, ListBase *seqbase, bool for_render) { Sequence *seq; - BKE_sequencer_cache_cleanup(); + BKE_sequencer_cache_cleanup(scene); for (seq = seqbase->first; seq; seq = seq->next) { if (for_render && CFRA >= seq->startdisp && CFRA <= seq->enddisp) { @@ -4723,8 +4647,8 @@ bool BKE_sequence_tx_test(Sequence *seq) /** * Return \a true if given \a seq needs a complete cleanup of its cache when it is transformed. * - * Some (effect) strip types need a complete recache of themselves when they are transformed, because - * they do not 'contain' anything and do not have any explicit relations to other strips. + * Some (effect) strip types need a complete recache of themselves when they are transformed, + * because they do not 'contain' anything and do not have any explicit relations to other strips. */ bool BKE_sequence_tx_fullupdate_test(Sequence *seq) { @@ -5446,6 +5370,7 @@ Sequence *BKE_sequence_alloc(ListBase *lb, int cfra, int machine) seq->scene_sound = NULL; seq->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Sequence Stereo Format"); + seq->cache_flag = SEQ_CACHE_ALL_TYPES; return seq; } @@ -5529,7 +5454,7 @@ Sequence *BKE_sequencer_add_image_strip(bContext *C, ListBase *seqbasep, SeqLoad seq = BKE_sequence_alloc(seqbasep, seq_load->start_frame, seq_load->channel); seq->type = SEQ_TYPE_IMAGE; - seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ + seq->blend_mode = SEQ_TYPE_ALPHAOVER; /* basic defaults */ seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); @@ -5563,17 +5488,18 @@ Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoad Strip *strip; StripElem *se; - AUD_SoundInfo info; - sound = BKE_sound_new_file(bmain, seq_load->path); /* handles relative paths */ + /* Load the original sound, so we can access number of channels and length information. + * We free the sound handle on the original bSound datablock before existing this function, it is + * to be allocated on an evaluated version after this. */ + BKE_sound_load_audio(bmain, sound); + AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); if (sound->playback_handle == NULL) { BKE_id_free(bmain, sound); return NULL; } - info = AUD_getInfo(sound->playback_handle); - if (info.specs.channels == AUD_CHANNELS_INVALID) { BKE_id_free(bmain, sound); return NULL; @@ -5588,7 +5514,8 @@ Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoad /* basic defaults */ seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); - /* We add a very small negative offset here, because ceil(132.0) == 133.0, not nice with videos, see T47135. */ + /* We add a very small negative offset here, because + * ceil(132.0) == 133.0, not nice with videos, see T47135. */ seq->len = (int)ceil((double)info.length * FPS - 1e-4); strip->us = 1; @@ -5597,8 +5524,7 @@ Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoad BLI_split_dirfile(seq_load->path, strip->dir, se->name, sizeof(strip->dir), sizeof(se->name)); - seq->scene_sound = BKE_sound_add_scene_sound( - scene, seq, seq_load->start_frame, seq_load->start_frame + seq->len, 0); + seq->scene_sound = NULL; BKE_sequence_calc_disp(scene, seq); @@ -5607,6 +5533,11 @@ Sequence *BKE_sequencer_add_sound_strip(bContext *C, ListBase *seqbasep, SeqLoad seq_load_apply(bmain, scene, seq, seq_load); + BKE_sound_free_audio(sound); + + /* TODO(sergey): Shall we tag here or in the oeprator? */ + DEG_relations_tag_update(bmain); + return seq; } #else // WITH_AUDASPACE @@ -5693,7 +5624,7 @@ Sequence *BKE_sequencer_add_movie_strip(bContext *C, ListBase *seqbasep, SeqLoad seq->flag |= seq_load->flag & SEQ_USE_VIEWS; seq->type = SEQ_TYPE_MOVIE; - seq->blend_mode = SEQ_TYPE_CROSS; /* so alpha adjustment fade to the strip below */ + seq->blend_mode = SEQ_TYPE_ALPHAOVER; for (i = 0; i < totfiles; i++) { if (anim_arr[i]) { @@ -5818,10 +5749,7 @@ static Sequence *seq_dupli(const Scene *scene_src, } else if (seq->type == SEQ_TYPE_SOUND_RAM) { seqn->strip->stripdata = MEM_dupallocN(seq->strip->stripdata); - if (seq->scene_sound) { - seqn->scene_sound = BKE_sound_add_scene_sound_defaults(scene_dst, seqn); - } - + seqn->scene_sound = NULL; if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { id_us_plus((ID *)seqn->sound); } @@ -5846,9 +5774,9 @@ static Sequence *seq_dupli(const Scene *scene_src, /* When using SEQ_DUPE_UNIQUE_NAME, it is mandatory to add new sequences in relevant container * (scene or meta's one), *before* checking for unique names. Otherwise the meta's list is empty * and hence we miss all seqs in that meta that have already been duplicated (see T55668). - * Note that unique name check itslef could be done at a later step in calling code, once all seqs - * have bee duplicated (that was first, simpler solution), but then handling of animation data will - * be broken (see T60194). */ + * Note that unique name check itslef could be done at a later step in calling code, once all + * seqs have bee duplicated (that was first, simpler solution), but then handling of animation + * data will be broken (see T60194). */ if (new_seq_list != NULL) { BLI_addtail(new_seq_list, seqn); } @@ -6000,7 +5928,8 @@ int BKE_sequencer_find_next_prev_edit(Scene *scene, int dist, best_dist, best_frame = cfra; int seq_frames[2], seq_frames_tot; - /* in case where both is passed, frame just finds the nearest end while frame_left the nearest start */ + /* In case where both is passed, + * frame just finds the nearest end while frame_left the nearest start. */ best_dist = MAXFRAME * 2; @@ -6073,15 +6002,12 @@ static void sequencer_all_free_anim_ibufs(ListBase *seqbase, int cfra) } } -void BKE_sequencer_all_free_anim_ibufs(Main *bmain, int cfra) +void BKE_sequencer_all_free_anim_ibufs(Scene *scene, int cfra) { - BKE_sequencer_cache_cleanup(); - for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) { - Editing *ed = BKE_sequencer_editing_get(scene, false); - if (ed == NULL) { - /* Ignore scenes without sequencer. */ - continue; - } - sequencer_all_free_anim_ibufs(&ed->seqbase, cfra); + Editing *ed = BKE_sequencer_editing_get(scene, false); + if (ed == NULL) { + return; } + sequencer_all_free_anim_ibufs(&ed->seqbase, cfra); + BKE_sequencer_cache_cleanup(scene); } diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 3cd2131c22b..6a72b46a8f2 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -69,25 +69,25 @@ #define OUT_OF_MEMORY() ((void)printf("Shrinkwrap: Out of memory\n")) typedef struct ShrinkwrapCalcData { - ShrinkwrapModifierData *smd; //shrinkwrap modifier data + ShrinkwrapModifierData *smd; // shrinkwrap modifier data - struct Object *ob; //object we are applying shrinkwrap to + struct Object *ob; // object we are applying shrinkwrap to - struct MVert *vert; //Array of verts being projected (to fetch normals or other data) - float (*vertexCos)[3]; //vertexs being shrinkwraped + struct MVert *vert; // Array of verts being projected (to fetch normals or other data) + float (*vertexCos)[3]; // vertexs being shrinkwraped int numVerts; - struct MDeformVert *dvert; //Pointer to mdeform array - int vgroup; //Vertex group num + struct MDeformVert *dvert; // Pointer to mdeform array + int vgroup; // Vertex group num bool invert_vgroup; /* invert vertex group influence */ - struct Mesh *target; //mesh we are shrinking to - struct SpaceTransform local2target; //transform to move between local and target space + struct Mesh *target; // mesh we are shrinking to + struct SpaceTransform local2target; // transform to move between local and target space struct ShrinkwrapTreeData *tree; // mesh BVH tree data struct Object *aux_target; - float keepDist; //Distance to keep above target surface (units are in local space) + float keepDist; // Distance to keep above target surface (units are in local space) } ShrinkwrapCalcData; typedef struct ShrinkwrapCalcCBData { @@ -375,8 +375,8 @@ static void shrinkwrap_calc_nearest_vertex_cb_ex(void *__restrict userdata, /* Use local proximity heuristics (to reduce the nearest search) * - * If we already had an hit before.. we assume this vertex is going to have a close hit to that other vertex - * so we can initiate the "nearest.dist" with the expected value to that last hit. + * If we already had an hit before.. we assume this vertex is going to have a close hit to that + * other vertex so we can initiate the "nearest.dist" with the expected value to that last hit. * This will lead in pruning of the search tree. */ if (nearest->index != -1) { nearest->dist_sq = len_squared_v3v3(tmp_co, nearest->co); @@ -538,8 +538,9 @@ static void shrinkwrap_calc_normal_projection_cb_ex(void *__restrict userdata, if (calc->vert != NULL && calc->smd->projAxis == MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) { /* calc->vert contains verts from evaluated mesh. */ - /* These coordinates are deformed by vertexCos only for normal projection (to get correct normals) */ - /* for other cases calc->verts contains undeformed coordinates and vertexCos should be used */ + /* These coordinates are deformed by vertexCos only for normal projection + * (to get correct normals) for other cases calc->verts contains undeformed coordinates and + * vertexCos should be used */ copy_v3_v3(tmp_co, calc->vert[i].co); normal_short_to_float_v3(tmp_no, calc->vert[i].no); } @@ -549,8 +550,9 @@ static void shrinkwrap_calc_normal_projection_cb_ex(void *__restrict userdata, } hit->index = -1; - hit->dist = - BVH_RAYCAST_DIST_MAX; /* TODO: we should use FLT_MAX here, but sweepsphere code isn't prepared for that */ + + /* TODO: we should use FLT_MAX here, but sweepsphere code isn't prepared for that */ + hit->dist = BVH_RAYCAST_DIST_MAX; bool is_aux = false; @@ -938,7 +940,8 @@ static bool update_hit(BVHTreeNearest *nearest, return false; } -/* Target projection on a non-manifold boundary edge - treats it like an infinitely thin cylinder. */ +/* Target projection on a non-manifold boundary edge - + * treats it like an infinitely thin cylinder. */ static void target_project_edge(const ShrinkwrapTreeData *tree, int index, const float co[3], @@ -1142,8 +1145,8 @@ static void shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdat /* Use local proximity heuristics (to reduce the nearest search) * - * If we already had an hit before.. we assume this vertex is going to have a close hit to that other vertex - * so we can initiate the "nearest.dist" with the expected value to that last hit. + * If we already had an hit before.. we assume this vertex is going to have a close hit to that + * other vertex so we can initiate the "nearest.dist" with the expected value to that last hit. * This will lead in pruning of the search tree. */ if (nearest->index != -1) { if (calc->smd->shrinkType == MOD_SHRINKWRAP_TARGET_PROJECT) { diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index a815aaefb29..d6858e2d4d2 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -119,7 +119,7 @@ struct WTURBULENCE *smoke_turbulence_init(int *UNUSED(res), { return NULL; } -//struct FLUID_3D *smoke_init(int *UNUSED(res), float *UNUSED(dx), float *UNUSED(dtdef), int UNUSED(use_heat), int UNUSED(use_fire), int UNUSED(use_colors)) { return NULL; } + void smoke_free(struct FLUID_3D *UNUSED(fluid)) { } @@ -914,7 +914,8 @@ static void obstacles_from_mesh(Object *coll_ob, // DG TODO // if (scs->type > SM_COLL_STATIC) - // if line above is used, the code is in trouble if the object moves but is declared as "does not move" + // if line above is used, the code is in trouble if the object moves + // but is declared as "does not move". { vert_vel = MEM_callocN(sizeof(float) * numverts * 3, "smoke_obs_velocity"); @@ -1680,7 +1681,8 @@ static void sample_mesh(SmokeFlowSettings *sfs, interp_v3_v3v3v3(hit_normal, n1, n2, n3, weights); normalize_v3(hit_normal); /* apply normal directional and random velocity - * - TODO: random disabled for now since it doesn't really work well as pressure calc smoothens it out... */ + * - TODO: random disabled for now since it doesn't really work well + * as pressure calc smoothens it out. */ velocity_map[index * 3] += hit_normal[0] * sfs->vel_normal * 0.25f; velocity_map[index * 3 + 1] += hit_normal[1] * sfs->vel_normal * 0.25f; velocity_map[index * 3 + 2] += hit_normal[2] * sfs->vel_normal * 0.25f; @@ -2674,7 +2676,7 @@ static void update_flowsfluids( float *velocity_x = smoke_get_velocity_x(sds->fluid); float *velocity_y = smoke_get_velocity_y(sds->fluid); float *velocity_z = smoke_get_velocity_z(sds->fluid); - //unsigned char *obstacle = smoke_get_obstacle(sds->fluid); + // unsigned char *obstacle = smoke_get_obstacle(sds->fluid); // DG TODO UNUSED unsigned char *obstacleAnim = smoke_get_obstacle_anim(sds->fluid); int bigres[3]; float *velocity_map = em->velocity; @@ -2734,7 +2736,8 @@ static void update_flowsfluids( /* loop through high res blocks if high res enabled */ if (bigdensity) { - // neighbor cell emission densities (for high resolution smoke smooth interpolation) + /* Neighbor cell emission densities + * (for high resolution smoke smooth interpolation). */ float c000, c001, c010, c011, c100, c101, c110, c111; smoke_turbulence_get_res(sds->wt, bigres); @@ -3034,12 +3037,9 @@ static void step(Depsgraph *depsgraph, update_obstacles(depsgraph, ob, sds, dtSubdiv, substep, totalSubsteps); if (sds->total_cells > 1) { - update_effectors( - depsgraph, - scene, - ob, - sds, - dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt + // DG TODO? problem --> uses forces instead of velocity, + // need to check how they need to be changed with variable dt. + update_effectors(depsgraph, scene, ob, sds, dtSubdiv); smoke_step(sds->fluid, gravity, dtSubdiv); } } diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 6903021e0cf..2a3145bee6c 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -190,8 +190,8 @@ static float sb_time_scale(Object *ob) /* hrms .. this could be IPO as well :) * estimated range [0.001 sluggish slug - 100.0 very fast (i hope ODE solver can handle that)] * 1 approx = a unit 1 pendulum at g = 9.8 [earth conditions] has period 65 frames - * theory would give a 50 frames period .. so there must be something inaccurate .. looking for that (BM) - */ + * theory would give a 50 frames period .. so there must be something inaccurate .. + * looking for that (BM). */ } return (1.0f); /* @@ -599,7 +599,7 @@ static void add_mesh_quad_diag_springs(Object *ob) if (ob->soft) { int nofquads; - //float s_shear = ob->soft->shearstiff*ob->soft->shearstiff; + // float s_shear = ob->soft->shearstiff*ob->soft->shearstiff; nofquads = count_mesh_quads(me); if (nofquads) { @@ -1459,7 +1459,7 @@ static void _scan_for_ext_spring_forces( sb->bpoint[bs->v1].pos, sb->bpoint[bs->v2].pos, &damp, feedback, ob, timenow)) { add_v3_v3(bs->ext_force, feedback); bs->flag |= BSF_INTERSECT; - //bs->cf=damp; + // bs->cf=damp; bs->cf = sb->choke * 0.01f; } } @@ -1528,8 +1528,10 @@ static void sb_sfesf_threads_run(struct Depsgraph *depsgraph, ListBase threads; SB_thread_context *sb_threads; int i, totthread, left, dec; - int lowsprings = - 100; /* wild guess .. may increase with better thread management 'above' or even be UI option sb->spawn_cf_threads_nopts */ + + /* wild guess .. may increase with better thread management 'above' + * or even be UI option sb->spawn_cf_threads_nopts */ + int lowsprings = 100; ListBase *effectors = BKE_effectors_create(depsgraph, ob, NULL, ob->soft->effector_weights); @@ -1823,7 +1825,10 @@ static int sb_deflect_face(Object *ob, copy_v3_v3(s_actpos, actpos); deflected = sb_detect_vertex_collisionCached( s_actpos, facenormal, cf, force, ob, time, vel, intrusion); - //deflected= sb_detect_vertex_collisionCachedEx(s_actpos, facenormal, cf, force, ob, time, vel, intrusion); +#if 0 + deflected = sb_detect_vertex_collisionCachedEx( + s_actpos, facenormal, cf, force, ob, time, vel, intrusion); +#endif return (deflected); } @@ -2006,7 +2011,8 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, float compare; float bstune = sb->ballstiff; - /* running in a slice we must not assume anything done with obp neither alter the data of obp */ + /* Running in a slice we must not assume anything done with obp + * neither alter the data of obp. */ for (c = sb->totpoint, obp = sb->bpoint; c > 0; c--, obp++) { compare = (obp->colball + bp->colball); sub_v3_v3v3(def, bp->pos, obp->pos); @@ -2196,8 +2202,10 @@ static void sb_cf_threads_run(Scene *scene, ListBase threads; SB_thread_context *sb_threads; int i, totthread, left, dec; - int lowpoints = - 100; /* wild guess .. may increase with better thread management 'above' or even be UI option sb->spawn_cf_threads_nopts */ + + /* wild guess .. may increase with better thread management 'above' + * or even be UI option sb->spawn_cf_threads_nopts. */ + int lowpoints = 100; /* figure the number of threads while preventing pretty pointless threading overhead */ totthread = BKE_scene_num_threads(scene); @@ -2266,7 +2274,9 @@ static void softbody_calc_forces( /* check conditions for various options */ do_deflector = query_external_colliders(depsgraph, sb->collision_group); - /* do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); */ /* UNUSED */ +#if 0 + do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); +#endif do_springcollision = do_deflector && (ob->softflag & OB_SB_EDGES) && (ob->softflag & OB_SB_EDGECOLL); do_aero = ((sb->aeroedge) && (ob->softflag & OB_SB_EDGES)); @@ -2333,7 +2343,7 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * #endif for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) { - /* now we have individual masses */ + /* Now we have individual masses. */ /* claim a minimum mass for vertex */ if (_final_mass(ob, bp) > 0.009999f) { timeovermass = forcetime / _final_mass(ob, bp); @@ -2348,10 +2358,20 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * copy_v3_v3(dx, bp->vec); } - /* so here is (v)' = a(cceleration) = sum(F_springs)/m + gravitation + some friction forces + more forces*/ - /* the ( ... )' operator denotes derivate respective time */ - /* the euler step for velocity then becomes */ - /* v(t + dt) = v(t) + a(t) * dt */ + /** + * So here is: + * <pre> + * (v)' = a(cceleration) = + * sum(F_springs)/m + gravitation + some friction forces + more forces. + * </pre> + * + * The ( ... )' operator denotes derivate respective time. + * + * The euler step for velocity then becomes: + * <pre> + * v(t + dt) = v(t) + a(t) * dt + * </pre> + */ mul_v3_fl(bp->force, timeovermass); /* individual mass of node here */ /* some nasty if's to have heun in here too */ copy_v3_v3(dv, bp->force); @@ -2446,7 +2466,7 @@ static void softbody_apply_forces(Object *ob, float forcetime, int mode, float * else { *err = maxerrpos; } - //printf("EP %f EV %f\n", maxerrpos, maxerrvel); + // printf("EP %f EV %f\n", maxerrpos, maxerrvel); if (fuzzy) { *err /= sb->fuzzyness; } @@ -2970,10 +2990,15 @@ static void curve_surf_to_softbody(Scene *scene, Object *ob) for (nu = cu->nurb.first; nu; nu = nu->next) { if (nu->bezt) { - /* bezier case ; this is nicly said naive; who ever wrote this part, it was not me (JOW) :) */ - /* a: never ever make tangent handles (sub) and or (ob)ject to collision */ - /* b: rather calculate them using some C2 (C2= continuous in second derivate -> no jump in bending ) condition */ - /* not too hard to do, but needs some more code to care for; some one may want look at it JOW 2010/06/12*/ + /* Bezier case; this is nicly said naive; who ever wrote this part, + * it was not me (JOW) :). + * + * a: never ever make tangent handles (sub) and or (ob)ject to collision. + * b: rather calculate them using some C2 + * (C2= continuous in second derivate -> no jump in bending ) condition. + * + * Not too hard to do, but needs some more code to care for; + * some one may want look at it JOW 2010/06/12. */ for (bezt = nu->bezt, a = 0; a < nu->pntsu; a++, bezt++, bp += 3, curindex += 3) { if (setgoal) { bp->goal *= bezt->weight; @@ -3158,7 +3183,7 @@ void sbFreeSimulation(SoftBody *sb) /* makes totally fresh start situation */ void sbObjectToSoftbody(Object *ob) { - //ob->softflag |= OB_SB_REDO; + // ob->softflag |= OB_SB_REDO; free_softbody_intern(ob->soft); } @@ -3213,10 +3238,9 @@ static void softbody_update_positions(Object *ob, * that is: * a precise position vector denoting the motion of the center of mass * give a rotation/scale matrix using averaging method, that's why estimate and not calculate - * see: this is kind of reverse engineering: having to states of a point cloud and recover what happened - * our advantage here we know the identity of the vertex - * there are others methods giving other results. - * lloc, lrot, lscale are allowed to be NULL, just in case you don't need it. + * see: this is kind of reverse engineering: having to states of a point cloud and recover what + * happened our advantage here we know the identity of the vertex there are others methods giving + * other results. lloc, lrot, lscale are allowed to be NULL, just in case you don't need it. * should be pretty useful for pythoneers :) * not! velocity .. 2nd order stuff * vcloud_estimate_transform_v3 see @@ -3248,7 +3272,7 @@ void SB_estimate_transform(Object *ob, float lloc[3], float lrot[3][3], float ls } vcloud_estimate_transform_v3(sb->totpoint, opos, NULL, rpos, NULL, com, rcom, lrot, lscale); - //sub_v3_v3(com, rcom); + // sub_v3_v3(com, rcom); if (lloc) { copy_v3_v3(lloc, com); } @@ -3397,7 +3421,7 @@ static void softbody_step( if (forcetime > forcetimemin) { forcetime = max_ff(forcetime / 2.0f, forcetimemin); softbody_restore_prev_step(ob); - //printf("down, "); + // printf("down, "); } else { timedone += forcetime; @@ -3407,7 +3431,8 @@ static void softbody_step( float newtime = forcetime * 1.1f; /* hope for 1.1 times better conditions in next step */ if (sb->scratch->flag & SBF_DOFUZZY) { - //if (err > SoftHeunTol/(2.0f*sb->fuzzyness)) { /* stay with this stepsize unless err really small */ + ///* stay with this stepsize unless err really small */ + // if (err > SoftHeunTol/(2.0f*sb->fuzzyness)) { newtime = forcetime; //} } @@ -3418,7 +3443,7 @@ static void softbody_step( } timedone += forcetime; newtime = min_ff(forcetimemax, max_ff(newtime, forcetimemin)); - //if (newtime > forcetime) printf("up, "); + // if (newtime > forcetime) printf("up, "); if (forcetime > 0.0f) { forcetime = min_ff(dtime - timedone, newtime); } @@ -3451,14 +3476,14 @@ static void softbody_step( } else if (sb->solver_ID == 2) { /* do semi "fake" implicit euler */ - //removed + // removed } /*SOLVER SELECT*/ else if (sb->solver_ID == 4) { /* do semi "fake" implicit euler */ } /*SOLVER SELECT*/ else if (sb->solver_ID == 3) { /* do "stupid" semi "fake" implicit euler */ - //removed + // removed } /*SOLVER SELECT*/ else { @@ -3591,9 +3616,9 @@ void sbObjectStep(struct Depsgraph *depsgraph, else if (cache_result == PTCACHE_READ_OLD) { /* pass */ } - else if (/*ob->id.lib || */ ( - cache->flag & - PTCACHE_BAKED)) { /* "library linking & pointcaches" has to be solved properly at some point */ + else if (/*ob->id.lib || */ + /* "library linking & pointcaches" has to be solved properly at some point */ + (cache->flag & PTCACHE_BAKED)) { /* if baked and nothing in cache, do nothing */ if (can_write_cache) { BKE_ptcache_invalidate(cache); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 857d59d9e5c..9ccb90b5cdc 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -38,6 +38,7 @@ #include "DNA_screen_types.h" #include "DNA_sound_types.h" #include "DNA_speaker_types.h" +#include "DNA_windowmanager_types.h" #ifdef WITH_AUDASPACE # include <AUD_Sound.h> @@ -55,13 +56,38 @@ #include "BKE_sequencer.h" #include "BKE_scene.h" +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + #ifdef WITH_AUDASPACE /* evil globals ;-) */ static int sound_cfra; static char **audio_device_names = NULL; #endif -bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath) +BLI_INLINE void sound_verify_evaluated_id(ID *id) +{ + UNUSED_VARS_NDEBUG(id); + /* This is a bit tricky and not quite reliable, but good enough check. + * + * We don't want audio system handles to be allocated on amn original datablocks, and only want + * them to be allocated on a datablocks which are result of dependency graph evaluation. + * + * Datablocks which are covered by a copy-on-write system of dependency graph will have + * LIB_TAG_COPIED_ON_WRITE tag set on them. But if some of datablocks during its evaluation + * decides to re-allocate it's nested one (for example, object evaluation could re-allocate mesh + * when evaluating modifier stack). Such datablocks will have LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT + * tag set on them. + * + * Additionally, we also allow datablocks outside of main database. Those can not be "original" + * and could be used as a temporary evaluated result during operations like baking. + * + * NOTE: We conder ID evaluated if ANY of those flags is set. We do NOT require ALL of them. */ + BLI_assert(id->tag & + (LIB_TAG_COPIED_ON_WRITE | LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT | LIB_TAG_NO_MAIN)); +} + +bSound *BKE_sound_new_file(Main *bmain, const char *filepath) { bSound *sound; const char *path; @@ -77,12 +103,15 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath) BLI_strncpy(sound->name, filepath, FILE_MAX); /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */ - BKE_sound_load(bmain, sound); + sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); + BLI_spin_init(sound->spinlock); + + BKE_sound_reset_runtime(sound); return sound; } -bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists) +bSound *BKE_sound_new_file_exists_ex(Main *bmain, const char *filepath, bool *r_exists) { bSound *sound; char str[FILE_MAX], strtest[FILE_MAX]; @@ -110,7 +139,7 @@ bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, b return BKE_sound_new_file(bmain, filepath); } -bSound *BKE_sound_new_file_exists(struct Main *bmain, const char *filepath) +bSound *BKE_sound_new_file_exists(Main *bmain, const char *filepath) { return BKE_sound_new_file_exists_ex(bmain, filepath, NULL); } @@ -125,6 +154,18 @@ void BKE_sound_free(bSound *sound) sound->packedfile = NULL; } + BKE_sound_free_audio(sound); + BKE_sound_free_waveform(sound); + + if (sound->spinlock) { + BLI_spin_end(sound->spinlock); + MEM_freeN(sound->spinlock); + sound->spinlock = NULL; + } +} + +void BKE_sound_free_audio(bSound *sound) +{ #ifdef WITH_AUDASPACE if (sound->handle) { AUD_Sound_free(sound->handle); @@ -136,26 +177,22 @@ void BKE_sound_free(bSound *sound) AUD_Sound_free(sound->cache); sound->cache = NULL; } - - BKE_sound_free_waveform(sound); - +#else + UNUSED_VARS(sound); #endif /* WITH_AUDASPACE */ - if (sound->spinlock) { - BLI_spin_end(sound->spinlock); - MEM_freeN(sound->spinlock); - sound->spinlock = NULL; - } } /** - * Only copy internal data of Sound ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Sound ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * * \param flag: Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). */ -void BKE_sound_copy_data(Main *bmain, +void BKE_sound_copy_data(Main *UNUSED(bmain), bSound *sound_dst, const bSound *UNUSED(sound_src), const int UNUSED(flag)) @@ -164,8 +201,8 @@ void BKE_sound_copy_data(Main *bmain, sound_dst->cache = NULL; sound_dst->waveform = NULL; sound_dst->playback_handle = NULL; - sound_dst->spinlock = - NULL; /* Think this is OK? Otherwise, easy to create new spinlock here... */ + sound_dst->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock"); + BLI_spin_init(sound_dst->spinlock); /* Just to be sure, should not have any value actually after reading time. */ sound_dst->ipo = NULL; @@ -175,8 +212,7 @@ void BKE_sound_copy_data(Main *bmain, sound_dst->packedfile = dupPackedFile(sound_dst->packedfile); } - /* Initialize whole runtime (audaspace) stuff. */ - BKE_sound_load(bmain, sound_dst); + BKE_sound_reset_runtime(sound_dst); } void BKE_sound_make_local(Main *bmain, bSound *sound, const bool lib_local) @@ -189,31 +225,15 @@ void BKE_sound_make_local(Main *bmain, bSound *sound, const bool lib_local) static const char *force_device = NULL; # ifdef WITH_JACK +static SoundJackSyncCallback sound_jack_sync_callback = NULL; + static void sound_sync_callback(void *data, int mode, float time) { - // Ugly: Blender doesn't like it when the animation is played back during rendering - if (G.is_rendering) { + if (sound_jack_sync_callback == NULL) { return; } - - struct Main *bmain = (struct Main *)data; - struct Scene *scene; - - scene = bmain->scenes.first; - while (scene) { - if (scene->audio.flag & AUDIO_SYNC) { - if (mode) { - BKE_sound_play_scene(scene); - } - else { - BKE_sound_stop_scene(scene); - } - if (scene->playback_handle) { - AUD_Handle_setPosition(scene->playback_handle, time); - } - } - scene = scene->id.next; - } + Main *bmain = (Main *)data; + sound_jack_sync_callback(bmain, mode, time); } # endif @@ -235,7 +255,7 @@ void *BKE_sound_get_device(void) return sound_device; } -void BKE_sound_init(struct Main *bmain) +void BKE_sound_init(Main *bmain) { /* Make sure no instance of the sound system is running, otherwise we get leaks. */ BKE_sound_exit(); @@ -289,14 +309,14 @@ void BKE_sound_init(struct Main *bmain) BKE_sound_init_main(bmain); } -void BKE_sound_init_main(struct Main *bmain) +void BKE_sound_init_main(Main *bmain) { # ifdef WITH_JACK if (sound_device) { AUD_setSynchronizerCallback(sound_sync_callback, bmain); } # else - (void)bmain; /* unused */ + UNUSED_VARS(bmain); # endif } @@ -324,7 +344,7 @@ void BKE_sound_exit_once(void) /* XXX unused currently */ # if 0 -bSound *BKE_sound_new_buffer(struct Main *bmain, bSound *source) +bSound *BKE_sound_new_buffer(Main *bmain, bSound *source) { bSound *sound = NULL; @@ -342,7 +362,7 @@ bSound *BKE_sound_new_buffer(struct Main *bmain, bSound *source) return sound; } -bSound *BKE_sound_new_limiter(struct Main *bmain, bSound *source, float start, float end) +bSound *BKE_sound_new_limiter(Main *bmain, bSound *source, float start, float end) { bSound *sound = NULL; @@ -365,6 +385,8 @@ bSound *BKE_sound_new_limiter(struct Main *bmain, bSound *source, float start, f void BKE_sound_cache(bSound *sound) { + sound_verify_evaluated_id(&sound->id); + sound->flags |= SOUND_FLAGS_CACHING; if (sound->cache) { AUD_Sound_free(sound->cache); @@ -389,46 +411,52 @@ void BKE_sound_delete_cache(bSound *sound) } } -void BKE_sound_load(struct Main *bmain, bSound *sound) +void BKE_sound_load(Main *bmain, bSound *sound) { - if (sound) { - if (sound->cache) { - AUD_Sound_free(sound->cache); - sound->cache = NULL; - } + sound_verify_evaluated_id(&sound->id); + BKE_sound_load_audio(bmain, sound); +} - if (sound->handle) { - AUD_Sound_free(sound->handle); - sound->handle = NULL; - sound->playback_handle = NULL; - } +void BKE_sound_load_audio(Main *bmain, bSound *sound) +{ - BKE_sound_free_waveform(sound); + if (sound->cache) { + AUD_Sound_free(sound->cache); + sound->cache = NULL; + } + + if (sound->handle) { + AUD_Sound_free(sound->handle); + sound->handle = NULL; + sound->playback_handle = NULL; + } + + BKE_sound_free_waveform(sound); /* XXX unused currently */ # if 0 switch (sound->type) { case SOUND_TYPE_FILE: # endif - { - char fullpath[FILE_MAX]; + { + char fullpath[FILE_MAX]; - /* load sound */ - PackedFile *pf = sound->packedfile; + /* load sound */ + PackedFile *pf = sound->packedfile; - /* don't modify soundact->sound->name, only change a copy */ - BLI_strncpy(fullpath, sound->name, sizeof(fullpath)); - BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id)); + /* don't modify soundact->sound->name, only change a copy */ + BLI_strncpy(fullpath, sound->name, sizeof(fullpath)); + BLI_path_abs(fullpath, ID_BLEND_PATH(bmain, &sound->id)); - /* but we need a packed file then */ - if (pf) { - sound->handle = AUD_Sound_bufferFile((unsigned char *)pf->data, pf->size); - } - else { - /* or else load it from disk */ - sound->handle = AUD_Sound_file(fullpath); - } + /* but we need a packed file then */ + if (pf) { + sound->handle = AUD_Sound_bufferFile((unsigned char *)pf->data, pf->size); + } + else { + /* or else load it from disk */ + sound->handle = AUD_Sound_file(fullpath); } + } /* XXX unused currently */ # if 0 break; @@ -445,34 +473,34 @@ void BKE_sound_load(struct Main *bmain, bSound *sound) break; } # endif - if (sound->flags & SOUND_FLAGS_MONO) { - void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO); - AUD_Sound_free(sound->handle); - sound->handle = handle; - } - - if (sound->flags & SOUND_FLAGS_CACHING) { - sound->cache = AUD_Sound_cache(sound->handle); - } + if (sound->flags & SOUND_FLAGS_MONO) { + void *handle = AUD_Sound_rechannel(sound->handle, AUD_CHANNELS_MONO); + AUD_Sound_free(sound->handle); + sound->handle = handle; + } - if (sound->cache) { - sound->playback_handle = sound->cache; - } - else { - sound->playback_handle = sound->handle; - } + if (sound->flags & SOUND_FLAGS_CACHING) { + sound->cache = AUD_Sound_cache(sound->handle); + } - BKE_sound_update_sequencer(bmain, sound); + if (sound->cache) { + sound->playback_handle = sound->cache; + } + else { + sound->playback_handle = sound->handle; } } -AUD_Device *BKE_sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume) +AUD_Device *BKE_sound_mixdown(Scene *scene, AUD_DeviceSpecs specs, int start, float volume) { + sound_verify_evaluated_id(&scene->id); return AUD_openMixdownDevice(specs, scene->sound_scene, volume, start / FPS); } -void BKE_sound_create_scene(struct Scene *scene) +void BKE_sound_create_scene(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + /* should be done in version patch, but this gets called before */ if (scene->r.frs_sec_base == 0) { scene->r.frs_sec_base = 1; @@ -487,7 +515,7 @@ void BKE_sound_create_scene(struct Scene *scene) scene->speaker_handles = NULL; } -void BKE_sound_destroy_scene(struct Scene *scene) +void BKE_sound_destroy_scene(Scene *scene) { if (scene->playback_handle) { AUD_Handle_stop(scene->playback_handle); @@ -503,25 +531,32 @@ void BKE_sound_destroy_scene(struct Scene *scene) } } -void BKE_sound_reset_scene_specs(struct Scene *scene) +void BKE_sound_reset_scene_specs(Scene *scene) { - AUD_Specs specs; + sound_verify_evaluated_id(&scene->id); - specs.channels = AUD_Device_getChannels(sound_device); - specs.rate = AUD_Device_getRate(sound_device); + if (scene->sound_scene) { + AUD_Specs specs; - AUD_Sequence_setSpecs(scene->sound_scene, specs); + specs.channels = AUD_Device_getChannels(sound_device); + specs.rate = AUD_Device_getRate(sound_device); + + AUD_Sequence_setSpecs(scene->sound_scene, specs); + } } -void BKE_sound_mute_scene(struct Scene *scene, int muted) +void BKE_sound_mute_scene(Scene *scene, int muted) { + sound_verify_evaluated_id(&scene->id); if (scene->sound_scene) { AUD_Sequence_setMuted(scene->sound_scene, muted); } } -void BKE_sound_update_fps(struct Scene *scene) +void BKE_sound_update_fps(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + if (scene->sound_scene) { AUD_Sequence_setFPS(scene->sound_scene, FPS); } @@ -529,16 +564,19 @@ void BKE_sound_update_fps(struct Scene *scene) BKE_sequencer_refresh_sound_length(scene); } -void BKE_sound_update_scene_listener(struct Scene *scene) +void BKE_sound_update_scene_listener(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + AUD_Sequence_setSpeedOfSound(scene->sound_scene, scene->audio.speed_of_sound); AUD_Sequence_setDopplerFactor(scene->sound_scene, scene->audio.doppler_factor); AUD_Sequence_setDistanceModel(scene->sound_scene, scene->audio.distance_model); } void *BKE_sound_scene_add_scene_sound( - struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) + Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip) { + sound_verify_evaluated_id(&scene->id); if (sequence->scene && scene != sequence->scene) { const double fps = FPS; return AUD_Sequence_add(scene->sound_scene, @@ -550,7 +588,7 @@ void *BKE_sound_scene_add_scene_sound( return NULL; } -void *BKE_sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) +void *BKE_sound_scene_add_scene_sound_defaults(Scene *scene, Sequence *sequence) { return BKE_sound_scene_add_scene_sound(scene, sequence, @@ -560,8 +598,9 @@ void *BKE_sound_scene_add_scene_sound_defaults(struct Scene *scene, struct Seque } void *BKE_sound_add_scene_sound( - struct Scene *scene, struct Sequence *sequence, int startframe, int endframe, int frameskip) + Scene *scene, Sequence *sequence, int startframe, int endframe, int frameskip) { + sound_verify_evaluated_id(&scene->id); /* Happens when sequence's sound datablock was removed. */ if (sequence->sound == NULL) { return NULL; @@ -579,7 +618,7 @@ void *BKE_sound_add_scene_sound( return handle; } -void *BKE_sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) +void *BKE_sound_add_scene_sound_defaults(Scene *scene, Sequence *sequence) { return BKE_sound_add_scene_sound(scene, sequence, @@ -588,7 +627,7 @@ void *BKE_sound_add_scene_sound_defaults(struct Scene *scene, struct Sequence *s sequence->startofs + sequence->anim_startofs); } -void BKE_sound_remove_scene_sound(struct Scene *scene, void *handle) +void BKE_sound_remove_scene_sound(Scene *scene, void *handle) { AUD_Sequence_remove(scene->sound_scene, handle); } @@ -599,14 +638,16 @@ void BKE_sound_mute_scene_sound(void *handle, char mute) } void BKE_sound_move_scene_sound( - struct Scene *scene, void *handle, int startframe, int endframe, int frameskip) + Scene *scene, void *handle, int startframe, int endframe, int frameskip) { + sound_verify_evaluated_id(&scene->id); const double fps = FPS; AUD_SequenceEntry_move(handle, startframe / fps, endframe / fps, frameskip / fps); } -void BKE_sound_move_scene_sound_defaults(struct Scene *scene, struct Sequence *sequence) +void BKE_sound_move_scene_sound_defaults(Scene *scene, Sequence *sequence) { + sound_verify_evaluated_id(&scene->id); if (sequence->scene_sound) { BKE_sound_move_scene_sound(scene, sequence->scene_sound, @@ -626,8 +667,9 @@ void BKE_sound_set_cfra(int cfra) sound_cfra = cfra; } -void BKE_sound_set_scene_volume(struct Scene *scene, float volume) +void BKE_sound_set_scene_volume(Scene *scene, float volume) { + sound_verify_evaluated_id(&scene->id); AUD_Sequence_setAnimationData(scene->sound_scene, AUD_AP_VOLUME, CFRA, @@ -651,17 +693,21 @@ void BKE_sound_set_scene_sound_pan(void *handle, float pan, char animated) AUD_SequenceEntry_setAnimationData(handle, AUD_AP_PANNING, sound_cfra, &pan, animated); } -void BKE_sound_update_sequencer(struct Main *main, bSound *sound) +void BKE_sound_update_sequencer(Main *main, bSound *sound) { - struct Scene *scene; + BLI_assert(!"is not supposed to be used, is weird function."); + + Scene *scene; for (scene = main->scenes.first; scene; scene = scene->id.next) { BKE_sequencer_update_sound(scene, sound); } } -static void sound_start_play_scene(struct Scene *scene) +static void sound_start_play_scene(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + if (scene->playback_handle) { AUD_Handle_stop(scene->playback_handle); } @@ -673,8 +719,10 @@ static void sound_start_play_scene(struct Scene *scene) } } -void BKE_sound_play_scene(struct Scene *scene) +void BKE_sound_play_scene(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + AUD_Status status; const float cur_time = (float)((double)CFRA / FPS); @@ -704,7 +752,7 @@ void BKE_sound_play_scene(struct Scene *scene) AUD_Device_unlock(sound_device); } -void BKE_sound_stop_scene(struct Scene *scene) +void BKE_sound_stop_scene(Scene *scene) { if (scene->playback_handle) { AUD_Handle_pause(scene->playback_handle); @@ -715,8 +763,10 @@ void BKE_sound_stop_scene(struct Scene *scene) } } -void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene) +void BKE_sound_seek_scene(Main *bmain, Scene *scene) { + sound_verify_evaluated_id(&scene->id); + AUD_Status status; bScreen *screen; int animation_playing; @@ -748,9 +798,10 @@ void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene) } } - if (scene->audio.flag & AUDIO_SCRUB && !animation_playing) { + Scene *scene_orig = (Scene *)DEG_get_original_id(&scene->id); + if (scene_orig->audio.flag & AUDIO_SCRUB && !animation_playing) { AUD_Handle_setPosition(scene->playback_handle, cur_time); - if (scene->audio.flag & AUDIO_SYNC) { + if (scene_orig->audio.flag & AUDIO_SYNC) { AUD_seekSynchronizer(scene->playback_handle, cur_time); } AUD_Handle_resume(scene->playback_handle); @@ -766,7 +817,7 @@ void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene) } } else { - if (scene->audio.flag & AUDIO_SYNC) { + if (scene_orig->audio.flag & AUDIO_SYNC) { AUD_seekSynchronizer(scene->playback_handle, cur_time); } else { @@ -779,8 +830,10 @@ void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene) AUD_Device_unlock(sound_device); } -float BKE_sound_sync_scene(struct Scene *scene) +float BKE_sound_sync_scene(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + // Ugly: Blender doesn't like it when the animation is played back during rendering if (G.is_rendering) { return NAN_FLT; @@ -797,8 +850,10 @@ float BKE_sound_sync_scene(struct Scene *scene) return NAN_FLT; } -int BKE_sound_scene_playing(struct Scene *scene) +int BKE_sound_scene_playing(Scene *scene) { + sound_verify_evaluated_id(&scene->id); + // Ugly: Blender doesn't like it when the animation is played back during rendering if (G.is_rendering) { return -1; @@ -829,6 +884,9 @@ void BKE_sound_free_waveform(bSound *sound) sound->tags &= ~SOUND_TAGS_WAVEFORM_NO_RELOAD; } +/* TODO(sergey): Consider mamakinging this function fully autonomous, as in, not require having + * an existing playback handle. That would make it easy to read waveforms, which doesn't seem to + * be affected by evaluated scene (waveworm comes from file). */ void BKE_sound_read_waveform(bSound *sound, short *stop) { AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); @@ -877,11 +935,14 @@ static void sound_update_base(Scene *scene, Base *base, void *new_set) Speaker *speaker; float quat[4]; - if ((ob->id.tag & LIB_TAG_DOIT) == 0) { - return; - } + sound_verify_evaluated_id(&scene->id); + sound_verify_evaluated_id(&ob->id); - ob->id.tag &= ~LIB_TAG_DOIT; + // TODO(sergey): Bring the test back, or make it a part of dependency graph update. + // if ((ob->id.tag & LIB_TAG_DOIT) == 0) { + // return; + // } + // ob->id.tag &= ~LIB_TAG_DOIT; if ((ob->type != OB_SPEAKER) || !ob->adt) { return; @@ -944,6 +1005,8 @@ static void sound_update_base(Scene *scene, Base *base, void *new_set) void BKE_sound_update_scene(Main *bmain, Scene *scene) { + sound_verify_evaluated_id(&scene->id); + Base *base; Scene *sce_it; @@ -953,7 +1016,8 @@ void BKE_sound_update_scene(Main *bmain, Scene *scene) /* cheap test to skip looping over all objects (no speakers is a common case) */ if (!BLI_listbase_is_empty(&bmain->speakers)) { - BKE_main_id_tag_listbase(&bmain->objects, LIB_TAG_DOIT, true); + // TODO(sergey): Bring the test back, or make it a part of dependency graph update. + // BKE_main_id_tag_listbase(&bmain->objects, LIB_TAG_DOIT, true); for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { @@ -990,6 +1054,7 @@ void *BKE_sound_get_factory(void *sound) /* stupid wrapper because AUD_C-API.h includes Python.h which makesrna doesn't like */ float BKE_sound_get_length(bSound *sound) { + sound_verify_evaluated_id(&sound->id); AUD_SoundInfo info = AUD_getInfo(sound->playback_handle); return info.length; @@ -1014,7 +1079,7 @@ void BKE_sound_force_device(const char *UNUSED(device)) void BKE_sound_init_once(void) { } -void BKE_sound_init(struct Main *UNUSED(bmain)) +void BKE_sound_init(Main *UNUSED(bmain)) { } void BKE_sound_exit(void) @@ -1023,110 +1088,107 @@ void BKE_sound_exit(void) void BKE_sound_exit_once(void) { } -void BKE_sound_cache(struct bSound *UNUSED(sound)) +void BKE_sound_cache(bSound *UNUSED(sound)) { } -void BKE_sound_delete_cache(struct bSound *UNUSED(sound)) +void BKE_sound_delete_cache(bSound *UNUSED(sound)) { } -void BKE_sound_load(struct Main *UNUSED(bmain), struct bSound *UNUSED(sound)) +void BKE_sound_load(Main *UNUSED(bmain), bSound *UNUSED(sound)) { } -void BKE_sound_create_scene(struct Scene *UNUSED(scene)) +void BKE_sound_create_scene(Scene *UNUSED(scene)) { } -void BKE_sound_destroy_scene(struct Scene *UNUSED(scene)) +void BKE_sound_destroy_scene(Scene *UNUSED(scene)) { } -void BKE_sound_reset_scene_specs(struct Scene *UNUSED(scene)) +void BKE_sound_reset_scene_specs(Scene *UNUSED(scene)) { } -void BKE_sound_mute_scene(struct Scene *UNUSED(scene), int UNUSED(muted)) +void BKE_sound_mute_scene(Scene *UNUSED(scene), int UNUSED(muted)) { } -void *BKE_sound_scene_add_scene_sound(struct Scene *UNUSED(scene), - struct Sequence *UNUSED(sequence), +void *BKE_sound_scene_add_scene_sound(Scene *UNUSED(scene), + Sequence *UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } -void *BKE_sound_scene_add_scene_sound_defaults(struct Scene *UNUSED(scene), - struct Sequence *UNUSED(sequence)) +void *BKE_sound_scene_add_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence)) { return NULL; } -void *BKE_sound_add_scene_sound(struct Scene *UNUSED(scene), - struct Sequence *UNUSED(sequence), +void *BKE_sound_add_scene_sound(Scene *UNUSED(scene), + Sequence *UNUSED(sequence), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { return NULL; } -void *BKE_sound_add_scene_sound_defaults(struct Scene *UNUSED(scene), - struct Sequence *UNUSED(sequence)) +void *BKE_sound_add_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence)) { return NULL; } -void BKE_sound_remove_scene_sound(struct Scene *UNUSED(scene), void *UNUSED(handle)) +void BKE_sound_remove_scene_sound(Scene *UNUSED(scene), void *UNUSED(handle)) { } void BKE_sound_mute_scene_sound(void *UNUSED(handle), char UNUSED(mute)) { } -void BKE_sound_move_scene_sound(struct Scene *UNUSED(scene), +void BKE_sound_move_scene_sound(Scene *UNUSED(scene), void *UNUSED(handle), int UNUSED(startframe), int UNUSED(endframe), int UNUSED(frameskip)) { } -void BKE_sound_move_scene_sound_defaults(struct Scene *UNUSED(scene), - struct Sequence *UNUSED(sequence)) +void BKE_sound_move_scene_sound_defaults(Scene *UNUSED(scene), Sequence *UNUSED(sequence)) { } -void BKE_sound_play_scene(struct Scene *UNUSED(scene)) +void BKE_sound_play_scene(Scene *UNUSED(scene)) { } -void BKE_sound_stop_scene(struct Scene *UNUSED(scene)) +void BKE_sound_stop_scene(Scene *UNUSED(scene)) { } -void BKE_sound_seek_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) +void BKE_sound_seek_scene(Main *UNUSED(bmain), Scene *UNUSED(scene)) { } -float BKE_sound_sync_scene(struct Scene *UNUSED(scene)) +float BKE_sound_sync_scene(Scene *UNUSED(scene)) { return NAN_FLT; } -int BKE_sound_scene_playing(struct Scene *UNUSED(scene)) +int BKE_sound_scene_playing(Scene *UNUSED(scene)) { return -1; } -void BKE_sound_read_waveform(struct bSound *sound, short *stop) +void BKE_sound_read_waveform(bSound *sound, short *stop) { UNUSED_VARS(sound, stop); } -void BKE_sound_init_main(struct Main *UNUSED(bmain)) +void BKE_sound_init_main(Main *UNUSED(bmain)) { } void BKE_sound_set_cfra(int UNUSED(cfra)) { } -void BKE_sound_update_sequencer(struct Main *UNUSED(main), struct bSound *UNUSED(sound)) +void BKE_sound_update_sequencer(Main *UNUSED(main), bSound *UNUSED(sound)) { } -void BKE_sound_update_scene(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene)) +void BKE_sound_update_scene(Main *UNUSED(bmain), Scene *UNUSED(scene)) { } -void BKE_sound_update_scene_sound(void *UNUSED(handle), struct bSound *UNUSED(sound)) +void BKE_sound_update_scene_sound(void *UNUSED(handle), bSound *UNUSED(sound)) { } -void BKE_sound_update_scene_listener(struct Scene *UNUSED(scene)) +void BKE_sound_update_scene_listener(Scene *UNUSED(scene)) { } -void BKE_sound_update_fps(struct Scene *UNUSED(scene)) +void BKE_sound_update_fps(Scene *UNUSED(scene)) { } void BKE_sound_set_scene_sound_volume(void *UNUSED(handle), @@ -1137,7 +1199,7 @@ void BKE_sound_set_scene_sound_volume(void *UNUSED(handle), void BKE_sound_set_scene_sound_pan(void *UNUSED(handle), float UNUSED(pan), char UNUSED(animated)) { } -void BKE_sound_set_scene_volume(struct Scene *UNUSED(scene), float UNUSED(volume)) +void BKE_sound_set_scene_volume(Scene *UNUSED(scene), float UNUSED(volume)) { } void BKE_sound_set_scene_sound_pitch(void *UNUSED(handle), @@ -1145,7 +1207,7 @@ void BKE_sound_set_scene_sound_pitch(void *UNUSED(handle), char UNUSED(animated)) { } -float BKE_sound_get_length(struct bSound *UNUSED(sound)) +float BKE_sound_get_length(bSound *UNUSED(sound)) { return 0; } @@ -1155,4 +1217,94 @@ char **BKE_sound_get_device_names(void) return names; } +void BKE_sound_free_waveform(bSound *UNUSED(sound)) +{ +} + +void BKE_sound_load_audio(Main *UNUSED(bmain), bSound *UNUSED(sound)) +{ +} + #endif /* WITH_AUDASPACE */ + +void BKE_sound_update_and_seek(Main *bmain, Depsgraph *depsgraph) +{ + Scene *scene_orig = DEG_get_input_scene(depsgraph); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + /* NOTE: We don't do copy-on-write or anything like that here because we need to know scene's + * flags like "scrubbing" in the BKE_sound_seek_scene(). So we simply update frame to which + * seek needs to happen. + * + * TODO(sergey): Might change API so the frame is passes explicitly. */ + scene_eval->r.cfra = scene_orig->r.cfra; + BKE_sound_seek_scene(bmain, scene_eval); +} + +void BKE_sound_reset_scene_runtime(Scene *scene) +{ + scene->sound_scene = NULL; + scene->playback_handle = NULL; + scene->sound_scrub_handle = NULL; + scene->speaker_handles = NULL; +} + +void BKE_sound_ensure_scene(struct Scene *scene) +{ + if (scene->sound_scene != NULL) { + return; + } + BKE_sound_create_scene(scene); +} + +void BKE_sound_reset_runtime(bSound *sound) +{ + sound->cache = NULL; + sound->playback_handle = NULL; +} + +void BKE_sound_ensure_loaded(Main *bmain, bSound *sound) +{ + if (sound->cache != NULL) { + return; + } + BKE_sound_load(bmain, sound); +} + +void BKE_sound_jack_sync_callback_set(SoundJackSyncCallback callback) +{ +#if defined(WITH_AUDASPACE) && defined(WITH_JACK) + sound_jack_sync_callback = callback; +#else + UNUSED_VARS(callback); +#endif +} + +void BKE_sound_jack_scene_update(Scene *scene, int mode, float time) +{ + sound_verify_evaluated_id(&scene->id); + + /* Ugly: Blender doesn't like it when the animation is played back during rendering. */ + if (G.is_rendering) { + return; + } + + if (mode) { + BKE_sound_play_scene(scene); + } + else { + BKE_sound_stop_scene(scene); + } +#ifdef WITH_AUDASPACE + if (scene->playback_handle != NULL) { + AUD_Handle_setPosition(scene->playback_handle, time); + } +#else + UNUSED_VARS(time); +#endif +} + +void BKE_sound_evaluate(Depsgraph *depsgraph, Main *bmain, bSound *sound) +{ + DEG_debug_print_eval(depsgraph, __func__, sound->id.name, sound); + BKE_sound_ensure_loaded(bmain, sound); +} diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index 8565fde4565..c7a0d65a2a9 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -60,8 +60,10 @@ void *BKE_speaker_add(Main *bmain, const char *name) } /** - * Only copy internal data of Speaker ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Speaker ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/studiolight.c b/source/blender/blenkernel/intern/studiolight.c index 315bd0cabc9..e0ff5fcccca 100644 --- a/source/blender/blenkernel/intern/studiolight.c +++ b/source/blender/blenkernel/intern/studiolight.c @@ -692,7 +692,8 @@ static float studiolight_spherical_harmonics_geomerics_eval( const float normal[3], float sh0, float sh1, float sh2, float sh3) { /* Use Geomerics non-linear SH. */ - /* http://www.geomerics.com/wp-content/uploads/2015/08/CEDEC_Geomerics_ReconstructingDiffuseLighting1.pdf */ + /* http://www.geomerics.com/wp-content/uploads/2015/08/CEDEC_Geomerics_ReconstructingDiffuseLighting1.pdf + */ float R0 = sh0 * M_1_PI; float R1[3] = {-sh3, sh2, -sh1}; @@ -1283,7 +1284,8 @@ void BKE_studiolight_init(void) BLI_addtail(&studiolights, sl); /* go over the preset folder and add a studiolight for every image with its path */ - /* for portable installs (where USER and SYSTEM paths are the same), only go over LOCAL datafiles once */ + /* for portable installs (where USER and SYSTEM paths are the same), + * only go over LOCAL datafiles once */ /* Also reserve icon space for it. */ if (!BKE_appdir_app_is_portable_install()) { studiolight_add_files_from_datafolder(BLENDER_USER_DATAFILES, diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index a58d1eaff3e..ad81fc49b19 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -305,8 +305,8 @@ static int ss_sync_from_uv(CCGSubSurf *ss, CCGSubSurf *origss, DerivedMesh *dm, limit[0] = limit[1] = STD_UV_CONNECT_LIMIT; /* previous behavior here is without accounting for winding, however this causes stretching in - * UV map in really simple cases with mirror + subsurf, see second part of T44530. Also, initially - * intention is to treat merged vertices from mirror modifier as seams. + * UV map in really simple cases with mirror + subsurf, see second part of T44530. + * Also, initially intention is to treat merged vertices from mirror modifier as seams. * This fixes a very old regression (2.49 was correct here) */ vmap = BKE_mesh_uv_vert_map_create(mpoly, mloop, mloopuv, totface, totvert, limit, false, true); if (!vmap) { @@ -746,7 +746,7 @@ static void ss_sync_ccg_from_derivedmesh(CCGSubSurf *ss, static int hasGivenError = 0; if (!hasGivenError) { - //XXX error("Unrecoverable error in SubSurf calculation," + // XXX error("Unrecoverable error in SubSurf calculation," // " mesh is inconsistent."); hasGivenError = 1; @@ -1729,8 +1729,8 @@ static void ccgDM_foreachMappedLoop(DerivedMesh *dm, void *userData, DMForeachFlag flag) { - /* We can't use dm->getLoopDataLayout(dm) here, we want to always access dm->loopData, EditDerivedBMesh would - * return loop data from bmesh itself. */ + /* We can't use dm->getLoopDataLayout(dm) here, we want to always access dm->loopData, + * EditDerivedBMesh would return loop data from bmesh itself. */ const float(*lnors)[3] = (flag & DM_FOREACH_USE_NORMAL) ? DM_get_loop_data_layer(dm, CD_NORMAL) : NULL; @@ -1978,10 +1978,9 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type) if (type == CD_TESSLOOPNORMAL) { /* Create tessloopnormal on demand to save memory. */ - /* Note that since tessellated face corners are the same a loops in CCGDM, and since all faces have four - * loops/corners, we can simplify the code here by converting tessloopnormals from 'short (*)[4][3]' - * to 'short (*)[3]'. - */ + /* Note that since tessellated face corners are the same a loops in CCGDM, + * and since all faces have four loops/corners, we can simplify the code + * here by converting tessloopnormals from 'short (*)[4][3]' to 'short (*)[3]'. */ short(*tlnors)[3]; /* Avoid re-creation if the layer exists already */ @@ -2000,7 +1999,8 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type) DM_add_tessface_layer(dm, CD_TESSLOOPNORMAL, CD_CALLOC, NULL); tlnors = tlnors_it = (short(*)[3])DM_get_tessface_data_layer(dm, CD_TESSLOOPNORMAL); - /* With ccgdm, we have a simple one to one mapping between loops and tessellated face corners. */ + /* With ccgdm, we have a simple one to one mapping between loops + * and tessellated face corners. */ for (i = 0; i < numLoops; ++i, ++tlnors_it, ++lnors) { normal_float_to_short_v3(*tlnors_it, *lnors); } @@ -2255,8 +2255,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) bool grid_pbvh = ccgDM_use_grid_pbvh(ccgdm); if ((ob->mode & OB_MODE_SCULPT) == 0) { /* In vwpaint, we may use a grid_pbvh for multires/subsurf, under certain conditions. - * More complex cases break 'history' trail back to original vertices, in that case we fall back to - * deformed cage only (i.e. original deformed mesh). */ + * More complex cases break 'history' trail back to original vertices, + * in that case we fall back to deformed cage only (i.e. original deformed mesh). */ VirtualModifierData virtualModifierData; ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); @@ -2294,8 +2294,8 @@ static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) } if (ob->sculpt->pbvh) { - /* Note that we have to clean up exisitng pbvh instead of updating it in case it does not match current - * grid_pbvh status. */ + /* Note that we have to clean up exisitng pbvh instead of updating it in case it does not + * match current grid_pbvh status. */ const PBVHType pbvh_type = BKE_pbvh_type(ob->sculpt->pbvh); if (grid_pbvh) { if (pbvh_type == PBVH_GRIDS) { @@ -2438,7 +2438,8 @@ static void set_default_ccgdm_callbacks(CCGDerivedMesh *ccgdm) ccgdm->dm.getNumVerts = ccgDM_getNumVerts; ccgdm->dm.getNumEdges = ccgDM_getNumEdges; ccgdm->dm.getNumLoops = ccgDM_getNumLoops; - /* reuse of ccgDM_getNumTessFaces is intentional here: subsurf polys are just created from tessfaces */ + /* reuse of ccgDM_getNumTessFaces is intentional here: + * subsurf polys are just created from tessfaces */ ccgdm->dm.getNumPolys = ccgDM_getNumPolys; ccgdm->dm.getNumTessFaces = ccgDM_getNumTessFaces; diff --git a/source/blender/blenkernel/intern/suggestions.c b/source/blender/blenkernel/intern/suggestions.c index 42e1ef6fa0a..47d536f4f4f 100644 --- a/source/blender/blenkernel/intern/suggestions.c +++ b/source/blender/blenkernel/intern/suggestions.c @@ -39,7 +39,7 @@ static Text *activeToolText = NULL; static SuggList suggestions = {NULL, NULL, NULL, NULL, NULL}; static char *documentation = NULL; -//static int doc_lines = 0; +// static int doc_lines = 0; static void txttl_free_suggest(void) { diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 9047aa51dea..f07751e349f 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -464,8 +464,10 @@ Text *BKE_text_load(Main *bmain, const char *file, const char *relpath) } /** - * Only copy internal data of Text ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Text ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * @@ -2004,7 +2006,7 @@ static void txt_undo_add_unprefix_op(Text *text, BLI_assert(BLI_listbase_count(line_index_mask) == line_index_mask_len); - /* OP byte + UInt32 count + counted UInt32 line numbers + UInt32 count + 12-bytes selection + OP byte */ + /* OP byte + u32 count + counted u32 line numbers + u32 count + 12-bytes selection + OP byte. */ if (!max_undo_test(utxt, 2 + 4 + (line_index_mask_len * 4) + 4 + 12 + 1)) { return; } @@ -2446,7 +2448,7 @@ void txt_do_undo(Text *text, TextUndoBuf *utxt) break; } default: - //XXX error("Undo buffer error - resetting"); + // XXX error("Undo buffer error - resetting"); utxt->pos = -1; break; @@ -2638,7 +2640,7 @@ void txt_do_redo(Text *text, TextUndoBuf *utxt) break; } default: - //XXX error("Undo buffer error - resetting"); + // XXX error("Undo buffer error - resetting"); utxt->pos = -1; break; @@ -3266,7 +3268,7 @@ int txt_setcurr_tab_spaces(Text *text, int space) } while (text->curl->line[i] == indent) { - //we only count those tabs/spaces that are before any text or before the curs; + // we only count those tabs/spaces that are before any text or before the curs; if (i == text->curc) { return i; } @@ -3331,7 +3333,8 @@ int text_check_bracket(const char ch) return 0; } -/* TODO, have a function for operators - http://docs.python.org/py3k/reference/lexical_analysis.html#operators */ +/* TODO, have a function for operators - + * http://docs.python.org/py3k/reference/lexical_analysis.html#operators */ bool text_check_delim(const char ch) { int a; diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index dd307880eb6..9baa8bd20e1 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -214,7 +214,8 @@ void BKE_texture_free(Tex *tex) void BKE_texture_default(Tex *tex) { - /* BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(tex, id)); */ /* Not here, can be called with some pointers set. :/ */ + /* Not here, can be called with some pointers set. :/ */ + /* BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(tex, id)); */ tex->type = TEX_IMAGE; tex->ima = NULL; @@ -411,8 +412,10 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot) /* ------------------------------------------------------------------------- */ /** - * Only copy internal data of Texture ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of Texture ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c index 73f50be612e..a5445be7ce5 100644 --- a/source/blender/blenkernel/intern/tracking.c +++ b/source/blender/blenkernel/intern/tracking.c @@ -209,7 +209,8 @@ static void tracking_tracks_copy(ListBase *tracks_dst, } } -/* copy the whole list of plane tracks (need whole MovieTracking structures due to embedded pointers to tracks). +/* Copy the whole list of plane tracks + * (need whole MovieTracking structures due to embedded pointers to tracks). * WARNING: implies tracking_[dst/src] and their tracks have already been copied. */ static void tracking_plane_tracks_copy(ListBase *plane_tracks_list_dst, const ListBase *plane_tracks_list_src, @@ -321,7 +322,8 @@ void BKE_tracking_copy(MovieTracking *tracking_dst, /* Warning! Will override tracks_mapping. */ tracking_objects_copy(&tracking_dst->objects, &tracking_src->objects, tracks_mapping, flag); - /* Those remaining are runtime data, they will be reconstructed as needed, do not bother copying them. */ + /* Those remaining are runtime data, they will be reconstructed as needed, + * do not bother copying them. */ tracking_dst->dopesheet.ok = false; BLI_listbase_clear(&tracking_dst->dopesheet.channels); BLI_listbase_clear(&tracking_dst->dopesheet.coverage_segments); @@ -2093,7 +2095,8 @@ static void reconstructed_camera_scale_set(MovieTrackingObject *object, float ma void BKE_tracking_camera_shift_get( MovieTracking *tracking, int winx, int winy, float *shiftx, float *shifty) { - /* indeed in both of cases it should be winx -- it's just how camera shift works for blender's camera */ + /* Indeed in both of cases it should be winx - + * it's just how camera shift works for blender's camera. */ *shiftx = (0.5f * winx - tracking->camera.principal[0]) / winx; *shifty = (0.5f * winy - tracking->camera.principal[1]) / winx; } diff --git a/source/blender/blenkernel/intern/tracking_region_tracker.c b/source/blender/blenkernel/intern/tracking_region_tracker.c index 0d2113aebe8..1d6bb88c3f4 100644 --- a/source/blender/blenkernel/intern/tracking_region_tracker.c +++ b/source/blender/blenkernel/intern/tracking_region_tracker.c @@ -252,7 +252,8 @@ static bool configure_and_run_tracker(ImBuf *destination_ibuf, /* configure the tracker */ tracking_configure_tracker(track, mask, &options); - /* convert the marker corners and center into pixel coordinates in the search/destination images. */ + /* Convert the marker corners and center into pixel coordinates in the + * search/destination images. */ tracking_get_marker_coords_for_tracking( frame_width, frame_height, reference_marker, src_pixel_x, src_pixel_y); tracking_get_marker_coords_for_tracking( diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c index 1fe63e21e78..695f9b21559 100644 --- a/source/blender/blenkernel/intern/tracking_stabilize.c +++ b/source/blender/blenkernel/intern/tracking_stabilize.c @@ -275,10 +275,10 @@ static int search_closest_marker_index(MovieTrackingTrack *track, int ref_frame) i = MAX2(0, i); i = MIN2(i, end - 1); for (; i < end - 1 && markers[i].framenr <= ref_frame; ++i) { - ; + /* pass */ } for (; 0 < i && markers[i].framenr > ref_frame; --i) { - ; + /* pass */ } track->last_marker = i; diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index d32bc7c6054..d3e0ff56977 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -135,7 +135,8 @@ static void undosys_id_ref_store(void *UNUSED(user_data), UndoRefID *id_ref) static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref) { - /* Note: we could optimize this, for now it's not too bad since it only runs when we access undo! */ + /* Note: we could optimize this, + * for now it's not too bad since it only runs when we access undo! */ Main *bmain = user_data; ListBase *lb = which_libbase(bmain, GS(id_ref->name)); for (ID *id = lb->first; id; id = id->next) { @@ -154,7 +155,8 @@ static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, Und UNDO_NESTED_CHECK_END; if (ok) { if (us->type->step_foreach_ID_ref != NULL) { - /* Don't use from context yet because sometimes context is fake and not all members are filled in. */ + /* Don't use from context yet because sometimes context is fake and + * not all members are filled in. */ us->type->step_foreach_ID_ref(us, undosys_id_ref_store, bmain); } #ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER @@ -193,7 +195,8 @@ static void undosys_step_decode(bContext *C, Main *bmain, UndoStack *ustack, Und } } #endif - /* Don't use from context yet because sometimes context is fake and not all members are filled in. */ + /* Don't use from context yet because sometimes context is fake and + * not all members are filled in. */ us->type->step_foreach_ID_ref(us, undosys_id_ref_resolve, bmain); } @@ -429,7 +432,8 @@ void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size } } #endif - /* Free from first to last, free functions may update de-duplication info (see #MemFileUndoStep). */ + /* Free from first to last, free functions may update de-duplication info + * (see #MemFileUndoStep). */ undosys_stack_clear_all_first(ustack, us->prev); #ifdef WITH_GLOBAL_UNDO_KEEP_ONE diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index aa08370e139..f5b73d88867 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -426,8 +426,8 @@ static size_t unit_as_string(char *str, value_conv = value / unit->scalar; /* Adjust precision to expected number of significant digits. - * Note that here, we shall not have to worry about very big/small numbers, units are expected to replace - * 'scientific notation' in those cases. */ + * Note that here, we shall not have to worry about very big/small numbers, units are expected to + * replace 'scientific notation' in those cases. */ prec -= integer_digits_d(value_conv); CLAMP(prec, 0, 6); @@ -663,7 +663,7 @@ static const char *unit_find_str(const char *str, const char *substr, bool case_ } /* If str_found is not a valid unit, we have to check further in the string... */ for (str_found++; isalpha_or_utf8(*str_found); str_found++) { - ; + /* pass */ } str = str_found; } @@ -803,7 +803,8 @@ static const bUnitDef *unit_detect_from_str(const bUnitCollection *usys, { /* Try to find a default unit from current or previous string. * This allows us to handle cases like 2 + 2mm, people would expect to get 4mm, not 2.002m! - * Note this does not handle corner cases like 2 + 2cm + 1 + 2.5mm... We can't support everything. */ + * Note this does not handle corner cases like 2 + 2cm + 1 + 2.5mm... We can't support + * everything. */ const bUnitDef *unit = NULL; /* see which units the new value has */ @@ -889,10 +890,12 @@ bool bUnit_ReplaceString( /* Try to find a default unit from current or previous string. */ default_unit = unit_detect_from_str(usys, str, str_prev); - /* We apply the default unit to the whole expression (default unit is now the reference '1.0' one). */ + /* We apply the default unit to the whole expression (default unit is now the reference '1.0' + * one). */ scale_pref_base *= default_unit->scalar; - /* Apply the default unit on the whole expression, this allows to handle nasty cases like '2+2in'. */ + /* Apply the default unit on the whole expression, this allows to handle nasty cases like + * '2+2in'. */ if (BLI_snprintf(str_tmp, sizeof(str_tmp), "(%s)*%.9g", str, default_unit->scalar) < sizeof(str_tmp)) { strncpy(str, str_tmp, len_max); @@ -913,9 +916,9 @@ bool bUnit_ReplaceString( { /* try other unit systems now, so we can evaluate imperial when metric is set for eg. */ - /* Note that checking other systems at that point means we do not support their units as 'default' one. - * In other words, when in metrics, typing '2+2in' will give 2 meters 2 inches, not 4 inches. - * I do think this is the desired behavior! + /* Note that checking other systems at that point means we do not support their units as + * 'default' one. In other words, when in metrics, typing '2+2in' will give 2 meters 2 inches, + * not 4 inches. I do think this is the desired behavior! */ const bUnitCollection *usys_iter; int system_iter; diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 2e9591a99c7..f9584adc6e0 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -113,8 +113,9 @@ static void *workspace_relation_get_data_matching_parent(const ListBase *relatio } /** - * Checks if \a screen is already used within any workspace. A screen should never be assigned to multiple - * WorkSpaceLayouts, but that should be ensured outside of the BKE_workspace module and without such checks. + * Checks if \a screen is already used within any workspace. A screen should never be assigned to + * multiple WorkSpaceLayouts, but that should be ensured outside of the BKE_workspace module + * and without such checks. * Hence, this should only be used as assert check before assigining a screen to a workspace. */ #ifndef NDEBUG @@ -143,8 +144,9 @@ WorkSpace *BKE_workspace_add(Main *bmain, const char *name) } /** - * The function that actually frees the workspace data (not workspace itself). It shouldn't be called - * directly, instead #BKE_workspace_remove should be, which calls this through #BKE_id_free then. + * The function that actually frees the workspace data (not workspace itself). + * It shouldn't be called directly, instead #BKE_workspace_remove should be, + * which calls this through #BKE_id_free then. * * Should something like a bke_internal.h be added, this should go there! */ @@ -275,7 +277,8 @@ WorkSpaceLayout *BKE_workspace_layout_find(const WorkSpace *workspace, const bSc * Find the layout for \a screen without knowing which workspace to look in. * Can also be used to find the workspace that contains \a screen. * - * \param r_workspace: Optionally return the workspace that contains the looked up layout (if found). + * \param r_workspace: Optionally return the workspace that contains the + * looked up layout (if found). */ WorkSpaceLayout *BKE_workspace_layout_find_global(const Main *bmain, const bScreen *screen, @@ -303,7 +306,8 @@ WorkSpaceLayout *BKE_workspace_layout_find_global(const Main *bmain, /** * Circular workspace layout iterator. * - * \param callback: Custom function which gets executed for each layout. Can return false to stop iterating. + * \param callback: Custom function which gets executed for each layout. + * Can return false to stop iterating. * \param arg: Custom data passed to each \a callback call. * * \return the layout at which \a callback returned false. diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index 741d67296df..109d615ae83 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -95,8 +95,10 @@ World *BKE_world_add(Main *bmain, const char *name) } /** - * Only copy internal data of World ID from source to already allocated/initialized destination. - * You probably never want to use that directly, use BKE_id_copy or BKE_id_copy_ex for typical needs. + * Only copy internal data of World ID from source + * to already allocated/initialized destination. + * You probably never want to use that directly, + * use #BKE_id_copy or #BKE_id_copy_ex for typical needs. * * WARNING! This function will not handle ID user count! * diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index 8456a2cddfc..a74d5b241ed 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -637,7 +637,7 @@ static AVStream *alloc_video_stream(FFMpegContext *context, } /* Deprecated and not doing anything since July 2015, deleted in recent ffmpeg */ - //c->me_method = ME_EPZS; + // c->me_method = ME_EPZS; codec = avcodec_find_encoder(c->codec_id); if (!codec) { @@ -787,15 +787,16 @@ static AVStream *alloc_audio_stream(FFMpegContext *context, codec = avcodec_find_encoder(c->codec_id); if (!codec) { - //XXX error("Couldn't find a valid audio codec"); + // XXX error("Couldn't find a valid audio codec"); return NULL; } if (codec->sample_fmts) { - /* check if the preferred sample format for this codec is supported. - * this is because, depending on the version of libav, and with the whole ffmpeg/libav fork situation, - * you have various implementations around. float samples in particular are not always supported. - */ + /* Check if the preferred sample format for this codec is supported. + * this is because, depending on the version of libav, + * and with the whole ffmpeg/libav fork situation, + * you have various implementations around. + * Float samples in particular are not always supported. */ const enum AVSampleFormat *p = codec->sample_fmts; for (; *p != -1; p++) { if (*p == st->codec->sample_fmt) { @@ -830,7 +831,7 @@ static AVStream *alloc_audio_stream(FFMpegContext *context, set_ffmpeg_properties(rd, c, "audio", &opts); if (avcodec_open2(c, codec, &opts) < 0) { - //XXX error("Couldn't initialize audio codec"); + // XXX error("Couldn't initialize audio codec"); BLI_strncpy(error, IMB_ffmpeg_last_error(), error_size); av_dict_free(&opts); return NULL; @@ -1522,7 +1523,6 @@ static IDProperty *BKE_ffmpeg_property_add(RenderData *rd, (char *)" "; val.string.len = 80; - /* val.str = (char *)" ";*/ idp_type = IDP_STRING; break; case AV_OPT_TYPE_CONST: @@ -1636,7 +1636,9 @@ static void ffmpeg_set_expert_options(RenderData *rd) * The other options were taken from the libx264-default.preset * included in the ffmpeg distribution. */ - // ffmpeg_property_add_string(rd, "video", "flags:loop"); // this breaks compatibility for QT + + /* This breaks compatibility for QT. */ + // BKE_ffmpeg_property_add_string(rd, "video", "flags:loop"); BKE_ffmpeg_property_add_string(rd, "video", "cmp:chroma"); BKE_ffmpeg_property_add_string(rd, "video", "partitions:parti4x4"); // Deprecated. BKE_ffmpeg_property_add_string(rd, "video", "partitions:partp8x8"); // Deprecated. diff --git a/source/blender/blenkernel/nla_private.h b/source/blender/blenkernel/nla_private.h index 59c9b4e7d33..dc086987e21 100644 --- a/source/blender/blenkernel/nla_private.h +++ b/source/blender/blenkernel/nla_private.h @@ -163,7 +163,8 @@ typedef struct NlaKeyframingContext { float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode); /* --------------- NLA Evaluation (very-private stuff) ----------------------- */ -/* these functions are only defined here to avoid problems with the order in which they get defined... */ +/* these functions are only defined here to avoid problems with the order + * in which they get defined. */ NlaEvalStrip *nlastrips_ctime_get_strip( struct Depsgraph *depsgraph, ListBase *list, ListBase *strips, short index, float ctime); |