本文整理汇总了C++中Chunk::GetxPlus方法的典型用法代码示例。如果您正苦于以下问题:C++ Chunk::GetxPlus方法的具体用法?C++ Chunk::GetxPlus怎么用?C++ Chunk::GetxPlus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk::GetxPlus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UnloadChunk
void ChunkManager::UnloadChunk(Chunk* pChunk)
{
ChunkCoordKeys coordKeys;
coordKeys.x = pChunk->GetGridX();
coordKeys.y = pChunk->GetGridY();
coordKeys.z = pChunk->GetGridZ();
Chunk* pChunkXMinus = GetChunk(coordKeys.x - 1, coordKeys.y, coordKeys.z);
Chunk* pChunkXPlus = GetChunk(coordKeys.x + 1, coordKeys.y, coordKeys.z);
Chunk* pChunkYMinus = GetChunk(coordKeys.x, coordKeys.y - 1, coordKeys.z);
Chunk* pChunkYPlus = GetChunk(coordKeys.x, coordKeys.y + 1, coordKeys.z);
Chunk* pChunkZMinus = GetChunk(coordKeys.x, coordKeys.y, coordKeys.z - 1);
Chunk* pChunkZPlus = GetChunk(coordKeys.x, coordKeys.y, coordKeys.z + 1);
if (pChunkXMinus)
{
if (pChunkXMinus->GetxPlus())
{
pChunkXMinus->SetNumNeighbours(pChunkXMinus->GetNumNeighbours() - 1);
pChunkXMinus->SetxPlus(NULL);
}
}
if (pChunkXPlus)
{
if (pChunkXPlus->GetxMinus())
{
pChunkXPlus->SetNumNeighbours(pChunkXPlus->GetNumNeighbours() - 1);
pChunkXPlus->SetxMinus(NULL);
}
}
if (pChunkYMinus)
{
if (pChunkYMinus->GetyPlus())
{
pChunkYMinus->SetNumNeighbours(pChunkYMinus->GetNumNeighbours() - 1);
pChunkYMinus->SetyPlus(NULL);
}
}
if (pChunkYPlus)
{
if (pChunkYPlus->GetyMinus())
{
pChunkYPlus->SetNumNeighbours(pChunkYPlus->GetNumNeighbours() - 1);
pChunkYPlus->SetyMinus(NULL);
}
}
if (pChunkZMinus)
{
if (pChunkZMinus->GetzPlus())
{
pChunkZMinus->SetNumNeighbours(pChunkZMinus->GetNumNeighbours() - 1);
pChunkZMinus->SetzPlus(NULL);
}
}
if (pChunkZPlus)
{
if (pChunkZPlus->GetzMinus())
{
pChunkZPlus->SetNumNeighbours(pChunkZPlus->GetNumNeighbours() - 1);
pChunkZPlus->SetzMinus(NULL);
}
}
// Remove from map
m_ChunkMapMutexLock.lock();
map<ChunkCoordKeys, Chunk*>::iterator it = m_chunksMap.find(coordKeys);
if (it != m_chunksMap.end())
{
m_chunksMap.erase(coordKeys);
}
m_ChunkMapMutexLock.unlock();
// Clear chunk linkage
if (m_pPlayer != NULL)
{
m_pPlayer->ClearChunkCacheForChunk(pChunk);
}
// Unload and delete
pChunk->Unload();
delete pChunk;
}
示例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;
//.........这里部分代码省略.........
示例3: UpdateChunkNeighbours
void ChunkManager::UpdateChunkNeighbours(Chunk* pChunk, int x, int y, int z)
{
pChunk->SetNumNeighbours(0);
Chunk* pChunkXMinus = GetChunk(x - 1, y, z);
Chunk* pChunkXPlus = GetChunk(x + 1, y, z);
Chunk* pChunkYMinus = GetChunk(x, y - 1, z);
Chunk* pChunkYPlus = GetChunk(x, y + 1, z);
Chunk* pChunkZMinus = GetChunk(x, y, z - 1);
Chunk* pChunkZPlus = GetChunk(x, y, z + 1);
if (pChunkXMinus)
{
pChunk->SetNumNeighbours(pChunk->GetNumNeighbours() + 1);
pChunk->SetxMinus(pChunkXMinus);
if (pChunkXMinus->GetxPlus() == NULL)
{
pChunkXMinus->SetNumNeighbours(pChunkXMinus->GetNumNeighbours() + 1);
pChunkXMinus->SetxPlus(pChunk);
}
}
if (pChunkXPlus)
{
pChunk->SetNumNeighbours(pChunk->GetNumNeighbours() + 1);
pChunk->SetxPlus(pChunkXPlus);
if (pChunkXPlus->GetxMinus() == NULL)
{
pChunkXPlus->SetNumNeighbours(pChunkXPlus->GetNumNeighbours() + 1);
pChunkXPlus->SetxMinus(pChunk);
}
}
if (pChunkYMinus)
{
pChunk->SetNumNeighbours(pChunk->GetNumNeighbours() + 1);
pChunk->SetyMinus(pChunkYMinus);
if (pChunkYMinus->GetyPlus() == NULL)
{
pChunkYMinus->SetNumNeighbours(pChunkYMinus->GetNumNeighbours() + 1);
pChunkYMinus->SetyPlus(pChunk);
}
}
if (pChunkYPlus)
{
pChunk->SetNumNeighbours(pChunk->GetNumNeighbours() + 1);
pChunk->SetyPlus(pChunkYPlus);
if (pChunkYPlus->GetyMinus() == NULL)
{
pChunkYPlus->SetNumNeighbours(pChunkYPlus->GetNumNeighbours() + 1);
pChunkYPlus->SetyMinus(pChunk);
}
}
if (pChunkZMinus)
{
pChunk->SetNumNeighbours(pChunk->GetNumNeighbours() + 1);
pChunk->SetzMinus(pChunkZMinus);
if (pChunkZMinus->GetzPlus() == NULL)
{
pChunkZMinus->SetNumNeighbours(pChunkZMinus->GetNumNeighbours() + 1);
pChunkZMinus->SetzPlus(pChunk);
}
}
if (pChunkZPlus)
{
pChunk->SetNumNeighbours(pChunk->GetNumNeighbours() + 1);
pChunk->SetzPlus(pChunkZPlus);
if (pChunkZPlus->GetzMinus() == NULL)
{
pChunkZPlus->SetNumNeighbours(pChunkZPlus->GetNumNeighbours() + 1);
pChunkZPlus->SetzMinus(pChunk);
}
}
}