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

View File

@ -26,7 +26,7 @@ LevelController::LevelController(Engine* engine, std::unique_ptr<Level> level)
this->level.get(), settings.chunks.padding.get()
)),
player(std::make_unique<PlayerController>(
engine, this->level.get(), blocks.get()
settings, this->level.get(), blocks.get()
)) {
scripting::on_world_load(this);
}

View File

@ -6,7 +6,7 @@
#include "content/Content.hpp"
#include "core_defs.hpp"
#include "engine.hpp"
#include "settings.hpp"
#include "items/Inventory.hpp"
#include "items/ItemDef.hpp"
#include "items/ItemStack.hpp"
@ -189,12 +189,12 @@ void CameraControl::update(PlayerInput input, float delta, Chunks* chunks) {
}
PlayerController::PlayerController(
Engine* engine, Level* level,
const EngineSettings& settings, Level* level,
BlocksController* blocksController
)
: engine(engine), level(level),
: settings(settings), level(level),
player(level->getObject<Player>(0)),
camControl(player, engine->getSettings().camera),
camControl(player, settings.camera),
blocksController(blocksController) {
}
@ -263,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 = {};
}
@ -481,13 +481,13 @@ 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;
if (interactionTimer > 0.0f) {
interactionTimer -= static_cast<float>(engine->getDelta());
interactionTimer -= delta;
}
bool xkey = Events::active(BIND_PLAYER_FAST_INTERACTOIN);
float maxDistance = xkey ? 200.0f : 10.0f;

View File

@ -14,6 +14,7 @@ class Chunks;
class BlocksController;
struct Hitbox;
struct CameraSettings;
struct EngineSettings;
class CameraControl {
std::shared_ptr<Player> player;
@ -46,7 +47,7 @@ public:
};
class PlayerController {
Engine* engine;
const EngineSettings& settings;
Level* level;
std::shared_ptr<Player> player;
PlayerInput input {};
@ -58,7 +59,7 @@ class PlayerController {
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);
@ -68,7 +69,7 @@ class PlayerController {
voxel* updateSelection(float maxDistance);
public:
PlayerController(
Engine* engine, Level* level, 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);