diff --git a/res/config/bindings.toml b/res/config/bindings.toml index 2d373cb9..a0ab278f 100644 --- a/res/config/bindings.toml +++ b/res/config/bindings.toml @@ -16,4 +16,5 @@ player.attack="mouse:left" player.build="mouse:right" player.pick="mouse:middle" player.drop="key:q" +player.fast_interaction="key:x" hud.inventory="key:tab" diff --git a/res/texts/en_US.txt b/res/texts/en_US.txt index 3f6d1c74..40c684a4 100644 --- a/res/texts/en_US.txt +++ b/res/texts/en_US.txt @@ -31,6 +31,7 @@ hud.inventory=Inventory player.pick=Pick Block player.attack=Attack / Break player.build=Place Block +player.fast_interaction=Accelerated interaction player.flight=Flight player.noclip=No-clip player.drop=Drop Item diff --git a/res/texts/ru_RU.txt b/res/texts/ru_RU.txt index df8f945e..53368e92 100644 --- a/res/texts/ru_RU.txt +++ b/res/texts/ru_RU.txt @@ -92,6 +92,7 @@ hud.inventory=Инвентарь player.pick=Подобрать Блок player.attack=Атаковать / Сломать player.build=Поставить Блок +player.fast_interaction=Ускоренное взаимодействие player.flight=Полёт player.drop=Выбросить Предмет camera.zoom=Приближение diff --git a/src/core_defs.hpp b/src/core_defs.hpp index 0f25de3a..c2b5dd39 100644 --- a/src/core_defs.hpp +++ b/src/core_defs.hpp @@ -27,6 +27,8 @@ inline const std::string BIND_PLAYER_FLIGHT = "player.flight"; inline const std::string BIND_PLAYER_ATTACK = "player.attack"; inline const std::string BIND_PLAYER_BUILD = "player.build"; inline const std::string BIND_PLAYER_PICK = "player.pick"; +inline const std::string BIND_PLAYER_FAST_INTERACTOIN = + "player.fast_interaction"; inline const std::string BIND_HUD_INVENTORY = "hud.inventory"; class EnginePaths; diff --git a/src/frontend/screens/LevelScreen.cpp b/src/frontend/screens/LevelScreen.cpp index 8824d640..c0d4aa88 100644 --- a/src/frontend/screens/LevelScreen.cpp +++ b/src/frontend/screens/LevelScreen.cpp @@ -37,7 +37,7 @@ LevelScreen::LevelScreen(Engine* engine, std::unique_ptr level) auto menu = engine->getGUI()->getMenu(); menu->reset(); - controller = std::make_unique(settings, std::move(level)); + controller = std::make_unique(engine, std::move(level)); frontend = std::make_unique(controller->getPlayer(), controller.get(), assets); worldRenderer = std::make_unique(engine, frontend.get(), controller->getPlayer()); diff --git a/src/logic/LevelController.cpp b/src/logic/LevelController.cpp index f0bee4c5..2cd491d4 100644 --- a/src/logic/LevelController.cpp +++ b/src/logic/LevelController.cpp @@ -3,6 +3,7 @@ #include #include "debug/Logger.hpp" +#include "engine.hpp" #include "files/WorldFiles.hpp" #include "interfaces/Object.hpp" #include "objects/Entities.hpp" @@ -15,10 +16,8 @@ static debug::Logger logger("level-control"); -LevelController::LevelController( - EngineSettings& settings, std::unique_ptr level -) - : settings(settings), +LevelController::LevelController(Engine* engine, std::unique_ptr level) + : settings(engine->getSettings()), level(std::move(level)), blocks(std::make_unique( this->level.get(), settings.chunks.padding.get() @@ -27,7 +26,7 @@ LevelController::LevelController( this->level.get(), settings.chunks.padding.get() )), player(std::make_unique( - this->level.get(), settings, blocks.get() + settings, this->level.get(), blocks.get() )) { scripting::on_world_load(this); } diff --git a/src/logic/LevelController.hpp b/src/logic/LevelController.hpp index a2c5af3e..94e0ac2c 100644 --- a/src/logic/LevelController.hpp +++ b/src/logic/LevelController.hpp @@ -6,6 +6,7 @@ #include "ChunksController.hpp" #include "PlayerController.hpp" +class Engine; class Level; class Player; struct EngineSettings; @@ -19,7 +20,7 @@ class LevelController { std::unique_ptr chunks; std::unique_ptr player; public: - LevelController(EngineSettings& settings, std::unique_ptr level); + LevelController(Engine* engine, std::unique_ptr level); /// @param delta time elapsed since the last update /// @param input is user input allowed to be handled diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 64e2a40c..00e4d1a7 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -6,6 +6,7 @@ #include "content/Content.hpp" #include "core_defs.hpp" +#include "settings.hpp" #include "items/Inventory.hpp" #include "items/ItemDef.hpp" #include "items/ItemStack.hpp" @@ -26,6 +27,7 @@ #include "BlocksController.hpp" #include "scripting/scripting.hpp" +const float INTERACTION_RELOAD = 0.160f; const float STEPS_SPEED = 2.2f; const float CAM_SHAKE_OFFSET = 0.0075f; const float CAM_SHAKE_OFFSET_Y = 0.031f; @@ -187,11 +189,10 @@ void CameraControl::update(PlayerInput input, float delta, Chunks* chunks) { } PlayerController::PlayerController( - Level* level, - const EngineSettings& settings, + const EngineSettings& settings, Level* level, BlocksController* blocksController ) - : level(level), + : settings(settings), level(level), player(level->getObject(0)), camControl(player, settings.camera), blocksController(blocksController) { @@ -262,7 +263,7 @@ void PlayerController::postUpdate(float delta, bool input, bool pause) { player->postUpdate(); camControl.update(this->input, pause ? 0.0f : delta, level->chunks.get()); if (input) { - updateInteraction(); + updateInteraction(delta); } else { player->selection = {}; } @@ -480,17 +481,24 @@ void PlayerController::updateEntityInteraction( } } -void PlayerController::updateInteraction() { +void PlayerController::updateInteraction(float delta) { auto indices = level->content->getIndices(); auto chunks = level->chunks.get(); const auto& selection = player->selection; - - bool xkey = Events::pressed(keycode::X); - bool lclick = Events::jactive(BIND_PLAYER_ATTACK) || - (xkey && Events::active(BIND_PLAYER_ATTACK)); - bool rclick = Events::jactive(BIND_PLAYER_BUILD) || - (xkey && Events::active(BIND_PLAYER_BUILD)); + + if (interactionTimer > 0.0f) { + interactionTimer -= delta; + } + bool xkey = Events::active(BIND_PLAYER_FAST_INTERACTOIN); float maxDistance = xkey ? 200.0f : 10.0f; + bool longInteraction = interactionTimer <= 0 || xkey; + bool lclick = Events::jactive(BIND_PLAYER_ATTACK) || + (longInteraction && Events::active(BIND_PLAYER_ATTACK)); + bool rclick = Events::jactive(BIND_PLAYER_BUILD) || + (longInteraction && Events::active(BIND_PLAYER_BUILD)); + if (lclick || rclick) { + interactionTimer = INTERACTION_RELOAD; + } auto inventory = player->getInventory(); const ItemStack& stack = inventory->getSlot(player->getChosenSlot()); diff --git a/src/logic/PlayerController.hpp b/src/logic/PlayerController.hpp index 306e2336..6affa43d 100644 --- a/src/logic/PlayerController.hpp +++ b/src/logic/PlayerController.hpp @@ -6,6 +6,7 @@ #include "objects/Player.hpp" +class Engine; class Camera; class Level; class Block; @@ -13,6 +14,7 @@ class Chunks; class BlocksController; struct Hitbox; struct CameraSettings; +struct EngineSettings; class CameraControl { std::shared_ptr player; @@ -45,17 +47,19 @@ public: }; class PlayerController { + const EngineSettings& settings; Level* level; std::shared_ptr player; PlayerInput input {}; CameraControl camControl; BlocksController* blocksController; + float interactionTimer = 0.0f; void updateKeyboard(); void resetKeyboard(); void updatePlayer(float delta); void updateEntityInteraction(entityid_t eid, bool lclick, bool rclick); - void updateInteraction(); + void updateInteraction(float delta); float stepsTimer = 0.0f; void onFootstep(const Hitbox& hitbox); @@ -65,9 +69,7 @@ class PlayerController { voxel* updateSelection(float maxDistance); public: PlayerController( - Level* level, - const EngineSettings& settings, - BlocksController* blocksController + const EngineSettings& settings, Level* level, BlocksController* blocksController ); void update(float delta, bool input, bool pause); void postUpdate(float delta, bool input, bool pause);