2019-04-11 14:40:54 +08:00
|
|
|
|
// Copyright (c) 2016-2018 Kiwano - Nomango
|
2019-03-31 01:37:06 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
|
|
//
|
|
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
|
|
//
|
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
|
// THE SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano/macros.h>
|
|
|
|
|
|
#include <kiwano/base/Resource.h>
|
|
|
|
|
|
#include <kiwano/2d/include-forwards.h>
|
|
|
|
|
|
#include <kiwano/renderer/GifImage.h>
|
2019-10-11 21:12:29 +08:00
|
|
|
|
#include <3rd-party/tinyxml2/tinyxml2.h>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-04-11 14:40:54 +08:00
|
|
|
|
namespace kiwano
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-08-13 14:44:37 +08:00
|
|
|
|
// <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
|
|
|
|
|
class KGE_API ResourceCache
|
2019-08-13 15:00:43 +08:00
|
|
|
|
: public Singleton<ResourceCache>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-08-13 15:00:43 +08:00
|
|
|
|
KGE_DECLARE_SINGLETON(ResourceCache);
|
|
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
public:
|
2019-07-31 00:09:24 +08:00
|
|
|
|
// <20><> JSON <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
bool LoadFromJsonFile(String const& file_path);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><> JSON <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
bool LoadFromJson(Json const& json_data);
|
|
|
|
|
|
|
2019-08-04 00:11:47 +08:00
|
|
|
|
// <20><> XML <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
bool LoadFromXmlFile(String const& file_path);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><> XML <20>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
2019-08-22 17:16:32 +08:00
|
|
|
|
bool LoadFromXml(const tinyxml2::XMLDocument* doc);
|
2019-08-04 00:11:47 +08:00
|
|
|
|
|
2019-08-18 17:49:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>֡ͼ<D6A1><CDBC>
|
|
|
|
|
|
bool AddFrame(String const& id, String const& file_path);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-18 17:49:13 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD>֡ͼ<D6A1><CDBC>
|
2019-08-13 14:44:37 +08:00
|
|
|
|
bool AddFrame(String const& id, FramePtr frame);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-13 14:44:37 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
2019-09-29 22:23:13 +08:00
|
|
|
|
std::size_t AddFrameSequence(String const& id, Vector<String> const& files);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-13 14:44:37 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
2019-03-31 01:37:06 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>ͼƬ
|
2019-09-29 22:23:13 +08:00
|
|
|
|
std::size_t AddFrameSequence(String const& id, String const& file_path, int cols, int rows = 1, float padding_x = 0, float padding_y = 0);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-13 14:44:37 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
2019-09-29 22:23:13 +08:00
|
|
|
|
std::size_t AddFrameSequence(String const& id, FrameSequencePtr frames);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>Ӷ<EFBFBD><D3B6><EFBFBD>
|
2019-08-18 10:23:54 +08:00
|
|
|
|
bool AddObjectBase(String const& id, ObjectBasePtr obj);
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-22 17:16:32 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD> GIF ͼ<><CDBC>
|
|
|
|
|
|
bool AddGifImage(String const& id, GifImage const& gif);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD> GIF ͼ<><CDBC>
|
|
|
|
|
|
bool AddGifImage(String const& id, String const& file_path);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>弯
|
|
|
|
|
|
bool AddFontCollection(String const& id, FontCollection const& collection);
|
|
|
|
|
|
|
2019-08-18 17:49:13 +08:00
|
|
|
|
// <20><>ȡ֡ͼ<D6A1><CDBC>
|
2019-08-13 14:44:37 +08:00
|
|
|
|
FramePtr GetFrame(String const& id) const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-01 13:07:48 +08:00
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>֡
|
2019-08-13 14:44:37 +08:00
|
|
|
|
FrameSequencePtr GetFrameSequence(String const& id) const;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
2019-08-22 17:16:32 +08:00
|
|
|
|
// <20><>ȡ GIF ͼ<><CDBC>
|
|
|
|
|
|
GifImage GetGifImage(String const& id) const;
|
|
|
|
|
|
|
|
|
|
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>弯
|
|
|
|
|
|
FontCollection GetFontCollection(String const& id) const;
|
|
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
// ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
void Delete(String const& id);
|
|
|
|
|
|
|
2019-08-13 15:00:43 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
void Clear();
|
2019-03-31 01:37:06 +08:00
|
|
|
|
|
|
|
|
|
|
template<typename _Ty>
|
|
|
|
|
|
_Ty* Get(String const& id) const
|
|
|
|
|
|
{
|
2019-08-13 14:44:37 +08:00
|
|
|
|
auto iter = cache_.find(id);
|
|
|
|
|
|
if (iter == cache_.end())
|
2019-03-31 01:37:06 +08:00
|
|
|
|
return nullptr;
|
2019-08-13 21:16:38 +08:00
|
|
|
|
return dynamic_cast<_Ty*>((*iter).second.get());
|
2019-03-31 01:37:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-13 15:00:43 +08:00
|
|
|
|
protected:
|
2019-08-13 14:44:37 +08:00
|
|
|
|
ResourceCache();
|
2019-08-01 13:07:48 +08:00
|
|
|
|
|
2019-08-13 14:44:37 +08:00
|
|
|
|
virtual ~ResourceCache();
|
2019-08-01 13:07:48 +08:00
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
protected:
|
2019-08-18 10:23:54 +08:00
|
|
|
|
UnorderedMap<String, ObjectBasePtr> cache_;
|
2019-08-22 17:16:32 +08:00
|
|
|
|
|
|
|
|
|
|
UnorderedMap<String, GifImage> gif_cache_;
|
|
|
|
|
|
UnorderedMap<String, FontCollection> font_collection_cache_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|