Magic_Game/src/kiwano/base/component/ComponentManager.h

106 lines
2.7 KiB
C
Raw Normal View History

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
#include <kiwano/core/IntrusiveList.h>
2020-05-24 20:46:52 +08:00
#include <kiwano/base/component/Component.h>
2020-02-18 12:53:18 +08:00
namespace kiwano
{
2020-04-16 10:06:36 +08:00
/**
* \addtogroup Component
* @{
*/
2020-02-18 12:53:18 +08:00
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3>
typedef UnorderedMap<size_t, ComponentPtr> ComponentMap;
2020-02-18 12:53:18 +08:00
/**
* \~chinese
2020-05-24 20:46:52 +08:00
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-02-18 12:53:18 +08:00
*/
2020-05-24 20:46:52 +08:00
class KGE_API ComponentManager
2020-02-18 12:53:18 +08:00
{
public:
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// @param component <20><><EFBFBD><EFBFBD>
Component* AddComponent(ComponentPtr component);
2020-02-18 12:53:18 +08:00
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
Component* GetComponent(const String& name);
/// \~chinese
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
Component* GetComponent(size_t name_hash);
2020-02-18 12:53:18 +08:00
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ComponentMap& GetAllComponents();
2020-02-18 12:53:18 +08:00
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const ComponentMap& GetAllComponents() const;
2020-02-18 12:53:18 +08:00
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
void RemoveComponent(ComponentPtr component);
2020-02-18 12:53:18 +08:00
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
/// @param name <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void RemoveComponent(const String& name);
/// \~chinese
/// @brief <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD>
/// @param name_hash <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>hashֵ
void RemoveComponent(size_t name_hash);
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void RemoveAllComponents();
/// \~chinese
/// @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2020-05-24 20:46:52 +08:00
void Update(Duration dt);
2020-02-23 14:56:14 +08:00
/// \~chinese
/// @brief <20><>Ⱦ<EFBFBD><C8BE><EFBFBD><EFBFBD>
2020-05-24 20:46:52 +08:00
void Render(RenderContext& ctx);
2020-02-23 14:56:14 +08:00
2020-02-18 12:53:18 +08:00
/// \~chinese
2020-05-24 20:46:52 +08:00
/// @brief <20>ַ<EFBFBD><D6B7>¼<EFBFBD>
void DispatchToComponents(Event* evt);
protected:
ComponentManager(Actor* target);
2020-02-18 12:53:18 +08:00
private:
Actor* target_;
ComponentMap components_;
2020-02-18 12:53:18 +08:00
};
2020-04-16 10:06:36 +08:00
/** @} */
2020-02-18 12:53:18 +08:00
} // namespace kiwano