Merge from DigitalPulseSoftware.

Former-commit-id: 17a2c31780b5e9b000a953d3a21fdfc8080bd21d
This commit is contained in:
Alexandre Janniaux 2013-01-05 01:17:58 +01:00
commit 9e0d263694
20 changed files with 211 additions and 196 deletions

View File

@ -24,6 +24,7 @@ class NAZARA_API NzDebugDrawer
static void Draw(const NzCubeui& cube); static void Draw(const NzCubeui& cube);
static void Draw(const NzSkeleton* skeleton); static void Draw(const NzSkeleton* skeleton);
static void DrawNormals(const NzSubMesh* subMesh); static void DrawNormals(const NzSubMesh* subMesh);
static void DrawTangents(const NzSubMesh* subMesh);
static bool Initialize(); static bool Initialize();

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -8,23 +8,21 @@
#include <sys/time.h> #include <sys/time.h>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
bool NzClockImplInitializeHighPrecision() bool NzClockImplInitializeHighPrecision()
{ {
// No initialization needed return true; // No initialization needed
} }
nzUInt64 NzClockImplGetMicroseconds() nzUInt64 NzClockImplGetMicroseconds()
{ {
timeval clock; timeval clock;
gettimeofday(&clock, nullptr); gettimeofday(&clock, nullptr);
return static_cast<nzUInt64>(clock.tv_sec*1000000 + (clock.tv_nsec/1000)); return static_cast<nzUInt64>(clock.tv_sec*1000000 + (clock.tv_nsec/1000));
} }
nzUInt64 NzClockImplGetMilliseconds() nzUInt64 NzClockImplGetMilliseconds()
{ {
timeval clock; timeval clock;
gettimeofday(&clock, nullptr); gettimeofday(&clock, nullptr);
return static_cast<nzUInt64>(clock.tv_sec*1000 + (clock.tv_nsec/1000000)); return static_cast<nzUInt64>(clock.tv_sec*1000 + (clock.tv_nsec/1000000));
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp

View File

@ -1,9 +1,7 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
// Source: http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
#include <Nazara/Core/Posix/ConditionVariableImpl.hpp> #include <Nazara/Core/Posix/ConditionVariableImpl.hpp>
#include <Nazara/Core/Posix/MutexImpl.hpp> #include <Nazara/Core/Posix/MutexImpl.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
@ -35,8 +33,6 @@ void NzConditionVariableImpl::Wait(NzMutexImpl* mutex)
bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout) bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
{ {
// get the current time // get the current time
timeval tv; timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
@ -48,5 +44,4 @@ bool NzConditionVariableImpl::Wait(NzMutexImpl* mutex, nzUInt32 timeout)
ti.tv_nsec %= 1000000000; ti.tv_nsec %= 1000000000;
pthread_cond_timedwait(&m_cv,mutex, &tv); pthread_cond_timedwait(&m_cv,mutex, &tv);
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -22,7 +22,6 @@ class NzConditionVariableImpl
NzConditionVariableImpl(); NzConditionVariableImpl();
~NzConditionVariableImpl(); ~NzConditionVariableImpl();
void Signal(); void Signal();
void SignalAll(); void SignalAll();
@ -30,7 +29,6 @@ class NzConditionVariableImpl
bool Wait(NzMutexImpl* mutex, nzUInt32 timeout); bool Wait(NzMutexImpl* mutex, nzUInt32 timeout);
private: private:
pthread_cond_t m_cv; pthread_cond_t m_cv;
}; };

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -6,7 +6,6 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzDirectoryImpl::NzDirectoryImpl(const NzDirectory* parent) NzDirectoryImpl::NzDirectoryImpl(const NzDirectory* parent)
{ {
NazaraUnused(parent); NazaraUnused(parent);
@ -19,15 +18,15 @@ void NzDirectoryImpl::Close()
NzString NzDirectoryImpl::GetResultName() const NzString NzDirectoryImpl::GetResultName() const
{ {
return NzString::Unicode(m_result.d_name); return m_result.d_name;
} }
nzUInt64 NzDirectoryImpl::GetResultSize() const nzUInt64 NzDirectoryImpl::GetResultSize() const
{ {
struct stat64 resulststat; struct stat64 resulststat;
stat64(m_result.d_name, &resulststat); stat64(m_result.d_name, &resulststat);
return static_cast<nzUInt64>(resulststat.st_size); return static_cast<nzUInt64>(resulststat.st_size);
} }
bool NzDirectoryImpl::IsResultDirectory() const bool NzDirectoryImpl::IsResultDirectory() const
@ -37,8 +36,7 @@ bool NzDirectoryImpl::IsResultDirectory() const
bool NzDirectoryImpl::NextResult() bool NzDirectoryImpl::NextResult()
{ {
if ((m_result = readdir64(m_handle)))
if (m_result = readdir64(m_handle))
return true; return true;
else else
{ {
@ -51,9 +49,8 @@ bool NzDirectoryImpl::NextResult()
bool NzDirectoryImpl::Open(const NzString& dirPath) bool NzDirectoryImpl::Open(const NzString& dirPath)
{ {
m_handle = opendir(dirPath.GetConstBuffer()); m_handle = opendir(dirPath.GetConstBuffer());
if (!m_handle)
if (m_handle == NULL)
{ {
NazaraError("Unable to open directory: " + NzGetLastSystemError()); NazaraError("Unable to open directory: " + NzGetLastSystemError());
return false; return false;
@ -64,17 +61,17 @@ bool NzDirectoryImpl::Open(const NzString& dirPath)
bool NzDirectoryImpl::Create(const NzString& dirPath) bool NzDirectoryImpl::Create(const NzString& dirPath)
{ {
mode_t permissions; // TODO: check permissions mode_t permissions; // TODO: check permissions
bool success = mkdir(dirPath.GetConstBuffer(), permissions) != -1;
return success; return mkdir(dirPath.GetConstBuffer(), permissions) != -1;;
} }
bool NzDirectoryImpl::Exists(const NzString& dirPath) bool NzDirectoryImpl::Exists(const NzString& dirPath)
{ {
if (S_ISDIR(dirPath.GetConstBuffer())) if (S_ISDIR(dirPath.GetConstBuffer()))
return true; return true;
return false;
return false;
} }
NzString NzDirectoryImpl::GetCurrent() NzString NzDirectoryImpl::GetCurrent()
@ -82,9 +79,9 @@ NzString NzDirectoryImpl::GetCurrent()
NzString currentPath; NzString currentPath;
char* path = new char[_PC_PATH_MAX]; char* path = new char[_PC_PATH_MAX];
if (getcwd(path, _PC_PATH_MAX)) if (getcwd(path, _PC_PATH_MAX))
currentPath = NzString::Unicode(path); currentPath = path;
else else
NazaraError("Unable to get current directory: " + NzGetLastSystemError()); NazaraError("Unable to get current directory: " + NzGetLastSystemError());
delete[] path; delete[] path;
@ -94,7 +91,6 @@ NzString NzDirectoryImpl::GetCurrent()
bool NzDirectoryImpl::Remove(const NzString& dirPath) bool NzDirectoryImpl::Remove(const NzString& dirPath)
{ {
bool success = rmdir(dirPath.GetConstBuffer()) != -1; bool success = rmdir(dirPath.GetConstBuffer()) != -1;
return success; return success;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -9,10 +9,10 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp> #include <Nazara/Core/NonCopyable.hpp>
#include <dirent.h>
#include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
class NzDirectory; class NzDirectory;
class NzString; class NzString;
@ -42,7 +42,6 @@ class NzDirectoryImpl : NzNonCopyable
private: private:
DIR* m_handle; DIR* m_handle;
dirent64* m_result; dirent64* m_result;
bool m_firstCall;
}; };
#endif // NAZARA_DIRECTORYIMPL_HPP #endif // NAZARA_DIRECTORYIMPL_HPP

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -15,11 +15,25 @@ m_parent(parent)
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const
{ {
NzDynLibFunc sym = reinterpret_cast<NzDynLibFunc>(dlsym(m_handle, symbol.GetConstBuffer())); /*
if (!sym) Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction.
m_parent->SetLastError(NzGetLastSystemError()); // dlerror() ? Nous devons donc utiliser des techniques diaboliques venant du malin lui-même.. :D
Au moins ce n'est pas aussi terrible qu'un const_cast
-Lynix
*/
union
{
NzDynLibFunc func;
void* pointer;
} converter;
return sym; dlerror(); // Clear error flag
converter.pointer = dlsym(m_handle, symbol.GetConstBuffer());
if (!converter.pointer)
m_parent->SetLastError(dlerror());
return converter.func;
} }
bool NzDynLibImpl::Load(const NzString& libraryPath) bool NzDynLibImpl::Load(const NzString& libraryPath)
@ -28,13 +42,15 @@ bool NzDynLibImpl::Load(const NzString& libraryPath)
if (!path.EndsWith(".so")) if (!path.EndsWith(".so"))
path += ".so"; path += ".so";
m_handle = dlopen(path.GetConstBuffer(),); dlerror(); // Clear error flag
m_handle = dlopen(path.GetConstBuffer(), RTLD_LAZY | RTLD_GLOBAL);
if (m_handle) if (m_handle)
return true; return true;
else else
{ {
m_parent->SetLastError(NzGetLastSystemError()); m_parent->SetLastError(dlerror());
return false; return false;
} }
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -27,7 +27,7 @@ bool NzFileImpl::EndOfFile() const
if (!m_endOfFileUpdated) if (!m_endOfFileUpdated)
{ {
stat64 fileSize; stat64 fileSize;
if (fstat64(m_handle, &fileSize) == -1) if (fstat64(m_fileDescriptor, &fileSize) == -1)
fileSize.st_size = 0; fileSize.st_size = 0;
m_endOfFile = (GetCursorPos() >= static_cast<nzUInt64>(fileSize.st_size)); m_endOfFile = (GetCursorPos() >= static_cast<nzUInt64>(fileSize.st_size));
@ -45,32 +45,30 @@ void NzFileImpl::Flush()
nzUInt64 NzFileImpl::GetCursorPos() const nzUInt64 NzFileImpl::GetCursorPos() const
{ {
off64_t position = lseek64(m_fileDescriptor, 0, SEEK_CUR); off64_t position = lseek64(m_fileDescriptor, 0, SEEK_CUR);
return static_cast<nzUInt64>(position); return static_cast<nzUInt64>(position);
} }
bool NzFileImpl::Open(const NzString& filePath, unsigned int mode) bool NzFileImpl::Open(const NzString& filePath, unsigned int mode)
{ {
int flags; int flags;
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
if (mode & NzFile::ReadOnly) if (mode & NzFile::ReadOnly)
flags = O_RDONLY; flags = O_RDONLY;
else if (mode & NzFile::ReadWrite) else if (mode & NzFile::ReadWrite)
{ {
flags = O_CREAT | O_RDWR; flags = O_CREAT | O_RDWR;
if (mode & NzFile::Append) if (mode & NzFile::Append)
flags |= O_APPEND; flags |= O_APPEND;
if (mode & NzFile::Truncate) if (mode & NzFile::Truncate)
flags |= O_TRUNC; flags |= O_TRUNC;
} }
else if (mode & NzFile::WriteOnly) else if (mode & NzFile::WriteOnly)
{ {
flags = O_CREAT | O_WRONLY; flags = O_CREAT | O_WRONLY;
if (mode & NzFile::Append) if (mode & NzFile::Append)
flags |= O_APPEND; flags |= O_APPEND;
@ -81,19 +79,17 @@ bool NzFileImpl::Open(const NzString& filePath, unsigned int mode)
else else
return false; return false;
// TODO: lock ///TODO: lock
// if ((mode & NzFile::Lock) == 0) // if ((mode & NzFile::Lock) == 0)
// shareMode |= FILE_SHARE_WRITE; // shareMode |= FILE_SHARE_WRITE;
const char* path = filePath.GetConstBuffer(); m_fileDescriptor = open64(filePath.GetConstBuffer(), flags, permissions);
return m_fileDescriptor != -1;
m_fileDescriptor = open64(path, flags, permissions);
return m_fileDescriptor != -1;
} }
std::size_t NzFileImpl::Read(void* buffer, std::size_t size) std::size_t NzFileImpl::Read(void* buffer, std::size_t size)
{ {
ssize_t bytes; ssize_t bytes;
if ((bytes = read(m_fileDescriptor, buffer, size)) != -1) if ((bytes = read(m_fileDescriptor, buffer, size)) != -1)
{ {
m_endOfFile = (static_cast<std::size_t>(bytes) != size); m_endOfFile = (static_cast<std::size_t>(bytes) != size);
@ -129,14 +125,14 @@ bool NzFileImpl::SetCursorPos(NzFile::CursorPosition pos, nzInt64 offset)
m_endOfFileUpdated = false; m_endOfFileUpdated = false;
return lseek64(m_fileDescriptor, offset, moveMethod) != -1; return lseek64(m_fileDescriptor, offset, moveMethod) != -1;
} }
std::size_t NzFileImpl::Write(const void* buffer, std::size_t size) std::size_t NzFileImpl::Write(const void* buffer, std::size_t size)
{ {
lockf64(m_fileDescriptor, F_LOCK, size); lockf64(m_fileDescriptor, F_LOCK, size);
ssize_t written = write(m_fileDescriptor, buffer, size); ssize_t written = write(m_fileDescriptor, buffer, size);
lockf64(m_fileDescriptor, F_ULOCK, size); lockf64(m_fileDescriptor, F_ULOCK, size);
m_endOfFileUpdated = false; m_endOfFileUpdated = false;
@ -145,47 +141,45 @@ std::size_t NzFileImpl::Write(const void* buffer, std::size_t size)
bool NzFileImpl::Copy(const NzString& sourcePath, const NzString& targetPath) bool NzFileImpl::Copy(const NzString& sourcePath, const NzString& targetPath)
{ {
int fd1 = open64(sourcePath.GetConstBuffer(), O_RDONLY); int fd1 = open64(sourcePath.GetConstBuffer(), O_RDONLY);
if (fd1 == -1) if (fd1 == -1)
{ {
NazaraError("Fail to open input file (" + sourcePath + "): " + NzGetLastSystemError()); NazaraError("Fail to open input file (" + sourcePath + "): " + NzGetLastSystemError());
return false; return false;
} }
mode_t permissions; // TODO : get permission from first file mode_t permissions; // TODO : get permission from first file
int fd2 = open64(sourcePath.GetConstBuffer(), O_WRONLY | O_TRUNC, permissions); int fd2 = open64(targetPath.GetConstBuffer(), O_WRONLY | O_TRUNC, permissions);
if (fd2 == -1) if (fd2 == -1)
{ {
NazaraError("Fail to open output file (" + targetPath + "): " + NzGetLastSystemError()); // TODO: more info ? NazaraError("Fail to open output file (" + targetPath + "): " + NzGetLastSystemError()); // TODO: more info ?
close(fd1); close(fd1);
return false; return false;
} }
char buffer[512];
ssize_t bytes;
do
{
bytes = read(fd1,buffer,512);
if (bytes == -1)
{
close(fd1);
close(fd2);
NazaraError("An error occured from copy : " + NzGetLastSystemError());
return false;
}
write(fd2,buffer,bytes);
}
while (bytes == 512);
char buffer[512]; close(fd1);
ssize_t bytes; close(fd2);
do
{
bytes = read(fd1,buffer,512);
if (bytes == -1)
{
close(fd1);
close(fd2);
NazaraError("An error occured from copy : " + NzGetLastSystemError());
return false;
}
write(fd2,buffer,bytes);
} while (bytes == 512);
close(fd1);
close(fd2);
} }
bool NzFileImpl::Delete(const NzString& filePath) bool NzFileImpl::Delete(const NzString& filePath)
{ {
const char* path = filePath.GetConstBuffer(); bool success = unlink(filePath.GetConstBuffer()) != -1;
bool success = unlink(path) != -1;
if (success) if (success)
return true; return true;
@ -199,49 +193,46 @@ bool NzFileImpl::Delete(const NzString& filePath)
bool NzFileImpl::Exists(const NzString& filePath) bool NzFileImpl::Exists(const NzString& filePath)
{ {
char* path = filePath.GetConstBuffer(); char* path = filePath.GetConstBuffer();
if (access(path, F_OK) != -1) if (access(path, F_OK) != -1)
return true; return true;
return false;
return false;
} }
time_t NzFileImpl::GetCreationTime(const NzString& filePath) time_t NzFileImpl::GetCreationTime(const NzString& filePath)
{ {
struct stat64 stats; NazaraWarning("Posix has no creation time information");
stat64(filePath.GetConstBuffer(), &stats);
return NzFileTimeToTime(std::ctime(&stats.st_ctim)); // not sure ? return 0;
} }
time_t NzFileImpl::GetLastAccessTime(const NzString& filePath) time_t NzFileImpl::GetLastAccessTime(const NzString& filePath)
{ {
struct stat64 stats; struct stat64 stats;
stat64(filePath.GetConstBuffer(), &stats); stat64(filePath.GetConstBuffer(), &stats);
return NzFileTimeToTime(std::ctime(&stats.st_atim)); return stats.st_atime;
} }
time_t NzFileImpl::GetLastWriteTime(const NzString& filePath) time_t NzFileImpl::GetLastWriteTime(const NzString& filePath)
{ {
struct stat64 stats; struct stat64 stats;
stat64(filePath.GetConstBuffer(), &stats); stat64(filePath.GetConstBuffer(), &stats);
return NzFileTimeToTime(std::ctime(&stats.st_mtim)); return stats.st_mtime;
} }
nzUInt64 NzFileImpl::GetSize(const NzString& filePath) nzUInt64 NzFileImpl::GetSize(const NzString& filePath)
{ {
struct stat64 stats; struct stat64 stats;
stat64(filePath.GetConstBuffer(), &stats); stat64(filePath.GetConstBuffer(), &stats);
return static_cast<nzUInt64>(stats.st_size); return static_cast<nzUInt64>(stats.st_size);
} }
bool NzFileImpl::Rename(const NzString& sourcePath, const NzString& targetPath) bool NzFileImpl::Rename(const NzString& sourcePath, const NzString& targetPath)
{ {
const char* path = sourcePath.GetConstBuffer(); bool success = std::rename(sourcePath.GetConstBuffer(), targetPath.GetConstBuffer()) != -1;
const char* newPath = targetPath.GetConstBuffer();
bool success = std::rename(path, newPath) != -1;
if (success) if (success)
return true; return true;

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -20,11 +20,6 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
/*
04/01/2012 : alexandre.janniaux@gmail.com
Add posix file implementation.
*/
class NzFile; class NzFile;
class NzString; class NzString;
@ -54,7 +49,6 @@ class NzFileImpl : NzNonCopyable
private: private:
int m_fileDescriptor; int m_fileDescriptor;
FILE* m_handle;
mutable bool m_endOfFile; mutable bool m_endOfFile;
mutable bool m_endOfFileUpdated; mutable bool m_endOfFileUpdated;
}; };

View File

@ -1,21 +1,14 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Posix/HardwareInfoImpl.hpp> #include <Nazara/Core/Posix/HardwareInfoImpl.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#ifdef NAZARA_COMPILER_MSVC
#include <intrin.h>
#endif
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
void NzHardwareInfoImpl::Cpuid(nzUInt32 code, nzUInt32 result[4]) void NzHardwareInfoImpl::Cpuid(nzUInt32 code, nzUInt32 result[4])
{ {
#if defined(NAZARA_COMPILER_MSVC) #if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
__cpuid(reinterpret_cast<int*>(result), static_cast<int>(code)); // Visual propose une fonction intrinsèque pour le cpuid
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
// Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c // Source: http://stackoverflow.com/questions/1666093/cpuid-implementations-in-c
asm volatile ("cpuid" // Besoin d'être volatile ? asm volatile ("cpuid" // Besoin d'être volatile ?
: "=a" (result[0]), "=b" (result[1]), "=c" (result[2]), "=d" (result[3]) // output : "=a" (result[0]), "=b" (result[1]), "=c" (result[2]), "=d" (result[3]) // output
@ -36,26 +29,7 @@ bool NzHardwareInfoImpl::IsCpuidSupported()
#ifdef NAZARA_PLATFORM_x64 #ifdef NAZARA_PLATFORM_x64
return true; // Toujours supporté sur un processeur 64 bits return true; // Toujours supporté sur un processeur 64 bits
#else #else
#if defined(NAZARA_COMPILER_MSVC) #if defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
int supported;
__asm
{
pushfd
pop eax
mov ecx, eax
xor eax, 0x200000
push eax
popfd
pushfd
pop eax
xor eax, ecx
mov supported, eax
push ecx
popfd
};
return supported != 0;
#elif defined(NAZARA_COMPILER_CLANG) || defined(NAZARA_COMPILER_GCC) || defined(NAZARA_COMPILER_INTEL)
int supported; int supported;
asm volatile (" pushfl\n" asm volatile (" pushfl\n"
" pop %%eax\n" " pop %%eax\n"

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -12,20 +12,20 @@ NzMutexImpl::NzMutexImpl()
NzMutexImpl::~NzMutexImpl() NzMutexImpl::~NzMutexImpl()
{ {
pthread_mutex_destroy(&m_handle); pthread_mutex_destroy(m_handle);
} }
void NzMutexImpl::Lock() void NzMutexImpl::Lock()
{ {
pthread_mutex_lock(&m_handle); pthread_mutex_lock(m_handle);
} }
bool NzMutexImpl::TryLock() bool NzMutexImpl::TryLock()
{ {
pthread_mutex_trylock(&m_handle) == 0; return pthread_mutex_trylock(m_handle) == 0;
} }
void NzMutexImpl::Unlock() void NzMutexImpl::Unlock()
{ {
pthread_mutex_unlock(&m_handle); pthread_mutex_unlock(m_handle);
} }

View File

@ -1,12 +1,7 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
/*
04/01/2012 : alexandre.janniaux@gmail.com
Add pthread mutex implementation.
*/
#pragma once #pragma once
#ifndef NAZARA_MUTEXIMPL_HPP #ifndef NAZARA_MUTEXIMPL_HPP

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -49,10 +49,10 @@ void NzSemaphoreImpl::Wait()
bool NzSemaphoreImpl::Wait(nzUInt32 timeout) bool NzSemaphoreImpl::Wait(nzUInt32 timeout)
{ {
timespec ti; timespec ti;
ti.tv_nsec = (tv.tv_usec + (timeout % 1000)) * 1000000; ti.tv_nsec = (tv.tv_usec + (timeout % 1000)) * 1000000;
ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000); ti.tv_sec = tv.tv_sec + (timeout / 1000) + (ti.tv_nsec / 1000000000);
ti.tv_nsec %= 1000000000; ti.tv_nsec %= 1000000000;
#if NAZARA_CORE_SAFE #if NAZARA_CORE_SAFE
if (sem_timedwait(m_semaphore, timeout) == -1) if (sem_timedwait(m_semaphore, timeout) == -1)
@ -61,8 +61,8 @@ bool NzSemaphoreImpl::Wait(nzUInt32 timeout)
return false; return false;
} }
return true; return true;
#else #else
return sem_timedwait(&m_semaphore, ti) != -1; return sem_timedwait(&m_semaphore, ti) == 0 && errno != ETIMEDOUT;
#endif #endif
} }

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp

View File

@ -1,4 +1,4 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
@ -6,6 +6,8 @@
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Functor.hpp> #include <Nazara/Core/Functor.hpp>
#include <process.h> #include <process.h>
#include <unistd.h>
#include <sys/time.h>
#include <Nazara/Core/Debug.hpp> #include <Nazara/Core/Debug.hpp>
NzThreadImpl::NzThreadImpl(NzFunctor* functor) NzThreadImpl::NzThreadImpl(NzFunctor* functor)
@ -17,26 +19,20 @@ NzThreadImpl::NzThreadImpl(NzFunctor* functor)
void NzThreadImpl::Detach() void NzThreadImpl::Detach()
{ {
// http://stackoverflow.com/questions/418742/is-it-reasonable-to-call-closehandle-on-a-thread-before-it-terminates pthread_detach(m_handle);
pthread_detach(&m_handle);
} }
void NzThreadImpl::Join() void NzThreadImpl::Join()
{ {
pthread_join(&m_handle, nullptr); pthread_join(m_handle, nullptr);
} }
unsigned int __stdcall NzThreadImpl::ThreadProc(void* userdata) unsigned int NzThreadImpl::ThreadProc(void* userdata)
{ {
NzFunctor* func = static_cast<NzFunctor*>(userdata); NzFunctor* func = static_cast<NzFunctor*>(userdata);
func->Run(); func->Run();
delete func; delete func;
/*
En C++, il vaut mieux retourner depuis la fonction que de quitter le thread explicitement
Source : http://msdn.microsoft.com/en-us/library/windows/desktop/ms682659(v=vs.85).aspx
*/
return 0; return 0;
} }
@ -50,16 +46,14 @@ void NzThreadImpl::Sleep(nzUInt32 time)
// this implementation is inspired from Qt // this implementation is inspired from Qt
nzUint64 usecs = time.asMicroseconds();
// get the current time // get the current time
timeval tv; timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
// construct the time limit (current time + time to wait) // construct the time limit (current time + time to wait)
timespec ti; timespec ti;
ti.tv_nsec = (tv.tv_usec + (usecs % 1000000)) * 1000; ti.tv_nsec = (tv.tv_usec + (time % 1000)) * 1000;
ti.tv_sec = tv.tv_sec + (usecs / 1000000) + (ti.tv_nsec / 1000000000); ti.tv_sec = tv.tv_sec + (time / 1000) + (ti.tv_nsec / 1000000000);
ti.tv_nsec %= 1000000000; ti.tv_nsec %= 1000000000;
// create a mutex and thread condition // create a mutex and thread condition

View File

@ -1,9 +1,7 @@
// Copyright (C) 2012 Jérôme Leclercq // Copyright (C) 2012 Alexandre Janniaux
// This file is part of the "Nazara Engine - Core module" // This file is part of the "Nazara Engine - Core module"
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
// Inspiré du code de la SFML par Laurent Gomila
#pragma once #pragma once
#ifndef NAZARA_THREADIMPL_HPP #ifndef NAZARA_THREADIMPL_HPP
@ -11,8 +9,6 @@
#include <Nazara/Prerequesites.hpp> #include <Nazara/Prerequesites.hpp>
#include <pthread.h> #include <pthread.h>
#include <unistd.h>
#include <sys/time.h>
struct NzFunctor; struct NzFunctor;

View File

@ -301,6 +301,74 @@ void NzDebugDrawer::DrawNormals(const NzSubMesh* subMesh)
} }
} }
void NzDebugDrawer::DrawTangents(const NzSubMesh* subMesh)
{
if (!initialized)
{
NazaraError("Debug drawer is not initialized");
return;
}
unsigned int tangentCount = subMesh->GetVertexCount();
unsigned int vertexCount = tangentCount*2;
if (vertexBuffer->GetVertexCount() < vertexCount)
{
NazaraError("Debug buffer not length enougth to draw object");
return;
}
NzBufferMapper<NzVertexBuffer> inputMapper(subMesh->GetVertexBuffer(), nzBufferAccess_ReadOnly);
NzBufferMapper<NzVertexBuffer> outputMapper(vertexBuffer, nzBufferAccess_DiscardAndWrite, 0, vertexCount);
NzMeshVertex* inputVertex = reinterpret_cast<NzMeshVertex*>(inputMapper.GetPointer());
NzVertexStruct_XYZ* outputVertex = reinterpret_cast<NzVertexStruct_XYZ*>(outputMapper.GetPointer());
for (unsigned int i = 0; i < tangentCount; ++i)
{
outputVertex->position = inputVertex->position;
outputVertex++;
outputVertex->position = inputVertex->position + inputVertex->tangent;
outputVertex++;
inputVertex++;
}
inputMapper.Unmap();
outputMapper.Unmap();
if (vertexCount > 0)
{
const NzShader* oldShader = NzRenderer::GetShader();
if (!NzRenderer::SetShader(shader))
{
NazaraError("Failed to set debug shader");
return;
}
bool depthTestActive = NzRenderer::IsEnabled(nzRendererParameter_DepthTest);
if (depthTestActive != depthTest)
NzRenderer::Enable(nzRendererParameter_DepthTest, depthTest);
NzRenderer::SetVertexBuffer(vertexBuffer);
float oldLineWidth = NzRenderer::GetLineWidth();
NzRenderer::SetLineWidth(lineWidth);
shader->SendColor(colorLocation, primaryColor);
NzRenderer::DrawPrimitives(nzPrimitiveType_LineList, 0, vertexCount);
NzRenderer::SetLineWidth(oldLineWidth);
if (depthTestActive != depthTest)
NzRenderer::Enable(nzRendererParameter_DepthTest, depthTestActive);
if (!NzRenderer::SetShader(oldShader))
NazaraWarning("Failed to reset shader");
}
}
bool NzDebugDrawer::Initialize() bool NzDebugDrawer::Initialize()
{ {
if (!initialized) if (!initialized)