Cleanup: remove more G.main from BKE area.

This commit is contained in:
Bastien Montagne 2018-06-13 10:57:10 +02:00
parent 2788202417
commit 67e8c1e1c7
19 changed files with 84 additions and 76 deletions

@ -56,7 +56,7 @@ void BKE_gpencil_stroke_sync_selection(struct bGPDstroke *gps);
struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe); struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe); struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);
struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive); struct bGPDlayer *BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive);
struct bGPdata *BKE_gpencil_data_addnew(const char name[]); struct bGPdata *BKE_gpencil_data_addnew(struct Main *bmain, const char name[]);
struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src); struct bGPDframe *BKE_gpencil_frame_duplicate(const struct bGPDframe *gpf_src);
struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src); struct bGPDlayer *BKE_gpencil_layer_duplicate(const struct bGPDlayer *gpl_src);

@ -326,9 +326,10 @@ void psys_particle_on_emitter(struct ParticleSystemModifierData *psmd, int distr
float utan[3], float vtan[3], float orco[3], float ornor[3]); float utan[3], float vtan[3], float orco[3], float ornor[3]);
struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys); struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys);
struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, const char *name); struct ModifierData *object_add_particle_system(
void object_remove_particle_system(struct Scene *scene, struct Object *ob); struct Main *bmain, struct Scene *scene, struct Object *ob, const char *name);
struct ParticleSettings *BKE_particlesettings_add(struct Main *main, const char *name); void object_remove_particle_system(struct Main *bmain, struct Scene *scene, struct Object *ob);
struct ParticleSettings *BKE_particlesettings_add(struct Main *bmain, const char *name);
void BKE_particlesettings_copy_data( void BKE_particlesettings_copy_data(
struct Main *bmain, struct ParticleSettings *part_dst, const struct ParticleSettings *part_src, struct Main *bmain, struct ParticleSettings *part_dst, const struct ParticleSettings *part_src,
const int flag); const int flag);

