SoftBody: refactored sbFree()
This prevents having to wrap each call to sbFree() in an if(ob->soft) condition and assign ob->soft = NULL after calling. Furthermore, passing `Object *` allows us to change freeing behaviour depending on whether the object is an evaluated copy or an original (not done in this commit yet).
This commit is contained in:
parent
75b5ff6698
commit
9e4d667c2c
|
@ -54,7 +54,7 @@ typedef struct BodyPoint {
|
|||
extern struct SoftBody *sbNew(struct Scene *scene);
|
||||
|
||||
/* frees internal data and softbody itself */
|
||||
extern void sbFree(struct SoftBody *sb);
|
||||
extern void sbFree(struct Object *ob);
|
||||
|
||||
/* frees simulation data to reset simulation */
|
||||
extern void sbFreeSimulation(struct SoftBody *sb);
|
||||
|
|
|
@ -165,10 +165,7 @@ void BKE_object_free_particlesystems(Object *ob)
|
|||
|
||||
void BKE_object_free_softbody(Object *ob)
|
||||
{
|
||||
if (ob->soft) {
|
||||
sbFree(ob->soft);
|
||||
ob->soft = NULL;
|
||||
}
|
||||
sbFree(ob);
|
||||
}
|
||||
|
||||
void BKE_object_free_curve_cache(Object *ob)
|
||||
|
@ -452,10 +449,7 @@ void BKE_object_free(Object *ob)
|
|||
BKE_rigidbody_free_object(ob, NULL);
|
||||
BKE_rigidbody_free_constraint(ob);
|
||||
|
||||
if (ob->soft) {
|
||||
sbFree(ob->soft);
|
||||
ob->soft = NULL;
|
||||
}
|
||||
sbFree(ob);
|
||||
|
||||
for (ObjectEngineData *oed = ob->drawdata.first; oed; oed = oed->next) {
|
||||
if (oed->free != NULL) {
|
||||
|
|
|
@ -3287,14 +3287,21 @@ SoftBody *sbNew(Scene *scene)
|
|||
}
|
||||
|
||||
/* frees all */
|
||||
void sbFree(SoftBody *sb)
|
||||
void sbFree(Object *ob)
|
||||
{
|
||||
SoftBody *sb = ob->soft;
|
||||
if (sb == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
free_softbody_intern(sb);
|
||||
BKE_ptcache_free_list(&sb->ptcaches);
|
||||
sb->pointcache = NULL;
|
||||
if (sb->effector_weights)
|
||||
MEM_freeN(sb->effector_weights);
|
||||
MEM_freeN(sb);
|
||||
|
||||
ob->soft = NULL;
|
||||
}
|
||||
|
||||
void sbFreeSimulation(SoftBody *sb)
|
||||
|
|
|
@ -1050,7 +1050,7 @@ static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short ev
|
|||
DEG_relations_tag_update(bmain);
|
||||
}
|
||||
else if (event == 23) {
|
||||
if (base->object->soft) sbFree(base->object->soft);
|
||||
sbFree(base->object);
|
||||
BKE_object_copy_softbody(base->object, ob, 0);
|
||||
|
||||
if (!modifiers_findByType(base->object, eModifierType_Softbody)) {
|
||||
|
|
|
@ -293,9 +293,8 @@ static bool object_modifier_remove(Main *bmain, Object *ob, ModifierData *md,
|
|||
}
|
||||
else if (md->type == eModifierType_Softbody) {
|
||||
if (ob->soft) {
|
||||
sbFree(ob->soft);
|
||||
ob->soft = NULL;
|
||||
ob->softflag = 0;
|
||||
sbFree(ob);
|
||||
ob->softflag = 0; /* TODO(Sybren): this should probably be moved into sbFree() */
|
||||
}
|
||||
}
|
||||
else if (md->type == eModifierType_Collision) {
|
||||
|
|
Loading…
Reference in New Issue