EngineSettings: chunksLoadDistance, chunksPadding

This commit is contained in:
MihailRis
2023-11-06 01:47:17 +03:00
parent 26935473a3
commit 01eb264f44
12 changed files with 79 additions and 53 deletions
+5 -4
View File
@@ -11,15 +11,16 @@
#include "../objects/Player.h"
#include "../objects/player_control.h"
Level::Level(World* world, Player* player, Chunks* chunks, ChunksStorage* chunksStorage, PhysicsSolver* physics, LevelEvents* events) :
Level::Level(World* world, Player* player, ChunksStorage* chunksStorage, LevelEvents* events, uint loadDistance, uint chunksPadding) :
world(world),
player(player),
chunks(chunks),
chunksStorage(chunksStorage),
physics(physics),
events(events) {
physics = new PhysicsSolver(vec3(0, -19.6f, 0));
uint matrixSize = (loadDistance+chunksPadding) * 2;
chunks = new Chunks(matrixSize, matrixSize, 0, 0, events);
lighting = new Lighting(chunks);
chunksController = new ChunksController(this, chunks, lighting);
chunksController = new ChunksController(this, chunks, lighting, chunksPadding);
playerController = new PlayerController(this);
events->listen(EVT_CHUNK_HIDDEN, [this](lvl_event_type type, Chunk* chunk) {
this->chunksStorage->remove(chunk->x, chunk->z);
+8 -2
View File
@@ -1,6 +1,8 @@
#ifndef WORLD_LEVEL_H_
#define WORLD_LEVEL_H_
#include "../typedefs.h"
class World;
class Player;
class Chunks;
@@ -22,11 +24,15 @@ public:
ChunksController* chunksController;
PlayerController* playerController;
LevelEvents* events;
Level(World* world, Player* player, Chunks* chunks, ChunksStorage* chunksStorage, PhysicsSolver* physics, LevelEvents* events);
Level(World* world,
Player* player,
ChunksStorage* chunksStorage,
LevelEvents* events,
uint loadDistance,
uint chunksPadding);
~Level();
void update(float delta, bool interactions);
};
#endif /* WORLD_LEVEL_H_ */
+3 -3
View File
@@ -36,14 +36,14 @@ void World::write(Level* level) {
wfile->writePlayer(level->player);
}
Level* World::loadLevel(Player* player) {
Level* World::loadLevel(Player* player, uint loadDistance, uint chunksPadding) {
ChunksStorage* storage = new ChunksStorage();
LevelEvents* events = new LevelEvents();
Level* level = new Level(this, player, new Chunks(16, 16, 0, 0, events), storage, new PhysicsSolver(vec3(0, -19.6f, 0)), events);
Level* level = new Level(this, player, storage, events, loadDistance, chunksPadding);
wfile->readPlayer(player);
Camera* camera = player->camera;
camera->rotation = mat4(1.0f);
camera->rotate(player->camY, player->camX, 0);
return level;
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
#define WORLD_WORLD_H_
#include <string>
#include "../typedefs.h"
class WorldFiles;
class Chunks;
@@ -18,7 +19,7 @@ public:
~World();
void write(Level* level);
Level* loadLevel(Player* player);
Level* loadLevel(Player* player, uint loadDistance, uint chunksPadding);
};
#endif /* WORLD_WORLD_H_ */