| 149 | void *userData); |
| 150 | |
| 151 | class GameInputProxy { |
| 152 | public: |
| 153 | explicit GameInputProxy(AndroidPlatform *platform) { |
| 154 | _androidPlatform = platform; |
| 155 | if (0 != platform->_app->activity->vm->AttachCurrentThread(&_jniEnv, nullptr)) { |
| 156 | CC_LOG_FATAL("*** FATAL ERROR: Failed to attach thread to JNI."); |
| 157 | ABORT_GAME |
| 158 | } |
| 159 | ABORT_IF(_jniEnv != nullptr) |
| 160 | |
| 161 | Paddleboat_init(_jniEnv, cc::JniHelper::getContext()); |
| 162 | Paddleboat_setControllerStatusCallback(gameControllerStatusCallback, this); |
| 163 | // This is needed to allow controller events through to us. |
| 164 | // By default, only touch-screen events are passed through, to match the |
| 165 | // behaviour of NativeActivity. |
| 166 | android_app_set_motion_event_filter(platform->_app, nullptr); |
| 167 | |
| 168 | // Flags to control how the IME behaves. |
| 169 | static constexpr int INPUTTYPE_DOT_TYPE_CLASS_TEXT = 1; |
| 170 | static constexpr int IME_ACTION_NONE = 1; |
| 171 | static constexpr int IME_FLAG_NO_FULLSCREEN = 33554432; |
| 172 | |
| 173 | GameActivity_setImeEditorInfo(platform->_app->activity, INPUTTYPE_DOT_TYPE_CLASS_TEXT, |
| 174 | IME_ACTION_NONE, IME_FLAG_NO_FULLSCREEN); |
| 175 | } |
| 176 | |
| 177 | ~GameInputProxy() { |
| 178 | Paddleboat_setControllerStatusCallback(nullptr, nullptr); |
| 179 | Paddleboat_destroy(_jniEnv); |
| 180 | if (_jniEnv) { |
| 181 | CC_LOG_INFO("Detaching current thread from JNI."); |
| 182 | _androidPlatform->_app->activity->vm->DetachCurrentThread(); |
| 183 | CC_LOG_INFO("Current thread detached from JNI."); |
| 184 | _jniEnv = nullptr; |
| 185 | } |
| 186 | } |
| 187 | void checkForNewAxis() { |
| 188 | // Tell GameActivity about any new axis ids so it reports |
| 189 | // their events |
| 190 | const uint64_t activeAxisIds = Paddleboat_getActiveAxisMask(); |
| 191 | uint64_t newAxisIds = activeAxisIds ^ _activeAxisIds; |
| 192 | if (newAxisIds != 0) { |
| 193 | _activeAxisIds = activeAxisIds; |
| 194 | int32_t currentAxisId = 0; |
| 195 | while (newAxisIds != 0) { |
| 196 | if ((newAxisIds & 1) != 0) { |
| 197 | CC_LOG_INFO("Enable Axis: %d", currentAxisId); |
| 198 | GameActivityPointerAxes_enableAxis(currentAxisId); |
| 199 | } |
| 200 | ++currentAxisId; |
| 201 | newAxisIds >>= 1; |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void handleInput() { |
| 207 | checkForNewAxis(); |
| 208 | Paddleboat_update(_jniEnv); |