Merge remote-tracking branch 'refs/remotes/origin/master' into gui

This commit is contained in:
Lynix
2016-11-30 13:08:08 +01:00
227 changed files with 9347 additions and 4815 deletions

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 24 Jun 2015 at 13:55:50
// This file was automatically generated
/*
Nazara Engine - Audio module

View File

@@ -73,6 +73,7 @@ namespace Nz
bool FillAndQueueBuffer(unsigned int buffer);
void MusicThread();
void StopThread();
static MusicLoader::LoaderList s_loaders;
};

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 09 May 2016 at 17:07:09
// This file was automatically generated
/*
Nazara Engine - Core module

View File

@@ -1,10 +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
/*!
* \ingroup core
* \class Nz::AbstractLogger
* \brief Logger interface
*/

View File

@@ -22,6 +22,7 @@ namespace Nz
template<typename F, typename Tuple> decltype(auto) Apply(F&& fn, Tuple&& t);
template<typename O, typename F, typename Tuple> decltype(auto) Apply(O& object, F&& fn, Tuple&& t);
template<typename T> constexpr std::size_t BitCount();
template<typename T> ByteArray ComputeHash(HashType hash, const T& v);
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
template<typename T, std::size_t N> constexpr std::size_t CountOf(T(&name)[N]) noexcept;

View File

@@ -11,6 +11,7 @@
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Stream.hpp>
#include <climits>
#include <Nazara/Core/Debug.hpp>
namespace Nz
@@ -70,6 +71,17 @@ namespace Nz
return Detail::ApplyImplMethod(object, std::forward<F>(fn), std::forward<Tuple>(t), std::make_index_sequence<tSize>());
}
/*!
* \ingroup core
* \brief Returns the number of bits occupied by the type T
* \return Number of bits occupied by the type
*/
template<typename T>
constexpr std::size_t BitCount()
{
return CHAR_BIT * sizeof(T);
}
/*!
* \ingroup core
* \brief Computes the hash of a hashable object

View File

@@ -8,6 +8,7 @@
#define NAZARA_BITSET_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/String.hpp>
#include <limits>
#include <memory>
@@ -24,6 +25,7 @@ namespace Nz
public:
class Bit;
using PointerSequence = std::pair<const void*, std::size_t>; //< Start pointer, bit offset
Bitset();
explicit Bitset(std::size_t bitCount, bool val);
@@ -35,6 +37,8 @@ namespace Nz
Bitset(Bitset&& bitset) noexcept = default;
~Bitset() noexcept = default;
template<typename T> void AppendBits(T bits, std::size_t bitCount);
void Clear() noexcept;
std::size_t Count() const;
void Flip();
@@ -47,6 +51,9 @@ namespace Nz
std::size_t GetCapacity() const;
std::size_t GetSize() const;
PointerSequence Read(const void* ptr, std::size_t bitCount);
PointerSequence Read(const PointerSequence& sequence, std::size_t bitCount);
void PerformsAND(const Bitset& a, const Bitset& b);
void PerformsNOT(const Bitset& a);
void PerformsOR(const Bitset& a, const Bitset& b);
@@ -60,6 +67,8 @@ namespace Nz
void Reset();
void Reset(std::size_t bit);
void Reverse();
void Set(bool val = true);
void Set(std::size_t bit, bool val = true);
void SetBlock(std::size_t i, Block block);
@@ -102,9 +111,11 @@ namespace Nz
Bitset& operator^=(const Bitset& bitset);
static constexpr Block fullBitMask = std::numeric_limits<Block>::max();
static constexpr std::size_t bitsPerBlock = std::numeric_limits<Block>::digits;
static constexpr std::size_t bitsPerBlock = BitCount<Block>();
static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
static Bitset FromPointer(const void* ptr, std::size_t bitCount, PointerSequence* sequence = nullptr);
private:
std::size_t FindFirstFrom(std::size_t blockIndex) const;
Block GetLastBlockMask() const;
@@ -154,6 +165,9 @@ namespace Nz
Block m_mask;
};
template<typename Block, class Allocator>
std::ostream& operator<<(std::ostream& out, const Bitset<Block, Allocator>& bitset);
template<typename Block, class Allocator>
bool operator==(const Bitset<Block, Allocator>& lhs, const Nz::Bitset<Block, Allocator>& rhs);

View File

@@ -6,7 +6,6 @@
#include <Nazara/Core/Error.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <cstdlib>
#include <limits>
#include <utility>
#include <Nazara/Core/Debug.hpp>
@@ -122,13 +121,13 @@ namespace Nz
{
if (sizeof(T) <= sizeof(Block))
{
m_bitCount = std::numeric_limits<T>::digits;
m_bitCount = BitCount<T>();
m_blocks.push_back(static_cast<Block>(value));
}
else
{
// Note: I was kinda tired when I wrote this, there's probably a much easier method than checking bits to write bits
for (std::size_t bitPos = 0; bitPos < std::numeric_limits<T>::digits; bitPos++)
for (std::size_t bitPos = 0; bitPos < BitCount<T>(); bitPos++)
{
if (value & (T(1U) << bitPos))
UnboundedSet(bitPos, true);
@@ -137,11 +136,63 @@ namespace Nz
}
/*!
* \brief Clears the content of the bitset, GetSize() is now equals to 0
* \brief Appends bits to the bitset
*
* \remark The memory allocated is not released
* This function extends the bitset with bits extracted from an integer value
*
* \param bits An integer value from where bits will be extracted
* \param bitCount Number of bits to extract from the value
*
* \remark This function does not require bitCount to be lower or equal to the number of bits of T, thus
* reading 32 bits from a UInt8 will work (by extracting the first 8 bits values and appending 24 zeros afterneath).
*
* \see AppendBits
* \see Read
*/
template<typename Block, class Allocator>
template<typename T>
void Bitset<Block, Allocator>::AppendBits(T bits, std::size_t bitCount)
{
std::size_t bitShift = m_bitCount % bitsPerBlock;
m_bitCount += bitCount;
if (bitShift != 0)
{
std::size_t remainingBits = bitsPerBlock - bitShift;
m_blocks.back() |= Block(bits) << bitShift;
bits >>= bitsPerBlock - bitShift;
bitCount -= std::min(remainingBits, bitCount);
}
if (bitCount > 0)
{
std::size_t blockCount = ComputeBlockCount(bitCount);
for (std::size_t block = 0; block < blockCount - 1; ++block)
{
m_blocks.push_back(static_cast<Block>(bits));
bits = (BitCount<Block>() < BitCount<T>()) ? bits >> BitCount<Block>() : 0U;
bitCount -= BitCount<Block>();
}
// For the last iteration, mask out the bits we don't want
std::size_t remainingBits = bitCount;
bits &= ((Block(1U) << remainingBits) - 1U);
m_blocks.push_back(static_cast<Block>(bits));
}
}
/*!
* \brief Clears the content of the bitset
*
* This function clears the bitset content, resetting its bit and block count at zero.
*
* \remark This does not changes the bits values to zero but empties the bitset, to reset the bits use the Reset() function
* \remark This call does not changes the bitset capacity
*
* \see Reset()
*/
template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Clear() noexcept
{
@@ -151,9 +202,9 @@ namespace Nz
/*!
* \brief Counts the number of bits set to 1
*
* \return Number of bits set to 1
*/
template<typename Block, class Allocator>
std::size_t Bitset<Block, Allocator>::Count() const
{
@@ -169,8 +220,9 @@ namespace Nz
/*!
* \brief Flips each bit of the bitset
*
* This function flips every bit of the bitset, which means every '1' turns into a '0' and conversely.
*/
template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Flip()
{
@@ -182,9 +234,9 @@ namespace Nz
/*!
* \brief Finds the first bit set to one in the bitset
* \return Index of the first bit
*
* \return The 0-based index of the first bit enabled
*/
template<typename Block, class Allocator>
std::size_t Bitset<Block, Allocator>::FindFirst() const
{
@@ -192,14 +244,14 @@ namespace Nz
}
/*!
* \brief Finds the next bit set to one in the bitset
* \return Index of the next bit if exists or npos
* \brief Finds the next enabled in the bitset
*
* \param bit Index of the bit, the search begin with bit + 1
* \param bit Index of the last bit found, which will not be treated by this function
*
* \remark Produce a NazaraAssert if bit is greather than number of bits in bitset
* \return Index of the next enabled bit or npos if all the following bits are disabled
*
* \remark This function is typically used in for-loops to iterate on bits
*/
template<typename Block, class Allocator>
std::size_t Bitset<Block, Allocator>::FindNext(std::size_t bit) const
{
@@ -275,6 +327,76 @@ namespace Nz
return m_bitCount;
}
/*!
* \brief Read a byte sequence into a bitset
*
* This function extends the bitset with bits read from a byte sequence
*
* \param ptr A pointer to the start of the byte sequence
* \param bitCount Number of bits to read from the byte sequence
*
* \returns A pointer to the next byte to read along with the next bit index (useful when reading multiple times)
*
* \remark For technical reasons, ceil(bitCount / 8) bytes from the sequence will always be read (even with non-multiple-of-8 bitCount)
*
* \see AppendBits
* \see Read
*/
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::PointerSequence Bitset<Block, Allocator>::Read(const void* ptr, std::size_t bitCount)
{
return Read(PointerSequence(ptr, 0U), bitCount);
}
/*!
* \brief Read a byte sequence into a bitset
*
* This function extends the bitset with bits read from a pointer sequence (made of a pointer and a bit index)
*
* \param sequence A pointer sequence to the start of the byte sequence
* \param bitCount Number of bits to read from the byte sequence
*
* \returns A pointer to the next byte to read along with the next bit index (useful when reading multiple times)
*
* \remark For technical reasons, ceil(bitCount / 8) bytes from the sequence will always be read (even with non-multiple-of-8 bitCount)
*
* \see AppendBits
* \see Read
*/
template<typename Block, class Allocator>
typename Bitset<Block, Allocator>::PointerSequence Bitset<Block, Allocator>::Read(const PointerSequence& sequence, std::size_t bitCount)
{
NazaraAssert(sequence.first, "Invalid pointer sequence");
NazaraAssert(sequence.second < 8, "Invalid next bit index (must be < 8)");
std::size_t totalBitCount = sequence.second + bitCount;
const UInt8* u8Ptr = static_cast<const UInt8*>(sequence.first);
const UInt8* endPtr = u8Ptr + ((totalBitCount != 0) ? (totalBitCount - 1) / 8 : 0);
const UInt8* nextPtr = endPtr + ((totalBitCount % 8 != 0) ? 0 : 1);
// Read the first block apart to apply a mask on the first byte if necessary
if (sequence.second != 0)
{
UInt8 mask = ~((1U << sequence.second) - 1U);
std::size_t readCount = std::min(bitCount, 8 - sequence.second);
AppendBits(Block(*u8Ptr++ & mask) >> sequence.second, readCount);
bitCount -= readCount;
}
// And then read the remaining bytes
while (u8Ptr <= endPtr)
{
std::size_t bitToRead = std::min<std::size_t>(bitCount, 8);
AppendBits(*u8Ptr++, bitToRead);
bitCount -= bitToRead;
}
// Returns informations to continue reading
return PointerSequence(nextPtr, totalBitCount % 8);
}
/*!
* \brief Performs the "AND" operator between two bitsets
*
@@ -289,15 +411,17 @@ namespace Nz
{
std::pair<std::size_t, std::size_t> minmax = std::minmax(a.GetBlockCount(), b.GetBlockCount());
// We reinitialise our blocks with zero
m_blocks.clear();
m_blocks.resize(minmax.second, 0U);
m_blocks.resize(minmax.second);
m_bitCount = std::max(a.GetSize(), b.GetSize());
// In case of the "AND", we can stop with the smallest size (because x & 0 = 0)
for (std::size_t i = 0; i < minmax.first; ++i)
m_blocks[i] = a.GetBlock(i) & b.GetBlock(i);
// And then reset every other block to zero
for (std::size_t i = minmax.first; i < minmax.second; ++i)
m_blocks[i] = 0U;
ResetExtraBits();
}
@@ -458,6 +582,30 @@ namespace Nz
Set(bit, false);
}
/*!
* \brief Reverse the order of bits in a bitset
*
* Reverse the order of bits in the bitset (first bit swap with the last one, etc.)
*/
template<typename Block, class Allocator>
void Bitset<Block, Allocator>::Reverse()
{
if (m_bitCount == 0)
return;
std::size_t i = 0;
std::size_t j = m_bitCount - 1;
while (i < j)
{
bool bit1 = Test(i);
bool bit2 = Test(j);
Set(i++, bit2);
Set(j--, bit1);
}
}
/*!
* \brief Sets the bitset to val
*
@@ -535,27 +683,28 @@ namespace Nz
return;
}
auto div = std::lldiv(pos, bitsPerBlock);
if (div.rem != 0)
std::size_t blockShift = pos / bitsPerBlock;
std::size_t remainder = pos % bitsPerBlock;
if (remainder != 0)
{
std::size_t lastIndex = m_blocks.size() - 1;
std::size_t remaining = bitsPerBlock - div.rem;
std::size_t remaining = bitsPerBlock - remainder;
for (std::size_t i = lastIndex - div.quot; i > 0; --i)
m_blocks[i + div.quot] = (m_blocks[i] << div.rem) | (m_blocks[i - 1] >> remaining);
for (std::size_t i = lastIndex - blockShift; i > 0; --i)
m_blocks[i + blockShift] = (m_blocks[i] << remainder) | (m_blocks[i - 1] >> remaining);
m_blocks[div.quot] = m_blocks[0] << div.rem;
m_blocks[blockShift] = m_blocks[0] << remainder;
std::fill_n(m_blocks.begin(), div.quot, Block(0));
std::fill_n(m_blocks.begin(), blockShift, Block(0));
}
else
{
for (auto it = m_blocks.rbegin(); it != m_blocks.rend(); ++it)
{
if (static_cast<std::size_t>(std::distance(m_blocks.rbegin(), it) + div.quot) < m_blocks.size())
if (static_cast<std::size_t>(std::distance(m_blocks.rbegin(), it) + blockShift) < m_blocks.size())
{
auto shiftedIt = it;
std::advance(shiftedIt, div.quot);
std::advance(shiftedIt, blockShift);
*it = *shiftedIt;
}
@@ -588,27 +737,28 @@ namespace Nz
return;
}
auto div = std::lldiv(pos, bitsPerBlock);
if (div.rem != 0)
std::size_t blockShift = pos / bitsPerBlock;
std::size_t remainder = pos % bitsPerBlock;
if (remainder != 0)
{
std::size_t lastIndex = m_blocks.size() - 1;
std::size_t remaining = bitsPerBlock - div.rem;
std::size_t remaining = bitsPerBlock - remainder;
for (std::size_t i = div.quot; i < lastIndex; ++i)
m_blocks[i - div.quot] = (m_blocks[i] >> div.rem) | (m_blocks[i + 1] << remaining);
for (std::size_t i = blockShift; i < lastIndex; ++i)
m_blocks[i - blockShift] = (m_blocks[i] >> remainder) | (m_blocks[i + 1] << remaining);
m_blocks[lastIndex - div.quot] = m_blocks[lastIndex] >> div.rem;
m_blocks[lastIndex - blockShift] = m_blocks[lastIndex] >> remainder;
std::fill_n(m_blocks.begin() + (m_blocks.size() - div.quot), div.quot, Block(0));
std::fill_n(m_blocks.begin() + (m_blocks.size() - blockShift), blockShift, Block(0));
}
else
{
for (auto it = m_blocks.begin(); it != m_blocks.end(); ++it)
{
if (static_cast<std::size_t>(std::distance(m_blocks.begin(), it) + div.quot) < m_blocks.size())
if (static_cast<std::size_t>(std::distance(m_blocks.begin(), it) + blockShift) < m_blocks.size())
{
auto shiftedIt = it;
std::advance(shiftedIt, div.quot);
std::advance(shiftedIt, blockShift);
*it = *shiftedIt;
}
@@ -716,7 +866,7 @@ namespace Nz
{
static_assert(std::is_integral<T>() && std::is_unsigned<T>(), "T must be a unsigned integral type");
NazaraAssert(m_bitCount <= std::numeric_limits<T>::digits, "Bit count cannot be greater than T bit count");
NazaraAssert(m_bitCount <= BitCount<T>(), "Bit count cannot be greater than T bit count");
T value = 0;
for (std::size_t i = 0; i < m_blocks.size(); ++i)
@@ -989,13 +1139,41 @@ namespace Nz
return *this;
}
/*!
* \brief Builds a bitset from a byte sequence
*
* This function builds a bitset using a byte sequence by reading bitCount bits from it
*
* \param ptr A pointer to the start of the byte sequence
* \param bitCount Number of bits to read from the byte sequence
* \param sequence Optional data to pass to a next call to Read
*
* \return The constructed bitset
*
* \remark For technical reasons, ceil(bitCount / 8) bytes from the sequence will always be read (even with non-multiple-of-8 bitCount)
*
* \see AppendBits
* \see Read
*/
template<typename Block, class Allocator>
Bitset<Block, Allocator> Bitset<Block, Allocator>::FromPointer(const void* ptr, std::size_t bitCount, PointerSequence* sequence)
{
Bitset bitset;
if (sequence)
*sequence = bitset.Read(ptr, bitCount);
else
bitset.Read(ptr, bitCount);
return bitset;
}
/*!
* \brief Finds the position of the first bit set to true after the blockIndex
* \return The position of the bit
*
* \param blockIndex Index of the block
*/
template<typename Block, class Allocator>
std::size_t Bitset<Block, Allocator>::FindFirstFrom(std::size_t blockIndex) const
{
@@ -1124,7 +1302,7 @@ namespace Nz
template<typename Block, class Allocator>
bool Bitset<Block, Allocator>::Bit::Test() const
{
return m_block & m_mask;
return (m_block & m_mask) != 0;
}
/*!
@@ -1269,6 +1447,14 @@ namespace Nz
return *this;
}
template<typename Block, class Allocator>
std::ostream& operator<<(std::ostream& out, const Bitset<Block, Allocator>& bitset)
{
return out << bitset.ToString();
}
/*!
* \brief Compares two bitsets
* \return true if the two bitsets are the same

View File

@@ -88,7 +88,7 @@ namespace Nz
inline void ShrinkToFit();
inline void Swap(ByteArray& other);
inline String ToHex() const;
String ToHex() const;
inline String ToString() const;
// STL interface

View File

@@ -465,22 +465,6 @@ namespace Nz
m_array.swap(other.m_array);
}
/*!
* \brief Gives a string representation in base 16
* \return String in base 16
*/
inline String ByteArray::ToHex() const
{
std::size_t length = m_array.size() * 2;
String hexOutput(length, '\0');
for (std::size_t i = 0; i < m_array.size(); ++i)
std::sprintf(&hexOutput[i * 2], "%02x", m_array[i]);
return hexOutput;
}
/*!
* \brief Gives a string representation
* \return String where each byte is converted to char

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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
@@ -19,7 +19,7 @@ namespace Nz
{
public:
inline ByteStream(Stream* stream = nullptr);
ByteStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
ByteStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
ByteStream(void* ptr, Nz::UInt64 size);
ByteStream(const void* ptr, Nz::UInt64 size);
ByteStream(const ByteStream&) = delete;
@@ -36,7 +36,7 @@ namespace Nz
inline void SetDataEndianness(Endianness endiannes);
inline void SetStream(Stream* stream);
void SetStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
void SetStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
void SetStream(void* ptr, Nz::UInt64 size);
void SetStream(const void* ptr, Nz::UInt64 size);

View File

@@ -29,7 +29,7 @@ namespace Nz
bool Wait(Mutex* mutex, UInt32 timeout);
ConditionVariable& operator=(const ConditionVariable&) = delete;
inline ConditionVariable& operator=(ConditionVariable&& condition) noexcept;
ConditionVariable& operator=(ConditionVariable&& condition) noexcept;
private:
ConditionVariableImpl* m_impl;

View File

@@ -7,6 +7,8 @@
#ifndef NAZARA_ENUMS_CORE_HPP
#define NAZARA_ENUMS_CORE_HPP
#include <Nazara/Core/Flags.hpp>
namespace Nz
{
enum CoordSys
@@ -73,23 +75,31 @@ namespace Nz
HashType_Max = HashType_Whirlpool
};
enum OpenModeFlags
enum OpenMode
{
OpenMode_NotOpen = 0x00, // Use the current mod of opening
OpenMode_NotOpen, // Use the current mod of opening
OpenMode_Append = 0x01, // Disable writing on existing parts and put the cursor at the end
OpenMode_Lock = 0x02, // Disable modifying the file before it is open
OpenMode_MustExit = 0x04, // Fail if the file doesn't exists, even if opened in write mode
OpenMode_ReadOnly = 0x08, // Open in read only
OpenMode_Text = 0x10, // Open in text mod
OpenMode_Truncate = 0x20, // Create the file if it doesn't exist and empty it if it exists
OpenMode_WriteOnly = 0x40, // Open in write only, create the file if it doesn't exist
OpenMode_Append, // Disable writing on existing parts and put the cursor at the end
OpenMode_Lock, // Disable modifying the file before it is open
OpenMode_MustExist, // Fail if the file doesn't exists, even if opened in write mode
OpenMode_ReadOnly, // Open in read only
OpenMode_Text, // Open in text mod
OpenMode_Truncate, // Create the file if it doesn't exist and empty it if it exists
OpenMode_WriteOnly, // Open in write only, create the file if it doesn't exist
OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly, // Open in read and write
OpenMode_Max = OpenMode_WriteOnly * 2 - 1
OpenMode_Max = OpenMode_WriteOnly
};
template<>
struct EnableFlagsOperators<OpenMode>
{
static constexpr bool value = true;
};
using OpenModeFlags = Flags<OpenMode>;
constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly;
enum ParameterType
{
ParameterType_Boolean,
@@ -173,16 +183,24 @@ namespace Nz
SphereType_Max = SphereType_UV
};
enum StreamOptionFlags
enum StreamOption
{
StreamOption_None = 0,
StreamOption_None,
StreamOption_Sequential = 0x1,
StreamOption_Text = 0x2,
StreamOption_Sequential,
StreamOption_Text,
StreamOption_Max = StreamOption_Text * 2 - 1
StreamOption_Max = StreamOption_Text
};
template<>
struct EnableFlagsOperators<StreamOption>
{
static constexpr bool value = true;
};
using StreamOptionFlags = Flags<StreamOption>;
enum Ternary
{
Ternary_False,

View File

@@ -31,7 +31,7 @@ namespace Nz
public:
File();
File(const String& filePath);
File(const String& filePath, UInt32 openMode);
File(const String& filePath, OpenModeFlags openMode);
File(const File&) = delete;
File(File&& file) noexcept;
~File();
@@ -57,8 +57,8 @@ namespace Nz
bool IsOpen() const;
bool Open(unsigned int openMode = OpenMode_NotOpen);
bool Open(const String& filePath, unsigned int openMode = OpenMode_NotOpen);
bool Open(OpenModeFlags openMode = OpenMode_NotOpen);
bool Open(const String& filePath, OpenModeFlags openMode = OpenMode_NotOpen);
bool Rename(const String& newFilePath);

View File

@@ -0,0 +1,60 @@
// Copyright (C) 2016 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_FLAGS_HPP
#define NAZARA_FLAGS_HPP
#include <Nazara/Prerequesites.hpp>
#include <type_traits>
namespace Nz
{
template<typename E>
class Flags
{
static_assert(std::is_enum<E>::value, "Type must be an enumeration");
public:
constexpr Flags(UInt32 value);
constexpr Flags(E enumVal);
explicit constexpr operator bool() const;
explicit constexpr operator UInt32() const;
constexpr Flags operator~() const;
constexpr Flags operator&(Flags rhs) const;
constexpr Flags operator|(Flags rhs) const;
constexpr Flags operator^(Flags rhs) const;
constexpr bool operator==(Flags rhs) const;
constexpr bool operator!=(Flags rhs) const;
/*constexpr*/ Flags& operator|=(Flags rhs);
/*constexpr*/ Flags& operator&=(Flags rhs);
/*constexpr*/ Flags& operator^=(Flags rhs);
static constexpr UInt32 GetFlagValue(E enumValue);
private:
UInt32 m_value;
};
// From: https://www.justsoftwaresolutions.co.uk/cplusplus/using-enum-classes-as-bitfields.html
template<typename E>
struct EnableFlagsOperators
{
static constexpr bool value = false;
};
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs);
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs);
template<typename E> constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs);
}
#include <Nazara/Core/Flags.inl>
#endif // NAZARA_FLAGS_HPP

