mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Restore pass-through of direction keys (#11924)
This moves relevant code into the PlayerControl class and gets rid of separate keyPressed variable.
This commit is contained in:
parent
76dbd0d2d0
commit
5eb45e1ea0
11 changed files with 165 additions and 98 deletions
|
@ -931,7 +931,7 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
|
|||
v3f sf = myplayer->getSpeed() * 100;
|
||||
s32 pitch = myplayer->getPitch() * 100;
|
||||
s32 yaw = myplayer->getYaw() * 100;
|
||||
u32 keyPressed = myplayer->keyPressed;
|
||||
u32 keyPressed = myplayer->control.getKeysPressed();
|
||||
// scaled by 80, so that pi can fit into a u8
|
||||
u8 fov = clientMap->getCameraFov() * 80;
|
||||
u8 wanted_range = MYMIN(255,
|
||||
|
@ -1287,22 +1287,24 @@ void Client::sendPlayerPos()
|
|||
if (!player)
|
||||
return;
|
||||
|
||||
ClientMap &map = m_env.getClientMap();
|
||||
u8 camera_fov = map.getCameraFov();
|
||||
u8 wanted_range = map.getControl().wanted_range;
|
||||
|
||||
// Save bandwidth by only updating position when
|
||||
// player is not dead and something changed
|
||||
|
||||
if (m_activeobjects_received && player->isDead())
|
||||
return;
|
||||
|
||||
ClientMap &map = m_env.getClientMap();
|
||||
u8 camera_fov = map.getCameraFov();
|
||||
u8 wanted_range = map.getControl().wanted_range;
|
||||
|
||||
u32 keyPressed = player->control.getKeysPressed();
|
||||
|
||||
if (
|
||||
player->last_position == player->getPosition() &&
|
||||
player->last_speed == player->getSpeed() &&
|
||||
player->last_pitch == player->getPitch() &&
|
||||
player->last_yaw == player->getYaw() &&
|
||||
player->last_keyPressed == player->keyPressed &&
|
||||
player->last_keyPressed == keyPressed &&
|
||||
player->last_camera_fov == camera_fov &&
|
||||
player->last_wanted_range == wanted_range)
|
||||
return;
|
||||
|
@ -1311,7 +1313,7 @@ void Client::sendPlayerPos()
|
|||
player->last_speed = player->getSpeed();
|
||||
player->last_pitch = player->getPitch();
|
||||
player->last_yaw = player->getYaw();
|
||||
player->last_keyPressed = player->keyPressed;
|
||||
player->last_keyPressed = keyPressed;
|
||||
player->last_camera_fov = camera_fov;
|
||||
player->last_wanted_range = wanted_range;
|
||||
|
||||
|
|
|
@ -70,10 +70,10 @@ static void dump_start_data(const GameStartData &data)
|
|||
|
||||
ClientLauncher::~ClientLauncher()
|
||||
{
|
||||
delete receiver;
|
||||
|
||||
delete input;
|
||||
|
||||
delete receiver;
|
||||
|
||||
delete g_fontengine;
|
||||
delete g_gamecallback;
|
||||
|
||||
|
|
|
@ -2481,6 +2481,10 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
|
|||
//TimeTaker tt("update player control", NULL, PRECISION_NANO);
|
||||
|
||||
PlayerControl control(
|
||||
isKeyDown(KeyType::FORWARD),
|
||||
isKeyDown(KeyType::BACKWARD),
|
||||
isKeyDown(KeyType::LEFT),
|
||||
isKeyDown(KeyType::RIGHT),
|
||||
isKeyDown(KeyType::JUMP) || player->getAutojump(),
|
||||
isKeyDown(KeyType::AUX1),
|
||||
isKeyDown(KeyType::SNEAK),
|
||||
|
@ -2511,39 +2515,7 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
|
|||
}
|
||||
#endif
|
||||
|
||||
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)
|
||||
);
|
||||
|
||||
// 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);
|
||||
player->keyPressed = keypress_bits;
|
||||
|
||||
//tt.stop();
|
||||
}
|
||||
|
|
|
@ -152,8 +152,14 @@ public:
|
|||
// in the subsequent iteration of Game::processPlayerInteraction
|
||||
bool WasKeyReleased(const KeyPress &keycode) const { return keyWasReleased[keycode]; }
|
||||
|
||||
void listenForKey(const KeyPress &keyCode) { keysListenedFor.set(keyCode); }
|
||||
void dontListenForKeys() { keysListenedFor.clear(); }
|
||||
void listenForKey(const KeyPress &keyCode)
|
||||
{
|
||||
keysListenedFor.set(keyCode);
|
||||
}
|
||||
void dontListenForKeys()
|
||||
{
|
||||
keysListenedFor.clear();
|
||||
}
|
||||
|
||||
s32 getMouseWheel()
|
||||
{
|
||||
|
@ -189,8 +195,6 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
s32 mouse_wheel = 0;
|
||||
|
||||
JoystickController *joystick = nullptr;
|
||||
|
||||
#ifdef HAVE_TOUCHSCREENGUI
|
||||
|
@ -198,6 +202,8 @@ public:
|
|||
#endif
|
||||
|
||||
private:
|
||||
s32 mouse_wheel = 0;
|
||||
|
||||
// The current state of keys
|
||||
KeyList keyIsDown;
|
||||
|
||||
|
@ -272,6 +278,12 @@ public:
|
|||
{
|
||||
m_receiver->joystick = &joystick;
|
||||
}
|
||||
|
||||
virtual ~RealInputHandler()
|
||||
{
|
||||
m_receiver->joystick = nullptr;
|
||||
}
|
||||
|
||||
virtual bool isKeyDown(GameKeyType k)
|
||||
{
|
||||
return m_receiver->IsKeyDown(keycache.key[k]) || joystick.isKeyDown(k);
|
||||
|
@ -288,6 +300,7 @@ public:
|
|||
{
|
||||
return m_receiver->WasKeyReleased(keycache.key[k]) || joystick.wasKeyReleased(k);
|
||||
}
|
||||
|
||||
virtual float getMovementSpeed()
|
||||
{
|
||||
bool f = m_receiver->IsKeyDown(keycache.key[KeyType::FORWARD]),
|
||||
|
@ -307,6 +320,7 @@ public:
|
|||
}
|
||||
return joystick.getMovementSpeed();
|
||||
}
|
||||
|
||||
virtual float getMovementDirection()
|
||||
{
|
||||
float x = 0, z = 0;
|
||||
|
@ -326,10 +340,12 @@ public:
|
|||
else
|
||||
return joystick.getMovementDirection();
|
||||
}
|
||||
|
||||
virtual bool cancelPressed()
|
||||
{
|
||||
return wasKeyDown(KeyType::ESC) || m_receiver->WasKeyDown(CancelKey);
|
||||
}
|
||||
|
||||
virtual void clearWasKeyPressed()
|
||||
{
|
||||
m_receiver->clearWasKeyPressed();
|
||||
|
@ -338,17 +354,21 @@ public:
|
|||
{
|
||||
m_receiver->clearWasKeyReleased();
|
||||
}
|
||||
|
||||
virtual void listenForKey(const KeyPress &keyCode)
|
||||
{
|
||||
m_receiver->listenForKey(keyCode);
|
||||
}
|
||||
virtual void dontListenForKeys() { m_receiver->dontListenForKeys(); }
|
||||
virtual void dontListenForKeys()
|
||||
{
|
||||
m_receiver->dontListenForKeys();
|
||||
}
|
||||
|
||||
virtual v2s32 getMousePos()
|
||||
{
|
||||
if (RenderingEngine::get_raw_device()->getCursorControl()) {
|
||||
return RenderingEngine::get_raw_device()
|
||||
->getCursorControl()
|
||||
->getPosition();
|
||||
auto control = RenderingEngine::get_raw_device()->getCursorControl();
|
||||
if (control) {
|
||||
return control->getPosition();
|
||||
}
|
||||
|
||||
return m_mousepos;
|
||||
|
@ -356,16 +376,18 @@ public:
|
|||
|
||||
virtual void setMousePos(s32 x, s32 y)
|
||||
{
|
||||
if (RenderingEngine::get_raw_device()->getCursorControl()) {
|
||||
RenderingEngine::get_raw_device()
|
||||
->getCursorControl()
|
||||
->setPosition(x, y);
|
||||
auto control = RenderingEngine::get_raw_device()->getCursorControl();
|
||||
if (control) {
|
||||
control->setPosition(x, y);
|
||||
} else {
|
||||
m_mousepos = v2s32(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
virtual s32 getMouseWheel() { return m_receiver->getMouseWheel(); }
|
||||
virtual s32 getMouseWheel()
|
||||
{
|
||||
return m_receiver->getMouseWheel();
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
|
|
|
@ -1096,10 +1096,8 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
|
|||
if (m_autojump)
|
||||
return;
|
||||
|
||||
bool control_forward = keyPressed & (1 << 0);
|
||||
|
||||
bool could_autojump =
|
||||
m_can_jump && !control.jump && !control.sneak && control_forward;
|
||||
m_can_jump && !control.jump && !control.sneak && control.isMoving();
|
||||
|
||||
if (!could_autojump)
|
||||
return;
|
||||
|
|
|
@ -86,7 +86,7 @@ public:
|
|||
v3f last_speed;
|
||||
float last_pitch = 0.0f;
|
||||
float last_yaw = 0.0f;
|
||||
unsigned int last_keyPressed = 0;
|
||||
u32 last_keyPressed = 0;
|
||||
u8 last_camera_fov = 0;
|
||||
u8 last_wanted_range = 0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue