@@ -2460,7 +2460,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
2460
2460
2461
2461
if (m_cache_enable_joysticks) {
2462
2462
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;
2464
2464
cam->camera_yaw -= input->joystick .getAxisWithoutDead (JA_FRUSTUM_HORIZONTAL) * c;
2465
2465
cam->camera_pitch += input->joystick .getAxisWithoutDead (JA_FRUSTUM_VERTICAL) * c;
2466
2466
}
@@ -2471,41 +2471,29 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
2471
2471
2472
2472
void Game::updatePlayerControl (const CameraOrientation &cam)
2473
2473
{
2474
- // TimeTaker tt("update player control", NULL, PRECISION_NANO );
2474
+ LocalPlayer * player = client-> getEnv (). getLocalPlayer ( );
2475
2475
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);
2479
2477
2480
2478
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 (),
2486
2480
isKeyDown (KeyType::AUX1),
2487
2481
isKeyDown (KeyType::SNEAK),
2488
2482
isKeyDown (KeyType::ZOOM),
2489
2483
isKeyDown (KeyType::DIG),
2490
2484
isKeyDown (KeyType::PLACE),
2491
2485
cam.camera_pitch ,
2492
2486
cam.camera_yaw ,
2493
- input->joystick . getAxisWithoutDead (JA_SIDEWARD_MOVE ),
2494
- input->joystick . getAxisWithoutDead (JA_FORWARD_MOVE )
2487
+ input->getMovementSpeed ( ),
2488
+ input->getMovementDirection ( )
2495
2489
);
2496
2490
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
+ }
2509
2497
2510
2498
#ifdef ANDROID
2511
2499
/* For Android, simulate holding down AUX1 (fast move) if the user has
@@ -2515,23 +2503,38 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
2515
2503
*/
2516
2504
if (m_cache_hold_aux1) {
2517
2505
control.aux1 = control.aux1 ^ true ;
2518
- keypress_bits ^= ((u32)(1U << 5 ));
2519
2506
}
2520
2507
#endif
2521
2508
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
+ );
2529
2517
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
2535
2538
}
2536
2539
2537
2540
client->setPlayerControl (control);
0 commit comments