refactor PlayerController

This commit is contained in:
MihailRis
2024-11-03 12:17:42 +03:00
parent 1777600275
commit 315b4b44e1
3 changed files with 12 additions and 11 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ LevelController::LevelController(Engine* engine, std::unique_ptr<Level> level)
this->level.get(), settings.chunks.padding.get() this->level.get(), settings.chunks.padding.get()
)), )),
player(std::make_unique<PlayerController>( player(std::make_unique<PlayerController>(
engine, this->level.get(), blocks.get() settings, this->level.get(), blocks.get()
)) { )) {
scripting::on_world_load(this); scripting::on_world_load(this);
} }
+7 -7
View File
@@ -6,7 +6,7 @@
#include "content/Content.hpp" #include "content/Content.hpp"
#include "core_defs.hpp" #include "core_defs.hpp"
#include "engine.hpp" #include "settings.hpp"
#include "items/Inventory.hpp" #include "items/Inventory.hpp"
#include "items/ItemDef.hpp" #include "items/ItemDef.hpp"
#include "items/ItemStack.hpp" #include "items/ItemStack.hpp"
@@ -189,12 +189,12 @@ void CameraControl::update(PlayerInput input, float delta, Chunks* chunks) {
} }
PlayerController::PlayerController( PlayerController::PlayerController(
Engine* engine, Level* level, const EngineSettings& settings, Level* level,
BlocksController* blocksController BlocksController* blocksController
) )
: engine(engine), level(level), : settings(settings), level(level),
player(level->getObject<Player>(0)), player(level->getObject<Player>(0)),
camControl(player, engine->getSettings().camera), camControl(player, settings.camera),
blocksController(blocksController) { blocksController(blocksController) {
} }
@@ -263,7 +263,7 @@ void PlayerController::postUpdate(float delta, bool input, bool pause) {
player->postUpdate(); player->postUpdate();
camControl.update(this->input, pause ? 0.0f : delta, level->chunks.get()); camControl.update(this->input, pause ? 0.0f : delta, level->chunks.get());
if (input) { if (input) {
updateInteraction(); updateInteraction(delta);
} else { } else {
player->selection = {}; player->selection = {};
} }
@@ -481,13 +481,13 @@ void PlayerController::updateEntityInteraction(
} }
} }
void PlayerController::updateInteraction() { void PlayerController::updateInteraction(float delta) {
auto indices = level->content->getIndices(); auto indices = level->content->getIndices();
auto chunks = level->chunks.get(); auto chunks = level->chunks.get();
const auto& selection = player->selection; const auto& selection = player->selection;
if (interactionTimer > 0.0f) { if (interactionTimer > 0.0f) {
interactionTimer -= static_cast<float>(engine->getDelta()); interactionTimer -= delta;
} }
bool xkey = Events::active(BIND_PLAYER_FAST_INTERACTOIN); bool xkey = Events::active(BIND_PLAYER_FAST_INTERACTOIN);
float maxDistance = xkey ? 200.0f : 10.0f; float maxDistance = xkey ? 200.0f : 10.0f;
+4 -3
View File
@@ -14,6 +14,7 @@ class Chunks;
class BlocksController; class BlocksController;
struct Hitbox; struct Hitbox;
struct CameraSettings; struct CameraSettings;
struct EngineSettings;
class CameraControl { class CameraControl {
std::shared_ptr<Player> player; std::shared_ptr<Player> player;
@@ -46,7 +47,7 @@ public:
}; };
class PlayerController { class PlayerController {
Engine* engine; const EngineSettings& settings;
Level* level; Level* level;
std::shared_ptr<Player> player; std::shared_ptr<Player> player;
PlayerInput input {}; PlayerInput input {};
@@ -58,7 +59,7 @@ class PlayerController {
void resetKeyboard(); void resetKeyboard();
void updatePlayer(float delta); void updatePlayer(float delta);
void updateEntityInteraction(entityid_t eid, bool lclick, bool rclick); void updateEntityInteraction(entityid_t eid, bool lclick, bool rclick);
void updateInteraction(); void updateInteraction(float delta);
float stepsTimer = 0.0f; float stepsTimer = 0.0f;
void onFootstep(const Hitbox& hitbox); void onFootstep(const Hitbox& hitbox);
@@ -68,7 +69,7 @@ class PlayerController {
voxel* updateSelection(float maxDistance); voxel* updateSelection(float maxDistance);
public: public:
PlayerController( PlayerController(
Engine* engine, Level* level, BlocksController* blocksController const EngineSettings& settings, Level* level, BlocksController* blocksController
); );
void update(float delta, bool input, bool pause); void update(float delta, bool input, bool pause);
void postUpdate(float delta, bool input, bool pause); void postUpdate(float delta, bool input, bool pause);