Blender  V3.3
Classes | Macros | Functions | Variables
editmesh_undo.c File Reference
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
#include "DNA_key_types.h"
#include "DNA_layer_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BLI_array_utils.h"
#include "BLI_listbase.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
#include "BKE_key.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
#include "BKE_undo_system.h"
#include "DEG_depsgraph.h"
#include "ED_mesh.h"
#include "ED_object.h"
#include "ED_undo.h"
#include "ED_util.h"
#include "WM_api.h"
#include "WM_types.h"
#include "BLI_array_store.h"
#include "BLI_array_store_utils.h"
#include "BLI_task.h"

Go to the source code of this file.

Classes

struct  BArrayCustomData
 
struct  UndoMesh
 
struct  UMArrayData
 
struct  MeshUndoStep_Elem
 
struct  MeshUndoStep
 

Macros

#define USE_ARRAY_STORE
 
#define ARRAY_CHUNK_SIZE   256
 
#define USE_ARRAY_STORE_THREAD
 

Typedefs

Undo Conversion
typedef struct BArrayCustomData BArrayCustomData
 
typedef struct UndoMesh UndoMesh
 

Functions

static voidundomesh_from_editmesh (UndoMesh *um, BMEditMesh *em, Key *key, UndoMesh *um_ref)
 
static void undomesh_to_editmesh (UndoMesh *um, Object *ob, BMEditMesh *em)
 
static void undomesh_free_data (UndoMesh *um)
 
static Objecteditmesh_object_from_context (bContext *C)
 
Array Store Utilities
static UndoMesh ** mesh_undostep_reference_elems_from_objects (Object **object, int object_len)
 

Variables

static CLG_LogRef LOG = {"ed.undo.mesh"}
 

Implements ED Undo System

Note
This is similar for all edit-mode types.
typedef struct MeshUndoStep_Elem MeshUndoStep_Elem
 
typedef struct MeshUndoStep MeshUndoStep
 
static bool mesh_undosys_poll (bContext *C)
 
static bool mesh_undosys_step_encode (struct bContext *C, struct Main *bmain, UndoStep *us_p)
 
static void mesh_undosys_step_decode (struct bContext *C, struct Main *bmain, UndoStep *us_p, const eUndoStepDir UNUSED(dir), bool UNUSED(is_final))
 
static void mesh_undosys_step_free (UndoStep *us_p)
 
