예제 #1
0
파일: Chunk.cpp 프로젝트: CodeMason/Vox
void Chunk::Unload()
{
	m_isUnloading = true;

	if (m_pMesh != NULL)
	{
		m_pRenderer->ClearMesh(m_pMesh);
		m_pMesh = NULL;
	}

	if (m_setup == true)
	{
		Chunk* pChunkXMinus = m_pChunkManager->GetChunk(m_gridX - 1, m_gridY, m_gridZ);
		Chunk* pChunkXPlus = m_pChunkManager->GetChunk(m_gridX + 1, m_gridY, m_gridZ);
		Chunk* pChunkYMinus = m_pChunkManager->GetChunk(m_gridX, m_gridY - 1, m_gridZ);
		Chunk* pChunkYPlus = m_pChunkManager->GetChunk(m_gridX, m_gridY + 1, m_gridZ);
		Chunk* pChunkZMinus = m_pChunkManager->GetChunk(m_gridX, m_gridY, m_gridZ - 1);
		Chunk* pChunkZPlus = m_pChunkManager->GetChunk(m_gridX, m_gridY, m_gridZ + 1);

		if (pChunkXMinus != NULL && pChunkXMinus->IsSetup() == true)
			pChunkXMinus->UpdateSurroundedFlag();
		if (pChunkXPlus != NULL && pChunkXPlus->IsSetup() == true)
			pChunkXPlus->UpdateSurroundedFlag();
		if (pChunkYMinus != NULL && pChunkYMinus->IsSetup() == true)
			pChunkYMinus->UpdateSurroundedFlag();
		if (pChunkYPlus != NULL && pChunkYPlus->IsSetup() == true)
			pChunkYPlus->UpdateSurroundedFlag();
		if (pChunkZMinus != NULL && pChunkZMinus->IsSetup() == true)
			pChunkZMinus->UpdateSurroundedFlag();
		if (pChunkZPlus != NULL && pChunkZPlus->IsSetup() == true)
			pChunkZPlus->UpdateSurroundedFlag();
	}
}
예제 #2
0
파일: Chunk.cpp 프로젝트: CodeMason/Vox
// Rebuild
void Chunk::RebuildMesh()
{
	m_isRebuildingMesh = true;
	if (m_pMesh != NULL)
	{
		m_pRenderer->ClearMesh(m_pMesh);
		m_pMesh = NULL;
	}

	CreateMesh();

	// Update our wall flags, so that our neighbors can check if they are surrounded
	UpdateWallFlags();
	UpdateSurroundedFlag();

	Chunk* pChunkXMinus = m_pChunkManager->GetChunk(m_gridX - 1, m_gridY, m_gridZ);
	Chunk* pChunkXPlus = m_pChunkManager->GetChunk(m_gridX + 1, m_gridY, m_gridZ);
	Chunk* pChunkYMinus = m_pChunkManager->GetChunk(m_gridX, m_gridY - 1, m_gridZ);
	Chunk* pChunkYPlus = m_pChunkManager->GetChunk(m_gridX, m_gridY + 1, m_gridZ);
	Chunk* pChunkZMinus = m_pChunkManager->GetChunk(m_gridX, m_gridY, m_gridZ - 1);
	Chunk* pChunkZPlus = m_pChunkManager->GetChunk(m_gridX, m_gridY, m_gridZ + 1);

	if (pChunkXMinus != NULL && pChunkXMinus->IsSetup() == true)
		pChunkXMinus->UpdateSurroundedFlag();
	if (pChunkXPlus != NULL && pChunkXPlus->IsSetup() == true)
		pChunkXPlus->UpdateSurroundedFlag();
	if (pChunkYMinus != NULL && pChunkYMinus->IsSetup() == true)
		pChunkYMinus->UpdateSurroundedFlag();
	if (pChunkYPlus != NULL && pChunkYPlus->IsSetup() == true)
		pChunkYPlus->UpdateSurroundedFlag();
	if (pChunkZMinus != NULL && pChunkZMinus->IsSetup() == true)
		pChunkZMinus->UpdateSurroundedFlag();
	if (pChunkZPlus != NULL && pChunkZPlus->IsSetup() == true)
		pChunkZPlus->UpdateSurroundedFlag();

	// Rebuild neighbours
	if (m_rebuildNeighours)
	{
		if (pChunkXMinus != NULL && pChunkXMinus->IsSetup() == true)
			pChunkXMinus->SetNeedsRebuild(true, false);
		if (pChunkXPlus != NULL && pChunkXPlus->IsSetup() == true)
			pChunkXPlus->SetNeedsRebuild(true, false);
		if (pChunkYMinus != NULL && pChunkYMinus->IsSetup() == true)
			pChunkYMinus->SetNeedsRebuild(true, false);
		if (pChunkYPlus != NULL && pChunkYPlus->IsSetup() == true)
			pChunkYPlus->SetNeedsRebuild(true, false);
		if (pChunkZMinus != NULL && pChunkZMinus->IsSetup() == true)
			pChunkZMinus->SetNeedsRebuild(true, false);
		if (pChunkZPlus != NULL && pChunkZPlus->IsSetup() == true)
			pChunkZPlus->SetNeedsRebuild(true, false);

		m_rebuildNeighours = false;
	}

	m_numRebuilds++;
	m_rebuild = false;
}