Skip to content

Commit 4c0810c

Browse files
committed
Get rid of redundant geoms_ in world.hpp
1 parent fd1e309 commit 4c0810c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/multi_body.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ class MultiBody {
9191

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

94+
virtual ~MultiBody() { clear(); }
95+
96+
void clear() {
97+
for (auto p : collision_geometries_) {
98+
delete p;
99+
}
100+
collision_geometries_.clear();
101+
}
102+
94103
template <typename AlgebraTo = Algebra>
95104
MultiBody<AlgebraTo> clone() const {
96105
typedef Conversion<Algebra, AlgebraTo> C;
@@ -588,7 +597,7 @@ class MultiBody {
588597
"JOINT_FIXED", "JOINT_PRISMATIC_X", "JOINT_PRISMATIC_Y",
589598
"JOINT_PRISMATIC_Z", "JOINT_PRISMATIC_AXIS", "JOINT_REVOLUTE_X",
590599
"JOINT_REVOLUTE_Y", "JOINT_REVOLUTE_Z", "JOINT_REVOLUTE_AXIS",
591-
"JOINT_SPHERICAL", "JOINT_INVALID",
600+
"JOINT_SPHERICAL", "JOINT_INVALID",
592601
};
593602
return names[int(t) + 1];
594603
}

src/rigid_body.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class RigidBody {
5959
Algebra::set_zero(total_torque_);
6060
}
6161

62+
virtual ~RigidBody() { delete geometry_; }
63+
6264
template <typename AlgebraTo = Algebra>
6365
RigidBody<AlgebraTo> clone() const {
6466
typedef Conversion<Algebra, AlgebraTo> C;

src/world.hpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ class World {
4848
std::vector<MultiBody*> multi_bodies_;
4949

5050
Vector3 gravity_acceleration_;
51-
52-
std::vector<Geometry*> geoms_;
53-
54-
51+
5552

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

7875
size_t num_rigid_bodies() const { return rigid_bodies_.size(); }
7976
size_t num_multi_bodies() const { return multi_bodies_.size(); }
80-
size_t num_geoms() const { return geoms_.size(); }
8177

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

10197
void clear() {
102-
while (!geoms_.empty()) {
103-
delete geoms_.back(), geoms_.pop_back();
104-
}
10598
while (!rigid_bodies_.empty()) {
10699
delete rigid_bodies_.back(), rigid_bodies_.pop_back();
107100
}
@@ -122,25 +115,21 @@ class World {
122115

123116
Capsule* create_capsule(const Scalar& radius, const Scalar& length) {
124117
Capsule* capsule = new Capsule(radius, length);
125-
geoms_.push_back(capsule);
126118
return capsule;
127119
}
128120

129121
Plane* create_plane() {
130122
Plane* plane = new Plane();
131-
geoms_.push_back(plane);
132123
return plane;
133124
}
134125

135126
Sphere* create_sphere(const Scalar& radius) {
136127
Sphere* sphere = new Sphere(radius);
137-
geoms_.push_back(sphere);
138128
return sphere;
139129
}
140130

141131
Box* create_box (const Vector3& extents) {
142132
Box* box = new Box(extents);
143-
geoms_.push_back(box);
144133
return box;
145134
}
146135

0 commit comments

Comments
 (0)