static void mesh_undosys_foreach_ID_ref (UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
 
void ED_mesh_undosys_type (UndoType *ut)
 

Array Store

struct {
   struct BArrayStore_AtSize   bs_stride
 
   int   users
 
   ListBase   local_links
 
   TaskPool *   task_pool
 
um_arraystore = {{NULL}}
 
static void um_arraystore_cd_compact (struct CustomData *cdata, const size_t data_len, bool create, const BArrayCustomData *bcd_reference, BArrayCustomData **r_bcd_first)
 
static void um_arraystore_cd_expand (const BArrayCustomData *bcd, struct CustomData *cdata, const size_t data_len)
 
static void um_arraystore_cd_free (BArrayCustomData *bcd)
 
static void um_arraystore_compact_ex (UndoMesh *um, const UndoMesh *um_ref, bool create)
 
static void um_arraystore_compact (UndoMesh *um, const UndoMesh *um_ref)
 
static void um_arraystore_compact_with_info (UndoMesh *um, const UndoMesh *um_ref)
 
static void um_arraystore_compact_cb (TaskPool *__restrict UNUSED(pool), void *taskdata)
 
static void um_arraystore_expand_clear (UndoMesh *um)
 
static void um_arraystore_expand (UndoMesh *um)
 
static void um_arraystore_free (UndoMesh *um)
 

Macro Definition Documentation

◆ ARRAY_CHUNK_SIZE

#define ARRAY_CHUNK_SIZE   256

Definition at line 54 of file editmesh_undo.c.

◆ USE_ARRAY_STORE

#define USE_ARRAY_STORE

Definition at line 42 of file editmesh_undo.c.

◆ USE_ARRAY_STORE_THREAD

#define USE_ARRAY_STORE_THREAD

Definition at line 56 of file editmesh_undo.c.

Typedef Documentation

◆ BArrayCustomData

◆ MeshUndoStep

typedef struct MeshUndoStep MeshUndoStep

◆ MeshUndoStep_Elem

◆ UndoMesh

typedef struct UndoMesh UndoMesh

Function Documentation

◆ ED_mesh_undosys_type()

void ED_mesh_undosys_type ( struct UndoType ut)

◆ editmesh_object_from_context()

static Object* editmesh_object_from_context ( bContext C)
static

◆ mesh_undostep_reference_elems_from_objects()

static UndoMesh** mesh_undostep_reference_elems_from_objects ( Object **  object,
int  object_len 
)
static

Create an array of UndoMesh from objects.

where each element in the resulting array is the most recently created undo-mesh for the object's mesh. When no undo-mesh can be found that array index is NULL.

This is used for de-duplicating memory between undo steps, failure to find the undo step will store a full duplicate in memory. define DEBUG_PRINT to check memory is de-duplicating as expected.

Definition at line 535 of file editmesh_undo.c.

References BLI_assert, BLI_ghash_free(), BLI_ghash_insert(), BLI_ghash_len(), BLI_ghash_popkey(), BLI_ghash_ptr_new_ex(), Mesh::id, UndoMesh::local_prev, UndoMesh::me, MEM_callocN, MEM_freeN, NULL, POINTER_FROM_INT, ID::session_uuid, and um_arraystore.

Referenced by mesh_undosys_step_encode().

◆ mesh_undosys_foreach_ID_ref()

static void mesh_undosys_foreach_ID_ref ( UndoStep us_p,
UndoTypeForEachIDRefFn  foreach_ID_ref_fn,
void user_data 
)
static

◆ mesh_undosys_poll()

static bool mesh_undosys_poll ( bContext C)
static

Definition at line 764 of file editmesh_undo.c.

References C, editmesh_object_from_context(), and NULL.

Referenced by ED_mesh_undosys_type(), and mesh_undosys_step_decode().

◆ mesh_undosys_step_decode()

static void mesh_undosys_step_decode ( struct bContext C,
struct Main bmain,
UndoStep us_p,
const eUndoStepDir   UNUSEDdir,
bool   UNUSEDis_final 
)
static

◆ mesh_undosys_step_encode()

static bool mesh_undosys_step_encode ( struct bContext C,
struct Main bmain,
UndoStep us_p 
)
static

◆ mesh_undosys_step_free()

static void mesh_undosys_step_free ( UndoStep us_p)
static

◆ um_arraystore_cd_compact()

static void um_arraystore_cd_compact ( struct CustomData cdata,
const size_t  data_len,
bool  create,
const BArrayCustomData bcd_reference,
BArrayCustomData **  r_bcd_first 
)
static

◆ um_arraystore_cd_expand()

static void um_arraystore_cd_expand ( const BArrayCustomData bcd,
struct CustomData cdata,
const size_t  data_len 
)
static
Note
There is no room for data going out of sync here. The layers and the states are stored together so this can be kept working.

Definition at line 262 of file editmesh_undo.c.

References BLI_array_store_state_data_get_alloc(), BLI_assert, CustomData_sizeof(), CustomDataLayer::data, CustomData::layers, BArrayCustomData::next, NULL, BArrayCustomData::states, BArrayCustomData::states_len, stride, BArrayCustomData::type, CustomDataLayer::type, and UNUSED_VARS_NDEBUG.

Referenced by um_arraystore_expand().

◆ um_arraystore_cd_free()

static void um_arraystore_cd_free ( BArrayCustomData bcd)
static

◆ um_arraystore_compact()

static void um_arraystore_compact ( UndoMesh um,
const UndoMesh um_ref 
)
static

Move data from allocated arrays to de-duplicated states and clear arrays.

Definition at line 371 of file editmesh_undo.c.

References um_arraystore_compact_ex().

Referenced by um_arraystore_compact_with_info().

◆ um_arraystore_compact_cb()

static void um_arraystore_compact_cb ( TaskPool *__restrict   UNUSEDpool,
void taskdata 
)
static

◆ um_arraystore_compact_ex()

static void um_arraystore_compact_ex ( UndoMesh um,
const UndoMesh um_ref,
bool  create 
)
static

◆ um_arraystore_compact_with_info()

static void um_arraystore_compact_with_info ( UndoMesh um,
const UndoMesh um_ref 
)
static

◆ um_arraystore_expand()

static void um_arraystore_expand ( UndoMesh um)
static

◆ um_arraystore_expand_clear()

static void um_arraystore_expand_clear ( UndoMesh um)
static

Remove data we only expanded for temporary use.

Definition at line 434 of file editmesh_undo.c.

References NULL, UMArrayData::um, and um_arraystore_compact_ex().

Referenced by undomesh_to_editmesh().

◆ um_arraystore_free()

static void um_arraystore_free ( UndoMesh um)
static

◆ undomesh_free_data()

static void undomesh_free_data ( UndoMesh um)
static

◆ undomesh_from_editmesh()

static void* undomesh_from_editmesh ( UndoMesh um,
BMEditMesh em,
Key key,
UndoMesh um_ref 
)
static
Parameters
um_refThe reference to use for de-duplicating memory between undo-steps.

Definition at line 576 of file editmesh_undo.c.

References BKE_id_copy_ex(), BLI_array_is_zeroed, BLI_assert, BLI_task_pool_work_and_wait(), BMEditMesh::bm, BM_mesh_bm_to_me(), Key::id, Mesh::key, LIB_ID_COPY_LOCALIZE, LIB_ID_COPY_NO_ANIMDATA, UndoMesh::me, NULL, UMArrayData::um, and um_arraystore.

Referenced by mesh_undosys_step_encode().

◆ undomesh_to_editmesh()

static void undomesh_to_editmesh ( UndoMesh um,
Object ob,
BMEditMesh em 
)
static

Variable Documentation

◆ bs_stride

struct BArrayStore_AtSize bs_stride

Definition at line 108 of file editmesh_undo.c.

◆ local_links

ListBase local_links

A list of UndoMesh items ordered from oldest to newest used to access previous undo data for a mesh.

Definition at line 129 of file editmesh_undo.c.

◆ LOG

CLG_LogRef LOG = {"ed.undo.mesh"}
static

We only need this locally.

Definition at line 64 of file editmesh_undo.c.

Referenced by mesh_undosys_step_decode().

◆ task_pool

TaskPool* task_pool

◆ 

struct { ... } um_arraystore

◆ users

int users

Definition at line 123 of file editmesh_undo.c.