1//
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions
4// are met:
5// * Redistributions of source code must retain the above copyright
6// notice, this list of conditions and the following disclaimer.
7// * Redistributions in binary form must reproduce the above copyright
8// notice, this list of conditions and the following disclaimer in the
9// documentation and/or other materials provided with the distribution.
10// * Neither the name of NVIDIA CORPORATION nor the names of its
11// contributors may be used to endorse or promote products derived
12// from this software without specific prior written permission.
13//
14// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25//
26// Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29
30
31#ifndef PX_PHYSICS_METADATA_H
32#define PX_PHYSICS_METADATA_H
33/** \addtogroup physics
34@{
35*/
36
37#include "foundation/Px.h"
38#include "foundation/PxIO.h"
39#include "PxMetaDataFlags.h"
40
41
42#if !PX_DOXYGEN
43namespace physx
44{
45#endif
46
47 /**
48 \brief Struct to store meta data definitions.
49
50 Note: The individual fields have different meaning depending on the meta data entry configuration.
51 */
52 struct PxMetaDataEntry
53 {
54 const char* type; //!< Field type (bool, byte, quaternion, etc)
55 const char* name; //!< Field name (appears exactly as in the source file)
56 PxU32 offset; //!< Offset from the start of the class (ie from "this", field is located at "this"+Offset)
57 PxU32 size; //!< sizeof(Type)
58 PxU32 count; //!< Number of items of type Type (0 for dynamic sizes)
59 PxU32 offsetSize; //!< Offset of dynamic size param, for dynamic arrays
60 PxU32 flags; //!< Field parameters
61 PxU32 alignment; //!< Explicit alignment
62 };
63
64 #define PX_STORE_METADATA(stream, metaData) stream.write(&metaData, sizeof(PxMetaDataEntry))
65
66 #define PX_SIZE_OF(Class, Member) sizeof((reinterpret_cast<Class*>(0))->Member)
67
68 /**
69 \brief specifies a binary metadata entry for a member variable of a class
70 */
71 #define PX_DEF_BIN_METADATA_ITEM(stream, Class, type, name, flags) \
72 { \
73 PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
74 1, 0, flags, 0}; \
75 PX_STORE_METADATA(stream, tmp); \
76 }
77
78 /**
79 \brief specifies a binary metadata entry for a member array variable of a class
80 \details similar to PX_DEF_BIN_METADATA_ITEMS_AUTO but for cases with mismatch between specified type and array type
81 */
82 #define PX_DEF_BIN_METADATA_ITEMS(stream, Class, type, name, flags, count) \
83 { \
84 PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
85 count, 0, flags, 0}; \
86 PX_STORE_METADATA(stream, tmp); \
87 }
88
89 /**
90 \brief specifies a binary metadata entry for a member array variable of a class
91 \details similar to PX_DEF_BIN_METADATA_ITEMS but automatically detects the array length, which only works when the specified
92 type matches the type of the array - does not support PxMetaDataFlag::ePTR
93 */
94 #define PX_DEF_BIN_METADATA_ITEMS_AUTO(stream, Class, type, name, flags) \
95 { \
96 PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
97 sizeof((reinterpret_cast<Class*>(0))->name)/sizeof(type), 0, flags, 0}; \
98 PX_STORE_METADATA(stream, tmp); \
99 }
100
101 /**
102 \brief specifies a binary metadata entry for a class
103 */
104 #define PX_DEF_BIN_METADATA_CLASS(stream, Class) \
105 { \
106 PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
107 PX_STORE_METADATA(stream, tmp); \
108 }
109
110 /**
111 \brief specifies a binary metadata entry for a virtual class
112 */
113 #define PX_DEF_BIN_METADATA_VCLASS(stream, Class) \
114 { \
115 PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS|PxMetaDataFlag::eVIRTUAL, 0}; \
116 PX_STORE_METADATA(stream, tmp); \
117 }
118
119 /**
120 \brief specifies a binary metadata entry for a typedef
121 */
122 #define PX_DEF_BIN_METADATA_TYPEDEF(stream, newType, oldType) \
123 { \
124 PxMetaDataEntry tmp = { #newType, #oldType, 0, 0, 0, 0, PxMetaDataFlag::eTYPEDEF, 0 }; \
125 PX_STORE_METADATA(stream, tmp); \
126 }
127
128 /**
129 \brief specifies a binary metadata entry for declaring a base class
130 */
131 #define PX_DEF_BIN_METADATA_BASE_CLASS(stream, Class, BaseClass) \
132 { \
133 Class* myClass = reinterpret_cast<Class*>(42); \
134 BaseClass* s = static_cast<BaseClass*>(myClass); \
135 const PxU32 offset = PxU32(size_t(s) - size_t(myClass)); \
136 PxMetaDataEntry tmp = { #Class, #BaseClass, offset, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
137 PX_STORE_METADATA(stream, tmp); \
138 }
139
140 /**
141 \brief specifies a binary metadata entry for a union
142 */
143 #define PX_DEF_BIN_METADATA_UNION(stream, Class, name) \
144 { \
145 PxMetaDataEntry tmp = { #Class, 0, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
146 1, 0, PxMetaDataFlag::eUNION, 0 }; \
147 PX_STORE_METADATA(stream, tmp); \
148 }
149
150 /**
151 \brief specifies a binary metadata entry for a particular member type of a union
152 */
153 #define PX_DEF_BIN_METADATA_UNION_TYPE(stream, Class, type, enumValue) \
154 { \
155 PxMetaDataEntry tmp = { #Class, #type, enumValue, 0, 0, 0, PxMetaDataFlag::eUNION, 0 }; \
156 PX_STORE_METADATA(stream, tmp); \
157 }
158
159 /**
160 \brief specifies a binary metadata entry for extra data
161 */
162 #define PX_DEF_BIN_METADATA_EXTRA_ITEM(stream, Class, type, control, align) \
163 { \
164 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), sizeof(type), 0, PxU32(PX_SIZE_OF(Class, control)), \
165 PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEM, align }; \
166 PX_STORE_METADATA(stream, tmp); \
167 }
168
169 /**
170 \brief specifies a binary metadata entry for an array of extra data
171 */
172 #define PX_DEF_BIN_METADATA_EXTRA_ITEMS(stream, Class, type, control, count, flags, align) \
173 { \
174 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
175 PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
176 PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags, align }; \
177 PX_STORE_METADATA(stream, tmp); \
178 }
179
180 /**
181 \brief specifies a binary metadata entry for an array of extra data
182 additional to PX_DEF_BIN_METADATA_EXTRA_ITEMS a mask can be specified to interpret the control value
183 @see PxMetaDataFlag::eCONTROL_MASK
184 */
185 #define PX_DEF_BIN_METADATA_EXTRA_ITEMS_MASKED_CONTROL(stream, Class, type, control, controlMask ,count, flags, align) \
186 { \
187 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
188 PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
189 PxMetaDataFlag::eCONTROL_MASK|PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags|(controlMask & PxMetaDataFlag::eCONTROL_MASK_RANGE) << 16, \
190 align}; \
191 PX_STORE_METADATA(stream, tmp); \
192 }
193
194 /**
195 \brief specifies a binary metadata entry for an array of extra data
196 \details similar to PX_DEF_BIN_METADATA_EXTRA_ITEMS, but supporting no control - PxMetaDataFlag::ePTR is also not supported
197 */
198 #define PX_DEF_BIN_METADATA_EXTRA_ARRAY(stream, Class, type, dyn_count, align, flags) \
199 { \
200 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, dyn_count)), PX_SIZE_OF(Class, dyn_count), align, 0, \
201 PxMetaDataFlag::eEXTRA_DATA|flags, align }; \
202 PX_STORE_METADATA(stream, tmp); \
203 }
204
205 /**
206 \brief specifies a binary metadata entry for an string of extra data
207 */
208 #define PX_DEF_BIN_METADATA_EXTRA_NAME(stream, Class, control, align) \
209 { \
210 PxMetaDataEntry tmp = { "char", "string", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_NAME, align }; \
211 PX_STORE_METADATA(stream, tmp); \
212 }
213
214 /**
215 \brief specifies a binary metadata entry declaring an extra data alignment for a class
216 */
217 #define PX_DEF_BIN_METADATA_EXTRA_ALIGN(stream, Class, align) \
218 { \
219 PxMetaDataEntry tmp = { "PxU8", "Alignment", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eALIGNMENT, align}; \
220 PX_STORE_METADATA(stream, tmp); \
221 }
222
223#if !PX_DOXYGEN
224} // namespace physx
225#endif
226
227/** @} */
228#endif
229

source code of qtquick3dphysics/src/3rdparty/PhysX/include/common/PxMetaData.h