本文整理汇总了C++中MapBlock类的典型用法代码示例。如果您正苦于以下问题:C++ MapBlock类的具体用法?C++ MapBlock怎么用?C++ MapBlock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MapBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getBlockOrStartGen
bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
BlockMakeData *data, bool allow_gen)
{
#if !ENABLE_THREADS
auto lock = map->m_nothread_locker.lock_unique_rec();
#endif
MapBlock *block;
{
//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
//JMutexAutoLock envlock(m_server->m_env_mutex);
// Attempt to load block
block = map->getBlockNoCreateNoEx(p);
if (!block || block->isDummy()) {
EMERGE_DBG_OUT("not in memory, attempting to load from disk ag="<<allow_gen<<" block="<<block<<" p="<<p);
block = map->loadBlock(p);
if (block && block->isGenerated())
map->prepareBlock(block);
}
}
// If could not load and allowed to generate,
// start generation inside this same envlock
if (allow_gen && (!block)) {
EMERGE_DBG_OUT("generating b="<<block);
*b = block;
return map->initBlockMake(data, p);
}
*b = block;
return false;
}
示例2: getBlockOrStartGen
bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
BlockMakeData *data, bool allow_gen) {
//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
//JMutexAutoLock envlock(m_server->m_env_mutex);
// Attempt to load block
MapBlock *block = map->getBlockNoCreateNoEx(p);
if (!block || block->isDummy()) {
EMERGE_DBG_OUT("not in memory, attempting to load from disk ag="<<allow_gen<<" block="<<block<<" p="<<p);
block = map->loadBlock(p);
if(block)
{
// block->pushElementsToCircuit(m_circuit);
// m_circuit->processElementsQueue(*map, map->getNodeDefManager());
}
if (block && block->isGenerated())
map->prepareBlock(block);
}
// If could not load and allowed to generate,
// start generation inside this same envlock
if (allow_gen && (!block)) {
EMERGE_DBG_OUT("generating b="<<block);
*b = block;
return map->initBlockMake(data, p);
}
*b = block;
return false;
}
示例3: p2d
bool EmergeThread::getBlockOrStartGen(v3s16 p, MapBlock **b,
BlockMakeData *data, bool allow_gen) {
v2s16 p2d(p.X, p.Z);
//envlock: usually takes <=1ms, sometimes 90ms or ~400ms to acquire
JMutexAutoLock envlock(m_server->m_env_mutex);
// Load sector if it isn't loaded
if (map->getSectorNoGenerateNoEx(p2d) == NULL)
map->loadSectorMeta(p2d);
// Attempt to load block
MapBlock *block = map->getBlockNoCreateNoEx(p);
if (!block || block->isDummy() || !block->isGenerated()) {
EMERGE_DBG_OUT("not in memory, attempting to load from disk");
block = map->loadBlock(p);
if (block && block->isGenerated())
map->prepareBlock(block);
}
// If could not load and allowed to generate,
// start generation inside this same envlock
if (allow_gen && (block == NULL || !block->isGenerated())) {
EMERGE_DBG_OUT("generating");
*b = block;
return map->initBlockMake(data, p);
}
*b = block;
return false;
}
示例4: ScreenPosition
void TMissionEditor::DrawDrag(MapBlock& block)
{
if (dragline.b1.x!=int(0x80000000))
{
CurrCanvas->Pen(psSolid,(TColor)0xFF0000,1);
int x1,x2,x3,w,y1,y2,y3,h;
x2=dragline.b1.x;
y2=dragline.b1.y;
ScreenPosition(x2,y2);
x1=dragline.a.x;
y1=dragline.a.y;
if (x1!=int(0x80000000))
{
ScreenPosition(x1,y1);
block.MoveTo(x2,y2);
block.DragLineTo(x1,y1);
}
x3=dragline.c.x;
y3=dragline.c.y;
if (x3!=int(0x80000000))
{
ScreenPosition(x3,y3);
block.MoveTo(x3,y3);
block.DragLineTo(x2,y2);
}
w=dragline.bw.x;
h=dragline.bw.y;
if (w!=int(0x80000000))
{
w/=cmpixscale;
h/=cmpixscale;
block.Rectangle(x2-w,y2-h,x2+w,y2+h);
}
CurrCanvas->Pen(psSolid,(TColor)0x0000FF,1);
x2=dragline.b2.x;
y2=dragline.b2.y;
if (x2!=int(0x80000000))
{
ScreenPosition(x2,y2);
if (x1!=int(0x80000000))
{
block.MoveTo(x1,y1);
block.DragLineTo(x2,y2);
}
if (x3!=int(0x80000000))
{
block.MoveTo(x3,y3);
block.DragLineTo(x2,y2);
}
if (w!=int(0x80000000))
{
block.Rectangle(x2-w,y2-h,x2+w,y2+h);
}
}
}
}
示例5: satisfy
/*
Remove objects that satisfy (m_removed && m_known_by_count==0)
*/
void ServerEnvironment::removeRemovedObjects()
{
core::list<u16> objects_to_remove;
for(core::map<u16, ServerActiveObject*>::Iterator
i = m_active_objects.getIterator();
i.atEnd()==false; i++)
{
u16 id = i.getNode()->getKey();
ServerActiveObject* obj = i.getNode()->getValue();
// This shouldn't happen but check it
if(obj == NULL)
{
dstream<<"WARNING: NULL object found in ServerEnvironment"
<<" while finding removed objects. id="<<id<<std::endl;
// Id to be removed from m_active_objects
objects_to_remove.push_back(id);
continue;
}
/*
We will delete objects that are marked as removed or thatare
waiting for deletion after deactivation
*/
if(obj->m_removed == false && obj->m_pending_deactivation == false)
continue;
/*
Delete static data from block if is marked as removed
*/
if(obj->m_static_exists && obj->m_removed)
{
MapBlock *block = m_map->getBlockNoCreateNoEx(obj->m_static_block);
if(block)
{
block->m_static_objects.remove(id);
block->setChangedFlag();
}
}
// If m_known_by_count > 0, don't actually remove.
if(obj->m_known_by_count > 0)
continue;
// Delete
delete obj;
// Id to be removed from m_active_objects
objects_to_remove.push_back(id);
}
// Remove references from m_active_objects
for(core::list<u16>::Iterator i = objects_to_remove.begin();
i != objects_to_remove.end(); i++)
{
m_active_objects.remove(*i);
}
}
示例6: fill
void MeshMakeData::fill(u32 daynight_ratio, MapBlock *block)
{
m_daynight_ratio = daynight_ratio;
m_blockpos = block->getPos();
v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;
/*
There is no harm not copying the TempMods of the neighbors
because they are already copied to this block
*/
m_temp_mods.clear();
block->copyTempMods(m_temp_mods);
/*
Copy data
*/
// Allocate this block + neighbors
m_vmanip.clear();
m_vmanip.addArea(VoxelArea(blockpos_nodes-v3s16(1,1,1)*MAP_BLOCKSIZE,
blockpos_nodes+v3s16(1,1,1)*MAP_BLOCKSIZE*2-v3s16(1,1,1)));
{
//TimeTaker timer("copy central block data");
// 0ms
// Copy our data
block->copyTo(m_vmanip);
}
{
//TimeTaker timer("copy neighbor block data");
// 0ms
/*
Copy neighbors. This is lightning fast.
Copying only the borders would be *very* slow.
*/
// Get map
Map *map = block->getParent();
for(u16 i=0; i<6; i++)
{
const v3s16 &dir = g_6dirs[i];
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
b->copyTo(m_vmanip);
}
}
}
示例7: sp
void MeshMakeData::fill_data()
{
if (!block || filled)
return;
filled = true;
#if !defined(MESH_ZEROCOPY)
ScopeProfiler sp(g_profiler, "Client: Mesh data fill");
v3POS blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;
/*
Copy data
*/
// Allocate this block + neighbors
m_vmanip.clear();
VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE,
blockpos_nodes + v3s16(1,1,1) * MAP_BLOCKSIZE*2-v3s16(1,1,1));
m_vmanip.addArea(voxel_area);
{
//TimeTaker timer("copy central block data");
// 0ms
// Copy our data
block->copyTo(m_vmanip);
}
{
//TimeTaker timer("copy neighbor block data");
// 0ms
/*
Copy neighbors. This is lightning fast.
Copying only the borders would be *very* slow.
*/
// Get map
Map *map = block->getParent();
for(u16 i=0; i<26; i++)
{
const v3s16 &dir = g_26dirs[i];
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
b->copyTo(m_vmanip);
}
}
#endif
}
示例8: assert
u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
bool set_changed)
{
assert(object);
if(object->getId() == 0)
{
u16 new_id = getFreeServerActiveObjectId(m_active_objects);
if(new_id == 0)
{
dstream<<"WARNING: ServerEnvironment::addActiveObjectRaw(): "
<<"no free ids available"<<std::endl;
delete object;
return 0;
}
object->setId(new_id);
}
if(isFreeServerActiveObjectId(object->getId(), m_active_objects) == false)
{
dstream<<"WARNING: ServerEnvironment::addActiveObjectRaw(): "
<<"id is not free ("<<object->getId()<<")"<<std::endl;
delete object;
return 0;
}
/*dstream<<"INGO: ServerEnvironment::addActiveObjectRaw(): "
<<"added (id="<<object->getId()<<")"<<std::endl;*/
m_active_objects.insert(object->getId(), object);
// Add static object to active static list of the block
v3f objectpos = object->getBasePosition();
std::string staticdata = object->getStaticData();
StaticObject s_obj(object->getType(), objectpos, staticdata);
// Add to the block where the object is located in
v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
MapBlock *block = m_map->getBlockNoCreateNoEx(blockpos);
if(block)
{
block->m_static_objects.m_active.insert(object->getId(), s_obj);
object->m_static_exists = true;
object->m_static_block = blockpos;
if(set_changed)
block->setChangedFlag();
}
else{
dstream<<"WARNING: ServerEnv: Could not find a block for "
<<"storing newly added static active object"<<std::endl;
}
return object->getId();
}
示例9: makeMapBlockMesh
void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server)
{
/*infostream<<"Client::addUpdateMeshTask(): "
<<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
<<std::endl;*/
MapBlock *b = m_env.getMap().getBlockNoCreateNoEx(p);
if(b == NULL)
return;
/*
Create a task to update the mesh of the block
*/
MeshMakeData *data = new MeshMakeData;
{
//TimeTaker timer("data fill");
// Release: ~0ms
// Debug: 1-6ms, avg=2ms
data->fill(getDayNightRatio(), b);
}
// Debug wait
//while(m_mesh_update_thread.m_queue_in.size() > 0) sleep_ms(10);
// Add task to queue
m_mesh_update_thread.m_queue_in.addBlock(p, data, ack_to_server);
/*infostream<<"Mesh update input queue size is "
<<m_mesh_update_thread.m_queue_in.size()
<<std::endl;*/
#if 0
// Temporary test: make mesh directly in here
{
//TimeTaker timer("make mesh");
// 10ms
scene::SMesh *mesh_new = NULL;
mesh_new = makeMapBlockMesh(data);
b->replaceMesh(mesh_new);
delete data;
}
#endif
/*
Mark mesh as non-expired at this point so that it can already
be marked as expired again if the data changes
*/
b->setMeshExpired(false);
}
示例10: 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;
}
示例11: getNodeBlockPos
void NodeMetaRef::reportMetadataChange(NodeMetaRef *ref)
{
// NOTE: This same code is in rollback_interface.cpp
// Inform other things that the metadata has changed
v3s16 blockpos = getNodeBlockPos(ref->m_p);
MapEditEvent event;
event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
event.p = blockpos;
ref->m_env->getMap().dispatchEvent(&event);
// Set the block to be saved
MapBlock *block = ref->m_env->getMap().getBlockNoCreateNoEx(blockpos);
if(block)
block->raiseModified(MOD_STATE_WRITE_NEEDED,
"NodeMetaRef::reportMetadataChange");
}
示例12: fillBlockDataBegin
void MeshMakeData::fill(MapBlock *block)
{
fillBlockDataBegin(block->getPos());
fillBlockData(v3s16(0,0,0), block->getData());
// Get map for reading neigbhor blocks
Map *map = block->getParent();
for (u16 i=0; i<26; i++) {
const v3s16 &dir = g_26dirs[i];
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
fillBlockData(dir, b->getData());
}
}
示例13: MapBlock
/**
* Loads the terrain from a YAML file.
* @param node YAML node.
* @param mod Mod for the terrain.
*/
void RuleTerrain::load(const YAML::Node &node, Mod *mod)
{
if (const YAML::Node &map = node["mapDataSets"])
{
_mapDataSets.clear();
for (YAML::const_iterator i = map.begin(); i != map.end(); ++i)
{
_mapDataSets.push_back(mod->getMapDataSet(i->as<std::string>()));
}
}
if (const YAML::Node &map = node["mapBlocks"])
{
_mapBlocks.clear();
for (YAML::const_iterator i = map.begin(); i != map.end(); ++i)
{
MapBlock *mapBlock = new MapBlock((*i)["name"].as<std::string>());
mapBlock->load(*i);
_mapBlocks.push_back(mapBlock);
}
}
_name = node["name"].as<std::string>(_name);
if (const YAML::Node &civs = node["civilianTypes"])
{
_civilianTypes = civs.as<std::vector<std::string> >(_civilianTypes);
}
else
{
_civilianTypes.push_back("MALE_CIVILIAN");
_civilianTypes.push_back("FEMALE_CIVILIAN");
}
for (YAML::const_iterator i = node["music"].begin(); i != node["music"].end(); ++i)
{
_music.push_back((*i).as<std::string>(""));
}
if (node["depth"])
{
_minDepth = node["depth"][0].as<int>(_minDepth);
_maxDepth = node["depth"][1].as<int>(_maxDepth);
}
if (node["ambience"])
{
_ambience = mod->getSoundOffset(node["ambience"].as<int>(_ambience), "BATTLE.CAT");
}
_ambientVolume = node["ambientVolume"].as<double>(_ambientVolume);
_script = node["script"].as<std::string>(_script);
}
示例14: voxel_area
void MeshMakeData::fill(MapBlock *block)
{
m_blockpos = block->getPos();
v3s16 blockpos_nodes = m_blockpos*MAP_BLOCKSIZE;
/*
Copy data
*/
// Allocate this block + neighbors
m_vmanip.clear();
VoxelArea voxel_area(blockpos_nodes - v3s16(1,1,1) * MAP_BLOCKSIZE,
blockpos_nodes + v3s16(1,1,1) * MAP_BLOCKSIZE*2-v3s16(1,1,1));
m_vmanip.addArea(voxel_area);
{
//TimeTaker timer("copy central block data");
// 0ms
// Copy our data
block->copyTo(m_vmanip);
}
{
//TimeTaker timer("copy neighbor block data");
// 0ms
/*
Copy neighbors. This is lightning fast.
Copying only the borders would be *very* slow.
*/
// Get map
Map *map = block->getParent();
for(u16 i=0; i<26; i++)
{
const v3s16 &dir = g_26dirs[i];
v3s16 bp = m_blockpos + dir;
MapBlock *b = map->getBlockNoCreateNoEx(bp);
if(b)
b->copyTo(m_vmanip);
}
}
}
示例15: sqlite3_bind_int64
const DB::Block DBSQLite3::getBlockOnPos(const BlockPos &pos)
{
static thread_local MapBlock block;
block.reset();
block.setPos(pos);
int result = 0;
m_blocksQueriedCount++;
sqlite3_stmt *statement;
// Disabled RowID querying, as it may cause blocks not to be found when mapping
// while minetest is running (i.e. modifying blocks).
if (false && pos.databasePosIdIsValid()) {
statement = m_blockOnRowidStatement;
sqlite3_bind_int64(m_blockOnRowidStatement, 1, pos.databasePosId());
}
else {
statement = m_blockOnPosStatement;
sqlite3_bind_int64(m_blockOnPosStatement, 1, pos.databasePosI64());
}
while (true) {
result = sqlite3_step(statement);
if (result == SQLITE_ROW) {
//const auto *data = static_cast<const unsigned char *>(sqlite3_column_blob(statement, 1));
int size = sqlite3_column_bytes(statement, 1);
//block = MapBlock(pos, sqlite3_column_blob(statement, 1), size);
block.setData(sqlite3_column_blob(statement, 1), size);
//block.second.assign(&data[0], &data[size]);
m_blocksReadCount++;
break;
}
else if (result == SQLITE_BUSY) { // Wait some time and try again
sleepMs(10);
}
else {
break;
}
}
sqlite3_reset(statement);
return block;
}