aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2022-01-09 18:46:36 +0100
committerGitHub <noreply@github.com>2022-01-09 18:46:36 +0100
commit5eb45e1ea03c6104f007efec6dd9c351f310193d (patch)
tree28a40addf99493aedfbf67e4d85fa6cf88723419 /src/client
parent76dbd0d2d04712dcad4f7c6afecb97fa8d662d6d (diff)
downloadhax-minetest-server-5eb45e1ea03c6104f007efec6dd9c351f310193d.tar.gz
hax-minetest-server-5eb45e1ea03c6104f007efec6dd9c351f310193d.zip
Restore pass-through of direction keys (#11924)
This moves relevant code into the PlayerControl class and gets rid of separate keyPressed variable.
Diffstat (limited to 'src/client')
-rw-r--r--src/client/client.cpp16
-rw-r--r--src/client/clientlauncher.cpp4
-rw-r--r--src/client/game.cpp36
-rw-r--r--src/client/inputhandler.h50
-rw-r--r--src/client/localplayer.cpp4
-rw-r--r--src/client/localplayer.h2
6 files changed, 53 insertions, 59 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 2caa953e4..d4c271bab 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -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;
diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp
index 95be72ca0..063154316 100644
--- a/src/client/clientlauncher.cpp
+++ b/src/client/clientlauncher.cpp
@@ -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;
diff --git a/src/client/game.cpp b/src/client/game.cpp
index f62d26e8f..182dc3815 100644
--- a/src/client/game.cpp
+++ b/src/client/game.cpp
@@ -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();
}
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index e630b860e..3db105c51 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -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()
{
diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp
index 3f78d201d..4f1ea7bda 100644
--- a/src/client/localplayer.cpp
+++ b/src/client/localplayer.cpp
@@ -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;
diff --git a/src/client/localplayer.h b/src/client/localplayer.h
index 13b35ae4e..577be2803 100644
--- a/src/client/localplayer.h
+++ b/src/client/localplayer.h
@@ -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;