First commit

This commit is contained in:
Lynix
2012-05-01 16:43:48 +02:00
commit 71b4262c51
208 changed files with 46084 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_AUDIO_HPP
#define NAZARA_CONFIG_AUDIO_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_AUDIO_MEMORYLEAKTRACKER 0
#endif // NAZARA_CONFIG_AUDIOs_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Audio/Config.hpp>
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SOUND_HPP
#define NAZARA_SOUND_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzSound
{
public:
NzSound();
~NzSound();
bool LoadFromFile(const NzString& filePath);
bool LoadFromMemory(const nzUInt8* ptr, std::size_t size);
private:
};
#endif // NAZARA_SOUND_HPP

View File

@@ -0,0 +1,124 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_BYTEARRAY_HPP
#define NAZARA_BYTEARRAY_HPP
#define NAZARA_BYTEARRAY
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
class NzAbstractHash;
class NzHashDigest;
class NAZARA_API NzByteArray : public NzHashable
{
public:
struct SharedArray;
NzByteArray();
NzByteArray(const nzUInt8* buffer, unsigned int bufferLength);
NzByteArray(const NzByteArray& buffer);
NzByteArray(NzByteArray&& buffer);
NzByteArray(SharedArray* sharedArray);
~NzByteArray();
unsigned int Capacity() const;
void Clear();
const nzUInt8* GetBuffer() const;
unsigned int GetSize() const;
NzByteArray& Insert(int pos, const nzUInt8* buffer, unsigned int bufferLength);
NzByteArray& Insert(int pos, const NzByteArray& byteArray);
bool IsEmpty() const;
void Reserve(unsigned int bufferSize);
NzByteArray& Resize(int size, nzUInt8 byte = '\0');
NzByteArray Resized(int size, nzUInt8 byte = '\0') const;
NzByteArray SubArray(int startPos, int endPos = -1) const;
void Swap(NzByteArray& byteArray);
NzByteArray& Trim(nzUInt8 byte = '\0');
NzByteArray Trimmed(nzUInt8 byte = '\0') const;
// Méthodes compatibles STD
nzUInt8* begin();
const nzUInt8* begin() const;
nzUInt8* end();
const nzUInt8* end() const;
void push_front(nzUInt8 c);
void push_back(nzUInt8 c);
/*nzUInt8* rbegin();
const nzUInt8* rbegin() const;
nzUInt8* rend();
const nzUInt8* rend() const;*/
typedef const nzUInt8& const_reference;
typedef nzUInt8* iterator;
//typedef nzUInt8* reverse_iterator;
typedef nzUInt8 value_type;
// Méthodes compatibles STD
nzUInt8& operator[](unsigned int pos);
nzUInt8 operator[](unsigned int pos) const;
NzByteArray& operator=(const NzByteArray& byteArray);
NzByteArray& operator=(NzByteArray&& byteArray);
NzByteArray operator+(const NzByteArray& byteArray) const;
NzByteArray& operator+=(const NzByteArray& byteArray);
static int Compare(const NzByteArray& first, const NzByteArray& second);
struct NAZARA_API SharedArray
{
SharedArray() :
refCount(1)
{
}
SharedArray(unsigned int bufferSize, unsigned int arraySize, unsigned short referenceCount, nzUInt8* ptr) :
allocatedSize(bufferSize),
size(arraySize),
refCount(referenceCount),
buffer(ptr)
{
}
unsigned int allocatedSize;
unsigned int size;
unsigned short refCount;
nzUInt8* buffer;
NazaraMutex(mutex)
};
static SharedArray emptyArray;
private:
void EnsureOwnership();
bool FillHash(NzHashImpl* hash) const;
void ReleaseArray();
SharedArray* m_sharedArray;
};
namespace std
{
NAZARA_API void swap(NzByteArray& lhs, NzByteArray& rhs);
}
#undef NAZARA_BYTEARRAY
#endif // NAZARA_BYTEARRAY_HPP

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CLOCK_HPP
#define NAZARA_CLOCK_HPP
#define NAZARA_CLOCK
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
class NAZARA_API NzClock
{
public:
NzClock();
float GetSeconds() const;
nzUInt64 GetMicroseconds() const;
nzUInt64 GetMilliseconds() const;
bool IsPaused() const;
void Pause();
void Restart();
void Unpause();
private:
NazaraMutexAttrib(m_mutex, mutable)
nzUInt64 m_elapsedTime;
nzUInt64 m_refTime;
bool m_paused;
};
typedef nzUInt64 (*NzClockFunction)();
extern NAZARA_API NzClockFunction NzGetMicroseconds;
extern NAZARA_API NzClockFunction NzGetMilliseconds;
#undef NAZARA_CLOCK
#endif // NAZARA_CLOCK_HPP

View File

@@ -0,0 +1,79 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_CORE_HPP
#define NAZARA_CONFIG_CORE_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Appelle exit dès qu'une assertion est invalide
#define NAZARA_CORE_EXIT_ON_ASSERT_FAILURE 1
// Teste les assertions
#define NAZARA_CORE_ENABLE_ASSERTS 0
// Taille du buffer lors d'une lecture complète d'un fichier (ex: Hash)
#define NAZARA_CORE_FILE_BUFFERSIZE 4096
// Le moteur doit-il incorporer les Unicode Character Data (Nécessaires pour faire fonctionner le flag NzString::HandleUTF8)
#define NAZARA_CORE_INCLUDE_UNICODEDATA 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_CORE_MEMORYLEAKTRACKER 0
// Standardise les séparateurs des dossiers selon le système d'exploitation courant
#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1
// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule)
#define NAZARA_CORE_REAL_PRECISION 6
// Redirige la sortie du log sur le flux d'erreur standard (cerr) en cas d'erreur d'écriture (ou d'ouverture du fichier)
#define NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE 1
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_CORE_SAFE 1
// Protége le noyau des accès concurrentiels
#define NAZARA_CORE_THREADSAFE 1
#if NAZARA_CORE_THREADSAFE
#define NAZARA_THREADSAFETY_APPLICATION 1 // NzApplication
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib
#define NAZARA_THREADSAFETY_FILE 1 // NzFile
#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest
#define NAZARA_THREADSAFETY_LOG 1 // NzLog
#define NAZARA_THREADSAFETY_STRING 1 // NzString
#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream
#endif
/*
// Règle le temps entre le réveil du thread des timers et l'activation d'un timer (En millisecondes)
#define NAZARA_CORE_TIMER_WAKEUPTIME 10
*/
#endif // NAZARA_CONFIG_CORE_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Config.hpp>
#if NAZARA_CORE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DEBUG_MEMORYLEAKTRACKER_HPP
#define NAZARA_DEBUG_MEMORYLEAKTRACKER_HPP
#define NAZARA_DEBUG_MEMORYLEAKTRACKER
#include <Nazara/Prerequesites.hpp>
#include <cstdio>
#include <cstring>
class NAZARA_API NzMemoryManager
{
public:
NzMemoryManager();
~NzMemoryManager();
static void* Allocate(std::size_t size, bool multi, const char* file = nullptr, unsigned int line = 0);
static void Free(void* pointer, bool multi);
static void NextFree(const char* file, unsigned int line);
private:
static void EnsureInitialization();
static void Initialize();
static char* TimeInfo();
static void Uninitialize();
};
NAZARA_API void* operator new(std::size_t size, const char* file, unsigned int line);
NAZARA_API void* operator new[](std::size_t size, const char* file, unsigned int line);
NAZARA_API void operator delete(void* ptr, const char* file, unsigned int line) throw();
NAZARA_API void operator delete[](void* ptr, const char* file, unsigned int line) throw();
#undef NAZARA_DEBUG_MEMORYLEAKTRACKER
#endif // NAZARA_DEBUG_MEMORYLEAKTRACKER_HPP

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_CORE_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,64 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DIRECTORY_HPP
#define NAZARA_DIRECTORY_HPP
#define NAZARA_DIRECTORY
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
#define NAZARA_DIRECTORY_SEPARATOR '\\'
#elif defined(NAZARA_PLATFORM_LINUX)
#define NAZARA_DIRECTORY_SEPARATOR '/'
#else
#error OS not handled
#define NAZARA_DIRECTORY_SEPARATOR '/'
#endif
class NzDirectoryImpl;
class NAZARA_API NzDirectory
{
public:
NzDirectory();
NzDirectory(const NzString& dirPath);
~NzDirectory();
void Close();
NzString GetResultName() const;
NzString GetResultPath() const;
nzUInt64 GetResultSize() const;
bool IsResultDirectory() const;
bool NextResult(bool skipDots = true);
bool Open();
void SetDirectory(const NzString& dirPath);
static bool Copy(const NzString& sourcePath, const NzString& destPath);
static bool Create(const NzString& dirPath, bool recursive = false);
static bool Exists(const NzString& dirPath);
static NzString GetCurrent();
static bool Remove(const NzString& dirPath, bool emptyDirectory = false);
static bool SetCurrent(const NzString& dirPath);
private:
NazaraMutexAttrib(m_mutex, mutable)
NzString m_dirPath;
NzDirectoryImpl* m_impl;
};
#undef NAZARA_DIRECTORY
#endif // NAZARA_DIRECTORY_HPP

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_DYNLIB_HPP
#define NAZARA_DYNLIB_HPP
#define NAZARA_DYNLIB
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NzDynLibImpl;
typedef int (*NzDynLibFunc)(); // Type "générique" de pointeur sur fonction
class NzDynLib : NzNonCopyable
{
friend class NzDynLibImpl;
public:
NzDynLib(const NzString& libraryPath);
~NzDynLib();
NzString GetLastError() const;
NzDynLibFunc GetSymbol(const NzString& symbol) const;
bool Load();
void Unload();
private:
void SetLastError(const NzString& error);
NazaraMutexAttrib(m_mutex, mutable)
NzString m_lastError;
NzString m_path;
NzDynLibImpl* m_impl;
};
#undef NAZARA_DYNLIB
#endif // NAZARA_DYNLIB_HPP

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENDIANNESS_HPP
#define NAZARA_ENDIANNESS_HPP
#define NAZARA_ENDIANNESS
#include <Nazara/Prerequesites.hpp>
#if defined(NAZARA_ENDIANNESS_BIGENDIAN)
#define NAZARA_ENDIANNESS_DETECTED 1
#define NazaraEndianness nzEndianness_BigEndian
#elif defined(NAZARA_ENDIANNESS_LITTLEENDIAN)
#define NAZARA_ENDIANNESS_DETECTED 1
#define NazaraEndianness nzEndianness_LittleEndian
#else
#if defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || (defined(__MIPS__) && defined(__MISPEB__)) || \
defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || defined(__sparc__) || defined(__hppa__)
#define NAZARA_ENDIANNESS_DETECTED 1
#define NAZARA_ENDIANNESS_BIGENDIAN
#define NazaraEndianness nzEndianness_BigEndian
#elif defined(__i386__) || defined(__i386) || defined(__X86__) || defined (__x86_64)
#define NAZARA_ENDIANNESS_DETECTED 1
#define NAZARA_ENDIANNESS_LITTLEENDIAN
#define NazaraEndianness nzEndianness_LittleEndian
#else
#define NAZARA_ENDIANNESS_DETECTED 0
#define NazaraEndianness NzGetPlatformEndianness()
#endif
#endif
enum nzEndianness
{
nzEndianness_BigEndian,
nzEndianness_LittleEndian,
nzEndianness_Unknown
};
inline void NzByteSwap(void* buffer, unsigned int size);
inline nzEndianness NzGetPlatformEndianness();
#include <Nazara/Core/Endianness.inl>
#undef NAZARA_ENDIANNESS
#endif // NAZARA_ENDIANNESS_HPP

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
inline void NzByteSwap(void* buffer, unsigned int size)
{
nzUInt8* bytes = reinterpret_cast<nzUInt8*>(buffer);
unsigned int i = 0;
unsigned int j = size-1;
while (i < j)
std::swap(bytes[i++], bytes[j--]);
}
inline nzEndianness NzGetPlatformEndianness()
{
#if NAZARA_ENDIANNESS_DETECTED
return NazaraEndianness;
#else
static nzEndianness endianness = nzEndianness_Unknown;
static bool tested = false;
if (!tested)
{
nzUInt32 i = 1;
nzUInt8* p = reinterpret_cast<nzUInt8*>(&i);
// Méthode de récupération de l'endianness au runtime
if (p[0] == 1)
endianness = nzEndianness_LittleEndian;
else if (p[3] == 1)
endianness = nzEndianness_BigEndian;
tested = true;
}
return endianness;
#endif
}

View File

@@ -0,0 +1,39 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ERROR_HPP
#define NAZARA_ERROR_HPP
#define NAZARA_ERROR
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
#define NazaraAssert(a, err) if (!(a)) NzError(nzErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#else
#define NazaraAssert(a, err)
#endif
#define NazaraError(err) NzError(nzErrorType_Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraInternalError(err) NzError(nzErrorType_Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION)
#define NazaraWarning(err) NzError(nzErrorType_Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION)
enum nzErrorType
{
nzErrorType_AssertFailed,
nzErrorType_Internal,
nzErrorType_Normal,
nzErrorType_Warning
};
NAZARA_API void NzError(nzErrorType type, const NzString& error, unsigned int line, const char* file, const char* function);
NAZARA_API unsigned int NzGetLastSystemErrorCode();
NAZARA_API NzString NzGetLastSystemError(unsigned int code = NzGetLastSystemErrorCode());
#undef NAZARA_ERROR
#endif // NAZARA_ERROR_HPP

View File

@@ -0,0 +1,120 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FILE_HPP
#define NAZARA_FILE_HPP
#define NAZARA_FILE
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NzFileImpl;
class NAZARA_API NzFile : public NzHashable, NzNonCopyable
{
public:
enum CursorPosition
{
AtBegin, // Début du fichier
AtCurrent, // Position du pointeur
AtEnd // Fin du fichier
};
enum OpenMode
{
Current = 0x00, // Utilise le mode d'ouverture actuel
Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
ReadOnly = 0x04, // Ouvre uniquement en lecture
ReadWrite = 0x08, // Ouvre en lecture/écriture
Text = 0x10, // Ouvre en mode texte
Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
};
NzFile();
NzFile(const NzString& filePath);
NzFile(const NzString& filePath, unsigned long openMode);
NzFile(NzFile&& file);
~NzFile();
bool Copy(const NzString& newFilePath);
void Close();
bool Delete();
bool EndOfFile() const;
bool Exists() const;
void Flush();
time_t GetCreationTime() const;
nzUInt64 GetCursorPos() const;
NzString GetDirectoryPath() const;
NzString GetFilePath() const;
NzString GetFileName() const;
time_t GetLastAccessTime() const;
time_t GetLastWriteTime() const;
NzString GetLine(unsigned int lineSize = 0);
nzUInt64 GetSize() const;
bool IsOpen() const;
bool Open(unsigned long openMode = Current);
std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count);
bool Rename(const NzString& newFilePath);
bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0);
bool SetCursorPos(nzUInt64 offset);
void SetEndianness(nzEndianness endianness);
bool SetFile(const NzString& filePath);
bool SetOpenMode(unsigned int openMode);
bool Write(const NzString& string);
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count);
NzFile& operator=(const NzString& filePath);
NzFile& operator=(NzFile&& file);
static NzString AbsolutePath(const NzString& filePath);
static bool Copy(const NzString& sourcePath, const NzString& targetPath);
static bool Delete(const NzString& filePath);
static bool Exists(const NzString& filePath);
static time_t GetCreationTime(const NzString& filePath);
static time_t GetLastAccessTime(const NzString& filePath);
static time_t GetLastWriteTime(const NzString& filePath);
static NzHashDigest GetHash(const NzString& filePath, nzHash hash);
static NzHashDigest GetHash(const NzString& filePath, NzHashImpl* hash);
static nzUInt64 GetSize(const NzString& filePath);
static bool IsAbsolute(const NzString& path);
static NzString NormalizePath(const NzString& filePath);
static NzString NormalizeSeparators(const NzString& filePath);
static bool Rename(const NzString& sourcePath, const NzString& targetPath);
private:
bool FillHash(NzHashImpl* hash) const;
NazaraMutexAttrib(m_mutex, mutable)
nzEndianness m_endianness;
NzString m_filePath;
NzFileImpl* m_impl;
unsigned int m_openMode;
};
#undef NAZARA_FILE
#endif // NAZARA_FILE_HPP

View File

@@ -0,0 +1,18 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FORMAT_HPP
#define NAZARA_FORMAT_HPP
#define NAZARA_FORMAT
#include <Nazara/Core/String.hpp>
template<typename... Args> NzString NzFormat(const NzString& str, Args... args);
#undef NAZARA_FORMAT
#endif // NAZARA_FORMAT_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_HPP
#define NAZARA_HASH_HPP
#define NAZARA_HASH
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NAZARA_API NzHash : NzNonCopyable
{
public:
NzHash(nzHash hash);
NzHash(NzHashImpl* hashImpl);
~NzHash();
NzHashDigest Hash(const NzHashable& hashable);
private:
NzHashImpl* m_impl;
};
#undef NAZARA_HASH
#endif // NAZARA_HASH_HPP

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_CRC32_HPP
#define NAZARA_HASH_CRC32_HPP
#define NAZARA_HASH_CRC32
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
struct NzHashCRC32_state;
class NAZARA_API NzHashCRC32 : public NzHashImpl
{
public:
NzHashCRC32(nzUInt32 polynomial = 0x04c11db7);
virtual ~NzHashCRC32();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
NzHashCRC32_state* m_state;
};
#undef NAZARA_HASH_CRC32
#endif // NAZARA_HASH_CRC32_HPP

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_FLETCHER16_HPP
#define NAZARA_HASH_FLETCHER16_HPP
#define NAZARA_HASH_FLETCHER16
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
#include <Nazara/Core/String.hpp>
struct NzHashFletcher16_state;
class NAZARA_API NzHashFletcher16 : public NzHashImpl
{
public:
NzHashFletcher16();
virtual ~NzHashFletcher16();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
NzHashFletcher16_state* m_state;
};
#undef NAZARA_HASH_FLETCHER16
#endif // NAZARA_HASH_FLETCHER16_HPP

View File

@@ -0,0 +1,37 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASH_MD5_HPP
#define NAZARA_HASH_MD5_HPP
#define NAZARA_HASH_MD5
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
struct NzHashMD5_state;
class NAZARA_API NzHashMD5 : public NzHashImpl
{
public:
NzHashMD5();
virtual ~NzHashMD5();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
NzHashMD5_state* m_state;
};
#undef NAZARA_HASH_MD5
#endif // NAZARA_HASH_MD5_HPP

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_HASH_WHIRLPOOL_HPP
#define NAZARA_HASH_WHIRLPOOL_HPP
#define NAZARA_HASH_WHIRLPOOL
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
struct NzHashWhirlpool_state;
class NAZARA_API NzHashWhirlpool : public NzHashImpl
{
public:
NzHashWhirlpool();
virtual ~NzHashWhirlpool();
void Append(const nzUInt8* data, unsigned int len);
void Begin();
NzHashDigest End();
static unsigned int GetDigestLength();
static NzString GetHashName();
private:
NzHashWhirlpool_state* m_state;
};
#undef NAZARA_HASH_WHIRLPOOL
#endif // NAZARA_HASH_WHIRLPOOL_HPP

View File

