Commit: 784f7f3264143ec6c8011173610870eefd73fc4b
Author: Bastien Montagne
Date:   Sun Jul 24 17:55:43 2016 +0200
Branches: asset-engine
https://developer.blender.org/rB784f7f3264143ec6c8011173610870eefd73fc4b

Merge branch 'master' into asset-engine

Conflicts:
        source/blender/windowmanager/intern/wm_files_link.c

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



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

diff --cc source/blender/windowmanager/intern/wm_files_link.c
index 7b50975,e2ccb6f..8195212
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@@ -691,9 -551,9 +691,13 @@@ static int wm_lib_relocate_invoke(bCont
        return OPERATOR_CANCELLED;
  }
  
- /* Note that IDs listed in lapp_data items *must* have been removed from 
bmain by caller. */
++/**
++ * \param library if given, all IDs from that library will be removed and 
reloaded. Otherwise, IDs must have already
++ *                been removed from \a bmain, and added to \a lapp_data.
++ */
  static void lib_relocate_do(
-         Main *bmain, WMLinkAppendData *lapp_data, ReportList *reports, 
AssetEngineType *aet, const bool do_reload)
+         Main *bmain, Scene *scene,
 -        Library *library, WMLinkAppendData *lapp_data, ReportList *reports, 
const bool do_reload)
++        Library *library, WMLinkAppendData *lapp_data, ReportList *reports, 
AssetEngineType *aet, const bool do_reload)
  {
        ListBase *lbarray[MAX_LIBARRAY];
        int lba_idx;
@@@ -701,6 -561,34 +705,36 @@@
        LinkNode *itemlink;
        int item_idx;
  
+       /* Remove all IDs to be reloaded from Main. */
 -      lba_idx = set_listbasepointers(bmain, lbarray);
 -      while (lba_idx--) {
 -              ID *id = lbarray[lba_idx]->first;
 -              const short idcode = id ? GS(id->name) : 0;
 -
 -              if (!id || !BKE_idcode_is_linkable(idcode)) {
 -                      /* No need to reload non-linkable datatypes, those will 
get relinked with their 'users ID'. */
 -                      continue;
 -              }
++      if (library) {
++              lba_idx = set_listbasepointers(bmain, lbarray);
++              while (lba_idx--) {
++                      ID *id = lbarray[lba_idx]->first;
++                      const short idcode = id ? GS(id->name) : 0;
++
++                      if (!id || !BKE_idcode_is_linkable(idcode)) {
++                              /* No need to reload non-linkable datatypes, 
those will get relinked with their 'users ID'. */
++                              continue;
++                      }
+ 
 -              for (; id; id = id->next) {
 -                      if (id->lib == library) {
 -                              WMLinkAppendDataItem *item;
++                      for (; id; id = id->next) {
++                              if (id->lib == library) {
++                                      WMLinkAppendDataItem *item;
+ 
 -                              /* We remove it from current Main, and add it 
to items to link... */
 -                              /* Note that non-linkable IDs (like e.g. 
shapekeys) are also explicitely linked here... */
 -                              BLI_remlink(lbarray[lba_idx], id);
 -                              item = wm_link_append_data_item_add(lapp_data, 
id->name + 2, idcode, id);
 -                              BLI_BITMAP_SET_ALL(item->libraries, true, 
lapp_data->num_libraries);
++                                      /* We remove it from current Main, and 
add it to items to link... */
++                                      /* Note that non-linkable IDs (like 
e.g. shapekeys) are also explicitely linked here... */
++                                      BLI_remlink(lbarray[lba_idx], id);
++                                      item = 
wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, NULL, id);
++                                      BLI_BITMAP_SET_ALL(item->libraries, 
true, lapp_data->num_libraries);
+ 
+ #ifdef PRINT_DEBUG
 -                              printf("\tdatablock to seek for: %s\n", 
id->name);
++                                      printf("\tdatablock to seek for: %s\n", 
id->name);
+ #endif
++                              }
+                       }
+               }
+       }
+ 
        BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
  
        /* We do not want any instanciation here! */
@@@ -839,6 -727,43 +873,43 @@@
                        }
                }
        }
