Files
NazaraEngine/SDK/include/NDK/Algorithm.inl
Lynix 46d125d205 (NDK) Added explicit initialisation
Components and systems just can't be initialized at startup, so we need
some kind of explicit initialisation. I followed the same layout as the
others modules by adding a core class (Ndk::Sdk) which will initialize
components and systems, and Nazara's modules.

This is starting to get serious, I like it.


Former-commit-id: 263500e8d16db70ef7f92047b8a7e3235c08bcd0
2015-04-07 17:39:20 +02:00

48 lines
1.2 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 <Nazara/Core/Endianness.hpp>
namespace Ndk
{
///TODO: constexpr avec le C++14
template<unsigned int N>
ComponentId BuildComponentId(const char (&name)[N])
{
static_assert(N-1 <= sizeof(ComponentId), "Name too long for this size of component id");
ComponentId componentId = 0;
for (int i = 0; i < N; ++i)
componentId |= static_cast<ComponentId>(name[i]) << i*8;
return componentId;
}
template<typename ComponentType>
constexpr ComponentIndex GetComponentIndex()
{
return ComponentType::componentIndex;
}
template<typename SystemType>
constexpr SystemIndex GetSystemIndex()
{
return SystemType::systemIndex;
}
template<typename ComponentType, unsigned int N>
ComponentIndex InitializeComponent(const char (&name)[N])
{
ComponentType::componentIndex = ComponentType::RegisterComponent(name);
return ComponentType::componentIndex;
}
template<typename SystemType>
SystemIndex InitializeSystem()
{
SystemType::systemIndex = SystemType::RegisterSystem();
return SystemType::systemIndex;
}
}