| 310 | } |
| 311 | |
| 312 | int32_t PlatformAndroid::run(int argc, char** argv) |
| 313 | { |
| 314 | m_App = g_App; |
| 315 | assert(m_App); |
| 316 | |
| 317 | DBG("Inside RUN"); |
| 318 | |
| 319 | m_App->userData = this; |
| 320 | m_App->onAppCmd = [](struct android_app* app, int32_t cmd){ |
| 321 | PlatformAndroid* pl = (PlatformAndroid*)app->userData; |
| 322 | pl->onAppCmd(app, cmd); |
| 323 | }; |
| 324 | |
| 325 | m_App->onInputEvent = [](struct android_app* app, AInputEvent* event) { |
| 326 | PlatformAndroid* pl = (PlatformAndroid*)app->userData; |
| 327 | return pl->onInputEvent(app, event); |
| 328 | }; |
| 329 | |
| 330 | |
| 331 | bindKey(ACTION_PlayerForward, ActionType::PlayerForward, true); |
| 332 | bindKey(ACTION_PlayerBackward, ActionType::PlayerBackward, true); |
| 333 | bindKey(ACTION_PlayerTurnLeft, ActionType::PlayerTurnLeft, true); |
| 334 | bindKey(ACTION_PlayerTurnRight, ActionType::PlayerTurnRight, true); |
| 335 | bindKey(ACTION_PlayerStrafeLeft, ActionType::PlayerStrafeLeft, true); |
| 336 | bindKey(ACTION_PlayerStrafeRight, ActionType::PlayerStrafeRight, true); |
| 337 | bindKey(ACTION_PlayerAction, ActionType::PlayerAction, false); |
| 338 | bindKey(ACTION_Escape, ActionType::Escape, false); |
| 339 | |
| 340 | // Read all pending events. |
| 341 | int ident; |
| 342 | int events; |
| 343 | struct android_poll_source* source; |
| 344 | |
| 345 | while(0 == m_App->destroyRequested) |
| 346 | { |
| 347 | int dirPressed = 0; |
| 348 | |
| 349 | // Map directions to keys |
| 350 | if(m_ThumbstickPosition[0] != Math::float2(0, 0)) |
| 351 | { |
| 352 | if(m_ThumbstickPosition[0].dot(Math::float2(0.0f, 1.0f)) > 0.5f) |
| 353 | dirPressed = ACTION_PlayerBackward; |
| 354 | else if(m_ThumbstickPosition[0].dot(Math::float2(0.0f, -1.0f)) > 0.5f) |
| 355 | dirPressed = ACTION_PlayerForward; |
| 356 | else if(m_ThumbstickPosition[0].dot(Math::float2(-1.0f, 0.0f)) > 0.5f) |
| 357 | dirPressed = ACTION_PlayerStrafeLeft; |
| 358 | else if(m_ThumbstickPosition[0].dot(Math::float2(1.0f, 0.0f)) > 0.5f) |
| 359 | dirPressed = ACTION_PlayerStrafeRight; |
| 360 | |
| 361 | } |
| 362 | |
| 363 | if(getKeysState()[ACTION_PlayerForward] && dirPressed != ACTION_PlayerForward) |
| 364 | keyEvent(ACTION_PlayerForward, 0, KEY_ACTION_RELEASE, 0); |
| 365 | |
| 366 | if(getKeysState()[ACTION_PlayerBackward] && dirPressed != ACTION_PlayerBackward) |
| 367 | keyEvent(ACTION_PlayerBackward, 0, KEY_ACTION_RELEASE, 0); |
| 368 | |
| 369 | if(getKeysState()[ACTION_PlayerTurnLeft] && dirPressed != ACTION_PlayerTurnLeft) |
nothing calls this directly
no test coverage detected