Update ResourceCache

This commit is contained in:
Nomango 2020-01-13 16:09:28 +08:00
parent c0d1307598
commit 88d61df5c0
8 changed files with 32 additions and 162 deletions

View File

@ -33,7 +33,6 @@
<ClInclude Include="..\..\..\src\3rd-party\curl\typecheck-gcc.h">
<Filter>include</Filter>
</ClInclude>
<ClInclude Include="..\..\..\src\3rd-party\curl\tinyxml2.h" />
</ItemGroup>
<ItemGroup>
<Library Include="..\..\..\src\3rd-party\curl\libs\libcurl.lib">

View File

@ -1,98 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="..\..\..\src\3rd-party\pugixml\pugixml.hpp" />
<ClInclude Include="..\..\..\src\3rd-party\pugixml\pugiconfig.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\src\3rd-party\pugixml\pugixml.cpp" />
</ItemGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{AB47E875-85E5-4105-A71E-88930EAAB910}</ProjectGuid>
<RootNamespace>pugixml</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)\output\$(PlatformToolset)\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\build\$(PlatformToolset)\$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>None</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>../../../src/3rd-party;</AdditionalIncludeDirectories>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<BufferSecurityCheck>false</BufferSecurityCheck>
<TreatWarningAsError>true</TreatWarningAsError>
<DebugInformationFormat>None</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>../../../src/3rd-party;</AdditionalIncludeDirectories>
<MinimalRebuild>false</MinimalRebuild>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="..\..\..\src\3rd-party\tinyxml2\tinyxml2.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\src\3rd-party\tinyxml2\tinyxml2.h" />
</ItemGroup>
</Project>

View File

@ -14,8 +14,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kiwano-physics", "kiwano-ph
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3rd-party", "3rd-party", "{2D8919F2-8922-4B3F-8F68-D4127C6BCBB7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pugixml", "3rd-party\pugixml\libpugixml.vcxproj", "{AB47E875-85E5-4105-A71E-88930EAAB910}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libimgui", "3rd-party\imgui\libimgui.vcxproj", "{7FA1E56D-62AC-47D1-97D1-40B302724198}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libcurl", "3rd-party\curl\libcurl.vcxproj", "{A9ABACC7-75A1-46BA-8E48-4105346D9719}"
@ -49,10 +47,6 @@ Global
{DF599AFB-744F-41E5-AF0C-2146F90575C8}.Debug|Win32.Build.0 = Debug|Win32
{DF599AFB-744F-41E5-AF0C-2146F90575C8}.Release|Win32.ActiveCfg = Release|Win32
{DF599AFB-744F-41E5-AF0C-2146F90575C8}.Release|Win32.Build.0 = Release|Win32
{AB47E875-85E5-4105-A71E-88930EAAB910}.Debug|Win32.ActiveCfg = Debug|Win32
{AB47E875-85E5-4105-A71E-88930EAAB910}.Debug|Win32.Build.0 = Debug|Win32
{AB47E875-85E5-4105-A71E-88930EAAB910}.Release|Win32.ActiveCfg = Release|Win32
{AB47E875-85E5-4105-A71E-88930EAAB910}.Release|Win32.Build.0 = Release|Win32
{7FA1E56D-62AC-47D1-97D1-40B302724198}.Debug|Win32.ActiveCfg = Debug|Win32
{7FA1E56D-62AC-47D1-97D1-40B302724198}.Debug|Win32.Build.0 = Debug|Win32
{7FA1E56D-62AC-47D1-97D1-40B302724198}.Release|Win32.ActiveCfg = Release|Win32
@ -70,7 +64,6 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AB47E875-85E5-4105-A71E-88930EAAB910} = {2D8919F2-8922-4B3F-8F68-D4127C6BCBB7}
{7FA1E56D-62AC-47D1-97D1-40B302724198} = {2D8919F2-8922-4B3F-8F68-D4127C6BCBB7}
{A9ABACC7-75A1-46BA-8E48-4105346D9719} = {2D8919F2-8922-4B3F-8F68-D4127C6BCBB7}
{0CBA9295-F14D-4966-A7C4-1DD68158176C} = {2D8919F2-8922-4B3F-8F68-D4127C6BCBB7}

View File

@ -164,11 +164,6 @@
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\3rd-party\pugixml\libpugixml.vcxproj">
<Project>{ab47e875-85e5-4105-a71e-88930eaab910}</Project>
</ProjectReference>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}</ProjectGuid>
<RootNamespace>kiwano</RootNamespace>

View File

