Author: loonycyborg
Date: Sat Dec 6 23:41:32 2008
New Revision: 31323
URL: http://svn.gna.org/viewcvs/wesnoth?rev=31323&view=rev
Log:
Reverted Dave's changes to image cache in r31277 since they were causing
serious slowdowns e.g. during animations.
Modified:
trunk/src/image.cpp
trunk/src/image.hpp
Modified: trunk/src/image.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.cpp?rev=31323&r1=31322&r2=31323&view=diff
==============================================================================
--- trunk/src/image.cpp (original)
+++ trunk/src/image.cpp Sat Dec 6 23:41:32 2008
@@ -67,8 +67,8 @@
std::list<int> dummy_list;
-template<typename T, typename SizeFunctor>
-void cache_type<T, SizeFunctor>::flush()
+template<typename T>
+void cache_type<T>::flush()
{
typename std::vector<cache_item<T> >::iterator beg = content_.begin();
typename std::vector<cache_item<T> >::iterator end = content_.end();
@@ -780,9 +780,6 @@
res = create_optimized_surface(res);
i_locator.add_to_cache(*imap, res);
- DBG_CACHE << "IMAGES: " << (images_.size()/1024) << " HEXED: " <<
(images_.size()/1024) << " SCALED_TO_HEX: " <<
(scaled_to_hex_images_.size()/1024) << " SCALED_TO_ZOOM: " <<
(scaled_to_zoom_.size()/1024) << " UNMASKED: " <<
(unmasked_images_.size()/1024) << " BRIGHTENED: " <<
(brightened_images_.size()/1024) << " SEMI: " <<
(semi_brightened_images_.size()/1024)
- << " TOTAL: " << (images_.size() + hexed_images_.size() +
scaled_to_hex_images_.size() + scaled_to_zoom_.size() + unmasked_images_.size()
+ brightened_images_.size() + semi_brightened_images_.size())/(1024*1024) <<
"\n";
-
return res;
}
@@ -868,8 +865,8 @@
}
-template<typename T, typename SizeFunctor>
-cache_item<T>& cache_type<T, SizeFunctor>::get_element(int index){
+template<typename T>
+cache_item<T>& cache_type<T>::get_element(int index){
assert (index != -1);
while(static_cast<size_t>(index) >= content_.size()) {
content_.push_back(cache_item<T>());
@@ -883,22 +880,19 @@
}
return elt;
}
-template<typename T, typename SizeFunctor>
-void cache_type<T, SizeFunctor>::on_load(int index){
+template<typename T>
+void cache_type<T>::on_load(int index){
if(index == -1) return ;
cache_item<T>& elt = content_[index];
if(!elt.loaded) return ;
lru_list_.push_front(index);
- DBG_CACHE << "cache size: " << size_functor_(elt.item) << "\n";
- DBG_CACHE << "cache size max: " << cache_size_ << "/" <<
cache_max_size_ << "\n";
- cache_size_ += size_functor_(elt.item);
elt.position = lru_list_.begin();
while(cache_size_ > cache_max_size_-100) {
cache_item<T>& elt = content_[lru_list_.back()];
- cache_size_ -= size_functor_(elt.item);
elt.loaded=false;
elt.item = T();
lru_list_.pop_back();
+ cache_size_--;
}
}
Modified: trunk/src/image.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/image.hpp?rev=31323&r1=31322&r2=31323&view=diff
==============================================================================
--- trunk/src/image.hpp (original)
+++ trunk/src/image.hpp Sat Dec 6 23:41:32 2008
@@ -72,22 +72,13 @@
std::list<int>::iterator position;
};
- struct SizeSurface {
- int operator()(const surface& s) const { return 256 + (s ?
s->w*s->h*4 : 0); }
- };
-
- struct SizeOne {
- template<typename T>
- int operator()(const T&) const { return 1; }
- };
-
- template<typename T, typename SizeFunctor>
+ template<typename T>
class cache_type
{
public:
cache_type() :
cache_size_(0),
- cache_max_size_(10000000),
+ cache_max_size_(2000),
lru_list_(),
content_()
{
@@ -96,13 +87,11 @@
cache_item<T>& get_element(int index);
void on_load(int index);
void flush();
- size_t size() const { return cache_size_; }
private:
- size_t cache_size_;
- size_t cache_max_size_;
+ int cache_size_;
+ int cache_max_size_;
std::list<int> lru_list_;
std::vector<cache_item<T> > content_;
- SizeFunctor size_functor_;
};
//a generic image locator. Abstracts the location of an image.
@@ -167,18 +156,18 @@
// loads the image it is pointing to from the disk
surface load_from_disk() const;
- bool in_cache(cache_type<surface,SizeSurface>& cache) const
+ bool in_cache(cache_type<surface>& cache) const
{ return index_ == -1 ? false :
cache.get_element(index_).loaded; }
- surface locate_in_cache(cache_type<surface,SizeSurface>& cache)
const
+ surface locate_in_cache(cache_type<surface>& cache) const
{ return index_ == -1 ? surface() :
cache.get_element(index_).item; }
- void add_to_cache(cache_type<surface,SizeSurface>& cache, const
surface &image) const
+ void add_to_cache(cache_type<surface>& cache, const surface
&image) const
{ if(index_ != -1 ) cache.get_element(index_) =
cache_item<surface>(image); cache.on_load(index_); }
- bool in_cache(cache_type<locator,SizeOne>& cache) const
+ bool in_cache(cache_type<locator>& cache) const
{ return index_ == -1 ? false :
cache.get_element(index_).loaded; cache.on_load(index_); }
- locator locate_in_cache(cache_type<locator,SizeOne>& cache)
const
+ locator locate_in_cache(cache_type<locator>& cache) const
{ return index_ == -1 ? locator() :
cache.get_element(index_).item; }
- void add_to_cache(cache_type<locator,SizeOne>& cache, const
locator &image) const
+ void add_to_cache(cache_type<locator>& cache, const locator
&image) const
{ if(index_ != -1) cache.get_element(index_) =
cache_item<locator>(image); }
protected:
static int last_index_;
@@ -192,8 +181,8 @@
};
- typedef cache_type<surface,SizeSurface> image_cache;
- typedef cache_type<locator,SizeOne> locator_cache;
+ typedef cache_type<surface> image_cache;
+ typedef cache_type<locator> locator_cache;
typedef std::map<t_translation::t_terrain, surface>
mini_terrain_cache_map;
extern mini_terrain_cache_map mini_terrain_cache;
extern mini_terrain_cache_map mini_fogged_terrain_cache;
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits