RavEngine
Loading...
Searching...
No Matches
FdFoundation.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 PX_FOUNDATION_PSFOUNDATION_H
30#define PX_FOUNDATION_PSFOUNDATION_H
31
32#include "foundation/PxErrors.h"
33#include "foundation/PxProfiler.h"
34#include "foundation/PxFoundation.h"
35#include "foundation/PxAllocator.h"
36#include "foundation/PxHashMap.h"
37#include "foundation/PxUserAllocated.h"
38#include "foundation/PxBroadcast.h"
39#include "foundation/PxTempAllocator.h"
40#include "foundation/PxMutex.h"
41
42#include <stdarg.h>
43
44namespace physx
45{
46
47#if PX_VC
48#pragma warning(push)
49#pragma warning(disable : 4251) // class needs to have dll-interface to be used by clients of class
50#endif
51
52class PX_FOUNDATION_API Foundation : public PxFoundation, public PxUserAllocated
53{
54 PX_NOCOPY(Foundation)
55
56 public:
59
60 public:
61 // factory
62 // note, you MUST eventually call release if createInstance returned true!
63 static Foundation* createInstance(PxU32 version, PxErrorCallback& errc, PxAllocatorCallback& alloc);
64 static Foundation& getInstance();
65 static void setInstance(Foundation& foundation);
66 void release();
67 static void incRefCount(); // this call requires a foundation object to exist already
68 static void decRefCount(); // this call requires a foundation object to exist already
69 static PxU32 getRefCount();
70
71 // Begin Errors
73 {
74 return mErrorCallback;
75 } // Return the user's error callback
76 PxErrorCallback& getInternalErrorCallback()
77 {
78 return mBroadcastingError;
79 } // Return the broadcasting error callback
80
81 virtual void registerErrorCallback(PxErrorCallback& listener);
82 virtual void deregisterErrorCallback(PxErrorCallback& listener);
83
85 {
86 mErrorMask = mask;
87 }
89 {
90 return mErrorMask;
91 }
92
93 virtual bool error(PxErrorCode::Enum, const char* file, int line, const char* messageFmt, ...); // Report errors with the
94 // broadcasting
95 virtual bool error(PxErrorCode::Enum, const char* file, int line, const char* messageFmt, va_list); // error callback
96
97 static PxU32 getWarnOnceTimestamp();
98
99 // End errors
100
101 // Begin Allocations
103 {
104 return mAllocatorCallback;
105 } // Return the user's allocator callback
106 PxAllocatorCallback& getBroadcastAllocator()
107 {
108 return mBroadcastingAllocator;
109 } // Return the broadcasting allocator
110
111 virtual void registerAllocationListener(physx::PxAllocationListener& listener);
112 virtual void deregisterAllocationListener(physx::PxAllocationListener& listener);
113
114 virtual bool getReportAllocationNames() const
115 {
116 return mReportAllocationNames;
117 }
118 virtual void setReportAllocationNames(bool value)
119 {
120 mReportAllocationNames = value;
121 }
122
123 PX_INLINE AllocFreeTable& getTempAllocFreeTable()
124 {
125 return mTempAllocFreeTable;
126 }
127 PX_INLINE Mutex& getTempAllocMutex()
128 {
129 return mTempAllocMutex;
130 }
131 // End allocations
132
133 private:
134 static void destroyInstance();
135
136 Foundation(PxErrorCallback& errc, PxAllocatorCallback& alloc);
137 ~Foundation();
138
139 // init order is tricky here: the mutexes require the allocator, the allocator may require the error stream
140 PxAllocatorCallback& mAllocatorCallback;
141 PxErrorCallback& mErrorCallback;
142
143 PxBroadcastingAllocator mBroadcastingAllocator;
144 PxBroadcastingErrorCallback mBroadcastingError;
145
146 bool mReportAllocationNames;
147
148 PxErrorCode::Enum mErrorMask;
149 Mutex mErrorMutex;
150
151 AllocFreeTable mTempAllocFreeTable;
152 Mutex mTempAllocMutex;
153
154 Mutex mListenerMutex;
155
156 static Foundation* mInstance;
157 PxU32 mRefCount;
158 static PxU32 mWarnOnceTimestap;
159};
160#if PX_VC
161#pragma warning(pop)
162#endif
163
164PX_INLINE Foundation& getFoundation()
165{
166 return Foundation::getInstance();
167}
168
169} // namespace physx
170
171
172#endif
Definition FdFoundation.h:53
virtual void setReportAllocationNames(bool value)
Definition FdFoundation.h:118
virtual bool getReportAllocationNames() const
Definition FdFoundation.h:114
virtual PxAllocatorCallback & getAllocatorCallback()
Definition FdFoundation.h:102
virtual void setErrorLevel(PxErrorCode::Enum mask)
Definition FdFoundation.h:84
virtual PxErrorCode::Enum getErrorLevel() const
Definition FdFoundation.h:88
virtual PxErrorCallback & getErrorCallback()
Definition FdFoundation.h:72
Abstract listener class that listens to allocation and deallocation events from the foundation memory...
Definition PxBroadcast.h:49
Abstract base class for an application defined memory allocator that can be used by the Nv library.
Definition PxAllocatorCallback.h:53
Definition PxArray.h:53
User defined interface class. Used by the library to emit debug information.
Definition PxErrorCallback.h:51
Foundation SDK singleton class.
Definition PxFoundation.h:57
Definition PxMutex.h:89
Definition PxUserAllocated.h:43
#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
Enum
Definition PxErrors.h:52