comparison engine/core/util/resource/pool.cpp @ 148:72c25cc27d8b

For your convenience pools now have a function called purgeLoadedResources exposed to python which will delete all loaded resources that have a ref count of zero. You can use this after closing a map or something alike. It may however impact performance, as the next map may very well reload the same resources. Just be aware of that. :-)
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Sat, 11 Oct 2008 06:05:11 +0000
parents fb6ccb367dd1
children 823544621b5b
comparison
equal deleted inserted replaced
147:fb6ccb367dd1 148:72c25cc27d8b
47 47
48 Pool::~Pool() { 48 Pool::~Pool() {
49 FL_LOG(_log, LMsg("Pool destroyed: ") << m_name); 49 FL_LOG(_log, LMsg("Pool destroyed: ") << m_name);
50 printStatistics(); 50 printStatistics();
51 sanityCheck(); 51 sanityCheck();
52 clear(); 52 reset();
53 std::vector<ResourceLoader*>::iterator loader; 53 std::vector<ResourceLoader*>::iterator loader;
54 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) { 54 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) {
55 delete (*loader); 55 delete (*loader);
56 } 56 }
57 } 57 }
58 58
59 void Pool::clear() { 59 void Pool::reset() {
60 std::vector<IPoolListener*>::iterator listener; 60 std::vector<IPoolListener*>::iterator listener;
61 for (listener = m_listeners.begin(); listener != m_listeners.end(); listener++) { 61 for (listener = m_listeners.begin(); listener != m_listeners.end(); listener++) {
62 (*listener)->poolCleared(); 62 (*listener)->poolCleared();
63 } 63 }
64 std::vector<PoolEntry*>::iterator entry; 64 std::vector<PoolEntry*>::iterator entry;
71 } 71 }
72 delete (*entry); 72 delete (*entry);
73 } 73 }
74 m_entries.clear(); 74 m_entries.clear();
75 m_location_to_entry.clear(); 75 m_location_to_entry.clear();
76 }
77
78 int Pool::purgeLoadedResources() {
79 std::vector<IPoolListener*>::iterator listener;
80 for (listener = m_listeners.begin(); listener != m_listeners.end(); listener++) {
81 (*listener)->poolCleared();
82 }
83 int count = 0;
84 std::vector<PoolEntry*>::iterator it;
85 for (it = m_entries.begin(); it != m_entries.end(); it++) {
86 PoolEntry* entry = *it;
87 if( entry->resource && entry->resource->getRefCount() == 0 ) {
88 delete entry->resource;
89 entry->resource = 0;
90 ++count;
91 }
92 }
93 return count;
76 } 94 }
77 95
78 void Pool::addResourceLoader(ResourceLoader* loader) { 96 void Pool::addResourceLoader(ResourceLoader* loader) {
79 m_loaders.push_back(loader); 97 m_loaders.push_back(loader);
80 } 98 }