1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | |
31 | #ifndef PX_PHYSICS_NP_ACTOR |
32 | #define PX_PHYSICS_NP_ACTOR |
33 | |
34 | #include "NpConnector.h" |
35 | #include "ScbActor.h" // DM: without this inclusion PVD-diabled android build fails, lacking Scb::Actor definition |
36 | |
37 | namespace physx |
38 | { |
39 | class NpShapeManager; |
40 | class NpAggregate; |
41 | class NpScene; |
42 | class NpShape; |
43 | |
44 | class NpActor |
45 | { |
46 | //= ATTENTION! ===================================================================================== |
47 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
48 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
49 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
50 | // accordingly. |
51 | //================================================================================================== |
52 | |
53 | // We sometimes pass in the PxActor here even though it's always a base class |
54 | // of the objects which inherit from this class too. But passing |
55 | // context to functions which need it allows this to be purely a mixin containing shared |
56 | // utility code rather than an abstract base class. |
57 | |
58 | public: |
59 | // PX_SERIALIZATION |
60 | NpActor(const PxEMPTY) {} |
61 | |
62 | void (PxSerializationContext& stream); |
63 | void (PxDeserializationContext& context); |
64 | void resolveReferences(PxDeserializationContext& context); |
65 | static void getBinaryMetaData(PxOutputStream& stream); |
66 | //~PX_SERIALIZATION |
67 | NpActor(const char* name); |
68 | |
69 | void releaseConstraints(PxRigidActor& owner); |
70 | void release(PxActor& owner); |
71 | |
72 | NpAggregate* getNpAggregate(PxU32& index) const; |
73 | void setAggregate(NpAggregate* np, PxActor& owner); |
74 | PxAggregate* getAggregate() const; |
75 | |
76 | void removeConstraintsFromScene(); |
77 | PX_FORCE_INLINE void addConstraintsToScene() // inline the fast path for addActors() |
78 | { |
79 | if(mConnectorArray) |
80 | addConstraintsToSceneInternal(); |
81 | } |
82 | |
83 | PX_FORCE_INLINE NpConnectorArray** getConnectorArrayAddress() { return &mConnectorArray;} |
84 | PxU32 findConnector(NpConnectorType::Enum type, PxBase* object) const; |
85 | void addConnector(NpConnectorType::Enum type, PxBase* object, const char* errMsg); |
86 | void removeConnector(PxActor& owner, NpConnectorType::Enum type, PxBase* object, const char* errorMsg); |
87 | PxU32 getNbConnectors(NpConnectorType::Enum type) const; |
88 | |
89 | static NpShapeManager* getShapeManager(PxRigidActor& actor); // bit misplaced here, but we don't want a separate subclass just for this |
90 | static const NpShapeManager* getShapeManager(const PxRigidActor& actor); // bit misplaced here, but we don't want a separate subclass just for this |
91 | |
92 | static void getGlobalPose(PxTransform& globalPose, const NpShape& shape, const PxRigidActor& actor); |
93 | static void getGlobalPose(PxTransform& globalPose, const Scb::Shape& scbShape, const Scb::Actor& scbActor); |
94 | |
95 | static NpActor& getFromPxActor(PxActor& actor) { return *Ps::pointerOffset<NpActor*>(p: &actor, offset: ptrdiff_t(sOffsets.pxActorToNpActor[actor.getConcreteType()])); } |
96 | static const NpActor& getFromPxActor(const PxActor& actor) { return *Ps::pointerOffset<const NpActor*>(p: &actor, offset: ptrdiff_t(sOffsets.pxActorToNpActor[actor.getConcreteType()])); } |
97 | |
98 | static Scb::Actor& getScbFromPxActor(PxActor& actor) { return *Ps::pointerOffset<Scb::Actor*>(p: &actor, offset: ptrdiff_t(sOffsets.pxActorToScbActor[actor.getConcreteType()])); } |
99 | static const Scb::Actor& getScbFromPxActor(const PxActor& actor) { return *Ps::pointerOffset<const Scb::Actor*>(p: &actor, offset: ptrdiff_t(sOffsets.pxActorToScbActor[actor.getConcreteType()])); } |
100 | |
101 | static NpScene* getAPIScene(const PxActor& actor); // the scene the user thinks the actor is in |
102 | static NpScene* getOwnerScene(const PxActor& actor); // the scene the user thinks the actor is in, or from which the actor is pending removal |
103 | |
104 | PX_FORCE_INLINE NpConnectorIterator getConnectorIterator(NpConnectorType::Enum type) |
105 | { |
106 | if (mConnectorArray) |
107 | return NpConnectorIterator(&mConnectorArray->front(), mConnectorArray->size(), type); |
108 | else |
109 | return NpConnectorIterator(NULL, 0, type); |
110 | } |
111 | |
112 | // a couple of methods that sever include dependencies in NpActor.h |
113 | |
114 | static void onActorRelease(PxActor* actor); |
115 | |
116 | |
117 | |
118 | template<typename T> |
119 | PxU32 getConnectors(NpConnectorType::Enum type, T** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const |
120 | { |
121 | PxU32 nbConnectors = 0; |
122 | PxU32 virtualIndex = 0; |
123 | |
124 | if(mConnectorArray) |
125 | { |
126 | for(PxU32 i=0; i < mConnectorArray->size(); i++) |
127 | { |
128 | NpConnector& c = (*mConnectorArray)[i]; |
129 | if (c.mType == type && nbConnectors < bufferSize) |
130 | { |
131 | if (virtualIndex++ >= startIndex) |
132 | { |
133 | userBuffer[nbConnectors] = static_cast<T*>(c.mObject); |
134 | nbConnectors++; |
135 | } |
136 | } |
137 | } |
138 | } |
139 | |
140 | return nbConnectors; |
141 | } |
142 | |
143 | protected: |
144 | ~NpActor(); |
145 | const char* mName; |
146 | // Lazy-create array for connector objects like constraints, observers, ... |
147 | // Most actors have no such objects, so we bias this class accordingly: |
148 | NpConnectorArray* mConnectorArray; |
149 | |
150 | private: |
151 | void addConstraintsToSceneInternal(); |
152 | void removeConnector(PxActor& owner, PxU32 index); |
153 | struct Offsets |
154 | { |
155 | size_t pxActorToNpActor[PxConcreteType::ePHYSX_CORE_COUNT]; |
156 | size_t pxActorToScbActor[PxConcreteType::ePHYSX_CORE_COUNT]; |
157 | Offsets(); |
158 | }; |
159 | public: |
160 | static const Offsets sOffsets; |
161 | }; |
162 | |
163 | |
164 | |
165 | } |
166 | |
167 | #endif |
168 | |