18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef SCENEPLUGIN_ASSETMANAGER_H 178bf80f4bSopenharmony_ci#define SCENEPLUGIN_ASSETMANAGER_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_asset_loader.h> 208bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_asset_manager.h> 218bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_entity_collection.h> 228bf80f4bSopenharmony_ci 238bf80f4bSopenharmony_ci#include "ecs_serializer.h" 248bf80f4bSopenharmony_ci 258bf80f4bSopenharmony_ciSCENE_BEGIN_NAMESPACE() 268bf80f4bSopenharmony_ci 278bf80f4bSopenharmony_ciclass AssetManager : public IAssetManager { 288bf80f4bSopenharmony_cipublic: 298bf80f4bSopenharmony_ci AssetManager(RENDER_NS::IRenderContext& renderContext, CORE3D_NS::IGraphicsContext& graphicsContext); 308bf80f4bSopenharmony_ci virtual ~AssetManager(); 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ci // 338bf80f4bSopenharmony_ci // From IAssetManager 348bf80f4bSopenharmony_ci // 358bf80f4bSopenharmony_ci ExtensionType GetExtensionType(BASE_NS::string_view ext) const override; 368bf80f4bSopenharmony_ci 378bf80f4bSopenharmony_ci IAssetLoader::Ptr CreateAssetLoader( 388bf80f4bSopenharmony_ci IEntityCollection& ec, BASE_NS::string_view src, BASE_NS::string_view contextUri) override; 398bf80f4bSopenharmony_ci 408bf80f4bSopenharmony_ci bool LoadAsset(IEntityCollection& ec, BASE_NS::string_view uri, BASE_NS::string_view contextUri) override; 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ci bool SaveJsonEntityCollection( 438bf80f4bSopenharmony_ci const IEntityCollection& ec, BASE_NS::string_view uri, BASE_NS::string_view contextUri) const override; 448bf80f4bSopenharmony_ci 458bf80f4bSopenharmony_ci IEntityCollection* LoadAssetToCache(CORE_NS::IEcs& ecs, BASE_NS::string_view cacheUri, BASE_NS::string_view uri, 468bf80f4bSopenharmony_ci BASE_NS::string_view contextUri, bool active, bool forceReload) override; 478bf80f4bSopenharmony_ci 488bf80f4bSopenharmony_ci bool IsCachedCollection(BASE_NS::string_view uri, BASE_NS::string_view contextUri) const override; 498bf80f4bSopenharmony_ci IEntityCollection* CreateCachedCollection( 508bf80f4bSopenharmony_ci CORE_NS::IEcs& ecs, BASE_NS::string_view uri, BASE_NS::string_view contextUri) override; 518bf80f4bSopenharmony_ci IEntityCollection* GetCachedCollection(BASE_NS::string_view uri, BASE_NS::string_view contextUri) const override; 528bf80f4bSopenharmony_ci void RemoveFromCache(BASE_NS::string_view uri, BASE_NS::string_view contextUri) override; 538bf80f4bSopenharmony_ci void ClearCache() override; 548bf80f4bSopenharmony_ci 558bf80f4bSopenharmony_ci void RefreshAsset(IEntityCollection& ec, bool active) override; 568bf80f4bSopenharmony_ci 578bf80f4bSopenharmony_ci IEntityCollection* InstantiateCollection( 588bf80f4bSopenharmony_ci IEntityCollection& ec, BASE_NS::string_view uri, BASE_NS::string_view contextUri) override; 598bf80f4bSopenharmony_ci 608bf80f4bSopenharmony_ci IEcsSerializer& GetEcsSerializer() override; 618bf80f4bSopenharmony_ci 628bf80f4bSopenharmony_ci // 638bf80f4bSopenharmony_ci // From IEcsSerializer::IListener 648bf80f4bSopenharmony_ci // 658bf80f4bSopenharmony_ci IEntityCollection* GetExternalCollection( 668bf80f4bSopenharmony_ci CORE_NS::IEcs& ecs, BASE_NS::string_view uri, BASE_NS::string_view contextUri) override; 678bf80f4bSopenharmony_ci 688bf80f4bSopenharmony_ciprotected: 698bf80f4bSopenharmony_ci void Destroy() override; 708bf80f4bSopenharmony_ci 718bf80f4bSopenharmony_ciprivate: 728bf80f4bSopenharmony_ci RENDER_NS::IRenderContext& renderContext_; 738bf80f4bSopenharmony_ci CORE3D_NS::IGraphicsContext& graphicsContext_; 748bf80f4bSopenharmony_ci EcsSerializer ecsSerializer_; 758bf80f4bSopenharmony_ci 768bf80f4bSopenharmony_ci // Mapping from uri to a collection of entities. The entities live in the ECS but we need to keep track of some kind 778bf80f4bSopenharmony_ci // of internal ownership of each cached entity. 788bf80f4bSopenharmony_ci BASE_NS::unordered_map<BASE_NS::string, IEntityCollection::Ptr> cacheCollections_; 798bf80f4bSopenharmony_ci}; 808bf80f4bSopenharmony_ci 818bf80f4bSopenharmony_ciSCENE_END_NAMESPACE() 828bf80f4bSopenharmony_ci 838bf80f4bSopenharmony_ci#endif // SCENEPLUGIN_ASSETMANAGER_H 84