diff options
| author | sschirm <[email protected]> | 2016-12-23 14:20:36 +0100 |
|---|---|---|
| committer | sschirm <[email protected]> | 2016-12-23 14:56:17 +0100 |
| commit | ef6937e69e8ee3f409cf9d460d5ad300a65d5924 (patch) | |
| tree | 710426e8daa605551ce3f34b581897011101c30f /PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h | |
| parent | Initial commit: (diff) | |
| download | physx-3.4-ef6937e69e8ee3f409cf9d460d5ad300a65d5924.tar.xz physx-3.4-ef6937e69e8ee3f409cf9d460d5ad300a65d5924.zip | |
PhysX 3.4 / APEX 1.4 release candidate @21506124
Diffstat (limited to 'PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h')
| -rw-r--r-- | PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h | 102 |
1 files changed, 33 insertions, 69 deletions
diff --git a/PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h b/PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h index 697017bf..b4440dbe 100644 --- a/PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h +++ b/PhysX_3.4/Source/PhysX/src/buffering/ScbShape.h @@ -27,7 +27,6 @@ // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. - #ifndef PX_PHYSICS_SCB_SHAPE #define PX_PHYSICS_SCB_SHAPE @@ -47,13 +46,10 @@ namespace physx { - #if PX_SUPPORT_PVD - #define UPDATE_PVD_MATERIALS() \ - if(getControlState() == ControlState::eIN_SCENE) \ - { \ - getScbScene()->getScenePvdClient().updateMaterials(this); \ - } + #define UPDATE_PVD_MATERIALS() \ + if(getControlState() == ControlState::eIN_SCENE) \ + getScbScene()->getScenePvdClient().updateMaterials(this); #else #define UPDATE_PVD_MATERIALS() {} #endif @@ -71,6 +67,8 @@ struct ShapeBuffer ShapeBuffer() : materialBufferIndex(0), materialCount(0) {} + // PT: I think we start with "2" (instead of 0) because the two first bits are reserved + // below, for geometry & materials. SCB_REGULAR_ATTRIBUTE_ALIGNED(2, PxTransform, Shape2Actor, 16) SCB_REGULAR_ATTRIBUTE(3, PxFilterData, SimulationFilterData) SCB_REGULAR_ATTRIBUTE(4, PxReal, ContactOffset) @@ -86,12 +84,11 @@ struct ShapeBuffer }; PxU16 materialCount; - enum + enum { - BF_Geometry = 1<<0, - BF_Material = 1<<1 + BF_Geometry = 1<<0, + BF_Material = 1<<1 }; - }; class Shape : public Base @@ -135,7 +132,7 @@ public: PX_INLINE void setSimulationFilterData(const PxFilterData& v) { write<Buf::BF_SimulationFilterData>(v); } PX_INLINE PxReal getContactOffset() const { return read<Buf::BF_ContactOffset>(); } - PX_INLINE void setContactOffset(PxReal v); + PX_INLINE void setContactOffset(PxReal v) { write<Buf::BF_ContactOffset>(v); } PX_INLINE PxReal getRestOffset() const { return read<Buf::BF_RestOffset>(); } PX_INLINE void setRestOffset(PxReal v) { write<Buf::BF_RestOffset>(v); } @@ -143,13 +140,11 @@ public: PX_INLINE PxShapeFlags getFlags() const { return read<Buf::BF_Flags>(); } PX_INLINE void setFlags(PxShapeFlags v) { write<Buf::BF_Flags>(v); } - //--------------------------------------------------------------------------------- // Data synchronization //--------------------------------------------------------------------------------- void syncState(); - //--------------------------------------------------------------------------------- // Miscellaneous //--------------------------------------------------------------------------------- @@ -158,15 +153,12 @@ public: PX_FORCE_INLINE Sc::ShapeCore& getScShape() { return mShape; } // Only use if you know what you're doing! PX_FORCE_INLINE const Sc::ShapeCore& getScShape() const { return mShape; } - PX_FORCE_INLINE bool isExclusive() const { return getScbType() == ScbType::SHAPE_EXCLUSIVE; } + PX_FORCE_INLINE bool isExclusive() const { return getScbType() == ScbType::eSHAPE_EXCLUSIVE; } PX_FORCE_INLINE void setControlStateIfExclusive(Scene* s, ControlState::Enum cs); // for exclusive shapes template<bool sync> PX_FORCE_INLINE void checkUpdateOnRemove(Scene* s); - static size_t getScOffset() - { - return reinterpret_cast<size_t>(&reinterpret_cast<Shape*>(0)->mShape); - } + static size_t getScOffset() { return reinterpret_cast<size_t>(&reinterpret_cast<Shape*>(0)->mShape); } private: bool setMaterialsHelper(PxMaterial* const* materials, PxU16 materialCount); @@ -176,10 +168,9 @@ private: PX_FORCE_INLINE const Scb::ShapeBuffer* getBufferedData() const { return reinterpret_cast<const Scb::ShapeBuffer*>(getStream()); } PX_FORCE_INLINE Scb::ShapeBuffer* getBufferedData() { return reinterpret_cast<Scb::ShapeBuffer*>(getStream()); } - PX_FORCE_INLINE const PxU16* getMaterialBuffer(const Scb::Scene& scene, const Scb::ShapeBuffer& sb) const { - if (sb.materialCount == 1) + if(sb.materialCount == 1) return &sb.materialIndex; else return scene.getShapeMaterialBuffer(sb.materialBufferIndex); @@ -194,7 +185,7 @@ private: template<typename Fns> static PX_FORCE_INLINE void write(Shape& base, Core& core, typename Fns::Arg v) { - if (!base.isBuffering()) + if(!base.isBuffering()) { PxShapeFlags oldShapeFlags = core.getFlags(); Fns::setCore(core, v); @@ -214,16 +205,14 @@ private: Fns::setBuffered(*reinterpret_cast<Buf*>(base.getStream()), v); base.markUpdated(Fns::flag); } - } - + } }; + template<PxU32 f> PX_FORCE_INLINE typename Buf::Fns<f,0>::Arg read() const { return Access::read<Buf::Fns<f,0> >(*this, mShape); } template<PxU32 f> PX_FORCE_INLINE void write(typename Buf::Fns<f,0>::Arg v) { Access::write<Buf::Fns<f,0> >(*this, mShape, v); } template<PxU32 f> PX_FORCE_INLINE void flush(const Buf& buf) { Access::flush<Buf::Fns<f,0> >(*this, mShape, buf); } - }; - PX_INLINE Shape::Shape(const PxGeometry& geometry, PxShapeFlags shapeFlags, const PxU16* materialIndices, @@ -242,13 +231,12 @@ PX_INLINE Shape::Shape(const PxGeometry& geometry, PX_COMPILE_TIME_ASSERT(PxU32(ShapeBuffer::BF_Flags) == PxU32(Sc::ShapeChangeNotifyFlag::eFLAGS)); PX_COMPILE_TIME_ASSERT(PxU32(ShapeBuffer::BF_Geometry) == PxU32(Sc::ShapeChangeNotifyFlag::eGEOMETRY)); - if (isExclusive) - setScbType(ScbType::SHAPE_EXCLUSIVE); + if(isExclusive) + setScbType(ScbType::eSHAPE_EXCLUSIVE); else - setScbType(ScbType::SHAPE_SHARED); + setScbType(ScbType::eSHAPE_SHARED); } - PX_INLINE PxGeometryType::Enum Shape::getGeometryType() const { return mShape.getGeometryType(); @@ -256,7 +244,7 @@ PX_INLINE PxGeometryType::Enum Shape::getGeometryType() const PX_INLINE const PxGeometry& Shape::getGeometry() const { - if (isBuffered(Buf::BF_Geometry)) + if(isBuffered(Buf::BF_Geometry)) return getBufferedData()->geometry.getGeometry(); else return mShape.getGeometry(); @@ -264,13 +252,12 @@ PX_INLINE const PxGeometry& Shape::getGeometry() const PX_INLINE const Gu::GeometryUnion& Shape::getGeometryUnion() const { - if (isBuffered(Buf::BF_Geometry)) + if(isBuffered(Buf::BF_Geometry)) return getBufferedData()->geometry; else return mShape.getGeometryUnion(); } - PX_INLINE Scb::ShapeBuffer* Shape::setGeometry(const PxGeometry& geom) { Scb::ShapeBuffer* shapeBuffer = NULL; @@ -278,17 +265,13 @@ PX_INLINE Scb::ShapeBuffer* Shape::setGeometry(const PxGeometry& geom) { Scb::Scene* sc = getScbScene(); - if (sc) - { + if(sc) sc->getScScene().unregisterShapeFromNphase(mShape); - } mShape.setGeometry(geom); - if (sc) - { + if(sc) sc->getScScene().registerShapeInNphase(mShape); - } Sc::RigidCore* rigidCore = NpShapeGetScRigidObjectFromScbSLOW(*this); if(rigidCore) @@ -297,9 +280,7 @@ PX_INLINE Scb::ShapeBuffer* Shape::setGeometry(const PxGeometry& geom) #if PX_SUPPORT_PVD Scb::Scene* scbScene = getScbSceneForAPI(); if(scbScene) - { - scbScene->getScenePvdClient().releaseAndRecreateGeometry( this ); - } + scbScene->getScenePvdClient().releaseAndRecreateGeometry(this); #endif } else @@ -312,22 +293,20 @@ PX_INLINE Scb::ShapeBuffer* Shape::setGeometry(const PxGeometry& geom) return shapeBuffer; } - PX_INLINE PxU16 Shape::getNbMaterials() const { - if (isBuffered(Buf::BF_Material)) + if(isBuffered(Buf::BF_Material)) return getBufferedData()->materialCount; else return mShape.getNbMaterialIndices(); } - PX_INLINE PxMaterial* Shape::getMaterial(PxU32 index) const { PX_ASSERT(index < getNbMaterials()); NpMaterialManager& matManager = NpPhysics::getInstance().getMaterialManager(); - if (isBuffered(Buf::BF_Material)) + if(isBuffered(Buf::BF_Material)) { const PxU16* materialIndices = getMaterialBuffer(*getScbScene(), *getBufferedData()); return matManager.getMaterial(materialIndices[index]); @@ -339,13 +318,12 @@ PX_INLINE PxMaterial* Shape::getMaterial(PxU32 index) const } } - PX_INLINE PxU32 Shape::getMaterials(PxMaterial** buffer, PxU32 bufferSize, PxU32 startIndex) const { const PxU16* materialIndices; PxU32 matCount; NpMaterialManager& matManager = NpPhysics::getInstance().getMaterialManager(); - if (isBuffered(Buf::BF_Material)) + if(isBuffered(Buf::BF_Material)) { // IMPORTANT: // As long as the material pointers get copied to a user buffer, this works fine. @@ -375,10 +353,9 @@ PX_INLINE PxU32 Shape::getMaterials(PxMaterial** buffer, PxU32 bufferSize, PxU32 return writeCount; } - PX_INLINE bool Shape::setMaterials(PxMaterial* const* materials, PxU16 materialCount) { - if (!isBuffering()) + if(!isBuffering()) { bool ret = setMaterialsHelper(materials, materialCount); UPDATE_PVD_MATERIALS() @@ -389,7 +366,7 @@ PX_INLINE bool Shape::setMaterials(PxMaterial* const* materials, PxU16 materialC Scb::ShapeBuffer* PX_RESTRICT bufferedData = getBufferedData(); PxU16* materialIndices; - if (materialCount == 1) + if(materialCount == 1) materialIndices = &bufferedData->materialIndex; else { @@ -407,44 +384,31 @@ PX_INLINE bool Shape::setMaterials(PxMaterial* const* materials, PxU16 materialC } } -PX_INLINE void Shape::setContactOffset(PxReal v) -{ - write<Buf::BF_ContactOffset>(v); -} - - PX_FORCE_INLINE void Shape::setControlStateIfExclusive(Scene* s, ControlState::Enum cs) { - if (isExclusive()) + if(isExclusive()) { setControlState(cs); setScbScene(s); } } - template<bool sync> PX_FORCE_INLINE void Shape::checkUpdateOnRemove(Scene* s) { // special code to cover the case where a shape has a pending update and gets released. The following operations have to be done // before the ref-counter of the shape gets decremented because that could cause the shape to be deleted in which case it must not // be in the pending update list any longer. - if (getControlFlags() & Scb::ControlFlag::eIS_UPDATED) + if(getControlFlags() & Scb::ControlFlag::eIS_UPDATED) { - if (sync) + if(sync) syncState(); s->removeShapeFromPendingUpdateList(*this); + + resetControlFlag(ControlFlag::eIS_UPDATED); } } - -//-------------------------------------------------------------- -// -// Data synchronization -// -//-------------------------------------------------------------- - - } // namespace Scb } |