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