Merge branch 'master' into NDK

Conflicts:
	include/Nazara/Core/Algorithm.inl
	include/Nazara/Core/ByteArray.hpp
	include/Nazara/Math/Algorithm.inl
	src/Nazara/Graphics/SkyboxBackground.cpp

Former-commit-id: 42f52f71989fa805f69527fd07edb8405df06566
This commit is contained in:
Lynix
2015-08-21 18:55:58 +02:00
76 changed files with 2358 additions and 833 deletions

View File

@@ -8,120 +8,132 @@
#define NAZARA_BYTEARRAY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <atomic>
#include <Nazara/Core/String.hpp>
#include <vector>
class NzAbstractHash;
class NzHashDigest;
class NAZARA_CORE_API NzByteArray : public NzHashable
{
using Container = std::vector<nzUInt8>;
public:
struct SharedArray;
// types:
using allocator_type = typename Container::allocator_type;
using const_iterator = typename Container::const_iterator;
using const_reference = typename Container::const_reference;
using const_pointer = typename Container::const_pointer;
using const_reverse_iterator = typename Container::const_reverse_iterator;
using difference_type = typename Container::difference_type;
using pointer = typename Container::pointer;
using iterator = typename Container::iterator;
using reference = typename Container::reference;
using reverse_iterator = typename Container::reverse_iterator;
using size_type = typename Container::size_type;
using value_type = typename Container::value_type;
NzByteArray();
explicit NzByteArray(unsigned int size);
NzByteArray(const void* buffer, unsigned int size);
NzByteArray(const NzByteArray& buffer);
NzByteArray(NzByteArray&& buffer) noexcept;
NzByteArray(SharedArray* sharedArray);
~NzByteArray();
// construct/destroy:
inline NzByteArray() = default;
inline explicit NzByteArray(size_type n);
inline NzByteArray(const void* buffer, size_type n);
inline NzByteArray(size_type n, value_type value);
template <class InputIterator> NzByteArray(InputIterator first, InputIterator last);
NzByteArray(const NzByteArray& other) = default;
NzByteArray(NzByteArray&& other) = default;
~NzByteArray() = default;
NzByteArray& Append(const void* buffer, unsigned int size);
NzByteArray& Append(const NzByteArray& array);
inline iterator Append(const void* buffer, size_type size);
inline iterator Append(const NzByteArray& other);
template <class InputIterator> void Assign(InputIterator first, InputIterator last);
inline void Assign(size_type n, value_type value);
void Clear(bool keepBuffer = false);
inline reference Back();
inline const_reference Back() const;
nzUInt8* GetBuffer();
unsigned int GetCapacity() const;
const nzUInt8* GetConstBuffer() const;
unsigned int GetSize() const;
inline void Clear(bool keepBuffer = false);
NzByteArray& Insert(int pos, const void* buffer, unsigned int size);
NzByteArray& Insert(int pos, const NzByteArray& array);
inline iterator Erase(const_iterator pos);
inline iterator Erase(const_iterator first, const_iterator last);
bool IsEmpty() const;
inline reference Front();
inline const_reference Front() const;
NzByteArray& Prepend(const void* buffer, unsigned int size);
NzByteArray& Prepend(const NzByteArray& array);
inline allocator_type GetAllocator() const;
inline pointer GetBuffer();
inline size_type GetCapacity() const noexcept;
inline const_pointer GetConstBuffer() const;
inline size_type GetMaxSize() const noexcept;
inline size_type GetSize() const noexcept;
inline NzByteArray GetSubArray(const_iterator startPos, const_iterator endPos) const;
void Reserve(unsigned int bufferSize);
inline iterator Insert(const_iterator pos, const void* buffer, size_type n);
inline iterator Insert(const_iterator pos, const NzByteArray& other);
inline iterator Insert(const_iterator pos, size_type n, const value_type byte);
template <class InputIterator> iterator Insert(const_iterator pos, InputIterator first, InputIterator last);
inline bool IsEmpty() const noexcept;
NzByteArray& Resize(int size);
NzByteArray& Resize(int size, nzUInt8 byte);
NzByteArray Resized(int size) const;
NzByteArray Resized(int size, nzUInt8 byte) const;
inline void PopBack();
inline void PopFront();
inline iterator Prepend(const void* buffer, size_type size);
inline iterator Prepend(const NzByteArray& other);
inline void PushBack(value_type byte);
inline void PushFront(value_type byte);
NzByteArray SubArray(int startPos, int endPos = -1) const;
inline void Reserve(size_type bufferSize);
inline void Resize(size_type newSize);
inline void Resize(size_type newSize, value_type byte);
void Swap(NzByteArray& array);
inline void ShrinkToFit();
inline void Swap(NzByteArray& other);
// Méthodes compatibles STD
nzUInt8* begin();
const nzUInt8* begin() const;
nzUInt8* end();
const nzUInt8* end() const;
void push_front(nzUInt8 byte);
void push_back(nzUInt8 byte);
/*nzUInt8* rbegin();
const nzUInt8* rbegin() const;
nzUInt8* rend();
const nzUInt8* rend() const;*/
inline NzString ToString() const;
typedef const nzUInt8& const_reference;
typedef nzUInt8* iterator;
//typedef nzUInt8* reverse_iterator;
typedef nzUInt8 value_type;
// Méthodes compatibles STD
// STL interface
inline iterator begin() noexcept;
inline const_iterator begin() const noexcept;
inline bool empty() const noexcept;
inline iterator end() noexcept;
inline const_iterator end() const noexcept;
inline reverse_iterator rbegin() noexcept;
inline const_reverse_iterator rbegin() const noexcept;
inline reverse_iterator rend() noexcept;
inline const_reverse_iterator rend() const noexcept;
inline const_iterator cbegin() const noexcept;
inline const_iterator cend() const noexcept;
inline const_reverse_iterator crbegin() const noexcept;
inline const_reverse_iterator crend() const noexcept;
inline size_type size() const noexcept;
nzUInt8& operator[](unsigned int pos);
nzUInt8 operator[](unsigned int pos) const;
// Operators
inline reference operator[](size_type pos);
inline const_reference operator[](size_type pos) const;
inline NzByteArray& operator=(const NzByteArray& array) = default;
inline NzByteArray& operator=(NzByteArray&& array) = default;
inline NzByteArray operator+(const NzByteArray& array) const;
inline NzByteArray& operator+=(const NzByteArray& array);
NzByteArray& operator=(const NzByteArray& array);
NzByteArray& operator=(NzByteArray&& array) noexcept;
NzByteArray operator+(const NzByteArray& array) const;
NzByteArray& operator+=(const NzByteArray& array);
static int Compare(const NzByteArray& first, const NzByteArray& second);
struct NAZARA_CORE_API SharedArray
{
SharedArray() :
refCount(1)
{
}
SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
capacity(bufferSize),
size(arraySize),
buffer(ptr),
refCount(referenceCount)
{
}
unsigned int capacity;
unsigned int size;
nzUInt8* buffer;
std::atomic_ushort refCount;
};
static SharedArray emptyArray;
static unsigned int npos;
inline bool operator==(const NzByteArray& rhs) const;
inline bool operator!=(const NzByteArray& rhs) const;
inline bool operator<(const NzByteArray& rhs) const;
inline bool operator<=(const NzByteArray& rhs) const;
inline bool operator>(const NzByteArray& rhs) const;
inline bool operator>=(const NzByteArray& rhs) const;
private:
void EnsureOwnership();
bool FillHash(NzAbstractHash* hash) const;
void ReleaseArray();
SharedArray* m_sharedArray;
Container m_array;
};
NAZARA_CORE_API std::ostream& operator<<(std::ostream& out, const NzByteArray& byteArray);
namespace std
{
NAZARA_CORE_API void swap(NzByteArray& lhs, NzByteArray& rhs);
void swap(NzByteArray& lhs, NzByteArray& rhs);
}
#include <Nazara/Core/ByteArray.inl>
#endif // NAZARA_BYTEARRAY_HPP

