本文整理汇总了C++中core::map::find方法的典型用法代码示例。如果您正苦于以下问题:C++ map::find方法的具体用法?C++ map::find怎么用?C++ map::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core::map
的用法示例。
在下文中一共展示了map::find方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
DebugStacker::DebugStacker(const char *text)
{
threadid_t threadid = get_current_thread_id();
JMutexAutoLock lock(g_debug_stacks_mutex);
core::map<threadid_t, DebugStack*>::Node *n;
n = g_debug_stacks.find(threadid);
if(n != NULL)
{
m_stack = n->getValue();
}
else
{
/*DEBUGPRINT("Creating new debug stack for thread %x\n",
(unsigned int)threadid);*/
m_stack = new DebugStack(threadid);
g_debug_stacks.insert(threadid, m_stack);
}
if(m_stack->stack_i >= DEBUG_STACK_SIZE)
{
m_overflowed = true;
}
else
{
m_overflowed = false;
snprintf(m_stack->stack[m_stack->stack_i],
DEBUG_STACK_TEXT_SIZE, "%s", text);
m_stack->stack_i++;
if(m_stack->stack_i > m_stack->stack_max_i)
m_stack->stack_max_i = m_stack->stack_i;
}
}
示例2: getTextureId
u32 TextureSource::getTextureId(const std::string &name)
{
//infostream<<"getTextureId(): \""<<name<<"\""<<std::endl;
{
/*
See if texture already exists
*/
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
core::map<std::string, u32>::Node *n;
n = m_name_to_id.find(name);
if(n != NULL)
{
return n->getValue();
}
}
/*
Get texture
*/
if(get_current_thread_id() == m_main_thread)
{
return getTextureIdDirect(name);
}
else
{
infostream<<"getTextureId(): Queued: name=\""<<name<<"\""<<std::endl;
// We're gonna ask the result to be put into here
ResultQueue<std::string, u32, u8, u8> result_queue;
// Throw a request in
m_get_texture_queue.add(name, 0, 0, &result_queue);
infostream<<"Waiting for texture from main thread, name=\""
<<name<<"\""<<std::endl;
try
{
// Wait result for a second
GetResult<std::string, u32, u8, u8>
result = result_queue.pop_front(1000);
// Check that at least something worked OK
assert(result.key == name);
return result.item;
}
catch(ItemNotFoundException &e)
{
infostream<<"Waiting for texture timed out."<<std::endl;
return 0;
}
}
infostream<<"getTextureId(): Failed"<<std::endl;
return 0;
}
示例3: getAddedActiveObjects
/*
Finds out what new objects have been added to
inside a radius around a position
*/
void ServerEnvironment::getAddedActiveObjects(v3s16 pos, s16 radius,
core::map<u16, bool> ¤t_objects,
core::map<u16, bool> &added_objects)
{
v3f pos_f = intToFloat(pos, BS);
f32 radius_f = radius * BS;
/*
Go through the object list,
- discard m_removed objects,
- discard objects that are too far away,
- discard objects that are found in current_objects.
- add remaining objects to added_objects
*/
for(core::map<u16, ServerActiveObject*>::Iterator
i = m_active_objects.getIterator();
i.atEnd()==false; i++)
{
u16 id = i.getNode()->getKey();
// Get object
ServerActiveObject *object = i.getNode()->getValue();
if(object == NULL)
continue;
// Discard if removed
if(object->m_removed)
continue;
// Discard if too far
f32 distance_f = object->getBasePosition().getDistanceFrom(pos_f);
if(distance_f > radius_f)
continue;
// Discard if already on current_objects
core::map<u16, bool>::Node *n;
n = current_objects.find(id);
if(n != NULL)
continue;
// Add to added_objects
added_objects.insert(id, false);
}
}
示例4: ground_height
HeightPoint ground_height(u64 seed, v2s16 p2d)
{
core::map<v2s16, HeightPoint>::Node *n = g_heights.find(p2d);
if(n)
return n->getValue();
HeightPoint hp;
s16 level = mapgen::find_ground_level_from_noise(seed, p2d, 3);
hp.gh = (level-4)*BS;
hp.ma = (4)*BS;
/*hp.gh = BS*base_rock_level_2d(seed, p2d);
hp.ma = BS*get_mud_add_amount(seed, p2d);*/
hp.have_sand = mapgen::get_have_sand(seed, p2d);
if(hp.gh > BS*WATER_LEVEL)
hp.tree_amount = mapgen::tree_amount_2d(seed, p2d);
else
hp.tree_amount = 0;
// No mud has been added if mud amount is less than 1
if(hp.ma < 1.0*BS)
hp.ma = 0.0;
//hp.gh -= BS*3; // Lower a bit so that it is not that much in the way
g_heights[p2d] = hp;
return hp;
}
示例5: buildMainAtlas
//.........这里部分代码省略.........
NULL);*/
img2->copyTo(atlas_img,
pos_in_atlas + v2s32(j*dim.Width,0),
core::rect<s32>(v2s32(0,0), dim),
NULL);
}
// Copy the borders a few times to disallow texture bleeding
for(u32 side=0; side<2; side++) // top and bottom
for(s32 y0=0; y0<padding; y0++)
for(s32 x0=0; x0<(s32)xwise_tiling*(s32)dim.Width; x0++)
{
s32 dst_y;
s32 src_y;
if(side==0)
{
dst_y = y0 + pos_in_atlas.Y + dim.Height;
src_y = pos_in_atlas.Y + dim.Height - 1;
}
else
{
dst_y = -y0 + pos_in_atlas.Y-1;
src_y = pos_in_atlas.Y;
}
s32 x = x0 + pos_in_atlas.X;
video::SColor c = atlas_img->getPixel(x, src_y);
atlas_img->setPixel(x,dst_y,c);
}
img2->drop();
/*
Add texture to caches
*/
bool reuse_old_id = false;
u32 id = m_atlaspointer_cache.size();
// Check old id without fetching a texture
core::map<std::string, u32>::Node *n;
n = m_name_to_id.find(name);
// If it exists, we will replace the old definition
if(n){
id = n->getValue();
reuse_old_id = true;
/*infostream<<"TextureSource::buildMainAtlas(): "
<<"Replacing old AtlasPointer"<<std::endl;*/
}
// Create AtlasPointer
AtlasPointer ap(id);
ap.atlas = NULL; // Set on the second pass
ap.pos = v2f((float)pos_in_atlas.X/(float)atlas_dim.Width,
(float)pos_in_atlas.Y/(float)atlas_dim.Height);
ap.size = v2f((float)dim.Width/(float)atlas_dim.Width,
(float)dim.Width/(float)atlas_dim.Height);
ap.tiled = xwise_tiling;
// Create SourceAtlasPointer and add to containers
SourceAtlasPointer nap(name, ap, atlas_img, pos_in_atlas, dim);
if(reuse_old_id)
m_atlaspointer_cache[id] = nap;
else
m_atlaspointer_cache.push_back(nap);
m_name_to_id[name] = id;
// Increment position
pos_in_atlas.Y += dim.Height + padding * 2;
}
/*
Make texture
*/
video::ITexture *t = driver->addTexture("__main_atlas__", atlas_img);
assert(t);
/*
Second pass: set texture pointer in generated AtlasPointers
*/
for(core::map<std::string, bool>::Iterator
i = sourcelist.getIterator();
i.atEnd() == false; i++)
{
std::string name = i.getNode()->getKey();
if(m_name_to_id.find(name) == NULL)
continue;
u32 id = m_name_to_id[name];
//infostream<<"id of name "<<name<<" is "<<id<<std::endl;
m_atlaspointer_cache[id].a.atlas = t;
}
/*
Write image to file so that it can be inspected
*/
/*std::string atlaspath = porting::path_user
+ DIR_DELIM + "generated_texture_atlas.png";
infostream<<"Removing and writing texture atlas for inspection to "
<<atlaspath<<std::endl;
fs::RecursiveDelete(atlaspath);
driver->writeImageToFile(atlas_img, atlaspath.c_str());*/
}
示例6: getTextureIdDirect
/*
This method generates all the textures
*/
u32 TextureSource::getTextureIdDirect(const std::string &name)
{
//infostream<<"getTextureIdDirect(): name=\""<<name<<"\""<<std::endl;
// Empty name means texture 0
if(name == "")
{
infostream<<"getTextureIdDirect(): name is empty"<<std::endl;
return 0;
}
/*
Calling only allowed from main thread
*/
if(get_current_thread_id() != m_main_thread)
{
errorstream<<"TextureSource::getTextureIdDirect() "
"called not from main thread"<<std::endl;
return 0;
}
/*
See if texture already exists
*/
{
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
core::map<std::string, u32>::Node *n;
n = m_name_to_id.find(name);
if(n != NULL)
{
/*infostream<<"getTextureIdDirect(): \""<<name
<<"\" found in cache"<<std::endl;*/
return n->getValue();
}
}
/*infostream<<"getTextureIdDirect(): \""<<name
<<"\" NOT found in cache. Creating it."<<std::endl;*/
/*
Get the base image
*/
char separator = '^';
/*
This is set to the id of the base image.
If left 0, there is no base image and a completely new image
is made.
*/
u32 base_image_id = 0;
// Find last meta separator in name
s32 last_separator_position = -1;
for(s32 i=name.size()-1; i>=0; i--)
{
if(name[i] == separator)
{
last_separator_position = i;
break;
}
}
/*
If separator was found, construct the base name and make the
base image using a recursive call
*/
std::string base_image_name;
if(last_separator_position != -1)
{
// Construct base name
base_image_name = name.substr(0, last_separator_position);
/*infostream<<"getTextureIdDirect(): Calling itself recursively"
" to get base image of \""<<name<<"\" = \""
<<base_image_name<<"\""<<std::endl;*/
base_image_id = getTextureIdDirect(base_image_name);
}
//infostream<<"base_image_id="<<base_image_id<<std::endl;
video::IVideoDriver* driver = m_device->getVideoDriver();
assert(driver);
video::ITexture *t = NULL;
/*
An image will be built from files and then converted into a texture.
*/
video::IImage *baseimg = NULL;
// If a base image was found, copy it to baseimg
if(base_image_id != 0)
{
JMutexAutoLock lock(m_atlaspointer_cache_mutex);
SourceAtlasPointer ap = m_atlaspointer_cache[base_image_id];
//.........这里部分代码省略.........