Files
NazaraEngine/SDK/include/NDK/BaseComponent.hpp
Gawaboumga 9eba331f34 Documentation for module 'NDK'
Former-commit-id: 63e1cac538c577a1f1aafa71fa7eef69a6d4daab [formerly b2d8769fd02a0e7d9c476d4ad7be1988a1fd6789] [formerly 636b5cb79bcb8da44d9aa45ba1023565bcf29f0d [formerly a2361ec2b8679d4d4ba096e543b5d4b91825dd62]]
Former-commit-id: d402d35477f9db0135c553d55c401939426bf62d [formerly 607336ea0f42731e4604f3a8c2df06f3aecfc401]
Former-commit-id: 69e23cd6c06723486de5e4641ce810012dac66da
2016-08-21 13:48:52 +02:00

70 lines
1.6 KiB
C++

// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_BASECOMPONENT_HPP
#define NDK_BASECOMPONENT_HPP
#include <NDK/Entity.hpp>
#include <functional>
#include <unordered_map>
#include <vector>
namespace Ndk
{
class NDK_API BaseComponent
{
friend Entity;
friend class Sdk;
public:
using Factory = std::function<BaseComponent*()>;
BaseComponent(ComponentIndex componentIndex);
BaseComponent(const BaseComponent&) = default;
BaseComponent(BaseComponent&&) = default;
virtual ~BaseComponent();
virtual std::unique_ptr<BaseComponent> Clone() const = 0;
ComponentIndex GetIndex() const;
inline static ComponentIndex GetMaxComponentIndex();
BaseComponent& operator=(const BaseComponent&) = default;
BaseComponent& operator=(BaseComponent&&) = default;
protected:
ComponentIndex m_componentIndex;
EntityHandle m_entity;
static ComponentIndex RegisterComponent(ComponentId id, Factory factoryFunc);
private:
virtual void OnAttached();
virtual void OnComponentAttached(BaseComponent& component);
virtual void OnComponentDetached(BaseComponent& component);
virtual void OnDetached();
void SetEntity(Entity* entity);
static bool Initialize();
static void Uninitialize();
struct ComponentEntry
{
ComponentId id;
Factory factory;
};
static std::vector<ComponentEntry> s_entries;
static std::unordered_map<ComponentId, ComponentIndex> s_idToIndex;
};
}
#include <NDK/BaseComponent.inl>
#endif // NDK_BASECOMPONENT_HPP