• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SCENE_SRC_CORE_ECS_LISTENER_H
17 #define SCENE_SRC_CORE_ECS_LISTENER_H
18 
19 #include <scene/base/types.h>
20 #include <scene/ext/intf_ecs_context.h>
21 #include <scene/ext/intf_ecs_event_listener.h>
22 
23 #include <base/containers/unordered_map.h>
24 
SCENE_BEGIN_NAMESPACE()25 SCENE_BEGIN_NAMESPACE()
26 
27 class EcsListener : CORE_NS::IEcs::EntityListener, CORE_NS::IEcs::ComponentListener {
28 public:
29     bool Initialize(IEcsContext& context);
30     void Uninitialize();
31 
32     void RegisterEcsObject(const IEcsObject::Ptr&);
33     void DeregisterEcsObject(const IEcsObject::ConstPtr&);
34     void DeregisterEcsObject(CORE_NS::Entity);
35 
36     IEcsObject::Ptr FindEcsObject(CORE_NS::Entity ent) const;
37 
38 private:
39     void OnEntityEvent(
40         CORE_NS::IEcs::EntityListener::EventType type, BASE_NS::array_view<const CORE_NS::Entity> entities) override;
41     void OnComponentEvent(CORE_NS::IEcs::ComponentListener::EventType type, const CORE_NS::IComponentManager& manager,
42         BASE_NS::array_view<const CORE_NS::Entity> entities) override;
43 
44 private:
45     IEcsContext* ecs_ {};
46     BASE_NS::unordered_map<CORE_NS::Entity, IEcsObject::WeakPtr> objects_;
47 };
48 
49 SCENE_END_NAMESPACE()
50 
51 #endif