void ChunkManager::Render() { if (m_textureId != -1) { m_renderer->BindTextureToShader(m_textureId, 0); } m_renderer->PushMatrix(); m_chunkMapMutex.lock(); std::map<ChunkCoordKey, Chunk*>::iterator it; for (it = m_chunkMap.begin(); it != m_chunkMap.end(); ++it) { Chunk* chunk = it->second; if (chunk->IsLoaded()) { glm::vec3 chunkCenter = chunk->GetCenter(); float chunkSize = Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE; if (m_renderer->CubeInFrustum(chunkCenter, chunkSize, chunkSize, chunkSize)) { chunk->Render(); } } } m_chunkMapMutex.unlock(); m_renderer->PopMatrix(); }
void Chunk::UpdateSurroundedFlag() { Chunk* chunkXMinus = m_chunkManager->GetChunk(m_grid.x - 1, m_grid.y, m_grid.z); Chunk* chunkXPlus = m_chunkManager->GetChunk(m_grid.x + 1, m_grid.y, m_grid.z); Chunk* chunkYMinus = m_chunkManager->GetChunk(m_grid.x, m_grid.y - 1, m_grid.z); Chunk* chunkYPlus = m_chunkManager->GetChunk(m_grid.x, m_grid.y + 1, m_grid.z); Chunk* chunkZMinus = m_chunkManager->GetChunk(m_grid.x, m_grid.y, m_grid.z - 1); Chunk* chunkZPlus = m_chunkManager->GetChunk(m_grid.x, m_grid.y, m_grid.z + 1); if (chunkXMinus != nullptr && chunkXMinus->IsLoaded() && chunkXMinus->m_x_plus_full && chunkXPlus != nullptr && chunkXPlus->IsLoaded() && chunkXPlus->m_x_minus_full && chunkYMinus != nullptr && chunkYMinus->IsLoaded() && chunkYMinus->m_y_plus_full && chunkYPlus != nullptr && chunkYPlus->IsLoaded() && chunkYPlus->m_y_minus_full && chunkZMinus != nullptr && chunkZMinus->IsLoaded() && chunkZMinus->m_z_plus_full && chunkZPlus != nullptr && chunkZPlus->IsLoaded() && chunkZPlus->m_z_minus_full) { m_surrounded = true; } else { m_surrounded = false; } }