Remade component ids
No longer based on incrementing counter Former-commit-id: b875e17781d8bcda48ea9ada523adf0823b22a8b
This commit is contained in:
27
SDK/include/NDK/Algorithm.inl
Normal file
27
SDK/include/NDK/Algorithm.inl
Normal file
@@ -0,0 +1,27 @@
|
||||
// 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 (&id)[N])
|
||||
{
|
||||
static_assert(N-1 <= sizeof(ComponentId), "ID too long for this size of component id");
|
||||
|
||||
ComponentId componentId = 0;
|
||||
for (int i = 0; i < N; ++i)
|
||||
componentId |= static_cast<ComponentId>(id[i]) << i*8;
|
||||
|
||||
return componentId;
|
||||
}
|
||||
|
||||
template<typename ComponentType>
|
||||
constexpr ComponentId GetComponentId()
|
||||
{
|
||||
return ComponentType::ComponentId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user