diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_addon.h | 13 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/addon.c | 48 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/blender.c | 7 | ||||
-rw-r--r-- | source/blender/editors/interface/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/resources.c | 17 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 23 |
6 files changed, 87 insertions, 25 deletions
diff --git a/source/blender/blenkernel/BKE_addon.h b/source/blender/blenkernel/BKE_addon.h index 74c1edd1c1b..e631d1d6537 100644 --- a/source/blender/blenkernel/BKE_addon.h +++ b/source/blender/blenkernel/BKE_addon.h @@ -26,8 +26,11 @@ * \ingroup bke */ -#include "RNA_types.h" +struct ListBase; +struct bAddon; + +#ifdef __RNA_TYPES_H__ typedef struct bAddonPrefType { /* type info */ char idname[64]; // best keep the same size as BKE_ST_MAXNAME @@ -36,6 +39,10 @@ typedef struct bAddonPrefType { ExtensionRNA ext; } bAddonPrefType; +#else +typedef struct bAddonPrefType bAddonPrefType; +#endif + bAddonPrefType *BKE_addon_pref_type_find(const char *idname, bool quiet); void BKE_addon_pref_type_add(bAddonPrefType *apt); void BKE_addon_pref_type_remove(const bAddonPrefType *apt); @@ -43,4 +50,8 @@ void BKE_addon_pref_type_remove(const bAddonPrefType *apt); void BKE_addon_pref_type_init(void); void BKE_addon_pref_type_free(void); +struct bAddon *BKE_addon_new(void); +struct bAddon *BKE_addon_ensure(struct ListBase *addons, const char *module); +void BKE_addon_free(struct bAddon *addon); + #endif /* __BKE_ADDON_H__ */ diff --git a/source/blender/blenkernel/intern/addon.c b/source/blender/blenkernel/intern/addon.c index 0ef12397fe7..8a5154f0039 100644 --- a/source/blender/blenkernel/intern/addon.c +++ b/source/blender/blenkernel/intern/addon.c @@ -27,13 +27,59 @@ #include <stddef.h> #include <stdlib.h> +#include "RNA_types.h" + #include "BLI_utildefines.h" #include "BLI_ghash.h" +#include "BLI_string.h" +#include "BLI_listbase.h" +#include "BLI_utildefines.h" #include "BKE_addon.h" /* own include */ +#include "BKE_idprop.h" + +#include "DNA_listBase.h" +#include "DNA_userdef_types.h" + #include "MEM_guardedalloc.h" +/* -------------------------------------------------------------------- */ +/** \name Add-on New/Free + * \{ */ + +bAddon *BKE_addon_new(void) +{ + bAddon *addon = MEM_callocN(sizeof(bAddon), "bAddon"); + return addon; +} + +bAddon *BKE_addon_ensure(ListBase *addon_list, const char *module) +{ + bAddon *addon = BLI_findstring(addon_list, module, offsetof(bAddon, module)); + if (addon == NULL) { + addon = BKE_addon_new(); + BLI_strncpy(addon->module, module, sizeof(addon->module)); + BLI_addtail(addon_list, addon); + } + return addon; +} + +void BKE_addon_free(bAddon *addon) +{ + if (addon->prop) { + IDP_FreeProperty(addon->prop); + MEM_freeN(addon->prop); + } + MEM_freeN(addon); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Add-on Preference API + * \{ */ + static GHash *global_addonpreftype_hash = NULL; @@ -81,3 +127,5 @@ void BKE_addon_pref_type_free(void) BLI_ghash_free(global_addonpreftype_hash, NULL, MEM_freeN); global_addonpreftype_hash = NULL; } + +/** \} */ diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 182b88c1c57..e9a6d0fe5a5 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -45,6 +45,7 @@ #include "IMB_imbuf.h" #include "IMB_moviecache.h" +#include "BKE_addon.h" #include "BKE_blender.h" /* own include */ #include "BKE_blender_version.h" /* own include */ #include "BKE_blendfile.h" @@ -202,11 +203,7 @@ static void userdef_free_addons(UserDef *userdef) { for (bAddon *addon = userdef->addons.first, *addon_next; addon; addon = addon_next) { addon_next = addon->next; - if (addon->prop) { - IDP_FreeProperty(addon->prop); - MEM_freeN(addon->prop); - } - MEM_freeN(addon); + BKE_addon_free(addon); } BLI_listbase_clear(&userdef->addons); } diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 523215da29e..c023816b52c 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -83,6 +83,10 @@ if(WITH_HEADLESS) add_definitions(-DWITH_HEADLESS) endif() +if(WITH_CYCLES) + add_definitions(-DWITH_CYCLES) +endif() + if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index 2eae452debb..5073fb8c0ae 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -45,6 +45,7 @@ #include "BLI_utildefines.h" #include "BLI_math.h" +#include "BKE_addon.h" #include "BKE_appdir.h" #include "BKE_colorband.h" #include "BKE_DerivedMesh.h" @@ -2307,13 +2308,19 @@ void init_userdef_do_versions(void) if (btheme->tipo.handle_sel_auto_clamped[3] == 0) rgba_char_args_set(btheme->tipo.handle_sel_auto_clamped, 0xf0, 0xaf, 0x90, 255); } - + +#ifdef WITH_CYCLES /* enable (Cycles) addon by default */ - if (!BLI_findstring(&U.addons, "cycles", offsetof(bAddon, module))) { - bAddon *baddon = MEM_callocN(sizeof(bAddon), "bAddon"); - BLI_strncpy(baddon->module, "cycles", sizeof(baddon->module)); - BLI_addtail(&U.addons, baddon); + BKE_addon_ensure(&U.addons, "cycles"); +#else + { + bAddon *addon = BLI_findstring(&U.addons, "cycles", offsetof(bAddon, module)); + if (addon) { + BKE_addon_free(addon); + BLI_remlink(&U.addons, addon); + } } +#endif } if (!USER_VERSION_ATLEAST(260, 5)) { diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 69997883c42..27a9f971ee6 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -399,27 +399,22 @@ static void rna_userdef_autosave_update(Main *bmain, Scene *scene, PointerRNA *p static bAddon *rna_userdef_addon_new(void) { ListBase *addons_list = &U.addons; - bAddon *bext = MEM_callocN(sizeof(bAddon), "bAddon"); - BLI_addtail(addons_list, bext); - return bext; + bAddon *addon = BKE_addon_new(); + BLI_addtail(addons_list, addon); + return addon; } -static void rna_userdef_addon_remove(ReportList *reports, PointerRNA *bext_ptr) +static void rna_userdef_addon_remove(ReportList *reports, PointerRNA *addon_ptr) { ListBase *addons_list = &U.addons; - bAddon *bext = bext_ptr->data; - if (BLI_findindex(addons_list, bext) == -1) { + bAddon *addon = addon_ptr->data; + if (BLI_findindex(addons_list, addon) == -1) { BKE_report(reports, RPT_ERROR, "Add-on is no longer valid"); return; } - - if (bext->prop) { - IDP_FreeProperty(bext->prop); - MEM_freeN(bext->prop); - } - - BLI_freelinkN(addons_list, bext); - RNA_POINTER_INVALIDATE(bext_ptr); + BLI_remlink(addons_list, addon); + BKE_addon_free(addon); + RNA_POINTER_INVALIDATE(addon_ptr); } static bPathCompare *rna_userdef_pathcompare_new(void) |