Clean up X macros and usages for mjOption, mjStatistic, and mjVisual.

* Replace various MJOPTION_ macros with a single MJOPTION_FIELDS.
* Use XVEC macro to denote vector members where there is a mixture of
  vector and scalar members in a given struct type.
* Split up MJVISUAL_FIELDS into separate macros for each substruct.
* Modify engine_print.c and Python bindings struct.h/cc to use the
  new X macros.

PiperOrigin-RevId: 869760513
Change-Id: Idac4fe9aa99f0258e7c79802ca9023a0d4486e2d
This commit is contained in:
Saran Tunyasuvunakool
2026-02-13 09:09:45 -08:00
committed by Copybara-Service
parent 6d8b6028e2
commit 5274e5f720
7 changed files with 521 additions and 359 deletions
+7 -3
View File
@@ -83,16 +83,20 @@ inline std::size_t NConMax(const mjData* d) {
} // namespace
// ==================== MJOPTION ===============================================
#define X(var, dim) , var(InitPyArray(std::array{dim}, ptr_->var, owner_))
#define X(type, var, dim)
#define XVEC(type, var, dim) \
, var(InitPyArray(std::array{dim}, ptr_->var, owner_))
MjOptionWrapper::MjWrapper()
: WrapperBase([]() {
raw::MjOption* const opt = new raw::MjOption;
mj_defaultOption(opt);
return opt;
}()) MJOPTION_VECTORS {}
}()) MJOPTION_FIELDS {}
MjOptionWrapper::MjWrapper(raw::MjOption* ptr, py::handle owner)
: WrapperBase(ptr, owner) MJOPTION_VECTORS {}
: WrapperBase(ptr, owner) MJOPTION_FIELDS {}
#undef XVEC
#undef X
MjOptionWrapper::MjWrapper(const MjOptionWrapper& other) : MjOptionWrapper() {