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

@@ -6,6 +6,7 @@
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <cstddef>
#include <cstring>
#if defined(NAZARA_PLATFORM_WINDOWS)
@@ -165,7 +166,7 @@ namespace Nz
#endif
String name;
do
for (;;)
{
if (!m_impl->NextResult())
return false;
@@ -178,7 +179,6 @@ namespace Nz
if (name.Match(m_pattern))
break;
}
while (true);
return true;
}
@@ -268,7 +268,7 @@ namespace Nz
if (recursive)
{
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)
return false;
@@ -280,13 +280,13 @@ namespace Nz
if (foundPos == String::npos)
return false;
foundPos = path.Find('\\', foundPos+1);
foundPos = path.Find('\\', foundPos + 1);
if (foundPos == String::npos)
return false;
}
#endif
do
for (;;)
{
String p = path.SubString(0, foundPos);
if (p.EndsWith(NAZARA_DIRECTORY_SEPARATOR))
@@ -298,9 +298,8 @@ namespace Nz
if (foundPos == String::npos)
break;
foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR, foundPos+1);
foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR, foundPos + 1);
}
while (true);
return true;
}
@@ -324,25 +323,14 @@ namespace Nz
const char* Directory::GetCurrentFileRelativeToEngine(const char* currentFile)
{
///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)
{
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;
}
}
if (!ptr)
ptr = currentFile;
return &currentFile[offset];
return ptr;
}
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.
bool bestFlipped;
int bestFreeRect;
int bestRect;
int bestScore = std::numeric_limits<int>::max();
std::size_t bestFreeRect;
std::size_t bestRect;
std::size_t bestScore = std::numeric_limits<std::size_t>::max();
for (std::size_t i = 0; i < m_freeRectangles.size(); ++i)
{
@@ -170,7 +170,7 @@ namespace Nz
bestFreeRect = i;
bestRect = j;
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.
break;
}
@@ -180,7 +180,7 @@ namespace Nz
bestFreeRect = i;
bestRect = j;
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.
break;
}
@@ -212,14 +212,14 @@ namespace Nz
}
// 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
if (inserted)
{
for (Rectui* rect : remainingRects)
{
unsigned int position = rect - rects;
std::ptrdiff_t position = rect - rects;
inserted[position] = false;
}
}
@@ -228,7 +228,7 @@ namespace Nz
}
// 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];
rect.x = m_freeRectangles[bestFreeRect].x;
rect.y = m_freeRectangles[bestFreeRect].y;

View File

@@ -98,7 +98,7 @@ namespace Nz
delete m_state;
}
void HashCRC32::Append(const UInt8* data, unsigned int len)
void HashCRC32::Append(const UInt8* data, std::size_t len)
{
while (len--)
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);
}
unsigned int HashCRC32::GetDigestLength() const
std::size_t HashCRC32::GetDigestLength() const
{
return 4;
}

View File

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

View File

@@ -277,7 +277,7 @@ namespace Nz
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;
int left = len;
@@ -352,7 +352,7 @@ namespace Nz
return ByteArray(&digest[0], 16);
}
unsigned int HashMD5::GetDigestLength() const
std::size_t HashMD5::GetDigestLength() const
{
return 16;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
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);
}
@@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA1_DIGEST_LENGTH);
}
unsigned int HashSHA1::GetDigestLength() const
std::size_t HashSHA1::GetDigestLength() const
{
return SHA1_DIGEST_LENGTH;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
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);
}
@@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA224_DIGEST_LENGTH);
}
unsigned int HashSHA224::GetDigestLength() const
std::size_t HashSHA224::GetDigestLength() const
{
return SHA224_DIGEST_LENGTH;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
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);
}
@@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA256_DIGEST_LENGTH);
}
unsigned int HashSHA256::GetDigestLength() const
std::size_t HashSHA256::GetDigestLength() const
{
return SHA256_DIGEST_LENGTH;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
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);
}
@@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA384_DIGEST_LENGTH);
}
unsigned int HashSHA384::GetDigestLength() const
std::size_t HashSHA384::GetDigestLength() const
{
return SHA384_DIGEST_LENGTH;
}

View File

