<commit_before>// Copyright (C) 2013 <NAME>
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp

#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>
#include <Nazara/Utility/Loaders/MD5Anim.hpp>
#include <Nazara/Utility/Loaders/MD5Mesh.hpp>
#include <Nazara/Utility/Loaders/PCX.hpp>
#include <Nazara/Utility/Loaders/STB.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Utility/Debug.hpp>

bool NzUtility::Initialize()
{
	if (s_moduleReferenceCounter++ != 0)
		return true; // Déjà initialisé

	// Initialisation des dépendances
	if (!NzCore::Initialize())
	{
		NazaraError("Failed to initialize core module");
		Uninitialize();

		return false;
	}

	// 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");
		Uninitialize();

		return false;
	}

	if (!NzPixelFormat::Initialize())
	{
		NazaraError("Failed to initialize pixel formats");
		Uninitialize();

		return false;
	}

	if (!NzWindow::Initialize())
	{
		NazaraError("Failed to initialize window's system");
		Uninitialize();

		return false;
	}

	// On enregistre les loaders pour les extensions
	// Il s'agit ici d'une liste LIFO, le dernier loader enregistré possède la priorité

	/// Loaders génériques
	// Image
	NzLoaders_STB_Register(); // Loader générique (STB)

	/// Loaders spécialisés
	// Mesh
	NzLoaders_MD2_Register(); // Loader de fichiers .md2 (v8)
	NzLoaders_MD5Anim_Register(); // Loader de fichiers .md5anim (v10)
	NzLoaders_MD5Mesh_Register(); // Loader de fichiers .md5mesh (v10)

	// Image
	NzLoaders_PCX_Register(); // Loader de fichiers .pcx (1, 4, 8, 24 bits)

	NazaraNotice("Initialized: Utility module");

	return true;
}

bool NzUtility::IsInitialized()
{
	return s_moduleReferenceCounter != 0;
}

void NzUtility::Uninitialize()
{
	if (s_moduleReferenceCounter != 1)
	{
		// Le module est soit encore utilisé, soit pas initialisé
		if (s_moduleReferenceCounter > 1)
			s_moduleReferenceCounter--;

		return;
	}

	// Libération du module
	s_moduleReferenceCounter = 0;

	NzLoaders_MD2_Unregister();
	NzLoaders_MD5Mesh_Unregister();
	NzLoaders_PCX_Unregister();
	NzLoaders_STB_Unregister();

	NzWindow::Uninitialize();
	NzPixelFormat::Uninitialize();
	NzBuffer::Uninitialize();

	NazaraNotice("Uninitialized: Utility module");

	// Libération des dépendances
	NzCore::Uninitialize();
}

unsigned int NzUtility::s_moduleReferenceCounter = 0;
<commit_msg>Fixed MD5Anim loaders not being unregistred<commit_after>// Copyright (C) 2013 <NAME>
// This file is part of the "Nazara Engine - Utility module"
// For conditions of distribution and use, see copyright notice in Config.hpp

#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>
#include <Nazara/Utility/Loaders/MD5Anim.hpp>
#include <Nazara/Utility/Loaders/MD5Mesh.hpp>
#include <Nazara/Utility/Loaders/PCX.hpp>
#include <Nazara/Utility/Loaders/STB.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Utility/Debug.hpp>

bool NzUtility::Initialize()
{
	if (s_moduleReferenceCounter++ != 0)
		return true; // Déjà initialisé

	// Initialisation des dépendances
	if (!NzCore::Initialize())
	{
		NazaraError("Failed to initialize core module");
		Uninitialize();

		return false;
	}

	// 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");
		Uninitialize();

		return false;
	}

	if (!NzPixelFormat::Initialize())
	{
		NazaraError("Failed to initialize pixel formats");
		Uninitialize();

		return false;
	}

	if (!NzWindow::Initialize())
	{
		NazaraError("Failed to initialize window's system");
		Uninitialize();

		return false;
	}

	// On enregistre les loaders pour les extensions
	// Il s'agit ici d'une liste LIFO, le dernier loader enregistré possède la priorité

	/// Loaders génériques
	// Image
	NzLoaders_STB_Register(); // Loader générique (STB)

	/// Loaders spécialisés
	// Animation
	NzLoaders_MD5Anim_Register(); // Loader de fichiers .md5anim (v10)

	// Mesh
	NzLoaders_MD2_Register(); // Loader de fichiers .md2 (v8)
	NzLoaders_MD5Mesh_Register(); // Loader de fichiers .md5mesh (v10)

	// Image
	NzLoaders_PCX_Register(); // Loader de fichiers .pcx (1, 4, 8, 24 bits)

	NazaraNotice("Initialized: Utility module");

	return true;
}

bool NzUtility::IsInitialized()
{
	return s_moduleReferenceCounter != 0;
}

void NzUtility::Uninitialize()
{
	if (s_moduleReferenceCounter != 1)
	{
		// Le module est soit encore utilisé, soit pas initialisé
		if (s_moduleReferenceCounter > 1)
			s_moduleReferenceCounter--;

		return;
	}

	// Libération du module
	s_moduleReferenceCounter = 0;

	NzLoaders_MD2_Unregister();
	NzLoaders_MD5Anim_Unregister();
	NzLoaders_MD5Mesh_Unregister();
	NzLoaders_PCX_Unregister();
	NzLoaders_STB_Unregister();

	NzWindow::Uninitialize();
	NzPixelFormat::Uninitialize();
	NzBuffer::Uninitialize();

	NazaraNotice("Uninitialized: Utility module");

	// Libération des dépendances
	NzCore::Uninitialize();
}

unsigned int NzUtility::s_moduleReferenceCounter = 0;

{'fraction_non_alphanumeric': 0.12603511096389533, 'fraction_numerical': 0.010599536270288175, 'mean_word_length': 4.909001956947162, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196562', 'n_tokens_mistral': 2256, 'n_tokens_neox': 2185, 'n_words': 479}