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


C++ BlockMap::setBlock方法代码示例

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


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

示例1: renderWorldToFile

	void Cartographer::renderWorldToFile(
			const std::string worldDir, const std::string filename)
	{
		std::cout << "Cartographer: fetching world files..." << std::endl;
		MapLoader loader(worldDir);
		std::set<Vector3i> blockPositions;
		loader.getAllBlockPositions(blockPositions);
		std::cout << "| Found "
			<< blockPositions.size() << " block files." << std::endl;

		if(blockPositions.size() == 0)
		{
			std::cout << "Cartographer: the world is empty : aborted" << std::endl;
			return;
		}

		std::cout << "Cartographer: Computing world edges... " << std::endl;
		Vector3i min, max;
		for(auto & pos : blockPositions)
		{
			if(pos.x < min.x) min.x = pos.x;
			if(pos.x > max.x) max.x = pos.x;

			if(pos.y < min.y) min.y = pos.y;
			if(pos.y > max.y) max.y = pos.y;

			if(pos.z < min.z) min.z = pos.z;
			if(pos.z > max.z) max.z = pos.z;
		}
		std::cout << "| min=" << min << ", max=" << max << std::endl;

		const Vector3i area = max - min;
		if( area.x >= MAX_SIZE_BLOCKS ||
			area.y >= MAX_SIZE_BLOCKS ||
			area.z >= MAX_SIZE_BLOCKS)
		{
			std::cout << "ERROR: Cartographer: cannot perform a full one-picture "
				<< "rendering, the world is too big." << std::endl;
			return;
		}

		std::cout << "| Done." << std::endl;

		std::cout << "Cartographer: rendering..." << std::endl;

		BlockMap map;
		Vector3i pos;
		Cartography cartography;

		for(pos.x = min.x; pos.x <= max.x; pos.x++)
		{
			for(pos.y = min.y; pos.y <= max.y; pos.y++)
			{
				// Load a Z-wise chunk
				for(pos.z = min.z; pos.z <= max.z; pos.z++)
				{
					if(loader.isBlockOnHardDrive(pos))
					{
						Block * b = loader.loadBlock(pos);
						if(b != 0)
							map.setBlock(b);
					}
				}

				// Render the chunk
				sf::Image pic = renderChunkTopDown(
					map, pos.x, pos.y, Block::SIZE * min.z, Block::SIZE * (max.z+1));

				// Add it to the cartography
				cartography.setPictureFromImage(Vector2i(pos.x, pos.y), pic);

				// Clear map
				map.clear();
			}

			// Progress
			int p = 100.f * (float)(pos.x - min.x) / (float)(max.x - min.x);
			std::cout << "| Progress : " << p << "%" << std::endl;
		}

		std::cout << "| Done." << std::endl;

		std::cout << "Cartographer: Saving cartography..." << std::endl;
		cartography.saveAsBigImage(filename);
		std::cout << "Cartographer: Finished." << std::endl;
	}
开发者ID:Clever-Boy,项目名称:zCraft,代码行数:86,代码来源:Cartographer.cpp


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