@ -184,7 +184,7 @@ typedef struct PTCacheID {
} PTCacheID; } PTCacheID;
typedef struct PTCacheBaker { typedef struct PTCacheBaker {
struct Main *main; struct Main *bmain;
struct Scene *scene; struct Scene *scene;
int bake; int bake;
int render; int render;

@ -79,9 +79,9 @@ char versionstr[48] = "";
/* only to be called on exit blender */ /* only to be called on exit blender */
void BKE_blender_free(void) void BKE_blender_free(void)
{ {
/* samples are in a global list..., also sets G.main->sound->sample NULL */ /* samples are in a global list..., also sets G_MAIN->sound->sample NULL */
BKE_main_free(G.main); BKE_main_free(G_MAIN);
G.main = NULL; G_MAIN = NULL;
if (G.log.file != NULL) { if (G.log.file != NULL) {
fclose(G.log.file); fclose(G.log.file);
@ -123,7 +123,7 @@ void BKE_blender_globals_init(void)
U.savetime = 1; U.savetime = 1;
G.main = BKE_main_new(); G_MAIN = BKE_main_new();
strcpy(G.ima, "//"); strcpy(G.ima, "//");
@ -140,9 +140,9 @@ void BKE_blender_globals_init(void)
void BKE_blender_globals_clear(void) void BKE_blender_globals_clear(void)
{ {
BKE_main_free(G.main); /* free all lib data */ BKE_main_free(G_MAIN); /* free all lib data */
G.main = NULL; G_MAIN = NULL;
} }
/***/ /***/

@ -113,7 +113,7 @@ static void setup_app_data(
bContext *C, BlendFileData *bfd, bContext *C, BlendFileData *bfd,
const char *filepath, ReportList *reports) const char *filepath, ReportList *reports)
{ {
Main *bmain = G.main; /* Valid usage */ Main *bmain = G_MAIN;
Scene *curscene = NULL; Scene *curscene = NULL;
const bool is_startup = (bfd->filename[0] == '\0'); const bool is_startup = (bfd->filename[0] == '\0');
const bool recover = (G.fileflags & G_FILE_RECOVER) != 0; const bool recover = (G.fileflags & G_FILE_RECOVER) != 0;
@ -198,7 +198,7 @@ static void setup_app_data(
} }
} }
/* BKE_blender_globals_clear will free G.main, here we can still restore pointers */ /* BKE_blender_globals_clear will free G_MAIN, here we can still restore pointers */
blo_lib_link_screen_restore(bfd->main, curscreen, curscene); blo_lib_link_screen_restore(bfd->main, curscreen, curscene);
/* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */ /* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */
if (curscreen) { if (curscreen) {
@ -215,14 +215,14 @@ static void setup_app_data(
} }
} }
/* free G.main Main database */ /* free G_MAIN Main database */
// CTX_wm_manager_set(C, NULL); // CTX_wm_manager_set(C, NULL);
BKE_blender_globals_clear(); BKE_blender_globals_clear();
/* clear old property update cache, in case some old references are left dangling */ /* clear old property update cache, in case some old references are left dangling */
RNA_property_update_cache_free(); RNA_property_update_cache_free();
bmain = G.main = bfd->main; bmain = G_MAIN = bfd->main;
CTX_data_main_set(C, bmain); CTX_data_main_set(C, bmain);

@ -3499,7 +3499,7 @@ bool CustomData_verify_versions(struct CustomData *data, int index)
static void customdata_external_filename(char filename[FILE_MAX], ID *id, CustomDataExternal *external) static void customdata_external_filename(char filename[FILE_MAX], ID *id, CustomDataExternal *external)
{ {
BLI_strncpy(filename, external->filename, FILE_MAX); BLI_strncpy(filename, external->filename, FILE_MAX);
BLI_path_abs(filename, ID_BLEND_PATH(G.main, id)); BLI_path_abs(filename, ID_BLEND_PATH_FROM_GLOBAL(id));
} }
void CustomData_external_reload(CustomData *data, ID *UNUSED(id), CustomDataMask mask, int totelem) void CustomData_external_reload(CustomData *data, ID *UNUSED(id), CustomDataMask mask, int totelem)

@ -622,12 +622,12 @@ bGPDpalettecolor *BKE_gpencil_palettecolor_addnew(bGPDpalette *palette, const ch
} }
/* add a new gp-datablock */ /* add a new gp-datablock */
bGPdata *BKE_gpencil_data_addnew(const char name[]) bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[])
{ {
bGPdata *gpd; bGPdata *gpd;
/* allocate memory for a new block */ /* allocate memory for a new block */
gpd = BKE_libblock_alloc(G.main, ID_GD, name, 0); gpd = BKE_libblock_alloc(bmain, ID_GD, name, 0);
/* initial settings */ /* initial settings */
gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND); gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND);

@ -1524,7 +1524,7 @@ static void action_to_animato(ID *id, bAction *act, ListBase *groups, ListBase *
* This assumes that AnimData has been added already. Separation of drivers * This assumes that AnimData has been added already. Separation of drivers
* from animation data is accomplished here too... * from animation data is accomplished here too...
*/ */
static void ipo_to_animdata(ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq) static void ipo_to_animdata(Main *bmain, ID *id, Ipo *ipo, char actname[], char constname[], Sequence *seq)
{ {
AnimData *adt = BKE_animdata_from_id(id); AnimData *adt = BKE_animdata_from_id(id);
ListBase anim = {NULL, NULL}; ListBase anim = {NULL, NULL};
@ -1559,7 +1559,7 @@ static void ipo_to_animdata(ID *id, Ipo *ipo, char actname[], char constname[],
BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name + 2); BLI_snprintf(nameBuf, sizeof(nameBuf), "CDA:%s", ipo->id.name + 2);
adt->action = BKE_action_add(G.main, nameBuf); adt->action = BKE_action_add(bmain, nameBuf);
if (G.debug & G_DEBUG) printf("\t\tadded new action - '%s'\n", nameBuf); if (G.debug & G_DEBUG) printf("\t\tadded new action - '%s'\n", nameBuf);
} }
@ -1695,19 +1695,19 @@ static void nlastrips_to_animdata(ID *id, ListBase *strips)
* clear which datablocks have yet to be converted, and also prevent freeing errors when we exit. * clear which datablocks have yet to be converted, and also prevent freeing errors when we exit.
*/ */
// XXX currently done after all file reading... // XXX currently done after all file reading...
void do_versions_ipos_to_animato(Main *main) void do_versions_ipos_to_animato(Main *bmain)
{ {
ListBase drivers = {NULL, NULL}; ListBase drivers = {NULL, NULL};
ID *id; ID *id;
if (main == NULL) { if (bmain == NULL) {
printf("Argh! Main is NULL in do_versions_ipos_to_animato()\n"); printf("Argh! Main is NULL in do_versions_ipos_to_animato()\n");
return; return;
} }
/* only convert if version is right */ /* only convert if version is right */
if (main->versionfile >= 250) { if (bmain->versionfile >= 250) {
printf("WARNING: Animation data too new to convert (Version %d)\n", main->versionfile); printf("WARNING: Animation data too new to convert (Version %d)\n", bmain->versionfile);
return; return;
} }
else if (G.debug & G_DEBUG) else if (G.debug & G_DEBUG)
@ -1716,7 +1716,7 @@ void do_versions_ipos_to_animato(Main *main)
/* ----------- Animation Attached to Data -------------- */ /* ----------- Animation Attached to Data -------------- */
/* objects */ /* objects */
for (id = main->object.first; id; id = id->next) { for (id = bmain->object.first; id; id = id->next) {
Object *ob = (Object *)id; Object *ob = (Object *)id;
bPoseChannel *pchan; bPoseChannel *pchan;
bConstraint *con; bConstraint *con;
@ -1731,7 +1731,7 @@ void do_versions_ipos_to_animato(Main *main)
/* IPO first to take into any non-NLA'd Object Animation */ /* IPO first to take into any non-NLA'd Object Animation */
if (ob->ipo) { if (ob->ipo) {
ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, ob->ipo, NULL, NULL, NULL);
id_us_min(&ob->ipo->id); id_us_min(&ob->ipo->id);
ob->ipo = NULL; ob->ipo = NULL;
@ -1765,7 +1765,7 @@ void do_versions_ipos_to_animato(Main *main)
/* IPO second... */ /* IPO second... */
if (ob->ipo) { if (ob->ipo) {
ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, ob->ipo, NULL, NULL, NULL);
id_us_min(&ob->ipo->id); id_us_min(&ob->ipo->id);
ob->ipo = NULL; ob->ipo = NULL;
@ -1802,7 +1802,7 @@ void do_versions_ipos_to_animato(Main *main)
/* although this was the constraint's local IPO, we still need to provide pchan + con /* although this was the constraint's local IPO, we still need to provide pchan + con
* so that drivers can be added properly... * so that drivers can be added properly...
*/ */
ipo_to_animdata(id, con->ipo, pchan->name, con->name, NULL); ipo_to_animdata(bmain, id, con->ipo, pchan->name, con->name, NULL);
id_us_min(&con->ipo->id); id_us_min(&con->ipo->id);
con->ipo = NULL; con->ipo = NULL;
} }
@ -1822,7 +1822,7 @@ void do_versions_ipos_to_animato(Main *main)
/* although this was the constraint's local IPO, we still need to provide con /* although this was the constraint's local IPO, we still need to provide con
* so that drivers can be added properly... * so that drivers can be added properly...
*/ */
ipo_to_animdata(id, con->ipo, NULL, con->name, NULL); ipo_to_animdata(bmain, id, con->ipo, NULL, con->name, NULL);
id_us_min(&con->ipo->id); id_us_min(&con->ipo->id);
con->ipo = NULL; con->ipo = NULL;
} }
@ -1842,7 +1842,7 @@ void do_versions_ipos_to_animato(Main *main)
/* convert Constraint Channel's IPO data */ /* convert Constraint Channel's IPO data */
if (conchan->ipo) { if (conchan->ipo) {
ipo_to_animdata(id, conchan->ipo, NULL, conchan->name, NULL); ipo_to_animdata(bmain, id, conchan->ipo, NULL, conchan->name, NULL);
id_us_min(&conchan->ipo->id); id_us_min(&conchan->ipo->id);
conchan->ipo = NULL; conchan->ipo = NULL;
} }
@ -1861,7 +1861,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* shapekeys */ /* shapekeys */
for (id = main->key.first; id; id = id->next) { for (id = bmain->key.first; id; id = id->next) {
Key *key = (Key *)id; Key *key = (Key *)id;
if (G.debug & G_DEBUG) printf("\tconverting key %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting key %s\n", id->name + 2);
@ -1875,7 +1875,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert Shapekey data... */ /* Convert Shapekey data... */
ipo_to_animdata(id, key->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, key->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = key->ipo->blocktype; adt->action->idroot = key->ipo->blocktype;
@ -1886,7 +1886,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* materials */ /* materials */
for (id = main->mat.first; id; id = id->next) { for (id = bmain->mat.first; id; id = id->next) {
Material *ma = (Material *)id; Material *ma = (Material *)id;
if (G.debug & G_DEBUG) printf("\tconverting material %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting material %s\n", id->name + 2);
@ -1897,7 +1897,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert Material data... */ /* Convert Material data... */
ipo_to_animdata(id, ma->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, ma->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = ma->ipo->blocktype; adt->action->idroot = ma->ipo->blocktype;
@ -1908,7 +1908,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* worlds */ /* worlds */
for (id = main->world.first; id; id = id->next) { for (id = bmain->world.first; id; id = id->next) {
World *wo = (World *)id; World *wo = (World *)id;
if (G.debug & G_DEBUG) printf("\tconverting world %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting world %s\n", id->name + 2);
@ -1919,7 +1919,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert World data... */ /* Convert World data... */
ipo_to_animdata(id, wo->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, wo->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = wo->ipo->blocktype; adt->action->idroot = wo->ipo->blocktype;
@ -1930,7 +1930,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* sequence strips */ /* sequence strips */
for (id = main->scene.first; id; id = id->next) { for (id = bmain->scene.first; id; id = id->next) {
Scene *scene = (Scene *)id; Scene *scene = (Scene *)id;
Editing *ed = scene->ed; Editing *ed = scene->ed;
if (ed && ed->seqbasep) { if (ed && ed->seqbasep) {
@ -1970,7 +1970,7 @@ void do_versions_ipos_to_animato(Main *main)
icu->adrcode = adrcode; icu->adrcode = adrcode;
/* convert IPO */ /* convert IPO */
ipo_to_animdata((ID *)scene, seq->ipo, NULL, NULL, seq); ipo_to_animdata(bmain, (ID *)scene, seq->ipo, NULL, NULL, seq);
if (adt->action) if (adt->action)
adt->action->idroot = ID_SCE; /* scene-rooted */ adt->action->idroot = ID_SCE; /* scene-rooted */
@ -1984,7 +1984,7 @@ void do_versions_ipos_to_animato(Main *main)
/* textures */ /* textures */
for (id = main->tex.first; id; id = id->next) { for (id = bmain->tex.first; id; id = id->next) {
Tex *te = (Tex *)id; Tex *te = (Tex *)id;
if (G.debug & G_DEBUG) printf("\tconverting texture %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting texture %s\n", id->name + 2);
@ -1995,7 +1995,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert Texture data... */ /* Convert Texture data... */
ipo_to_animdata(id, te->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, te->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = te->ipo->blocktype; adt->action->idroot = te->ipo->blocktype;
@ -2006,7 +2006,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* cameras */ /* cameras */
for (id = main->camera.first; id; id = id->next) { for (id = bmain->camera.first; id; id = id->next) {
Camera *ca = (Camera *)id; Camera *ca = (Camera *)id;
if (G.debug & G_DEBUG) printf("\tconverting camera %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting camera %s\n", id->name + 2);
@ -2017,7 +2017,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert Camera data... */ /* Convert Camera data... */
ipo_to_animdata(id, ca->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, ca->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = ca->ipo->blocktype; adt->action->idroot = ca->ipo->blocktype;
@ -2028,7 +2028,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* lamps */ /* lamps */
for (id = main->lamp.first; id; id = id->next) { for (id = bmain->lamp.first; id; id = id->next) {
Lamp *la = (Lamp *)id; Lamp *la = (Lamp *)id;
if (G.debug & G_DEBUG) printf("\tconverting lamp %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting lamp %s\n", id->name + 2);
@ -2039,7 +2039,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert Lamp data... */ /* Convert Lamp data... */
ipo_to_animdata(id, la->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, la->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = la->ipo->blocktype; adt->action->idroot = la->ipo->blocktype;
@ -2050,7 +2050,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* curves */ /* curves */
for (id = main->curve.first; id; id = id->next) { for (id = bmain->curve.first; id; id = id->next) {
Curve *cu = (Curve *)id; Curve *cu = (Curve *)id;
if (G.debug & G_DEBUG) printf("\tconverting curve %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting curve %s\n", id->name + 2);
@ -2061,7 +2061,7 @@ void do_versions_ipos_to_animato(Main *main)
AnimData *adt = BKE_animdata_add_id(id); AnimData *adt = BKE_animdata_add_id(id);
/* Convert Curve data... */ /* Convert Curve data... */
ipo_to_animdata(id, cu->ipo, NULL, NULL, NULL); ipo_to_animdata(bmain, id, cu->ipo, NULL, NULL, NULL);
if (adt->action) if (adt->action)
adt->action->idroot = cu->ipo->blocktype; adt->action->idroot = cu->ipo->blocktype;
@ -2083,7 +2083,7 @@ void do_versions_ipos_to_animato(Main *main)
*/ */
/* actions */ /* actions */
for (id = main->action.first; id; id = id->next) { for (id = bmain->action.first; id; id = id->next) {
bAction *act = (bAction *)id; bAction *act = (bAction *)id;
if (G.debug & G_DEBUG) printf("\tconverting action %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting action %s\n", id->name + 2);
@ -2097,7 +2097,7 @@ void do_versions_ipos_to_animato(Main *main)
} }
/* ipo's */ /* ipo's */
for (id = main->ipo.first; id; id = id->next) { for (id = bmain->ipo.first; id; id = id->next) {
Ipo *ipo = (Ipo *)id; Ipo *ipo = (Ipo *)id;
if (G.debug & G_DEBUG) printf("\tconverting ipo %s\n", id->name + 2); if (G.debug & G_DEBUG) printf("\tconverting ipo %s\n", id->name + 2);
@ -2107,7 +2107,7 @@ void do_versions_ipos_to_animato(Main *main)
bAction *new_act; bAction *new_act;
/* add a new action for this, and convert all data into that action */ /* add a new action for this, and convert all data into that action */
new_act = BKE_action_add(main, id->name + 2); new_act = BKE_action_add(bmain, id->name + 2);
ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers); ipo_to_animato(NULL, ipo, NULL, NULL, NULL, NULL, &new_act->curves, &drivers);
new_act->idroot = ipo->blocktype; new_act->idroot = ipo->blocktype;
} }

@ -2014,7 +2014,7 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
/* Make full copy outside of Main database. /* Make full copy outside of Main database.
* Note: previews are not copied here. * Note: previews are not copied here.
*/ */
BKE_id_copy_ex(G.main, (ID *)ntree, (ID **)&ltree, BKE_id_copy_ex(NULL, (ID *)ntree, (ID **)&ltree,
LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_COPY_NO_PREVIEW, false); LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_COPY_NO_PREVIEW, false);
ltree->flag |= NTREE_IS_LOCALIZED; ltree->flag |= NTREE_IS_LOCALIZED;

@ -3146,7 +3146,7 @@ void psys_mat_hair_to_global(Object *ob, DerivedMesh *dm, short from, ParticleDa
/************************************************/ /************************************************/
/* ParticleSettings handling */ /* ParticleSettings handling */
/************************************************/ /************************************************/
ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *name) ModifierData *object_add_particle_system(Main *bmain, Scene *scene, Object *ob, const char *name)
{ {
ParticleSystem *psys; ParticleSystem *psys;
ModifierData *md; ModifierData *md;
@ -3163,7 +3163,7 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
psys->pointcache = BKE_ptcache_add(&psys->ptcaches); psys->pointcache = BKE_ptcache_add(&psys->ptcaches);
BLI_addtail(&ob->particlesystem, psys); BLI_addtail(&ob->particlesystem, psys);
psys->part = BKE_particlesettings_add(NULL, DATA_("ParticleSettings")); psys->part = BKE_particlesettings_add(bmain, DATA_("ParticleSettings"));
if (BLI_listbase_count_at_most(&ob->particlesystem, 2) > 1) if (BLI_listbase_count_at_most(&ob->particlesystem, 2) > 1)
BLI_snprintf(psys->name, sizeof(psys->name), DATA_("ParticleSystem %i"), BLI_listbase_count(&ob->particlesystem)); BLI_snprintf(psys->name, sizeof(psys->name), DATA_("ParticleSystem %i"), BLI_listbase_count(&ob->particlesystem));
@ -3186,12 +3186,12 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
psys->flag = PSYS_CURRENT; psys->flag = PSYS_CURRENT;
psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1); psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1);
DAG_relations_tag_update(G.main); DAG_relations_tag_update(bmain);
DAG_id_tag_update(&ob->id, OB_RECALC_DATA); DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
return md; return md;
} }
void object_remove_particle_system(Scene *UNUSED(scene), Object *ob) void object_remove_particle_system(Main *bmain, Scene *UNUSED(scene), Object *ob)
{ {
ParticleSystem *psys = psys_get_current(ob); ParticleSystem *psys = psys_get_current(ob);
ParticleSystemModifierData *psmd; ParticleSystemModifierData *psmd;
@ -3232,7 +3232,7 @@ void object_remove_particle_system(Scene *UNUSED(scene), Object *ob)
else else
ob->mode &= ~OB_MODE_PARTICLE_EDIT; ob->mode &= ~OB_MODE_PARTICLE_EDIT;
DAG_relations_tag_update(G.main); DAG_relations_tag_update(bmain);
DAG_id_tag_update(&ob->id, OB_RECALC_DATA); DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
} }
@ -3321,14 +3321,11 @@ static void default_particle_settings(ParticleSettings *part)
} }
ParticleSettings *BKE_particlesettings_add(Main *main, const char *name) ParticleSettings *BKE_particlesettings_add(Main *bmain, const char *name)
{ {
ParticleSettings *part; ParticleSettings *part;
if (main == NULL) part = BKE_libblock_alloc(bmain, ID_PA, name, 0);
main = G.main;
part = BKE_libblock_alloc(main, ID_PA, name, 0);
default_particle_settings(part); default_particle_settings(part);

@ -3516,7 +3516,7 @@ void BKE_ptcache_quick_cache_all(Main *bmain, Scene *scene)
PTCacheBaker baker; PTCacheBaker baker;
memset(&baker, 0, sizeof(baker)); memset(&baker, 0, sizeof(baker));
baker.main = bmain; baker.bmain = bmain;
baker.scene = scene; baker.scene = scene;
baker.bake = 0; baker.bake = 0;
baker.render = 0; baker.render = 0;
@ -3541,7 +3541,7 @@ static void ptcache_dt_to_str(char *str, double dtime)
/* if bake is not given run simulations to current frame */ /* if bake is not given run simulations to current frame */
void BKE_ptcache_bake(PTCacheBaker *baker) void BKE_ptcache_bake(PTCacheBaker *baker)
{ {
Main *bmain = baker->main; Main *bmain = baker->bmain;
Scene *scene = baker->scene; Scene *scene = baker->scene;
Scene *sce_iter; /* SETLOOPER macro only */ Scene *sce_iter; /* SETLOOPER macro only */
Base *base; Base *base;

@ -52,14 +52,15 @@
#include "DNA_view3d_types.h" #include "DNA_view3d_types.h"
#include "DNA_gpencil_types.h" #include "DNA_gpencil_types.h"
#include "BKE_colortools.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_gpencil.h" #include "BKE_gpencil.h"
#include "BKE_library.h" #include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h" #include "BKE_object.h"
#include "BKE_report.h" #include "BKE_report.h"
#include "BKE_scene.h" #include "BKE_scene.h"
#include "BKE_screen.h" #include "BKE_screen.h"
#include "BKE_colortools.h"
#include "UI_interface.h" #include "UI_interface.h"
#include "UI_resources.h" #include "UI_resources.h"
@ -83,6 +84,7 @@
/* add new datablock - wrapper around API */ /* add new datablock - wrapper around API */
static int gp_data_add_exec(bContext *C, wmOperator *op) static int gp_data_add_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C);
bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
ToolSettings *ts = CTX_data_tool_settings(C); ToolSettings *ts = CTX_data_tool_settings(C);
@ -95,7 +97,7 @@ static int gp_data_add_exec(bContext *C, wmOperator *op)
bGPdata *gpd = (*gpd_ptr); bGPdata *gpd = (*gpd_ptr);
id_us_min(&gpd->id); id_us_min(&gpd->id);
*gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil")); *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
/* if not exist brushes, create a new set */ /* if not exist brushes, create a new set */
if (ts) { if (ts) {
@ -183,6 +185,7 @@ void GPENCIL_OT_data_unlink(wmOperatorType *ot)
/* add new layer - wrapper around API */ /* add new layer - wrapper around API */
static int gp_layer_add_exec(bContext *C, wmOperator *op) static int gp_layer_add_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C);
bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
ToolSettings *ts = CTX_data_tool_settings(C); ToolSettings *ts = CTX_data_tool_settings(C);
@ -192,7 +195,7 @@ static int gp_layer_add_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
if (*gpd_ptr == NULL) if (*gpd_ptr == NULL)
*gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil")); *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
/* if not exist brushes, create a new set */ /* if not exist brushes, create a new set */
if (ts) { if (ts) {
@ -1376,6 +1379,7 @@ void GPENCIL_OT_brush_select(wmOperatorType *ot)
/* add new palette - wrapper around API */ /* add new palette - wrapper around API */
static int gp_palette_add_exec(bContext *C, wmOperator *op) static int gp_palette_add_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C);
bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
/* if there's no existing Grease-Pencil data there, add some */ /* if there's no existing Grease-Pencil data there, add some */
@ -1384,7 +1388,7 @@ static int gp_palette_add_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
if (*gpd_ptr == NULL) if (*gpd_ptr == NULL)
*gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil")); *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
/* add new palette now */ /* add new palette now */
BKE_gpencil_palette_addnew(*gpd_ptr, DATA_("GP_Palette"), true); BKE_gpencil_palette_addnew(*gpd_ptr, DATA_("GP_Palette"), true);
@ -1588,6 +1592,7 @@ void GPENCIL_OT_palette_lock_layer(wmOperatorType *ot)
/* add new palette - wrapper around API */ /* add new palette - wrapper around API */
static int gp_palettecolor_add_exec(bContext *C, wmOperator *op) static int gp_palettecolor_add_exec(bContext *C, wmOperator *op)
{ {
Main *bmain = CTX_data_main(C);
bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL); bGPdata **gpd_ptr = ED_gpencil_data_get_pointers(C, NULL);
/* if there's no existing Grease-Pencil data there, add some */ /* if there's no existing Grease-Pencil data there, add some */
@ -1596,7 +1601,7 @@ static int gp_palettecolor_add_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
if (*gpd_ptr == NULL) if (*gpd_ptr == NULL)
*gpd_ptr = BKE_gpencil_data_addnew(DATA_("GPencil")); *gpd_ptr = BKE_gpencil_data_addnew(bmain, DATA_("GPencil"));
/* verify palette */ /* verify palette */
bGPDpalette *palette = BKE_gpencil_palette_getactive(*gpd_ptr); bGPDpalette *palette = BKE_gpencil_palette_getactive(*gpd_ptr);

@ -1381,6 +1381,7 @@ static void gp_init_palette(tGPsdata *p)
/* (re)init new painting data */ /* (re)init new painting data */
static bool gp_session_initdata(bContext *C, tGPsdata *p) static bool gp_session_initdata(bContext *C, tGPsdata *p)
{ {
Main *bmain = CTX_data_main(C);
bGPdata **gpd_ptr = NULL; bGPdata **gpd_ptr = NULL;
ScrArea *curarea = CTX_wm_area(C); ScrArea *curarea = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C); ARegion *ar = CTX_wm_region(C);
@ -1530,7 +1531,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
else { else {
/* if no existing GPencil block exists, add one */ /* if no existing GPencil block exists, add one */
if (*gpd_ptr == NULL) if (*gpd_ptr == NULL)
*gpd_ptr = BKE_gpencil_data_addnew("GPencil"); *gpd_ptr = BKE_gpencil_data_addnew(bmain, "GPencil");
p->gpd = *gpd_ptr; p->gpd = *gpd_ptr;
} }

@ -115,7 +115,7 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *sc
/* don't need to worry about the new modifier's name, since that is set to the number /* don't need to worry about the new modifier's name, since that is set to the number
* of particle systems which shouldn't have too many duplicates * of particle systems which shouldn't have too many duplicates
*/ */
new_md = object_add_particle_system(scene, ob, name); new_md = object_add_particle_system(bmain, scene, ob, name);
} }
else { else {
/* get new modifier data to add */ /* get new modifier data to add */

@ -77,13 +77,14 @@ static float I[4][4] = {{1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0
static int particle_system_add_exec(bContext *C, wmOperator *UNUSED(op)) static int particle_system_add_exec(bContext *C, wmOperator *UNUSED(op))
{ {
Main *bmain = CTX_data_main(C);
Object *ob= ED_object_context(C); Object *ob= ED_object_context(C);
Scene *scene = CTX_data_scene(C); Scene *scene = CTX_data_scene(C);
if (!scene || !ob) if (!scene || !ob)
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
object_add_particle_system(scene, ob, NULL); object_add_particle_system(bmain, scene, ob, NULL);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob); WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob);
@ -108,6 +109,7 @@ void OBJECT_OT_particle_system_add(wmOperatorType *ot)
static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op)) static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
{ {
Main *bmain = CTX_data_main(C);
Object *ob = ED_object_context(C); Object *ob = ED_object_context(C);
Scene *scene = CTX_data_scene(C); Scene *scene = CTX_data_scene(C);
int mode_orig; int mode_orig;
@ -116,7 +118,7 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
mode_orig = ob->mode; mode_orig = ob->mode;
object_remove_particle_system(scene, ob); object_remove_particle_system(bmain, scene, ob);
/* possible this isn't the active object /* possible this isn't the active object
* object_remove_particle_system() clears the mode on the last psys * object_remove_particle_system() clears the mode on the last psys

@ -163,7 +163,7 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all)
{ {
PTCacheBaker *baker = MEM_callocN(sizeof(PTCacheBaker), "PTCacheBaker"); PTCacheBaker *baker = MEM_callocN(sizeof(PTCacheBaker), "PTCacheBaker");
baker->main = CTX_data_main(C); baker->bmain = CTX_data_main(C);
baker->scene = CTX_data_scene(C); baker->scene = CTX_data_scene(C);
baker->bake = RNA_boolean_get(op->ptr, "bake"); baker->bake = RNA_boolean_get(op->ptr, "bake");
baker->render = 0; baker->render = 0;

@ -38,8 +38,9 @@
#include "BLT_translation.h" #include "BLT_translation.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_unit.h"
#include "BKE_gpencil.h" #include "BKE_gpencil.h"
#include "BKE_main.h"
#include "BKE_unit.h"
#include "BIF_gl.h" #include "BIF_gl.h"
@ -292,6 +293,7 @@ static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state)
#define RULER_ID "RulerData3D" #define RULER_ID "RulerData3D"
static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info) static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
{ {
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C); Scene *scene = CTX_data_scene(C);
bGPDlayer *gpl; bGPDlayer *gpl;
bGPDframe *gpf; bGPDframe *gpf;
@ -303,7 +305,7 @@ static bool view3d_ruler_to_gpencil(bContext *C, RulerInfo *ruler_info)
bool changed = false; bool changed = false;
if (scene->gpd == NULL) { if (scene->gpd == NULL) {
scene->gpd = BKE_gpencil_data_addnew("GPencil"); scene->gpd = BKE_gpencil_data_addnew(bmain, "GPencil");
} }
gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info)); gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info));

@ -1773,7 +1773,7 @@ void RNA_def_main_gpencil(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
func = RNA_def_function(srna, "new", "BKE_gpencil_data_addnew"); func = RNA_def_function(srna, "new", "BKE_gpencil_data_addnew");
RNA_def_function_flag(func, FUNC_NO_SELF); RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_MAIN);
parm = RNA_def_string(func, "name", "GreasePencil", 0, "", "New name for the data-block"); parm = RNA_def_string(func, "name", "GreasePencil", 0, "", "New name for the data-block");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
/* return type */ /* return type */

@ -3190,7 +3190,7 @@ static void update_physics_cache(Render *re, Scene *scene, int UNUSED(anim_init)
PTCacheBaker baker; PTCacheBaker baker;
memset(&baker, 0, sizeof(baker)); memset(&baker, 0, sizeof(baker));
baker.main = re->main; baker.bmain = re->main;
baker.scene = scene; baker.scene = scene;
baker.bake = 0; baker.bake = 0;
baker.render = 1; baker.render = 1;