Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/library.c
| Show First 20 Lines • Show All 1,406 Lines • ▼ Show 20 Lines | void *BKE_id_new_nomain(const short type, const char *name) | ||||
| return id; | return id; | ||||
| } | } | ||||
| void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) | void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) | ||||
| { | { | ||||
| ID *new_id = *r_newid; | ID *new_id = *r_newid; | ||||
| /* Grrrrrrrrr... Not adding 'root' nodetrees to bmain.... grrrrrrrrrrrrrrrrrrrr! */ | /* Grrrrrrrrr... Not adding 'root' nodetrees to bmain.... grrrrrrrrrrrrrrrrrrrr! */ | ||||
| /* This is taken from original ntree copy code, might be weak actually? */ | /* This is taken from original ntree copy code, might be weak actually? */ | ||||
| const bool use_nodetree_alloc_exception = ((GS(id->name) == ID_NT) && (bmain != NULL) && | const bool use_nodetree_alloc_exception = ((GS(id->name) == ID_NT) && (bmain != NULL) && | ||||
| (BLI_findindex(&bmain->nodetrees, id) < 0)); | (BLI_findindex(&bmain->nodetrees, id) < 0)); | ||||
mont29: Probably as a separate commit, but could be interesting to use that new `LIB_PRIVATE_DATA` flag… | |||||
| /* The id->flag bits to copy over. */ | |||||
| const int copy_flag_mask = LIB_PRIVATE_DATA; | |||||
| BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL); | BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || bmain != NULL); | ||||
| BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0); | BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) != 0 || (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0); | ||||
| BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0); | BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) != 0); | ||||
| /* Never implicitly copy shapekeys when generating temp data outside of Main database. */ | /* Never implicitly copy shapekeys when generating temp data outside of Main database. */ | ||||
| BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_COPY_SHAPEKEY) == 0); | BLI_assert((flag & LIB_ID_CREATE_NO_MAIN) == 0 || (flag & LIB_ID_COPY_SHAPEKEY) == 0); | ||||
| if ((flag & LIB_ID_CREATE_NO_ALLOCATE) != 0) { | if ((flag & LIB_ID_CREATE_NO_ALLOCATE) != 0) { | ||||
| /* r_newid already contains pointer to allocated memory. */ | /* r_newid already contains pointer to allocated memory. */ | ||||
| Show All 15 Lines | void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag) | ||||
| const size_t id_offset = sizeof(ID); | const size_t id_offset = sizeof(ID); | ||||
| if ((int)id_len - (int)id_offset > 0) { /* signed to allow neg result */ /* XXX ????? */ | if ((int)id_len - (int)id_offset > 0) { /* signed to allow neg result */ /* XXX ????? */ | ||||
| const char *cp = (const char *)id; | const char *cp = (const char *)id; | ||||
| char *cpn = (char *)new_id; | char *cpn = (char *)new_id; | ||||
| memcpy(cpn + id_offset, cp + id_offset, id_len - id_offset); | memcpy(cpn + id_offset, cp + id_offset, id_len - id_offset); | ||||
| } | } | ||||
| new_id->flag = (new_id->flag & ~copy_flag_mask) | (id->flag & copy_flag_mask); | |||||
Not Done Inline ActionsOn one hand am a bit wary of putting that in the generic ID management code, on the other hand it makes total sense... Maybe hide it behind the use_nodetree_alloc_exception condition, to be 100% clear that this is a specific case? mont29: On one hand am a bit wary of putting that in the generic ID management code, on the other hand… | |||||
Done Inline ActionsI think it's not "specific" - it's just the first case when a flag has to be copied too. angavrilov: I think it's not "specific" - it's just the first case when a flag has to be copied too. | |||||
| if (id->properties) { | if (id->properties) { | ||||
| new_id->properties = IDP_CopyProperty_ex(id->properties, flag); | new_id->properties = IDP_CopyProperty_ex(id->properties, flag); | ||||
| } | } | ||||
| /* XXX Again... We need a way to control what we copy in a much more refined way. | /* XXX Again... We need a way to control what we copy in a much more refined way. | ||||
| * We cannot always copy this, some internal copying will die on it! */ | * We cannot always copy this, some internal copying will die on it! */ | ||||
| /* For now, upper level code will have to do that itself when required. */ | /* For now, upper level code will have to do that itself when required. */ | ||||
| #if 0 | #if 0 | ||||
| ▲ Show 20 Lines • Show All 981 Lines • Show Last 20 Lines | |||||
Probably as a separate commit, but could be interesting to use that new LIB_PRIVATE_DATA flag instead of the BLI_findindex() call here? And rename it to use_private_data_alloc e.g.