当前位置: 首页>>代码示例>>C++>>正文


C++ ChunkList::size方法代码示例

本文整理汇总了C++中ChunkList::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ChunkList::size方法的具体用法?C++ ChunkList::size怎么用?C++ ChunkList::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ChunkList的用法示例。


在下文中一共展示了ChunkList::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Update

void ChunkManager::Update() {
	ChunkList unloadList;

	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->IsUnloading()) {
			unloadList.push_back(chunk);
		}
		else if (chunk->IsRebuildComplete()) {
			chunk->CompleteMesh();
		}
	}
	m_chunkMapMutex.unlock();
	
	int numUnloadChunks = 0;
	const static int MAX_NUM_CHUNKS_UNLOAD = 1;
	for (unsigned int i = 0; i < unloadList.size() && numUnloadChunks < MAX_NUM_CHUNKS_UNLOAD; ++i) {
		Chunk* chunk = unloadList[i];
		UnloadChunk(chunk);
	}
}
开发者ID:ggtucker,项目名称:SugoiEngine,代码行数:23,代码来源:ChunkManager.cpp

示例2: UpdatingChunksThread

void ChunkManager::UpdatingChunksThread()
{
	while (m_updateThreadActive)
	{
		while (m_pPlayer == NULL)
		{
#ifdef _WIN32
			Sleep(100);
#else
			usleep(100000);
#endif
		}

		while (m_stepLockEnabled == true && m_updateStepLock == true)
		{
#ifdef _WIN32
			Sleep(100);
#else
			usleep(100000);
#endif
		}

		ChunkList updateChunkList;
		ChunkCoordKeysList addChunkList;
		ChunkList rebuildChunkList;
		ChunkList unloadChunkList;

		m_ChunkMapMutexLock.lock();
		typedef map<ChunkCoordKeys, Chunk*>::iterator it_type;
		for (it_type iterator = m_chunksMap.begin(); iterator != m_chunksMap.end(); iterator++)
		{
			Chunk* pChunk = iterator->second;

			updateChunkList.push_back(pChunk);
		}
		m_ChunkMapMutexLock.unlock();

		// Updating chunks
		int numAddedChunks = 0;
		int MAX_NUM_CHUNKS_ADD = 10;
		sort(updateChunkList.begin(), updateChunkList.end(), Chunk::ClosestToCamera);
		for (unsigned int i = 0; i < (int)updateChunkList.size(); i++)
		{
			Chunk* pChunk = updateChunkList[i];

			if (pChunk != NULL)
			{
				pChunk->Update(0.01f);

				int gridX = pChunk->GetGridX();
				int gridY = pChunk->GetGridY();
				int gridZ = pChunk->GetGridZ();

				float xPos = gridX * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;
				float yPos = gridY * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;
				float zPos = gridZ * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;

				vec3 chunkCenter = vec3(xPos, yPos, zPos) + vec3(Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE, Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE, Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE);
				vec3 distanceVec = chunkCenter - m_pPlayer->GetCenter();
				float lengthValue = length(distanceVec);

				if (lengthValue > m_loaderRadius)
				{
					unloadChunkList.push_back(pChunk);
				}
				else
				{
					if (numAddedChunks < MAX_NUM_CHUNKS_ADD)
					{
						// Check neighbours
						if (pChunk->GetNumNeighbours() < 6 && (pChunk->IsEmpty() == false) || (gridY == 0))
						{
							if (pChunk->GetxMinus() == NULL)
							{
								ChunkCoordKeys coordKey;
								coordKey.x = gridX - 1;
								coordKey.y = gridY;
								coordKey.z = gridZ;
								float xPos = coordKey.x * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;
								float yPos = coordKey.y * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;
								float zPos = coordKey.z * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;

								vec3 chunkCenter = vec3(xPos, yPos, zPos) + vec3(Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE, Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE, Chunk::CHUNK_SIZE*Chunk::BLOCK_RENDER_SIZE);
								vec3 distanceVec = chunkCenter - m_pPlayer->GetCenter();
								float lengthValue = length(distanceVec);

								if (lengthValue <= m_loaderRadius)
								{
									addChunkList.push_back(coordKey);
									numAddedChunks++;
								}
							}
							if (pChunk->GetxPlus() == NULL)
							{
								ChunkCoordKeys coordKey;
								coordKey.x = gridX + 1;
								coordKey.y = gridY;
								coordKey.z = gridZ;
								float xPos = coordKey.x * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;
								float yPos = coordKey.y * Chunk::CHUNK_SIZE * Chunk::BLOCK_RENDER_SIZE*2.0f;
//.........这里部分代码省略.........
开发者ID:CodeMason,项目名称:Vox,代码行数:101,代码来源:ChunkManager.cpp

示例3: ImportQubicleBinaryMatrix


//.........这里部分代码省略.........
			if (mirrorZ)
				zPosition = zValueToUse - 1;

			for (unsigned int z = 0; z < zValueToUse; z++)
			{
				int xPosition_modified = xPosition;
				int yPosition_modified = yPosition;
				int zPosition_modified = zPosition;
				if (flipXZ)
				{
					xPosition_modified = zPosition;
					zPosition_modified = xPosition;
				}
				if (flipXY)
				{
					xPosition_modified = yPosition;
					yPosition_modified = xPosition;
				}
				if (flipYZ)
				{
					yPosition_modified = zPosition;
					zPosition_modified = yPosition;
				}

				if (pMatrix->GetActive(xPosition_modified, yPosition_modified, zPosition_modified) == false)
				{
					// Do nothing
				}
				else
				{
					unsigned int colour = pMatrix->GetColourCompact(xPosition_modified, yPosition_modified, zPosition_modified);

					vec3 blockPos = position - vec3((xValueToUse + 0.05f)*0.5f, 0.0f, (zValueToUse + 0.05f)*0.5f) + vec3(x*Chunk::BLOCK_RENDER_SIZE*2.0f, y*Chunk::BLOCK_RENDER_SIZE*2.0f, z*Chunk::BLOCK_RENDER_SIZE*2.0f);

					vec3 blockPosition;
					int blockX, blockY, blockZ;
					Chunk* pChunk = NULL;
					bool blockActive = GetBlockActiveFrom3DPosition(blockPos.x, blockPos.y, blockPos.z, &blockPosition, &blockX, &blockY, &blockZ, &pChunk);

					if (pChunk != NULL)
					{
						pChunk->SetColour(blockX, blockY, blockZ, colour);

						// Add to batch update list (no duplicates)
						bool found = false;
						for (int i = 0; i < (int)vChunkBatchUpdateList.size() && found == false; i++)
						{
							if (vChunkBatchUpdateList[i] == pChunk)
							{
								found = true;
							}
						}
						if (found == false)
						{
							vChunkBatchUpdateList.push_back(pChunk);
							pChunk->StartBatchUpdate();
						}
					}
					else
					{
						// Add to the chunk storage
						int gridX;
						int gridY;
						int gridZ;
						GetGridFromPosition(blockPos, &gridX, &gridY, &gridZ);
						ChunkStorageLoader* pStorage = GetChunkStorage(gridX, gridY, gridZ, true);

						if (pStorage != NULL)
						{
							GetBlockGridFrom3DPositionChunkStorage(blockPos.x, blockPos.y, blockPos.z, &blockX, &blockY, &blockZ, pStorage);

							pStorage->SetBlockColour(blockX, blockY, blockZ, colour);
						}
					}
				}

				if (mirrorZ)
					zPosition--;
				else
					zPosition++;
			}

			if (mirrorY)
				yPosition--;
			else
				yPosition++;
		}

		if (mirrorX)
			xPosition--;
		else
			xPosition++;
	}

	for (int i = 0; i < (int)vChunkBatchUpdateList.size(); i++)
	{
		vChunkBatchUpdateList[i]->StopBatchUpdate();
	}
	vChunkBatchUpdateList.clear();
}
开发者ID:CodeMason,项目名称:Vox,代码行数:101,代码来源:ChunkManager.cpp

示例4: UpdateChunksThread

void ChunkManager::UpdateChunksThread() {
	while (m_updateThreadActive) {

		while (m_stepLockEnabled && m_updateStepLock) {
			std::this_thread::sleep_for(std::chrono::milliseconds(100));
		}

		ChunkList updateList;
		ChunkList rebuildList;
		ChunkCoordKeyList addKeyList;

		// STEP 1: PUT ALL CREATED CHUNKS IN `UPDATE LIST`

		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->IsUnloading()) {
				updateList.push_back(chunk);
			}
		}
		m_chunkMapMutex.unlock();

		// STEP 2: FIND CHUNKS TO ADD (OR UNLOAD IF THEY'RE TOO FAR)

		int numAddedChunks = 0;
		const int MAX_NUM_CHUNKS_ADD = 10;
		std::sort(updateList.begin(), updateList.end(), Chunk::ClosestToCamera);
		for (unsigned int i = 0; i < updateList.size(); ++i) {

			Chunk* chunk = updateList[i];

			if (chunk) {
				glm::vec3 chunkCenter = chunk->GetCenter();
				glm::vec3 cameraPos = m_renderer->GetCamera().GetPosition();
				float cameraDistance = glm::length(chunkCenter - cameraPos);

				if (cameraDistance > m_loadRadius) {
					chunk->SetUnloading();
				}
				else if (numAddedChunks < MAX_NUM_CHUNKS_ADD) {

					ChunkCoordKeyList missing = chunk->GetMissingNeighbors();

					if (!chunk->IsEmpty()) {

						for (ChunkCoordKey key : missing) {

							if (std::find(addKeyList.begin(), addKeyList.end(), key) == addKeyList.end()) {

								// Here we are calculating the distance of each
								// neighbor chunk to decide if we should add it
								glm::vec3 chunkCenter = Chunk::GetWorldCenter(key.x, key.y, key.z);
								float cameraDistance = glm::length(chunkCenter - cameraPos);

								if (cameraDistance <= m_loadRadius && key.y == 0) {
									addKeyList.push_back(key);
									++numAddedChunks;
								}
							}
						}
					}
				}
			}
		}
		updateList.clear();

		// STEP 3: ADD CHUNKS

		for (unsigned int i = 0; i < addKeyList.size(); ++i) {
			ChunkCoordKey key = addKeyList[i];
			CreateNewChunk(key.x, key.y, key.z);
		}
		addKeyList.clear();

		// STEP 4: CHECK FOR REBUILD CHUNKS

		m_chunkMapMutex.lock();
		for (it = m_chunkMap.begin(); it != m_chunkMap.end(); ++it) {
			Chunk* chunk = it->second;
			if (!chunk->IsUnloading() && chunk->NeedsRebuild()) {
				rebuildList.push_back(chunk);
			}
		}
		m_chunkMapMutex.unlock();

		// STEP 5: REBUILD CHUNKS

		int numRebuildChunks = 0;
		const int MAX_NUM_CHUNKS_REBUILD = 30;
		for (unsigned int i = 0; i < rebuildList.size() && numRebuildChunks < MAX_NUM_CHUNKS_REBUILD; ++i) {
			Chunk* chunk = rebuildList[i];
			chunk->RebuildMesh();
			++numRebuildChunks;
		}
		rebuildList.clear();

		if (m_stepLockEnabled && !m_updateStepLock) {
			m_updateStepLock = true;
		}
//.........这里部分代码省略.........
开发者ID:ggtucker,项目名称:SugoiEngine,代码行数:101,代码来源:ChunkManager.cpp


注:本文中的ChunkList::size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。