/*****************************************************************************
 * $LastChangedDate: 2009-11-22 22:39:11 -0500 (Sun, 22 Nov 2009) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Physics control (master switches).
 *//*
 * LEGAL:   COPYRIGHT (C) 2008 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef PHYSICS_PHYSICS_CONTROL_HH
#define PHYSICS_PHYSICS_CONTROL_HH 1

namespace physics {

////////////////////////////////////////////////////////////////////////////////
/// @brief Main Physics object.
///
/// This class is a master switch.
///
class PhysicsControl
{
PREVENT_COPYING(PhysicsControl)
public:
    // Globally enable all physics:
    CLASS_METHOD bool Enable( const bool enable )
    {
        const bool prev = msEnabled;
        if ( not msPermanentlyDisabled )
            msEnabled = enable;
        return prev;
    }

    // Forces PhysicsControl::Enable() to become a NOP.
    CLASS_METHOD void PermanentlyDisable( void )
    {
        msEnabled = false;
        msPermanentlyDisabled = true;
    }

    CLASS_METHOD bool IfEnabled( void )
    {
        return msEnabled;
    }

    // Enable aircraft stalling.
    CLASS_METHOD void EnableStall( const bool enabled )
    {
        msStallEnabled = enabled;
    }

    CLASS_METHOD bool IfStallEnabled( void )
    {
        return msStallEnabled;
    }

    /// Get "simulation speed".  Used to scale translation steps computed by physics.
    CLASS_METHOD fp GetSimulationSpeed( void )
    {
        return msSimulationSpeed;
    }

    CLASS_METHOD void SetSimulationSpeed( const fp simulationSpeed )
    {
        msSimulationSpeed = simulationSpeed;
    }

private:
    CLASS_VAR bool msEnabled;
    CLASS_VAR bool msPermanentlyDisabled;   ///< set by -no-physics
    CLASS_VAR bool msStallEnabled;
    CLASS_VAR fp   msSimulationSpeed;       ///< for fast-motion
};

#if PHYSICS_MODULE_CC
bool PhysicsControl::msEnabled = true;
bool PhysicsControl::msPermanentlyDisabled = false;
bool PhysicsControl::msStallEnabled = true;
fp   PhysicsControl::msSimulationSpeed = 1.0f;
#endif

} // namespace physics

#endif // PHYSICS_PHYSICS_CONTROL_HH
