本文整理汇总了C++中WorldMap::Bounds方法的典型用法代码示例。如果您正苦于以下问题:C++ WorldMap::Bounds方法的具体用法?C++ WorldMap::Bounds怎么用?C++ WorldMap::Bounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorldMap
的用法示例。
在下文中一共展示了WorldMap::Bounds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
//.........这里部分代码省略.........
示例2: EvalIndustrial
double EvalBuildingScript::EvalIndustrial( bool debugLog )
{
Chit* building = ParentChit();
int hitB = 0, hitIBuilding = 0, hitNBuilding = 0, hitWater = 0, hitPlant = 0, hitRock = 0, hitWaterfall = 0;
int hitShrub = 0; // doesn't terminate a ray.
if (lastEval == 0 || (Context()->chitBag->AbsTime() - lastEval) > 2000) {
lastEval = Context()->chitBag->AbsTime();
GameItem* item = building->GetItem();
GLASSERT(item);
reachable = true;
IString consume = item->keyValues.GetIString(ISC::zone);
if (consume.empty()) {
eval = 0;
return eval;
}
MapSpatialComponent* msc = GET_SUB_COMPONENT(building, SpatialComponent, MapSpatialComponent);
GLASSERT(msc);
if (!msc) {
eval = 0;
return eval;
}
Rectangle2I porch = msc->PorchPos();
static const int RAD = 4;
Rectangle2I bounds = porch;
if (porch.min.x == 0) { // shouldn't happen, but be sure.
GLASSERT(0);
eval = 0;
return eval;
}
bounds.Outset(RAD);
Vector2I sector = ToSector(building->Position());
WorldMap* worldMap = Context()->worldMap;
Rectangle2I mapBounds = worldMap->Bounds();
if (!mapBounds.Contains(bounds)) {
eval = 0;
return eval; // not worth dealing with edge of world
}
// Check if we can go from the core to the porch.
// And make sure the core is inUse!
CoreScript* cs = CoreScript::GetCore(ToSector(porch.min));
if (!cs || !cs->InUse())
reachable = false;
if (reachable) {
const SectorData& sd = worldMap->GetSectorData(ToSector(porch.min));
reachable = worldMap->CalcPath(ToWorld2F(sd.core), ToWorld2F(porch.min), 0, 0, false);
}
CChitArray arr;
BuildingFilter buildingFilter;
const FluidSim* fluidSim = Context()->physicsSims->GetFluidSim(sector);
bool hasWaterfalls = fluidSim->NumWaterfalls() > 0;
LumosChitBag* chitBag = Context()->chitBag;
Rectangle2IEdgeIterator it(bounds);
while (!it.Done()) {
Vector2I pos = { it.Pos().x >= porch.max.x ? porch.max.x : porch.min.x,
it.Pos().y >= porch.max.y ? porch.max.y : porch.min.y };
LineWalk walk(pos.x, pos.y, it.Pos().x, it.Pos().y);
walk.Step(); // ignore where we are standing.
while ( !walk.Done() ) { // non-intuitive iterator. See linewalk docs.
// - building
// - plant
// - ice
// - rock
// - waterfall
// - water
// Buildings. Can be 2x2. Extend out beyond current check.
bool hitBuilding = false;
Vector2I p = walk.P();
// Don't count self as a hit, but stops the ray cast.
// Also, use a larger radius because buildings can be 2x2
chitBag->QuerySpatialHash(&arr, ToWorld2F(p), 0.8f, 0, &buildingFilter);
for (int i = 0; i < arr.Size(); ++i) {
if (arr[i] != building) {
MapSpatialComponent* buildingMSC = GET_SUB_COMPONENT(arr[i], SpatialComponent, MapSpatialComponent);
GLASSERT(buildingMSC);
if (buildingMSC->Bounds().Contains(p)) {
hitBuilding = true;
double thisSys = arr[i]->GetItem()->GetBuildingIndustrial();
hitB++;
if (thisSys <= -0.5) hitNBuilding++;
if (thisSys >= 0.5) hitIBuilding++;
break;
//.........这里部分代码省略.........