General refactor

This commit is contained in:
MihailRis
2023-11-30 04:30:40 +03:00
parent de134dc2e5
commit 1d5037893c
27 changed files with 558 additions and 419 deletions
+1 -30
View File
@@ -5,12 +5,10 @@
#include "../lighting/Lighting.h"
#include "../voxels/Chunk.h"
#include "../voxels/Chunks.h"
#include "../voxels/ChunksController.h"
#include "../voxels/ChunksStorage.h"
#include "../physics/Hitbox.h"
#include "../physics/PhysicsSolver.h"
#include "../objects/Player.h"
#include "../objects/player_control.h"
Level::Level(World* world, const Content* content, Player* player, EngineSettings& settings)
: world(world),
@@ -30,9 +28,6 @@ Level::Level(World* world, const Content* content, Player* player, EngineSetting
events,
content);
lighting = new Lighting(content, chunks);
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);
@@ -45,31 +40,7 @@ Level::~Level(){
delete physics;
delete player;
delete lighting;
delete chunksController;
delete chunksStorage;
delete playerController;
}
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);
}
playerController->refreshCamera();
if (interactions) {
playerController->updateInteraction();
} else {
playerController->selectedBlockId = -1;
}
}
void Level::update() {
@@ -77,7 +48,7 @@ void Level::update() {
chunks->setCenter(position.x, position.z);
int matrixSize = (settings.chunks.loadDistance+
settings.chunks.padding) * 2;
settings.chunks.padding) * 2;
if (chunks->w != matrixSize) {
chunks->resize(matrixSize, matrixSize);
}
+2 -7
View File
@@ -24,11 +24,11 @@ public:
Player* player;
Chunks* chunks;
ChunksStorage* chunksStorage;
PhysicsSolver* physics;
Lighting* lighting;
ChunksController* chunksController;
PlayerController* playerController;
LevelEvents* events;
const EngineSettings& settings;
Level(World* world,
@@ -37,11 +37,6 @@ public:
EngineSettings& settings);
~Level();
void updatePlayer(float delta,
bool input,
bool pause,
bool interactions);
void update();
};
+4 -8
View File
@@ -46,25 +46,21 @@ void World::write(Level* level) {
wfile->put(chunk.get());
}
wfile->write(WorldInfo {name, wfile->directory, seed, daytime, daytimeSpeed}, content);
wfile->write(this, content);
wfile->writePlayer(level->player);
}
Level* World::load(EngineSettings& settings, const Content* content) {
WorldInfo info {name, wfile->directory, seed, daytime, daytimeSpeed};
wfile->readWorldInfo(info);
seed = info.seed;
name = info.name;
daytime = info.daytime;
daytimeSpeed = info.daytimeSpeed;
wfile->readWorldInfo(this);
vec3 playerPosition = vec3(0, 100, 0);
Camera* camera = new Camera(playerPosition, glm::radians(90.0f));
Player* player = new Player(playerPosition, 4.0f, camera);
Level* level = new Level(this, content, player, settings);
wfile->readPlayer(player);
camera->rotation = mat4(1.0f);
camera->rotation = glm::mat4(1.0f);
camera->rotate(player->camY, player->camX, 0);
return level;
}