RavEngine
Loading...
Searching...
No Matches
ScActorSim.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 SC_ACTOR_SIM_H
30#define SC_ACTOR_SIM_H
31
32#include "foundation/PxUserAllocated.h"
33#include "CmPtrTable.h"
34#include "CmUtils.h"
35#include "PxActor.h"
36#include "ScInteractionFlags.h"
37#include "ScActorCore.h"
38#include "PxsSimpleIslandManager.h"
39
40namespace physx
41{
42
43class PxActor;
44
45namespace Sc
46{
47
48#define SC_NOT_IN_SCENE_INDEX 0xffffffff // the body is not in the scene yet
49#define SC_NOT_IN_ACTIVE_LIST_INDEX 0xfffffffe // the body is in the scene but not in the active list
50
51 static const PxReal ScInternalWakeCounterResetValue = 20.0f*0.02f;
52
53 class Interaction;
54 class ElementSim;
55
57 {
58 public:
59
60 ShapeManager() {}
61 ~ShapeManager() {}
62
63 PX_FORCE_INLINE PxU32 getNbElements() const
64 {
65 return mShapes.getCount();
66 }
67 PX_FORCE_INLINE ElementSim** getElements()
68 {
69 return reinterpret_cast<ElementSim**>(mShapes.getPtrs());
70 }
71 PX_FORCE_INLINE ElementSim*const* getElements() const
72 {
73 return reinterpret_cast<ElementSim*const*>(mShapes.getPtrs());
74 }
75 // void onElementAttach(ElementSim& element);
76 void onElementDetach(ElementSim& element);
77
78 Cm::PtrTable mShapes;
79 };
80
81
82 class ActorSim : public ShapeManager
83 {
84 friend class Scene; // the scene is allowed to set the scene array index
85 friend class Interaction;
86 PX_NOCOPY(ActorSim)
87
88 public:
89 enum ActivityChangeInfoFlag
90 {
91 AS_PART_OF_CREATION = (1 << 0),
92 AS_PART_OF_ISLAND_GEN = (1 << 1)
93 };
94
95 enum InternalFlags
96 {
97 //BF_DISABLE_GRAVITY = 1 << 0, // Don't apply the scene's gravity
98
99 BF_HAS_STATIC_TOUCH = 1 << 1, // Set when a body is part of an island with static contacts. Needed to be able to recalculate adaptive force if this changes
100 BF_KINEMATIC_MOVED = 1 << 2, // Set when the kinematic was moved
101
102 BF_ON_DEATHROW = 1 << 3, // Set when the body is destroyed
103
104 BF_IS_IN_SLEEP_LIST = 1 << 4, // Set when the body is added to the list of bodies which were put to sleep
105 BF_IS_IN_WAKEUP_LIST = 1 << 5, // Set when the body is added to the list of bodies which were woken up
106 BF_SLEEP_NOTIFY = 1 << 6, // A sleep notification should be sent for this body (and not a wakeup event, even if the body is part of the woken list as well)
107 BF_WAKEUP_NOTIFY = 1 << 7, // A wake up notification should be sent for this body (and not a sleep event, even if the body is part of the sleep list as well)
108
109 BF_HAS_CONSTRAINTS = 1 << 8, // Set if the body has one or more constraints
110 BF_KINEMATIC_SETTLING = 1 << 9, // Set when the body was moved kinematically last frame
111 BF_KINEMATIC_SETTLING_2 = 1 << 10,
112 BF_KINEMATIC_MOVE_FLAGS = BF_KINEMATIC_MOVED | BF_KINEMATIC_SETTLING | BF_KINEMATIC_SETTLING_2, //Used to clear kinematic masks in 1 call
113 BF_KINEMATIC_SURFACE_VELOCITY = 1 << 11, //Set when the application calls setKinematicVelocity. Actor remains awake until application calls clearKinematicVelocity.
114 BF_IS_COMPOUND_RIGID = 1 << 12, // Set when the body is a compound actor, we dont want to set the sq bounds
115
116 // PT: WARNING: flags stored on 16-bits now.
117 };
118
120 virtual ~ActorSim();
121
122 // Get the scene the actor resides in
123 PX_FORCE_INLINE Scene& getScene() const { return mScene; }
124
125 // Get the number of interactions connected to the actor
126 PX_FORCE_INLINE PxU32 getActorInteractionCount() const { return mInteractions.size(); }
127
128 // Get an iterator to the interactions connected to the actor
129 PX_FORCE_INLINE Interaction** getActorInteractions() const { return mInteractions.begin(); }
130
131 // Get the type ID of the actor
132 PX_FORCE_INLINE PxActorType::Enum getActorType() const { return mCore.getActorCoreType(); }
133
134 // Returns true if the actor is a dynamic rigid body (including articulation links)
135 PX_FORCE_INLINE bool isDynamicRigid() const { const PxActorType::Enum type = getActorType(); return type == PxActorType::eRIGID_DYNAMIC || type == PxActorType::eARTICULATION_LINK; }
136 PX_FORCE_INLINE bool isSoftBody() const { const PxActorType::Enum type = getActorType(); return type == PxActorType::eSOFTBODY; }
137 PX_FORCE_INLINE bool isFEMCloth() const { const PxActorType::Enum type = getActorType(); return type == PxActorType::eFEMCLOTH; }
138 PX_FORCE_INLINE bool isParticleSystem() const { const PxActorType::Enum type = getActorType(); return type == PxActorType::ePBD_PARTICLESYSTEM || type == PxActorType::eFLIP_PARTICLESYSTEM || type == PxActorType::eMPM_PARTICLESYSTEM || type == PxActorType::eCUSTOM_PARTICLESYSTEM; }
139 PX_FORCE_INLINE bool isHairSystem() const { const PxActorType::Enum type = getActorType(); return type == PxActorType::eHAIRSYSTEM; }
140 PX_FORCE_INLINE bool isNonRigid() const { const PxActorType::Enum type = getActorType(); return type!=PxActorType::eRIGID_STATIC && type!=PxActorType::eRIGID_DYNAMIC && type!=PxActorType::eARTICULATION_LINK; }
141 PX_FORCE_INLINE bool isStaticRigid() const { const PxActorType::Enum type = getActorType(); return type == PxActorType::eRIGID_STATIC; }
142
143 virtual void postActorFlagChange(PxU32, PxU32) {}
144
145 void setActorsInteractionsDirty(InteractionDirtyFlag::Enum flag, const ActorSim* other, PxU8 interactionFlag);
146
147 PX_FORCE_INLINE ActorCore& getActorCore() const { return mCore; }
148
149 PX_FORCE_INLINE bool isActive() const { return (mActiveListIndex < SC_NOT_IN_ACTIVE_LIST_INDEX); }
150 void setActive(bool active, PxU32 infoFlag = 0); // see ActivityChangeInfoFlag
151
152 PX_FORCE_INLINE PxU32 getActiveListIndex() const { return mActiveListIndex; } // if the body is active, the index is smaller than SC_NOT_IN_ACTIVE_LIST_INDEX
153 PX_FORCE_INLINE void setActiveListIndex(PxU32 index) { mActiveListIndex = index; }
154
155 PX_FORCE_INLINE PxU32 getActiveCompoundListIndex() const { return mActiveCompoundListIndex; } // if the body is active and is compound, the index is smaller than SC_NOT_IN_ACTIVE_LIST_INDEX
156 PX_FORCE_INLINE void setActiveCompoundListIndex(PxU32 index) { mActiveCompoundListIndex = index; }
157
158 PX_FORCE_INLINE PxNodeIndex getNodeIndex() const { return mNodeIndex; }
159
160 PX_FORCE_INLINE PxU32 getActorID() const { return mId; }
161
162 PX_FORCE_INLINE PxU16 getInternalFlag() const { return mInternalFlags; }
163 PX_FORCE_INLINE PxU16 readInternalFlag(InternalFlags flag) const { return PxU16(mInternalFlags & flag); }
164 PX_FORCE_INLINE void raiseInternalFlag(InternalFlags flag) { mInternalFlags |= flag; }
165 PX_FORCE_INLINE void clearInternalFlag(InternalFlags flag) { mInternalFlags &= ~flag; }
166
167 virtual PxActor* getPxActor() const = 0;
168
169 //This can all be removed and functionality can be subsumed by the island system, removing the need for this
170 //virtual call and any associated work
171 virtual void registerCountedInteraction() {}
172 virtual void unregisterCountedInteraction() {}
173 virtual PxU32 getNumCountedInteractions() const { return 0; }
174
175 virtual void activate() {}
176 virtual void deactivate() {}
177 virtual void internalWakeUp(PxReal wakeCounterValue = ScInternalWakeCounterResetValue) { PX_UNUSED(wakeCounterValue); }
178
179 private:
180 //These are called from interaction creation/destruction
181 void registerInteractionInActor(Interaction* interaction);
182 void unregisterInteractionFromActor(Interaction* interaction);
183
184 void reallocInteractions(Sc::Interaction**& mem, PxU32& capacity, PxU32 size, PxU32 requiredMinCapacity);
185 protected:
186 // dsequeira: interaction arrays are a major cause of small allocations, so we don't want to delegate them to the heap allocator
187 // it's not clear this inline array is really needed, we should take it out and see whether the cache perf is worse
188
189 static const PxU32 INLINE_INTERACTION_CAPACITY = 4;
190 Interaction* mInlineInteractionMem[INLINE_INTERACTION_CAPACITY];
191
193 mInteractions;
194
195 Scene& mScene;
196
197 ActorCore& mCore;
198
199 //---------------------------------------------------------------------------------
200 // Sleeping
201 //---------------------------------------------------------------------------------
202 PxU32 mActiveListIndex; // Used by Scene to track active bodies
203 PxU32 mActiveCompoundListIndex; // Used by Scene to track active compound bodies
204
205 //---------------------------------------------------------------------------------
206 // Island manager
207 //---------------------------------------------------------------------------------
208 PxNodeIndex mNodeIndex;
209
210 PxU32 mId;
211
212 PxU16 mInternalFlags;
213 };
214
215} // namespace Sc
216
217}
218
219#endif
Definition CmUtils.h:116
PxActor is the base class for the main simulation objects in the physics SDK.
Definition PxActor.h:201
PxNodeIndex.
Definition PxNodeIndex.h:51
Definition PxUserAllocated.h:43
Definition ScActorCore.h:48
Definition ScActorSim.h:83
Definition ScElementSim.h:50
Definition ScInteraction.h:50
Definition ScScene.h:240
Definition ScActorSim.h:57
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Definition CmPtrTable.h:72
Enum
Definition PxActor.h:121
@ eCUSTOM_PARTICLESYSTEM
A CUSTOM ParticleSystem.
Definition PxActor.h:178
@ eARTICULATION_LINK
An articulation link.
Definition PxActor.h:138
@ eFLIP_PARTICLESYSTEM
A FLIP ParticleSystem.
Definition PxActor.h:164
@ eFEMCLOTH
A FEM-based cloth.
Definition PxActor.h:151
@ eSOFTBODY
A FEM-based soft body.
Definition PxActor.h:144
@ eHAIRSYSTEM
A HairSystem.
Definition PxActor.h:185
@ ePBD_PARTICLESYSTEM
A PBD ParticleSystem.
Definition PxActor.h:157
@ eMPM_PARTICLESYSTEM
A MPM ParticleSystem.
Definition PxActor.h:171
@ eRIGID_STATIC
A static rigid body.
Definition PxActor.h:126
@ eRIGID_DYNAMIC
A dynamic rigid body.
Definition PxActor.h:132