+ 
+       BKE_main_lib_objects_recalc_all(bmain);
+       IMB_colormanagement_check_file_config(bmain);
+ 
+       /* important we unset, otherwise these object wont
+        * link into other scenes from this blend file */
+       BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
+ 
+       /* recreate dependency graph to include new objects */
+       DAG_scene_relations_rebuild(bmain, scene);
+ 
+       /* free gpu materials, some materials depend on existing objects, such 
as lamps so freeing correctly refreshes */
+       GPU_materials_free();
+ }
+ 
+ void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
+ {
+       if (!BLO_has_bfile_extension(lib->filepath)) {
+               BKE_reportf(reports, RPT_ERROR, "'%s' is not a valid library 
filepath", lib->filepath);
+               return;
+       }
+ 
+       if (!BLI_exists(lib->filepath)) {
+               BKE_reportf(reports, RPT_ERROR,
+                           "Trying to reload library '%s' from invalid path 
'%s'", lib->id.name, lib->filepath);
+               return;
+       }
+ 
+       WMLinkAppendData *lapp_data = wm_link_append_data_new(0);
+ 
+       wm_link_append_data_library_add(lapp_data, lib->filepath);
+ 
 -      lib_relocate_do(CTX_data_main(C), CTX_data_scene(C), lib, lapp_data, 
reports, true);
++      lib_relocate_do(CTX_data_main(C), CTX_data_scene(C), lib, lapp_data, 
reports, NULL, true);
+ 
+       wm_link_append_data_free(lapp_data);
+ 
+       WM_event_add_notifier(C, NC_WINDOW, NULL);
  }
  
  static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool 
do_reload)
@@@ -949,34 -866,7 +1017,7 @@@
                        }
                }
  
-               lba_idx = set_listbasepointers(bmain, lbarray);
-               while (lba_idx--) {
-                       ID *id = lbarray[lba_idx]->first;
-                       const short idcode = id ? GS(id->name) : 0;
- 
-                       if (!id || !BKE_idcode_is_linkable(idcode)) {
-                               /* No need to reload non-linkable datatypes, 
those will get relinked with their 'users ID'. */
-                               continue;
-                       }
- 
-                       for (; id; id = id->next) {
-                               if (id->lib == lib) {
-                                       WMLinkAppendDataItem *item;
- 
-                                       /* We remove it from current Main, and 
add it to items to link... */
-                                       /* Note that non-linkable IDs (like 
e.g. shapekeys) are also explicitely linked here... */
-                                       BLI_remlink(lbarray[lba_idx], id);
-                                       item = 
wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, NULL, id);
-                                       BLI_BITMAP_SET_ALL(item->libraries, 
true, lapp_data->num_libraries);
- 
- #ifdef PRINT_DEBUG
-                                       printf("\tdatablock to seek for: %s\n", 
id->name);
- #endif
-                               }
-                       }
-               }
- 
-               lib_relocate_do(bmain, lapp_data, op->reports, NULL, do_reload);
 -              lib_relocate_do(bmain, scene, lib, lapp_data, op->reports, 
do_reload);
++              lib_relocate_do(bmain, scene, lib, lapp_data, op->reports, 
NULL, do_reload);
  
                wm_link_append_data_free(lapp_data);
  
