Refactored mathematics module

Added AABBs
Added code examples
Added experimental support for texture arrays (1D/2D)
Added initialisers (new way of initialising modules)
Added global headers (Plus a global header generator script)
Added pattern support for directory
Added support for spinlocks critical section on Windows
Added NzRenderWindow::SetFramerateLimit
Core project now includes Mathematics files
Fixed color implementation using double
Fixed declaration needing renderer include
Fixed MLT not clearing nextFree(File/Line) after Free
Fixed move operators not being noexcept
Fixed thread-safety (Now working correctly - If I'm lucky)
Moved Resource to core
New interface for modules
New interface for the renderer
Put some global functions to anonymous namespace
Removed empty modules
Renamed ThreadCondition to ConditionVariable
Replaced redirect to cerr log option by duplicate to cout
Setting mouse position relative to a window will make this window ignore
the event
Shaders sending methods no longer takes the uniform variable name (it's
using ID instead)
Using new OpenGL 4.3 header
This commit is contained in:
Lynix
2012-08-08 04:44:17 +02:00
parent 06eda4eba9
commit b442ab0bd2
142 changed files with 6861 additions and 2326 deletions

View File

@@ -15,6 +15,24 @@
#include <Nazara/Core/Debug.hpp>
namespace
{
nzUInt64 NzGetMicrosecondsLowPrecision()
{
return NzClockImplGetMilliseconds()*1000ULL;
}
nzUInt64 NzGetMicrosecondsFirstRun()
{
if (NzClockImplInitializeHighPrecision())
NzGetMicroseconds = NzClockImplGetMicroseconds;
else
NzGetMicroseconds = NzGetMicrosecondsLowPrecision;
return NzGetMicroseconds();
}
}
NzClock::NzClock() :
m_elapsedTime(0),
m_refTime(NzGetMicroseconds()),
@@ -81,20 +99,5 @@ void NzClock::Unpause()
NazaraWarning("Clock is not paused, ignoring...");
}
nzUInt64 NzGetMicrosecondsLowPrecision()
{
return NzClockImplGetMilliseconds()*1000ULL;
}
nzUInt64 NzGetMicrosecondsFirstRun()
{
if (NzClockImplInitializeHighPrecision())
NzGetMicroseconds = NzClockImplGetMicroseconds;
else
NzGetMicroseconds = NzGetMicrosecondsLowPrecision;
return NzGetMicroseconds();
}
NzClockFunction NzGetMicroseconds = NzGetMicrosecondsFirstRun;
NzClockFunction NzGetMilliseconds = NzClockImplGetMilliseconds;

View File

@@ -2,45 +2,45 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/ThreadCondition.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Mutex.hpp>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <Nazara/Core/Win32/ThreadConditionImpl.hpp>
#include <Nazara/Core/Win32/ConditionVariableImpl.hpp>
#elif defined(NAZARA_PLATFORM_POSIX)
#include <Nazara/Core/Posix/ThreadConditionImpl.hpp>
#include <Nazara/Core/Posix/ConditionVariableImpl.hpp>
#else
#error Thread condition has no implementation
#endif
#include <Nazara/Core/Debug.hpp>
NzThreadCondition::NzThreadCondition()
NzConditionVariable::NzConditionVariable()
{
m_impl = new NzThreadConditionImpl;
m_impl = new NzConditionVariableImpl;
}
NzThreadCondition::~NzThreadCondition()
NzConditionVariable::~NzConditionVariable()
{
delete m_impl;
}
void NzThreadCondition::Signal()
void NzConditionVariable::Signal()
{
m_impl->Signal();
}
void NzThreadCondition::SignalAll()
void NzConditionVariable::SignalAll()
{
m_impl->SignalAll();
}
void NzThreadCondition::Wait(NzMutex* mutex)
void NzConditionVariable::Wait(NzMutex* mutex)
{
m_impl->Wait(mutex->m_impl);
}
bool NzThreadCondition::Wait(NzMutex* mutex, nzUInt32 timeout)
bool NzConditionVariable::Wait(NzMutex* mutex, nzUInt32 timeout)
{
return m_impl->Wait(mutex->m_impl, timeout);
}

39
src/Nazara/Core/Core.cpp Normal file
View File

