Add accumulated recalc flags to IDs.

Those accumulated flags get cleared every time an undo step is written
to memfile.

Preliminary work for undo-speedup.

Part of T60695/D6580.
This commit is contained in:
Bastien Montagne 2020-03-17 12:09:06 +01:00
parent 055863d9c1
commit b02a25b7e1
3 changed files with 28 additions and 1 deletions

View File

@ -703,7 +703,7 @@ void IDP_WriteProperty(const IDProperty *prop, void *wd)
IDP_WriteProperty_OnlyData(prop, wd);
}
static void write_iddata(void *wd, const ID *id)
static void write_iddata(WriteData *wd, ID *id)
{
/* ID_WM's id->properties are considered runtime only, and never written in .blend file. */
if (id->properties && !ELEM(GS(id->name), ID_WM)) {
@ -731,6 +731,11 @@ static void write_iddata(void *wd, const ID *id)
}
}
}
/* Clear the accumulated recalc flags in case of undo step saving. */
if (wd->use_memfile) {
id->recalc_undo_accumulated = 0;
}
}
static void write_previews(WriteData *wd, const PreviewImage *prv_orig)
@ -1131,6 +1136,11 @@ static void write_nodetree_nolib(WriteData *wd, bNodeTree *ntree)
for (sock = ntree->outputs.first; sock; sock = sock->next) {
write_node_socket_interface(wd, sock);
}
/* Clear the accumulated recalc flags in case of undo step saving. */
if (wd->use_memfile) {
ntree->id.recalc_undo_accumulated = 0;
}
}
/**
@ -2425,6 +2435,11 @@ static void write_collection_nolib(WriteData *wd, Collection *collection)
for (CollectionChild *child = collection->children.first; child; child = child->next) {
writestruct(wd, DATA, CollectionChild, 1, child);
}
/* Clear the accumulated recalc flags in case of undo step saving. */
if (wd->use_memfile) {
collection->id.recalc_undo_accumulated = 0;
}
}
static void write_collection(WriteData *wd, Collection *collection)

View File

@ -814,12 +814,16 @@ void DEG_ids_check_recalc(
static void deg_graph_clear_id_recalc_flags(ID *id)
{
/* Keep incremental track of used recalc flags, to get proper update when undoing. */
id->recalc_undo_accumulated |= id->recalc;
id->recalc &= ~ID_RECALC_ALL;
bNodeTree *ntree = ntreeFromID(id);
/* Clear embedded node trees too. */
if (ntree) {
ntree->id.recalc_undo_accumulated |= ntree->id.recalc;
ntree->id.recalc &= ~ID_RECALC_ALL;
}
/* XXX And what about scene's master collection here? */
}
void DEG_ids_clear_recalc(Main *UNUSED(bmain), Depsgraph *depsgraph)

View File

@ -245,6 +245,12 @@ typedef struct ID {
int us;
int icon_id;
int recalc;
/**
* Used by undo code. Value of recalc is stored there when reading an ID from memfile, and not
* touched by anything, which means it can be used as 'reference' recalc value for the next undo
* step, when going backward (i.e. actual undo, redo can just use recalc value directly).
*/
int recalc_undo_accumulated;
/**
* A session-wide unique identifier for a given ID, that remain the same across potential
@ -252,6 +258,8 @@ typedef struct ID {
*/
unsigned int session_uuid;
char _pad[4];
IDProperty *properties;
/** Reference linked ID which this one overrides. */