Go to the documentation of this file.00001
00002
00003
00004
00005 #ifndef INPUT_H
00006 #define INPUT_H
00007
00008 #include <gccore.h>
00009 #include <wiiuse/wpad.h>
00010
00011 #include "globals.h"
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define ALL_ScanPads() \
00023 { \
00024 PAD_ScanPads(); \
00025 WPAD_ScanPads(); \
00026 for (int i = 0; i < MAX_PLAYERS; ++i) \
00027 { \
00028 WPAD_Accel(i, g_wiiacc + i); \
00029 WPAD_Expansion(i, g_wiiexp + i); \
00030 } \
00031 for(int i=3; i >= 0; i--) \
00032 { \
00033 userInput[i].pad.btns_d = PAD_ButtonsDown(i); \
00034 userInput[i].pad.btns_u = PAD_ButtonsUp(i); \
00035 userInput[i].pad.btns_h = PAD_ButtonsHeld(i); \
00036 userInput[i].pad.stickX = PAD_StickX(i); \
00037 userInput[i].pad.stickY = PAD_StickY(i); \
00038 userInput[i].pad.substickX = PAD_SubStickX(i); \
00039 userInput[i].pad.substickY = PAD_SubStickY(i); \
00040 userInput[i].pad.triggerL = PAD_TriggerL(i); \
00041 userInput[i].pad.triggerR = PAD_TriggerR(i); \
00042 } \
00043 }
00044
00045
00046
00047 #define NUNCHUK_CONNECTED(i) (g_wiiexp[i].type == WPAD_EXP_NUNCHUK)
00048
00049 #define NUNCHUK_StickPosX(i) g_wiiexp[i].nunchuk.js.pos.x
00050 #define NUNCHUK_StickPosY(i) g_wiiexp[i].nunchuk.js.pos.y
00051
00052 #define NUNCHUK_StickCenterX(i) g_wiiexp[i].nunchuk.js.center.x
00053 #define NUNCHUK_StickCenterY(i) g_wiiexp[i].nunchuk.js.center.y
00054
00055 #define NUNCHUK_StickDX(i) (NUNCHUK_StickPosX(i) - NUNCHUK_StickCenterX(i))
00056 #define NUNCHUK_StickDY(i) (NUNCHUK_StickPosY(i) - NUNCHUK_StickCenterY(i))
00057
00058 #define NUNCHUK_THRESHOLD 65
00059
00060 #define NUNCHUK_LEFT_PRESSED(i) (NUNCHUK_StickDX(i) < -NUNCHUK_THRESHOLD)
00061 #define NUNCHUK_RIGHT_PRESSED(i) (NUNCHUK_StickDX(i) > NUNCHUK_THRESHOLD)
00062 #define NUNCHUK_UP_PRESSED(i) (NUNCHUK_StickDY(i) > NUNCHUK_THRESHOLD)
00063 #define NUNCHUK_DOWN_PRESSED(i) (NUNCHUK_StickDY(i) < -NUNCHUK_THRESHOLD)
00064
00065 #define NUNCHUK_ButtonsDown(i) g_wiiexp[i].nunchuk.btns
00066 #define NUNCHUK_ButtonsReleased(i) g_wiiexp[i].nunchuk.btns_released
00067
00068 #define NUNCHUK_C_PRESSED(i) (NUNCHUK_ButtonsDown(i) & NUNCHUK_BUTTON_C)
00069 #define NUNCHUK_Z_PRESSED(i) (NUNCHUK_ButtonsDown(i) & NUNCHUK_BUTTON_Z)
00070 #define NUNCHUK_Z_RELEASED(i) (NUNCHUK_ButtonsReleased(i) & NUNCHUK_BUTTON_Z)
00071
00072
00073
00074
00075 #define MENU_LEFT_PRESSED(i) \
00076 ( \
00077 PAD_ButtonsDown(i) & PAD_BUTTON_LEFT \
00078 || PAD_StickX(i) < -65 \
00079 || (NUNCHUK_CONNECTED(i) ? \
00080 WPAD_ButtonsDown(i) & WPAD_BUTTON_LEFT || NUNCHUK_LEFT_PRESSED(i) \
00081 : \
00082 WPAD_ButtonsDown(i) & WPAD_BUTTON_UP) \
00083 )
00084
00085 #define MENU_RIGHT_PRESSED(i) \
00086 ( \
00087 PAD_ButtonsDown(i) & PAD_BUTTON_RIGHT \
00088 || PAD_StickX(i) > 65 \
00089 || (NUNCHUK_CONNECTED(i) ? \
00090 WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT || NUNCHUK_RIGHT_PRESSED(i) \
00091 : \
00092 WPAD_ButtonsDown(i) & WPAD_BUTTON_DOWN) \
00093 )
00094
00095 #define MENU_UP_PRESSED(i) \
00096 ( \
00097 PAD_ButtonsDown(i) & PAD_BUTTON_UP \
00098 || PAD_StickY(i) > 65 \
00099 || (NUNCHUK_CONNECTED(i) ? \
00100 WPAD_ButtonsDown(i) & WPAD_BUTTON_UP || NUNCHUK_UP_PRESSED(i) \
00101 : \
00102 WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT) \
00103 )
00104
00105 #define MENU_DOWN_PRESSED(i) \
00106 ( \
00107 PAD_ButtonsDown(i) & PAD_BUTTON_DOWN \
00108 || PAD_StickY(i) < -65 \
00109 || (NUNCHUK_CONNECTED(i) ? \
00110 WPAD_ButtonsDown(i) & WPAD_BUTTON_DOWN || NUNCHUK_DOWN_PRESSED(i) \
00111 : \
00112 WPAD_ButtonsDown(i) & WPAD_BUTTON_LEFT) \
00113 )
00114
00115 #define MENU_SELECT_PRESSED(i) \
00116 ( \
00117 PAD_ButtonsDown(i) & PAD_BUTTON_A \
00118 || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_A : WPAD_BUTTON_2) \
00119 )
00120
00121 #define MENU_EXIT_PRESSED(i) \
00122 ( \
00123 PAD_ButtonsDown(i) & PAD_BUTTON_B \
00124 || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_B : WPAD_BUTTON_1) \
00125 )
00126
00127 #define A_PRESSED(i) \
00128 ( \
00129 WPAD_ButtonsDown(i) & WPAD_BUTTON_A \
00130 || PAD_ButtonsDown(i) & PAD_BUTTON_A \
00131 )
00132
00133 #define B_PRESSED(i) \
00134 ( \
00135 WPAD_ButtonsDown(i) & WPAD_BUTTON_B \
00136 || PAD_ButtonsDown(i) & PAD_BUTTON_B \
00137 )
00138
00139 #define LEFT_PRESSED(i) \
00140 ( \
00141 (g_players[i].isNormalRotation ? \
00142 _LEFT_PRESSED(i) \
00143 : \
00144 _RIGHT_PRESSED(i)) \
00145 )
00146
00147 #define RIGHT_PRESSED(i) \
00148 ( \
00149 (g_players[i].isNormalRotation ? \
00150 _RIGHT_PRESSED(i) \
00151 : \
00152 _LEFT_PRESSED(i)) \
00153 )
00154
00155 #define _LEFT_PRESSED(i) \
00156 ( \
00157 PAD_ButtonsDown(i) & PAD_BUTTON_LEFT \
00158 || PAD_StickX(i) < -65 \
00159 || (NUNCHUK_CONNECTED(i) ? \
00160 WPAD_ButtonsDown(i) & WPAD_BUTTON_LEFT || NUNCHUK_LEFT_PRESSED(i) \
00161 : \
00162 WPAD_ButtonsHeld(i) & WPAD_BUTTON_UP) \
00163 )
00164
00165 #define _RIGHT_PRESSED(i) \
00166 ( \
00167 PAD_ButtonsDown(i) & PAD_BUTTON_RIGHT \
00168 || PAD_StickX(i) > 65 \
00169 || (NUNCHUK_CONNECTED(i) ? \
00170 WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT || NUNCHUK_RIGHT_PRESSED(i) \
00171 : \
00172 WPAD_ButtonsHeld(i) & WPAD_BUTTON_DOWN) \
00173 )
00174
00175 #define UP_PRESSED(i) \
00176 ( \
00177 PAD_ButtonsDown(i) & PAD_BUTTON_UP \
00178 || PAD_StickY(i) > 65 \
00179 || (NUNCHUK_CONNECTED(i) ? \
00180 WPAD_ButtonsDown(i) & WPAD_BUTTON_UP || NUNCHUK_UP_PRESSED(i) \
00181 : \
00182 WPAD_ButtonsDown(i) & WPAD_BUTTON_RIGHT) \
00183 )
00184
00185 #define DOWN_PRESSED(i) \
00186 ( \
00187 PAD_ButtonsHeld(i) & PAD_BUTTON_X \
00188 || PAD_ButtonsHeld(i) & PAD_BUTTON_Y \
00189 || PAD_StickY(i) < -65 \
00190 || (NUNCHUK_CONNECTED(i) ? \
00191 WPAD_ButtonsDown(i) & WPAD_BUTTON_DOWN || NUNCHUK_DOWN_PRESSED(i) \
00192 : \
00193 WPAD_ButtonsHeld(i) & WPAD_BUTTON_LEFT) \
00194 )
00195
00196
00197 #define ROTATE_PRESSED(i) \
00198 ( \
00199 PAD_ButtonsDown(i) & PAD_BUTTON_A \
00200 || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_A : WPAD_BUTTON_2) \
00201 )
00202
00203
00204 #define ROTATE2_PRESSED(i) \
00205 ( \
00206 PAD_ButtonsDown(i) & PAD_BUTTON_B \
00207 || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_B : WPAD_BUTTON_1) \
00208 )
00209
00210
00211 #define GRAB_HELD(i) \
00212 ( \
00213 WPAD_ButtonsHeld(i) & WPAD_BUTTON_A \
00214 )
00215
00216 #define PAUSE_PRESSED(i) \
00217 ( \
00218 PAD_ButtonsDown(i) & PAD_BUTTON_START \
00219 || WPAD_ButtonsDown(i) & WPAD_BUTTON_PLUS \
00220 )
00221
00222 #define MENU_PRESSED(i) \
00223 ( \
00224 PAD_ButtonsDown(i) & PAD_TRIGGER_Z \
00225 || WPAD_ButtonsDown(i) & WPAD_BUTTON_MINUS \
00226 )
00227
00228 #define LOADER_PRESSED(i) \
00229 ( \
00230 PAD_ButtonsDown(i) & PAD_TRIGGER_R \
00231 || WPAD_ButtonsDown(i) & WPAD_BUTTON_HOME \
00232 )
00233
00234
00235 #define ACCEL_Z_THRESHOLD 750
00236 #define ACCEL_Z_PRESSED(i) (g_wiiacc[i].z > ACCEL_Z_THRESHOLD)
00237
00238 #define DROP_PRESSED(i) \
00239 ( \
00240 PAD_ButtonsDown(i) & PAD_BUTTON_DOWN \
00241 || WPAD_ButtonsDown(i) & (NUNCHUK_CONNECTED(i) ? WPAD_BUTTON_DOWN : WPAD_BUTTON_A) \
00242 )
00243
00244
00245
00246
00247 #define PAUSE_HELD(i) \
00248 ( \
00249 PAD_ButtonsHeld(i) & PAD_BUTTON_START \
00250 || WPAD_ButtonsHeld(i) & WPAD_BUTTON_PLUS \
00251 )
00252
00253 inline bool PausePressedAnyPlayer()
00254 {
00255 for (int i = 0; i < g_options.players; ++i)
00256 {
00257 if (PAUSE_PRESSED(i))
00258 return true;
00259 }
00260
00261 return false;
00262 }
00263
00264 #endif // INPUT_H