@@ -0,0 +1,39 @@
// Copyright (C) 2012 AUTHORS
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/Debug.hpp>
bool NzCore::Initialize()
{
if (s_moduleReferenceCouter++ != 0)
return true; // Déjà initialisé
// Initialisation du module
// Le noyau de Nazara n'a pour l'instant aucun besoin d'initialisation, mais dans le futur il est très probable que ce soit le cas.
// Donc en prévision, tous les modules initialisent le noyau
NazaraNotice("Initialized: Core");
return true;
}
bool NzCore::IsInitialized()
{
return s_moduleReferenceCouter != 0;
}
void NzCore::Uninitialize()
{
if (--s_moduleReferenceCouter != 0)
return; // Encore utilisé
// Libération du module
NazaraNotice("Uninitialized: Core");
}
unsigned int NzCore::s_moduleReferenceCouter = 0;

View File

@@ -119,19 +119,16 @@ void NzMemoryManager::Free(void* pointer, bool multi)
if (nextFreeFile)
{
if (multi)
std::fprintf(log, "%s Warning: delete[] on new at %s:%d\n", time, nextFreeFile, nextFreeLine);
std::fprintf(log, "%s Warning: delete[] after new at %s:%d\n", time, nextFreeFile, nextFreeLine);
else
std::fprintf(log, "%s Warning: delete on new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
nextFreeFile = nullptr;
nextFreeLine = 0;
std::fprintf(log, "%s Warning: delete after new[] at %s:%d\n", time, nextFreeFile, nextFreeLine);
}
else
{
if (multi)
std::fprintf(log, "%s Warning: delete[] on new at unknown position\n", time);
std::fprintf(log, "%s Warning: delete[] after new at unknown position\n", time);
else
std::fprintf(log, "%s Warning: delete on new[] at unknown position\n", time);
std::fprintf(log, "%s Warning: delete after new[] at unknown position\n", time);
}
std::fclose(log);
@@ -145,6 +142,9 @@ void NzMemoryManager::Free(void* pointer, bool multi)
std::free(ptr);
nextFreeFile = nullptr;
nextFreeLine = 0;
#if defined(NAZARA_PLATFORM_WINDOWS)
LeaveCriticalSection(&mutex);
#elif defined(NAZARA_PLATFORM_POSIX)

View File

@@ -25,14 +25,14 @@ namespace
}
NzDirectory::NzDirectory() :
m_impl(nullptr)
m_pattern('*')
{
}
NzDirectory::NzDirectory(const NzString& dirPath) :
m_impl(nullptr)
m_dirPath(dirPath),
m_pattern('*')
{
SetDirectory(dirPath);
}
NzDirectory::~NzDirectory()
@@ -42,18 +42,27 @@ NzDirectory::~NzDirectory()
void NzDirectory::Close()
{
NazaraLock(m_mutex);
if (m_impl)
{
m_impl->Close();
delete m_impl;
m_impl = nullptr;
NazaraMutexUnlock(m_mutex);
}
}
NzString NzDirectory::GetPattern() const
{
NazaraLock(m_mutex);
return m_pattern;
}
NzString NzDirectory::GetResultName() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@@ -67,6 +76,8 @@ NzString NzDirectory::GetResultName() const
NzString NzDirectory::GetResultPath() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@@ -80,6 +91,8 @@ NzString NzDirectory::GetResultPath() const
nzUInt64 NzDirectory::GetResultSize() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@@ -91,8 +104,17 @@ nzUInt64 NzDirectory::GetResultSize() const
return m_impl->GetResultSize();
}
bool NzDirectory::IsOpen() const
{
NazaraLock(m_mutex);
return m_impl != nullptr;
}
bool NzDirectory::IsResultDirectory() const
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@@ -106,6 +128,8 @@ bool NzDirectory::IsResultDirectory() const
bool NzDirectory::NextResult(bool skipDots)
{
NazaraLock(m_mutex);
#if NAZARA_CORE_SAFE
if (!m_impl)
{
@@ -114,41 +138,40 @@ bool NzDirectory::NextResult(bool skipDots)
}
#endif
if (skipDots)
NzString name;
do
{
NzString name;
do
{
if (!m_impl->NextResult())
return false;
if (!m_impl->NextResult())
return false;
name = m_impl->GetResultName();
}
while (name == '.' || name == "..");
name = m_impl->GetResultName();
return true;
if (skipDots && (name == '.' || name == ".."))
continue;
if (name.Match(m_pattern))
break;
}
else
return m_impl->NextResult();
while (true);
return true;
}
bool NzDirectory::Open()
{
NazaraLock(m_mutex);
Close();
if (!Exists(m_dirPath))
return false;
NazaraMutexLock(m_mutex);
m_impl = new NzDirectoryImpl(this);
if (!m_impl->Open(m_dirPath))
{
delete m_impl;
m_impl = nullptr;
NazaraMutexUnlock(m_mutex);
return false;
}
@@ -157,11 +180,20 @@ bool NzDirectory::Open()
void NzDirectory::SetDirectory(const NzString& dirPath)
{
NazaraLock(m_mutex);
Close();
m_dirPath = NzFile::AbsolutePath(dirPath);
}
void NzDirectory::SetPattern(const NzString& pattern)
{
NazaraLock(m_mutex);
m_pattern = pattern;
}
bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath)
{
if (sourcePath.IsEmpty() || destPath.IsEmpty())
@@ -187,12 +219,12 @@ bool NzDirectory::Copy(const NzString& sourcePath, const NzString& destPath)
{
if (dir.IsResultDirectory())
{
if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
if (!Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
return false;
}
else if (!NzFile::Copy(dir.GetResultPath(), dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName()))
{
NazaraError("Unable to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"');
NazaraError("Failed to copy \"" + dir.GetResultPath() + "\" to \"" + dest + NAZARA_DIRECTORY_SEPARATOR + dir.GetResultName() + '"');
return false;
}
}

View File

@@ -42,7 +42,7 @@ NzString NzGetLastSystemError(unsigned int code)
wchar_t* buffer = nullptr;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
0,
nullptr,
code,
0,
reinterpret_cast<LPWSTR>(&buffer),

View File

@@ -45,7 +45,7 @@ m_openMode(0)
Open(openMode);
}
NzFile::NzFile(NzFile&& file) :
NzFile::NzFile(NzFile&& file) noexcept :
m_endianness(file.m_endianness),
m_filePath(std::move(file.m_filePath)),
m_impl(file.m_impl),
@@ -525,7 +525,7 @@ NzFile& NzFile::operator=(const NzString& filePath)
return *this;
}
NzFile& NzFile::operator=(NzFile&& file)
NzFile& NzFile::operator=(NzFile&& file) noexcept
{
NazaraLock(m_mutex)
@@ -570,7 +570,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
NazaraError("Path unrecognized");
return path;
}
#elif NAZARA_PLATEFORM_LINUX
#elif defined(NAZARA_PLATEFORM_LINUX)
base = '/';
start = 0;
#else
@@ -718,7 +718,7 @@ bool NzFile::IsAbsolute(const NzString& path)
return true;
else
return false;
#elif NAZARA_PLATEFORM_LINUX
#elif defined(NAZARA_PLATEFORM_LINUX)
return wpath.StartsWith('/');
#else
#error OS case not implemented
@@ -752,7 +752,7 @@ NzString NzFile::NormalizeSeparators(const NzString& filePath)
#elif defined(NAZARA_PLATFORM_LINUX)
path.Replace('\\', '/');
#else
#error OS not handled
#error OS case not implemented
#endif
return path;
@@ -793,4 +793,4 @@ bool NzFile::FillHash(NzHashImpl* hash) const
}
return true;
} // Fermeture auttomatique du fichier
} // Fermeture automatique du fichier