@ -15,7 +15,7 @@
#define HEADER_PUGICONFIG_HPP
// Uncomment this to enable wchar_t mode
// #define PUGIXML_WCHAR_MODE
#define PUGIXML_WCHAR_MODE
// Uncomment this to enable compact mode
// #define PUGIXML_COMPACT
@ -27,7 +27,7 @@
// #define PUGIXML_NO_STL
// Uncomment this to disable exceptions
// #define PUGIXML_NO_EXCEPTIONS
#define PUGIXML_NO_EXCEPTIONS
// Set this to control attributes for public classes/functions, i.e.:
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
@ -41,7 +41,7 @@
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
// Uncomment this to switch to header-only version
// #define PUGIXML_HEADER_ONLY
#define PUGIXML_HEADER_ONLY
// Uncomment this to enable long long support
// #define PUGIXML_HAS_LONG_LONG

View File

@ -121,8 +121,10 @@ namespace kiwano
return false;
}
String full_path = FileSystem::instance().GetFullPathForFile(file_path);
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file(file_path.c_str(), pugi::parse_default, pugi::encoding_auto);
pugi::xml_parse_result result = doc.load_file(full_path.c_str(), pugi::parse_default, pugi::encoding_auto);
if (result)
{
@ -130,44 +132,36 @@ namespace kiwano
}
else
{
KGE_ERROR(L"XML [%s] parsed with errors: %s", file_path.c_str(), result.description());
KGE_ERROR(L"XML [%s] parsed with errors: %s", full_path.c_str(), result.description());
return false;
}
}
bool ResourceCache::LoadFromXml(const ResourceCache::XmlDocument& doc)
bool ResourceCache::LoadFromXml(const pugi::xml_document& doc)
{
if (doc)
if (pugi::xml_node root = doc.child(L"resources"))
{
try
{
if (pugi::xml_node root = doc.child(L"resources"))
{
String version;
if (auto version_node = root.child(L"version"))
version = version_node.value();
String version;
if (auto version_node = root.child(L"version"))
version = version_node.child_value();
auto load = load_xml_funcs.find(version);
if (load != load_xml_funcs.end())
{
return load->second(this, root);
}
else if (version.empty())
{
return load_xml_funcs[L"latest"](this, root);
}
else
{
throw std::runtime_error("unknown JSON data version");
}
}
}
catch (std::exception& e)
auto load = load_xml_funcs.find(version);
if (load != load_xml_funcs.end())
{
KGE_WARN(L"ResourceCache::LoadFromXml failed: %s", oc::string_to_wide(e.what()).c_str());
return load->second(this, root);
}
else if (version.empty())
{
return load_xml_funcs[L"latest"](this, root);
}
else
{
KGE_ERROR(L"Unknown version");
return false;
}
}
KGE_ERROR(L"Unknown version");
return false;
}
@ -480,7 +474,7 @@ namespace kiwano
GlobalData global_data;
if (auto path = elem.child(L"path"))
{
global_data.path = path.value();
global_data.path = path.child_value();
}
if (auto images = elem.child(L"images"))
@ -490,7 +484,7 @@ namespace kiwano
String id, type, file;
int rows = 0, cols = 0;
if (auto attr = image.attribute(L"id")) id = attr.value();
if (auto attr = image.attribute(L"id")) id.assign(attr.value());
if (auto attr = image.attribute(L"type")) type = attr.value();
if (auto attr = image.attribute(L"file")) file = attr.value();
if (auto attr = image.attribute(L"rows")) rows = attr.as_int(0);
@ -511,9 +505,9 @@ namespace kiwano
Vector<const wchar_t*> files_arr;
for (auto file : image.children())
{
if (auto path = file.attribute(L"path").value())
if (auto path = file.attribute(L"path"))
{
files_arr.push_back(path);
files_arr.push_back(path.value());
}
}
if (!LoadTexturesFromData(loader, &global_data, &id, &files_arr))
@ -532,8 +526,8 @@ namespace kiwano
for (auto font : fonts.children())
{
String id, file;
if (auto attr = font.attribute(L"id")) id.assign(attr.value());
if (auto attr = font.attribute(L"file")) file.assign(attr.value());
if (auto attr = font.attribute(L"id")) id.assign(attr.value());
if (auto attr = font.attribute(L"file")) file = attr.value();
if (!LoadFontsFromData(loader, &global_data, &id, &file))
return false;

View File

@ -24,8 +24,6 @@
#include <kiwano/2d/FrameSequence.h>
#include <kiwano/renderer/GifImage.h>
#include <kiwano/renderer/Font.h>
#define PUGIXML_WCHAR_MODE
#include <3rd-party/pugixml/pugixml.hpp>
namespace kiwano
@ -39,8 +37,6 @@ namespace kiwano
friend Singleton<ResourceCache>;
public:
using XmlDocument = pugi::xml_document;
/// \~chinese
/// @brief 从 JSON 文件加载资源信息
/// @param file_path JSON文件路径
@ -59,7 +55,7 @@ namespace kiwano
/// \~chinese
/// @brief 从 XML 文档对象加载资源信息
/// @param doc XML文档对象
bool LoadFromXml(XmlDocument const& doc);
bool LoadFromXml(pugi::xml_document const& doc);
/// \~chinese
/// @brief 获取资源