Example #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);
}
Example #2
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);
}