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 #include "LampBasic.h"
00026 #include "Input/Pad/SFPad.h"
00027 #include "Input/Joystick/Joystick.h"
00028 #include "Input/Pad/PS2Pad.h"
00029
00030 namespace Lamp{
00031
00032
00033
00034 bool SFPad::checkCompatibility(Joystick* joystick){
00035
00036 if(!joystick->hasXAxis()){ return false; }
00037 if(!joystick->hasYAxis()){ return false; }
00038
00039 if(joystick->getButtonCount() < 8){ return false; }
00040 return true;
00041 }
00042
00043
00044
00045
00046 SFPad::SFPad(Joystick* joystick) :
00047 Pad(joystick), digitalBoundary_(0.6f){
00048
00049 Assert(checkCompatibility(joystick_));
00050
00051
00052 int buttonCount = joystick_->getButtonCount();
00053 if(PS2Pad::checkCompatibility(joystick_) &&
00054 (buttonCount == 12)){
00055
00056 buttonMap_[buttonA] = PS2Pad::buttonMaru;
00057 buttonMap_[buttonB] = PS2Pad::buttonBatu;
00058 buttonMap_[buttonX] = PS2Pad::buttonSankaku;
00059 buttonMap_[buttonY] = PS2Pad::buttonSikaku;
00060 buttonMap_[buttonL] = PS2Pad::buttonL1;
00061 buttonMap_[buttonR] = PS2Pad::buttonR1;
00062 buttonMap_[buttonStart] = PS2Pad::buttonStart;
00063 buttonMap_[buttonSelect] = PS2Pad::buttonSelect;
00064 }else if(PS2Pad::checkCompatibility(joystick_) &&
00065 (buttonCount == 16)){
00066
00067 buttonMap_[buttonA] = PS2Pad::buttonMaru;
00068 buttonMap_[buttonB] = PS2Pad::buttonBatu;
00069 buttonMap_[buttonX] = PS2Pad::buttonSankaku;
00070 buttonMap_[buttonY] = PS2Pad::buttonSikaku;
00071 buttonMap_[buttonL] = PS2Pad::buttonL1;
00072 buttonMap_[buttonR] = PS2Pad::buttonR1;
00073 buttonMap_[buttonStart] = PS2Pad::buttonSelect;
00074 buttonMap_[buttonSelect] = PS2Pad::buttonStart;
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 }else{
00118
00119 for(int i = 0;i < 4; i++){ buttonMap_[i] = i; }
00120 int offset = buttonCount - 4;
00121 for(int i = 0;i < 4; i++){ buttonMap_[i + 4] = offset + i; }
00122 }
00123 }
00124
00125
00126 SFPad::~SFPad(){
00127 }
00128
00129
00130
00131
00132 void SFPad::changeButtonMap(Button button, int id){
00133 Assert((button >= 0) && (button < maxButtonCount));
00134 if(buttonMap_[button] == id){ return; }
00135 int destinationID = buttonMap_[button];
00136 for(int i = 0; i < maxButtonCount; i++){
00137 if(buttonMap_[i] == id){ buttonMap_[i] = destinationID; }
00138 }
00139 buttonMap_[button] = id;
00140 }
00141
00142
00143
00144
00145 float SFPad::getXAxis() const{
00146 return joystick_->getXAxis();
00147 }
00148
00149
00150 float SFPad::getYAxis() const{
00151 return joystick_->getYAxis();
00152 }
00153
00154
00155
00156
00157 bool SFPad::upKeyPressed() const{
00158 return yAxisToUpKey(joystick_->getYAxis());
00159 }
00160
00161
00162 bool SFPad::upKeyDown() const{
00163 return (yAxisToUpKey(joystick_->getYAxis()) &&
00164 (!yAxisToUpKey(joystick_->getPreYAxis())));
00165 }
00166
00167
00168 bool SFPad::upKeyUp() const{
00169 return (!yAxisToUpKey(joystick_->getYAxis()) &&
00170 (yAxisToUpKey(joystick_->getPreYAxis())));
00171 }
00172
00173
00174 bool SFPad::downKeyPressed() const{
00175 return yAxisToDownKey(joystick_->getYAxis());
00176 }
00177
00178
00179 bool SFPad::downKeyDown() const{
00180 return (yAxisToDownKey(joystick_->getYAxis()) &&
00181 (!yAxisToDownKey(joystick_->getPreYAxis())));
00182 }
00183
00184
00185 bool SFPad::downKeyUp() const{
00186 return (!yAxisToDownKey(joystick_->getYAxis()) &&
00187 (yAxisToDownKey(joystick_->getPreYAxis())));
00188 }
00189
00190
00191 bool SFPad::leftKeyPressed() const{
00192 return xAxisToLeftKey(joystick_->getXAxis());
00193 }
00194
00195
00196 bool SFPad::leftKeyDown() const{
00197 return (xAxisToLeftKey(joystick_->getXAxis()) &&
00198 (!xAxisToLeftKey(joystick_->getPreXAxis())));
00199 }
00200
00201
00202 bool SFPad::leftKeyUp() const{
00203 return (!xAxisToLeftKey(joystick_->getXAxis()) &&
00204 (xAxisToLeftKey(joystick_->getPreXAxis())));
00205 }
00206
00207
00208 bool SFPad::rightKeyPressed() const{
00209 return xAxisToRightKey(joystick_->getXAxis());
00210 }
00211
00212
00213 bool SFPad::rightKeyDown() const{
00214 return (xAxisToRightKey(joystick_->getXAxis()) &&
00215 (!xAxisToRightKey(joystick_->getPreXAxis())));
00216 }
00217
00218
00219 bool SFPad::rightKeyUp() const{
00220 return (!xAxisToRightKey(joystick_->getXAxis()) &&
00221 (xAxisToRightKey(joystick_->getPreXAxis())));
00222 }
00223
00224
00225
00226
00227 bool SFPad::buttonPressed(Button button) const{
00228 Assert((button >= 0) && (button < maxButtonCount));
00229 return joystick_->buttonPressed(buttonMap_[button]);
00230 }
00231
00232
00233 bool SFPad::buttonDown(Button button) const{
00234 Assert((button >= 0) && (button < maxButtonCount));
00235 return joystick_->buttonDown(buttonMap_[button]);
00236 }
00237
00238
00239 bool SFPad::buttonUp(Button button) const{
00240 Assert((button >= 0) && (button < maxButtonCount));
00241 return joystick_->buttonUp(buttonMap_[button]);
00242 }
00243
00244
00245
00246
00247 String SFPad::getButtonString(Button button){
00248 if(button == -1){ return "Unknown"; }
00249 Assert((button >= 0) && (button < maxButtonCount));
00250 String buttonString[] = { "A", "B", "X", "Y", "L", "R", "Start", "Select" };
00251 return buttonString[button];
00252 }
00253
00254
00255 String SFPad::toString() const{
00256 String result, temp;
00257 result = Pad::toString();
00258
00259
00260 result += " Press Down Up\n";
00261 temp.format(" UpKey %d %d %d\n",
00262 upKeyPressed(), upKeyDown(), upKeyUp());
00263 result += temp;
00264 temp.format(" DownKey %d %d %d\n",
00265 downKeyPressed(), downKeyDown(), downKeyUp());
00266 result += temp;
00267 temp.format(" LeftKey %d %d %d\n",
00268 leftKeyPressed(), leftKeyDown(), leftKeyUp());
00269 result += temp;
00270 temp.format(" RightKey %d %d %d\n",
00271 rightKeyPressed(), rightKeyDown(), rightKeyUp());
00272 result += temp;
00273
00274
00275 temp.format(" A %d %d %d\n",
00276 buttonPressed(buttonA), buttonDown(buttonA), buttonUp(buttonA));
00277 result += temp;
00278 temp.format(" B %d %d %d\n",
00279 buttonPressed(buttonB), buttonDown(buttonB), buttonUp(buttonB));
00280 result += temp;
00281 temp.format(" X %d %d %d\n",
00282 buttonPressed(buttonX), buttonDown(buttonX), buttonUp(buttonX));
00283 result += temp;
00284 temp.format(" Y %d %d %d\n",
00285 buttonPressed(buttonY), buttonDown(buttonY), buttonUp(buttonY));
00286 result += temp;
00287 temp.format(" L %d %d %d\n",
00288 buttonPressed(buttonL), buttonDown(buttonL), buttonUp(buttonL));
00289 result += temp;
00290 temp.format(" R %d %d %d\n",
00291 buttonPressed(buttonR), buttonDown(buttonR), buttonUp(buttonR));
00292 result += temp;
00293 temp.format(" Start %d %d %d\n",
00294 buttonPressed(buttonStart), buttonDown(buttonStart),
00295 buttonUp(buttonStart));
00296 result += temp;
00297 temp.format(" Select %d %d %d\n",
00298 buttonPressed(buttonSelect), buttonDown(buttonSelect),
00299 buttonUp(buttonSelect));
00300 result += temp;
00301 return result;
00302 }
00303
00304 }
00305