00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
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 
00045 
00046 
00047 #define uMAX_ACTIONS 300
00048 
00049 
00050 
00051 class uAction:public tListItem<uAction>{
00052 protected:
00053     int localID;  
00054     int globalID; 
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     
00066     
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 
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 
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     
00130     static bool IsBreakingGlobalBind(int sym);
00131 };
00132 
00133 
00134 
00135 
00136 
00137 
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     
00183     void SetBind( uBind * bound ){ bound_ = bound; }
00184     uBind * GetBind() const { return bound_; }
00185 
00186     
00187     void SetPressed( float pressed ){ pressed_ = pressed; }
00188     float GetPressed() const { return pressed_; }
00189 
00190     
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 
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 
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 
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 
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 );       
00270 void su_HandleDelayedEvents( );                         
00271 
00272 void su_InputSync(); 
00273 
00274 void su_ClearKeys(); 
00275 
00276 
00277 void su_KeyInit();
00278 
00279 
00280 void su_JoystickInit();
00281 
00282 #endif
00283