From a84110a5755b3e74062135b2b8d3ab9311a8dad1 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sat, 21 Jan 2017 20:31:53 +0100 Subject: [PATCH 01/27] Core/ObjectHandle: Fix operator<= --- include/Nazara/Core/ObjectHandle.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Core/ObjectHandle.hpp b/include/Nazara/Core/ObjectHandle.hpp index 66c6161e4..bf22734d3 100644 --- a/include/Nazara/Core/ObjectHandle.hpp +++ b/include/Nazara/Core/ObjectHandle.hpp @@ -69,7 +69,7 @@ namespace Nz template bool operator<(const T& lhs, const ObjectHandle& rhs); template bool operator<(const ObjectHandle& lhs, const T& rhs); - template bool operator<=(const ObjectHandle, const ObjectHandle& rhs); + template bool operator<=(const ObjectHandle&, const ObjectHandle& rhs); template bool operator<=(const T& lhs, const ObjectHandle& rhs); template bool operator<=(const ObjectHandle& lhs, const T& rhs); From 071147bf51ac19eda4b5909f3f7c178e6cf7f124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Mon, 23 Jan 2017 11:58:05 +0100 Subject: [PATCH 02/27] Network/AbstractSocket: Prevent querying/setting receive/send buffer size without opening the socket first --- include/Nazara/Network/UdpSocket.hpp | 2 +- src/Nazara/Network/AbstractSocket.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/Nazara/Network/UdpSocket.hpp b/include/Nazara/Network/UdpSocket.hpp index e6470e365..3c4abdfe7 100644 --- a/include/Nazara/Network/UdpSocket.hpp +++ b/include/Nazara/Network/UdpSocket.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 Jérôme Leclercq // This file is part of the "Nazara Engine - Network module" // For conditions of distribution and use, see copyright notice in Config.hpp diff --git a/src/Nazara/Network/AbstractSocket.cpp b/src/Nazara/Network/AbstractSocket.cpp index f562900d2..3b3d9cb56 100644 --- a/src/Nazara/Network/AbstractSocket.cpp +++ b/src/Nazara/Network/AbstractSocket.cpp @@ -117,8 +117,7 @@ namespace Nz */ std::size_t AbstractSocket::QueryReceiveBufferSize() const { - if (m_handle == SocketImpl::InvalidHandle) - return 0; + NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first"); return SocketImpl::QueryReceiveBufferSize(m_handle); } @@ -129,8 +128,7 @@ namespace Nz */ std::size_t AbstractSocket::QuerySendBufferSize() const { - if (m_handle == SocketImpl::InvalidHandle) - return 0; + NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first"); return SocketImpl::QuerySendBufferSize(m_handle); } @@ -142,8 +140,9 @@ namespace Nz */ void AbstractSocket::SetReceiveBufferSize(std::size_t size) { - if (m_handle != SocketImpl::InvalidHandle) - SocketImpl::SetReceiveBufferSize(m_handle, size); + NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first"); + + SocketImpl::SetReceiveBufferSize(m_handle, size); } /*! @@ -153,8 +152,9 @@ namespace Nz */ void AbstractSocket::SetSendBufferSize(std::size_t size) { - if (m_handle != SocketImpl::InvalidHandle) - SocketImpl::SetSendBufferSize(m_handle, size); + NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Socket must be created first"); + + SocketImpl::SetSendBufferSize(m_handle, size); } /*! From 28965b799e7ff35a60f18691e73f0bad9b8947ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 25 Jan 2017 15:53:25 +0100 Subject: [PATCH 03/27] Core/MemoryPool: Fix incorrect inlines --- include/Nazara/Core/MemoryPool.hpp | 8 +++++--- include/Nazara/Core/MemoryPool.inl | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Core/MemoryPool.hpp b/include/Nazara/Core/MemoryPool.hpp index bda0915fa..10f147f5c 100644 --- a/include/Nazara/Core/MemoryPool.hpp +++ b/include/Nazara/Core/MemoryPool.hpp @@ -22,12 +22,14 @@ namespace Nz ~MemoryPool() = default; void* Allocate(unsigned int size); + template void Delete(T* ptr); + void Free(void* ptr); - unsigned int GetBlockSize() const; - unsigned int GetFreeBlocks() const; - unsigned int GetSize() const; + inline unsigned int GetBlockSize() const; + inline unsigned int GetFreeBlocks() const; + inline unsigned int GetSize() const; template T* New(Args&&... args); diff --git a/include/Nazara/Core/MemoryPool.inl b/include/Nazara/Core/MemoryPool.inl index db0cbc648..41443e38b 100644 --- a/include/Nazara/Core/MemoryPool.inl +++ b/include/Nazara/Core/MemoryPool.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -95,9 +96,8 @@ namespace Nz * * \remark If ptr is null, nothing is done */ - template - inline void MemoryPool::Delete(T* ptr) + void MemoryPool::Delete(T* ptr) { if (ptr) { From 311e2a545dc00d6bef7deab9f30e53d132d3b86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 25 Jan 2017 15:54:13 +0100 Subject: [PATCH 04/27] Network/SocketPoller: Fix cases where EAGAIN is not the same as EWOULDBLOCK (Posix) --- src/Nazara/Network/Posix/SocketImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 69f0d0bf3..7d28e6785 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -465,6 +465,7 @@ namespace Nz int errorCode = GetLastErrorCode(); switch (errorCode) { + case EAGAIN: case EWOULDBLOCK: { // If we have no data and are not blocking, return true with 0 byte read From 1d6f22cd8ac1e924a5c3cd042f7c0c1e19685df5 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 14:49:07 +0100 Subject: [PATCH 05/27] Core/Flags: Make Flags default-constructible --- include/Nazara/Core/Flags.hpp | 2 +- include/Nazara/Core/Flags.inl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/Nazara/Core/Flags.hpp b/include/Nazara/Core/Flags.hpp index 1dbd102a0..f356a04a5 100644 --- a/include/Nazara/Core/Flags.hpp +++ b/include/Nazara/Core/Flags.hpp @@ -29,7 +29,7 @@ namespace Nz public: using BitField = typename std::conditional<(EnumAsFlags::max > 32), UInt64, UInt32>::type; - constexpr Flags(BitField value); + constexpr Flags(BitField value = 0); constexpr Flags(E enumVal); explicit constexpr operator bool() const; diff --git a/include/Nazara/Core/Flags.inl b/include/Nazara/Core/Flags.inl index 67fee6a26..57ffd9e7e 100644 --- a/include/Nazara/Core/Flags.inl +++ b/include/Nazara/Core/Flags.inl @@ -13,13 +13,13 @@ namespace Nz * \brief Core class used to combine enumeration values into flags bitfield */ - /*! - * \brief Constructs a Flags object using a bitfield - * - * \param value Bitfield to be used + /*! + * \brief Constructs a Flags object using a bitfield + * + * \param value Bitfield to be used * * Uses a bitfield to builds the flag value. (e.g. if bit 0 is active, then Enum value 0 will be set as active). - */ + */ template constexpr Flags::Flags(BitField value) : m_value(value) From ab3b730d217c5d26216962e32b5083d9a44ea777 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 14:51:01 +0100 Subject: [PATCH 06/27] Network/TcpClient|UdpSocket: Add SendMultiple method To efficiently merge multiples buffers into a reduced number of network packets --- include/Nazara/Network/AbstractSocket.hpp | 4 +- include/Nazara/Network/NetBuffer.hpp | 21 ++++++++++ include/Nazara/Network/TcpClient.hpp | 2 + include/Nazara/Network/UdpSocket.hpp | 8 ++-- src/Nazara/Network/Posix/SocketImpl.cpp | 51 +++++++++++++++++++++++ src/Nazara/Network/Posix/SocketImpl.hpp | 1 + src/Nazara/Network/TcpClient.cpp | 39 +++++++++++++++++ src/Nazara/Network/UdpSocket.cpp | 25 +++++++++++ src/Nazara/Network/Win32/SocketImpl.cpp | 51 ++++++++++++++++++++++- src/Nazara/Network/Win32/SocketImpl.hpp | 10 +++-- 10 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 include/Nazara/Network/NetBuffer.hpp diff --git a/include/Nazara/Network/AbstractSocket.hpp b/include/Nazara/Network/AbstractSocket.hpp index 8a2e55e25..0b33c6a8f 100644 --- a/include/Nazara/Network/AbstractSocket.hpp +++ b/include/Nazara/Network/AbstractSocket.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 Jérôme Leclercq // This file is part of the "Nazara Engine - Network module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -68,4 +68,4 @@ namespace Nz #include -#endif // NAZARA_ABSTRACTSOCKET_HPP \ No newline at end of file +#endif // NAZARA_ABSTRACTSOCKET_HPP diff --git a/include/Nazara/Network/NetBuffer.hpp b/include/Nazara/Network/NetBuffer.hpp new file mode 100644 index 000000000..0c05c53b2 --- /dev/null +++ b/include/Nazara/Network/NetBuffer.hpp @@ -0,0 +1,21 @@ +// Copyright (C) 2017 Jérôme Leclercq +// This file is part of the "Nazara Engine - Network module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#pragma once + +#ifndef NAZARA_NETBUFFER_HPP +#define NAZARA_NETBUFFER_HPP + +#include + +namespace Nz +{ + struct NetBuffer + { + void* data; + std::size_t dataLength; + }; +} + +#endif // NAZARA_NETBUFFER_HPP diff --git a/include/Nazara/Network/TcpClient.hpp b/include/Nazara/Network/TcpClient.hpp index dc41d8eb5..a3b229bda 100644 --- a/include/Nazara/Network/TcpClient.hpp +++ b/include/Nazara/Network/TcpClient.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace Nz { @@ -49,6 +50,7 @@ namespace Nz bool ReceivePacket(NetPacket* packet); bool Send(const void* buffer, std::size_t size, std::size_t* sent); + bool SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent); bool SendPacket(const NetPacket& packet); bool SetCursorPos(UInt64 offset) override; diff --git a/include/Nazara/Network/UdpSocket.hpp b/include/Nazara/Network/UdpSocket.hpp index 3c4abdfe7..04ca41db0 100644 --- a/include/Nazara/Network/UdpSocket.hpp +++ b/include/Nazara/Network/UdpSocket.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 Jérôme Leclercq // This file is part of the "Nazara Engine - Network module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace Nz { @@ -29,7 +30,7 @@ namespace Nz inline bool Create(NetProtocol protocol); void EnableBroadcasting(bool broadcasting); - + inline IpAddress GetBoundAddress() const; inline UInt16 GetBoundPort() const; inline SocketState GetState() const; @@ -42,6 +43,7 @@ namespace Nz bool ReceivePacket(NetPacket* packet, IpAddress* from); bool Send(const IpAddress& to, const void* buffer, std::size_t size, std::size_t* sent); + bool SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent); bool SendPacket(const IpAddress& to, const NetPacket& packet); private: @@ -55,4 +57,4 @@ namespace Nz #include -#endif // NAZARA_UDPSOCKET_HPP \ No newline at end of file +#endif // NAZARA_UDPSOCKET_HPP diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 7d28e6785..93fe74d4d 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -577,6 +577,57 @@ namespace Nz return true; } + bool SocketImpl::SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error) + { + NazaraAssert(handle != InvalidHandle, "Invalid handle"); + NazaraAssert(buffers && bufferCount > 0, "Invalid buffers"); + + StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(iovec)); + iovec* sysBuffers = static_cast(memory.GetPtr()); + for (std::size_t i = 0; i < bufferCount; ++i) + { + sysBuffers[i].iov_base = buffers[i].data; + sysBuffers[i].iov_len = buffers[i].dataLength; + } + + struct msghdr header; + std::memset(&header, 0, sizeof(header); + + IpAddressImpl::SockAddrBuffer nameBuffer; + header.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data()); + header.msg_name = nameBuffer.data(); + msgHdr.msg_iov = sysBuffers; + msgHdr.msg_iovlen = static_cast(bufferCount); + + int sentLength = sendmsg (socket, &msgHdr, MSG_NOSIGNAL); + if (byteSent == SOCKET_ERROR) + { + int errorCode = GetLastErrorCode(); + switch (errorCode) + { + case EWOULDBLOCK: + byteSent = 0; + break; + + default: + { + if (error) + *error = TranslateErrnoToResolveError(errorCode); + + return false; //< Error + } + } + } + + if (sent) + *sent = static_cast(byteSent); + + if (error) + *error = SocketError_NoError; + + return true; + } + bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error) { NazaraAssert(handle != InvalidHandle, "Invalid handle"); diff --git a/src/Nazara/Network/Posix/SocketImpl.hpp b/src/Nazara/Network/Posix/SocketImpl.hpp index a543d8880..e90d4cc74 100644 --- a/src/Nazara/Network/Posix/SocketImpl.hpp +++ b/src/Nazara/Network/Posix/SocketImpl.hpp @@ -64,6 +64,7 @@ namespace Nz static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error); static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error); + static bool SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error); static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error); static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr); diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index b5fd845ee..54144e8fd 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -353,6 +353,45 @@ namespace Nz return true; } + /*! + * \brief Sends multiple buffers at once + * \return true If data were sent + * + * \param buffers A pointer to an array of NetBuffer containing buffers and size data + * \param size Number of NetBuffer to send + * \param sent Optional argument to get the number of bytes sent + */ + bool TcpClient::SendMultiple(const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent) + { + NazaraAssert(buffers && bufferCount > 0, "Invalid buffer"); + + int byteSent; + if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, m_peerAddress, &byteSent, &m_lastError)) + { + switch (m_lastError) + { + case SocketError_ConnectionClosed: + case SocketError_ConnectionRefused: + UpdateState(SocketState_NotConnected); + break; + + default: + break; + } + + if (sent) + *sent = byteSent; + + return false; + } + + if (sent) + *sent = byteSent; + + UpdateState(SocketState_Connected); + return true; + } + /*! * \brief Sends the packet available * \return true If packet sent diff --git a/src/Nazara/Network/UdpSocket.cpp b/src/Nazara/Network/UdpSocket.cpp index 679922513..c13dee343 100644 --- a/src/Nazara/Network/UdpSocket.cpp +++ b/src/Nazara/Network/UdpSocket.cpp @@ -179,6 +179,31 @@ namespace Nz return true; } + /*! + * \brief Sends multiple buffers as one datagram + * \return true If data were sent + * + * \param to Destination IpAddress (must match socket protocol) + * \param buffers A pointer to an array of NetBuffer containing buffers and size data + * \param size Number of NetBuffer to send + * \param sent Optional argument to get the number of bytes sent + */ + bool UdpSocket::SendMultiple(const IpAddress& to, const NetBuffer* buffers, std::size_t bufferCount, std::size_t* sent) + { + NazaraAssert(to.IsValid(), "Invalid ip address"); + NazaraAssert(to.GetProtocol() == m_protocol, "IP Address has a different protocol than the socket"); + NazaraAssert(buffers && bufferCount > 0, "Invalid buffer"); + + int byteSent; + if (!SocketImpl::SendMultiple(m_handle, buffers, bufferCount, to, &byteSent, &m_lastError)) + return false; + + if (sent) + *sent = byteSent; + + return true; + } + /*! * \brief Sends the packet available * \return true If packet sent diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 74550fe37..3a5c285e9 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -608,6 +608,53 @@ namespace Nz return true; } + bool SocketImpl::SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error) + { + NazaraAssert(handle != InvalidHandle, "Invalid handle"); + NazaraAssert(buffers && bufferCount > 0, "Invalid buffers"); + + IpAddressImpl::SockAddrBuffer nameBuffer; + int bufferLength = IpAddressImpl::ToSockAddr(to, nameBuffer.data()); + + StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(WSABUF)); + WSABUF* winBuffers = static_cast(memory.GetPtr()); + for (std::size_t i = 0; i < bufferCount; ++i) + { + winBuffers[i].buf = static_cast(buffers[i].data); + winBuffers[i].len = static_cast(buffers[i].dataLength); + } + + DWORD byteSent; + if (WSASendTo(handle, winBuffers, static_cast(bufferCount), &byteSent, 0, reinterpret_cast(nameBuffer.data()), bufferLength, nullptr, nullptr) == SOCKET_ERROR) + { + int errorCode = WSAGetLastError(); + switch (errorCode) + { + case WSAEWOULDBLOCK: + { + byteSent = 0; + break; + } + + default: + { + if (error) + *error = TranslateWSAErrorToSocketError(errorCode); + + return false; //< Error + } + } + } + + if (sent) + *sent = static_cast(byteSent); + + if (error) + *error = SocketError_NoError; + + return true; + } + bool SocketImpl::SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error) { NazaraAssert(handle != InvalidHandle, "Invalid handle"); @@ -719,7 +766,7 @@ namespace Nz { NazaraAssert(handle != InvalidHandle, "Invalid handle"); - DWORD option = size; + DWORD option = static_cast(size); if (setsockopt(handle, SOL_SOCKET, SO_RCVBUF, reinterpret_cast(&option), sizeof(option)) == SOCKET_ERROR) { if (error) @@ -738,7 +785,7 @@ namespace Nz { NazaraAssert(handle != InvalidHandle, "Invalid handle"); - DWORD option = size; + DWORD option = static_cast(size); if (setsockopt(handle, SOL_SOCKET, SO_SNDBUF, reinterpret_cast(&option), sizeof(option)) == SOCKET_ERROR) { if (error) diff --git a/src/Nazara/Network/Win32/SocketImpl.hpp b/src/Nazara/Network/Win32/SocketImpl.hpp index 5af2b2534..edcc7ce09 100644 --- a/src/Nazara/Network/Win32/SocketImpl.hpp +++ b/src/Nazara/Network/Win32/SocketImpl.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 Jérôme Leclercq // This file is part of the "Nazara Engine - Network module" // For conditions of distribution and use, see copyright notice in Config.hpp @@ -7,9 +7,10 @@ #ifndef NAZARA_SOCKETIMPL_HPP #define NAZARA_SOCKETIMPL_HPP -#include #include #include +#include +#include #include #define NAZARA_NETWORK_POLL_SUPPORT NAZARA_CORE_WINDOWS_NT6 @@ -34,7 +35,7 @@ namespace Nz static SocketState Bind(SocketHandle handle, const IpAddress& address, SocketError* error); static SocketHandle Create(NetProtocol protocol, SocketType type, SocketError* error); - + static void ClearErrorCode(SocketHandle handle); static void Close(SocketHandle handle); @@ -65,6 +66,7 @@ namespace Nz static bool ReceiveFrom(SocketHandle handle, void* buffer, int length, IpAddress* from, int* read, SocketError* error); static bool Send(SocketHandle handle, const void* buffer, int length, int* sent, SocketError* error); + static bool SendMultiple(SocketHandle handle, const NetBuffer* buffers, std::size_t bufferCount, const IpAddress& to, int* sent, SocketError* error); static bool SendTo(SocketHandle handle, const void* buffer, int length, const IpAddress& to, int* sent, SocketError* error); static bool SetBlocking(SocketHandle handle, bool blocking, SocketError* error = nullptr); @@ -87,4 +89,4 @@ namespace Nz }; } -#endif // NAZARA_SOCKETIMPL_HPP \ No newline at end of file +#endif // NAZARA_SOCKETIMPL_HPP From 002d33f590458681c6c6fbd3ec27e491d0c57e9e Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 14:55:37 +0100 Subject: [PATCH 07/27] Network/SocketImpl: Fix compilation --- src/Nazara/Network/Posix/SocketImpl.cpp | 2 +- src/Nazara/Network/Win32/SocketImpl.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 93fe74d4d..b41895a42 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -465,7 +466,6 @@ namespace Nz int errorCode = GetLastErrorCode(); switch (errorCode) { - case EAGAIN: case EWOULDBLOCK: { // If we have no data and are not blocking, return true with 0 byte read diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 3a5c285e9..5c4bdaa0c 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -1,10 +1,11 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 Jérôme Leclercq // This file is part of the "Nazara Engine - Network module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include +#include #include #if defined(NAZARA_COMPILER_MINGW) && __GNUC__ < 5 From 453ca77c1b6dba611771577da31472293c8f4e93 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 15:05:04 +0100 Subject: [PATCH 08/27] Network/SocketImpl: Fix Send causing a SocketError_Internal status on non-blocking sockets --- src/Nazara/Network/Posix/SocketImpl.cpp | 36 +++++++++++++++++++---- src/Nazara/Network/Win32/SocketImpl.cpp | 38 +++++++++++++++++++++---- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index b41895a42..257a1c3bc 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -562,10 +562,22 @@ namespace Nz int byteSent = send(handle, reinterpret_cast(buffer), length, 0); if (byteSent == SOCKET_ERROR) { - if (error) - *error = TranslateErrnoToResolveError(GetLastErrorCode()); + int errorCode = GetLastErrorCode(); - return false; //< Error + switch (errorCode) + { + case EWOULDBLOCK: + byteSent = 0; + break; + + default: + { + if (error) + *error = TranslateErrnoToResolveError(errorCode); + + return false; //< Error + } + } } if (sent) @@ -639,10 +651,22 @@ namespace Nz int byteSent = sendto(handle, reinterpret_cast(buffer), length, 0, reinterpret_cast(nameBuffer.data()), bufferLength); if (byteSent == SOCKET_ERROR) { - if (error) - *error = TranslateErrnoToResolveError(GetLastErrorCode()); + int errorCode = GetLastErrorCode(); - return false; //< Error + switch (errorCode) + { + case EWOULDBLOCK: + byteSent = 0; + break; + + default: + { + if (error) + *error = TranslateErrnoToResolveError(errorCode); + + return false; //< Error + } + } } if (sent) diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 5c4bdaa0c..32404f53a 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -594,10 +594,23 @@ namespace Nz int byteSent = send(handle, reinterpret_cast(buffer), length, 0); if (byteSent == SOCKET_ERROR) { - if (error) - *error = TranslateWSAErrorToSocketError(WSAGetLastError()); + int errorCode = WSAGetLastError(); + switch (errorCode) + { + case WSAEWOULDBLOCK: + { + byteSent = 0; + break; + } - return false; //< Error + default: + { + if (error) + *error = TranslateWSAErrorToSocketError(errorCode); + + return false; //< Error + } + } } if (sent) @@ -667,10 +680,23 @@ namespace Nz int byteSent = sendto(handle, reinterpret_cast(buffer), length, 0, reinterpret_cast(nameBuffer.data()), bufferLength); if (byteSent == SOCKET_ERROR) { - if (error) - *error = TranslateWSAErrorToSocketError(WSAGetLastError()); + int errorCode = WSAGetLastError(); + switch (errorCode) + { + case WSAEWOULDBLOCK: + { + byteSent = 0; + break; + } - return false; //< Error + default: + { + if (error) + *error = TranslateWSAErrorToSocketError(errorCode); + + return false; //< Error + } + } } if (sent) From d8b7ff9fa635c7b4d538e1e1411682c6b4f3de4d Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 15:05:26 +0100 Subject: [PATCH 09/27] Network/SocketImpl: Fix possible code errors (Posix) --- src/Nazara/Network/Posix/SocketImpl.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 257a1c3bc..2897a99fc 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -464,6 +464,9 @@ namespace Nz if (byteRead == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); + if (errorCode == EAGAIN) + errorCode = EWOULDBLOCK; + switch (errorCode) { case EWOULDBLOCK: @@ -513,6 +516,9 @@ namespace Nz if (byteRead == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); + if (errorCode == EAGAIN) + errorCode = EWOULDBLOCK; + switch (errorCode) { case EWOULDBLOCK: @@ -563,6 +569,8 @@ namespace Nz if (byteSent == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); + if (errorCode == EAGAIN) + errorCode = EWOULDBLOCK; switch (errorCode) { @@ -595,7 +603,7 @@ namespace Nz NazaraAssert(buffers && bufferCount > 0, "Invalid buffers"); StackAllocation memory = NazaraStackAllocation(bufferCount * sizeof(iovec)); - iovec* sysBuffers = static_cast(memory.GetPtr()); + struct iovec* sysBuffers = static_cast(memory.GetPtr()); for (std::size_t i = 0; i < bufferCount; ++i) { sysBuffers[i].iov_base = buffers[i].data; @@ -611,16 +619,19 @@ namespace Nz msgHdr.msg_iov = sysBuffers; msgHdr.msg_iovlen = static_cast(bufferCount); - int sentLength = sendmsg (socket, &msgHdr, MSG_NOSIGNAL); + int sentLength = sendmsg(socket, &msgHdr, MSG_NOSIGNAL); if (byteSent == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); + if (errorCode == EAGAIN) + errorCode = EWOULDBLOCK; + switch (errorCode) { case EWOULDBLOCK: byteSent = 0; break; - + default: { if (error) @@ -652,6 +663,8 @@ namespace Nz if (byteSent == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); + if (errorCode == EAGAIN) + errorCode = EWOULDBLOCK; switch (errorCode) { From 348942106450571c3e243bbb91c402b786551d18 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 15:08:26 +0100 Subject: [PATCH 10/27] Network/UdpSocket: Fix UdpSocket::Receive failing when peers suddenly closes its socket --- src/Nazara/Network/UdpSocket.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Nazara/Network/UdpSocket.cpp b/src/Nazara/Network/UdpSocket.cpp index c13dee343..145257afc 100644 --- a/src/Nazara/Network/UdpSocket.cpp +++ b/src/Nazara/Network/UdpSocket.cpp @@ -93,7 +93,18 @@ namespace Nz int read; if (!SocketImpl::ReceiveFrom(m_handle, buffer, static_cast(size), from, &read, &m_lastError)) - return false; + { + switch (m_lastError) + { + case SocketError_ConnectionClosed: + m_lastError = SocketError_NoError; + read = 0; + break; + + default: + return false; + } + } if (received) *received = read; From 86ae60b6c2d1be933d42909272396fdf7a0f148c Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 16:07:41 +0100 Subject: [PATCH 11/27] Network: Fix compilation --- include/Nazara/Network/Enums.hpp | 2 ++ src/Nazara/Network/Posix/SocketImpl.hpp | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/Nazara/Network/Enums.hpp b/include/Nazara/Network/Enums.hpp index 7dccd7dd1..f80ba6cd9 100644 --- a/include/Nazara/Network/Enums.hpp +++ b/include/Nazara/Network/Enums.hpp @@ -7,6 +7,8 @@ #ifndef NAZARA_ENUMS_NETWORK_HPP #define NAZARA_ENUMS_NETWORK_HPP +#include + namespace Nz { enum NetCode : UInt16 diff --git a/src/Nazara/Network/Posix/SocketImpl.hpp b/src/Nazara/Network/Posix/SocketImpl.hpp index e90d4cc74..7ee2e24f6 100644 --- a/src/Nazara/Network/Posix/SocketImpl.hpp +++ b/src/Nazara/Network/Posix/SocketImpl.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #define NAZARA_NETWORK_POLL_SUPPORT 1 @@ -88,4 +89,4 @@ namespace Nz }; } -#endif // NAZARA_SOCKETIMPL_HPP \ No newline at end of file +#endif // NAZARA_SOCKETIMPL_HPP From 90237186b5a78ff4755600fd264f4b439f9c3916 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 16:25:48 +0100 Subject: [PATCH 12/27] Network/SocketImpl: Fix missing include --- src/Nazara/Network/Posix/SocketImpl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 2897a99fc..baaa8a0d0 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include From 31ebe5983e84bba1f9c894111e7169bf8cddd865 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 16:31:41 +0100 Subject: [PATCH 13/27] Network: Fix typo.. --- src/Nazara/Network/Posix/SocketImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index baaa8a0d0..19da49c89 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include From 7602b4a041ac3ab01557c2ef337fb730293ba399 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 16:37:16 +0100 Subject: [PATCH 14/27] Network/SocketImpl: Fix typo --- src/Nazara/Network/Posix/SocketImpl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 19da49c89..3b7f9bccb 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -611,12 +611,12 @@ namespace Nz sysBuffers[i].iov_len = buffers[i].dataLength; } - struct msghdr header; - std::memset(&header, 0, sizeof(header); + struct msghdr msgHdr; + std::memset(&msgHdr, 0, sizeof(header)); IpAddressImpl::SockAddrBuffer nameBuffer; - header.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data()); - header.msg_name = nameBuffer.data(); + msgHdr.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data()); + msgHdr.msg_name = nameBuffer.data(); msgHdr.msg_iov = sysBuffers; msgHdr.msg_iovlen = static_cast(bufferCount); From 80442924c1c38b3eb14777ae5d44d2442c6debfb Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 16:43:54 +0100 Subject: [PATCH 15/27] Network/SocketImpl: Fix code, once more --- src/Nazara/Network/Posix/SocketImpl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 3b7f9bccb..a75a0df35 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -612,7 +612,7 @@ namespace Nz } struct msghdr msgHdr; - std::memset(&msgHdr, 0, sizeof(header)); + std::memset(&msgHdr, 0, sizeof(msgHdr)); IpAddressImpl::SockAddrBuffer nameBuffer; msgHdr.msg_namelen = IpAddressImpl::ToSockAddr(to, nameBuffer.data()); @@ -620,7 +620,7 @@ namespace Nz msgHdr.msg_iov = sysBuffers; msgHdr.msg_iovlen = static_cast(bufferCount); - int sentLength = sendmsg(socket, &msgHdr, MSG_NOSIGNAL); + int byteSent = sendmsg(socket, &msgHdr, MSG_NOSIGNAL); if (byteSent == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); From 42d5f849f7331ce4b3f8034098d74de41c3a9932 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 27 Jan 2017 16:49:09 +0100 Subject: [PATCH 16/27] Network/SocketImpl: Okay, I promise to try to compile myself next time --- src/Nazara/Network/Posix/SocketImpl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index a75a0df35..be6f84581 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -620,7 +620,7 @@ namespace Nz msgHdr.msg_iov = sysBuffers; msgHdr.msg_iovlen = static_cast(bufferCount); - int byteSent = sendmsg(socket, &msgHdr, MSG_NOSIGNAL); + int byteSent = sendmsg(handle, &msgHdr, MSG_NOSIGNAL); if (byteSent == SOCKET_ERROR) { int errorCode = GetLastErrorCode(); From ed8deed23c9d41b65d1ddc96a3b0a295ab5d9cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 1 Feb 2017 17:52:32 +0100 Subject: [PATCH 17/27] Core/MemoryHelper: Add PlacementDestroy --- include/Nazara/Core/MemoryHelper.hpp | 5 ++++- include/Nazara/Core/MemoryHelper.inl | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Core/MemoryHelper.hpp b/include/Nazara/Core/MemoryHelper.hpp index 6f53a012f..dc1bcc475 100644 --- a/include/Nazara/Core/MemoryHelper.hpp +++ b/include/Nazara/Core/MemoryHelper.hpp @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 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 @@ -38,6 +38,9 @@ namespace Nz template T* PlacementNew(T* ptr, Args&&... args); + template + void PlacementDestroy(T* ptr); + class StackAllocation { public: diff --git a/include/Nazara/Core/MemoryHelper.inl b/include/Nazara/Core/MemoryHelper.inl index f7380e1b8..dcee8ca4e 100644 --- a/include/Nazara/Core/MemoryHelper.inl +++ b/include/Nazara/Core/MemoryHelper.inl @@ -1,4 +1,4 @@ -// Copyright (C) 2017 Jérôme Leclercq +// Copyright (C) 2017 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 @@ -64,6 +64,17 @@ namespace Nz return new (ptr) T(std::forward(args)...); } + /*! + * \brief Calls the object destructor explicitly + * + * \param ptr Pointer to a previously constructed pointer on raw memory + */ + template + void PlacementDestroy(T* ptr) + { + ptr->~T(); + } + /*! * \ingroup core * \class Nz::StackAllocation From 9c66711a5362aa2c55a4012e761f890120ad5482 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 1 Feb 2017 20:02:12 +0100 Subject: [PATCH 18/27] Update version --- include/Nazara/Prerequesites.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Nazara/Prerequesites.hpp b/include/Nazara/Prerequesites.hpp index 13a044f68..0ac6b0fae 100644 --- a/include/Nazara/Prerequesites.hpp +++ b/include/Nazara/Prerequesites.hpp @@ -77,8 +77,8 @@ // Nazara version macro #define NAZARA_VERSION_MAJOR 0 -#define NAZARA_VERSION_MINOR 2 -#define NAZARA_VERSION_PATCH 1 +#define NAZARA_VERSION_MINOR 3 +#define NAZARA_VERSION_PATCH 0 #include From 2518a3939ff54d84538ce93c0c8ee8ac0c1fa388 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 1 Feb 2017 20:54:25 +0100 Subject: [PATCH 19/27] Update documentation version --- Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile b/Doxyfile index 04a327a38..116ba2c2a 100644 --- a/Doxyfile +++ b/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "Nazara Engine" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 0.2 +PROJECT_NUMBER = 0.3 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a From 1a677387d1facf09a4df0578ed1b25eafa7dec4f Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 7 Feb 2017 20:12:31 +0100 Subject: [PATCH 20/27] Noise/NoiseBase: Replace default_random_engine by mt19937 --- include/Nazara/Noise/NoiseBase.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Nazara/Noise/NoiseBase.hpp b/include/Nazara/Noise/NoiseBase.hpp index 744070e26..cdf068083 100644 --- a/include/Nazara/Noise/NoiseBase.hpp +++ b/include/Nazara/Noise/NoiseBase.hpp @@ -40,7 +40,7 @@ namespace Nz static std::array s_gradients4; private: - std::default_random_engine m_randomEngine; + std::mt19937 m_randomEngine; }; } From 4df5ec776cc40a4872c5a353402aa0fe0b24a7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leclercq?= Date: Wed, 8 Feb 2017 16:27:55 +0100 Subject: [PATCH 21/27] Sdk/Entity: Fix entity destruction not calling Component::OnDetached --- SDK/src/NDK/Entity.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SDK/src/NDK/Entity.cpp b/SDK/src/NDK/Entity.cpp index ce72aca62..d88556a31 100644 --- a/SDK/src/NDK/Entity.cpp +++ b/SDK/src/NDK/Entity.cpp @@ -158,11 +158,16 @@ namespace Ndk } m_systemBits.Clear(); - UnregisterAllHandles(); + // We properly destroy each component + for (std::size_t i = m_componentBits.FindFirst(); i != m_componentBits.npos; i = m_componentBits.FindNext(i)) + m_components[i]->SetEntity(nullptr); m_components.clear(); m_componentBits.Reset(); + // And then free every handle + UnregisterAllHandles(); + m_valid = false; } From ab6e9d3b86eb5c3793541f12705622c6c61ad4fb Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 10 Feb 2017 15:20:43 +0100 Subject: [PATCH 22/27] Core/String: Fix FormatVA bug --- src/Nazara/Core/String.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Nazara/Core/String.cpp b/src/Nazara/Core/String.cpp index a0bca5d64..7ea8c7df2 100644 --- a/src/Nazara/Core/String.cpp +++ b/src/Nazara/Core/String.cpp @@ -5102,10 +5102,14 @@ namespace Nz */ String String::FormatVA(const char* format, va_list args) { + // Copy va_list to use it twice + va_list args2; + va_copy(args2, args); + std::size_t length = std::vsnprintf(nullptr, 0, format, args); auto str = std::make_shared(length); - std::vsnprintf(str->string.get(), length + 1, format, args); + std::vsnprintf(str->string.get(), length + 1, format, args2); return String(std::move(str)); } From 212f3eddf00bef96944060520f803692767d0c29 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 12 Feb 2017 02:10:37 +0100 Subject: [PATCH 23/27] Network/UdpSocket: Fix documentation [skip ci] --- src/Nazara/Network/UdpSocket.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Nazara/Network/UdpSocket.cpp b/src/Nazara/Network/UdpSocket.cpp index 145257afc..bc86f8401 100644 --- a/src/Nazara/Network/UdpSocket.cpp +++ b/src/Nazara/Network/UdpSocket.cpp @@ -17,6 +17,12 @@ namespace Nz { + /*! + * \ingroup network + * \class Nz::UdpSocket + * \brief Network class that represents a UDP socket, allowing for sending/receiving datagrams. + */ + /*! * \brief Binds a specific IpAddress * \return State of the socket From 7cc11245f9e5916bc3e1ec42e6ced8c3cb31c1c9 Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 15 Feb 2017 07:13:00 +0100 Subject: [PATCH 24/27] Core/Flags: Move external operators to the global scope Fixes usage of those operators outside of the Nz namespace, global scoping is not an issue thanks to the enable_if --- include/Nazara/Core/Flags.hpp | 10 +-- include/Nazara/Core/Flags.inl | 115 +++++++++++++++++----------------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/include/Nazara/Core/Flags.hpp b/include/Nazara/Core/Flags.hpp index f356a04a5..cb336def6 100644 --- a/include/Nazara/Core/Flags.hpp +++ b/include/Nazara/Core/Flags.hpp @@ -54,13 +54,13 @@ namespace Nz private: BitField m_value; }; - - template constexpr std::enable_if_t::value, Flags> operator~(E lhs); - template constexpr std::enable_if_t::value, Flags> operator|(E lhs, E rhs); - template constexpr std::enable_if_t::value, Flags> operator&(E lhs, E rhs); - template constexpr std::enable_if_t::value, Flags> operator^(E lhs, E rhs); } +template constexpr std::enable_if_t::value, Nz::Flags> operator~(E lhs); +template constexpr std::enable_if_t::value, Nz::Flags> operator|(E lhs, E rhs); +template constexpr std::enable_if_t::value, Nz::Flags> operator&(E lhs, E rhs); +template constexpr std::enable_if_t::value, Nz::Flags> operator^(E lhs, E rhs); + #include #endif // NAZARA_FLAGS_HPP diff --git a/include/Nazara/Core/Flags.inl b/include/Nazara/Core/Flags.inl index 57ffd9e7e..973da958d 100644 --- a/include/Nazara/Core/Flags.inl +++ b/include/Nazara/Core/Flags.inl @@ -209,68 +209,67 @@ namespace Nz { return 1U << static_cast(enumValue); } +} +/*! +* \brief Override binary NOT operator on enum to turns into a Flags object. +* \return A Flags object with reversed bits. +* +* \param lhs Enumeration value to reverse. +* +* Returns a Flags object with all state enabled except for the enum one. +*/ +template +constexpr std::enable_if_t::value, Nz::Flags> operator~(E lhs) +{ + return ~Nz::Flags(lhs); +} - /*! - * \brief Override binary NOT operator on enum to turns into a Flags object. - * \return A Flags object with reversed bits. - * - * \param lhs Enumeration value to reverse. - * - * Returns a Flags object with all state enabled except for the enum one. - */ - template - constexpr std::enable_if_t::value, Flags> operator~(E lhs) - { - return ~Flags(lhs); - } +/*! +* \brief Override binary OR operator on enum to turns into a Flags object. +* \return A Flags object with combined enum states. +* +* \param lhs First enumeration value to combine. +* \param rhs Second enumeration value to combine. +* +* Returns a Flags object with combined states from the two enumeration values. +*/ +template +constexpr std::enable_if_t::value, Nz::Flags> operator|(E lhs, E rhs) +{ + return Nz::Flags(lhs) | rhs; +} - /*! - * \brief Override binary OR operator on enum to turns into a Flags object. - * \return A Flags object with combined enum states. - * - * \param lhs First enumeration value to combine. - * \param rhs Second enumeration value to combine. - * - * Returns a Flags object with combined states from the two enumeration values. - */ - template - constexpr std::enable_if_t::value, Flags> operator|(E lhs, E rhs) - { - return Flags(lhs) | rhs; - } +/*! +* \brief Override binary AND operator on enum to turns into a Flags object. +* \return A Flags object with compare enum states. +* +* \param lhs First enumeration value to compare. +* \param rhs Second enumeration value to compare. +* +* Returns a Flags object with compared states from the two enumeration values. +* In this case, only one flag will be enabled if both enumeration values are the same. +*/ +template +constexpr std::enable_if_t::value, Nz::Flags> operator&(E lhs, E rhs) +{ + return Nz::Flags(lhs) & rhs; +} - /*! - * \brief Override binary AND operator on enum to turns into a Flags object. - * \return A Flags object with compare enum states. - * - * \param lhs First enumeration value to compare. - * \param rhs Second enumeration value to compare. - * - * Returns a Flags object with compared states from the two enumeration values. - * In this case, only one flag will be enabled if both enumeration values are the same. - */ - template - constexpr std::enable_if_t::value, Flags> operator&(E lhs, E rhs) - { - return Flags(lhs) & rhs; - } - - /*! - * \brief Override binary XOR operator on enum to turns into a Flags object. - * \return A Flags object with XORed enum states. - * - * \param lhs First enumeration value to compare. - * \param rhs Second enumeration value to compare. - * - * Returns a Flags object with XORed states from the two enumeration values. - * In this case, two flags will be enabled if both the enumeration values are different. - */ - template - constexpr std::enable_if_t::value, Flags> operator^(E lhs, E rhs) - { - return Flags(lhs) ^ rhs; - } +/*! +* \brief Override binary XOR operator on enum to turns into a Flags object. +* \return A Flags object with XORed enum states. +* +* \param lhs First enumeration value to compare. +* \param rhs Second enumeration value to compare. +* +* Returns a Flags object with XORed states from the two enumeration values. +* In this case, two flags will be enabled if both the enumeration values are different. +*/ +template +constexpr std::enable_if_t::value, Nz::Flags> operator^(E lhs, E rhs) +{ + return Nz::Flags(lhs) ^ rhs; } #include From dc158d06a8c8bcc591e19f174b011bf4a0ed1ef4 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 17 Feb 2017 00:21:28 +0100 Subject: [PATCH 25/27] Fix warnings reported by Clang --- src/Nazara/Graphics/DepthRenderTechnique.cpp | 2 +- .../Graphics/ForwardRenderTechnique.cpp | 2 - src/Nazara/Graphics/ParticleGroup.cpp | 8 ++-- src/Nazara/Utility/Image.cpp | 1 - src/Nazara/Utility/IndexBuffer.cpp | 4 +- src/Nazara/Utility/SimpleTextDrawer.cpp | 4 +- src/Nazara/Utility/VertexBuffer.cpp | 4 +- src/Nazara/Utility/X11/CursorImpl.cpp | 40 ++++++++++--------- src/Nazara/Utility/X11/Display.cpp | 6 +-- src/Nazara/Utility/X11/WindowImpl.cpp | 6 +-- src/Nazara/Utility/X11/WindowImpl.hpp | 1 - 11 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/Nazara/Graphics/DepthRenderTechnique.cpp b/src/Nazara/Graphics/DepthRenderTechnique.cpp index d58975d7f..13f8b30af 100644 --- a/src/Nazara/Graphics/DepthRenderTechnique.cpp +++ b/src/Nazara/Graphics/DepthRenderTechnique.cpp @@ -68,7 +68,7 @@ namespace Nz * \param sceneData Data of the scene */ - void DepthRenderTechnique::Clear(const SceneData& sceneData) const + void DepthRenderTechnique::Clear(const SceneData& /*sceneData*/) const { Renderer::Enable(RendererParameter_DepthBuffer, true); Renderer::Enable(RendererParameter_DepthWrite, true); diff --git a/src/Nazara/Graphics/ForwardRenderTechnique.cpp b/src/Nazara/Graphics/ForwardRenderTechnique.cpp index c0493e74b..543587b3d 100644 --- a/src/Nazara/Graphics/ForwardRenderTechnique.cpp +++ b/src/Nazara/Graphics/ForwardRenderTechnique.cpp @@ -990,7 +990,6 @@ namespace Nz if (uniforms.locations.shadowMapping != -1) shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr); - unsigned int textureUnit = Material::GetTextureUnit(static_cast(TextureMap_ShadowCube_1 + index)); if (light.shadowMap) { unsigned int textureUnitCube = Material::GetTextureUnit(static_cast(TextureMap_ShadowCube_1 + index)); @@ -1014,7 +1013,6 @@ namespace Nz if (uniforms.locations.shadowMapping != -1) shader->SendBoolean(uniforms.locations.shadowMapping + uniformOffset, light.shadowMap != nullptr); - unsigned int textureUnit = Material::GetTextureUnit(static_cast(TextureMap_Shadow2D_1 + index)); if (light.shadowMap) { unsigned int textureUnit2D = Material::GetTextureUnit(static_cast(TextureMap_Shadow2D_1 + index)); diff --git a/src/Nazara/Graphics/ParticleGroup.cpp b/src/Nazara/Graphics/ParticleGroup.cpp index 08743a58e..ab9f6568c 100644 --- a/src/Nazara/Graphics/ParticleGroup.cpp +++ b/src/Nazara/Graphics/ParticleGroup.cpp @@ -40,9 +40,9 @@ namespace Nz ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration) : m_declaration(std::move(declaration)), - m_processing(false), m_maxParticleCount(maxParticleCount), - m_particleCount(0) + m_particleCount(0), + m_processing(false) { // In case of error, the constructor can only throw an exception ErrorFlags flags(ErrorFlag_ThrowException, true); @@ -64,10 +64,10 @@ namespace Nz m_generators(system.m_generators), m_declaration(system.m_declaration), m_renderer(system.m_renderer), - m_processing(false), m_maxParticleCount(system.m_maxParticleCount), m_particleCount(system.m_particleCount), - m_particleSize(system.m_particleSize) + m_particleSize(system.m_particleSize), + m_processing(false) { ErrorFlags flags(ErrorFlag_ThrowException, true); diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index bdfe57007..15d9133fe 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -835,7 +835,6 @@ namespace Nz if (!PixelFormat::IsCompressed(m_sharedImage->format)) { const PixelFormatInfo& info = PixelFormat::GetInfo(m_sharedImage->format); - const UInt8* pixel = GetConstPixels(); Bitset<> workingBitset; std::size_t pixelCount = m_sharedImage->width * m_sharedImage->height * ((m_sharedImage->type == ImageType_Cubemap) ? 6 : m_sharedImage->depth); diff --git a/src/Nazara/Utility/IndexBuffer.cpp b/src/Nazara/Utility/IndexBuffer.cpp index ed49535cd..306fffb7f 100644 --- a/src/Nazara/Utility/IndexBuffer.cpp +++ b/src/Nazara/Utility/IndexBuffer.cpp @@ -35,10 +35,10 @@ namespace Nz IndexBuffer::IndexBuffer(const IndexBuffer& indexBuffer) : RefCounted(), m_buffer(indexBuffer.m_buffer), - m_largeIndices(indexBuffer.m_largeIndices), m_endOffset(indexBuffer.m_endOffset), m_indexCount(indexBuffer.m_indexCount), - m_startOffset(indexBuffer.m_startOffset) + m_startOffset(indexBuffer.m_startOffset), + m_largeIndices(indexBuffer.m_largeIndices) { } diff --git a/src/Nazara/Utility/SimpleTextDrawer.cpp b/src/Nazara/Utility/SimpleTextDrawer.cpp index 1b8c41653..fb153185c 100644 --- a/src/Nazara/Utility/SimpleTextDrawer.cpp +++ b/src/Nazara/Utility/SimpleTextDrawer.cpp @@ -365,12 +365,14 @@ namespace Nz { case '\n': { + // Extend the line bounding rect to the last glyph it contains, thus extending upon all glyphs of the line if (!m_glyphs.empty()) { - Glyph& glyph = m_glyphs.back(); + Glyph& lastGlyph = m_glyphs.back(); m_lines.back().bounds.ExtendTo(glyph.bounds); } + // Reset cursor advance = 0; m_drawPos.x = 0; m_drawPos.y += sizeInfo.lineHeight; diff --git a/src/Nazara/Utility/VertexBuffer.cpp b/src/Nazara/Utility/VertexBuffer.cpp index 371ba2efa..f06d46ed0 100644 --- a/src/Nazara/Utility/VertexBuffer.cpp +++ b/src/Nazara/Utility/VertexBuffer.cpp @@ -31,10 +31,10 @@ namespace Nz VertexBuffer::VertexBuffer(const VertexBuffer& vertexBuffer) : RefCounted(), m_buffer(vertexBuffer.m_buffer), - m_vertexDeclaration(vertexBuffer.m_vertexDeclaration), m_endOffset(vertexBuffer.m_endOffset), m_startOffset(vertexBuffer.m_startOffset), - m_vertexCount(vertexBuffer.m_vertexCount) + m_vertexCount(vertexBuffer.m_vertexCount), + m_vertexDeclaration(vertexBuffer.m_vertexDeclaration) { } diff --git a/src/Nazara/Utility/X11/CursorImpl.cpp b/src/Nazara/Utility/X11/CursorImpl.cpp index 2925b2b6d..94f10629e 100644 --- a/src/Nazara/Utility/X11/CursorImpl.cpp +++ b/src/Nazara/Utility/X11/CursorImpl.cpp @@ -232,25 +232,27 @@ namespace Nz std::array CursorImpl::s_systemCursorIds = { - // http://gnome-look.org/content/preview.php?preview=1&id=128170&file1=128170-1.png&file2=&file3=&name=Dummy+X11+cursors&PHPSESSID=6 - "crosshair", // SystemCursor_Crosshair - "left_ptr", // SystemCursor_Default - "hand", // SystemCursor_Hand - "help", // SystemCursor_Help - "fleur", // SystemCursor_Move - nullptr, // SystemCursor_None - "hand", // SystemCursor_Pointer - "watch", // SystemCursor_Progress - "right_side", // SystemCursor_ResizeE - "top_side", // SystemCursor_ResizeN - "top_right_corner", // SystemCursor_ResizeNE - "top_left_corner", // SystemCursor_ResizeNW - "bottom_side", // SystemCursor_ResizeS - "bottom_right_corner", // SystemCursor_ResizeSE - "bottom_left_corner", // SystemCursor_ResizeSW - "left_side", // SystemCursor_ResizeW - "xterm", // SystemCursor_Text - "watch" // SystemCursor_Wait + { + // http://gnome-look.org/content/preview.php?preview=1&id=128170&file1=128170-1.png&file2=&file3=&name=Dummy+X11+cursors&PHPSESSID=6 + "crosshair", // SystemCursor_Crosshair + "left_ptr", // SystemCursor_Default + "hand", // SystemCursor_Hand + "help", // SystemCursor_Help + "fleur", // SystemCursor_Move + nullptr, // SystemCursor_None + "hand", // SystemCursor_Pointer + "watch", // SystemCursor_Progress + "right_side", // SystemCursor_ResizeE + "top_side", // SystemCursor_ResizeN + "top_right_corner", // SystemCursor_ResizeNE + "top_left_corner", // SystemCursor_ResizeNW + "bottom_side", // SystemCursor_ResizeS + "bottom_right_corner", // SystemCursor_ResizeSE + "bottom_left_corner", // SystemCursor_ResizeSW + "left_side", // SystemCursor_ResizeW + "xterm", // SystemCursor_Text + "watch" // SystemCursor_Wait + } }; static_assert(SystemCursor_Max + 1 == 18, "System cursor array is incomplete"); diff --git a/src/Nazara/Utility/X11/Display.cpp b/src/Nazara/Utility/X11/Display.cpp index 8a9ff719c..1232cea64 100644 --- a/src/Nazara/Utility/X11/Display.cpp +++ b/src/Nazara/Utility/X11/Display.cpp @@ -229,14 +229,14 @@ namespace Nz return screen_nbr; } - xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screen_nbr) + xcb_screen_t* X11::XCBScreenOfDisplay(xcb_connection_t* connection, int screenIndex) { NazaraAssert(connection == sharedConnection, "The model is meant for one connection to X11 server"); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(xcb_get_setup(connection)); - for (; iter.rem; --screen_nbr, xcb_screen_next (&iter)) + for (; iter.rem; --screenIndex, xcb_screen_next (&iter)) { - if (screen_nbr == 0) + if (screenIndex == 0) return iter.data; } diff --git a/src/Nazara/Utility/X11/WindowImpl.cpp b/src/Nazara/Utility/X11/WindowImpl.cpp index d0cf3da59..884244287 100644 --- a/src/Nazara/Utility/X11/WindowImpl.cpp +++ b/src/Nazara/Utility/X11/WindowImpl.cpp @@ -58,7 +58,6 @@ namespace Nz m_style(0), m_parent(parent), m_smoothScrolling(false), - m_scrolling(0), m_mousePos(0, 0), m_keyRepeat(true) { @@ -1134,7 +1133,6 @@ namespace Nz // if (std::isprint(codePoint)) Is not working ? + handle combining ? { - WindowEvent event; event.type = Nz::WindowEventType_TextEntered; event.text.character = codePoint; event.text.repeated = false; @@ -1396,7 +1394,7 @@ namespace Nz hints.functions |= MWM_FUNC_CLOSE; } - ScopedXCB error(xcb_request_check( + ScopedXCB propertyError(xcb_request_check( connection, xcb_change_property_checked( connection, @@ -1410,7 +1408,7 @@ namespace Nz ) )); - if (error) + if (propertyError) NazaraError("xcb_change_property failed, could not set window hints"); } else diff --git a/src/Nazara/Utility/X11/WindowImpl.hpp b/src/Nazara/Utility/X11/WindowImpl.hpp index 8ce44f178..d82ff06cc 100644 --- a/src/Nazara/Utility/X11/WindowImpl.hpp +++ b/src/Nazara/Utility/X11/WindowImpl.hpp @@ -111,7 +111,6 @@ namespace Nz bool m_ownsWindow; bool m_smoothScrolling; bool m_threadActive; - short m_scrolling; Vector2i m_mousePos; bool m_keyRepeat; From a4100d5b4e210f70a105d5cd728584e9f6014f9f Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 17 Feb 2017 00:21:40 +0100 Subject: [PATCH 26/27] Utility/X11: Fix crash at startup --- src/Nazara/Utility/X11/CursorImpl.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Nazara/Utility/X11/CursorImpl.cpp b/src/Nazara/Utility/X11/CursorImpl.cpp index 94f10629e..aa59290b3 100644 --- a/src/Nazara/Utility/X11/CursorImpl.cpp +++ b/src/Nazara/Utility/X11/CursorImpl.cpp @@ -164,8 +164,19 @@ namespace Nz ScopedXCBConnection connection; xcb_screen_t* screen = X11::XCBDefaultScreen(connection); - if (xcb_cursor_context_new(connection, screen, &m_cursorContext) >= 0) - m_cursor = xcb_cursor_load_cursor(m_cursorContext, s_systemCursorIds[cursor]); + const char* cursorName = s_systemCursorIds[cursor]; + if (cursorName) + { + if (xcb_cursor_context_new(connection, screen, &m_cursorContext) >= 0) + m_cursor = xcb_cursor_load_cursor(m_cursorContext, cursorName); + else + { + NazaraError("Failed to create cursor context"); + return false; + } + } + else + m_cursor = s_hiddenCursor; return true; } From ee9712fdcdf41fa9a10868bf4f151497ceb16a3d Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 17 Feb 2017 00:38:44 +0100 Subject: [PATCH 27/27] Some more warning fixes --- src/Nazara/Renderer/RenderTexture.cpp | 20 +++++++++---------- .../Renderer/UberShaderPreprocessor.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Nazara/Renderer/RenderTexture.cpp b/src/Nazara/Renderer/RenderTexture.cpp index aa32dd447..8ae1a4bb1 100644 --- a/src/Nazara/Renderer/RenderTexture.cpp +++ b/src/Nazara/Renderer/RenderTexture.cpp @@ -36,7 +36,7 @@ namespace Nz unsigned int width; }; - unsigned int attachmentIndex[AttachmentPoint_Max+1] = + unsigned int s_attachmentIndex[AttachmentPoint_Max+1] = { 3, // AttachmentPoint_Color 0, // AttachmentPoint_Depth @@ -117,7 +117,7 @@ namespace Nz return false; } - unsigned int depthStencilIndex = attachmentIndex[AttachmentPoint_DepthStencil]; + unsigned int depthStencilIndex = s_attachmentIndex[AttachmentPoint_DepthStencil]; if (m_impl->attachments.size() > depthStencilIndex && m_impl->attachments[depthStencilIndex].isUsed) { if (attachmentPoint == AttachmentPoint_Depth) @@ -154,7 +154,7 @@ namespace Nz Unlock(); - unsigned int attachIndex = attachmentIndex[attachmentPoint] + index; + unsigned int attachIndex = s_attachmentIndex[attachmentPoint] + index; if (attachIndex >= m_impl->attachments.size()) m_impl->attachments.resize(attachIndex+1); @@ -223,7 +223,7 @@ namespace Nz return false; } - unsigned int depthStencilIndex = attachmentIndex[AttachmentPoint_DepthStencil]; + unsigned int depthStencilIndex = s_attachmentIndex[AttachmentPoint_DepthStencil]; if (attachmentPoint == AttachmentPoint_Depth && m_impl->attachments.size() > depthStencilIndex && m_impl->attachments[depthStencilIndex].isUsed) { @@ -288,7 +288,7 @@ namespace Nz Unlock(); - unsigned int attachIndex = attachmentIndex[attachmentPoint] + index; + unsigned int attachIndex = s_attachmentIndex[attachmentPoint] + index; if (attachIndex >= m_impl->attachments.size()) m_impl->attachments.resize(attachIndex+1); @@ -394,7 +394,7 @@ namespace Nz } #endif - unsigned int attachIndex = attachmentIndex[attachmentPoint] + index; + unsigned int attachIndex = s_attachmentIndex[attachmentPoint] + index; if (attachIndex >= m_impl->attachments.size()) return; @@ -575,7 +575,7 @@ namespace Nz #if NAZARA_RENDERER_SAFE for (unsigned int i = 0; i < targetCount; ++i) { - unsigned int index = attachmentIndex[AttachmentPoint_Color] + targets[i]; + unsigned int index = s_attachmentIndex[AttachmentPoint_Color] + targets[i]; if (index >= m_impl->attachments.size() || !m_impl->attachments[index].isUsed) { NazaraError("Target " + String::Number(targets[i]) + " not attached"); @@ -598,7 +598,7 @@ namespace Nz #if NAZARA_RENDERER_SAFE for (UInt8 target : targets) { - unsigned int index = attachmentIndex[AttachmentPoint_Color] + target; + unsigned int index = s_attachmentIndex[AttachmentPoint_Color] + target; if (index >= m_impl->attachments.size() || !m_impl->attachments[index].isUsed) { NazaraError("Target " + String::Number(target) + " not attached"); @@ -752,7 +752,7 @@ namespace Nz for (UInt8 index : m_impl->colorTargets) { - Attachment& attachment = m_impl->attachments[attachmentIndex[AttachmentPoint_Color] + index]; + Attachment& attachment = m_impl->attachments[s_attachmentIndex[AttachmentPoint_Color] + index]; if (!attachment.isBuffer) attachment.texture->InvalidateMipmaps(); } @@ -833,7 +833,7 @@ namespace Nz m_impl->colorTargets.clear(); unsigned int colorIndex = 0; - for (unsigned int index = attachmentIndex[AttachmentPoint_Color]; index < m_impl->attachments.size(); ++index) + for (unsigned int index = s_attachmentIndex[AttachmentPoint_Color]; index < m_impl->attachments.size(); ++index) m_impl->colorTargets.push_back(colorIndex++); } diff --git a/src/Nazara/Renderer/UberShaderPreprocessor.cpp b/src/Nazara/Renderer/UberShaderPreprocessor.cpp index 6f838d6cf..b6d524645 100644 --- a/src/Nazara/Renderer/UberShaderPreprocessor.cpp +++ b/src/Nazara/Renderer/UberShaderPreprocessor.cpp @@ -93,7 +93,7 @@ namespace Nz } catch (const std::exception&) { - ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled); + ErrorFlags errFlags2(ErrorFlag_ThrowExceptionDisabled); NazaraError("Shader code failed to compile (" + stage.GetLog() + ")\n" + code.ToString()); throw;