src/ui/uInput.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #ifndef ArmageTron_INPUT_H
00029 #define ArmageTron_INPUT_H
00030 
00031 #include "rSDL.h"
00032 #include "tString.h"
00033 #include "defs.h"
00034 #include "tLinkedList.h"
00035 #include "tLocale.h"
00036 #include "tSafePTR.h"
00037 
00038 #define uMAX_PLAYERS 8
00039 
00040 extern bool su_mouseGrab;         
00041 extern REAL su_doubleBindTimeout; 
00042 
00043 // ***************************
00044 //      player controls
00045 // ***************************
00046 
00047 #define uMAX_ACTIONS 300
00048 
00049 // the possible actions; player actions and global actions
00050 
00051 class uAction:public tListItem<uAction>{
00052 protected:
00053     int localID;  // unique id on this host
00054     int globalID; // unique ID send from the server
00055 public:
00056     typedef enum {uINPUT_DIGITAL,uINPUT_ANALOG} uInputType;
00057 
00058     uInputType          type;
00059     int                         priority;
00060     tString             internalName;
00061     const tOutput       description;
00062     const tOutput       helpText;
00063 
00064 #ifdef SLOPPYLOCALE
00065     //  uAction(uAction *&anchor,const char *name,const char *desc,const char *help,
00066     //   uInputType t=uINPUT_DIGITAL);
00067 #endif
00068     uAction(uAction *&anchor,const char* name,
00069             int priority = 0,
00070             uInputType t=uINPUT_DIGITAL);
00071 
00072     uAction(uAction *&anchor,const char* name,
00073             const tOutput& desc,
00074             const tOutput& help,
00075             int priority = 0,
00076             uInputType t=uINPUT_DIGITAL);
00077 
00078     virtual ~uAction();
00079 
00081     static uAction * Find( char const * name );
00082 
00083     unsigned short ID() const{return globalID;}
00084 };
00085 
00086 // player actions (move,shoot) and global actions (stop game, pause..)
00087 
00088 class uActionPlayer:public uAction{
00089 public:
00090     uActionPlayer(const char *name,
00091                   int priority = 0,
00092                   uInputType    t=uINPUT_DIGITAL);
00093 
00094     uActionPlayer(const char *name,
00095                   const tOutput& desc,
00096                   const tOutput& help,
00097                   int priority = 0,
00098                   uInputType t=uINPUT_DIGITAL);
00099 
00100     virtual ~uActionPlayer();
00101 
00102     bool operator==(const uActionPlayer &x);
00103 
00104     static uActionPlayer *Find(int globalID);
00105 };
00106 
00107 class uActionCamera:public uAction{
00108 public:
00109     uActionCamera(const char *name,
00110                   int priority = 0,
00111                   uInputType    t=uINPUT_DIGITAL);
00112 
00113     virtual ~uActionCamera();
00114 
00115     bool operator==(const uActionCamera &x);
00116 };
00117 
00118 // global actions
00119 class uActionGlobal:public uAction{
00120 public:
00121     uActionGlobal(const char *name,
00122                   int priority = 0,
00123                   uInputType    t=uINPUT_DIGITAL);
00124 
00125     virtual ~uActionGlobal();
00126 
00127     bool operator==(const uActionGlobal &x);
00128 
00129     // binding that should interrupt chat/console input
00130     static bool IsBreakingGlobalBind(int sym);
00131 };
00132 
00133 
00134 
00135 
00136 // *********************************************
00137 // generic keypress/mouse movement binding class
00138 // *********************************************
00139 
00140 class uInput;
00141 
00142 class uBind: public tReferencable< uBind >
00143 {
00144     friend class uMenuItemInput;
00145 
00146     virtual bool Delayable()=0;
00147     virtual bool DoActivate(REAL x)=0;
00148     REAL lastValue_;
00149     REAL delayedValue_;
00150 
00151     uInput const * lastInput_;     
00152     double lastTime_;              
00153 
00154 public:
00155     uAction *act;
00156 
00157     uBind(uAction *a );
00158     uBind(std::istream &s);
00159     virtual ~uBind();
00160 
00161     virtual void Write(std::ostream &s);
00162 
00163     virtual bool CheckPlayer(int p)=0;
00164 
00165     bool Activate(REAL x, bool delayed );
00166     void HanldeDelayed();
00167 
00169     bool IsDoubleBind( uInput const * input );
00170 };
00171 
00173 class uInput
00174 {
00175 public:
00176     uInput( tString const & persistentID, tString const & name );
00177     ~uInput();
00178 
00179     int ID(){ return ID_; }
00180     tString const & PersistentID(){ return persistentID_; }
00181 
00182     // the binding of this key
00183     void SetBind( uBind * bound ){ bound_ = bound; }
00184     uBind * GetBind() const { return bound_; }
00185 
00186     // the pressed status
00187     void SetPressed( float pressed ){ pressed_ = pressed; }
00188     float GetPressed() const { return pressed_; }
00189 
00190     // a human readable name
00191     std::string const Name(){ return name_; }
00192 private:
00193     int ID_;               
00194     tString persistentID_; 
00195     tString name_;         
00196 
00197     tJUST_CONTROLLED_PTR< uBind > bound_; 
00198     float pressed_;                       
00199 };
00200 
00201 // *****************
00202 // Player binds
00203 // *****************
00204 
00205 class uBindPlayer:public uBind{
00206     int            ePlayer;
00207 
00208     virtual bool Delayable();
00209     virtual bool DoActivate(REAL x);
00210 
00211     uBindPlayer(uAction *a,int p);
00212 public:
00213     virtual ~uBindPlayer();
00214 
00215     static uBindPlayer * NewBind( uAction * action, int player );
00216     static uBindPlayer * NewBind( std::istream & s );
00217 
00218     static bool IsKeyWord(const char *n);
00219 
00220     virtual bool CheckPlayer(int p);
00221 
00222     virtual void Write(std::ostream &s);
00223 };
00224 
00225 
00226 // *****************
00227 // Global actions
00228 // *****************
00229 
00230 typedef bool ACTION_FUNC(REAL x);
00231 
00232 class uActionGlobalFunc: public tListItem<uActionGlobalFunc>{
00233     ACTION_FUNC   *func;
00234     uActionGlobal *act;
00235     bool           rebindable;
00236 
00237 public:
00238     uActionGlobalFunc(uActionGlobal *a, ACTION_FUNC *f, bool rebind = true );
00239     static bool IsBreakingGlobalBind(uAction *act);
00240     static bool GlobalAct(uAction *act, REAL x);
00241 };
00242 
00243 
00244 // ***************************
00245 //      player prototype
00246 // ***************************
00247 
00248 class uPlayerPrototype{
00249 protected:
00250     static uPlayerPrototype* playerConfig[uMAX_PLAYERS];
00251     int id;
00252 public:
00253     uPlayerPrototype();
00254     virtual ~uPlayerPrototype();
00255 
00256     virtual bool         Act(uAction *act, REAL x)=0;
00257     virtual const char * Name() const            =0;
00258 
00259     static uPlayerPrototype* PlayerConfig(int i);
00260     static int Num();
00261 };
00262 
00263 
00264 
00265 // the input configuration menu
00266 void su_InputConfig(int player);
00267 void su_InputConfigCamera(int player);
00268 void su_InputConfigGlobal();
00269 bool su_HandleEvent(SDL_Event &e, bool delayed );       // handle event during gameplay
00270 void su_HandleDelayedEvents( );                         // set menu state
00271 
00272 void su_InputSync(); // tells the input system that a new frame has been drawn;
00273 // autorepeat functions may be called.
00274 void su_ClearKeys(); // clears all keys into the unpressed state.
00275 
00276 // initialize keys (and mouse)
00277 void su_KeyInit();
00278 
00279 // initialize joysticks
00280 void su_JoystickInit();
00281 
00282 #endif
00283 

Generated on Sat Mar 15 22:56:14 2008 for Armagetron Advanced by  doxygen 1.5.4