1/*
2 * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12
13
14#ifndef PX_PHYSICS_METADATA_H
15#define PX_PHYSICS_METADATA_H
16/** \addtogroup physics
17@{
18*/
19
20#include "foundation/Px.h"
21#include "PxMetaDataFlags.h"
22#include "foundation/PxIO.h"
23
24#ifndef PX_DOXYGEN
25namespace physx
26{
27#endif
28
29 /**
30 \brief Struct to store meta data definitions.
31
32 Note: The individual fields have different meaning depending on the meta data entry configuration.
33 */
34 struct PxMetaDataEntry
35 {
36 const char* type; //!< Field type (bool, byte, quaternion, etc)
37 const char* name; //!< Field name (appears exactly as in the source file)
38 PxU32 offset; //!< Offset from the start of the class (ie from "this", field is located at "this"+Offset)
39 PxU32 size; //!< sizeof(Type)
40 PxU32 count; //!< Number of items of type Type (0 for dynamic sizes)
41 PxU32 offsetSize; //!< Offset of dynamic size param, for dynamic arrays
42 PxU32 flags; //!< Field parameters
43 PxU32 alignment; //!< Explicit alignment
44 };
45
46 #define PX_STORE_METADATA(stream, metaData) stream.write(&metaData, sizeof(PxMetaDataEntry))
47
48 /**
49 \brief specifies a binary metadata entry for a member variable of a class
50 */
51 #define PX_DEF_BIN_METADATA_ITEM(stream, Class, type, name, flags) \
52 { \
53 PxMetaDataEntry tmp = { #type, #name, (PxU32)PX_OFFSET_OF(Class, name), PX_SIZE_OF(Class, name), \
54 1, 0, flags, 0}; \
55 PX_STORE_METADATA(stream, tmp); \
56 }
57
58 /**
59 \brief specifies a binary metadata entry for a member array variable of a class
60 \details similar to PX_DEF_BIN_METADATA_ITEMS_AUTO but for cases with mismatch between specified type and array type
61 */
62 #define PX_DEF_BIN_METADATA_ITEMS(stream, Class, type, name, flags, count) \
63 { \
64 PxMetaDataEntry tmp = { #type, #name, (PxU32)PX_OFFSET_OF(Class, name), PX_SIZE_OF(Class, name), \
65 count, 0, flags, 0}; \
66 PX_STORE_METADATA(stream, tmp); \
67 }
68
69 /**
70 \brief specifies a binary metadata entry for a member array variable of a class
71 \details similar to PX_DEF_BIN_METADATA_ITEMS but automatically detects the array length, which only works when the specified
72 type matches the type of the array - does not support PxMetaDataFlag::ePTR
73 */
74 #define PX_DEF_BIN_METADATA_ITEMS_AUTO(stream, Class, type, name, flags) \
75 { \
76 PxMetaDataEntry tmp = { #type, #name, (PxU32)PX_OFFSET_OF(Class, name), PX_SIZE_OF(Class, name), \
77 sizeof(((Class*)0)->name)/sizeof(type), 0, flags, 0}; \
78 PX_STORE_METADATA(stream, tmp); \
79 }
80
81 /**
82 \brief specifies a binary metadata entry for a class
83 */
84 #define PX_DEF_BIN_METADATA_CLASS(stream, Class) \
85 { \
86 PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
87 PX_STORE_METADATA(stream, tmp); \
88 }
89
90 /**
91 \brief specifies a binary metadata entry for a virtual class
92 */
93 #define PX_DEF_BIN_METADATA_VCLASS(stream, Class) \
94 { \
95 PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS|PxMetaDataFlag::eVIRTUAL, 0}; \
96 PX_STORE_METADATA(stream, tmp); \
97 }
98
99 /**
100 \brief specifies a binary metadata entry for a typedef
101 */
102 #define PX_DEF_BIN_METADATA_TYPEDEF(stream, newType, oldType) \
103 { \
104 PxMetaDataEntry tmp = { #newType, #oldType, 0, 0, 0, 0, PxMetaDataFlag::eTYPEDEF, 0 }; \
105 PX_STORE_METADATA(stream, tmp); \
106 }
107
108 /**
109 \brief specifies a binary metadata entry for declaring a base class
110 */
111 #define PX_DEF_BIN_METADATA_BASE_CLASS(stream, Class, BaseClass) \
112 { \
113 Class* myClass = reinterpret_cast<Class*>(42); \
114 BaseClass* s = static_cast<BaseClass*>(myClass); \
115 const PxU32 offset = PxU32(size_t(s) - size_t(myClass)); \
116 PxMetaDataEntry tmp = { #Class, #BaseClass, offset, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
117 PX_STORE_METADATA(stream, tmp); \
118 }
119
120 /**
121 \brief specifies a binary metadata entry for a union
122 */
123 #define PX_DEF_BIN_METADATA_UNION(stream, Class, name) \
124 { \
125 PxMetaDataEntry tmp = { #Class, 0, (PxU32)PX_OFFSET_OF(Class, name), PX_SIZE_OF(Class, name), \
126 1, 0, PxMetaDataFlag::eUNION, 0 }; \
127 PX_STORE_METADATA(stream, tmp); \
128 }
129
130 /**
131 \brief specifies a binary metadata entry for a particular member type of a union
132 */
133 #define PX_DEF_BIN_METADATA_UNION_TYPE(stream, Class, type, enumValue) \
134 { \
135 PxMetaDataEntry tmp = { #Class, #type, enumValue, 0, 0, 0, PxMetaDataFlag::eUNION, 0 }; \
136 PX_STORE_METADATA(stream, tmp); \
137 }
138
139 /**
140 \brief specifies a binary metadata entry for extra data
141 */
142 #define PX_DEF_BIN_METADATA_EXTRA_ITEM(stream, Class, type, control, align) \
143 { \
144 PxMetaDataEntry tmp = { #type, 0, (PxU32)PX_OFFSET_OF(Class, control), sizeof(type), 0, (PxU32)PX_SIZE_OF(Class, control), \
145 PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEM, align }; \
146 PX_STORE_METADATA(stream, tmp); \
147 }
148
149 /**
150 \brief specifies a binary metadata entry for an array of extra data
151 */
152 #define PX_DEF_BIN_METADATA_EXTRA_ITEMS(stream, Class, type, control, count, flags, align) \
153 { \
154 PxMetaDataEntry tmp = { #type, 0, (PxU32)PX_OFFSET_OF(Class, control), (PxU32)PX_SIZE_OF(Class, control), \
155 (PxU32)PX_OFFSET_OF(Class, count), (PxU32)PX_SIZE_OF(Class, count), \
156 PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags, align }; \
157 PX_STORE_METADATA(stream, tmp); \
158 }
159
160 /**
161 \brief specifies a binary metadata entry for an array of extra data
162 additional to PX_DEF_BIN_METADATA_EXTRA_ITEMS a mask can be specified to interpret the control value
163 @see PxMetaDataFlag::eCONTROL_MASK
164 */
165 #define PX_DEF_BIN_METADATA_EXTRA_ITEMS_MASKED_CONTROL(stream, Class, type, control, controlMask ,count, flags, align) \
166 { \
167 PxMetaDataEntry tmp = { #type, 0, (PxU32)PX_OFFSET_OF(Class, control), (PxU32)PX_SIZE_OF(Class, control), \
168 (PxU32)PX_OFFSET_OF(Class, count), (PxU32)PX_SIZE_OF(Class, count), \
169 PxMetaDataFlag::eCONTROL_MASK|PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags|(controlMask & PxMetaDataFlag::eCONTROL_MASK_RANGE) << 16, \
170 align}; \
171 PX_STORE_METADATA(stream, tmp); \
172 }
173
174 /**
175 \brief specifies a binary metadata entry for an array of extra data
176 \details similar to PX_DEF_BIN_METADATA_EXTRA_ITEMS, but supporting no control - PxMetaDataFlag::ePTR is also not supported
177 */
178 #define PX_DEF_BIN_METADATA_EXTRA_ARRAY(stream, Class, type, dyn_count, align, flags) \
179 { \
180 PxMetaDataEntry tmp = { #type, 0, (PxU32)PX_OFFSET_OF(Class, dyn_count), PX_SIZE_OF(Class, dyn_count), align, 0, \
181 PxMetaDataFlag::eEXTRA_DATA|flags, align }; \
182 PX_STORE_METADATA(stream, tmp); \
183 }
184
185 /**
186 \brief specifies a binary metadata entry for an string of extra data
187 */
188 #define PX_DEF_BIN_METADATA_EXTRA_NAME(stream, Class, control, align) \
189 { \
190 PxMetaDataEntry tmp = { "char", "string", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_NAME, align }; \
191 PX_STORE_METADATA(stream, tmp); \
192 }
193
194 /**
195 \brief specifies a binary metadata entry declaring an extra data alignment for a class
196 */
197 #define PX_DEF_BIN_METADATA_EXTRA_ALIGN(stream, Class, align) \
198 { \
199 PxMetaDataEntry tmp = { "PxU8", "Alignment", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eALIGNMENT, align}; \
200 PX_STORE_METADATA(stream, tmp); \
201 }
202
203#ifndef PX_DOXYGEN
204} // namespace physx
205#endif
206
207/** @} */
208#endif
209