RavEngine
Loading...
Searching...
No Matches
NpActorTemplate.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_TEMPLATE_H
30#define NP_ACTOR_TEMPLATE_H
31
32#include "NpCheck.h"
33#include "NpActor.h"
34#include "NpScene.h"
35
36#include "omnipvd/OmniPvdPxSampler.h"
37
38namespace physx
39{
40
41// PT: only API (virtual) functions should be implemented here. Other shared non-virtual functions should go to NpActor.
42
52template<class APIClass>
53class NpActorTemplate : public APIClass, public NpActor
54{
55//= ATTENTION! =====================================================================================
56// Changing the data layout of this class breaks the binary serialization format. See comments for
57// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
58// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
59// accordingly.
60//==================================================================================================
61 PX_NOCOPY(NpActorTemplate)
62public:
63// PX_SERIALIZATION
64 NpActorTemplate(PxBaseFlags baseFlags) : APIClass(baseFlags), NpActor(PxEmpty) {}
65
66 virtual void exportExtraData(PxSerializationContext& context) { NpActor::exportExtraData(context); }
67 virtual void importExtraData(PxDeserializationContext& context) { NpActor::importExtraData(context); }
68 virtual void resolveReferences(PxDeserializationContext& context) { NpActor::resolveReferences(context); }
69//~PX_SERIALIZATION
70
71 NpActorTemplate(PxType concreteType, PxBaseFlags baseFlags, NpType::Enum type);
72 virtual ~NpActorTemplate();
73
74 // The rule is: If an API method is used somewhere in here, it has to be redeclared, else GCC whines
75
76 // PxActor
77 virtual void release() = 0;
78 virtual PxActorType::Enum getType() const = 0;
79 virtual PxScene* getScene() const PX_OVERRIDE;
80 virtual void setName(const char*) PX_OVERRIDE;
81 virtual const char* getName() const PX_OVERRIDE;
82 virtual PxBounds3 getWorldBounds(float inflation=1.01f) const = 0;
83 virtual void setActorFlag(PxActorFlag::Enum flag, bool value) PX_OVERRIDE;
84 virtual void setActorFlags(PxActorFlags inFlags) PX_OVERRIDE;
85 virtual PxActorFlags getActorFlags() const PX_OVERRIDE;
86 virtual void setDominanceGroup(PxDominanceGroup dominanceGroup) PX_OVERRIDE;
87 virtual PxDominanceGroup getDominanceGroup() const PX_OVERRIDE;
88 virtual void setOwnerClient( PxClientID inClient ) PX_OVERRIDE;
89 virtual PxClientID getOwnerClient() const PX_OVERRIDE;
90 virtual PxAggregate* getAggregate() const PX_OVERRIDE { return NpActor::getAggregate(); }
91 //~PxActor
92
93protected:
94 PX_FORCE_INLINE void setActorFlagInternal(PxActorFlag::Enum flag, bool value);
95 PX_FORCE_INLINE void setActorFlagsInternal(PxActorFlags inFlags);
96};
97
99
100template<class APIClass>
101NpActorTemplate<APIClass>::NpActorTemplate(PxType concreteType, PxBaseFlags baseFlags, NpType::Enum type) :
102 APIClass(concreteType, baseFlags),
103 NpActor (type)
104{
105 PX_ASSERT(!APIClass::userData);
106}
107
108template<class APIClass>
109NpActorTemplate<APIClass>::~NpActorTemplate()
110{
111 NpActor::onActorRelease(this);
112}
113
115
116template<class APIClass>
117PxScene* NpActorTemplate<APIClass>::getScene() const
118{
119 return getNpScene();
120}
121
123
124template<class APIClass>
125void NpActorTemplate<APIClass>::setName(const char* debugName)
126{
127 NP_WRITE_CHECK(getNpScene());
128
129 PX_CHECK_SCENE_API_WRITE_FORBIDDEN_EXCEPT_SPLIT_SIM(getNpScene(), "PxActor::setName() not allowed while simulation is running. Call will be ignored.")
130
131 mName = debugName;
132
133#if PX_SUPPORT_OMNI_PVD
134 PxActor & a = *this;
135 streamActorName(a, mName);
136#endif
137
138
139#if PX_SUPPORT_PVD
140 NpScene* npScene = getNpScene();
141 //Name changing is not bufferred
142 if(npScene)
143 npScene->getScenePvdClientInternal().updatePvdProperties(static_cast<NpActor*>(this));
144#endif
145}
146
147template<class APIClass>
148const char* NpActorTemplate<APIClass>::getName() const
149{
150 NP_READ_CHECK(getNpScene());
151 return mName;
152}
153
155
156template<class APIClass>
157void NpActorTemplate<APIClass>::setDominanceGroup(PxDominanceGroup dominanceGroup)
158{
159 NpScene* npScene = getNpScene();
160 NP_WRITE_CHECK(npScene);
161
162 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene, "PxActor::setDominanceGroup() not allowed while simulation is running. Call will be ignored.")
163
164 NpActor::scSetDominanceGroup(dominanceGroup);
165}
166
167template<class APIClass>
168PxDominanceGroup NpActorTemplate<APIClass>::getDominanceGroup() const
169{
170 NP_READ_CHECK(getNpScene());
171 return NpActor::getDominanceGroup();
172}
173
175
176template<class APIClass>
177void NpActorTemplate<APIClass>::setOwnerClient( PxClientID inId )
178{
179 if ( getNpScene() != NULL )
180 {
181 PxGetFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__,
182 "Attempt to set the client id when an actor is already in a scene.");
183 }
184 else
185 NpActor::scSetOwnerClient( inId );
186}
187
188template<class APIClass>
189PxClientID NpActorTemplate<APIClass>::getOwnerClient() const
190{
191 return NpActor::getOwnerClient();
192}
193
195
196template<class APIClass>
197PX_FORCE_INLINE void NpActorTemplate<APIClass>::setActorFlagInternal(PxActorFlag::Enum flag, bool value)
198{
199 NpActor& a = *this;
200 if (value)
201 a.scSetActorFlags( a.getActorFlags() | flag );
202 else
203 a.scSetActorFlags( a.getActorFlags() & (~PxActorFlags(flag)) );
204}
205
206template<class APIClass>
207PX_FORCE_INLINE void NpActorTemplate<APIClass>::setActorFlagsInternal(PxActorFlags inFlags)
208{
209 NpActor::scSetActorFlags(inFlags);
210}
211
212template<class APIClass>
213void NpActorTemplate<APIClass>::setActorFlag(PxActorFlag::Enum flag, bool value)
214{
215 NpScene* npScene = getNpScene();
216 NP_WRITE_CHECK(npScene);
217
218 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene, "PxActor::setActorFlag() not allowed while simulation is running. Call will be ignored.")
219
220 setActorFlagInternal(flag, value);
221}
222
223template<class APIClass>
224void NpActorTemplate<APIClass>::setActorFlags(PxActorFlags inFlags)
225{
226 NpScene* npScene = getNpScene();
227 NP_WRITE_CHECK(npScene);
228
229 PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene, "PxActor::setActorFlags() not allowed while simulation is running. Call will be ignored.")
230
231 setActorFlagsInternal(inFlags);
232}
233
234template<class APIClass>
235PxActorFlags NpActorTemplate<APIClass>::getActorFlags() const
236{
237 NP_READ_CHECK(getNpScene());
238 return NpActor::getActorFlags();
239}
240
242
243}
244
245#endif
Definition base.h:1940
Definition NpActorTemplate.h:54
Definition NpActor.h:45
Class to aggregate actors into a single broad-phase entry.
Definition PxAggregate.h:98
Class representing 3D range or axis aligned bounding box.
Definition PxBounds3.h:58
Binary deserialization context class.
Definition PxSerialFramework.h:174
A scene is a collection of bodies and constraints which can interact.
Definition PxScene.h:178
Binary serialization context class.
Definition PxSerialFramework.h:99
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
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
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
PxFlags< PxActorFlag::Enum, PxU8 > PxActorFlags
collection of set bits defined in PxActorFlag.
Definition PxActor.h:111
Enum
Definition PxActor.h:66
Enum
Definition PxActor.h:121
@ eINVALID_OPERATION
method was called at a time when an operation is not possible
Definition PxErrors.h:65