[deploy] Merge pull request #51 from KiwanoEngine/dev
Update FrameSequence
This commit is contained in:
commit
bd3fe87a95
|
|
@ -3,9 +3,9 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx10.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx11.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx10.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx11.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{A7062ED8-8910-48A5-A3BC-C1612672571F}</ProjectGuid>
|
<ProjectGuid>{A7062ED8-8910-48A5-A3BC-C1612672571F}</ProjectGuid>
|
||||||
|
|
@ -112,4 +112,4 @@
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -2,16 +2,31 @@
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\kiwano-imgui.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx10.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl_dx11.h" />
|
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiLayer.h" />
|
||||||
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
<ClInclude Include="..\..\src\kiwano-imgui\ImGuiModule.h" />
|
||||||
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl.h">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.h">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.h">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx10.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl_dx11.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiLayer.cpp" />
|
||||||
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
<ClCompile Include="..\..\src\kiwano-imgui\ImGuiModule.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx10.cpp">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\kiwano-imgui\imgui_impl\imgui_impl_dx11.cpp">
|
||||||
|
<Filter>imgui_impl</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="imgui_impl">
|
||||||
|
<UniqueIdentifier>{a11036bf-f334-4e51-aef2-15dd46be924d}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <kiwano/platform/win32/WindowImpl.h>
|
#include <kiwano/platform/win32/WindowImpl.h>
|
||||||
#include <kiwano/render/Renderer.h>
|
#include <kiwano/render/Renderer.h>
|
||||||
#include <kiwano-imgui/ImGuiModule.h>
|
#include <kiwano-imgui/ImGuiModule.h>
|
||||||
#include <kiwano-imgui/imgui_impl.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl.h>
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#if !defined(KGE_USE_DIRECTX10)
|
#if !defined(KGE_USE_DIRECTX10)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx11.h>
|
||||||
#include <kiwano/render/DirectX/RendererImpl.h>
|
#include <kiwano/render/DirectX/RendererImpl.h>
|
||||||
|
|
||||||
inline bool ImGui_Impl_Init()
|
inline bool ImGui_Impl_Init()
|
||||||
|
|
@ -43,7 +43,7 @@ inline bool ImGui_Impl_CreateDeviceObjects()
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx10.h>
|
||||||
|
|
||||||
inline bool ImGui_Impl_Init()
|
inline bool ImGui_Impl_Init()
|
||||||
{
|
{
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// dear imgui: Renderer for Kiwano (DirectX10)
|
// dear imgui: Renderer for Kiwano (DirectX10)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx10.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx10.h>
|
||||||
|
|
||||||
// DirectX
|
// DirectX
|
||||||
#include <d3d10_1.h>
|
#include <d3d10_1.h>
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// dear imgui: Renderer for Kiwano (DirectX11)
|
// dear imgui: Renderer for Kiwano (DirectX11)
|
||||||
|
|
||||||
#include <kiwano-imgui/imgui_impl_dx11.h>
|
#include <kiwano-imgui/imgui_impl/imgui_impl_dx11.h>
|
||||||
|
|
||||||
// DirectX
|
// DirectX
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
|
|
@ -24,6 +24,12 @@
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
|
|
||||||
|
FrameSequencePtr FrameSequence::Create()
|
||||||
|
{
|
||||||
|
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
FrameSequencePtr FrameSequence::Create(Vector<FramePtr> const& frames)
|
FrameSequencePtr FrameSequence::Create(Vector<FramePtr> const& frames)
|
||||||
{
|
{
|
||||||
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
||||||
|
|
@ -34,6 +40,17 @@ FrameSequencePtr FrameSequence::Create(Vector<FramePtr> const& frames)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FrameSequencePtr FrameSequence::Create(FramePtr frame, int cols, int rows, int max_num, float padding_x,
|
||||||
|
float padding_y)
|
||||||
|
{
|
||||||
|
FrameSequencePtr ptr = new (std::nothrow) FrameSequence;
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
ptr->AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
FrameSequence::FrameSequence() {}
|
FrameSequence::FrameSequence() {}
|
||||||
|
|
||||||
FrameSequence::~FrameSequence() {}
|
FrameSequence::~FrameSequence() {}
|
||||||
|
|
@ -60,6 +77,51 @@ void FrameSequence::AddFrames(Vector<FramePtr> const& frames)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrameSequence::AddFrames(FramePtr frame, int cols, int rows, int max_num, float padding_x, float padding_y)
|
||||||
|
{
|
||||||
|
if (cols <= 0 || rows <= 0 || max_num == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!frame)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Rect src_rect = frame->GetCropRect();
|
||||||
|
float raw_width = src_rect.GetWidth();
|
||||||
|
float raw_height = src_rect.GetHeight();
|
||||||
|
float width = (raw_width - (cols - 1) * padding_x) / cols;
|
||||||
|
float height = (raw_height - (rows - 1) * padding_y) / rows;
|
||||||
|
|
||||||
|
Vector<FramePtr> frames;
|
||||||
|
frames.reserve((max_num > 0) ? max_num : (rows * cols));
|
||||||
|
|
||||||
|
int current_num = 0;
|
||||||
|
|
||||||
|
float dty = src_rect.GetTop();
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
float dtx = src_rect.GetLeft();
|
||||||
|
|
||||||
|
for (int j = 0; j < cols; j++)
|
||||||
|
{
|
||||||
|
FramePtr ptr = new (std::nothrow) Frame;
|
||||||
|
if (ptr)
|
||||||
|
{
|
||||||
|
ptr->SetTexture(frame->GetTexture());
|
||||||
|
ptr->SetCropRect(Rect{ dtx, dty, dtx + width, dty + height });
|
||||||
|
frames.push_back(ptr);
|
||||||
|
++current_num;
|
||||||
|
}
|
||||||
|
dtx += (width + padding_x);
|
||||||
|
}
|
||||||
|
dty += (height + padding_y);
|
||||||
|
|
||||||
|
if (max_num > 0 && current_num == max_num)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
AddFrames(frames);
|
||||||
|
}
|
||||||
|
|
||||||
FramePtr FrameSequence::GetFrame(size_t index) const
|
FramePtr FrameSequence::GetFrame(size_t index) const
|
||||||
{
|
{
|
||||||
KGE_ASSERT(index < frames_.size());
|
KGE_ASSERT(index < frames_.size());
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,26 @@ KGE_DECLARE_SMART_PTR(FrameSequence);
|
||||||
class KGE_API FrameSequence : public virtual ObjectBase
|
class KGE_API FrameSequence : public virtual ObjectBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 创建序列帧
|
||||||
|
static FrameSequencePtr Create();
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 创建序列帧
|
/// @brief 创建序列帧
|
||||||
/// @param frames 图像帧集合
|
/// @param frames 图像帧集合
|
||||||
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
static FrameSequencePtr Create(Vector<FramePtr> const& frames);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 按行列分割图像并创建序列帧
|
||||||
|
/// @param frame 图像帧
|
||||||
|
/// @param cols 列数
|
||||||
|
/// @param rows 行数
|
||||||
|
/// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧
|
||||||
|
/// @param padding_x X方向间隔
|
||||||
|
/// @param padding_y Y方向间隔
|
||||||
|
static FrameSequencePtr Create(FramePtr frame, int cols, int rows = 1, int max_num = -1, float padding_x = 0,
|
||||||
|
float padding_y = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 构建空序列帧
|
/// @brief 构建空序列帧
|
||||||
FrameSequence();
|
FrameSequence();
|
||||||
|
|
@ -55,6 +70,16 @@ public:
|
||||||
/// @param frames 图像帧集合
|
/// @param frames 图像帧集合
|
||||||
void AddFrames(Vector<FramePtr> const& frames);
|
void AddFrames(Vector<FramePtr> const& frames);
|
||||||
|
|
||||||
|
/// \~chinese
|
||||||
|
/// @brief 按行列分割图像并添加序列帧
|
||||||
|
/// @param frame 图像帧
|
||||||
|
/// @param cols 列数
|
||||||
|
/// @param rows 行数
|
||||||
|
/// @param max_num 最大帧数量,设-1为将分割后的图像全部作为序列帧
|
||||||
|
/// @param padding_x X方向间隔
|
||||||
|
/// @param padding_y Y方向间隔
|
||||||
|
void AddFrames(FramePtr frame, int cols, int rows = 1, int max_num = -1, float padding_x = 0, float padding_y = 0);
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 获取关键帧
|
/// @brief 获取关键帧
|
||||||
/// @param index 图像帧下标
|
/// @param index 图像帧下标
|
||||||
|
|
|
||||||
|
|
@ -26,23 +26,27 @@
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
namespace __resource_cache_01
|
namespace resource_cache_01
|
||||||
{
|
{
|
||||||
|
|
||||||
bool LoadJsonData(ResourceCache* loader, Json const& json_data);
|
bool LoadJsonData(ResourceCache* loader, Json const& json_data);
|
||||||
bool LoadXmlData(ResourceCache* loader, const pugi::xml_node& elem);
|
bool LoadXmlData(ResourceCache* loader, const pugi::xml_node& elem);
|
||||||
} // namespace __resource_cache_01
|
|
||||||
|
} // namespace resource_cache_01
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
Map<String, Function<bool(ResourceCache*, Json const&)>> load_json_funcs = {
|
Map<String, Function<bool(ResourceCache*, Json const&)>> load_json_funcs = {
|
||||||
{ "latest", __resource_cache_01::LoadJsonData },
|
{ "latest", resource_cache_01::LoadJsonData },
|
||||||
{ "0.1", __resource_cache_01::LoadJsonData },
|
{ "0.1", resource_cache_01::LoadJsonData },
|
||||||
};
|
};
|
||||||
|
|
||||||
Map<String, Function<bool(ResourceCache*, const pugi::xml_node&)>> load_xml_funcs = {
|
Map<String, Function<bool(ResourceCache*, const pugi::xml_node&)>> load_xml_funcs = {
|
||||||
{ "latest", __resource_cache_01::LoadXmlData },
|
{ "latest", resource_cache_01::LoadXmlData },
|
||||||
{ "0.1", __resource_cache_01::LoadXmlData },
|
{ "0.1", resource_cache_01::LoadXmlData },
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ResourceCache::ResourceCache() {}
|
ResourceCache::ResourceCache() {}
|
||||||
|
|
@ -162,109 +166,6 @@ bool ResourceCache::LoadFromXml(const pugi::xml_document& doc)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ResourceCache::AddFrameSequence(String const& id, Vector<String> const& files)
|
|
||||||
{
|
|
||||||
if (files.empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Vector<FramePtr> frames;
|
|
||||||
frames.reserve(files.size());
|
|
||||||
|
|
||||||
for (const auto& file : files)
|
|
||||||
{
|
|
||||||
FramePtr ptr = new (std::nothrow) Frame;
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
if (ptr->Load(file))
|
|
||||||
{
|
|
||||||
frames.push_back(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AddFrameSequence(id, frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ResourceCache::AddFrameSequence(String const& id, Vector<Resource> const& resources)
|
|
||||||
{
|
|
||||||
if (resources.empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
Vector<FramePtr> frames;
|
|
||||||
frames.reserve(resources.size());
|
|
||||||
|
|
||||||
for (const auto& res : resources)
|
|
||||||
{
|
|
||||||
FramePtr ptr = new (std::nothrow) Frame;
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
if (ptr->Load(res))
|
|
||||||
{
|
|
||||||
frames.push_back(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AddFrameSequence(id, frames);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ResourceCache::AddFrameSequence(String const& id, Vector<FramePtr> const& frames)
|
|
||||||
{
|
|
||||||
if (frames.empty())
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
FrameSequencePtr fs = FrameSequence::Create(frames);
|
|
||||||
if (fs)
|
|
||||||
{
|
|
||||||
AddObject(id, fs);
|
|
||||||
return fs->GetFramesCount();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t ResourceCache::AddFrameSequence(String const& id, FramePtr frame, int cols, int rows, float padding_x,
|
|
||||||
float padding_y)
|
|
||||||
{
|
|
||||||
if (cols <= 0 || rows <= 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!frame)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
float raw_width = frame->GetWidth();
|
|
||||||
float raw_height = frame->GetHeight();
|
|
||||||
float width = (raw_width - (cols - 1) * padding_x) / cols;
|
|
||||||
float height = (raw_height - (rows - 1) * padding_y) / rows;
|
|
||||||
|
|
||||||
Vector<FramePtr> frames;
|
|
||||||
frames.reserve(rows * cols);
|
|
||||||
|
|
||||||
float dty = 0;
|
|
||||||
for (int i = 0; i < rows; i++)
|
|
||||||
{
|
|
||||||
float dtx = 0;
|
|
||||||
for (int j = 0; j < cols; j++)
|
|
||||||
{
|
|
||||||
FramePtr ptr = new (std::nothrow) Frame;
|
|
||||||
if (ptr)
|
|
||||||
{
|
|
||||||
ptr->SetTexture(frame->GetTexture());
|
|
||||||
ptr->SetCropRect(Rect{ dtx, dty, dtx + width, dty + height });
|
|
||||||
frames.push_back(ptr);
|
|
||||||
}
|
|
||||||
dtx += (width + padding_x);
|
|
||||||
}
|
|
||||||
dty += (height + padding_y);
|
|
||||||
}
|
|
||||||
|
|
||||||
FrameSequencePtr fs = new (std::nothrow) FrameSequence;
|
|
||||||
if (fs)
|
|
||||||
{
|
|
||||||
fs->AddFrames(frames);
|
|
||||||
AddObject(id, fs);
|
|
||||||
return fs->GetFramesCount();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ResourceCache::AddObject(String const& id, ObjectBasePtr obj)
|
bool ResourceCache::AddObject(String const& id, ObjectBasePtr obj)
|
||||||
{
|
{
|
||||||
if (obj)
|
if (obj)
|
||||||
|
|
@ -297,7 +198,7 @@ ObjectBasePtr ResourceCache::Get(String const& id) const
|
||||||
|
|
||||||
namespace kiwano
|
namespace kiwano
|
||||||
{
|
{
|
||||||
namespace __resource_cache_01
|
namespace resource_cache_01
|
||||||
{
|
{
|
||||||
struct GlobalData
|
struct GlobalData
|
||||||
{
|
{
|
||||||
|
|
@ -332,8 +233,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String& id,
|
bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String& id, const Vector<String>& files)
|
||||||
const Vector<String>& files)
|
|
||||||
{
|
{
|
||||||
if (!gdata)
|
if (!gdata)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -361,7 +261,7 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String& id, const String& file, int rows,
|
bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String& id, const String& file, int rows,
|
||||||
int cols, float padding_x, float padding_y)
|
int cols, int max_num, float padding_x, float padding_y)
|
||||||
{
|
{
|
||||||
if (!gdata)
|
if (!gdata)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -374,8 +274,12 @@ bool LoadTexturesFromData(ResourceCache* loader, GlobalData* gdata, const String
|
||||||
FramePtr frame = new (std::nothrow) Frame;
|
FramePtr frame = new (std::nothrow) Frame;
|
||||||
if (frame && frame->Load(gdata->path + file))
|
if (frame && frame->Load(gdata->path + file))
|
||||||
{
|
{
|
||||||
return !!loader->AddFrameSequence(id, frame, std::max(cols, 1), std::max(rows, 1), padding_x,
|
FrameSequencePtr frame_seq = new (std::nothrow) FrameSequence;
|
||||||
padding_y);
|
if (frame_seq)
|
||||||
|
{
|
||||||
|
frame_seq->AddFrames(frame, cols, rows, max_num, padding_x, padding_y);
|
||||||
|
return loader->AddObject(id, frame_seq);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -417,7 +321,7 @@ bool LoadJsonData(ResourceCache* loader, Json const& json_data)
|
||||||
for (const auto& image : json_data["images"])
|
for (const auto& image : json_data["images"])
|
||||||
{
|
{
|
||||||
String id, type, file;
|
String id, type, file;
|
||||||
int rows = 0, cols = 0;
|
int rows = 0, cols = 0, max_num = -1;
|
||||||
|
|
||||||
if (image.count("id"))
|
if (image.count("id"))
|
||||||
id = image["id"].get<String>();
|
id = image["id"].get<String>();
|
||||||
|
|
@ -429,6 +333,8 @@ bool LoadJsonData(ResourceCache* loader, Json const& json_data)
|
||||||
rows = image["rows"].get<int>();
|
rows = image["rows"].get<int>();
|
||||||
if (image.count("cols"))
|
if (image.count("cols"))
|
||||||
cols = image["cols"].get<int>();
|
cols = image["cols"].get<int>();
|
||||||
|
if (image.count("max_num"))
|
||||||
|
max_num = image["max_num"].get<int>();
|
||||||
|
|
||||||
if (rows || cols)
|
if (rows || cols)
|
||||||
{
|
{
|
||||||
|
|
@ -438,7 +344,7 @@ bool LoadJsonData(ResourceCache* loader, Json const& json_data)
|
||||||
if (image.count("padding-y"))
|
if (image.count("padding-y"))
|
||||||
padding_y = image["padding-y"].get<float>();
|
padding_y = image["padding-y"].get<float>();
|
||||||
|
|
||||||
if (!LoadTexturesFromData(loader, &global_data, id, file, rows, cols, padding_x, padding_y))
|
if (!LoadTexturesFromData(loader, &global_data, id, file, rows, cols, max_num, padding_x, padding_y))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -492,7 +398,7 @@ bool LoadXmlData(ResourceCache* loader, const pugi::xml_node& elem)
|
||||||
for (auto image : images.children())
|
for (auto image : images.children())
|
||||||
{
|
{
|
||||||
String id, type, file;
|
String id, type, file;
|
||||||
int rows = 0, cols = 0;
|
int rows = 0, cols = 0, max_num = -1;
|
||||||
|
|
||||||
if (auto attr = image.attribute("id"))
|
if (auto attr = image.attribute("id"))
|
||||||
id.assign(attr.value());
|
id.assign(attr.value());
|
||||||
|
|
@ -504,6 +410,8 @@ bool LoadXmlData(ResourceCache* loader, const pugi::xml_node& elem)
|
||||||
rows = attr.as_int(0);
|
rows = attr.as_int(0);
|
||||||
if (auto attr = image.attribute("cols"))
|
if (auto attr = image.attribute("cols"))
|
||||||
cols = attr.as_int(0);
|
cols = attr.as_int(0);
|
||||||
|
if (auto attr = image.attribute("max_num"))
|
||||||
|
max_num = attr.as_int(-1);
|
||||||
|
|
||||||
if (rows || cols)
|
if (rows || cols)
|
||||||
{
|
{
|
||||||
|
|
@ -513,7 +421,7 @@ bool LoadXmlData(ResourceCache* loader, const pugi::xml_node& elem)
|
||||||
if (auto attr = image.attribute("padding-y"))
|
if (auto attr = image.attribute("padding-y"))
|
||||||
padding_y = attr.as_float(0.0f);
|
padding_y = attr.as_float(0.0f);
|
||||||
|
|
||||||
if (!LoadTexturesFromData(loader, &global_data, id, file, rows, cols, padding_x, padding_y))
|
if (!LoadTexturesFromData(loader, &global_data, id, file, rows, cols, max_num, padding_x, padding_y))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -554,5 +462,5 @@ bool LoadXmlData(ResourceCache* loader, const pugi::xml_node& elem)
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace __resource_cache_01
|
} // namespace resource_cache_01
|
||||||
} // namespace kiwano
|
} // namespace kiwano
|
||||||
|
|
|
||||||
|
|
@ -78,40 +78,6 @@ public:
|
||||||
/// @param obj 对象
|
/// @param obj 对象
|
||||||
bool AddObject(String const& id, ObjectBasePtr obj);
|
bool AddObject(String const& id, ObjectBasePtr obj);
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 从多个本地图片构建序列帧,并放入缓存
|
|
||||||
/// @param id 对象ID
|
|
||||||
/// @param files 本地图片路径集合
|
|
||||||
/// @return 序列帧的帧数量
|
|
||||||
size_t AddFrameSequence(String const& id, Vector<String> const& files);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 从多个图片资源构建序列帧,并放入缓存
|
|
||||||
/// @param id 对象ID
|
|
||||||
/// @param resources 图片资源集合
|
|
||||||
/// @return 序列帧的帧数量
|
|
||||||
size_t AddFrameSequence(String const& id, Vector<Resource> const& resources);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 从多个图像帧构建序列帧,并放入缓存
|
|
||||||
/// @param id 对象ID
|
|
||||||
/// @param frames 图像帧集合
|
|
||||||
/// @return 序列帧的帧数量
|
|
||||||
size_t AddFrameSequence(String const& id, Vector<FramePtr> const& frames);
|
|
||||||
|
|
||||||
/// \~chinese
|
|
||||||
/// @brief 将图像帧按行列分割构建序列帧,并放入缓存
|
|
||||||
/// @brief 按行列数裁剪图片
|
|
||||||
/// @param id 对象ID
|
|
||||||
/// @param frame 图像帧
|
|
||||||
/// @param cols 列
|
|
||||||
/// @param rows 行
|
|
||||||
/// @param padding_x X方向间隔
|
|
||||||
/// @param padding_y Y方向间隔
|
|
||||||
/// @return 序列帧的帧数量
|
|
||||||
size_t AddFrameSequence(String const& id, FramePtr frame, int cols, int rows = 1, float padding_x = 0,
|
|
||||||
float padding_y = 0);
|
|
||||||
|
|
||||||
/// \~chinese
|
/// \~chinese
|
||||||
/// @brief 删除指定资源
|
/// @brief 删除指定资源
|
||||||
/// @param id 对象ID
|
/// @param id 对象ID
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue