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
26
namespace
kiwano
27
{
28
29
class
Actor;
30
class
Event;
31
class
ComponentManager;
32
47
class
KGE_API
Component
:
public
ObjectBase
48
{
49
friend
class
ComponentManager
;
50
51
public
:
54
bool
IsEnable()
const
;
55
58
void
SetEnabled(
bool
enabled);
59
62
Actor
* GetBoundActor()
const
;
63
66
void
RemoveFromActor();
67
68
protected
:
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
93
private
:
94
bool
enabled_;
95
Actor
* actor_;
96
};
97
100
inline
bool
Component::IsEnable
()
const
101
{
102
return
enabled_;
103
}
104
105
inline
void
Component::SetEnabled
(
bool
enabled)
106
{
107
enabled_ = enabled;
108
}
109
110
inline
Actor
*
Component::GetBoundActor
()
const
111
{
112
return
actor_;
113
}
114
115
inline
void
Component::OnUpdate
(
Duration
dt)
116
{
117
KGE_NOT_USED(dt);
118
}
119
120
inline
void
Component::OnRender
(
RenderContext
& ctx)
121
{
122
KGE_NOT_USED(ctx);
123
}
124
125
inline
void
Component::HandleEvent
(
Event
* evt)
126
{
127
KGE_NOT_USED(evt);
128
}
129
130
}
// namespace kiwano
kiwano::Actor
角色
Definition:
Actor.h:63
kiwano::ComponentManager
组件管理器
Definition:
ComponentManager.h:42
kiwano::Component
组件
Definition:
Component.h:48
kiwano::Component::HandleEvent
virtual void HandleEvent(Event *evt)
处理角色事件
Definition:
Component.h:125
kiwano::Component::OnUpdate
virtual void OnUpdate(Duration dt)
更新组件
Definition:
Component.h:115
kiwano::Component::GetBoundActor
Actor * GetBoundActor() const
获取绑定的角色
Definition:
Component.h:110
kiwano::Component::OnRender
virtual void OnRender(RenderContext &ctx)
渲染组件
Definition:
Component.h:120
kiwano::Component::SetEnabled
void SetEnabled(bool enabled)
设置组件启用或禁用
Definition:
Component.h:105
kiwano::Component::IsEnable
bool IsEnable() const
是否启用组件
Definition:
Component.h:100
kiwano::Event
事件
Definition:
Event.h:43
kiwano::ObjectBase
基础对象
Definition:
ObjectBase.h:138
kiwano::RenderContext
渲染上下文
Definition:
RenderContext.h:62
kiwano::Duration
时间段
Definition:
Duration.h:48
src
kiwano
base
component
Component.h
制作者
1.9.4