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_ENTITYCOLLECTION_H 178bf80f4bSopenharmony_ci#define SCENEPLUGIN_ENTITYCOLLECTION_H 188bf80f4bSopenharmony_ci 198bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_entity_collection.h> 208bf80f4bSopenharmony_ci 218bf80f4bSopenharmony_ci#include <base/containers/unique_ptr.h> 228bf80f4bSopenharmony_ci#include <base/containers/unordered_map.h> 238bf80f4bSopenharmony_ci 248bf80f4bSopenharmony_ciSCENE_BEGIN_NAMESPACE() 258bf80f4bSopenharmony_ci 268bf80f4bSopenharmony_ciclass EntityCollection : public IEntityCollection, private IEntityCollection::IListener { 278bf80f4bSopenharmony_cipublic: 288bf80f4bSopenharmony_ci using Ptr = BASE_NS::unique_ptr<EntityCollection, Deleter>; 298bf80f4bSopenharmony_ci 308bf80f4bSopenharmony_ci EntityCollection(CORE_NS::IEcs& ecs, BASE_NS::string_view uri, BASE_NS::string_view contextUri); 318bf80f4bSopenharmony_ci 328bf80f4bSopenharmony_ci void AddListener(IEntityCollection::IListener& listener) override; 338bf80f4bSopenharmony_ci void RemoveListener(IEntityCollection::IListener& listener) override; 348bf80f4bSopenharmony_ci 358bf80f4bSopenharmony_ci // 368bf80f4bSopenharmony_ci // From IEntityCollection 378bf80f4bSopenharmony_ci // 388bf80f4bSopenharmony_ci 398bf80f4bSopenharmony_ci IEntityCollection::Ptr CreateNewEntityCollection( 408bf80f4bSopenharmony_ci BASE_NS::string_view uri, BASE_NS::string_view contextUri) override; 418bf80f4bSopenharmony_ci 428bf80f4bSopenharmony_ci CORE_NS::IEcs& GetEcs() const override; 438bf80f4bSopenharmony_ci BASE_NS::string GetUri() const override; 448bf80f4bSopenharmony_ci void SetUri(const BASE_NS::string& uri) override; 458bf80f4bSopenharmony_ci 468bf80f4bSopenharmony_ci BASE_NS::string GetContextUri() const override; 478bf80f4bSopenharmony_ci 488bf80f4bSopenharmony_ci BASE_NS::string GetSrc() const override; 498bf80f4bSopenharmony_ci void SetSrc(BASE_NS::string_view src) override; 508bf80f4bSopenharmony_ci 518bf80f4bSopenharmony_ci BASE_NS::string GetType() const override; 528bf80f4bSopenharmony_ci void SetType(BASE_NS::string_view type) override; 538bf80f4bSopenharmony_ci 548bf80f4bSopenharmony_ci size_t GetEntityCount() const override; 558bf80f4bSopenharmony_ci CORE_NS::EntityReference GetEntity(size_t collectionIndex) const override; 568bf80f4bSopenharmony_ci CORE_NS::EntityReference GetEntity(BASE_NS::string_view localContextId) const override; 578bf80f4bSopenharmony_ci CORE_NS::EntityReference GetEntityRecursive(BASE_NS::string_view localContextId) const override; 588bf80f4bSopenharmony_ci BASE_NS::array_view<const CORE_NS::EntityReference> GetEntities() const override; 598bf80f4bSopenharmony_ci void AddEntity(CORE_NS::EntityReference entitity) override; 608bf80f4bSopenharmony_ci void AddEntities(BASE_NS::array_view<const CORE_NS::EntityReference> entities) override; 618bf80f4bSopenharmony_ci bool RemoveEntity(CORE_NS::EntityReference entitity) override; 628bf80f4bSopenharmony_ci void RemoveEntities(BASE_NS::array_view<const CORE_NS::EntityReference> entities) override; 638bf80f4bSopenharmony_ci void RemoveEntityRecursive(CORE_NS::Entity entity) override; 648bf80f4bSopenharmony_ci 658bf80f4bSopenharmony_ci void SetId(BASE_NS::string_view id, CORE_NS::EntityReference entity) override; 668bf80f4bSopenharmony_ci BASE_NS::string_view GetId(CORE_NS::Entity entity) const override; 678bf80f4bSopenharmony_ci BASE_NS::string_view GetIdRecursive(CORE_NS::Entity entity) const override; 688bf80f4bSopenharmony_ci 698bf80f4bSopenharmony_ci void SetUniqueIdentifier(BASE_NS::string_view id, CORE_NS::EntityReference entity) override; 708bf80f4bSopenharmony_ci BASE_NS::string_view GetUniqueIdentifier(CORE_NS::Entity entity) const override; 718bf80f4bSopenharmony_ci BASE_NS::string_view GetUniqueIdentifierRecursive(CORE_NS::Entity entity) const override; 728bf80f4bSopenharmony_ci 738bf80f4bSopenharmony_ci size_t GetSubCollectionCount() const override; 748bf80f4bSopenharmony_ci IEntityCollection* GetSubCollection(size_t index) override; 758bf80f4bSopenharmony_ci const IEntityCollection* GetSubCollection(size_t index) const override; 768bf80f4bSopenharmony_ci int32_t GetSubCollectionIndex(BASE_NS::string_view uri) const override; 778bf80f4bSopenharmony_ci int32_t GetSubCollectionIndexByRoot(CORE_NS::Entity entity) const override; 788bf80f4bSopenharmony_ci IEntityCollection& AddSubCollection( 798bf80f4bSopenharmony_ci BASE_NS::string_view uri, BASE_NS::string_view contextUri, bool serializable) override; 808bf80f4bSopenharmony_ci IEntityCollection& AddSubCollectionClone(IEntityCollection& collection, BASE_NS::string_view uri) override; 818bf80f4bSopenharmony_ci void RemoveSubCollection(size_t index) override; 828bf80f4bSopenharmony_ci 838bf80f4bSopenharmony_ci size_t GetEntityCountRecursive(bool includeDestroyed, bool includeNonSerialized = true) const override; 848bf80f4bSopenharmony_ci void GetEntitiesRecursive(bool includeDestroyed, BASE_NS::vector<CORE_NS::EntityReference>& entitiesOut, 858bf80f4bSopenharmony_ci bool includeNonSerialized = true) const override; 868bf80f4bSopenharmony_ci 878bf80f4bSopenharmony_ci bool Contains(CORE_NS::Entity entity) const override; 888bf80f4bSopenharmony_ci bool IsExternal(CORE_NS::Entity entity) const override; 898bf80f4bSopenharmony_ci bool isSubCollectionRoot(CORE_NS::Entity entity) const override; 908bf80f4bSopenharmony_ci CORE_NS::EntityReference GetReference(CORE_NS::Entity entity) const override; 918bf80f4bSopenharmony_ci 928bf80f4bSopenharmony_ci void SetActive(bool active) override; 938bf80f4bSopenharmony_ci bool IsActive() const override; 948bf80f4bSopenharmony_ci 958bf80f4bSopenharmony_ci void MarkDestroyed(bool destroyed) override; 968bf80f4bSopenharmony_ci bool IsMarkedDestroyed() const override; 978bf80f4bSopenharmony_ci 988bf80f4bSopenharmony_ci void MarkModified(bool modified) override; 998bf80f4bSopenharmony_ci void MarkModified(bool modified, bool recursive) override; 1008bf80f4bSopenharmony_ci bool IsMarkedModified() const override; 1018bf80f4bSopenharmony_ci 1028bf80f4bSopenharmony_ci void Clear() override; 1038bf80f4bSopenharmony_ci 1048bf80f4bSopenharmony_ci void CopyContents(IEntityCollection& srcCollection) override; 1058bf80f4bSopenharmony_ci 1068bf80f4bSopenharmony_ci BASE_NS::vector<CORE_NS::EntityReference> CopyContentsWithSerialization(IEntityCollection& srcCollection) override; 1078bf80f4bSopenharmony_ci BASE_NS::vector<CORE_NS::EntityReference> CopyContentsWithSerialization( 1088bf80f4bSopenharmony_ci IEntityCollection& srcCollection, BASE_NS::array_view<const CORE_NS::EntityReference> entities) override; 1098bf80f4bSopenharmony_ci 1108bf80f4bSopenharmony_ci bool MarkComponentSerialized(CORE_NS::Entity entity, BASE_NS::Uid component, bool serialize) override; 1118bf80f4bSopenharmony_ci bool MarkAllPropertiesSerialized(CORE_NS::Entity entity, BASE_NS::Uid component) override; 1128bf80f4bSopenharmony_ci bool MarkPropertySerialized( 1138bf80f4bSopenharmony_ci CORE_NS::Entity entity, BASE_NS::Uid component, BASE_NS::string_view propertyPath, bool serialize) override; 1148bf80f4bSopenharmony_ci bool IsPropertySerialized( 1158bf80f4bSopenharmony_ci CORE_NS::Entity entity, BASE_NS::Uid component, BASE_NS::string_view propertyPath) override; 1168bf80f4bSopenharmony_ci const PropertyList* GetSerializedProperties(CORE_NS::Entity entity, BASE_NS::Uid component) const override; 1178bf80f4bSopenharmony_ci 1188bf80f4bSopenharmony_ci void AddEntityToSubcollection( 1198bf80f4bSopenharmony_ci BASE_NS::string_view collection, BASE_NS::string_view name, CORE_NS::Entity entity, bool makeUnique) override; 1208bf80f4bSopenharmony_ci 1218bf80f4bSopenharmony_ci bool IsSerialized() const override; 1228bf80f4bSopenharmony_ci void SetSerialized(bool serialize) override; 1238bf80f4bSopenharmony_ci 1248bf80f4bSopenharmony_ciprotected: 1258bf80f4bSopenharmony_ci void Destroy() override; 1268bf80f4bSopenharmony_ci ~EntityCollection() override; 1278bf80f4bSopenharmony_ci 1288bf80f4bSopenharmony_ciprivate: 1298bf80f4bSopenharmony_ci // Prevent copying. 1308bf80f4bSopenharmony_ci EntityCollection(const EntityCollection&) = delete; 1318bf80f4bSopenharmony_ci EntityCollection& operator=(const EntityCollection&) = delete; 1328bf80f4bSopenharmony_ci 1338bf80f4bSopenharmony_ci // From IEntityCollection::IListener 1348bf80f4bSopenharmony_ci void ModifiedChanged(IEntityCollection& entityCollection, bool modified) override; 1358bf80f4bSopenharmony_ci 1368bf80f4bSopenharmony_ci void DoGetEntitiesRecursive( 1378bf80f4bSopenharmony_ci bool includeDestroyed, bool includeNonSerialized, BASE_NS::vector<CORE_NS::EntityReference>& entitiesOut) const; 1388bf80f4bSopenharmony_ci 1398bf80f4bSopenharmony_ci void ClonePrivate(EntityCollection& dst) const; 1408bf80f4bSopenharmony_ci void DoCloneRecursive(EntityCollection& dst) const; 1418bf80f4bSopenharmony_ci 1428bf80f4bSopenharmony_ci // TODO: Create a better data structure for this information. 1438bf80f4bSopenharmony_ci // Components to be serialized in an entity. 1448bf80f4bSopenharmony_ci using ComponentMap = BASE_NS::unordered_map<BASE_NS::Uid, PropertyList>; 1458bf80f4bSopenharmony_ci BASE_NS::unordered_map<CORE_NS::Entity, ComponentMap> serializationInfo_; 1468bf80f4bSopenharmony_ci 1478bf80f4bSopenharmony_ci CORE_NS::IEcs& ecs_; 1488bf80f4bSopenharmony_ci BASE_NS::string uri_; 1498bf80f4bSopenharmony_ci BASE_NS::string contextUri_; 1508bf80f4bSopenharmony_ci 1518bf80f4bSopenharmony_ci BASE_NS::string src_ {}; 1528bf80f4bSopenharmony_ci BASE_NS::string type_ {}; 1538bf80f4bSopenharmony_ci 1548bf80f4bSopenharmony_ci BASE_NS::unordered_map<BASE_NS::string, CORE_NS::EntityReference> namedEntities_; 1558bf80f4bSopenharmony_ci BASE_NS::unordered_map<BASE_NS::string, CORE_NS::EntityReference> entityIdentifiers_; 1568bf80f4bSopenharmony_ci BASE_NS::vector<CORE_NS::EntityReference> entities_; 1578bf80f4bSopenharmony_ci 1588bf80f4bSopenharmony_ci BASE_NS::vector<EntityCollection::Ptr> collections_; 1598bf80f4bSopenharmony_ci 1608bf80f4bSopenharmony_ci bool isActive_ { true }; 1618bf80f4bSopenharmony_ci bool isMarkedDestroyed_ { false }; 1628bf80f4bSopenharmony_ci bool isMarkedModified_ { false }; 1638bf80f4bSopenharmony_ci bool isSerialized_ { true }; 1648bf80f4bSopenharmony_ci 1658bf80f4bSopenharmony_ci BASE_NS::vector<IEntityCollection::IListener*> listeners_; 1668bf80f4bSopenharmony_ci}; 1678bf80f4bSopenharmony_ci 1688bf80f4bSopenharmony_ciSCENE_END_NAMESPACE() 1698bf80f4bSopenharmony_ci 1708bf80f4bSopenharmony_ci#endif // SCENEPLUGIN_ENTITYCOLLECTION_H 171