1 /***************************************************************************** 2 * $LastChangedDate: 2009-11-22 22:39:11 -0500 (Sun, 22 Nov 2009) $ 3 * @file 4 * @author Jim E. Brooks http://www.palomino3d.org 5 * @brief Physics control (master switches). 6 *//* 7 * LEGAL: COPYRIGHT (C) 2008 JIM E. BROOKS 8 * THIS SOURCE CODE IS RELEASED UNDER THE TERMS 9 * OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2). 10 *****************************************************************************/ 11 12 #ifndef PHYSICS_PHYSICS_CONTROL_HH 13 #define PHYSICS_PHYSICS_CONTROL_HH 1 14 15 namespace physics { 16 17 //////////////////////////////////////////////////////////////////////////////// 18 /// @brief Main Physics object. 19 /// 20 /// This class is a master switch. 21 /// 22 class PhysicsControl 23 { 24 PREVENT_COPYING(PhysicsControl) 25 public: 26 // Globally enable all physics: Enable(const bool enable)27 CLASS_METHOD bool Enable( const bool enable ) 28 { 29 const bool prev = msEnabled; 30 if ( not msPermanentlyDisabled ) 31 msEnabled = enable; 32 return prev; 33 } 34 35 // Forces PhysicsControl::Enable() to become a NOP. PermanentlyDisable(void)36 CLASS_METHOD void PermanentlyDisable( void ) 37 { 38 msEnabled = false; 39 msPermanentlyDisabled = true; 40 } 41 IfEnabled(void)42 CLASS_METHOD bool IfEnabled( void ) 43 { 44 return msEnabled; 45 } 46 47 // Enable aircraft stalling. EnableStall(const bool enabled)48 CLASS_METHOD void EnableStall( const bool enabled ) 49 { 50 msStallEnabled = enabled; 51 } 52 IfStallEnabled(void)53 CLASS_METHOD bool IfStallEnabled( void ) 54 { 55 return msStallEnabled; 56 } 57 58 /// Get "simulation speed". Used to scale translation steps computed by physics. GetSimulationSpeed(void)59 CLASS_METHOD fp GetSimulationSpeed( void ) 60 { 61 return msSimulationSpeed; 62 } 63 SetSimulationSpeed(const fp simulationSpeed)64 CLASS_METHOD void SetSimulationSpeed( const fp simulationSpeed ) 65 { 66 msSimulationSpeed = simulationSpeed; 67 } 68 69 private: 70 CLASS_VAR bool msEnabled; 71 CLASS_VAR bool msPermanentlyDisabled; ///< set by -no-physics 72 CLASS_VAR bool msStallEnabled; 73 CLASS_VAR fp msSimulationSpeed; ///< for fast-motion 74 }; 75 76 #if PHYSICS_MODULE_CC 77 bool PhysicsControl::msEnabled = true; 78 bool PhysicsControl::msPermanentlyDisabled = false; 79 bool PhysicsControl::msStallEnabled = true; 80 fp PhysicsControl::msSimulationSpeed = 1.0f; 81 #endif 82 83 } // namespace physics 84 85 #endif // PHYSICS_PHYSICS_CONTROL_HH 86