General refactor
This commit is contained in:
+1
-30
@@ -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
@@ -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
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user