Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 移除 zstd #623

Merged
merged 1 commit into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 14 additions & 32 deletions src/Magpie.Core/EffectCacheManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include "Logger.h"
#include "CommonSharedConstants.h"
#include <d3dcompiler.h>
#include <zstd.h>
#include "Utils.h"
#include "YasHelper.h"
#include "ZstdHelper.h"

namespace yas::detail {

Expand Down Expand Up @@ -79,7 +77,7 @@ static constexpr const uint32_t MAX_CACHE_COUNT = 127;

// 缓存版本
// 当缓存文件结构有更改时更新它,使旧缓存失效
static constexpr const uint32_t EFFECT_CACHE_VERSION = 11;
static constexpr const uint32_t EFFECT_CACHE_VERSION = 12;


static std::wstring GetLinearEffectName(std::wstring_view effectName) {
Expand Down Expand Up @@ -153,16 +151,8 @@ bool EffectCacheManager::Load(std::wstring_view effectName, std::wstring_view ha
}

std::vector<BYTE> buf;
{
std::vector<BYTE> compressedBuf;
if (!Win32Utils::ReadFile(cacheFileName.c_str(), compressedBuf) || compressedBuf.empty()) {
return false;
}

if (!ZstdHelper::ZstdDecompress(compressedBuf, buf)) {
Logger::Get().Error("解压缓存失败");
return false;
}
if (!Win32Utils::ReadFile(cacheFileName.c_str(), buf) || buf.empty()) {
return false;
}

try {
Expand All @@ -185,25 +175,17 @@ bool EffectCacheManager::Load(std::wstring_view effectName, std::wstring_view ha
void EffectCacheManager::Save(std::wstring_view effectName, std::wstring_view hash, const EffectDesc& desc) {
std::wstring linearEffectName = GetLinearEffectName(effectName);

std::vector<BYTE> compressedBuf;
{
std::vector<BYTE> buf;
buf.reserve(4096);

try {
yas::vector_ostream os(buf);
yas::binary_oarchive<yas::vector_ostream<BYTE>, yas::binary> oa(os);

oa& desc;
} catch (...) {
Logger::Get().Error("序列化 EffectDesc 失败");
return;
}
std::vector<BYTE> buf;
buf.reserve(4096);

try {
yas::vector_ostream os(buf);
yas::binary_oarchive<yas::vector_ostream<BYTE>, yas::binary> oa(os);

if (!ZstdHelper::ZstdCompress(buf, compressedBuf, ZSTD_CLEVEL_DEFAULT)) {
Logger::Get().Error("压缩缓存失败");
return;
}
oa& desc;
} catch (...) {
Logger::Get().Error("序列化 EffectDesc 失败");
return;
}

if (!Win32Utils::DirExists(CommonSharedConstants::CACHE_DIR)) {
Expand Down Expand Up @@ -246,7 +228,7 @@ void EffectCacheManager::Save(std::wstring_view effectName, std::wstring_view ha
}

std::wstring cacheFileName = GetCacheFileName(linearEffectName, hash, desc.flags);
if (!Win32Utils::WriteFile(cacheFileName.c_str(), compressedBuf.data(), compressedBuf.size())) {
if (!Win32Utils::WriteFile(cacheFileName.c_str(), buf.data(), buf.size())) {
Logger::Get().Error("保存缓存失败");
}

Expand Down
2 changes: 0 additions & 2 deletions src/Magpie.Core/Magpie.Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
<ClInclude Include="TextureLoader.h" />
<ClInclude Include="WindowHelper.h" />
<ClInclude Include="YasHelper.h" />
<ClInclude Include="ZstdHelper.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="CursorManager.cpp" />
Expand Down Expand Up @@ -142,7 +141,6 @@
<ClCompile Include="Renderer.cpp" />
<ClCompile Include="TextureLoader.cpp" />
<ClCompile Include="WindowHelper.cpp" />
<ClCompile Include="ZstdHelper.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Magpie.Core.rc" />
Expand Down
6 changes: 0 additions & 6 deletions src/Magpie.Core/Magpie.Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@
<ClInclude Include="YasHelper.h">
<Filter>Helpers</Filter>
</ClInclude>
<ClInclude Include="ZstdHelper.h">
<Filter>Helpers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="MagRuntime.cpp" />
Expand Down Expand Up @@ -154,9 +151,6 @@
<ClCompile Include="ImGuiFontsCacheManager.cpp">
<Filter>Overlay</Filter>
</ClCompile>
<ClCompile Include="ZstdHelper.cpp">
<Filter>Helpers</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Magpie.Core.rc">
Expand Down
41 changes: 0 additions & 41 deletions src/Magpie.Core/ZstdHelper.cpp

This file was deleted.

11 changes: 0 additions & 11 deletions src/Magpie.Core/ZstdHelper.h

This file was deleted.

1 change: 0 additions & 1 deletion src/Magpie.Core/conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ spdlog/1.11.0
parallel-hashmap/1.37
muparser/2.3.4
yas/7.1.0
zstd/1.5.5
imgui/1.89.4

[generators]
Expand Down