View File

@@ -136,7 +136,7 @@ namespace
* On little-endian machines, we can process properly aligned
* data without copying it.
*/
if (!((data - reinterpret_cast<const nzUInt8*>(0)) & 3))
if (!(data - static_cast<const nzUInt8*>(nullptr)) & 3)
{
/* data are properly aligned */
X = reinterpret_cast<const nzUInt32*>(data);

View File

@@ -315,119 +315,122 @@ void SHA1_Init(SHA_CTX* context)
(b) = ROTL32(30, b); \
j++;
void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
namespace
{
nzUInt32 a, b, c, d, e;
nzUInt32 T1, *W1;
int j;
void SHA1_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
{
nzUInt32 a, b, c, d, e;
nzUInt32 T1, *W1;
int j;
W1 = reinterpret_cast<nzUInt32*>(context->s1.buffer);
W1 = reinterpret_cast<nzUInt32*>(context->s1.buffer);
/* Initialize registers with the prev. intermediate value */
a = context->s1.state[0];
b = context->s1.state[1];
c = context->s1.state[2];
d = context->s1.state[3];
e = context->s1.state[4];
/* Initialize registers with the prev. intermediate value */
a = context->s1.state[0];
b = context->s1.state[1];
c = context->s1.state[2];
d = context->s1.state[3];
e = context->s1.state[4];
j = 0;
j = 0;
/* Rounds 0 to 15 unrolled: */
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
/* Rounds 0 to 15 unrolled: */
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
ROUND1_0_TO_15(e,a,b,c,d);
ROUND1_0_TO_15(d,e,a,b,c);
ROUND1_0_TO_15(c,d,e,a,b);
ROUND1_0_TO_15(b,c,d,e,a);
ROUND1_0_TO_15(a,b,c,d,e);
/* Rounds 16 to 19 unrolled: */
ROUND1_16_TO_19(e,a,b,c,d);
ROUND1_16_TO_19(d,e,a,b,c);
ROUND1_16_TO_19(c,d,e,a,b);
ROUND1_16_TO_19(b,c,d,e,a);
/* Rounds 16 to 19 unrolled: */
ROUND1_16_TO_19(e,a,b,c,d);
ROUND1_16_TO_19(d,e,a,b,c);
ROUND1_16_TO_19(c,d,e,a,b);
ROUND1_16_TO_19(b,c,d,e,a);
/* Rounds 20 to 39 unrolled: */
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
/* Rounds 20 to 39 unrolled: */
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
ROUND1_20_TO_39(a,b,c,d,e);
ROUND1_20_TO_39(e,a,b,c,d);
ROUND1_20_TO_39(d,e,a,b,c);
ROUND1_20_TO_39(c,d,e,a,b);
ROUND1_20_TO_39(b,c,d,e,a);
/* Rounds 40 to 59 unrolled: */
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
/* Rounds 40 to 59 unrolled: */
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
ROUND1_40_TO_59(a,b,c,d,e);
ROUND1_40_TO_59(e,a,b,c,d);
ROUND1_40_TO_59(d,e,a,b,c);
ROUND1_40_TO_59(c,d,e,a,b);
ROUND1_40_TO_59(b,c,d,e,a);
/* Rounds 60 to 79 unrolled: */
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
/* Rounds 60 to 79 unrolled: */
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
ROUND1_60_TO_79(a,b,c,d,e);
ROUND1_60_TO_79(e,a,b,c,d);
ROUND1_60_TO_79(d,e,a,b,c);
ROUND1_60_TO_79(c,d,e,a,b);
ROUND1_60_TO_79(b,c,d,e,a);
/* Compute the current intermediate hash value */
context->s1.state[0] += a;
context->s1.state[1] += b;
context->s1.state[2] += c;
context->s1.state[3] += d;
context->s1.state[4] += e;
/* Compute the current intermediate hash value */
context->s1.state[0] += a;
context->s1.state[1] += b;
context->s1.state[2] += c;
context->s1.state[3] += d;
context->s1.state[4] += e;
}
}
void SHA1_Update(SHA_CTX* context, const nzUInt8* data, std::size_t len)
@@ -766,9 +769,12 @@ void SHA224_Init(SHA_CTX* context)
SHA256_Internal_Init(context, sha224_initial_hash_value);
}
void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
namespace
{
SHA256_Internal_Transform(context, data);
void SHA224_Internal_Transform(SHA_CTX* context, const nzUInt32* data)
{
SHA256_Internal_Transform(context, data);
}
}
void SHA224_Update(SHA_CTX* context, const nzUInt8 *data, std::size_t len)

