move PlayerController to LevelScreen

This commit is contained in:
MihailRis
2024-12-11 23:42:59 +03:00
parent 9adaf6d527
commit 863146cf6b
7 changed files with 66 additions and 64 deletions
+3 -35
View File
@@ -5,14 +5,14 @@
#include "debug/Logger.hpp"
#include "engine.hpp"
#include "files/WorldFiles.hpp"
#include "maths/voxmaths.hpp"
#include "objects/Entities.hpp"
#include "objects/Players.hpp"
#include "physics/Hitbox.hpp"
#include "scripting/scripting.hpp"
#include "settings.hpp"
#include "world/Level.hpp"
#include "world/World.hpp"
#include "maths/voxmaths.hpp"
#include "scripting/scripting.hpp"
static debug::Logger logger("level-control");
@@ -25,41 +25,17 @@ LevelController::LevelController(Engine* engine, std::unique_ptr<Level> levelPtr
chunks(std::make_unique<ChunksController>(
*level, settings.chunks.padding.get()
)) {
if (!engine->isHeadless()) {
player = std::make_unique<PlayerController>(
settings, level.get(), level->players->get(0), blocks.get()
);
}
scripting::on_world_load(this);
}
void LevelController::update(float delta, bool input, bool pause) {
if (player) {
glm::vec3 position = player->getPlayer()->getPosition();
level->loadMatrix(
position.x,
position.z,
settings.chunks.loadDistance.get() + settings.chunks.padding.get() * 2
);
chunks->update(
settings.chunks.loadSpeed.get(), settings.chunks.loadDistance.get(),
floordiv(position.x, CHUNK_W), floordiv(position.z, CHUNK_D)
);
}
void LevelController::update(float delta, bool pause) {
if (!pause) {
// update all objects that needed
blocks->update(delta);
if (player) {
player->update(delta, input);
}
level->entities->updatePhysics(delta);
level->entities->update(delta);
}
level->entities->clean();
if (player) {
player->postUpdate(delta, input, pause);
}
}
void LevelController::saveWorld() {
@@ -79,10 +55,6 @@ Level* LevelController::getLevel() {
return level.get();
}
Player* LevelController::getPlayer() {
return player->getPlayer();
}
BlocksController* LevelController::getBlocksController() {
return blocks.get();
}
@@ -90,7 +62,3 @@ BlocksController* LevelController::getBlocksController() {
ChunksController* LevelController::getChunksController() {
return chunks.get();
}
PlayerController* LevelController::getPlayerController() {
return player.get();
}