Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ChunkManager::updateChunks()
- {
- int chunkView = 6;
- float r = 3;
- i32v3 pos = getChunkByPos((i32v3)_cam->getPosition());
- for (int x = pos.x - r; x < pos.x + chunkView; x++)
- {
- for (int y = pos.y - r; y < pos.y + chunkView; y++)
- {
- for (int z = pos.z - r; z < pos.z + chunkView; z++)
- {
- float x2 = (x * 32);
- float y2 = (y * 32);
- float z2 = (z * 32);
- i32v3 newPos = i32v3(x, y, z);
- if (std::abs(_cam->getPosition().x - x2) < (32 * r) && std::abs(_cam->getPosition().y - y2) < (32 * r) && std::abs(_cam->getPosition().z - z2) < (32 * r))
- {
- if (chunkList[newPos] == NULL)
- {
- loadChunk(newPos.x, newPos.y, newPos.z, true);
- }
- }
- else
- {
- if (chunkList[newPos] != NULL)
- {
- unloadChunk(newPos.x, newPos.y, newPos.z);
- }
- }
- }
- }
- }
- }
- void ChunkManager::loadChunk(float x, float y, float z, bool threaded)
- {
- mtx.lock();
- if (threaded)
- {
- i32v3 pos = i32v3(x, y, z);
- Chunk* chunk = new Chunk(this, _cam, _oneissaMath, _contentSystem, _bManager);
- chunkList[pos] = chunk;
- chunk->init((x * 32), (y * 32), (z * 32));
- chunk->fillChunk((x * 32), (y * 32), (z * 32));
- chunk->buildChunk((x * 32), (y * 32), (z * 32));
- voxelCount += chunk->voxelCount;
- if (chunk->voxelCount == 0)
- {
- chunkList[pos] = NULL;
- chunkCount--;
- }
- chunkCount++;
- }
- else
- {
- i32v3 pos = i32v3(x, y, z);
- Chunk* chunk = new Chunk(this, _cam, _oneissaMath, _contentSystem, _bManager);
- chunkList[pos] = chunk;
- chunk->init((x * 32), (y * 32), (z * 32));
- chunk->fillChunk((x * 32), (y * 32), (z * 32));
- chunk->buildChunk((x * 32), (y * 32), (z * 32));
- chunk->buildVBO();
- voxelCount += chunk->voxelCount;
- if (chunk->voxelCount == 0)
- {
- chunkList[pos] = NULL;
- chunkCount--;
- }
- chunkCount++;
- }
- mtx.unlock();
- }
Advertisement
Add Comment
Please, Sign In to add comment