Replace mjs_setActivePlugins with mjs_activatePlugin.
PiperOrigin-RevId: 680613007 Change-Id: Ic03e0dc42a1f5f083e313672bc6e3ccebadc58b3
This commit is contained in:
committed by
Copybara-Service
parent
cf13413c0b
commit
6832df3091
+15
-10
@@ -205,6 +205,21 @@ void mjs_addSpec(mjSpec* s, mjSpec* child) {
|
||||
|
||||
|
||||
|
||||
// activate plugin
|
||||
int mjs_activatePlugin(mjSpec* s, const char* name) {
|
||||
int plugin_slot = -1;
|
||||
const mjpPlugin* plugin = mjp_getPlugin(name, &plugin_slot);
|
||||
if (!plugin) {
|
||||
mju_error("unknown plugin '%s'", name);
|
||||
return -1;
|
||||
}
|
||||
mjCModel* model = static_cast<mjCModel*>(s->element);
|
||||
model->ActivatePlugin(plugin, plugin_slot);
|
||||
return plugin_slot;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// delete object, it will call the appropriate destructor since ~mjCBase is virtual
|
||||
void mjs_delete(mjsElement* element) {
|
||||
mjCBase* object = static_cast<mjCBase*>(element);
|
||||
@@ -1027,16 +1042,6 @@ void mjs_setPluginAttributes(mjsPlugin* plugin, void* attributes) {
|
||||
|
||||
|
||||
|
||||
// Set active plugins.
|
||||
void mjs_setActivePlugins(mjSpec* s, void* activeplugins) {
|
||||
mjCModel* modelC = static_cast<mjCModel*>(s->element);
|
||||
std::vector<std::pair<const mjpPlugin*, int>>* active_plugins =
|
||||
reinterpret_cast<std::vector<std::pair<const mjpPlugin*, int>>*>(activeplugins);
|
||||
modelC->SetActivePlugins(std::move(*active_plugins));
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -------------------------- GLOBAL ASSET CACHE -------------------------------
|
||||
|
||||
void mj_setCacheSize(mjCache cache, std::size_t size) {
|
||||
|
||||
+3
-3
@@ -63,6 +63,9 @@ MJAPI void mj_deleteSpec(mjSpec* s);
|
||||
// Add spec (model asset) to spec.
|
||||
MJAPI void mjs_addSpec(mjSpec* s, mjSpec* child);
|
||||
|
||||
// Activate plugin, return slot number.
|
||||
MJAPI int mjs_activatePlugin(mjSpec* s, const char* name);
|
||||
|
||||
|
||||
//---------------------------------- Attachment ----------------------------------------------------
|
||||
|
||||
@@ -347,9 +350,6 @@ MJAPI const double* mjs_getDouble(const mjDoubleVec* source, int* size);
|
||||
|
||||
//---------------------------------- Other utilities -----------------------------------------------
|
||||
|
||||
// Set active plugins.
|
||||
MJAPI void mjs_setActivePlugins(mjSpec* s, void* activeplugins);
|
||||
|
||||
// Set element's default.
|
||||
MJAPI void mjs_setDefault(mjsElement* element, mjsDefault* def);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <mujoco/mjdata.h>
|
||||
@@ -4450,6 +4451,23 @@ bool mjCModel::CopyBack(const mjModel* m) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mjCModel::ActivatePlugin(const mjpPlugin* plugin, int slot) {
|
||||
bool already_declared = false;
|
||||
for (const auto& [existing_plugin, existing_slot] : active_plugins_) {
|
||||
if (plugin == existing_plugin) {
|
||||
already_declared = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!already_declared) {
|
||||
active_plugins_.emplace_back(std::make_pair(plugin, slot));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mjCModel::ResolvePlugin(mjCBase* obj, const std::string& plugin_name,
|
||||
const std::string& plugin_instance_name, mjCPlugin** plugin_instance) {
|
||||
// if plugin_name is specified, check if it is in the list of active plugins
|
||||
|
||||
@@ -233,9 +233,7 @@ class mjCModel : public mjCModel_, private mjSpec {
|
||||
mjCBase* FindObject(mjtObj type, std::string name) const; // find object given type and name
|
||||
mjCBase* FindTree(mjCBody* body, mjtObj type, std::string name); // find tree object given name
|
||||
mjSpec* FindSpec(std::string name) const; // find spec given name
|
||||
void SetActivePlugins(const std::vector<std::pair<const mjpPlugin*, int>>&& active_plugins) {
|
||||
active_plugins_ = std::move(active_plugins);
|
||||
}
|
||||
void ActivatePlugin(const mjpPlugin* plugin, int slot); // activate plugin
|
||||
|
||||
// accessors
|
||||
std::string get_meshdir() const { return meshdir_; }
|
||||
|
||||
@@ -2882,7 +2882,6 @@ void mjXReader::Default(XMLElement* section, const mjsDefault* def, const mjVFS*
|
||||
// extension section parser
|
||||
void mjXReader::Extension(XMLElement* section) {
|
||||
XMLElement* elem = FirstChildElement(section);
|
||||
std::vector<std::pair<const mjpPlugin*, int>> active_plugins;
|
||||
|
||||
while (elem) {
|
||||
// get sub-element name
|
||||
@@ -2890,23 +2889,8 @@ void mjXReader::Extension(XMLElement* section) {
|
||||
|
||||
if (name == "plugin") {
|
||||
string plugin_name;
|
||||
int plugin_slot = -1;
|
||||
ReadAttrTxt(elem, "plugin", plugin_name, /* required = */ true);
|
||||
const mjpPlugin* plugin = mjp_getPlugin(plugin_name.c_str(), &plugin_slot);
|
||||
if (!plugin) {
|
||||
throw mjXError(elem, "unknown plugin '%s'", plugin_name.c_str());
|
||||
}
|
||||
|
||||
bool already_declared = false;
|
||||
for (const auto& [existing_plugin, existing_slot] : active_plugins) {
|
||||
if (plugin == existing_plugin) {
|
||||
already_declared = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!already_declared) {
|
||||
active_plugins.emplace_back(std::make_pair(plugin, plugin_slot));
|
||||
}
|
||||
int plugin_slot = mjs_activatePlugin(spec, plugin_name.c_str());
|
||||
|
||||
XMLElement* child = FirstChildElement(elem);
|
||||
while (child) {
|
||||
@@ -2933,8 +2917,6 @@ void mjXReader::Extension(XMLElement* section) {
|
||||
// advance to next element
|
||||
elem = NextSiblingElement(elem);
|
||||
}
|
||||
|
||||
mjs_setActivePlugins(spec, &active_plugins);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user