[Bf-blender-cvs] [1ff8be24ef8] blender2.8: Cleanup/Refactor: move Main stuff into BKE's new main.c file (and header).
Bastien Montagne
noreply at git.blender.org
Wed Nov 7 21:15:10 CET 2018
Commit: 1ff8be24ef8970f140865dfb118112ec08e7dfad
Author: Bastien Montagne
Date: Wed Nov 7 16:06:36 2018 +0100
Branches: blender2.8
https://developer.blender.org/rB1ff8be24ef8970f140865dfb118112ec08e7dfad
Cleanup/Refactor: move Main stuff into BKE's new main.c file (and header).
We already had a BKE_main.h header, no reason not to put there
Main-specific functions, BKE_library has already more than enough to
handle with IDs and library management!
===================================================================
M source/blender/blenkernel/BKE_library.h
M source/blender/blenkernel/BKE_main.h
M source/blender/blenkernel/CMakeLists.txt
M source/blender/blenkernel/intern/blender.c
M source/blender/blenkernel/intern/idcode.c
M source/blender/blenkernel/intern/library.c
M source/blender/blenkernel/intern/library_idmap.c
A source/blender/blenkernel/intern/main.c
M source/blender/depsgraph/intern/depsgraph.h
M tests/gtests/alembic/abc_export_test.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 897d6206641..b821d19c0d6 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -165,28 +165,7 @@ bool new_id(struct ListBase *lb, struct ID *id, const char *name) ATTR_NONNULL(1
void id_clear_lib_data(struct Main *bmain, struct ID *id);
void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, const bool id_in_mainlist);
-struct ListBase *which_libbase(struct Main *mainlib, short type);
-
-#define MAX_LIBARRAY 37
-int set_listbasepointers(struct Main *main, struct ListBase *lb[MAX_LIBARRAY]);
-
-/* Main API */
-struct Main *BKE_main_new(void);
-void BKE_main_free(struct Main *mainvar);
-
-void BKE_main_lock(struct Main *bmain);
-void BKE_main_unlock(struct Main *bmain);
-
-void BKE_main_relations_create(struct Main *bmain);
-void BKE_main_relations_free(struct Main *bmain);
-
-struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct ImBuf *img);
-struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data);
-void BKE_main_thumbnail_create(struct Main *bmain);
-
-const char *BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL();
-const char *BKE_main_blendfile_path_from_global(void);
-
+/* Affect whole Main database. */
void BKE_main_id_tag_idcode(struct Main *mainvar, const short type, const int tag, const bool value);
void BKE_main_id_tag_listbase(struct ListBase *lb, const int tag, const bool value);
void BKE_main_id_tag_all(struct Main *mainvar, const int tag, const bool value);
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index 492962f3b00..e5a816b92ce 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -42,15 +42,20 @@
*/
#include "DNA_listBase.h"
+#include "BLI_compiler_attrs.h"
+#include "BLI_sys_types.h"
+
#ifdef __cplusplus
extern "C" {
#endif
+struct BlendThumbnail;
+struct BLI_mempool;
struct Depsgraph;
+struct GHash;
+struct ImBuf;
struct Library;
struct MainLock;
-struct GHash;
-struct BLI_mempool;
/* Blender thumbnail, as written on file (width, height, and data as char RGBA). */
/* We pack pixel data after that struct. */
@@ -134,6 +139,27 @@ typedef struct Main {
struct MainLock *lock;
} Main;
+struct Main *BKE_main_new(void);
+void BKE_main_free(struct Main *mainvar);
+
+void BKE_main_lock(struct Main *bmain);
+void BKE_main_unlock(struct Main *bmain);
+
+void BKE_main_relations_create(struct Main *bmain);
+void BKE_main_relations_free(struct Main *bmain);
+
+struct BlendThumbnail *BKE_main_thumbnail_from_imbuf(struct Main *bmain, struct ImBuf *img);
+struct ImBuf *BKE_main_thumbnail_to_imbuf(struct Main *bmain, struct BlendThumbnail *data);
+void BKE_main_thumbnail_create(struct Main *bmain);
+
+const char *BKE_main_blendfile_path(const struct Main *bmain) ATTR_NONNULL();
+const char *BKE_main_blendfile_path_from_global(void);
+
+struct ListBase *which_libbase(struct Main *mainlib, short type);
+
+#define MAX_LIBARRAY 37
+int set_listbasepointers(struct Main *main, struct ListBase *lb[MAX_LIBARRAY]);
+
#define MAIN_VERSION_ATLEAST(main, ver, subver) \
((main)->versionfile > (ver) || (main->versionfile == (ver) && (main)->subversionfile >= (subver)))
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index b18b6f6d63d..4161a5ecd79 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -136,6 +136,7 @@ set(SRC
intern/library_query.c
intern/library_remap.c
intern/linestyle.c
+ intern/main.c
intern/mask.c
intern/mask_evaluate.c
intern/mask_rasterize.c
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 66020679bf7..d0dea75860e 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -58,6 +58,7 @@
#include "BKE_image.h"
#include "BKE_layer.h"
#include "BKE_library.h"
+#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_report.h"
#include "BKE_scene.h"
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index 8328d71128a..23648a1a984 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -39,7 +39,7 @@
#include "BLT_translation.h"
-#include "BKE_library.h"
+#include "BKE_main.h"
#include "BKE_idcode.h"
typedef struct {
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 74c3341fa96..64227219683 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -898,85 +898,6 @@ void BKE_libblock_management_usercounts_clear(Main *bmain, void *idv)
id->tag |= LIB_TAG_NO_USER_REFCOUNT;
}
-ListBase *which_libbase(Main *mainlib, short type)
-{
- switch ((ID_Type)type) {
- case ID_SCE:
- return &(mainlib->scene);
- case ID_LI:
- return &(mainlib->library);
- case ID_OB:
- return &(mainlib->object);
- case ID_ME:
- return &(mainlib->mesh);
- case ID_CU:
- return &(mainlib->curve);
- case ID_MB:
- return &(mainlib->mball);
- case ID_MA:
- return &(mainlib->mat);
- case ID_TE:
- return &(mainlib->tex);
- case ID_IM:
- return &(mainlib->image);
- case ID_LT:
- return &(mainlib->latt);
- case ID_LA:
- return &(mainlib->lamp);
- case ID_CA:
- return &(mainlib->camera);
- case ID_IP:
- return &(mainlib->ipo);
- case ID_KE:
- return &(mainlib->key);
- case ID_WO:
- return &(mainlib->world);
- case ID_SCR:
- return &(mainlib->screen);
- case ID_VF:
- return &(mainlib->vfont);
- case ID_TXT:
- return &(mainlib->text);
- case ID_SPK:
- return &(mainlib->speaker);
- case ID_LP:
- return &(mainlib->lightprobe);
- case ID_SO:
- return &(mainlib->sound);
- case ID_GR:
- return &(mainlib->collection);
- case ID_AR:
- return &(mainlib->armature);
- case ID_AC:
- return &(mainlib->action);
- case ID_NT:
- return &(mainlib->nodetree);
- case ID_BR:
- return &(mainlib->brush);
- case ID_PA:
- return &(mainlib->particle);
- case ID_WM:
- return &(mainlib->wm);
- case ID_GD:
- return &(mainlib->gpencil);
- case ID_MC:
- return &(mainlib->movieclip);
- case ID_MSK:
- return &(mainlib->mask);
- case ID_LS:
- return &(mainlib->linestyle);
- case ID_PAL:
- return &(mainlib->palettes);
- case ID_PC:
- return &(mainlib->paintcurves);
- case ID_CF:
- return &(mainlib->cachefiles);
- case ID_WS:
- return &(mainlib->workspaces);
- }
- return NULL;
-}
-
/**
* Clear or set given tags for all ids in listbase (runtime tags).
*/
@@ -1065,70 +986,6 @@ void BKE_main_lib_objects_recalc_all(Main *bmain)
DEG_id_type_tag(bmain, ID_OB);
}
-/**
- * puts into array *lb pointers to all the ListBase structs in main,
- * and returns the number of them as the function result. This is useful for
- * generic traversal of all the blocks in a Main (by traversing all the
- * lists in turn), without worrying about block types.
- *
- * \note MAX_LIBARRAY define should match this code */
-int set_listbasepointers(Main *main, ListBase **lb)
-{
- /* BACKWARDS! also watch order of free-ing! (mesh<->mat), first items freed last.
- * This is important because freeing data decreases usercounts of other datablocks,
- * if this data is its self freed it can crash. */
- lb[INDEX_ID_LI] = &(main->library); /* Libraries may be accessed from pretty much any other ID... */
- lb[INDEX_ID_IP] = &(main->ipo);
- lb[INDEX_ID_AC] = &(main->action); /* moved here to avoid problems when freeing with animato (aligorith) */
- lb[INDEX_ID_KE] = &(main->key);
- lb[INDEX_ID_PAL] = &(main->palettes); /* referenced by gpencil, so needs to be before that to avoid crashes */
- lb[INDEX_ID_GD] = &(main->gpencil); /* referenced by nodes, objects, view, scene etc, before to free after. */
- lb[INDEX_ID_NT] = &(main->nodetree);
- lb[INDEX_ID_IM] = &(main->image);
- lb[INDEX_ID_TE] = &(main->tex);
- lb[INDEX_ID_MA] = &(main->mat);
- lb[INDEX_ID_VF] = &(main->vfont);
-
- /* Important!: When adding a new object type,
- * the specific data should be inserted here
- */
-
- lb[INDEX_ID_AR] = &(main->armature);
-
- lb[INDEX_ID_CF] = &(main->cachefiles);
- lb[INDEX_ID_ME] = &(main->mesh);
- lb[INDEX_ID_CU] = &(main->curve);
- lb[INDEX_ID_MB] = &(main->mball);
-
- lb[INDEX_ID_LT] = &(main->latt);
- lb[INDEX_ID_LA] = &(main->lamp);
- lb[INDEX_ID_CA] = &(main->camera);
-
- lb[INDEX_ID_TXT] = &(main->text);
- lb[INDEX_ID_SO] = &(main->sound);
- lb[INDEX_ID_GR] = &(main->collection);
- lb[INDEX_ID_PAL] = &(main->palettes);
- lb[INDEX_ID_PC] = &(main->paintcurves);
- lb[INDEX_ID_BR] = &(main->brush);
- lb[INDEX_ID_PA] = &(main->particle);
- lb[INDEX_ID_SPK] = &(main->speaker);
- lb[INDEX_ID_LP] = &(main->lightprobe);
-
- lb[INDEX_ID_WO] = &(main->world);
- lb[INDEX_ID_MC] = &(main->movieclip);
- lb[INDEX_ID_SCR] = &(main->screen);
- lb[INDEX_ID_OB] = &(main->object);
- lb[INDEX_ID_LS] = &(main->linestyle); /* referenced by scenes */
- lb[INDEX_ID_SCE] = &(main->scene);
- lb[INDEX_ID_WS] = &(main->workspaces); /* before wm, so it's freed after it! */
- lb[INDEX_ID_WM] = &(main->wm);
- lb[INDEX_ID_MSK] = &(main->mask);
-
- lb[INDEX_ID_NULL] = NULL;
-
- return (MAX_LIBARRAY - 1);
-}
-
/* *********** ALLOC AND FREE *****************
*
* BKE_libblock_free(ListBase *lb, ID *id )
@@ -1511,254 +1368,6 @@ void BKE_library_free(Library *lib)
freePackedFile(lib->packedfile);
}
-Main *BKE_main_new(void)
-{
- Main *bmain = MEM_callocN(sizeof(Main), "new main");
- bmain->lock = MEM_mallocN(sizeof(SpinLock), "main lock");
- BLI_spin_init((SpinLock *)bmain->lock);
- return bmain;
-}
-
-void BKE_main_free(Main *mainvar)
-{
- /* also call when reading a file, erase all, etc */
- ListBase *lbarray[MAX_LIBARRAY];
- int a;
-
- MEM_SAFE_FREE(mainvar->blen_thumb);
-
- a = set_listbasepointers(mainvar, lbarray);
- while (a--) {
- ListBase *lb = lbarray[a];
- ID *id;
-
- while ( (id = lb->first) ) {
-#if 1
- BKE_libblock_free_ex(mainvar, id, false, false)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list