Merge branch 'NDK' into NDK-ShadowMapping
Conflicts: include/Nazara/Math/Matrix4.inl Former-commit-id: e4b7d178a7acba17c03de2b585af86324b8d75a6
This commit is contained in:
@@ -46,7 +46,6 @@
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/ErrorFlags.hpp>
|
||||
#include <Nazara/Core/File.hpp>
|
||||
#include <Nazara/Core/Format.hpp>
|
||||
#include <Nazara/Core/Functor.hpp>
|
||||
#include <Nazara/Core/GuillotineBinPack.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
|
||||
template<typename F, typename Tuple> auto NzApply(F&& fn, Tuple&& t);
|
||||
template<typename O, typename F, typename Tuple> auto NzApply(O& object, F&& fn, Tuple&& t);
|
||||
template<typename T> void NzHashCombine(std::size_t& seed, const T& v);
|
||||
template<typename F, typename... ArgsT> void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t);
|
||||
|
||||
template<typename T>
|
||||
struct NzTypeTag {};
|
||||
|
||||
#include <Nazara/Core/Algorithm.inl>
|
||||
|
||||
|
||||
@@ -8,28 +8,34 @@
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
///TODO: Améliorer l'implémentation de UnpackTuple
|
||||
|
||||
template<unsigned int N>
|
||||
struct NzImplTupleUnpack
|
||||
// http://www.cppsamples.com/common-tasks/apply-tuple-to-function.html
|
||||
template<typename F, typename Tuple, size_t... S>
|
||||
auto NzApplyImplFunc(F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||
{
|
||||
template <typename F, typename... ArgsT, typename... Args>
|
||||
void operator()(F func, const std::tuple<ArgsT...>& t, Args&... args)
|
||||
{
|
||||
NzImplTupleUnpack<N-1>()(func, t, std::get<N-1>(t), args...);
|
||||
}
|
||||
};
|
||||
return std::forward<F>(fn)(std::get<S>(std::forward<Tuple>(t))...);
|
||||
}
|
||||
|
||||
template<>
|
||||
struct NzImplTupleUnpack<0>
|
||||
template<typename F, typename Tuple>
|
||||
auto NzApply(F&& fn, Tuple&& t)
|
||||
{
|
||||
template <typename F, typename... ArgsT, typename... Args>
|
||||
void operator()(F func, const std::tuple<ArgsT...>&, Args&... args)
|
||||
{
|
||||
func(args...);
|
||||
}
|
||||
};
|
||||
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
|
||||
|
||||
return NzApplyImplFunc(std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||
}
|
||||
|
||||
template<typename O, typename F, typename Tuple, size_t... S>
|
||||
auto NzApplyImplMethod(O& object, F&& fn, Tuple&& t, std::index_sequence<S...>)
|
||||
{
|
||||
return (object .* std::forward<F>(fn))(std::get<S>(std::forward<Tuple>(t))...);
|
||||
}
|
||||
|
||||
template<typename O, typename F, typename Tuple>
|
||||
auto NzApply(O& object, F&& fn, Tuple&& t)
|
||||
{
|
||||
constexpr std::size_t tSize = std::tuple_size<typename std::remove_reference<Tuple>::type>::value;
|
||||
|
||||
return NzApplyImplMethod(object, std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
|
||||
}
|
||||
// Algorithme venant de CityHash par Google
|
||||
// http://stackoverflow.com/questions/8513911/how-to-create-a-good-hash-combine-with-64-bit-output-inspired-by-boosthash-co
|
||||
template<typename T>
|
||||
@@ -47,10 +53,4 @@ void NzHashCombine(std::size_t& seed, const T& v)
|
||||
seed = static_cast<std::size_t>(b * kMul);
|
||||
}
|
||||
|
||||
template<typename F, typename... ArgsT>
|
||||
void NzUnpackTuple(F func, const std::tuple<ArgsT...>& t)
|
||||
{
|
||||
NzImplTupleUnpack<sizeof...(ArgsT)>()(func, t);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -8,120 +8,132 @@
|
||||
#define NAZARA_BYTEARRAY_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <atomic>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <vector>
|
||||
|
||||
class NzAbstractHash;
|
||||
class NzHashDigest;
|
||||
|
||||
class NAZARA_CORE_API NzByteArray : public NzHashable
|
||||
{
|
||||
using Container = std::vector<nzUInt8>;
|
||||
|
||||
public:
|
||||
struct SharedArray;
|
||||
// types:
|
||||
using allocator_type = Container::allocator_type;
|
||||
using const_iterator = Container::const_iterator;
|
||||
using const_reference = Container::const_reference;
|
||||
using const_pointer = Container::const_pointer;
|
||||
using const_reverse_iterator = Container::const_reverse_iterator;
|
||||
using difference_type = Container::difference_type;
|
||||
using pointer = Container::pointer;
|
||||
using iterator = Container::iterator;
|
||||
using reference = Container::reference;
|
||||
using reverse_iterator = Container::reverse_iterator;
|
||||
using size_type = Container::size_type;
|
||||
using value_type = Container::value_type;
|
||||
|
||||
NzByteArray();
|
||||
explicit NzByteArray(unsigned int size);
|
||||
NzByteArray(const void* buffer, unsigned int size);
|
||||
NzByteArray(const NzByteArray& buffer);
|
||||
NzByteArray(NzByteArray&& buffer) noexcept;
|
||||
NzByteArray(SharedArray* sharedArray);
|
||||
~NzByteArray();
|
||||
// construct/destroy:
|
||||
inline NzByteArray() = default;
|
||||
inline explicit NzByteArray(size_type n);
|
||||
inline NzByteArray(const void* buffer, size_type n);
|
||||
inline NzByteArray(size_type n, value_type value);
|
||||
template <class InputIterator> NzByteArray(InputIterator first, InputIterator last);
|
||||
NzByteArray(const NzByteArray& other) = default;
|
||||
NzByteArray(NzByteArray&& other) = default;
|
||||
~NzByteArray() = default;
|
||||
|
||||
NzByteArray& Append(const void* buffer, unsigned int size);
|
||||
NzByteArray& Append(const NzByteArray& array);
|
||||
inline iterator Append(const void* buffer, size_type size);
|
||||
inline iterator Append(const NzByteArray& other);
|
||||
template <class InputIterator> void Assign(InputIterator first, InputIterator last);
|
||||
inline void Assign(size_type n, value_type value);
|
||||
|
||||
void Clear(bool keepBuffer = false);
|
||||
inline reference Back();
|
||||
inline const_reference Back() const;
|
||||
|
||||
nzUInt8* GetBuffer();
|
||||
unsigned int GetCapacity() const;
|
||||
const nzUInt8* GetConstBuffer() const;
|
||||
unsigned int GetSize() const;
|
||||
inline void Clear(bool keepBuffer = false);
|
||||
|
||||
NzByteArray& Insert(int pos, const void* buffer, unsigned int size);
|
||||
NzByteArray& Insert(int pos, const NzByteArray& array);
|
||||
inline iterator Erase(const_iterator pos);
|
||||
inline iterator Erase(const_iterator first, const_iterator last);
|
||||
|
||||
bool IsEmpty() const;
|
||||
inline reference Front();
|
||||
inline const_reference Front() const;
|
||||
|
||||
NzByteArray& Prepend(const void* buffer, unsigned int size);
|
||||
NzByteArray& Prepend(const NzByteArray& array);
|
||||
inline allocator_type GetAllocator() const;
|
||||
inline pointer GetBuffer();
|
||||
inline size_type GetCapacity() const noexcept;
|
||||
inline const_pointer GetConstBuffer() const;
|
||||
inline size_type GetMaxSize() const noexcept;
|
||||
inline size_type GetSize() const noexcept;
|
||||
inline NzByteArray GetSubArray(const_iterator startPos, const_iterator endPos) const;
|
||||
|
||||
void Reserve(unsigned int bufferSize);
|
||||
inline iterator Insert(const_iterator pos, const void* buffer, size_type n);
|
||||
inline iterator Insert(const_iterator pos, const NzByteArray& other);
|
||||
inline iterator Insert(const_iterator pos, size_type n, value_type byte);
|
||||
template <class InputIterator> iterator Insert(const_iterator pos, InputIterator first, InputIterator last);
|
||||
inline bool IsEmpty() const noexcept;
|
||||
|
||||
NzByteArray& Resize(int size);
|
||||
NzByteArray& Resize(int size, nzUInt8 byte);
|
||||
NzByteArray Resized(int size) const;
|
||||
NzByteArray Resized(int size, nzUInt8 byte) const;
|
||||
inline void PopBack();
|
||||
inline void PopFront();
|
||||
inline iterator Prepend(const void* buffer, size_type size);
|
||||
inline iterator Prepend(const NzByteArray& other);
|
||||
inline void PushBack(value_type byte);
|
||||
inline void PushFront(value_type byte);
|
||||
|
||||
NzByteArray SubArray(int startPos, int endPos = -1) const;
|
||||
inline void Reserve(size_type bufferSize);
|
||||
inline void Resize(size_type newSize);
|
||||
inline void Resize(size_type newSize, value_type byte);
|
||||
|
||||
void Swap(NzByteArray& array);
|
||||
inline void ShrinkToFit();
|
||||
inline void Swap(NzByteArray& other);
|
||||
|
||||
// Méthodes compatibles STD
|
||||
nzUInt8* begin();
|
||||
const nzUInt8* begin() const;
|
||||
nzUInt8* end();
|
||||
const nzUInt8* end() const;
|
||||
void push_front(nzUInt8 byte);
|
||||
void push_back(nzUInt8 byte);
|
||||
/*nzUInt8* rbegin();
|
||||
const nzUInt8* rbegin() const;
|
||||
nzUInt8* rend();
|
||||
const nzUInt8* rend() const;*/
|
||||
inline NzString ToString() const;
|
||||
|
||||
typedef const nzUInt8& const_reference;
|
||||
typedef nzUInt8* iterator;
|
||||
//typedef nzUInt8* reverse_iterator;
|
||||
typedef nzUInt8 value_type;
|
||||
// Méthodes compatibles STD
|
||||
// STL interface
|
||||
inline iterator begin() noexcept;
|
||||
inline const_iterator begin() const noexcept;
|
||||
inline bool empty() const noexcept;
|
||||
inline iterator end() noexcept;
|
||||
inline const_iterator end() const noexcept;
|
||||
inline reverse_iterator rbegin() noexcept;
|
||||
inline const_reverse_iterator rbegin() const noexcept;
|
||||
inline reverse_iterator rend() noexcept;
|
||||
inline const_reverse_iterator rend() const noexcept;
|
||||
inline const_iterator cbegin() const noexcept;
|
||||
inline const_iterator cend() const noexcept;
|
||||
inline const_reverse_iterator crbegin() const noexcept;
|
||||
inline const_reverse_iterator crend() const noexcept;
|
||||
inline size_type size() const noexcept;
|
||||
|
||||
nzUInt8& operator[](unsigned int pos);
|
||||
nzUInt8 operator[](unsigned int pos) const;
|
||||
// Operators
|
||||
inline reference operator[](size_type pos);
|
||||
inline const_reference operator[](size_type pos) const;
|
||||
inline NzByteArray& operator=(const NzByteArray& array) = default;
|
||||
inline NzByteArray& operator=(NzByteArray&& array) = default;
|
||||
inline NzByteArray operator+(const NzByteArray& array) const;
|
||||
inline NzByteArray& operator+=(const NzByteArray& array);
|
||||
|
||||
NzByteArray& operator=(const NzByteArray& array);
|
||||
NzByteArray& operator=(NzByteArray&& array) noexcept;
|
||||
|
||||
NzByteArray operator+(const NzByteArray& array) const;
|
||||
NzByteArray& operator+=(const NzByteArray& array);
|
||||
|
||||
static int Compare(const NzByteArray& first, const NzByteArray& second);
|
||||
|
||||
struct NAZARA_CORE_API SharedArray
|
||||
{
|
||||
SharedArray() :
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
|
||||
capacity(bufferSize),
|
||||
size(arraySize),
|
||||
buffer(ptr),
|
||||
refCount(referenceCount)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int capacity;
|
||||
unsigned int size;
|
||||
nzUInt8* buffer;
|
||||
|
||||
std::atomic_ushort refCount;
|
||||
};
|
||||
|
||||
static SharedArray emptyArray;
|
||||
static unsigned int npos;
|
||||
inline bool operator==(const NzByteArray& rhs) const;
|
||||
inline bool operator!=(const NzByteArray& rhs) const;
|
||||
inline bool operator<(const NzByteArray& rhs) const;
|
||||
inline bool operator<=(const NzByteArray& rhs) const;
|
||||
inline bool operator>(const NzByteArray& rhs) const;
|
||||
inline bool operator>=(const NzByteArray& rhs) const;
|
||||
|
||||
private:
|
||||
void EnsureOwnership();
|
||||
bool FillHash(NzAbstractHash* hash) const;
|
||||
void ReleaseArray();
|
||||
|
||||
SharedArray* m_sharedArray;
|
||||
Container m_array;
|
||||
};
|
||||
|
||||
NAZARA_CORE_API std::ostream& operator<<(std::ostream& out, const NzByteArray& byteArray);
|
||||
|
||||
namespace std
|
||||
{
|
||||
NAZARA_CORE_API void swap(NzByteArray& lhs, NzByteArray& rhs);
|
||||
void swap(NzByteArray& lhs, NzByteArray& rhs);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/ByteArray.inl>
|
||||
|
||||
#endif // NAZARA_BYTEARRAY_HPP
|
||||
|
||||
319
include/Nazara/Core/ByteArray.inl
Normal file
319
include/Nazara/Core/ByteArray.inl
Normal file
@@ -0,0 +1,319 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
inline NzByteArray::NzByteArray(size_type n) :
|
||||
m_array()
|
||||
{
|
||||
m_array.reserve(n);
|
||||
}
|
||||
|
||||
inline NzByteArray::NzByteArray(const void* buffer, size_type n) :
|
||||
m_array(static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzByteArray::NzByteArray(size_type n, const value_type value) :
|
||||
m_array(n, value)
|
||||
{
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
NzByteArray::NzByteArray(InputIterator first, InputIterator last) :
|
||||
m_array(first, last)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Append(const void* buffer, size_type n)
|
||||
{
|
||||
return Insert(end(), static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Append(const NzByteArray& other)
|
||||
{
|
||||
return Insert(end(), other.begin(), other.end());
|
||||
}
|
||||
|
||||
inline void NzByteArray::Assign(size_type n, value_type value)
|
||||
{
|
||||
m_array.assign(n, value);
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
void NzByteArray::Assign(InputIterator first, InputIterator last)
|
||||
{
|
||||
m_array.assign(first, last);
|
||||
}
|
||||
|
||||
inline NzByteArray::reference NzByteArray::Back()
|
||||
{
|
||||
return m_array.back();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_reference NzByteArray::Back() const
|
||||
{
|
||||
return m_array.back();
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Erase(const_iterator pos)
|
||||
{
|
||||
return m_array.erase(pos);
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Erase(const_iterator first, const_iterator last)
|
||||
{
|
||||
return m_array.erase(first, last);
|
||||
}
|
||||
|
||||
inline NzByteArray::allocator_type NzByteArray::GetAllocator() const
|
||||
{
|
||||
return m_array.get_allocator();
|
||||
}
|
||||
|
||||
inline NzByteArray::pointer NzByteArray::GetBuffer()
|
||||
{
|
||||
return m_array.data();
|
||||
}
|
||||
|
||||
inline NzByteArray::size_type NzByteArray::GetCapacity() const noexcept
|
||||
{
|
||||
return m_array.capacity();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_pointer NzByteArray::GetConstBuffer() const
|
||||
{
|
||||
return m_array.data();
|
||||
}
|
||||
|
||||
inline NzByteArray::size_type NzByteArray::GetMaxSize() const noexcept
|
||||
{
|
||||
return m_array.max_size();
|
||||
}
|
||||
|
||||
inline NzByteArray::size_type NzByteArray::GetSize() const noexcept
|
||||
{
|
||||
return m_array.size();
|
||||
}
|
||||
|
||||
inline NzByteArray NzByteArray::GetSubArray(const_iterator startPos, const_iterator endPos) const
|
||||
{
|
||||
return NzByteArray(startPos, endPos);
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Insert(const_iterator pos, const void* buffer, size_type n)
|
||||
{
|
||||
return m_array.insert(pos, static_cast<const_pointer>(buffer), static_cast<const_pointer>(buffer) + n);
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Insert(const_iterator pos, const NzByteArray& other)
|
||||
{
|
||||
return m_array.insert(pos, other.begin(), other.end());
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Insert(const_iterator pos, size_type n, value_type byte)
|
||||
{
|
||||
return m_array.insert(pos, n, byte);
|
||||
}
|
||||
|
||||
template <class InputIterator>
|
||||
NzByteArray::iterator NzByteArray::Insert(const_iterator pos, InputIterator first, InputIterator last)
|
||||
{
|
||||
return m_array.insert(pos, first, last);
|
||||
}
|
||||
|
||||
inline bool NzByteArray::IsEmpty() const noexcept
|
||||
{
|
||||
return m_array.empty();
|
||||
}
|
||||
|
||||
inline void NzByteArray::PopBack()
|
||||
{
|
||||
Erase(end() - 1);
|
||||
}
|
||||
|
||||
inline void NzByteArray::PopFront()
|
||||
{
|
||||
Erase(begin());
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Prepend(const void* buffer, size_type n)
|
||||
{
|
||||
return Insert(begin(), buffer, n);
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::Prepend(const NzByteArray& other)
|
||||
{
|
||||
return Insert(begin(), other);
|
||||
}
|
||||
|
||||
inline void NzByteArray::PushBack(const value_type byte)
|
||||
{
|
||||
m_array.push_back(byte);
|
||||
}
|
||||
|
||||
inline void NzByteArray::PushFront(const value_type byte)
|
||||
{
|
||||
m_array.insert(begin(), 1, byte);
|
||||
}
|
||||
|
||||
inline void NzByteArray::Reserve(size_type bufferSize)
|
||||
{
|
||||
m_array.reserve(bufferSize);
|
||||
}
|
||||
|
||||
inline void NzByteArray::Resize(size_type newSize)
|
||||
{
|
||||
m_array.resize(newSize);
|
||||
}
|
||||
|
||||
inline void NzByteArray::Resize(size_type newSize, const value_type byte)
|
||||
{
|
||||
m_array.resize(newSize, byte);
|
||||
}
|
||||
|
||||
inline void NzByteArray::ShrinkToFit()
|
||||
{
|
||||
m_array.shrink_to_fit();
|
||||
}
|
||||
|
||||
inline void NzByteArray::Swap(NzByteArray& other)
|
||||
{
|
||||
m_array.swap(other.m_array);
|
||||
}
|
||||
|
||||
inline NzString NzByteArray::ToString() const
|
||||
{
|
||||
return NzString(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::begin() noexcept
|
||||
{
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_iterator NzByteArray::begin() const noexcept
|
||||
{
|
||||
return m_array.begin();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_iterator NzByteArray::cbegin() const noexcept
|
||||
{
|
||||
return m_array.cbegin();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_iterator NzByteArray::cend() const noexcept
|
||||
{
|
||||
return m_array.cend();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_reverse_iterator NzByteArray::crbegin() const noexcept
|
||||
{
|
||||
return m_array.crbegin();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_reverse_iterator NzByteArray::crend() const noexcept
|
||||
{
|
||||
return m_array.crend();
|
||||
}
|
||||
|
||||
inline bool NzByteArray::empty() const noexcept
|
||||
{
|
||||
return m_array.empty();
|
||||
}
|
||||
|
||||
inline NzByteArray::iterator NzByteArray::end() noexcept
|
||||
{
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_iterator NzByteArray::end() const noexcept
|
||||
{
|
||||
return m_array.end();
|
||||
}
|
||||
|
||||
inline NzByteArray::reverse_iterator NzByteArray::rbegin() noexcept
|
||||
{
|
||||
return m_array.rbegin();
|
||||
}
|
||||
|
||||
inline NzByteArray::const_reverse_iterator NzByteArray::rbegin() const noexcept
|
||||
{
|
||||
return m_array.rbegin();
|
||||
}
|
||||
|
||||
inline NzByteArray::reverse_iterator NzByteArray::rend() noexcept
|
||||
{
|
||||
return m_array.rend();
|
||||
}
|
||||
|
||||
inline NzByteArray::size_type NzByteArray::size() const noexcept
|
||||
{
|
||||
return GetSize();
|
||||
}
|
||||
|
||||
inline NzByteArray::reference NzByteArray::operator[](size_type pos)
|
||||
{
|
||||
NazaraAssert(pos < GetSize(), "Index out of range");
|
||||
|
||||
return m_array[pos];
|
||||
}
|
||||
|
||||
inline NzByteArray::const_reference NzByteArray::operator[](size_type pos) const
|
||||
{
|
||||
NazaraAssert(pos < GetSize(), "Index out of range");
|
||||
|
||||
return m_array[pos];
|
||||
}
|
||||
|
||||
inline NzByteArray NzByteArray::operator+(const NzByteArray& other) const
|
||||
{
|
||||
NzByteArray tmp(*this);
|
||||
tmp += other;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
inline NzByteArray& NzByteArray::operator+=(const NzByteArray& other)
|
||||
{
|
||||
Append(other);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool NzByteArray::operator==(const NzByteArray& rhs) const
|
||||
{
|
||||
return m_array == rhs.m_array;
|
||||
}
|
||||
|
||||
inline bool NzByteArray::operator!=(const NzByteArray& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
inline bool NzByteArray::operator<(const NzByteArray& rhs) const
|
||||
{
|
||||
return m_array < rhs.m_array;
|
||||
}
|
||||
|
||||
inline bool NzByteArray::operator<=(const NzByteArray& rhs) const
|
||||
{
|
||||
return m_array <= rhs.m_array;
|
||||
}
|
||||
|
||||
inline bool NzByteArray::operator>(const NzByteArray& rhs) const
|
||||
{
|
||||
return m_array > rhs.m_array;
|
||||
}
|
||||
|
||||
inline bool NzByteArray::operator>=(const NzByteArray& rhs) const
|
||||
{
|
||||
return m_array >= rhs.m_array;
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
inline void swap(NzByteArray& lhs, NzByteArray& rhs)
|
||||
{
|
||||
lhs.Swap(rhs);
|
||||
}
|
||||
}
|
||||
@@ -317,8 +317,8 @@ inline void NzColor::ToHSV(const NzColor& color, float* hue, float* saturation,
|
||||
float g = color.g / 255.f;
|
||||
float b = color.b / 255.f;
|
||||
|
||||
float min = std::min(std::min(r, g), b); //Min. value of RGB
|
||||
float max = std::max(std::max(r, g), b); //Max. value of RGB
|
||||
float min = std::min({r, g, b}); //Min. value of RGB
|
||||
float max = std::max({r, g, b}); //Max. value of RGB
|
||||
|
||||
float deltaMax = max - min; //Delta RGB value
|
||||
|
||||
|
||||
@@ -8,11 +8,12 @@
|
||||
#define NAZARA_CONDITIONVARIABLE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/NonCopyable.hpp>
|
||||
|
||||
class NzConditionVariableImpl;
|
||||
class NzMutex;
|
||||
|
||||
class NAZARA_CORE_API NzConditionVariable
|
||||
class NAZARA_CORE_API NzConditionVariable : NzNonCopyable
|
||||
{
|
||||
public:
|
||||
NzConditionVariable();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// On force la valeur de MANAGE_MEMORY en mode debug
|
||||
#if defined(NAZARA_DEBUG) && !NAZARA_CORE_MANAGE_MEMORY
|
||||
#undef NAZARA_CORE_MANAGE_MEMORY
|
||||
#define NAZARA_CORE_MANAGE_MEMORY 1
|
||||
#define NAZARA_CORE_MANAGE_MEMORY 0
|
||||
#endif
|
||||
|
||||
NazaraCheckTypeAndVal(NAZARA_CORE_DECIMAL_DIGITS, integral, >, 0, " shall be a strictly positive integer");
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
using NzDynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
|
||||
using NzDynLibFunc = int (*)(); // Type "générique" de pointeur sur fonction
|
||||
|
||||
class NzDynLibImpl;
|
||||
|
||||
|
||||
@@ -15,6 +15,15 @@ enum nzCoordSys
|
||||
nzCoordSys_Max = nzCoordSys_Local
|
||||
};
|
||||
|
||||
enum nzCursorPosition
|
||||
{
|
||||
nzCursorPosition_AtBegin, // Début du fichier
|
||||
nzCursorPosition_AtCurrent, // Position du pointeur
|
||||
nzCursorPosition_AtEnd, // Fin du fichier
|
||||
|
||||
nzCursorPosition_Max = nzCursorPosition_AtEnd
|
||||
};
|
||||
|
||||
enum nzEndianness
|
||||
{
|
||||
nzEndianness_Unknown = -1,
|
||||
@@ -57,7 +66,24 @@ enum nzHash
|
||||
nzHash_SHA256,
|
||||
nzHash_SHA384,
|
||||
nzHash_SHA512,
|
||||
nzHash_Whirlpool
|
||||
nzHash_Whirlpool,
|
||||
|
||||
nzHash_Max = nzHash_Whirlpool
|
||||
};
|
||||
|
||||
enum nzOpenModeFlags
|
||||
{
|
||||
nzOpenMode_Current = 0x00, // Utilise le mode d'ouverture actuel
|
||||
|
||||
nzOpenMode_Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
|
||||
nzOpenMode_Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
|
||||
nzOpenMode_ReadOnly = 0x04, // Ouvre uniquement en lecture
|
||||
nzOpenMode_ReadWrite = 0x08, // Ouvre en lecture/écriture
|
||||
nzOpenMode_Text = 0x10, // Ouvre en mode texte
|
||||
nzOpenMode_Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
|
||||
nzOpenMode_WriteOnly = 0x40, // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
|
||||
|
||||
nzOpenMode_Max = nzOpenMode_WriteOnly
|
||||
};
|
||||
|
||||
enum nzParameterType
|
||||
|
||||
@@ -23,34 +23,16 @@
|
||||
#include <Nazara/Core/ThreadSafetyOff.hpp>
|
||||
#endif
|
||||
|
||||
#include <ctime>
|
||||
|
||||
class NzFileImpl;
|
||||
|
||||
class NAZARA_CORE_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
|
||||
{
|
||||
public:
|
||||
enum CursorPosition
|
||||
{
|
||||
AtBegin, // Début du fichier
|
||||
AtCurrent, // Position du pointeur
|
||||
AtEnd // Fin du fichier
|
||||
};
|
||||
|
||||
enum OpenMode
|
||||
{
|
||||
Current = 0x00, // Utilise le mode d'ouverture actuel
|
||||
|
||||
Append = 0x01, // Empêche l'écriture sur la partie déjà existante et met le curseur à la fin
|
||||
Lock = 0x02, // Empêche le fichier d'être modifié tant qu'il est ouvert
|
||||
ReadOnly = 0x04, // Ouvre uniquement en lecture
|
||||
ReadWrite = 0x08, // Ouvre en lecture/écriture
|
||||
Text = 0x10, // Ouvre en mode texte
|
||||
Truncate = 0x20, // Créé le fichier s'il n'existe pas et le vide s'il existe
|
||||
WriteOnly = 0x40 // Ouvre uniquement en écriture, créé le fichier s'il n'existe pas
|
||||
};
|
||||
|
||||
NzFile();
|
||||
NzFile(const NzString& filePath);
|
||||
NzFile(const NzString& filePath, unsigned long openMode);
|
||||
NzFile(const NzString& filePath, unsigned int openMode);
|
||||
NzFile(NzFile&& file) noexcept;
|
||||
~NzFile();
|
||||
|
||||
@@ -77,14 +59,14 @@ class NAZARA_CORE_API NzFile : public NzHashable, public NzInputStream, NzNonCop
|
||||
|
||||
bool IsOpen() const;
|
||||
|
||||
bool Open(unsigned long openMode = Current);
|
||||
bool Open(const NzString& filePath, unsigned long openMode = Current);
|
||||
bool Open(unsigned int openMode = nzOpenMode_Current);
|
||||
bool Open(const NzString& filePath, unsigned int openMode = nzOpenMode_Current);
|
||||
|
||||
std::size_t Read(void* buffer, std::size_t size);
|
||||
std::size_t Read(void* buffer, std::size_t typeSize, unsigned int count);
|
||||
bool Rename(const NzString& newFilePath);
|
||||
|
||||
bool SetCursorPos(CursorPosition pos, nzInt64 offset = 0);
|
||||
bool SetCursorPos(nzCursorPosition pos, nzInt64 offset = 0);
|
||||
bool SetCursorPos(nzUInt64 offset);
|
||||
void SetEndianness(nzEndianness endianness);
|
||||
bool SetFile(const NzString& filePath);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_FORMAT_HPP
|
||||
#define NAZARA_FORMAT_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
|
||||
template<typename... Args> NzString NzFormat(const NzString& str, Args... args);
|
||||
|
||||
#endif // NAZARA_FORMAT_HPP
|
||||
@@ -26,7 +26,7 @@ m_args(std::forward<Args>(args)...)
|
||||
template<typename F, typename... Args>
|
||||
void NzFunctorWithArgs<F, Args...>::Run()
|
||||
{
|
||||
NzUnpackTuple(m_func, m_args);
|
||||
NzApply(m_func, m_args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ class NAZARA_CORE_API NzHardwareInfo
|
||||
static unsigned int GetProcessorCount();
|
||||
static nzProcessorVendor GetProcessorVendor();
|
||||
static NzString GetProcessorVendorName();
|
||||
static nzUInt64 GetTotalMemory();
|
||||
|
||||
static bool HasCapability(nzProcessorCap capability);
|
||||
|
||||
|
||||
@@ -21,7 +21,9 @@ class NAZARA_CORE_API NzMutex : NzNonCopyable
|
||||
~NzMutex();
|
||||
|
||||
void Lock();
|
||||
|
||||
bool TryLock();
|
||||
|
||||
void Unlock();
|
||||
|
||||
private:
|
||||
|
||||
@@ -57,7 +57,7 @@ bool NzResourceLoader<Type, Parameters>::LoadFromFile(Type* resource, const NzSt
|
||||
|
||||
if (checkFunc && !file.IsOpen())
|
||||
{
|
||||
if (!file.Open(NzFile::ReadOnly))
|
||||
if (!file.Open(nzOpenMode_ReadOnly))
|
||||
{
|
||||
NazaraError("Failed to load file: unable to open \"" + filePath + '"');
|
||||
return false;
|
||||
|
||||
@@ -19,7 +19,9 @@ class NAZARA_CORE_API NzSemaphore : NzNonCopyable
|
||||
~NzSemaphore();
|
||||
|
||||
unsigned int GetCount() const;
|
||||
|
||||
void Post();
|
||||
|
||||
void Wait();
|
||||
bool Wait(nzUInt32 timeout);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Core/Hashable.hpp>
|
||||
#include <atomic>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -22,15 +23,13 @@ class NAZARA_CORE_API NzString : public NzHashable
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
None = 0x00, // Mode par défaut
|
||||
CaseInsensitive = 0x01, // Insensible à la casse
|
||||
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8
|
||||
None = 0x00, // Mode par défaut
|
||||
CaseInsensitive = 0x01, // Insensible à la casse
|
||||
HandleUtf8 = 0x02, // Traite les octets comme une suite de caractères UTF-8
|
||||
TrimOnlyLeft = 0x04, // Trim(med), ne coupe que la partie gauche de la chaîne
|
||||
TrimOnlyRight = 0x08 // Trim(med), ne coupe que la partie droite de la chaîne
|
||||
};
|
||||
|
||||
struct SharedString;
|
||||
|
||||
NzString();
|
||||
explicit NzString(char character);
|
||||
NzString(unsigned int rep, char character);
|
||||
@@ -40,10 +39,9 @@ class NAZARA_CORE_API NzString : public NzHashable
|
||||
NzString(const char* string);
|
||||
NzString(const char* string, unsigned int length);
|
||||
NzString(const std::string& string);
|
||||
NzString(const NzString& string);
|
||||
NzString(NzString&& string) noexcept;
|
||||
NzString(SharedString* sharedString);
|
||||
~NzString();
|
||||
NzString(const NzString& string) = default;
|
||||
NzString(NzString&& string) noexcept = default;
|
||||
~NzString() = default;
|
||||
|
||||
NzString& Append(char character);
|
||||
NzString& Append(const char* string);
|
||||
@@ -137,7 +135,6 @@ class NAZARA_CORE_API NzString : public NzHashable
|
||||
NzString& Set(const std::string& string);
|
||||
NzString& Set(const NzString& string);
|
||||
NzString& Set(NzString&& string) noexcept;
|
||||
NzString& Set(SharedString* sharedString);
|
||||
|
||||
NzString Simplified(nzUInt32 flags = None) const;
|
||||
NzString& Simplify(nzUInt32 flags = None);
|
||||
@@ -299,37 +296,30 @@ class NAZARA_CORE_API NzString : public NzHashable
|
||||
NAZARA_CORE_API friend bool operator>=(const char* string, const NzString& nstring);
|
||||
NAZARA_CORE_API friend bool operator>=(const std::string& string, const NzString& nstring);
|
||||
|
||||
struct NAZARA_CORE_API SharedString
|
||||
{
|
||||
SharedString() :
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) :
|
||||
capacity(bufferSize),
|
||||
size(stringSize),
|
||||
string(str),
|
||||
refCount(referenceCount)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int capacity;
|
||||
unsigned int size;
|
||||
char* string;
|
||||
|
||||
std::atomic_ushort refCount;
|
||||
};
|
||||
|
||||
static SharedString emptyString;
|
||||
static const unsigned int npos;
|
||||
|
||||
private:
|
||||
struct SharedString;
|
||||
|
||||
NzString(std::shared_ptr<SharedString>&& sharedString);
|
||||
|
||||
void EnsureOwnership(bool discardContent = false);
|
||||
bool FillHash(NzAbstractHash* hash) const;
|
||||
void ReleaseString();
|
||||
inline void ReleaseString();
|
||||
|
||||
SharedString* m_sharedString;
|
||||
static std::shared_ptr<SharedString> GetEmptyString();
|
||||
|
||||
std::shared_ptr<SharedString> m_sharedString;
|
||||
|
||||
struct SharedString
|
||||
{
|
||||
inline SharedString();
|
||||
inline SharedString(unsigned int strSize);
|
||||
|
||||
unsigned int capacity;
|
||||
unsigned int size;
|
||||
std::unique_ptr<char[]> string;
|
||||
};
|
||||
};
|
||||
|
||||
namespace std
|
||||
|
||||
@@ -4,11 +4,36 @@
|
||||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
inline NzString::NzString(std::shared_ptr<SharedString>&& sharedString) :
|
||||
m_sharedString(std::move(sharedString))
|
||||
{
|
||||
}
|
||||
|
||||
inline void NzString::ReleaseString()
|
||||
{
|
||||
m_sharedString = std::move(GetEmptyString());
|
||||
}
|
||||
|
||||
inline NzString::SharedString::SharedString() : // Special case: empty string
|
||||
capacity(0),
|
||||
size(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzString::SharedString::SharedString(unsigned int strSize) :
|
||||
capacity(strSize),
|
||||
size(strSize),
|
||||
string(new char[strSize + 1])
|
||||
{
|
||||
string[strSize] = '\0';
|
||||
}
|
||||
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<NzString>
|
||||
{
|
||||
template<>
|
||||
struct hash<NzString>
|
||||
{
|
||||
size_t operator()(const NzString& str) const
|
||||
{
|
||||
// Algorithme DJB2
|
||||
@@ -26,7 +51,7 @@ namespace std
|
||||
|
||||
return h;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
||||
@@ -108,8 +108,9 @@ class NAZARA_LUA_API NzLuaInstance : NzNonCopyable
|
||||
void Pop(unsigned int n = 1U);
|
||||
|
||||
void PushBoolean(bool value);
|
||||
void PushCFunction(NzLuaCFunction func, int upvalueCount = 0);
|
||||
void PushCFunction(NzLuaCFunction func, unsigned int upvalueCount = 0);
|
||||
void PushFunction(NzLuaFunction func);
|
||||
template<typename R, typename... Args> void PushFunction(R(*func)(Args...));
|
||||
void PushInteger(long long value);
|
||||
void PushLightUserdata(void* value);
|
||||
void PushMetatable(const char* str);
|
||||
@@ -118,6 +119,7 @@ class NAZARA_LUA_API NzLuaInstance : NzNonCopyable
|
||||
void PushNumber(double value);
|
||||
void PushReference(int ref);
|
||||
void PushString(const char* str);
|
||||
void PushString(const char* str, unsigned int size);
|
||||
void PushString(const NzString& str);
|
||||
void PushTable(unsigned int sequenceElementCount = 0, unsigned int arrayElementCount = 0);
|
||||
void* PushUserdata(unsigned int size);
|
||||
@@ -165,4 +167,6 @@ class NAZARA_LUA_API NzLuaInstance : NzNonCopyable
|
||||
unsigned int m_level;
|
||||
};
|
||||
|
||||
#include <Nazara/Lua/LuaInstance.inl>
|
||||
|
||||
#endif // NAZARA_LUASTATE_HPP
|
||||
|
||||
167
include/Nazara/Lua/LuaInstance.inl
Normal file
167
include/Nazara/Lua/LuaInstance.inl
Normal file
@@ -0,0 +1,167 @@
|
||||
// Copyright (C) 2015 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Lua scripting module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <string>
|
||||
|
||||
// Functions args
|
||||
bool NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<bool>)
|
||||
{
|
||||
return instance.CheckBoolean(index);
|
||||
}
|
||||
|
||||
double NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<double>)
|
||||
{
|
||||
return instance.CheckNumber(index);
|
||||
}
|
||||
|
||||
float NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<float>)
|
||||
{
|
||||
return static_cast<float>(instance.CheckNumber(index));
|
||||
}
|
||||
|
||||
int NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<int>)
|
||||
{
|
||||
return static_cast<int>(instance.CheckInteger(index));
|
||||
}
|
||||
|
||||
std::string NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<std::string>)
|
||||
{
|
||||
std::size_t strLength = 0;
|
||||
const char* str = instance.CheckString(index, &strLength);
|
||||
|
||||
return std::string(str, strLength);
|
||||
}
|
||||
|
||||
NzString NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<NzString>)
|
||||
{
|
||||
std::size_t strLength = 0;
|
||||
const char* str = instance.CheckString(index, &strLength);
|
||||
|
||||
return NzString(str, strLength);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<const T&>)
|
||||
{
|
||||
return NzLuaImplQueryArg(instance, index, NzTypeTag<T>());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_unsigned<T>::value, T> NzLuaImplQueryArg(NzLuaInstance& instance, unsigned int index, NzTypeTag<T>)
|
||||
{
|
||||
return static_cast<T>(NzLuaImplQueryArg(instance, index, NzTypeTag<typename std::make_signed<T>::type>()));
|
||||
}
|
||||
|
||||
// Function returns
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, bool&& val, NzTypeTag<bool>)
|
||||
{
|
||||
instance.PushBoolean(val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, double&& val, NzTypeTag<double>)
|
||||
{
|
||||
instance.PushNumber(val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, float&& val, NzTypeTag<float>)
|
||||
{
|
||||
instance.PushNumber(val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, int&& val, NzTypeTag<int>)
|
||||
{
|
||||
instance.PushInteger(val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, std::string&& val, NzTypeTag<std::string>)
|
||||
{
|
||||
instance.PushString(val.c_str(), val.size());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, NzString&& val, NzTypeTag<NzString>)
|
||||
{
|
||||
instance.PushString(std::move(val));
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename T1, typename T2>
|
||||
int NzLuaImplReplyVal(NzLuaInstance& instance, std::pair<T1, T2>&& val, NzTypeTag<std::pair<T1, T2>>)
|
||||
{
|
||||
int retVal = 0;
|
||||
|
||||
retVal += NzLuaImplReplyVal(instance, std::move(val.first), NzTypeTag<T1>());
|
||||
retVal += NzLuaImplReplyVal(instance, std::move(val.second), NzTypeTag<T2>());
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
std::enable_if_t<std::is_unsigned<T>::value, int> NzLuaImplReplyVal(NzLuaInstance& instance, T&& val, NzTypeTag<T>)
|
||||
{
|
||||
using SignedT = typename std::make_signed<T>::type;
|
||||
|
||||
return NzLuaImplReplyVal(instance, val, NzTypeTag<SignedT>());
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
class NzLuaImplFunctionProxy
|
||||
{
|
||||
public:
|
||||
NzLuaImplFunctionProxy(NzLuaInstance& instance) :
|
||||
m_instance(instance)
|
||||
{
|
||||
}
|
||||
|
||||
template<unsigned int N, typename ArgType>
|
||||
void ProcessArgs()
|
||||
{
|
||||
std::get<N>(m_args) = std::move(NzLuaImplQueryArg(m_instance, N+1, NzTypeTag<ArgType>()));
|
||||
}
|
||||
|
||||
template<int N, typename ArgType1, typename ArgType2, typename... Rest>
|
||||
void ProcessArgs()
|
||||
{
|
||||
ProcessArgs<N, ArgType1>();
|
||||
ProcessArgs<N+1, ArgType2, Rest...>();
|
||||
}
|
||||
|
||||
void ProcessArgs()
|
||||
{
|
||||
ProcessArgs<0, Args...>();
|
||||
}
|
||||
|
||||
int Invoke(void (*func)(Args...))
|
||||
{
|
||||
NzApply(func, m_args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Ret>
|
||||
int Invoke(Ret (*func)(Args...))
|
||||
{
|
||||
return NzLuaImplReplyVal(m_instance, std::move(NzApply(func, m_args)), NzTypeTag<decltype(NzApply(func, m_args))>());
|
||||
}
|
||||
|
||||
private:
|
||||
NzLuaInstance& m_instance;
|
||||
std::tuple<Args...> m_args;
|
||||
};
|
||||
|
||||
template<typename R, typename... Args>
|
||||
void NzLuaInstance::PushFunction(R(*func)(Args...))
|
||||
{
|
||||
PushFunction([func](NzLuaInstance& instance) -> int
|
||||
{
|
||||
NzLuaImplFunctionProxy<Args...> handler(instance);
|
||||
handler.ProcessArgs();
|
||||
|
||||
return handler.Invoke(func);
|
||||
});
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <type_traits>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
@@ -336,9 +337,10 @@ bool NzNumberEquals(T a, T b)
|
||||
template<typename T>
|
||||
bool NzNumberEquals(T a, T b, T maxDifference)
|
||||
{
|
||||
std::pair<const T&, const T&> minmax = std::minmax(a, b);
|
||||
T diff = minmax.second - minmax.first;
|
||||
if (b > a)
|
||||
std::swap(a, b);
|
||||
|
||||
T diff = a - b;
|
||||
return diff <= maxDifference;
|
||||
}
|
||||
|
||||
|
||||
@@ -212,7 +212,10 @@ template<typename T>
|
||||
bool NzBoundingVolume<T>::operator==(const NzBoundingVolume& volume) const
|
||||
{
|
||||
if (extend == volume.extend)
|
||||
return obb == volume.obb;
|
||||
if (extend == nzExtend_Finite)
|
||||
return obb == volume.obb;
|
||||
else
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ template<typename T>
|
||||
bool NzBox<T>::Contains(const NzBox<T>& box) const
|
||||
{
|
||||
return Contains(box.x, box.y, box.z) &&
|
||||
Contains(box.x + box.width, box.y + box.height, box.z + box.depth);
|
||||
Contains(box.x + box.width, box.y + box.height, box.z + box.depth);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -399,9 +399,9 @@ NzBox<T>& NzBox<T>::Transform(const NzMatrix4<T>& matrix, bool applyTranslation)
|
||||
NzVector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Valeur multipliant la translation
|
||||
NzVector3<T> halfSize = GetLengths()/F(2.0);
|
||||
|
||||
halfSize.Set(std::fabs(matrix(0,0))*halfSize.x + std::fabs(matrix(1,0))*halfSize.y + std::fabs(matrix(2,0))*halfSize.z,
|
||||
std::fabs(matrix(0,1))*halfSize.x + std::fabs(matrix(1,1))*halfSize.y + std::fabs(matrix(2,1))*halfSize.z,
|
||||
std::fabs(matrix(0,2))*halfSize.x + std::fabs(matrix(1,2))*halfSize.y + std::fabs(matrix(2,2))*halfSize.z);
|
||||
halfSize.Set(std::abs(matrix(0,0))*halfSize.x + std::abs(matrix(1,0))*halfSize.y + std::abs(matrix(2,0))*halfSize.z,
|
||||
std::abs(matrix(0,1))*halfSize.x + std::abs(matrix(1,1))*halfSize.y + std::abs(matrix(2,1))*halfSize.z,
|
||||
std::abs(matrix(0,2))*halfSize.x + std::abs(matrix(1,2))*halfSize.y + std::abs(matrix(2,2))*halfSize.z);
|
||||
|
||||
return Set(center - halfSize, center + halfSize);
|
||||
}
|
||||
@@ -486,7 +486,7 @@ template<typename T>
|
||||
bool NzBox<T>::operator==(const NzBox& box) const
|
||||
{
|
||||
return NzNumberEquals(x, box.x) && NzNumberEquals(y, box.y) && NzNumberEquals(z, box.z) &&
|
||||
NzNumberEquals(width, box.width) && NzNumberEquals(height, box.height) && NzNumberEquals(depth, box.depth);
|
||||
NzNumberEquals(width, box.width) && NzNumberEquals(height, box.height) && NzNumberEquals(depth, box.depth);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -91,11 +91,18 @@ void NzEulerAngles<T>::Set(const NzEulerAngles<U>& angles)
|
||||
template<typename T>
|
||||
NzQuaternion<T> NzEulerAngles<T>::ToQuaternion() const
|
||||
{
|
||||
NzQuaternion<T> rotX(pitch, NzVector3<T>::UnitX());
|
||||
NzQuaternion<T> rotY(yaw, NzVector3<T>::UnitY());
|
||||
NzQuaternion<T> rotZ(roll, NzVector3<T>::UnitZ());
|
||||
T c1 = std::cos(NzToRadians(yaw) / F(2.0));
|
||||
T c2 = std::cos(NzToRadians(roll) / F(2.0));
|
||||
T c3 = std::cos(NzToRadians(pitch) / F(2.0));
|
||||
|
||||
return rotY * rotX * rotZ;
|
||||
T s1 = std::sin(NzToRadians(yaw) / F(2.0));
|
||||
T s2 = std::sin(NzToRadians(roll) / F(2.0));
|
||||
T s3 = std::sin(NzToRadians(pitch) / F(2.0));
|
||||
|
||||
return NzQuaternion<T>(c1 * c2 * c3 - s1 * s2 * s3,
|
||||
s1 * s2 * c3 + c1 * c2 * s3,
|
||||
s1 * c2 * c3 + c1 * s2 * s3,
|
||||
c1 * s2 * c3 - s1 * c2 * s3);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -180,7 +180,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
plane[3] *= invLength;
|
||||
plane[3] *= -invLength;
|
||||
|
||||
m_planes[nzFrustumPlane_Right].Set(plane);
|
||||
|
||||
@@ -195,7 +195,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
plane[3] *= invLength;
|
||||
plane[3] *= -invLength;
|
||||
|
||||
m_planes[nzFrustumPlane_Left].Set(plane);
|
||||
|
||||
@@ -210,7 +210,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
plane[3] *= invLength;
|
||||
plane[3] *= -invLength;
|
||||
|
||||
m_planes[nzFrustumPlane_Bottom].Set(plane);
|
||||
|
||||
@@ -225,7 +225,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
plane[3] *= invLength;
|
||||
plane[3] *= -invLength;
|
||||
|
||||
m_planes[nzFrustumPlane_Top].Set(plane);
|
||||
|
||||
@@ -240,7 +240,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
plane[3] *= invLength;
|
||||
plane[3] *= -invLength;
|
||||
|
||||
m_planes[nzFrustumPlane_Far].Set(plane);
|
||||
|
||||
@@ -255,7 +255,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
plane[3] *= invLength;
|
||||
plane[3] *= -invLength;
|
||||
|
||||
m_planes[nzFrustumPlane_Near].Set(plane);
|
||||
|
||||
@@ -332,10 +332,7 @@ NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& clipMatrix)
|
||||
template<typename T>
|
||||
NzFrustum<T>& NzFrustum<T>::Extract(const NzMatrix4<T>& view, const NzMatrix4<T>& projection)
|
||||
{
|
||||
NzMatrix4<T> clipMatrix(view);
|
||||
clipMatrix *= projection;
|
||||
|
||||
return Extract(clipMatrix);
|
||||
return Extract(NzMatrix4<T>::Concatenate(view, projection));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -81,7 +81,6 @@ class NzMatrix4
|
||||
NzMatrix4& Set(const T matrix[16]);
|
||||
//NzMatrix4(const NzMatrix3<T>& matrix);
|
||||
NzMatrix4& Set(const NzMatrix4& matrix);
|
||||
NzMatrix4& Set(NzMatrix4&& matrix);
|
||||
template<typename U> NzMatrix4& Set(const NzMatrix4<U>& matrix);
|
||||
NzMatrix4& SetRotation(const NzQuaternion<T>& rotation);
|
||||
NzMatrix4& SetScale(const NzVector3<T>& scale);
|
||||
|
||||
@@ -585,6 +585,21 @@ NzMatrix4<T>& NzMatrix4<T>::MakeIdentity()
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzMatrix4<T>& NzMatrix4<T>::MakeLookAt(const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up)
|
||||
{
|
||||
NzVector3<T> f = NzVector3<T>::Normalize(target - eye);
|
||||
NzVector3<T> s = NzVector3<T>::Normalize(f.CrossProduct(up));
|
||||
NzVector3<T> u = s.CrossProduct(f);
|
||||
|
||||
Set(s.x, u.x, -f.x, T(0.0),
|
||||
s.y, u.y, -f.y, T(0.0),
|
||||
s.z, u.z, -f.z, T(0.0),
|
||||
-s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzMatrix4<T>& NzMatrix4<T>::MakeOrtho(T left, T right, T top, T bottom, T zNear, T zFar)
|
||||
{
|
||||
@@ -597,22 +612,6 @@ NzMatrix4<T>& NzMatrix4<T>::MakeOrtho(T left, T right, T top, T bottom, T zNear,
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzMatrix4<T>& NzMatrix4<T>::MakeLookAt(const NzVector3<T>& eye, const NzVector3<T>& target, const NzVector3<T>& up)
|
||||
{
|
||||
NzVector3<T> f = NzVector3<T>::Normalize(target - eye);
|
||||
NzVector3<T> u(up.GetNormal());
|
||||
NzVector3<T> s = NzVector3<T>::Normalize(f.CrossProduct(u));
|
||||
u = s.CrossProduct(f);
|
||||
|
||||
Set(s.x, u.x, -f.x, T(0.0),
|
||||
s.y, u.y, -f.y, T(0.0),
|
||||
s.z, u.z, -f.z, T(0.0),
|
||||
-s.DotProduct(eye), -u.DotProduct(eye), f.DotProduct(eye), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzMatrix4<T>& NzMatrix4<T>::MakePerspective(T angle, T ratio, T zNear, T zFar)
|
||||
{
|
||||
@@ -627,8 +626,8 @@ NzMatrix4<T>& NzMatrix4<T>::MakePerspective(T angle, T ratio, T zNear, T zFar)
|
||||
|
||||
Set(yScale / ratio, F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), yScale, F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), zFar / (zNear-zFar), F(-1.0),
|
||||
F(0.0), F(0.0), (zNear*zFar) / (zNear-zFar), F(0.0));
|
||||
F(0.0), F(0.0), - (zFar + zNear) / (zFar - zNear), F(-1.0),
|
||||
F(0.0), F(0.0), F(-2.0) * (zNear * zFar) / (zFar - zNear), F(0.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -703,7 +702,7 @@ NzMatrix4<T>& NzMatrix4<T>::MakeViewMatrix(const NzVector3<T>& translation, cons
|
||||
// Une matrice de vue doit appliquer une transformation opposée à la matrice "monde"
|
||||
NzQuaternion<T> invRot = rotation.GetConjugate(); // Inverse de la rotation
|
||||
|
||||
return MakeTransform(-(invRot*translation), invRot);
|
||||
return MakeTransform(-(invRot * translation), invRot);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -828,9 +827,9 @@ NzString NzMatrix4<T>::ToString() const
|
||||
{
|
||||
NzStringStream ss;
|
||||
return ss << "Matrix4(" << m11 << ", " << m12 << ", " << m13 << ", " << m14 << ",\n"
|
||||
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
|
||||
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
|
||||
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
|
||||
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
|
||||
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
|
||||
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -103,9 +103,9 @@ template<typename U>
|
||||
NzOrientedBox<T>& NzOrientedBox<T>::Set(const NzOrientedBox<U>& orientedBox)
|
||||
{
|
||||
for (unsigned int i = 0; i <= nzBoxCorner_Max; ++i)
|
||||
m_corners[i].Set(orientedBox.m_corners[i]);
|
||||
m_corners[i].Set(orientedBox(i));
|
||||
|
||||
localBox = orientedBox.localBox;
|
||||
localBox.Set(orientedBox.localBox);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -158,7 +158,7 @@ NzVector3<T>& NzOrientedBox<T>::operator()(unsigned int i)
|
||||
if (i > nzBoxCorner_Max)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << "Index out of range: (" << i << " >= 3)";
|
||||
ss << "Index out of range: (" << i << " >= " << nzBoxCorner_Max << ")";
|
||||
|
||||
NazaraError(ss);
|
||||
throw std::out_of_range(ss.ToString());
|
||||
@@ -175,7 +175,7 @@ NzVector3<T> NzOrientedBox<T>::operator()(unsigned int i) const
|
||||
if (i > nzBoxCorner_Max)
|
||||
{
|
||||
NzStringStream ss;
|
||||
ss << "Index out of range: (" << i << " >= 3)";
|
||||
ss << "Index out of range: (" << i << " >= " << nzBoxCorner_Max << ")";
|
||||
|
||||
NazaraError(ss);
|
||||
throw std::out_of_range(ss.ToString());
|
||||
|
||||
@@ -37,6 +37,9 @@ class NzPlane
|
||||
|
||||
NzString ToString() const;
|
||||
|
||||
bool operator==(const NzPlane& plane) const;
|
||||
bool operator!=(const NzPlane& plane) const;
|
||||
|
||||
static NzPlane Lerp(const NzPlane& from, const NzPlane& to, T interpolation);
|
||||
static NzPlane XY();
|
||||
static NzPlane XZ();
|
||||
|
||||
@@ -49,7 +49,7 @@ NzPlane<T>::NzPlane(const NzPlane<U>& plane)
|
||||
template<typename T>
|
||||
T NzPlane<T>::Distance(const NzVector3<T>& point) const
|
||||
{
|
||||
return normal.DotProduct(point) + distance;
|
||||
return normal.DotProduct(point) - distance; // ax + by + cd - d = 0.
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -110,7 +110,7 @@ NzPlane<T>& NzPlane<T>::Set(const NzVector3<T>& point1, const NzVector3<T>& poin
|
||||
normal = edge1.CrossProduct(edge2);
|
||||
normal.Normalize();
|
||||
|
||||
distance = -normal.DotProduct(point3);
|
||||
distance = normal.DotProduct(point3);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -133,6 +133,18 @@ NzString NzPlane<T>::ToString() const
|
||||
return ss << "Plane(Normal: " << normal.ToString() << "; Distance: " << distance << ')';
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzPlane<T>::operator==(const NzPlane& plane) const
|
||||
{
|
||||
return (normal == plane.normal && NzNumberEquals(distance, plane.distance)) || (normal == -plane.normal && NzNumberEquals(distance, -plane.distance));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzPlane<T>::operator!=(const NzPlane& plane) const
|
||||
{
|
||||
return !operator==(plane);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzPlane<T> NzPlane<T>::Lerp(const NzPlane& from, const NzPlane& to, T interpolation)
|
||||
{
|
||||
@@ -155,19 +167,19 @@ NzPlane<T> NzPlane<T>::Lerp(const NzPlane& from, const NzPlane& to, T interpolat
|
||||
template<typename T>
|
||||
NzPlane<T> NzPlane<T>::XY()
|
||||
{
|
||||
return NzPlane<T>(F(0.0), F(0.0), F(1.0), F(0.0));
|
||||
return NzPlane<T>(F(0.0), F(0.0), F(1.0), F(0.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzPlane<T> NzPlane<T>::XZ()
|
||||
{
|
||||
return NzPlane<T>(F(0.0), F(1.0), F(0.0), F(0.0));
|
||||
return NzPlane<T>(F(0.0), F(1.0), F(0.0), F(0.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzPlane<T> NzPlane<T>::YZ()
|
||||
{
|
||||
return NzPlane<T>(F(1.0), F(0.0), F(0.0), F(0.0));
|
||||
return NzPlane<T>(F(1.0), F(0.0), F(0.0), F(0.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -237,10 +237,10 @@ template<typename T>
|
||||
template<typename U>
|
||||
NzQuaternion<T>& NzQuaternion<T>::Set(const NzQuaternion<U>& quat)
|
||||
{
|
||||
w = static_cast<T>(quat.w);
|
||||
x = static_cast<T>(quat.x);
|
||||
y = static_cast<T>(quat.y);
|
||||
z = static_cast<T>(quat.z);
|
||||
w = F(quat.w);
|
||||
x = F(quat.x);
|
||||
y = F(quat.y);
|
||||
z = F(quat.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -270,9 +270,9 @@ NzEulerAngles<T> NzQuaternion<T>::ToEulerAngles() const
|
||||
if (test < F(-0.499))
|
||||
return NzEulerAngles<T>(NzFromDegrees(F(-90.0)), NzFromRadians(F(-2.0) * std::atan2(x, w)), F(0.0));
|
||||
|
||||
return NzEulerAngles<T>(NzFromRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*x* - F(2.0)*z*z)),
|
||||
NzFromRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*y*y - F(2.0)*z*z)),
|
||||
NzFromRadians(std::asin(F(2.0)*test)));
|
||||
return NzEulerAngles<T>(NzFromRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*x*x - F(2.0)*z*z)),
|
||||
NzFromRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*y*y - F(2.0)*z*z)),
|
||||
NzFromRadians(std::asin(F(2.0)*test)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -329,9 +329,9 @@ template<typename T>
|
||||
NzQuaternion<T> NzQuaternion<T>::operator*(T scale) const
|
||||
{
|
||||
return NzQuaternion(w * scale,
|
||||
x * scale,
|
||||
y * scale,
|
||||
z * scale);
|
||||
x * scale,
|
||||
y * scale,
|
||||
z * scale);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -368,9 +368,9 @@ template<typename T>
|
||||
bool NzQuaternion<T>::operator==(const NzQuaternion& quat) const
|
||||
{
|
||||
return NzNumberEquals(w, quat.w) &&
|
||||
NzNumberEquals(x, quat.x) &&
|
||||
NzNumberEquals(y, quat.y) &&
|
||||
NzNumberEquals(z, quat.z);
|
||||
NzNumberEquals(x, quat.x) &&
|
||||
NzNumberEquals(y, quat.y) &&
|
||||
NzNumberEquals(z, quat.z);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -450,23 +450,23 @@ NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& from, const NzQuatern
|
||||
if (cosOmega > F(0.9999))
|
||||
{
|
||||
// Interpolation linéaire pour éviter une division par zéro
|
||||
k0 = F(1.0) - interpolation;
|
||||
k1 = interpolation;
|
||||
}
|
||||
else
|
||||
{
|
||||
T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega);
|
||||
T omega = std::atan2(sinOmega, cosOmega);
|
||||
k0 = F(1.0) - interpolation;
|
||||
k1 = interpolation;
|
||||
}
|
||||
else
|
||||
{
|
||||
T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega);
|
||||
T omega = std::atan2(sinOmega, cosOmega);
|
||||
|
||||
// Pour éviter deux divisions
|
||||
sinOmega = F(1.0)/sinOmega;
|
||||
|
||||
k0 = std::sin((F(1.0) - interpolation) * omega) * sinOmega;
|
||||
k1 = std::sin(interpolation*omega) * sinOmega;
|
||||
}
|
||||
k0 = std::sin((F(1.0) - interpolation) * omega) * sinOmega;
|
||||
k1 = std::sin(interpolation*omega) * sinOmega;
|
||||
}
|
||||
|
||||
NzQuaternion result(k0 * from.w, k0 * from.x, k0 * from.y, k0 * from.z);
|
||||
return result += q*k1;
|
||||
NzQuaternion result(k0 * from.w, k0 * from.x, k0 * from.y, k0 * from.z);
|
||||
return result += q*k1;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -34,12 +34,12 @@ class NzRay
|
||||
|
||||
NzVector3<T> GetPoint(T lambda) const;
|
||||
|
||||
//bool Intersect(const NzBoundingVolume<T>& volume, T* closestHit = nullptr, T* farthestHit = nullptr) const;
|
||||
bool Intersect(const NzBox<T>& box, T* closestHit = nullptr, T* farthestHit = nullptr) const;
|
||||
bool Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T* closestHit = nullptr, T* farthestHit = nullptr) const;
|
||||
//bool Intersect(const NzOrientedBox<T>& orientedBox, T* closestHit = nullptr, T* farthestHit = nullptr) const;
|
||||
bool Intersect(const NzBoundingVolume<T>& volume, T* closestHit = nullptr, T* furthestHit = nullptr) const;
|
||||
bool Intersect(const NzBox<T>& box, T* closestHit = nullptr, T* furthestHit = nullptr) const;
|
||||
bool Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T* closestHit = nullptr, T* furthestHit = nullptr) const;
|
||||
bool Intersect(const NzOrientedBox<T>& orientedBox, T* closestHit = nullptr, T* furthestHit = nullptr) const;
|
||||
bool Intersect(const NzPlane<T>& plane, T* hit = nullptr) const;
|
||||
bool Intersect(const NzSphere<T>& sphere, T* closestHit = nullptr, T* farthestHit = nullptr) const;
|
||||
bool Intersect(const NzSphere<T>& sphere, T* closestHit = nullptr, T* furthestHit = nullptr) const;
|
||||
|
||||
NzRay& MakeAxisX();
|
||||
NzRay& MakeAxisY();
|
||||
@@ -57,6 +57,9 @@ class NzRay
|
||||
|
||||
NzVector3<T> operator*(T lambda) const;
|
||||
|
||||
bool operator==(const NzRay& ray) const;
|
||||
bool operator!=(const NzRay& ray) const;
|
||||
|
||||
static NzRay AxisX();
|
||||
static NzRay AxisY();
|
||||
static NzRay AxisZ();
|
||||
|
||||
@@ -59,18 +59,18 @@ T NzRay<T>::ClosestPoint(const NzVector3<T>& point) const
|
||||
template<typename T>
|
||||
NzVector3<T> NzRay<T>::GetPoint(T lambda) const
|
||||
{
|
||||
return origin + lambda*direction;
|
||||
return origin + lambda * direction;
|
||||
}
|
||||
/*
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::Intersect(const NzBoundingVolume<T>& volume, T* closestHit, T* farthestHit) const
|
||||
bool NzRay<T>::Intersect(const NzBoundingVolume<T>& volume, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
switch (volume.extend)
|
||||
{
|
||||
case nzExtend_Finite:
|
||||
{
|
||||
if (Intersect(volume.aabb))
|
||||
return Intersect(volume.obb, closestHit, farthestHit);
|
||||
return Intersect(volume.obb, closestHit, furthestHit);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -80,8 +80,8 @@ bool NzRay<T>::Intersect(const NzBoundingVolume<T>& volume, T* closestHit, T* fa
|
||||
if (closestHit)
|
||||
*closestHit = F(0.0);
|
||||
|
||||
if (farthestHit)
|
||||
*farthestHit = std::numeric_limits<T>::infinity();
|
||||
if (furthestHit)
|
||||
*furthestHit = std::numeric_limits<T>::infinity();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -93,9 +93,9 @@ bool NzRay<T>::Intersect(const NzBoundingVolume<T>& volume, T* closestHit, T* fa
|
||||
NazaraError("Invalid extend type (0x" + NzString::Number(volume.extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::Intersect(const NzBox<T>& box, T* closestHit, T* farthestHit) const
|
||||
bool NzRay<T>::Intersect(const NzBox<T>& box, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
// http://www.gamedev.net/topic/429443-obb-ray-and-obb-plane-intersection/
|
||||
T tfirst = F(0.0);
|
||||
@@ -134,14 +134,14 @@ bool NzRay<T>::Intersect(const NzBox<T>& box, T* closestHit, T* farthestHit) con
|
||||
if (closestHit)
|
||||
*closestHit = tfirst;
|
||||
|
||||
if (farthestHit)
|
||||
*farthestHit = tlast;
|
||||
if (furthestHit)
|
||||
*furthestHit = tlast;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T* closestHit, T* farthestHit) const
|
||||
bool NzRay<T>::Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
// http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/
|
||||
// Intersection method from Real-Time Rendering and Essential Mathematics for Games
|
||||
@@ -192,32 +192,39 @@ bool NzRay<T>::Intersect(const NzBox<T>& box, const NzMatrix4<T>& transform, T*
|
||||
if (closestHit)
|
||||
*closestHit = tMin;
|
||||
|
||||
if (farthestHit)
|
||||
*farthestHit = tMax;
|
||||
if (furthestHit)
|
||||
*furthestHit = tMax;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///FIXME: Le test ci-dessous est beaucoup trop approximatif pour être vraiment utile
|
||||
/// Mais le vrai problème vient certainement des OrientedBox en elles-mêmes, peut-être faut-il envisager de les refaire ?
|
||||
/*
|
||||
template<typename T>
|
||||
bool NzRay<T>::Intersect(const NzOrientedBox<T>& orientedBox, T* closestHit, T* farthestHit) const
|
||||
bool NzRay<T>::Intersect(const NzOrientedBox<T>& orientedBox, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
NzVector3<T> width = (orientedBox.GetCorner(nzBoxCorner_NearLeftBottom) - orientedBox.GetCorner(nzBoxCorner_FarLeftBottom)).Normalize();
|
||||
NzVector3<T> height = (orientedBox.GetCorner(nzBoxCorner_FarLeftTop) - orientedBox.GetCorner(nzBoxCorner_FarLeftBottom)).Normalize();
|
||||
NzVector3<T> depth = (orientedBox.GetCorner(nzBoxCorner_FarRightBottom) - orientedBox.GetCorner(nzBoxCorner_FarLeftBottom)).Normalize();
|
||||
NzVector3<T> corner = orientedBox.GetCorner(nzBoxCorner_FarLeftBottom);
|
||||
NzVector3<T> oppositeCorner = orientedBox.GetCorner(nzBoxCorner_NearRightTop);
|
||||
|
||||
NzVector3<T> width = (orientedBox.GetCorner(nzBoxCorner_NearLeftBottom) - corner);
|
||||
NzVector3<T> height = (orientedBox.GetCorner(nzBoxCorner_FarLeftTop) - corner);
|
||||
NzVector3<T> depth = (orientedBox.GetCorner(nzBoxCorner_FarRightBottom) - corner);
|
||||
|
||||
// Construction de la matrice de transformation de l'OBB
|
||||
NzMatrix4<T> matrix(width.x, height.x, depth.x, F(0.0),
|
||||
width.y, height.y, depth.y, F(0.0),
|
||||
width.z, height.z, depth.z, F(0.0),
|
||||
NzMatrix4<T> matrix(width.x, height.x, depth.x, corner.x,
|
||||
width.y, height.y, depth.y, corner.y,
|
||||
width.z, height.z, depth.z, corner.z,
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
|
||||
// Test en tant qu'AABB avec une matrice de rotation
|
||||
return Intersect(orientedBox.localBox, matrix, closestHit, farthestHit);
|
||||
matrix.InverseAffine();
|
||||
|
||||
corner = matrix.Transform(corner);
|
||||
oppositeCorner = matrix.Transform(oppositeCorner);
|
||||
|
||||
NzBox<T> tmpBox(corner, oppositeCorner);
|
||||
NzRay<T> tmpRay(matrix.Transform(origin), matrix.Transform(direction));
|
||||
|
||||
return tmpRay.Intersect(tmpBox, closestHit, furthestHit);
|
||||
}
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::Intersect(const NzPlane<T>& plane, T* hit) const
|
||||
{
|
||||
@@ -225,9 +232,9 @@ bool NzRay<T>::Intersect(const NzPlane<T>& plane, T* hit) const
|
||||
if (NzNumberEquals(divisor, F(0.0)))
|
||||
return false; // perpendicular
|
||||
|
||||
T lambda = -(plane.normal.DotProduct(origin) + plane.distance) / divisor; // The plane is ax+by+cz=d
|
||||
T lambda = -(plane.normal.DotProduct(origin) - plane.distance) / divisor; // The plane is ax + by + cz = d
|
||||
if (lambda < F(0.0))
|
||||
return false; // Le plan est derrière le rayon
|
||||
return false; // The plane is 'behind' the ray.
|
||||
|
||||
if (hit)
|
||||
*hit = lambda;
|
||||
@@ -236,7 +243,7 @@ bool NzRay<T>::Intersect(const NzPlane<T>& plane, T* hit) const
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::Intersect(const NzSphere<T>& sphere, T* closestHit, T* farthestHit) const
|
||||
bool NzRay<T>::Intersect(const NzSphere<T>& sphere, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
NzVector3<T> sphereRay = sphere.GetPosition() - origin;
|
||||
T length = sphereRay.DotProduct(direction);
|
||||
@@ -251,15 +258,15 @@ bool NzRay<T>::Intersect(const NzSphere<T>& sphere, T* closestHit, T* farthestHi
|
||||
return false; // if the ray is further than the radius
|
||||
|
||||
// Calcul des points d'intersection si besoin
|
||||
if (closestHit || farthestHit)
|
||||
if (closestHit || furthestHit)
|
||||
{
|
||||
T deltaLambda = std::sqrt(squaredRadius - squaredDistance);
|
||||
|
||||
if (closestHit)
|
||||
*closestHit = length - deltaLambda;
|
||||
|
||||
if (farthestHit)
|
||||
*farthestHit = length + deltaLambda;
|
||||
if (furthestHit)
|
||||
*furthestHit = length + deltaLambda;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -380,6 +387,18 @@ NzVector3<T> NzRay<T>::operator*(T lambda) const
|
||||
return GetPoint(lambda);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::operator==(const NzRay& ray) const
|
||||
{
|
||||
return direction == ray.direction && origin == ray.origin;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool NzRay<T>::operator!=(const NzRay& ray) const
|
||||
{
|
||||
return !operator==(ray);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzRay<T> NzRay<T>::AxisX()
|
||||
{
|
||||
|
||||
@@ -64,7 +64,7 @@ template<typename T>
|
||||
bool NzRect<T>::Contains(const NzRect<T>& rect) const
|
||||
{
|
||||
return Contains(rect.x, rect.y) &&
|
||||
Contains(rect.x + rect.width, rect.y + rect.height);
|
||||
Contains(rect.x + rect.width, rect.y + rect.height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -410,7 +410,7 @@ template<typename T>
|
||||
bool NzRect<T>::operator==(const NzRect& rect) const
|
||||
{
|
||||
return NzNumberEquals(x, rect.x) && NzNumberEquals(y, rect.y) &&
|
||||
NzNumberEquals(width, rect.width) && NzNumberEquals(height, rect.height);
|
||||
NzNumberEquals(width, rect.width) && NzNumberEquals(height, rect.height);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -51,13 +51,13 @@ bool NzSphere<T>::Contains(T X, T Y, T Z) const
|
||||
template<typename T>
|
||||
bool NzSphere<T>::Contains(const NzBox<T>& box) const
|
||||
{
|
||||
if (box.GetMinimum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
{
|
||||
if (box.GetMaximum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
return true;
|
||||
}
|
||||
if (box.GetMinimum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
{
|
||||
if (box.GetMaximum().SquaredDistance(GetPosition()) <= radius * radius)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
template<typename T>
|
||||
bool NzSphere<T>::Contains(const NzVector3<T>& point) const
|
||||
@@ -155,7 +155,7 @@ bool NzSphere<T>::Intersect(const NzBox<T>& box) const
|
||||
squaredDistance += diff*diff;
|
||||
}
|
||||
|
||||
return squaredDistance <= radius * radius;
|
||||
return squaredDistance <= radius * radius;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -27,12 +27,10 @@ class NzVector2
|
||||
~NzVector2() = default;
|
||||
|
||||
T AbsDotProduct(const NzVector2& vec) const;
|
||||
|
||||
T AngleBetween(const NzVector2& vec) const;
|
||||
|
||||
T Distance(const NzVector2& vec) const;
|
||||
float Distancef(const NzVector2& vec) const;
|
||||
|
||||
T DotProduct(const NzVector2& vec) const;
|
||||
|
||||
T GetLength() const;
|
||||
@@ -40,6 +38,7 @@ class NzVector2
|
||||
NzVector2 GetNormal(T* length = nullptr) const;
|
||||
T GetSquaredLength() const;
|
||||
|
||||
NzVector2& MakeUnit();
|
||||
NzVector2& MakeUnitX();
|
||||
NzVector2& MakeUnitY();
|
||||
NzVector2& MakeZero();
|
||||
@@ -89,6 +88,7 @@ class NzVector2
|
||||
bool operator>=(const NzVector2& vec) const;
|
||||
|
||||
static NzVector2 Lerp(const NzVector2& from, const NzVector2& to, T interpolation);
|
||||
static NzVector2 Unit();
|
||||
static NzVector2 UnitX();
|
||||
static NzVector2 UnitY();
|
||||
static NzVector2 Zero();
|
||||
|
||||
@@ -105,6 +105,12 @@ T NzVector2<T>::GetSquaredLength() const
|
||||
return x*x + y*y;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>& NzVector2<T>::MakeUnit()
|
||||
{
|
||||
return Set(F(1.0), F(1.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T>& NzVector2<T>::MakeUnitX()
|
||||
{
|
||||
@@ -129,7 +135,7 @@ NzVector2<T>& NzVector2<T>::Maximize(const NzVector2& vec)
|
||||
if (vec.x > x)
|
||||
x = vec.x;
|
||||
|
||||
if (vec.y > y)
|
||||
if (vec.y > y)
|
||||
y = vec.y;
|
||||
|
||||
return *this;
|
||||
@@ -141,7 +147,7 @@ NzVector2<T>& NzVector2<T>::Minimize(const NzVector2& vec)
|
||||
if (vec.x < x)
|
||||
x = vec.x;
|
||||
|
||||
if (vec.y < y)
|
||||
if (vec.y < y)
|
||||
y = vec.y;
|
||||
|
||||
return *this;
|
||||
@@ -229,7 +235,7 @@ NzVector2<T>& NzVector2<T>::Set(const NzVector4<T>& vec)
|
||||
template<typename T>
|
||||
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
|
||||
{
|
||||
return operator-(vec).GetSquaredLength();
|
||||
return (*this - vec).GetSquaredLength();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -398,7 +404,7 @@ template<typename T>
|
||||
bool NzVector2<T>::operator==(const NzVector2& vec) const
|
||||
{
|
||||
return NzNumberEquals(x, vec.x) &&
|
||||
NzNumberEquals(y, vec.y);
|
||||
NzNumberEquals(y, vec.y);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -443,6 +449,15 @@ NzVector2<T> NzVector2<T>::Lerp(const NzVector2& from, const NzVector2& to, T in
|
||||
return NzLerp(from, to, interpolation);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T> NzVector2<T>::Unit()
|
||||
{
|
||||
NzVector2 vector;
|
||||
vector.MakeUnit();
|
||||
|
||||
return vector;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
NzVector2<T> NzVector2<T>::UnitX()
|
||||
{
|
||||
|
||||
@@ -28,14 +28,12 @@ class NzVector3
|
||||
~NzVector3() = default;
|
||||
|
||||
T AbsDotProduct(const NzVector3& vec) const;
|
||||
|
||||
T AngleBetween(const NzVector3& vec) const;
|
||||
|
||||
NzVector3 CrossProduct(const NzVector3& vec) const;
|
||||
|
||||
T Distance(const NzVector3& vec) const;
|
||||
float Distancef(const NzVector3& vec) const;
|
||||
|
||||
T DotProduct(const NzVector3& vec) const;
|
||||
|
||||
T GetLength() const;
|
||||
|
||||
@@ -64,9 +64,9 @@ template<typename T>
|
||||
T NzVector3<T>::AngleBetween(const NzVector3& vec) const
|
||||
{
|
||||
// sqrt(a) * sqrt(b) = sqrt(a*b)
|
||||
T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength());
|
||||
T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength());
|
||||
|
||||
#if NAZARA_MATH_SAFE
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NzNumberEquals(divisor, F(0.0)))
|
||||
{
|
||||
NzString error("Division by zero");
|
||||
@@ -325,7 +325,7 @@ NzVector3<T>& NzVector3<T>::Set(const NzVector4<T>& vec)
|
||||
template<typename T>
|
||||
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
|
||||
{
|
||||
return operator-(vec).GetSquaredLength();
|
||||
return (*this - vec).GetSquaredLength();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -121,11 +121,11 @@ NzVector4<T>& NzVector4<T>::Maximize(const NzVector4& vec)
|
||||
if (vec.y > y)
|
||||
y = vec.y;
|
||||
|
||||
if (vec.z > z)
|
||||
z = vec.z;
|
||||
if (vec.z > z)
|
||||
z = vec.z;
|
||||
|
||||
if (vec.w > w)
|
||||
w = vec.w;
|
||||
if (vec.w > w)
|
||||
w = vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -139,11 +139,11 @@ NzVector4<T>& NzVector4<T>::Minimize(const NzVector4& vec)
|
||||
if (vec.y < y)
|
||||
y = vec.y;
|
||||
|
||||
if (vec.z < z)
|
||||
z = vec.z;
|
||||
if (vec.z < z)
|
||||
z = vec.z;
|
||||
|
||||
if (vec.w < w)
|
||||
w = vec.w;
|
||||
if (vec.w < w)
|
||||
w = vec.w;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -447,9 +447,9 @@ template<typename T>
|
||||
bool NzVector4<T>::operator==(const NzVector4& vec) const
|
||||
{
|
||||
return NzNumberEquals(x, vec.x) &&
|
||||
NzNumberEquals(y, vec.y) &&
|
||||
NzNumberEquals(z, vec.z) &&
|
||||
NzNumberEquals(w, vec.w);
|
||||
NzNumberEquals(y, vec.y) &&
|
||||
NzNumberEquals(z, vec.z) &&
|
||||
NzNumberEquals(w, vec.w);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
#define NAZARA_EXPORT __attribute__((visibility ("default")))
|
||||
#define NAZARA_IMPORT __attribute__((visibility ("default")))
|
||||
/*#elif defined(__APPLE__) && defined(__MACH__)
|
||||
#define NAZARA_API
|
||||
#define NAZARA_CORE_API
|
||||
#define NAZARA_PLATFORM_MACOSX
|
||||
#define NAZARA_PLATFORM_POSIX*/
|
||||
#else
|
||||
@@ -129,7 +129,7 @@
|
||||
#error This operating system is not fully supported by the Nazara Engine
|
||||
|
||||
#define NAZARA_PLATFORM_UNKNOWN
|
||||
#define NAZARA_API
|
||||
#define NAZARA_CORE_API
|
||||
#endif
|
||||
|
||||
// Détection 64 bits
|
||||
|
||||
@@ -29,6 +29,7 @@ class NAZARA_RENDERER_API NzDebugDrawer
|
||||
static void Draw(const NzOrientedBoxf& orientedBox);
|
||||
static void Draw(const NzSkeleton* skeleton);
|
||||
static void Draw(const NzVector3f& position, float size = 0.1f);
|
||||
static void DrawAxes(const NzVector3f& position = NzVector3f::Zero(), float size = 1.f);
|
||||
static void DrawBinormals(const NzStaticMesh* subMesh);
|
||||
static void DrawCone(const NzVector3f& origin, const NzQuaternionf& rotation, float angle, float length);
|
||||
static void DrawLine(const NzVector3f& p1, const NzVector3f& p2);
|
||||
|
||||
Reference in New Issue
Block a user