Mercurial > fife-parpg
annotate 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 |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 /*************************************************************************** |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 * Copyright (C) 2005-2008 by the FIFE team * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 * http://www.fifengine.de * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 * This file is part of FIFE. * |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
6 * FIFE is free software; you can redistribute it and/or * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
8 * License as published by the Free Software Foundation; either * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
11 * This library is distributed in the hope that it will be useful, * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
14 * Lesser General Public License for more details. * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 * * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public * |
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
17 * License along with this library; if not, write to the * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 * Free Software Foundation, Inc., * |
46
90005975cdbb
* Final LGPL switch step by adjusting the file headers
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 ***************************************************************************/ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 // Standard C++ library includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 // 3rd party library includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 // FIFE includes |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 // These includes are split up in two parts, separated by one empty line |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 // First block: files included from the FIFE root src directory |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 // Second block: files included from the same folder |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 #include "util/base/exception.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 #include "util/log/logger.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 #include "pool.h" |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 namespace FIFE { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 static Logger _log(LM_POOL); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
38 Pool::Pool(const std::string& name): |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 m_entries(), |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
40 m_location_to_entry(), |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 m_listeners(), |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
42 m_loaders(), |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
43 m_curind(0), |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
44 m_name(name) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 Pool::~Pool() { |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
49 FL_LOG(_log, LMsg("Pool destroyed: ") << m_name); |
144
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
50 printStatistics(); |
147
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
51 sanityCheck(); |
148
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
52 reset(); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 std::vector<ResourceLoader*>::iterator loader; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 delete (*loader); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
58 |
148
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
59 void Pool::reset() { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 std::vector<IPoolListener*>::iterator listener; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 for (listener = m_listeners.begin(); listener != m_listeners.end(); listener++) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 (*listener)->poolCleared(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 std::vector<PoolEntry*>::iterator entry; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
66 // Warn about leaks, but at least display ALL of them |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
67 // Instead of bailing out with an exception in the FifeClass destructor. |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
68 if( (*entry)->resource && (*entry)->resource->getRefCount() > 0 ) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
69 FL_WARN(_log, LMsg(m_name + " leak: ") << (*entry)->location->getFilename()); |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
70 (*entry)->resource = 0; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
71 } |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
72 delete (*entry); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
73 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
74 m_entries.clear(); |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
75 m_location_to_entry.clear(); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 |
148
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
78 int Pool::purgeLoadedResources() { |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
79 std::vector<IPoolListener*>::iterator listener; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
80 for (listener = m_listeners.begin(); listener != m_listeners.end(); listener++) { |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
81 (*listener)->poolCleared(); |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
82 } |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
83 int count = 0; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
84 std::vector<PoolEntry*>::iterator it; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
85 for (it = m_entries.begin(); it != m_entries.end(); it++) { |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
86 PoolEntry* entry = *it; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
87 if( entry->resource && entry->resource->getRefCount() == 0 ) { |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
88 delete entry->resource; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
89 entry->resource = 0; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
90 ++count; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
91 } |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
92 } |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
93 return count; |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
94 } |
72c25cc27d8b
For your convenience pools now have a function
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
147
diff
changeset
|
95 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 void Pool::addResourceLoader(ResourceLoader* loader) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 m_loaders.push_back(loader); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 int Pool::addResourceFromLocation(const ResourceLocation& loc) { |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
101 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc); |
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
102 if (it != m_location_to_entry.end()) { |
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
103 return (*it).second; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 PoolEntry* entry = new PoolEntry(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 entry->location = loc.clone(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 m_entries.push_back(entry); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
109 size_t index = m_entries.size() - 1; |
100
69a7d40ccf62
added hashing to pool to improve techdemo loading time
jasoka@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
46
diff
changeset
|
110 m_location_to_entry[loc] = index; |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
111 return index; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 int Pool::addResourceFromFile(const std::string& filename) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 return addResourceFromLocation(ResourceLocation(filename)); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 IResource& Pool::get(unsigned int index, bool inc) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 if (index >= m_entries.size()) { |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
120 FL_ERR(_log, LMsg("Tried to get with index ") << index << ", only " << m_entries.size() << " items in pool " + m_name); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 throw IndexOverflow( __FUNCTION__ ); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 IResource* res = NULL; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 PoolEntry* entry = m_entries[index]; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 if (entry->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 res = entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 } else { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 if (!entry->loader) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 findAndSetProvider(*entry); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 } else { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 entry->resource = entry->loader->loadResource(*entry->location); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 } |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
133 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 if (!entry->loader) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 LMsg msg("No suitable loader was found for resource "); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
136 msg << "#" << index << "<" << entry->location->getFilename() |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
137 << "> in pool " << m_name; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 FL_ERR(_log, msg); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
139 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 throw NotFound(msg.str); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 } |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
142 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 if (!entry->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
144 LMsg msg("No loader was able to load the requested resource "); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
145 msg << "#" << index << "<" << entry->location->getFilename() |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
146 << "> in pool " << m_name; |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 FL_ERR(_log, msg); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
148 throw NotFound(msg.str); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
149 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
150 res = entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
151 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
152 if (inc) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
153 res->addRef(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
155 res->setPoolId(index); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
156 return *res; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
159 int Pool::getIndex(const std::string& filename) { |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 // create resource |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 return addResourceFromFile(filename); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 void Pool::release(unsigned int index, bool dec) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 if (index >= m_entries.size()) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 throw IndexOverflow( __FUNCTION__ ); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 IResource* res = NULL; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 PoolEntry* entry = m_entries[index]; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 if (entry->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 res = entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 if (dec) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
174 res->decRef(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
175 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
176 if(res->getRefCount() == 0) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
177 delete entry->resource; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
178 entry->resource = 0; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
179 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
180 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
181 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
182 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
183 int Pool::getResourceCount(int status) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
184 int amount = 0; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
185 std::vector<PoolEntry*>::iterator entry; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
186 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
187 if (status & RES_LOADED) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
188 if ((*entry)->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
189 amount++; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
190 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
191 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
192 if (status & RES_NON_LOADED) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
193 if (!(*entry)->resource) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
194 amount++; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
195 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
196 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
197 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
198 return amount; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
199 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
200 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
201 void Pool::addPoolListener(IPoolListener* listener) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
202 m_listeners.push_back(listener); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
203 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
204 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
205 void Pool::removePoolListener(IPoolListener* listener) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
206 std::vector<IPoolListener*>::iterator i = m_listeners.begin(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
207 while (i != m_listeners.end()) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
208 if ((*i) == listener) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
209 m_listeners.erase(i); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
210 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
211 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
212 ++i; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
213 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
214 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
215 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
216 void Pool::findAndSetProvider(PoolEntry& entry) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
217 std::vector<ResourceLoader*>::iterator it = m_loaders.begin(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
218 std::vector<ResourceLoader*>::iterator end = m_loaders.end(); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
219 if( it == end ) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
220 FL_PANIC(_log, "no loader constructors given for resource pool"); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
221 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
222 for(; it != end; ++it) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
223 IResource* res = (*it)->loadResource(*entry.location); |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
224 if (res) { |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
225 entry.resource = res; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
226 entry.loader = *it; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
227 return; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
228 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
229 }; |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
230 } |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
231 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
232 void Pool::printStatistics() { |
144
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
233 FL_LOG(_log, LMsg("Pool not loaded =") << getResourceCount(RES_NON_LOADED)); |
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
234 FL_LOG(_log, LMsg("Pool loaded =") << getResourceCount(RES_LOADED)); |
146
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
235 int amount = 0; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
236 std::vector<PoolEntry*>::iterator entry; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
237 for (entry = m_entries.begin(); entry != m_entries.end(); entry++) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
238 if ((*entry)->resource) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
239 if ((*entry)->resource->getRefCount() > 0) { |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
240 amount++; |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
241 } |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
242 } |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
243 } |
54b3984e1afc
The getIndex function was a hack that shadowed another bug
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
144
diff
changeset
|
244 FL_LOG(_log, LMsg("Pool locked =") << amount); |
144
d2f1e81fbe2c
* Fixed a scons issue, where libraries checked for C instead of C++
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
100
diff
changeset
|
245 FL_LOG(_log, LMsg("Pool total size =") << m_entries.size()); |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
246 } |
147
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
247 |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
248 void Pool::sanityCheck() { |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
249 // It is easy to mess up the important consistent |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
250 // less-than operator for the location classes. |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
251 // This will check if according to the '==' operator |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
252 // entries are duplicate (=memory leaks). |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
253 // Slow and inaccurate. But should barf at real messups. |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
254 for(unsigned i = 0; i != m_entries.size(); ++i) { |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
255 int count = 0; |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
256 for(unsigned j = i+1; j < m_entries.size(); ++j) { |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
257 if( *m_entries[i]->location == *m_entries[j]->location ) |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
258 count ++; |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
259 } |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
260 if( 0 == count ) |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
261 continue; |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
262 FL_WARN(_log, LMsg("Multiple entries: ") << m_entries[i]->location->getFilename() |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
263 << " #entries = " << (count+1) ); |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
264 } |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
265 } |
fb6ccb367dd1
Added just some docs and a sanityCheck against the
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
146
diff
changeset
|
266 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
267 } |