Refactor and fixes

This commit is contained in:
MihailRis
2023-11-12 02:44:02 +03:00
parent b4a3608302
commit 63b5f4bc6b
25 changed files with 394 additions and 278 deletions
+27 -11
View File
@@ -11,17 +11,20 @@
#include "../objects/Player.h"
#include "../objects/player_control.h"
Level::Level(World* world, Player* player, ChunksStorage* chunksStorage, LevelEvents* events, uint loadDistance, uint chunksPadding) :
Level::Level(World* world, Player* player, ChunksStorage* chunksStorage, LevelEvents* events, EngineSettings& settings) :
world(world),
player(player),
chunksStorage(chunksStorage),
events(events) {
physics = new PhysicsSolver(vec3(0, -19.6f, 0));
uint matrixSize = (loadDistance+chunksPadding) * 2;
uint matrixSize = (settings.chunks.loadDistance+
settings.chunks.padding) * 2;
chunks = new Chunks(matrixSize, matrixSize, 0, 0, world->wfile, events);
lighting = new Lighting(chunks);
chunksController = new ChunksController(this, chunks, lighting, chunksPadding);
playerController = new PlayerController(this);
chunksController = new ChunksController(this, chunks, lighting, settings.chunks.padding);
playerController = new PlayerController(this, settings);
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
this->chunksStorage->remove(chunk->x, chunk->z);
});
@@ -38,16 +41,29 @@ Level::~Level(){
delete playerController;
}
void Level::update(float delta, bool updatePlayer, bool interactions) {
if (updatePlayer)
playerController->update_controls(delta, updatePlayer);
if (interactions) {
playerController->update_interaction();
void Level::updatePlayer(float delta,
bool input,
bool pause,
bool interactions) {
if (!pause) {
if (input) {
playerController->updateKeyboard();
playerController->updateCameraControl();
} else {
playerController->resetKeyboard();
}
playerController->updateControls(delta);
}
else
{
playerController->refreshCamera();
if (interactions) {
playerController->updateInteraction();
} else {
playerController->selectedBlockId = -1;
}
}
void Level::update() {
vec3 position = player->hitbox->position;
chunks->setCenter(position.x, position.z);
}