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-11-13 14:33:15 +08:00
|
|
|
|
#include <kiwano/core/Resource.h>
|
2019-12-23 18:05:08 +08:00
|
|
|
|
#include <kiwano/2d/Frame.h>
|
|
|
|
|
|
#include <kiwano/2d/FrameSequence.h>
|
2019-10-11 21:55:29 +08:00
|
|
|
|
#include <kiwano/renderer/GifImage.h>
|
2019-12-26 19:25:43 +08:00
|
|
|
|
#include <kiwano/renderer/Font.h>
|
2020-01-13 12:52:21 +08:00
|
|
|
|
#include <3rd-party/pugixml/pugixml.hpp>
|
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-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @details <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
2019-08-13 14:44:37 +08:00
|
|
|
|
class KGE_API ResourceCache
|
2019-08-13 15:00:43 +08:00
|
|
|
|
: public Singleton<ResourceCache>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-12-20 17:49:16 +08:00
|
|
|
|
friend Singleton<ResourceCache>;
|
2019-08-13 15:00:43 +08:00
|
|
|
|
|
2019-03-31 01:37:06 +08:00
|
|
|
|
public:
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><> JSON <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
/// @param file_path JSON<4F>ļ<EFBFBD>·<EFBFBD><C2B7>
|
2019-07-31 00:09:24 +08:00
|
|
|
|
bool LoadFromJsonFile(String const& file_path);
|
|
|
|
|
|
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><> JSON <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
/// @param json_data JSON<4F><4E><EFBFBD><EFBFBD>
|
2019-07-31 00:09:24 +08:00
|
|
|
|
bool LoadFromJson(Json const& json_data);
|
|
|
|
|
|
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><> XML <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
/// @param file_path XML<4D>ļ<EFBFBD>·<EFBFBD><C2B7>
|
2019-08-04 00:11:47 +08:00
|
|
|
|
bool LoadFromXmlFile(String const& file_path);
|
|
|
|
|
|
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><> XML <20>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4>Ϣ
|
|
|
|
|
|
/// @param doc XML<4D>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD>
|
2020-01-13 16:09:28 +08:00
|
|
|
|
bool LoadFromXml(pugi::xml_document const& doc);
|
2019-08-04 00:11:47 +08:00
|
|
|
|
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>Դ
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
2019-12-26 19:25:43 +08:00
|
|
|
|
ObjectBasePtr Get(String const& id) const;
|
|
|
|
|
|
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ȡ<EFBFBD><C8A1>Դ
|
|
|
|
|
|
/// @tparam _Ty <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
/// @return ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ָ<EFBFBD><D6B8>
|
2019-03-31 01:37:06 +08:00
|
|
|
|
template<typename _Ty>
|
2019-12-26 19:25:43 +08:00
|
|
|
|
SmartPtr<_Ty> Get(String const& id) const
|
2019-03-31 01:37:06 +08:00
|
|
|
|
{
|
2019-12-26 19:25:43 +08:00
|
|
|
|
return dynamic_cast<_Ty*>(Get(id).get());
|
2019-03-31 01:37:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-12-30 10:00:24 +08:00
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA>
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
/// @param obj <20><><EFBFBD><EFBFBD>
|
|
|
|
|
|
bool AddObject(String const& id, ObjectBasePtr obj);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ӷ<EFBFBD><D3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA>
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
/// @param files <20><><EFBFBD><EFBFBD>ͼƬ·<C6AC><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
size_t AddFrameSequence(String const& id, Vector<String> const& files);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ӷ<EFBFBD><D3B6><EFBFBD>ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA>
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
/// @param resources ͼƬ<CDBC><C6AC>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
size_t AddFrameSequence(String const& id, Vector<Resource> const& resources);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20>Ӷ<EFBFBD><D3B6><EFBFBD>ͼ<EFBFBD><CDBC>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA>
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
/// @param frames ͼ<><CDBC>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
size_t AddFrameSequence(String const& id, Vector<FramePtr> const& frames);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><>ͼ<EFBFBD><CDBC>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD>зָ<D6B8><EEB9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EBBBBA>
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD>ͼƬ
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
/// @param frame ͼ<><CDBC>֡
|
|
|
|
|
|
/// @param cols <20><>
|
|
|
|
|
|
/// @param rows <20><>
|
|
|
|
|
|
/// @param padding_x X<><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @param padding_y Y<><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
/// @return <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>
|
|
|
|
|
|
size_t AddFrameSequence(String const& id, FramePtr frame, int cols, int rows = 1, float padding_x = 0, float padding_y = 0);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief ɾ<><C9BE>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
/// @param id <20><><EFBFBD><EFBFBD>ID
|
|
|
|
|
|
void Remove(String const& id);
|
|
|
|
|
|
|
|
|
|
|
|
/// \~chinese
|
|
|
|
|
|
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
2019-12-23 18:05:08 +08:00
|
|
|
|
private:
|
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-12-23 18:05:08 +08:00
|
|
|
|
private:
|
2019-12-26 19:25:43 +08:00
|
|
|
|
UnorderedMap<String, ObjectBasePtr> object_cache_;
|
2019-03-31 01:37:06 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|