本文整理汇总了C++中MapBlock::getPos方法的典型用法代码示例。如果您正苦于以下问题:C++ MapBlock::getPos方法的具体用法?C++ MapBlock::getPos怎么用?C++ MapBlock::getPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MapBlock
的用法示例。
在下文中一共展示了MapBlock::getPos方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBlockNoCreateNoEx
MapBlock * Map::createBlankBlock(v3POS & p) {
auto lock = m_blocks.lock_unique_rec();
MapBlock *block = getBlockNoCreateNoEx(p, false, true);
if (block != NULL) {
infostream << "Block already created p=" << block->getPos() << std::endl;
return block;
}
block = createBlankBlockNoInsert(p);
m_blocks.set(p, block);
return block;
}
示例2: renderMap
//.........这里部分代码省略.........
u32 meshbuffer_count = 0;
// For limiting number of mesh animations per frame
u32 mesh_animate_count = 0;
u32 mesh_animate_count_far = 0;
// Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
// Blocks which had a corresponding meshbuffer for this pass
u32 blocks_had_pass_meshbuf = 0;
// Blocks from which stuff was actually drawn
u32 blocks_without_stuff = 0;
/*
Draw the selected MapBlocks
*/
{
ScopeProfiler sp(g_profiler, prefix+"drawing blocks", SPT_AVG);
MeshBufListList drawbufs;
for(std::map<v3s16, MapBlock*>::iterator
i = m_drawlist.begin();
i != m_drawlist.end(); ++i)
{
MapBlock *block = i->second;
// If the mesh of the block happened to get deleted, ignore it
if(block->mesh == NULL)
continue;
float d = 0.0;
if(isBlockInSight(block->getPos(), camera_position,
camera_direction, camera_fov,
100000*BS, &d) == false)
{
continue;
}
// Mesh animation
{
//JMutexAutoLock lock(block->mesh_mutex);
MapBlockMesh *mapBlockMesh = block->mesh;
assert(mapBlockMesh);
// Pretty random but this should work somewhat nicely
bool faraway = d >= BS*50;
//bool faraway = d >= m_control.wanted_range * BS;
if(mapBlockMesh->isAnimationForced() ||
!faraway ||
mesh_animate_count_far < (m_control.range_all ? 200 : 50))
{
bool animated = mapBlockMesh->animate(
faraway,
animation_time,
crack,
daynight_ratio);
if(animated)
mesh_animate_count++;
if(animated && faraway)
mesh_animate_count_far++;
}
else
{
mapBlockMesh->decreaseAnimationForceTimer();
}
示例3: updateDrawList
void ClientMap::updateDrawList(video::IVideoDriver* driver)
{
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
g_profiler->add("CM::updateDrawList() count", 1);
INodeDefManager *nodemgr = m_gamedef->ndef();
for(std::map<v3s16, MapBlock*>::iterator
i = m_drawlist.begin();
i != m_drawlist.end(); ++i)
{
MapBlock *block = i->second;
block->refDrop();
}
m_drawlist.clear();
m_camera_mutex.Lock();
v3f camera_position = m_camera_position;
v3f camera_direction = m_camera_direction;
f32 camera_fov = m_camera_fov;
m_camera_mutex.Unlock();
// Use a higher fov to accomodate faster camera movements.
// Blocks are cropped better when they are drawn.
// Or maybe they aren't? Well whatever.
camera_fov *= 1.2;
v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
// Take a fair amount as we will be dropping more out later
// Umm... these additions are a bit strange but they are needed.
v3s16 p_blocks_min(
p_nodes_min.X / MAP_BLOCKSIZE - 3,
p_nodes_min.Y / MAP_BLOCKSIZE - 3,
p_nodes_min.Z / MAP_BLOCKSIZE - 3);
v3s16 p_blocks_max(
p_nodes_max.X / MAP_BLOCKSIZE + 1,
p_nodes_max.Y / MAP_BLOCKSIZE + 1,
p_nodes_max.Z / MAP_BLOCKSIZE + 1);
// Number of blocks in rendering range
u32 blocks_in_range = 0;
// Number of blocks occlusion culled
u32 blocks_occlusion_culled = 0;
// Number of blocks in rendering range but don't have a mesh
u32 blocks_in_range_without_mesh = 0;
// Blocks that had mesh that would have been drawn according to
// rendering range (if max blocks limit didn't kick in)
u32 blocks_would_have_drawn = 0;
// Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
// Blocks which had a corresponding meshbuffer for this pass
//u32 blocks_had_pass_meshbuf = 0;
// Blocks from which stuff was actually drawn
//u32 blocks_without_stuff = 0;
for(std::map<v2s16, MapSector*>::iterator
si = m_sectors.begin();
si != m_sectors.end(); ++si)
{
MapSector *sector = si->second;
v2s16 sp = sector->getPos();
if(m_control.range_all == false)
{
if(sp.X < p_blocks_min.X
|| sp.X > p_blocks_max.X
|| sp.Y < p_blocks_min.Z
|| sp.Y > p_blocks_max.Z)
continue;
}
std::list< MapBlock * > sectorblocks;
sector->getBlocks(sectorblocks);
/*
Loop through blocks in sector
*/
u32 sector_blocks_drawn = 0;
std::list< MapBlock * >::iterator i;
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{
MapBlock *block = *i;
/*
Compare block position to camera position, skip
if not seen on display
*/
float range = 100000 * BS;
if(m_control.range_all == false)
range = m_control.wanted_range * BS;
float d = 0.0;
if(isBlockInSight(block->getPos(), camera_position,
camera_direction, camera_fov,
//.........这里部分代码省略.........
示例4: deactivateFarObjects
/*
Convert objects that are not in active blocks to static.
If m_known_by_count != 0, active object is not deleted, but static
data is still updated.
If force_delete is set, active object is deleted nevertheless. It
shall only be set so in the destructor of the environment.
*/
void ServerEnvironment::deactivateFarObjects(bool force_delete)
{
core::list<u16> objects_to_remove;
for(core::map<u16, ServerActiveObject*>::Iterator
i = m_active_objects.getIterator();
i.atEnd()==false; i++)
{
ServerActiveObject* obj = i.getNode()->getValue();
u16 id = i.getNode()->getKey();
v3f objectpos = obj->getBasePosition();
// This shouldn't happen but check it
if(obj == NULL)
{
dstream<<"WARNING: NULL object found in ServerEnvironment"
<<std::endl;
assert(0);
continue;
}
// The block in which the object resides in
v3s16 blockpos_o = getNodeBlockPos(floatToInt(objectpos, BS));
// If block is active, don't remove
if(m_active_blocks.contains(blockpos_o))
continue;
/*
Update the static data
*/
// Delete old static object
MapBlock *oldblock = NULL;
if(obj->m_static_exists)
{
MapBlock *block = m_map->getBlockNoCreateNoEx
(obj->m_static_block);
if(block)
{
block->m_static_objects.remove(id);
oldblock = block;
}
}
// Create new static object
std::string staticdata = obj->getStaticData();
StaticObject s_obj(obj->getType(), objectpos, staticdata);
// Add to the block where the object is located in
v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
// Get or generate the block
MapBlock *block = m_map->emergeBlock(blockpos);
/*MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
if(block == NULL)
{
// Block not found. Is the old block still ok?
if(oldblock)
block = oldblock;
// Load from disk or generate
else
block = m_map->emergeBlock(blockpos);
}*/
if(block)
{
block->m_static_objects.insert(0, s_obj);
block->setChangedFlag();
obj->m_static_exists = true;
obj->m_static_block = block->getPos();
}
else{
dstream<<"WARNING: ServerEnv: Could not find or generate "
<<"a block for storing static object"<<std::endl;
obj->m_static_exists = false;
continue;
}
/*
Delete active object if not known by some client,
else set pending deactivation
*/
// If known by some client, don't delete.
if(obj->m_known_by_count > 0 && force_delete == false)
{
obj->m_pending_deactivation = true;
continue;
}
/*dstream<<"INFO: Server: Stored static data. Deleting object."
<<std::endl;*/
// Delete active object
//.........这里部分代码省略.........
示例5: renderMap
void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass)
{
DSTACK(FUNCTION_NAME);
bool is_transparent_pass = pass == scene::ESNRP_TRANSPARENT;
std::string prefix;
if (pass == scene::ESNRP_SOLID)
prefix = "CM: solid: ";
else
prefix = "CM: transparent: ";
/*
This is called two times per frame, reset on the non-transparent one
*/
if (pass == scene::ESNRP_SOLID)
m_last_drawn_sectors.clear();
/*
Get time for measuring timeout.
Measuring time is very useful for long delays when the
machine is swapping a lot.
*/
std::time_t time1 = time(0);
/*
Get animation parameters
*/
float animation_time = m_client->getAnimationTime();
int crack = m_client->getCrackLevel();
u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
v3f camera_position = m_camera_position;
v3f camera_direction = m_camera_direction;
f32 camera_fov = m_camera_fov;
/*
Get all blocks and draw all visible ones
*/
u32 vertex_count = 0;
u32 meshbuffer_count = 0;
// For limiting number of mesh animations per frame
u32 mesh_animate_count = 0;
u32 mesh_animate_count_far = 0;
// Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
// Blocks which had a corresponding meshbuffer for this pass
u32 blocks_had_pass_meshbuf = 0;
// Blocks from which stuff was actually drawn
u32 blocks_without_stuff = 0;
/*
Draw the selected MapBlocks
*/
{
ScopeProfiler sp(g_profiler, prefix + "drawing blocks", SPT_AVG);
MeshBufListList drawbufs;
for (std::map<v3s16, MapBlock*>::iterator i = m_drawlist.begin();
i != m_drawlist.end(); ++i) {
MapBlock *block = i->second;
// If the mesh of the block happened to get deleted, ignore it
if (!block->mesh)
continue;
float d = 0.0;
if (!isBlockInSight(block->getPos(), camera_position,
camera_direction, camera_fov, 100000 * BS, &d))
continue;
// Mesh animation
if (pass == scene::ESNRP_SOLID) {
//MutexAutoLock lock(block->mesh_mutex);
MapBlockMesh *mapBlockMesh = block->mesh;
assert(mapBlockMesh);
// Pretty random but this should work somewhat nicely
bool faraway = d >= BS * 50;
//bool faraway = d >= m_control.wanted_range * BS;
if (mapBlockMesh->isAnimationForced() || !faraway ||
mesh_animate_count_far < (m_control.range_all ? 200 : 50)) {
bool animated = mapBlockMesh->animate(faraway, animation_time,
crack, daynight_ratio);
if (animated)
mesh_animate_count++;
if (animated && faraway)
mesh_animate_count_far++;
} else {
mapBlockMesh->decreaseAnimationForceTimer();
}
}
/*
Get the meshbuffers of the block
//.........这里部分代码省略.........
示例6: updateDrawList
void ClientMap::updateDrawList(video::IVideoDriver* driver)
{
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
g_profiler->add("CM::updateDrawList() count", 1);
for (std::map<v3s16, MapBlock*>::iterator i = m_drawlist.begin();
i != m_drawlist.end(); ++i) {
MapBlock *block = i->second;
block->refDrop();
}
m_drawlist.clear();
v3f camera_position = m_camera_position;
v3f camera_direction = m_camera_direction;
f32 camera_fov = m_camera_fov;
// Use a higher fov to accomodate faster camera movements.
// Blocks are cropped better when they are drawn.
// Or maybe they aren't? Well whatever.
camera_fov *= 1.2;
v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
v3s16 p_blocks_min;
v3s16 p_blocks_max;
getBlocksInViewRange(cam_pos_nodes, &p_blocks_min, &p_blocks_max);
// Number of blocks in rendering range
u32 blocks_in_range = 0;
// Number of blocks occlusion culled
u32 blocks_occlusion_culled = 0;
// Number of blocks in rendering range but don't have a mesh
u32 blocks_in_range_without_mesh = 0;
// Blocks that had mesh that would have been drawn according to
// rendering range (if max blocks limit didn't kick in)
u32 blocks_would_have_drawn = 0;
// Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
// Blocks which had a corresponding meshbuffer for this pass
//u32 blocks_had_pass_meshbuf = 0;
// Blocks from which stuff was actually drawn
//u32 blocks_without_stuff = 0;
// Distance to farthest drawn block
float farthest_drawn = 0;
// No occlusion culling when free_move is on and camera is
// inside ground
bool occlusion_culling_enabled = true;
if (g_settings->getBool("free_move")) {
MapNode n = getNodeNoEx(cam_pos_nodes);
if (n.getContent() == CONTENT_IGNORE ||
m_nodedef->get(n).solidness == 2)
occlusion_culling_enabled = false;
}
for (std::map<v2s16, MapSector*>::iterator si = m_sectors.begin();
si != m_sectors.end(); ++si) {
MapSector *sector = si->second;
v2s16 sp = sector->getPos();
if (m_control.range_all == false) {
if (sp.X < p_blocks_min.X || sp.X > p_blocks_max.X ||
sp.Y < p_blocks_min.Z || sp.Y > p_blocks_max.Z)
continue;
}
MapBlockVect sectorblocks;
sector->getBlocks(sectorblocks);
/*
Loop through blocks in sector
*/
u32 sector_blocks_drawn = 0;
for (MapBlockVect::iterator i = sectorblocks.begin();
i != sectorblocks.end(); ++i) {
MapBlock *block = *i;
/*
Compare block position to camera position, skip
if not seen on display
*/
if (block->mesh)
block->mesh->updateCameraOffset(m_camera_offset);
float range = 100000 * BS;
if (!m_control.range_all)
range = m_control.wanted_range * BS;
float d = 0.0;
if (!isBlockInSight(block->getPos(), camera_position,
camera_direction, camera_fov, range, &d))
continue;
blocks_in_range++;
/*
Ignore if mesh doesn't exist
*/
//.........这里部分代码省略.........
示例7: renderMap
//.........这里部分代码省略.........
u32 mesh_animate_count = 0;
u32 mesh_animate_count_far = 0;
// Number of blocks in rendering range
u32 blocks_in_range = 0;
// Number of blocks occlusion culled
u32 blocks_occlusion_culled = 0;
// Number of blocks in rendering range but don't have a mesh
u32 blocks_in_range_without_mesh = 0;
// Blocks that had mesh that would have been drawn according to
// rendering range (if max blocks limit didn't kick in)
u32 blocks_would_have_drawn = 0;
// Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
// Blocks which had a corresponding meshbuffer for this pass
u32 blocks_had_pass_meshbuf = 0;
// Blocks from which stuff was actually drawn
u32 blocks_without_stuff = 0;
/*
Collect a set of blocks for drawing
*/
core::map<v3s16, MapBlock*> drawset;
{
ScopeProfiler sp(g_profiler, prefix+"collecting blocks for drawing", SPT_AVG);
for(core::map<v2s16, MapSector*>::Iterator
si = m_sectors.getIterator();
si.atEnd() == false; si++)
{
MapSector *sector = si.getNode()->getValue();
v2s16 sp = sector->getPos();
if(m_control.range_all == false)
{
if(sp.X < p_blocks_min.X
|| sp.X > p_blocks_max.X
|| sp.Y < p_blocks_min.Z
|| sp.Y > p_blocks_max.Z)
continue;
}
core::list< MapBlock * > sectorblocks;
sector->getBlocks(sectorblocks);
/*
Loop through blocks in sector
*/
u32 sector_blocks_drawn = 0;
core::list< MapBlock * >::Iterator i;
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{
MapBlock *block = *i;
/*
Compare block position to camera position, skip
if not seen on display
*/
float range = 100000 * BS;
if(m_control.range_all == false)
range = m_control.wanted_range * BS;
示例8: updateDrawList
void ClientMap::updateDrawList(video::IVideoDriver* driver, float dtime)
{
ScopeProfiler sp(g_profiler, "CM::updateDrawList()", SPT_AVG);
//g_profiler->add("CM::updateDrawList() count", 1);
INodeDefManager *nodemgr = m_gamedef->ndef();
if (!m_drawlist_last)
m_drawlist_current = !m_drawlist_current;
auto & drawlist = m_drawlist_current ? m_drawlist_1 : m_drawlist_0;
float max_cycle_ms = 0.1/getControl().fps_wanted;
u32 n = 0, calls = 0, end_ms = porting::getTimeMs() + max_cycle_ms;
m_camera_mutex.Lock();
v3f camera_position = m_camera_position;
v3f camera_direction = m_camera_direction;
f32 camera_fov = m_camera_fov;
v3s16 camera_offset = m_camera_offset;
m_camera_mutex.Unlock();
// Use a higher fov to accomodate faster camera movements.
// Blocks are cropped better when they are drawn.
// Or maybe they aren't? Well whatever.
camera_fov *= 1.2;
v3s16 cam_pos_nodes = floatToInt(camera_position, BS);
v3s16 box_nodes_d = m_control.wanted_range * v3s16(1,1,1);
v3s16 p_nodes_min = cam_pos_nodes - box_nodes_d;
v3s16 p_nodes_max = cam_pos_nodes + box_nodes_d;
// Take a fair amount as we will be dropping more out later
// Umm... these additions are a bit strange but they are needed.
v3s16 p_blocks_min(
p_nodes_min.X / MAP_BLOCKSIZE - 3,
p_nodes_min.Y / MAP_BLOCKSIZE - 3,
p_nodes_min.Z / MAP_BLOCKSIZE - 3);
v3s16 p_blocks_max(
p_nodes_max.X / MAP_BLOCKSIZE + 1,
p_nodes_max.Y / MAP_BLOCKSIZE + 1,
p_nodes_max.Z / MAP_BLOCKSIZE + 1);
// Number of blocks in rendering range
u32 blocks_in_range = 0;
// Number of blocks occlusion culled
u32 blocks_occlusion_culled = 0;
// Number of blocks in rendering range but don't have a mesh
u32 blocks_in_range_without_mesh = 0;
// Blocks that had mesh that would have been drawn according to
// rendering range (if max blocks limit didn't kick in)
u32 blocks_would_have_drawn = 0;
// Blocks that were drawn and had a mesh
u32 blocks_drawn = 0;
// Blocks which had a corresponding meshbuffer for this pass
//u32 blocks_had_pass_meshbuf = 0;
// Blocks from which stuff was actually drawn
//u32 blocks_without_stuff = 0;
// Distance to farthest drawn block
float farthest_drawn = 0;
{
auto lock = m_blocks.lock_shared_rec();
for(auto & ir : m_blocks) {
if (n++ < m_drawlist_last)
continue;
else
m_drawlist_last = 0;
++calls;
MapBlock *block = ir.second;
auto bp = block->getPos();
if(m_control.range_all == false)
{
if(bp.X < p_blocks_min.X
|| bp.X > p_blocks_max.X
|| bp.Z > p_blocks_max.Z
|| bp.Z < p_blocks_min.Z
|| bp.Y < p_blocks_min.Y
|| bp.Y > p_blocks_max.Y)
continue;
}
int mesh_step = getFarmeshStep(m_control, getNodeBlockPos(cam_pos_nodes).getDistanceFrom(block->getPos()));
/*
Compare block position to camera position, skip
if not seen on display
*/
if (block->getMesh(mesh_step) != NULL)
block->getMesh(mesh_step)->updateCameraOffset(m_camera_offset);
float range = 100000 * BS;
if(m_control.range_all == false)
range = m_control.wanted_range * BS;
float d = 0.0;
if(isBlockInSight(block->getPos(), camera_position,
camera_direction, camera_fov,
range, &d) == false)
//.........这里部分代码省略.........
示例9: transformLiquidsReal
//.........这里部分代码省略.........
must_reflow_second.push_back(neighbors[i].pos + liquid_flow_dirs[ii]);
//must_reflow_second[neighbors[i].pos + liquid_flow_dirs[ii]] = 1;
}
}
#if LIQUID_DEBUG
if (liquid_levels_want[i] > 0)
flowed += liquid_levels_want[i];
#endif
if (liquid_levels[i] == liquid_levels_want[i]) {
continue;
}
if (neighbors[i].drop) {// && level_max > 1 && total_level >= level_max - 1
m_server->getEnv().getScriptIface()->node_drop(neighbors[i].pos, 2);
}
neighbors[i].node.setContent(liquid_kind_flowing);
neighbors[i].node.setLevel(nodemgr, liquid_levels_want[i], 1);
try {
setNode(neighbors[i].pos, neighbors[i].node);
} catch(InvalidPositionException &e) {
verbosestream << "transformLiquidsReal: setNode() failed:" << neighbors[i].pos << ":" << e.what() << std::endl;
}
// If node emits light, MapBlock requires lighting update
// or if node removed
v3POS blockpos = getNodeBlockPos(neighbors[i].pos);
MapBlock *block = getBlockNoCreateNoEx(blockpos, true); // remove true if light bugs
if(block != NULL) {
//modified_blocks[blockpos] = block;
if(!nodemgr->get(neighbors[i].node).light_propagates || nodemgr->get(neighbors[i].node).light_source) // better to update always
lighting_modified_blocks.set_try(block->getPos(), block);
}
// fmtodo: make here random %2 or..
if (total_level < level_max * can_liquid)
must_reflow.push_back(neighbors[i].pos);
}
#if LIQUID_DEBUG
//if (total_was != flowed) {
if (total_was > flowed) {
infostream << " volume changed! flowed=" << flowed << " total_was=" << total_was << " want_level=" << want_level;
for (u16 rr = 0; rr <= 6; rr++) {
infostream << " i=" << rr << ",b" << (int)liquid_levels[rr] << ",a" << (int)liquid_levels_want[rr];
}
infostream << std::endl;
}
#endif
/* //for better relax only same level
if (changed) for (u16 ii = D_SELF + 1; ii < D_TOP; ++ii) {
if (!neighbors[ii].l) continue;
must_reflow.push_back(p0 + dirs[ii]);
}*/
//g_profiler->graphAdd("liquids", 1);
}
u32 ret = loopcount >= initial_size ? 0 : transforming_liquid_size();
if (ret || loopcount > m_liquid_step_flow)
m_liquid_step_flow += (m_liquid_step_flow > loopcount ? -1 : 1) * (int)loopcount / 10;
/*
if (loopcount)
infostream<<"Map::transformLiquidsReal(): loopcount="<<loopcount<<" initial_size="<<initial_size
<<" avgflow="<<m_liquid_step_flow