Mercurial > fife-parpg
comparison engine/core/util/resource/pool.cpp @ 156:376b8afc9a18
Fixed a horrendous misconeception in the pool.
The map was sorted by pointer comparison.
Needs a bit cleanup, though.
author | phoku@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 12 Oct 2008 20:30:09 +0000 |
parents | 679ed3e15513 |
children | a46368b3d8a0 |
comparison
equal
deleted
inserted
replaced
155:29309cd5e240 | 156:376b8afc9a18 |
---|---|
85 | 85 |
86 void Pool::addResourceLoader(ResourceLoader* loader) { | 86 void Pool::addResourceLoader(ResourceLoader* loader) { |
87 m_loaders.push_back(loader); | 87 m_loaders.push_back(loader); |
88 } | 88 } |
89 | 89 |
90 int Pool::addResourceFromLocation(const ResourceLocation& loc) { | 90 int Pool::addResourceFromLocation(ResourceLocation* loc) { |
91 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc); | 91 ResourceLocationToEntry::const_iterator it = m_location_to_entry.find(loc); |
92 if (it != m_location_to_entry.end()) { | 92 if (it != m_location_to_entry.end()) { |
93 return (*it).second; | 93 return it->second; |
94 } | 94 } |
95 | 95 |
96 PoolEntry* entry = new PoolEntry(); | 96 PoolEntry* entry = new PoolEntry(); |
97 entry->location = loc.clone(); | 97 entry->location = loc->clone(); |
98 m_entries.push_back(entry); | 98 m_entries.push_back(entry); |
99 size_t index = m_entries.size() - 1; | 99 size_t index = m_entries.size() - 1; |
100 m_location_to_entry[loc] = index; | 100 m_location_to_entry[entry->location] = index; |
101 return index; | 101 return index; |
102 } | 102 } |
103 | 103 |
104 int Pool::addResourceFromFile(const std::string& filename) { | 104 int Pool::addResourceFromFile(const std::string& filename) { |
105 return addResourceFromLocation(ResourceLocation(filename)); | 105 ResourceLocation r = ResourceLocation(filename); |
106 return addResourceFromLocation(&r); | |
106 } | 107 } |
107 | 108 |
108 IResource& Pool::get(unsigned int index, bool inc) { | 109 IResource& Pool::get(unsigned int index, bool inc) { |
109 if (index >= m_entries.size()) { | 110 if (index >= m_entries.size()) { |
110 FL_ERR(_log, LMsg("Tried to get with index ") << index << ", only " << m_entries.size() << " items in pool " + m_name); | 111 FL_ERR(_log, LMsg("Tried to get with index ") << index << ", only " << m_entries.size() << " items in pool " + m_name); |