Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugins] add plugins loading method #65

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ endif()
find_package(Boost REQUIRED COMPONENTS program_options)

add_executable(mc_mujoco main.cpp)
target_compile_definitions(mc_mujoco PUBLIC MUJOCO_BIN_DIR="${MUJOCO_BIN_DIR}")
target_link_libraries(mc_mujoco PRIVATE mc_mujoco_lib Boost::program_options
Boost::disable_autolinking)

Expand Down
27 changes: 27 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ namespace po = boost::program_options;

bool render_state = true;

#define MUJOCO_PLUGIN_DIR "mujoco_plugin"

void scanPluginLibraries()
{
// define platform-specific strings
#if defined(_WIN32) || defined(__CYGWIN__)
const std::string sep = "\\";
#else
const std::string sep = "/";
#endif

const std::string plugin_dir = MUJOCO_BIN_DIR + sep + MUJOCO_PLUGIN_DIR;
mj_loadAllPluginLibraries(
plugin_dir.c_str(),
+[](const char * filename, int first, int count)
{
std::printf("Plugins registered by library '%s':\n", filename);
for(int i = first; i < first + count; ++i)
{
std::printf(" %s\n", mjp_getPluginAtSlot(i)->name);
}
});
}

void simulate(mc_mujoco::MjSim & mj_sim)
{
bool done = false;
Expand Down Expand Up @@ -68,6 +92,9 @@ int main(int argc, char * argv[])
config.visualize_collisions = vm["with-collisions"].as<bool>();
}
}

scanPluginLibraries();

mc_mujoco::MjSim mj_sim(config);

std::thread simThread(simulate, std::ref(mj_sim));
Expand Down