Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Sneak and Aux1 optionally togglable #15785

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ doubletap_jump (Double tap jump for fly) bool false
# enabled.
always_fly_fast (Always fly fast) bool true

# If enabled, the "Sneak" key will toggle when pressed. Only affects player movement.
toggle_sneak_key (Toggle sneak key) bool false

# If enabled, the "Aux1" key will toggle when pressed. Only affects player movement.
toggle_aux1_key (Toggle aux1 key) bool false

# The time in seconds it takes between repeated node placements when holding
# the place button.
#
Expand Down
27 changes: 25 additions & 2 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ class Game {
bool m_cache_enable_fog;
bool m_cache_enable_noclip;
bool m_cache_enable_free_move;
bool m_cache_toggle_aux1_key;
bool m_cache_toggle_sneak_key;
f32 m_cache_mouse_sensitivity;
f32 m_cache_joystick_frustum_sensitivity;
f32 m_repeat_place_time;
Expand Down Expand Up @@ -789,6 +791,10 @@ Game::Game() :
&settingChangedCallback, this);
g_settings->registerChangedCallback("doubletap_jump",
&settingChangedCallback, this);
g_settings->registerChangedCallback("toggle_sneak_key",
&settingChangedCallback, this);
g_settings->registerChangedCallback("toggle_aux1_key",
&settingChangedCallback, this);
g_settings->registerChangedCallback("enable_joysticks",
&settingChangedCallback, this);
g_settings->registerChangedCallback("enable_fog",
Expand Down Expand Up @@ -2442,15 +2448,30 @@ void Game::updatePlayerControl(const CameraOrientation &cam)
LocalPlayer *player = client->getEnv().getLocalPlayer();

//TimeTaker tt("update player control", NULL, PRECISION_NANO);
bool sneak_state = false;
if (!m_cache_toggle_sneak_key){
sneak_state = isKeyDown(KeyType::SNEAK);
} else {
sneak_state = player->control.sneak;
if (wasKeyPressed(KeyType::SNEAK)) sneak_state = !sneak_state;
}
bool aux1_state = false;
if (!m_cache_toggle_aux1_key){
aux1_state = isKeyDown(KeyType::AUX1);
} else {
aux1_state = player->control.aux1;
if (wasKeyPressed(KeyType::AUX1)) aux1_state = !aux1_state;
}


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),
aux1_state, //isKeyDown(KeyType::AUX1),
sneak_state, //isKeyDown(KeyType::SNEAK),
isKeyDown(KeyType::ZOOM),
isKeyDown(KeyType::DIG),
isKeyDown(KeyType::PLACE),
Expand Down Expand Up @@ -4111,6 +4132,8 @@ void Game::readSettings()

m_cache_enable_noclip = g_settings->getBool("noclip");
m_cache_enable_free_move = g_settings->getBool("free_move");
m_cache_toggle_sneak_key = g_settings->getBool("toggle_sneak_key");
m_cache_toggle_aux1_key = g_settings->getBool("toggle_aux1_key");

m_cache_cam_smoothing = 0;
if (g_settings->getBool("cinematic"))
Expand Down
2 changes: 2 additions & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ void set_default_settings()
settings->setDefault("aux1_descends", "false");
settings->setDefault("doubletap_jump", "false");
settings->setDefault("always_fly_fast", "true");
settings->setDefault("toggle_sneak_key", "false");
settings->setDefault("toggle_aux1_key", "false");
settings->setDefault("autojump", bool_to_cstr(has_touch));
settings->setDefault("continuous_forward", "false");
settings->setDefault("enable_joysticks", "false");
Expand Down
3 changes: 3 additions & 0 deletions src/gettext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ void init_gettext(const char *path, const std::string &configured_language,
SetEnvironmentVariableA("LANGUAGE", configured_language.c_str());

#if CHECK_CLIENT_BUILD()
#if NDEBUG
// Hack to force gettext to see the right environment
// Disabled during debug as it can break debugging
if (current_language != configured_language)
MSVC_LocaleWorkaround(argc, argv);
#endif
#else
errorstream << "*******************************************************" << std::endl;
errorstream << "Can't apply locale workaround for server!" << std::endl;
Expand Down
13 changes: 7 additions & 6 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,13 @@ u32 PlayerControl::getKeysPressed() const
void PlayerControl::unpackKeysPressed(u32 keypress_bits)
{
direction_keys = keypress_bits & 0xf;
jump = keypress_bits & (1 << 4);
aux1 = keypress_bits & (1 << 5);
sneak = keypress_bits & (1 << 6);
dig = keypress_bits & (1 << 7);
place = keypress_bits & (1 << 8);
zoom = keypress_bits & (1 << 9);
jump = keypress_bits & (1 << 4);
aux1 = keypress_bits & (1 << 5);
sneak = keypress_bits & (1 << 6);
dig = keypress_bits & (1 << 7);
place = keypress_bits & (1 << 8);
zoom = keypress_bits & (1 << 9);

}

v2f PlayerControl::getMovement() const
Expand Down
1 change: 1 addition & 0 deletions src/script/common/c_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <vector>
#include <string_view>
#include <string>

#include "irrlichttypes_bloated.h"

Expand Down
1 change: 1 addition & 0 deletions src/script/common/c_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#pragma once

#include <string_view>
#include <string>

extern "C" {
#include <lua.h>
Expand Down
1 change: 1 addition & 0 deletions src/script/lua_api/l_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "log.h"

#include <iomanip>
#include <string>

#define HTTP_API(name) \
lua_pushstring(L, #name); \
Expand Down