/*****************************************************************************
 * $LastChangedDate: 2011-04-09 21:58:06 -0400 (Sat, 09 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Control is a Singleton that responds to input and contains the current Craft.
 *//*
 * LEGAL:   COPYRIGHT (C) 2007 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef CONTROL_CONTROL_HH
#define CONTROL_CONTROL_HH 1

#include "base/singleton.hh"
#include "object/module.hh"
#include "object/craft.hh"
using namespace object;

namespace control {

#define GET_CONTROL()            (control::Control::GetInstance())
#define GET_CURRENT_CRAFT()      (control::Control::GetInstance().GetCurrentCraft())
#define SET_CURRENT_CRAFT(CRAFT) (control::Control::GetInstance().SetCurrentCraft( (CRAFT) ))

////////////////////////////////////////////////////////////////////////////////
/// @brief Control is a Singleton that supports higher-level input handlers.
///
/// +----------------+
/// |   application  |
/// +----------------+
/// | control module |
/// +----------------+
/// |   input module |
/// +----------------+
///
class Control : public Singleton
{
PREVENT_COPYING(Control)
private:
    Control( void ) : mCurrentCraft(NULL), mRollLeftDir(1), mPitchUpDir(1), mYawLeftDir(1) { }
    ~Control() { }

public:
                     DEFINE_GetInstance( Control )  // Singleton
    shptr0<Craft>    GetCurrentCraft( void )  // possibly NULL
                     { CHECK_TYPESIG_NULL_OK(mCurrentCraft,TYPESIG_CRAFT);
                       return mCurrentCraft; }
    void             SetCurrentCraft( shptr<Craft> craft )
                     { CHECK_TYPESIG(craft,TYPESIG_CRAFT);
                       mCurrentCraft = craft.PTR(); }

    // Configuration for graphical rotation.
    // Not to be confused with joystick axis direction.
    // -1 or +1 for which way to rotate.
    int             GetRollLeftDir( void )  { return  mRollLeftDir; }
    int             GetRollRightDir( void ) { return -mRollLeftDir; }
    int             GetPitchUpDir( void )   { return  mPitchUpDir; }
    int             GetPitchDownDir( void ) { return -mPitchUpDir; }
    int             GetYawLeftDir( void )   { return  mYawLeftDir; }
    int             GetYawRightDir( void )  { return -mYawLeftDir; }

private:
    DECLARE_SINGLETON_CLASS_VARS( Control )
    shptr0<Craft>   mCurrentCraft;
    int             mRollLeftDir, mPitchUpDir, mYawLeftDir;  ///< +-1
};

// control.cc omitted.
#if CONTROL_MODULE_CC
DEFINE_SINGLETON_CLASS_VARS( Control )
#endif

} // namespace control

#endif // CONTROL_CONTROL_HH
