Introduce mjtBool for boolean types.

PiperOrigin-RevId: 920201340
Change-Id: I3b19c11a00357e06a1df08b8819832955c37f9ff
This commit is contained in:
Yuval Tassa
2026-05-23 09:13:21 -07:00
committed by Copybara-Service
parent 466d068089
commit 7667e7110e
7 changed files with 34 additions and 12 deletions
+17 -1
View File
@@ -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
+1 -2
View File
@@ -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``
+6 -5
View File
@@ -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);
+7 -2
View File
@@ -15,6 +15,7 @@
#ifndef MUJOCO_INCLUDE_MJTYPE_H_
#define MUJOCO_INCLUDE_MJTYPE_H_
#include <stdbool.h>
#include <stdint.h>
@@ -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 -----------------------------------------------
@@ -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
+1
View File
@@ -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,
+1 -1
View File
@@ -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}"