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


C++ Weather::Temperature方法代码示例

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


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

示例1: SetBodyText

void StartGameWidget::SetBodyText()
{
	if (sectors.Empty()) return;

	const SectorData* sd = sectors[currentSector];
	Weather* weather = Weather::Instance();
	Vector2I pos = sd->CoreLoc();
	Vector2F pos2 = ToWorld2F(pos);
	GLASSERT(weather);
	const float AREA = float(SECTOR_SIZE*SECTOR_SIZE);
	int nPorts = 0;
	for (int i = 0; i < 4; ++i) {
		if ((1 << i) & sd->ports) {
			nPorts++;
		}
	}

	int bioFlora = 0;
	int flowers = 0;
	Rectangle2I bi = sd->InnerBounds();
	for (Rectangle2IIterator it(bi); !it.Done(); it.Next()) {
		const WorldGrid& wg = worldMap->GetWorldGrid(it.Pos().x, it.Pos().y);
		if (wg.Plant() >= 7) {
			flowers++;
		}
		else if (wg.Plant()) {
			bioFlora++;
		}
	}

	CStr<400> str;
	str.Format("%s\nTemperature=%d%%  Rain=%d%%  Land=%d%%  Water=%d%%  nPorts=%d\n"
		"bioFlora=%d%%  flowers=%d%%",
		sd->name.c_str(),
		LRint(weather->Temperature(pos2.x, pos2.y) * 100.0f),
		LRint(weather->RainFraction(pos2.x, pos2.y) * 100.0f),
		LRint(100.0f*float(sd->area) / AREA),
		LRint(100.0f*float(AREA - sd->area) / AREA),
		nPorts,
		LRint(100.0f*float(bioFlora) / AREA),
		LRint(100.0f*float(flowers) / AREA));

	bodyLabel.SetText(str.c_str());

	str.Format("%d/%d", currentSector+1, sectors.Size());
	countLabel.SetText(str.c_str());
}
开发者ID:csioza,项目名称:alteraorbis,代码行数:47,代码来源:startwidget.cpp

示例2: DoTick

void PlantScript::DoTick(U32 delta)
{
	// We need process at a steady rate so that
	// the time between ticks is constant.
	// This is performance regressive, so something
	// to keep an eye on.
	static const int MAP2 = MAX_MAP_SIZE*MAX_MAP_SIZE;
	static const int DELTA = 100*1000;	// How frequenty to tick a given plant
	static const int N_PER_MSEC = MAP2 / DELTA;
	static const int GROWTH_CHANCE = 8;
	static const int PRIME = 1553;

	static const float SHADE_EFFECT = 0.7f;

	int n = N_PER_MSEC * delta;
	Weather* weather = Weather::Instance();

	WorldMap* worldMap = context->worldMap;
	Rectangle2I bounds = worldMap->Bounds();
	bounds.Outset(-1);	// edge of map: don't want to tap over the edge.

	const Vector3F& light = context->engine->lighting.direction;
	const float		norm = Max(fabs(light.x), fabs(light.z));
	Vector2I		lightTap = { int(LRintf(light.x / norm)), int(LRintf(light.z / norm)) };
	Census*			census = &context->chitBag->census;

	for (int i = 0; i < n; ++i) {
		index += PRIME;

		int x = IndexToMapX(index);
		int y = IndexToMapY(index);

		const WorldGrid& wg = worldMap->GetWorldGrid(x, y);
		if (!wg.Plant()) continue;

		Vector2I pos2i = { x, y };
		Vector2F pos2f = ToWorld2F(pos2i);

		// --- Light Tap --- //
		const float	height = PlantScript::PlantRes(wg.Plant() - 1, wg.PlantStage())->AABB().SizeY();
		const float	rainBase		= weather->RainFraction(pos2f.x, pos2f.y);
		const float sunBase			= (1.0f - rainBase);
		const float temperatureBase	= weather->Temperature(pos2f.x, pos2f.y);

		float rain			= rainBase;
		float sun			= sunBase;
		float temperature	= temperatureBase;
		float growth		= 1.0f;

		Vector2I tap = pos2i + lightTap;

		// Check for something between us and the light.
		const WorldGrid& wgTap = worldMap->GetWorldGrid(tap);
		float tapHeight = float(wgTap.RockHeight());
		if (wgTap.PlantStage()) {
			tapHeight = PlantScript::PlantRes(wgTap.Plant() - 1, wgTap.PlantStage())->AABB().SizeY();
		}

		if (tapHeight > (height + 0.1f)) {
			// in shade
			sun *= SHADE_EFFECT;
			temperature *= SHADE_EFFECT;
		}

		// ---- Adjacent --- //
		static const int NADJ = 4;
		static const Vector2I check[NADJ] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
		int same = 0;
		for (int i = 0; i<NADJ; ++i) {
			tap = pos2i + check[i];
			const WorldGrid& wgAdj = worldMap->GetWorldGrid(tap.x, tap.y);
			if (wgAdj.Plant() == wg.Plant()) {
				++same;
			}

			if (wgAdj.RockHeight()) {
				// Water or rock runoff increase water.
				rain += 0.25f * rainBase;
			}
			if (wgAdj.IsFluid()) {
				rain += 0.25f;	// just a lot of water.
			}
			if (wgAdj.IsWater()) {
				rain += 0.25f;	// more water
				temperature = Mean(0.5f, temperature); // moderate temperature
			}
		}
		// Nutrient depletion? Too packed in?
		if (same == NADJ) {
			growth *= 0.25f;
		}

		// Are we under water?
		float fluidHeight = wg.FluidHeight();
		if (fluidHeight > 0.01f) {
			// Any amount of water goes to rain 100%
			rain = 1.0f;
			// not sure what to do with temp...assume a little cooler?
			temperature *= 0.8f;

//.........这里部分代码省略.........
开发者ID:fordream,项目名称:alteraorbis,代码行数:101,代码来源:plantscript.cpp


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