Skip to content

Commit

Permalink
Get rid of redundant geoms_ in world.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jotix16 committed Apr 22, 2022
1 parent fd1e309 commit 4c0810c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
11 changes: 10 additions & 1 deletion src/multi_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ class MultiBody {

explicit MultiBody(bool isFloating = false) : is_floating_(isFloating) {}

virtual ~MultiBody() { clear(); }

void clear() {
for (auto p : collision_geometries_) {
delete p;
}
collision_geometries_.clear();
}

template <typename AlgebraTo = Algebra>
MultiBody<AlgebraTo> clone() const {
typedef Conversion<Algebra, AlgebraTo> C;
Expand Down Expand Up @@ -588,7 +597,7 @@ class MultiBody {
"JOINT_FIXED", "JOINT_PRISMATIC_X", "JOINT_PRISMATIC_Y",
"JOINT_PRISMATIC_Z", "JOINT_PRISMATIC_AXIS", "JOINT_REVOLUTE_X",
"JOINT_REVOLUTE_Y", "JOINT_REVOLUTE_Z", "JOINT_REVOLUTE_AXIS",
"JOINT_SPHERICAL", "JOINT_INVALID",
"JOINT_SPHERICAL", "JOINT_INVALID",
};
return names[int(t) + 1];
}
Expand Down
2 changes: 2 additions & 0 deletions src/rigid_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class RigidBody {
Algebra::set_zero(total_torque_);
}

virtual ~RigidBody() { delete geometry_; }

template <typename AlgebraTo = Algebra>
RigidBody<AlgebraTo> clone() const {
typedef Conversion<Algebra, AlgebraTo> C;
Expand Down
13 changes: 1 addition & 12 deletions src/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ class World {
std::vector<MultiBody*> multi_bodies_;

Vector3 gravity_acceleration_;

std::vector<Geometry*> geoms_;




CollisionDispatcher<Algebra> dispatcher_;
RigidBodyConstraintSolver<Algebra>* rb_constraint_solver_{nullptr};
Expand All @@ -77,7 +74,6 @@ class World {

size_t num_rigid_bodies() const { return rigid_bodies_.size(); }
size_t num_multi_bodies() const { return multi_bodies_.size(); }
size_t num_geoms() const { return geoms_.size(); }

inline void submit_profile_timing(const char* name=0) const {
if (profile_timing_func_) {
Expand All @@ -99,9 +95,6 @@ class World {
}

void clear() {
while (!geoms_.empty()) {
delete geoms_.back(), geoms_.pop_back();
}
while (!rigid_bodies_.empty()) {
delete rigid_bodies_.back(), rigid_bodies_.pop_back();
}
Expand All @@ -122,25 +115,21 @@ class World {

Capsule* create_capsule(const Scalar& radius, const Scalar& length) {
Capsule* capsule = new Capsule(radius, length);
geoms_.push_back(capsule);
return capsule;
}

Plane* create_plane() {
Plane* plane = new Plane();
geoms_.push_back(plane);
return plane;
}

Sphere* create_sphere(const Scalar& radius) {
Sphere* sphere = new Sphere(radius);
geoms_.push_back(sphere);
return sphere;
}

Box* create_box (const Vector3& extents) {
Box* box = new Box(extents);
geoms_.push_back(box);
return box;
}

Expand Down

0 comments on commit 4c0810c

Please sign in to comment.