View File

@@ -317,8 +317,8 @@ inline void NzColor::ToHSV(const NzColor& color, float* hue, float* saturation,
float g = color.g / 255.f;
float b = color.b / 255.f;
float min = std::min(std::min(r, g), b); //Min. value of RGB
float max = std::max(std::max(r, g), b); //Max. value of RGB
float min = std::min({r, g, b}); //Min. value of RGB
float max = std::max({r, g, b}); //Max. value of RGB
float deltaMax = max - min; //Delta RGB value

View File

@@ -27,7 +27,7 @@
#include <Nazara/Core/ThreadSafetyOff.hpp>
#endif
using NzDynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
using NzDynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
class NzDynLibImpl;

View File

@@ -15,6 +15,15 @@ enum nzCoordSys
nzCoordSys_Max = nzCoordSys_Local
};
enum nzCursorPosition
{
nzCursorPosition_AtBegin, // Début du fichier
nzCursorPosition_AtCurrent, // Position du pointeur
nzCursorPosition_AtEnd, // Fin du fichier
nzCursorPosition_Max = nzCursorPosition_AtEnd
};
enum nzEndianness
{
nzEndianness_Unknown = -1,
@@ -57,7 +66,24 @@ enum nzHash
nzHash_SHA256,
nzHash_SHA384,
nzHash_SHA512,
nzHash_Whirlpool
nzHash_Whirlpool,
nzHash_Max = nzHash_Whirlpool
};
enum nzOpenModeFlags
{
nzOpenMode_Current = 0x00, // Utilise le mode d'ouverture actuel
nzOpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
nzOpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
nzOpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture
nzOpenMode_ReadWrite = 0x08, // Ouvre en lecture/écriture
nzOpenMode_Text = 0x10, // Ouvre en mode texte
nzOpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
nzOpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
nzOpenMode_Max = nzOpenMode_WriteOnly
};
enum nzParameterType

