Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
PXDevice.cpp
Go to the documentation of this file.
1
2
3#include "Headers/PXDevice.h"
4
9
10#ifndef DVD_PHYSICS_API_FOUND_
11#error "No physics library implemented!"
12#endif
13
14namespace Divide
15{
16
17 namespace
18 {
19 constexpr F32 g_maxSimSpeed = 1000.f;
20 };
21
23 : PhysicsAPIWrapper(context )
24 , FrameListener( "PXDevice", context.kernel().frameListenerMgr(), 2u )
25 {
26 }
27
29 {
31 }
32
33 ErrorCode PXDevice::initPhysicsAPI( const U8 targetFrameRate, const F32 simSpeed )
34 {
35 DIVIDE_ASSERT( _api == nullptr,
36 "PXDevice error: initPhysicsAPI called twice!" );
37 switch ( _apiID )
38 {
40 {
41 _api = std::make_unique<PhysX>( _context );
42 } break;
43 case PhysicsAPI::ODE:
46 {
47 Console::errorfn( LOCALE_STR( "ERROR_PFX_DEVICE_API" ) );
49 };
50 };
51 _simulationSpeed = CLAMPED( simSpeed, 0.f, g_maxSimSpeed );
52 return _api->initPhysicsAPI( targetFrameRate, _simulationSpeed );
53 }
54
56 {
57 if ( _api == nullptr )
58 {
59 return false;
60 }
61
62 Console::printfn( LOCALE_STR( "STOP_PHYSICS_INTERFACE" ) );
63 const bool state = _api->closePhysicsAPI();
64 _api.reset();
65
66 return state;
67 }
68
69 void PXDevice::updateTimeStep( const U8 timeStepFactor, const F32 simSpeed )
70 {
72 _api->updateTimeStep( timeStepFactor, simSpeed );
73 }
74
75 bool PXDevice::frameEnded( const FrameEvent& evt ) noexcept
76 {
78
79 frameEnded( evt._time._game._deltaTimeUS );
80 return true;
81 }
82
83 void PXDevice::frameEnded( const U64 deltaTimeGameUS ) noexcept
84 {
85 _api->frameEnded( deltaTimeGameUS );
86 }
87
89 {
91
93 return true;
94 }
95
96 void PXDevice::frameStarted( const U64 deltaTimeGameUS )
97 {
98 _api->frameStarted( deltaTimeGameUS );
99 }
100
102 {
104
105 _api->idle();
106 }
107
109 {
110 return _api->initPhysicsScene( scene );
111 }
112
114 {
115 return _api->destroyPhysicsScene( scene );
116 }
117
119 {
121 return _api->createRigidActor( node, parentComp );
122 }
123
124 bool PXDevice::convertActor( PhysicsAsset* actor, const PhysicsGroup newGroup )
125 {
127 return _api->convertActor( actor, newGroup );
128 }
129
130 bool PXDevice::intersect( const Ray& intersectionRay, const vec2<F32> range, vector<SGNRayResult>& intersectionsOut ) const
131 {
133 return _api->intersect( intersectionRay, range, intersectionsOut );
134 }
135} //namespace Divide
#define LOCALE_STR(X)
Definition: Localization.h:91
#define DIVIDE_ASSERT(...)
#define PROFILE_SCOPE_AUTO(CATEGORY)
Definition: Profiler.h:87
void updateTimeStep(U8 timeStepFactor, F32 simSpeed) override
Definition: PXDevice.cpp:69
ErrorCode initPhysicsAPI(U8 targetFrameRate, F32 simSpeed) override
Definition: PXDevice.cpp:33
bool initPhysicsScene(Scene &scene) override
Definition: PXDevice.cpp:108
PhysicsAPIWrapper_uptr _api
Definition: PXDevice.h:84
bool destroyPhysicsScene(const Scene &scene) override
Definition: PXDevice.cpp:113
bool intersect(const Ray &intersectionRay, vec2< F32 > range, vector< SGNRayResult > &intersectionsOut) const override
Definition: PXDevice.cpp:130
bool frameStarted(const FrameEvent &evt) override
Definition: PXDevice.cpp:88
F32 _simulationSpeed
Definition: PXDevice.h:83
bool closePhysicsAPI() override
Definition: PXDevice.cpp:55
~PXDevice() override
Definition: PXDevice.cpp:28
void idle() override
Definition: PXDevice.cpp:101
PhysicsAsset * createRigidActor(SceneGraphNode *node, RigidBodyComponent &parentComp) override
Definition: PXDevice.cpp:118
bool convertActor(PhysicsAsset *actor, PhysicsGroup newGroup) override
Definition: PXDevice.cpp:124
bool frameEnded(const FrameEvent &evt) noexcept override
frameEnded is called after the buffers have been swapped
Definition: PXDevice.cpp:75
constexpr Optick::Category::Type Physics
Definition: Profiler.h:62
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
::value constexpr T CLAMPED(T n, T min, T max) noexcept
Definition: MathHelper.inl:126
uint64_t U64
static NO_INLINE void errorfn(const char *format, T &&... args)
static NO_INLINE void printfn(const char *format, T &&... args)
struct Divide::FrameEvent::Time::Impl _game
struct Divide::FrameEvent::Time _time