Controllers minor refactor
This commit is contained in:
parent
c0050cffaa
commit
856f5879f1
@ -23,22 +23,7 @@ void LevelController::update(
|
||||
float delta,
|
||||
bool input,
|
||||
bool pause) {
|
||||
if (!pause) {
|
||||
if (input) {
|
||||
player->updateKeyboard();
|
||||
} else {
|
||||
player->resetKeyboard();
|
||||
}
|
||||
player->updateCamera(delta, input);
|
||||
player->updateControls(delta);
|
||||
|
||||
}
|
||||
player->refreshCamera();
|
||||
if (input) {
|
||||
player->updateInteraction();
|
||||
} else {
|
||||
player->selectedBlockId = -1;
|
||||
}
|
||||
player->update(delta, input, pause);
|
||||
level->update();
|
||||
chunks->update(settings.chunks.loadSpeed);
|
||||
}
|
||||
@ -7,7 +7,7 @@ class Level;
|
||||
class ChunksController;
|
||||
class PlayerController;
|
||||
|
||||
/* LevelController - the main game logic controller */
|
||||
/* LevelController manages other controllers */
|
||||
class LevelController {
|
||||
EngineSettings& settings;
|
||||
Level* level;
|
||||
|
||||
@ -115,6 +115,25 @@ PlayerController::PlayerController(Level* level, const EngineSettings& settings)
|
||||
camControl(level->player, settings.camera) {
|
||||
}
|
||||
|
||||
void PlayerController::update(float delta, bool input, bool pause) {
|
||||
if (!pause) {
|
||||
if (input) {
|
||||
updateKeyboard();
|
||||
} else {
|
||||
resetKeyboard();
|
||||
}
|
||||
updateCamera(delta, input);
|
||||
updateControls(delta);
|
||||
|
||||
}
|
||||
refreshCamera();
|
||||
if (input) {
|
||||
updateInteraction();
|
||||
} else {
|
||||
selectedBlockId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerController::updateKeyboard() {
|
||||
input.moveForward = Events::active(BIND_MOVE_FORWARD);
|
||||
input.moveBack = Events::active(BIND_MOVE_BACK);
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
#include "../objects/Player.h"
|
||||
|
||||
class Camera;
|
||||
class Player;
|
||||
class Level;
|
||||
|
||||
class CameraControl {
|
||||
@ -30,17 +29,20 @@ class PlayerController {
|
||||
Player* player;
|
||||
PlayerInput input;
|
||||
CameraControl camControl;
|
||||
public:
|
||||
static glm::vec3 selectedBlockPosition;
|
||||
static int selectedBlockId;
|
||||
|
||||
PlayerController(Level* level, const EngineSettings& settings);
|
||||
void updateKeyboard();
|
||||
void updateCamera(float delta, bool movement);
|
||||
void refreshCamera();
|
||||
void resetKeyboard();
|
||||
void updateControls(float delta);
|
||||
void updateInteraction();
|
||||
|
||||
public:
|
||||
static glm::vec3 selectedBlockPosition;
|
||||
static int selectedBlockId;
|
||||
|
||||
PlayerController(Level* level, const EngineSettings& settings);
|
||||
void update(float delta, bool input, bool pause);
|
||||
};
|
||||
|
||||
#endif /* PLAYER_CONTROL_H_ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user