Skip to content

Commit

Permalink
Replace static default world with sdf default world
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoenig committed Oct 2, 2024
1 parent 3c7e333 commit 21ccdf0
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/ServerPrivate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ using namespace sim;
const char ServerPrivate::kClassicMaterialScriptUri[] =
"file://media/materials/scripts/gazebo.material";

/// \brief This struct provides access to the default world.
struct DefaultWorld
{
/// \brief Get the default world as a string.
/// Plugins will be loaded from the server.config file.
/// \return An SDF string that contains the default world.
public: static std::string &World()
{
static std::string world = std::string("<?xml version='1.0'?>"
"<sdf version='1.6'>"
"<world name='default'>") +
"</world>"
"</sdf>";

return world;
}
};

/// \brief This struct provides access to the record plugin SDF string
struct LoggingPlugin
{
Expand Down Expand Up @@ -669,10 +651,12 @@ sdf::Errors ServerPrivate::LoadSdfRootHelper(const ServerConfig &_config)
}
else
{
sdf::World defaultWorld;
defaultWorld.SetName("default");

// If the specified file only contains a model, load the default
// world and add the model to it.
errors = this->sdfRoot.LoadSdfString(
DefaultWorld::World(), sdfParserConfig);
errors = this->sdfRoot.AddWorld(defaultWorld);
sdf::World *world = this->sdfRoot.WorldByIndex(0);
if (world == nullptr) {
errors.push_back({sdf::ErrorCode::FATAL_ERROR,
Expand All @@ -696,9 +680,12 @@ sdf::Errors ServerPrivate::LoadSdfRootHelper(const ServerConfig &_config)
default:
{
gzmsg << "Loading default world.\n";

sdf::World defaultWorld;
defaultWorld.SetName("default");

// Load an empty world.
/// \todo(nkoenig) Add a "AddWorld" function to sdf::Root.
errors = this->sdfRoot.LoadSdfString(DefaultWorld::World());
errors = this->sdfRoot.AddWorld(defaultWorld);
break;
}
}
Expand Down

0 comments on commit 21ccdf0

Please sign in to comment.