PxMetaData.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 //
00026 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
00029 
00030 
00031 #ifndef PX_PHYSICS_METADATA_H
00032 #define PX_PHYSICS_METADATA_H
00033 
00037 #include "foundation/Px.h"
00038 #include "foundation/PxIO.h"
00039 #include "PxMetaDataFlags.h"
00040 
00041 
00042 #if !PX_DOXYGEN
00043 namespace physx
00044 {
00045 #endif
00046 
00052     struct PxMetaDataEntry
00053     {
00054         const char*     type;           
00055         const char*     name;           
00056         PxU32           offset;         
00057         PxU32           size;           
00058         PxU32           count;          
00059         PxU32           offsetSize;     
00060         PxU32           flags;          
00061         PxU32           alignment;      
00062     };
00063 
00064     #define PX_STORE_METADATA(stream, metaData) stream.write(&metaData, sizeof(PxMetaDataEntry))
00065 
00066     #define PX_SIZE_OF(Class, Member)   sizeof((reinterpret_cast<Class*>(0))->Member)
00067 
00071     #define PX_DEF_BIN_METADATA_ITEM(stream, Class, type, name, flags) \
00072     { \
00073         PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
00074                                 1, 0, flags, 0}; \
00075         PX_STORE_METADATA(stream, tmp); \
00076     }
00077 
00082     #define PX_DEF_BIN_METADATA_ITEMS(stream, Class, type, name, flags, count) \
00083     { \
00084         PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
00085                             count, 0, flags, 0}; \
00086         PX_STORE_METADATA(stream, tmp); \
00087     }
00088 
00094     #define PX_DEF_BIN_METADATA_ITEMS_AUTO(stream, Class, type, name, flags) \
00095     { \
00096         PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
00097                             sizeof((reinterpret_cast<Class*>(0))->name)/sizeof(type), 0, flags, 0}; \
00098                             PX_STORE_METADATA(stream, tmp); \
00099     }
00100 
00104     #define PX_DEF_BIN_METADATA_CLASS(stream, Class) \
00105     { \
00106         PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
00107         PX_STORE_METADATA(stream, tmp); \
00108     }
00109 
00113     #define PX_DEF_BIN_METADATA_VCLASS(stream, Class) \
00114     { \
00115         PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS|PxMetaDataFlag::eVIRTUAL, 0}; \
00116         PX_STORE_METADATA(stream, tmp); \
00117     }
00118 
00122     #define PX_DEF_BIN_METADATA_TYPEDEF(stream, newType, oldType) \
00123     { \
00124         PxMetaDataEntry tmp = { #newType, #oldType, 0, 0, 0, 0, PxMetaDataFlag::eTYPEDEF, 0 }; \
00125         PX_STORE_METADATA(stream, tmp); \
00126     }
00127 
00131     #define PX_DEF_BIN_METADATA_BASE_CLASS(stream, Class, BaseClass) \
00132     { \
00133         Class* myClass = reinterpret_cast<Class*>(42);                                                          \
00134         BaseClass* s = static_cast<BaseClass*>(myClass);                                                        \
00135         const PxU32 offset = PxU32(size_t(s) - size_t(myClass));                                                \
00136         PxMetaDataEntry tmp = { #Class, #BaseClass, offset, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 };   \
00137         PX_STORE_METADATA(stream, tmp);                                                                         \
00138     }
00139 
00143     #define PX_DEF_BIN_METADATA_UNION(stream, Class, name) \
00144     { \
00145         PxMetaDataEntry tmp = { #Class, 0, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
00146                             1, 0, PxMetaDataFlag::eUNION, 0 }; \
00147         PX_STORE_METADATA(stream, tmp); \
00148     }
00149 
00153     #define PX_DEF_BIN_METADATA_UNION_TYPE(stream, Class, type, enumValue)  \
00154     { \
00155         PxMetaDataEntry tmp = { #Class, #type, enumValue, 0, 0, 0, PxMetaDataFlag::eUNION, 0 }; \
00156         PX_STORE_METADATA(stream, tmp); \
00157     }
00158 
00162     #define PX_DEF_BIN_METADATA_EXTRA_ITEM(stream, Class, type, control, align) \
00163     { \
00164         PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), sizeof(type), 0, PxU32(PX_SIZE_OF(Class, control)), \
00165                             PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEM, align }; \
00166         PX_STORE_METADATA(stream, tmp); \
00167     }
00168 
00172     #define PX_DEF_BIN_METADATA_EXTRA_ITEMS(stream, Class, type, control, count, flags, align)  \
00173     { \
00174         PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
00175                             PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
00176                             PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags, align }; \
00177         PX_STORE_METADATA(stream, tmp); \
00178     }
00179     
00185     #define PX_DEF_BIN_METADATA_EXTRA_ITEMS_MASKED_CONTROL(stream, Class, type, control, controlMask ,count, flags, align) \
00186     { \
00187         PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
00188                             PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
00189                             PxMetaDataFlag::eCONTROL_MASK|PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags|(controlMask & PxMetaDataFlag::eCONTROL_MASK_RANGE) << 16, \
00190                             align}; \
00191         PX_STORE_METADATA(stream, tmp); \
00192     }
00193 
00198     #define PX_DEF_BIN_METADATA_EXTRA_ARRAY(stream, Class, type, dyn_count, align, flags) \
00199     { \
00200         PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, dyn_count)), PX_SIZE_OF(Class, dyn_count), align, 0, \
00201                             PxMetaDataFlag::eEXTRA_DATA|flags, align }; \
00202         PX_STORE_METADATA(stream, tmp); \
00203     }
00204 
00208     #define PX_DEF_BIN_METADATA_EXTRA_NAME(stream, Class, control, align) \
00209     { \
00210         PxMetaDataEntry tmp = { "char", "string", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_NAME, align }; \
00211         PX_STORE_METADATA(stream, tmp); \
00212     }
00213     
00217     #define PX_DEF_BIN_METADATA_EXTRA_ALIGN(stream, Class, align)   \
00218     { \
00219         PxMetaDataEntry tmp = { "PxU8", "Alignment", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eALIGNMENT, align}; \
00220         PX_STORE_METADATA(stream, tmp); \
00221     }
00222 
00223 #if !PX_DOXYGEN
00224 } // namespace physx
00225 #endif
00226 
00228 #endif


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com