@@ -18,7 +18,7 @@ namespace Nz
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);
}
@@ -37,7 +37,7 @@ namespace Nz
return ByteArray(digest, SHA512_DIGEST_LENGTH);
}
unsigned int HashSHA512::GetDigestLength() const
std::size_t HashSHA512::GetDigestLength() const
{
return SHA512_DIGEST_LENGTH;
}

View File

@@ -866,12 +866,12 @@ namespace Nz
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 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]. */
UInt32 b;
@@ -1015,7 +1015,7 @@ namespace Nz
return ByteArray(&result[0], 64);
}
unsigned int HashWhirlpool::GetDigestLength() const
std::size_t HashWhirlpool::GetDigestLength() const
{
return 64;
}

View File

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

View File

@@ -73,37 +73,21 @@ namespace Nz
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
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
NazaraAssert(i < m_primitives.size(), "Primitive index out of range");
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
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
NazaraAssert(i < m_primitives.size(), "Primitive index out of range");
return m_primitives[i];
}
unsigned int PrimitiveList::GetSize() const
std::size_t PrimitiveList::GetSize() const
{
return m_primitives.size();
}

View File

@@ -32,7 +32,7 @@ namespace Nz
char buffer[bufferSize + 1];
buffer[bufferSize] = '\0';
unsigned int readSize;
std::size_t readSize;
do
{
readSize = Read(buffer, bufferSize);
@@ -40,7 +40,7 @@ namespace Nz
const char* ptr = std::strchr(buffer, '\n');
if (ptr)
{
unsigned int pos = ptr - buffer;
std::ptrdiff_t pos = ptr - buffer;
if (m_streamOptions & StreamOption_Text && pos > 0 && buffer[pos - 1] == '\r')
line.Append(buffer, pos - 1);
@@ -60,8 +60,8 @@ namespace Nz
else
{
line.Set(lineSize, '\0');
unsigned int readSize = Read(&line[0], lineSize);
unsigned int pos = line.Find('\n');
std::size_t readSize = Read(&line[0], lineSize);
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 (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
{
bool TaskSchedulerImpl::Initialize(unsigned int workerCount)
bool TaskSchedulerImpl::Initialize(std::size_t workerCount)
{
if (IsInitialized())
return true; // Déjà initialisé
@@ -30,9 +30,9 @@ namespace Nz
s_workerThreads.reset(new HANDLE[workerCount]);
// 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
Worker& worker = s_workers[i];
@@ -59,18 +59,18 @@ namespace Nz
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
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
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
Worker& worker = s_workers[i];
unsigned int taskCount = (i == 0) ? div.quot + div.rem : div.quot;
for (unsigned int j = 0; j < taskCount; ++j)
std::size_t taskCount = (i == 0) ? div.quot + div.rem : div.quot;
for (std::size_t j = 0; j < taskCount; ++j)
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
@@ -145,13 +145,13 @@ namespace Nz
WaitForMultipleObjects(s_workerCount, &s_doneEvents[0], true, INFINITE);
}
Functor* TaskSchedulerImpl::StealTask(unsigned int workerID)
Functor* TaskSchedulerImpl::StealTask(std::size_t workerID)
{
bool shouldRetry;
do
{
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.
if (i == workerID)
@@ -244,5 +244,5 @@ namespace Nz
std::unique_ptr<HANDLE[]> TaskSchedulerImpl::s_doneEvents; // Doivent être contigus
std::unique_ptr<TaskSchedulerImpl::Worker[]> TaskSchedulerImpl::s_workers;
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;
static bool Initialize(unsigned int workerCount);
static bool Initialize(std::size_t workerCount);
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 WaitForTasks();
private:
static Functor* StealTask(unsigned int workerID);
static Functor* StealTask(std::size_t workerID);
static unsigned int __stdcall WorkerProc(void* userdata);
struct Worker
{
std::atomic_uint workCount;
std::atomic_size_t workCount;
std::queue<Functor*> queue;
CRITICAL_SECTION queueMutex;
HANDLE wakeEvent;
@@ -44,7 +44,7 @@ namespace Nz
static std::unique_ptr<HANDLE[]> s_doneEvents; // Doivent être contigus
static std::unique_ptr<Worker[]> s_workers;
static std::unique_ptr<HANDLE[]> s_workerThreads; // Doivent être contigus
static unsigned int s_workerCount;
static std::size_t s_workerCount;
};
}