Fix "doversion" of collection settings for collections

For collections we do not need a doversion as granular as the scene one.
However if a new engine settings is added we need to take care of it.
This commit is contained in:
Dalai Felinto 2017-05-04 11:25:03 +02:00
parent 930f0ba702
commit e778be9e20
3 changed files with 47 additions and 14 deletions

View File

@ -115,7 +115,8 @@ struct IDProperty *BKE_scene_collection_engine_get(struct Scene *scene, const in
void BKE_layer_collection_engine_settings_callback_register(struct Main *bmain, const char *engine_name, CollectionEngineSettingsCB func);
void BKE_layer_collection_engine_settings_callback_free(void);
void BKE_layer_collection_engine_settings_create(struct IDProperty *root);
void BKE_layer_collection_engine_settings_validate(struct Scene *scene);
void BKE_layer_collection_engine_settings_validate_scene(struct Scene *scene);
void BKE_layer_collection_engine_settings_validate_collection(struct LayerCollection *lc);
void BKE_collection_engine_property_add_float(struct IDProperty *props, const char *name, float value);
void BKE_collection_engine_property_add_int(struct IDProperty *props, const char *name, int value);

View File

@ -1278,17 +1278,29 @@ void BKE_layer_collection_engine_settings_create(IDProperty *root)
* Reference of IDProperty group scene collection settings
* Used when reading blendfiles, to see if there is any missing settings.
*/
static IDProperty *root_reference = NULL;
static struct {
IDProperty *scene;
IDProperty *layer_collection;
} root_reference = {
.scene = NULL,
.layer_collection = NULL,
};
/**
* Free the reference scene collection settings IDProperty group.
*/
static void layer_collection_engine_settings_validate_init(void)
{
if (root_reference == NULL) {
IDPropertyTemplate val = {0};
root_reference = IDP_New(IDP_GROUP, &val, ROOT_PROP);
BKE_layer_collection_engine_settings_create(root_reference);
IDPropertyTemplate val = {0};
if (root_reference.scene == NULL) {
root_reference.scene = IDP_New(IDP_GROUP, &val, ROOT_PROP);
collection_engine_settings_init(root_reference.scene, true);
}
if (root_reference.layer_collection == NULL) {
root_reference.layer_collection = IDP_New(IDP_GROUP, &val, ROOT_PROP);
collection_engine_settings_init(root_reference.layer_collection, false);
}
}
@ -1297,19 +1309,25 @@ static void layer_collection_engine_settings_validate_init(void)
*/
static void layer_collection_engine_settings_validate_free(void)
{
if (root_reference != NULL) {
IDP_FreeProperty(root_reference);
MEM_freeN(root_reference);
root_reference = NULL;
if (root_reference.scene != NULL) {
IDP_FreeProperty(root_reference.scene);
MEM_freeN(root_reference.scene);
root_reference.scene = NULL;
}
if (root_reference.layer_collection != NULL) {
IDP_FreeProperty(root_reference.layer_collection);
MEM_freeN(root_reference.layer_collection);
root_reference.layer_collection = NULL;
}
}
/**
* Make sure Scene has all required collection settings.
*/
void BKE_layer_collection_engine_settings_validate(Scene *scene)
void BKE_layer_collection_engine_settings_validate_scene(Scene *scene)
{
if (root_reference == NULL) {
if (root_reference.scene == NULL) {
layer_collection_engine_settings_validate_init();
}
@ -1319,10 +1337,23 @@ void BKE_layer_collection_engine_settings_validate(Scene *scene)
BKE_layer_collection_engine_settings_create(scene->collection_properties);
}
else {
IDP_MergeGroup(scene->collection_properties, root_reference, false);
IDP_MergeGroup(scene->collection_properties, root_reference.scene, false);
}
}
/**
* Maker sure LayerCollection has all required collection settings.
*/
void BKE_layer_collection_engine_settings_validate_collection(LayerCollection *lc)
{
if (root_reference.layer_collection == NULL) {
layer_collection_engine_settings_validate_init();
}
BLI_assert(lc->properties != NULL);
IDP_MergeGroup(lc->properties, root_reference.layer_collection, false);
}
/* ---------------------------------------------------------------------- */
/* Iterators */

View File

@ -6027,6 +6027,7 @@ static void direct_link_layer_collections(FileData *fd, ListBase *lb)
if (lc->properties) {
lc->properties = newdataadr(fd, lc->properties);
IDP_DirectLinkGroup_OrFree(&lc->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
BKE_layer_collection_engine_settings_validate_collection(lc);
}
lc->properties_evaluated = NULL;
@ -6313,7 +6314,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
sce->collection_properties = newdataadr(fd, sce->collection_properties);
IDP_DirectLinkGroup_OrFree(&sce->collection_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
BKE_layer_collection_engine_settings_validate(sce);
BKE_layer_collection_engine_settings_validate_scene(sce);
}
/* ************ READ WM ***************** */