diff --git a/doc/APIreference/APItypes.rst b/doc/APIreference/APItypes.rst index 879d4bda..ba1a6135 100644 --- a/doc/APIreference/APItypes.rst +++ b/doc/APIreference/APItypes.rst @@ -84,13 +84,29 @@ changed by the user. mjtByte ^^^^^^^ -Byte type used to represent boolean variables. +Byte type used to represent small integers and binary data. .. code-block:: C typedef unsigned char mjtByte; +.. _mjtBool: + +mjtBool +^^^^^^^ + +Boolean type used to represent true/false values. + +.. code-block:: C + + #ifndef __cplusplus + typedef _Bool mjtBool; + #else + typedef bool mjtBool; + #endif + + .. _mjtSize: mjtSize diff --git a/doc/programming/index.rst b/doc/programming/index.rst index 852685cb..99cc50dc 100644 --- a/doc/programming/index.rst +++ b/doc/programming/index.rst @@ -230,8 +230,7 @@ to which the symbol belongs. First we list the prefixes corresponding to type de Core simulation data structure (C struct), for example :ref:`mjModel`. If all characters after the prefix are capital, for example :ref:`mjMIN`, this is a macro or a symbol (#define). ``mjt`` - Primitive type, for example :ref:`mjtGeom`. Except for mjtByte and mjtNum, all other - definitions in this family are enums. + Primitive type, for example :ref:`mjtNum` and :ref:`mjtGeom`. Most types in this family are enums. ``mjf`` Callback function type, for example :ref:`mjfGeneric`. ``mjv`` diff --git a/include/mujoco/mjassert.h b/include/mujoco/mjassert.h index 5c69f940..169cbb30 100644 --- a/include/mujoco/mjassert.h +++ b/include/mujoco/mjassert.h @@ -36,16 +36,17 @@ typedef char mj_assert_##type[sizeof(type) == (size) ? 1 : -1] #endif -// mjtnum.h -MJ_ASSERT_SIZE(mjtByte, 1); -MJ_ASSERT_SIZE(mjtSize, 8); +// primitive types #if !defined(mjUSESINGLE) MJ_ASSERT_SIZE(mjtNum, 8); #else MJ_ASSERT_SIZE(mjtNum, 4); #endif +MJ_ASSERT_SIZE(mjtByte, 1); +MJ_ASSERT_SIZE(mjtBool, 1); +MJ_ASSERT_SIZE(mjtSize, 8); -// mjmodel.h +// mjModel enums MJ_ASSERT_SIZE(mjtDisableBit, 4); MJ_ASSERT_SIZE(mjtEnableBit, 4); MJ_ASSERT_SIZE(mjtJoint, 4); @@ -79,7 +80,7 @@ MJ_ASSERT_SIZE(mjtLRMode, 4); MJ_ASSERT_SIZE(mjtFlexSelf, 4); MJ_ASSERT_SIZE(mjtSDFType, 4); -// mjdata.h +// mjData enums MJ_ASSERT_SIZE(mjtState, 4); MJ_ASSERT_SIZE(mjtConstraint, 4); MJ_ASSERT_SIZE(mjtConstraintState, 4); diff --git a/include/mujoco/mjtype.h b/include/mujoco/mjtype.h index 62426a11..b3296824 100644 --- a/include/mujoco/mjtype.h +++ b/include/mujoco/mjtype.h @@ -15,6 +15,7 @@ #ifndef MUJOCO_INCLUDE_MJTYPE_H_ #define MUJOCO_INCLUDE_MJTYPE_H_ +#include #include @@ -33,9 +34,13 @@ //---------------------------------- byte definition ----------------------------------------------- -typedef unsigned char mjtByte; // used for true/false - +typedef unsigned char mjtByte; // used for small integers and binary data +#ifndef __cplusplus + typedef _Bool mjtBool; // used for boolean values +#else + typedef bool mjtBool; // used for boolean values +#endif //---------------------------------- size definition ----------------------------------------------- diff --git a/python/mujoco/codegen/generate_spec_bindings.py b/python/mujoco/codegen/generate_spec_bindings.py index 724325c6..5dee5684 100644 --- a/python/mujoco/codegen/generate_spec_bindings.py +++ b/python/mujoco/codegen/generate_spec_bindings.py @@ -22,7 +22,7 @@ from introspect import ast_nodes from introspect import structs -SCALAR_TYPES = {'int', 'double', 'float', 'mjtByte', 'mjtNum'} +SCALAR_TYPES = {'int', 'double', 'float', 'mjtByte', 'mjtBool', 'mjtNum'} # pylint: disable=bad-whitespace # key, parent, default, listname, objtype diff --git a/wasm/codegen/generators/constants.py b/wasm/codegen/generators/constants.py index 2338dff0..fedb130f 100644 --- a/wasm/codegen/generators/constants.py +++ b/wasm/codegen/generators/constants.py @@ -24,6 +24,7 @@ PRIMITIVE_TYPES: Set[str] = { "float", "int", "mjtByte", + "mjtBool", "mjtMeshBuiltin", "mjtNum", "mjtObj", # Adding this to the primitives because it is used as int, diff --git a/wasm/codegen/generators/functions.py b/wasm/codegen/generators/functions.py index bc0f73d1..bb296d12 100644 --- a/wasm/codegen/generators/functions.py +++ b/wasm/codegen/generators/functions.py @@ -148,7 +148,7 @@ def get_param_string(p: ast_nodes.FunctionParameterDecl) -> str: return f"const String& {p.name}" elif ( p.type.inner_type.name - in ["int", "float", "double", "mjtNum", "mjtByte"] + in ["int", "float", "double", "mjtNum", "mjtByte", "mjtBool"] and p.type.inner_type.is_const ): return f"const NumberArray& {p.name}"