Refactor and fixes
This commit is contained in:
+27
-11
@@ -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);
|
||||
}
|
||||
|
||||
+9
-3
@@ -2,6 +2,7 @@
|
||||
#define WORLD_LEVEL_H_
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include "../settings.h"
|
||||
|
||||
class World;
|
||||
class Player;
|
||||
@@ -24,15 +25,20 @@ public:
|
||||
ChunksController* chunksController;
|
||||
PlayerController* playerController;
|
||||
LevelEvents* events;
|
||||
|
||||
Level(World* world,
|
||||
Player* player,
|
||||
ChunksStorage* chunksStorage,
|
||||
LevelEvents* events,
|
||||
uint loadDistance,
|
||||
uint chunksPadding);
|
||||
EngineSettings& settings);
|
||||
~Level();
|
||||
|
||||
void update(float delta, bool updatePlayer, bool interactions);
|
||||
void updatePlayer(float delta,
|
||||
bool input,
|
||||
bool pause,
|
||||
bool interactions);
|
||||
|
||||
void update();
|
||||
};
|
||||
|
||||
#endif /* WORLD_LEVEL_H_ */
|
||||
|
||||
+2
-2
@@ -36,10 +36,10 @@ void World::write(Level* level) {
|
||||
wfile->writePlayer(level->player);
|
||||
}
|
||||
|
||||
Level* World::loadLevel(Player* player, uint loadDistance, uint chunksPadding) {
|
||||
Level* World::loadLevel(Player* player, EngineSettings& settings) {
|
||||
ChunksStorage* storage = new ChunksStorage();
|
||||
LevelEvents* events = new LevelEvents();
|
||||
Level* level = new Level(this, player, storage, events, loadDistance, chunksPadding);
|
||||
Level* level = new Level(this, player, storage, events, settings);
|
||||
wfile->readPlayer(player);
|
||||
|
||||
Camera* camera = player->camera;
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <string>
|
||||
#include "../typedefs.h"
|
||||
#include "../settings.h"
|
||||
|
||||
class WorldFiles;
|
||||
class Chunks;
|
||||
@@ -19,7 +20,7 @@ public:
|
||||
~World();
|
||||
|
||||
void write(Level* level);
|
||||
Level* loadLevel(Player* player, uint loadDistance, uint chunksPadding);
|
||||
Level* loadLevel(Player* player, EngineSettings& settings);
|
||||
};
|
||||
|
||||
#endif /* WORLD_WORLD_H_ */
|
||||
|
||||
Reference in New Issue
Block a user