VideoCommon: move AssetMap to a types header file, so it can be pulled in without the DirectFilesystemAssetLibrary dependencies, the header will be expanded later

This commit is contained in:
iwubcode
2024-07-04 17:41:49 -05:00
parent 7d59c2743d
commit 2ae43324cb
6 changed files with 27 additions and 12 deletions

View File

@ -675,6 +675,7 @@
<ClInclude Include="VideoCommon\Assets\MeshAsset.h" /> <ClInclude Include="VideoCommon\Assets\MeshAsset.h" />
<ClInclude Include="VideoCommon\Assets\ShaderAsset.h" /> <ClInclude Include="VideoCommon\Assets\ShaderAsset.h" />
<ClInclude Include="VideoCommon\Assets\TextureAsset.h" /> <ClInclude Include="VideoCommon\Assets\TextureAsset.h" />
<ClInclude Include="VideoCommon\Assets\Types.h" />
<ClInclude Include="VideoCommon\AsyncRequests.h" /> <ClInclude Include="VideoCommon\AsyncRequests.h" />
<ClInclude Include="VideoCommon\AsyncShaderCompiler.h" /> <ClInclude Include="VideoCommon\AsyncShaderCompiler.h" />
<ClInclude Include="VideoCommon\BoundingBox.h" /> <ClInclude Include="VideoCommon\BoundingBox.h" />

View File

@ -396,10 +396,10 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass
} }
void DirectFilesystemAssetLibrary::SetAssetIDMapData(const AssetID& asset_id, void DirectFilesystemAssetLibrary::SetAssetIDMapData(const AssetID& asset_id,
AssetMap asset_path_map) VideoCommon::Assets::AssetMap asset_path_map)
{ {
std::lock_guard lk(m_lock); std::lock_guard lk(m_lock);
m_assetid_to_asset_map_path[asset_id] = std::move(asset_path_map); m_asset_id_to_asset_map_path[asset_id] = std::move(asset_path_map);
} }
bool DirectFilesystemAssetLibrary::LoadMips(const std::filesystem::path& asset_path, bool DirectFilesystemAssetLibrary::LoadMips(const std::filesystem::path& asset_path,
@ -454,12 +454,12 @@ bool DirectFilesystemAssetLibrary::LoadMips(const std::filesystem::path& asset_p
return true; return true;
} }
DirectFilesystemAssetLibrary::AssetMap VideoCommon::Assets::AssetMap
DirectFilesystemAssetLibrary::GetAssetMapForID(const AssetID& asset_id) const DirectFilesystemAssetLibrary::GetAssetMapForID(const AssetID& asset_id) const
{ {
std::lock_guard lk(m_lock); std::lock_guard lk(m_lock);
if (auto iter = m_assetid_to_asset_map_path.find(asset_id); if (auto iter = m_asset_id_to_asset_map_path.find(asset_id);
iter != m_assetid_to_asset_map_path.end()) iter != m_asset_id_to_asset_map_path.end())
{ {
return iter->second; return iter->second;
} }

View File

@ -10,6 +10,7 @@
#include "VideoCommon/Assets/CustomAssetLibrary.h" #include "VideoCommon/Assets/CustomAssetLibrary.h"
#include "VideoCommon/Assets/CustomTextureData.h" #include "VideoCommon/Assets/CustomTextureData.h"
#include "VideoCommon/Assets/Types.h"
namespace VideoCommon namespace VideoCommon
{ {
@ -18,8 +19,6 @@ namespace VideoCommon
class DirectFilesystemAssetLibrary final : public CustomAssetLibrary class DirectFilesystemAssetLibrary final : public CustomAssetLibrary
{ {
public: public:
using AssetMap = std::map<std::string, std::filesystem::path>;
LoadInfo LoadTexture(const AssetID& asset_id, TextureData* data) override; LoadInfo LoadTexture(const AssetID& asset_id, TextureData* data) override;
LoadInfo LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) override; LoadInfo LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) override;
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override; LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
@ -28,16 +27,16 @@ public:
// Assigns the asset id to a map of files, how this map is read is dependent on the data // Assigns the asset id to a map of files, how this map is read is dependent on the data
// For instance, a raw texture would expect the map to have a single entry and load that // For instance, a raw texture would expect the map to have a single entry and load that
// file as the asset. But a model file data might have its data spread across multiple files // file as the asset. But a model file data might have its data spread across multiple files
void SetAssetIDMapData(const AssetID& asset_id, AssetMap asset_path_map); void SetAssetIDMapData(const AssetID& asset_id, Assets::AssetMap asset_path_map);
private: private:
// Loads additional mip levels into the texture structure until _mip<N> texture is not found // Loads additional mip levels into the texture structure until _mip<N> texture is not found
bool LoadMips(const std::filesystem::path& asset_path, CustomTextureData::ArraySlice* data); bool LoadMips(const std::filesystem::path& asset_path, CustomTextureData::ArraySlice* data);
// Gets the asset map given an asset id // Gets the asset map given an asset id
AssetMap GetAssetMapForID(const AssetID& asset_id) const; Assets::AssetMap GetAssetMapForID(const AssetID& asset_id) const;
mutable std::mutex m_lock; mutable std::mutex m_lock;
std::map<AssetID, std::map<std::string, std::filesystem::path>> m_assetid_to_asset_map_path; std::map<AssetID, Assets::AssetMap> m_asset_id_to_asset_map_path;
}; };
} // namespace VideoCommon } // namespace VideoCommon

View File

@ -0,0 +1,13 @@
// Copyright 2024 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <filesystem>
#include <map>
#include <string>
namespace VideoCommon::Assets
{
using AssetMap = std::map<std::string, std::filesystem::path>;
}

View File

@ -26,6 +26,7 @@ add_library(videocommon
Assets/ShaderAsset.h Assets/ShaderAsset.h
Assets/TextureAsset.cpp Assets/TextureAsset.cpp
Assets/TextureAsset.h Assets/TextureAsset.h
Assets/Types.h
AsyncRequests.cpp AsyncRequests.cpp
AsyncRequests.h AsyncRequests.h
AsyncShaderCompiler.cpp AsyncShaderCompiler.cpp

View File

@ -7,12 +7,13 @@
#include <picojson.h> #include <picojson.h>
#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h" #include "VideoCommon/Assets/CustomAssetLibrary.h"
#include "VideoCommon/Assets/Types.h"
struct GraphicsModAssetConfig struct GraphicsModAssetConfig
{ {
VideoCommon::CustomAssetLibrary::AssetID m_asset_id; VideoCommon::CustomAssetLibrary::AssetID m_asset_id;
VideoCommon::DirectFilesystemAssetLibrary::AssetMap m_map; VideoCommon::Assets::AssetMap m_map;
void SerializeToConfig(picojson::object& json_obj) const; void SerializeToConfig(picojson::object& json_obj) const;
bool DeserializeFromConfig(const picojson::object& obj); bool DeserializeFromConfig(const picojson::object& obj);