From dceb911f2538fa7b7299d5f589c2a474bf71bfb9 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Sun, 12 Jan 2014 18:12:43 -0800 Subject: [PATCH] Clean up some crazy in plClientResMgr --- .../plClientResMgr/plClientResMgr.cpp | 37 +++++++------------ .../plClientResMgr/plClientResMgr.h | 11 +++--- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp index 5e544a48..d85cde24 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp @@ -59,28 +59,19 @@ plClientResMgr& plClientResMgr::Instance(void) return theInstance; } -plClientResMgr::plClientResMgr() -{ - this->ClientResources = new std::map; -} - plClientResMgr::~plClientResMgr() { - if (this->ClientResources) { - std::map::iterator it; - - for (it = this->ClientResources->begin(); it != this->ClientResources->end(); ++it) { - if (it->second) - it->second->UnRef(); - } + std::map::iterator it; - delete this->ClientResources; + for (it = ClientResources.begin(); it != ClientResources.end(); ++it) { + if (it->second) + it->second->UnRef(); } } -void plClientResMgr::ILoadResources(const char* resfile) +void plClientResMgr::ILoadResources(const plFileName& resfile) { - if (!resfile) { + if (!resfile.IsValid()) { return; } @@ -98,10 +89,8 @@ void plClientResMgr::ILoadResources(const char* resfile) for (int i = 0; i < num_resources; i++) { plMipmap* res_data = NULL; uint32_t res_size = 0; - char* tmp_name = in.ReadSafeStringLong(); - std::string res_name = std::string(tmp_name); - std::string res_type = res_name.substr(res_name.length() - 4, 4); - delete[] tmp_name; + plString res_name = in.ReadSafeStringLong_TEMP(); + plString res_type = res_name.Substr(res_name.GetSize() - 4, 4); // Version 1 doesn't encode format, so we'll try some simple // extension sniffing @@ -122,7 +111,7 @@ void plClientResMgr::ILoadResources(const char* resfile) in.Skip(res_size); } - (*this->ClientResources)[res_name] = res_data; + ClientResources[res_name] = res_data; } break; @@ -134,12 +123,12 @@ void plClientResMgr::ILoadResources(const char* resfile) } } -plMipmap* plClientResMgr::getResource(const char* resname) +plMipmap* plClientResMgr::getResource(const plString& resname) { - plMipmap* resmipmap = NULL; - std::map::iterator it = this->ClientResources->find(resname); + plMipmap* resmipmap = nullptr; + std::map::iterator it = ClientResources.find(resname); - if (it != this->ClientResources->end()) { + if (it != ClientResources.end()) { resmipmap = it->second; } else { hsAssert(resmipmap, "Unknown client resource requested."); diff --git a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h index f3c16b73..1dc2e241 100644 --- a/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h +++ b/Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h @@ -44,21 +44,22 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _plClientResMgr_h #include -#include class plMipmap; +class plString; +class plFileName; class plClientResMgr { protected: - std::map* ClientResources; + std::map ClientResources; public: - plClientResMgr(); + plClientResMgr() { } ~plClientResMgr(); - void ILoadResources(const char* resfile); + void ILoadResources(const plFileName& resfile); - plMipmap* getResource(const char* resname); + plMipmap* getResource(const plString& resname); static plClientResMgr& Instance(void); };