diff --git a/CHANGELOG.md b/CHANGELOG.md index 8697e8547936a..78f54127008ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ * Misc + * Add World::create(): [#962](https://github.com/dartsim/dart/pull/962) * Suppressed warnings: [#937](https://github.com/dartsim/dart/pull/937) * Fixed various build issues with Visual Studio: [#956](https://github.com/dartsim/dart/pull/956) diff --git a/dart/simulation/World.cpp b/dart/simulation/World.cpp index 1103db8f4560d..0269cc8657661 100644 --- a/dart/simulation/World.cpp +++ b/dart/simulation/World.cpp @@ -51,6 +51,12 @@ namespace dart { namespace simulation { +//============================================================================== +std::shared_ptr World::create(const std::string& name) +{ + return std::make_shared(name); +} + //============================================================================== World::World(const std::string& _name) : mName(_name), @@ -83,7 +89,7 @@ World::~World() //============================================================================== WorldPtr World::clone() const { - WorldPtr worldClone(new World(mName)); + WorldPtr worldClone = World::create(mName); worldClone->setGravity(mGravity); worldClone->setTimeStep(mTimeStep); diff --git a/dart/simulation/World.hpp b/dart/simulation/World.hpp index 7453b99beb9bf..acada0edf7045 100644 --- a/dart/simulation/World.hpp +++ b/dart/simulation/World.hpp @@ -86,6 +86,9 @@ class World : public virtual common::Subject // Constructor and Destructor //-------------------------------------------------------------------------- + /// Creates a World + static std::shared_ptr create(const std::string& name = "world"); + /// Constructor World(const std::string& _name = "world"); diff --git a/dart/utils/SkelParser.cpp b/dart/utils/SkelParser.cpp index a579db4974891..d4c724c769248 100644 --- a/dart/utils/SkelParser.cpp +++ b/dart/utils/SkelParser.cpp @@ -687,7 +687,7 @@ simulation::WorldPtr readWorld( assert(_worldElement != nullptr); // Create a world - simulation::WorldPtr newWorld(new simulation::World); + simulation::WorldPtr newWorld = simulation::World::create(); //-------------------------------------------------------------------------- // Load physics diff --git a/dart/utils/sdf/SdfParser.cpp b/dart/utils/sdf/SdfParser.cpp index 93cbedf75b248..018079bd251bd 100644 --- a/dart/utils/sdf/SdfParser.cpp +++ b/dart/utils/sdf/SdfParser.cpp @@ -369,7 +369,7 @@ simulation::WorldPtr readWorld( assert(worldElement != nullptr); // Create a world - simulation::WorldPtr newWorld(new simulation::World); + simulation::WorldPtr newWorld = simulation::World::create(); //-------------------------------------------------------------------------- // Name attribute diff --git a/dart/utils/urdf/DartLoader.cpp b/dart/utils/urdf/DartLoader.cpp index 044eb0dc244e4..691938c02f7ce 100644 --- a/dart/utils/urdf/DartLoader.cpp +++ b/dart/utils/urdf/DartLoader.cpp @@ -160,7 +160,7 @@ simulation::WorldPtr DartLoader::parseWorldString( return nullptr; } - simulation::WorldPtr world(new simulation::World); + simulation::WorldPtr world = simulation::World::create(); for(std::size_t i = 0; i < worldInterface->models.size(); ++i) { diff --git a/examples/atlasSimbicon/Main.cpp b/examples/atlasSimbicon/Main.cpp index 8f508a5cff2d6..bb921e3a153ec 100644 --- a/examples/atlasSimbicon/Main.cpp +++ b/examples/atlasSimbicon/Main.cpp @@ -50,7 +50,7 @@ using namespace dart::utils; int main(int argc, char* argv[]) { // Create empty soft world - WorldPtr myWorld(new World); + WorldPtr myWorld = World::create(); // Load ground and Atlas robot and add them to the world DartLoader urdfLoader; diff --git a/examples/osgExamples/osgAtlasPuppet/osgAtlasPuppet.cpp b/examples/osgExamples/osgAtlasPuppet/osgAtlasPuppet.cpp index 673fd325a4c27..9bb3b186181f0 100644 --- a/examples/osgExamples/osgAtlasPuppet/osgAtlasPuppet.cpp +++ b/examples/osgExamples/osgAtlasPuppet/osgAtlasPuppet.cpp @@ -837,7 +837,7 @@ void enableDragAndDrops(dart::gui::osg::Viewer& viewer, const SkeletonPtr& atlas int main() { - WorldPtr world(new World); + WorldPtr world = World::create(); SkeletonPtr atlas = createAtlas(); world->addSkeleton(atlas); diff --git a/tutorials/tutorialMultiPendulum-Finished/tutorialMultiPendulum-Finished.cpp b/tutorials/tutorialMultiPendulum-Finished/tutorialMultiPendulum-Finished.cpp index 3318da8ece685..f0c0fe633811a 100644 --- a/tutorials/tutorialMultiPendulum-Finished/tutorialMultiPendulum-Finished.cpp +++ b/tutorials/tutorialMultiPendulum-Finished/tutorialMultiPendulum-Finished.cpp @@ -438,7 +438,7 @@ int main(int argc, char* argv[]) pendulum->getDof(1)->setPosition(120 * M_PI / 180.0); // Create a world and add the pendulum to the world - WorldPtr world(new World); + WorldPtr world = World::create(); world->addSkeleton(pendulum); // Create a window for rendering the world and handling user input diff --git a/tutorials/tutorialMultiPendulum/tutorialMultiPendulum.cpp b/tutorials/tutorialMultiPendulum/tutorialMultiPendulum.cpp index 5e57cd936cc2c..51214293f6e6b 100644 --- a/tutorials/tutorialMultiPendulum/tutorialMultiPendulum.cpp +++ b/tutorials/tutorialMultiPendulum/tutorialMultiPendulum.cpp @@ -367,7 +367,7 @@ int main(int argc, char* argv[]) pendulum->getDof(1)->setPosition(120 * M_PI / 180.0); // Create a world and add the pendulum to the world - WorldPtr world(new World); + WorldPtr world = World::create(); world->addSkeleton(pendulum); // Create a window for rendering the world and handling user input diff --git a/unittests/comprehensive/test_Building.cpp b/unittests/comprehensive/test_Building.cpp index 70503db6a26d4..466914cbc1d26 100644 --- a/unittests/comprehensive/test_Building.cpp +++ b/unittests/comprehensive/test_Building.cpp @@ -81,7 +81,7 @@ TEST(BUILDING, BASIC) joint3->setAxis(Eigen::Vector3d(1.0, 0.0, 0.0)); // World - WorldPtr world(new World); + WorldPtr world = World::create(); world->addSkeleton(skel1); //-------------------------------------------------------------------------- diff --git a/unittests/comprehensive/test_Constraint.cpp b/unittests/comprehensive/test_Constraint.cpp index 6362e46274c2c..db0dc70c26ec0 100644 --- a/unittests/comprehensive/test_Constraint.cpp +++ b/unittests/comprehensive/test_Constraint.cpp @@ -116,7 +116,7 @@ void ConstraintTest::SingleContactTest(const std::string& /*_fileName*/) // std::size_t testCount = 1; #endif - WorldPtr world(new World); + WorldPtr world = World::create(); EXPECT_TRUE(world != nullptr); world->setGravity(Vector3d(0.0, -10.00, 0.0)); world->setTimeStep(0.001); diff --git a/unittests/comprehensive/test_Joints.cpp b/unittests/comprehensive/test_Joints.cpp index 0c857fec9667b..6fee3a7b26d30 100644 --- a/unittests/comprehensive/test_Joints.cpp +++ b/unittests/comprehensive/test_Joints.cpp @@ -667,7 +667,7 @@ void testServoMotor() double insufficient_force = 1e-1; // World - simulation::WorldPtr world(new simulation::World); + simulation::WorldPtr world = simulation::World::create(); EXPECT_TRUE(world != nullptr); world->setGravity(Eigen::Vector3d(0, 0, -9.81)); diff --git a/unittests/comprehensive/test_World.cpp b/unittests/comprehensive/test_World.cpp index dacd8682ed18c..799ffb25f95b0 100644 --- a/unittests/comprehensive/test_World.cpp +++ b/unittests/comprehensive/test_World.cpp @@ -54,7 +54,7 @@ using namespace simulation; TEST(World, AddingAndRemovingSkeletons) { // World - WorldPtr world(new World); + WorldPtr world = World::create(); //-------------------- Test World::removeSkeleton() ------------------------ SkeletonPtr skeleton1 = createThreeLinkRobot(Eigen::Vector3d(1.0, 1.0, 1.0), diff --git a/unittests/unit/test_VskParser.cpp b/unittests/unit/test_VskParser.cpp index aeb97127ba88c..54ed57cc2c263 100644 --- a/unittests/unit/test_VskParser.cpp +++ b/unittests/unit/test_VskParser.cpp @@ -51,7 +51,7 @@ using namespace utils; //============================================================================== TEST(VskParser, EmptySkeleton) { - WorldPtr world(new World()); + WorldPtr world = World::create(); EXPECT_TRUE(world != nullptr); SkeletonPtr skeleton @@ -67,7 +67,7 @@ TEST(VskParser, EmptySkeleton) //============================================================================== TEST(VskParser, SingleStepSimulations) { - WorldPtr world(new World()); + WorldPtr world = World::create(); EXPECT_NE(world , nullptr); SkeletonPtr nick