Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
10 changes: 10 additions & 0 deletions assets/asset_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ void AssetManager::PushBack(std::unique_ptr<AssetResolver> resolver) {
resolvers_.push_back(std::move(resolver));
}

void AssetManager::Merge(std::shared_ptr<AssetManager> assetManager) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the name, Merge typically means that all the elements will be combined somehow, but it doesn't look like that's what this is doing.

I'd like to suggest a better name, but I think I don't understand what is special about the last resolver of assetManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe PreserveBundleManager or something like that?

The very last resolve is the first one ever added, which is the one that resolves assets from the APK/IPA bundle that is installed with the device. Preserving it means that we don't need to sync every asset into the devFS when connecting to a device

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like this work?

  • AssetManager adds an API to declare which asset resolvers should be preserved across a hot reload
  • Shell::OnServiceProtocolSetAssetBundlePath retains those resolvers when constructing the new AssetManager

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would have to be done in engine.cc since the current asset manager will be private. I could add a param to the directory asset resolver that controls whether it should be preserved and then set this to true for the initial resolvers.

if (assetManager == nullptr) {
return;
}
if (assetManager->resolvers_.size() > 0) {
resolvers_.push_back(std::move(
assetManager->resolvers_[assetManager->resolvers_.size() - 1]));
}
}

// |AssetResolver|
std::unique_ptr<fml::Mapping> AssetManager::GetAsMapping(
const std::string& asset_name) const {
Expand Down
2 changes: 2 additions & 0 deletions assets/asset_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class AssetManager final : public AssetResolver {

void PushBack(std::unique_ptr<AssetResolver> resolver);

void Merge(std::shared_ptr<AssetManager> assetManager);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is doing something fancier than a straight-up merge as I think is usually understood, it would be good to have a bunch of comments here about what this does.


// |AssetResolver|
bool IsValid() const override;

Expand Down
3 changes: 2 additions & 1 deletion shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ bool Engine::UpdateAssetManager(
if (asset_manager_ == new_asset_manager) {
return false;
}

auto old_asset_manager = asset_manager_;
asset_manager_ = new_asset_manager;

if (!asset_manager_) {
return false;
}
asset_manager_->Merge(old_asset_manager);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More comments please =)


// Using libTXT as the text engine.
font_collection_.RegisterFonts(asset_manager_);
Expand Down