From b110551db6ad746137225e32a1b11b89c1eb7a6e Mon Sep 17 00:00:00 2001 From: Faerbit Date: Thu, 28 May 2015 11:23:27 +0200 Subject: [PATCH] Added a parameter to getSurroundingChunks to limit the chunkRenderDistance. --- game/level.cc | 13 +++++++++---- game/level.hh | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/game/level.cc b/game/level.cc index f70fb63..3a79a29 100644 --- a/game/level.cc +++ b/game/level.cc @@ -141,13 +141,18 @@ void Level::enqueueObjects(Graphics* graphics) { graphics->enqueueObjects(&sortedCrossChunkObjects); } -std::vector Level::getSurroundingChunks() { +std::vector Level::getSurroundingChunks(int chunkRenderDistance) { int renderDistance = 0; - if ((int)farPlane % chunkSize == 0) { - renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize; + if (chunkRenderDistance < 0) { + if ((int)farPlane % chunkSize == 0) { + renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize; + } + else { + renderDistance = ((((int)skydomeSize)+chunkSize/2)/chunkSize) + 1; + } } else { - renderDistance = ((((int)skydomeSize)+chunkSize/2)/chunkSize) + 1; + renderDistance = chunkRenderDistance; } int xPosition = ((int)cameraCenter->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize; int zPosition = ((int)cameraCenter->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize; diff --git a/game/level.hh b/game/level.hh index b632985..7dea9fd 100644 --- a/game/level.hh +++ b/game/level.hh @@ -86,7 +86,7 @@ class Level { void sortObjects(int textureCount); std::vector* getClosestLights(); private: - std::vector getSurroundingChunks(); + std::vector getSurroundingChunks(int chunkRenderDistance); lua_State* luaState=nullptr; std::vector crossChunkObjects; std::vector> sortedCrossChunkObjects;