switch to unordered_map for sprites

This commit is contained in:
Konstantin Käfer
2014-07-02 11:36:36 +02:00
parent 231e3ef80c
commit 5d92e7c610
2 changed files with 10 additions and 6 deletions

View File

@@ -1,14 +1,14 @@
#ifndef LLMR_STYLE_SPRITE
#define LLMR_STYLE_SPRITE
#include <map>
#include <llmr/util/raster.hpp>
#include <llmr/util/vec.hpp>
#include <string>
#include <mutex>
#include <memory>
#include <atomic>
#include <llmr/util/raster.hpp>
#include <llmr/util/vec.hpp>
#include <unordered_map>
namespace llmr {
@@ -55,7 +55,7 @@ private:
std::string body;
std::string image;
std::atomic<bool> loaded;
std::map<std::string, SpritePosition> pos;
std::unordered_map<std::string, SpritePosition> pos;
const SpritePosition empty;
};

View File

@@ -83,6 +83,8 @@ void Sprite::parseJSON(std::shared_ptr<Sprite> &sprite) {
sprite->body.clear();
if (d.IsObject()) {
std::unordered_map<std::string, SpritePosition> pos;
for (rapidjson::Value::ConstMemberIterator itr = d.MemberBegin(); itr != d.MemberEnd(); ++itr) {
const std::string& name = itr->name.GetString();
const rapidjson::Value& value = itr->value;
@@ -99,9 +101,11 @@ void Sprite::parseJSON(std::shared_ptr<Sprite> &sprite) {
if (value.HasMember("width")) width = value["width"].GetInt();
if (value.HasMember("height")) height = value["height"].GetInt();
if (value.HasMember("pixelRatio")) pixelRatio = value["pixelRatio"].GetInt();
sprite->pos.emplace(name, SpritePosition { x, y, width, height, pixelRatio });
pos.emplace(name, SpritePosition { x, y, width, height, pixelRatio });
}
}
sprite->pos.swap(pos);
}
}