RavEngine
Loading...
Searching...
No Matches
NpActor.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef NP_ACTOR_H
30#define NP_ACTOR_H
31
32#include "NpConnector.h"
33#include "NpBase.h"
34
35namespace physx
36{
37 class NpShapeManager;
38 class NpAggregate;
39 class NpScene;
40 class NpShape;
41
42 Sc::BodyCore* getBodyCore(PxRigidActor* actor);
43
44class NpActor : public NpBase
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
53public:
54// PX_SERIALIZATION
55 NpActor(const PxEMPTY) : NpBase(PxEmpty) {}
56 void exportExtraData(PxSerializationContext& stream);
57 void importExtraData(PxDeserializationContext& context);
58 void resolveReferences(PxDeserializationContext& context);
59 static void getBinaryMetaData(PxOutputStream& stream);
60//~PX_SERIALIZATION
61 NpActor(NpType::Enum type);
62
63 void removeConstraints(PxRigidActor& owner);
64 void removeFromAggregate(PxActor& owner);
65
66 NpAggregate* getNpAggregate(PxU32& index) const;
67 void setAggregate(NpAggregate* np, PxActor& owner);
68 PxAggregate* getAggregate() const;
69 void scSetDominanceGroup(PxDominanceGroup v);
70 void scSetOwnerClient(PxClientID inId);
71 void removeConstraintsFromScene();
72 PX_FORCE_INLINE void addConstraintsToScene() // inline the fast path for addActors()
73 {
74 if(mConnectorArray)
75 addConstraintsToSceneInternal();
76 }
77
78 PxU32 findConnector(NpConnectorType::Enum type, PxBase* object) const;
79 void addConnector(NpConnectorType::Enum type, PxBase* object, const char* errMsg);
80 void removeConnector(PxActor& owner, NpConnectorType::Enum type, PxBase* object, const char* errorMsg);
81 PxU32 getNbConnectors(NpConnectorType::Enum type) const;
82
83 static NpShapeManager* getShapeManager_(PxRigidActor& actor); // bit misplaced here, but we don't want a separate subclass just for this
84 static const NpShapeManager* getShapeManager_(const PxRigidActor& actor); // bit misplaced here, but we don't want a separate subclass just for this
85
86 static NpActor& getFromPxActor(PxActor& actor) { return *PxPointerOffset<NpActor*>(&actor, ptrdiff_t(sOffsets.pxActorToNpActor[actor.getConcreteType()])); }
87 static const NpActor& getFromPxActor(const PxActor& actor) { return *PxPointerOffset<const NpActor*>(&actor, ptrdiff_t(sOffsets.pxActorToNpActor[actor.getConcreteType()])); }
88
89 const PxActor* getPxActor() const;
90
91 static NpScene* getNpSceneFromActor(const PxActor& actor)
92 {
93 return getFromPxActor(actor).getNpScene();
94 }
95
96 PX_FORCE_INLINE NpConnectorIterator getConnectorIterator(NpConnectorType::Enum type)
97 {
98 if (mConnectorArray)
99 return NpConnectorIterator(&mConnectorArray->front(), mConnectorArray->size(), type);
100 else
101 return NpConnectorIterator(NULL, 0, type);
102 }
103
104 static void onActorRelease(PxActor* actor);
105
106 template<typename T> PxU32 getConnectors(NpConnectorType::Enum type, T** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const
107 {
108 PxU32 nbConnectors = 0;
109 if(mConnectorArray)
110 {
111 for(PxU32 i=0; i<mConnectorArray->size(); i++)
112 {
113 NpConnector& c = (*mConnectorArray)[i];
114 if(c.mType == type && nbConnectors < bufferSize && i>=startIndex)
115 userBuffer[nbConnectors++] = static_cast<T*>(c.mObject);
116 }
117 }
118 return nbConnectors;
119 }
120
121 PX_INLINE PxActorFlags getActorFlags() const { return getActorCore().getActorFlags(); }
122 PX_INLINE PxDominanceGroup getDominanceGroup() const { return getActorCore().getDominanceGroup(); }
123 PX_INLINE PxClientID getOwnerClient() const { return getActorCore().getOwnerClient(); }
124
125 PX_INLINE void scSetActorFlags(PxActorFlags v)
126 {
127 PX_ASSERT(!isAPIWriteForbidden());
128
129 // PT: TODO: move this check out of here, they should be done in Np!
130#if PX_CHECKED
131 const PxActorFlags aFlags = getActorFlags();
132 const NpType::Enum npType = getNpType();
134 (npType != NpType::eBODY) && (npType != NpType::eRIGID_STATIC))
135 {
136 PxGetFoundation().error(PxErrorCode::eINVALID_PARAMETER, __FILE__, __LINE__,
137 "PxActor::setActorFlag: PxActorFlag::eDISABLE_SIMULATION is only supported by PxRigidDynamic and PxRigidStatic objects.");
138 }
139#endif
140 getActorCore().setActorFlags(v);
141 UPDATE_PVD_PROPERTY
142 }
143
144
145 PX_FORCE_INLINE const Sc::ActorCore& getActorCore() const
146 {
147 return *reinterpret_cast<const Sc::ActorCore*>(size_t(this) + sNpOffsets.npToSc[getNpType()]);
148 }
149 PX_FORCE_INLINE Sc::ActorCore& getActorCore()
150 {
151 return *reinterpret_cast<Sc::ActorCore*>(size_t(this) + sNpOffsets.npToSc[getNpType()]);
152 }
153
154 PX_INLINE const Sc::RigidCore& getScRigidCore() const
155 {
156 return static_cast<const Sc::RigidCore&>(getActorCore());
157 }
158 PX_INLINE Sc::RigidCore& getScRigidCore()
159 {
160 return static_cast<Sc::RigidCore&>(getActorCore());
161 }
162
163 PX_FORCE_INLINE void scSwitchToNoSim()
164 {
165 NpScene* scene = getNpScene();
166
167 if(scene && (!scene->isAPIWriteForbidden()))
168 scene->scSwitchRigidToNoSim(*this);
169 }
170
171 PX_FORCE_INLINE void scSwitchFromNoSim()
172 {
173 NpScene* scene = getNpScene();
174
175 if(scene && (!scene->isAPIWriteForbidden()))
176 scene->scSwitchRigidFromNoSim(*this);
177 }
178protected:
179 ~NpActor() {}
180 const char* mName;
181 // Lazy-create array for connector objects like constraints, observers, ...
182 // Most actors have no such objects, so we bias this class accordingly:
183 NpConnectorArray* mConnectorArray;
184private:
185 void addConstraintsToSceneInternal();
186 void removeConnector(PxActor& owner, PxU32 index);
187 struct Offsets
188 {
189 size_t pxActorToNpActor[PxConcreteType::ePHYSX_CORE_COUNT];
190 Offsets();
191 };
192public:
193 static const Offsets sOffsets;
194
196 {
197 size_t npToSc[NpType::eTYPE_COUNT];
198 NpOffsets();
199 };
200 static const NpOffsets sNpOffsets;
201};
202
203}
204
205#endif
Definition base.h:1940
Definition NpActor.h:45
Definition NpAggregate.h:40
Definition NpBase.h:167
Definition NpConnector.h:112
Definition NpConnector.h:86
Definition NpConnector.h:54
Definition NpScene.h:130
Definition NpShapeManager.h:61
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
Class to aggregate actors into a single broad-phase entry.
Definition PxAggregate.h:98
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
PX_FORCE_INLINE const T & front() const
Definition PxArray.h:207
Base class for objects that can be members of a PxCollection.
Definition PxBase.h:73
Binary deserialization context class.
Definition PxSerialFramework.h:174
Output stream class for I/O.
Definition PxIO.h:114
PxRigidActor represents a base class shared between dynamic and static rigid bodies in the physics SD...
Definition PxRigidActor.h:53
Binary serialization context class.
Definition PxSerialFramework.h:99
Definition ScActorCore.h:48
Definition ScRigidCore.h:61
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
PX_C_EXPORT PX_FOUNDATION_API physx::PxFoundation &PX_CALL_CONV PxGetFoundation()
Retrieves the Foundation SDK after it has been created.
Definition FdFoundation.cpp:279
#define PX_INLINE
Definition PxPreprocessor.h:320
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU8 PxClientID
An ID to identify different clients for multiclient support.
Definition PxClient.h:44
PxU8 PxDominanceGroup
Group index which allows to specify 1- or 2-way interaction.
Definition PxActor.h:56
PxEMPTY
Definition Px.h:87
Definition NpActor.h:196
@ eDISABLE_SIMULATION
Disables simulation for the actor.
Definition PxActor.h:102
@ eINVALID_PARAMETER
method called with invalid parameter(s)
Definition PxErrors.h:62