From b6467a92a35ceb5d2412ef0fc7a207837330925a Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 27 May 2015 10:27:08 +0200 Subject: [PATCH] Added getSurroundingChunks method to level. --- game/level.cc | 37 +++++++++++++++++++++++++++++++++++++ game/level.hh | 1 + 2 files changed, 38 insertions(+) diff --git a/game/level.cc b/game/level.cc index 2a1276e..43067c6 100644 --- a/game/level.cc +++ b/game/level.cc @@ -141,6 +141,43 @@ void Level::enqueueObjects(Graphics* graphics) { graphics->enqueueObjects(&sortedCrossChunkObjects); } +std::vector Level::getSurroundingChunks() { + int renderDistance = 0; + if ((int)farPlane % chunkSize == 0) { + renderDistance = (((int)skydomeSize)+chunkSize/2)/chunkSize; + } + else { + renderDistance = ((((int)skydomeSize)+chunkSize/2)/chunkSize) + 1; + } + int xPosition = ((int)cameraCenter->getPosition().x + (terrain.getHeightmapWidth()/2))/chunkSize; + int zPosition = ((int)cameraCenter->getPosition().z + (terrain.getHeightmapHeight()/2))/chunkSize; + int xStart = xPosition - renderDistance; + unsigned int xEnd = xPosition + renderDistance; + int zStart = zPosition - renderDistance; + unsigned int zEnd = zPosition + renderDistance; + if (xStart < 0) { + xStart = 0; + } + if (zStart < 0) { + zStart = 0; + } + if (xEnd >= chunks.size()) { + xEnd = chunks.size()-1; + } + if (zEnd >= chunks.at(0).size()) { + zEnd = chunks.at(0).size()-1; + } + std::vector vector = std::vector((2*renderDistance)*(2*renderDistance)); + int counter = 0; + for(unsigned int i = xStart; i<=xEnd; i++) { + for(unsigned int j = zStart; j<=zEnd; j++) { + vector.at(counter) = &chunks.at(i).at(j); + counter++; + } + } + return vector; +} + void Level::sortObjects(int textureCount) { for(unsigned int i = 0; i* getClosestLights(); private: + std::vector getSurroundingChunks(); lua_State* luaState=nullptr; std::vector crossChunkObjects; std::vector> sortedCrossChunkObjects;