@@ -0,0 +1,55 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASHDIGEST_HPP
#define NAZARA_HASHDIGEST_HPP
#define NAZARA_HASHDIGEST
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <ostream>
class NAZARA_API NzHashDigest
{
public:
NzHashDigest();
NzHashDigest(NzString hashName, const nzUInt8* digest, unsigned int length);
NzHashDigest(const NzHashDigest& rhs);
NzHashDigest(NzHashDigest&& rhs);
~NzHashDigest();
bool IsValid() const;
const nzUInt8* GetDigest() const;
unsigned int GetDigestLength() const;
NzString GetHashName() const;
NzString ToHex() const;
nzUInt8 operator[](unsigned short pos) const;
NzHashDigest& operator=(const NzHashDigest& rhs);
NzHashDigest& operator=(NzHashDigest&& rhs);
bool operator==(const NzHashDigest& rhs) const;
bool operator!=(const NzHashDigest& rhs) const;
bool operator<(const NzHashDigest& rhs) const;
bool operator<=(const NzHashDigest& rhs) const;
bool operator>(const NzHashDigest& rhs) const;
bool operator>=(const NzHashDigest& rhs) const;
NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzHashDigest& string);
private:
NzString m_hashName;
nzUInt8* m_digest;
unsigned short m_digestLength;
};
#undef NAZARA_HASHDIGEST
#endif // NAZARA_HASHDIGEST_HPP

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_HASHIMPL_HPP
#define NAZARA_HASHIMPL_HPP
#define NAZARA_HASHIMPL
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NzHashDigest;
class NAZARA_API NzHashImpl : NzNonCopyable
{
public:
NzHashImpl() = default;
virtual ~NzHashImpl() {}
virtual void Append(const nzUInt8* data, unsigned int len) = 0;
virtual void Begin() = 0;
virtual NzHashDigest End() = 0;
};
#undef NAZARA_HASHIMPL
#endif // NAZARA_HASHIMPL_HPP

View File

@@ -0,0 +1,39 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef HASHABLE_HPP_INCLUDED
#define HASHABLE_HPP_INCLUDED
#include <Nazara/Prerequesites.hpp>
enum nzHash
{
nzHash_CRC32,
nzHash_Fletcher16,
nzHash_MD5,
nzHash_Whirlpool
};
class NzHash;
class NzHashDigest;
class NzHashImpl;
class NAZARA_API NzHashable
{
friend class NzHash;
public:
NzHashable() = default;
virtual ~NzHashable() {}
NzHashDigest GetHash(nzHash hash) const;
NzHashDigest GetHash(NzHashImpl* impl) const;
private:
virtual bool FillHash(NzHashImpl* impl) const = 0;
};
#endif // HASHABLE_HPP_INCLUDED

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LOCK_HPP
#define NAZARA_LOCK_HPP
#define NAZARA_LOCK
#include <Nazara/Prerequesites.hpp>
class NzMutex;
class NAZARA_API NzLock
{
public:
NzLock(NzMutex& mutex);
~NzLock();
private:
NzMutex& m_mutex;
};
#undef NAZARA_LOCK
#endif // NAZARA_LOCK_HPP

View File

@@ -0,0 +1,55 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_LOG_HPP
#define NAZARA_LOG_HPP
#define NAZARA_LOG
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
#define NazaraLog NzLog::Instance()
class NzFile;
class NAZARA_API NzLog : NzNonCopyable
{
public:
void Enable(bool enable);
void EnableAppend(bool enable);
void EnableDateTime(bool enable);
NzString GetFile() const;
bool IsEnabled() const;
void SetFile(const NzString& filePath);
void Write(const NzString& string);
void WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func);
static NzLog* Instance();
private:
NzLog();
~NzLog();
NazaraMutexAttrib(m_mutex, mutable)
NzString m_filePath;
NzFile* m_file;
bool m_append;
bool m_enabled;
bool m_writeTime;
};
#undef NAZARA_LOGGER
#endif // NAZARA_LOGGER_HPP

View File

@@ -0,0 +1,36 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MUTEX_HPP
#define NAZARA_MUTEX_HPP
#define NAZARA_MUTEX
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NzMutexImpl;
class NzThreadCondition;
class NAZARA_API NzMutex : NzNonCopyable
{
friend class NzThreadCondition;
public:
NzMutex();
~NzMutex();
void Lock();
bool TryLock();
void Unlock();
private:
NzMutexImpl* m_impl;
};
#undef NAZARA_MUTEX
#endif // NAZARA_MUTEX_HPP

View File

@@ -0,0 +1,34 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SEMAPHORE_HPP
#define NAZARA_SEMAPHORE_HPP
#define NAZARA_SEMAPHORE
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NzSemaphoreImpl;
class NAZARA_API NzSemaphore : NzNonCopyable
{
public:
NzSemaphore(unsigned int count);
~NzSemaphore();
unsigned int GetCount() const;
void Post();
void Wait();
bool Wait(nzUInt32 timeout);
private:
NzSemaphoreImpl* m_impl;
};
#undef NAZARA_SEMAPHORE
#endif // NAZARA_SEMAPHORE_HPP

View File

