Fix cycles continuously updating when creating a driver for a scene property,

like driving integrator seed with #frame.

The scene drivers are evaluated continuously, which would be nice to fix but
complicated, now it compares the RNA value to see if it actually changed, and
avoids the update in that case, which is a useful optimization by itself.

(merged from tomato branch)
This commit is contained in:
Brecht Van Lommel
2012-09-06 11:35:16 +00:00
parent a18b60c0c8
commit f647348420

View File

@@ -1160,6 +1160,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in
/* set value - only for animatable numerical values */
if (RNA_property_animateable(&new_ptr, prop)) {
int array_len = RNA_property_array_length(&new_ptr, prop);
int written = FALSE;
if (array_len && array_index >= array_len) {
if (G.debug & G_DEBUG) {
@@ -1173,25 +1174,52 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN:
if (array_len)
RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value));
else
RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value));
if (array_len) {
if (RNA_property_boolean_get_index(&new_ptr, prop, array_index) != ANIMSYS_FLOAT_AS_BOOL(value)) {
RNA_property_boolean_set_index(&new_ptr, prop, array_index, ANIMSYS_FLOAT_AS_BOOL(value));
written = TRUE;
}
}
else {
if (RNA_property_boolean_get(&new_ptr, prop) != ANIMSYS_FLOAT_AS_BOOL(value)) {
RNA_property_boolean_set(&new_ptr, prop, ANIMSYS_FLOAT_AS_BOOL(value));
written = TRUE;
}
}
break;
case PROP_INT:
if (array_len)
RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value);
else
RNA_property_int_set(&new_ptr, prop, (int)value);
if (array_len) {
if (RNA_property_int_get_index(&new_ptr, prop, array_index) != (int)value) {
RNA_property_int_set_index(&new_ptr, prop, array_index, (int)value);
written = TRUE;
}
}
else {
if (RNA_property_int_get(&new_ptr, prop) != (int)value) {
RNA_property_int_set(&new_ptr, prop, (int)value);
written = TRUE;
}
}
break;
case PROP_FLOAT:
if (array_len)
RNA_property_float_set_index(&new_ptr, prop, array_index, value);
else
RNA_property_float_set(&new_ptr, prop, value);
if (array_len) {
if (RNA_property_float_get_index(&new_ptr, prop, array_index) != value) {
RNA_property_float_set_index(&new_ptr, prop, array_index, value);
written = TRUE;
}
}
else {
if (RNA_property_float_get(&new_ptr, prop) != value) {
RNA_property_float_set(&new_ptr, prop, value);
written = TRUE;
}
}
break;
case PROP_ENUM:
RNA_property_enum_set(&new_ptr, prop, (int)value);
if (RNA_property_enum_get(&new_ptr, prop) != (int)value) {
RNA_property_enum_set(&new_ptr, prop, (int)value);
written = TRUE;
}
break;
default:
/* nothing can be done here... so it is unsuccessful? */
@@ -1201,7 +1229,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in
/* RNA property update disabled for now - [#28525] [#28690] [#28774] [#28777] */
#if 0
/* buffer property update for later flushing */
if (RNA_property_update_check(prop)) {
if (written && RNA_property_update_check(prop)) {
short skip_updates_hack = 0;
/* optimization hacks: skip property updates for those properties
@@ -1221,7 +1249,7 @@ static short animsys_write_rna_setting(PointerRNA *ptr, char *path, int array_in
/* as long as we don't do property update, we still tag datablock
* as having been updated. this flag does not cause any updates to
* be run, it's for e.g. render engines to synchronize data */
if (new_ptr.id.data) {
if (written && new_ptr.id.data) {
ID *id = new_ptr.id.data;
id->flag |= LIB_ID_RECALC;
DAG_id_type_tag(G.main, GS(id->name));