@@@ -1057,463 -934,4 +1085,451 @@@ void WM_OT_lib_reload(wmOperatorType *o
                    FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
  }
  
 +/** \name Asset-related operators.
 + *
 + * \{ */
 +
 +typedef struct AssetUpdateCheckEngine {
 +      struct AssetUpdateCheckEngine *next, *prev;
 +      AssetEngine *ae;
 +
 +      /* Note: We cannot store IDs themselves in non-locking async task... so 
we'll have to check again for
 +       *       UUID/IDs mapping on each update call... Not ideal, but don't 
think it will be that big of a bottleneck
 +       *       in practice. */
 +      AssetUUIDList uuids;
 +      int allocated_uuids;
 +      int ae_job_id;
 +      short status;
 +} AssetUpdateCheckEngine;
 +
 +typedef struct AssetUpdateCheckJob {
 +      ListBase engines;
 +      short flag;
 +
 +      float *progress;
 +      short *stop;
 +} AssetUpdateCheckJob;
 +
 +/* AssetUpdateCheckEngine.status */
 +enum {
 +      AUCE_UPDATE_CHECK_DONE  = 1 << 0,  /* Update check is finished for this 
engine. */
 +      AUCE_ENSURE_ASSETS_DONE = 1 << 1,  /* Asset ensure is finished for this 
engine (if applicable). */
 +};
 +
 +/* AssetUpdateCheckJob.flag */
 +enum {
 +      AUCJ_ENSURE_ASSETS = 1 << 0,  /* Try to perform the 'ensure' task too. 
*/
 +};
 +
 +/* Helper to fetch a set of assets to handle, regrouped by asset engine. */
 +static void asset_update_engines_uuids_fetch(
 +        ListBase *engines,
 +        Main *bmain, AssetUUIDList *uuids, const short uuid_tags,
 +        const bool do_reset_tags)
 +{
 +      for (Library *lib = bmain->library.first; lib; lib = lib->id.next) {
 +              if (lib->asset_repository) {
 +                      printf("Checking lib file '%s' (engine %s, ver. %d)\n", 
lib->filepath,
 +                             lib->asset_repository->asset_engine, 
lib->asset_repository->asset_engine_version);
 +
 +                      AssetUpdateCheckEngine *auce = NULL;
 +                      AssetEngineType *ae_type = 
BKE_asset_engines_find(lib->asset_repository->asset_engine);
 +                      bool copy_engine = false;
 +
 +                      if (ae_type == NULL) {
 +                              printf("ERROR! Unknown asset engine!\n");
 +                      }
 +
 +                      for (AssetRef *aref = 
lib->asset_repository->assets.first; aref; aref = aref->next) {
 +                              ID *id = ((LinkData 
*)aref->id_list.first)->data;
 +                              BLI_assert(id->uuid);
 +
 +                              if (uuid_tags && !(id->uuid->tag & uuid_tags)) {
 +                                      continue;
 +                              }
 +
 +                              if (uuids) {
 +                                      int i = uuids->nbr_uuids;
 +                                      bool skip = true;
 +                                      for (AssetUUID *uuid = uuids->uuids; 
i--; uuid++) {
 +                                              if (ASSETUUID_COMPARE(id->uuid, 
uuid)) {
 +                                                      skip = false;
 +                                                      break;
 +                                              }
 +                                      }
 +                                      if (skip) {
 +                                              continue;
 +                                      }
 +                              }
 +
 +                              if (ae_type == NULL) {
 +                                      if (do_reset_tags) {
 +                                              id->uuid->tag = 
UUID_TAG_ENGINE_MISSING;
 +                                      }
 +                                      else {
 +                                              id->uuid->tag |= 
UUID_TAG_ENGINE_MISSING;
 +                                      }
 +                                      G.f |= G_ASSETS_FAIL;
 +                                      continue;
 +                              }
 +
 +                              if (auce == NULL) {
 +                                      for (auce = engines->first; auce; auce 
= auce->next) {
 +                                              if (auce->ae->type == ae_type) {
 +                                                      /* In case we have 
several engine versions for the same engine, we create several
 +                                                       * 
AssetUpdateCheckEngine structs (since an uuid list can only handle one ae 
version), using
 +                                                       * the same (shallow) 
copy of the actual asset engine. */
 +                                                      copy_engine = 
(auce->uuids.asset_engine_version != 
lib->asset_repository->asset_engine_version);
 +                                                      break;
 +                                              }
 +                                      }
 +                                      if (copy_engine || auce == NULL) {
 +                                              AssetUpdateCheckEngine 
*auce_prev = auce;
 +                                              auce = 
MEM_callocN(sizeof(*auce), __func__);
 +                                              auce->ae = copy_engine ? 
BKE_asset_engine_copy(auce_prev->ae) :
 +                                                                       
BKE_asset_engine_create(ae_type, NULL);
 +                                              auce->ae_job_id = 
AE_JOB_ID_UNSET;
 +                                              
auce->uuids.asset_engine_version = lib->asset_repository->asset_engine_version;
 +                                              BLI_addtail(engines, auce);
 +                                      }
 +                              }
 +
 +                              printf("\tWe need to check for updated asset 
%s...\n", id->name);
 +                              if (do_reset_tags) {
 +                                      id->uuid->tag = (id->tag & 
LIB_TAG_MISSING) ? UUID_TAG_ASSET_MISSING : 0;
 +                              }
 +
 +                              auce->uuids.nbr_uuids++;
 +                              BKE_asset_uuid_print(id->uuid);
 +                              if (auce->uuids.nbr_uuids > 
auce->allocated_uuids) {
 +                                      auce->allocated_uuids += 16;
 +                                      BLI_assert(auce->uuids.nbr_uuids < 
auce->allocated_uuids);
 +
 +                                      const size_t allocsize = 
sizeof(*auce->uuids.uuids) * (size_t)auce->allocated_uuids;
 +                                      auce->uuids.uuids = auce->uuids.uuids ?
 +

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to