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


C++ Noise::eval方法代码示例

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


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

示例1: clock

Map::Map(const int width, const int height, char* mapData)
{
	Map::map = this;
	unsigned int start = clock();

	this->Width = width;
	this->Height = height;
	Noise* noiser = new Noise((unsigned int)time(NULL));

	heightMap = new int[width];
	for (int i = 0; i < Width; i++) {
		heightMap[i] = (int) (noiser->eval(i / 20.0f) * Height);
	}

	walls = new Wall*[Width];
	for (int i = 0; i < Width; i++) {
		walls[i] = new Wall[Height];
		for (int j = 0; j < Height; j++) {
			walls[i][j].Id = 0;
		}
	}
	blocks = new Tile*[Width];
	for (int i = 0; i < Width; i++) {
		blocks[i] = new Tile[Height];
	}

	if (!Settings::Multiplayer)
	{

		for (int i = 0; i < Width; i++) {
			int top = heightMap[i];
			for (int j = 0; j < Height; j++) {
				walls[i][j].Id = Block::Dirt->Id;
				if (rand() % 101 > 50 || true || j > top && j < top + 3)
					blocks[i][j].Id = Block::Dirt->Id;
			}
		}
		for (int i = 0; i < Width; i++) {
			int top = heightMap[i];
			for (int j = 0; j <= top; j++) {
				walls[i][j].Id = 0;
				blocks[i][j].Id = 0;
			}
		}
		printf("World tiles fill: %d ms. \n", clock() - start);
		start = clock();

		/*for (int i = 0; i < 0; i++)
			CelluarAuto(Height, i);*/

		printf("Celluar Auto: %d ms. \n", clock() - start);
		start = clock();

		int k = 0;
		while (k < 100)
		{
			int i = rand() % Width;
			int j = rand() % height;
			if (GetBlock(i, j) == 0)
				continue;
			k += GenerateVein(i, j, Block::Stone->Id, 5);
		}

		printf("Veins generation: %d ms. \n", (clock() - start));
	}
	else
	{
		for (int i = 0; i < Width; i++) {
			for (int j = 0; j < Height; j++) {
				blocks[i][j].Id = mapData[i + j * width];
			}
		}
	}


	start = clock();
	
	for (int i = 0; i < Width; i++) {
		for (int j = 0; j < Height; j++) {
			if (blocks[i][j].Id != 0)
				blocks[i][j].connectionIndex = GetConnectionIndex(i, j);
		}
	}
	for (int i = 0; i < Width; i++) {
		for (int j = 0; j < Height; j++) {
			if (walls[i][j].Id != 0)
				walls[i][j].connectionIndex = GetConnectionIndex(i, j, true);
		}
	}
	printf("Tiles connections: %d ms. \n", clock() - start);
	start = clock();

	for (int i = 0; i < Width; i++) {
		for (int j = 0; j < Height; j++) {
			if (blocks[i][j].Id == 0 && walls[i][j].Id == 0)
			{
				blocks[i][j].lightSource = MAX_LIGHT;
				if (NearLive(i, j, 1) == 0)
					blocks[i][j].lightValue = MAX_LIGHT;
			}
//.........这里部分代码省略.........
开发者ID:SharkDX,项目名称:PenguinBasket,代码行数:101,代码来源:Map.cpp


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