本文整理汇总了C++中FileSpecifier::SetToImageCacheDir方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSpecifier::SetToImageCacheDir方法的具体用法?C++ FileSpecifier::SetToImageCacheDir怎么用?C++ FileSpecifier::SetToImageCacheDir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSpecifier
的用法示例。
在下文中一共展示了FileSpecifier::SetToImageCacheDir方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save_cache
void WadImageCache::save_cache()
{
if (!m_cache_dirty)
return;
InfoTree pt;
for (cache_iter_t it = m_used.begin(); it != m_used.end(); ++it)
{
std::string name = it->second.first;
WadImageDescriptor desc = boost::tuples::get<0>(it->first);
pt.put(name + ".path", desc.file.GetPath());
pt.put(name + ".checksum", desc.checksum);
pt.put(name + ".index", desc.index);
pt.put(name + ".tag", desc.tag);
pt.put(name + ".width", boost::tuples::get<1>(it->first));
pt.put(name + ".height", boost::tuples::get<2>(it->first));
pt.put(name + ".filesize", it->second.second);
}
FileSpecifier info;
info.SetToImageCacheDir();
info.AddPart("Cache.ini");
try {
pt.save_ini(info);
m_cache_dirty = false;
} catch (InfoTree::ini_error e) {
logError("Could not save image cache to %s (%s)", info.GetPath(), e.what());
return;
}
}
示例2: delete_storage_for_name
void WadImageCache::delete_storage_for_name(std::string& name) const
{
FileSpecifier file;
file.SetToImageCacheDir();
file.AddPart(name);
file.Delete();
}
示例3:
SDL_Surface *WadImageCache::image_from_name(std::string& name) const
{
FileSpecifier file;
file.SetToImageCacheDir();
file.AddPart(name);
OpenedFile of;
if (!file.Open(of))
return NULL;
#ifdef HAVE_SDL_IMAGE
SDL_Surface *img = IMG_Load_RW(of.GetRWops(), 0);
#else
SDL_Surface *img = SDL_LoadBMP_RW(of.GetRWops(), 0);
#endif
return img;
}
示例4: initialize_cache
void WadImageCache::initialize_cache()
{
FileSpecifier info;
info.SetToImageCacheDir();
info.AddPart("Cache.ini");
if (!info.Exists())
return;
InfoTree pt;
try {
pt = InfoTree::load_ini(info);
} catch (InfoTree::ini_error e) {
logError("Could not read image cache from %s (%s)", info.GetPath(), e.what());
}
for (InfoTree::iterator it = pt.begin(); it != pt.end(); ++it)
{
std::string name = it->first;
InfoTree ptc = it->second;
WadImageDescriptor desc;
std::string path;
ptc.read("path", path);
desc.file = FileSpecifier(path);
ptc.read("checksum", desc.checksum);
ptc.read("index", desc.index);
ptc.read("tag", desc.tag);
int width = 0;
ptc.read("width", width);
int height = 0;
ptc.read("height", height);
size_t filesize = 0;
ptc.read("filesize", filesize);
cache_key_t key = cache_key_t(desc, width, height);
cache_value_t val = cache_value_t(name, filesize);
m_used.push_front(cache_pair_t(key, val));
m_cacheinfo[key] = m_used.begin();
m_cachesize += filesize;
}
}
示例5: image_to_new_name
std::string WadImageCache::image_to_new_name(SDL_Surface *image, int32 *filesize) const
{
// create name
boost::uuids::random_generator gen;
boost::uuids::uuid u = gen();
std::string ustr = boost::uuids::to_string(u);
FileSpecifier File;
File.SetToImageCacheDir();
File.AddPart(ustr);
FileSpecifier TempFile;
TempFile.SetTempName(File);
int ret;
//#if defined(HAVE_PNG) && defined(HAVE_SDL_IMAGE)
// ret = aoIMG_SavePNG(TempFile.GetPath(), image, IMG_COMPRESS_DEFAULT, NULL, 0);
#ifdef HAVE_SDL_IMAGE
ret = IMG_SavePNG(image, TempFile.GetPath());
#else
ret = SDL_SaveBMP(image, TempFile.GetPath());
#endif
if (ret == 0 && TempFile.Rename(File))
{
if (filesize)
{
OpenedFile of;
if (File.Open(of))
of.GetLength(*filesize);
}
return ustr;
}
if (filesize)
*filesize = 0;
return "";
}