12 |
// |
// |
13 |
// $Id$ |
// $Id$ |
14 |
|
|
|
#include "texture.hpp" |
|
15 |
#include <ext/hash_map> |
#include <ext/hash_map> |
16 |
#include <string> |
#include <string> |
17 |
#include <functional> |
#include <functional> |
18 |
#include <utility> |
#include <utility> |
19 |
|
|
20 |
|
#include <boost/thread/mutex.hpp> |
21 |
#include <boost/shared_ptr.hpp> |
#include <boost/shared_ptr.hpp> |
22 |
#include <boost/filesystem/operations.hpp> |
#include <boost/filesystem/operations.hpp> |
23 |
#include <boost/bind.hpp> |
#include <boost/bind.hpp> |
24 |
#include <boost/format.hpp> |
#include <boost/format.hpp> |
25 |
#include <iostream> |
|
26 |
|
#include "texture.hpp" |
27 |
#include "texture-meta.hpp" |
#include "texture-meta.hpp" |
28 |
#include "log.hpp" |
#include "log.hpp" |
29 |
|
|
56 |
> TextureCache; |
> TextureCache; |
57 |
|
|
58 |
typedef TextureCache::value_type TextureCache_vt; |
typedef TextureCache::value_type TextureCache_vt; |
59 |
|
|
60 |
|
|
61 |
|
boost::mutex mutex; |
62 |
|
|
63 |
MetaMap meta; |
MetaMap meta; |
64 |
TextureCache texture_cache; |
TextureCache texture_cache; |
67 |
TextureMeta TextureManagerImpl::get_meta(const std::string& textureAlias); |
TextureMeta TextureManagerImpl::get_meta(const std::string& textureAlias); |
68 |
void cache(Texture_sp& texture, const std::string& alias); |
void cache(Texture_sp& texture, const std::string& alias); |
69 |
|
|
70 |
|
|
71 |
}; |
}; |
72 |
|
|
73 |
void |
void |
74 |
TextureManagerImpl :: cache(Texture_sp& texture, |
TextureManagerImpl :: cache(Texture_sp& texture, |
75 |
const std::string& alias) |
const std::string& alias) |
76 |
{ |
{ |
77 |
|
boost::mutex::scoped_lock L(mutex); |
78 |
texture_cache.insert(TextureCache_vt(alias, texture)); |
texture_cache.insert(TextureCache_vt(alias, texture)); |
79 |
return; |
return; |
80 |
} |
} |
81 |
Texture_sp |
Texture_sp |
82 |
TextureManagerImpl::check_cache(const std::string& textureAlias) |
TextureManagerImpl::check_cache(const std::string& textureAlias) |
83 |
{ |
{ |
84 |
|
boost::mutex::scoped_lock L(mutex); |
85 |
TextureCache::iterator tc_it = texture_cache.find(textureAlias); |
TextureCache::iterator tc_it = texture_cache.find(textureAlias); |
86 |
if (tc_it == texture_cache.end()) |
if (tc_it == texture_cache.end()) |
87 |
{ |
{ |
94 |
TextureMeta |
TextureMeta |
95 |
TextureManagerImpl::get_meta(const std::string& textureAlias) |
TextureManagerImpl::get_meta(const std::string& textureAlias) |
96 |
{ |
{ |
97 |
|
boost::mutex::scoped_lock L(mutex); |
98 |
MetaMap::iterator mm_it = meta.find(textureAlias); |
MetaMap::iterator mm_it = meta.find(textureAlias); |
99 |
if (mm_it == meta.end()) |
if (mm_it == meta.end()) |
100 |
{ |
{ |
118 |
{ |
{ |
119 |
impl->meta.insert(TextureManagerImpl::MetaMap::value_type(m->alias, *m)); |
impl->meta.insert(TextureManagerImpl::MetaMap::value_type(m->alias, *m)); |
120 |
} |
} |
|
/* |
|
|
void |
|
|
adjust_add_meta(boost::filesystem::path p, TextureManager*tm, const TextureMeta*m) |
|
|
{ |
|
|
// adjust filename |
|
|
|
|
|
boost::filesystem::path fullpath = p / m->filename; |
|
|
|
|
|
// std::cout << m->filename << " becomes " << fullpath.native_file_string() << std::endl; |
|
|
TextureMeta adjusted(*m); |
|
|
|
|
|
adjusted.filename=fullpath.native_file_string(); |
|
|
tm->add_meta(&adjusted); |
|
|
return; |
|
|
} |
|
|
*/ |
|
121 |
|
|
122 |
Texture_sp |
Texture_sp |
123 |
TextureManager::get(const std::string& texAlias) |
TextureManager::get(const std::string& texAlias) |
138 |
TextureManager::load_path(const boost::filesystem::path& p) |
TextureManager::load_path(const boost::filesystem::path& p) |
139 |
{ |
{ |
140 |
using boost::filesystem::path; |
using boost::filesystem::path; |
141 |
log::BufferedStream logstream; //(&log::server, log::Level::INFO); |
log::BufferedStream logstream; |
142 |
path mf = p / "textures" / "meta"; |
path mf = p / "textures" / "meta"; |
143 |
logstream << (boost::format("Loading texture metadata from '%1%'")%mf.native_file_string()).str() << log::commit; |
logstream << (boost::format("Loading texture metadata from '%1%'")%mf.native_file_string()).str() << log::commit; |
144 |
|
|