1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "util/uri_lookup.h"
17
18 #include <3d/ecs/components/animation_component.h>
19 #include <3d/ecs/components/material_component.h>
20 #include <3d/ecs/components/mesh_component.h>
21 #include <3d/ecs/components/render_handle_component.h>
22 #include <3d/ecs/components/skin_ibm_component.h>
23 #include <3d/ecs/components/uri_component.h>
24 #include <core/ecs/intf_ecs.h>
25 #include <core/ecs/intf_entity_manager.h>
26 #include <core/property/intf_property_handle.h>
27
28 CORE3D_BEGIN_NAMESPACE()
29 using namespace BASE_NS;
30 using namespace CORE_NS;
31 using namespace RENDER_NS;
32
33 template<typename ComponentManager>
LookupResourceByUri(string_view uri,const IUriComponentManager & uriManager,const ComponentManager & componentManager)34 Entity LookupResourceByUri(
35 string_view uri, const IUriComponentManager& uriManager, const ComponentManager& componentManager)
36 {
37 const auto& entityManager = uriManager.GetEcs().GetEntityManager();
38 const auto uriComponents = uriManager.GetComponentCount();
39 for (auto i = 0u; i < uriComponents; ++i) {
40 if (Entity entity = uriManager.GetEntity(i); entityManager.IsAlive(entity)) {
41 if (const auto uriHandle = uriManager.Read(i); uriHandle) {
42 const bool found = uriHandle->uri == uri;
43 if (found && componentManager.HasComponent(entity)) {
44 return entity;
45 }
46 }
47 }
48 }
49 return {};
50 }
51
52 template Entity LookupResourceByUri<>(
53 string_view uri, const IUriComponentManager& uriManager, const IAnimationComponentManager& componentManager);
54
55 template Entity LookupResourceByUri<>(
56 string_view uri, const IUriComponentManager& uriManager, const IRenderHandleComponentManager& componentManager);
57
58 template Entity LookupResourceByUri<>(
59 string_view uri, const IUriComponentManager& uriManager, const IMaterialComponentManager& componentManager);
60
61 template Entity LookupResourceByUri<>(
62 string_view uri, const IUriComponentManager& uriManager, const IMeshComponentManager& componentManager);
63
64 template Entity LookupResourceByUri<>(
65 string_view uri, const IUriComponentManager& uriManager, const ISkinIbmComponentManager& componentManager);
66 CORE3D_END_NAMESPACE()
67