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 | #ifndef PX_PHYSICS_SCB_FSACTOR |
31 | #define PX_PHYSICS_SCB_FSACTOR |
32 | |
33 | #include "ScActorCore.h" |
34 | #include "PsUtilities.h" |
35 | #include "ScbBase.h" |
36 | #include "ScbDefs.h" |
37 | |
38 | #include "PxClient.h" |
39 | |
40 | |
41 | namespace physx |
42 | { |
43 | namespace Scb |
44 | { |
45 | struct ActorBuffer |
46 | { |
47 | #ifdef USE_NEW_SYSTEM |
48 | PxActorFlags mActorFlags; |
49 | PxDominanceGroup mDominanceGroup; |
50 | // PxActorClientBehaviorFlags mClientBehaviorFlags; |
51 | #else |
52 | template <PxU32 I, PxU32 Dummy> struct Fns {}; |
53 | typedef Sc::ActorCore Core; |
54 | typedef ActorBuffer Buf; |
55 | |
56 | SCB_REGULAR_ATTRIBUTE (0, PxActorFlags, ActorFlags) |
57 | SCB_REGULAR_ATTRIBUTE (1, PxDominanceGroup, DominanceGroup) |
58 | // SCB_REGULAR_ATTRIBUTE (2, PxActorClientBehaviorFlags, ClientBehaviorFlags) |
59 | #endif |
60 | enum { AttrCount = 3 }; |
61 | |
62 | protected: |
63 | ~ActorBuffer(){} |
64 | }; |
65 | |
66 | class Actor : public Base |
67 | { |
68 | //= ATTENTION! ===================================================================================== |
69 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
70 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
71 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
72 | // accordingly. |
73 | //================================================================================================== |
74 | |
75 | typedef ActorBuffer Buf; |
76 | typedef Sc::ActorCore Core; |
77 | |
78 | public: |
79 | // PX_SERIALIZATION |
80 | Actor(const PxEMPTY) : Base(PxEmpty) {} |
81 | static void getBinaryMetaData(PxOutputStream& stream); |
82 | //~PX_SERIALIZATION |
83 | |
84 | PX_INLINE Actor() {} |
85 | |
86 | #ifdef USE_NEW_SYSTEM |
87 | SCB_MEMBER(Actor, getActorCore(), ActorFlags, PxActorFlags, 0) |
88 | SCB_MEMBER(Actor, getActorCore(), DominanceGroup, PxDominanceGroup, 1) |
89 | // SCB_MEMBER(Actor, getActorCore(), ClientBehaviorFlags, PxActorClientBehaviorFlags, 2) |
90 | #endif |
91 | |
92 | //--------------------------------------------------------------------------------- |
93 | // Wrapper for Sc::Actor interface |
94 | //--------------------------------------------------------------------------------- |
95 | #ifndef USE_NEW_SYSTEM |
96 | PX_INLINE PxActorFlags getActorFlags() const { return read<Buf::BF_ActorFlags>(); } |
97 | PX_INLINE void setActorFlags(PxActorFlags v); |
98 | |
99 | PX_INLINE PxDominanceGroup getDominanceGroup() const { return read<Buf::BF_DominanceGroup>();} |
100 | PX_INLINE void setDominanceGroup(PxDominanceGroup v) { write<Buf::BF_DominanceGroup>(v); } |
101 | |
102 | // PX_INLINE PxActorClientBehaviorFlags getClientBehaviorFlags() const { return read<Buf::BF_ClientBehaviorFlags>(); } |
103 | // PX_INLINE void setClientBehaviorFlags(PxActorClientBehaviorFlags v){ write<Buf::BF_ClientBehaviorFlags>(v); } |
104 | #endif |
105 | |
106 | PX_INLINE void setOwnerClient(PxClientID inId); |
107 | PX_INLINE PxClientID getOwnerClient() const { return getActorCore().getOwnerClient(); } //immutable, so this should be fine. |
108 | |
109 | //--------------------------------------------------------------------------------- |
110 | // Miscellaneous |
111 | //--------------------------------------------------------------------------------- |
112 | PX_FORCE_INLINE const Core& getActorCore() const { return *reinterpret_cast<const Core*>(reinterpret_cast<size_t>(this) + sOffsets.scbToSc[getScbType()]); } |
113 | PX_FORCE_INLINE Core& getActorCore() { return *reinterpret_cast<Core*>(reinterpret_cast<size_t>(this) + sOffsets.scbToSc[getScbType()]); } |
114 | |
115 | PX_FORCE_INLINE static const Actor& fromSc(const Core& a) { return *reinterpret_cast<const Actor*>(reinterpret_cast<size_t>(&a) - sOffsets.scToScb[a.getActorCoreType()]); } |
116 | PX_FORCE_INLINE static Actor& fromSc(Core &a) { return *reinterpret_cast<Actor*>(reinterpret_cast<size_t>(&a) - sOffsets.scToScb[a.getActorCoreType()]); } |
117 | |
118 | PX_FORCE_INLINE PxActorType::Enum getActorType() const { return getActorCore().getActorCoreType(); } |
119 | |
120 | protected: |
121 | ~Actor() {} |
122 | PX_INLINE void syncState(); |
123 | |
124 | #ifndef USE_NEW_SYSTEM |
125 | //--------------------------------------------------------------------------------- |
126 | // Infrastructure for regular attributes |
127 | //--------------------------------------------------------------------------------- |
128 | struct Access: public BufferedAccess<Buf, Core, Actor> {}; |
129 | template<PxU32 f> PX_FORCE_INLINE typename Buf::Fns<f,0>::Arg read() const { return Access::read<Buf::Fns<f,0> >(*this, getActorCore()); } |
130 | template<PxU32 f> PX_FORCE_INLINE void write(typename Buf::Fns<f,0>::Arg v) { Access::write<Buf::Fns<f,0> >(*this, getActorCore(), v); } |
131 | template<PxU32 f> PX_FORCE_INLINE void flush(Core& core, const Buf& buf) { Access::flush<Buf::Fns<f,0> >(*this, core, buf); } |
132 | #endif |
133 | |
134 | struct Offsets |
135 | { |
136 | size_t scToScb[PxActorType::eACTOR_COUNT]; |
137 | size_t scbToSc[ScbType::eTYPE_COUNT]; |
138 | Offsets(); |
139 | }; |
140 | static const Offsets sOffsets; |
141 | }; |
142 | |
143 | #ifndef USE_NEW_SYSTEM |
144 | PX_INLINE void Actor::setActorFlags(PxActorFlags v) |
145 | { |
146 | // PT: TODO: move this check out of here, they should be done in Np! |
147 | #if PX_CHECKED |
148 | const PxActorFlags aFlags = getActorFlags(); |
149 | const PxActorType::Enum aType = getActorType(); |
150 | if((!aFlags.isSet(PxActorFlag::eDISABLE_SIMULATION)) && v.isSet(PxActorFlag::eDISABLE_SIMULATION) && |
151 | (aType != PxActorType::eRIGID_DYNAMIC) && (aType != PxActorType::eRIGID_STATIC)) |
152 | { |
153 | Ps::getFoundation().error(PxErrorCode::eINVALID_PARAMETER, __FILE__, __LINE__, |
154 | "PxActor::setActorFlag: PxActorFlag::eDISABLE_SIMULATION is only supported by PxRigidDynamic and PxRigidStatic objects." ); |
155 | } |
156 | #endif |
157 | |
158 | write<Buf::BF_ActorFlags>(v); |
159 | } |
160 | #endif |
161 | |
162 | PX_INLINE void Actor::setOwnerClient(PxClientID inId) |
163 | { |
164 | //This call is only valid if we aren't in a scene. |
165 | //Thus we can't be buffering yet |
166 | if(!isBuffering()) |
167 | { |
168 | getActorCore().setOwnerClient(inId); |
169 | UPDATE_PVD_PROPERTIES_OBJECT() |
170 | } |
171 | else |
172 | { |
173 | Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, |
174 | messageFmt: "Attempt to set the client id when an actor is buffering" ); |
175 | } |
176 | } |
177 | |
178 | PX_INLINE void Actor::syncState() |
179 | { |
180 | //this should be called from syncState() of derived classes |
181 | |
182 | const PxU32 flags = getBufferFlags(); |
183 | #ifdef USE_NEW_SYSTEM |
184 | if(flags & (BF_ActorFlags|BF_DominanceGroup/*|BF_ClientBehaviorFlags*/)) |
185 | { |
186 | syncActorFlags(); |
187 | syncDominanceGroup(); |
188 | // syncClientBehaviorFlags(); |
189 | } |
190 | #else |
191 | if(flags & (Buf::BF_ActorFlags|Buf::BF_DominanceGroup/*|Buf::BF_ClientBehaviorFlags*/)) |
192 | { |
193 | Core& core = getActorCore(); |
194 | const Buf& buffer = *reinterpret_cast<const Buf*>(getStream()); |
195 | |
196 | flush<Buf::BF_ActorFlags>(core, buf: buffer); |
197 | flush<Buf::BF_DominanceGroup>(core, buf: buffer); |
198 | // flush<Buf::BF_ClientBehaviorFlags>(core, buffer); |
199 | } |
200 | #endif |
201 | } |
202 | |
203 | } // namespace Scb |
204 | |
205 | } |
206 | |
207 | #endif |
208 | |