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 API_CORE_ECS_ISYSTEM_H
17 #define API_CORE_ECS_ISYSTEM_H
18 
19 #include <cstdint>
20 
21 #include <base/containers/string_view.h>
22 #include <base/namespace.h>
23 #include <base/util/uid.h>
24 #include <core/namespace.h>
25 
26 CORE_BEGIN_NAMESPACE()
27 class IEcs;
28 class IPropertyHandle;
29 
30 /** @ingroup group_ecs_isystem */
31 /** ISystem */
32 class ISystem {
33 public:
34     /** Get class name of the system.
35      */
36     virtual BASE_NS::string_view GetName() const = 0;
37 
38     /** Returns the UID of the system.
39      */
40     virtual BASE_NS::Uid GetUid() const = 0;
41 
42     /** Get properties of the system. (Modifiable)
43      */
44     virtual IPropertyHandle* GetProperties() = 0;
45 
46     /** Get properties of the system. (Read only)
47      */
48     virtual const IPropertyHandle* GetProperties() const = 0;
49 
50     /** Set properties of the system.
51      */
52     virtual void SetProperties(const IPropertyHandle&) = 0;
53 
54     /** Get active status for the system.
55      */
56     virtual bool IsActive() const = 0;
57 
58     /** Set active status for the system.
59      *  @param isActive State what is set, true for active and false for inactive.
60      */
61     virtual void SetActive(bool isActive) = 0;
62 
63     /** Initialize system (Application developer should not call this since its called automatically).
64      */
65     virtual void Initialize() = 0;
66 
67     /** Update system with current time in the ECS and delta occured between last frame (Application developer should
68      * not call this since its called automatically). Delta is scaled by the ECS time scale. For actual delta the
69      * system implementation should e.g. take a difference between current and previous total time.
70      * @param isFrameRenderingQueued If true, the frame rendering will happen and system must update all render data.
71      * @param time Elapsed total time (in us).
72      * @param delta Elapsed time since last update, scaled IEcs::GetTimeScale (in us).
73      * @return True if the system updated any render data, this will queue the current frame for rendering.
74      */
75     virtual bool Update(bool isFrameRenderingQueued, uint64_t time, uint64_t delta) = 0;
76 
77     /** Uninitialize system (Application developer should not call this since its called automatically).
78      */
79     virtual void Uninitialize() = 0;
80 
81     /** Get ECS from system.
82      */
83     virtual const IEcs& GetECS() const = 0;
84 
85 protected:
86     ISystem() = default;
87     ISystem(const ISystem&) = delete;
88     ISystem(ISystem&&) = delete;
89     ISystem& operator=(const ISystem&) = delete;
90     ISystem& operator=(ISystem&&) = delete;
91     virtual ~ISystem() = default;
92 };
93 CORE_END_NAMESPACE()
94 
95 #endif // API_CORE_ECS_ISYSTEM_H
96