Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/intern/bmesh_log.c
| Show First 20 Lines • Show All 459 Lines • ▼ Show 20 Lines | BMLog *BM_log_create(BMesh *bm) | ||||
| log->elem_to_id = BLI_ghash_ptr_new_ex(AT, bm->totvert + bm->totface); | log->elem_to_id = BLI_ghash_ptr_new_ex(AT, bm->totvert + bm->totface); | ||||
| /* Assign IDs to all existing vertices and faces */ | /* Assign IDs to all existing vertices and faces */ | ||||
| bm_log_assign_ids(bm, log); | bm_log_assign_ids(bm, log); | ||||
| return log; | return log; | ||||
| } | } | ||||
| void BM_log_cleanup_entry(BMLogEntry *entry) | |||||
| { | |||||
| BMLog *log = entry->log; | |||||
| if (log) { | |||||
| /* Take all used IDs */ | |||||
| bm_log_id_ghash_retake(log->unused_ids, entry->deleted_verts); | |||||
| bm_log_id_ghash_retake(log->unused_ids, entry->deleted_faces); | |||||
| bm_log_id_ghash_retake(log->unused_ids, entry->added_verts); | |||||
| bm_log_id_ghash_retake(log->unused_ids, entry->added_faces); | |||||
| bm_log_id_ghash_retake(log->unused_ids, entry->modified_verts); | |||||
| /* delete entries to avoid releasing ids in node cleanup */ | |||||
| BLI_ghash_clear(entry->deleted_verts, NULL, NULL); | |||||
| BLI_ghash_clear(entry->deleted_faces, NULL, NULL); | |||||
| BLI_ghash_clear(entry->added_verts, NULL, NULL); | |||||
| BLI_ghash_clear(entry->added_faces, NULL, NULL); | |||||
| BLI_ghash_clear(entry->modified_verts, NULL, NULL); | |||||
| } | |||||
| } | |||||
| /* Allocate and initialize a new BMLog using existing BMLogEntries | /* Allocate and initialize a new BMLog using existing BMLogEntries | ||||
| * | * | ||||
| * The 'entry' should be the last entry in the BMLog. Its prev pointer | * The 'entry' should be the last entry in the BMLog. Its prev pointer | ||||
| * will be followed back to find the first entry. | * will be followed back to find the first entry. | ||||
| * | * | ||||
| * The unused IDs field of the log will be initialized by taking all | * The unused IDs field of the log will be initialized by taking all | ||||
| * keys from all GHashes in the log entry. | * keys from all GHashes in the log entry. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | if (!log) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (!entry->prev) { | if (!entry->prev) { | ||||
| /* Release IDs of elements that are deleted by this | /* Release IDs of elements that are deleted by this | ||||
| * entry. Since the entry is at the beginning of the undo | * entry. Since the entry is at the beginning of the undo | ||||
| * stack, and it's being deleted, those elements can never be | * stack, and it's being deleted, those elements can never be | ||||
| * restored. Their IDs can go back into the pool. */ | * restored. Their IDs can go back into the pool. */ | ||||
| bm_log_id_ghash_release(log, entry->deleted_faces); | |||||
| bm_log_id_ghash_release(log, entry->deleted_verts); | /* This would never happen usually since first entry of log is | ||||
| * usually dyntopo enable, which, when reverted will free the log | |||||
| * completely. However, it is possible have a stroke instead of | |||||
| * dyntopo enable as first entry if nodes have been cleaned up | |||||
| * after sculpting on a different object than A, B. | |||||
| * | |||||
| * The steps are: | |||||
| * A dyntopo enable - sculpt | |||||
| * B dyntopo enable - sculpt - undo (A objects operators get cleaned up) | |||||
| * A sculpt (now A's log has a sculpt operator as first entry) | |||||
| * | |||||
| * Causing a cleanup at this point will call the code below, however | |||||
| * this will invalidate the state of the log since the deleted vertices | |||||
| * have been reclaimed already on step 2 (see BM_log_cleanup_entry) | |||||
| * | |||||
| * Also, design wise, a first entry should not have any deleted vertices since it | |||||
| * should not have anything to delete them -from- | |||||
| */ | |||||
| //bm_log_id_ghash_release(log, entry->deleted_faces); | |||||
| //bm_log_id_ghash_release(log, entry->deleted_verts); | |||||
| } | } | ||||
| else if (!entry->next) { | else if (!entry->next) { | ||||
| /* Release IDs of elements that are added by this entry. Since | /* Release IDs of elements that are added by this entry. Since | ||||
| * the entry is at the end of the undo stack, and it's being | * the entry is at the end of the undo stack, and it's being | ||||
| * deleted, those elements can never be restored. Their IDs | * deleted, those elements can never be restored. Their IDs | ||||
| * can go back into the pool. */ | * can go back into the pool. */ | ||||
| bm_log_id_ghash_release(log, entry->added_faces); | bm_log_id_ghash_release(log, entry->added_faces); | ||||
| bm_log_id_ghash_release(log, entry->added_verts); | bm_log_id_ghash_release(log, entry->added_verts); | ||||
| ▲ Show 20 Lines • Show All 349 Lines • Show Last 20 Lines | |||||