mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
* feat: 添加 ImGuiBackend * chore: 优化格式 * refactor: 将 ImGuiBackend 重构为类 * chore: 清理 ImGuiBackend * chore: 清理 ImGuiBackend * chore: 清理 ImGuiBackend * perf: 优化着色器编译 * feat: 添加错误记录 * feat: 不再按需构造字体 * feat: 添加 ImGuiFontCacheManager * feat: 实现序列化 ImFontAtlas * feat: 实现反序列话 ImFontAtlas * feat: 为字体缓存添加版本号 * feat: 在字体缓存中保存调试名称 * feat: 添加禁用字体缓存选项
46 lines
1.3 KiB
C++
46 lines
1.3 KiB
C++
#pragma once
|
|
#include "Win32Utils.h"
|
|
#include "EffectDesc.h"
|
|
#include <parallel_hashmap/phmap.h>
|
|
|
|
namespace Magpie::Core {
|
|
|
|
class EffectCacheManager {
|
|
public:
|
|
static EffectCacheManager& Get() noexcept {
|
|
static EffectCacheManager instance;
|
|
return instance;
|
|
}
|
|
|
|
EffectCacheManager(const EffectCacheManager&) = delete;
|
|
EffectCacheManager(EffectCacheManager&&) = delete;
|
|
|
|
bool Load(std::wstring_view effectName, std::wstring_view hash, EffectDesc& desc);
|
|
|
|
void Save(std::wstring_view effectName, std::wstring_view hash, const EffectDesc& desc);
|
|
|
|
// inlineParams 为内联变量,可以为空
|
|
// 接受 std::string& 的重载速度更快,且保证不修改 source
|
|
static std::wstring GetHash(
|
|
std::string_view source,
|
|
const phmap::flat_hash_map<std::wstring, float>* inlineParams = nullptr
|
|
);
|
|
static std::wstring GetHash(
|
|
std::string& source,
|
|
const phmap::flat_hash_map<std::wstring, float>* inlineParams = nullptr
|
|
);
|
|
|
|
private:
|
|
EffectCacheManager() = default;
|
|
|
|
void _AddToMemCache(const std::wstring& cacheFileName, const EffectDesc& desc);
|
|
bool _LoadFromMemCache(const std::wstring& cacheFileName, EffectDesc& desc);
|
|
|
|
// 用于同步对 _memCache 的访问
|
|
Win32Utils::SRWMutex _srwMutex;
|
|
// cacheFileName -> (EffectDesc, lastAccess)
|
|
phmap::flat_hash_map<std::wstring, std::pair<EffectDesc, UINT>> _memCache;
|
|
UINT _lastAccess = 0;
|
|
};
|
|
|
|
}
|