[Bf-blender-cvs] [e3d1361c755] asset-engine: Merge branch 'id_override_static' into asset-engine

Bastien Montagne noreply at git.blender.org
Thu Aug 10 17:08:50 CEST 2017


Commit: e3d1361c755b76a5bfee7b457bf92b945cac95eb
Author: Bastien Montagne
Date:   Thu Aug 10 16:21:38 2017 +0200
Branches: asset-engine
https://developer.blender.org/rBe3d1361c755b76a5bfee7b457bf92b945cac95eb

Merge branch 'id_override_static' into asset-engine

Conflicts:
	source/blender/blenkernel/intern/library_remap.c
	source/blender/blenloader/intern/readfile.c
	source/blender/makesdna/DNA_ID.h
	source/blender/makesrna/intern/rna_ID.c

===================================================================



===================================================================

diff --cc source/blender/blenkernel/CMakeLists.txt
index 372d0a3c8a9,aabc98ed59d..3951e585d68
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@@ -120,8 -119,8 +120,9 @@@ set(SR
  	intern/lamp.c
  	intern/lattice.c
  	intern/library.c
 +	intern/library_asset.c
  	intern/library_idmap.c
+ 	intern/library_override.c
  	intern/library_query.c
  	intern/library_remap.c
  	intern/linestyle.c
diff --cc source/blender/blenkernel/intern/library_asset.c
index 7bafe4f496b,00000000000..4c60d2ab2bb
mode 100644,000000..100644
--- a/source/blender/blenkernel/intern/library_asset.c
+++ b/source/blender/blenkernel/intern/library_asset.c
@@@ -1,270 -1,0 +1,270 @@@
 +/*
 + * ***** BEGIN GPL LICENSE BLOCK *****
 + *
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + *
 + * The Original Code is Copyright (C) 2015,2016 by Blender Foundation.
 + * All rights reserved.
 + *
 + * The Original Code is: all of this file.
 + *
 + * Contributor(s): Bastien Montagne.
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file blender/blenkernel/intern/library_asset.c
 + *  \ingroup bke
 + *
 + * Contains asset-related management of ID's and libraries.
 + */
 +
 +#include <string.h>
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "BLI_blenlib.h"
 +#include "BLI_utildefines.h"
 +
 +#include "RNA_types.h"
 +
 +#include "BKE_asset_engine.h"
 +#include "BKE_library.h"
 +#include "BKE_library_query.h"
 +#include "BKE_main.h"
 +
 +
 +/* Asset managing - TODO: we most likely want to turn this into a hashing at some point, could become a bit slow
 + *                        when having huge assets (or many of them)... */
 +void BKE_library_asset_repository_init(Library *lib, const AssetEngineType *aet, const char *repo_root)
 +{
 +	BKE_library_asset_repository_free(lib);
 +	lib->asset_repository = MEM_mallocN(sizeof(*lib->asset_repository), __func__);
 +
 +	BLI_strncpy(lib->asset_repository->asset_engine, aet->idname, sizeof(lib->asset_repository->asset_engine));
 +	lib->asset_repository->asset_engine_version = aet->version;
 +	BLI_strncpy(lib->asset_repository->root, repo_root, sizeof(lib->asset_repository->root));
 +
 +	BLI_listbase_clear(&lib->asset_repository->assets);
 +}
 +
 +void BKE_library_asset_repository_clear(Library *lib)
 +{
 +	if (lib->asset_repository) {
 +		for (AssetRef *aref; (aref = BLI_pophead(&lib->asset_repository->assets)); ) {
 +			BLI_freelistN(&aref->id_list);
 +			MEM_freeN(aref);
 +		}
 +	}
 +}
 +
 +void BKE_library_asset_repository_free(Library *lib)
 +{
 +	if (lib->asset_repository) {
 +		BKE_library_asset_repository_clear(lib);
 +		MEM_freeN(lib->asset_repository);
 +		lib->asset_repository = NULL;
 +	}
 +}
 +
 +AssetRef *BKE_library_asset_repository_asset_add(Library *lib, const void *idv)
 +{
 +	const ID *id = idv;
 +	BLI_assert(id->uuid != NULL);
 +
 +	AssetRef *aref = BKE_library_asset_repository_asset_find(lib, idv);
 +	if (!aref) {
 +		aref = MEM_callocN(sizeof(*aref), __func__);
 +		aref->uuid = *id->uuid;
 +		BKE_library_asset_repository_subdata_add(aref, idv);
 +		BLI_addtail(&lib->asset_repository->assets, aref);
 +	}
 +
 +	return aref;
 +}
 +
 +AssetRef *BKE_library_asset_repository_asset_find(Library *lib, const void *idv)
 +{
 +	const ID *id = idv;
 +	BLI_assert(id->uuid != NULL);
 +
 +	for (AssetRef *aref = lib->asset_repository->assets.first; aref; aref = aref->next) {
 +		if (ASSETUUID_COMPARE(&aref->uuid, id->uuid)) {
 +#ifndef NDEBUG
 +			LinkData *link = aref->id_list.first;
 +			BLI_assert(link && (link->data == idv));
 +#endif
 +			return aref;
 +		}
 +	}
 +	return NULL;
 +}
 +
 +void BKE_library_asset_repository_asset_remove(Library *lib, const void *idv)
 +{
 +	AssetRef *aref = BKE_library_asset_repository_asset_find(lib, idv);
 +	BLI_remlink(&lib->asset_repository->assets, aref);
 +	BLI_freelistN(&aref->id_list);
 +	MEM_freeN(aref);
 +}
 +
 +void BKE_library_asset_repository_subdata_add(AssetRef *aref, const void *idv)
 +{
 +	if (BLI_findptr(&aref->id_list, idv, offsetof(LinkData, data)) == NULL) {
 +		BLI_addtail(&aref->id_list, BLI_genericNodeN((void *)idv));
 +	}
 +}
 +
 +void BKE_library_asset_repository_subdata_remove(AssetRef *aref, const void *idv)
 +{
 +	LinkData *link = BLI_findptr(&aref->id_list, idv, offsetof(LinkData, data));
 +	if (link) {
 +		BLI_freelinkN(&aref->id_list, link);
 +	}
 +}
 +
 +void BKE_libraries_asset_subdata_remove(Main *bmain, const void *idv)
 +{
 +	const ID *id = idv;
 +
 +	if (id->lib == NULL) {
 +		return;
 +	}
 +
 +	ListBase *lb = &bmain->library;
 +	for (Library *lib = lb->first; lib; lib = lib->id.next) {
 +		if (lib->asset_repository) {
 +			for (AssetRef *aref = lib->asset_repository->assets.first; aref; aref = aref->next) {
 +				LinkData *subdata = aref->id_list.first;
 +				/* Skip first one, it's main asset, not subdata! */
 +				for (subdata = subdata->next; subdata; subdata = subdata->next) {
 +					if (subdata->data == idv) {
 +						BLI_freelinkN(&aref->id_list, subdata);
 +						break;
 +					}
 +				}
 +			}
 +		}
 +	}
 +}
 +
 +void BKE_libraries_asset_repositories_clear(Main *bmain)
 +{
 +	ListBase *lb = which_libbase(bmain, ID_LI);
 +	for (Library *lib = lb->first; lib; lib = lib->id.next) {
 +		BKE_library_asset_repository_clear(lib);
 +	}
 +	BKE_main_id_tag_all(bmain, LIB_TAG_ASSET, false);
 +}
 +
 +static int library_asset_dependencies_rebuild_cb(void *userdata, ID *id_self, ID **idp, int UNUSED(cd_flag))
 +{
 +	if (!idp || !*idp) {
 +		return IDWALK_RET_NOP;
 +	}
 +
 +	AssetRef *aref = userdata;
 +	ID *id = *idp;
 +
 +	if (id->uuid) {
 +		return IDWALK_RET_STOP_RECURSION;
 +	}
 +
 +	printf("%s (from %s)\n", id->name, id_self->name);
 +
 +	BKE_library_asset_repository_subdata_add(aref, (const void *)id);
 +	id->tag |= LIB_TAG_ASSET;
 +	return IDWALK_RET_NOP;
 +}
 +
 +static void library_asset_dependencies_rebuild(ID *asset)
 +{
 +	Library *lib = asset->lib;
 +	BLI_assert(lib && lib->asset_repository);
 +
 +	if (!(lib && lib->asset_repository)) {
 +		printf("asset: %s\n", asset->name);
 +		printf("lib: %p\n", lib);
 +		printf("lib: %s\n", lib->id.name);
 +		printf("lib: %s\n", lib->name);
 +		printf("lib: %p\n\n\n", lib->asset_repository);
 +	}
 +
 +	asset->tag |= LIB_TAG_ASSET;
 +
 +	AssetRef *aref = BKE_library_asset_repository_asset_add(lib, asset);
 +
 +	/* TODO: pass main and use Main->relations? */
 +	BKE_library_foreach_ID_link(NULL, asset, library_asset_dependencies_rebuild_cb, aref, IDWALK_RECURSE);
 +}
 +
 +void BKE_libraries_asset_repositories_rebuild(Main *bmain)
 +{
 +	ListBase *lbarray[MAX_LIBARRAY];
 +	ID *id;
 +	int a;
 +
 +	BKE_libraries_asset_repositories_clear(bmain);
 +
 +	a = set_listbasepointers(bmain, lbarray);
 +	while (a--) {
 +		for (id = lbarray[a]->first; id; id = id->next) {
 +			if (id->uuid) {
 +				library_asset_dependencies_rebuild(id);
 +			}
 +		}
 +	}
 +}
 +
 +AssetRef *BKE_libraries_asset_repository_uuid_find(Main *bmain, const AssetUUID *uuid)
 +{
 +	ListBase *lb = which_libbase(bmain, ID_LI);
 +	for (Library *lib = lb->first; lib; lib = lib->id.next) {
 +		for (AssetRef *aref = lib->asset_repository->assets.first; aref; aref = aref->next) {
 +			if (ASSETUUID_COMPARE(&aref->uuid, uuid)) {
 +#ifndef NDEBUG
 +				LinkData *link = aref->id_list.first;
 +				BLI_assert(link && ((ID *)link->data)->uuid && ASSETUUID_COMPARE(((ID *)link->data)->uuid, uuid));
 +#endif
 +				return aref;
 +			}
 +		}
 +	}
 +	return NULL;
 +}
 +
 +/** Find or add the 'virtual' library datablock matching this asset engine, used for non-blend-data assets. */
 +Library *BKE_library_asset_virtual_ensure(Main *bmain, const AssetEngineType *aet)
 +{
 +	Library *lib;
 +	ListBase *lb = which_libbase(bmain, ID_LI);
 +
 +	for (lib = lb->first; lib; lib = lib->id.next) {
 +		if (!(lib->flag & LIBRARY_FLAG_VIRTUAL) || !lib->asset_repository) {
 +			continue;
 +		}
 +
 +		if (STREQ(lib->asset_repository->asset_engine, aet->idname) &&
 +		    lib->asset_repository->asset_engine_version == aet->version)
 +		{
 +			return lib;
 +		}
 +	}
 +
- 	lib = BKE_libblock_alloc(bmain, ID_LI, "VirtualLib");
++	lib = BKE_libblock_alloc(bmain, ID_LI, "VirtualLib", 0);
 +	BKE_library_asset_repository_init(lib, aet, "");
 +	lib->flag |= LIBRARY_FLAG_VIRTUAL;
 +	return lib;
 +}
diff --cc source/blender/blenkernel/intern/library_query.c
index d64889e491f,bd308991c79..8f1ab1ddb74
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@@ -368,9 -368,13 +368,13 @@@ void BKE_library_foreach_ID_link(Main *
  #define CALLBACK_INVOKE(check_id_super, cb_flag) \
  	FOREACH_CALLBACK_INVOKE(&data, check_id_super, cb_flag)
  
+ 	if (id->override) {
+ 		CALLBACK_INVOKE_ID(id->override->reference, IDWALK_CB_USER);
+ 	}
+ 
  	for (; id != NULL; id = (flag & IDWALK_RECURSE) ? BLI_LINKSTACK_POP(data.ids_todo) : NULL) {
  		data.self_id = id;
 -		data.cb_flag = ID_IS_LINKED_DATABLOCK(id) ? IDWALK_CB_INDIRECT_USAGE : 0;
 +		data.cb_flag = ID_IS_LINKED(id) ? IDWALK_CB_INDIRECT_USAGE : 0;
  
  		if (bmain != NULL && bmain->relations != NULL && (flag & IDWALK_READONLY)) {
  			/* Note that this is minor optimization, even in worst cases (like id being an object with lots of
diff --cc source/blender/blenkernel/intern/library_remap.c
index 21bcdb8a592,a8a57b8ebeb..4e27f4695cc
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@@ -731,12 -738,14 +738,18 @@@ void BKE_libblock_free_data(ID *id, con
  		MEM_freeN(id->properties);
  	}
  
+ 	if (id->override) {
+ 		BKE_overr

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list