1 | /* |
2 | * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved. |
3 | * |
4 | * NVIDIA CORPORATION and its licensors retain all intellectual property |
5 | * and proprietary rights in and to this software, related documentation |
6 | * and any modifications thereto. Any use, reproduction, disclosure or |
7 | * distribution of this software and related documentation without an express |
8 | * license agreement from NVIDIA CORPORATION is strictly prohibited. |
9 | */ |
10 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
11 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
12 | |
13 | |
14 | #ifndef PX_PHYSICS_NX_DELETIONLISTENER |
15 | #define PX_PHYSICS_NX_DELETIONLISTENER |
16 | /** \addtogroup physics |
17 | @{ |
18 | */ |
19 | |
20 | #include "PxPhysXConfig.h" |
21 | #include "common/PxBase.h" |
22 | |
23 | #ifndef PX_DOXYGEN |
24 | namespace physx |
25 | { |
26 | #endif |
27 | |
28 | |
29 | /** |
30 | \brief Flags specifying deletion event types. |
31 | |
32 | @see PxDeletionListener::onRelease PxPhysics.registerDeletionListener() |
33 | */ |
34 | struct PxDeletionEventFlag |
35 | { |
36 | enum Enum |
37 | { |
38 | eUSER_RELEASE = (1<<0), //!< The user has called release on an object. |
39 | eMEMORY_RELEASE = (1<<1) //!< The destructor of an object has been called and the memory has been released. |
40 | }; |
41 | }; |
42 | |
43 | /** |
44 | \brief Collection of set bits defined in PxDeletionEventFlag. |
45 | |
46 | @see PxDeletionEventFlag |
47 | */ |
48 | typedef PxFlags<PxDeletionEventFlag::Enum,PxU8> PxDeletionEventFlags; |
49 | PX_FLAGS_OPERATORS(PxDeletionEventFlag::Enum,PxU8) |
50 | |
51 | |
52 | /** |
53 | \brief interface to get notification on object deletion |
54 | |
55 | */ |
56 | class PxDeletionListener |
57 | { |
58 | public: |
59 | /** |
60 | \brief Notification if an object or its memory gets released |
61 | |
62 | If release() gets called on a PxBase object, an eUSER_RELEASE event will get fired immediately. The object state can be queried in the callback but |
63 | it is not allowed to change the state. Furthermore, when reading from the object it is the user's responsibility to make sure that no other thread |
64 | is writing at the same time to the object (this includes the simulation itself, i.e., #PxScene::fetchResults() must not get called at the same time). |
65 | |
66 | Calling release() on a PxBase object does not necessarily trigger its destructor immediately. For example, the object can be shared and might still |
67 | be referenced by other objects or the simulation might still be running and accessing the object state. In such cases the destructor will be called |
68 | as soon as it is safe to do so. After the destruction of the object and its memory, an eMEMORY_RELEASE event will get fired. In this case it is not |
69 | allowed to dereference the object pointer in the callback. |
70 | |
71 | \param[in] observed The object for which the deletion event gets fired. |
72 | \param[in] userData The user data pointer of the object for which the deletion event gets fired. Not available for all object types in which case it will be set to 0. |
73 | \param[in] deletionEvent The type of deletion event. Do not dereference the object pointer argument if the event is eMEMORY_RELEASE. |
74 | |
75 | */ |
76 | virtual void onRelease(const PxBase* observed, void* userData, PxDeletionEventFlag::Enum deletionEvent) = 0; |
77 | |
78 | protected: |
79 | PxDeletionListener() {} |
80 | virtual ~PxDeletionListener() {} |
81 | }; |
82 | |
83 | |
84 | #ifndef PX_DOXYGEN |
85 | } // namespace physx |
86 | #endif |
87 | |
88 | /** @} */ |
89 | #endif |
90 | |