@@ -0,0 +1,323 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_STRING_HPP
#define NAZARA_STRING_HPP
#define NAZARA_STRING
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
#include <istream>
#include <ostream>
#include <string>
#include <vector>
class NzAbstractHash;
class NzHashDigest;
class NAZARA_API NzString : public NzHashable
{
public:
enum Flags
{
None = 0x00, // Mode par défaut
CaseInsensitive = 0x01, // Insensible à la casse
HandleUtf8 = 0x02 // Traite les octets comme une suite de caractères UTF-8
};
struct SharedString;
NzString();
NzString(char character);
NzString(const char* string);
NzString(const std::string& string);
NzString(const NzString& string);
NzString(NzString&& string);
NzString(SharedString* sharedString);
~NzString();
NzString& Append(char character);
NzString& Append(const char* string);
NzString& Append(const NzString& string);
void Clear();
bool Contains(char character, int start = 0, nzUInt32 flags = None) const;
bool Contains(const char* string, int start = 0, nzUInt32 flags = None) const;
bool Contains(const NzString& string, int start = 0, nzUInt32 flags = None) const;
unsigned int Count(char character, int start = 0, nzUInt32 flags = None) const;
unsigned int Count(const char* string, int start = 0, nzUInt32 flags = None) const;
unsigned int Count(const NzString& string, int start = 0, nzUInt32 flags = None) const;
unsigned int CountAny(const char* string, int start = 0, nzUInt32 flags = None) const;
unsigned int CountAny(const NzString& string, int start = 0, nzUInt32 flags = None) const;
bool EndsWith(char character, nzUInt32 flags = None) const;
bool EndsWith(const char* string, nzUInt32 flags = None) const;
bool EndsWith(const NzString& string, nzUInt32 flags = None) const;
unsigned int Find(char character, int start = 0, nzUInt32 flags = None) const;
unsigned int Find(const char* string, int start = 0, nzUInt32 flags = None) const;
unsigned int Find(const NzString& string, int start = 0, nzUInt32 flags = None) const;
unsigned int FindAny(const char* string, int start = 0, nzUInt32 flags = None) const;
unsigned int FindAny(const NzString& string, int start = 0, nzUInt32 flags = None) const;
unsigned int FindLast(char character, int start = -1, nzUInt32 flags = None) const;
unsigned int FindLast(const char *string, int start = -1, nzUInt32 flags = None) const;
unsigned int FindLast(const NzString& string, int start = -1, nzUInt32 flags = None) const;
unsigned int FindLastAny(const char* string, int start = -1, nzUInt32 flags = None) const;
unsigned int FindLastAny(const NzString& string, int start = -1, nzUInt32 flags = None) const;
unsigned int FindLastWord(const char* string, int start = -1, nzUInt32 flags = None) const;
unsigned int FindLastWord(const NzString& string, int start = -1, nzUInt32 flags = None) const;
unsigned int FindWord(const char* string, int start = 0, nzUInt32 flags = None) const;
unsigned int FindWord(const NzString& string, int start = 0, nzUInt32 flags = None) const;
char* GetBuffer();
unsigned int GetCapacity() const;
const char* GetConstBuffer() const;
unsigned int GetLength() const;
unsigned int GetSize() const;
char* GetUtf8Buffer(unsigned int* size = nullptr) const;
char16_t* GetUtf16Buffer(unsigned int* size = nullptr) const;
char32_t* GetUtf32Buffer(unsigned int* size = nullptr) const;
wchar_t* GetWideBuffer(unsigned int* size = nullptr) const;
NzString GetWord(unsigned int index, nzUInt32 flags = None) const;
unsigned int GetWordPosition(unsigned int index, nzUInt32 flags = None) const;
NzString& Insert(int pos, char character);
NzString& Insert(int pos, const char* string);
NzString& Insert(int pos, const NzString& string);
bool IsEmpty() const;
bool IsNull() const;
bool IsNumber(nzUInt8 radix = 10, nzUInt32 flags = CaseInsensitive) const;
bool Match(const char* pattern) const;
bool Match(const NzString& pattern) const;
NzString& Prepend(char character);
NzString& Prepend(const char* string);
NzString& Prepend(const NzString& string);
unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
void Reserve(unsigned int bufferSize);
NzString& Resize(int size, char character = ' ');
NzString Resized(int size, char character = ' ') const;
NzString& Reverse();
NzString Reversed() const;
NzString Simplified(nzUInt32 flags = None) const;
NzString& Simplify(nzUInt32 flags = None);
unsigned int Split(std::vector<NzString>& result, char separation = ' ', int start = 0, nzUInt32 flags = None) const;
unsigned int Split(std::vector<NzString>& result, const char* separation, int start = 0, nzUInt32 flags = None) const;
unsigned int Split(std::vector<NzString>& result, const NzString& separation, int start = 0, nzUInt32 flags = None) const;
unsigned int SplitAny(std::vector<NzString>& result, const char* separations, int start = 0, nzUInt32 flags = None) const;
unsigned int SplitAny(std::vector<NzString>& result, const NzString& separations, int start = 0, nzUInt32 flags = None) const;
bool StartsWith(char character, nzUInt32 flags = None) const;
bool StartsWith(const char* string, nzUInt32 flags = None) const;
bool StartsWith(const NzString& string, nzUInt32 flags = None) const;
NzString Substr(int startPos, int endPos = -1) const;
NzString SubstrFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrFrom(const NzString& string, int startPos = 0, bool fromLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrTo(char character, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
NzString SubstrTo(const NzString& string, int startPos = 0, bool toLast = false, bool include = false, nzUInt32 flags = None) const;
void Swap(NzString& str);
bool ToBool(bool* value, nzUInt32 flags = None) const;
bool ToDouble(double* value) const;
bool ToInteger(long long* value, nzUInt8 radix = 10) const;
NzString ToLower(nzUInt32 flags = None) const;
NzString ToUpper(nzUInt32 flags = None) const;
NzString& Trim(nzUInt32 flags = None);
NzString& Trim(char character, nzUInt32 flags = None);
NzString Trimmed(nzUInt32 flags = None) const;
NzString Trimmed(char character, nzUInt32 flags = None) const;
// Méthodes compatibles STD
char* begin();
const char* begin() const;
char* end();
const char* end() const;
void push_front(char c);
void push_back(char c);
/*char* rbegin();
const char* rbegin() const;
char* rend();
const char* rend() const;*/
typedef const char& const_reference;
typedef char* iterator;
//typedef char* reverse_iterator;
typedef char value_type;
// Méthodes compatibles STD
operator std::string() const;
char& operator[](unsigned int pos);
char operator[](unsigned int pos) const;
NzString& operator=(char character);
NzString& operator=(const char* string);
NzString& operator=(const std::string& string);
NzString& operator=(const NzString& string);
NzString& operator=(NzString&& string);
NzString operator+(char character) const;
NzString operator+(const char* string) const;
NzString operator+(const std::string& string) const;
NzString operator+(const NzString& string) const;
NzString& operator+=(char character);
NzString& operator+=(const char* string);
NzString& operator+=(const std::string& string);
NzString& operator+=(const NzString& string);
bool operator==(char character) const;
bool operator==(const char* string) const;
bool operator==(const std::string& string) const;
bool operator!=(char character) const;
bool operator!=(const char* string) const;
bool operator!=(const std::string& string) const;
bool operator<(char character) const;
bool operator<(const char* string) const;
bool operator<(const std::string& string) const;
bool operator<=(char character) const;
bool operator<=(const char* string) const;
bool operator<=(const std::string& string) const;
bool operator>(char character) const;
bool operator>(const char* string) const;
bool operator>(const std::string& string) const;
bool operator>=(char character) const;
bool operator>=(const char* string) const;
bool operator>=(const std::string& string) const;
static NzString Boolean(bool boolean);
static int Compare(const NzString& first, const NzString& second);
static NzString Number(float number);
static NzString Number(double number);
static NzString Number(long double number);
static NzString Number(signed char number, nzUInt8 radix = 10);
static NzString Number(unsigned char number, nzUInt8 radix = 10);
static NzString Number(short number, nzUInt8 radix = 10);
static NzString Number(unsigned short number, nzUInt8 radix = 10);
static NzString Number(int number, nzUInt8 radix = 10);
static NzString Number(unsigned int number, nzUInt8 radix = 10);
static NzString Number(long number, nzUInt8 radix = 10);
static NzString Number(unsigned long number, nzUInt8 radix = 10);
static NzString Number(long long number, nzUInt8 radix = 10);
static NzString Number(unsigned long long number, nzUInt8 radix = 10);
static NzString Pointer(const void* ptr);
static NzString Unicode(char32_t character);
static NzString Unicode(const char* u8String);
static NzString Unicode(const char16_t* u16String);
static NzString Unicode(const char32_t* u32String);
static NzString Unicode(const wchar_t* wString);
NAZARA_API friend std::istream& operator>>(std::istream& in, NzString& string);
NAZARA_API friend std::ostream& operator<<(std::ostream& out, const NzString& string);
NAZARA_API friend NzString operator+(char character, const NzString& string);
NAZARA_API friend NzString operator+(const char* string, const NzString& nstring);
NAZARA_API friend NzString operator+(const std::string& string, const NzString& nstring);
NAZARA_API friend bool operator==(const NzString& first, const NzString& second);
NAZARA_API friend bool operator!=(const NzString& first, const NzString& second);
NAZARA_API friend bool operator<(const NzString& first, const NzString& second);
NAZARA_API friend bool operator<=(const NzString& first, const NzString& second);
NAZARA_API friend bool operator>(const NzString& first, const NzString& second);
NAZARA_API friend bool operator>=(const NzString& first, const NzString& second);
NAZARA_API friend bool operator==(char character, const NzString& nstring);
NAZARA_API friend bool operator==(const char* string, const NzString& nstring);
NAZARA_API friend bool operator==(const std::string& string, const NzString& nstring);
NAZARA_API friend bool operator!=(char character, const NzString& nstring);
NAZARA_API friend bool operator!=(const char* string, const NzString& nstring);
NAZARA_API friend bool operator!=(const std::string& string, const NzString& nstring);
NAZARA_API friend bool operator<(char character, const NzString& nstring);
NAZARA_API friend bool operator<(const char* string, const NzString& nstring);
NAZARA_API friend bool operator<(const std::string& string, const NzString& nstring);
NAZARA_API friend bool operator<=(char character, const NzString& nstring);
NAZARA_API friend bool operator<=(const char* string, const NzString& nstring);
NAZARA_API friend bool operator<=(const std::string& string, const NzString& nstring);
NAZARA_API friend bool operator>(char character, const NzString& nstring);
NAZARA_API friend bool operator>(const char* string, const NzString& nstring);
NAZARA_API friend bool operator>(const std::string& string, const NzString& nstring);
NAZARA_API friend bool operator>=(char character, const NzString& nstring);
NAZARA_API friend bool operator>=(const char* string, const NzString& nstring);
NAZARA_API friend bool operator>=(const std::string& string, const NzString& nstring);
struct NAZARA_API SharedString
{
SharedString() :
refCount(1)
{
}
SharedString(unsigned int bufferSize, unsigned int stringSize, unsigned short referenceCount, char* str) :
allocatedSize(bufferSize),
size(stringSize),
refCount(referenceCount),
string(str)
{
}
unsigned int allocatedSize;
unsigned int size;
unsigned short refCount;
char* string;
NazaraMutex(mutex)
};
static SharedString emptyString;
static unsigned int npos;
private:
void EnsureOwnership();
bool FillHash(NzHashImpl* hash) const;
void ReleaseString();
SharedString* m_sharedString;
};
namespace std
{
NAZARA_API istream& getline(istream& is, NzString& str);
NAZARA_API istream& getline(istream& is, NzString& str, char delim);
NAZARA_API void swap(NzString& lhs, NzString& rhs);
}
#undef NAZARA_STRING
#endif // NAZARA_STRING_HPP

View File

@@ -0,0 +1,56 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_STRINGSTREAM_HPP
#define NAZARA_STRINGSTREAM_HPP
#define NAZARA_STRINGSTREAM
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/ThreadSafety.hpp>
#include <string>
#include <vector>
class NAZARA_API NzStringStream
{
public:
NzStringStream();
NzStringStream(const NzString& str);
NzString ToString() const;
NzStringStream& operator<<(bool boolean);
NzStringStream& operator<<(short number);
NzStringStream& operator<<(unsigned short number);
NzStringStream& operator<<(int number);
NzStringStream& operator<<(unsigned int number);
NzStringStream& operator<<(long number);
NzStringStream& operator<<(unsigned long number);
NzStringStream& operator<<(long long number);
NzStringStream& operator<<(unsigned long long number);
NzStringStream& operator<<(float number);
NzStringStream& operator<<(double number);
NzStringStream& operator<<(long double number);
NzStringStream& operator<<(char character);
NzStringStream& operator<<(unsigned char character);
NzStringStream& operator<<(const char* string);
NzStringStream& operator<<(const std::string& string);
NzStringStream& operator<<(const NzString& string);
NzStringStream& operator<<(const void* ptr);
operator NzString() const;
private:
NazaraMutexAttrib(m_mutex, mutable)
std::vector<NzString> m_strings;
unsigned int m_bufferSize;
};
#undef NAZARA_STRINGSTREAM
#endif // NAZARA_STRINGSTREAM_HPP

View File

@@ -0,0 +1,69 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Inspiré du code de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_THREAD_HPP
#define NAZARA_THREAD_HPP
#define NAZARA_THREAD
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/Functor.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NzThreadImpl;
class NAZARA_API NzThread : NzNonCopyable
{
friend class NzThreadImpl;
public:
class NAZARA_API Id
{
friend class NzThread;
friend class NzThreadImpl;
public:
Id() : m_handle(nullptr) {}
Id(Id&& rhs) = default;
~Id();
Id& operator=(Id&& rhs) = default;
bool operator==(const Id& rhs) const;
bool operator!=(const Id& rhs) const;
private:
Id(void* handle) : m_handle(handle) {}
Id(const NzThreadImpl* thread);
void* m_handle;
};
template<typename F> NzThread(F function);
template<typename F, typename... Args> NzThread(F function, Args... args);
~NzThread();
Id GetId() const;
bool IsCurrent() const;
void Launch(bool independent = false);
void Join();
void Terminate();
static Id GetCurrentId();
static void Sleep(nzUInt32 time);
private:
NzFunctor* m_func;
NzThreadImpl* m_impl;
bool m_independent;
};
#include <Nazara/Core/Thread.inl>
#undef NAZARA_THREAD
#endif // NAZARA_THREAD_HPP

View File

@@ -0,0 +1,19 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Debug.hpp>
template<typename F> NzThread::NzThread(F function) :
m_func(new NzFunctorWithoutArgs<F>(function)),
m_impl(nullptr)
{
}
template<typename F, typename... Args> NzThread::NzThread(F function, Args... args) :
m_func(new NzFunctorWithArgs<F, Args...>(function, args...)),
m_impl(nullptr)
{
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_THREADCONDITION_HPP
#define NAZARA_THREADCONDITION_HPP
#define NAZARA_THREADCONDITION
#include <Nazara/Prerequesites.hpp>
class NzMutex;
class NzThreadConditionImpl;
class NAZARA_API NzThreadCondition
{
public:
NzThreadCondition();
~NzThreadCondition();
void Signal();
void SignalAll();
void Wait(NzMutex* mutex);
bool Wait(NzMutex* mutex, nzUInt32 timeout);
private:
NzThreadConditionImpl* m_impl;
};
#undef NAZARA_THREADCONDITION
#endif // NAZARA_THREADCONDITION_HPP

View File

@@ -0,0 +1,43 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Pas de header guard
#include <Nazara/Core/Config.hpp>
#undef NazaraLock
#undef NazaraMutex
#undef NazaraMutexAttrib
#undef NazaraMutexLock
#undef NazaraMutexUnlock
#undef NazaraNamedLock
#if NAZARA_CORE_THREADSAFE && (\
(NAZARA_THREADSAFETY_BYTEARRAY && (defined(NAZARA_BYTEARRAY) || defined(NAZARA_BYTEARRAY_CPP))) || \
(NAZARA_THREADSAFETY_CLOCK && (defined(NAZARA_CLOCK) || defined(NAZARA_CLOCK_CPP))) || \
(NAZARA_THREADSAFETY_DIRECTORY && (defined(NAZARA_DIRECTORY) || defined(NAZARA_DIRECTORY_CPP))) || \
(NAZARA_THREADSAFETY_DYNLIB && (defined(NAZARA_DYNLIB) || defined(NAZARA_DYNLIB_CPP))) || \
(NAZARA_THREADSAFETY_FILE && (defined(NAZARA_FILE) || defined(NAZARA_FILE_CPP))) || \
(NAZARA_THREADSAFETY_HASHDIGEST && (defined(NAZARA_HASHDIGEST) || defined(NAZARA_HASHDIGEST_CPP))) || \
(NAZARA_THREADSAFETY_LOG && (defined(NAZARA_LOG) || defined(NAZARA_LOG_CPP))) || \
(NAZARA_THREADSAFETY_STRING && (defined(NAZARA_STRING) || defined(NAZARA_STRING_CPP))) || \
(NAZARA_THREADSAFETY_STRINGSTREAM && (defined(NAZARA_STRINGSTREAM) || defined(NAZARA_STRINGSTREAM_CPP))))
#include <Nazara/Core/Lock.hpp>
#include <Nazara/Core/Mutex.hpp>
#define NazaraLock(mutex) NzLock lock_mutex(mutex);
#define NazaraMutex(name) NzMutex name;
#define NazaraMutexAttrib(name, attribute) attribute NzMutex name;
#define NazaraMutexLock(mutex) mutex.Lock();
#define NazaraMutexUnlock(mutex) mutex.Unlock();
#define NazaraNamedLock(mutex, name) NzLock lock_##name(mutex);
#else
#define NazaraLock(mutex)
#define NazaraMutex(name)
#define NazaraMutexAttrib(name, attribute)
#define NazaraMutexLock(mutex)
#define NazaraMutexUnlock(mutex)
#define NazaraNamedLock(mutex, name)
#endif

View File

@@ -0,0 +1,110 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_UNICODE_HPP
#define NAZARA_UNICODE_HPP
#define NAZARA_UNICODE
#include <Nazara/Prerequesites.hpp>
namespace NzUnicode
{
/*
Catégorie Unicode:
-Les valeurs de 0x01 à 0x80 indiquent la catégorie.
-Les valeurs de 0x100 à 0x10000 indiquent la sous-catégorie.
*/
enum Category : nzUInt16
{
// Catégorie non-reconnue par Nazara
Category_NoCategory = 0,
// Lettres
Category_Letter = 0x01, // L
Category_Letter_Lowercase = Category_Letter | 0x0100, // Ll
Category_Letter_Modifier = Category_Letter | 0x0200, // Lm
Category_Letter_Other = Category_Letter | 0x0400, // Lo
Category_Letter_Titlecase = Category_Letter | 0x0800, // Lt
Category_Letter_Uppercase = Category_Letter | 0x1000, // Lu
// Marques
Category_Mark = 0x02, // M
Category_Mark_Enclosing = Category_Mark | 0x100, // Me
Category_Mark_NonSpacing = Category_Mark | 0x200, // Mn
Category_Mark_SpacingCombining = Category_Mark | 0x400, // Mc
// Nombres
Category_Number = 0x04, // N
Category_Number_DecimalDigit = Category_Number | 0x100, // Nd
Category_Number_Letter = Category_Number | 0x200, // Nl
Category_Number_Other = Category_Number | 0x400, // No
// Autres
Category_Other = 0x08, // C
Category_Other_Control = Category_Other | 0x0100, // Cc
Category_Other_Format = Category_Other | 0x0200, // Cf
Category_Other_NotAssigned = Category_Other | 0x0400, // Cn
Category_Other_PrivateUse = Category_Other | 0x0800, // Co
Category_Other_Surrogate = Category_Other | 0x1000, // Cs
// Ponctuations
Category_Punctuation = 0x10, // P
Category_Punctuation_Close = Category_Punctuation | 0x0100, // Pe
Category_Punctuation_Connector = Category_Punctuation | 0x0200, // Pc
Category_Punctuation_Dash = Category_Punctuation | 0x0400, // Pd
Category_Punctuation_FinalQuote = Category_Punctuation | 0x0800, // Pf
Category_Punctuation_InitialQuote = Category_Punctuation | 0x1000, // Pi
Category_Punctuation_Open = Category_Punctuation | 0x2000, // Ps
Category_Punctuation_Other = Category_Punctuation | 0x4000, // Po
// Espacements
Category_Separator = 0x20, // Z
Category_Separator_Line = Category_Separator | 0x0100, // Zl
Category_Separator_Paragraph = Category_Separator | 0x0200, // Zp
Category_Separator_Space = Category_Separator | 0x0400, // Zs
// Symboles
Category_Symbol = 0x40, // S
Category_Symbol_Currency = Category_Symbol | 0x0100, // Sc
Category_Symbol_Math = Category_Symbol | 0x0200, // Sm
Category_Symbol_Modifier = Category_Symbol | 0x0400, // Sk
Category_Symbol_Other = Category_Symbol | 0x0800 // So
};
enum Direction : nzUInt8
{
Direction_Arabic_Letter, // AL
Direction_Arabic_Number, // AN
Direction_Boundary_Neutral, // BN
Direction_Common_Separator, // CS
Direction_European_Number, // EN
Direction_European_Separator, // ES
Direction_European_Terminator, // ET
Direction_Left_To_Right, // L
Direction_Left_To_Right_Embedding, // LRE
Direction_Left_To_Right_Override, // LRO
Direction_Nonspacing_Mark, // NSM
Direction_Other_Neutral, // ON
Direction_Paragraph_Separator, // B
Direction_Pop_Directional_Format, // PDF
Direction_Right_To_Left, // R
Direction_Right_To_Left_Embedding, // RLE
Direction_Right_To_Left_Override, // RLO
Direction_Segment_Separator, // S
Direction_White_Space // WS
};
Category GetCategory(char32_t character);
Direction GetDirection(char32_t character);
char32_t GetLowercase(char32_t character);
char32_t GetTitlecase(char32_t character);
char32_t GetUppercase(char32_t character);
}
#undef NAZARA_UNICODE
#endif // NAZARA_UNICODE_HPP

View File

@@ -0,0 +1,48 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_BASIC_HPP
#define NAZARA_BASIC_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/String.hpp>
#ifndef M_PI
#define M_PI 3.141592653589793238462643
#endif
#ifndef M_SQRT2
#define M_SQRT2 1.4142135623730950488016887
#endif
template<typename T> T NzApproach(T value, T objective, T increment);
template<typename T> T NzClamp(T value, T min, T max);
template<typename T> T NzDegrees(T degrees);
template<typename T> T NzDegreeToRadian(T degrees);
inline unsigned int NzGetNumberLength(signed char number);
inline unsigned int NzGetNumberLength(unsigned char number);
inline unsigned int NzGetNumberLength(short number);
inline unsigned int NzGetNumberLength(unsigned short number);
inline unsigned int NzGetNumberLength(int number);
inline unsigned int NzGetNumberLength(unsigned int number);
inline unsigned int NzGetNumberLength(long number);
inline unsigned int NzGetNumberLength(unsigned long number);
inline unsigned int NzGetNumberLength(long long number);
inline unsigned int NzGetNumberLength(unsigned long long number);
inline unsigned int NzGetNumberLength(float number, nzUInt8 precision = NAZARA_CORE_REAL_PRECISION);
inline unsigned int NzGetNumberLength(double number, nzUInt8 precision = NAZARA_CORE_REAL_PRECISION);
inline unsigned int NzGetNumberLength(long double number, nzUInt8 precision = NAZARA_CORE_REAL_PRECISION);
template<typename T> T NzNormalizeAngle(T angle);
template<typename T> bool NzNumberEquals(T a, T b);
inline NzString NzNumberToString(long long number, nzUInt8 radix = 10);
template<typename T> T NzRadians(T radians);
template<typename T> T NzRadianToDegree(T radians);
inline long long NzStringToNumber(NzString str, nzUInt8 radix = 10);
#include <Nazara/Math/Basic.inl>
#endif // NAZARA_BASIC_HPP

View File

@@ -0,0 +1,279 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Config.hpp>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <Nazara/Core/Debug.hpp>
template<typename T>
T NzApproach(T value, T objective, T increment)
{
if (value < objective)
return std::min(value + increment, objective);
else if (value > objective)
return std::max(value - increment, objective);
else
return value;
}
template<typename T>
T NzClamp(T value, T min, T max)
{
if (value < min)
return min;
else if (value > max)
return max;
else
return value;
}
template<typename T>
T NzDegrees(T degrees)
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzDegreeToRadian(degrees);
#else
return degrees;
#endif
}
template<typename T>
T NzDegreeToRadian(T degrees)
{
return degrees * (M_PI/180.0);
}
unsigned int NzGetNumberLength(signed char number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}
unsigned int NzGetNumberLength(unsigned char number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
}
unsigned int NzGetNumberLength(short number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}
unsigned int NzGetNumberLength(unsigned short number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
}
unsigned int NzGetNumberLength(int number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}
unsigned int NzGetNumberLength(unsigned int number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
}
unsigned int NzGetNumberLength(long number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}
unsigned int NzGetNumberLength(unsigned long number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
}
unsigned int NzGetNumberLength(long long number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
}
unsigned int NzGetNumberLength(unsigned long long number)
{
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
}
unsigned int NzGetNumberLength(float number, nzUInt8 precision)
{
// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}
unsigned int NzGetNumberLength(double number, nzUInt8 precision)
{
// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}
unsigned int NzGetNumberLength(long double number, nzUInt8 precision)
{
// L'imprécision des flottants nécessite un cast (log10(9.99999) = 1)
return NzGetNumberLength(static_cast<long long>(number)) + precision + 1; // Plus un pour le point
}
template<typename T>
T NzNormalizeAngle(T angle)
{
#if NAZARA_MATH_ANGLE_RADIAN
const T limit = M_PI;
#else
const T limit = 180.0;
#endif
///TODO: Trouver une solution sans duplication
if (angle > 0.0)
{
angle += limit;
angle -= static_cast<int>(angle/(2.0*limit))*(2.0*limit);
angle -= limit;
}
else
{
angle -= limit;
angle -= static_cast<int>(angle/(2.0*limit))*(2.0*limit);
angle += limit;
}
return angle;
}
template<typename T>
bool NzNumberEquals(T a, T b)
{
if (a > b)
return (a-b) <= std::numeric_limits<T>::epsilon();
else
return (b-a) <= std::numeric_limits<T>::epsilon();
}
NzString NzNumberToString(long long number, nzUInt8 radix)
{
#if NAZARA_MATH_SAFE
if (radix < 2 || radix > 36)
{
NazaraError("Base must be between 2 and 36");
return NzString();
}
#endif
if (number == 0)
return '0';
static const char* symbols("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
bool negative;
if (number < 0)
{
negative = true;
number = -number;
}
else
negative = false;
NzString str;
str.Reserve(NzGetNumberLength(number));
do
{
str += symbols[number % radix];
number /= radix;
}
while (number > 0);
if (negative)
str += '-';
return str.Reversed();
}
template<typename T>
T NzRadians(T radians)
{
#if NAZARA_MATH_ANGLE_RADIAN
return radians;
#else
return NzRadianToDegree(radians);
#endif
}
template<typename T>
T NzRadianToDegree(T radians)
{
return radians * (180.0/M_PI);
}
long long NzStringToNumber(NzString str, nzUInt8 radix)
{
#if NAZARA_MATH_SAFE
if (radix < 2 || radix > 36)
{
NazaraError("Radix must be between 2 and 36");
return 0;
}
#endif
str.Simplify();
if (radix > 10)
str.ToUpper();
bool negative = str.StartsWith('-');
static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char* digit = &str[(negative) ? 1 : 0];
unsigned long long total = 0;
do
{
if (*digit == ' ')
continue;
total *= radix;
const char* c = std::strchr(symbols, *digit);
if (c && c-symbols < radix)
total += c-symbols;
else
{
NazaraError("str is not a valid number");
return 0;
}
}
while (*++digit);
return (negative) ? -static_cast<long long>(total) : total;
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,42 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Rémi "overdrivr" Begues (remi.beges@laposte.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_MATH_HPP
#define NAZARA_CONFIG_MATH_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Définit le radian comme l'unité utilisée pour les angles
#define NAZARA_MATH_ANGLE_RADIAN 0
// Définit la disposition des matrices en colonnes
#define NAZARA_MATH_MATRIX_COLUMN_MAJOR 1
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_MATH_SAFE 1
#endif // NAZARA_CONFIG_MATH_HPP

View File

@@ -0,0 +1,70 @@
// Copyright (C) 2012 Rémi Begues
// Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_EULERANGLES_HPP
#define NAZARA_EULERANGLES_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzQuaternion;
template<typename T> class NzVector3;
template<typename T> class NzEulerAngles
{
public:
NzEulerAngles();
NzEulerAngles(T P, T Y, T R);
NzEulerAngles(T angles[3]);
//NzEulerAngles(const NzMatrix3<T>& mat);
NzEulerAngles(const NzQuaternion<T>& quat);
template<typename U> explicit NzEulerAngles(const NzEulerAngles<U>& angles);
NzEulerAngles(const NzEulerAngles& angles) = default;
~NzEulerAngles() = default;
NzVector3<T> GetForward() const;
NzVector3<T> GetRight() const;
NzVector3<T> GetUp() const;
void Normalize();
void Set(T P, T Y, T R);
void Set(T angles[3]);
void Set(const NzEulerAngles<T>& angles);
//void Set(const NzMatrix3<T>& mat);
void Set(const NzQuaternion<T>& quat);
template<typename U> void Set(const NzEulerAngles<U>& angles);
void SetZero();
//NzEulerAngles<T> ToEulerAngles() const;
//NzMatrix3<T> ToRotationMatrix() const;
NzQuaternion<T> ToQuaternion() const;
NzString ToString() const;
NzEulerAngles operator+(const NzEulerAngles& angles) const;
NzEulerAngles operator-(const NzEulerAngles& angles) const;
NzEulerAngles operator*(const NzEulerAngles& angles) const;
NzEulerAngles operator/(const NzEulerAngles& angles) const;
NzEulerAngles operator+=(const NzEulerAngles& angles);
NzEulerAngles operator-=(const NzEulerAngles& angles);
NzEulerAngles operator*=(const NzEulerAngles& angles);
NzEulerAngles operator/=(const NzEulerAngles& angles);
bool operator==(const NzEulerAngles& angles) const;
bool operator!=(const NzEulerAngles& angles) const;
T pitch, yaw, roll;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzEulerAngles<T>& angles);
typedef NzEulerAngles<double> NzEulerAnglesd;
typedef NzEulerAngles<float> NzEulerAnglesf;
#include <Nazara/Math/EulerAngles.inl>
#endif // NAZARA_EULERANGLES_HPP

View File

@@ -0,0 +1,199 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <cmath>
#include <Nazara/Core/Debug.hpp>
template<typename T>
NzEulerAngles<T>::NzEulerAngles()
{
}
template<typename T>
NzEulerAngles<T>::NzEulerAngles(T P, T Y, T R)
{
Set(P, Y, R);
}
template<typename T>
NzEulerAngles<T>::NzEulerAngles(T angles[3])
{
Set(angles);
}
template<typename T>
NzEulerAngles<T>::NzEulerAngles(const NzQuaternion<T>& quat)
{
Set(quat);
}
template<typename T>
template<typename U>
NzEulerAngles<T>::NzEulerAngles(const NzEulerAngles<U>& angles)
{
Set(angles);
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetForward() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::cos(yaw), std::sin(roll), std::sin(yaw));
#else
return NzVector3<T>(std::cos(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(roll)), std::sin(NzDegreeToRadian(yaw)));
#endif
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetRight() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::sin(yaw), std::sin(pitch), std::cos(pitch));
#else
return NzVector3<T>(std::sin(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(pitch)), std::cos(NzDegreeToRadian(pitch)));
#endif
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetUp() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::sin(roll), std::cos(pitch), -std::sin(pitch));
#else
return NzVector3<T>(std::sin(NzDegreeToRadian(roll)), std::cos(NzDegreeToRadian(pitch)), -std::sin(NzDegreeToRadian(pitch)));
#endif
}
template<typename T>
void NzEulerAngles<T>::Normalize()
{
pitch = NzNormalizeAngle(pitch);
yaw = NzNormalizeAngle(yaw);
roll = NzNormalizeAngle(roll);
}
template<typename T>
void NzEulerAngles<T>::Set(T P, T Y, T R)
{
pitch = P;
yaw = Y;
roll = R;
}
template<typename T>
void NzEulerAngles<T>::Set(T angles[3])
{
pitch = angles[0];
yaw = angles[1];
roll = angles[2];
}
template<typename T>
void NzEulerAngles<T>::Set(const NzEulerAngles& angles)
{
pitch = angles.pitch;
yaw = angles.yaw;
roll = angles.roll;
}
template<typename T>
void NzEulerAngles<T>::Set(const NzQuaternion<T>& quat)
{
Set(quat.ToEulerAngles());
}
template<typename T>
template<typename U>
void NzEulerAngles<T>::Set(const NzEulerAngles<U>& angles)
{
pitch = static_cast<T>(angles.pitch);
yaw = static_cast<T>(angles.yaw);
roll = static_cast<T>(angles.roll);
}
template<typename T>
void NzEulerAngles<T>::SetZero()
{
Set(0.0, 0.0, 0.0);
}
template<typename T>
NzQuaternion<T> NzEulerAngles<T>::ToQuaternion() const
{
NzQuaternion<T> Qx(pitch, NzVector3<T>(1.0, 0.0, 0.0));
NzQuaternion<T> Qy(yaw, NzVector3<T>(0.0, 1.0, 0.0));
NzQuaternion<T> Qz(roll, NzVector3<T>(0.0, 0.0, 1.0));
return Qx * Qy * Qz;
}
template<typename T>
NzString NzEulerAngles<T>::ToString() const
{
NzStringStream ss;
return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')';
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::operator+(const NzEulerAngles& angles) const
{
return NzEulerAngles(pitch + angles.pitch,
yaw + angles.yaw,
roll + angles.roll);
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::operator-(const NzEulerAngles& angles) const
{
return NzEulerAngles(pitch - angles.pitch,
yaw - angles.yaw,
roll - angles.roll);
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::operator+=(const NzEulerAngles& angles)
{
pitch += angles.pitch;
yaw += angles.yaw;
roll += angles.roll;
return *this;
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::operator-=(const NzEulerAngles& angles)
{
pitch -= angles.pitch;
yaw -= angles.yaw;
roll -= angles.roll;
return *this;
}
template<typename T>
bool NzEulerAngles<T>::operator==(const NzEulerAngles& angles) const
{
return NzNumberEquals(pitch, angles.pitch) &&
NzNumberEquals(yaw, angles.yaw) &&
NzNumberEquals(roll, angles.roll);
}
template<typename T>
bool NzEulerAngles<T>::operator!=(const NzEulerAngles& angles) const
{
return !operator==(angles);
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzEulerAngles<T>& angles)
{
return out << angles.ToString();
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,100 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_MATRIX4_HPP
#define NAZARA_MATRIX4_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzEulerAngles;
template<typename T> class NzQuaternion;
template<typename T> class NzVector2;
template<typename T> class NzVector3;
template<typename T> class NzVector4;
template<typename T> class NzMatrix4
{
public:
NzMatrix4();
NzMatrix4(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
NzMatrix4(T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& mat);
template<typename U> explicit NzMatrix4(const NzMatrix4<U>& mat);
NzMatrix4(const NzMatrix4& mat) = default;
~NzMatrix4() = default;
T GetDeterminant() const;
NzMatrix4 GetInverse() const;
//NzMatrix3 GetRotationMatrix() const;
NzVector3<T> GetScale() const;
NzVector3<T> GetTranslation() const;
NzMatrix4 GetTransposed() const;
bool HasNegativeScale() const;
bool HasScale() const;
void Set(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
void Set(T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& mat);
void Set(const NzMatrix4& mat);
template<typename U> void Set(const NzMatrix4<U>& mat);
void SetIdentity();
void SetLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
void SetPerspective(T angle, T ratio, T zNear, T zFar);
void SetRotation(const NzQuaternion<T>& rotation);
void SetScale(const NzVector3<T>& scale);
void SetTranslation(const NzVector3<T>& translation);
void SetZero();
NzString ToString() const;
NzVector2<T> Transform(const NzVector2<T>& vector, T z = 0.0, T w = 1.0) const;
NzVector3<T> Transform(const NzVector3<T>& vector, T w = 1.0) const;
NzVector4<T> Transform(const NzVector4<T>& vector) const;
NzMatrix4& Transpose();
operator T*();
operator const T*() const;
T& operator()(unsigned int x, unsigned int y);
const T& operator()(unsigned int x, unsigned int y) const;
NzMatrix4 operator*(const NzMatrix4& mat) const;
NzVector2<T> operator*(const NzVector2<T>& vector) const;
NzVector3<T> operator*(const NzVector3<T>& vector) const;
NzVector4<T> operator*(const NzVector4<T>& vector) const;
NzMatrix4 operator*(T scalar) const;
NzMatrix4& operator*=(const NzMatrix4& mat);
NzMatrix4& operator*=(T scalar);
static NzMatrix4 LookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar);
static NzMatrix4 Rotate(const NzQuaternion<T>& rotation);
static NzMatrix4 Scale(const NzVector3<T>& scale);
static NzMatrix4 Translate(const NzVector3<T>& translation);
T m11, m12, m13, m14,
m21, m22, m23, m24,
m31, m32, m33, m34,
m41, m42, m43, m44;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzMatrix4<T>& mat);
typedef NzMatrix4<double> NzMatrix4d;
typedef NzMatrix4<float> NzMatrix4f;
#include <Nazara/Math/Matrix4.inl>
#endif // NAZARA_MATRIX4_HPP

View File

@@ -0,0 +1,576 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <cmath>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
template<typename T>
NzMatrix4<T>::NzMatrix4()
{
}
template<typename T>
NzMatrix4<T>::NzMatrix4(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44)
{
Set(r11, r12, r13, r14,
r21, r22, r23, r24,
r31, r32, r33, r34,
r41, r42, r43, r44);
}
template<typename T>
NzMatrix4<T>::NzMatrix4(T matrix[16])
{
Set(matrix);
}
template<typename T>
template<typename U>
NzMatrix4<T>::NzMatrix4(const NzMatrix4<U>& mat)
{
Set(mat);
}
template<typename T>
T NzMatrix4<T>::GetDeterminant() const
{
T A = m22 * (m33 * m44 - m43 * m34) - m32 * (m23 * m44 - m43 * m24) + m42 * (m23 * m34 - m33 * m24);
T B = m12 * (m33 * m44 - m43 * m34) - m32 * (m13 * m44 - m43 * m14) + m42 * (m13 * m34 - m33 * m14);
T C = m12 * (m23 * m44 - m43 * m24) - m22 * (m13 * m44 - m43 * m14) + m42 * (m13 * m24 - m23 * m14);
T D = m12 * (m23 * m34 - m33 * m24) - m22 * (m13 * m34 - m33 * m14) + m32 * (m13 * m24 - m23 * m14);
return m11 * A - m21 * B + m31 * C - m41 * D;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::GetInverse() const
{
NzMatrix4 mat;
T det = GetDeterminant();
if (det != 0.0)
{
mat.m11 = (m22 * (m33 * m44 - m34 * m43) - m32 * (m23 * m44 - m43 * m24) + m42 * (m23 * m34 - m33 * m24)) / det;
mat.m12 = -(m12 * (m33 * m44 - m43 * m34) - m32 * (m13 * m44 - m43 * m14) + m42 * (m13 * m34 - m33 * m14)) / det;
mat.m13 = (m12 * (m23 * m44 - m43 * m24) - m22 * (m13 * m44 - m43 * m14) + m42 * (m13 * m24 - m23 * m14)) / det;
mat.m14 = -(m12 * (m23 * m34 - m33 * m24) - m22 * (m13 * m34 - m33 * m14) + m32 * (m13 * m24 - m23 * m14)) / det;
mat.m21 = -(m21 * (m33 * m44 - m34 * m43) - m23 * (m31 * m44 - m34 * m41) + m24 * (m31 * m43 - m33 * m41)) / det;
mat.m22 = (m11 * (m33 * m44 - m34 * m43) - m13 * (m31 * m44 - m34 * m41) + m14 * (m31 * m43 - m33 * m41)) / det;
mat.m23 = -(m11 * (m23 * m44 - m24 * m43) - m13 * (m21 * m44 - m24 * m41) + m14 * (m21 * m43 - m23 * m41)) / det;
mat.m24 = (m11 * (m23 * m34 - m24 * m33) - m13 * (m21 * m34 - m24 * m31) + m14 * (m21 * m33 - m23 * m31)) / det;
mat.m31 = (m21 * (m32 * m44 - m34 * m42) - m22 * (m31 * m44 - m34 * m41) + m24 * (m31 * m42 - m32 * m41)) / det;
mat.m32 = -(m11 * (m32 * m44 - m34 * m42) - m12 * (m31 * m44 - m34 * m41) + m14 * (m31 * m42 - m32 * m41)) / det;
mat.m33 = (m11 * (m22 * m44 - m24 * m42) - m12 * (m21 * m44 - m24 * m41) + m14 * (m21 * m42 - m22 * m41)) / det;
mat.m34 = -(m11 * (m22 * m34 - m24 * m32) - m12 * (m21 * m34 - m24 * m31) + m14 * (m21 * m32 - m22 * m31)) / det;
mat.m41 = -(m21 * (m32 * m43 - m33 * m42) - m22 * (m31 * m43 - m33 * m41) + m23 * (m31 * m42 - m32 * m41)) / det;
mat.m42 = (m11 * (m32 * m43 - m33 * m42) - m12 * (m31 * m43 - m33 * m41) + m13 * (m31 * m42 - m32 * m41)) / det;
mat.m43 = -(m11 * (m22 * m43 - m23 * m42) - m12 * (m21 * m43 - m23 * m41) + m13 * (m21 * m42 - m22 * m41)) / det;
mat.m44 = (m11 * (m22 * m33 - m23 * m32) - m12 * (m21 * m33 - m23 * m31) + m13 * (m21 * m32 - m22 * m31)) / det;
}
return mat;
}
template<typename T>
NzVector3<T> NzMatrix4<T>::GetScale() const
{
return NzVector3<T>(std::sqrt(m11 * m11 + m21 * m21 + m31 * m31),
std::sqrt(m12 * m12 + m22 * m22 + m32 * m32),
std::sqrt(m13 * m13 + m23 * m23 + m33 * m33));
}
template<typename T>
NzVector3<T> NzMatrix4<T>::GetTranslation() const
{
#if NAZARA_MATH_MATRIX_COLUMN_MAJOR
return NzVector3<T>(m41, m42, m43);
#else
return NzVector3<T>(m14, m24, m34);
#endif
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::GetTransposed() const
{
return NzMatrix4(m11, m21, m31, m41,
m12, m22, m32, m42,
m13, m23, m33, m43,
m14, m24, m34, m44);
}
template<typename T>
bool NzMatrix4<T>::HasNegativeScale() const
{
return GetDeterminant() < 0.f;
}
template<typename T>
bool NzMatrix4<T>::HasScale() const
{
T t = m11 * m11 + m21 * m21 + m31 * m31;
if (1.0 - t > std::numeric_limits<T>::epsilon())
return true;
t = m12 * m12 + m22 * m22 + m32 * m32;
if (1.0 - t > std::numeric_limits<T>::epsilon())
return true;
t = m13 * m13 + m23 * m23 + m33 * m33;
if (1.0 - t > std::numeric_limits<T>::epsilon())
return true;
return false;
}
template<typename T>
void NzMatrix4<T>::Set(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44)
{
m11 = r11;
m12 = r12;
m13 = r13;
m14 = r14;
m21 = r21;
m22 = r22;
m23 = r23;
m24 = r24;
m31 = r31;
m32 = r32;
m33 = r33;
m34 = r34;
m41 = r41;
m42 = r42;
m43 = r43;
m44 = r44;
}
template<typename T> void NzMatrix4<T>::Set(T matrix[16])
{
// Ici nous sommes certains de la continuité des éléments en mémoire
std::memcpy(&m41, matrix, 16*sizeof(T));
}
template<typename T> void NzMatrix4<T>::Set(const NzMatrix4& mat)
{
// Pareil
std::memcpy(&m41, &mat.m41, 16*sizeof(T));
}
template<typename T>
template<typename U>
void NzMatrix4<T>::Set(const NzMatrix4<U>& mat)
{
m11 = static_cast<T>(mat.m11);
m12 = static_cast<T>(mat.m12);
m13 = static_cast<T>(mat.m13);
m14 = static_cast<T>(mat.m14);
m21 = static_cast<T>(mat.m21);
m22 = static_cast<T>(mat.m22);
m23 = static_cast<T>(mat.m23);
m24 = static_cast<T>(mat.m24);
m31 = static_cast<T>(mat.m31);
m32 = static_cast<T>(mat.m32);
m33 = static_cast<T>(mat.m33);
m34 = static_cast<T>(mat.m34);
m41 = static_cast<T>(mat.m41);
m42 = static_cast<T>(mat.m42);
m43 = static_cast<T>(mat.m43);
m44 = static_cast<T>(mat.m44);
}
template<typename T>
void NzMatrix4<T>::SetIdentity()
{
Set(1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0);
}
template<typename T>
void NzMatrix4<T>::SetLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up)
{
NzVector3<T> f = center - eye;
f.Normalize();
NzVector3<T> u = up;
u.Normalize();
NzVector3<T> s = f.CrossProduct(u);
s.Normalize();
u = s.CrossProduct(f);
Set(s.x, u.x, -f.x, 0.0,
s.y, u.y, -f.y, 0.0,
s.z, u.z, -f.z, 0.0,
0.0, 0.0, 0.0, 1.0);
operator*=(Translate(-eye));
}
template<typename T>
void NzMatrix4<T>::SetPerspective(T angle, T ratio, T zNear, T zFar)
{
#if NAZARA_MATH_ANGLE_RADIAN
angle /= 2;
#else
angle = NzDegreeToRadian(angle/2);
#endif
T f = 1 / std::tan(angle);
#if NAZARA_MATH_MATRIX_COLUMN_MAJOR
Set(f / ratio, 0.0, 0.0, 0.0,
0.0, f, 0.0, 0.0,
0.0, 0.0, (zNear + zFar) / (zNear - zFar), -1.0,
0.0, 0.0, (2 * zNear * zFar) / (zNear - zFar), 1.0);
#else
Set(f / ratio, 0.0, 0.0, 0.0,
0.0, f, 0.0, 0.0,
0.0, 0.0, (zNear + zFar) / (zNear - zFar), (2 * zNear * zFar) / (zNear - zFar),
0.0, 0.0, -1.0, 1.0);
#endif
}
template<typename T>
void NzMatrix4<T>::SetRotation(const NzQuaternion<T>& rotation)
{
// http://www.flipcode.com/documents/matrfaq.html#Q54
T xx = rotation.x * rotation.x;
T xy = rotation.x * rotation.y;
T xz = rotation.x * rotation.z;
T xw = rotation.x * rotation.w;
T yy = rotation.y * rotation.y;
T yz = rotation.y * rotation.z;
T yw = rotation.y * rotation.w;
T zz = rotation.z * rotation.z;
T zw = rotation.z * rotation.w;
Set(1.0 - 2.0*(yy+zz), 2.0*(xy-zw), 2.0*(xz+yw), 0.0,
2.0*(xz+zw), 1.0 - 2.0*(xx+zz), 2.0*(yz-xw), 0.0,
2.0*(xz-yw), 2.0*(yz+xw), 1.0 - 2.0*(xx+yy), 0.0,
0.0, 0.0, 0.0, 1.0);
}
template<typename T>
void NzMatrix4<T>::SetScale(const NzVector3<T>& vector)
{
Set(vector.x, 0.0, 0.0, 0.0,
0.0, vector.y, 0.0, 0.0,
0.0, 0.0, vector.z, 0.0,
0.0, 0.0, 0.0, 1.0);
}
template<typename T>
void NzMatrix4<T>::SetTranslation(const NzVector3<T>& translation)
{
#if NAZARA_MATH_MATRIX_COLUMN_MAJOR
Set(1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
translation.x, translation.y, translation.z, 1.0);
#else
Set(1.0, 0.0, 0.0, translation.x,
0.0, 1.0, 0.0, translation.y,
0.0, 0.0, 1.0, translation.z,
0.0, 0.0, 0.0, 1.0);
#endif
}
template<typename T>
void NzMatrix4<T>::SetZero()
{
Set(0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0);
}
template<typename T>
NzString NzMatrix4<T>::ToString() const
{
NzStringStream ss;
return ss << "Matrix4(" << m11 << ", " << m12 << ", " << m13 << ", " << m14 << ",\n"
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
}
template<typename T>
NzVector2<T> NzMatrix4<T>::Transform(const NzVector2<T>& vector, T z, T w) const
{
return NzVector2<T>(m11 * vector.x + m12 * vector.y + m13 * z + m14 * w,
m21 * vector.x + m22 * vector.y + m23 * z + m24 * w);
}
template<typename T>
NzVector3<T> NzMatrix4<T>::Transform(const NzVector3<T>& vector, T w) const
{
return NzVector3<T>(m11 * vector.x + m12 * vector.y + m13 * vector.z + m14 * w,
m21 * vector.x + m22 * vector.y + m23 * vector.z + m24 * w,
m31 * vector.x + m32 * vector.y + m33 * vector.z + m34 * w);
}
template<typename T>
NzVector4<T> NzMatrix4<T>::Transform(const NzVector4<T>& vector) const
{
return NzVector4<T>(m11 * vector.x + m12 * vector.y + m13 * vector.z + m14 * vector.w,
m21 * vector.x + m22 * vector.y + m23 * vector.z + m24 * vector.w,
m31 * vector.x + m32 * vector.y + m33 * vector.z + m34 * vector.w,
m41 * vector.x + m42 * vector.y + m43 * vector.z + m44 * vector.w);
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::Transpose()
{
std::swap(m12, m21);
std::swap(m13, m31);
std::swap(m14, m41);
std::swap(m23, m32);
std::swap(m24, m42);
std::swap(m34, m43);
return *this;
}
template<typename T>
NzMatrix4<T>::operator T*()
{
return &m11;
}
template<typename T>
NzMatrix4<T>::operator const T*() const
{
return &m11;
}
template<typename T>
T& NzMatrix4<T>::operator()(unsigned int x, unsigned int y)
{
#if NAZARA_MATH_SAFE
if (x > 3 || y > 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)";
throw std::out_of_range(ss.ToString());
}
#endif
return (&m11)[x*4+y];
}
template<typename T>
const T& NzMatrix4<T>::operator()(unsigned int x, unsigned int y) const
{
#if NAZARA_MATH_SAFE
if (x > 3 || y > 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range: (" << x << ", " << y << ") > (3,3)";
throw std::out_of_range(ss.ToString());
}
#endif
return (&m11)[x*4+y];
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::operator*(const NzMatrix4& mat) const
{
NzMatrix4 matrix;
for(int k = 0; k < 4; k++)
{
for(int j = 0; j < 4; j++)
{
for(int i = 0; i < 4; i++)
matrix(j, k) += (*this)(j, i) * mat(i, k);
}
}
return matrix;
/*return NzMatrix4(m11 * mat.m11 + m21 * mat.m12 + m31 * mat.m13 + m41 * mat.m14,
m12 * mat.m11 + m22 * mat.m12 + m32 * mat.m13 + m42 * mat.m14,
m13 * mat.m11 + m23 * mat.m12 + m33 * mat.m13 + m43 * mat.m14,
m14 * mat.m11 + m24 * mat.m12 + m34 * mat.m13 + m44 * mat.m14,
m11 * mat.m21 + m21 * mat.m22 + m31 * mat.m23 + m41 * mat.m24,
m12 * mat.m21 + m22 * mat.m22 + m32 * mat.m23 + m42 * mat.m24,
m13 * mat.m21 + m23 * mat.m22 + m33 * mat.m23 + m43 * mat.m24,
m14 * mat.m21 + m24 * mat.m22 + m34 * mat.m23 + m44 * mat.m24,
m11 * mat.m31 + m21 * mat.m32 + m31 * mat.m33 + m41 * mat.m34,
m12 * mat.m31 + m22 * mat.m32 + m32 * mat.m33 + m42 * mat.m34,
m13 * mat.m31 + m23 * mat.m32 + m33 * mat.m33 + m43 * mat.m34,
m14 * mat.m31 + m24 * mat.m32 + m34 * mat.m33 + m44 * mat.m34,
m11 * mat.m41 + m21 * mat.m42 + m31 * mat.m43 + m41 * mat.m44,
m12 * mat.m41 + m22 * mat.m42 + m32 * mat.m43 + m42 * mat.m44,
m13 * mat.m41 + m23 * mat.m42 + m33 * mat.m43 + m43 * mat.m44,
m14 * mat.m41 + m24 * mat.m42 + m34 * mat.m43 + m44 * mat.m44);*/
}
template<typename T>
NzVector2<T> NzMatrix4<T>::operator*(const NzVector2<T>& vector) const
{
return Transform(vector);
}
template<typename T>
NzVector3<T> NzMatrix4<T>::operator*(const NzVector3<T>& vector) const
{
return Transform(vector);
}
template<typename T>
NzVector4<T> NzMatrix4<T>::operator*(const NzVector4<T>& vector) const
{
return Transform(vector);
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::operator*(T scalar) const
{
return NzMatrix4(m11 * scalar, m12 * scalar, m13 * scalar, m14 * scalar,
m21 * scalar, m22 * scalar, m23 * scalar, m24 * scalar,
m31 * scalar, m32 * scalar, m33 * scalar, m34 * scalar,
m41 * scalar, m42 * scalar, m43 * scalar, m44 * scalar);
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::operator*=(const NzMatrix4& mat)
{
T r11 = m11 * mat.m11 + m21 * mat.m12 + m31 * mat.m13 + m41 * mat.m14;
T r12 = m12 * mat.m11 + m22 * mat.m12 + m32 * mat.m13 + m42 * mat.m14;
T r13 = m13 * mat.m11 + m23 * mat.m12 + m33 * mat.m13 + m43 * mat.m14;
T r14 = m14 * mat.m11 + m24 * mat.m12 + m34 * mat.m13 + m44 * mat.m14;
T r21 = m11 * mat.m21 + m21 * mat.m22 + m31 * mat.m23 + m41 * mat.m24;
T r22 = m12 * mat.m21 + m22 * mat.m22 + m32 * mat.m23 + m42 * mat.m24;
T r23 = m13 * mat.m21 + m23 * mat.m22 + m33 * mat.m23 + m43 * mat.m24;
T r24 = m14 * mat.m21 + m24 * mat.m22 + m34 * mat.m23 + m44 * mat.m24;
T r31 = m11 * mat.m31 + m21 * mat.m32 + m31 * mat.m33 + m41 * mat.m34;
T r32 = m12 * mat.m31 + m22 * mat.m32 + m32 * mat.m33 + m42 * mat.m34;
T r33 = m13 * mat.m31 + m23 * mat.m32 + m33 * mat.m33 + m43 * mat.m34;
T r34 = m14 * mat.m31 + m24 * mat.m32 + m34 * mat.m33 + m44 * mat.m34;
T r41 = m11 * mat.m41 + m21 * mat.m42 + m31 * mat.m43 + m41 * mat.m44;
T r42 = m12 * mat.m41 + m22 * mat.m42 + m32 * mat.m43 + m42 * mat.m44;
T r43 = m13 * mat.m41 + m23 * mat.m42 + m33 * mat.m43 + m43 * mat.m44;
m44 = m14 * mat.m41 + m24 * mat.m42 + m34 * mat.m43 + m44 * mat.m44;
m43 = r43;
m42 = r42;
m41 = r41;
m34 = r34;
m33 = r33;
m32 = r32;
m31 = r31;
m24 = r24;
m23 = r23;
m22 = r22;
m21 = r21;
m14 = r14;
m13 = r13;
m12 = r12;
m11 = r11;
return *this;
}
template<typename T>
NzMatrix4<T>& NzMatrix4<T>::operator*=(T scalar)
{
m11 *= scalar;
m12 *= scalar;
m13 *= scalar;
m14 *= scalar;
m21 *= scalar;
m22 *= scalar;
m23 *= scalar;
m24 *= scalar;
m31 *= scalar;
m32 *= scalar;
m33 *= scalar;
m34 *= scalar;
m41 *= scalar;
m42 *= scalar;
m43 *= scalar;
m44 *= scalar;
return *this;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::LookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up)
{
NzMatrix4 mat;
mat.SetLookAt(eye, center, up);
return mat;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::Perspective(T angle, T ratio, T zNear, T zFar)
{
NzMatrix4 mat;
mat.SetPerspective(angle, ratio, zNear, zFar);
return mat;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::Rotate(const NzQuaternion<T>& rotation)
{
NzMatrix4 mat;
mat.SetRotation(rotation);
return mat;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::Scale(const NzVector3<T>& scale)
{
NzMatrix4 mat;
mat.SetScale(scale);
return mat;
}
template<typename T>
NzMatrix4<T> NzMatrix4<T>::Translate(const NzVector3<T>& translation)
{
NzMatrix4 mat;
mat.SetTranslation(translation);
return mat;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzMatrix4<T>& mat)
{
return out << mat.ToString();
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,78 @@
// Copyright (C) 2012 Rémi Begues
// Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_QUATERNION_HPP
#define NAZARA_QUATERNION_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzEulerAngles;
template<typename T> class NzVector3;
template<typename T> class NzQuaternion
{
public:
NzQuaternion();
NzQuaternion(T W, T X, T Y, T Z);
NzQuaternion(T quat[4]);
NzQuaternion(T angle, const NzVector3<T>& axis);
NzQuaternion(const NzEulerAngles<T>& angles);
//NzQuaternion(const NzMatrix3<T>& mat);
template<typename U> explicit NzQuaternion(const NzQuaternion<U>& quat);
NzQuaternion(const NzQuaternion& quat) = default;
~NzQuaternion() = default;
NzQuaternion GetConjugate() const;
NzQuaternion GetNormalized() const;
double Magnitude() const;
double Normalize();
T SquaredMagnitude() const;
void Set(T W, T X, T Y, T Z);
void Set(T quat[4]);
void Set(T angle, const NzVector3<T>& normalizedAxis);
void Set(const NzEulerAngles<T>& angles);
//void Set(const NzMatrix3<T>& mat);
void Set(const NzQuaternion& quat);
template<typename U> void Set(const NzQuaternion<U>& quat);
void SetIdentity();
void SetZero();
NzEulerAngles<T> ToEulerAngles() const;
//NzMatrix3<T> ToRotationMatrix() const;
NzString ToString() const;
NzQuaternion operator+(const NzQuaternion& quat) const;
NzQuaternion operator*(const NzQuaternion& quat) const;
NzVector3<T> operator*(const NzVector3<T>& vec) const;
NzQuaternion operator*(T scale) const;
NzQuaternion operator/(const NzQuaternion& quat) const;
NzQuaternion operator+=(const NzQuaternion& quat);
NzQuaternion operator*=(const NzQuaternion& quat);
NzQuaternion operator*=(T scale);
NzQuaternion operator/=(const NzQuaternion& quat);
bool operator==(const NzQuaternion& quat) const;
bool operator!=(const NzQuaternion& quat) const;
bool operator<(const NzQuaternion& quat) const;
bool operator<=(const NzQuaternion& quat) const;
bool operator>(const NzQuaternion& quat) const;
bool operator>=(const NzQuaternion& quat) const;
T w, x, y, z;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzQuaternion<T>& quat);
typedef NzQuaternion<double> NzQuaterniond;
typedef NzQuaternion<float> NzQuaternionf;
#include <Nazara/Math/Quaternion.inl>
#endif // NAZARA_QUATERNION_HPP

View File

@@ -0,0 +1,328 @@
// Copyright (C) 2012 Rémi Begues
// Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Core/Debug.hpp>
template<typename T>
NzQuaternion<T>::NzQuaternion()
{
}
template<typename T>
NzQuaternion<T>::NzQuaternion(T W, T X, T Y, T Z)
{
Set(W, X, Y, Z);
}
template<typename T>
NzQuaternion<T>::NzQuaternion(T quat[4])
{
Set(quat);
}
template<typename T>
NzQuaternion<T>::NzQuaternion(T angle, const NzVector3<T>& axis)
{
Set(angle, axis);
}
template<typename T>
NzQuaternion<T>::NzQuaternion(const NzEulerAngles<T>& angles)
{
Set(angles);
}
/*
template<typename T>
NzQuaternion<T>::NzQuaternion(const NzMatrix3<T>& mat)
{
Set(mat);
}
*/
template<typename T>
template<typename U>
NzQuaternion<T>::NzQuaternion(const NzQuaternion<U>& quat)
{
Set(quat);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::GetConjugate() const
{
return NzQuaternion(w, -x, -y, -z);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::GetNormalized() const
{
NzQuaternion<T> quat(*this);
quat.Normalize();
return quat;
}
template<typename T>
double NzQuaternion<T>::Magnitude() const
{
return std::sqrt(SquaredMagnitude());
}
template<typename T>
double NzQuaternion<T>::Normalize()
{
double length = Magnitude();
if (length != 0.0)
{
w /= length;
x /= length;
y /= length;
z /= length;
}
return length;
}
template<typename T>
T NzQuaternion<T>::SquaredMagnitude() const
{
return w * w + x * x + y * y + z * z;
}
template<typename T>
void NzQuaternion<T>::Set(T W, T X, T Y, T Z)
{
w = W;
x = X;
y = Y;
z = Z;
}
template<typename T>
void NzQuaternion<T>::Set(T quat[4])
{
w = quat[0];
x = quat[1];
y = quat[2];
z = quat[3];
}
template<typename T>
void NzQuaternion<T>::Set(T angle, const NzVector3<T>& normalizedAxis)
{
#if !NAZARA_MATH_ANGLE_RADIAN
angle = NzDegreeToRadian(angle);
#endif
angle /= 2;
auto sinAngle = std::sin(angle);
w = std::cos(angle);
x = normalizedAxis.x * sinAngle;
y = normalizedAxis.y * sinAngle;
z = normalizedAxis.z * sinAngle;
}
template<typename T>
void NzQuaternion<T>::Set(const NzEulerAngles<T>& angles)
{
Set(angles.ToQuaternion());
}
template<typename T>
template<typename U>
void NzQuaternion<T>::Set(const NzQuaternion<U>& quat)
{
w = static_cast<T>(quat.w);
x = static_cast<T>(quat.x);
y = static_cast<T>(quat.y);
z = static_cast<T>(quat.z);
}
template<typename T>
void NzQuaternion<T>::Set(const NzQuaternion& quat)
{
w = quat.w;
x = quat.x;
y = quat.y;
z = quat.z;
}
template<typename T>
void NzQuaternion<T>::SetIdentity()
{
Set(1.0, 0.0, 0.0, 0.0);
}
template<typename T>
void NzQuaternion<T>::SetZero()
{
Set(0.0, 0.0, 0.0, 0.0);
}
template<typename T>
NzEulerAngles<T> NzQuaternion<T>::ToEulerAngles() const
{
T test = x*y + z*w;
if (test > 0.499)
// singularity at north pole
return NzEulerAngles<T>(NzDegrees(90.0), NzRadians(2.0 * std::atan2(x, w)), 0.0);
if (test < -0.499)
return NzEulerAngles<T>(NzDegrees(-90.0), NzRadians(-2.0 * std::atan2(x, w)), 0.0);
T xx = x*x;
T yy = y*y;
T zz = z*z;
return NzEulerAngles<T>(NzRadians(std::atan2(2.0*x*w - 2.0*y*z, 1.0 - 2.0*xx - 2.0*zz)),
NzRadians(std::atan2(2.0*y*w - 2.0*x*z, 1.f - 2.0*yy - 2.0*zz)),
NzRadians(std::asin(2.0*test)));
}
template<typename T>
NzString NzQuaternion<T>::ToString() const
{
NzStringStream ss;
return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')';
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
{
return NzQuaternion(w + quat.w,
x + quat.x,
y + quat.y,
z + quat.z);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator*(const NzQuaternion& quat) const
{
return NzQuaternion(w * quat.w - x * quat.x - y * quat.y - z * quat.z,
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
}
template<typename T>
NzVector3<T> NzQuaternion<T>::operator*(const NzVector3<T>& vec) const
{
NzVector3<T> uv, uuv;
NzVector3<T> qvec(x, y, z);
uv = qvec.CrossProduct(vec);
uuv = qvec.CrossProduct(uv);
uv *= 2.0 * w;
uuv *= 2.0;
return vec + uv + uuv;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator*(T scale) const
{
return NzQuaternion(w * scale,
x * scale,
y * scale,
z * scale);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator/(const NzQuaternion& quat) const
{
return GetConjugate(quat) * (*this);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator+=(const NzQuaternion& quat)
{
w += quat.w;
x += quat.x;
y += quat.y;
z += quat.z;
return *this;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator*=(const NzQuaternion& quat)
{
NzQuaternion q(*this);
operator=(q * quat);
return *this;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator*=(T scale)
{
w *= scale;
x *= scale;
y *= scale;
z *= scale;
return *this;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator/=(const NzQuaternion& quat)
{
NzQuaternion q(*this);
operator=(q / quat);
return *this;
}
template<typename T>
bool NzQuaternion<T>::operator==(const NzQuaternion& quat) const
{
return NzNumberEquals(w, quat.w) &&
NzNumberEquals(x, quat.x) &&
NzNumberEquals(y, quat.y) &&
NzNumberEquals(z, quat.z);
}
template<typename T>
bool NzQuaternion<T>::operator!=(const NzQuaternion& quat) const
{
return !operator==(quat);
}
template<typename T>
bool NzQuaternion<T>::operator<(const NzQuaternion& quat) const
{
return w < quat.w && x < quat.x && y < quat.y && z < quat.z;
}
template<typename T>
bool NzQuaternion<T>::operator<=(const NzQuaternion& quat) const
{
return operator<(quat) || operator==(quat);
}
template<typename T>
bool NzQuaternion<T>::operator>(const NzQuaternion& quat) const
{
return !operator<=(quat);
}
template<typename T>
bool NzQuaternion<T>::operator>=(const NzQuaternion& quat) const
{
return !operator<(quat);
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzQuaternion<T>& quat)
{
return out << quat.ToString();
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,80 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VECTOR2_HPP
#define NAZARA_VECTOR2_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzVector2
{
public:
NzVector2();
NzVector2(T X, T Y);
explicit NzVector2(T scale);
NzVector2(T vec[2]);
template<typename U> explicit NzVector2(const NzVector2<U>& vec);
NzVector2(const NzVector2& vec) = default;
~NzVector2() = default;
T AbsDotProduct(const NzVector2& vec) const;
double Distance(const NzVector2& vec) const;
T DotProduct(const NzVector2& vec) const;
NzVector2 GetNormal() const;
void MakeCeil(const NzVector2& vec);
void MakeFloor(const NzVector2& vec);
double Length() const;
double Normalize();
T SquaredDistance(const NzVector2& vec) const;
T SquaredLength() const;
NzString ToString() const;
operator NzString() const;
T& operator[](unsigned int i);
T operator[](unsigned int i) const;
const NzVector2& operator+() const;
NzVector2 operator-() const;
NzVector2 operator+(const NzVector2& vec) const;
NzVector2 operator-(const NzVector2& vec) const;
NzVector2 operator*(const NzVector2& vec) const;
NzVector2 operator*(T scale) const;
NzVector2 operator/(const NzVector2& vec) const;
NzVector2 operator/(T scale) const;
NzVector2& operator+=(const NzVector2& vec);
NzVector2& operator-=(const NzVector2& vec);
NzVector2& operator*=(const NzVector2& vec);
NzVector2& operator*=(T scale);
NzVector2& operator/=(const NzVector2& vec);
NzVector2& operator/=(T scale);
bool operator==(const NzVector2& vec) const;
bool operator!=(const NzVector2& vec) const;
bool operator<(const NzVector2& vec) const;
bool operator<=(const NzVector2& vec) const;
bool operator>(const NzVector2& vec) const;
bool operator>=(const NzVector2& vec) const;
T x;
T y;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector2<T>& vec);
template<typename T> NzVector2<T> operator*(T scale, const NzVector2<T>& vec);
template<typename T> NzVector2<T> operator/(T scale, const NzVector2<T>& vec);
typedef NzVector2<double> NzVector2d;
typedef NzVector2<float> NzVector2f;
typedef NzVector2<int> NzVector2i;
#include <Nazara/Math/Vector2.inl>
#endif // NAZARA_VECTOR2_HPP

View File

@@ -0,0 +1,369 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
template<typename T>
NzVector2<T>::NzVector2()
{
}
template<typename T>
NzVector2<T>::NzVector2(T X, T Y) :
x(X),
y(Y)
{
}
template<typename T>
NzVector2<T>::NzVector2(T scale) :
x(scale),
y(scale)
{
}
template<typename T>
NzVector2<T>::NzVector2(T vec[2]) :
x(vec[0]),
y(vec[1])
{
}
template<typename T>
template<typename U>
NzVector2<T>::NzVector2(const NzVector2<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y))
{
}
template<typename T>
T NzVector2<T>::AbsDotProduct(const NzVector2& vec) const
{
return std::fabs(x * vec.x) + std::fabs(y * vec.y);
}
template<> inline int NzVector2<int>::AbsDotProduct(const NzVector2<int>& vec) const
{
return std::labs(x * vec.x) + std::labs(y * vec.y);
}
template<typename T>
double NzVector2<T>::Distance(const NzVector2& vec) const
{
return std::sqrt(SquaredDistance(vec));
}
template<typename T>
T NzVector2<T>::DotProduct(const NzVector2& vec) const
{
return x * vec.x + y * vec.y;
}
template<typename T>
NzVector2<T> NzVector2<T>::GetNormal() const
{
NzVector2 vec(*this);
vec.Normalize();
return vec;
}
template<typename T>
void NzVector2<T>::MakeCeil(const NzVector2& vec)
{
if (vec.x > x)
x = vec.x;
if (vec.y > y)
y = vec.y;
}
template<typename T>
void NzVector2<T>::MakeFloor(const NzVector2& vec)
{
if (vec.x < x)
x = vec.x;
if (vec.y < y)
y = vec.y;
}
template<typename T>
double NzVector2<T>::Length() const
{
return std::sqrt(SquaredLength());
}
template<typename T>
double NzVector2<T>::Normalize()
{
double length = Length();
if (length != 0.f)
{
x /= length;
y /= length;
}
return length;
}
template<typename T>
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
{
return operator-(vec).SquaredLength();
}
template<typename T>
T NzVector2<T>::SquaredLength() const
{
return x * x + y * y;
}
template<typename T>
NzString NzVector2<T>::ToString() const
{
NzStringStream ss;
return ss << "Vector2(" << x << ", " << y << ')';
}
template<typename T>
NzVector2<T>::operator NzString() const
{
return ToString();
}
template<typename T>
T& NzVector2<T>::operator[](unsigned int i)
{
if (i >= 2)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)";
throw std::domain_error(ss.ToString());
}
return *(&x+i);
}
template<typename T>
T NzVector2<T>::operator[](unsigned int i) const
{
if (i >= 2)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 2)";
throw std::domain_error(ss.ToString());
}
return *(&x+i);
}
template<typename T>
const NzVector2<T>& NzVector2<T>::operator+() const
{
return *this;
}
template<typename T>
NzVector2<T> NzVector2<T>::operator-() const
{
return NzVector2(-x, -y);
}
template<typename T>
NzVector2<T> NzVector2<T>::operator+(const NzVector2& vec) const
{
return NzVector2(x + vec.x, y + vec.y);
}
template<typename T>
NzVector2<T> NzVector2<T>::operator-(const NzVector2& vec) const
{
return NzVector2(x - vec.x, y - vec.y);
}
template<typename T>
NzVector2<T> NzVector2<T>::operator*(const NzVector2& vec) const
{
return NzVector2(x * vec.x, y * vec.y);
}
template<typename T>
NzVector2<T> NzVector2<T>::operator*(T scale) const
{
return NzVector2(x * scale, y * scale);
}
template<typename T>
NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
{
if (vec.x == 0.f || vec.y == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector2(x / vec.x, y / vec.y);
}
template<typename T>
NzVector2<T> NzVector2<T>::operator/(T scale) const
{
if (scale == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector2(x / scale, y / scale);
}
template<typename T>
NzVector2<T>& NzVector2<T>::operator+=(const NzVector2& vec)
{
x += vec.x;
y += vec.y;
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::operator-=(const NzVector2& vec)
{
x -= vec.x;
y -= vec.y;
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::operator*=(const NzVector2& vec)
{
x *= vec.x;
y *= vec.y;
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::operator*=(T scale)
{
x *= scale;
y *= scale;
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
{
if (vec.x == 0.f || vec.y == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
x /= vec.x;
y /= vec.y;
return *this;
}
template<typename T>
NzVector2<T>& NzVector2<T>::operator/=(T scale)
{
if (scale == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
x /= scale;
y /= scale;
return *this;
}
template<typename T>
bool NzVector2<T>::operator==(const NzVector2& vec) const
{
return NzNumberEquals(x, vec.x) &&
NzNumberEquals(y, vec.y);
}
template<typename T>
bool NzVector2<T>::operator!=(const NzVector2& vec) const
{
return !operator==(vec);
}
template<typename T>
bool NzVector2<T>::operator<(const NzVector2& vec) const
{
return x < vec.x && y < vec.y;
}
template<typename T>
bool NzVector2<T>::operator<=(const NzVector2& vec) const
{
return operator<(vec) || operator==(vec);
}
template<typename T>
bool NzVector2<T>::operator>(const NzVector2& vec) const
{
return !operator<=(vec);
}
template<typename T>
bool NzVector2<T>::operator>=(const NzVector2& vec) const
{
return !operator<(vec);
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector2<T>& vec)
{
return out << vec.ToString();
}
template<typename T>
NzVector2<T> operator*(T scale, const NzVector2<T>& vec)
{
return NzVector2<T>(scale * vec.x, scale * vec.y);
}
template<typename T>
NzVector2<T> operator/(T scale, const NzVector2<T>& vec)
{
if (vec.x == 0.f || vec.y == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector2<T>(scale/vec.x, scale/vec.y);
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,82 @@
// Copyright (C) 2012 Rémi Begues
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VECTOR3_HPP
#define NAZARA_VECTOR3_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzVector3
{
public:
NzVector3();
NzVector3(T X, T Y, T Z);
explicit NzVector3(T scale);
NzVector3(T vec[3]);
template<typename U> explicit NzVector3(const NzVector3<U>& vec);
NzVector3(const NzVector3& vec) = default;
~NzVector3() = default;
T AbsDotProduct(const NzVector3& vec) const;
NzVector3 CrossProduct(const NzVector3& vec) const;
double Distance(const NzVector3& vec) const;
T DotProduct(const NzVector3& vec) const;
NzVector3 GetNormal() const;
void MakeCeil(const NzVector3& vec);
void MakeFloor(const NzVector3& vec);
double Length() const;
double Normalize();
T SquaredDistance(const NzVector3& vec) const;
T SquaredLength() const;
NzString ToString() const;
operator NzString() const;
T& operator[](unsigned int i);
T operator[](unsigned int i) const;
const NzVector3& operator+() const;
NzVector3 operator-() const;
NzVector3 operator+(const NzVector3& vec) const;
NzVector3 operator-(const NzVector3& vec) const;
NzVector3 operator*(const NzVector3& vec) const;
NzVector3 operator*(T scale) const;
NzVector3 operator/(const NzVector3& vec) const;
NzVector3 operator/(T scale) const;
NzVector3& operator+=(const NzVector3& vec);
NzVector3& operator-=(const NzVector3& vec);
NzVector3& operator*=(const NzVector3& vec);
NzVector3& operator*=(T scale);
NzVector3& operator/=(const NzVector3& vec);
NzVector3& operator/=(T scale);
bool operator==(const NzVector3& vec) const;
bool operator!=(const NzVector3& vec) const;
bool operator<(const NzVector3& vec) const;
bool operator<=(const NzVector3& vec) const;
bool operator>(const NzVector3& vec) const;
bool operator>=(const NzVector3& vec) const;
T x;
T y;
T z;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec);
template<typename T> NzVector3<T> operator*(T scale, const NzVector3<T>& vec);
template<typename T> NzVector3<T> operator/(T scale, const NzVector3<T>& vec);
typedef NzVector3<double> NzVector3d;
typedef NzVector3<float> NzVector3f;
typedef NzVector3<int> NzVector3i;
#include <Nazara/Math/Vector3.inl>
#endif // NAZARA_VECTOR3_HPP

View File

@@ -0,0 +1,393 @@
// Copyright (C) 2012 Rémi Begues
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
template<typename T>
NzVector3<T>::NzVector3()
{
}
template<typename T>
NzVector3<T>::NzVector3(T X, T Y, T Z) :
x(X),
y(Y),
z(Z)
{
}
template<typename T>
NzVector3<T>::NzVector3(T scale) :
x(scale),
y(scale),
z(scale)
{
}
template<typename T>
NzVector3<T>::NzVector3(T vec[3]) :
x(vec[0]),
y(vec[1]),
z(vec[2])
{
}
template<typename T>
template<typename U>
NzVector3<T>::NzVector3(const NzVector3<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y)),
z(static_cast<T>(vec.z))
{
}
template<typename T>
T NzVector3<T>::AbsDotProduct(const NzVector3& vec) const
{
return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z);
}
template<> inline int NzVector3<int>::AbsDotProduct(const NzVector3<int>& vec) const
{
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z);
}
template<typename T>
NzVector3<T> NzVector3<T>::CrossProduct(const NzVector3& vec) const
{
return NzVector3(y * vec.z - z * vec.y, z * vec.x - x * vec.y, x * vec.y - y * vec.x);
}
template<typename T>
double NzVector3<T>::Distance(const NzVector3& vec) const
{
return std::sqrt(SquaredDistance(vec));
}
template<typename T>
T NzVector3<T>::DotProduct(const NzVector3& vec) const
{
return x * vec.x + y * vec.y + z * vec.z;
}
template<typename T>
NzVector3<T> NzVector3<T>::GetNormal() const
{
NzVector3 vec(*this);
vec.Normalize();
return vec;
}
template<typename T>
void NzVector3<T>::MakeCeil(const NzVector3& vec)
{
if (vec.x > x)
x = vec.x;
if (vec.y > y)
y = vec.y;
if (vec.z > z)
z = vec.z;
}
template<typename T>
void NzVector3<T>::MakeFloor(const NzVector3& vec)
{
if (vec.x < x)
x = vec.x;
if (vec.y < y)
y = vec.y;
if (vec.z < z)
z = vec.z;
}
template<typename T>
double NzVector3<T>::Length() const
{
return std::sqrt(SquaredLength());
}
template<typename T>
double NzVector3<T>::Normalize()
{
double length = Length();
if (length != 0.f)
{
x /= length;
y /= length;
z /= length;
}
return length;
}
template<typename T>
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
{
return operator-(vec).SquaredLength();
}
template<typename T>
T NzVector3<T>::SquaredLength() const
{
return x * x + y * y + z * z;
}
template<typename T>
NzString NzVector3<T>::ToString() const
{
NzStringStream ss;
return ss << "Vector3(" << x << ", " << y << ", " << z <<')';
}
template<typename T>
NzVector3<T>::operator NzString() const
{
return ToString();
}
template<typename T>
T& NzVector3<T>::operator[](unsigned int i)
{
if (i >= 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
throw std::domain_error(ss.ToString());
}
return *(&x+i);
}
template<typename T>
T NzVector3<T>::operator[](unsigned int i) const
{
if (i >= 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
throw std::domain_error(ss.ToString());
}
return *(&x+i);
}
template<typename T>
const NzVector3<T>& NzVector3<T>::operator+() const
{
return *this;
}
template<typename T>
NzVector3<T> NzVector3<T>::operator-() const
{
return NzVector3(-x, -y, -z);
}
template<typename T>
NzVector3<T> NzVector3<T>::operator+(const NzVector3& vec) const
{
return NzVector3(x + vec.x, y + vec.y, z + vec.z);
}
template<typename T>
NzVector3<T> NzVector3<T>::operator-(const NzVector3& vec) const
{
return NzVector3(x - vec.x, y - vec.y, z - vec.z);
}
template<typename T>
NzVector3<T> NzVector3<T>::operator*(const NzVector3& vec) const
{
return NzVector3(x * vec.x, y * vec.y, z * vec.z);
}
template<typename T>
NzVector3<T> NzVector3<T>::operator*(T scale) const
{
return NzVector3(x * scale, y * scale, z * scale);
}
template<typename T>
NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
{
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector3(x / vec.x, y / vec.y, z / vec.z);
}
template<typename T>
NzVector3<T> NzVector3<T>::operator/(T scale) const
{
if (scale == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector3(x / scale, y / scale, z / scale);
}
template<typename T>
NzVector3<T>& NzVector3<T>::operator+=(const NzVector3& vec)
{
x += vec.x;
y += vec.y;
z += vec.z;
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::operator-=(const NzVector3& vec)
{
x -= vec.x;
y -= vec.y;
z -= vec.z;
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::operator*=(const NzVector3& vec)
{
x *= vec.x;
y *= vec.y;
z *= vec.z;
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::operator*=(T scale)
{
x *= scale;
y *= scale;
z *= scale;
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
{
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
x /= vec.x;
y /= vec.y;
z /= vec.z;
return *this;
}
template<typename T>
NzVector3<T>& NzVector3<T>::operator/=(T scale)
{
if (scale == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
x /= scale;
y /= scale;
z /= scale;
return *this;
}
template<typename T>
bool NzVector3<T>::operator==(const NzVector3& vec) const
{
return NzNumberEquals(x, vec.x) &&
NzNumberEquals(y, vec.y) &&
NzNumberEquals(z, vec.z);
}
template<typename T>
bool NzVector3<T>::operator!=(const NzVector3& vec) const
{
return !operator==(vec);
}
template<typename T>
bool NzVector3<T>::operator<(const NzVector3& vec) const
{
return x < vec.x && y < vec.y && z < vec.z;
}
template<typename T>
bool NzVector3<T>::operator<=(const NzVector3& vec) const
{
return operator<(vec) || operator==(vec);
}
template<typename T>
bool NzVector3<T>::operator>(const NzVector3& vec) const
{
return !operator<=(vec);
}
template<typename T>
bool NzVector3<T>::operator>=(const NzVector3& vec) const
{
return !operator<(vec);
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec)
{
return out << vec.ToString();
}
template<typename T>
NzVector3<T> operator*(T scale, const NzVector3<T>& vec)
{
return NzVector3<T>(scale * vec.x, scale * vec.y, scale * vec.z);
}
template<typename T>
NzVector3<T> operator/(T scale, const NzVector3<T>& vec)
{
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,77 @@
// Copyright (C) 2012 Rémi Begues
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VECTOR4_HPP
#define NAZARA_VECTOR4_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzVector4
{
public:
NzVector4();
NzVector4(T X, T Y, T Z, T W = 1.0);
explicit NzVector4(T scale);
NzVector4(T vec[4]);
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
NzVector4(const NzVector4& vec) = default;
~NzVector4() = default;
T AbsDotProduct(const NzVector4& vec) const;
T DotProduct(const NzVector4& vec) const;
void MakeCeil(const NzVector4& vec);
void MakeFloor(const NzVector4& vec);
void Normalize();
NzString ToString() const;
operator NzString() const;
T& operator[](unsigned int i);
T operator[](unsigned int i) const;
const NzVector4& operator+() const;
NzVector4 operator-() const;
NzVector4 operator+(const NzVector4& vec) const;
NzVector4 operator-(const NzVector4& vec) const;
NzVector4 operator*(const NzVector4& vec) const;
NzVector4 operator*(T scale) const;
NzVector4 operator/(const NzVector4& vec) const;
NzVector4 operator/(T scale) const;
NzVector4& operator+=(const NzVector4& vec);
NzVector4& operator-=(const NzVector4& vec);
NzVector4& operator*=(const NzVector4& vec);
NzVector4& operator*=(T scale);
NzVector4& operator/=(const NzVector4& vec);
NzVector4& operator/=(T scale);
bool operator==(const NzVector4& vec) const;
bool operator!=(const NzVector4& vec) const;
bool operator<(const NzVector4& vec) const;
bool operator<=(const NzVector4& vec) const;
bool operator>(const NzVector4& vec) const;
bool operator>=(const NzVector4& vec) const;
T x;
T y;
T z;
T w;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector4<T>& vec);
template<typename T> NzVector4<T> operator*(T scale, const NzVector4<T>& vec);
template<typename T> NzVector4<T> operator/(T scale, const NzVector4<T>& vec);
typedef NzVector4<double> NzVector4d;
typedef NzVector4<float> NzVector4f;
typedef NzVector4<int> NzVector4i;
#include <Nazara/Math/Vector4.inl>
#endif // NAZARA_VECTOR4_HPP

View File

@@ -0,0 +1,367 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
template<typename T>
NzVector4<T>::NzVector4()
{
}
template<typename T>
NzVector4<T>::NzVector4(T X, T Y, T Z, T W) :
x(X),
y(Y),
z(Z),
w(W)
{
}
template<typename T>
NzVector4<T>::NzVector4(T scale) :
x(scale),
y(scale),
z(scale),
w(scale)
{
}
template<typename T>
NzVector4<T>::NzVector4(T vec[4]) :
x(vec[0]),
y(vec[1]),
z(vec[2]),
w(vec[3])
{
}
template<typename T>
template<typename U>
NzVector4<T>::NzVector4(const NzVector4<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y)),
z(static_cast<T>(vec.z)),
w(static_cast<T>(vec.w))
{
}
template<typename T>
T NzVector4<T>::AbsDotProduct(const NzVector4& vec) const
{
return std::fabs(x * vec.x) + std::fabs(y * vec.y) + std::fabs(z * vec.z) + std::fabs(w * vec.w);
}
template<> inline int NzVector4<int>::AbsDotProduct(const NzVector4<int>& vec) const
{
return std::labs(x * vec.x) + std::labs(y * vec.y) + std::labs(z * vec.z) + std::labs(w * vec.w);
}
template<typename T>
T NzVector4<T>::DotProduct(const NzVector4& vec) const
{
return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
}
template<typename T>
void NzVector4<T>::MakeCeil(const NzVector4& vec)
{
if (vec.x > x)
x = vec.x;
if (vec.y > y)
y = vec.y;
if (vec.z > z)
z = vec.z;
if (vec.w > w)
w = vec.w;
}
template<typename T>
void NzVector4<T>::MakeFloor(const NzVector4& vec)
{
if (vec.x < x)
x = vec.x;
if (vec.y < y)
y = vec.y;
if (vec.z < z)
z = vec.z;
if (vec.w < w)
w = vec.w;
}
template<typename T>
void NzVector4<T>::Normalize()
{
if (w != 0.f)
{
x /= w;
y /= w;
z /= w;
}
}
template<typename T>
NzString NzVector4<T>::ToString() const
{
NzStringStream ss;
return ss << "Vector4(" << x << ", " << y << ", " << z <<')';
}
template<typename T>
NzVector4<T>::operator NzString() const
{
return ToString();
}
template<typename T>
T& NzVector4<T>::operator[](unsigned int i)
{
if (i >= 4)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
throw std::domain_error(ss.ToString());
}
return *(&x+i);
}
template<typename T>
T NzVector4<T>::operator[](unsigned int i) const
{
if (i >= 4)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
throw std::domain_error(ss.ToString());
}
return *(&x+i);
}
template<typename T>
const NzVector4<T>& NzVector4<T>::operator+() const
{
return *this;
}
template<typename T>
NzVector4<T> NzVector4<T>::operator-() const
{
return NzVector4(-x, -y, -z, -w);
}
template<typename T>
NzVector4<T> NzVector4<T>::operator+(const NzVector4& vec) const
{
return NzVector4(x + vec.x, y + vec.y, z + vec.z, w + vec.w);
}
template<typename T>
NzVector4<T> NzVector4<T>::operator-(const NzVector4& vec) const
{
return NzVector4(x - vec.x, y - vec.y, z - vec.z);
}
template<typename T>
NzVector4<T> NzVector4<T>::operator*(const NzVector4& vec) const
{
return NzVector4(x * vec.x, y * vec.y, z * vec.z, w * vec.w);
}
template<typename T>
NzVector4<T> NzVector4<T>::operator*(T scale) const
{
return NzVector4(x * scale, y * scale, z * scale, w * scale);
}
template<typename T>
NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
{
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f || vec.w == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w);
}
template<typename T>
NzVector4<T> NzVector4<T>::operator/(T scale) const
{
if (scale == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector4(x / scale, y / scale, z / scale, w / scale);
}
template<typename T>
NzVector4<T>& NzVector4<T>::operator+=(const NzVector4& vec)
{
x += vec.x;
y += vec.y;
z += vec.z;
w += vec.w;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::operator-=(const NzVector4& vec)
{
x -= vec.x;
y -= vec.y;
z -= vec.z;
w -= vec.w;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::operator*=(const NzVector4& vec)
{
x *= vec.x;
y *= vec.y;
z *= vec.z;
w *= vec.w;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::operator*=(T scale)
{
x *= scale;
y *= scale;
z *= scale;
w *= scale;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
{
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f || vec.w == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
x /= vec.x;
y /= vec.y;
z /= vec.z;
w /= vec.w;
return *this;
}
template<typename T>
NzVector4<T>& NzVector4<T>::operator/=(T scale)
{
if (scale == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
x /= scale;
y /= scale;
z /= scale;
w /= scale;
return *this;
}
template<typename T>
bool NzVector4<T>::operator==(const NzVector4& vec) const
{
return NzNumberEquals(x, vec.x) &&
NzNumberEquals(y, vec.y) &&
NzNumberEquals(z, vec.z) &&
NzNumberEquals(w, vec.w);
}
template<typename T>
bool NzVector4<T>::operator!=(const NzVector4& vec) const
{
return !operator==(vec);
}
template<typename T>
bool NzVector4<T>::operator<(const NzVector4& vec) const
{
return x < vec.x && y < vec.y && z < vec.z && w < vec.w;
}
template<typename T>
bool NzVector4<T>::operator<=(const NzVector4& vec) const
{
return operator<(vec) || operator==(vec);
}
template<typename T>
bool NzVector4<T>::operator>(const NzVector4& vec) const
{
return !operator<=(vec);
}
template<typename T>
bool NzVector4<T>::operator>=(const NzVector4& vec) const
{
return !operator<(vec);
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector4<T>& vec)
{
return out << vec.ToString();
}
template<typename T>
NzVector4<T> operator*(T scale, const NzVector4<T>& vec)
{
return NzVector4<T>(scale * vec.x, scale * vec.y, scale * vec.z, scale * vec.w);
}
template<typename T>
NzVector4<T> operator/(T scale, const NzVector4<T>& vec)
{
if (vec.x == 0.f || vec.y == 0.f || vec.z == 0.f || vec.w == 0.f)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
return NzVector3<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -0,0 +1,35 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_NETWORK_HPP
#define NAZARA_CONFIG_NETWORK_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_NETWORK_MEMORYLEAKTRACKER 0
#endif // NAZARA_CONFIG_NETWORK_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/Config.hpp>
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,112 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_PREREQUESITES_HPP
#define NAZARA_PREREQUESITES_HPP
// Version du moteur
#define NAZARA_VERSION_MAJOR 0
#define NAZARA_VERSION_MINOR 1
// (Commenté en attendant GCC 4.7)
/*#if __cplusplus < 201103L
#error Nazara requires a C++11 compliant compiler
#endif*/
///TODO: Rajouter des tests d'identification de compilateurs
#if defined(_MSC_VER)
#define NAZARA_COMPILER_MSVC
#define NAZARA_DEPRECATED(txt) __declspec(deprecated(txt))
#define NAZARA_FUNCTION __FUNCSIG__
#elif defined(__GNUC__)
#define NAZARA_COMPILER_GCC
#define NAZARA_FUNCTION __PRETTY_FUNCTION__
#define NAZARA_DEPRECATED(txt) __attribute__((__deprecated__(txt)))
#elif defined(__BORLANDC__)
#define NAZARA_COMPILER_BORDLAND
#define NAZARA_DEPRECATED(txt)
#define NAZARA_FUNCTION __FUNC__
#else
#define NAZARA_COMPILER_UNKNOWN
#define NAZARA_DEPRECATED(txt)
#define NAZARA_FUNCTION __func__ // __func__ est standard depuis le C++11
#error This compiler is not fully supported
#endif
#define NazaraUnused(a) (void) a
#if defined(_WIN32) || defined(__WIN32__) || defined(NAZARA_PLATFORM_WINDOWSVISTA)
#if !defined(NAZARA_STATIC)
#ifdef NAZARA_BUILD
#define NAZARA_API __declspec(dllexport)
#else
#define NAZARA_API __declspec(dllimport)
#endif
#else
#define NAZARA_API
#endif
#define NAZARA_PLATFORM_WINDOWS
// Des defines pour le header Windows
#if defined(NAZARA_BUILD) // Pour ne pas entrer en conflit avec les defines de l'application ou d'une autre bibliothèque
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifndef _WIN32_WINNT
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
#define _WIN32_WINNT 0x0600 // Version de Windows minimale : Vista
#else
#define _WIN32_WINNT 0x0501 // Version de Windows minimale : XP
#endif
#endif
#endif
#elif defined(linux) || defined(__linux)
#if !defined(NAZARA_STATIC) && defined(NAZARA_COMPILER_GCC)
#define NAZARA_API __attribute__((visibility ("default")))
#else
#define NAZARA_API
#endif
#define NAZARA_PLATFORM_LINUX
#define NAZARA_PLATFORM_POSIX
/*#elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || defined(Macintosh)
#define NAZARA_API
#define NAZARA_PLATFORM_MACOS
#define NAZARA_PLATFORM_POSIX
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
#define NAZARA_API
#define NAZARA_PLATFORM_FREEBSD
#define NAZARA_PLATFORM_POSIX*/
#else
// À commenter pour tenter quand même une compilation
#error This operating system is not fully supported by the Nazara Engine
#define NAZARA_PLATFORM_UNKNOWN
#define NAZARA_API
#endif
#if !defined(NAZARA_DEBUG) && !defined(NDEBUG)
#define NDEBUG
#endif
#include <cstdint>
typedef int8_t nzInt8;
typedef uint8_t nzUInt8;
typedef int16_t nzInt16;
typedef uint16_t nzUInt16;
typedef int32_t nzInt32;
typedef uint32_t nzUInt32;
typedef int64_t nzInt64;
typedef uint64_t nzUInt64;
#endif // NAZARA_PREREQUESITES_HPP

View File

@@ -0,0 +1,82 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_BUFFER_HPP
#define NAZARA_BUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/Resource.hpp>
enum nzBufferLock
{
nzBufferLock_DiscardAndWrite,
nzBufferLock_ReadOnly,
nzBufferLock_ReadWrite,
nzBufferLock_WriteOnly
};
enum nzBufferStorage
{
nzBufferStorage_Hardware,
nzBufferStorage_Software
};
enum nzBufferType
{
nzBufferType_Index,
nzBufferType_Vertex
};
enum nzBufferUsage
{
nzBufferUsage_Dynamic,
nzBufferUsage_Static
};
class NzBufferImpl;
class NzRenderer;
class NAZARA_API NzBuffer : public NzResource
{
friend class NzRenderer;
public:
NzBuffer(nzBufferType type);
NzBuffer(nzBufferType type, unsigned int length, nzUInt8 typeSize, nzBufferUsage usage = nzBufferUsage_Static);
~NzBuffer();
bool CopyContent(NzBuffer& buffer);
bool Create(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage = nzBufferUsage_Static);
void Destroy();
bool Fill(const void* data, unsigned int offset, unsigned int length);
unsigned int GetLength() const;
unsigned int GetSize() const;
nzBufferStorage GetStorage() const;
nzBufferType GetType() const;
nzUInt8 GetTypeSize() const;
nzBufferUsage GetUsage() const;
bool IsHardware() const;
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
bool Unlock();
static bool IsHardwareSupported();
private:
nzBufferStorage m_storage;
nzBufferType m_type;
nzBufferUsage m_usage;
nzUInt8 m_typeSize;
NzBufferImpl* m_impl;
unsigned int m_length;
};
#endif // NAZARA_BUFFER_HPP

View File

@@ -0,0 +1,47 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_RENDERER_HPP
#define NAZARA_CONFIG_RENDERER_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Active une fenêtre de rendu (NzRenderWindow) lors de sa création
#define NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION 1
// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes)
#define NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_RENDERER_SAFE 1
// Fait en sorte que le Renderer soit un singleton plutôt qu'une instance globale
#define NAZARA_RENDERER_SINGLETON 0
#endif // NAZARA_CONFIG_MODULENAME_HPP

View File

@@ -0,0 +1,44 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifdef NAZARA_RENDERER_COMMON
#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it
#endif
#pragma once
#ifndef NAZARA_CONTEXT_HPP
#define NAZARA_CONTEXT_HPP
#include <Nazara/Renderer/ContextParameters.hpp>
class NzContextImpl;
class NAZARA_API NzContext
{
friend class NzContextImpl;
public:
NzContext();
~NzContext();
bool Create(const NzContextParameters& parameters = NzContextParameters());
const NzContextParameters& GetParameters() const;
bool IsActive() const;
bool SetActive(bool active);
void SwapBuffers();
static const NzContext* GetCurrent();
static const NzContext* GetReference();
static bool InitializeReference();
static void UninitializeReference();
private:
NzContextParameters m_parameters;
NzContextImpl* m_impl;
static NzContext* s_reference;
};
#endif // NAZARA_CONTEXT_HPP

View File

@@ -0,0 +1,54 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONTEXTPARAMETERS_HPP
#define NAZARA_CONTEXTPARAMETERS_HPP
#include <Nazara/Renderer/RenderTargetParameters.hpp>
#include <Nazara/Utility/VideoMode.hpp>
#include <Nazara/Utility/WindowHandle.hpp>
class NzContext;
struct NAZARA_API NzContextParameters
{
NzContextParameters(const NzRenderTargetParameters& parameters = NzRenderTargetParameters()) :
antialiasingLevel(parameters.antialiasingLevel),
bitsPerPixel(NzVideoMode::GetDesktopMode().bitsPerPixel),
depthBits(parameters.depthBits),
majorVersion(defaultMajorVersion),
minorVersion(defaultMinorVersion),
stencilBits(parameters.stencilBits),
shareContext(defaultShareContext),
window(defaultWindow),
compatibilityProfile(defaultCompatibilityProfile),
doubleBuffered(defaultDoubleBuffered),
shared(defaultShared)
{
}
nzUInt8 antialiasingLevel;
nzUInt8 bitsPerPixel;
nzUInt8 depthBits;
nzUInt8 majorVersion;
nzUInt8 minorVersion;
nzUInt8 stencilBits;
const NzContext* shareContext;
NzWindowHandle window;
bool compatibilityProfile;
bool doubleBuffered;
bool shared;
static nzUInt8 defaultMajorVersion;
static nzUInt8 defaultMinorVersion;
static const NzContext* defaultShareContext;
static NzWindowHandle defaultWindow;
static bool defaultCompatibilityProfile;
static bool defaultDoubleBuffered;
static bool defaultShared;
};
#endif // NAZARA_CONTEXTPARAMETERS_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/Config.hpp>
#if NAZARA_RENDERER_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_RENDERER_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,41 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_INDEXBUFFER_HPP
#define NAZARA_INDEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Buffer.hpp>
class NAZARA_API NzIndexBuffer
{
public:
NzIndexBuffer(NzBuffer* buffer, unsigned int startIndex, unsigned int indexCount);
NzIndexBuffer(unsigned int length, nzUInt8 indexSize, nzBufferUsage usage = nzBufferUsage_Static);
NzIndexBuffer(const NzIndexBuffer& indexBuffer);
~NzIndexBuffer();
bool Fill(const void* data, unsigned int offset, unsigned int length);
NzBuffer* GetBuffer() const;
nzUInt8 GetIndexSize() const;
unsigned int GetIndexCount() const;
unsigned int GetStartIndex() const;
bool IsHardware() const;
bool IsSequential() const;
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
bool Unlock();
private:
NzBuffer* m_buffer;
bool m_ownsBuffer;
unsigned int m_indexCount;
unsigned int m_startIndex;
};
#endif // NAZARA_INDEXBUFFER_HPP

View File

@@ -0,0 +1,159 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifdef NAZARA_RENDERER_COMMON
#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it
#endif
#pragma once
#ifndef NAZARA_OPENGL_HPP
#define NAZARA_OPENGL_HPP
// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier
#include <GL3/gl3.h>
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
// Il semblerait qu'il ne soit pas conseillé d'inclure gl3.h t glext.h en même temps, mais je ne vois pas oomment gérer les extensions autrement...
#include <GLext/glext.h>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <GLext/wglext.h>
#elif defined(NAZARA_PLATFORM_LINUX)
#include <GLext/glxext.h>
#else
#error OS not handled
#endif
typedef void (*NzOpenGLFunc)();
class NAZARA_API NzOpenGL
{
public:
enum Extension
{
AnisotropicFilter,
FP64,
Framebuffer_Object,
Occlusion_Query,
Texture3D,
Count
};
static unsigned int GetVersion();
static bool Initialize();
static bool IsSupported(Extension extension);
static bool IsSupported(const NzString& string);
static void Uninitialize();
};
NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture;
NAZARA_API extern PFNGLATTACHSHADERPROC glAttachShader;
NAZARA_API extern PFNGLBEGINQUERYPROC glBeginQuery;
NAZARA_API extern PFNGLBINDATTRIBLOCATIONPROC glBindAttribLocation;
NAZARA_API extern PFNGLBINDBUFFERPROC glBindBuffer;
NAZARA_API extern PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
NAZARA_API extern PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
NAZARA_API extern PFNGLBINDTEXTUREPROC glBindTexture;
NAZARA_API extern PFNGLBLENDFUNCPROC glBlendFunc;
NAZARA_API extern PFNGLBUFFERDATAPROC glBufferData;
NAZARA_API extern PFNGLBUFFERSUBDATAPROC glBufferSubData;
NAZARA_API extern PFNGLCLEARPROC glClear;
NAZARA_API extern PFNGLCLEARCOLORPROC glClearColor;
NAZARA_API extern PFNGLCLEARDEPTHPROC glClearDepth;
NAZARA_API extern PFNGLCLEARSTENCILPROC glClearStencil;
NAZARA_API extern PFNGLCREATEPROGRAMPROC glCreateProgram;
NAZARA_API extern PFNGLCREATESHADERPROC glCreateShader;
NAZARA_API extern PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
NAZARA_API extern PFNGLCOLORMASKPROC glColorMask;
NAZARA_API extern PFNGLCULLFACEPROC glCullFace;
NAZARA_API extern PFNGLCOMPILESHADERPROC glCompileShader;
NAZARA_API extern PFNGLDELETEBUFFERSPROC glDeleteBuffers;
NAZARA_API extern PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
NAZARA_API extern PFNGLDELETEPROGRAMPROC glDeleteProgram;
NAZARA_API extern PFNGLDELETEQUERIESPROC glDeleteQueries;
NAZARA_API extern PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
NAZARA_API extern PFNGLDELETESHADERPROC glDeleteShader;
NAZARA_API extern PFNGLDELETETEXTURESPROC glDeleteTextures;
NAZARA_API extern PFNGLDEPTHFUNCPROC glDepthFunc;
NAZARA_API extern PFNGLDEPTHMASKPROC glDepthMask;
NAZARA_API extern PFNGLDISABLEPROC glDisable;
NAZARA_API extern PFNGLDISABLEVERTEXATTRIBARRAYPROC glDisableVertexAttribArray;
NAZARA_API extern PFNGLDRAWARRAYSPROC glDrawArrays;
NAZARA_API extern PFNGLDRAWBUFFERPROC glDrawBuffer;
NAZARA_API extern PFNGLDRAWBUFFERSPROC glDrawBuffers;
NAZARA_API extern PFNGLDRAWELEMENTSPROC glDrawElements;
NAZARA_API extern PFNGLENDQUERYPROC glEndQuery;
NAZARA_API extern PFNGLFLUSHPROC glFlush;
NAZARA_API extern PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
NAZARA_API extern PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D;
NAZARA_API extern PFNGLENABLEPROC glEnable;
NAZARA_API extern PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
NAZARA_API extern PFNGLGENERATEMIPMAPPROC glGenerateMipmap;
NAZARA_API extern PFNGLGENBUFFERSPROC glGenBuffers;
NAZARA_API extern PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
NAZARA_API extern PFNGLGENQUERIESPROC glGenQueries;
NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures;
NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv;
NAZARA_API extern PFNGLGETERRORPROC glGetError;
NAZARA_API extern PFNGLGETINTEGERVPROC glGetIntegerv;
NAZARA_API extern PFNGLGETPROGRAMIVPROC glGetProgramiv;
NAZARA_API extern PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
NAZARA_API extern PFNGLGETQUERYIVPROC glGetQueryiv;
NAZARA_API extern PFNGLGETQUERYOBJECTIVPROC glGetQueryObjectiv;
NAZARA_API extern PFNGLGETQUERYOBJECTUIVPROC glGetQueryObjectuiv;
NAZARA_API extern PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
NAZARA_API extern PFNGLGETSHADERIVPROC glGetShaderiv;
NAZARA_API extern PFNGLGETSHADERSOURCEPROC glGetShaderSource;
NAZARA_API extern PFNGLGETSTRINGPROC glGetString;
NAZARA_API extern PFNGLGETSTRINGIPROC glGetStringi;
NAZARA_API extern PFNGLGETTEXIMAGEPROC glGetTexImage;
NAZARA_API extern PFNGLGETTEXPARAMETERFVPROC glGetTexParameterfv;
NAZARA_API extern PFNGLGETTEXPARAMETERIVPROC glGetTexParameteriv;
NAZARA_API extern PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
NAZARA_API extern PFNGLLINKPROGRAMPROC glLinkProgram;
NAZARA_API extern PFNGLMAPBUFFERPROC glMapBuffer;
NAZARA_API extern PFNGLMAPBUFFERRANGEPROC glMapBufferRange;
NAZARA_API extern PFNGLPOLYGONMODEPROC glPolygonMode;
NAZARA_API extern PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
NAZARA_API extern PFNGLSCISSORPROC glScissor;
NAZARA_API extern PFNGLSHADERSOURCEPROC glShaderSource;
NAZARA_API extern PFNGLSTENCILFUNCPROC glStencilFunc;
NAZARA_API extern PFNGLSTENCILOPPROC glStencilOp;
NAZARA_API extern PFNGLTEXIMAGE2DPROC glTexImage2D;
NAZARA_API extern PFNGLTEXIMAGE3DEXTPROC glTexImage3D;
NAZARA_API extern PFNGLTEXPARAMETERFPROC glTexParameterf;
NAZARA_API extern PFNGLTEXPARAMETERIPROC glTexParameteri;
NAZARA_API extern PFNGLTEXSUBIMAGE2DPROC glTexSubImage2D;
NAZARA_API extern PFNGLTEXSUBIMAGE3DEXTPROC glTexSubImage3D;
NAZARA_API extern PFNGLUNIFORM1DPROC glUniform1d;
NAZARA_API extern PFNGLUNIFORM1FPROC glUniform1f;
NAZARA_API extern PFNGLUNIFORM1IPROC glUniform1i;
NAZARA_API extern PFNGLUNIFORM2DVPROC glUniform2dv;
NAZARA_API extern PFNGLUNIFORM2FVPROC glUniform2fv;
NAZARA_API extern PFNGLUNIFORM3DVPROC glUniform3dv;
NAZARA_API extern PFNGLUNIFORM3FVPROC glUniform3fv;
NAZARA_API extern PFNGLUNIFORM4DVPROC glUniform4dv;
NAZARA_API extern PFNGLUNIFORM4FVPROC glUniform4fv;
NAZARA_API extern PFNGLUNIFORMMATRIX4DVPROC glUniformMatrix4dv;
NAZARA_API extern PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
NAZARA_API extern PFNGLUNMAPBUFFERPROC glUnmapBuffer;
NAZARA_API extern PFNGLUSEPROGRAMPROC glUseProgram;
NAZARA_API extern PFNGLVERTEXATTRIB4FPROC glVertexAttrib4f;
NAZARA_API extern PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
NAZARA_API extern PFNGLVIEWPORTPROC glViewport;
#if defined(NAZARA_PLATFORM_WINDOWS)
NAZARA_API extern PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormat;
NAZARA_API extern PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribs;
NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB;
NAZARA_API extern PFNWGLGETEXTENSIONSSTRINGEXTPROC wglGetExtensionsStringEXT;
NAZARA_API extern PFNWGLSWAPINTERVALEXTPROC wglSwapInterval;
#elif defined(NAZARA_PLATFORM_LINUX)
NAZARA_API extern PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs;
NAZARA_API extern PFNGLXSWAPINTERVALSGIPROC glXSwapInterval;
#endif
#endif // NAZARA_OPENGL_HPP

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERTARGET_HPP
#define NAZARA_RENDERTARGET_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/RenderTargetParameters.hpp>
class NzRenderer;
class NAZARA_API NzRenderTarget
{
friend class NzRenderer;
public:
NzRenderTarget() = default;
virtual ~NzRenderTarget();
virtual bool CanActivate() const = 0;
virtual NzRenderTargetParameters GetRenderTargetParameters() const = 0;
#ifdef NAZARA_RENDERER_OPENGL
virtual bool HasContext() const = 0;
#endif
bool IsActive() const;
bool SetActive(bool active);
protected:
virtual bool Activate() = 0;
virtual void Desactivate();
};
#endif // NAZARA_RENDERTARGET_HPP

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERTARGETPARAMETERS_HPP
#define NAZARA_RENDERTARGETPARAMETERS_HPP
#include <Nazara/Prerequesites.hpp>
struct NzRenderTargetParameters
{
NzRenderTargetParameters(nzUInt8 antialiasing = 0, nzUInt8 depth = 24, nzUInt8 stencil = 0) :
antialiasingLevel(antialiasing),
depthBits(depth),
stencilBits(stencil)
{
}
nzUInt8 antialiasingLevel;
nzUInt8 depthBits;
nzUInt8 stencilBits;
};
#endif // NAZARA_RENDERTARGETPARAMETERS_HPP

View File

@@ -0,0 +1,59 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_RENDERWINDOW_HPP
#define NAZARA_RENDERWINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Utility/Window.hpp>
#ifndef NAZARA_RENDERER_COMMON
#include <Nazara/Renderer/ContextParameters.hpp>
#endif
class NzContext;
struct NzContextParameters;
class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
{
public:
NzRenderWindow();
NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = NzWindow::Default, const NzContextParameters& parameters = NzContextParameters());
NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
virtual ~NzRenderWindow();
bool CanActivate() const;
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = NzWindow::Default, const NzContextParameters& parameters = NzContextParameters());
bool Create(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
void Display();
void EnableVerticalSync(bool enabled);
NzRenderTargetParameters GetRenderTargetParameters() const;
#ifndef NAZARA_RENDERER_COMMON
NzContextParameters GetContextParameters() const;
bool HasContext() const;
#endif
protected:
bool Activate();
private:
void OnClose();
bool OnCreate();
NzContext* m_context;
NzContextParameters m_parameters;
};
#endif // NAZARA_RENDERWINDOW_HPP

View File

@@ -0,0 +1,79 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RENDERER_HPP
#define NAZARA_RENDERER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/IndexBuffer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/VertexBuffer.hpp>
#define NazaraRenderer NzRenderer::Instance()
enum nzRendererCap
{
nzRendererCap_AnisotropicFilter,
nzRendererCap_FP64,
nzRendererCap_HardwareBuffer,
nzRendererCap_MultipleRenderTargets,
nzRendererCap_Texture3D,
nzRendererCap_TextureCubemap,
nzRendererCap_TextureMulti,
nzRendererCap_TextureNPOT,
nzRendererCap_Count
};
enum nzRendererClear
{
nzRendererClear_Color = 0x01,
nzRendererClear_Depth = 0x02,
nzRendererClear_Stencil = 0x04
};
class NAZARA_API NzRenderer
{
public:
NzRenderer();
~NzRenderer();
void Clear(nzRendererClear flags);
NzShader* GetShader() const;
NzRenderTarget* GetTarget() const;
bool HasCapability(nzRendererCap capability) const;
bool Initialize();
void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
void SetClearDepth(double depth);
void SetClearStencil(unsigned int value);
bool SetIndexBuffer(const NzIndexBuffer* indexBuffer);
bool SetShader(NzShader* shader);
bool SetTarget(NzRenderTarget* target);
bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
void Uninitialize();
#if NAZARA_RENDERER_SINGLETON
static void Destroy();
#endif
static NzRenderer* Instance();
private:
static NzRenderer* s_instance;
const NzIndexBuffer* m_indexBuffer;
NzRenderTarget* m_target;
NzShader* m_shader;
const NzVertexBuffer* m_vertexBuffer;
bool m_capabilities[nzRendererCap_Count];
bool m_vertexBufferUpdated;
};
#endif // NAZARA_RENDERER_HPP

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADER_HPP
#define NAZARA_SHADER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
enum nzShaderLanguage
{
nzShaderLanguage_Unknown,
nzShaderLanguage_Cg,
nzShaderLanguage_GLSL
};
enum nzShaderType
{
nzShaderType_Fragment,
nzShaderType_Geometry,
nzShaderType_Vertex,
nzShaderType_Count
};
class NzRenderer;
class NzShaderImpl;
class NAZARA_API NzShader
{
friend class NzRenderer;
public:
NzShader();
NzShader(nzShaderLanguage language);
~NzShader();
bool Create(nzShaderLanguage language);
bool Compile();
void Destroy();
NzString GetLog() const;
nzShaderLanguage GetLanguage() const;
NzString GetSourceCode(nzShaderType type) const;
bool IsCompiled() const;
bool IsLoaded(nzShaderType type) const;
bool Load(nzShaderType type, const NzString& source);
bool LoadFromFile(nzShaderType type, const NzString& source);
bool SendBoolean(const NzString& name, bool value);
bool SendDouble(const NzString& name, double value);
bool SendFloat(const NzString& name, float value);
bool SendInteger(const NzString& name, int value);
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
static bool IsLanguageSupported(nzShaderLanguage language);
static bool IsTypeSupported(nzShaderType type);
private:
bool CommitUniforms();
NzShaderImpl* m_impl;
bool m_compiled;
};
#endif // NAZARA_SHADER_HPP

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_VERTEXBUFFER_HPP
#define NAZARA_VERTEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Buffer.hpp>
class NAZARA_API NzVertexBuffer
{
public:
NzVertexBuffer(NzBuffer* buffer, unsigned int startVertex, unsigned int vertexCount);
NzVertexBuffer(unsigned int length, nzUInt8 typeSize, nzBufferUsage usage = nzBufferUsage_Static);
NzVertexBuffer(const NzVertexBuffer& vertexBuffer);
~NzVertexBuffer();
bool Fill(const void* data, unsigned int offset, unsigned int length);
NzBuffer* GetBuffer() const;
unsigned int GetStartVertex() const;
nzUInt8 GetTypeSize() const;
unsigned int GetVertexCount() const;
bool IsHardware() const;
void* Lock(nzBufferLock lock, unsigned int offset = 0, unsigned int length = 0);
bool Unlock();
private:
NzBuffer* m_buffer;
bool m_ownsBuffer;
unsigned int m_startVertex;
unsigned int m_vertexCount;
};
#endif // NAZARA_VERTEXBUFFER_HPP

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifndef NAZARA_VERTEXDECLARATION_HPP
#define NAZARA_VERTEXDECLARATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <vector>
enum nzElementType
{
nzElementType_Color,
nzElementType_Double1,
nzElementType_Double2,
nzElementType_Double3,
nzElementType_Double4,
nzElementType_Float1,
nzElementType_Float2,
nzElementType_Float3,
nzElementType_Float4
};
enum nzElementUsage
{
nzElementType_Diffuse,
nzElementType_Normal,
nzElementType_Position,
nzElementType_Tangent,
nzElementType_TexCoord
};
struct NzVertexElement
{
NzVertexElement() : stream(0), usageIndex(0) {}
unsigned int offset;
unsigned int stream;
unsigned int usageIndex;
nzElementType type;
nzElementUsage usage;
};
class NAZARA_API NzVertexDeclaration
{
public:
struct Element
{
unsigned int offset;
unsigned int usageIndex;
nzElementType type;
nzElementUsage usage;
};
NzVertexDeclaration() = default;
~NzVertexDeclaration() = default;
bool Create(const NzVertexElement* elements, unsigned int elementCount);
const Element* GetElement(unsigned int i, unsigned int stream = 0) const;
unsigned int GetElementCount(unsigned int stream = 0) const;
unsigned int GetStreamCount() const;
unsigned int GetStride(unsigned int stream = 0) const;
private:
struct Stream
{
std::vector<Element> elements;
unsigned int stride;
};
std::vector<Stream> m_streams;
};
#endif // NAZARA_VERTEXDECLARATION_HPP

View File

@@ -0,0 +1,41 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_UTILITY_HPP
#define NAZARA_CONFIG_UTILITY_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_UTILITY_MEMORYLEAKTRACKER 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_UTILITY_SAFE 1
// Fait tourner chaque fenêtre dans un thread séparé
#define NAZARA_UTILITY_THREADED_WINDOW 1
#endif // NAZARA_CONFIG_UTILITY_HPP

View File

@@ -0,0 +1,11 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Utility/Config.hpp>
#if NAZARA_UTILITY_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

View File

@@ -0,0 +1,8 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_UTILITY_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif

View File

@@ -0,0 +1,94 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_EVENT_HPP
#define NAZARA_EVENT_HPP
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/Mouse.hpp>
struct NzEvent
{
struct KeyEvent
{
NzKeyboard::Key code;
bool alt;
bool control;
bool shift;
bool system;
};
struct MouseButtonEvent
{
NzMouse::Button button;
unsigned int x;
unsigned int y;
};
struct MouseMoveEvent
{
int x;
int y;
};
struct MouseWheelEvent
{
float delta;
};
struct PositionEvent
{
int x;
int y;
};
struct SizeEvent
{
unsigned int height;
unsigned int width;
};
struct TextEvent
{
char32_t character;
};
enum Type
{
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
MouseButtonDoubleClicked,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
MouseLeft,
MouseMoved,
MouseWheelMoved,
Moved,
Quit,
Resized,
TextEntered
};
Type type;
union
{
KeyEvent key;
MouseButtonEvent mouseButton;
MouseMoveEvent mouseMove;
MouseWheelEvent mouseWheel;
PositionEvent position;
SizeEvent size;
TextEvent text;
};
};
#endif // NAZARA_EVENT_HPP

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_FUNCTOR_HPP
#define NAZARA_FUNCTOR_HPP
#include <Nazara/Utility/Tuple.hpp>
// Inspiré du code de la SFML par Laurent Gomila
struct NzFunctor
{
virtual ~NzFunctor() {}
virtual void Run() = 0;
};
template<typename F> struct NzFunctorWithoutArgs : NzFunctor
{
NzFunctorWithoutArgs(F func);
void Run();
F function;
};
template<typename F, typename... Args> struct NzFunctorWithArgs : NzFunctor
{
NzFunctorWithArgs(F func, Args&... args);
void Run();
F function;
std::tuple<Args...> arguments;
};
template<typename F> struct NzFunctorWithoutArgs;
template<typename F, typename... Args> struct NzFunctorWithArgs;
#include <Nazara/Utility/Functor.inl>
#endif // NAZARA_FUNCTOR_HPP

View File

@@ -0,0 +1,24 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
template<typename F> NzFunctorWithoutArgs<F>::NzFunctorWithoutArgs(F func) :
function(func)
{
}
template<typename F> void NzFunctorWithoutArgs<F>::Run()
{
function();
}
template<typename F, typename... Args> NzFunctorWithArgs<F, Args...>::NzFunctorWithArgs(F func, Args&... args) :
function(func),
arguments(args...)
{
}
template<typename F, typename... Args> void NzFunctorWithArgs<F, Args...>::Run()
{
NzUnpackTuple(function, arguments);
}

View File

@@ -0,0 +1,165 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_KEYBOARD_HPP
#define NAZARA_KEYBOARD_HPP
#include <Nazara/Prerequesites.hpp>
class NAZARA_API NzKeyboard
{
public:
enum Key
{
Undefined = -1,
// Lettres
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
// Touches de fonction
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
// Flèches directionnelles
Down,
Left,
Right,
Up,
// Pavé numérique
Add,
Divide,
Multiply,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
Subtract,
// Divers
Backslash,
Backspace,
Clear,
Comma,
Dash,
Delete,
End,
Equal,
Escape,
Home,
Insert,
LAlt,
LBracket,
LControl,
LShift,
LSystem,
Num0,
Num1,
Num2,
Num3,
Num4,
Num5,
Num6,
Num7,
Num8,
Num9,
PageDown,
PageUp,
Pause,
Period,
Print,
PrintScreen,
Quote,
RAlt,
RBracket,
RControl,
Return,
RShift,
RSystem,
Semicolon,
Slash,
Space,
Tab,
Tilde,
// Touches navigateur
Browser_Back,
Browser_Favorites,
Browser_Forward,
Browser_Home,
Browser_Refresh,
Browser_Search,
Browser_Stop,
// Touches de contrôle de lecture
Media_Next,
Media_Play,
Media_Previous,
Media_Stop,
// Touches de contrôle du volume
Volume_Down,
Volume_Mute,
Volume_Up,
// Touches à verrouillage
CapsLock,
NumLock,
ScrollLock,
Count
};
static bool IsKeyPressed(Key key);
};
#endif // NAZARA_KEYBOARD_HPP

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_MOUSE_HPP
#define NAZARA_MOUSE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector2.hpp>
class NzWindow;
class NAZARA_API NzMouse
{
public:
enum Button
{
Left,
Middle,
Right,
XButton1,
XButton2,
Count
};
static NzVector2i GetPosition();
static NzVector2i GetPosition(const NzWindow& relativeTo);
static bool IsButtonPressed(Button button);
static void SetPosition(const NzVector2i& position);
static void SetPosition(const NzVector2i& position, const NzWindow& relativeTo);
static void SetPosition(int x, int y);
static void SetPosition(int x, int y, const NzWindow& relativeTo);
};
#endif // NAZARA_MOUSE_HPP

View File

@@ -0,0 +1,20 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_NONCOPYABLE_HPP
#define NAZARA_NONCOPYABLE_HPP
#include <Nazara/Prerequesites.hpp>
class NAZARA_API NzNonCopyable
{
protected:
NzNonCopyable() = default;
NzNonCopyable(const NzNonCopyable&) = delete;
NzNonCopyable& operator=(const NzNonCopyable&) = delete;
};
#endif // NAZARA_NONCOPYABLE_HPP

View File

@@ -0,0 +1,30 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RESOURCE_HPP
#define NAZARA_RESOURCE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
class NAZARA_API NzResource : NzNonCopyable
{
public:
NzResource(bool persistent = true);
virtual ~NzResource();
void AddResourceReference() const;
bool IsPersistent() const;
void RemoveResourceReference() const;
void SetPersistent(bool persistent = true);
private:
// Je fais précéder le nom par 'resource' pour éviter les éventuels conflits de noms
mutable bool m_resourcePersistent;
mutable unsigned int m_resourceReferenceCount;
};
#endif // NAZARA_RESOURCE_HPP

View File

@@ -0,0 +1,16 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_TUPLE_HPP
#define NAZARA_TUPLE_HPP
#include <tuple>
template<typename F, typename... ArgsT> void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t);
#include <Nazara/Utility/Tuple.inl>
#endif // NAZARA_TUPLE_HPP

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// http://stackoverflow.com/questions/687490/c0x-how-do-i-expand-a-tuple-into-variadic-template-function-arguments
// Merci à Ryan "FullMetal Alchemist" Lahfa
// Merci aussi à Freedom de siteduzero.com
#include <Nazara/Utility/Debug.hpp>
template<unsigned int N> struct NzTupleUnpack
{
template <typename F, typename... ArgsT, typename... Args>
void operator()(F func, const std::tuple<ArgsT...>& t, Args&... args)
{
NzTupleUnpack<N-1>()(func, t, std::get<N-1>(t), args...);
}
};
template<> struct NzTupleUnpack<0>
{
template <typename F, typename... ArgsT, typename... Args>
void operator()(F func, const std::tuple<ArgsT...>&, Args&... args)
{
func(args...);
}
};
template<typename F, typename... ArgsT>
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t )
{
NzTupleUnpack<sizeof...(ArgsT)>()(func, t);
}
#include <Nazara/Utility/DebugOff.hpp>

View File

@@ -0,0 +1,38 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_VIDEOMODE_HPP
#define NAZARA_VIDEOMODE_HPP
#include <Nazara/Prerequesites.hpp>
#include <vector>
class NAZARA_API NzVideoMode
{
public:
NzVideoMode();
NzVideoMode(unsigned int w, unsigned int h, nzUInt8 bpp);
bool IsFullscreenValid() const;
static NzVideoMode GetDesktopMode();
static const std::vector<NzVideoMode>& GetFullscreenModes();
nzUInt8 bitsPerPixel;
unsigned int height;
unsigned int width;
};
bool operator==(const NzVideoMode& left, const NzVideoMode& right);
bool operator!=(const NzVideoMode& left, const NzVideoMode& right);
bool operator<(const NzVideoMode& left, const NzVideoMode& right);
bool operator<=(const NzVideoMode& left, const NzVideoMode& right);
bool operator>(const NzVideoMode& left, const NzVideoMode& right);
bool operator>=(const NzVideoMode& left, const NzVideoMode& right);
#endif // NAZARA_VIDEOMODE_HPP

View File

@@ -0,0 +1,113 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// Interface inspirée de la SFML par Laurent Gomila
#pragma once
#ifndef NAZARA_WINDOW_HPP
#define NAZARA_WINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/NonCopyable.hpp>
#include <Nazara/Utility/VideoMode.hpp>
#include <Nazara/Utility/WindowHandle.hpp>
#include <queue>
#if NAZARA_UTILITY_THREADED_WINDOW
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/ThreadCondition.hpp>
#endif
class NzWindowImpl;
class NAZARA_API NzWindow : NzNonCopyable
{
friend class NzWindowImpl;
public:
enum Style
{
None = 0x0,
Fullscreen = 0x1,
Closable = 0x2,
Resizable = 0x4,
Titlebar = 0x8,
Default = Closable | Resizable | Titlebar
};
NzWindow();
NzWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = Default);
NzWindow(NzWindowHandle handle);
virtual ~NzWindow();
void Close();
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = Default);
bool Create(NzWindowHandle handle);
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
NzWindowHandle GetHandle() const;
unsigned int GetHeight() const;
NzVector2i GetPosition() const;
NzVector2i GetSize() const;
NzString GetTitle() const;
unsigned int GetWidth() const;
bool HasFocus() const;
bool IsMinimized() const;
bool IsOpen() const;
bool IsVisible() const;
bool PollEvent(NzEvent* event);
void SetEventListener(bool listener);
void SetFocus();
void SetMaximumSize(const NzVector2i& maxSize);
void SetMaximumSize(int width, int height);
void SetMinimumSize(const NzVector2i& minSize);
void SetMinimumSize(int width, int height);
void SetPosition(const NzVector2i& position);
void SetPosition(int x, int y);
void SetSize(const NzVector2i& size);
void SetSize(unsigned int width, unsigned int height);
void SetTitle(const NzString& title);
void SetVisible(bool visible);
void ShowMouseCursor(bool show);
void StayOnTop(bool stayOnTop);
bool WaitEvent(NzEvent* event);
protected:
virtual void OnClose();
virtual bool OnCreate();
NzWindowImpl* m_impl;
private:
void PushEvent(const NzEvent& event);
std::queue<NzEvent> m_events;
#if NAZARA_UTILITY_THREADED_WINDOW
NzMutex m_eventMutex;
NzMutex m_eventConditionMutex;
NzThreadCondition m_eventCondition;
bool m_eventListener;
bool m_waitForEvent;
#endif
bool m_ownsWindow;
};
#endif // NAZARA_WINDOW_HPP

View File

@@ -0,0 +1,22 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_WINDOWHANDLE_HPP
#define NAZARA_WINDOWHANDLE_HPP
#include <Nazara/Prerequesites.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
// http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx
typedef void* NzWindowHandle;
#elif defined(NAZARA_PLATFORM_LINUX)
// http://en.wikipedia.org/wiki/Xlib#Data_types
typedef unsigned long NzWindowHandle;
#else
#error Lack of implementation: WindowHandle
#endif
#endif // NAZARA_WINDOWHANDLE_HPP