(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
This commit is contained in:
@@ -14,6 +14,8 @@ namespace Ndk
|
||||
template<unsigned int N> ComponentId BuildComponentId(const char (&name)[N]);
|
||||
template<typename ComponentType> constexpr ComponentIndex GetComponentIndex();
|
||||
template<typename SystemType> constexpr SystemIndex GetSystemIndex();
|
||||
template<typename ComponentType, unsigned int N> ComponentIndex InitializeComponent(const char (&name)[N]);
|
||||
template<typename SystemType> SystemIndex InitializeSystem();
|
||||
}
|
||||
|
||||
#include <Ndk/Algorithm.inl>
|
||||
|
||||
@@ -30,4 +30,18 @@ namespace Ndk
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Ndk
|
||||
{
|
||||
class NDK_API BaseComponent
|
||||
{
|
||||
friend class Sdk;
|
||||
|
||||
public:
|
||||
using Factory = std::function<BaseComponent*()>;
|
||||
|
||||
@@ -32,6 +34,9 @@ namespace Ndk
|
||||
static ComponentIndex RegisterComponent(ComponentId id, Factory factoryFunc);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
struct ComponentEntry
|
||||
{
|
||||
ComponentId id;
|
||||
|
||||
@@ -34,4 +34,16 @@ namespace Ndk
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
inline bool BaseComponent::Initialize()
|
||||
{
|
||||
// Rien à faire
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void BaseComponent::Uninitialize()
|
||||
{
|
||||
s_entries.clear();
|
||||
s_idToIndex.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace Ndk
|
||||
|
||||
class NDK_API BaseSystem
|
||||
{
|
||||
friend class Entity;
|
||||
friend class Sdk;
|
||||
friend Entity;
|
||||
friend World;
|
||||
|
||||
public:
|
||||
@@ -55,6 +56,9 @@ namespace Ndk
|
||||
|
||||
void SetWorld(World& world);
|
||||
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
std::vector<EntityHandle> m_entities;
|
||||
NzBitset<nzUInt64> m_entityBits;
|
||||
NzBitset<> m_excludedComponents;
|
||||
|
||||
@@ -113,4 +113,17 @@ namespace Ndk
|
||||
{
|
||||
m_world = &world;
|
||||
}
|
||||
|
||||
inline bool BaseSystem::Initialize()
|
||||
{
|
||||
s_nextIndex = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void BaseSystem::Uninitialize()
|
||||
{
|
||||
// Rien à faire
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
31
SDK/include/NDK/Sdk.hpp
Normal file
31
SDK/include/NDK/Sdk.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// 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_SDK_HPP
|
||||
#define NDK_SDK_HPP
|
||||
|
||||
#include <NDK/Prerequesites.hpp>
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
class NDK_API Sdk
|
||||
{
|
||||
public:
|
||||
Sdk() = delete;
|
||||
~Sdk() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
static bool IsInitialized();
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_referenceCounter;
|
||||
};
|
||||
}
|
||||
|
||||
#include <NDK/Sdk.inl>
|
||||
|
||||
#endif // NDK_SDK_HPP
|
||||
11
SDK/include/NDK/Sdk.inl
Normal file
11
SDK/include/NDK/Sdk.inl
Normal file
@@ -0,0 +1,11 @@
|
||||
// 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
|
||||
|
||||
namespace Ndk
|
||||
{
|
||||
inline bool Sdk::IsInitialized()
|
||||
{
|
||||
return s_referenceCounter != 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user