RavEngine
Loading...
Searching...
No Matches
PxMetaData.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef PX_METADATA_H
30#define PX_METADATA_H
35#include "foundation/Px.h"
36#include "foundation/PxIO.h"
37#include "PxMetaDataFlags.h"
38
39
40#if !PX_DOXYGEN
41namespace physx
42{
43#endif
44
51 {
52 const char* type;
53 const char* name;
54 PxU32 offset;
55 PxU32 size;
56 PxU32 count;
57 PxU32 offsetSize;
58 PxU32 flags;
59 PxU32 alignment;
60 };
61
62 #define PX_STORE_METADATA(stream, metaData) stream.write(&metaData, sizeof(PxMetaDataEntry))
63
64 #define PX_SIZE_OF(Class, Member) sizeof((reinterpret_cast<Class*>(0))->Member)
65
69 #define PX_DEF_BIN_METADATA_ITEM(stream, Class, type, name, flags) \
70 { \
71 PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
72 1, 0, flags, 0}; \
73 PX_STORE_METADATA(stream, tmp); \
74 }
75
80 #define PX_DEF_BIN_METADATA_ITEMS(stream, Class, type, name, flags, count) \
81 { \
82 PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
83 count, 0, flags, 0}; \
84 PX_STORE_METADATA(stream, tmp); \
85 }
86
92 #define PX_DEF_BIN_METADATA_ITEMS_AUTO(stream, Class, type, name, flags) \
93 { \
94 PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
95 sizeof((reinterpret_cast<Class*>(0))->name)/sizeof(type), 0, flags, 0}; \
96 PX_STORE_METADATA(stream, tmp); \
97 }
98
102 #define PX_DEF_BIN_METADATA_CLASS(stream, Class) \
103 { \
104 PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
105 PX_STORE_METADATA(stream, tmp); \
106 }
107
111 #define PX_DEF_BIN_METADATA_VCLASS(stream, Class) \
112 { \
113 PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS|PxMetaDataFlag::eVIRTUAL, 0}; \
114 PX_STORE_METADATA(stream, tmp); \
115 }
116
120 #define PX_DEF_BIN_METADATA_TYPEDEF(stream, newType, oldType) \
121 { \
122 PxMetaDataEntry tmp = { #newType, #oldType, 0, 0, 0, 0, PxMetaDataFlag::eTYPEDEF, 0 }; \
123 PX_STORE_METADATA(stream, tmp); \
124 }
125
129 #define PX_DEF_BIN_METADATA_BASE_CLASS(stream, Class, BaseClass) \
130 { \
131 Class* myClass = reinterpret_cast<Class*>(42); \
132 BaseClass* s = static_cast<BaseClass*>(myClass); \
133 const PxU32 offset = PxU32(size_t(s) - size_t(myClass)); \
134 PxMetaDataEntry tmp = { #Class, #BaseClass, offset, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
135 PX_STORE_METADATA(stream, tmp); \
136 }
137
141 #define PX_DEF_BIN_METADATA_UNION(stream, Class, name) \
142 { \
143 PxMetaDataEntry tmp = { #Class, 0, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
144 1, 0, PxMetaDataFlag::eUNION, 0 }; \
145 PX_STORE_METADATA(stream, tmp); \
146 }
147
151 #define PX_DEF_BIN_METADATA_UNION_TYPE(stream, Class, type, enumValue) \
152 { \
153 PxMetaDataEntry tmp = { #Class, #type, enumValue, 0, 0, 0, PxMetaDataFlag::eUNION, 0 }; \
154 PX_STORE_METADATA(stream, tmp); \
155 }
156
160 #define PX_DEF_BIN_METADATA_EXTRA_ITEM(stream, Class, type, control, align) \
161 { \
162 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), sizeof(type), 0, PxU32(PX_SIZE_OF(Class, control)), \
163 PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEM, align }; \
164 PX_STORE_METADATA(stream, tmp); \
165 }
166
170 #define PX_DEF_BIN_METADATA_EXTRA_ITEMS(stream, Class, type, control, count, flags, align) \
171 { \
172 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
173 PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
174 PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags, align }; \
175 PX_STORE_METADATA(stream, tmp); \
176 }
177
183 #define PX_DEF_BIN_METADATA_EXTRA_ITEMS_MASKED_CONTROL(stream, Class, type, control, controlMask ,count, flags, align) \
184 { \
185 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
186 PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
187 PxMetaDataFlag::eCONTROL_MASK|PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags|(controlMask & PxMetaDataFlag::eCONTROL_MASK_RANGE) << 16, \
188 align}; \
189 PX_STORE_METADATA(stream, tmp); \
190 }
191
196 #define PX_DEF_BIN_METADATA_EXTRA_ARRAY(stream, Class, type, dyn_count, align, flags) \
197 { \
198 PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, dyn_count)), PX_SIZE_OF(Class, dyn_count), align, 0, \
199 PxMetaDataFlag::eEXTRA_DATA|flags, align }; \
200 PX_STORE_METADATA(stream, tmp); \
201 }
202
206 #define PX_DEF_BIN_METADATA_EXTRA_NAME(stream, Class, control, align) \
207 { \
208 PxMetaDataEntry tmp = { "char", "string", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_NAME, align }; \
209 PX_STORE_METADATA(stream, tmp); \
210 }
211
215 #define PX_DEF_BIN_METADATA_EXTRA_ALIGN(stream, Class, align) \
216 { \
217 PxMetaDataEntry tmp = { "PxU8", "Alignment", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eALIGNMENT, align}; \
218 PX_STORE_METADATA(stream, tmp); \
219 }
220
221#if !PX_DOXYGEN
222} // namespace physx
223#endif
224
226#endif
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Struct to store meta data definitions.
Definition PxMetaData.h:51
PxU32 flags
Field parameters.
Definition PxMetaData.h:58
PxU32 count
Number of items of type Type (0 for dynamic sizes)
Definition PxMetaData.h:56
const char * type
Field type (bool, byte, quaternion, etc)
Definition PxMetaData.h:52
PxU32 offsetSize
Offset of dynamic size param, for dynamic arrays.
Definition PxMetaData.h:57
PxU32 size
sizeof(Type)
Definition PxMetaData.h:55
PxU32 offset
Offset from the start of the class (ie from "this", field is located at "this"+Offset)
Definition PxMetaData.h:54
PxU32 alignment
Explicit alignment.
Definition PxMetaData.h:59
const char * name
Field name (appears exactly as in the source file)
Definition PxMetaData.h:53