X::Initialize no longer takes arguments
Former-commit-id: a8233235e89112630f2d31c637723443bd0829a4
This commit is contained in:
parent
d8c5f4a0fd
commit
8694f71c2a
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzCore
|
|||
NzCore() = delete;
|
||||
~NzCore() = delete;
|
||||
|
||||
static bool Initialize(bool initializeHardwareInfo = false, bool initializeTaskScheduler = false);
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ class NAZARA_API NzTaskScheduler
|
|||
template<typename F, typename... Args> static void AddTask(F function, Args... args);
|
||||
template<typename C> static void AddTask(void (C::*function)(), C* object);
|
||||
static unsigned int GetWorkerCount();
|
||||
static bool Initialize(unsigned int workerCount = NzThread::HardwareConcurrency());
|
||||
static bool Initialize();
|
||||
static void SetWorkerCount(unsigned int workerCount);
|
||||
static void Uninitialize();
|
||||
static void WaitForTasks();
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ class NAZARA_API NzRenderer
|
|||
|
||||
static bool HasCapability(nzRendererCap capability);
|
||||
|
||||
static bool Initialize(bool initializeDebugDrawer = false);
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsEnabled(nzRendererParameter parameter);
|
||||
static bool IsInitialized();
|
||||
|
|
|
|||
|
|
@ -10,24 +10,9 @@
|
|||
#include <Nazara/Core/TaskScheduler.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
bool NzCore::Initialize(bool initializeHardwareInfo, bool initializeTaskScheduler)
|
||||
bool NzCore::Initialize()
|
||||
{
|
||||
s_moduleReferenceCounter++;
|
||||
|
||||
// Initialisation du module
|
||||
if (initializeHardwareInfo && !NzHardwareInfo::Initialize())
|
||||
NazaraWarning("Failed to initialize hardware info"); // Non-critique
|
||||
|
||||
if (initializeTaskScheduler && !NzTaskScheduler::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize task scheduler");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Vérification après l'initialisation des sous-modules
|
||||
if (s_moduleReferenceCounter != 1)
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
NazaraNotice("Initialized: Core");
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ NzString NzHardwareInfo::GetProcessorBrandString()
|
|||
|
||||
unsigned int NzHardwareInfo::GetProcessorCount()
|
||||
{
|
||||
///DOC: Ne nécessite pas l'initialisation de HardwareInfo pour fonctionner
|
||||
static unsigned int processorCount = std::max(NzHardwareInfoImpl::GetProcessorCount(), 1U);
|
||||
return processorCount;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Core/TaskScheduler.hpp>
|
||||
#include <Nazara/Core/ConditionVariable.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/LockGuard.hpp>
|
||||
#include <Nazara/Core/Mutex.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
|
|
@ -19,7 +20,7 @@ namespace
|
|||
struct TaskSchedulerImpl
|
||||
{
|
||||
std::queue<NzFunctor*> tasks;
|
||||
std::vector<NzThread*> workers;
|
||||
std::vector<NzThread> workers;
|
||||
NzConditionVariable waiterConditionVariable;
|
||||
NzConditionVariable workerConditionVariable;
|
||||
NzMutex taskMutex;
|
||||
|
|
@ -31,6 +32,7 @@ namespace
|
|||
};
|
||||
|
||||
TaskSchedulerImpl* s_impl = nullptr;
|
||||
unsigned int s_workerCount = 0;
|
||||
|
||||
void WorkerFunc()
|
||||
{
|
||||
|
|
@ -84,31 +86,41 @@ namespace
|
|||
|
||||
unsigned int NzTaskScheduler::GetWorkerCount()
|
||||
{
|
||||
#ifdef NAZARA_CORE_SAFE
|
||||
if (!s_impl)
|
||||
{
|
||||
NazaraError("Task scheduler is not initialized");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return s_impl->workers.size();
|
||||
return (s_workerCount > 0) ? s_workerCount : NzHardwareInfo::GetProcessorCount();
|
||||
}
|
||||
|
||||
bool NzTaskScheduler::Initialize(unsigned int workerCount)
|
||||
bool NzTaskScheduler::Initialize()
|
||||
{
|
||||
if (s_impl)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
s_impl = new TaskSchedulerImpl;
|
||||
s_impl->workers.reserve(workerCount);
|
||||
|
||||
unsigned int workerCount = GetWorkerCount();
|
||||
|
||||
s_impl->workers.resize(workerCount);
|
||||
for (unsigned int i = 0; i < workerCount; ++i)
|
||||
s_impl->workers.push_back(new NzThread(WorkerFunc));
|
||||
s_impl->workers[i] = NzThread(WorkerFunc);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NzTaskScheduler::SetWorkerCount(unsigned int workerCount)
|
||||
{
|
||||
s_workerCount = workerCount;
|
||||
if (s_impl)
|
||||
{
|
||||
unsigned int newWorkerCount = GetWorkerCount();
|
||||
unsigned int oldWorkerCount = s_impl->workers.size();
|
||||
s_impl->workers.resize(newWorkerCount);
|
||||
if (newWorkerCount > oldWorkerCount)
|
||||
{
|
||||
for (unsigned int i = oldWorkerCount-1; i < newWorkerCount; ++i)
|
||||
s_impl->workers[i] = NzThread(WorkerFunc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NzTaskScheduler::Uninitialize()
|
||||
{
|
||||
if (s_impl)
|
||||
|
|
@ -130,11 +142,8 @@ void NzTaskScheduler::Uninitialize()
|
|||
s_impl->workerConditionVariable.SignalAll();
|
||||
s_impl->workerConditionVariableMutex.Unlock();
|
||||
|
||||
for (NzThread* thread : s_impl->workers)
|
||||
{
|
||||
thread->Join();
|
||||
delete thread;
|
||||
}
|
||||
for (NzThread& thread : s_impl->workers)
|
||||
thread.Join();
|
||||
|
||||
delete s_impl;
|
||||
s_impl = nullptr;
|
||||
|
|
|
|||
|
|
@ -616,15 +616,10 @@ bool NzRenderer::HasCapability(nzRendererCap capability)
|
|||
return s_capabilities[capability];
|
||||
}
|
||||
|
||||
bool NzRenderer::Initialize(bool initializeDebugDrawer)
|
||||
bool NzRenderer::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCounter++ != 0)
|
||||
{
|
||||
if (initializeDebugDrawer && !NzDebugDrawer::Initialize())
|
||||
NazaraWarning("Failed to initialize debug drawer"); // Non-critique
|
||||
|
||||
return true; // Déjà initialisé
|
||||
}
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzUtility::Initialize())
|
||||
|
|
@ -761,9 +756,6 @@ bool NzRenderer::Initialize(bool initializeDebugDrawer)
|
|||
s_quadBuffer = new NzVertexBuffer(declaration.get(), 4, nzBufferStorage_Hardware, nzBufferUsage_Dynamic);
|
||||
declaration.release();
|
||||
|
||||
if (initializeDebugDrawer && !NzDebugDrawer::Initialize())
|
||||
NazaraWarning("Failed to initialize debug drawer"); // Non-critique
|
||||
|
||||
if (!NzShaderBuilder::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize shader builder");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@
|
|||
#include <Nazara/Utility/Utility.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Core/Thread.hpp>
|
||||
#include <Nazara/Utility/Buffer.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Loaders/MD2.hpp>
|
||||
|
|
@ -23,11 +25,7 @@ bool NzUtility::Initialize()
|
|||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation des dépendances
|
||||
#if NAZARA_UTILITY_MULTITHREADED_SKINNING
|
||||
if (!NzCore::Initialize(false, true))
|
||||
#else
|
||||
if (!NzCore::Initialize())
|
||||
#endif
|
||||
{
|
||||
NazaraError("Failed to initialize core module");
|
||||
Uninitialize();
|
||||
|
|
@ -36,6 +34,16 @@ bool NzUtility::Initialize()
|
|||
}
|
||||
|
||||
// Initialisation du module
|
||||
#if NAZARA_UTILITY_MULTITHREADED_SKINNING
|
||||
if (!NzTaskScheduler::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize task scheduler");
|
||||
Uninitialize();
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!NzBuffer::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize buffers");
|
||||
|
|
|
|||
Loading…
Reference in New Issue