EngineSettings: chunksLoadDistance, chunksPadding
This commit is contained in:
parent
26935473a3
commit
01eb264f44
@ -20,7 +20,6 @@ int _png_load(const char* file, int* width, int* height){
|
||||
png_bytepp row_pointers;
|
||||
png_structp png_ptr;
|
||||
GLuint texture;
|
||||
GLuint texturems;
|
||||
int alpha;
|
||||
|
||||
if ( !( f = fopen(file, "r" ) ) ) {
|
||||
|
||||
@ -4,20 +4,20 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "typedefs.h"
|
||||
#include "assets/Assets.h"
|
||||
#include "graphics/Shader.h"
|
||||
#include "graphics/Batch2D.h"
|
||||
#include "graphics/Font.h"
|
||||
#include "graphics/Mesh.h"
|
||||
#include "window/Camera.h"
|
||||
#include "window/Window.h"
|
||||
#include "window/Events.h"
|
||||
#include "voxels/Chunks.h"
|
||||
#include "voxels/Block.h"
|
||||
#include "world/World.h"
|
||||
#include "world/Level.h"
|
||||
#include "objects/Player.h"
|
||||
#include "../typedefs.h"
|
||||
#include "../assets/Assets.h"
|
||||
#include "../graphics/Shader.h"
|
||||
#include "../graphics/Batch2D.h"
|
||||
#include "../graphics/Font.h"
|
||||
#include "../graphics/Mesh.h"
|
||||
#include "../window/Camera.h"
|
||||
#include "../window/Window.h"
|
||||
#include "../window/Events.h"
|
||||
#include "../voxels/Chunks.h"
|
||||
#include "../voxels/Block.h"
|
||||
#include "../world/World.h"
|
||||
#include "../world/Level.h"
|
||||
#include "../objects/Player.h"
|
||||
|
||||
|
||||
HudRenderer::HudRenderer() {
|
||||
@ -4,23 +4,23 @@
|
||||
#include <GL/glew.h>
|
||||
#include <memory>
|
||||
|
||||
#include "graphics/ChunksRenderer.h"
|
||||
#include "window/Window.h"
|
||||
#include "window/Camera.h"
|
||||
#include "graphics/Mesh.h"
|
||||
#include "graphics/Shader.h"
|
||||
#include "graphics/Texture.h"
|
||||
#include "graphics/LineBatch.h"
|
||||
#include "graphics/Batch3D.h"
|
||||
#include "voxels/Chunks.h"
|
||||
#include "voxels/Chunk.h"
|
||||
#include "voxels/Block.h"
|
||||
#include "world/World.h"
|
||||
#include "world/Level.h"
|
||||
#include "world/LevelEvents.h"
|
||||
#include "objects/Player.h"
|
||||
#include "assets/Assets.h"
|
||||
#include "objects/player_control.h"
|
||||
#include "../graphics/ChunksRenderer.h"
|
||||
#include "../window/Window.h"
|
||||
#include "../window/Camera.h"
|
||||
#include "../graphics/Mesh.h"
|
||||
#include "../graphics/Shader.h"
|
||||
#include "../graphics/Texture.h"
|
||||
#include "../graphics/LineBatch.h"
|
||||
#include "../graphics/Batch3D.h"
|
||||
#include "../voxels/Chunks.h"
|
||||
#include "../voxels/Chunk.h"
|
||||
#include "../voxels/Block.h"
|
||||
#include "../world/World.h"
|
||||
#include "../world/Level.h"
|
||||
#include "../world/LevelEvents.h"
|
||||
#include "../objects/Player.h"
|
||||
#include "../assets/Assets.h"
|
||||
#include "../objects/player_control.h"
|
||||
|
||||
using std::shared_ptr;
|
||||
|
||||
@ -32,8 +32,8 @@
|
||||
#include "definitions.h"
|
||||
#include "assets/Assets.h"
|
||||
#include "assets/AssetsLoader.h"
|
||||
#include "world_render.h"
|
||||
#include "hud_render.h"
|
||||
#include "frontend/world_render.h"
|
||||
#include "frontend/hud_render.h"
|
||||
|
||||
using std::shared_ptr;
|
||||
|
||||
@ -47,11 +47,17 @@ public:
|
||||
struct EngineSettings {
|
||||
int displayWidth;
|
||||
int displayHeight;
|
||||
|
||||
/* Anti-aliasing samples */
|
||||
int displaySamples;
|
||||
const char* title;
|
||||
/* Window title */
|
||||
const char* displayTitle;
|
||||
/* Max milliseconds that engine uses for chunks loading only */
|
||||
uint chunksLoadSpeed;
|
||||
/* Radius of chunks loading zone (chunk is unit) */
|
||||
uint chunksLoadDistance;
|
||||
/* Buffer zone where chunks are not unloading (chunk is unit)*/
|
||||
uint chunksPadding;
|
||||
};
|
||||
|
||||
|
||||
@ -76,7 +82,10 @@ public:
|
||||
Engine::Engine(const EngineSettings& settings) {
|
||||
this->settings = settings;
|
||||
|
||||
Window::initialize(settings.displayWidth, settings.displayHeight, settings.title, settings.displaySamples);
|
||||
Window::initialize(settings.displayWidth,
|
||||
settings.displayHeight,
|
||||
settings.displayTitle,
|
||||
settings.displaySamples);
|
||||
|
||||
assets = new Assets();
|
||||
std::cout << "-- loading assets" << std::endl;
|
||||
@ -95,7 +104,7 @@ Engine::Engine(const EngineSettings& settings) {
|
||||
Camera* camera = new Camera(playerPosition, radians(90.0f));
|
||||
World* world = new World("world-1", "world/", 42);
|
||||
Player* player = new Player(playerPosition, 4.0f, camera);
|
||||
level = world->loadLevel(player);
|
||||
level = world->loadLevel(player, settings.chunksLoadDistance, settings.chunksPadding);
|
||||
|
||||
std::cout << "-- initializing finished" << std::endl;
|
||||
|
||||
@ -178,7 +187,15 @@ Engine::~Engine() {
|
||||
int main() {
|
||||
setup_definitions();
|
||||
try {
|
||||
Engine engine(EngineSettings{ 1280, 720, 1, "VoxelEngine-Cpp v13", 15 });
|
||||
EngineSettings settings;
|
||||
settings.displayWidth = 1280;
|
||||
settings.displayHeight = 720;
|
||||
settings.displaySamples = 4;
|
||||
settings.displayTitle = "VoxelEngine-Cpp v13";
|
||||
settings.chunksLoadSpeed = 15;
|
||||
settings.chunksLoadDistance = 12;
|
||||
settings.chunksPadding = 2;
|
||||
Engine engine(settings);
|
||||
engine.mainloop();
|
||||
}
|
||||
catch (const initialize_error& err) {
|
||||
|
||||
@ -31,7 +31,8 @@ using std::chrono::duration_cast;
|
||||
using std::chrono::microseconds;
|
||||
|
||||
|
||||
ChunksController::ChunksController(Level* level, Chunks* chunks, Lighting* lighting) : level(level), chunks(chunks), lighting(lighting){
|
||||
ChunksController::ChunksController(Level* level, Chunks* chunks, Lighting* lighting, uint padding)
|
||||
: level(level), chunks(chunks), lighting(lighting), padding(padding) {
|
||||
}
|
||||
|
||||
ChunksController::~ChunksController(){
|
||||
@ -61,9 +62,9 @@ bool ChunksController::loadVisible(WorldFiles* worldFiles){
|
||||
const int oz = chunks->oz;
|
||||
int nearX = 0;
|
||||
int nearZ = 0;
|
||||
int minDistance = (w/2)*(w/2);
|
||||
for (int z = 2; z < d-2; z++){
|
||||
for (int x = 2; x < w-2; x++){
|
||||
int minDistance = ((w-padding*2)/2)*((w-padding*2)/2);
|
||||
for (int z = padding; z < d-padding; z++){
|
||||
for (int x = padding; x < w-padding; x++){
|
||||
int index = z * w + x;
|
||||
shared_ptr<Chunk> chunk = chunks->chunks[index];
|
||||
if (chunk != nullptr){
|
||||
|
||||
@ -16,8 +16,9 @@ private:
|
||||
Chunks* chunks;
|
||||
Lighting* lighting;
|
||||
int64_t avgDurationMcs = 1000;
|
||||
uint padding;
|
||||
public:
|
||||
ChunksController(Level* level, Chunks* chunks, Lighting* lighting);
|
||||
ChunksController(Level* level, Chunks* chunks, Lighting* lighting, uint padding);
|
||||
~ChunksController();
|
||||
|
||||
void update(int64_t maxDuration);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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_ */
|
||||
|
||||
@ -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,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_ */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user