Browse Source

Clean up some crazy in plClientResMgr

Michael Hansen 11 years ago
parent
commit
dceb911f25
  1. 37
      Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp
  2. 11
      Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h

37
Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp

@ -59,28 +59,19 @@ plClientResMgr& plClientResMgr::Instance(void)
return theInstance; return theInstance;
} }
plClientResMgr::plClientResMgr()
{
this->ClientResources = new std::map<std::string, plMipmap*>;
}
plClientResMgr::~plClientResMgr() plClientResMgr::~plClientResMgr()
{ {
if (this->ClientResources) { std::map<plString, plMipmap*>::iterator it;
std::map<std::string, plMipmap*>::iterator it;
for (it = this->ClientResources->begin(); it != this->ClientResources->end(); ++it) {
if (it->second)
it->second->UnRef();
}
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; return;
} }
@ -98,10 +89,8 @@ void plClientResMgr::ILoadResources(const char* resfile)
for (int i = 0; i < num_resources; i++) { for (int i = 0; i < num_resources; i++) {
plMipmap* res_data = NULL; plMipmap* res_data = NULL;
uint32_t res_size = 0; uint32_t res_size = 0;
char* tmp_name = in.ReadSafeStringLong(); plString res_name = in.ReadSafeStringLong_TEMP();
std::string res_name = std::string(tmp_name); plString res_type = res_name.Substr(res_name.GetSize() - 4, 4);
std::string res_type = res_name.substr(res_name.length() - 4, 4);
delete[] tmp_name;
// Version 1 doesn't encode format, so we'll try some simple // Version 1 doesn't encode format, so we'll try some simple
// extension sniffing // extension sniffing
@ -122,7 +111,7 @@ void plClientResMgr::ILoadResources(const char* resfile)
in.Skip(res_size); in.Skip(res_size);
} }
(*this->ClientResources)[res_name] = res_data; ClientResources[res_name] = res_data;
} }
break; 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; plMipmap* resmipmap = nullptr;
std::map<std::string, plMipmap*>::iterator it = this->ClientResources->find(resname); std::map<plString, plMipmap*>::iterator it = ClientResources.find(resname);
if (it != this->ClientResources->end()) { if (it != ClientResources.end()) {
resmipmap = it->second; resmipmap = it->second;
} else { } else {
hsAssert(resmipmap, "Unknown client resource requested."); hsAssert(resmipmap, "Unknown client resource requested.");

11
Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h

@ -44,21 +44,22 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plClientResMgr_h #define _plClientResMgr_h
#include <map> #include <map>
#include <string>
class plMipmap; class plMipmap;
class plString;
class plFileName;
class plClientResMgr { class plClientResMgr {
protected: protected:
std::map<std::string, plMipmap*>* ClientResources; std::map<plString, plMipmap*> ClientResources;
public: public:
plClientResMgr(); 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); static plClientResMgr& Instance(void);
}; };

Loading…
Cancel
Save