Fix a shitloads of warnings on VS

Former-commit-id: fca61118f4e0530ed2eaaf9ff96de29806aa5aa8
This commit is contained in:
Lynix 2015-11-25 18:19:26 +01:00
parent c6d16c0128
commit bbe8a776e8
42 changed files with 406 additions and 437 deletions

View File

@ -23,11 +23,11 @@ namespace Nz
AbstractHash(AbstractHash&&) = default; AbstractHash(AbstractHash&&) = default;
virtual ~AbstractHash(); virtual ~AbstractHash();
virtual void Append(const UInt8* data, unsigned int len) = 0; virtual void Append(const UInt8* data, std::size_t len) = 0;
virtual void Begin() = 0; virtual void Begin() = 0;
virtual ByteArray End() = 0; virtual ByteArray End() = 0;
virtual unsigned int GetDigestLength() const = 0; virtual std::size_t GetDigestLength() const = 0;
virtual const char* GetHashName() const = 0; virtual const char* GetHashName() const = 0;
AbstractHash& operator=(const AbstractHash&) = delete; AbstractHash& operator=(const AbstractHash&) = delete;

View File

@ -204,10 +204,10 @@ namespace Nz
inline String ByteArray::ToHex() const inline String ByteArray::ToHex() const
{ {
unsigned int length = m_array.size() * 2; std::size_t length = m_array.size() * 2;
String hexOutput(length, '\0'); String hexOutput(length, '\0');
for (unsigned int i = 0; i < m_array.size(); ++i) for (std::size_t i = 0; i < m_array.size(); ++i)
std::sprintf(&hexOutput[i * 2], "%02x", m_array[i]); std::sprintf(&hexOutput[i * 2], "%02x", m_array[i]);
return hexOutput; return hexOutput;

View File

@ -54,22 +54,24 @@ namespace Nz
inline Color Color::operator+(const Color& color) const inline Color Color::operator+(const Color& color) const
{ {
///TODO: Improve this shit
Color c; Color c;
c.r = std::min(static_cast<unsigned int>(r) + static_cast<unsigned int>(color.r), 255U); c.r = static_cast<UInt8>(std::min(static_cast<unsigned int>(r) + static_cast<unsigned int>(color.r), 255U));
c.g = std::min(static_cast<unsigned int>(g) + static_cast<unsigned int>(color.g), 255U); c.g = static_cast<UInt8>(std::min(static_cast<unsigned int>(g) + static_cast<unsigned int>(color.g), 255U));
c.b = std::min(static_cast<unsigned int>(b) + static_cast<unsigned int>(color.b), 255U); c.b = static_cast<UInt8>(std::min(static_cast<unsigned int>(b) + static_cast<unsigned int>(color.b), 255U));
c.a = std::min(static_cast<unsigned int>(a) + static_cast<unsigned int>(color.a), 255U); c.a = static_cast<UInt8>(std::min(static_cast<unsigned int>(a) + static_cast<unsigned int>(color.a), 255U));
return c; return c;
} }
inline Color Color::operator*(const Color& color) const inline Color Color::operator*(const Color& color) const
{ {
///TODO: Improve this shit
Color c; Color c;
c.r = (static_cast<unsigned int>(r) * static_cast<unsigned int>(color.r)) / 255U; c.r = static_cast<UInt8>((static_cast<unsigned int>(r) * static_cast<unsigned int>(color.r)) / 255U);
c.g = (static_cast<unsigned int>(g) * static_cast<unsigned int>(color.g)) / 255U; c.g = static_cast<UInt8>((static_cast<unsigned int>(g) * static_cast<unsigned int>(color.g)) / 255U);
c.b = (static_cast<unsigned int>(b) * static_cast<unsigned int>(color.b)) / 255U; c.b = static_cast<UInt8>((static_cast<unsigned int>(b) * static_cast<unsigned int>(color.b)) / 255U);
c.a = (static_cast<unsigned int>(a) * static_cast<unsigned int>(color.a)) / 255U; c.a = static_cast<UInt8>((static_cast<unsigned int>(a) * static_cast<unsigned int>(color.a)) / 255U);
return c; return c;
} }

View File

@ -14,9 +14,9 @@
#include <Nazara/Core/String.hpp> #include <Nazara/Core/String.hpp>
#if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG) #if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG)
#define NazaraAssert(a, err) do { if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION); } while (false) #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)
#else #else
#define NazaraAssert(a, err) do {} while (false) #define NazaraAssert(a, err) for (;;) break
#endif #endif
#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION) #define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, Nz::Directory::GetCurrentFileRelativeToEngine(__FILE__), NAZARA_FUNCTION)

View File

@ -21,11 +21,11 @@ namespace Nz
HashCRC32(UInt32 polynomial = 0x04c11db7); HashCRC32(UInt32 polynomial = 0x04c11db7);
virtual ~HashCRC32(); virtual ~HashCRC32();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -22,11 +22,11 @@ namespace Nz
HashFletcher16(); HashFletcher16();
virtual ~HashFletcher16(); virtual ~HashFletcher16();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -21,11 +21,11 @@ namespace Nz
HashMD5(); HashMD5();
virtual ~HashMD5(); virtual ~HashMD5();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -21,11 +21,11 @@ namespace Nz
HashSHA1(); HashSHA1();
virtual ~HashSHA1(); virtual ~HashSHA1();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -21,11 +21,11 @@ namespace Nz
HashSHA224(); HashSHA224();
virtual ~HashSHA224(); virtual ~HashSHA224();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -21,11 +21,11 @@ namespace Nz
HashSHA256(); HashSHA256();
virtual ~HashSHA256(); virtual ~HashSHA256();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -21,11 +21,11 @@ namespace Nz
HashSHA384(); HashSHA384();
virtual ~HashSHA384(); virtual ~HashSHA384();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -21,11 +21,11 @@ namespace Nz
HashSHA512(); HashSHA512();
virtual ~HashSHA512(); virtual ~HashSHA512();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const override; std::size_t GetDigestLength() const override;
const char* GetHashName() const override; const char* GetHashName() const override;
private: private:

View File

@ -19,11 +19,11 @@ namespace Nz
HashWhirlpool(); HashWhirlpool();
virtual ~HashWhirlpool(); virtual ~HashWhirlpool();
void Append(const UInt8* data, unsigned int len) override; void Append(const UInt8* data, std::size_t len) override;
void Begin() override; void Begin() override;
ByteArray End() override; ByteArray End() override;
unsigned int GetDigestLength() const; std::size_t GetDigestLength() const;
const char* GetHashName() const; const char* GetHashName() const;
private: private:

View File

@ -13,6 +13,7 @@
namespace Nz namespace Nz
{ {
///TODO: Inline this
class NAZARA_CORE_API PrimitiveList class NAZARA_CORE_API PrimitiveList
{ {
public: public:
@ -35,9 +36,9 @@ namespace Nz
void AddUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const Matrix4f& transformMatrix = Matrix4f::Identity()); void AddUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
void AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity()); void AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
Primitive& GetPrimitive(unsigned int i); Primitive& GetPrimitive(std::size_t i);
const Primitive& GetPrimitive(unsigned int i) const; const Primitive& GetPrimitive(std::size_t i) const;
unsigned int GetSize() const; std::size_t GetSize() const;
PrimitiveList& operator=(const PrimitiveList&) = default; PrimitiveList& operator=(const PrimitiveList&) = default;
PrimitiveList& operator=(PrimitiveList&&) = default; PrimitiveList& operator=(PrimitiveList&&) = default;

View File

@ -32,12 +32,12 @@ namespace Nz
String(); String();
explicit String(char character); explicit String(char character);
String(unsigned int rep, char character); String(std::size_t rep, char character);
String(unsigned int rep, const char* string); String(std::size_t rep, const char* string);
String(unsigned int rep, const char* string, unsigned int length); String(std::size_t rep, const char* string, std::size_t length);
String(unsigned int rep, const String& string); String(std::size_t rep, const String& string);
String(const char* string); String(const char* string);
String(const char* string, unsigned int length); String(const char* string, std::size_t length);
String(const std::string& string); String(const std::string& string);
String(const String& string) = default; String(const String& string) = default;
String(String&& string) noexcept = default; String(String&& string) noexcept = default;
@ -45,57 +45,57 @@ namespace Nz
String& Append(char character); String& Append(char character);
String& Append(const char* string); String& Append(const char* string);
String& Append(const char* string, unsigned int length); String& Append(const char* string, std::size_t length);
String& Append(const String& string); String& Append(const String& string);
void Clear(bool keepBuffer = false); void Clear(bool keepBuffer = false);
bool Contains(char character, int start = 0, UInt32 flags = None) const; bool Contains(char character, std::intmax_t start = 0, UInt32 flags = None) const;
bool Contains(const char* string, int start = 0, UInt32 flags = None) const; bool Contains(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
bool Contains(const String& string, int start = 0, UInt32 flags = None) const; bool Contains(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Count(char character, int start = 0, UInt32 flags = None) const; unsigned int Count(char character, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Count(const char* string, int start = 0, UInt32 flags = None) const; unsigned int Count(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Count(const String& string, int start = 0, UInt32 flags = None) const; unsigned int Count(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int CountAny(const char* string, int start = 0, UInt32 flags = None) const; unsigned int CountAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int CountAny(const String& string, int start = 0, UInt32 flags = None) const; unsigned int CountAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
bool EndsWith(char character, UInt32 flags = None) const; bool EndsWith(char character, UInt32 flags = None) const;
bool EndsWith(const char* string, UInt32 flags = None) const; bool EndsWith(const char* string, UInt32 flags = None) const;
bool EndsWith(const char* string, unsigned int length, UInt32 flags = None) const; bool EndsWith(const char* string, std::size_t length, UInt32 flags = None) const;
bool EndsWith(const String& string, UInt32 flags = None) const; bool EndsWith(const String& string, UInt32 flags = None) const;
unsigned int Find(char character, int start = 0, UInt32 flags = None) const; std::size_t Find(char character, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Find(const char* string, int start = 0, UInt32 flags = None) const; std::size_t Find(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Find(const String& string, int start = 0, UInt32 flags = None) const; std::size_t Find(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int FindAny(const char* string, int start = 0, UInt32 flags = None) const; std::size_t FindAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int FindAny(const String& string, int start = 0, UInt32 flags = None) const; std::size_t FindAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int FindLast(char character, int start = -1, UInt32 flags = None) const; std::size_t FindLast(char character, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindLast(const char *string, int start = -1, UInt32 flags = None) const; std::size_t FindLast(const char *string, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindLast(const String& string, int start = -1, UInt32 flags = None) const; std::size_t FindLast(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindLastAny(const char* string, int start = -1, UInt32 flags = None) const; std::size_t FindLastAny(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindLastAny(const String& string, int start = -1, UInt32 flags = None) const; std::size_t FindLastAny(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindLastWord(const char* string, int start = -1, UInt32 flags = None) const; std::size_t FindLastWord(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindLastWord(const String& string, int start = -1, UInt32 flags = None) const; std::size_t FindLastWord(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
unsigned int FindWord(const char* string, int start = 0, UInt32 flags = None) const; std::size_t FindWord(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int FindWord(const String& string, int start = 0, UInt32 flags = None) const; std::size_t FindWord(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
char* GetBuffer(); char* GetBuffer();
unsigned int GetCapacity() const; std::size_t GetCapacity() const;
const char* GetConstBuffer() const; const char* GetConstBuffer() const;
unsigned int GetLength() const; std::size_t GetLength() const;
unsigned int GetSize() const; std::size_t GetSize() const;
std::string GetUtf8String() const; std::string GetUtf8String() const;
std::u16string GetUtf16String() const; std::u16string GetUtf16String() const;
std::u32string GetUtf32String() const; std::u32string GetUtf32String() const;
std::wstring GetWideString() const; std::wstring GetWideString() const;
String GetWord(unsigned int index, UInt32 flags = None) const; String GetWord(unsigned int index, UInt32 flags = None) const;
unsigned int GetWordPosition(unsigned int index, UInt32 flags = None) const; std::size_t GetWordPosition(unsigned int index, UInt32 flags = None) const;
String& Insert(int pos, char character); String& Insert(std::intmax_t pos, char character);
String& Insert(int pos, const char* string); String& Insert(std::intmax_t pos, const char* string);
String& Insert(int pos, const char* string, unsigned int length); String& Insert(std::intmax_t pos, const char* string, std::size_t length);
String& Insert(int pos, const String& string); String& Insert(std::intmax_t pos, const String& string);
bool IsEmpty() const; bool IsEmpty() const;
bool IsNull() const; bool IsNull() const;
@ -106,32 +106,32 @@ namespace Nz
String& Prepend(char character); String& Prepend(char character);
String& Prepend(const char* string); String& Prepend(const char* string);
String& Prepend(const char* string, unsigned int length); String& Prepend(const char* string, std::size_t length);
String& Prepend(const String& string); String& Prepend(const String& string);
unsigned int Replace(char oldCharacter, char newCharacter, int start = 0, UInt32 flags = None); unsigned int Replace(char oldCharacter, char newCharacter, std::intmax_t start = 0, UInt32 flags = None);
unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, UInt32 flags = None); unsigned int Replace(const char* oldString, const char* replaceString, std::intmax_t start = 0, UInt32 flags = None);
unsigned int Replace(const char* oldString, unsigned int oldLength, const char* replaceString, unsigned int replaceLength, int start = 0, UInt32 flags = None); unsigned int Replace(const char* oldString, std::size_t oldLength, const char* replaceString, std::size_t replaceLength, std::intmax_t start = 0, UInt32 flags = None);
unsigned int Replace(const String& oldString, const String& replaceString, int start = 0, UInt32 flags = None); unsigned int Replace(const String& oldString, const String& replaceString, std::intmax_t start = 0, UInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, UInt32 flags = None); unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, std::intmax_t start = 0, UInt32 flags = None);
//unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, UInt32 flags = None); //unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, std::intmax_t start = 0, UInt32 flags = None);
//unsigned int ReplaceAny(const String& oldCharacters, const String& replaceString, int start = 0, UInt32 flags = None); //unsigned int ReplaceAny(const String& oldCharacters, const String& replaceString, std::intmax_t start = 0, UInt32 flags = None);
void Reserve(unsigned int bufferSize); void Reserve(std::size_t bufferSize);
String& Resize(int size, char character = ' '); String& Resize(std::intmax_t size, char character = ' ');
String Resized(int size, char character = ' ') const; String Resized(std::intmax_t size, char character = ' ') const;
String& Reverse(); String& Reverse();
String Reversed() const; String Reversed() const;
String& Set(char character); String& Set(char character);
String& Set(unsigned int rep, char character); String& Set(std::size_t rep, char character);
String& Set(unsigned int rep, const char* string); String& Set(std::size_t rep, const char* string);
String& Set(unsigned int rep, const char* string, unsigned int length); String& Set(std::size_t rep, const char* string, std::size_t length);
String& Set(unsigned int rep, const String& string); String& Set(std::size_t rep, const String& string);
String& Set(const char* string); String& Set(const char* string);
String& Set(const char* string, unsigned int length); String& Set(const char* string, std::size_t length);
String& Set(const std::string& string); String& Set(const std::string& string);
String& Set(const String& string); String& Set(const String& string);
String& Set(String&& string) noexcept; String& Set(String&& string) noexcept;
@ -139,26 +139,26 @@ namespace Nz
String Simplified(UInt32 flags = None) const; String Simplified(UInt32 flags = None) const;
String& Simplify(UInt32 flags = None); String& Simplify(UInt32 flags = None);
unsigned int Split(std::vector<String>& result, char separation = ' ', int start = 0, UInt32 flags = None) const; unsigned int Split(std::vector<String>& result, char separation = ' ', std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Split(std::vector<String>& result, const char* separation, int start = 0, UInt32 flags = None) const; unsigned int Split(std::vector<String>& result, const char* separation, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Split(std::vector<String>& result, const char* separation, unsigned int length, int start = 0, UInt32 flags = None) const; unsigned int Split(std::vector<String>& result, const char* separation, std::size_t length, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int Split(std::vector<String>& result, const String& separation, int start = 0, UInt32 flags = None) const; unsigned int Split(std::vector<String>& result, const String& separation, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int SplitAny(std::vector<String>& result, const char* separations, int start = 0, UInt32 flags = None) const; unsigned int SplitAny(std::vector<String>& result, const char* separations, std::intmax_t start = 0, UInt32 flags = None) const;
unsigned int SplitAny(std::vector<String>& result, const String& separations, int start = 0, UInt32 flags = None) const; unsigned int SplitAny(std::vector<String>& result, const String& separations, std::intmax_t start = 0, UInt32 flags = None) const;
bool StartsWith(char character, UInt32 flags = None) const; bool StartsWith(char character, UInt32 flags = None) const;
bool StartsWith(const char* string, UInt32 flags = None) const; bool StartsWith(const char* string, UInt32 flags = None) const;
bool StartsWith(const String& string, UInt32 flags = None) const; bool StartsWith(const String& string, UInt32 flags = None) const;
String SubString(int startPos, int endPos = -1) const; String SubString(std::intmax_t startPos, std::intmax_t endPos = -1) const;
String SubStringFrom(char character, int startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; String SubStringFrom(char character, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
String SubStringFrom(const char *string, int startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; String SubStringFrom(const char* string, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
String SubStringFrom(const char *string, unsigned int length, int startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; String SubStringFrom(const char* string, std::size_t length, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
String SubStringFrom(const String& string, int startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const; String SubStringFrom(const String& string, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
String SubStringTo(char character, int startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; String SubStringTo(char character, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
String SubStringTo(const char *string, int startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; String SubStringTo(const char* string, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
String SubStringTo(const char *string, unsigned int length, int startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; String SubStringTo(const char* string, std::size_t length, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
String SubStringTo(const String& string, int startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const; String SubStringTo(const String& string, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
void Swap(String& str); void Swap(String& str);
@ -193,8 +193,8 @@ namespace Nz
operator std::string() const; operator std::string() const;
char& operator[](unsigned int pos); char& operator[](std::size_t pos);
char operator[](unsigned int pos) const; char operator[](std::size_t pos) const;
String& operator=(char character); String& operator=(char character);
String& operator=(const char* string); String& operator=(const char* string);
@ -296,7 +296,7 @@ namespace Nz
NAZARA_CORE_API friend bool operator>=(const char* string, const String& nstring); NAZARA_CORE_API friend bool operator>=(const char* string, const String& nstring);
NAZARA_CORE_API friend bool operator>=(const std::string& string, const String& nstring); NAZARA_CORE_API friend bool operator>=(const std::string& string, const String& nstring);
static const unsigned int npos; static const std::size_t npos;
private: private:
struct SharedString; struct SharedString;
@ -313,11 +313,11 @@ namespace Nz
struct SharedString struct SharedString
{ {
inline SharedString(); inline SharedString();
inline SharedString(unsigned int strSize); inline SharedString(std::size_t strSize);
inline SharedString(unsigned int strSize, unsigned int strCapacity); inline SharedString(std::size_t strSize, std::size_t strCapacity);
unsigned int capacity; std::size_t capacity;
unsigned int size; std::size_t size;
std::unique_ptr<char[]> string; std::unique_ptr<char[]> string;
}; };
}; };

View File

@ -23,7 +23,7 @@ namespace Nz
{ {
} }
inline String::SharedString::SharedString(unsigned int strSize) : inline String::SharedString::SharedString(std::size_t strSize) :
capacity(strSize), capacity(strSize),
size(strSize), size(strSize),
string(new char[strSize + 1]) string(new char[strSize + 1])
@ -31,7 +31,7 @@ namespace Nz
string[strSize] = '\0'; string[strSize] = '\0';
} }
inline String::SharedString::SharedString(unsigned int strSize, unsigned int strCapacity) : inline String::SharedString::SharedString(std::size_t strSize, std::size_t strCapacity) :
capacity(strCapacity), capacity(strCapacity),
size(strSize), size(strSize),
string(new char[strCapacity + 1]) string(new char[strCapacity + 1])

View File

@ -50,7 +50,7 @@ namespace Nz
private: private:
std::vector<String> m_strings; std::vector<String> m_strings;
unsigned int m_bufferSize; std::size_t m_bufferSize;
}; };
} }

View File

@ -36,7 +36,7 @@ namespace Nz
template<typename T> constexpr T FromDegrees(T degrees); template<typename T> constexpr T FromDegrees(T degrees);
template<typename T> constexpr T FromRadians(T radians); template<typename T> constexpr T FromRadians(T radians);
template<typename T> constexpr T DegreeToRadian(T degrees); template<typename T> constexpr T DegreeToRadian(T degrees);
unsigned int GetNearestPowerOfTwo(unsigned int number); template<typename T> T GetNearestPowerOfTwo(T number);
unsigned int GetNumberLength(signed char number); unsigned int GetNumberLength(signed char number);
unsigned int GetNumberLength(unsigned char number); unsigned int GetNumberLength(unsigned char number);
unsigned int GetNumberLength(int number); unsigned int GetNumberLength(int number);

View File

@ -156,10 +156,11 @@ namespace Nz
#endif #endif
} }
inline unsigned int GetNearestPowerOfTwo(unsigned int number) template<typename T>
T GetNearestPowerOfTwo(T number)
{ {
///TODO: Marquer comme constexpr en C++14 ///TODO: Marquer comme constexpr en C++14
unsigned int x = 1; T x = 1;
// Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux // Tant que x est plus petit que n, on décale ses bits vers la gauche, ce qui revient à multiplier par deux
while (x < number) while (x < number)
x <<= 1; x <<= 1;

View File

@ -109,13 +109,13 @@ namespace Nz
template<typename T> template<typename T>
T Vector3<T>::GetLength() const T Vector3<T>::GetLength() const
{ {
return std::sqrt(GetSquaredLength()); return static_cast<T>(std::sqrt(GetSquaredLength()));
} }
template<typename T> template<typename T>
float Vector3<T>::GetLengthf() const float Vector3<T>::GetLengthf() const
{ {
return std::sqrt(static_cast<float>(GetSquaredLength())); return std::sqrt<float>(static_cast<float>(GetSquaredLength()));
} }
template<typename T> template<typename T>

View File

@ -34,12 +34,12 @@ namespace Nz
~VertexDeclaration(); ~VertexDeclaration();
void DisableComponent(VertexComponent component); void DisableComponent(VertexComponent component);
void EnableComponent(VertexComponent component, ComponentType type, unsigned int offset); void EnableComponent(VertexComponent component, ComponentType type, std::size_t offset);
void GetComponent(VertexComponent component, bool* enabled, ComponentType* type, unsigned int* offset) const; void GetComponent(VertexComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const;
unsigned int GetStride() const; std::size_t GetStride() const;
void SetStride(unsigned int stride); void SetStride(std::size_t stride);
VertexDeclaration& operator=(const VertexDeclaration& declaration); VertexDeclaration& operator=(const VertexDeclaration& declaration);
@ -58,7 +58,7 @@ namespace Nz
{ {
ComponentType type; // Le type de donnée ComponentType type; // Le type de donnée
bool enabled = false; // Ce composant est-il activé ?/ bool enabled = false; // Ce composant est-il activé ?/
unsigned int offset; // La position, en octets, de la première donnée std::size_t offset; // La position, en octets, de la première donnée
/* /*
** -Lynix: ** -Lynix:
@ -70,7 +70,7 @@ namespace Nz
}; };
Component m_components[VertexComponent_Max+1]; Component m_components[VertexComponent_Max+1];
unsigned int m_stride; std::size_t m_stride;
static VertexDeclaration s_declarations[VertexLayout_Max+1]; static VertexDeclaration s_declarations[VertexLayout_Max+1];
static VertexDeclarationLibrary::LibraryMap s_library; static VertexDeclarationLibrary::LibraryMap s_library;

View File

@ -16,7 +16,7 @@ namespace Nz
// Ensuite le composant qui nous intéresse // Ensuite le composant qui nous intéresse
bool enabled; bool enabled;
ComponentType type; ComponentType type;
unsigned int offset; std::size_t offset;
declaration->GetComponent(component, &enabled, &type, &offset); declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled) if (enabled)

View File

@ -6,6 +6,7 @@
#include <Nazara/Core/Config.hpp> #include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp> #include <Nazara/Core/File.hpp>
#include <cstddef>
#include <cstring> #include <cstring>
#if defined(NAZARA_PLATFORM_WINDOWS) #if defined(NAZARA_PLATFORM_WINDOWS)
@ -165,7 +166,7 @@ namespace Nz
#endif #endif
String name; String name;
do for (;;)
{ {
if (!m_impl->NextResult()) if (!m_impl->NextResult())
return false; return false;
@ -178,7 +179,6 @@ namespace Nz
if (name.Match(m_pattern)) if (name.Match(m_pattern))
break; break;
} }
while (true);
return true; return true;
} }
@ -268,7 +268,7 @@ namespace Nz
if (recursive) if (recursive)
{ {
String path = File::NormalizePath(dirPath); String path = File::NormalizePath(dirPath);
unsigned int foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR); std::size_t foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR);
if (foundPos == String::npos) if (foundPos == String::npos)
return false; return false;
@ -280,13 +280,13 @@ namespace Nz
if (foundPos == String::npos) if (foundPos == String::npos)
return false; return false;
foundPos = path.Find('\\', foundPos+1); foundPos = path.Find('\\', foundPos + 1);
if (foundPos == String::npos) if (foundPos == String::npos)
return false; return false;
} }
#endif #endif
do for (;;)
{ {
String p = path.SubString(0, foundPos); String p = path.SubString(0, foundPos);
if (p.EndsWith(NAZARA_DIRECTORY_SEPARATOR)) if (p.EndsWith(NAZARA_DIRECTORY_SEPARATOR))
@ -298,9 +298,8 @@ namespace Nz
if (foundPos == String::npos) if (foundPos == String::npos)
break; break;
foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR, foundPos+1); foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR, foundPos + 1);
} }
while (true);
return true; return true;
} }
@ -324,25 +323,14 @@ namespace Nz
const char* Directory::GetCurrentFileRelativeToEngine(const char* currentFile) const char* Directory::GetCurrentFileRelativeToEngine(const char* currentFile)
{ {
///FIXME: Est-ce que cette méthode est au bon endroit ? ///FIXME: Est-ce que cette méthode est au bon endroit ?
static int offset = -1; const char* ptr = std::strstr(currentFile, "NazaraEngine/");
if (!ptr)
ptr = std::strstr(currentFile, "NazaraEngine\\");
if (offset < 0) if (!ptr)
{ ptr = currentFile;
const char* directoryFile = __FILE__;
const char* ptr = std::strstr(directoryFile, "NazaraEngine/src/Nazara/Core/Directory.cpp");
if (ptr)
offset = ptr - directoryFile;
else
{
ptr = std::strstr(directoryFile, "NazaraEngine\\src\\Nazara\\Core\\Directory.cpp");
if (ptr)
offset = ptr - directoryFile;
else
offset = 0;
}
}
return &currentFile[offset]; return ptr;
} }
bool Directory::Remove(const String& dirPath, bool emptyDirectory) bool Directory::Remove(const String& dirPath, bool emptyDirectory)

View File

@ -152,9 +152,9 @@ namespace Nz
{ {
// Stores the penalty score of the best rectangle placement - bigger=worse, smaller=better. // Stores the penalty score of the best rectangle placement - bigger=worse, smaller=better.
bool bestFlipped; bool bestFlipped;
int bestFreeRect; std::size_t bestFreeRect;
int bestRect; std::size_t bestRect;
int bestScore = std::numeric_limits<int>::max(); std::size_t bestScore = std::numeric_limits<std::size_t>::max();
for (std::size_t i = 0; i < m_freeRectangles.size(); ++i) for (std::size_t i = 0; i < m_freeRectangles.size(); ++i)
{ {
@ -170,7 +170,7 @@ namespace Nz
bestFreeRect = i; bestFreeRect = i;
bestRect = j; bestRect = j;
bestFlipped = false; bestFlipped = false;
bestScore = std::numeric_limits<int>::min(); bestScore = std::numeric_limits<std::size_t>::min();
i = m_freeRectangles.size(); // Force a jump out of the outer loop as well - we got an instant fit. i = m_freeRectangles.size(); // Force a jump out of the outer loop as well - we got an instant fit.
break; break;
} }
@ -180,7 +180,7 @@ namespace Nz
bestFreeRect = i; bestFreeRect = i;
bestRect = j; bestRect = j;
bestFlipped = true; bestFlipped = true;
bestScore = std::numeric_limits<int>::min(); bestScore = std::numeric_limits<std::size_t>::min();
i = m_freeRectangles.size(); // Force a jump out of the outer loop as well - we got an instant fit. i = m_freeRectangles.size(); // Force a jump out of the outer loop as well - we got an instant fit.
break; break;
} }
@ -212,14 +212,14 @@ namespace Nz
} }
// If we didn't manage to find any rectangle to pack, abort. // If we didn't manage to find any rectangle to pack, abort.
if (bestScore == std::numeric_limits<int>::max()) if (bestScore == std::numeric_limits<std::size_t>::max())
{ {
// Si nous le pouvons, on marque les rectangles n'ayant pas pu être insérés // Si nous le pouvons, on marque les rectangles n'ayant pas pu être insérés
if (inserted) if (inserted)
{ {
for (Rectui* rect : remainingRects) for (Rectui* rect : remainingRects)
{ {
unsigned int position = rect - rects; std::ptrdiff_t position = rect - rects;
inserted[position] = false; inserted[position] = false;
} }
} }
@ -228,7 +228,7 @@ namespace Nz
} }
// Otherwise, we're good to go and do the actual packing. // Otherwise, we're good to go and do the actual packing.
unsigned int position = remainingRects[bestRect] - rects; std::ptrdiff_t position = remainingRects[bestRect] - rects;
Rectui& rect = *remainingRects[bestRect]; Rectui& rect = *remainingRects[bestRect];
rect.x = m_freeRectangles[bestFreeRect].x; rect.x = m_freeRectangles[bestFreeRect].x;
rect.y = m_freeRectangles[bestFreeRect].y; rect.y = m_freeRectangles[bestFreeRect].y;

View File

@ -98,7 +98,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashCRC32::Append(const UInt8* data, unsigned int len) void HashCRC32::Append(const UInt8* data, std::size_t len)
{ {
while (len--) while (len--)
m_state->crc = m_state->table[(m_state->crc ^ *data++) & 0xFF] ^ (m_state->crc >> 8); m_state->crc = m_state->table[(m_state->crc ^ *data++) & 0xFF] ^ (m_state->crc >> 8);
@ -120,7 +120,7 @@ namespace Nz
return ByteArray(reinterpret_cast<UInt8*>(&m_state->crc), 4); return ByteArray(reinterpret_cast<UInt8*>(&m_state->crc), 4);
} }
unsigned int HashCRC32::GetDigestLength() const std::size_t HashCRC32::GetDigestLength() const
{ {
return 4; return 4;
} }

View File

@ -24,11 +24,11 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashFletcher16::Append(const UInt8* data, unsigned int len) void HashFletcher16::Append(const UInt8* data, std::size_t len)
{ {
while (len) while (len)
{ {
unsigned int tlen = std::min(len, 21U); std::size_t tlen = std::min<std::size_t>(len, 21U);
len -= tlen; len -= tlen;
do do
{ {
@ -62,7 +62,7 @@ namespace Nz
return ByteArray(reinterpret_cast<UInt8*>(&fletcher), 2); return ByteArray(reinterpret_cast<UInt8*>(&fletcher), 2);
} }
unsigned int HashFletcher16::GetDigestLength() const std::size_t HashFletcher16::GetDigestLength() const
{ {
return 2; return 2;
} }

View File

@ -277,7 +277,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashMD5::Append(const UInt8* data, unsigned int len) void HashMD5::Append(const UInt8* data, std::size_t len)
{ {
const UInt8 *p = data; const UInt8 *p = data;
int left = len; int left = len;
@ -352,7 +352,7 @@ namespace Nz
return ByteArray(&digest[0], 16); return ByteArray(&digest[0], 16);
} }
unsigned int HashMD5::GetDigestLength() const std::size_t HashMD5::GetDigestLength() const
{ {
return 16; return 16;
} }

View File

@ -18,7 +18,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashSHA1::Append(const UInt8* data, unsigned int len) void HashSHA1::Append(const UInt8* data, std::size_t len)
{ {
SHA1_Update(m_state, data, len); SHA1_Update(m_state, data, len);
} }
@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA1_DIGEST_LENGTH); return ByteArray(digest, SHA1_DIGEST_LENGTH);
} }
unsigned int HashSHA1::GetDigestLength() const std::size_t HashSHA1::GetDigestLength() const
{ {
return SHA1_DIGEST_LENGTH; return SHA1_DIGEST_LENGTH;
} }

View File

@ -18,7 +18,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashSHA224::Append(const UInt8* data, unsigned int len) void HashSHA224::Append(const UInt8* data, std::size_t len)
{ {
SHA224_Update(m_state, data, len); SHA224_Update(m_state, data, len);
} }
@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA224_DIGEST_LENGTH); return ByteArray(digest, SHA224_DIGEST_LENGTH);
} }
unsigned int HashSHA224::GetDigestLength() const std::size_t HashSHA224::GetDigestLength() const
{ {
return SHA224_DIGEST_LENGTH; return SHA224_DIGEST_LENGTH;
} }

View File

@ -18,7 +18,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashSHA256::Append(const UInt8* data, unsigned int len) void HashSHA256::Append(const UInt8* data, std::size_t len)
{ {
SHA256_Update(m_state, data, len); SHA256_Update(m_state, data, len);
} }
@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA256_DIGEST_LENGTH); return ByteArray(digest, SHA256_DIGEST_LENGTH);
} }
unsigned int HashSHA256::GetDigestLength() const std::size_t HashSHA256::GetDigestLength() const
{ {
return SHA256_DIGEST_LENGTH; return SHA256_DIGEST_LENGTH;
} }

View File

@ -18,7 +18,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashSHA384::Append(const UInt8* data, unsigned int len) void HashSHA384::Append(const UInt8* data, std::size_t len)
{ {
SHA384_Update(m_state, data, len); SHA384_Update(m_state, data, len);
} }
@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA384_DIGEST_LENGTH); return ByteArray(digest, SHA384_DIGEST_LENGTH);
} }
unsigned int HashSHA384::GetDigestLength() const std::size_t HashSHA384::GetDigestLength() const
{ {
return SHA384_DIGEST_LENGTH; return SHA384_DIGEST_LENGTH;
} }

View File

@ -18,7 +18,7 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashSHA512::Append(const UInt8* data, unsigned int len) void HashSHA512::Append(const UInt8* data, std::size_t len)
{ {
SHA512_Update(m_state, data, len); SHA512_Update(m_state, data, len);
} }
@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA512_DIGEST_LENGTH); return ByteArray(digest, SHA512_DIGEST_LENGTH);
} }
unsigned int HashSHA512::GetDigestLength() const std::size_t HashSHA512::GetDigestLength() const
{ {
return SHA512_DIGEST_LENGTH; return SHA512_DIGEST_LENGTH;
} }

View File

@ -866,12 +866,12 @@ namespace Nz
delete m_state; delete m_state;
} }
void HashWhirlpool::Append(const UInt8* data, unsigned int len) void HashWhirlpool::Append(const UInt8* data, std::size_t len)
{ {
len *= 8; // Whirlpool fonctionne avec une taille en bits len *= 8; // Whirlpool works with bits
int sourcePos = 0; /* index of leftmost source UInt8 containing data (1 to 8 bits). */ int sourcePos = 0; /* index of leftmost source UInt8 containing data (1 to 8 bits). */
int sourceGap = (8 - (static_cast<int>(len) & 7)) & 7; /* space on source[sourcePos]. */ int sourceGap = (8 - (static_cast<std::intmax_t>(len) & 7)) & 7; /* space on source[sourcePos]. */
int bufferRem = m_state->bufferBits & 7; /* occupied bits on buffer[bufferPos]. */ int bufferRem = m_state->bufferBits & 7; /* occupied bits on buffer[bufferPos]. */
UInt32 b; UInt32 b;
@ -1015,7 +1015,7 @@ namespace Nz
return ByteArray(&result[0], 64); return ByteArray(&result[0], 64);
} }
unsigned int HashWhirlpool::GetDigestLength() const std::size_t HashWhirlpool::GetDigestLength() const
{ {
return 64; return 64;
} }

View File

@ -100,7 +100,6 @@ namespace Nz
std::fclose(log); std::fclose(log);
throw std::bad_alloc(); throw std::bad_alloc();
return nullptr; // Ça me rassure d'avoir un return, aussi inutile soit-il
} }
ptr->array = multi; ptr->array = multi;

View File

@ -73,37 +73,21 @@ namespace Nz
m_primitives.push_back(Primitive::UVSphere(size, sliceCount, stackCount, position, rotation)); m_primitives.push_back(Primitive::UVSphere(size, sliceCount, stackCount, position, rotation));
} }
Primitive& PrimitiveList::GetPrimitive(unsigned int i) Primitive& PrimitiveList::GetPrimitive(std::size_t i)
{ {
#if NAZARA_CORE_SAFE NazaraAssert(i < m_primitives.size(), "Primitive index out of range");
if (i >= m_primitives.size())
{
NazaraError("Primitive index out of range (" + String::Number(i) + " >= " + String::Number(m_primitives.size()) + ')');
static Primitive dummy;
return dummy;
}
#endif
return m_primitives[i]; return m_primitives[i];
} }
const Primitive& PrimitiveList::GetPrimitive(unsigned int i) const const Primitive& PrimitiveList::GetPrimitive(std::size_t i) const
{ {
#if NAZARA_CORE_SAFE NazaraAssert(i < m_primitives.size(), "Primitive index out of range");
if (i >= m_primitives.size())
{
NazaraError("Primitive index out of range (" + String::Number(i) + " >= " + String::Number(m_primitives.size()) + ')');
static Primitive dummy;
return dummy;
}
#endif
return m_primitives[i]; return m_primitives[i];
} }
unsigned int PrimitiveList::GetSize() const std::size_t PrimitiveList::GetSize() const
{ {
return m_primitives.size(); return m_primitives.size();
} }

View File

@ -32,7 +32,7 @@ namespace Nz
char buffer[bufferSize + 1]; char buffer[bufferSize + 1];
buffer[bufferSize] = '\0'; buffer[bufferSize] = '\0';
unsigned int readSize; std::size_t readSize;
do do
{ {
readSize = Read(buffer, bufferSize); readSize = Read(buffer, bufferSize);
@ -40,7 +40,7 @@ namespace Nz
const char* ptr = std::strchr(buffer, '\n'); const char* ptr = std::strchr(buffer, '\n');
if (ptr) if (ptr)
{ {
unsigned int pos = ptr - buffer; std::ptrdiff_t pos = ptr - buffer;
if (m_streamOptions & StreamOption_Text && pos > 0 && buffer[pos - 1] == '\r') if (m_streamOptions & StreamOption_Text && pos > 0 && buffer[pos - 1] == '\r')
line.Append(buffer, pos - 1); line.Append(buffer, pos - 1);
@ -60,8 +60,8 @@ namespace Nz
else else
{ {
line.Set(lineSize, '\0'); line.Set(lineSize, '\0');
unsigned int readSize = Read(&line[0], lineSize); std::size_t readSize = Read(&line[0], lineSize);
unsigned int pos = line.Find('\n'); std::size_t pos = line.Find('\n');
if (pos <= readSize) // Faux uniquement si le caractère n'est pas présent (npos étant le plus grand entier) if (pos <= readSize) // Faux uniquement si le caractère n'est pas présent (npos étant le plus grand entier)
{ {
if (m_streamOptions & StreamOption_Text && pos > 0 && line[pos - 1] == '\r') if (m_streamOptions & StreamOption_Text && pos > 0 && line[pos - 1] == '\r')

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@
namespace Nz namespace Nz
{ {
bool TaskSchedulerImpl::Initialize(unsigned int workerCount) bool TaskSchedulerImpl::Initialize(std::size_t workerCount)
{ {
if (IsInitialized()) if (IsInitialized())
return true; // Déjà initialisé return true; // Déjà initialisé
@ -30,9 +30,9 @@ namespace Nz
s_workerThreads.reset(new HANDLE[workerCount]); s_workerThreads.reset(new HANDLE[workerCount]);
// L'identifiant de chaque worker doit rester en vie jusqu'à ce que chaque thread soit correctement lancé // L'identifiant de chaque worker doit rester en vie jusqu'à ce que chaque thread soit correctement lancé
std::unique_ptr<unsigned int[]> workerIDs(new unsigned int[workerCount]); std::unique_ptr<std::size_t[]> workerIDs(new std::size_t[workerCount]);
for (unsigned int i = 0; i < workerCount; ++i) for (std::size_t i = 0; i < workerCount; ++i)
{ {
// On initialise les évènements, mutex et threads de chaque worker // On initialise les évènements, mutex et threads de chaque worker
Worker& worker = s_workers[i]; Worker& worker = s_workers[i];
@ -59,18 +59,18 @@ namespace Nz
return s_workerCount > 0; return s_workerCount > 0;
} }
void TaskSchedulerImpl::Run(Functor** tasks, unsigned int count) void TaskSchedulerImpl::Run(Functor** tasks, std::size_t count)
{ {
// On s'assure que des tâches ne sont pas déjà en cours // On s'assure que des tâches ne sont pas déjà en cours
WaitForMultipleObjects(s_workerCount, &s_doneEvents[0], true, INFINITE); WaitForMultipleObjects(s_workerCount, &s_doneEvents[0], true, INFINITE);
std::ldiv_t div = std::ldiv(count, s_workerCount); // Division et modulo en une opération, y'a pas de petit profit std::ldiv_t div = std::ldiv(count, s_workerCount); // Division et modulo en une opération, y'a pas de petit profit
for (unsigned int i = 0; i < s_workerCount; ++i) for (std::size_t i = 0; i < s_workerCount; ++i)
{ {
// On va maintenant répartir les tâches entre chaque worker et les envoyer dans la queue de chacun // On va maintenant répartir les tâches entre chaque worker et les envoyer dans la queue de chacun
Worker& worker = s_workers[i]; Worker& worker = s_workers[i];
unsigned int taskCount = (i == 0) ? div.quot + div.rem : div.quot; std::size_t taskCount = (i == 0) ? div.quot + div.rem : div.quot;
for (unsigned int j = 0; j < taskCount; ++j) for (std::size_t j = 0; j < taskCount; ++j)
worker.queue.push(*tasks++); worker.queue.push(*tasks++);
// On stocke le nombre de tâches à côté dans un entier atomique pour éviter d'entrer inutilement dans une section critique // On stocke le nombre de tâches à côté dans un entier atomique pour éviter d'entrer inutilement dans une section critique
@ -145,13 +145,13 @@ namespace Nz
WaitForMultipleObjects(s_workerCount, &s_doneEvents[0], true, INFINITE); WaitForMultipleObjects(s_workerCount, &s_doneEvents[0], true, INFINITE);
} }
Functor* TaskSchedulerImpl::StealTask(unsigned int workerID) Functor* TaskSchedulerImpl::StealTask(std::size_t workerID)
{ {
bool shouldRetry; bool shouldRetry;
do do
{ {
shouldRetry = false; shouldRetry = false;
for (unsigned int i = 0; i < s_workerCount; ++i) for (std::size_t i = 0; i < s_workerCount; ++i)
{ {
// On ne vole pas la famille, ni soi-même. // On ne vole pas la famille, ni soi-même.
if (i == workerID) if (i == workerID)
@ -244,5 +244,5 @@ namespace Nz
std::unique_ptr<HANDLE[]> TaskSchedulerImpl::s_doneEvents; // Doivent être contigus std::unique_ptr<HANDLE[]> TaskSchedulerImpl::s_doneEvents; // Doivent être contigus
std::unique_ptr<TaskSchedulerImpl::Worker[]> TaskSchedulerImpl::s_workers; std::unique_ptr<TaskSchedulerImpl::Worker[]> TaskSchedulerImpl::s_workers;
std::unique_ptr<HANDLE[]> TaskSchedulerImpl::s_workerThreads; // Doivent être contigus std::unique_ptr<HANDLE[]> TaskSchedulerImpl::s_workerThreads; // Doivent être contigus
unsigned int TaskSchedulerImpl::s_workerCount; std::size_t TaskSchedulerImpl::s_workerCount;
} }

View File

@ -22,19 +22,19 @@ namespace Nz
TaskSchedulerImpl() = delete; TaskSchedulerImpl() = delete;
~TaskSchedulerImpl() = delete; ~TaskSchedulerImpl() = delete;
static bool Initialize(unsigned int workerCount); static bool Initialize(std::size_t workerCount);
static bool IsInitialized(); static bool IsInitialized();
static void Run(Functor** tasks, unsigned int count); static void Run(Functor** tasks, std::size_t count);
static void Uninitialize(); static void Uninitialize();
static void WaitForTasks(); static void WaitForTasks();
private: private:
static Functor* StealTask(unsigned int workerID); static Functor* StealTask(std::size_t workerID);
static unsigned int __stdcall WorkerProc(void* userdata); static unsigned int __stdcall WorkerProc(void* userdata);
struct Worker struct Worker
{ {
std::atomic_uint workCount; std::atomic_size_t workCount;
std::queue<Functor*> queue; std::queue<Functor*> queue;
CRITICAL_SECTION queueMutex; CRITICAL_SECTION queueMutex;
HANDLE wakeEvent; HANDLE wakeEvent;
@ -44,7 +44,7 @@ namespace Nz
static std::unique_ptr<HANDLE[]> s_doneEvents; // Doivent être contigus static std::unique_ptr<HANDLE[]> s_doneEvents; // Doivent être contigus
static std::unique_ptr<Worker[]> s_workers; static std::unique_ptr<Worker[]> s_workers;
static std::unique_ptr<HANDLE[]> s_workerThreads; // Doivent être contigus static std::unique_ptr<HANDLE[]> s_workerThreads; // Doivent être contigus
static unsigned int s_workerCount; static std::size_t s_workerCount;
}; };
} }

View File

@ -1556,7 +1556,7 @@ namespace Nz
{ {
ComponentType type; ComponentType type;
bool enabled; bool enabled;
unsigned int offset; std::size_t offset;
vertexDeclaration->GetComponent(static_cast<VertexComponent>(j), &enabled, &type, &offset); vertexDeclaration->GetComponent(static_cast<VertexComponent>(j), &enabled, &type, &offset);
if (enabled) if (enabled)

View File

@ -379,9 +379,8 @@ namespace Nz
m_vertices[i].current_score = CalculateVertexScore(i); m_vertices[i].current_score = CalculateVertexScore(i);
// calculate scores for all active triangles // calculate scores for all active triangles
float max_score; float max_score = std::numeric_limits<float>::lowest();
int max_score_tri = -1; int max_score_tri = -1;
bool first_time = true;
for (unsigned int i = 0; i < m_triangles.size(); ++i) for (unsigned int i = 0; i < m_triangles.size(); ++i)
{ {
@ -395,9 +394,8 @@ namespace Nz
m_triangles[i].current_score = sc; m_triangles[i].current_score = sc;
if (first_time || sc > max_score) if (sc > max_score)
{ {
first_time = false;
max_score = sc; max_score = sc;
max_score_tri = i; max_score_tri = i;
} }
@ -564,8 +562,7 @@ namespace Nz
int PartialScoreRecalculation() int PartialScoreRecalculation()
{ {
// iterate through all the vertices of the cache // iterate through all the vertices of the cache
bool first_time = true; float max_score = std::numeric_limits<float>::lowest();
float max_score;
int max_score_tri = -1; int max_score_tri = -1;
for (unsigned int i = 0; i < 32; ++i) for (unsigned int i = 0; i < 32; ++i)
@ -588,9 +585,8 @@ namespace Nz
float sc = t->current_score; float sc = t->current_score;
// we actually found a triangle to process // we actually found a triangle to process
if (first_time || sc > max_score) if (sc > max_score)
{ {
first_time = false;
max_score = sc; max_score = sc;
max_score_tri = tri; max_score_tri = tri;
} }

View File

@ -58,7 +58,7 @@ namespace Nz
} }
} }
void VertexDeclaration::EnableComponent(VertexComponent component, ComponentType type, unsigned int offset) void VertexDeclaration::EnableComponent(VertexComponent component, ComponentType type, std::size_t offset)
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (component > VertexComponent_Max) if (component > VertexComponent_Max)
@ -91,7 +91,7 @@ namespace Nz
m_stride += Utility::ComponentStride[type]; m_stride += Utility::ComponentStride[type];
} }
void VertexDeclaration::GetComponent(VertexComponent component, bool* enabled, ComponentType* type, unsigned int* offset) const void VertexDeclaration::GetComponent(VertexComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const
{ {
#ifdef NAZARA_DEBUG #ifdef NAZARA_DEBUG
if (component > VertexComponent_Max) if (component > VertexComponent_Max)
@ -121,12 +121,12 @@ namespace Nz
*offset = vertexComponent.offset; *offset = vertexComponent.offset;
} }
unsigned int VertexDeclaration::GetStride() const std::size_t VertexDeclaration::GetStride() const
{ {
return m_stride; return m_stride;
} }
void VertexDeclaration::SetStride(unsigned int stride) void VertexDeclaration::SetStride(std::size_t stride)
{ {
m_stride = stride; m_stride = stride;
} }