Ejemplo n.º 1
0
// Chunk Creation
void ChunkManager::CreateNewChunk(int x, int y, int z)
{
	ChunkCoordKeys coordKeys;
	coordKeys.x = x;
	coordKeys.y = y;
	coordKeys.z = z;

	// Create a new chunk at this grid position
	Chunk* pNewChunk = new Chunk(m_pRenderer, this, m_pVoxSettings);
	pNewChunk->SetPlayer(m_pPlayer);
	pNewChunk->SetSceneryManager(m_pSceneryManager);

	float xPos = x * (Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f);
	float yPos = y * (Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f);
	float zPos = z * (Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f);

	pNewChunk->SetPosition(vec3(xPos, yPos, zPos));
	pNewChunk->SetGrid(coordKeys.x, coordKeys.y, coordKeys.z);

	m_ChunkMapMutexLock.lock();
	m_chunksMap[coordKeys] = pNewChunk;
	m_ChunkMapMutexLock.unlock();

	pNewChunk->Setup();
	pNewChunk->SetNeedsRebuild(false, true);
	pNewChunk->RebuildMesh();
	pNewChunk->CompleteMesh();
	pNewChunk->SetCreated(true);

	UpdateChunkNeighbours(pNewChunk, x, y, z);
}
Ejemplo n.º 2
0
// 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;
}
Ejemplo n.º 3
0
void ChunkManager::CreateNewChunk(int x, int y, int z) {
	ChunkCoordKey key(x, y, z);
	//std::cout << "Create chunk: " << key.x << " " << key.y << " " << key.z << std::endl;

	Chunk* chunk = new Chunk(m_renderer, this);
	chunk->SetGrid(x, y, z);

	m_chunkMapMutex.lock();
	m_chunkMap[key] = chunk;
	m_chunkMapMutex.unlock();

	chunk->Load();
	chunk->SetNeedsRebuild(true, true);
	chunk->RebuildMesh();

	// UpdateChunkNeighbors(chunk, x, y, z);
}