[deploy] fix: std::map insert => operator[]
This commit is contained in:
parent
5e9937e0f0
commit
364a96b320
|
|
@ -35,78 +35,77 @@ SoundPlayer::~SoundPlayer()
|
|||
ClearCache();
|
||||
}
|
||||
|
||||
size_t SoundPlayer::GetId(const String& file_path) const
|
||||
{
|
||||
return std::hash<String>()(file_path);
|
||||
}
|
||||
|
||||
size_t SoundPlayer::GetId(const Resource& res) const
|
||||
{
|
||||
return static_cast<size_t>(res.GetId());
|
||||
}
|
||||
|
||||
size_t SoundPlayer::Load(const String& file_path)
|
||||
{
|
||||
size_t hash = std::hash<String>()(file_path);
|
||||
if (sound_cache_.end() != sound_cache_.find(hash))
|
||||
return hash;
|
||||
size_t id = GetId(file_path);
|
||||
if (sound_cache_.end() != sound_cache_.find(id))
|
||||
return id;
|
||||
|
||||
SoundPtr sound = MakePtr<Sound>();
|
||||
if (sound)
|
||||
{
|
||||
if (sound->Load(file_path))
|
||||
if (sound && sound->Load(file_path))
|
||||
{
|
||||
sound->SetVolume(volume_);
|
||||
sound_cache_.insert(std::make_pair(hash, sound));
|
||||
return hash;
|
||||
}
|
||||
sound_cache_.insert(std::make_pair(id, sound));
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t SoundPlayer::Load(const Resource& res)
|
||||
{
|
||||
size_t hash_code = static_cast<size_t>(res.GetId());
|
||||
if (sound_cache_.end() != sound_cache_.find(hash_code))
|
||||
return hash_code;
|
||||
size_t id = GetId(res);
|
||||
if (sound_cache_.end() != sound_cache_.find(id))
|
||||
return id;
|
||||
|
||||
SoundPtr sound = MakePtr<Sound>();
|
||||
|
||||
if (sound)
|
||||
{
|
||||
if (sound->Load(res))
|
||||
if (sound && sound->Load(res))
|
||||
{
|
||||
sound->SetVolume(volume_);
|
||||
sound_cache_.insert(std::make_pair(hash_code, sound));
|
||||
return hash_code;
|
||||
}
|
||||
sound_cache_.insert(std::make_pair(id, sound));
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SoundPlayer::Play(size_t id, int loop_count)
|
||||
{
|
||||
auto iter = sound_cache_.find(id);
|
||||
if (sound_cache_.end() != iter)
|
||||
iter->second->Play(loop_count);
|
||||
if (auto sound = GetSound(id))
|
||||
sound->Play(loop_count);
|
||||
}
|
||||
|
||||
void SoundPlayer::Pause(size_t id)
|
||||
{
|
||||
auto iter = sound_cache_.find(id);
|
||||
if (sound_cache_.end() != iter)
|
||||
iter->second->Pause();
|
||||
if (auto sound = GetSound(id))
|
||||
sound->Pause();
|
||||
}
|
||||
|
||||
void SoundPlayer::Resume(size_t id)
|
||||
{
|
||||
auto iter = sound_cache_.find(id);
|
||||
if (sound_cache_.end() != iter)
|
||||
iter->second->Resume();
|
||||
if (auto sound = GetSound(id))
|
||||
sound->Resume();
|
||||
}
|
||||
|
||||
void SoundPlayer::Stop(size_t id)
|
||||
{
|
||||
auto iter = sound_cache_.find(id);
|
||||
if (sound_cache_.end() != iter)
|
||||
iter->second->Stop();
|
||||
if (auto sound = GetSound(id))
|
||||
sound->Stop();
|
||||
}
|
||||
|
||||
bool SoundPlayer::IsPlaying(size_t id)
|
||||
{
|
||||
auto iter = sound_cache_.find(id);
|
||||
if (sound_cache_.end() != iter)
|
||||
return iter->second->IsPlaying();
|
||||
if (auto sound = GetSound(id))
|
||||
return sound->IsPlaying();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -124,6 +123,14 @@ void SoundPlayer::SetVolume(float volume)
|
|||
}
|
||||
}
|
||||
|
||||
SoundPtr SoundPlayer::GetSound(size_t id) const
|
||||
{
|
||||
auto iter = sound_cache_.find(id);
|
||||
if (iter != sound_cache_.end())
|
||||
return iter->second;
|
||||
return SoundPtr();
|
||||
}
|
||||
|
||||
void SoundPlayer::PauseAll()
|
||||
{
|
||||
for (auto& pair : sound_cache_)
|
||||
|
|
|
|||
|
|
@ -91,6 +91,23 @@ public:
|
|||
/// @param volume 音量大小,1.0 为原始音量, 大于 1 为放大音量, 0 为最小音量
|
||||
void SetVolume(float volume);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取本地音频文件id
|
||||
/// @param file_path 本地音频文件路径
|
||||
/// @return 音频标识符
|
||||
size_t GetId(const String& file_path) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取音频资源id
|
||||
/// @param res 音频资源
|
||||
/// @return 音频标识符
|
||||
size_t GetId(const Resource& res) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取音乐对象
|
||||
/// @param id 音频标识符
|
||||
SoundPtr GetSound(size_t id) const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 暂停所有音频
|
||||
void PauseAll();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ bool ImGuiLayer::CheckVisibility(RenderContext& ctx) const
|
|||
|
||||
void ImGuiLayer::AddItem(const String& name, const ImGuiPipeline& item)
|
||||
{
|
||||
pipelines_.insert(std::make_pair(name, item));
|
||||
pipelines_[name] = item;
|
||||
}
|
||||
|
||||
void ImGuiLayer::RemoveItem(const String& name)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ Component* ComponentManager::AddComponent(size_t index, ComponentPtr component)
|
|||
{
|
||||
component->InitComponent(target_);
|
||||
|
||||
components_.insert(std::make_pair(index, component));
|
||||
components_[index] = component;
|
||||
}
|
||||
return component.Get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -427,7 +427,7 @@ inline Deserializer& operator>>(Deserializer& deserializer, Map<_KTy, _Ty>& map)
|
|||
_KTy key;
|
||||
_Ty value;
|
||||
deserializer >> key >> value;
|
||||
map.insert(std::make_pair(key, value));
|
||||
map[key] = value;
|
||||
}
|
||||
return deserializer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,13 +119,13 @@ FontCache::~FontCache() {}
|
|||
|
||||
void FontCache::AddFont(size_t key, FontPtr font)
|
||||
{
|
||||
font_cache_.insert(std::make_pair(key, font));
|
||||
font_cache_[key] = font;
|
||||
}
|
||||
|
||||
void FontCache::AddFontByFamily(const String& font_family, FontPtr font)
|
||||
{
|
||||
String family = TransformFamily(font_family);
|
||||
font_family_cache_.insert(std::make_pair(family, font));
|
||||
font_family_cache_[family] = font;
|
||||
}
|
||||
|
||||
FontPtr FontCache::GetFont(size_t key) const
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ TextureCache::~TextureCache()
|
|||
|
||||
void TextureCache::AddTexture(size_t key, TexturePtr texture)
|
||||
{
|
||||
texture_cache_.insert(std::make_pair(key, texture));
|
||||
texture_cache_[key] = texture;
|
||||
}
|
||||
|
||||
void TextureCache::AddGifImage(size_t key, GifImagePtr gif)
|
||||
{
|
||||
gif_texture_cache_.insert(std::make_pair(key, gif));
|
||||
gif_texture_cache_[key] = gif;
|
||||
}
|
||||
|
||||
TexturePtr TextureCache::GetTexture(size_t key) const
|
||||
|
|
|
|||
|
|
@ -311,13 +311,13 @@ void ConfigIni::SetSectionMap(const SectionMap& sections)
|
|||
|
||||
void ConfigIni::SetSection(const String& section, const ValueMap& values)
|
||||
{
|
||||
sections_.insert(std::make_pair(section, values));
|
||||
sections_[section] = values;
|
||||
}
|
||||
|
||||
void ConfigIni::SetString(const String& section, const String& key, const String& value)
|
||||
{
|
||||
if (HasSection(section))
|
||||
sections_[section].insert(std::make_pair(key, value));
|
||||
sections_[section][key] = value;
|
||||
else
|
||||
SetSection(section, ValueMap{ { key, value } });
|
||||
}
|
||||
|
|
@ -363,19 +363,11 @@ void ConfigIni::DeleteKey(const String& section, const String& key)
|
|||
|
||||
ConfigIni::ValueMap& ConfigIni::operator[](const String& section)
|
||||
{
|
||||
if (!HasSection(section))
|
||||
{
|
||||
sections_.insert(std::make_pair(section, ValueMap()));
|
||||
}
|
||||
return sections_[section];
|
||||
}
|
||||
|
||||
const ConfigIni::ValueMap& ConfigIni::operator[](const String& section) const
|
||||
{
|
||||
if (!HasSection(section))
|
||||
{
|
||||
const_cast<SectionMap&>(sections_).insert(std::make_pair(section, ValueMap()));
|
||||
}
|
||||
return sections_.at(section);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ bool ResourceCache::LoadFromXmlFile(const String& file_path)
|
|||
|
||||
void ResourceCache::AddObject(const String& id, ObjectBasePtr obj)
|
||||
{
|
||||
object_cache_.insert(std::make_pair(id, obj));
|
||||
object_cache_[id] = obj;
|
||||
}
|
||||
|
||||
void ResourceCache::Remove(const String& id)
|
||||
|
|
|
|||
|
|
@ -34,19 +34,19 @@ Any UserData::Get(const String& key, const Any& default_data) const
|
|||
|
||||
void UserData::Set(const String& key, const Any& data)
|
||||
{
|
||||
data_.insert(std::make_pair(key, data));
|
||||
data_[key] = data;
|
||||
}
|
||||
|
||||
void UserData::Set(const DataPair& pair)
|
||||
{
|
||||
data_.insert(pair);
|
||||
data_[pair.first] = pair.second;
|
||||
}
|
||||
|
||||
void UserData::Set(const std::initializer_list<DataPair>& list)
|
||||
{
|
||||
for (const auto& pair : list)
|
||||
{
|
||||
data_.insert(pair);
|
||||
data_[pair.first] = pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue