switch to unordered_map for sprites
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user