| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  | #include <kiwano/core/Time.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | #include <kiwano/core/ObjectBase.h>
 | 
					
						
							|  |  |  | #include <kiwano/core/IntrusiveList.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-23 14:56:14 +08:00
										 |  |  | #include <kiwano/render/RenderContext.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace kiwano | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Actor; | 
					
						
							|  |  |  | class Event; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | KGE_DECLARE_SMART_PTR(Component); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// \~chinese
 | 
					
						
							|  |  |  | /// @brief 组件列表
 | 
					
						
							|  |  |  | typedef IntrusiveList<ComponentPtr> ComponentList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * \~chinese | 
					
						
							|  |  |  |  * @brief 组件 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class KGE_API Component | 
					
						
							| 
									
										
										
										
											2020-02-20 18:22:52 +08:00
										 |  |  |     : public ObjectBase | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |     , protected IntrusiveListValue<ComponentPtr> | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     friend class Actor; | 
					
						
							|  |  |  |     friend IntrusiveList<ComponentPtr>; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |     /// @brief 是否启用组件
 | 
					
						
							|  |  |  |     bool IsEnable() const; | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |     /// @brief 设置组件启用或禁用
 | 
					
						
							|  |  |  |     void SetEnabled(bool enabled); | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 获取绑定的角色
 | 
					
						
							|  |  |  |     Actor* GetBoundActor() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 从角色中移除
 | 
					
						
							|  |  |  |     void RemoveFromActor(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | protected: | 
					
						
							|  |  |  |     Component(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual ~Component(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 初始化组件
 | 
					
						
							|  |  |  |     virtual void InitComponent(Actor* actor); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 销毁组件
 | 
					
						
							|  |  |  |     virtual void DestroyComponent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 更新组件
 | 
					
						
							|  |  |  |     virtual void OnUpdate(Duration dt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 14:56:14 +08:00
										 |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 渲染组件
 | 
					
						
							|  |  |  |     virtual void OnRender(RenderContext& ctx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |     /// \~chinese
 | 
					
						
							|  |  |  |     /// @brief 处理角色事件
 | 
					
						
							|  |  |  |     virtual void HandleEvent(Event* evt); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  | private: | 
					
						
							|  |  |  |     bool   enabled_; | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |     Actor* actor_; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  | inline bool Component::IsEnable() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return enabled_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline void Component::SetEnabled(bool enabled) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     enabled_ = enabled; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | inline Actor* Component::GetBoundActor() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return actor_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  | inline void Component::OnUpdate(Duration dt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     KGE_NOT_USED(dt); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 14:56:14 +08:00
										 |  |  | inline void Component::OnRender(RenderContext& ctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     KGE_NOT_USED(ctx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline void Component::HandleEvent(Event* evt) | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-23 14:56:14 +08:00
										 |  |  |     KGE_NOT_USED(evt); | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace kiwano
 |