本文整理汇总了C++中Chunk::GetBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ Chunk::GetBlock方法的具体用法?C++ Chunk::GetBlock怎么用?C++ Chunk::GetBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chunk
的用法示例。
在下文中一共展示了Chunk::GetBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlaceBlock
void SocketStorage::PlaceBlock(char type, Vector3 chunkIndex, Vector3 blockIndex) {
Chunk *chunk = Loaded[chunkIndex];
if (chunk == NULL) return; // TODO: this *will* segfault on unloaded chunks!
Vector3 absolute = chunk->GetWorldPos(blockIndex);
Block *block = chunk->GetBlock(blockIndex);
chunk->PlaceBlock(type, blockIndex);
if (block->Type != type)
context->socket->SendBlock(type, chunkIndex, blockIndex);
}
示例2: PlaceBlock
void Terrain::PlaceBlock(char type, Vector3 chunkIndex, Vector3 blockIndex) {
// chunk isn't loaded, don't bother. TODO: doublecheck
if (!contains(RequestedChunks, chunkIndex)) return;
Chunk *chunk = LoadedChunks[chunkIndex];
Vector3 absolute = chunk->GetWorldPos(blockIndex);
Block *block = chunk->GetBlock(blockIndex);
if (block->Type > 0 && block->faces != 0) {
for (std::list<PositionedBlock*>::iterator it = VisibleBlocks.begin(); it != VisibleBlocks.end(); ++it) {
if ((*it)->pos == absolute) {
VisibleBlocks.remove(*it);
break;
}
}
}
Storage->PlaceBlock(type, chunkIndex, blockIndex);
block = chunk->PlaceBlock(type, blockIndex);
// TODO: handle placing blocks without just counting on a [reliable] glitch!
Block *blk = NULL;
if (blockIndex.X > 0 && chunk->GetBlock(blockIndex - Vector3(1, 0, 0))->Type > 0) {
blk = chunk->GetBlock(blockIndex - Vector3(1, 0, 0));
if (blk->faces == 0) VisibleBlocks.push_back(new PositionedBlock(blk, absolute - Vector3(1, 0, 0), 1));
blk->faces |= 0x08;
}
if (blockIndex.Y > 0 && chunk->GetBlock(blockIndex - Vector3(0, 1, 0))->Type > 0) {
blk = chunk->GetBlock(blockIndex - Vector3(0, 1, 0));
if (blk->faces == 0) VisibleBlocks.push_back(new PositionedBlock(blk, absolute - Vector3(0, 1, 0), 1));
blk->faces |= 0x10;
}
if (blockIndex.Z > 0 && chunk->GetBlock(blockIndex - Vector3(0, 0, 1))->Type > 0) {
blk = chunk->GetBlock(blockIndex - Vector3(0, 0, 1));
if (blk->faces == 0) VisibleBlocks.push_back(new PositionedBlock(blk, absolute - Vector3(0, 0, 1), 1));
blk->faces |= 0x20;
}
int Upper = chunk->SideLength - 1;
if (blockIndex.X < Upper && chunk->GetBlock(blockIndex + Vector3(1, 0, 0))->Type > 0) {
blk = chunk->GetBlock(blockIndex + Vector3(1, 0, 0));
if (blk->faces == 0) VisibleBlocks.push_back(new PositionedBlock(blk, absolute + Vector3(1, 0, 0), 1));
blk->faces |= 0x01;
}
if (blockIndex.Y < Upper && chunk->GetBlock(blockIndex + Vector3(0, 1, 0))->Type > 0) {
blk = chunk->GetBlock(blockIndex + Vector3(0, 1, 0));
if (blk->faces == 0) VisibleBlocks.push_back(new PositionedBlock(blk, absolute + Vector3(0, 1, 0), 1));
blk->faces |= 0x02;
}
if (blockIndex.Z < Upper && chunk->GetBlock(blockIndex + Vector3(0, 0, 1))->Type > 0) {
blk = chunk->GetBlock(blockIndex + Vector3(0, 0, 1));
if (blk->faces == 0) VisibleBlocks.push_back(new PositionedBlock(blk, absolute + Vector3(0, 0, 1), 1));
blk->faces |= 0x04;
}
// TODO: do faces calc on new block
if (type > 0) // && blk->faces != 0)
VisibleBlocks.push_back(new PositionedBlock(block, absolute, 1));
}