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


C++ Voxel::HasVoxelObjects方法代码示例

本文整理汇总了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;
}
开发者ID:chasegreenberg,项目名称:FreeRCT,代码行数:54,代码来源:map.cpp


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