Commit: 8d22d5a2a9b471354bbf2a9a0a0791d40900058d Author: Bastien Montagne Date: Wed Jun 14 17:08:20 2017 +0200 Branches: id_copy_refactor https://developer.blender.org/rB8d22d5a2a9b471354bbf2a9a0a0791d40900058d
Layout initial ideas/code structure of new ID copying. =================================================================== M source/blender/blenkernel/BKE_library.h M source/blender/blenkernel/intern/library.c M source/blender/blenloader/intern/readfile.c M source/blender/blenloader/intern/writefile.c M source/blender/makesdna/DNA_ID.h =================================================================== diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 258dcc84449..99aefad4388 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -87,6 +87,7 @@ void BKE_id_make_local_generic(struct Main *bmain, struct ID *id, const bool id_ bool id_make_local(struct Main *bmain, struct ID *id, const bool test, const bool force_local); bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop); bool id_copy(struct Main *bmain, const struct ID *id, struct ID **newid, bool test); +bool BKE_id_copy(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag, const bool test); void id_sort_by_name(struct ListBase *lb, struct ID *id); void BKE_id_expand_local(struct Main *bmain, struct ID *id); void BKE_id_copy_ensure_local(struct Main *bmain, const struct ID *old_id, struct ID *new_id); diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 2ea7342ff34..86a6886fb88 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -485,13 +485,19 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local) } /** - * Invokes the appropriate copy method for the block and returns the result in - * newid, unless test. Returns true if the block can be copied. + * Genric entry point for copying a datablock (new API). + * + * \param bmain Main database, may be NULL only if LIB_ID_COPY_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 test If set, do not do any copy, just test whether copy is supported. + * \return False when copying that ID type is not supported, true otherwise. */ -bool id_copy(Main *bmain, const ID *id, ID **newid, bool test) +bool BKE_id_copy(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test) { - if (!test) { - *newid = NULL; + if (!test && (flag & LIB_ID_COPY_NO_ALLOCATE) == 0) { + *r_newid = NULL; } /* conventions: @@ -499,85 +505,85 @@ bool id_copy(Main *bmain, const ID *id, ID **newid, bool test) * - id.us of the new ID is set to 1 */ switch ((ID_Type)GS(id->name)) { case ID_OB: - if (!test) *newid = (ID *)BKE_object_copy(bmain, (Object *)id); + if (!test) *r_newid = (ID *)BKE_object_copy(bmain, (Object *)id); return true; case ID_ME: - if (!test) *newid = (ID *)BKE_mesh_copy(bmain, (Mesh *)id); + if (!test) *r_newid = (ID *)BKE_mesh_copy(bmain, (Mesh *)id); return true; case ID_CU: - if (!test) *newid = (ID *)BKE_curve_copy(bmain, (Curve *)id); + if (!test) *r_newid = (ID *)BKE_curve_copy(bmain, (Curve *)id); return true; case ID_MB: - if (!test) *newid = (ID *)BKE_mball_copy(bmain, (MetaBall *)id); + if (!test) *r_newid = (ID *)BKE_mball_copy(bmain, (MetaBall *)id); return true; case ID_MA: - if (!test) *newid = (ID *)BKE_material_copy(bmain, (Material *)id); + if (!test) *r_newid = (ID *)BKE_material_copy(bmain, (Material *)id); return true; case ID_TE: - if (!test) *newid = (ID *)BKE_texture_copy(bmain, (Tex *)id); + if (!test) *r_newid = (ID *)BKE_texture_copy(bmain, (Tex *)id); return true; case ID_IM: - if (!test) *newid = (ID *)BKE_image_copy(bmain, (Image *)id); + if (!test) *r_newid = (ID *)BKE_image_copy(bmain, (Image *)id); return true; case ID_LT: - if (!test) *newid = (ID *)BKE_lattice_copy(bmain, (Lattice *)id); + if (!test) *r_newid = (ID *)BKE_lattice_copy(bmain, (Lattice *)id); return true; case ID_LA: - if (!test) *newid = (ID *)BKE_lamp_copy(bmain, (Lamp *)id); + if (!test) *r_newid = (ID *)BKE_lamp_copy(bmain, (Lamp *)id); return true; case ID_SPK: - if (!test) *newid = (ID *)BKE_speaker_copy(bmain, (Speaker *)id); + if (!test) *r_newid = (ID *)BKE_speaker_copy(bmain, (Speaker *)id); return true; case ID_CA: - if (!test) *newid = (ID *)BKE_camera_copy(bmain, (Camera *)id); + if (!test) *r_newid = (ID *)BKE_camera_copy(bmain, (Camera *)id); return true; case ID_KE: - if (!test) *newid = (ID *)BKE_key_copy(bmain, (Key *)id); + if (!test) *r_newid = (ID *)BKE_key_copy(bmain, (Key *)id); return true; case ID_WO: - if (!test) *newid = (ID *)BKE_world_copy(bmain, (World *)id); + if (!test) *r_newid = (ID *)BKE_world_copy(bmain, (World *)id); return true; case ID_TXT: - if (!test) *newid = (ID *)BKE_text_copy(bmain, (Text *)id); + if (!test) *r_newid = (ID *)BKE_text_copy(bmain, (Text *)id); return true; case ID_GR: - if (!test) *newid = (ID *)BKE_group_copy(bmain, (Group *)id); + if (!test) *r_newid = (ID *)BKE_group_copy(bmain, (Group *)id); return true; case ID_AR: - if (!test) *newid = (ID *)BKE_armature_copy(bmain, (bArmature *)id); + if (!test) *r_newid = (ID *)BKE_armature_copy(bmain, (bArmature *)id); return true; case ID_AC: - if (!test) *newid = (ID *)BKE_action_copy(bmain, (bAction *)id); + if (!test) *r_newid = (ID *)BKE_action_copy(bmain, (bAction *)id); return true; case ID_NT: - if (!test) *newid = (ID *)ntreeCopyTree(bmain, (bNodeTree *)id); + if (!test) *r_newid = (ID *)ntreeCopyTree(bmain, (bNodeTree *)id); return true; case ID_BR: - if (!test) *newid = (ID *)BKE_brush_copy(bmain, (Brush *)id); + if (!test) *r_newid = (ID *)BKE_brush_copy(bmain, (Brush *)id); return true; case ID_PA: - if (!test) *newid = (ID *)BKE_particlesettings_copy(bmain, (ParticleSettings *)id); + if (!test) *r_newid = (ID *)BKE_particlesettings_copy(bmain, (ParticleSettings *)id); return true; case ID_GD: - if (!test) *newid = (ID *)BKE_gpencil_data_duplicate(bmain, (bGPdata *)id, false); + if (!test) *r_newid = (ID *)BKE_gpencil_data_duplicate(bmain, (bGPdata *)id, false); return true; case ID_MC: - if (!test) *newid = (ID *)BKE_movieclip_copy(bmain, (MovieClip *)id); + if (!test) *r_newid = (ID *)BKE_movieclip_copy(bmain, (MovieClip *)id); return true; case ID_MSK: - if (!test) *newid = (ID *)BKE_mask_copy(bmain, (Mask *)id); + if (!test) *r_newid = (ID *)BKE_mask_copy(bmain, (Mask *)id); return true; case ID_LS: - if (!test) *newid = (ID *)BKE_linestyle_copy(bmain, (FreestyleLineStyle *)id); + if (!test) *r_newid = (ID *)BKE_linestyle_copy(bmain, (FreestyleLineStyle *)id); return true; case ID_PAL: - if (!test) *newid = (ID *)BKE_palette_copy(bmain, (Palette *)id); + if (!test) *r_newid = (ID *)BKE_palette_copy(bmain, (Palette *)id); return true; case ID_PC: - if (!test) *newid = (ID *)BKE_paint_curve_copy(bmain, (PaintCurve *)id); + if (!test) *r_newid = (ID *)BKE_paint_curve_copy(bmain, (PaintCurve *)id); return true; case ID_CF: - if (!test) *newid = (ID *)BKE_cachefile_copy(bmain, (CacheFile *)id); + if (!test) *r_newid = (ID *)BKE_cachefile_copy(bmain, (CacheFile *)id); return true; case ID_SCE: case ID_LI: @@ -590,10 +596,19 @@ bool id_copy(Main *bmain, const ID *id, ID **newid, bool test) case ID_IP: return false; /* deprecated */ } - + return false; } +/** + * Invokes the appropriate copy method for the block and returns the result in + * newid, unless test. Returns true if the block can be copied. + */ +bool id_copy(Main *bmain, const ID *id, ID **newid, bool test) +{ + return BKE_id_copy(bmain, id, newid, 0, test); +} + /** Does *not* set ID->newid pointer. */ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop) { diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index f224f0b5633..3c38a122787 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -8221,6 +8221,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short return blo_nextbhead(fd, bhead); id->tag = tag | LIB_TAG_NEED_LINK; + id->copy_tag = 0; id->lib = main->curlib; id->us = ID_FAKE_USERS(id); id->icon_id = 0; diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c index ee9665dc834..236fe2289aa 100644 --- a/source/blender/blenloader/intern/writefile.c +++ b/source/blender/blenloader/intern/writefile.c @@ -3841,6 +3841,9 @@ static bool write_file_handle( } for (; id; id = id->next) { + /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */ + BLI_assert(id->copy_tag == 0); + switch ((ID_Type)GS(id->name)) { case ID_WM: write_windowmanager(wd, (wmWindowManager *)id); diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index da0f505c4f3..8b56481b4da 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -132,6 +132,12 @@ typedef struct ID { int us; int icon_id; IDProperty *properties; + /** + * LIB_ID_COPY_... options (should be NULL/empty when ID is not temp/runtime-only one). + * Also used by freeing code to know what to do (unlink used IDs, remove from main, ...). + */ + int copy_tag; + int pad_i1; } ID; /** @@ -352,6 +358,30 @@ enum { LIB_TAG_ID_RECALC_ALL = (LIB_TAG_ID_RECALC | LIB_TAG_ID_RECALC_DATA), }; +/** + * id->copy_tag (runtime-only). + * + * Those flags keep track of special options used when copying that ID from another one (or, in some case, + * from special creation options). + * + * They are mostly here for two things: + * * Detect attempt to write in .blend file temp/runtime only IDs (id->copy_tag should be void for regular datablocks). + * * Simplify freeing, since they should tell whether ID has to be removed from main, whether it should be unlinked, etc. + */ +enum { + /* *** Generic options (should be handled by all ID types copying). *** */ + /* Create copy outside of any main database - similar to 'localize' functions of materials etc. */ + LIB_ID_COPY_NO_MAIN = 1 << 0, + LIB_ID_COPY_NO_USER_REFCOUNT = 1 << 1, /* Do not affect user refcount of datablocks used @@ 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