View File

@@ -30,29 +30,9 @@ class NzFileImpl;
class NAZARA_CORE_API NzFile : public NzHashable, public NzInputStream, 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(const NzString& filePath, unsigned int openMode);
NzFile(NzFile&& file) noexcept;
~NzFile();
@@ -79,14 +59,14 @@ class NAZARA_CORE_API NzFile : public NzHashable, public NzInputStream, NzNonCop
bool IsOpen() const;
bool Open(unsigned long openMode = Current);
bool Open(const NzString& filePath, unsigned long openMode = Current);
bool Open(unsigned int openMode = nzOpenMode_Current);
bool Open(const NzString& filePath, unsigned int openMode = nzOpenMode_Current);
std::size_t Read(void* buffer, std::size_t size);
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(nzCursorPosition pos, nzInt64 offset = 0);
bool SetCursorPos(nzUInt64 offset);
void SetEndianness(nzEndianness endianness);
bool SetFile(const NzString& filePath);

View File

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

View File

@@ -57,7 +57,7 @@ bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzSt
if (checkFunc && !file.IsOpen())
{
if (!file.Open(NzFile::ReadOnly))
if (!file.Open(nzOpenMode_ReadOnly))
{
NazaraError("Failed to load file: unable to open \"" + filePath + '"');
return false;

View File

@@ -22,9 +22,9 @@ class NAZARA_CORE_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
None = 0x00, // Mode par défaut
CaseInsensitive = 0x01, // Insensible à la casse
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8
TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne
TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne
};

View File

@@ -6,9 +6,9 @@
namespace std
{
template<>
struct hash<NzString>
{
template<>
struct hash<NzString>
{
size_t operator()(const NzString& str) const
{
// Algorithme DJB2
@@ -26,7 +26,7 @@ namespace std
return h;
}
};
};
}
#include <Nazara/Core/DebugOff.hpp>