Skip to content

Commit

Permalink
VideoCommon: move AssetMap to a types header file, so it can be pulle…
Browse files Browse the repository at this point in the history
…d in without the DirectFilesystemAssetLibrary dependencies, the header will be expanded later
  • Loading branch information
iwubcode committed Jul 12, 2024
1 parent 8904b56 commit 39cb24f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions Source/Core/DolphinLib.props
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@
<ClInclude Include="VideoCommon\Assets\MeshAsset.h" />
<ClInclude Include="VideoCommon\Assets\ShaderAsset.h" />
<ClInclude Include="VideoCommon\Assets\TextureAsset.h" />
<ClInclude Include="VideoCommon\Assets\Types.h" />
<ClInclude Include="VideoCommon\Assets\WatchableFilesystemAssetLibrary.h" />
<ClInclude Include="VideoCommon\AsyncRequests.h" />
<ClInclude Include="VideoCommon\AsyncShaderCompiler.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass
}

void DirectFilesystemAssetLibrary::SetAssetIDMapData(const AssetID& asset_id,
AssetMap asset_path_map)
VideoCommon::Assets::AssetMap asset_path_map)
{
AssetMap previous_asset_map;
VideoCommon::Assets::AssetMap previous_asset_map;
{
std::lock_guard lk(m_asset_map_lock);
previous_asset_map = m_assetid_to_asset_map_path[asset_id];
Expand Down Expand Up @@ -526,7 +526,7 @@ bool DirectFilesystemAssetLibrary::LoadMips(const std::filesystem::path& asset_p
return true;
}

DirectFilesystemAssetLibrary::AssetMap
VideoCommon::Assets::AssetMap
DirectFilesystemAssetLibrary::GetAssetMapForID(const AssetID& asset_id) const
{
std::lock_guard lk(m_asset_map_lock);
Expand Down
9 changes: 4 additions & 5 deletions Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>

#include "VideoCommon/Assets/CustomTextureData.h"
#include "VideoCommon/Assets/Types.h"
#include "VideoCommon/Assets/WatchableFilesystemAssetLibrary.h"

namespace VideoCommon
Expand All @@ -18,8 +19,6 @@ namespace VideoCommon
class DirectFilesystemAssetLibrary final : public WatchableFilesystemAssetLibrary
{
public:
using AssetMap = std::map<std::string, std::filesystem::path>;

LoadInfo LoadTexture(const AssetID& asset_id, TextureData* data) override;
LoadInfo LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) override;
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
Expand All @@ -31,7 +30,7 @@ class DirectFilesystemAssetLibrary final : public WatchableFilesystemAssetLibrar
// 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
// 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:
void PathModified(std::string_view path) override;
Expand All @@ -40,10 +39,10 @@ class DirectFilesystemAssetLibrary final : public WatchableFilesystemAssetLibrar
bool LoadMips(const std::filesystem::path& asset_path, CustomTextureData::ArraySlice* data);

// 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_asset_map_lock;
std::map<AssetID, std::map<std::string, std::filesystem::path>> m_assetid_to_asset_map_path;
std::map<AssetID, Assets::AssetMap> m_assetid_to_asset_map_path;

mutable std::mutex m_path_map_lock;
std::map<std::string, AssetID, std::less<>> m_path_to_asset_id;
Expand Down
13 changes: 13 additions & 0 deletions Source/Core/VideoCommon/Assets/Types.h
Original file line number Diff line number Diff line change
@@ -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>;
}
1 change: 1 addition & 0 deletions Source/Core/VideoCommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_library(videocommon
Assets/ShaderAsset.h
Assets/TextureAsset.cpp
Assets/TextureAsset.h
Assets/Types.h
Assets/WatchableFilesystemAssetLibrary.cpp
Assets/WatchableFilesystemAssetLibrary.h
AsyncRequests.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

#include <picojson.h>

#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"
#include "VideoCommon/Assets/CustomAssetLibrary.h"
#include "VideoCommon/Assets/Types.h"

struct GraphicsModAssetConfig
{
VideoCommon::CustomAssetLibrary::AssetID m_asset_id;
VideoCommon::DirectFilesystemAssetLibrary::AssetMap m_map;
VideoCommon::Assets::AssetMap m_map;

void SerializeToConfig(picojson::object& json_obj) const;
bool DeserializeFromConfig(const picojson::object& obj);
Expand Down

0 comments on commit 39cb24f

Please sign in to comment.