本文整理汇总了C++中Voxel::HasVoxelObjects方法的典型用法代码示例。如果您正苦于以下问题:C++ Voxel::HasVoxelObjects方法的具体用法?C++ Voxel::HasVoxelObjects怎么用?C++ Voxel::HasVoxelObjects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Voxel
的用法示例。
在下文中一共展示了Voxel::HasVoxelObjects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MoveStack
/**
* Move a voxel stack to this world. May destroy the original stack in the process.
* @param vs Source stack.
*/
void VoxelStack::MoveStack(VoxelStack *vs)
{
/* Clean up the stack a bit before copying it, and get lowest and highest non-empty voxel. */
int vs_first = 0;
int vs_last = 0;
for (int i = 0; i < (int)vs->height; i++) {
Voxel *v = &vs->voxels[i];
assert(!v->HasVoxelObjects()); // There should be no voxel objects in the stack being moved.
if (!v->IsEmpty()) {
vs_last = i;
} else {
if (vs_first == i) vs_first++;
}
}
/* There should be at least one surface voxel. */
assert(vs_first <= vs_last);
/* Examine current stack with respect to persons. */
int old_first = 0;
int old_last = 0;
for (int i = 0; i < (int)this->height; i++) {
const Voxel *v = &this->voxels[i];
if (v->HasVoxelObjects()) {
old_last = i;
} else {
if (old_first == i) old_first++;
}
}
int new_base = std::min(vs->base + vs_first, this->base + old_first);
int new_height = std::max(vs->base + vs_last, this->base + old_last) - new_base + 1;
assert(new_base >= 0);
/* Make a new stack. Copy new surface, then copy the persons. */
Voxel *new_voxels = MakeNewVoxels(new_height);
CopyStackData(new_voxels + (vs->base + vs_first) - new_base, vs->voxels + vs_first, vs_last - vs_first + 1, false);
int i = (this->base + old_first) - new_base;
while (old_first <= old_last) {
CopyVoxelObjectList(&new_voxels[i], &this->voxels[old_first]);
i++;
old_first++;
}
this->base = new_base;
this->height = new_height;
delete[] this->voxels;
this->voxels = new_voxels;
}