You're breathtaking!

This commit is contained in:
Wojtek Figat
2020-12-07 23:40:54 +01:00
commit 6fb9eee74c
5143 changed files with 1153594 additions and 0 deletions

201
Source/ThirdParty/PhysX/common/PxBase.h vendored Normal file
View File

@@ -0,0 +1,201 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_PX_BASE
#define PX_PHYSICS_PX_BASE
/** \addtogroup common
@{
*/
#include "foundation/PxFlags.h"
#include "common/PxSerialFramework.h"
#include "common/PxCollection.h"
#include "common/PxTypeInfo.h"
#include <string.h> // For strcmp
#if !PX_DOXYGEN
namespace physx
{
#endif
typedef PxU16 PxType;
/**
\brief Flags for PxBase.
*/
struct PxBaseFlag
{
enum Enum
{
eOWNS_MEMORY = (1<<0),
eIS_RELEASABLE = (1<<1)
};
};
typedef PxFlags<PxBaseFlag::Enum, PxU16> PxBaseFlags;
PX_FLAGS_OPERATORS(PxBaseFlag::Enum, PxU16)
/**
\brief Base class for objects that can be members of a PxCollection.
All PxBase sub-classes can be serialized.
@see PxCollection
*/
class PxBase
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format. See comments for
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
/**
\brief Releases the PxBase instance, please check documentation of release in derived class.
*/
virtual void release() = 0;
/**
\brief Returns string name of dynamic type.
\return Class name of most derived type of this object.
*/
virtual const char* getConcreteTypeName() const = 0;
/* brief Implements dynamic cast functionality.
Example use:
if(actor->is<PxRigidDynamic>()) {...}
\return A pointer to the specified type if object matches, otherwise NULL
*/
template<class T> T* is() { return typeMatch<T>() ? static_cast<T*>(this) : NULL; }
/* brief Implements dynamic cast functionality for const objects.
Example use:
if(actor->is<PxRigidDynamic>()) {...}
\return A pointer to the specified type if object matches, otherwise NULL
*/
template<class T> const T* is() const { return typeMatch<T>() ? static_cast<const T*>(this) : NULL; }
/**
\brief Returns concrete type of object.
\return PxConcreteType::Enum of serialized object
@see PxConcreteType
*/
PX_FORCE_INLINE PxType getConcreteType() const { return mConcreteType; }
/**
\brief Set PxBaseFlag
\param[in] flag The flag to be set
\param[in] value The flags new value
*/
PX_FORCE_INLINE void setBaseFlag(PxBaseFlag::Enum flag, bool value) { mBaseFlags = value ? mBaseFlags|flag : mBaseFlags&~flag; }
/**
\brief Set PxBaseFlags
\param[in] inFlags The flags to be set
@see PxBaseFlags
*/
PX_FORCE_INLINE void setBaseFlags(PxBaseFlags inFlags) { mBaseFlags = inFlags; }
/**
\brief Returns PxBaseFlags
\return PxBaseFlags
@see PxBaseFlags
*/
PX_FORCE_INLINE PxBaseFlags getBaseFlags() const { return mBaseFlags; }
/**
\brief Whether the object is subordinate.
A class is subordinate, if it can only be instantiated in the context of another class.
\return Whether the class is subordinate
@see PxSerialization::isSerializable
*/
virtual bool isReleasable() const { return mBaseFlags & PxBaseFlag::eIS_RELEASABLE; }
protected:
/**
\brief Constructor setting concrete type and base flags.
*/
PX_INLINE PxBase(PxType concreteType, PxBaseFlags baseFlags)
: mConcreteType(concreteType), mBaseFlags(baseFlags) {}
/**
\brief Deserialization constructor setting base flags.
*/
PX_INLINE PxBase(PxBaseFlags baseFlags) : mBaseFlags(baseFlags) {}
/**
\brief Destructor.
*/
virtual ~PxBase() {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* superClass) const { return !::strcmp(superClass, "PxBase"); }
template<class T> bool typeMatch() const
{
return PxU32(PxTypeInfo<T>::eFastTypeId)!=PxU32(PxConcreteType::eUNDEFINED) ?
PxU32(getConcreteType()) == PxU32(PxTypeInfo<T>::eFastTypeId) : isKindOf(PxTypeInfo<T>::name());
}
private:
friend void getBinaryMetaData_PxBase(PxOutputStream& stream);
protected:
PxType mConcreteType; // concrete type identifier - see PxConcreteType.
PxBaseFlags mBaseFlags; // internal flags
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,279 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_PX_COLLECTION
#define PX_PHYSICS_PX_COLLECTION
#include "common/PxSerialFramework.h"
/** \addtogroup common
@{
*/
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxBase;
/**
\brief Collection class for serialization.
A collection is a set of PxBase objects. PxBase objects can be added to the collection
regardless of other objects they depend on. Objects may be named using PxSerialObjectId values in order
to resolve dependencies between objects of different collections.
Serialization and deserialization only work through collections.
A scene is typically serialized using the following steps:
-# create a serialization registry
-# create a collection for scene objects
-# complete the scene objects (adds all dependent objects, e.g. meshes)
-# serialize collection
-# release collection
-# release serialization registry
For example the code may look like this:
\code
PxPhysics* physics; // The physics
PxScene* scene; // The physics scene
SerialStream s; // The user-defined stream doing the actual write to disk
PxSerializationRegistry* registry = PxSerialization::createSerializationRegistry(*physics); // step 1)
PxCollection* collection = PxSerialization::createCollection(*scene); // step 2)
PxSerialization::complete(*collection, *registry); // step 3)
PxSerialization::serializeCollectionToBinary(s, *collection, *registry); // step 4)
collection->release(); // step 5)
registry->release(); // step 6)
\endcode
A scene is typically deserialized using the following steps:
-# load a serialized collection into memory
-# create a serialization registry
-# create a collection by passing the serialized memory block
-# add collected objects to scene
-# release collection
-# release serialization registry
For example the code may look like this:
\code
PxPhysics* physics; // The physics
PxScene* scene; // The physics scene
void* memory128; // a 128-byte aligned buffer previously loaded from disk by the user - step 1)
PxSerializationRegistry* registry = PxSerialization::createSerializationRegistry(*physics); // step 2)
PxCollection* collection = PxSerialization::createCollectionFromBinary(memory128, *registry); // step 3)
scene->addCollection(*collection); // step 4)
collection->release(); // step 5)
registry->release(); // step 6)
\endcode
@see PxBase, PxCreateCollection()
*/
class PxCollection
{
public:
/**
\brief Adds a PxBase object to the collection.
Adds a PxBase object to the collection. Optionally a PxSerialObjectId can be provided
in order to resolve dependencies between collections. A PxSerialObjectId value of PX_SERIAL_OBJECT_ID_INVALID
means the object remains without id. Objects can be added regardless of other objects they require. If the object
is already in the collection, the ID will be set if it was PX_SERIAL_OBJECT_ID_INVALID previously, otherwise the
operation fails.
\param[in] object Object to be added to the collection
\param[in] id Optional PxSerialObjectId id
*/
virtual void add(PxBase& object, PxSerialObjectId id = PX_SERIAL_OBJECT_ID_INVALID) = 0;
/**
\brief Removes a PxBase member object from the collection.
Object needs to be contained by the collection.
\param[in] object PxBase object to be removed
*/
virtual void remove(PxBase& object) = 0;
/**
\brief Returns whether the collection contains a certain PxBase object.
\param[in] object PxBase object
\return Whether object is contained.
*/
virtual bool contains(PxBase& object) const = 0;
/**
\brief Adds an id to a member PxBase object.
If the object is already associated with an id within the collection, the id is replaced.
May only be called for objects that are members of the collection. The id needs to be unique
within the collection.
\param[in] object Member PxBase object
\param[in] id PxSerialObjectId id to be given to the object
*/
virtual void addId(PxBase& object, PxSerialObjectId id) = 0;
/**
\brief Removes id from a contained PxBase object.
May only be called for ids that are associated with an object in the collection.
\param[in] id PxSerialObjectId value
*/
virtual void removeId(PxSerialObjectId id) = 0;
/**
\brief Adds all PxBase objects and their ids of collection to this collection.
PxBase objects already in this collection are ignored. Object ids need to be conflict
free, i.e. the same object may not have two different ids within the two collections.
\param[in] collection Collection to be added
*/
virtual void add(PxCollection& collection) = 0;
/**
\brief Removes all PxBase objects of collection from this collection.
PxBase objects not present in this collection are ignored. Ids of objects
which are removed are also removed.
\param[in] collection Collection to be removed
*/
virtual void remove(PxCollection& collection) = 0;
/**
\brief Gets number of PxBase objects in this collection.
\return Number of objects in this collection
*/
virtual PxU32 getNbObjects() const = 0;
/**
\brief Gets the PxBase object of this collection given its index.
\param[in] index PxBase index in [0, getNbObjects())
\return PxBase object at index index
*/
virtual PxBase& getObject(PxU32 index) const = 0;
/**
\brief Copies member PxBase pointers to a user specified buffer.
\param[out] userBuffer Array of PxBase pointers
\param[in] bufferSize Capacity of userBuffer
\param[in] startIndex Offset into list of member PxBase objects
\return number of members PxBase objects that have been written to the userBuffer
*/
virtual PxU32 getObjects(PxBase** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
/**
\brief Looks for a PxBase object given a PxSerialObjectId value.
If there is no PxBase object in the collection with the given id, NULL is returned.
\param[in] id PxSerialObjectId value to look for
\return PxBase object with the given id value or NULL
*/
virtual PxBase* find(PxSerialObjectId id) const = 0;
/**
\brief Gets number of PxSerialObjectId names in this collection.
\return Number of PxSerialObjectId names in this collection
*/
virtual PxU32 getNbIds() const = 0;
/**
\brief Copies member PxSerialObjectId values to a user specified buffer.
\param[out] userBuffer Array of PxSerialObjectId values
\param[in] bufferSize Capacity of userBuffer
\param[in] startIndex Offset into list of member PxSerialObjectId values
\return number of members PxSerialObjectId values that have been written to the userBuffer
*/
virtual PxU32 getIds(PxSerialObjectId* userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
/**
\brief Gets the PxSerialObjectId name of a PxBase object within the collection.
The PxBase object needs to be a member of the collection.
\param[in] object PxBase object to get id for
\return PxSerialObjectId name of the object or PX_SERIAL_OBJECT_ID_INVALID if the object is unnamed
*/
virtual PxSerialObjectId getId(const PxBase& object) const = 0;
/**
\brief Deletes a collection object.
This function only deletes the collection object, i.e. the container class. It doesn't delete objects
that are part of the collection.
@see PxCreateCollection()
*/
virtual void release() = 0;
protected:
PxCollection() {}
virtual ~PxCollection() {}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/**
\brief Creates a collection object.
Objects can only be serialized or deserialized through a collection.
For serialization, users must add objects to the collection and serialize the collection as a whole.
For deserialization, the system gives back a collection of deserialized objects to users.
\return The new collection object.
@see PxCollection, PxCollection::release()
*/
PX_PHYSX_COMMON_API physx::PxCollection* PX_CALL_CONV PxCreateCollection();
/** @} */
#endif

View File

@@ -0,0 +1,211 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_CORE_UTILTY_TYPES_H
#define PX_CORE_UTILTY_TYPES_H
/** \addtogroup common
@{
*/
#include "foundation/PxAssert.h"
#include "foundation/PxMemory.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
struct PxStridedData
{
/**
\brief The offset in bytes between consecutive samples in the data.
<b>Default:</b> 0
*/
PxU32 stride;
const void* data;
PxStridedData() : stride( 0 ), data( NULL ) {}
template<typename TDataType>
PX_INLINE const TDataType& at( PxU32 idx ) const
{
PxU32 theStride( stride );
if ( theStride == 0 )
theStride = sizeof( TDataType );
PxU32 offset( theStride * idx );
return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const PxU8* >( data ) + offset ));
}
};
template<typename TDataType>
struct PxTypedStridedData
{
PxU32 stride;
const TDataType* data;
PxTypedStridedData()
: stride( 0 )
, data( NULL )
{
}
};
struct PxBoundedData : public PxStridedData
{
PxU32 count;
PxBoundedData() : count( 0 ) {}
};
template<PxU8 TNumBytes>
struct PxPadding
{
PxU8 mPadding[TNumBytes];
PxPadding()
{
for ( PxU8 idx =0; idx < TNumBytes; ++idx )
mPadding[idx] = 0;
}
};
template <PxU32 NB_ELEMENTS> class PxFixedSizeLookupTable
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format. See comments for
// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
PxFixedSizeLookupTable()
: mNbDataPairs(0)
{
}
PxFixedSizeLookupTable(const PxEMPTY) {}
PxFixedSizeLookupTable(const PxReal* dataPairs, const PxU32 numDataPairs)
{
PxMemCopy(mDataPairs,dataPairs,sizeof(PxReal)*2*numDataPairs);
mNbDataPairs=numDataPairs;
}
PxFixedSizeLookupTable(const PxFixedSizeLookupTable& src)
{
PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
mNbDataPairs=src.mNbDataPairs;
}
~PxFixedSizeLookupTable()
{
}
PxFixedSizeLookupTable& operator=(const PxFixedSizeLookupTable& src)
{
PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
mNbDataPairs=src.mNbDataPairs;
return *this;
}
PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
{
PX_ASSERT(mNbDataPairs<NB_ELEMENTS);
mDataPairs[2*mNbDataPairs+0]=x;
mDataPairs[2*mNbDataPairs+1]=y;
mNbDataPairs++;
}
PX_FORCE_INLINE PxReal getYVal(const PxReal x) const
{
if(0==mNbDataPairs)
{
PX_ASSERT(false);
return 0;
}
if(1==mNbDataPairs || x<getX(0))
{
return getY(0);
}
PxReal x0=getX(0);
PxReal y0=getY(0);
for(PxU32 i=1;i<mNbDataPairs;i++)
{
const PxReal x1=getX(i);
const PxReal y1=getY(i);
if((x>=x0)&&(x<x1))
{
return (y0+(y1-y0)*(x-x0)/(x1-x0));
}
x0=x1;
y0=y1;
}
PX_ASSERT(x>=getX(mNbDataPairs-1));
return getY(mNbDataPairs-1);
}
PxU32 getNbDataPairs() const {return mNbDataPairs;}
void clear()
{
memset(mDataPairs, 0, NB_ELEMENTS*2*sizeof(PxReal));
mNbDataPairs = 0;
}
PX_FORCE_INLINE PxReal getX(const PxU32 i) const
{
return mDataPairs[2*i];
}
PX_FORCE_INLINE PxReal getY(const PxU32 i) const
{
return mDataPairs[2*i+1];
}
PxReal mDataPairs[2*NB_ELEMENTS];
PxU32 mNbDataPairs;
PxU32 mPad[3];
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,228 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_METADATA_H
#define PX_PHYSICS_METADATA_H
/** \addtogroup physics
@{
*/
#include "foundation/Px.h"
#include "foundation/PxIO.h"
#include "PxMetaDataFlags.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Struct to store meta data definitions.
Note: The individual fields have different meaning depending on the meta data entry configuration.
*/
struct PxMetaDataEntry
{
const char* type; //!< Field type (bool, byte, quaternion, etc)
const char* name; //!< Field name (appears exactly as in the source file)
PxU32 offset; //!< Offset from the start of the class (ie from "this", field is located at "this"+Offset)
PxU32 size; //!< sizeof(Type)
PxU32 count; //!< Number of items of type Type (0 for dynamic sizes)
PxU32 offsetSize; //!< Offset of dynamic size param, for dynamic arrays
PxU32 flags; //!< Field parameters
PxU32 alignment; //!< Explicit alignment
};
#define PX_STORE_METADATA(stream, metaData) stream.write(&metaData, sizeof(PxMetaDataEntry))
#define PX_SIZE_OF(Class, Member) sizeof((reinterpret_cast<Class*>(0))->Member)
/**
\brief specifies a binary metadata entry for a member variable of a class
*/
#define PX_DEF_BIN_METADATA_ITEM(stream, Class, type, name, flags) \
{ \
PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
1, 0, flags, 0}; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a member array variable of a class
\details similar to PX_DEF_BIN_METADATA_ITEMS_AUTO but for cases with mismatch between specified type and array type
*/
#define PX_DEF_BIN_METADATA_ITEMS(stream, Class, type, name, flags, count) \
{ \
PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
count, 0, flags, 0}; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a member array variable of a class
\details similar to PX_DEF_BIN_METADATA_ITEMS but automatically detects the array length, which only works when the specified
type matches the type of the array - does not support PxMetaDataFlag::ePTR
*/
#define PX_DEF_BIN_METADATA_ITEMS_AUTO(stream, Class, type, name, flags) \
{ \
PxMetaDataEntry tmp = { #type, #name, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
sizeof((reinterpret_cast<Class*>(0))->name)/sizeof(type), 0, flags, 0}; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a class
*/
#define PX_DEF_BIN_METADATA_CLASS(stream, Class) \
{ \
PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a virtual class
*/
#define PX_DEF_BIN_METADATA_VCLASS(stream, Class) \
{ \
PxMetaDataEntry tmp = { #Class, 0, 0, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS|PxMetaDataFlag::eVIRTUAL, 0}; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a typedef
*/
#define PX_DEF_BIN_METADATA_TYPEDEF(stream, newType, oldType) \
{ \
PxMetaDataEntry tmp = { #newType, #oldType, 0, 0, 0, 0, PxMetaDataFlag::eTYPEDEF, 0 }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for declaring a base class
*/
#define PX_DEF_BIN_METADATA_BASE_CLASS(stream, Class, BaseClass) \
{ \
Class* myClass = reinterpret_cast<Class*>(42); \
BaseClass* s = static_cast<BaseClass*>(myClass); \
const PxU32 offset = PxU32(size_t(s) - size_t(myClass)); \
PxMetaDataEntry tmp = { #Class, #BaseClass, offset, sizeof(Class), 0, 0, PxMetaDataFlag::eCLASS, 0 }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a union
*/
#define PX_DEF_BIN_METADATA_UNION(stream, Class, name) \
{ \
PxMetaDataEntry tmp = { #Class, 0, PxU32(PX_OFFSET_OF_RT(Class, name)), PX_SIZE_OF(Class, name), \
1, 0, PxMetaDataFlag::eUNION, 0 }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for a particular member type of a union
*/
#define PX_DEF_BIN_METADATA_UNION_TYPE(stream, Class, type, enumValue) \
{ \
PxMetaDataEntry tmp = { #Class, #type, enumValue, 0, 0, 0, PxMetaDataFlag::eUNION, 0 }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for extra data
*/
#define PX_DEF_BIN_METADATA_EXTRA_ITEM(stream, Class, type, control, align) \
{ \
PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), sizeof(type), 0, PxU32(PX_SIZE_OF(Class, control)), \
PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEM, align }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for an array of extra data
*/
#define PX_DEF_BIN_METADATA_EXTRA_ITEMS(stream, Class, type, control, count, flags, align) \
{ \
PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags, align }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for an array of extra data
additional to PX_DEF_BIN_METADATA_EXTRA_ITEMS a mask can be specified to interpret the control value
@see PxMetaDataFlag::eCONTROL_MASK
*/
#define PX_DEF_BIN_METADATA_EXTRA_ITEMS_MASKED_CONTROL(stream, Class, type, control, controlMask ,count, flags, align) \
{ \
PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, control)), PxU32(PX_SIZE_OF(Class, control)), \
PxU32(PX_OFFSET_OF_RT(Class, count)), PxU32(PX_SIZE_OF(Class, count)), \
PxMetaDataFlag::eCONTROL_MASK|PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_ITEMS|flags|(controlMask & PxMetaDataFlag::eCONTROL_MASK_RANGE) << 16, \
align}; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for an array of extra data
\details similar to PX_DEF_BIN_METADATA_EXTRA_ITEMS, but supporting no control - PxMetaDataFlag::ePTR is also not supported
*/
#define PX_DEF_BIN_METADATA_EXTRA_ARRAY(stream, Class, type, dyn_count, align, flags) \
{ \
PxMetaDataEntry tmp = { #type, 0, PxU32(PX_OFFSET_OF_RT(Class, dyn_count)), PX_SIZE_OF(Class, dyn_count), align, 0, \
PxMetaDataFlag::eEXTRA_DATA|flags, align }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry for an string of extra data
*/
#define PX_DEF_BIN_METADATA_EXTRA_NAME(stream, Class, control, align) \
{ \
PxMetaDataEntry tmp = { "char", "string", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eEXTRA_NAME, align }; \
PX_STORE_METADATA(stream, tmp); \
}
/**
\brief specifies a binary metadata entry declaring an extra data alignment for a class
*/
#define PX_DEF_BIN_METADATA_EXTRA_ALIGN(stream, Class, align) \
{ \
PxMetaDataEntry tmp = { "PxU8", "Alignment", 0, 0, 0, 0, PxMetaDataFlag::eEXTRA_DATA|PxMetaDataFlag::eALIGNMENT, align}; \
PX_STORE_METADATA(stream, tmp); \
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,75 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_METADATA_FLAGS
#define PX_PHYSICS_METADATA_FLAGS
#include "foundation/Px.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Flags used to configure binary meta data entries, typically set through PX_DEF_BIN_METADATA defines.
@see PxMetaDataEntry
*/
struct PxMetaDataFlag
{
enum Enum
{
eCLASS = (1<<0), //!< declares a class
eVIRTUAL = (1<<1), //!< declares class to be virtual
eTYPEDEF = (1<<2), //!< declares a typedef
ePTR = (1<<3), //!< declares a pointer
eHANDLE = (1<<4), //!< declares a handle
eEXTRA_DATA = (1<<5), //!< declares extra data exported with PxSerializer::exportExtraData
eEXTRA_ITEM = (1<<6), //!< specifies one element of extra data
eEXTRA_ITEMS = (1<<7), //!< specifies an array of extra data
eEXTRA_NAME = (1<<8), //!< specifies a name of extra data
eUNION = (1<<9), //!< declares a union
ePADDING = (1<<10), //!< declares explicit padding data
eALIGNMENT = (1<<11), //!< declares aligned data
eCOUNT_MASK_MSB = (1<<12), //!< specifies that the count value's most significant bit needs to be masked out
eCOUNT_SKIP_IF_ONE = (1<<13), //!< specifies that the count value is treated as zero for a variable value of one - special case for single triangle meshes
eCONTROL_FLIP = (1<<14), //!< specifies that the control value is the negate of the variable value
eCONTROL_MASK = (1<<15), //!< specifies that the control value is masked - mask bits are assumed to be within eCONTROL_MASK_RANGE
eCONTROL_MASK_RANGE = 0x000000FF, //!< mask range allowed for eCONTROL_MASK
eFORCE_DWORD = 0x7fffffff
};
};
#if !PX_DOXYGEN
}
#endif
#endif

View File

@@ -0,0 +1,124 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_COMMON_NX
#define PX_PHYSICS_COMMON_NX
/** \addtogroup common
@{ */
#include "foundation/Px.h"
/*Disable support for VS2017 prior version 15.5.1 for windows platform, because of a compiler bug:
https://developercommunity.visualstudio.com/content/problem/66047/possible-compiler-bug.html
*/
#if (PX_VC == 15) && PX_WINDOWS && (_MSC_FULL_VER < 191225830)
#error Visual studio 2017 prior to 15.5.1 is not supported because of a compiler bug.
#endif
// define API function declaration (public API only needed because of extensions)
#if defined PX_PHYSX_STATIC_LIB
#define PX_PHYSX_CORE_API
#else
#if (PX_WINDOWS_FAMILY || PX_XBOXONE || PX_PS4)
#if defined PX_PHYSX_CORE_EXPORTS
#define PX_PHYSX_CORE_API __declspec(dllexport)
#else
#define PX_PHYSX_CORE_API __declspec(dllimport)
#endif
#elif PX_UNIX_FAMILY
#define PX_PHYSX_CORE_API PX_UNIX_EXPORT
#else
#define PX_PHYSX_CORE_API
#endif
#endif
#if PX_SUPPORT_GPU_PHYSX
// define API function declaration
#if defined PX_PHYSX_GPU_STATIC
#define PX_PHYSX_GPU_API
#else
#if PX_WINDOWS
#if defined PX_PHYSX_GPU_EXPORTS
#define PX_PHYSX_GPU_API __declspec(dllexport)
#else
#define PX_PHYSX_GPU_API __declspec(dllimport)
#endif
#elif PX_UNIX_FAMILY
#define PX_PHYSX_GPU_API PX_UNIX_EXPORT
#else
#define PX_PHYSX_GPU_API
#endif
#endif
#else // PX_SUPPORT_GPU_PHYSX
#define PX_PHYSX_GPU_API
#endif // PX_SUPPORT_GPU_PHYSX
#if defined PX_PHYSX_STATIC_LIB
#define PX_PHYSX_COMMON_API
#else
#if (PX_WINDOWS_FAMILY || PX_XBOXONE || PX_PS4) && !defined(__CUDACC__)
#if defined PX_PHYSX_COMMON_EXPORTS
#define PX_PHYSX_COMMON_API __declspec(dllexport)
#else
#define PX_PHYSX_COMMON_API __declspec(dllimport)
#endif
#elif PX_UNIX_FAMILY
#define PX_PHYSX_COMMON_API PX_UNIX_EXPORT
#else
#define PX_PHYSX_COMMON_API
#endif
#endif
// Changing these parameters requires recompilation of the SDK
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxCollection;
class PxBase;
class PxHeightField;
class PxHeightFieldDesc;
class PxTriangleMesh;
class PxConvexMesh;
typedef PxU32 PxTriangleID;
typedef PxU16 PxMaterialTableIndex;
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,84 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_PX_PHYSICS_INSERTION_CALLBACK
#define PX_PHYSICS_PX_PHYSICS_INSERTION_CALLBACK
#include "common/PxBase.h"
/** \addtogroup common
@{
*/
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Callback interface that permits PxCooking to insert a
TriangleMesh, HeightfieldMesh or ConvexMesh directly into PxPhysics without the need to store
the cooking results into a stream.
Using this is advised only if real-time cooking is required; using "offline" cooking and
streams is otherwise preferred.
The default PxPhysicsInsertionCallback implementation must be used. The PxPhysics
default callback can be obtained using the PxPhysics::getPhysicsInsertionCallback().
@see PxCooking PxPhysics
*/
class PxPhysicsInsertionCallback
{
public:
PxPhysicsInsertionCallback() {}
/**
\brief Builds object (TriangleMesh, HeightfieldMesh or ConvexMesh) from given data in PxPhysics.
\param type Object type to build.
\param data Object data
\return PxBase Created object in PxPhysics.
*/
virtual PxBase* buildObjectFromData(PxConcreteType::Enum type, void* data) = 0;
protected:
virtual ~PxPhysicsInsertionCallback() {}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,51 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
#ifndef PXFOUNDATION_PXPROFILEZONE_H
#define PXFOUNDATION_PXPROFILEZONE_H
#include "foundation/PxProfiler.h"
#include "PxFoundation.h"
#if PX_DEBUG || PX_CHECKED || PX_PROFILE
#define PX_PROFILE_ZONE(x, y) \
physx::PxProfileScoped PX_CONCAT(_scoped, __LINE__)(PxGetProfilerCallback(), x, false, y)
#define PX_PROFILE_START_CROSSTHREAD(x, y) \
if(PxGetProfilerCallback()) \
PxGetProfilerCallback()->zoneStart(x, true, y)
#define PX_PROFILE_STOP_CROSSTHREAD(x, y) \
if(PxGetProfilerCallback()) \
PxGetProfilerCallback()->zoneEnd(NULL, x, true, y)
#else
#define PX_PROFILE_ZONE(x, y)
#define PX_PROFILE_START_CROSSTHREAD(x, y)
#define PX_PROFILE_STOP_CROSSTHREAD(x, y)
#endif
#define PX_PROFILE_POINTER_TO_U64(pointer) static_cast<uint64_t>(reinterpret_cast<size_t>(pointer))
#endif // PXFOUNDATION_PXPROFILEZONE_H

View File

@@ -0,0 +1,157 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_FOUNDATION_PXRENDERBUFFER_H
#define PX_FOUNDATION_PXRENDERBUFFER_H
/** \addtogroup common
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxVec3.h"
#include "foundation/PxMat33.h"
#include "foundation/PxBounds3.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Default color values used for debug rendering.
*/
struct PxDebugColor
{
enum Enum
{
eARGB_BLACK = 0xff000000,
eARGB_RED = 0xffff0000,
eARGB_GREEN = 0xff00ff00,
eARGB_BLUE = 0xff0000ff,
eARGB_YELLOW = 0xffffff00,
eARGB_MAGENTA = 0xffff00ff,
eARGB_CYAN = 0xff00ffff,
eARGB_WHITE = 0xffffffff,
eARGB_GREY = 0xff808080,
eARGB_DARKRED = 0x88880000,
eARGB_DARKGREEN = 0x88008800,
eARGB_DARKBLUE = 0x88000088
};
};
/**
\brief Used to store a single point and colour for debug rendering.
*/
struct PxDebugPoint
{
PxDebugPoint(const PxVec3& p, const PxU32& c)
: pos(p), color(c) {}
PxVec3 pos;
PxU32 color;
};
/**
\brief Used to store a single line and colour for debug rendering.
*/
struct PxDebugLine
{
PxDebugLine(const PxVec3& p0, const PxVec3& p1, const PxU32& c)
: pos0(p0), color0(c), pos1(p1), color1(c) {}
PxVec3 pos0;
PxU32 color0;
PxVec3 pos1;
PxU32 color1;
};
/**
\brief Used to store a single triangle and colour for debug rendering.
*/
struct PxDebugTriangle
{
PxDebugTriangle(const PxVec3& p0, const PxVec3& p1, const PxVec3& p2, const PxU32& c)
: pos0(p0), color0(c), pos1(p1), color1(c), pos2(p2), color2(c) {}
PxVec3 pos0;
PxU32 color0;
PxVec3 pos1;
PxU32 color1;
PxVec3 pos2;
PxU32 color2;
};
/**
\brief Used to store a text for debug rendering. Doesn't own 'string' array.
*/
struct PxDebugText
{
PxDebugText() : string(0) {}
PxDebugText(const PxVec3& p, const PxReal& s, const PxU32& c, const char* str)
: position(p), size(s), color(c), string(str) {}
PxVec3 position;
PxReal size;
PxU32 color;
const char* string;
};
/**
\brief Interface for points, lines, triangles, and text buffer.
*/
class PxRenderBuffer
{
public:
virtual ~PxRenderBuffer() {}
virtual PxU32 getNbPoints() const = 0;
virtual const PxDebugPoint* getPoints() const = 0;
virtual PxU32 getNbLines() const = 0;
virtual const PxDebugLine* getLines() const = 0;
virtual PxU32 getNbTriangles() const = 0;
virtual const PxDebugTriangle* getTriangles() const = 0;
virtual PxU32 getNbTexts() const = 0;
virtual const PxDebugText* getTexts() const = 0;
virtual void append(const PxRenderBuffer& other) = 0;
virtual void clear() = 0;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,399 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
#define PX_PHYSICS_COMMON_NX_SERIAL_FRAMEWORK
/** \addtogroup common
@{
*/
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
typedef PxU16 PxType;
class PxBase;
class PxSerializationContext;
class PxRepXSerializer;
class PxSerializer;
class PxPhysics;
//! Default serialization alignment
#define PX_SERIAL_ALIGN 16
//! Serialized input data must be aligned to this value
#define PX_SERIAL_FILE_ALIGN 128
//! PxSerialObjectId value for objects that do not have an ID
#define PX_SERIAL_OBJECT_ID_INVALID 0
//! ID type for PxBase objects in a PxCollection
typedef PxU64 PxSerialObjectId;
//! Bit to mark pointer type references, @see PxDeserializationContext
#define PX_SERIAL_REF_KIND_PTR_TYPE_BIT (1u<<31)
//! Reference kind value for PxBase objects
#define PX_SERIAL_REF_KIND_PXBASE (0 | PX_SERIAL_REF_KIND_PTR_TYPE_BIT)
//! Reference kind value for material indices
#define PX_SERIAL_REF_KIND_MATERIAL_IDX (1)
//! Used to fix multi-byte characters warning from gcc for situations like: PxU32 foo = 'CCTS';
#define PX_MAKE_FOURCC(a, b, c, d) ( (a) | ((b)<<8) | ((c)<<16) | ((d)<<24) )
/**
\brief Callback class used to process PxBase objects.
@see PxSerializer::requires
*/
class PxProcessPxBaseCallback
{
public:
virtual ~PxProcessPxBaseCallback() {}
virtual void process(PxBase&) = 0;
};
/**
\brief Binary serialization context class.
This class is used to register reference values and write object
and object extra data during serialization.
It is mainly used by the serialization framework. Except for custom
serializable types, users should not have to worry about it.
@see PxDeserializationContext
*/
class PxSerializationContext
{
public:
/**
\brief Registers a reference value corresponding to a PxBase object.
This method is assumed to be called in the implementation of PxSerializer::registerReferences for serialized
references that need to be resolved on deserialization.
A reference needs to be associated with exactly one PxBase object in either the collection or the
external references collection.
Different kinds of references are supported and need to be specified. In the most common case
(PX_SERIAL_REF_KIND_PXBASE) the PxBase object matches the reference value (which is the pointer
to the PxBase object). Integer references maybe registered as well (used for internal material
indices with PX_SERIAL_REF_KIND_MATERIAL_IDX). Other kinds could be added with the restriction that
for pointer types the kind value needs to be marked with the PX_SERIAL_REF_KIND_PTR_TYPE_BIT.
\param[in] base PxBase object associated with the reference
\param[in] kind What kind of reference this is (PX_SERIAL_REF_KIND_PXBASE, PX_SERIAL_REF_KIND_MATERIAL_IDX or custom kind)
\param[in] reference Value of reference
@see PxDeserializationContext::resolveReference, PX_SERIAL_REF_KIND_PXBASE, PX_SERIAL_REF_KIND_MATERIAL_IDX, PxSerializer::registerReferences
*/
virtual void registerReference(PxBase& base, PxU32 kind, size_t reference) = 0;
/**
\brief Returns the collection that is being serialized.
*/
virtual const PxCollection& getCollection() const = 0;
/**
\brief Serializes object data and object extra data.
This function is assumed to be called within the implementation of PxSerializer::exportData and PxSerializer::exportExtraData.
@see PxSerializer::exportData, PxSerializer::exportExtraData, PxSerializer::createObject, PxDeserializationContext::readExtraData
*/
virtual void writeData(const void* data, PxU32 size) = 0;
/**
\brief Aligns the serialized data.
This function is assumed to be called within the implementation of PxSerializer::exportData and PxSerializer::exportExtraData.
@see PxSerializer::exportData, PxSerializer::exportExtraData, PxDeserializationContext::alignExtraData
*/
virtual void alignData(PxU32 alignment = PX_SERIAL_ALIGN) = 0;
/**
\brief Helper function to write a name to the extraData if serialization is configured to save names.
This function is assumed to be called within the implementation of PxSerializer::exportExtraData.
@see PxSerialization::serializeCollectionToBinary, PxDeserializationContext::readName
*/
virtual void writeName(const char* name) = 0;
protected:
PxSerializationContext() {}
virtual ~PxSerializationContext() {}
};
/**
\brief Binary deserialization context class.
This class is used to resolve references and access extra data during deserialization.
It is mainly used by the serialization framework. Except for custom
serializable types, users should not have to worry about it.
@see PxSerializationContext
*/
class PxDeserializationContext
{
public:
/**
\brief Retrieves a pointer to a deserialized PxBase object given a corresponding deserialized reference value
This method is assumed to be called in the implementation of PxSerializer::createObject in order
to update reference values on deserialization.
To update a PxBase reference the corresponding deserialized pointer value needs to be provided in order to retrieve
the location of the corresponding deserialized PxBase object. (PxDeserializationContext::translatePxBase simplifies
this common case).
For other kinds of references the reverence values need to be updated by deduction given the corresponding PxBase instance.
\param[in] kind What kind of reference this is (PX_SERIAL_REF_KIND_PXBASE, PX_SERIAL_REF_KIND_MATERIAL_IDX or custom kind)
\param[in] reference Deserialized reference value
\return PxBase object associated with the reference value
@see PxSerializationContext::registerReference, PX_SERIAL_REF_KIND_PXBASE, PX_SERIAL_REF_KIND_MATERIAL_IDX, translatePxBase
*/
virtual PxBase* resolveReference(PxU32 kind, size_t reference) const = 0;
/**
\brief Helper function to update PxBase pointer on deserialization
@see resolveReference, PX_SERIAL_REF_KIND_PXBASE
*/
template<typename T>
void translatePxBase(T*& base) { if (base) { base = static_cast<T*>(resolveReference(PX_SERIAL_REF_KIND_PXBASE, size_t(base))); } }
/**
\brief Helper function to read a name from the extra data during deserialization.
This function is assumed to be called within the implementation of PxSerializer::createObject.
@see PxSerializationContext::writeName
*/
PX_INLINE void readName(const char*& name)
{
PxU32 len = *reinterpret_cast<PxU32*>(mExtraDataAddress);
mExtraDataAddress += sizeof(len);
name = len ? reinterpret_cast<const char*>(mExtraDataAddress) : NULL;
mExtraDataAddress += len;
}
/**
\brief Function to read extra data during deserialization.
This function is assumed to be called within the implementation of PxSerializer::createObject.
@see PxSerializationContext::writeData, PxSerializer::createObject
*/
template<typename T>
PX_INLINE T* readExtraData(PxU32 count=1)
{
T* data = reinterpret_cast<T*>(mExtraDataAddress);
mExtraDataAddress += sizeof(T)*count;
return data;
}
/**
\brief Function to read extra data during deserialization optionally aligning the extra data stream before reading.
This function is assumed to be called within the implementation of PxSerializer::createObject.
@see PxSerializationContext::writeData, PxDeserializationContext::alignExtraData, PxSerializer::createObject
*/
template<typename T, PxU32 alignment>
PX_INLINE T* readExtraData(PxU32 count=1)
{
alignExtraData(alignment);
return readExtraData<T>(count);
}
/**
\brief Function to align the extra data stream to a power of 2 alignment
This function is assumed to be called within the implementation of PxSerializer::createObject.
@see PxSerializationContext::alignData, PxSerializer::createObject
*/
PX_INLINE void alignExtraData(PxU32 alignment = PX_SERIAL_ALIGN)
{
size_t addr = reinterpret_cast<size_t>(mExtraDataAddress);
addr = (addr+alignment-1)&~size_t(alignment-1);
mExtraDataAddress = reinterpret_cast<PxU8*>(addr);
}
protected:
PxDeserializationContext() {}
virtual ~PxDeserializationContext() {}
PxU8* mExtraDataAddress;
};
/**
\brief Callback type for exporting binary meta data for a serializable type.
@see PxSerializationRegistry::registerBinaryMetaDataCallback
\param stream Stream to store binary meta data.
*/
typedef void (*PxBinaryMetaDataCallback)(PxOutputStream& stream);
/**
\brief Class serving as a registry for XML (RepX) and binary serializable types.
In order to serialize and deserialize objects the application needs
to maintain an instance of this class. It can be created with
PxSerialization::createSerializationRegistry() and released with
PxSerializationRegistry::release().
@see PxSerialization::createSerializationRegistry
*/
class PxSerializationRegistry
{
public:
/************************************************************************************************/
/** @name Binary Serialization Functionality
*/
//@{
/**
\brief Register a serializer for a concrete type
\param type PxConcreteType corresponding to the serializer
\param serializer The PxSerializer to be registered
@see PxConcreteType, PxSerializer, PxSerializationRegistry::unregisterSerializer
*/
virtual void registerSerializer(PxType type, PxSerializer& serializer) = 0;
/**
\brief Unregister a serializer for a concrete type, and retrieves the corresponding serializer object.
\param type PxConcreteType for which the serializer should be unregistered
\return Unregistered serializer corresponding to type, NULL for types for which no serializer has been registered.
@see PxConcreteType, PxSerializationRegistry::registerSerializer, PxSerializationRegistry::release
*/
virtual PxSerializer* unregisterSerializer(PxType type) = 0;
/**
\brief Register binary meta data callback
The callback is executed when calling PxSerialization::dumpBinaryMetaData.
\param callback PxBinaryMetaDataCallback to be registered.
@see PxBinaryMetaDataCallback, PxSerialization::dumpBinaryMetaData
*/
virtual void registerBinaryMetaDataCallback(PxBinaryMetaDataCallback callback) = 0;
/**
\brief Returns PxSerializer corresponding to type
\param type PxConcreteType of the serializer requested.
\return Registered PxSerializer object corresponding to type
@see PxConcreteType
*/
virtual const PxSerializer* getSerializer(PxType type) const = 0;
//@}
/************************************************************************************************/
/** @name RepX (XML) Serialization Functionality
*/
//@{
/**
\brief Register a RepX serializer for a concrete type
\param type PxConcreteType corresponding to the RepX serializer
\param serializer The PxRepXSerializer to be registered
@see PxConcreteType, PxRepXSerializer
*/
virtual void registerRepXSerializer(PxType type, PxRepXSerializer& serializer) = 0;
/**
\brief Unregister a RepX serializer for a concrete type, and retrieves the corresponding serializer object.
\param type PxConcreteType for which the RepX serializer should be unregistered
\return Unregistered PxRepxSerializer corresponding to type, NULL for types for which no RepX serializer has been registered.
@see PxConcreteType, PxSerializationRegistry::registerRepXSerializer, PxSerializationRegistry::release
*/
virtual PxRepXSerializer* unregisterRepXSerializer(PxType type) = 0;
/**
\brief Returns RepX serializer given the corresponding type name
\param typeName Name of the type
\return Registered PxRepXSerializer object corresponding to type name
@see PxRepXSerializer, PxTypeInfo, PX_DEFINE_TYPEINFO
*/
virtual PxRepXSerializer* getRepXSerializer(const char* typeName) const = 0;
//@}
/************************************************************************************************/
/**
\brief Releases PxSerializationRegistry instance.
This unregisters all PhysX and PhysXExtension serializers. Make sure to unregister all custom type
serializers before releasing the PxSerializationRegistry.
@see PxSerializationRegistry::unregisterSerializer, PxSerializationRegistry::unregisterRepXSerializer
*/
virtual void release() = 0;
protected:
virtual ~PxSerializationRegistry(){}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,265 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_SERIALIZER_H
#define PX_SERIALIZER_H
/** \addtogroup extensions
@{
*/
#include "foundation/PxAssert.h"
#include "foundation/PxAllocatorCallback.h"
#include "common/PxSerialFramework.h"
#include "common/PxCollection.h"
#include "PxFoundation.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Serialization interface class.
PxSerializer is used to extend serializable PxBase classes with serialization functionality. The
interface is structured such that per-class adapter instances can be used as opposed to per-object
adapter instances, avoiding per object allocations. Hence the methods take a reference to PxBase as a parameter.
The PxSerializer interface needs to be implemented for binary or RepX serialization to work on custom
types. If only RepX serialization is needed, some methods can be left empty, as they are only needed
for binary serialization.
A default implementation is available as a template adapter (PxSerializerDefaultAdapter).
@see PxSerializerDefaultAdapter, PX_NEW_SERIALIZER_ADAPTER, PxSerializationRegistry::registerSerializer
*/
class PxSerializer
{
public:
/**********************************************************************************************************************/
/** @name Basics needed for Binary- and RepX-Serialization
*/
//@{
/**
\brief Returns string name of dynamic type.
\return Class name of most derived type of this object.
*/
virtual const char* getConcreteTypeName() const = 0;
/**
\brief Adds required objects to the collection.
This method does not add the required objects recursively, e.g. objects required by required objects.
@see PxCollection, PxSerialization::complete
*/
virtual void requiresObjects(PxBase&, PxProcessPxBaseCallback&) const = 0;
/**
\brief Whether the object is subordinate.
A class is subordinate, if it can only be instantiated in the context of another class.
\return Whether the class is subordinate
@see PxSerialization::isSerializable
*/
virtual bool isSubordinate() const = 0;
//@}
/**********************************************************************************************************************/
/**********************************************************************************************************************/
/** @name Functionality needed for Binary Serialization only
*/
//@{
/**
\brief Exports object's extra data to stream.
*/
virtual void exportExtraData(PxBase&, PxSerializationContext&) const = 0;
/**
\brief Exports object's data to stream.
*/
virtual void exportData(PxBase&, PxSerializationContext&) const = 0;
/**
\brief Register references that the object maintains to other objects.
*/
virtual void registerReferences(PxBase& obj, PxSerializationContext& s) const = 0;
/**
\brief Returns size needed to create the class instance.
\return sizeof class instance.
*/
virtual size_t getClassSize() const = 0;
/**
\brief Create object at a given address, resolve references and import extra data.
\param address Location at which object is created. Address is increased by the size of the created object.
\param context Context for reading external data and resolving references.
\return Created PxBase pointer (needs to be identical to address before increment).
*/
virtual PxBase* createObject(PxU8*& address, PxDeserializationContext& context) const = 0;
//@}
/**********************************************************************************************************************/
virtual ~PxSerializer() {}
};
/**
\brief Default PxSerializer implementation.
*/
template<class T>
class PxSerializerDefaultAdapter : public PxSerializer
{
public:
/************************************************************************************************/
/** @name Basics needed for Binary- and RepX-Serialization
*/
//@{
PxSerializerDefaultAdapter(const char* name) : mTypeName(name){}
virtual const char* getConcreteTypeName() const
{
return mTypeName;
}
virtual void requiresObjects(PxBase& obj, PxProcessPxBaseCallback& c) const
{
T& t = static_cast<T&>(obj);
t.requiresObjects(c);
}
virtual bool isSubordinate() const
{
return false;
}
//@}
/************************************************************************************************/
/** @name Functionality needed for Binary Serialization only
*/
//@{
// object methods
virtual void exportExtraData(PxBase& obj, PxSerializationContext& s) const
{
T& t = static_cast<T&>(obj);
t.exportExtraData(s);
}
virtual void exportData(PxBase& obj, PxSerializationContext& s) const
{
PxAllocatorCallback& allocator = PxGetFoundation().getAllocatorCallback();
T* copy = reinterpret_cast<T*>(allocator.allocate(sizeof(T), "TmpAllocExportData", __FILE__, __LINE__));
PxMemCopy(copy, &obj, sizeof(T));
copy->preExportDataReset();
s.writeData(copy, sizeof(T));
allocator.deallocate(copy);
}
virtual void registerReferences(PxBase& obj, PxSerializationContext& s) const
{
T& t = static_cast<T&>(obj);
s.registerReference(obj, PX_SERIAL_REF_KIND_PXBASE, size_t(&obj));
struct RequiresCallback : public PxProcessPxBaseCallback
{
RequiresCallback(PxSerializationContext& c) : context(c) {}
RequiresCallback& operator=(RequiresCallback&) { PX_ASSERT(0); return *this; }
void process(physx::PxBase& base)
{
context.registerReference(base, PX_SERIAL_REF_KIND_PXBASE, size_t(&base));
}
PxSerializationContext& context;
};
RequiresCallback callback(s);
t.requiresObjects(callback);
}
// class methods
virtual size_t getClassSize() const
{
return sizeof(T);
}
virtual PxBase* createObject(PxU8*& address, PxDeserializationContext& context) const
{
return T::createObject(address, context);
}
//@}
/************************************************************************************************/
private:
const char* mTypeName;
};
/**
\brief Preprocessor Macro to simplify adapter creation.
Note: that the allocator used for creation needs to match with the one used in PX_DELETE_SERIALIZER_ADAPTER.
*/
#define PX_NEW_SERIALIZER_ADAPTER(x) \
*new( PxGetFoundation().getAllocatorCallback().allocate(sizeof(PxSerializerDefaultAdapter<x>), \
"PxSerializerDefaultAdapter", __FILE__, __LINE__ )) PxSerializerDefaultAdapter<x>(#x)
/**
\brief Preprocessor Macro to simplify adapter deletion.
*/
#define PX_DELETE_SERIALIZER_ADAPTER(x) \
{ PxSerializer* s = x; if (s) { s->~PxSerializer(); PxGetFoundation().getAllocatorCallback().deallocate(s); } }
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,73 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_STRING_TABLE_H
#define PX_STRING_TABLE_H
#include "foundation/PxPreprocessor.h"
/** \addtogroup physics
@{
*/
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
* \brief a table to manage strings. Strings allocated through this object are expected to be owned by this object.
*/
class PxStringTable
{
protected:
virtual ~PxStringTable(){}
public:
/**
* \brief Allocate a new string.
*
* \param[in] inSrc Source string, null terminated or null.
*
* \return *Always* a valid null terminated string. "" is returned if "" or null is passed in.
*/
virtual const char* allocateStr( const char* inSrc ) = 0;
/**
* Release the string table and all the strings associated with it.
*/
virtual void release() = 0;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,108 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_SCALE_H
#define PX_SCALE_H
/** \addtogroup common
@{
*/
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxPhysics;
/**
\brief Class to define the scale at which simulation runs. Most simulation tolerances are
calculated in terms of the values here.
\note if you change the simulation scale, you will probablly also wish to change the scene's
default value of gravity, and stable simulation will probably require changes to the scene's
bounceThreshold also.
*/
class PxTolerancesScale
{
public:
/** brief
The approximate size of objects in the simulation.
For simulating roughly human-sized in metric units, 1 is a good choice.
If simulation is done in centimetres, use 100 instead. This is used to
estimate certain length-related tolerances.
*/
PxReal length;
/** brief
The typical magnitude of velocities of objects in simulation. This is used to estimate
whether a contact should be treated as bouncing or resting based on its impact velocity,
and a kinetic energy threshold below which the simulation may put objects to sleep.
For normal physical environments, a good choice is the approximate speed of an object falling
under gravity for one second.
*/
PxReal speed;
/**
\brief constructor sets to default
*/
PX_INLINE PxTolerancesScale();
/**
\brief Returns true if the descriptor is valid.
\return true if the current settings are valid (returns always true).
*/
PX_INLINE bool isValid() const;
};
PX_INLINE PxTolerancesScale::PxTolerancesScale():
length(1.0f),
speed(10.0f)
{
}
PX_INLINE bool PxTolerancesScale::isValid() const
{
return length>0.0f;
}
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,128 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_COMMON_PX_TYPEINFO
#define PX_PHYSICS_COMMON_PX_TYPEINFO
/** \addtogroup common
@{
*/
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief an enumeration of concrete classes inheriting from PxBase
Enumeration space is reserved for future PhysX core types, PhysXExtensions,
PhysXVehicle and Custom application types.
@see PxBase, PxTypeInfo
*/
struct PxConcreteType
{
enum Enum
{
eUNDEFINED,
eHEIGHTFIELD,
eCONVEX_MESH,
eTRIANGLE_MESH_BVH33,
eTRIANGLE_MESH_BVH34,
eRIGID_DYNAMIC,
eRIGID_STATIC,
eSHAPE,
eMATERIAL,
eCONSTRAINT,
eAGGREGATE,
eARTICULATION,
eARTICULATION_REDUCED_COORDINATE,
eARTICULATION_LINK,
eARTICULATION_JOINT,
eARTICULATION_JOINT_REDUCED_COORDINATE,
ePRUNING_STRUCTURE,
eBVH_STRUCTURE,
ePHYSX_CORE_COUNT,
eFIRST_PHYSX_EXTENSION = 256,
eFIRST_VEHICLE_EXTENSION = 512,
eFIRST_USER_EXTENSION = 1024
};
};
/**
\brief a structure containing per-type information for types inheriting from PxBase
@see PxBase, PxConcreteType
*/
template<typename T> struct PxTypeInfo {};
#define PX_DEFINE_TYPEINFO(_name, _fastType) \
class _name; \
template <> struct PxTypeInfo<_name> { static const char* name() { return #_name; } enum { eFastTypeId = _fastType }; };
/* the semantics of the fastType are as follows: an object A can be cast to a type B if B's fastType is defined, and A has the same fastType.
* This implies that B has no concrete subclasses or superclasses.
*/
PX_DEFINE_TYPEINFO(PxBase, PxConcreteType::eUNDEFINED)
PX_DEFINE_TYPEINFO(PxMaterial, PxConcreteType::eMATERIAL)
PX_DEFINE_TYPEINFO(PxConvexMesh, PxConcreteType::eCONVEX_MESH)
PX_DEFINE_TYPEINFO(PxTriangleMesh, PxConcreteType::eUNDEFINED)
PX_DEFINE_TYPEINFO(PxBVH33TriangleMesh, PxConcreteType::eTRIANGLE_MESH_BVH33)
PX_DEFINE_TYPEINFO(PxBVH34TriangleMesh, PxConcreteType::eTRIANGLE_MESH_BVH34)
PX_DEFINE_TYPEINFO(PxHeightField, PxConcreteType::eHEIGHTFIELD)
PX_DEFINE_TYPEINFO(PxActor, PxConcreteType::eUNDEFINED)
PX_DEFINE_TYPEINFO(PxRigidActor, PxConcreteType::eUNDEFINED)
PX_DEFINE_TYPEINFO(PxRigidBody, PxConcreteType::eUNDEFINED)
PX_DEFINE_TYPEINFO(PxRigidDynamic, PxConcreteType::eRIGID_DYNAMIC)
PX_DEFINE_TYPEINFO(PxRigidStatic, PxConcreteType::eRIGID_STATIC)
PX_DEFINE_TYPEINFO(PxArticulationLink, PxConcreteType::eARTICULATION_LINK)
PX_DEFINE_TYPEINFO(PxArticulationJoint, PxConcreteType::eARTICULATION_JOINT)
PX_DEFINE_TYPEINFO(PxArticulationJointReducedCoordinate, PxConcreteType::eARTICULATION_JOINT_REDUCED_COORDINATE)
PX_DEFINE_TYPEINFO(PxArticulation, PxConcreteType::eARTICULATION)
PX_DEFINE_TYPEINFO(PxArticulationReducedCoordinate, PxConcreteType::eARTICULATION_REDUCED_COORDINATE)
PX_DEFINE_TYPEINFO(PxAggregate, PxConcreteType::eAGGREGATE)
PX_DEFINE_TYPEINFO(PxConstraint, PxConcreteType::eCONSTRAINT)
PX_DEFINE_TYPEINFO(PxShape, PxConcreteType::eSHAPE)
PX_DEFINE_TYPEINFO(PxPruningStructure, PxConcreteType::ePRUNING_STRUCTURE)
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,102 @@
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of NVIDIA CORPORATION nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2019 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
#ifndef PX_PHYSICS_DELAY_LOAD_HOOK
#define PX_PHYSICS_DELAY_LOAD_HOOK
#include "foundation/PxPreprocessor.h"
#include "common/PxPhysXCommonConfig.h"
/** \addtogroup foundation
@{
*/
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief PxDelayLoadHook
This is a helper class for delay loading the PhysXCommon dll and PhysXFoundation dll.
If a PhysXCommon dll or PhysXFoundation dll with a non-default file name needs to be loaded,
PxDelayLoadHook can be sub-classed to provide the custom filenames.
Once the names are set, the instance must be set for use by PhysX.dll using PxSetPhysXDelayLoadHook(),
PhysXCooking.dll using PxSetPhysXCookingDelayLoadHook() or by PhysXCommon.dll using PxSetPhysXCommonDelayLoadHook().
@see PxSetPhysXDelayLoadHook(), PxSetPhysXCookingDelayLoadHook(), PxSetPhysXCommonDelayLoadHook()
*/
class PxDelayLoadHook
{
public:
PxDelayLoadHook() {}
virtual ~PxDelayLoadHook() {}
virtual const char* getPhysXFoundationDllName() const = 0;
virtual const char* getPhysXCommonDllName() const = 0;
protected:
private:
};
/**
\brief Sets delay load hook instance for PhysX dll.
\param[in] hook Delay load hook.
@see PxDelayLoadHook
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PX_CALL_CONV PxSetPhysXDelayLoadHook(const physx::PxDelayLoadHook* hook);
/**
\brief Sets delay load hook instance for PhysXCooking dll.
\param[in] hook Delay load hook.
@see PxDelayLoadHook
*/
PX_C_EXPORT PX_PHYSX_CORE_API void PX_CALL_CONV PxSetPhysXCookingDelayLoadHook(const physx::PxDelayLoadHook* hook);
/**
\brief Sets delay load hook instance for PhysXCommon dll.
\param[in] hook Delay load hook.
@see PxDelayLoadHook
*/
PX_C_EXPORT PX_PHYSX_COMMON_API void PX_CALL_CONV PxSetPhysXCommonDelayLoadHook(const physx::PxDelayLoadHook* hook);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif