00001 #include <vector> 00002 #include <IceUtil/Mutex.h> 00003 #include <IceUtil/Monitor.h> 00004 00005 #ifndef CONTROLLER_H_ 00006 #define CONTROLLER_H_ 00007 00008 using namespace std; 00009 00010 class Controller 00011 { 00012 public: 00013 00014 static const int BUTTON = 0; 00015 static const int AXIS = 1; 00016 00017 // Button identifiers to be used with buttonPressed(int) and buttonHeld(int) 00018 int BUTTON_A; 00019 int BUTTON_B; 00020 int BUTTON_X; 00021 int BUTTON_Y; 00022 int RIGHT_TRIGGER; 00023 int LEFT_TRIGGER; 00024 int RIGHT_BUMPER; 00025 int LEFT_BUMPER; 00026 int RIGHT_STICK; 00027 int LEFT_STICK; 00028 00029 // Joystick axis used with joystickValue(int); 00030 int JS_X_AXIS; 00031 int JS_Y_AXIS; 00032 00033 Controller(); 00034 00035 void update(bool isButton, int index, int value); 00036 void calibrate(); 00037 bool buttonPressed(int button); 00038 bool buttonHeld(int button); 00039 int getPreviousJSValue(int axis); 00040 int getCurrentJSValue(int axis); 00041 bool needCalibration(); 00042 void assignInput(int index); 00043 void setCalibration(bool needed); 00044 00045 private: 00046 00047 IceUtil::Mutex controllerLock; 00048 IceUtil::Monitor<IceUtil::Mutex> calibrationMonitor; 00049 00050 vector<int> oldJSValues; 00051 vector<int> newJSValues; 00052 vector<int> oldButtonValues; 00053 vector<int> newButtonValues; 00054 00055 int inputType; 00056 bool shouldCalibrate; 00057 00058 }; 00059 00060 #endif /* CONTROLLER_H_ */