Files
NazaraEngine/SDK/include/NDK/BaseComponent.inl
Lynix c528640d80 Fix a shitload of warnings in 64 bits mode
Former-commit-id: 5bc0c622c20eae45df51bb1ee62e5ed566e58a1b [formerly a8befbed30cb897ce876fd3b46a3585e1b70613e]
Former-commit-id: 999225e414c0d6a3e9c6868f040b68045b2ba724
2016-06-13 21:09:55 +02:00

70 lines
1.5 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
#include <NDK/BaseComponent.hpp>
#include <Nazara/Core/Error.hpp>
namespace Ndk
{
inline BaseComponent::BaseComponent(ComponentIndex index) :
m_componentIndex(index),
m_entity(nullptr)
{
}
inline ComponentIndex BaseComponent::GetIndex() const
{
return m_componentIndex;
}
inline ComponentIndex BaseComponent::GetMaxComponentIndex()
{
return static_cast<ComponentIndex>(s_entries.size());
}
inline ComponentIndex BaseComponent::RegisterComponent(ComponentId id, Factory factoryFunc)
{
// Nous allons rajouter notre composant à la fin
ComponentIndex index = static_cast<ComponentIndex>(s_entries.size());
s_entries.resize(index + 1);
// On récupère et on affecte
ComponentEntry& entry = s_entries.back();
entry.factory = factoryFunc;
entry.id = id;
// Une petite assertion pour s'assurer que l'identifiant n'est pas déjà utilisé
NazaraAssert(s_idToIndex.find(id) == s_idToIndex.end(), "This id is already in use");
s_idToIndex[id] = index;
return index;
}
inline void BaseComponent::SetEntity(Entity* entity)
{
if (m_entity != entity)
{
if (m_entity)
OnDetached();
m_entity = entity;
if (m_entity)
OnAttached();
}
}
inline bool BaseComponent::Initialize()
{
// Rien à faire
return true;
}
inline void BaseComponent::Uninitialize()
{
s_entries.clear();
s_idToIndex.clear();
}
}