RavEngine
Loading...
Searching...
No Matches
NpBase.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_BASE_H
30#define NP_BASE_H
31
32#include "foundation/PxUserAllocated.h"
33#include "NpScene.h"
34
35#if PX_SUPPORT_PVD
36 // PT: updatePvdProperties() is overloaded and the compiler needs to know 'this' type to do the right thing.
37 // Thus we can't just move this as an inlined Base function.
38 #define UPDATE_PVD_PROPERTY \
39 { \
40 NpScene* scene = getNpScene(); /* shared shapes also return zero here */ \
41 if(scene) \
42 scene->getScenePvdClientInternal().updatePvdProperties(this); \
43 }
44#else
45 #define UPDATE_PVD_PROPERTY
46#endif
47
49// PT: technically the following macros should all be "NP" macros (they're not exposed to the public API)
50// but I only renamed the local ones (used in NpBase.h) as "NP", while the other "PX" are used by clients
51// of these macros in other Np files. The PX_CHECK names are very misleading, since these checks seem to
52// stay in all builds, contrary to other macros like PX_CHECK_AND_RETURN.
54
55#define NP_API_READ_WRITE_ERROR_MSG(text) PxGetFoundation().error(PxErrorCode::eINVALID_OPERATION, PX_FL, text)
56
57// some API read calls are not allowed while the simulation is running since the properties might get
58// written to during simulation. Some of those are allowed while collision is running though or in callbacks
59// like contact modification, contact reports etc. Furthermore, it is ok to read all of them between fetchCollide
60// and advance.
61#define NP_API_READ_FORBIDDEN(npScene) (npScene && npScene->isAPIReadForbidden())
62#define NP_API_READ_FORBIDDEN_EXCEPT_COLLIDE(npScene) (npScene && npScene->isAPIReadForbidden() && (!npScene->isCollisionPhaseActive()))
63
65
66#define PX_CHECK_SCENE_API_READ_FORBIDDEN(npScene, text) \
67 if(NP_API_READ_FORBIDDEN(npScene)) \
68 { \
69 NP_API_READ_WRITE_ERROR_MSG(text); \
70 return; \
71 }
72
73#define PX_CHECK_SCENE_API_READ_FORBIDDEN_AND_RETURN_VAL(npScene, text, retValue) \
74 if(NP_API_READ_FORBIDDEN(npScene)) \
75 { \
76 NP_API_READ_WRITE_ERROR_MSG(text); \
77 return retValue; \
78 }
79
80#define PX_CHECK_SCENE_API_READ_FORBIDDEN_EXCEPT_COLLIDE(npScene, text) \
81 if(NP_API_READ_FORBIDDEN_EXCEPT_COLLIDE(npScene)) \
82 { \
83 NP_API_READ_WRITE_ERROR_MSG(text); \
84 return; \
85 }
86
87#define PX_CHECK_SCENE_API_READ_FORBIDDEN_EXCEPT_COLLIDE_AND_RETURN_VAL(npScene, text, retValue) \
88 if(NP_API_READ_FORBIDDEN_EXCEPT_COLLIDE(npScene)) \
89 { \
90 NP_API_READ_WRITE_ERROR_MSG(text); \
91 return retValue; \
92 }
93
95
96#define NP_API_WRITE_FORBIDDEN(npScene) (npScene && npScene->isAPIWriteForbidden())
97
98// some API write calls are allowed between fetchCollide and advance
99#define NP_API_WRITE_FORBIDDEN_EXCEPT_SPLIT_SIM(npScene) (npScene && npScene->isAPIWriteForbidden() && (npScene->getSimulationStage() != Sc::SimulationStage::eFETCHCOLLIDE))
100
102
103#define PX_CHECK_SCENE_API_WRITE_FORBIDDEN(npScene, text) \
104 if(NP_API_WRITE_FORBIDDEN(npScene)) \
105 { \
106 NP_API_READ_WRITE_ERROR_MSG(text); \
107 return; \
108 }
109
110#define PX_CHECK_SCENE_API_WRITE_FORBIDDEN_AND_RETURN_VAL(npScene, text, retValue) \
111 if(NP_API_WRITE_FORBIDDEN(npScene)) \
112 { \
113 NP_API_READ_WRITE_ERROR_MSG(text); \
114 return retValue; \
115 }
116
117#define PX_CHECK_SCENE_API_WRITE_FORBIDDEN_EXCEPT_SPLIT_SIM(npScene, text) \
118 if(NP_API_WRITE_FORBIDDEN_EXCEPT_SPLIT_SIM(npScene)) \
119 { \
120 NP_API_READ_WRITE_ERROR_MSG(text); \
121 return; \
122 }
123
125
126#define NP_UNUSED_BASE_INDEX 0x07ffffff
127#define NP_BASE_INDEX_MASK 0x07ffffff
128#define NP_BASE_INDEX_SHIFT 27
129
130namespace physx
131{
132 struct NpType
133 {
134 enum Enum
135 {
136 eUNDEFINED,
137 eSHAPE,
138 eBODY,
139 eBODY_FROM_ARTICULATION_LINK,
140 eRIGID_STATIC,
141 eCONSTRAINT,
142 eARTICULATION,
143 eARTICULATION_JOINT,
144 eARTICULATION_SENSOR,
145 eARTICULATION_SPATIAL_TENDON,
146 eARTICULATION_ATTACHMENT,
147 eARTICULATION_FIXED_TENDON,
148 eARTICULATION_TENDON_JOINT,
149 eAGGREGATE,
150 eSOFTBODY,
151 eFEMCLOTH,
152 ePBD_PARTICLESYSTEM,
153 eFLIP_PARTICLESYSTEM,
154 eMPM_PARTICLESYSTEM,
155 eCUSTOM_PARTICLESYSTEM,
156 eHAIRSYSTEM,
157 eTYPE_COUNT,
158
159 eFORCE_DWORD = 0x7fffffff
160 };
161 };
162
163 // PT: we're going to store that type on 5 bits, leaving 27 bits for the base index.
164 PX_COMPILE_TIME_ASSERT(NpType::eTYPE_COUNT<32);
165
166 class NpBase : public PxUserAllocated
167 {
168 PX_NOCOPY(NpBase)
169 public:
170// PX_SERIALIZATION
171 NpBase(const PxEMPTY) :
172 mScene (NULL),
173 mFreeSlot (0)
174 {
175 // PT: preserve type, reset base index
176 setBaseIndex(NP_UNUSED_BASE_INDEX);
177 }
178 static void getBinaryMetaData(PxOutputStream& stream);
179//~PX_SERIALIZATION
180 NpBase(NpType::Enum type) :
181 mScene (NULL),
182 mFreeSlot (0)
183 {
184 mBaseIndexAndType = (PxU32(type)<<NP_BASE_INDEX_SHIFT)|NP_UNUSED_BASE_INDEX;
185 }
186
187 PX_INLINE bool isAPIWriteForbidden() const { return NP_API_WRITE_FORBIDDEN(mScene); }
188 PX_INLINE bool isAPIWriteForbiddenExceptSplitSim() const { return NP_API_WRITE_FORBIDDEN_EXCEPT_SPLIT_SIM(mScene); }
189
190 PX_FORCE_INLINE NpType::Enum getNpType() const { return NpType::Enum(mBaseIndexAndType>>NP_BASE_INDEX_SHIFT); }
191 PX_FORCE_INLINE void setNpScene(NpScene* scene) { mScene = scene; }
192 PX_FORCE_INLINE NpScene* getNpScene() const { return mScene; }
193
194 PX_FORCE_INLINE PxU32 getBaseIndex() const { return mBaseIndexAndType & NP_BASE_INDEX_MASK; }
195 PX_FORCE_INLINE void setBaseIndex(PxU32 index)
196 {
197 PX_ASSERT(!(index & ~NP_BASE_INDEX_MASK));
198 const PxU32 type = mBaseIndexAndType & ~NP_BASE_INDEX_MASK;
199 mBaseIndexAndType = index|type;
200 }
201 protected:
202 ~NpBase(){}
203 private:
204 NpScene* mScene;
205 PxU32 mBaseIndexAndType;
206 protected:
207 PxU32 mFreeSlot;
208 };
209}
210
211#endif
Definition NpBase.h:167
Definition NpScene.h:130
Output stream class for I/O.
Definition PxIO.h:114
Definition PxUserAllocated.h:43
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_COMPILE_TIME_ASSERT(exp)
Definition PxPreprocessor.h:428
#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
PxEMPTY
Definition Px.h:87
Definition NpBase.h:133