本文整理汇总了C++中BlockIterator::get方法的典型用法代码示例。如果您正苦于以下问题:C++ BlockIterator::get方法的具体用法?C++ BlockIterator::get怎么用?C++ BlockIterator::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockIterator
的用法示例。
在下文中一共展示了BlockIterator::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: randomTick
void Dirt::randomTick(const Block &block, World &world, BlockIterator blockIterator, WorldLockManager &lock_manager) const
{
BlockIterator bi = blockIterator;
bi.moveBy(VectorI(0, 1, 0));
Block b = bi.get(lock_manager);
if(!b.good())
return;
if(b.lighting.toFloat(world.getLighting(bi.position().d)) < 4.0f / 15 || !b.descriptor->lightProperties.isTotallyTransparent())
return;
for(int dx = -1; dx <= 1; dx++)
{
for(int dy = -3; dy <= 1; dy++)
{
for(int dz = -1; dz <= 1; dz++)
{
bi = blockIterator;
bi.moveBy(VectorI(dx, dy, dz));
b = bi.get(lock_manager);
if(b.descriptor != Grass::descriptor())
continue;
bi.moveBy(VectorI(0, 1, 0));
Block b = bi.get(lock_manager);
if(b.lighting.toFloat(world.getLighting(bi.position().d)) < 9.0f / 15)
continue;
world.setBlock(blockIterator, lock_manager, Block(Grass::descriptor()));
return;
}
}
}
}
示例2: randomTick
void Grass::randomTick(const Block &block, World &world, BlockIterator blockIterator, WorldLockManager &lock_manager) const
{
BlockIterator bi = blockIterator;
bi.moveBy(VectorI(0, 1, 0));
Block b = bi.get(lock_manager);
if((b.lighting.toFloat(world.getLighting(bi.position().d)) >= 4.0f / 15 || b.lighting.indirectSkylight >= 4) && b.descriptor->lightProperties.isTotallyTransparent())
return;
world.setBlock(blockIterator, lock_manager, Block(Dirt::descriptor()));
}
示例3: onMove
void EntityPlayer::onMove(EntityData & data, shared_ptr<World> world, float deltaTimeIn) const
{
getEntity(data, world);
assert(data.extraData);
auto eData = dynamic_pointer_cast<ExtraData>(data.extraData);
assert(eData);
data.deltaAcceleration = VectorF(0);
data.acceleration = gravityVector;
if(eData->flying)
data.acceleration = VectorF(0);
int count = iceil(deltaTimeIn * abs(data.velocity) / 0.5 + 1);
BlockIterator bi = world->get((PositionI)data.position);
data.entity->acceleration = data.acceleration;
data.entity->deltaAcceleration = data.deltaAcceleration;
auto pphysicsObject = make_shared<PhysicsBox>((VectorF)data.position + physicsOffset(), physicsExtents(), data.velocity, data.entity->acceleration, data.entity->deltaAcceleration, data.position.d, physicsProperties(), -physicsOffset());
PhysicsBox & physicsObject = *pphysicsObject;
for(int step = 0; step < count; step++)
{
float deltaTime = deltaTimeIn / count;
data.entity->age += deltaTime;
int zeroCount = 0;
while(deltaTime * deltaTime * absSquared(data.velocity) > eps * eps)
{
bool supported = false;
PhysicsCollision firstCollision(data.position + deltaTime * data.velocity + deltaTime * deltaTime * 0.5f * data.entity->acceleration + deltaTime * deltaTime * deltaTime * (1 / 6.0f) * data.entity->deltaAcceleration, data.velocity + deltaTime * data.entity->acceleration + deltaTime * deltaTime * 0.5f * data.entity->deltaAcceleration, VectorF(0), deltaTime);
physicsObject.reInit((VectorF)data.position + physicsOffset(), physicsExtents(), data.velocity, data.entity->acceleration, data.entity->deltaAcceleration);
for(int dx = -1; dx <= 1; dx++)
{
for(int dy = -2; dy <= 2; dy++)
{
for(int dz = -1; dz <= 1; dz++)
{
BlockIterator curBI = bi;
curBI += VectorI(dx, dy, dz);
shared_ptr<PhysicsObject> otherObject;
if(curBI.get().good())
otherObject = curBI.get().desc->getPhysicsObject(curBI.position());
else
otherObject = static_pointer_cast<PhysicsObject>(make_shared<PhysicsBox>((VectorI)curBI.position() + VectorF(0.5), VectorF(0.5), VectorF(0), VectorF(0), VectorF(0), curBI.position().d, PhysicsProperties(PhysicsProperties::INFINITE_MASS, 1, 0)));
assert(otherObject);
{
bool filled = false;
float newY;
switch(otherObject->type())
{
case PhysicsObject::Type::Box:
{
const PhysicsBox * pbox = dynamic_cast<const PhysicsBox *>(otherObject.get());
VectorF min = pbox->center - pbox->extents;
VectorF max = pbox->center + pbox->extents;
if(min.x <= curBI.position().x && max.x >= curBI.position().x + 1 &&
min.y <= curBI.position().y && max.y >= curBI.position().y + 1 &&
min.z <= curBI.position().z && max.z >= curBI.position().z + 1)
{
newY = max.y + physicsObject.extents.y - physicsOffset().y;
filled = true;
}
VectorF temp;
if(isBoxCollision(pbox->center, pbox->extents, physicsObject.center - VectorF(0, eps * 10, 0) + physicsOffset(), physicsObject.extents, temp) && !isBoxCollision(pbox->center, pbox->extents, physicsObject.center + physicsOffset(), physicsObject.extents, temp))
{
supported = true;
}
break;
}
case PhysicsObject::Type::None:
break;
}
if(filled && zeroCount >= 2 && dx == 0 && dy == 0 && dz == 0)
{
firstCollision.time = 0;
firstCollision.newPosition = data.position;
firstCollision.newPosition.y = newY;
firstCollision.newVelocity = VectorF(0);
firstCollision.collisionNormal = VectorF(0, 1, 0);
break;
}
}
PhysicsCollision collision = physicsObject.collide(otherObject, deltaTime);
if(collision.valid)
{
if(collision.time < eps)
{
if(zeroCount > 25)
collision.valid = false;
else
zeroCount++;
}
else
zeroCount = 0;
}
if(collision.valid && collision.time < firstCollision.time)
firstCollision = collision;
}
}
}
deltaTime -= firstCollision.time;
data.setPosition(firstCollision.newPosition + eps * (2 + abs(firstCollision.newVelocity)) * firstCollision.collisionNormal);
data.setVelocity(firstCollision.newVelocity);
data.setAcceleration(data.entity->acceleration + data.entity->deltaAcceleration * firstCollision.time);
}
//.........这里部分代码省略.........