View File

@@ -42,7 +42,7 @@ m_digestLength(rhs.m_digestLength)
m_digest = nullptr;
}
NzHashDigest::NzHashDigest(NzHashDigest&& rhs) :
NzHashDigest::NzHashDigest(NzHashDigest&& rhs) noexcept :
m_hashName(std::move(rhs.m_hashName)),
m_digest(rhs.m_digest),
m_digestLength(rhs.m_digestLength)
@@ -118,7 +118,7 @@ NzHashDigest& NzHashDigest::operator=(const NzHashDigest& rhs)
return *this;
}
NzHashDigest& NzHashDigest::operator=(NzHashDigest&& rhs)
NzHashDigest& NzHashDigest::operator=(NzHashDigest&& rhs) noexcept
{
std::swap(m_hashName, rhs.m_hashName);
std::swap(m_digest, rhs.m_digest);

View File

@@ -8,8 +8,9 @@
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Math/Basic.hpp>
#include <ctime>
#include <cstring>
#if NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE
#if NAZARA_CORE_DUPLICATE_TO_COUT
#include <cstdio>
#endif
@@ -17,7 +18,7 @@
namespace
{
NzString errorType[] = {
const char* errorType[] = {
"Assert failed: ", // nzErrorType_AssertFailed
"Internal error: ", // nzErrorType_Internal
"Error: ", // nzErrorType_Normal
@@ -124,12 +125,11 @@ void NzLog::Write(const NzString& string)
line += string;
line += '\n';
#if NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE
if (!m_file->IsOpen() || !m_file->Write(line))
std::fputs(line.GetBuffer(), stderr);
#else
if (m_file->IsOpen())
m_file->Write(line);
#if NAZARA_CORE_DUPLICATE_TO_COUT
std::fputs(line.GetConstBuffer(), stderr);
#endif
}
}
@@ -137,7 +137,7 @@ void NzLog::Write(const NzString& string)
void NzLog::WriteError(nzErrorType type, const NzString& error, unsigned int line, const NzString& file, const NzString& func)
{
NzString stream;
stream.Reserve(errorType[type].GetSize() + error.GetSize() + 2 + file.GetSize() + 1 + NzGetNumberLength(line) +2 + func.GetSize() + 1);
stream.Reserve(std::strlen(errorType[type]) + error.GetSize() + 2 + file.GetSize() + 1 + NzGetNumberLength(line) +2 + func.GetSize() + 1);
stream += errorType[type];
stream += error;
stream += " (";

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
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp>
NzResource::NzResource(bool persistent) :
m_resourcePersistent(persistent),
m_resourceReferenceCount(0)
{
}
NzResource::NzResource(const NzResource& resource) :
m_resourcePersistent(resource.m_resourcePersistent),
m_resourceReferenceCount(0)
{
}
NzResource::~NzResource() = default;
void NzResource::AddResourceReference() const
{
m_resourceReferenceCount++;
}
bool NzResource::IsPersistent() const
{
return m_resourcePersistent;
}
void NzResource::RemoveResourceReference() const
{
#if NAZARA_CORE_SAFE
if (m_resourceReferenceCount == 0)
{
NazaraError("Impossible to remove reference (Ref. counter is already 0)");
return;
}
#endif
if (--m_resourceReferenceCount == 0 && !m_resourcePersistent)
delete this;
}
void NzResource::SetPersistent(bool persistent)
{
m_resourcePersistent = persistent;
if (!persistent && m_resourceReferenceCount == 0)
delete this;
}

View File

@@ -142,7 +142,7 @@ m_sharedString(string.m_sharedString)
}
}
NzString::NzString(NzString&& string) :
NzString::NzString(NzString&& string) noexcept :
m_sharedString(string.m_sharedString)
{
string.m_sharedString = &emptyString;
@@ -307,7 +307,6 @@ unsigned int NzString::Count(char character, int start, nzUInt32 flags) const
{
char character_lower = nzToLower(character);
char character_upper = nzToUpper(character);
unsigned int count = 0;
do
{
if (*str == character_lower || *str == character_upper)
@@ -807,14 +806,14 @@ unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const
{
if (NzUnicode::GetLowercase(*it) == c)
{
const char* pos = it.base();
const char* ptrPos = it.base();
++it;
utf8::unchecked::iterator<const char*> it2(t);
while (true)
{
if (*it2 == '\0')
return static_cast<unsigned int>(pos - m_sharedString->string);
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
if (*it == '\0')
return npos;
@@ -836,14 +835,14 @@ unsigned int NzString::Find(const char* string, int start, nzUInt32 flags) const
{
if (nzToLower(*str) == c)
{
char* pos = str;
char* ptrPos = str;
str++;
const char* ptr = &string[1];
while (true)
{
if (*ptr == '\0')
return static_cast<unsigned int>(pos - m_sharedString->string);
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
if (*str == '\0')
return npos;
@@ -897,14 +896,14 @@ unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) c
{
if (NzUnicode::GetLowercase(*it) == c)
{
const char* pos = it.base();
const char* ptrPos = it.base();
++it;
utf8::unchecked::iterator<const char*> it2(t);
while (true)
{
if (*it2 == '\0')
return static_cast<unsigned int>(pos - m_sharedString->string);
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
if (*it == '\0')
return npos;
@@ -926,14 +925,14 @@ unsigned int NzString::Find(const NzString& string, int start, nzUInt32 flags) c
{
if (nzToLower(*str) == c)
{
char* pos = str;
char* ptrPos = str;
str++;
const char* ptr = &string.m_sharedString->string[1];
while (true)
{
if (*ptr == '\0')
return static_cast<unsigned int>(pos - m_sharedString->string);
return static_cast<unsigned int>(ptrPos - m_sharedString->string);
if (*str == '\0')
return npos;
@@ -2296,7 +2295,7 @@ char16_t* NzString::GetUtf16Buffer(unsigned int* size) const
catch (const utf8::exception& exception)
{
NazaraError("UTF-8 error : " + NzString(exception.what()));
return 0;
return nullptr;
}
#endif
@@ -2340,7 +2339,7 @@ char32_t* NzString::GetUtf32Buffer(unsigned int* size) const
catch (const utf8::exception& exception)
{
NazaraError("UTF-8 error : " + NzString(exception.what()));
return 0;
return nullptr;
}
#endif
}
@@ -2387,7 +2386,7 @@ wchar_t* NzString::GetWideBuffer(unsigned int* size) const
catch (const utf8::exception& exception)
{
NazaraError("UTF-8 error : " + NzString(exception.what()));
return 0;
return nullptr;
}
#endif
}
@@ -2621,7 +2620,7 @@ bool NzString::IsNull() const
bool NzString::IsNumber(nzUInt8 base, nzUInt32 flags) const
{
#if !NAZARA_UNSAFE
#if NAZARA_CORE_SAFE
if (base < 2 || base > 36)
{
NazaraError("Base must be between 2 and 36");
@@ -2770,11 +2769,11 @@ unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start,
{
if (!found)
{
unsigned int pos = ptr-m_sharedString->string;
unsigned int offset = ptr-m_sharedString->string;
EnsureOwnership();
ptr = &m_sharedString->string[pos];
ptr = &m_sharedString->string[offset];
found = true;
}
@@ -2790,11 +2789,11 @@ unsigned int NzString::Replace(char oldCharacter, char newCharacter, int start,
{
if (!found)
{
unsigned int pos = ptr-m_sharedString->string;
unsigned int offset = ptr-m_sharedString->string;
EnsureOwnership();
ptr = &m_sharedString->string[pos];
ptr = &m_sharedString->string[offset];
found = true;
}
@@ -2954,6 +2953,7 @@ unsigned int NzString::Replace(const NzString& oldString, const NzString& replac
unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharacter, int start, nzUInt32 flags)
{
///FIXME: Ne gère pas l'UTF-8
if (!oldCharacters || !oldCharacters[0])
return 0;
@@ -2982,11 +2982,11 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact
{
if (!found)
{
unsigned int pos = ptr-m_sharedString->string;
unsigned int offset = ptr-m_sharedString->string;
EnsureOwnership();
ptr = &m_sharedString->string[pos];
ptr = &m_sharedString->string[offset];
found = true;
}
@@ -3006,11 +3006,11 @@ unsigned int NzString::ReplaceAny(const char* oldCharacters, char replaceCharact
{
if (!found)
{
unsigned int pos = ptr-m_sharedString->string;
unsigned int offset = ptr-m_sharedString->string;
EnsureOwnership();
ptr = &m_sharedString->string[pos];
ptr = &m_sharedString->string[offset];
found = true;
}
@@ -3203,7 +3203,10 @@ void NzString::Reserve(unsigned int bufferSize)
NzString& NzString::Resize(int size, char character)
{
if (size == 0)
{
Clear(true);
return *this;
}
if (size < 0)
size = std::max(static_cast<int>(m_sharedString->size + size), 0);
@@ -3249,9 +3252,6 @@ NzString& NzString::Resize(int size, char character)
NzString NzString::Resized(int size, char character) const
{
if (size == 0)
return NzString();
if (size < 0)
size = m_sharedString->size + size;
@@ -3692,12 +3692,12 @@ NzString NzString::Substr(int startPos, int endPos) const
return NzString();
}
unsigned int end = std::min(static_cast<unsigned int>(endPos), m_sharedString->size-1);
unsigned int minEnd = std::min(static_cast<unsigned int>(endPos), m_sharedString->size-1);
if (start > end || start >= m_sharedString->size)
if (start > minEnd || start >= m_sharedString->size)
return NzString();
unsigned int size = end-start+1;
unsigned int size = minEnd-start+1;
char* str = new char[size+1];
std::memcpy(str, &m_sharedString->string[start], size*sizeof(char));
str[size] = '\0';
@@ -4232,7 +4232,7 @@ NzString& NzString::operator=(const NzString& string)
return *this;
}
NzString& NzString::operator=(NzString&& string)
NzString& NzString::operator=(NzString&& string) noexcept
{
std::swap(m_sharedString, string.m_sharedString);
@@ -5107,7 +5107,6 @@ void NzString::ReleaseString()
if (freeSharedString)
{
NazaraMutexUnlock(m_sharedString->mutex);
delete[] m_sharedString->string;
delete m_sharedString;
}

View File

@@ -4,13 +4,13 @@
// Source: http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
#include <Nazara/Core/Win32/ThreadConditionImpl.hpp>
#include <Nazara/Core/Win32/ConditionVariableImpl.hpp>
#include <Nazara/Core/Win32/MutexImpl.hpp>
#include <Nazara/Core/Debug.hpp>
NzThreadConditionImpl::NzThreadConditionImpl()
NzConditionVariableImpl::NzConditionVariableImpl()
{
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
#if NAZARA_CORE_WINDOWS_VISTA
InitializeConditionVariable(&m_cv);
#else
m_count = 0;
@@ -20,16 +20,16 @@ NzThreadConditionImpl::NzThreadConditionImpl()
#endif
}
#ifndef NAZARA_PLATFORM_WINDOWSVISTA
NzThreadConditionImpl::~NzThreadConditionImpl()
#if !NAZARA_CORE_WINDOWS_VISTA
NzConditionVariableImpl::~NzConditionVariableImpl()
{
DeleteCriticalSection(&m_countLock);
}
#endif
void NzThreadConditionImpl::Signal()
void NzConditionVariableImpl::Signal()
{
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
#if NAZARA_CORE_WINDOWS_VISTA
WakeConditionVariable(&m_cv);
#else
// Avoid race conditions.
@@ -42,9 +42,9 @@ void NzThreadConditionImpl::Signal()
#endif
}
void NzThreadConditionImpl::SignalAll()
void NzConditionVariableImpl::SignalAll()
{
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
#if NAZARA_CORE_WINDOWS_VISTA
WakeAllConditionVariable(&m_cv);
#else
// Avoid race conditions.
@@ -57,14 +57,14 @@ void NzThreadConditionImpl::SignalAll()
#endif
}
void NzThreadConditionImpl::Wait(NzMutexImpl* mutex)
void NzConditionVariableImpl::Wait(NzMutexImpl* mutex)
{
Wait(mutex, INFINITE);
}
bool NzThreadConditionImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
{
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
#if NAZARA_CORE_WINDOWS_VISTA
return SleepConditionVariableCS(&m_cv, mutex->m_criticalSection, timeout);
#else
// Avoid race conditions.

View File

@@ -6,22 +6,22 @@
#pragma once
#ifndef NAZARA_THREADCONDITIONIMPL_HPP
#define NAZARA_THREADCONDITIONIMPL_HPP
#ifndef NAZARA_CONDITIONVARIABLEIMPL_HPP
#define NAZARA_CONDITIONVARIABLEIMPL_HPP
#include <Nazara/Prerequesites.hpp>
#include <windows.h>
class NzMutexImpl;
class NzThreadConditionImpl
class NzConditionVariableImpl
{
public:
NzThreadConditionImpl();
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
~NzThreadConditionImpl() = default;
NzConditionVariableImpl();
#if NAZARA_CORE_WINDOWS_VISTA
~NzConditionVariableImpl() = default;
#else
~NzThreadConditionImpl();
~NzConditionVariableImpl();
#endif
void Signal();
@@ -31,7 +31,7 @@ class NzThreadConditionImpl
bool Wait(NzMutexImpl* mutex, nzUInt32 timeout);
private:
#ifdef NAZARA_PLATFORM_WINDOWSVISTA
#if NAZARA_CORE_WINDOWS_VISTA
CONDITION_VARIABLE m_cv;
#else
enum
@@ -48,4 +48,4 @@ class NzThreadConditionImpl
};
#endif // NAZARA_THREADCONDITIONIMPL_HPP
#endif // NAZARA_CONDITIONVARIABLEIMPL_HPP

View File

@@ -117,7 +117,7 @@ std::size_t NzFileImpl::Read(void* buffer, std::size_t size)
/// D'après les tests, ce n'est pas le cas, la taille lue est inférieure à la taille en argument, mais pas nulle
/// Peut-être ais-je mal compris la documentation
/// Le correctif (dans le cas où la doc serait vraie) est commenté en début de fonction et après ce commentaire
/// Il est cependant plus lourd, et ne fonctionne pas selon les tests...
/// Il est cependant plus lourd, et ne fonctionne pas avec le comportement observé de la fonction
/*
if (read == 0)
{
@@ -254,7 +254,7 @@ time_t NzFileImpl::GetCreationTime(const NzString& filePath)
CloseHandle(handle);
return FileTimeToTime(&creationTime);
return NzFileTimeToTime(&creationTime);
}
time_t NzFileImpl::GetLastAccessTime(const NzString& filePath)
@@ -277,7 +277,7 @@ time_t NzFileImpl::GetLastAccessTime(const NzString& filePath)
CloseHandle(handle);
return FileTimeToTime(&accessTime);
return NzFileTimeToTime(&accessTime);
}
time_t NzFileImpl::GetLastWriteTime(const NzString& filePath)
@@ -300,7 +300,7 @@ time_t NzFileImpl::GetLastWriteTime(const NzString& filePath)
CloseHandle(handle);
return FileTimeToTime(&writeTime);
return NzFileTimeToTime(&writeTime);
}
nzUInt64 NzFileImpl::GetSize(const NzString& filePath)

View File

@@ -7,7 +7,11 @@
NzMutexImpl::NzMutexImpl()
{
#if NAZARA_CORE_WINDOWS_CS_SPINLOCKS > 0
InitializeCriticalSectionAndSpinCount(&m_criticalSection, NAZARA_CORE_WINDOWS_CS_SPINLOCKS);
#else
InitializeCriticalSection(&m_criticalSection);
#endif
}
NzMutexImpl::~NzMutexImpl()

View File

@@ -9,11 +9,11 @@
#include <windows.h>
class NzThreadConditionImpl;
class NzConditionVariableImpl;
class NzMutexImpl
{
friend class NzThreadConditionImpl;
friend class NzConditionVariableImpl;
public:
NzMutexImpl();

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
#include <Nazara/Core/Win32/Time.hpp>
time_t NzFileTimeToTime(FILETIME* time)
{
SYSTEMTIME stUTC, stLocal;
FileTimeToSystemTime(time, &stUTC);
SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal);
std::tm timeinfo;
timeinfo.tm_sec = stLocal.wSecond;
timeinfo.tm_min = stLocal.wMinute;
timeinfo.tm_hour = stLocal.wHour;
timeinfo.tm_mday = stLocal.wDay;
timeinfo.tm_mon = stLocal.wMonth-1;
timeinfo.tm_year = stLocal.wYear-1900;
timeinfo.tm_isdst = -1;
return std::mktime(&timeinfo);
}

View File

@@ -10,23 +10,6 @@
#include <ctime>
#include <windows.h>
time_t FileTimeToTime(FILETIME* time)
{
SYSTEMTIME stUTC, stLocal;
FileTimeToSystemTime(time, &stUTC);
SystemTimeToTzSpecificLocalTime(nullptr, &stUTC, &stLocal);
std::tm timeinfo;
timeinfo.tm_sec = stLocal.wSecond;
timeinfo.tm_min = stLocal.wMinute;
timeinfo.tm_hour = stLocal.wHour;
timeinfo.tm_mday = stLocal.wDay;
timeinfo.tm_mon = stLocal.wMonth-1;
timeinfo.tm_year = stLocal.wYear-1900;
timeinfo.tm_isdst = -1;
return std::mktime(&timeinfo);
}
time_t NzFileTimeToTime(FILETIME* time);
#endif // NAZARA_WINDOWS_TIME_HPP