Commit: 1cf5ce5e251efdb66dd7066decbdf2e7023a16f3 Author: Bastien Montagne Date: Thu Oct 8 12:50:04 2020 +0200 Branches: master https://developer.blender.org/rB1cf5ce5e251efdb66dd7066decbdf2e7023a16f3
Cleanup/refactor: `BKE_libblock_alloc` -> `BKE_id_new` in ID creation code. Better use higher-level code from common ID management when possible. Helps to de-duplicate logic, and reduces outside usages of more 'dangerous' functions. Note that we could get rid of many of those `BKE_<id_type>_add` functions now, but on the other hand several of those take extra parameters and perform additional actions, so think we can keep them all for now as 'non-standard ID specific creation functions'. =================================================================== M source/blender/blenkernel/intern/action.c M source/blender/blenkernel/intern/armature.c M source/blender/blenkernel/intern/brush.c M source/blender/blenkernel/intern/cachefile.c M source/blender/blenkernel/intern/camera.c M source/blender/blenkernel/intern/collection.c M source/blender/blenkernel/intern/curve.c M source/blender/blenkernel/intern/hair.c M source/blender/blenkernel/intern/key.c M source/blender/blenkernel/intern/lattice.c M source/blender/blenkernel/intern/light.c M source/blender/blenkernel/intern/lightprobe.c M source/blender/blenkernel/intern/material.c M source/blender/blenkernel/intern/mball.c M source/blender/blenkernel/intern/mesh.c M source/blender/blenkernel/intern/movieclip.c M source/blender/blenkernel/intern/object.c M source/blender/blenkernel/intern/paint.c M source/blender/blenkernel/intern/particle.c M source/blender/blenkernel/intern/pointcloud.c M source/blender/blenkernel/intern/scene.c M source/blender/blenkernel/intern/simulation.cc M source/blender/blenkernel/intern/speaker.c M source/blender/blenkernel/intern/text.c M source/blender/blenkernel/intern/texture.c M source/blender/blenkernel/intern/volume.cc M source/blender/blenkernel/intern/workspace.c M source/blender/blenkernel/intern/world.c =================================================================== diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 1f8c1cca113..9cb03a137a7 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -303,7 +303,7 @@ bAction *BKE_action_add(Main *bmain, const char name[]) { bAction *act; - act = BKE_libblock_alloc(bmain, ID_AC, name, 0); + act = BKE_id_new(bmain, ID_AC, name); return act; } diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index ed8c811c116..db5a5ce8ddf 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -331,7 +331,7 @@ bArmature *BKE_armature_add(Main *bmain, const char *name) { bArmature *arm; - arm = BKE_libblock_alloc(bmain, ID_AR, name, 0); + arm = BKE_id_new(bmain, ID_AR, name); arm->deformflag = ARM_DEF_VGROUP | ARM_DEF_ENVELOPE; arm->flag = ARM_COL_CUSTOM; /* custom bone-group colors */ arm->layer = 1; diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 3dfddbeed24..da4d9ea485c 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -455,9 +455,7 @@ Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode) { Brush *brush; - brush = BKE_libblock_alloc(bmain, ID_BR, name, 0); - - brush_init_data(&brush->id); + brush = BKE_id_new(bmain, ID_BR, name); brush->ob_mode = ob_mode; diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 8abf5515645..0ee0242866f 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -247,9 +247,7 @@ static void cachefile_handle_free(CacheFile *cache_file) void *BKE_cachefile_add(Main *bmain, const char *name) { - CacheFile *cache_file = BKE_libblock_alloc(bmain, ID_CF, name, 0); - - cache_file_init_data(&cache_file->id); + CacheFile *cache_file = BKE_id_new(bmain, ID_CF, name); return cache_file; } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index d54bebeafb9..3980a552855 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -213,9 +213,7 @@ void *BKE_camera_add(Main *bmain, const char *name) { Camera *cam; - cam = BKE_libblock_alloc(bmain, ID_CA, name, 0); - - camera_init_data(&cam->id); + cam = BKE_id_new(bmain, ID_CA, name); return cam; } diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index e49c0c63c84..9c4f46dac4b 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -203,7 +203,7 @@ static Collection *collection_add(Main *bmain, } /* Create new collection. */ - Collection *collection = BKE_libblock_alloc(bmain, ID_GR, name, 0); + Collection *collection = BKE_id_new(bmain, ID_GR, name); collection->color_tag = COLLECTION_COLOR_NONE; /* We increase collection user count when linking to Collections. */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index be82252159c..452f5835171 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -418,6 +418,7 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type) { Curve *cu; + /* We cannot use #BKE_id_new here as we need some custom initialization code. */ cu = BKE_libblock_alloc(bmain, ID_CU, name, 0); BKE_curve_init(cu, type); diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c index 3a35836d4d5..09f6fa3fe27 100644 --- a/source/blender/blenkernel/intern/hair.c +++ b/source/blender/blenkernel/intern/hair.c @@ -244,9 +244,7 @@ static void hair_random(Hair *hair) void *BKE_hair_add(Main *bmain, const char *name) { - Hair *hair = BKE_libblock_alloc(bmain, ID_HA, name, 0); - - hair_init_data(&hair->id); + Hair *hair = BKE_id_new(bmain, ID_HA, name); return hair; } diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index b93adf43751..5496da2d6f4 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -249,7 +249,7 @@ Key *BKE_key_add(Main *bmain, ID *id) /* common function */ Key *key; char *el; - key = BKE_libblock_alloc(bmain, ID_KE, "Key", 0); + key = BKE_id_new(bmain, ID_KE, "Key"); key->type = KEY_NORMAL; key->from = id; diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index bb62e4c2495..b7b1fc4daec 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -394,9 +394,7 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name) { Lattice *lt; - lt = BKE_libblock_alloc(bmain, ID_LT, name, 0); - - lattice_init_data(<->id); + lt = BKE_id_new(bmain, ID_LT, name); return lt; } diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index c8abe296f59..4780f0cf208 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -213,9 +213,7 @@ Light *BKE_light_add(Main *bmain, const char *name) { Light *la; - la = BKE_libblock_alloc(bmain, ID_LA, name, 0); - - light_init_data(&la->id); + la = BKE_id_new(bmain, ID_LA, name); return la; } diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c index debd9706b5e..31653a9a0ac 100644 --- a/source/blender/blenkernel/intern/lightprobe.c +++ b/source/blender/blenkernel/intern/lightprobe.c @@ -135,9 +135,7 @@ void *BKE_lightprobe_add(Main *bmain, const char *name) { LightProbe *probe; - probe = BKE_libblock_alloc(bmain, ID_LP, name, 0); - - lightprobe_init_data(&probe->id); + probe = BKE_id_new(bmain, ID_LP, name); return probe; } diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 70cb06185c9..965fdb53c09 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -297,9 +297,7 @@ Material *BKE_material_add(Main *bmain, const char *name) { Material *ma; - ma = BKE_libblock_alloc(bmain, ID_MA, name, 0); - - material_init_data(&ma->id); + ma = BKE_id_new(bmain, ID_MA, name); return ma; } diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 84f07b7bc60..75d6d36159e 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -210,9 +210,7 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name) { MetaBall *mb; - mb = BKE_libblock_alloc(bmain, ID_MB, name, 0); - - metaball_init_data(&mb->id); + mb = BKE_id_new(bmain, ID_MB, name); return mb; } diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 4486c9eb926..9765cd7fa1e 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -860,9 +860,7 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name) { Mesh *me; - me = BKE_libblock_alloc(bmain, ID_ME, name, 0); - - mesh_init_data(&me->id); + me = BKE_id_new(bmain, ID_ME, name); return me; } diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 36f9e47421b..854a421146d 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -921,7 +921,7 @@ static MovieClip *movieclip_alloc(Main *bmain, const char *name) { MovieClip *clip; - clip = BKE_libblock_alloc(bmain, ID_MC, name, 0); + clip = BKE_id_new(bmain, ID_MC, name); clip->aspx = clip->aspy = 1.0f; diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 6ab47f1b1f8..d401f263871 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1346,6 +1346,7 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name) name = get_obdata_defname(type); } + /* We cannot use #BKE_id_new here as we need some custom initialization code. */ ob = BKE_libblock_alloc(bmain, ID_OB, name, 0); /* We increase object user count when linking to Collections. */ diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index fd37ceed568..2488895c779 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -672,7 +672,7 @@ PaintCurve *BKE_paint_curve_add(Main *bmain, const char *name) { PaintCurve *pc; - pc = BKE_libblock_alloc(bmain, ID_PC, name, 0); + pc = BKE_id_new(bmain, ID_PC, name); return pc; } diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 8d091767709..329f11a57b9 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3858,7 +3858,7 @@ ParticleSettings *BKE_particlesettings_add(Main *bmain, const char *name) { ParticleSettings *part; - part = BKE_libblock_alloc(bmain, ID_PA, name, 0); + part = BKE_id_new(bmain, ID_PA, name); default_particle_settings(part); @@ -5009,7 +5009,8 @@ void psys_apply_hair_lattice(Depsgraph *depsgraph, Scene *scene, Object *ob, Par } /* Draw Engine */ -void (*BKE_particle_batch_cache_dirty_tag_cb)(ParticleSystem *psys, eMeshBatchDirtyMode mode) = NULL; +void (*BKE_particle_batch_cache_dirty_tag_cb)(ParticleSystem *psys, + eMeshBatchDirtyMode mode) = NULL; void (*BKE_particle_batch_cache_free_cb)(ParticleSystem *psys) = NULL; void BKE_particle_batch_cache_dirty_tag(ParticleSystem *psys, eMeshBatchDirtyMode mode) diff --git a/source/blender/blenkernel/intern/pointcloud.c b/source/blender/blenkernel/intern/pointcloud.c index a130117ded5..1233dc28b10 100644 --- a/source/b @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs