| 
									
										
										
										
											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-05-24 11:26:21 +08:00
										 |  |  |  | #include <kiwano/base/ObjectBase.h>
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  | #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); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-16 10:06:36 +08:00
										 |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \~chinese | 
					
						
							|  |  |  |  |  * \defgroup Component <EFBFBD><EFBFBD><EFBFBD><EFBFBD> | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \addtogroup Component | 
					
						
							|  |  |  |  |  * @{ | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  | /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  | /// @brief <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  | typedef IntrusiveList<ComponentPtr> ComponentList; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \~chinese | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |  * @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD> | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  |  */ | 
					
						
							|  |  |  |  | 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-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     bool IsEnable() const; | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     void SetEnabled(bool enabled); | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><>ȡ<EFBFBD>Ľ<F3B6A8B5>ɫ
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  |     Actor* GetBoundActor() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20>ӽ<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>Ƴ<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     void RemoveFromActor(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  | protected: | 
					
						
							|  |  |  |  |     Component(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     virtual ~Component(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     virtual void InitComponent(Actor* actor); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     virtual void DestroyComponent(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-19 11:50:05 +08:00
										 |  |  |  |     virtual void OnUpdate(Duration dt); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 14:56:14 +08:00
										 |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-23 14:56:14 +08:00
										 |  |  |  |     virtual void OnRender(RenderContext& ctx); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  |     /// \~chinese
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:28:50 +08:00
										 |  |  |  |     /// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD>¼<EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2020-02-18 12:53:18 +08:00
										 |  |  |  |     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-04-16 10:06:36 +08:00
										 |  |  |  | /** @} */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
 |