aboutsummaryrefslogtreecommitdiff
path: root/src/client/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/client/game.cpp77
1 files changed, 40 insertions, 37 deletions
diff --git a/src/client/game.cpp b/src/client/game.cpp
index 011875e4a..18df5cc58 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -2460,7 +2460,7 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
if (m_cache_enable_joysticks) {
f32 sens_scale = getSensitivityScaleFactor();
- f32 c = m_cache_joystick_frustum_sensitivity * (1.f / 32767.f) * dtime * sens_scale;
+ f32 c = m_cache_joystick_frustum_sensitivity * dtime * sens_scale;
cam->camera_yaw -= input->joystick.getAxisWithoutDead(JA_FRUSTUM_HORIZONTAL) * c;
cam->camera_pitch += input->joystick.getAxisWithoutDead(JA_FRUSTUM_VERTICAL) * c;
}
@@ -2471,18 +2471,12 @@ void Game::updateCameraOrientation(CameraOrientation *cam, float dtime)
void Game::updatePlayerControl(const CameraOrientation &cam)
{
- //TimeTaker tt("update player control", NULL, PRECISION_NANO);
+ LocalPlayer *player = client->getEnv().getLocalPlayer();
- // DO NOT use the isKeyDown method for the forward, backward, left, right
- // buttons, as the code that uses the controls needs to be able to
- // distinguish between the two in order to know when to use joysticks.
+ //TimeTaker tt("update player control", NULL, PRECISION_NANO);
PlayerControl control(
- input->isKeyDown(KeyType::FORWARD),
- input->isKeyDown(KeyType::BACKWARD),
- input->isKeyDown(KeyType::LEFT),
- input->isKeyDown(KeyType::RIGHT),
- isKeyDown(KeyType::JUMP),
+ isKeyDown(KeyType::JUMP) || player->getAutojump(),
isKeyDown(KeyType::AUX1),
isKeyDown(KeyType::SNEAK),
isKeyDown(KeyType::ZOOM),
@@ -2490,22 +2484,16 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
isKeyDown(KeyType::PLACE),
cam.camera_pitch,
cam.camera_yaw,
- input->joystick.getAxisWithoutDead(JA_SIDEWARD_MOVE),
- input->joystick.getAxisWithoutDead(JA_FORWARD_MOVE)
+ input->getMovementSpeed(),
+ input->getMovementDirection()
);
- u32 keypress_bits = (
- ( (u32)(isKeyDown(KeyType::FORWARD) & 0x1) << 0) |
- ( (u32)(isKeyDown(KeyType::BACKWARD) & 0x1) << 1) |
- ( (u32)(isKeyDown(KeyType::LEFT) & 0x1) << 2) |
- ( (u32)(isKeyDown(KeyType::RIGHT) & 0x1) << 3) |
- ( (u32)(isKeyDown(KeyType::JUMP) & 0x1) << 4) |
- ( (u32)(isKeyDown(KeyType::AUX1) & 0x1) << 5) |
- ( (u32)(isKeyDown(KeyType::SNEAK) & 0x1) << 6) |
- ( (u32)(isKeyDown(KeyType::DIG) & 0x1) << 7) |
- ( (u32)(isKeyDown(KeyType::PLACE) & 0x1) << 8) |
- ( (u32)(isKeyDown(KeyType::ZOOM) & 0x1) << 9)
- );
+ // autoforward if set: move towards pointed position at maximum speed
+ if (player->getPlayerSettings().continuous_forward &&
+ client->activeObjectsReceived() && !player->isDead()) {
+ control.movement_speed = 1.0f;
+ control.movement_direction = 0.0f;
+ }
#ifdef ANDROID
/* For Android, simulate holding down AUX1 (fast move) if the user has
@@ -2515,23 +2503,38 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
*/
if (m_cache_hold_aux1) {
control.aux1 = control.aux1 ^ true;
- keypress_bits ^= ((u32)(1U << 5));
}
#endif
- LocalPlayer *player = client->getEnv().getLocalPlayer();
-
- // autojump if set: simulate "jump" key
- if (player->getAutojump()) {
- control.jump = true;
- keypress_bits |= 1U << 4;
- }
+ u32 keypress_bits = (
+ ( (u32)(control.jump & 0x1) << 4) |
+ ( (u32)(control.aux1 & 0x1) << 5) |
+ ( (u32)(control.sneak & 0x1) << 6) |
+ ( (u32)(control.dig & 0x1) << 7) |
+ ( (u32)(control.place & 0x1) << 8) |
+ ( (u32)(control.zoom & 0x1) << 9)
+ );
- // autoforward if set: simulate "up" key
- if (player->getPlayerSettings().continuous_forward &&
- client->activeObjectsReceived() && !player->isDead()) {
- control.up = true;
- keypress_bits |= 1U << 0;
+ // Set direction keys to ensure mod compatibility
+ if (control.movement_speed > 0.001f) {
+ float absolute_direction;
+
+ // Check in original orientation (absolute value indicates forward / backward)
+ absolute_direction = abs(control.movement_direction);
+ if (absolute_direction < (3.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 0); // Forward
+ if (absolute_direction > (5.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 1); // Backward
+
+ // Rotate entire coordinate system by 90 degrees (absolute value indicates left / right)
+ absolute_direction = control.movement_direction + M_PI_2;
+ if (absolute_direction >= M_PI)
+ absolute_direction -= 2 * M_PI;
+ absolute_direction = abs(absolute_direction);
+ if (absolute_direction < (3.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 2); // Left
+ if (absolute_direction > (5.0f / 8.0f * M_PI))
+ keypress_bits |= (u32)(0x1 << 3); // Right
}
client->setPlayerControl(control);