Add option to only sync the state to improve sync performance in passive mode.
By default this option is off, which preserves the current behavior of syncing all of `mjModel` and `mjData`. PiperOrigin-RevId: 776498017 Change-Id: I02127c9397efbabebb89b0e0d139b00b6e665d35
This commit is contained in:
committed by
Copybara-Service
parent
8f6a13aa8f
commit
09f7154e57
+12
-3
@@ -1912,7 +1912,7 @@ Simulate::Simulate(std::unique_ptr<PlatformUIAdapter> platform_ui,
|
||||
//------------------------- Synchronize render and physics threads ---------------------------------
|
||||
|
||||
// operations which require holding the mutex, prevents racing with physics thread
|
||||
void Simulate::Sync() {
|
||||
void Simulate::Sync(bool state_only) {
|
||||
MutexLock lock(this->mtx);
|
||||
|
||||
if (!m_) {
|
||||
@@ -2159,8 +2159,17 @@ void Simulate::Sync() {
|
||||
if (!is_passive_) {
|
||||
mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
|
||||
} else {
|
||||
mjv_copyModel(m_passive_, m_);
|
||||
mjv_copyData(d_passive_, m_passive_, d_);
|
||||
if (state_only) {
|
||||
int state_size = mj_stateSize(m_, mjSTATE_INTEGRATION);
|
||||
mjtNum* state = new mjtNum[state_size];
|
||||
mj_getState(m_, d_, state, mjSTATE_INTEGRATION);
|
||||
mj_setState(m_passive_, d_passive_, state, mjSTATE_INTEGRATION);
|
||||
mj_forward(m_passive_, d_passive_);
|
||||
delete[] state;
|
||||
} else {
|
||||
mjv_copyModel(m_passive_, m_);
|
||||
mjv_copyData(d_passive_, m_passive_, d_);
|
||||
}
|
||||
|
||||
// append geoms from user_scn to scratch space
|
||||
if (user_scn) {
|
||||
|
||||
Reference in New Issue
Block a user