Browse Source

Convert plClientResMgr to plString

DIE std::string DIE!!!
Adam Johnson 11 years ago committed by Michael Hansen
parent
commit
b10795b9cb
  1. 18
      Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp
  2. 4
      Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h

18
Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.cpp

@ -41,6 +41,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "HeadSpin.h"
#include <algorithm>
#include "hsStream.h"
#include "hsResMgr.h"
@ -61,9 +62,7 @@ plClientResMgr& plClientResMgr::Instance(void)
plClientResMgr::~plClientResMgr()
{
std::map<plString, plMipmap*>::iterator it;
for (it = ClientResources.begin(); it != ClientResources.end(); ++it) {
for (auto it = ClientResources.begin(); it != ClientResources.end(); ++it) {
if (it->second)
it->second->UnRef();
}
@ -71,9 +70,8 @@ plClientResMgr::~plClientResMgr()
void plClientResMgr::ILoadResources(const plFileName& resfile)
{
if (!resfile.IsValid()) {
if (!resfile.IsValid())
return;
}
hsUNIXStream in;
@ -87,19 +85,19 @@ void plClientResMgr::ILoadResources(const plFileName& resfile)
num_resources = in.ReadLE32();
for (int i = 0; i < num_resources; i++) {
plMipmap* res_data = NULL;
plMipmap* res_data = nullptr;
uint32_t res_size = 0;
plString res_name = in.ReadSafeStringLong();
plString res_type = res_name.Substr(res_name.GetSize() - 4, 4);
plString extension = plFileName(res_name).GetFileExt();
// Version 1 doesn't encode format, so we'll try some simple
// extension sniffing
if (res_type == ".png") {
if (extension == "png") {
// Read resource stream size, but the PNG has that info in the header
// so it's not needed
res_size = in.ReadLE32();
res_data = plPNG::Instance().ReadFromStream(&in);
} else if (res_type == ".jpg") {
} else if (extension == "jpg") {
// Don't read resource stream size, as plJPEG's reader will need it
res_data = plJPEG::Instance().ReadFromStream(&in);
} else {
@ -126,7 +124,7 @@ void plClientResMgr::ILoadResources(const plFileName& resfile)
plMipmap* plClientResMgr::getResource(const plString& resname)
{
plMipmap* resmipmap = nullptr;
std::map<plString, plMipmap*>::iterator it = ClientResources.find(resname);
auto it = ClientResources.find(resname);
if (it != ClientResources.end()) {
resmipmap = it->second;

4
Sources/Plasma/PubUtilLib/plClientResMgr/plClientResMgr.h

@ -43,7 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef _plClientResMgr_h
#define _plClientResMgr_h
#include <map>
#include <unordered_map>
class plMipmap;
class plString;
@ -51,7 +51,7 @@ class plFileName;
class plClientResMgr {
protected:
std::map<plString, plMipmap*> ClientResources;
std::unordered_map<plString, plMipmap*, plString::hash> ClientResources;
public:
plClientResMgr() { }

Loading…
Cancel
Save