1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Merge pull request #371 from Hoikas/keycol-set

Fix plKeyCollector key trashing...
This commit is contained in:
Branan Purvine-Riley
2013-12-21 16:57:10 -08:00
6 changed files with 19 additions and 28 deletions

View File

@ -145,7 +145,7 @@ int main(int argc, char* argv[])
class plSoundBufferCollector : public plRegistryPageIterator, public plKeyCollector class plSoundBufferCollector : public plRegistryPageIterator, public plKeyCollector
{ {
public: public:
plSoundBufferCollector(hsTArray<plKey>& keyArray) plSoundBufferCollector(std::set<plKey>& keyArray)
: plKeyCollector(keyArray) {} : plKeyCollector(keyArray) {}
bool EatPage(plRegistryPageNode* page) bool EatPage(plRegistryPageNode* page)
@ -159,14 +159,14 @@ public:
bool DumpSounds() bool DumpSounds()
{ {
hsTArray<plKey> soundKeys; std::set<plKey> soundKeys;
plSoundBufferCollector soundCollector(soundKeys); plSoundBufferCollector soundCollector(soundKeys);
gResMgr->IterateAllPages(&soundCollector); gResMgr->IterateAllPages(&soundCollector);
for (int i = 0; i < soundKeys.GetCount(); i++) for (auto it = soundKeys.begin(); it != soundKeys.end(); ++it)
{ {
plSoundBuffer* buffer = plSoundBuffer::ConvertNoRef(soundKeys[i]->VerifyLoaded()); plSoundBuffer* buffer = plSoundBuffer::ConvertNoRef((*it)->VerifyLoaded());
if (buffer) if (buffer)
{ {
// Ref it... // Ref it...
@ -197,7 +197,7 @@ bool DumpSounds()
} }
} }
soundKeys.Reset(); soundKeys.clear();
plIndirectUnloadIterator iter; plIndirectUnloadIterator iter;
gResMgr->IterateAllPages(&iter); gResMgr->IterateAllPages(&iter);

View File

@ -162,7 +162,7 @@ public:
if (pageNode->GetPageInfo().GetAge().CompareI(fAgeName) == 0) if (pageNode->GetPageInfo().GetAge().CompareI(fAgeName) == 0)
{ {
// Try loading and searching thru this page // Try loading and searching thru this page
hsTArray<plKey> keyRefs; std::set<plKey> keyRefs;
IGetResMgr()->LoadPageKeys( pageNode ); IGetResMgr()->LoadPageKeys( pageNode );
plKeyCollector coll( keyRefs ); plKeyCollector coll( keyRefs );

View File

@ -42,16 +42,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plRegistryHelpers.h" #include "plRegistryHelpers.h"
#include "plRegistryNode.h" #include "plRegistryNode.h"
plKeyCollector::plKeyCollector( hsTArray<plKey> &keys ) : fKeys( keys )
{
}
bool plKeyCollector::EatKey(const plKey& key)
{
fKeys.Append(key);
return true;
}
bool plIndirectUnloadIterator::EatPage(plRegistryPageNode* page) bool plIndirectUnloadIterator::EatPage(plRegistryPageNode* page)
{ {
page->IterateKeys(this); page->IterateKeys(this);

View File

@ -53,8 +53,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plRegistryHelpers_h #define _plRegistryHelpers_h
#include "HeadSpin.h" #include "HeadSpin.h"
#include "hsTemplates.h"
#include "pnKeyedObject/plKey.h" #include "pnKeyedObject/plKey.h"
#include <set>
class plKey; class plKey;
class plRegistryPageNode; class plRegistryPageNode;
@ -76,16 +76,19 @@ public:
}; };
//// plKeyCollector ////////////////////////////////////////////////////////// /** Helper key iterator that collects keys into an std::set. */
// Helper key iterator that collects the given keys into the given hsTArray
class plKeyCollector : public plRegistryKeyIterator class plKeyCollector : public plRegistryKeyIterator
{ {
protected: protected:
hsTArray<plKey> &fKeys; std::set<plKey>& fKeys;
public: public:
plKeyCollector(hsTArray<plKey>& keys); plKeyCollector(std::set<plKey>& keys) : fKeys(keys) { }
virtual bool EatKey(const plKey& key); virtual bool EatKey(const plKey& key)
{
fKeys.insert(key);
return true;
}
}; };
// If you loaded keys with another iterator, this will ensure that they're unloaded // If you loaded keys with another iterator, this will ensure that they're unloaded

View File

@ -990,12 +990,11 @@ void plResManager::SetProgressBarProc(plProgressProc proc)
class plResAgeHolder : public hsRefCnt class plResAgeHolder : public hsRefCnt
{ {
public: public:
hsTArray<plKey> fKeys; std::set<plKey> fKeys;
plString fAge; plString fAge;
plResAgeHolder() {} plResAgeHolder() {}
plResAgeHolder( const plString& age ) : fAge( age ) {} plResAgeHolder( const plString& age ) : fAge( age ) {}
~plResAgeHolder() { fKeys.Reset(); }
}; };
//// plResHolderIterator ///////////////////////////////////////////////////// //// plResHolderIterator /////////////////////////////////////////////////////
@ -1003,12 +1002,12 @@ class plResAgeHolder : public hsRefCnt
class plResHolderIterator : public plRegistryPageIterator class plResHolderIterator : public plRegistryPageIterator
{ {
protected: protected:
hsTArray<plKey>& fKeys; std::set<plKey>& fKeys;
plString fAgeName; plString fAgeName;
plResManager* fResMgr; plResManager* fResMgr;
public: public:
plResHolderIterator(const plString& age, hsTArray<plKey>& keys, plResManager* resMgr) plResHolderIterator(const plString& age, std::set<plKey>& keys, plResManager* resMgr)
: fAgeName(age), fKeys(keys), fResMgr(resMgr) {} : fAgeName(age), fKeys(keys), fResMgr(resMgr) {}
virtual bool EatPage(plRegistryPageNode* page) virtual bool EatPage(plRegistryPageNode* page)

View File

@ -135,12 +135,11 @@ class plResPageKeyRefList : public plKeyCollector
{ {
protected: protected:
hsTArray<plKey> fKeyList; std::set<plKey> fKeyList;
public: public:
plResPageKeyRefList() : plKeyCollector( fKeyList ) {} plResPageKeyRefList() : plKeyCollector( fKeyList ) {}
virtual ~plResPageKeyRefList() { fKeyList.Reset(); }
}; };
#endif // _plResManagerHelper_h #endif // _plResManagerHelper_h