@@ -2460,7 +2460,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
24602460
24612461 if (m_cache_enable_joysticks) {
24622462 f32 sens_scale = getSensitivityScaleFactor ();
2463- f32 c = m_cache_joystick_frustum_sensitivity * ( 1 . f / 32767 . f ) * dtime * sens_scale;
2463+ f32 c = m_cache_joystick_frustum_sensitivity * dtime * sens_scale;
24642464 cam->camera_yaw -= input->joystick .getAxisWithoutDead (JA_FRUSTUM_HORIZONTAL) * c;
24652465 cam->camera_pitch += input->joystick .getAxisWithoutDead (JA_FRUSTUM_VERTICAL) * c;
24662466 }
@@ -2471,41 +2471,29 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
24712471
24722472void Game::updatePlayerControl (const CameraOrientation &cam)
24732473{
2474- // TimeTaker tt("update player control", NULL, PRECISION_NANO );
2474+ LocalPlayer * player = client-> getEnv (). getLocalPlayer ( );
24752475
2476- // DO NOT use the isKeyDown method for the forward, backward, left, right
2477- // buttons, as the code that uses the controls needs to be able to
2478- // distinguish between the two in order to know when to use joysticks.
2476+ // TimeTaker tt("update player control", NULL, PRECISION_NANO);
24792477
24802478 PlayerControl control (
2481- input->isKeyDown (KeyType::FORWARD),
2482- input->isKeyDown (KeyType::BACKWARD),
2483- input->isKeyDown (KeyType::LEFT),
2484- input->isKeyDown (KeyType::RIGHT),
2485- isKeyDown (KeyType::JUMP),
2479+ isKeyDown (KeyType::JUMP) || player->getAutojump (),
24862480 isKeyDown (KeyType::AUX1),
24872481 isKeyDown (KeyType::SNEAK),
24882482 isKeyDown (KeyType::ZOOM),
24892483 isKeyDown (KeyType::DIG),
24902484 isKeyDown (KeyType::PLACE),
24912485 cam.camera_pitch ,
24922486 cam.camera_yaw ,
2493- input->joystick . getAxisWithoutDead (JA_SIDEWARD_MOVE ),
2494- input->joystick . getAxisWithoutDead (JA_FORWARD_MOVE )
2487+ input->getMovementSpeed ( ),
2488+ input->getMovementDirection ( )
24952489 );
24962490
2497- u32 keypress_bits = (
2498- ( (u32 )(isKeyDown (KeyType::FORWARD) & 0x1 ) << 0 ) |
2499- ( (u32 )(isKeyDown (KeyType::BACKWARD) & 0x1 ) << 1 ) |
2500- ( (u32 )(isKeyDown (KeyType::LEFT) & 0x1 ) << 2 ) |
2501- ( (u32 )(isKeyDown (KeyType::RIGHT) & 0x1 ) << 3 ) |
2502- ( (u32 )(isKeyDown (KeyType::JUMP) & 0x1 ) << 4 ) |
2503- ( (u32 )(isKeyDown (KeyType::AUX1) & 0x1 ) << 5 ) |
2504- ( (u32 )(isKeyDown (KeyType::SNEAK) & 0x1 ) << 6 ) |
2505- ( (u32 )(isKeyDown (KeyType::DIG) & 0x1 ) << 7 ) |
2506- ( (u32 )(isKeyDown (KeyType::PLACE) & 0x1 ) << 8 ) |
2507- ( (u32 )(isKeyDown (KeyType::ZOOM) & 0x1 ) << 9 )
2508- );
2491+ // autoforward if set: move towards pointed position at maximum speed
2492+ if (player->getPlayerSettings ().continuous_forward &&
2493+ client->activeObjectsReceived () && !player->isDead ()) {
2494+ control.movement_speed = 1 .0f ;
2495+ control.movement_direction = 0 .0f ;
2496+ }
25092497
25102498#ifdef ANDROID
25112499 /* For Android, simulate holding down AUX1 (fast move) if the user has
@@ -2515,23 +2503,38 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
25152503 */
25162504 if (m_cache_hold_aux1) {
25172505 control.aux1 = control.aux1 ^ true ;
2518- keypress_bits ^= ((u32 )(1U << 5 ));
25192506 }
25202507#endif
25212508
2522- LocalPlayer *player = client->getEnv ().getLocalPlayer ();
2523-
2524- // autojump if set: simulate "jump" key
2525- if (player->getAutojump ()) {
2526- control.jump = true ;
2527- keypress_bits |= 1U << 4 ;
2528- }
2509+ u32 keypress_bits = (
2510+ ( (u32 )(control.jump & 0x1 ) << 4 ) |
2511+ ( (u32 )(control.aux1 & 0x1 ) << 5 ) |
2512+ ( (u32 )(control.sneak & 0x1 ) << 6 ) |
2513+ ( (u32 )(control.dig & 0x1 ) << 7 ) |
2514+ ( (u32 )(control.place & 0x1 ) << 8 ) |
2515+ ( (u32 )(control.zoom & 0x1 ) << 9 )
2516+ );
25292517
2530- // autoforward if set: simulate "up" key
2531- if (player->getPlayerSettings ().continuous_forward &&
2532- client->activeObjectsReceived () && !player->isDead ()) {
2533- control.up = true ;
2534- keypress_bits |= 1U << 0 ;
2518+ // Set direction keys to ensure mod compatibility
2519+ if (control.movement_speed > 0 .001f ) {
2520+ float absolute_direction;
2521+
2522+ // Check in original orientation (absolute value indicates forward / backward)
2523+ absolute_direction = abs (control.movement_direction );
2524+ if (absolute_direction < (3 .0f / 8 .0f * M_PI))
2525+ keypress_bits |= (u32 )(0x1 << 0 ); // Forward
2526+ if (absolute_direction > (5 .0f / 8 .0f * M_PI))
2527+ keypress_bits |= (u32 )(0x1 << 1 ); // Backward
2528+
2529+ // Rotate entire coordinate system by 90 degrees (absolute value indicates left / right)
2530+ absolute_direction = control.movement_direction + M_PI_2;
2531+ if (absolute_direction >= M_PI)
2532+ absolute_direction -= 2 * M_PI;
2533+ absolute_direction = abs (absolute_direction);
2534+ if (absolute_direction < (3 .0f / 8 .0f * M_PI))
2535+ keypress_bits |= (u32 )(0x1 << 2 ); // Left
2536+ if (absolute_direction > (5 .0f / 8 .0f * M_PI))
2537+ keypress_bits |= (u32 )(0x1 << 3 ); // Right
25352538 }
25362539
25372540 client->setPlayerControl (control);
0 commit comments