Kiwano Engine v1.3.x
Component.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Time.h>
23#include <kiwano/base/ObjectBase.h>
24#include <kiwano/render/RenderContext.h>
25
26namespace kiwano
27{
28
29class Actor;
30class Event;
31class ComponentManager;
32
47class KGE_API Component : public ObjectBase
48{
49 friend class ComponentManager;
50
51public:
54 bool IsEnable() const;
55
58 void SetEnabled(bool enabled);
59
62 Actor* GetBoundActor() const;
63
66 void RemoveFromActor();
67
68protected:
69 Component();
70
71 virtual ~Component();
72
75 virtual void InitComponent(Actor* actor);
76
79 virtual void DestroyComponent();
80
83 virtual void OnUpdate(Duration dt);
84
87 virtual void OnRender(RenderContext& ctx);
88
91 virtual void HandleEvent(Event* evt);
92
93private:
94 bool enabled_;
95 Actor* actor_;
96};
97
100inline bool Component::IsEnable() const
101{
102 return enabled_;
103}
104
105inline void Component::SetEnabled(bool enabled)
106{
107 enabled_ = enabled;
108}
109
111{
112 return actor_;
113}
114
116{
117 KGE_NOT_USED(dt);
118}
119
121{
122 KGE_NOT_USED(ctx);
123}
124
126{
127 KGE_NOT_USED(evt);
128}
129
130} // namespace kiwano
角色
Definition: Actor.h:63
组件管理器
Definition: ComponentManager.h:42
组件
Definition: Component.h:48
virtual void HandleEvent(Event *evt)
处理角色事件
Definition: Component.h:125
virtual void OnUpdate(Duration dt)
更新组件
Definition: Component.h:115
Actor * GetBoundActor() const
获取绑定的角色
Definition: Component.h:110
virtual void OnRender(RenderContext &ctx)
渲染组件
Definition: Component.h:120
void SetEnabled(bool enabled)
设置组件启用或禁用
Definition: Component.h:105
bool IsEnable() const
是否启用组件
Definition: Component.h:100
事件
Definition: Event.h:43
基础对象
Definition: ObjectBase.h:138
渲染上下文
Definition: RenderContext.h:62
时间段
Definition: Duration.h:48