the final rename
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
#ifndef PLAYER_CONTROL_HPP_
|
||||
#define PLAYER_CONTROL_HPP_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "../settings.hpp"
|
||||
#include "../objects/Player.hpp"
|
||||
|
||||
class Camera;
|
||||
class Level;
|
||||
class Block;
|
||||
class BlocksController;
|
||||
|
||||
class CameraControl {
|
||||
std::shared_ptr<Player> player;
|
||||
std::shared_ptr<Camera> camera;
|
||||
const CameraSettings& settings;
|
||||
glm::vec3 offset;
|
||||
float shake = 0.0f;
|
||||
float shakeTimer = 0.0f;
|
||||
glm::vec3 interpVel {0.0f};
|
||||
|
||||
/// @brief Update shaking timer and calculate camera offset
|
||||
/// @param delta delta time
|
||||
/// @return camera offset
|
||||
glm::vec3 updateCameraShaking(float delta);
|
||||
|
||||
/// @brief Update field-of-view effects
|
||||
/// @param input player inputs
|
||||
/// @param delta delta time
|
||||
void updateFovEffects(const PlayerInput& input, float delta);
|
||||
|
||||
/// @brief Switch active player camera
|
||||
void switchCamera();
|
||||
public:
|
||||
CameraControl(std::shared_ptr<Player> player, const CameraSettings& settings);
|
||||
void updateMouse(PlayerInput& input);
|
||||
void update(PlayerInput& input, float delta, Chunks* chunks);
|
||||
void refresh();
|
||||
};
|
||||
|
||||
enum class BlockInteraction {
|
||||
step,
|
||||
destruction,
|
||||
placing
|
||||
};
|
||||
|
||||
using on_block_interaction = std::function<void(
|
||||
Player*, glm::ivec3, const Block*, BlockInteraction type
|
||||
)>;
|
||||
|
||||
class PlayerController {
|
||||
Level* level;
|
||||
std::shared_ptr<Player> player;
|
||||
PlayerInput input;
|
||||
CameraControl camControl;
|
||||
BlocksController* blocksController;
|
||||
|
||||
std::vector<on_block_interaction> blockInteractionCallbacks;
|
||||
|
||||
void updateKeyboard();
|
||||
void updateCamera(float delta, bool movement);
|
||||
void resetKeyboard();
|
||||
void updateControls(float delta);
|
||||
void updateInteraction();
|
||||
void onBlockInteraction(
|
||||
glm::ivec3 pos,
|
||||
const Block* def,
|
||||
BlockInteraction type
|
||||
);
|
||||
|
||||
float stepsTimer = 0.0f;
|
||||
void onFootstep();
|
||||
void updateFootsteps(float delta);
|
||||
public:
|
||||
static glm::vec3 selectedBlockPosition;
|
||||
static glm::ivec3 selectedBlockNormal;
|
||||
static glm::vec3 selectedPointPosition;
|
||||
static int selectedBlockId;
|
||||
static int selectedBlockStates;
|
||||
|
||||
PlayerController(
|
||||
Level* level,
|
||||
const EngineSettings& settings,
|
||||
BlocksController* blocksController
|
||||
);
|
||||
void update(float delta, bool input, bool pause);
|
||||
|
||||
Player* getPlayer();
|
||||
|
||||
void listenBlockInteraction(on_block_interaction callback);
|
||||
};
|
||||
|
||||
#endif /* PLAYER_CONTROL_HPP_ */
|
||||
Reference in New Issue
Block a user