diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-03-19 21:03:18 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-03-19 21:04:50 +0300 |
commit | 254bb922e8654a85b3c3e2c715cb4a078f832bcb (patch) | |
tree | 2b6a0446a99186ff139742516daf06e9b734d11b | |
parent | 402486ea7bc52f669bc02a00c5e2703590361409 (diff) |
Cleanup: avoid passing bContext to particle API
Also add EvaluationContext to PEData
5 files changed, 50 insertions, 54 deletions
diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h index ffa6db18caa..ee60d1c8eef 100644 --- a/source/blender/editors/include/ED_particle.h +++ b/source/blender/editors/include/ED_particle.h @@ -55,7 +55,7 @@ struct ParticleEditSettings *PE_settings(struct Scene *scene); void PE_hide_keys_time(struct Scene *scene, struct PTCacheEdit *edit, float cfra); void PE_update_object( const struct EvaluationContext *eval_ctx, struct Scene *scene, - struct ViewLayer *view_layer, struct Object *ob, int useflag); + struct Object *ob, int useflag); /* selection tools */ int PE_mouse_particles(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle); diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index e1dcec1d9ab..224790269e2 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -351,6 +351,7 @@ typedef struct PEData { DerivedMesh *dm; PTCacheEdit *edit; BVHTreeFromMesh shape_bvh; + EvaluationContext eval_ctx; const int *mval; rcti *rect; @@ -383,6 +384,7 @@ static void PE_set_data(bContext *C, PEData *data) data->scene = CTX_data_scene(C); data->view_layer = CTX_data_view_layer(C); data->ob = CTX_data_active_object(C); + CTX_data_eval_ctx(C, &data->eval_ctx); data->edit = PE_get_current(data->scene, data->view_layer, data->ob); } @@ -394,13 +396,10 @@ static void PE_set_view3d_data(bContext *C, PEData *data) if (V3D_IS_ZBUF(data->vc.v3d)) { if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) { - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - /* needed or else the draw matrix can be incorrect */ view3d_operator_needs_opengl(C); - ED_view3d_backbuf_validate(&eval_ctx, &data->vc); + ED_view3d_backbuf_validate(&data->eval_ctx, &data->vc); /* we may need to force an update here by setting the rv3d as dirty * for now it seems ok, but take care!: * rv3d->depths->dirty = 1; */ @@ -1145,15 +1144,12 @@ void recalc_emitter_field(Object *ob, ParticleSystem *psys) BLI_kdtree_balance(edit->emitter_field); } -static void PE_update_selection(const bContext *C, Scene *scene, ViewLayer *view_layer, Object *ob, int useflag) +static void PE_update_selection(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int useflag) { - PTCacheEdit *edit = PE_get_current(scene, view_layer, ob); + PTCacheEdit *edit = PE_get_current(scene, eval_ctx->view_layer, ob); HairKey *hkey; - EvaluationContext eval_ctx; POINT_P; KEY_K; - CTX_data_eval_ctx(C, &eval_ctx); - /* flag all particles to be updated if not using flag */ if (!useflag) LOOP_POINTS @@ -1169,7 +1165,7 @@ static void PE_update_selection(const bContext *C, Scene *scene, ViewLayer *view } } - psys_cache_edit_paths(&eval_ctx, scene, ob, edit, CFRA, G.is_rendering); + psys_cache_edit_paths(eval_ctx, scene, ob, edit, CFRA, G.is_rendering); /* disable update flag */ @@ -1255,12 +1251,12 @@ static void update_velocities(PTCacheEdit *edit) } } -void PE_update_object(const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, Object *ob, int useflag) +void PE_update_object(const EvaluationContext *eval_ctx, Scene *scene, Object *ob, int useflag) { /* use this to do partial particle updates, not usable when adding or * removing, then a full redo is necessary and calling this may crash */ ParticleEditSettings *pset= PE_settings(scene); - PTCacheEdit *edit = PE_get_current(scene, view_layer, ob); + PTCacheEdit *edit = PE_get_current(scene, eval_ctx->view_layer, ob); POINT_P; if (!edit) @@ -1397,9 +1393,10 @@ static void select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, in static int pe_select_all_exec(bContext *C, wmOperator *op) { Scene *scene= CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); Object *ob= CTX_data_active_object(C); - PTCacheEdit *edit= PE_get_current(scene, view_layer, ob); + PTCacheEdit *edit= PE_get_current(scene, eval_ctx.view_layer, ob); POINT_P; KEY_K; int action = RNA_enum_get(op->ptr, "action"); @@ -1422,7 +1419,7 @@ static int pe_select_all_exec(bContext *C, wmOperator *op) } } - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1480,7 +1477,7 @@ int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselec else for_mouse_hit_keys(&data, toggle_key_select, 1); - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&data.eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1521,7 +1518,7 @@ static int select_roots_exec(bContext *C, wmOperator *op) data.select_action = action; foreach_point(&data, select_root); - PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); + PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1586,7 +1583,7 @@ static int select_tips_exec(bContext *C, wmOperator *op) data.select_action = action; foreach_point(&data, select_tip); - PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); + PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1625,7 +1622,6 @@ static int select_random_exec(bContext *C, wmOperator *op) PEData data; int type; Scene *scene; - ViewLayer *view_layer; Object *ob; /* used by LOOP_VISIBLE_POINTS, LOOP_VISIBLE_KEYS and LOOP_KEYS */ @@ -1645,9 +1641,8 @@ static int select_random_exec(bContext *C, wmOperator *op) PE_set_data(C, &data); data.select_action = SEL_SELECT; scene = CTX_data_scene(C); - view_layer = CTX_data_view_layer(C); ob = CTX_data_active_object(C); - edit = PE_get_current(scene, view_layer, ob); + edit = PE_get_current(scene, data.eval_ctx.view_layer, ob); rng = BLI_rng_new_srandom(seed); @@ -1672,7 +1667,7 @@ static int select_random_exec(bContext *C, wmOperator *op) BLI_rng_free(rng); - PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); + PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1716,7 +1711,7 @@ static int select_linked_exec(bContext *C, wmOperator *op) data.select= !RNA_boolean_get(op->ptr, "deselect"); for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */ - PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); + PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -1781,7 +1776,7 @@ int PE_border_select(bContext *C, rcti *rect, bool select, bool extend) for_mouse_hit_keys(&data, select_key, 0); - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&data.eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1807,7 +1802,7 @@ int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad) for_mouse_hit_keys(&data, select_key, 0); - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&data.eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1896,7 +1891,7 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool } } - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&data.eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1908,10 +1903,13 @@ static int hide_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - PTCacheEdit *edit= PE_get_current(scene, view_layer, ob); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + + PTCacheEdit *edit= PE_get_current(scene, eval_ctx.view_layer, ob); POINT_P; KEY_K; - + + if (RNA_enum_get(op->ptr, "unselected")) { LOOP_UNSELECTED_POINTS { point->flag |= PEP_HIDE; @@ -1931,7 +1929,7 @@ static int hide_exec(bContext *C, wmOperator *op) } } - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -1961,8 +1959,9 @@ static int reveal_exec(bContext *C, wmOperator *op) { Object *ob= CTX_data_active_object(C); Scene *scene= CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - PTCacheEdit *edit= PE_get_current(scene, view_layer, ob); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + PTCacheEdit *edit= PE_get_current(scene, eval_ctx.view_layer, ob); const bool select = RNA_boolean_get(op->ptr, "select"); POINT_P; KEY_K; @@ -1977,7 +1976,7 @@ static int reveal_exec(bContext *C, wmOperator *op) } } - PE_update_selection(C, scene, view_layer, ob, 1); + PE_update_selection(&eval_ctx, scene, ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob); return OPERATOR_FINISHED; @@ -2039,7 +2038,7 @@ static int select_less_exec(bContext *C, wmOperator *UNUSED(op)) PE_set_data(C, &data); foreach_point(&data, select_less_keys); - PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); + PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -2101,7 +2100,7 @@ static int select_more_exec(bContext *C, wmOperator *UNUSED(op)) PE_set_data(C, &data); foreach_point(&data, select_more_keys); - PE_update_selection(C, data.scene, data.view_layer, data.ob, 1); + PE_update_selection(&data.eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob); return OPERATOR_FINISHED; @@ -2204,7 +2203,7 @@ static int rekey_exec(bContext *C, wmOperator *op) foreach_selected_point(&data, rekey_particle); recalc_lengths(data.edit); - PE_update_object(&eval_ctx, data.scene, data.view_layer, data.ob, 1); + PE_update_object(&eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -2545,7 +2544,7 @@ static int subdivide_exec(bContext *C, wmOperator *UNUSED(op)) foreach_point(&data, subdivide_particle); recalc_lengths(data.edit); - PE_update_object(&eval_ctx, data.scene, data.view_layer, data.ob, 1); + PE_update_object(&eval_ctx, data.scene, data.ob, 1); WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob); return OPERATOR_FINISHED; @@ -4008,7 +4007,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { - PE_update_object(&eval_ctx, scene, view_layer, ob, 1); + PE_update_object(&eval_ctx, scene, ob, 1); } } @@ -4244,9 +4243,6 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) if (!PE_start_edit(edit)) return OPERATOR_CANCELLED; - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - /* disable locking temporatily for disconnected hair */ if (edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR) pset->flag &= ~PE_LOCK_FIRST; @@ -4275,7 +4271,7 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) DEG_id_tag_update(&ob->id, OB_RECALC_DATA); } else { - PE_update_object(&eval_ctx, scene, view_layer, ob, 1); + PE_update_object(&data.eval_ctx, scene, ob, 1); } if (edit->psys) { @@ -4453,7 +4449,7 @@ void PE_create_particle_edit( recalc_lengths(edit); if (psys && !cache) recalc_emitter_field(ob, psys); - PE_update_object(eval_ctx, scene, view_layer, ob, 1); + PE_update_object(eval_ctx, scene, ob, 1); PTCacheUndo_clear(edit); PE_undo_push(scene, view_layer, "Original"); @@ -4667,8 +4663,10 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - PTCacheEdit *edit = PE_get_current(scene, view_layer, ob); + EvaluationContext eval_ctx; + CTX_data_eval_ctx(C, &eval_ctx); + + PTCacheEdit *edit = PE_get_current(scene, eval_ctx.view_layer, ob); float average_length = calculate_average_length(edit); if (average_length == 0.0f) { @@ -4676,10 +4674,8 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) } scale_points_to_length(edit, average_length); - EvaluationContext eval_ctx; - CTX_data_eval_ctx(C, &eval_ctx); - PE_update_object(&eval_ctx, scene, view_layer, ob, 1); + PE_update_object(&eval_ctx, scene, ob, 1); if (edit->psys) { WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob); } diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index c8755ea0ed2..cbdb6e4592c 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -595,7 +595,7 @@ static void disconnect_hair( if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_PUFF)) pset->brushtype = PE_BRUSH_NONE; - PE_update_object(eval_ctx, scene, view_layer, ob, 0); + PE_update_object(eval_ctx, scene, ob, 0); } static int disconnect_hair_exec(bContext *C, wmOperator *op) @@ -832,7 +832,7 @@ static bool remap_hair_emitter( psys_free_path_cache(target_psys, target_edit); - PE_update_object(eval_ctx, scene, view_layer, target_ob, 0); + PE_update_object(eval_ctx, scene, target_ob, 0); return true; } @@ -964,7 +964,7 @@ static void copy_particle_edit( recalc_lengths(edit); recalc_emitter_field(ob, psys); - PE_update_object(eval_ctx, scene, view_layer, ob, true); + PE_update_object(eval_ctx, scene, ob, true); PTCacheUndo_clear(edit); PE_undo_push(scene, view_layer, "Original"); diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index 896b24d3086..adb2d475464 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -6622,7 +6622,7 @@ static void draw_update_ptcache_edit( const EvaluationContext *eval_ctx, Scene *scene, ViewLayer *view_layer, Object *ob, PTCacheEdit *edit) { if (edit->psys && edit->psys->flag & PSYS_HAIR_UPDATED) - PE_update_object(eval_ctx, scene, view_layer, ob, 0); + PE_update_object(eval_ctx, scene, ob, 0); /* create path and child path cache if it doesn't exist already */ if (edit->pathcache == NULL) { diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index d73d5e82d0f..5d267767cf9 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -2049,7 +2049,7 @@ void flushTransParticles(TransInfo *t) point->flag |= PEP_EDIT_RECALC; } - PE_update_object(&t->eval_ctx, scene, view_layer, OBACT(view_layer), 1); + PE_update_object(&t->eval_ctx, scene, OBACT(view_layer), 1); } /* ********************* mesh ****************** */ |