1 /*****************************************************************************
2  * $LastChangedDate: 2011-04-09 21:58:06 -0400 (Sat, 09 Apr 2011) $
3  * @file
4  * @author  Jim E. Brooks  http://www.palomino3d.org
5  * @brief   Control is a Singleton that responds to input and contains the current Craft.
6  *//*
7  * LEGAL:   COPYRIGHT (C) 2007 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 CONTROL_CONTROL_HH
13 #define CONTROL_CONTROL_HH 1
14 
15 #include "base/singleton.hh"
16 #include "object/module.hh"
17 #include "object/craft.hh"
18 using namespace object;
19 
20 namespace control {
21 
22 #define GET_CONTROL()            (control::Control::GetInstance())
23 #define GET_CURRENT_CRAFT()      (control::Control::GetInstance().GetCurrentCraft())
24 #define SET_CURRENT_CRAFT(CRAFT) (control::Control::GetInstance().SetCurrentCraft( (CRAFT) ))
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// @brief Control is a Singleton that supports higher-level input handlers.
28 ///
29 /// +----------------+
30 /// |   application  |
31 /// +----------------+
32 /// | control module |
33 /// +----------------+
34 /// |   input module |
35 /// +----------------+
36 ///
37 class Control : public Singleton
38 {
39 PREVENT_COPYING(Control)
40 private:
Control(void)41     Control( void ) : mCurrentCraft(NULL), mRollLeftDir(1), mPitchUpDir(1), mYawLeftDir(1) { }
~Control()42     ~Control() { }
43 
44 public:
DEFINE_GetInstance(Control)45                      DEFINE_GetInstance( Control )  // Singleton
46     shptr0<Craft>    GetCurrentCraft( void )  // possibly NULL
47                      { CHECK_TYPESIG_NULL_OK(mCurrentCraft,TYPESIG_CRAFT);
48                        return mCurrentCraft; }
SetCurrentCraft(shptr<Craft> craft)49     void             SetCurrentCraft( shptr<Craft> craft )
50                      { CHECK_TYPESIG(craft,TYPESIG_CRAFT);
51                        mCurrentCraft = craft.PTR(); }
52 
53     // Configuration for graphical rotation.
54     // Not to be confused with joystick axis direction.
55     // -1 or +1 for which way to rotate.
GetRollLeftDir(void)56     int             GetRollLeftDir( void )  { return  mRollLeftDir; }
GetRollRightDir(void)57     int             GetRollRightDir( void ) { return -mRollLeftDir; }
GetPitchUpDir(void)58     int             GetPitchUpDir( void )   { return  mPitchUpDir; }
GetPitchDownDir(void)59     int             GetPitchDownDir( void ) { return -mPitchUpDir; }
GetYawLeftDir(void)60     int             GetYawLeftDir( void )   { return  mYawLeftDir; }
GetYawRightDir(void)61     int             GetYawRightDir( void )  { return -mYawLeftDir; }
62 
63 private:
64     DECLARE_SINGLETON_CLASS_VARS( Control )
65     shptr0<Craft>   mCurrentCraft;
66     int             mRollLeftDir, mPitchUpDir, mYawLeftDir;  ///< +-1
67 };
68 
69 // control.cc omitted.
70 #if CONTROL_MODULE_CC
71 DEFINE_SINGLETON_CLASS_VARS( Control )
72 #endif
73 
74 } // namespace control
75 
76 #endif // CONTROL_CONTROL_HH
77