View File

@@ -0,0 +1,134 @@
// 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
#include <Nazara/Core/Flags.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
{
/*!
* \ingroup core
* \class Nz::Flags
* \brief Core class that represents a set of bits
*
* This class meets the requirements of Container, AllocatorAwareContainer, SequenceContainer
*/
template<typename E>
constexpr Flags<E>::Flags(UInt32 value) :
m_value(value)
{
}
template<typename E>
constexpr Flags<E>::Flags(E enumVal) :
Flags(GetFlagValue(enumVal))
{
}
template<typename E>
constexpr Flags<E>::operator bool() const
{
return m_value != 0;
}
template<typename E>
constexpr Flags<E>::operator UInt32() const
{
return m_value;
}
template<typename E>
constexpr Flags<E> Flags<E>::operator~() const
{
return Flags(~m_value);
}
template<typename E>
constexpr Flags<E> Flags<E>::operator&(Flags rhs) const
{
return Flags(m_value & rhs.m_value);
}
template<typename E>
constexpr Flags<E> Flags<E>::operator|(Flags rhs) const
{
return Flags(m_value | rhs.m_value);
}
template<typename E>
constexpr Flags<E> Flags<E>::operator^(Flags rhs) const
{
return Flags(m_value ^ rhs.m_value);
}
template<typename E>
constexpr bool Flags<E>::operator==(Flags rhs) const
{
return m_value == rhs.m_value;
}
template<typename E>
constexpr bool Flags<E>::operator!=(Flags rhs) const
{
return !operator==(rhs);
}
template<typename E>
/*constexpr*/ Flags<E>& Flags<E>::operator|=(Flags rhs)
{
m_value |= rhs.m_value;
return *this;
}
template<typename E>
/*constexpr*/ Flags<E>& Flags<E>::operator&=(Flags rhs)
{
m_value &= rhs.m_value;
return *this;
}
template<typename E>
/*constexpr*/ Flags<E>& Flags<E>::operator^=(Flags rhs)
{
m_value ^= rhs.m_value;
return *this;
}
template<typename E>
constexpr UInt32 Flags<E>::GetFlagValue(E enumValue)
{
return 1U << static_cast<UInt32>(enumValue);
}
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator~(E lhs)
{
return ~Flags<E>(lhs);
}
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator|(E lhs, E rhs)
{
return Flags<E>(lhs) | rhs;
}
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator&(E lhs, E rhs)
{
return Flags<E>(lhs) & rhs;
}
template<typename E>
constexpr std::enable_if_t<EnableFlagsOperators<E>::value, Flags<E>> operator^(E lhs, E rhs)
{
return Flags<E>(lhs) ^ rhs;
}
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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
@@ -18,7 +18,7 @@ namespace Nz
{
public:
inline MemoryStream();
inline MemoryStream(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
inline MemoryStream(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
MemoryStream(const MemoryStream&) = default;
MemoryStream(MemoryStream&&) = default;
~MemoryStream() = default;
@@ -32,7 +32,7 @@ namespace Nz
UInt64 GetCursorPos() const override;
UInt64 GetSize() const override;
void SetBuffer(ByteArray* byteArray, UInt32 openMode = OpenMode_ReadWrite);
void SetBuffer(ByteArray* byteArray, OpenModeFlags openMode = OpenMode_ReadWrite);
bool SetCursorPos(UInt64 offset) override;
MemoryStream& operator=(const MemoryStream&) = default;

View File

@@ -24,7 +24,7 @@ namespace Nz
* \param byteArray Bytes to stream
* \param openMode Reading/writing mode for the stream
*/
inline MemoryStream::MemoryStream(ByteArray* byteArray, UInt32 openMode) :
inline MemoryStream::MemoryStream(ByteArray* byteArray, OpenModeFlags openMode) :
MemoryStream()
{
SetBuffer(byteArray, openMode);

View File

@@ -60,10 +60,10 @@ namespace Nz
{
struct UserdataValue
{
UserdataValue(Destructor Destructor, void* value) :
UserdataValue(Destructor func, void* ud) :
counter(1),
destructor(Destructor),
ptr(value)
destructor(func),
ptr(ud)
{
}

View File

@@ -32,8 +32,8 @@ namespace Nz
virtual UInt64 GetCursorPos() const = 0;
virtual String GetDirectory() const;
virtual String GetPath() const;
inline UInt32 GetOpenMode() const;
inline UInt32 GetStreamOptions() const;
inline OpenModeFlags GetOpenMode() const;
inline StreamOptionFlags GetStreamOptions() const;
virtual UInt64 GetSize() const = 0;
@@ -55,14 +55,14 @@ namespace Nz
Stream& operator=(Stream&&) = default;
protected:
inline Stream(UInt32 streamOptions = StreamOption_None, UInt32 openMode = OpenMode_NotOpen);
inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags openMode = OpenMode_NotOpen);
virtual void FlushStream() = 0;
virtual std::size_t ReadBlock(void* buffer, std::size_t size) = 0;
virtual std::size_t WriteBlock(const void* buffer, std::size_t size) = 0;
UInt32 m_openMode;
UInt32 m_streamOptions;
OpenModeFlags m_openMode;
StreamOptionFlags m_streamOptions;
};
}

View File

@@ -15,7 +15,7 @@ namespace Nz
* \param openMode Reading/writing mode for the stream
*/
inline Stream::Stream(UInt32 streamOptions, UInt32 openMode) :
inline Stream::Stream(StreamOptionFlags streamOptions, OpenModeFlags openMode) :
m_openMode(openMode),
m_streamOptions(streamOptions)
{
@@ -53,7 +53,7 @@ namespace Nz
* \return Reading/writing mode for the stream
*/
inline UInt32 Stream::GetOpenMode() const
inline OpenModeFlags Stream::GetOpenMode() const
{
return m_openMode;
}
@@ -63,7 +63,7 @@ namespace Nz
* \return Options of the stream
*/
inline UInt32 Stream::GetStreamOptions() const
inline StreamOptionFlags Stream::GetStreamOptions() const
{
return m_streamOptions;
}
@@ -116,7 +116,7 @@ namespace Nz
* \param size Size meant to be read
*
* \remark Produces a NazaraAssert if stream is not readable
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
*/
inline std::size_t Stream::Read(void* buffer, std::size_t size)
@@ -134,7 +134,7 @@ namespace Nz
* \param size Size meant to be written
*
* \remark Produces a NazaraAssert if stream is not writable
* \remark If preallocated space of buffer is less than the size, the behaviour is undefined
* \remark If preallocated space of buffer is less than the size, the behavior is undefined
*/
inline std::size_t Stream::Write(const void* buffer, std::size_t size)

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 15 Sep 2016 at 00:43:26
// This file was automatically generated
/*
Nazara Engine - Graphics module
@@ -36,6 +36,7 @@
#include <Nazara/Graphics/Billboard.hpp>
#include <Nazara/Graphics/ColorBackground.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/DeferredBloomPass.hpp>
#include <Nazara/Graphics/DeferredDOFPass.hpp>
#include <Nazara/Graphics/DeferredFinalPass.hpp>
@@ -72,7 +73,6 @@
#include <Nazara/Graphics/ParticleRenderer.hpp>
#include <Nazara/Graphics/ParticleStruct.hpp>
#include <Nazara/Graphics/Renderable.hpp>
#include <Nazara/Graphics/MaterialPipeline.hpp>
#include <Nazara/Graphics/RenderTechniques.hpp>
#include <Nazara/Graphics/SceneData.hpp>
#include <Nazara/Graphics/SkeletalModel.hpp>

View File

@@ -0,0 +1,180 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CULLINGLIST_HPP
#define NAZARA_CULLINGLIST_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/Enums.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <vector>
namespace Nz
{
template<typename T>
class CullingList
{
public:
template<CullTest> class Entry;
class NoTestEntry;
class SphereEntry;
class VolumeEntry;
template<CullTest> friend class Entry;
friend NoTestEntry;
friend SphereEntry;
friend VolumeEntry;
using ResultContainer = std::vector<const T*>;
CullingList() = default;
CullingList(const CullingList& renderable) = delete;
CullingList(CullingList&& renderable) = delete;
~CullingList();
std::size_t Cull(const Frustumf& frustum, bool* forceInvalidation = nullptr);
NoTestEntry RegisterNoTest(const T* renderable);
SphereEntry RegisterSphereTest(const T* renderable);
VolumeEntry RegisterVolumeTest(const T* renderable);
CullingList& operator=(const CullingList& renderable) = delete;
CullingList& operator=(CullingList&& renderable) = delete;
// STL API
typename ResultContainer::iterator begin();
typename ResultContainer::const_iterator begin() const;
typename ResultContainer::const_iterator cbegin() const;
typename ResultContainer::const_iterator cend() const;
typename ResultContainer::const_reverse_iterator crbegin() const;
typename ResultContainer::const_reverse_iterator crend() const;
bool empty() const;
typename ResultContainer::iterator end();
typename ResultContainer::const_iterator end() const;
typename ResultContainer::reverse_iterator rbegin();
typename ResultContainer::const_reverse_iterator rbegin() const;
typename ResultContainer::reverse_iterator rend();
typename ResultContainer::const_reverse_iterator rend() const;
typename ResultContainer::size_type size() const;
NazaraSignal(OnCullingListRelease, CullingList* /*cullingList*/);
private:
inline void NotifyForceInvalidation(CullTest type, std::size_t index);
inline void NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr);
inline void NotifyRelease(CullTest type, std::size_t index);
inline void NotifySphereUpdate(std::size_t index, const Spheref& sphere);
inline void NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume);
struct NoTestVisibilityEntry
{
NoTestEntry* entry;
const T* renderable;
bool forceInvalidation;
};
struct SphereVisibilityEntry
{
Spheref sphere;
SphereEntry* entry;
const T* renderable;
bool forceInvalidation;
};
struct VolumeVisibilityEntry
{
BoundingVolumef volume;
VolumeEntry* entry;
const T* renderable;
bool forceInvalidation;
};
std::vector<NoTestVisibilityEntry> m_noTestList;
std::vector<SphereVisibilityEntry> m_sphereTestList;
std::vector<VolumeVisibilityEntry> m_volumeTestList;
ResultContainer m_results;
};
template<typename T>
template<CullTest Type>
class CullingList<T>::Entry
{
public:
Entry();
Entry(const Entry&) = delete;
Entry(Entry&& entry);
~Entry();
void ForceInvalidation();
CullingList* GetParent() const;
void UpdateIndex(std::size_t index);
Entry& operator=(const Entry&) = delete;
Entry& operator=(Entry&& entry);
protected:
Entry(CullingList* parent, std::size_t index);
std::size_t m_index;
CullingList* m_parent;
};
template<typename T>
class CullingList<T>::NoTestEntry : public CullingList::template Entry<CullTest::NoTest>
{
friend CullingList;
public:
NoTestEntry();
private:
NoTestEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::SphereEntry : public CullingList::template Entry<CullTest::Sphere>
{
friend CullingList;
public:
SphereEntry();
void UpdateSphere(const Spheref& sphere);
private:
SphereEntry(CullingList* parent, std::size_t index);
};
template<typename T>
class CullingList<T>::VolumeEntry : public CullingList::template Entry<CullTest::Volume>
{
friend CullingList;
public:
VolumeEntry();
void UpdateVolume(const BoundingVolumef& sphere);
private:
VolumeEntry(CullingList* parent, std::size_t index);
};
}
#include <Nazara/Graphics/CullingList.inl>
#endif // NAZARA_CULLINGLIST_HPP

View File

@@ -0,0 +1,431 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
template<typename T>
CullingList<T>::~CullingList()
{
OnCullingListRelease(this);
}
template<typename T>
std::size_t CullingList<T>::Cull(const Frustumf& frustum, bool* forceInvalidation)
{
m_results.clear();
bool forcedInvalidation = false;
std::size_t visibleHash = 0U;
for (NoTestVisibilityEntry& entry : m_noTestList)
{
m_results.push_back(entry.renderable);
Nz::HashCombine(visibleHash, entry.renderable);
if (entry.forceInvalidation)
{
forcedInvalidation = true;
entry.forceInvalidation = false;
}
}
for (SphereVisibilityEntry& entry : m_sphereTestList)
{
if (frustum.Contains(entry.sphere))
{
m_results.push_back(entry.renderable);
Nz::HashCombine(visibleHash, entry.renderable);
if (entry.forceInvalidation)
{
forcedInvalidation = true;
entry.forceInvalidation = false;
}
}
}
for (VolumeVisibilityEntry& entry : m_volumeTestList)
{
if (frustum.Contains(entry.volume))
{
m_results.push_back(entry.renderable);
Nz::HashCombine(visibleHash, entry.renderable);
if (entry.forceInvalidation)
{
forcedInvalidation = true;
entry.forceInvalidation = false;
}
}
}
if (forceInvalidation)
*forceInvalidation = forcedInvalidation;
return visibleHash;
}
template<typename T>
typename CullingList<T>::NoTestEntry CullingList<T>::RegisterNoTest(const T* renderable)
{
NoTestEntry entry(this, m_noTestList.size());
m_noTestList.emplace_back(NoTestVisibilityEntry{&entry, renderable, false}); //< Address of entry will be updated when moving
return entry;
}
template<typename T>
typename CullingList<T>::SphereEntry CullingList<T>::RegisterSphereTest(const T* renderable)
{
SphereEntry entry(this, m_sphereTestList.size());
m_sphereTestList.emplace_back(SphereVisibilityEntry{Nz::Spheref(), &entry, renderable, false}); //< Address of entry will be updated when moving
return entry;
}
template<typename T>
typename CullingList<T>::VolumeEntry CullingList<T>::RegisterVolumeTest(const T* renderable)
{
VolumeEntry entry(this, m_volumeTestList.size());
m_volumeTestList.emplace_back(VolumeVisibilityEntry{Nz::BoundingVolumef(), &entry, renderable, false}); //< Address of entry will be updated when moving
return entry;
}
// Interface STD
template<typename T>
typename CullingList<T>::ResultContainer::iterator CullingList<T>::begin()
{
return m_results.begin();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::begin() const
{
return m_results.begin();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::cbegin() const
{
return m_results.cbegin();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::cend() const
{
return m_results.cend();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::crbegin() const
{
return m_results.crbegin();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::crend() const
{
return m_results.crend();
}
template<typename T>
bool CullingList<T>::empty() const
{
return m_results.empty();
}
template<typename T>
typename CullingList<T>::ResultContainer::iterator CullingList<T>::end()
{
return m_results.end();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_iterator CullingList<T>::end() const
{
return m_results.end();
}
template<typename T>
typename CullingList<T>::ResultContainer::reverse_iterator CullingList<T>::rbegin()
{
return m_results.rbegin();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::rbegin() const
{
return m_results.rbegin();
}
template<typename T>
typename CullingList<T>::ResultContainer::reverse_iterator CullingList<T>::rend()
{
return m_results.rend();
}
template<typename T>
typename CullingList<T>::ResultContainer::const_reverse_iterator CullingList<T>::rend() const
{
return m_results.rend();
}
template<typename T>
typename CullingList<T>::ResultContainer::size_type CullingList<T>::size() const
{
return m_results.size();
}
template<typename T>
void CullingList<T>::NotifyForceInvalidation(CullTest type, std::size_t index)
{
switch (type)
{
case CullTest::NoTest:
{
m_noTestList[index].forceInvalidation = true;
break;
}
case CullTest::Sphere:
{
m_sphereTestList[index].forceInvalidation = true;
break;
}
case CullTest::Volume:
{
m_volumeTestList[index].forceInvalidation = true;
break;
}
default:
NazaraInternalError("Unhandled culltype");
break;
}
}
template<typename T>
void CullingList<T>::NotifyMovement(CullTest type, std::size_t index, void* oldPtr, void* newPtr)
{
switch (type)
{
case CullTest::NoTest:
{
NoTestVisibilityEntry& entry = m_noTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid entry");
entry.entry = static_cast<NoTestEntry*>(newPtr);
break;
}
case CullTest::Sphere:
{
SphereVisibilityEntry& entry = m_sphereTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid sphere entry");
entry.entry = static_cast<SphereEntry*>(newPtr);
break;
}
case CullTest::Volume:
{
VolumeVisibilityEntry& entry = m_volumeTestList[index];
NazaraAssert(entry.entry == oldPtr, "Invalid volume entry");
entry.entry = static_cast<VolumeEntry*>(newPtr);
break;
}
default:
NazaraInternalError("Unhandled culltype");
break;
}
}
template<typename T>
void CullingList<T>::NotifyRelease(CullTest type, std::size_t index)
{
switch (type)
{
case CullTest::NoTest:
{
m_noTestList[index] = std::move(m_noTestList.back());
m_noTestList[index].entry->UpdateIndex(index);
m_noTestList.pop_back();
break;
}
case CullTest::Sphere:
{
m_sphereTestList[index] = std::move(m_sphereTestList.back());
m_sphereTestList[index].entry->UpdateIndex(index);
m_sphereTestList.pop_back();
break;
}
case CullTest::Volume:
{
m_volumeTestList[index] = std::move(m_volumeTestList.back());
m_volumeTestList[index].entry->UpdateIndex(index);
m_volumeTestList.pop_back();
break;
}
default:
NazaraInternalError("Unhandled culltype");
break;
}
}
template<typename T>
void CullingList<T>::NotifySphereUpdate(std::size_t index, const Spheref& sphere)
{
m_sphereTestList[index].sphere = sphere;
}
template<typename T>
void CullingList<T>::NotifyVolumeUpdate(std::size_t index, const BoundingVolumef& boundingVolume)
{
m_volumeTestList[index].volume = boundingVolume;
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::Entry() :
m_parent(nullptr)
{
}
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::Entry(CullingList* parent, std::size_t index) :
m_index(index),
m_parent(parent)
{
}
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::Entry(Entry&& entry) :
m_index(entry.m_index),
m_parent(entry.m_parent)
{
if (m_parent)
m_parent->NotifyMovement(Type, m_index, &entry, this);
entry.m_parent = nullptr;
}
template<typename T>
template<CullTest Type>
CullingList<T>::Entry<Type>::~Entry()
{
if (m_parent)
m_parent->NotifyRelease(Type, m_index);
}
template<typename T>
template<CullTest Type>
void CullingList<T>::Entry<Type>::ForceInvalidation()
{
m_parent->NotifyForceInvalidation(Type, m_index);
}
template<typename T>
template<CullTest Type>
CullingList<T>* CullingList<T>::Entry<Type>::GetParent() const
{
return m_parent;
}
template<typename T>
template<CullTest Type>
void CullingList<T>::Entry<Type>::UpdateIndex(std::size_t index)
{
m_index = index;
}
template<typename T>
template<CullTest Type>
#ifdef NAZARA_COMPILER_MSVC
// MSVC bug
typename CullingList<T>::Entry<Type>& CullingList<T>::Entry<Type>::operator=(Entry&& entry)
#else
typename CullingList<T>::template Entry<Type>& CullingList<T>::Entry<Type>::operator=(Entry&& entry)
#endif
{
m_index = entry.m_index;
m_parent = entry.m_parent;
if (m_parent)
m_parent->NotifyMovement(Type, m_index, &entry, this);
entry.m_parent = nullptr;
return *this;
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::NoTestEntry::NoTestEntry() :
Entry<CullTest::NoTest>()
{
}
template<typename T>
CullingList<T>::NoTestEntry::NoTestEntry(CullingList* parent, std::size_t index) :
Entry<CullTest::NoTest>(parent, index)
{
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::SphereEntry::SphereEntry() :
Entry<CullTest::Sphere>()
{
}
template<typename T>
CullingList<T>::SphereEntry::SphereEntry(CullingList* parent, std::size_t index) :
Entry<CullTest::Sphere>(parent, index)
{
}
template<typename T>
void CullingList<T>::SphereEntry::UpdateSphere(const Spheref& sphere)
{
this->m_parent->NotifySphereUpdate(this->m_index, sphere);
}
//////////////////////////////////////////////////////////////////////////
template<typename T>
CullingList<T>::VolumeEntry::VolumeEntry() :
Entry<CullTest::Volume>()
{
}
template<typename T>
CullingList<T>::VolumeEntry::VolumeEntry(CullingList* parent, std::size_t index) :
Entry<CullTest::Volume>(parent, index)
{
}
template<typename T>
void CullingList<T>::VolumeEntry::UpdateVolume(const BoundingVolumef& volume)
{
this->m_parent->NotifyVolumeUpdate(this->m_index, volume);
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -19,6 +19,13 @@ namespace Nz
BackgroundType_Max = BackgroundType_User
};
enum class CullTest
{
NoTest,
Sphere,
Volume
};
enum ProjectionType
{
ProjectionType_Orthogonal,

View File

@@ -87,7 +87,7 @@ namespace Nz
struct SpriteChain_XYZ_Color_UV
{
const VertexStruct_XYZ_Color_UV* vertices;
unsigned int spriteCount;
std::size_t spriteCount;
};
struct BatchedSpriteEntry
@@ -160,7 +160,7 @@ namespace Nz
const Material* material;
};
typedef std::vector<unsigned int> TransparentModelContainer;
typedef std::vector<std::size_t> TransparentModelContainer;
struct Layer
{

View File

@@ -13,6 +13,7 @@
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/CullingList.hpp>
#include <Nazara/Math/BoundingVolume.hpp>
#include <Nazara/Math/Frustum.hpp>
#include <Nazara/Math/Matrix4.hpp>
@@ -31,15 +32,17 @@ namespace Nz
public:
struct InstanceData;
InstancedRenderable() = default;
inline InstancedRenderable();
inline InstancedRenderable(const InstancedRenderable& renderable);
InstancedRenderable(InstancedRenderable&& renderable) = delete;
virtual ~InstancedRenderable();
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
inline void EnsureBoundingVolumeUpdated() const;
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const = 0;
virtual bool Cull(const Frustumf& frustum, const InstanceData& instanceData) const;
virtual const BoundingVolumef& GetBoundingVolume() const;
virtual void InvalidateData(InstanceData* instanceData, UInt32 flags) const;
virtual void UpdateBoundingVolume(InstanceData* instanceData) const;
@@ -49,6 +52,7 @@ namespace Nz
InstancedRenderable& operator=(InstancedRenderable&& renderable) = delete;
// Signals:
NazaraSignal(OnInstancedRenderableInvalidateBoundingVolume, const InstancedRenderable* /*instancedRenderable*/);
NazaraSignal(OnInstancedRenderableInvalidateData, const InstancedRenderable* /*instancedRenderable*/, UInt32 /*flags*/);
NazaraSignal(OnInstancedRenderableRelease, const InstancedRenderable* /*instancedRenderable*/);
@@ -83,14 +87,16 @@ namespace Nz
};
protected:
virtual void MakeBoundingVolume() const = 0;
void InvalidateBoundingVolume();
inline void InvalidateBoundingVolume();
inline void InvalidateInstanceData(UInt32 flags);
inline void UpdateBoundingVolume() const;
virtual void MakeBoundingVolume() const = 0;
mutable BoundingVolumef m_boundingVolume;
private:
inline void UpdateBoundingVolume() const;
mutable bool m_boundingVolumeUpdated;
static InstancedRenderableLibrary::LibraryMap s_library;

View File

@@ -4,12 +4,19 @@
namespace Nz
{
/*!
* \brief Constructs a InstancedRenderable object by default
*/
inline InstancedRenderable::InstancedRenderable() :
m_boundingVolumeUpdated(false)
{
}
/*!
* \brief Constructs a InstancedRenderable object by assignation
*
* \param renderable InstancedRenderable to copy into this
*/
inline InstancedRenderable::InstancedRenderable(const InstancedRenderable& renderable) :
RefCounted(),
m_boundingVolume(renderable.m_boundingVolume),
@@ -34,6 +41,8 @@ namespace Nz
inline void InstancedRenderable::InvalidateBoundingVolume()
{
m_boundingVolumeUpdated = false;
OnInstancedRenderableInvalidateBoundingVolume(this);
}
/*!
@@ -69,6 +78,7 @@ namespace Nz
inline void InstancedRenderable::UpdateBoundingVolume() const
{
MakeBoundingVolume();
m_boundingVolumeUpdated = true;
}
}

View File

@@ -36,10 +36,10 @@ namespace Nz
~ParticleDeclaration();
void DisableComponent(ParticleComponent component);
void EnableComponent(ParticleComponent component, ComponentType type, unsigned int offset);
void EnableComponent(ParticleComponent component, ComponentType type, std::size_t offset);
void GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, unsigned int* offset) const;
unsigned int GetStride() const;
void GetComponent(ParticleComponent component, bool* enabled, ComponentType* type, std::size_t* offset) const;
std::size_t GetStride() const;
void SetStride(unsigned int stride);
@@ -60,7 +60,7 @@ namespace Nz
{
ComponentType type;
bool enabled = false;
unsigned int offset;
std::size_t offset;
/*
** -Lynix:
@@ -71,7 +71,7 @@ namespace Nz
};
std::array<Component, ParticleComponent_Max + 1> m_components;
unsigned int m_stride;
std::size_t m_stride;
static std::array<ParticleDeclaration, ParticleLayout_Max + 1> s_declarations;
static ParticleDeclarationLibrary::LibraryMap s_library;

View File

@@ -28,12 +28,12 @@ namespace Nz
void EnableLagCompensation(bool enable);
unsigned int GetEmissionCount() const;
std::size_t GetEmissionCount() const;
float GetEmissionRate() const;
bool IsLagCompensationEnabled() const;
void SetEmissionCount(unsigned int count);
void SetEmissionCount(std::size_t count);
void SetEmissionRate(float rate);
ParticleEmitter& operator=(const ParticleEmitter& emitter) = default;
@@ -49,7 +49,7 @@ namespace Nz
bool m_lagCompensationEnabled;
mutable float m_emissionAccumulator;
float m_emissionRate;
unsigned int m_emissionCount;
std::size_t m_emissionCount;
};
}

View File

@@ -44,12 +44,14 @@ namespace Nz
void* GenerateParticle();
void* GenerateParticles(unsigned int count);
inline void* GetBuffer();
inline const void* GetBuffer() const;
const ParticleDeclarationConstRef& GetDeclaration() const;
unsigned int GetMaxParticleCount() const;
unsigned int GetParticleCount() const;
unsigned int GetParticleSize() const;
std::size_t GetMaxParticleCount() const;
std::size_t GetParticleCount() const;
std::size_t GetParticleSize() const;
void KillParticle(unsigned int index);
void KillParticle(std::size_t index);
void KillParticles();
void RemoveController(ParticleController* controller);
@@ -81,6 +83,9 @@ namespace Nz
};
std::set<unsigned int, std::greater<unsigned int>> m_dyingParticles;
std::size_t m_maxParticleCount;
std::size_t m_particleCount;
std::size_t m_particleSize;
mutable std::vector<UInt8> m_buffer;
std::vector<ParticleControllerRef> m_controllers;
std::vector<EmitterEntry> m_emitters;
@@ -88,10 +93,9 @@ namespace Nz
ParticleDeclarationConstRef m_declaration;
ParticleRendererRef m_renderer;
bool m_processing;
unsigned int m_maxParticleCount;
unsigned int m_particleCount;
unsigned int m_particleSize;
};
}
#include <Nazara/Graphics/ParticleGroup.inl>
#endif // NAZARA_PARTICLEGROUP_HPP

View File

@@ -0,0 +1,40 @@
// Copyright (C) 2016 Jérôme Leclercq
// This file is part of the "Nazara Engine - Graphics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Graphics/ParticleGroup.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Graphics/Debug.hpp>
namespace Nz
{
/*!
* \brief Gets a raw pointer to the particle buffer
*
* This can be useful when working directly with a struct, or needing to iterate over all particles.
*
* \return Pointer to the buffer
*
* \see GetParticleCount
*/
inline void* ParticleGroup::GetBuffer()
{
return m_buffer.data();
}
/*!
* \brief Gets a raw pointer to the particle buffer
*
* This can be useful when working directly with a struct, or needing to iterate over all particles.
*
* \return Pointer to the buffer
*
* \see GetParticleCount
*/
inline const void* ParticleGroup::GetBuffer() const
{
return m_buffer.data();
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -22,6 +22,7 @@ namespace Nz
template<typename T> SparsePtr<T> GetComponentPtr(ParticleComponent component);
template<typename T> SparsePtr<const T> GetComponentPtr(ParticleComponent component) const;
inline void* GetPointer();
private:
const ParticleDeclaration* m_declaration;

View File

@@ -23,7 +23,7 @@ namespace Nz
// Then the component that are interesting
bool enabled;
ComponentType type;
unsigned int offset;
std::size_t offset;
m_declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled)
@@ -54,7 +54,7 @@ namespace Nz
// Then the component that are interesting
bool enabled;
ComponentType type;
unsigned int offset;
std::size_t offset;
m_declaration->GetComponent(component, &enabled, &type, &offset);
if (enabled)
@@ -68,6 +68,18 @@ namespace Nz
return SparsePtr<const T>();
}
}
/*!
* \brief Gets a raw pointer to the particle buffer
*
* This can be useful when working directly with a struct
*
* \return Pointer to the buffer
*/
inline void* ParticleMapper::GetPointer()
{
return m_ptr;
}
}
#include <Nazara/Graphics/DebugOff.hpp>

View File

@@ -21,16 +21,16 @@ namespace Nz
Vector3f normal;
Vector3f position;
Vector3f velocity;
UInt32 life;
float life;
float rotation;
};
struct ParticleStruct_Model
{
Quaternionf rotation;
Vector3f position;
Vector3f velocity;
UInt32 life;
Quaternionf rotation;
float life;
};
struct ParticleStruct_Sprite
@@ -38,7 +38,7 @@ namespace Nz
Color color;
Vector3f position;
Vector3f velocity;
UInt32 life;
float life;
float rotation;
};
}

View File

@@ -29,7 +29,7 @@ namespace Nz
static AbstractRenderTechnique* GetByName(const String& name, int* techniqueRanking = nullptr);
static AbstractRenderTechnique* GetByRanking(int maxRanking, int* techniqueRanking = nullptr);
static unsigned int GetCount();
static std::size_t GetCount();
static void Register(const String& name, int ranking, RenderTechniqueFactory factory);

View File

@@ -25,7 +25,9 @@ namespace Nz
virtual ~Renderable();
virtual void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix) const = 0;
virtual bool Cull(const Frustumf& frustum, const Matrix4f& transformMatrix) const;
inline void EnsureBoundingVolumeUpdated() const;
virtual const BoundingVolumef& GetBoundingVolume() const;
virtual void UpdateBoundingVolume(const Matrix4f& transformMatrix);
@@ -36,11 +38,12 @@ namespace Nz
protected:
virtual void MakeBoundingVolume() const = 0;
inline void InvalidateBoundingVolume();
inline void UpdateBoundingVolume() const;
mutable BoundingVolumef m_boundingVolume;
private:
inline void UpdateBoundingVolume() const;
mutable bool m_boundingVolumeUpdated;
};
}

View File

@@ -47,9 +47,11 @@ namespace Nz
inline void SetCornerColor(RectCorner corner, const Color& color);
inline void SetDefaultMaterial();
inline void SetMaterial(MaterialRef material, bool resizeSprite = true);
bool SetMaterial(String materialName, bool resizeSprite = true);
inline void SetOrigin(const Vector3f& origin);
inline void SetSize(const Vector2f& size);
inline void SetSize(float sizeX, float sizeY);
bool SetTexture(String textureName, bool resizeSprite = true);
inline void SetTexture(TextureRef texture, bool resizeSprite = true);
inline void SetTextureCoords(const Rectf& coords);
inline void SetTextureRect(const Rectui& rect);

View File

@@ -184,12 +184,11 @@ namespace Nz
}
/*!
* \brief Sets the material of the sprite
* \brief Changes the material of the sprite
*
* \param material Material for the sprite
* \param resizeSprite Should sprite be resized to the material size (diffuse map)
* \param resizeSprite Should the sprite be resized to the texture size?
*/
inline void Sprite::SetMaterial(MaterialRef material, bool resizeSprite)
{
m_material = std::move(material);
@@ -249,16 +248,19 @@ namespace Nz
/*!
* \brief Sets the texture of the sprite
*
* Assign a texture to the sprite material
*
* \param texture Texture for the sprite
* \param resizeSprite Should sprite be resized to the texture size
* \param resizeSprite Should the sprite be resized to the texture size?
*
* \remark The sprite material gets copied to prevent accidentally changing other drawable materials
*/
inline void Sprite::SetTexture(TextureRef texture, bool resizeSprite)
{
if (!m_material)
SetDefaultMaterial();
else if (m_material->GetReferenceCount() > 1)
m_material = Material::New(*m_material); // Copie
m_material = Material::New(*m_material); // Copy the material
if (resizeSprite && texture && texture->IsValid())
SetSize(Vector2f(Vector2ui(texture->GetSize())));

View File

@@ -149,6 +149,7 @@ namespace Nz
{
m_scale = scale;
InvalidateBoundingVolume();
InvalidateVertices();
}

View File

@@ -29,7 +29,7 @@ namespace Nz
m_isometricModeEnabled(false)
{
NazaraAssert(m_tiles.size() != 0U, "Invalid map size");
NazaraAssert(m_tileSize.x != 0U && m_tileSize.y != 0U, "Invalid tile size");
NazaraAssert(m_tileSize.x > 0 && m_tileSize.y > 0, "Invalid tile size");
NazaraAssert(m_layers.size() != 0U, "Invalid material count");
for (Layer& layer : m_layers)
@@ -175,7 +175,7 @@ namespace Nz
* \param color The multiplicative color applied to the tile
* \param materialIndex The material which will be used for rendering this tile
*
* \remark The material at [materialIndex] must have a valid diffuse map before using this function,
* \remark The material at [materialIndex] must have a valid diffuse map before using this function,
* as the size of the material diffuse map is used to compute normalized texture coordinates before returning.
*
* \see EnableTiles
@@ -253,7 +253,7 @@ namespace Nz
Rectf unnormalizedCoords(invWidth * rect.x, invHeight * rect.y, invWidth * rect.width, invHeight * rect.height);
EnableTiles(unnormalizedCoords, color, materialIndex);
}
/*!
* \brief Enable and sets tileCount tiles at positions contained at tilesPos location, enabling rendering at those locations
*
@@ -434,14 +434,14 @@ namespace Nz
*
* \param TileMap The other TileMap
*/
inline TileMap& TileMap::operator=(const TileMap& TileMap)
inline TileMap& TileMap::operator=(const TileMap& tileMap)
{
InstancedRenderable::operator=(TileMap);
InstancedRenderable::operator=(tileMap);
m_layers = TileMap.m_layers;
m_mapSize = TileMap.m_mapSize;
m_tiles = TileMap.m_tiles;
m_tileSize = TileMap.m_tileSize;
m_layers = tileMap.m_layers;
m_mapSize = tileMap.m_mapSize;
m_tiles = tileMap.m_tiles;
m_tileSize = tileMap.m_tileSize;
// We do not copy final vertices because it's highly probable that our parameters are modified and they must be regenerated
InvalidateBoundingVolume();

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 24 Jun 2015 at 13:55:50
// This file was automatically generated
/*
Nazara Engine - Lua scripting module

View File

@@ -129,7 +129,7 @@ namespace Nz
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArgs(lua);
handler.ProcessArguments(lua);
return handler.Invoke(lua, object, func);
});
@@ -143,7 +143,7 @@ namespace Nz
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArgs(lua);
handler.ProcessArguments(lua);
return handler.Invoke(lua, object, func);
});
@@ -157,7 +157,7 @@ namespace Nz
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArgs(lua);
handler.ProcessArguments(lua);
return handler.Invoke(lua, object, func);
});
@@ -171,7 +171,7 @@ namespace Nz
BindMethod(name, [func, handler] (LuaInstance& lua, T& object, std::size_t /*argumentCount*/) -> int
{
handler.ProcessArgs(lua);
handler.ProcessArguments(lua);
return handler.Invoke(lua, object, func);
});
@@ -203,7 +203,7 @@ namespace Nz
BindStaticMethod(name, [func, handler] (LuaInstance& lua) -> int
{
handler.ProcessArgs(lua);
handler.ProcessArguments(lua);
return handler.Invoke(lua, func);
});
@@ -335,7 +335,7 @@ namespace Nz
NazaraWarning("Class \"" + m_info->name + "\" already registred in this instance");
{
SetupFinalizer(lua);
if (m_info->getter || !m_info->parentGetters.empty())
SetupGetter(lua, GetterProxy);
else

View File

@@ -4,6 +4,7 @@
#include <Nazara/Lua/LuaInstance.hpp>
#include <Nazara/Core/Algorithm.hpp>
#include <Nazara/Core/Flags.hpp>
#include <Nazara/Core/MemoryHelper.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <limits>
@@ -59,7 +60,7 @@ namespace Nz
m_memoryUsage = instance.m_memoryUsage;
m_state = instance.m_state;
m_timeLimit = instance.m_timeLimit;
instance.m_state = nullptr;
return *this;
@@ -99,19 +100,50 @@ namespace Nz
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), TypeTag<UnderlyingT>());
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
return LuaImplQueryArg(instance, index, reinterpret_cast<UnderlyingT*>(arg), static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
UnderlyingT pot2Val;
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, TypeTag<UnderlyingT>());
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
return ret;
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, T defValue, TypeTag<T>)
{
using UnderlyingT = std::underlying_type_t<T>;
UnderlyingT pot2Val;
unsigned int ret = LuaImplQueryArg(instance, index, &pot2Val, 1U << static_cast<UnderlyingT>(defValue), TypeTag<UnderlyingT>());
*arg = static_cast<T>(IntegralLog2Pot(pot2Val));
return ret;
}
template<typename E>
unsigned int LuaImplQueryArg(const LuaInstance& instance, int index, Flags<E>* arg, TypeTag<Flags<E>>)
{
*arg = Flags<E>(instance.CheckBoundInteger<UInt32>(index));
return 1;
}
template<typename T>
std::enable_if_t<std::is_floating_point<T>::value, unsigned int> LuaImplQueryArg(const LuaInstance& instance, int index, T* arg, TypeTag<T>)
{
@@ -184,12 +216,26 @@ namespace Nz
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
std::enable_if_t<std::is_enum<T>::value && !EnableFlagsOperators<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
using EnumT = typename std::underlying_type<T>::type;
return LuaImplReplyVal(instance, static_cast<EnumT>(val), TypeTag<EnumT>());
}
template<typename T>
std::enable_if_t<std::is_enum<T>::value && EnableFlagsOperators<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
Flags<T> flags(val);
return LuaImplReplyVal(instance, flags, TypeTag<decltype(flags)>());
}
template<typename E>
int LuaImplReplyVal(const LuaInstance& instance, Flags<E> val, TypeTag<Flags<E>>)
{
instance.PushInteger(UInt32(val));
return 1;
}
template<typename T>
std::enable_if_t<std::is_integral<T>::value, int> LuaImplReplyVal(const LuaInstance& instance, T val, TypeTag<T>)
{
@@ -320,7 +366,7 @@ namespace Nz
{
}
void ProcessArgs(const LuaInstance& instance) const
void ProcessArguments(const LuaInstance& instance) const
{
m_index = 1;
ProcessArgs<0, Args...>(instance);
@@ -391,7 +437,7 @@ namespace Nz
{
}
void ProcessArgs(const LuaInstance& instance) const
void ProcessArguments(const LuaInstance& instance) const
{
m_index = 2; //< 1 being the instance
ProcessArgs<0, Args...>(instance);
@@ -714,7 +760,7 @@ namespace Nz
PushFunction([func, handler] (LuaInstance& lua) -> int
{
handler.ProcessArgs(lua);
handler.ProcessArguments(lua);
return handler.Invoke(lua, func);
});

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 24 Jun 2015 at 13:55:50
// This file was automatically generated
/*
Nazara Engine - Mathematics module

View File

@@ -37,7 +37,7 @@ namespace Nz
{
template<typename T> /*constexpr*/ T Approach(T value, T objective, T increment);
template<typename T> constexpr T Clamp(T value, T min, T max);
template<typename T> /*constexpr*/ T CountBits(T value);
template<typename T> /*constexpr*/ std::size_t CountBits(T value);
template<typename T> constexpr T FromDegrees(T degrees);
template<typename T> constexpr T FromRadians(T radians);
template<typename T> constexpr T DegreeToRadian(T degrees);

View File

@@ -147,10 +147,10 @@ namespace Nz
template<typename T>
//TODO: Mark as constexpr when supported by all major compilers
/*constexpr*/ inline T CountBits(T value)
/*constexpr*/ inline std::size_t CountBits(T value)
{
// https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
unsigned int count = 0;
std::size_t count = 0;
while (value)
{
value &= value - 1;

View File

@@ -17,11 +17,11 @@ namespace Nz
{
/*!
* \ingroup math
* \ingroup math
* \class Nz::EulerAngles
* \brief Math class that represents an Euler angle. Those describe a rotation transformation by rotating an object on its various axes in specified amounts per axis, and a specified axis order
*
* \remark Rotation are "left-handed", it means that you take your left hand, put your thumb finger in the direction you want and you other fingers represent the way of rotating
* \remark Rotation are "right-handed", it means that you take your right hand, put your thumb finger in the direction you want and you other fingers represent the way of rotating
*/
/*!
@@ -197,6 +197,7 @@ namespace Nz
template<typename T>
Quaternion<T> EulerAngles<T>::ToQuaternion() const
{
// XYZ
T c1 = std::cos(ToRadians(yaw) / F(2.0));
T c2 = std::cos(ToRadians(roll) / F(2.0));
T c3 = std::cos(ToRadians(pitch) / F(2.0));

View File

@@ -792,7 +792,7 @@ namespace Nz
template<typename T>
bool Matrix4<T>::IsAffine() const
{
return m14 == F(0.0) && m24 == F(0.0) && m34 == F(0.0) && m44 == F(1.0);
return NumberEquals(m14, F(0.0)) && NumberEquals(m24, F(0.0)) && NumberEquals(m34, F(0.0)) && NumberEquals(m44, F(1.0));
}
/*!

View File

@@ -714,10 +714,10 @@ namespace Nz
#endif
Quaternion interpolated;
interpolated.w = Lerp(from.w, to.w, interpolation);
interpolated.x = Lerp(from.x, to.x, interpolation);
interpolated.y = Lerp(from.y, to.y, interpolation);
interpolated.z = Lerp(from.z, to.z, interpolation);
interpolated.w = Nz::Lerp(from.w, to.w, interpolation);
interpolated.x = Nz::Lerp(from.x, to.x, interpolation);
interpolated.y = Nz::Lerp(from.y, to.y, interpolation);
interpolated.z = Nz::Lerp(from.z, to.z, interpolation);
return interpolated;
}

View File

@@ -911,9 +911,9 @@ namespace Nz
template<typename T>
bool Vector3<T>::operator<(const Vector3& vec) const
{
if (x == vec.x)
if (NumberEquals(x, vec.x))
{
if (y == vec.y)
if (NumberEquals(y, vec.y))
return z < vec.z;
else
return y < vec.y;
@@ -931,10 +931,10 @@ namespace Nz
template<typename T>
bool Vector3<T>::operator<=(const Vector3& vec) const
{
if (x == vec.x)
if (NumberEquals(x, vec.x))
{
if (y == vec.y)
return z <= vec.z;
if (NumberEquals(y, vec.y))
return NumberEquals(z, vec.z) || z < vec.z;
else
return y < vec.y;
}
@@ -1371,7 +1371,7 @@ namespace std
}
};
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -843,11 +843,11 @@ namespace Nz
template<typename T>
bool Vector4<T>::operator<(const Vector4& vec) const
{
if (x == vec.x)
if (NumberEquals(x, vec.x))
{
if (y == vec.y)
if (NumberEquals(y, vec.y))
{
if (z == vec.z)
if (NumberEquals(z, vec.z))
return w < vec.w;
else
return z < vec.z;
@@ -869,12 +869,12 @@ namespace Nz
template<typename T>
bool Vector4<T>::operator<=(const Vector4& vec) const
{
if (x == vec.x)
if (NumberEquals(x, vec.x))
{
if (y == vec.y)
if (NumberEquals(y, vec.y))
{
if (z == vec.z)
return w <= vec.w;
if (NumberEquals(z, vec.z))
return NumberEquals(w, vec.w) || w < vec.w;
else
return z < vec.z;
}
@@ -1144,7 +1144,7 @@ namespace std
}
};
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 03 Feb 2016 at 00:06:56
// This file was automatically generated
/*
Nazara Engine - Network module
@@ -36,7 +36,10 @@
#include <Nazara/Network/IpAddress.hpp>
#include <Nazara/Network/NetPacket.hpp>
#include <Nazara/Network/Network.hpp>
#include <Nazara/Network/RUdpConnection.hpp>
#include <Nazara/Network/RUdpMessage.hpp>
#include <Nazara/Network/SocketHandle.hpp>
#include <Nazara/Network/SocketPoller.hpp>
#include <Nazara/Network/TcpClient.hpp>
#include <Nazara/Network/TcpServer.hpp>
#include <Nazara/Network/UdpSocket.hpp>

View File

@@ -380,7 +380,7 @@ namespace std
// This is SDBM adapted for IP addresses, tested to generate the least collisions possible
// (It doesn't mean it cannot be improved though)
std::size_t hash = 0;
std::size_t h = 0;
switch (ip.GetProtocol())
{
case Nz::NetProtocol_Any:
@@ -389,20 +389,20 @@ namespace std
case Nz::NetProtocol_IPv4:
{
hash = ip.ToUInt32() + (hash << 6) + (hash << 16) - hash;
h = ip.ToUInt32() + (h << 6) + (h << 16) - h;
break;
}
case Nz::NetProtocol_IPv6:
{
Nz::IpAddress::IPv6 v6 = ip.ToIPv6();
for (std::size_t i = 0; i < v6.size(); i++)
hash = v6[i] + (hash << 6) + (hash << 16) - hash;
h = v6[i] + (h << 6) + (h << 16) - h;
break;
}
}
return ip.GetPort() + (hash << 6) + (hash << 16) - hash;
return ip.GetPort() + (h << 6) + (h << 16) - h;
}
};
}

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2015 Jérôme Leclercq
// 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
@@ -56,7 +56,7 @@ namespace Nz
void OnEmptyStream() override;
void FreeStream();
void InitStream(std::size_t minCapacity, UInt64 cursorPos, UInt32 openMode);
void InitStream(std::size_t minCapacity, UInt64 cursorPos, OpenModeFlags openMode);
static bool Initialize();
static void Uninitialize();

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 12 Jul 2016 at 17:44:43
// This file was automatically generated
/*
Nazara Engine - Noise module

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 14 Oct 2016 at 18:58:18
// This file was automatically generated
/*
Nazara Engine - Physics 2D module
@@ -29,11 +29,11 @@
#ifndef NAZARA_GLOBAL_PHYSICS2D_HPP
#define NAZARA_GLOBAL_PHYSICS2D_HPP
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Physics2D/Physics2D.hpp>
#include <Nazara/Physics2D/Collider2D.hpp>
#include <Nazara/Physics2D/Enums.hpp>
#include <Nazara/Physics2D/Config.hpp>
#include <Nazara/Physics2D/Enums.hpp>
#include <Nazara/Physics2D/Physics2D.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
#endif // NAZARA_GLOBAL_PHYSICS2D_HPP

View File

@@ -125,6 +125,33 @@ namespace Nz
private:
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
};
class SegmentCollider2D;
using SegmentCollider2DConstRef = ObjectRef<const SegmentCollider2D>;
using SegmentCollider2DRef = ObjectRef<SegmentCollider2D>;
class NAZARA_PHYSICS2D_API SegmentCollider2D : public Collider2D
{
public:
inline SegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness = 1.f);
float ComputeInertialMatrix(float mass) const override;
inline const Vector2f& GetFirstPoint() const;
inline float GetLength() const;
inline const Vector2f& GetSecondPoint() const;
ColliderType2D GetType() const override;
template<typename... Args> static SegmentCollider2DRef New(Args&&... args);
private:
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
Vector2f m_first;
Vector2f m_second;
float m_thickness;
};
}
#include <Nazara/Physics2D/Collider2D.inl>

View File

@@ -49,6 +49,36 @@ namespace Nz
return object.release();
}
SegmentCollider2D::SegmentCollider2D(const Vector2f& first, const Vector2f& second, float thickness) :
m_first(first),
m_second(second),
m_thickness(thickness)
{
}
inline const Vector2f& SegmentCollider2D::GetFirstPoint() const
{
return m_first;
}
inline float SegmentCollider2D::GetLength() const
{
return m_first.Distance(m_second);
}
inline const Vector2f& SegmentCollider2D::GetSecondPoint() const
{
return m_second;
}
template<typename... Args>
SegmentCollider2DRef SegmentCollider2D::New(Args&&... args)
{
std::unique_ptr<SegmentCollider2D> object(new SegmentCollider2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Physics2D/DebugOff.hpp>

View File

@@ -10,9 +10,9 @@
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
// On force la valeur de MANAGE_MEMORY en mode debug
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY
#undef NAZARA_PHYSICS_MANAGE_MEMORY
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS2D_MANAGE_MEMORY
#undef NAZARA_PHYSICS2D_MANAGE_MEMORY
#define NAZARA_PHYSICS2D_MANAGE_MEMORY 0
#endif
#endif // NAZARA_CONFIG_CHECK_PHYSICS_HPP

View File

@@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics3D/Config.hpp>
#if NAZARA_PHYSICS_MANAGE_MEMORY
#include <Nazara/Physics2D/Config.hpp>
#if NAZARA_PHYSICS2D_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
#if NAZARA_PHYSICS_MANAGE_MEMORY
#if NAZARA_PHYSICS2D_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@@ -49,6 +49,7 @@ namespace Nz
bool IsSleeping() const;
void SetAngularVelocity(float angularVelocity);
void SetGeom(Collider2DRef geom);
void SetMass(float mass);
void SetMassCenter(const Vector2f& center);
void SetPosition(const Vector2f& position);
@@ -59,8 +60,8 @@ namespace Nz
RigidBody2D& operator=(RigidBody2D&& object);
private:
void Create(float mass = 1.f, float moment = 1.f);
void Destroy();
void SetGeom(Collider2DRef geom);
std::vector<cpShape*> m_shapes;
Collider2DRef m_geom;

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 14 Oct 2016 at 18:58:18
// This file was automatically generated
/*
Nazara Engine - Physics 3D module
@@ -29,11 +29,11 @@
#ifndef NAZARA_GLOBAL_PHYSICS3D_HPP
#define NAZARA_GLOBAL_PHYSICS3D_HPP
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <Nazara/Physics3D/Physics3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <Nazara/Physics3D/Enums.hpp>
#include <Nazara/Physics3D/Config.hpp>
#include <Nazara/Physics3D/Collider3D.hpp>
#include <Nazara/Physics3D/Config.hpp>
#include <Nazara/Physics3D/Enums.hpp>
#include <Nazara/Physics3D/Physics3D.hpp>
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#endif // NAZARA_GLOBAL_PHYSICS3D_HPP

View File

@@ -10,8 +10,8 @@
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
// On force la valeur de MANAGE_MEMORY en mode debug
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY
#undef NAZARA_PHYSICS_MANAGE_MEMORY
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS3D_MANAGE_MEMORY
#undef NAZARA_PHYSICS3D_MANAGE_MEMORY
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
#endif

View File

@@ -3,6 +3,6 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics3D/Config.hpp>
#if NAZARA_PHYSICS_MANAGE_MEMORY
#if NAZARA_PHYSICS3D_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
#if NAZARA_PHYSICS_MANAGE_MEMORY
#if NAZARA_PHYSICS3D_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@@ -25,6 +25,6 @@ namespace Nz
ColliderType3D_Max = ColliderType3D_Tree
};
};
}
#endif // NAZARA_ENUMS_PHYSICS3D_HPP

View File

@@ -25,8 +25,7 @@
#ifndef NAZARA_PREREQUESITES_HPP
#define NAZARA_PREREQUESITES_HPP
// Identification du compilateur
///TODO: Rajouter des tests d'identification de compilateurs
// Try to identify the compiler
#if defined(__BORLANDC__)
#define NAZARA_COMPILER_BORDLAND
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
@@ -63,10 +62,10 @@
#pragma warning(disable: 4251)
#else
#define NAZARA_COMPILER_UNKNOWN
#define NAZARA_COMPILER_SUPPORTS_CPP11 (defined(__cplusplus) && __cplusplus >= 201103L)
#define NAZARA_DEPRECATED(txt)
#define NAZARA_FUNCTION __func__ // __func__ est standard depuis le C++11
#define NAZARA_FUNCTION __func__ // __func__ has been standardized in C++ 2011
/// Cette ligne n'est là que pour prévenir, n'hésitez pas à la commenter si elle vous empêche de compiler
#pragma message This compiler is not fully supported
#endif
@@ -76,20 +75,20 @@
// Nazara version macro
#define NAZARA_VERSION_MAJOR 0
#define NAZARA_VERSION_MINOR 1
#define NAZARA_VERSION_MINOR 2
#define NAZARA_VERSION_PATCH 1
#include <Nazara/Core/Config.hpp>
// Identification de la plateforme
// Try to identify target platform via defines
#if defined(_WIN32)
#define NAZARA_PLATFORM_WINDOWS
#define NAZARA_EXPORT __declspec(dllexport)
#define NAZARA_IMPORT __declspec(dllimport)
// Des defines pour le header Windows
#if defined(NAZARA_BUILD) // Pour ne pas entrer en conflit avec les defines de l'application ou d'une autre bibliothèque
// Somes defines for windows.h include..
#if defined(NAZARA_BUILD)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@@ -99,13 +98,12 @@
#endif
#if NAZARA_CORE_WINDOWS_NT6
// Version de Windows minimale : Vista
#define NAZARA_WINNT 0x0600
#else
#define NAZARA_WINNT 0x0501
#endif
// Pour ne pas casser le define déjà en place s'il est applicable
// Keep the actual define if existing and greater than our requirement
#if defined(_WIN32_WINNT)
#if _WIN32_WINNT < NAZARA_WINNT
#undef _WIN32_WINNT
@@ -128,7 +126,6 @@
#define NAZARA_PLATFORM_MACOSX
#define NAZARA_PLATFORM_POSIX*/
#else
// À commenter pour tenter quand même une compilation
#error This operating system is not fully supported by the Nazara Engine
#define NAZARA_PLATFORM_UNKNOWN
@@ -141,12 +138,7 @@
#define NAZARA_PLATFORM_x64
#endif
// Définit NDEBUG si NAZARA_DEBUG n'est pas présent
#if !defined(NAZARA_DEBUG) && !defined(NDEBUG)
#define NDEBUG
#endif
// Macros supplémentaires
// A bunch of useful macros
#define NazaraPrefix(a, prefix) prefix ## a
#define NazaraPrefixMacro(a, prefix) NazaraPrefix(a, prefix)
#define NazaraSuffix(a, suffix) a ## suffix
@@ -155,8 +147,11 @@
#define NazaraStringifyMacro(s) NazaraStringify(s) // http://gcc.gnu.org/onlinedocs/cpp/Stringification.html#Stringification
#define NazaraUnused(a) (void) a
#include <climits>
#include <cstdint>
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
@@ -169,17 +164,17 @@ static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
namespace Nz
{
typedef int8_t Int8;
typedef uint8_t UInt8;
typedef int8_t Int8;
typedef uint8_t UInt8;
typedef int16_t Int16;
typedef uint16_t UInt16;
typedef int16_t Int16;
typedef uint16_t UInt16;
typedef int32_t Int32;
typedef uint32_t UInt32;
typedef int32_t Int32;
typedef uint32_t UInt32;
typedef int64_t Int64;
typedef uint64_t UInt64;
typedef int64_t Int64;
typedef uint64_t UInt64;
}
#endif // NAZARA_PREREQUESITES_HPP

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 24 Jun 2015 at 13:55:50
// This file was automatically generated
/*
Nazara Engine - Renderer module
@@ -38,6 +38,7 @@
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/RenderBuffer.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderPipeline.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/RenderTargetParameters.hpp>

View File

@@ -30,7 +30,7 @@ namespace Nz
{
public:
RenderWindow() = default;
RenderWindow(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
RenderWindow(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
RenderWindow(const RenderWindow&) = delete;
RenderWindow(RenderWindow&&) = delete; ///TODO
@@ -39,7 +39,7 @@ namespace Nz
bool CopyToImage(AbstractImage* image, const Vector3ui& dstPos = Vector3ui(0U)) const;
bool CopyToImage(AbstractImage* image, const Rectui& rect, const Vector3ui& dstPos = Vector3ui(0U)) const;
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default, const ContextParameters& parameters = ContextParameters());
bool Create(WindowHandle handle, const ContextParameters& parameters = ContextParameters());
void Display();

View File

@@ -1,4 +1,4 @@
// This file was automatically generated on 12 Jul 2016 at 17:44:43
// This file was automatically generated
/*
Nazara Engine - Utility module
@@ -42,6 +42,7 @@
#include <Nazara/Utility/Cursor.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/EventHandler.hpp>
#include <Nazara/Utility/Font.hpp>
#include <Nazara/Utility/FontData.hpp>
#include <Nazara/Utility/FontGlyph.hpp>

View File

@@ -38,9 +38,6 @@
// Lors du parsage d'une ressource, déclenche un avertissement si une erreur non-critique est repérée dans une ressource (Plus lent)
#define NAZARA_UTILITY_STRICT_RESOURCE_PARSING 1
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
#define NAZARA_UTILITY_THREADED_WINDOW 0
// Protège les classes des accès concurrentiels
//#define NAZARA_UTILITY_THREADSAFE 1

View File

@@ -7,6 +7,8 @@
#ifndef NAZARA_ENUMS_UTILITY_HPP
#define NAZARA_ENUMS_UTILITY_HPP
#include <Nazara/Core/Flags.hpp>
namespace Nz
{
enum AnimationType
@@ -430,18 +432,29 @@ namespace Nz
WindowEventType_Max = WindowEventType_TextEntered
};
enum WindowStyleFlags
enum WindowStyle
{
WindowStyle_None = 0x0,
WindowStyle_Fullscreen = 0x1,
WindowStyle_None, ///< Window has no border nor titlebar.
WindowStyle_Fullscreen, ///< At the window creation, the OS tries to set it in fullscreen.
WindowStyle_Closable = 0x2,
WindowStyle_Resizable = 0x4,
WindowStyle_Titlebar = 0x8,
WindowStyle_Closable, ///< Allows the window to be closed by a button in the titlebar, generating a Quit event.
WindowStyle_Resizable, ///< Allows the window to be resized by dragging its corners or by a button of the titlebar.
WindowStyle_Titlebar, ///< Adds a titlebar to the window, this option is automatically enabled if buttons of the titlebar are enabled.
WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar,
WindowStyle_Max = WindowStyle_Titlebar*2-1
WindowStyle_Threaded, ///< Runs the window into a thread, allowing the application to keep updating while resizing/dragging the window.
WindowStyle_Max = WindowStyle_Threaded
};
template<>
struct EnableFlagsOperators<WindowStyle>
{
static constexpr bool value = true;
};
using WindowStyleFlags = Flags<WindowStyle>;
constexpr WindowStyleFlags WindowStyle_Default = WindowStyle_Closable | WindowStyle_Resizable | WindowStyle_Titlebar;
}
#endif // NAZARA_ENUMS_UTILITY_HPP

View File

@@ -24,6 +24,9 @@ namespace Nz
inline void Dispatch(const WindowEvent& event);
EventHandler& operator=(const EventHandler&) = delete;
EventHandler& operator=(EventHandler&&) = default;
NazaraSignal(OnEvent, const EventHandler* /*eventHandler*/, const WindowEvent& /*event*/);
NazaraSignal(OnGainedFocus, const EventHandler* /*eventHandler*/);
NazaraSignal(OnLostFocus, const EventHandler* /*eventHandler*/);

View File

@@ -91,6 +91,8 @@ namespace Nz
ImageType GetType() const;
unsigned int GetWidth(UInt8 level = 0) const;
bool HasAlpha() const;
bool IsValid() const;
// Load

View File

@@ -28,25 +28,15 @@ namespace Nz
{
struct NAZARA_UTILITY_API MeshParams : ResourceParameters
{
MeshParams(); // Vérifie que le storage par défaut est supporté (software autrement)
MeshParams();
// La transformation appliquée à tous les sommets du mesh
Matrix4f matrix = Matrix4f::Identity();
// Si ceci sera le stockage utilisé par les buffers
UInt32 storage = DataStorage_Hardware;
// Charger une version animée du mesh si possible ?
bool animated = true;
// Faut-il centrer le mesh autour de l'origine ?
bool center = false;
// Faut-il retourner les UV ?
bool flipUVs = false;
// Faut-il optimiser les index buffers ? (Rendu plus rapide, mais le chargement dure plus longtemps)
bool optimizeIndexBuffers = true;
Matrix4f matrix = Matrix4f::Identity(); ///< A matrix which will transform every vertex position
UInt32 storage = DataStorage_Hardware; ///< The place where the buffers will be allocated
Vector2f texCoordOffset = {0.f, 0.f}; ///< Offset to apply on the texture coordinates (not scaled)
Vector2f texCoordScale = {1.f, 1.f}; ///< Scale to apply on the texture coordinates
bool animated = true; ///< If true, will load an animated version of the model if possible
bool center = false; ///< If true, will center the mesh vertices around the origin
bool optimizeIndexBuffers = true; ///< Optimize the index buffers after loading, improve cache locality (and thus rendering speed) but increase loading time.
bool IsValid() const;
};

View File

@@ -39,18 +39,8 @@ namespace Nz
}
inline PixelFormatInfo::PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) :
redMask(rMask),
greenMask(gMask),
blueMask(bMask),
alphaMask(aMask),
content(formatContent),
redType(subType),
greenType(subType),
blueType(subType),
alphaType(subType),
name(formatName)
PixelFormatInfo(formatName, formatContent, subType, rMask, subType, gMask, subType, bMask, subType, aMask)
{
RecomputeBitsPerPixel();
}
inline PixelFormatInfo::PixelFormatInfo(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) :
@@ -65,6 +55,11 @@ namespace Nz
alphaType(aType),
name(formatName)
{
redMask.Reverse();
greenMask.Reverse();
blueMask.Reverse();
alphaMask.Reverse();
if (bpp == 0)
RecomputeBitsPerPixel();
}
@@ -123,6 +118,9 @@ namespace Nz
if (usedBits > bitsPerPixel)
return false;
if (usedBits > 64) //< Currently, formats with over 64 bits per component are not supported
return false;
switch (types[i])
{
case PixelFormatSubType_Half:

View File

@@ -19,6 +19,7 @@ namespace Nz
{
public:
VideoMode();
VideoMode(unsigned int w, unsigned int h);
VideoMode(unsigned int w, unsigned int h, UInt8 bpp);
bool IsFullscreenValid() const;

View File

@@ -10,6 +10,8 @@
#define NAZARA_WINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Utility/Config.hpp>
@@ -19,11 +21,6 @@
#include <Nazara/Utility/WindowHandle.hpp>
#include <queue>
#if NAZARA_UTILITY_THREADED_WINDOW
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Mutex.hpp>
#endif
namespace Nz
{
class Cursor;
@@ -39,7 +36,7 @@ namespace Nz
public:
inline Window();
inline Window(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
inline Window(WindowHandle handle);
Window(const Window&) = delete;
inline Window(Window&& window) noexcept;
@@ -47,7 +44,7 @@ namespace Nz
inline void Close();
bool Create(VideoMode mode, const String& title, UInt32 style = WindowStyle_Default);
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
bool Create(WindowHandle handle);
void Destroy();
@@ -65,7 +62,7 @@ namespace Nz
unsigned int GetHeight() const;
Vector2i GetPosition() const;
Vector2ui GetSize() const;
UInt32 GetStyle() const;
WindowStyleFlags GetStyle() const;
String GetTitle() const;
unsigned int GetWidth() const;
@@ -114,23 +111,24 @@ namespace Nz
private:
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
inline void HandleEvent(const WindowEvent& event);
inline void PushEvent(const WindowEvent& event);
static bool Initialize();
static void Uninitialize();
std::queue<WindowEvent> m_events;
#if NAZARA_UTILITY_THREADED_WINDOW
std::vector<WindowEvent> m_pendingEvents;
ConditionVariable m_eventCondition;
EventHandler m_eventHandler;
Mutex m_eventMutex;
Mutex m_eventConditionMutex;
bool m_waitForEvent;
#endif
EventHandler m_eventHandler;
bool m_asyncWindow;
bool m_closed;
bool m_closeOnQuit;
bool m_eventPolling;
bool m_ownsWindow;
bool m_waitForEvent;
};
}

View File

@@ -4,6 +4,7 @@
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Core/ErrorFlags.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Utility/Debug.hpp>
namespace Nz
@@ -13,15 +14,14 @@ namespace Nz
*/
inline Window::Window() :
m_impl(nullptr),
#if NAZARA_UTILITY_THREADED_WINDOW
m_waitForEvent(false),
#endif
m_asyncWindow(false),
m_closeOnQuit(true),
m_eventPolling(false)
m_eventPolling(false),
m_waitForEvent(false)
{
}
inline Window::Window(VideoMode mode, const String& title, UInt32 style) :
inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) :
Window()
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
@@ -41,16 +41,16 @@ namespace Nz
inline Window::Window(Window&& window) noexcept :
m_impl(window.m_impl),
m_events(std::move(window.m_events)),
#if NAZARA_UTILITY_THREADED_WINDOW
m_pendingEvents(std::move(window.m_pendingEvents)),
m_eventCondition(std::move(window.m_eventCondition)),
m_eventHandler(std::move(window.m_eventHandler)),
m_eventMutex(std::move(window.m_eventMutex)),
m_eventConditionMutex(std::move(window.m_eventConditionMutex)),
m_waitForEvent(window.m_waitForEvent),
#endif
m_closed(window.m_closed),
m_closeOnQuit(window.m_closeOnQuit),
m_eventPolling(window.m_eventPolling),
m_ownsWindow(window.m_ownsWindow)
m_ownsWindow(window.m_ownsWindow),
m_waitForEvent(window.m_waitForEvent)
{
window.m_impl = nullptr;
}
@@ -104,12 +104,8 @@ namespace Nz
return m_impl != nullptr;
}
inline void Window::PushEvent(const WindowEvent& event)
inline void Window::HandleEvent(const WindowEvent& event)
{
#if NAZARA_UTILITY_THREADED_WINDOW
m_eventMutex.Lock();
#endif
if (m_eventPolling)
m_events.push(event);
@@ -120,17 +116,27 @@ namespace Nz
if (event.type == WindowEventType_Quit && m_closeOnQuit)
Close();
}
#if NAZARA_UTILITY_THREADED_WINDOW
m_eventMutex.Unlock();
if (m_waitForEvent)
inline void Window::PushEvent(const WindowEvent& event)
{
if (!m_asyncWindow)
HandleEvent(event);
else
{
m_eventConditionMutex.Lock();
m_eventCondition.Signal();
m_eventConditionMutex.Unlock();
{
LockGuard eventLock(m_eventMutex);
m_pendingEvents.push_back(event);
}
if (m_waitForEvent)
{
m_eventConditionMutex.Lock();
m_eventCondition.Signal();
m_eventConditionMutex.Unlock();
}
}
#endif
}
/*!
@@ -141,22 +147,21 @@ namespace Nz
{
Destroy();
m_closed = window.m_closed;
m_closeOnQuit = window.m_closeOnQuit;
m_eventPolling = window.m_eventPolling;
m_impl = window.m_impl;
m_events = std::move(window.m_events);
m_ownsWindow = window.m_ownsWindow;
m_closed = window.m_closed;
m_closeOnQuit = window.m_closeOnQuit;
m_eventCondition = std::move(window.m_eventCondition);
m_eventConditionMutex = std::move(window.m_eventConditionMutex);
m_eventHandler = std::move(window.m_eventHandler);
m_eventMutex = std::move(window.m_eventMutex);
m_eventPolling = window.m_eventPolling;
m_impl = window.m_impl;
m_events = std::move(window.m_events);
m_pendingEvents = std::move(window.m_pendingEvents);
m_ownsWindow = window.m_ownsWindow;
m_waitForEvent = window.m_waitForEvent;
window.m_impl = nullptr;
#if NAZARA_UTILITY_THREADED_WINDOW
m_eventCondition = std::move(window.m_eventCondition);
m_eventMutex = std::move(window.m_eventMutex);
m_eventConditionMutex = std::move(window.m_eventConditionMutex);
m_waitForEvent = window.m_waitForEvent;
#endif
return *this;
}
}