diff --git a/include/Nazara/Core/Algorithm.inl b/include/Nazara/Core/Algorithm.inl index 3a163cd55..9b4e347fe 100644 --- a/include/Nazara/Core/Algorithm.inl +++ b/include/Nazara/Core/Algorithm.inl @@ -368,7 +368,7 @@ namespace Nz // Flush bits in case a writing is in progress context.FlushBits(); - if (context.endianness != Endianness_Unknown && context.endianness != GetPlatformEndianness()) + if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness()) SwapBytes(&value, sizeof(T)); return context.stream->Write(&value, sizeof(T)) == sizeof(T); @@ -447,7 +447,7 @@ namespace Nz if (context.stream->Read(value, sizeof(T)) == sizeof(T)) { - if (context.endianness != Endianness_Unknown && context.endianness != GetPlatformEndianness()) + if (context.endianness != Endianness::Unknown && context.endianness != GetPlatformEndianness()) SwapBytes(value, sizeof(T)); return true; diff --git a/include/Nazara/Core/Endianness.inl b/include/Nazara/Core/Endianness.inl index b3eca0b09..daae48586 100644 --- a/include/Nazara/Core/Endianness.inl +++ b/include/Nazara/Core/Endianness.inl @@ -15,9 +15,9 @@ namespace Nz inline constexpr Endianness GetPlatformEndianness() { #if defined(NAZARA_BIG_ENDIAN) - return Endianness_BigEndian; + return Endianness::BigEndian; #elif defined(NAZARA_LITTLE_ENDIAN) - return Endianness_LittleEndian; + return Endianness::LittleEndian; #endif } diff --git a/include/Nazara/Core/Enums.hpp b/include/Nazara/Core/Enums.hpp index 1df2b15e5..ecfef308b 100644 --- a/include/Nazara/Core/Enums.hpp +++ b/include/Nazara/Core/Enums.hpp @@ -11,193 +11,213 @@ namespace Nz { - enum CoordSys + enum class CoordSys { - CoordSys_Global, - CoordSys_Local, + Global, + Local, - CoordSys_Max = CoordSys_Local + Max = Local }; - enum CursorPosition + enum class CursorPosition { - CursorPosition_AtBegin, // beginning of the file - CursorPosition_AtCurrent, // Position of the cursor - CursorPosition_AtEnd, // End of the file + AtBegin, // beginning of the file + AtCurrent, // Position of the cursor + AtEnd, // End of the file - CursorPosition_Max = CursorPosition_AtEnd + Max = AtEnd }; - enum Endianness + enum class Endianness { - Endianness_Unknown = -1, + Unknown = -1, - Endianness_BigEndian, - Endianness_LittleEndian, + BigEndian, + LittleEndian, - Endianness_Max = Endianness_LittleEndian + Max = LittleEndian }; - enum ErrorFlag + enum class ErrorMode { - ErrorFlag_None = 0, + None, - ErrorFlag_Silent = 0x1, - ErrorFlag_SilentDisabled = 0x2, - ErrorFlag_ThrowException = 0x4, - ErrorFlag_ThrowExceptionDisabled = 0x8, + Silent, + SilentDisabled, + ThrowException, + ThrowExceptionDisabled, - ErrorFlag_Max = ErrorFlag_ThrowExceptionDisabled * 2 - 1 + Max = ThrowExceptionDisabled }; - enum ErrorType + template<> + struct EnumAsFlags { - ErrorType_AssertFailed, - ErrorType_Internal, - ErrorType_Normal, - ErrorType_Warning, - - ErrorType_Max = ErrorType_Warning + static constexpr ErrorMode max = ErrorMode::Max; }; - enum HashType - { - HashType_CRC32, - HashType_CRC64, - HashType_Fletcher16, - HashType_MD5, - HashType_SHA1, - HashType_SHA224, - HashType_SHA256, - HashType_SHA384, - HashType_SHA512, - HashType_Whirlpool, + using ErrorModeFlags = Flags; - HashType_Max = HashType_Whirlpool + enum class ErrorType + { + AssertFailed, + Internal, + Normal, + Warning, + + Max = Warning }; - enum OpenMode + constexpr std::size_t ErrorTypeCount = static_cast(ErrorType::Max) + 1; + + enum class HashType { - OpenMode_NotOpen, // Use the current mod of opening + CRC32, + CRC64, + Fletcher16, + MD5, + SHA1, + SHA224, + SHA256, + SHA384, + SHA512, + Whirlpool, - 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 + Max = Whirlpool + }; - OpenMode_Max = OpenMode_WriteOnly + constexpr std::size_t HashTypeCount = static_cast(HashType::Max) + 1; + + enum class OpenMode + { + NotOpen, // Use the current mod of opening + + Append, // Disable writing on existing parts and put the cursor at the end + Lock, // Disable modifying the file before it is open + MustExist, // Fail if the file doesn't exists, even if opened in write mode + ReadOnly, // Open in read only + Text, // Open in text mod + Truncate, // Create the file if it doesn't exist and empty it if it exists + WriteOnly, // Open in write only, create the file if it doesn't exist + + Max = WriteOnly }; template<> struct EnumAsFlags { - static constexpr OpenMode max = OpenMode_Max; + static constexpr OpenMode max = OpenMode::Max; }; using OpenModeFlags = Flags; - constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode_ReadOnly | OpenMode_WriteOnly; + constexpr OpenModeFlags OpenMode_ReadWrite = OpenMode::ReadOnly | OpenMode::WriteOnly; - enum ParameterType + enum class ParameterType { - ParameterType_Boolean, - ParameterType_Color, - ParameterType_Double, - ParameterType_Integer, - ParameterType_None, - ParameterType_Pointer, - ParameterType_String, - ParameterType_Userdata, + Boolean, + Color, + Double, + Integer, + None, + Pointer, + String, + Userdata, - ParameterType_Max = ParameterType_Userdata + Max = Userdata }; - enum Plugin + enum class Plugin { - Plugin_Assimp, + Assimp, - Plugin_Count + Max = Assimp }; - enum PrimitiveType - { - PrimitiveType_Box, - PrimitiveType_Cone, - PrimitiveType_Plane, - PrimitiveType_Sphere, + constexpr std::size_t PluginCount = static_cast(Plugin::Max) + 1; - PrimitiveType_Max = PrimitiveType_Sphere + enum class PrimitiveType + { + Box, + Cone, + Plane, + Sphere, + + Max = Sphere }; - enum ProcessorCap - { - ProcessorCap_x64, - ProcessorCap_AVX, - ProcessorCap_FMA3, - ProcessorCap_FMA4, - ProcessorCap_MMX, - ProcessorCap_XOP, - ProcessorCap_SSE, - ProcessorCap_SSE2, - ProcessorCap_SSE3, - ProcessorCap_SSSE3, - ProcessorCap_SSE41, - ProcessorCap_SSE42, - ProcessorCap_SSE4a, + constexpr std::size_t PrimitiveTypeCount = static_cast(PrimitiveType::Max) + 1; - ProcessorCap_Max = ProcessorCap_SSE4a + enum class ProcessorCap + { + x64, + AVX, + FMA3, + FMA4, + MMX, + XOP, + SSE, + SSE2, + SSE3, + SSSE3, + SSE41, + SSE42, + SSE4a, + + Max = SSE4a }; - enum ProcessorVendor + constexpr std::size_t ProcessorCapCount = static_cast(ProcessorCap::Max) + 1; + + enum class ProcessorVendor { - ProcessorVendor_Unknown = -1, + Unknown = -1, - ProcessorVendor_AMD, - ProcessorVendor_Centaur, - ProcessorVendor_Cyrix, - ProcessorVendor_Intel, - ProcessorVendor_KVM, - ProcessorVendor_HyperV, - ProcessorVendor_NSC, - ProcessorVendor_NexGen, - ProcessorVendor_Rise, - ProcessorVendor_SIS, - ProcessorVendor_Transmeta, - ProcessorVendor_UMC, - ProcessorVendor_VIA, - ProcessorVendor_VMware, - ProcessorVendor_Vortex, - ProcessorVendor_XenHVM, + AMD, + Centaur, + Cyrix, + Intel, + KVM, + HyperV, + NSC, + NexGen, + Rise, + SIS, + Transmeta, + UMC, + VIA, + VMware, + Vortex, + XenHVM, - ProcessorVendor_Max = ProcessorVendor_XenHVM + Max = XenHVM }; - enum SphereType - { - SphereType_Cubic, - SphereType_Ico, - SphereType_UV, + constexpr std::size_t ProcessorVendorCount = static_cast(ProcessorVendor::Max) + 1; - SphereType_Max = SphereType_UV + enum class SphereType + { + Cubic, + Ico, + UV, + + Max = UV }; - enum StreamOption + enum class StreamOption { - StreamOption_None, + None, - StreamOption_Sequential, - StreamOption_Text, + Sequential, + Text, - StreamOption_Max = StreamOption_Text + Max = Text }; template<> struct EnumAsFlags { - static constexpr StreamOption max = StreamOption_Max; + static constexpr StreamOption max = StreamOption::Max; }; using StreamOptionFlags = Flags; diff --git a/include/Nazara/Core/Error.hpp b/include/Nazara/Core/Error.hpp index 4ff2e229f..ef20ffd24 100644 --- a/include/Nazara/Core/Error.hpp +++ b/include/Nazara/Core/Error.hpp @@ -13,14 +13,14 @@ #include #if NAZARA_CORE_ENABLE_ASSERTS || defined(NAZARA_DEBUG) - #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType_AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION) + #define NazaraAssert(a, err) if (!(a)) Nz::Error::Trigger(Nz::ErrorType::AssertFailed, err, __LINE__, __FILE__, NAZARA_FUNCTION) #else #define NazaraAssert(a, err) for (;;) break #endif -#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType_Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION) -#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType_Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION) -#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType_Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION) +#define NazaraError(err) Nz::Error::Trigger(Nz::ErrorType::Normal, err, __LINE__, __FILE__, NAZARA_FUNCTION) +#define NazaraInternalError(err) Nz::Error::Trigger(Nz::ErrorType::Internal, err, __LINE__, __FILE__, NAZARA_FUNCTION) +#define NazaraWarning(err) Nz::Error::Trigger(Nz::ErrorType::Warning, err, __LINE__, __FILE__, NAZARA_FUNCTION) namespace Nz { @@ -30,12 +30,12 @@ namespace Nz Error() = delete; ~Error() = delete; - static UInt32 GetFlags(); + static ErrorModeFlags GetFlags(); static std::string GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr); static unsigned int GetLastSystemErrorCode(); static std::string GetLastSystemError(unsigned int code = GetLastSystemErrorCode()); - static void SetFlags(UInt32 flags); + static void SetFlags(ErrorModeFlags flags); static void Trigger(ErrorType type, std::string error); static void Trigger(ErrorType type, std::string error, unsigned int line, const char* file, const char* function); @@ -43,7 +43,7 @@ namespace Nz private: static const char* GetCurrentFileRelativeToEngine(const char* file); - static UInt32 s_flags; + static ErrorModeFlags s_flags; static std::string s_lastError; static const char* s_lastErrorFunction; static const char* s_lastErrorFile; diff --git a/include/Nazara/Core/ErrorFlags.hpp b/include/Nazara/Core/ErrorFlags.hpp index abcabbfc5..3c7ddd43f 100644 --- a/include/Nazara/Core/ErrorFlags.hpp +++ b/include/Nazara/Core/ErrorFlags.hpp @@ -8,26 +8,27 @@ #define NAZARA_ERRORFLAGS_HPP #include +#include namespace Nz { class NAZARA_CORE_API ErrorFlags { public: - ErrorFlags(UInt32 flags, bool replace = false); + ErrorFlags(ErrorModeFlags flags, bool replace = false); ErrorFlags(const ErrorFlags&) = delete; ErrorFlags(ErrorFlags&&) = delete; ~ErrorFlags(); - UInt32 GetPreviousFlags() const; + ErrorModeFlags GetPreviousFlags() const; - void SetFlags(UInt32 flags, bool replace = false); + void SetFlags(ErrorModeFlags flags, bool replace = false); ErrorFlags& operator=(const ErrorFlags&) = delete; ErrorFlags& operator=(ErrorFlags&&) = delete; private: - UInt32 m_previousFlags; + ErrorModeFlags m_previousFlags; }; } diff --git a/include/Nazara/Core/File.hpp b/include/Nazara/Core/File.hpp index f41c4e773..f0da5c4f4 100644 --- a/include/Nazara/Core/File.hpp +++ b/include/Nazara/Core/File.hpp @@ -48,8 +48,8 @@ namespace Nz bool IsOpen() const; - bool Open(OpenModeFlags openMode = OpenMode_NotOpen); - bool Open(const std::filesystem::path& filePath, OpenModeFlags openMode = OpenMode_NotOpen); + bool Open(OpenModeFlags openMode = OpenMode::NotOpen); + bool Open(const std::filesystem::path& filePath, OpenModeFlags openMode = OpenMode::NotOpen); bool SetCursorPos(CursorPosition pos, Int64 offset = 0); bool SetCursorPos(UInt64 offset) override; diff --git a/include/Nazara/Core/MemoryStream.inl b/include/Nazara/Core/MemoryStream.inl index 1395b3137..0e7b0abc3 100644 --- a/include/Nazara/Core/MemoryStream.inl +++ b/include/Nazara/Core/MemoryStream.inl @@ -13,7 +13,7 @@ namespace Nz * \brief Constructs a MemoryStream object by default */ inline MemoryStream::MemoryStream() : - Stream(StreamOption_None, OpenMode_ReadWrite), + Stream(StreamOption::None, OpenMode_ReadWrite), m_pos(0) { } diff --git a/include/Nazara/Core/Primitive.inl b/include/Nazara/Core/Primitive.inl index d9bd6f24c..58810e287 100644 --- a/include/Nazara/Core/Primitive.inl +++ b/include/Nazara/Core/Primitive.inl @@ -24,7 +24,7 @@ namespace Nz { matrix = transformMatrix; textureCoords = uvCoords; - type = PrimitiveType_Box; + type = PrimitiveType::Box; box.lengths = lengths; box.subdivision = subdivision; } @@ -56,7 +56,7 @@ namespace Nz { matrix = transformMatrix; textureCoords = uvCoords; - type = PrimitiveType_Cone; + type = PrimitiveType::Cone; cone.length = length; cone.radius = radius; cone.subdivision = subdivision; @@ -89,9 +89,9 @@ namespace Nz { matrix = transformMatrix; textureCoords = uvCoords; - type = PrimitiveType_Sphere; + type = PrimitiveType::Sphere; sphere.size = size; - sphere.type = SphereType_Cubic; + sphere.type = SphereType::Cubic; sphere.cubic.subdivision = subdivision; } @@ -121,9 +121,9 @@ namespace Nz { matrix = transformMatrix; textureCoords = uvCoords; - type = PrimitiveType_Sphere; + type = PrimitiveType::Sphere; sphere.size = size; - sphere.type = SphereType_Ico; + sphere.type = SphereType::Ico; sphere.ico.recursionLevel = recursionLevel; } @@ -153,7 +153,7 @@ namespace Nz { matrix = transformMatrix; textureCoords = uvCoords; - type = PrimitiveType_Plane; + type = PrimitiveType::Plane; plane.size = size; plane.subdivision = subdivision; } @@ -198,9 +198,9 @@ namespace Nz { matrix = transformMatrix; textureCoords = uvCoords; - type = PrimitiveType_Sphere; + type = PrimitiveType::Sphere; sphere.size = size; - sphere.type = SphereType_UV; + sphere.type = SphereType::UV; sphere.uv.sliceCount = sliceCount; sphere.uv.stackCount = stackCount; } diff --git a/include/Nazara/Core/ResourceLoader.inl b/include/Nazara/Core/ResourceLoader.inl index 1e17cf556..c9d7362b9 100644 --- a/include/Nazara/Core/ResourceLoader.inl +++ b/include/Nazara/Core/ResourceLoader.inl @@ -89,7 +89,7 @@ namespace Nz if (loader.streamChecker && !file.IsOpen()) { - if (!file.Open(OpenMode_ReadOnly)) + if (!file.Open(OpenMode::ReadOnly)) { NazaraError("Failed to load file: unable to open \"" + filePath.generic_u8string() + '"'); return nullptr; diff --git a/include/Nazara/Core/ResourceSaver.inl b/include/Nazara/Core/ResourceSaver.inl index 68450db68..6cf4a7955 100644 --- a/include/Nazara/Core/ResourceSaver.inl +++ b/include/Nazara/Core/ResourceSaver.inl @@ -89,7 +89,7 @@ namespace Nz { File file(filePath.generic_u8string()); - if (!file.Open(OpenMode_WriteOnly | OpenMode_Truncate)) + if (!file.Open(OpenMode::WriteOnly | OpenMode::Truncate)) { NazaraError("Failed to save to file: unable to open \"" + filePath.generic_u8string() + "\" in write mode"); return false; diff --git a/include/Nazara/Core/SerializationContext.hpp b/include/Nazara/Core/SerializationContext.hpp index 9cd64f2fd..0d715cd6a 100644 --- a/include/Nazara/Core/SerializationContext.hpp +++ b/include/Nazara/Core/SerializationContext.hpp @@ -20,7 +20,7 @@ namespace Nz struct NAZARA_CORE_API SerializationContext { MovablePtr stream; - Endianness endianness = Endianness_BigEndian; //< Default to Big Endian encoding + Endianness endianness = Endianness::BigEndian; //< Default to Big Endian encoding UInt8 readBitPos = 8; //< 8 means no bit is currently read UInt8 readByte; //< Undefined value, will be initialized at the first bit read UInt8 writeBitPos = 8; //< 8 means no bit is currently wrote diff --git a/include/Nazara/Core/Stream.hpp b/include/Nazara/Core/Stream.hpp index cd21c5f12..6813e2f20 100644 --- a/include/Nazara/Core/Stream.hpp +++ b/include/Nazara/Core/Stream.hpp @@ -56,7 +56,7 @@ namespace Nz Stream& operator=(Stream&&) noexcept = default; protected: - inline Stream(StreamOptionFlags streamOptions = StreamOption_None, OpenModeFlags 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; diff --git a/include/Nazara/Core/Stream.inl b/include/Nazara/Core/Stream.inl index 0c014919d..c55d6ed3b 100644 --- a/include/Nazara/Core/Stream.inl +++ b/include/Nazara/Core/Stream.inl @@ -29,9 +29,9 @@ namespace Nz inline void Stream::EnableTextMode(bool textMode) { if (textMode) - m_streamOptions |= StreamOption_Text; + m_streamOptions |= StreamOption::Text; else - m_streamOptions &= ~StreamOption_Text; + m_streamOptions &= ~StreamOption::Text; } /*! @@ -74,7 +74,7 @@ namespace Nz inline bool Stream::IsReadable() const { - return (m_openMode & OpenMode_ReadOnly) != 0; + return (m_openMode & OpenMode::ReadOnly) != 0; } /*! @@ -84,7 +84,7 @@ namespace Nz inline bool Stream::IsSequential() const { - return (m_streamOptions & StreamOption_Sequential) != 0; + return (m_streamOptions & StreamOption::Sequential) != 0; } /*! @@ -94,7 +94,7 @@ namespace Nz inline bool Stream::IsTextModeEnabled() const { - return (m_streamOptions & StreamOption_Text) != 0; + return (m_streamOptions & StreamOption::Text) != 0; } /*! @@ -104,7 +104,7 @@ namespace Nz inline bool Stream::IsWritable() const { - return (m_openMode & OpenMode_WriteOnly) != 0; + return (m_openMode & OpenMode::WriteOnly) != 0; } /*! diff --git a/include/Nazara/Network/ENetHost.hpp b/include/Nazara/Network/ENetHost.hpp index bfac8fd1c..6e0924f31 100644 --- a/include/Nazara/Network/ENetHost.hpp +++ b/include/Nazara/Network/ENetHost.hpp @@ -51,7 +51,7 @@ namespace Nz bool CheckEvents(ENetEvent* event); ENetPeer* Connect(const IpAddress& remoteAddress, std::size_t channelCount = 0, UInt32 data = 0); - ENetPeer* Connect(const std::string& hostName, NetProtocol protocol = NetProtocol_Any, const std::string& service = "http", ResolveError* error = nullptr, std::size_t channelCount = 0, UInt32 data = 0); + ENetPeer* Connect(const std::string& hostName, NetProtocol protocol = NetProtocol::Any, const std::string& service = "http", ResolveError* error = nullptr, std::size_t channelCount = 0, UInt32 data = 0); inline bool Create(NetProtocol protocol, UInt16 port, std::size_t peerCount, std::size_t channelCount = 0); bool Create(const IpAddress& listenAddress, std::size_t peerCount, std::size_t channelCount = 0); diff --git a/include/Nazara/Network/ENetHost.inl b/include/Nazara/Network/ENetHost.inl index 283d55059..faacd5c16 100644 --- a/include/Nazara/Network/ENetHost.inl +++ b/include/Nazara/Network/ENetHost.inl @@ -29,23 +29,23 @@ namespace Nz inline bool ENetHost::Create(NetProtocol protocol, UInt16 port, std::size_t peerCount, std::size_t channelCount) { - NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); + NazaraAssert(protocol != NetProtocol::Unknown, "Invalid protocol"); IpAddress any; switch (protocol) { - case NetProtocol_Unknown: + case NetProtocol::Unknown: NazaraInternalError("Invalid protocol"); return false; - case NetProtocol_IPv4: + case NetProtocol::IPv4: any = IpAddress::AnyIpV4; break; - case NetProtocol_Any: + case NetProtocol::Any: m_isUsingDualStack = true; // fallthrough - case NetProtocol_IPv6: + case NetProtocol::IPv6: any = IpAddress::AnyIpV6; break; } diff --git a/include/Nazara/Network/Enums.hpp b/include/Nazara/Network/Enums.hpp index 7a7348407..d7c6feb58 100644 --- a/include/Nazara/Network/Enums.hpp +++ b/include/Nazara/Network/Enums.hpp @@ -11,123 +11,114 @@ namespace Nz { - enum NetCode : UInt16 + enum class NetProtocol { - NetCode_Acknowledge = 0x9A4E, - NetCode_AcknowledgeConnection = 0xC108, - NetCode_Ping = 0x96AC, - NetCode_Pong = 0x974C, - NetCode_RequestConnection = 0xF27D, + Any, + IPv4, + IPv6, + Unknown, - NetCode_Invalid = 0x0000 + Max = Unknown }; - enum NetProtocol - { - NetProtocol_Any, - NetProtocol_IPv4, - NetProtocol_IPv6, - NetProtocol_Unknown, + constexpr std::size_t NetProtocolCount = static_cast(NetProtocol::Max) + 1; - NetProtocol_Max = NetProtocol_Unknown + enum class PacketReliability + { + Reliable, //< Packet will be resent if lost + ReliableOrdered, //< Packet will be resent if lost and will only arrive in order + Unreliable, //< Packet won't be resent if lost + + Max = Unreliable }; - enum PacketPriority - { - PacketPriority_High = 1, //< High-priority packet, will be sent quickly - PacketPriority_Immediate = 0, //< Immediate priority, will be sent immediately - PacketPriority_Medium = 2, //< Medium-priority packet, will be sent as regular - PacketPriority_Low = 3, //< Low-priority packet, may take some time to be sent + constexpr std::size_t PacketReliabilityCount = static_cast(PacketReliability::Max) + 1; - PacketPriority_Lowest = PacketPriority_Low, - PacketPriority_Highest = PacketPriority_Immediate, - PacketPriority_Max = PacketPriority_Low + enum class ResolveError + { + NoError, + + Internal, //< An internal error occurred + ResourceError, //< The operating system lacks the resources to proceed (insufficient memory) + NonRecoverable, //< An nonrecoverable error occurred + NotFound, //< No such host is known + NotInitialized, //< Nazara network has not been initialized + ProtocolNotSupported, //< A specified protocol is not supported by the server + TemporaryFailure, //< A temporary failure occurred, try again + Unknown, //< The last operation failed with an unlisted error code + + Max = Unknown }; - enum PacketReliability - { - PacketReliability_Reliable, //< Packet will be resent if lost - PacketReliability_ReliableOrdered, //< Packet will be resent if lost and will only arrive in order - PacketReliability_Unreliable, //< Packet won't be resent if lost + constexpr std::size_t ResolveErrorCount = static_cast(ResolveError::Max) + 1; - PacketReliability_Max = PacketReliability_Unreliable + enum class SocketError + { + NoError, + + AddressNotAvailable, //< The address is already in use (when binding/listening) + ConnectionClosed, //< The connection has been closed + ConnectionRefused, //< The connection attempt was refused + DatagramSize, //< The datagram size is over the system limit + Internal, //< The error is coming from the engine + Interrupted, //< The operation was interrupted by a signal + Packet, //< The packet encoding/decoding failed, probably because of corrupted data + NetworkError, //< The network system has failed (maybe network is down) + NotInitialized, //< Nazara network has not been initialized + NotSupported, //< The operation is not supported (e.g. creating a bluetooth socket on a system without any bluetooth adapter) + ResolveError, //< The hostname couldn't be resolved (more information in ResolveError code) + ResourceError, //< The operating system lacks the resources to proceed (e.g. memory/socket descriptor) + TimedOut, //< The operation timed out + Unknown, //< The last operation failed with an unlisted error code + UnreachableHost, //< The host is not reachable + + Max = UnreachableHost }; - enum ResolveError + constexpr std::size_t SocketErrorCount = static_cast(SocketError::Max) + 1; + + enum class SocketPollEvent { - ResolveError_NoError, + Read, //< One or more sockets is ready for a read operation + Write, //< One or more sockets is ready for a write operation - ResolveError_Internal, //< An internal error occurred - ResolveError_ResourceError, //< The operating system lacks the resources to proceed (insufficient memory) - ResolveError_NonRecoverable, //< An nonrecoverable error occurred - ResolveError_NotFound, //< No such host is known - ResolveError_NotInitialized, //< Nazara network has not been initialized - ResolveError_ProtocolNotSupported, //< A specified protocol is not supported by the server - ResolveError_TemporaryFailure, //< A temporary failure occurred, try again - ResolveError_Unknown, //< The last operation failed with an unlisted error code - - ResolveError_Max = ResolveError_Unknown + Max = Write }; - enum SocketError - { - SocketError_NoError, - - SocketError_AddressNotAvailable, //< The address is already in use (when binding/listening) - SocketError_ConnectionClosed, //< The connection has been closed - SocketError_ConnectionRefused, //< The connection attempt was refused - SocketError_DatagramSize, //< The datagram size is over the system limit - SocketError_Internal, //< The error is coming from the engine - SocketError_Interrupted, //< The operation was interrupted by a signal - SocketError_Packet, //< The packet encoding/decoding failed, probably because of corrupted data - SocketError_NetworkError, //< The network system has failed (maybe network is down) - SocketError_NotInitialized, //< Nazara network has not been initialized - SocketError_NotSupported, //< The operation is not supported (e.g. creating a bluetooth socket on a system without any bluetooth adapter) - SocketError_ResolveError, //< The hostname couldn't be resolved (more information in ResolveError code) - SocketError_ResourceError, //< The operating system lacks the resources to proceed (e.g. memory/socket descriptor) - SocketError_TimedOut, //< The operation timed out - SocketError_Unknown, //< The last operation failed with an unlisted error code - SocketError_UnreachableHost, //< The host is not reachable - - SocketError_Max = SocketError_UnreachableHost - }; - - enum SocketPollEvent - { - SocketPollEvent_Read, //< One or more sockets is ready for a read operation - SocketPollEvent_Write, //< One or more sockets is ready for a write operation - - SocketPollEvent_Max = SocketPollEvent_Write - }; + constexpr std::size_t SocketPollEventCount = static_cast(SocketPollEvent::Max) + 1; template<> struct EnumAsFlags { - static constexpr SocketPollEvent max = SocketPollEvent_Max; + static constexpr SocketPollEvent max = SocketPollEvent::Max; }; using SocketPollEventFlags = Flags; - enum SocketState + enum class SocketState { - SocketState_Bound, //< The socket is currently bound - SocketState_Connecting, //< The socket is currently connecting - SocketState_Connected, //< The socket is currently connected - SocketState_NotConnected, //< The socket is not connected (or has been disconnected) - SocketState_Resolving, //< The socket is currently resolving a host name + Bound, //< The socket is currently bound + Connecting, //< The socket is currently connecting + Connected, //< The socket is currently connected + NotConnected, //< The socket is not connected (or has been disconnected) + Resolving, //< The socket is currently resolving a host name - SocketState_Max = SocketState_Resolving + Max = Resolving }; - enum SocketType - { - SocketType_Raw, - SocketType_TCP, - SocketType_UDP, - SocketType_Unknown, + constexpr std::size_t SocketStateCount = static_cast(SocketState::Max) + 1; - SocketType_Max = SocketType_Unknown + enum class SocketType + { + Raw, + TCP, + UDP, + Unknown, + + Max = Unknown }; + + constexpr std::size_t SocketTypeCount = static_cast(SocketType::Max) + 1; } #endif // NAZARA_ENUMS_NETWORK_HPP diff --git a/include/Nazara/Network/IpAddress.inl b/include/Nazara/Network/IpAddress.inl index ee31cd405..4e822cc9f 100644 --- a/include/Nazara/Network/IpAddress.inl +++ b/include/Nazara/Network/IpAddress.inl @@ -27,7 +27,7 @@ namespace Nz inline IpAddress::IpAddress(const IPv4& ip, UInt16 port) : m_ipv4(ip), - m_protocol(NetProtocol_IPv4), + m_protocol(NetProtocol::IPv4), m_port(port), m_isValid(true) { @@ -42,7 +42,7 @@ namespace Nz inline IpAddress::IpAddress(const IPv6& ip, UInt16 port) : m_ipv6(ip), - m_protocol(NetProtocol_IPv6), + m_protocol(NetProtocol::IPv6), m_port(port), m_isValid(true) { @@ -149,7 +149,7 @@ namespace Nz inline IpAddress::IPv4 IpAddress::ToIPv4() const { - NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv4, "Address is not a valid IPv4"); + NazaraAssert(m_isValid && m_protocol == NetProtocol::IPv4, "Address is not a valid IPv4"); return m_ipv4; } @@ -163,7 +163,7 @@ namespace Nz inline IpAddress::IPv6 IpAddress::ToIPv6() const { - NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv6, "IP is not a valid IPv6"); + NazaraAssert(m_isValid && m_protocol == NetProtocol::IPv6, "IP is not a valid IPv6"); return m_ipv6; } @@ -177,7 +177,7 @@ namespace Nz inline UInt32 IpAddress::ToUInt32() const { - NazaraAssert(m_isValid && m_protocol == NetProtocol_IPv4, "Address is not a valid IPv4"); + NazaraAssert(m_isValid && m_protocol == NetProtocol::IPv4, "Address is not a valid IPv4"); return UInt32(m_ipv4[0]) << 24 | UInt32(m_ipv4[1]) << 16 | @@ -231,11 +231,11 @@ namespace Nz // Each protocol has its variables to compare switch (first.m_protocol) { - case NetProtocol_Any: - case NetProtocol_Unknown: + case NetProtocol::Any: + case NetProtocol::Unknown: break; - case NetProtocol_IPv4: + case NetProtocol::IPv4: { if (first.m_ipv4 != second.m_ipv4) return false; @@ -243,7 +243,7 @@ namespace Nz break; } - case NetProtocol_IPv6: + case NetProtocol::IPv6: { if (first.m_ipv6 != second.m_ipv6) return false; @@ -297,11 +297,11 @@ namespace Nz // Compare IP (thanks to std::array comparison operator) switch (first.m_protocol) { - case NetProtocol_Any: - case NetProtocol_Unknown: + case NetProtocol::Any: + case NetProtocol::Unknown: break; - case NetProtocol_IPv4: + case NetProtocol::IPv4: { if (first.m_ipv4 != second.m_ipv4) return first.m_ipv4 < second.m_ipv4; @@ -309,7 +309,7 @@ namespace Nz break; } - case NetProtocol_IPv6: + case NetProtocol::IPv6: { if (first.m_ipv6 != second.m_ipv6) return first.m_ipv6 < second.m_ipv6; @@ -387,16 +387,16 @@ namespace std std::size_t h = 0; switch (ip.GetProtocol()) { - case Nz::NetProtocol_Any: - case Nz::NetProtocol_Unknown: + case Nz::NetProtocol::Any: + case Nz::NetProtocol::Unknown: return std::numeric_limits::max(); - case Nz::NetProtocol_IPv4: + case Nz::NetProtocol::IPv4: { h = ip.ToUInt32() + (h << 6) + (h << 16) - h; break; } - case Nz::NetProtocol_IPv6: + case Nz::NetProtocol::IPv6: { Nz::IpAddress::IPv6 v6 = ip.ToIPv6(); for (std::size_t i = 0; i < v6.size(); i++) diff --git a/include/Nazara/Network/NetPacket.inl b/include/Nazara/Network/NetPacket.inl index abd75bd14..84ded62ab 100644 --- a/include/Nazara/Network/NetPacket.inl +++ b/include/Nazara/Network/NetPacket.inl @@ -12,9 +12,8 @@ namespace Nz /*! * \brief Constructs a NetPacket object by default */ - inline NetPacket::NetPacket() : - m_netCode(NetCode_Invalid) + m_netCode(0) { } @@ -156,7 +155,7 @@ namespace Nz inline void NetPacket::Reset(UInt16 netCode, const void* ptr, std::size_t size) { - InitStream(HeaderSize + size, HeaderSize, OpenMode_ReadOnly); + InitStream(HeaderSize + size, HeaderSize, OpenMode::ReadOnly); m_buffer->Resize(HeaderSize + size); if (ptr) diff --git a/include/Nazara/Network/RUdpConnection.hpp b/include/Nazara/Network/RUdpConnection.hpp deleted file mode 100644 index 4a8a19118..000000000 --- a/include/Nazara/Network/RUdpConnection.hpp +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (C) 2020 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_RUDPSERVER_HPP -#define NAZARA_RUDPSERVER_HPP - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace Nz -{ - class NAZARA_NETWORK_API RUdpConnection - { - friend class Network; - - public: - using SequenceIndex = UInt16; - - RUdpConnection(); - RUdpConnection(const RUdpConnection&) = delete; - RUdpConnection(RUdpConnection&&) = default; - ~RUdpConnection() = default; - - inline void Close(); - - bool Connect(const IpAddress& remoteAddress); - bool Connect(const std::string& hostName, NetProtocol protocol = NetProtocol_Any, const std::string& service = "http", ResolveError* error = nullptr); - inline void Disconnect(); - - inline IpAddress GetBoundAddress() const; - inline UInt16 GetBoundPort() const; - inline SocketError GetLastError() const; - - inline bool Listen(NetProtocol protocol, UInt16 port = 64266); - bool Listen(const IpAddress& address); - - bool PollMessage(RUdpMessage* message); - - bool Send(const IpAddress& clientIp, PacketPriority priority, PacketReliability reliability, const NetPacket& packet); - - inline void SetProtocolId(UInt32 protocolId); - inline void SetTimeBeforeAck(UInt32 ms); - - inline void SimulateNetwork(double packetLoss); - - void Update(); - - RUdpConnection& operator=(const RUdpConnection&) = delete; - RUdpConnection& operator=(RUdpConnection&&) = default; - - static constexpr std::size_t MessageHeader = sizeof(UInt16) + 2 * sizeof(SequenceIndex) + sizeof(UInt32); //< Protocol ID (begin) + Sequence ID + Remote Sequence ID + Ack bitfield - static constexpr std::size_t MessageFooter = sizeof(UInt16); //< Protocol ID (end) - - // Signals: - NazaraSignal(OnConnectedToPeer, RUdpConnection* /*connection*/); - NazaraSignal(OnPeerAcknowledged, RUdpConnection* /*connection*/, const IpAddress& /*adress*/); - NazaraSignal(OnPeerConnection, RUdpConnection* /*connection*/, const IpAddress& /*adress*/); - NazaraSignal(OnPeerDisconnected, RUdpConnection* /*connection*/, const IpAddress& /*adress*/); - - private: - struct PeerData; - struct PendingAckPacket; - struct PendingPacket; - - enum PeerState - { - PeerState_Aknowledged, //< A connection request from this peer has been received, we're waiting for another packet to validate - PeerState_Connected, //< Connection is working in both-ways - PeerState_Connecting, //< A connection request has been made - PeerState_WillAck //< Connected, received one or more packets and has no packets to send, waiting before sending an empty ack packet - }; - - void DisconnectPeer(std::size_t peerIndex); - void EnqueuePacket(PeerData& peer, PacketPriority priority, PacketReliability reliability, const NetPacket& packet); - void EnqueuePacketInternal(PeerData& peer, PacketPriority priority, PacketReliability reliability, NetPacket&& data); - bool InitSocket(NetProtocol protocol); - void ProcessAcks(PeerData& peer, SequenceIndex lastAck, UInt32 ackBits); - PeerData& RegisterPeer(const IpAddress& address, PeerState state); - void OnClientRequestingConnection(const IpAddress& address, SequenceIndex sequenceId, UInt64 token); - void OnPacketLost(PeerData& peer, PendingAckPacket&& packet); - void OnPacketReceived(const IpAddress& peerIp, NetPacket&& packet); - void SendPacket(PeerData& peer, PendingPacket&& packet); - - static inline unsigned int ComputeSequenceDifference(SequenceIndex sequence, SequenceIndex sequence2); - static inline bool HasPendingPackets(PeerData& peer); - static bool Initialize(); - static inline bool IsAckMoreRecent(SequenceIndex ack, SequenceIndex ack2); - static inline bool IsReliable(PacketReliability reliability); - static void Uninitialize(); - - struct PendingPacket - { - PacketPriority priority; - PacketReliability reliability; - NetPacket data; - }; - - struct PendingAckPacket - { - PacketPriority priority; - PacketReliability reliability; - NetPacket data; - SequenceIndex sequenceId; - UInt64 timeSent; - }; - - struct PeerData //TODO: Move this to RUdpClient - { - PeerData() = default; - PeerData(PeerData&& other) = default; - PeerData& operator=(PeerData&& other) = default; - - std::array, PacketPriority_Max + 1> pendingPackets; - std::deque pendingAckQueue; - std::set receivedQueue; - std::size_t index; - PeerState state; - IpAddress address; - SequenceIndex localSequence; - SequenceIndex remoteSequence; - UInt32 roundTripTime; - UInt64 lastPacketTime; - UInt64 lastPingTime; - UInt64 stateData1; - }; - - std::bernoulli_distribution m_packetLossProbability; - std::queue m_receivedMessages; - std::size_t m_peerIterator; - std::unordered_map m_peerByIP; - std::vector m_peers; - Bitset m_activeClients; - Clock m_clock; - SocketError m_lastError; - UdpSocket m_socket; - UInt32 m_forceAckSendTime; - UInt32 m_pingInterval; - UInt32 m_protocol; - UInt32 m_timeBeforePing; - UInt32 m_timeBeforeTimeOut; - UInt64 m_currentTime; - bool m_isSimulationEnabled; - bool m_shouldAcceptConnections; - - static std::mt19937_64 s_randomGenerator; - }; -} - -#include - -#endif // NAZARA_RUDPSERVER_HPP diff --git a/include/Nazara/Network/RUdpConnection.inl b/include/Nazara/Network/RUdpConnection.inl deleted file mode 100644 index d1b1e0705..000000000 --- a/include/Nazara/Network/RUdpConnection.inl +++ /dev/null @@ -1,220 +0,0 @@ -// Copyright (C) 2020 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 - -namespace Nz -{ - /*! - * \brief Closes the connection - */ - - inline void RUdpConnection::Close() - { - m_socket.Close(); - } - - /*! - * \brief Disconnects the connection - * - * \see Close - */ - - inline void RUdpConnection::Disconnect() - { - Close(); - } - - /*! - * \brief Gets the bound address - * \return IpAddress we are linked to - */ - - inline IpAddress RUdpConnection::GetBoundAddress() const - { - return m_socket.GetBoundAddress(); - } - - /*! - * \brief Gets the port of the bound address - * \return Port we are linked to - */ - - inline UInt16 RUdpConnection::GetBoundPort() const - { - return m_socket.GetBoundPort(); - } - - /*! - * \brief Gets the last error - * \return Socket error - */ - - inline SocketError RUdpConnection::GetLastError() const - { - return m_lastError; - } - - /*! - * \brief Listens to a socket - * \return true If successfully bound - * - * \param protocol Net protocol to listen to - * \param port Port to listen to - * - * \remark Produces a NazaraAssert if protocol is unknown or any - */ - - inline bool RUdpConnection::Listen(NetProtocol protocol, UInt16 port) - { - NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO - NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); - - IpAddress any; - switch (protocol) - { - case NetProtocol_Any: - case NetProtocol_Unknown: - NazaraInternalError("Invalid protocol Any at this point"); - return false; - - case NetProtocol_IPv4: - any = IpAddress::AnyIpV4; - break; - - case NetProtocol_IPv6: - any = IpAddress::AnyIpV6; - break; - } - - any.SetPort(port); - return Listen(any); - } - - /*! - * \brief Sets the protocol id - * - * \param protocolId Protocol ID like NNet - */ - - inline void RUdpConnection::SetProtocolId(UInt32 protocolId) - { - m_protocol = protocolId; - } - - /*! - * \brief Sets the time before ack - * - * \param Time before acking to send many together (in ms) - */ - - inline void RUdpConnection::SetTimeBeforeAck(UInt32 ms) - { - m_forceAckSendTime = ms * 1000; //< Store in microseconds for easier handling - } - - /*! - * \brief Computes the difference of sequence - * \return Delta between the two sequences - * - * \param sequence First sequence - * \param sequence2 Second sequence - */ - - inline unsigned int RUdpConnection::ComputeSequenceDifference(SequenceIndex sequence, SequenceIndex sequence2) - { - unsigned int difference; - if (sequence2 > sequence) - difference = std::numeric_limits::max() - sequence2 + sequence; - else - difference = sequence - sequence2; - - return difference; - } - - /*! - * \brief Checks whether the peer has pending packets - * \return true If it is the case - * - * \param peer Data relative to the peer - */ - - inline bool RUdpConnection::HasPendingPackets(PeerData& peer) - { - for (unsigned int priority = PacketPriority_Highest; priority <= PacketPriority_Lowest; ++priority) - { - std::vector& pendingPackets = peer.pendingPackets[priority]; - if (!pendingPackets.empty()) - return true; - } - - return false; - } - - /*! - * \brief Checks whether the ack is more recent - * \return true If it is the case - * - * \param ack First sequence - * \param ack2 Second sequence - */ - - inline bool RUdpConnection::IsAckMoreRecent(SequenceIndex ack, SequenceIndex ack2) - { - constexpr SequenceIndex maxDifference = std::numeric_limits::max() / 2; - - if (ack > ack2) - return ack - ack2 <= maxDifference; - else if (ack2 > ack) - return ack2 - ack > maxDifference; - else - return false; ///< Same ack - } - - /*! - * \brief Checks whether the connection is reliable - * \return true If it is the case - * - * \remark Produces a NazaraError if enumeration is invalid - */ - - inline bool RUdpConnection::IsReliable(PacketReliability reliability) - { - switch (reliability) - { - case PacketReliability_Reliable: - case PacketReliability_ReliableOrdered: - return true; - - case PacketReliability_Unreliable: - return false; - } - - NazaraError("PacketReliability not handled (0x" + NumberToString(reliability, 16) + ')'); - return false; - } - - /*! - * \brief Simulates the loss of packets on network - * - * \param packetLoss Ratio of packet loss according to bernoulli distribution - * - * \remark Produces a NazaraAssert if packetLoss is not in between 0.0 and 1.0 - */ - - inline void RUdpConnection::SimulateNetwork(double packetLoss) - { - NazaraAssert(packetLoss >= 0.0 && packetLoss <= 1.0, "Packet loss must be in range [0..1]"); - - if (packetLoss > 0.0) - { - m_isSimulationEnabled = true; - m_packetLossProbability = std::bernoulli_distribution(packetLoss); - } - else - m_isSimulationEnabled = false; - } -} - -#include diff --git a/include/Nazara/Network/RUdpMessage.hpp b/include/Nazara/Network/RUdpMessage.hpp deleted file mode 100644 index ce1c57771..000000000 --- a/include/Nazara/Network/RUdpMessage.hpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2020 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_RUDMESSAGE_HPP -#define NAZARA_RUDMESSAGE_HPP - -#include -#include -#include - -namespace Nz -{ - struct RUdpMessage - { - IpAddress from; - NetPacket data; - }; -} - -#endif // NAZARA_RUDMESSAGE_HPP \ No newline at end of file diff --git a/include/Nazara/Network/TcpClient.hpp b/include/Nazara/Network/TcpClient.hpp index 6dc5ac4d2..235f4f76b 100644 --- a/include/Nazara/Network/TcpClient.hpp +++ b/include/Nazara/Network/TcpClient.hpp @@ -29,7 +29,7 @@ namespace Nz ~TcpClient() = default; SocketState Connect(const IpAddress& remoteAddress); - SocketState Connect(const std::string& hostName, NetProtocol protocol = NetProtocol_Any, const std::string& service = "http", ResolveError* error = nullptr); + SocketState Connect(const std::string& hostName, NetProtocol protocol = NetProtocol::Any, const std::string& service = "http", ResolveError* error = nullptr); inline void Disconnect(); void EnableLowDelay(bool lowDelay); diff --git a/include/Nazara/Network/TcpClient.inl b/include/Nazara/Network/TcpClient.inl index ca559e72f..a5fe2d64f 100644 --- a/include/Nazara/Network/TcpClient.inl +++ b/include/Nazara/Network/TcpClient.inl @@ -11,8 +11,8 @@ namespace Nz */ inline TcpClient::TcpClient() : - AbstractSocket(SocketType_TCP), - Stream(StreamOption_Sequential), + AbstractSocket(SocketType::TCP), + Stream(StreamOption::Sequential), m_keepAliveInterval(1000), //TODO: Query OS default value m_keepAliveTime(7'200'000), //TODO: Query OS default value m_isKeepAliveEnabled(false), //TODO: Query OS default value diff --git a/include/Nazara/Network/TcpServer.inl b/include/Nazara/Network/TcpServer.inl index 759ff0b80..02422ecec 100644 --- a/include/Nazara/Network/TcpServer.inl +++ b/include/Nazara/Network/TcpServer.inl @@ -12,7 +12,7 @@ namespace Nz */ inline TcpServer::TcpServer() : - AbstractSocket(SocketType_TCP) + AbstractSocket(SocketType::TCP) { } @@ -61,22 +61,22 @@ namespace Nz inline SocketState TcpServer::Listen(NetProtocol protocol, UInt16 port, unsigned int queueSize) { - NazaraAssert(protocol != NetProtocol_Any, "Any protocol not supported for Listen"); //< TODO - NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); + NazaraAssert(protocol != NetProtocol::Any, "Any protocol not supported for Listen"); //< TODO + NazaraAssert(protocol != NetProtocol::Unknown, "Invalid protocol"); IpAddress any; switch (protocol) { - case NetProtocol_Any: - case NetProtocol_Unknown: + case NetProtocol::Any: + case NetProtocol::Unknown: NazaraInternalError("Invalid protocol Any at this point"); - return SocketState_NotConnected; + return SocketState::NotConnected; - case NetProtocol_IPv4: + case NetProtocol::IPv4: any = IpAddress::AnyIpV4; break; - case NetProtocol_IPv6: + case NetProtocol::IPv6: any = IpAddress::AnyIpV6; break; } diff --git a/include/Nazara/Network/UdpSocket.inl b/include/Nazara/Network/UdpSocket.inl index 93fe841cf..6380fb8be 100644 --- a/include/Nazara/Network/UdpSocket.inl +++ b/include/Nazara/Network/UdpSocket.inl @@ -11,7 +11,7 @@ namespace Nz */ inline UdpSocket::UdpSocket() : - AbstractSocket(SocketType_UDP) + AbstractSocket(SocketType::UDP) { } @@ -51,16 +51,16 @@ namespace Nz IpAddress any; switch (m_protocol) { - case NetProtocol_Unknown: + case NetProtocol::Unknown: NazaraInternalError("Invalid protocol"); - return SocketState_NotConnected; + return SocketState::NotConnected; - case NetProtocol_IPv4: + case NetProtocol::IPv4: any = IpAddress::AnyIpV4; break; - case NetProtocol_Any: - case NetProtocol_IPv6: + case NetProtocol::Any: + case NetProtocol::IPv6: any = IpAddress::AnyIpV6; break; } @@ -78,7 +78,7 @@ namespace Nz bool UdpSocket::Create(NetProtocol protocol) { - NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); + NazaraAssert(protocol != NetProtocol::Unknown, "Invalid protocol"); return Open(protocol); } diff --git a/include/Nazara/Physics2D/RigidBody2D.hpp b/include/Nazara/Physics2D/RigidBody2D.hpp index ce97d3c79..e98812a07 100644 --- a/include/Nazara/Physics2D/RigidBody2D.hpp +++ b/include/Nazara/Physics2D/RigidBody2D.hpp @@ -35,10 +35,10 @@ namespace Nz RigidBody2D(RigidBody2D&& object) noexcept; ~RigidBody2D(); - void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys_Global); - void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys_Global); - void AddImpulse(const Vector2f& impulse, CoordSys coordSys = CoordSys_Global); - void AddImpulse(const Vector2f& impulse, const Vector2f& point, CoordSys coordSys = CoordSys_Global); + void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys::Global); + void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys::Global); + void AddImpulse(const Vector2f& impulse, CoordSys coordSys = CoordSys::Global); + void AddImpulse(const Vector2f& impulse, const Vector2f& point, CoordSys coordSys = CoordSys::Global); void AddTorque(const RadianAnglef& torque); bool ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint = nullptr, float* closestDistance = nullptr) const; @@ -52,13 +52,13 @@ namespace Nz inline float GetAngularDamping() const; RadianAnglef GetAngularVelocity() const; NAZARA_DEPRECATED("Name error, please use GetMassCenter") - inline Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys_Local) const; + inline Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys::Local) const; float GetElasticity(std::size_t shapeIndex = 0) const; float GetFriction(std::size_t shapeIndex = 0) const; const std::shared_ptr& GetGeom() const; cpBody* GetHandle() const; float GetMass() const; - Vector2f GetMassCenter(CoordSys coordSys = CoordSys_Local) const; + Vector2f GetMassCenter(CoordSys coordSys = CoordSys::Local) const; float GetMomentOfInertia() const; Vector2f GetPosition() const; inline const Vector2f& GetPositionOffset() const; @@ -86,7 +86,7 @@ namespace Nz void SetFriction(std::size_t shapeIndex, float friction); void SetGeom(std::shared_ptr geom, bool recomputeMoment = true, bool recomputeMassCenter = true); void SetMass(float mass, bool recomputeMoment = true); - void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys_Local); + void SetMassCenter(const Vector2f& center, CoordSys coordSys = CoordSys::Local); void SetMomentOfInertia(float moment); void SetPosition(const Vector2f& position); void SetPositionOffset(const Vector2f& offset); diff --git a/include/Nazara/Physics3D/RigidBody3D.hpp b/include/Nazara/Physics3D/RigidBody3D.hpp index c7c0272c9..f185fa3c4 100644 --- a/include/Nazara/Physics3D/RigidBody3D.hpp +++ b/include/Nazara/Physics3D/RigidBody3D.hpp @@ -30,9 +30,9 @@ namespace Nz RigidBody3D(RigidBody3D&& object); ~RigidBody3D(); - void AddForce(const Vector3f& force, CoordSys coordSys = CoordSys_Global); - void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys_Global); - void AddTorque(const Vector3f& torque, CoordSys coordSys = CoordSys_Global); + void AddForce(const Vector3f& force, CoordSys coordSys = CoordSys::Global); + void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys::Global); + void AddTorque(const Vector3f& torque, CoordSys coordSys = CoordSys::Global); void EnableAutoSleep(bool autoSleep); void EnableSimulation(bool simulation); @@ -46,7 +46,7 @@ namespace Nz float GetLinearDamping() const; Vector3f GetLinearVelocity() const; float GetMass() const; - Vector3f GetMassCenter(CoordSys coordSys = CoordSys_Local) const; + Vector3f GetMassCenter(CoordSys coordSys = CoordSys::Local) const; int GetMaterial() const; const Matrix4f& GetMatrix() const; Vector3f GetPosition() const; diff --git a/include/Nazara/Platform/Window.inl b/include/Nazara/Platform/Window.inl index 4668313e8..d81a2ff5d 100644 --- a/include/Nazara/Platform/Window.inl +++ b/include/Nazara/Platform/Window.inl @@ -15,14 +15,14 @@ namespace Nz inline Window::Window(VideoMode mode, const std::string& title, WindowStyleFlags style) : Window() { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); Create(mode, title, style); } inline Window::Window(void* handle) : Window() { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); Create(handle); } diff --git a/include/Nazara/Renderer/RenderWindow.inl b/include/Nazara/Renderer/RenderWindow.inl index 7f458577f..c93291e46 100644 --- a/include/Nazara/Renderer/RenderWindow.inl +++ b/include/Nazara/Renderer/RenderWindow.inl @@ -15,14 +15,14 @@ namespace Nz inline RenderWindow::RenderWindow(std::shared_ptr renderDevice, VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) : RenderWindow() { - ErrorFlags errFlags(ErrorFlag_ThrowException, true); + ErrorFlags errFlags(ErrorMode::ThrowException, true); Create(std::move(renderDevice), mode, title, style, parameters); } inline RenderWindow::RenderWindow(std::shared_ptr renderDevice, void* handle, const RenderWindowParameters& parameters) { - ErrorFlags errFlags(ErrorFlag_ThrowException, true); + ErrorFlags errFlags(ErrorMode::ThrowException, true); Create(std::move(renderDevice), handle, parameters); } diff --git a/include/Nazara/Utility/Buffer.hpp b/include/Nazara/Utility/Buffer.hpp index 1302cf383..3be6680f7 100644 --- a/include/Nazara/Utility/Buffer.hpp +++ b/include/Nazara/Utility/Buffer.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace Nz { diff --git a/include/Nazara/Utility/Node.hpp b/include/Nazara/Utility/Node.hpp index d2faaab1c..0af3b619f 100644 --- a/include/Nazara/Utility/Node.hpp +++ b/include/Nazara/Utility/Node.hpp @@ -41,21 +41,21 @@ namespace Nz virtual Vector3f GetLeft() const; virtual NodeType GetNodeType() const; const Node* GetParent() const; - Vector3f GetPosition(CoordSys coordSys = CoordSys_Local) const; + Vector3f GetPosition(CoordSys coordSys = CoordSys::Local) const; virtual Vector3f GetRight() const; - Quaternionf GetRotation(CoordSys coordSys = CoordSys_Local) const; - Vector3f GetScale(CoordSys coordSys = CoordSys_Local) const; + Quaternionf GetRotation(CoordSys coordSys = CoordSys::Local) const; + Vector3f GetScale(CoordSys coordSys = CoordSys::Local) const; const Matrix4f& GetTransformMatrix() const; virtual Vector3f GetUp() const; bool HasChilds() const; - Node& Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys = CoordSys_Global); + Node& Interpolate(const Node& nodeA, const Node& nodeB, float interpolation, CoordSys coordSys = CoordSys::Global); - Node& Move(const Vector3f& movement, CoordSys coordSys = CoordSys_Local); - Node& Move(float movementX, float movementY, float movementZ = 0.f, CoordSys coordSys = CoordSys_Local); + Node& Move(const Vector3f& movement, CoordSys coordSys = CoordSys::Local); + Node& Move(float movementX, float movementY, float movementZ = 0.f, CoordSys coordSys = CoordSys::Local); - Node& Rotate(const Quaternionf& rotation, CoordSys coordSys = CoordSys_Local); + Node& Rotate(const Quaternionf& rotation, CoordSys coordSys = CoordSys::Local); Node& Scale(const Vector3f& scale); Node& Scale(float scale); @@ -72,13 +72,13 @@ namespace Nz void SetInitialPosition(float translationX, float translationXY, float translationZ = 0.f); void SetParent(const Node* node = nullptr, bool keepDerived = false); void SetParent(const Node& node, bool keepDerived = false); - void SetPosition(const Vector3f& translation, CoordSys coordSys = CoordSys_Local); - void SetPosition(float translationX, float translationY, float translationZ = 0.f, CoordSys coordSys = CoordSys_Local); - void SetRotation(const Quaternionf& quat, CoordSys coordSys = CoordSys_Local); - void SetScale(const Vector2f& scale, CoordSys coordSys = CoordSys_Local); - void SetScale(const Vector3f& scale, CoordSys coordSys = CoordSys_Local); - void SetScale(float scale, CoordSys coordSys = CoordSys_Local); - void SetScale(float scaleX, float scaleY, float scaleZ = 1.f, CoordSys coordSys = CoordSys_Local); + void SetPosition(const Vector3f& translation, CoordSys coordSys = CoordSys::Local); + void SetPosition(float translationX, float translationY, float translationZ = 0.f, CoordSys coordSys = CoordSys::Local); + void SetRotation(const Quaternionf& quat, CoordSys coordSys = CoordSys::Local); + void SetScale(const Vector2f& scale, CoordSys coordSys = CoordSys::Local); + void SetScale(const Vector3f& scale, CoordSys coordSys = CoordSys::Local); + void SetScale(float scale, CoordSys coordSys = CoordSys::Local); + void SetScale(float scaleX, float scaleY, float scaleZ = 1.f, CoordSys coordSys = CoordSys::Local); void SetTransformMatrix(const Matrix4f& matrix); // Local -> global diff --git a/include/Nazara/Utility/VertexDeclaration.hpp b/include/Nazara/Utility/VertexDeclaration.hpp index abe6001ac..4a9827d8b 100644 --- a/include/Nazara/Utility/VertexDeclaration.hpp +++ b/include/Nazara/Utility/VertexDeclaration.hpp @@ -13,6 +13,7 @@ #include #include #include +#include namespace Nz { diff --git a/include/NazaraSDK/Components/PhysicsComponent2D.hpp b/include/NazaraSDK/Components/PhysicsComponent2D.hpp index 89aeb8dfd..3f2851eeb 100644 --- a/include/NazaraSDK/Components/PhysicsComponent2D.hpp +++ b/include/NazaraSDK/Components/PhysicsComponent2D.hpp @@ -30,10 +30,10 @@ namespace Ndk PhysicsComponent2D(const PhysicsComponent2D& physics); ~PhysicsComponent2D() = default; - inline void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global); - inline void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global); - inline void AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys = Nz::CoordSys_Global); - inline void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global); + inline void AddForce(const Nz::Vector2f& force, Nz::CoordSys coordSys = Nz::CoordSys::Global); + inline void AddForce(const Nz::Vector2f& force, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys::Global); + inline void AddImpulse(const Nz::Vector2f& impulse, Nz::CoordSys coordSys = Nz::CoordSys::Global); + inline void AddImpulse(const Nz::Vector2f& impulse, const Nz::Vector2f& point, Nz::CoordSys coordSys = Nz::CoordSys::Global); inline void AddTorque(const Nz::RadianAnglef& torque); inline bool ClosestPointQuery(const Nz::Vector2f& position, Nz::Vector2f* closestPoint, float* closestDistance) const; @@ -47,11 +47,11 @@ namespace Ndk inline float GetAngularDamping() const; inline Nz::RadianAnglef GetAngularVelocity() const; NAZARA_DEPRECATED("Name error, please use GetMassCenter") - inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; + inline Nz::Vector2f GetCenterOfGravity(Nz::CoordSys coordSys = Nz::CoordSys::Local) const; inline float GetElasticity(std::size_t shapeIndex = 0) const; inline float GetFriction(std::size_t shapeIndex = 0) const; inline float GetMass() const; - inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; + inline Nz::Vector2f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys::Local) const; inline float GetMomentOfInertia() const; inline Nz::Vector2f GetPosition() const; inline Nz::RadianAnglef GetRotation() const; @@ -73,7 +73,7 @@ namespace Ndk inline void SetFriction(float friction); inline void SetFriction(std::size_t shapeIndex, float friction); inline void SetMass(float mass, bool recomputeMoment = true); - inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys_Local); + inline void SetMassCenter(const Nz::Vector2f& center, Nz::CoordSys coordSys = Nz::CoordSys::Local); inline void SetMomentOfInertia(float moment); inline void SetPosition(const Nz::Vector2f& position); inline void SetRotation(const Nz::RadianAnglef& rotation); diff --git a/include/NazaraSDK/Components/PhysicsComponent3D.hpp b/include/NazaraSDK/Components/PhysicsComponent3D.hpp index 16a242e81..be3ca4aae 100644 --- a/include/NazaraSDK/Components/PhysicsComponent3D.hpp +++ b/include/NazaraSDK/Components/PhysicsComponent3D.hpp @@ -27,9 +27,9 @@ namespace Ndk PhysicsComponent3D(const PhysicsComponent3D& physics); ~PhysicsComponent3D() = default; - inline void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global); - inline void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global); - inline void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys_Global); + inline void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys::Global); + inline void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys::Global); + inline void AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys = Nz::CoordSys::Global); inline void EnableAutoSleep(bool autoSleep); inline void EnableNodeSynchronization(bool nodeSynchronization); @@ -41,7 +41,7 @@ namespace Ndk inline float GetLinearDamping() const; inline Nz::Vector3f GetLinearVelocity() const; inline float GetMass() const; - inline Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys_Local) const; + inline Nz::Vector3f GetMassCenter(Nz::CoordSys coordSys = Nz::CoordSys::Local) const; inline const Nz::Matrix4f& GetMatrix() const; inline Nz::Vector3f GetPosition() const; inline Nz::Quaternionf GetRotation() const; diff --git a/include/NazaraSDK/Components/PhysicsComponent3D.inl b/include/NazaraSDK/Components/PhysicsComponent3D.inl index 9937f354c..6925d5608 100644 --- a/include/NazaraSDK/Components/PhysicsComponent3D.inl +++ b/include/NazaraSDK/Components/PhysicsComponent3D.inl @@ -480,7 +480,7 @@ namespace Ndk m_pendingStates.gravityFactor = rigidBody.GetGravityFactor(); m_pendingStates.linearDamping = rigidBody.GetLinearDamping(); m_pendingStates.mass = rigidBody.GetMass(); - m_pendingStates.massCenter = rigidBody.GetMassCenter(Nz::CoordSys_Local); + m_pendingStates.massCenter = rigidBody.GetMassCenter(Nz::CoordSys::Local); m_pendingStates.valid = true; } diff --git a/include/NazaraSDK/Components/VelocityComponent.hpp b/include/NazaraSDK/Components/VelocityComponent.hpp index a82ecdf5c..5a0f5bd2f 100644 --- a/include/NazaraSDK/Components/VelocityComponent.hpp +++ b/include/NazaraSDK/Components/VelocityComponent.hpp @@ -19,7 +19,7 @@ namespace Ndk class NDK_API VelocityComponent : public Component { public: - VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero(), Nz::CoordSys coordSystem = Nz::CoordSys_Global); + VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero(), Nz::CoordSys coordSystem = Nz::CoordSys::Global); ~VelocityComponent() = default; Nz::Vector3f linearVelocity; diff --git a/plugins/Assimp/CustomStream.cpp b/plugins/Assimp/CustomStream.cpp index 4e8392aad..d7ae0db27 100644 --- a/plugins/Assimp/CustomStream.cpp +++ b/plugins/Assimp/CustomStream.cpp @@ -79,28 +79,28 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod stream = reinterpret_cast(fileIOUserdata->originalStream); else { - ErrorFlags errFlags(ErrorFlag_ThrowExceptionDisabled, true); + ErrorFlags errFlags(ErrorMode::ThrowExceptionDisabled, true); ///TODO: Move to File::DecodeOpenMode OpenModeFlags openModeEnum = 0; if (std::strchr(openMode, 'r')) { - openModeEnum |= OpenMode_ReadOnly; + openModeEnum |= OpenMode::ReadOnly; if (std::strchr(openMode, '+')) - openModeEnum |= OpenMode_ReadWrite | OpenMode_MustExist; + openModeEnum |= OpenMode_ReadWrite | OpenMode::MustExist; } else if (std::strchr(openMode, 'w')) { - openModeEnum |= OpenMode_WriteOnly | OpenMode_Truncate; + openModeEnum |= OpenMode::WriteOnly | OpenMode::Truncate; if (std::strchr(openMode, '+')) - openModeEnum |= OpenMode_ReadOnly; + openModeEnum |= OpenMode::ReadOnly; } else if (std::strchr(openMode, 'a')) { - openModeEnum |= OpenMode_WriteOnly | OpenMode_Append; + openModeEnum |= OpenMode::WriteOnly | OpenMode::Append; if (std::strchr(openMode, '+')) - openModeEnum |= OpenMode_ReadOnly; + openModeEnum |= OpenMode::ReadOnly; } else { @@ -109,7 +109,7 @@ aiFile* StreamOpener(aiFileIO* fileIO, const char* filePath, const char* openMod } if (!std::strchr(openMode, 'b')) - openModeEnum |= OpenMode_Text; + openModeEnum |= OpenMode::Text; std::unique_ptr file = std::make_unique(); if (!file->Open(filePath, openModeEnum)) diff --git a/src/Nazara/Audio/Formats/sndfileLoader.cpp b/src/Nazara/Audio/Formats/sndfileLoader.cpp index 2490724fb..91202c6f9 100644 --- a/src/Nazara/Audio/Formats/sndfileLoader.cpp +++ b/src/Nazara/Audio/Formats/sndfileLoader.cpp @@ -146,7 +146,7 @@ namespace Nz // Nous devons gérer nous-même le flux car il doit rester ouvert après le passage du loader // (les flux automatiquement ouverts par le ResourceLoader étant fermés après celui-ci) std::unique_ptr file = std::make_unique(); - if (!file->Open(filePath, OpenMode_ReadOnly)) + if (!file->Open(filePath, OpenMode::ReadOnly)) { NazaraError("Failed to open stream from file: " + Error::GetLastError()); return false; diff --git a/src/Nazara/Core/AbstractHash.cpp b/src/Nazara/Core/AbstractHash.cpp index dff2570bc..b70c3d5fc 100644 --- a/src/Nazara/Core/AbstractHash.cpp +++ b/src/Nazara/Core/AbstractHash.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -40,42 +41,42 @@ namespace Nz std::unique_ptr AbstractHash::Get(HashType type) { - NazaraAssert(type <= HashType_Max, "Hash type value out of enum"); + NazaraAssert(type <= HashType::Max, "Hash type value out of enum"); switch (type) { - case HashType_Fletcher16: + case HashType::Fletcher16: return std::make_unique(); - case HashType_CRC32: + case HashType::CRC32: return std::make_unique(); - case HashType_CRC64: + case HashType::CRC64: return std::make_unique(); - case HashType_MD5: + case HashType::MD5: return std::make_unique(); - case HashType_SHA1: + case HashType::SHA1: return std::make_unique(); - case HashType_SHA224: + case HashType::SHA224: return std::make_unique(); - case HashType_SHA256: + case HashType::SHA256: return std::make_unique(); - case HashType_SHA384: + case HashType::SHA384: return std::make_unique(); - case HashType_SHA512: + case HashType::SHA512: return std::make_unique(); - case HashType_Whirlpool: + case HashType::Whirlpool: return std::make_unique(); } - NazaraInternalError("Hash type not handled (0x" + NumberToString(type, 16) + ')'); + NazaraInternalError("Hash type not handled (0x" + NumberToString(UnderlyingCast(type), 16) + ')'); return nullptr; } } diff --git a/src/Nazara/Core/AbstractLogger.cpp b/src/Nazara/Core/AbstractLogger.cpp index 8eba0df9b..da9614364 100644 --- a/src/Nazara/Core/AbstractLogger.cpp +++ b/src/Nazara/Core/AbstractLogger.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include @@ -11,13 +12,13 @@ namespace Nz namespace { const char* errorType[] = { - "Assert failed: ", // ErrorType_AssertFailed - "Internal error: ", // ErrorType_Internal - "Error: ", // ErrorType_Normal - "Warning: " // ErrorType_Warning + "Assert failed: ", // ErrorType::AssertFailed + "Internal error: ", // ErrorType::Internal + "Error: ", // ErrorType::Normal + "Warning: " // ErrorType::Warning }; - static_assert(sizeof(errorType) / sizeof(const char*) == ErrorType_Max + 1, "Error type array is incomplete"); + static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete"); } /*! @@ -27,7 +28,6 @@ namespace Nz * * \remark This class is abstract */ - AbstractLogger::~AbstractLogger() = default; /*! @@ -39,11 +39,10 @@ namespace Nz * \param file Filename * \param function Name of the function throwing the error */ - void AbstractLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function) { std::ostringstream ss; - ss << errorType[type] << error; + ss << errorType[UnderlyingCast(type)] << error; if (line != 0 && file && function) ss << " (" << file << ':' << line << ": " << function << ')'; diff --git a/src/Nazara/Core/Error.cpp b/src/Nazara/Core/Error.cpp index 7f7b12232..ff928b24e 100644 --- a/src/Nazara/Core/Error.cpp +++ b/src/Nazara/Core/Error.cpp @@ -31,7 +31,7 @@ namespace Nz * \return Flag */ - UInt32 Error::GetFlags() + ErrorModeFlags Error::GetFlags() { return s_flags; } @@ -116,7 +116,7 @@ namespace Nz * \param flags Flags for the error */ - void Error::SetFlags(UInt32 flags) + void Error::SetFlags(ErrorModeFlags flags) { s_flags = flags; } @@ -133,7 +133,7 @@ namespace Nz void Error::Trigger(ErrorType type, std::string error) { - if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) + if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0 || (s_flags & ErrorMode::SilentDisabled) != 0) Log::WriteError(type, error); s_lastError = std::move(error); @@ -142,12 +142,12 @@ namespace Nz s_lastErrorLine = 0; #if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE - if (type == ErrorType_AssertFailed) + if (type == ErrorType::AssertFailed) std::abort(); #endif - if (type == ErrorType_AssertFailed || (type != ErrorType_Warning && - (s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0)) + if (type == ErrorType::AssertFailed || (type != ErrorType::Warning && + (s_flags & ErrorMode::ThrowException) != 0 && (s_flags & ErrorMode::ThrowExceptionDisabled) == 0)) throw std::runtime_error(s_lastError); } @@ -168,7 +168,7 @@ namespace Nz { file = GetCurrentFileRelativeToEngine(file); - if (type == ErrorType_AssertFailed || (s_flags & ErrorFlag_Silent) == 0 || (s_flags & ErrorFlag_SilentDisabled) != 0) + if (type == ErrorType::AssertFailed || (s_flags & ErrorMode::Silent) == 0 || (s_flags & ErrorMode::SilentDisabled) != 0) Log::WriteError(type, error, line, file, function); s_lastError = std::move(error); @@ -177,12 +177,12 @@ namespace Nz s_lastErrorLine = line; #if NAZARA_CORE_EXIT_ON_ASSERT_FAILURE - if (type == ErrorType_AssertFailed) + if (type == ErrorType::AssertFailed) std::abort(); #endif - if (type == ErrorType_AssertFailed || (type != ErrorType_Warning && - (s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0)) + if (type == ErrorType::AssertFailed || (type != ErrorType::Warning && + (s_flags & ErrorMode::ThrowException) != 0 && (s_flags & ErrorMode::ThrowExceptionDisabled) == 0)) throw std::runtime_error(s_lastError); } @@ -197,7 +197,7 @@ namespace Nz return file; } - UInt32 Error::s_flags = ErrorFlag_None; + ErrorModeFlags Error::s_flags = ErrorMode::None; std::string Error::s_lastError; const char* Error::s_lastErrorFunction = ""; const char* Error::s_lastErrorFile = ""; diff --git a/src/Nazara/Core/ErrorFlags.cpp b/src/Nazara/Core/ErrorFlags.cpp index 478799672..8a4b424ab 100644 --- a/src/Nazara/Core/ErrorFlags.cpp +++ b/src/Nazara/Core/ErrorFlags.cpp @@ -21,7 +21,7 @@ namespace Nz * \param replace Replace the entirely the old flag if true, else do a "OR" */ - ErrorFlags::ErrorFlags(UInt32 flags, bool replace) : + ErrorFlags::ErrorFlags(ErrorModeFlags flags, bool replace) : m_previousFlags(Error::GetFlags()) { SetFlags(flags, replace); @@ -40,8 +40,7 @@ namespace Nz * \brief Gets the previous flag * \return Previous flag */ - - UInt32 ErrorFlags::GetPreviousFlags() const + ErrorModeFlags ErrorFlags::GetPreviousFlags() const { return m_previousFlags; } @@ -52,8 +51,7 @@ namespace Nz * \param flags Flags for the error * \param replace Replace the entirely the old flag if true, else do a "OR" */ - - void ErrorFlags::SetFlags(UInt32 flags, bool replace) + void ErrorFlags::SetFlags(ErrorModeFlags flags, bool replace) { if (!replace) flags |= m_previousFlags; diff --git a/src/Nazara/Core/File.cpp b/src/Nazara/Core/File.cpp index 3b1be9ada..b40fd2b4d 100644 --- a/src/Nazara/Core/File.cpp +++ b/src/Nazara/Core/File.cpp @@ -91,7 +91,7 @@ namespace Nz { m_impl.reset(); - m_openMode = OpenMode_NotOpen; + m_openMode = OpenMode::NotOpen; } } @@ -226,13 +226,13 @@ namespace Nz if (m_filePath.empty()) return false; - if (openMode == OpenMode_NotOpen) + if (openMode == OpenMode::NotOpen) return false; std::unique_ptr impl = std::make_unique(this); if (!impl->Open(m_filePath, openMode)) { - ErrorFlags flags(ErrorFlag_Silent); // Silent by default + ErrorFlags flags(ErrorMode::Silent); // Silent by default NazaraError("Failed to open \"" + m_filePath.generic_u8string() + "\": " + Error::GetLastSystemError()); return false; } @@ -240,10 +240,10 @@ namespace Nz m_openMode = openMode; m_impl = std::move(impl); - if (m_openMode & OpenMode_Text) - m_streamOptions |= StreamOption_Text; + if (m_openMode & OpenMode::Text) + m_streamOptions |= StreamOption::Text; else - m_streamOptions &= ~StreamOption_Text; + m_streamOptions &= ~StreamOption::Text; return true; } @@ -296,7 +296,7 @@ namespace Nz { NazaraAssert(IsOpen(), "File is not open"); - return m_impl->SetCursorPos(CursorPosition_AtBegin, offset); + return m_impl->SetCursorPos(CursorPosition::AtBegin, offset); } /*! @@ -383,7 +383,7 @@ namespace Nz // If we don't have to read, we move forward UInt64 currentPos = m_impl->GetCursorPos(); - m_impl->SetCursorPos(CursorPosition_AtCurrent, size); + m_impl->SetCursorPos(CursorPosition::AtCurrent, size); return static_cast(m_impl->GetCursorPos() - currentPos); } @@ -429,7 +429,7 @@ namespace Nz NazaraAssert(hash, "Invalid hash"); File file(originalFile.GetPath()); - if (!file.Open(OpenMode_ReadOnly)) + if (!file.Open(OpenMode::ReadOnly)) { NazaraError("Unable to open file"); return false; diff --git a/src/Nazara/Core/HardwareInfo.cpp b/src/Nazara/Core/HardwareInfo.cpp index a048ef99b..e190507f5 100644 --- a/src/Nazara/Core/HardwareInfo.cpp +++ b/src/Nazara/Core/HardwareInfo.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -27,55 +28,53 @@ namespace Nz ProcessorVendor vendorEnum; }; - // Exceptionellement, la valeur "unknown" est intégrée - const char* vendorNames[] = + const char* s_vendorNames[] = { - "Unknown", // ProcessorVendor_Unknown - "Advanced Micro Devices", // ProcessorVendor_AMD - "Centaur Technology", // ProcessorVendor_Centaur - "Cyrix Corporation", // ProcessorVendor_Cyrix - "Intel Corporation", // ProcessorVendor_Intel - "Kernel-based Virtual Machine", // ProcessorVendor_KVM - "Microsoft Hyper-V", // ProcessorVendor_HyperV - "National Semiconductor", // ProcessorVendor_NSC - "NexGen", // ProcessorVendor_NexGen - "Rise Technology", // ProcessorVendor_Rise - "Silicon Integrated Systems", // ProcessorVendor_SIS - "Transmeta Corporation", // ProcessorVendor_Transmeta - "United Microelectronics Corporation", // ProcessorVendor_UMC - "VIA Technologies", // ProcessorVendor_VIA - "VMware", // ProcessorVendor_VMware - "Vortex86", // ProcessorVendor_Vortex - "Xen" // ProcessorVendor_XenHVM + "Advanced Micro Devices", // ProcessorVendor::AMD + "Centaur Technology", // ProcessorVendor::Centaur + "Cyrix Corporation", // ProcessorVendor::Cyrix + "Intel Corporation", // ProcessorVendor::Intel + "Kernel-based Virtual Machine", // ProcessorVendor::KVM + "Microsoft Hyper-V", // ProcessorVendor::HyperV + "National Semiconductor", // ProcessorVendor::NSC + "NexGen", // ProcessorVendor::NexGen + "Rise Technology", // ProcessorVendor::Rise + "Silicon Integrated Systems", // ProcessorVendor::SIS + "Transmeta Corporation", // ProcessorVendor::Transmeta + "United Microelectronics Corporation", // ProcessorVendor::UMC + "VIA Technologies", // ProcessorVendor::VIA + "VMware", // ProcessorVendor::VMware + "Vortex86", // ProcessorVendor::Vortex + "Xen" // ProcessorVendor::XenHVM }; - static_assert(sizeof(vendorNames)/sizeof(const char*) == ProcessorVendor_Max+2, "Processor vendor name array is incomplete"); + static_assert(sizeof(s_vendorNames)/sizeof(const char*) == ProcessorVendorCount, "Processor vendor name array is incomplete"); VendorString vendorStrings[] = { // Triés par ordre alphabétique (Majuscules primant sur minuscules) - {"AMDisbetter!", ProcessorVendor_AMD}, - {"AuthenticAMD", ProcessorVendor_AMD}, - {"CentaurHauls", ProcessorVendor_Centaur}, - {"CyrixInstead", ProcessorVendor_Cyrix}, - {"GenuineIntel", ProcessorVendor_Intel}, - {"GenuineTMx86", ProcessorVendor_Transmeta}, - {"Geode by NSC", ProcessorVendor_NSC}, - {"KVMKVMKVMKVM", ProcessorVendor_KVM}, - {"Microsoft Hv", ProcessorVendor_HyperV}, - {"NexGenDriven", ProcessorVendor_NexGen}, - {"RiseRiseRise", ProcessorVendor_Rise}, - {"SiS SiS SiS ", ProcessorVendor_SIS}, - {"TransmetaCPU", ProcessorVendor_Transmeta}, - {"UMC UMC UMC ", ProcessorVendor_UMC}, - {"VIA VIA VIA ", ProcessorVendor_VIA}, - {"VMwareVMware", ProcessorVendor_VMware}, - {"Vortex86 SoC", ProcessorVendor_Vortex}, - {"XenVMMXenVMM", ProcessorVendor_XenHVM} + {"AMDisbetter!", ProcessorVendor::AMD}, + {"AuthenticAMD", ProcessorVendor::AMD}, + {"CentaurHauls", ProcessorVendor::Centaur}, + {"CyrixInstead", ProcessorVendor::Cyrix}, + {"GenuineIntel", ProcessorVendor::Intel}, + {"GenuineTMx86", ProcessorVendor::Transmeta}, + {"Geode by NSC", ProcessorVendor::NSC}, + {"KVMKVMKVMKVM", ProcessorVendor::KVM}, + {"Microsoft Hv", ProcessorVendor::HyperV}, + {"NexGenDriven", ProcessorVendor::NexGen}, + {"RiseRiseRise", ProcessorVendor::Rise}, + {"SiS SiS SiS ", ProcessorVendor::SIS}, + {"TransmetaCPU", ProcessorVendor::Transmeta}, + {"UMC UMC UMC ", ProcessorVendor::UMC}, + {"VIA VIA VIA ", ProcessorVendor::VIA}, + {"VMwareVMware", ProcessorVendor::VMware}, + {"Vortex86 SoC", ProcessorVendor::Vortex}, + {"XenVMMXenVMM", ProcessorVendor::XenHVM} }; - ProcessorVendor s_vendorEnum = ProcessorVendor_Unknown; - bool s_capabilities[ProcessorCap_Max+1] = {false}; + ProcessorVendor s_vendorEnum = ProcessorVendor::Unknown; + bool s_capabilities[ProcessorCapCount] = {false}; bool s_initialized = false; char s_brandString[48] = "Not initialized"; @@ -155,7 +154,7 @@ namespace Nz if (!Initialize()) NazaraError("Failed to initialize HardwareInfo"); - return vendorNames[s_vendorEnum+1]; + return s_vendorNames[UnderlyingCast(s_vendorEnum)]; } /*! @@ -180,15 +179,7 @@ namespace Nz bool HardwareInfo::HasCapability(ProcessorCap capability) { - #ifdef NAZARA_DEBUG - if (capability > ProcessorCap_Max) - { - NazaraError("Capability type out of enum"); - return false; - } - #endif - - return s_capabilities[capability]; + return s_capabilities[UnderlyingCast(capability)]; } /*! @@ -226,7 +217,7 @@ namespace Nz UInt32 manufacturerId[3] = {ebx, edx, ecx}; // Identification of conceptor - s_vendorEnum = ProcessorVendor_Unknown; + s_vendorEnum = ProcessorVendor::Unknown; for (const VendorString& vendorString : vendorStrings) { if (std::memcmp(manufacturerId, vendorString.vendor, 12) == 0) @@ -238,18 +229,18 @@ namespace Nz if (eax >= 1) { - // Retrieval of certain capacities of the processor (ECX et EDX, function 1) + // Retrieval of certain capacities of the processor (ECX and EDX, function 1) HardwareInfoImpl::Cpuid(1, 0, registers); - s_capabilities[ProcessorCap_AVX] = (ecx & (1U << 28)) != 0; - s_capabilities[ProcessorCap_FMA3] = (ecx & (1U << 12)) != 0; - s_capabilities[ProcessorCap_MMX] = (edx & (1U << 23)) != 0; - s_capabilities[ProcessorCap_SSE] = (edx & (1U << 25)) != 0; - s_capabilities[ProcessorCap_SSE2] = (edx & (1U << 26)) != 0; - s_capabilities[ProcessorCap_SSE3] = (ecx & (1U << 0)) != 0; - s_capabilities[ProcessorCap_SSSE3] = (ecx & (1U << 9)) != 0; - s_capabilities[ProcessorCap_SSE41] = (ecx & (1U << 19)) != 0; - s_capabilities[ProcessorCap_SSE42] = (ecx & (1U << 20)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::AVX)] = (ecx & (1U << 28)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::FMA3)] = (ecx & (1U << 12)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::MMX)] = (edx & (1U << 23)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSE)] = (edx & (1U << 25)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSE2)] = (edx & (1U << 26)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSE3)] = (ecx & (1U << 0)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSSE3)] = (ecx & (1U << 9)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSE41)] = (ecx & (1U << 19)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSE42)] = (ecx & (1U << 20)) != 0; } // Retrieval of biggest extended function handled (EAX, function 0x80000000) @@ -261,10 +252,10 @@ namespace Nz // Retrieval of extended capabilities of the processor (ECX and EDX, function 0x80000001) HardwareInfoImpl::Cpuid(0x80000001, 0, registers); - s_capabilities[ProcessorCap_x64] = (edx & (1U << 29)) != 0; // Support of 64bits, independent of the OS - s_capabilities[ProcessorCap_FMA4] = (ecx & (1U << 16)) != 0; - s_capabilities[ProcessorCap_SSE4a] = (ecx & (1U << 6)) != 0; - s_capabilities[ProcessorCap_XOP] = (ecx & (1U << 11)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::x64)] = (edx & (1U << 29)) != 0; // Support of 64bits, independent of the OS + s_capabilities[UnderlyingCast(ProcessorCap::FMA4)] = (ecx & (1U << 16)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::SSE4a)] = (ecx & (1U << 6)) != 0; + s_capabilities[UnderlyingCast(ProcessorCap::XOP)] = (ecx & (1U << 11)) != 0; if (maxSupportedExtendedFunction >= 0x80000004) { diff --git a/src/Nazara/Core/MemoryView.cpp b/src/Nazara/Core/MemoryView.cpp index 12d8c3fe5..ef9062aa6 100644 --- a/src/Nazara/Core/MemoryView.cpp +++ b/src/Nazara/Core/MemoryView.cpp @@ -25,7 +25,7 @@ namespace Nz */ MemoryView::MemoryView(void* ptr, UInt64 size) : - Stream(StreamOption_None, OpenMode_ReadWrite), + Stream(StreamOption::None, OpenMode_ReadWrite), m_ptr(static_cast(ptr)), m_pos(0), m_size(size) @@ -42,7 +42,7 @@ namespace Nz */ MemoryView::MemoryView(const void* ptr, UInt64 size) : - Stream(StreamOption_None, OpenMode_ReadOnly), + Stream(StreamOption::None, OpenMode::ReadOnly), m_ptr(static_cast(const_cast(ptr))), //< Okay, right, const_cast is bad, but this pointer is still read-only m_pos(0), m_size(size) diff --git a/src/Nazara/Core/ParameterList.cpp b/src/Nazara/Core/ParameterList.cpp index 3ccf9c98f..87b80822a 100644 --- a/src/Nazara/Core/ParameterList.cpp +++ b/src/Nazara/Core/ParameterList.cpp @@ -62,7 +62,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -73,15 +73,15 @@ namespace Nz switch (it->second.type) { - case ParameterType_Boolean: + case ParameterType::Boolean: *value = it->second.value.boolVal; return true; - case ParameterType_Integer: + case ParameterType::Integer: *value = (it->second.value.intVal != 0); return true; - case ParameterType_String: + case ParameterType::String: { if (it->second.value.stringVal == "1" || it->second.value.stringVal == "yes" || it->second.value.stringVal == "true") { @@ -97,11 +97,11 @@ namespace Nz break; } - case ParameterType_Color: - case ParameterType_Double: - case ParameterType_None: - case ParameterType_Pointer: - case ParameterType_Userdata: + case ParameterType::Color: + case ParameterType::Double: + case ParameterType::None: + case ParameterType::Pointer: + case ParameterType::Userdata: break; } @@ -124,7 +124,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -135,17 +135,17 @@ namespace Nz switch (it->second.type) { - case ParameterType_Color: + case ParameterType::Color: *value = it->second.value.colorVal; return true; - case ParameterType_Boolean: - case ParameterType_Double: - case ParameterType_Integer: - case ParameterType_String: - case ParameterType_None: - case ParameterType_Pointer: - case ParameterType_Userdata: + case ParameterType::Boolean: + case ParameterType::Double: + case ParameterType::Integer: + case ParameterType::String: + case ParameterType::None: + case ParameterType::Pointer: + case ParameterType::Userdata: break; } @@ -170,7 +170,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -181,15 +181,15 @@ namespace Nz switch (it->second.type) { - case ParameterType_Double: + case ParameterType::Double: *value = it->second.value.doubleVal; return true; - case ParameterType_Integer: + case ParameterType::Integer: *value = static_cast(it->second.value.intVal); return true; - case ParameterType_String: + case ParameterType::String: { const std::string& str = it->second.value.stringVal; @@ -206,11 +206,11 @@ namespace Nz return true; } - case ParameterType_Boolean: - case ParameterType_Color: - case ParameterType_None: - case ParameterType_Pointer: - case ParameterType_Userdata: + case ParameterType::Boolean: + case ParameterType::Color: + case ParameterType::None: + case ParameterType::Pointer: + case ParameterType::Userdata: break; } @@ -236,7 +236,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -247,19 +247,19 @@ namespace Nz switch (it->second.type) { - case ParameterType_Boolean: + case ParameterType::Boolean: *value = (it->second.value.boolVal) ? 1 : 0; return true; - case ParameterType_Double: + case ParameterType::Double: *value = static_cast(it->second.value.doubleVal); return true; - case ParameterType_Integer: + case ParameterType::Integer: *value = it->second.value.intVal; return true; - case ParameterType_String: + case ParameterType::String: { const std::string& str = it->second.value.stringVal; @@ -276,10 +276,10 @@ namespace Nz return true; } - case ParameterType_Color: - case ParameterType_None: - case ParameterType_Pointer: - case ParameterType_Userdata: + case ParameterType::Color: + case ParameterType::None: + case ParameterType::Pointer: + case ParameterType::Userdata: break; } @@ -325,7 +325,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -336,20 +336,20 @@ namespace Nz switch (it->second.type) { - case ParameterType_Pointer: + case ParameterType::Pointer: *value = it->second.value.ptrVal; return true; - case ParameterType_Userdata: + case ParameterType::Userdata: *value = it->second.value.userdataVal->ptr; return true; - case ParameterType_Boolean: - case ParameterType_Color: - case ParameterType_Double: - case ParameterType_Integer: - case ParameterType_None: - case ParameterType_String: + case ParameterType::Boolean: + case ParameterType::Color: + case ParameterType::Double: + case ParameterType::Integer: + case ParameterType::None: + case ParameterType::String: break; } @@ -379,7 +379,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -390,35 +390,35 @@ namespace Nz switch (it->second.type) { - case ParameterType_Boolean: + case ParameterType::Boolean: *value = (it->second.value.boolVal) ? "true" : "false"; return true; - case ParameterType_Color: + case ParameterType::Color: *value = it->second.value.colorVal.ToString(); return true; - case ParameterType_Double: + case ParameterType::Double: *value = std::to_string(it->second.value.doubleVal); return true; - case ParameterType_Integer: + case ParameterType::Integer: *value = std::to_string(it->second.value.intVal); return true; - case ParameterType_String: + case ParameterType::String: *value = it->second.value.stringVal; return true; - case ParameterType_Pointer: + case ParameterType::Pointer: *value = PointerToString(it->second.value.ptrVal); return true; - case ParameterType_Userdata: + case ParameterType::Userdata: *value = PointerToString(it->second.value.userdataVal->ptr); return true; - case ParameterType_None: + case ParameterType::None: *value = std::string(); return true; } @@ -444,7 +444,7 @@ namespace Nz { NazaraAssert(value, "Invalid pointer"); - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowExceptionDisabled); auto it = m_parameters.find(name); if (it == m_parameters.end()) @@ -455,7 +455,7 @@ namespace Nz const auto& parameter = it->second; - if (parameter.type == ParameterType_Userdata) + if (parameter.type == ParameterType::Userdata) { *value = parameter.value.userdataVal->ptr; return true; @@ -506,7 +506,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_None; + parameter.type = ParameterType::None; } /*! @@ -520,7 +520,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, const Color& value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_Color; + parameter.type = ParameterType::Color; PlacementNew(¶meter.value.colorVal, value); } @@ -536,7 +536,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, const std::string& value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_String; + parameter.type = ParameterType::String; PlacementNew(¶meter.value.stringVal, value); } @@ -552,7 +552,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, const char* value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_String; + parameter.type = ParameterType::String; PlacementNew(¶meter.value.stringVal, value); } @@ -568,7 +568,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, bool value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_Boolean; + parameter.type = ParameterType::Boolean; parameter.value.boolVal = value; } @@ -583,7 +583,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, double value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_Double; + parameter.type = ParameterType::Double; parameter.value.doubleVal = value; } @@ -598,7 +598,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, long long value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_Integer; + parameter.type = ParameterType::Integer; parameter.value.intVal = value; } @@ -616,7 +616,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, void* value) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_Pointer; + parameter.type = ParameterType::Pointer; parameter.value.ptrVal = value; } @@ -637,28 +637,28 @@ namespace Nz ss << it->first << ": "; switch (it->second.type) { - case ParameterType_Boolean: + case ParameterType::Boolean: ss << "Boolean(" << parameter.value.boolVal << ")"; break; - case ParameterType_Color: + case ParameterType::Color: ss << "Color(" << parameter.value.colorVal << ")"; break; - case ParameterType_Double: + case ParameterType::Double: ss << "Double(" << parameter.value.doubleVal << ")"; break; - case ParameterType_Integer: + case ParameterType::Integer: ss << "Integer(" << parameter.value.intVal << ")"; break; - case ParameterType_String: + case ParameterType::String: ss << "std::string(" << parameter.value.stringVal << ")"; break; - case ParameterType_Pointer: + case ParameterType::Pointer: ss << "Pointer(" << parameter.value.ptrVal << ")"; break; - case ParameterType_Userdata: + case ParameterType::Userdata: ss << "Userdata(" << parameter.value.userdataVal->ptr << ")"; break; - case ParameterType_None: + case ParameterType::None: ss << "None"; break; } @@ -686,7 +686,7 @@ namespace Nz void ParameterList::SetParameter(const std::string& name, void* value, Destructor destructor) { Parameter& parameter = CreateValue(name); - parameter.type = ParameterType_Userdata; + parameter.type = ParameterType::Userdata; parameter.value.userdataVal = new Parameter::UserdataValue(destructor, value); } @@ -706,28 +706,28 @@ namespace Nz switch (it->second.type) { - case ParameterType_Boolean: - case ParameterType_Color: - case ParameterType_Double: - case ParameterType_Integer: - case ParameterType_Pointer: + case ParameterType::Boolean: + case ParameterType::Color: + case ParameterType::Double: + case ParameterType::Integer: + case ParameterType::Pointer: std::memcpy(¶meter, &it->second, sizeof(Parameter)); break; - case ParameterType_String: - parameter.type = ParameterType_String; + case ParameterType::String: + parameter.type = ParameterType::String; PlacementNew(¶meter.value.stringVal, it->second.value.stringVal); break; - case ParameterType_Userdata: - parameter.type = ParameterType_Userdata; + case ParameterType::Userdata: + parameter.type = ParameterType::Userdata; parameter.value.userdataVal = it->second.value.userdataVal; ++(parameter.value.userdataVal->counter); break; - case ParameterType_None: - parameter.type = ParameterType_None; + case ParameterType::None: + parameter.type = ParameterType::None; break; } } @@ -762,11 +762,11 @@ namespace Nz { switch (parameter.type) { - case ParameterType_String: + case ParameterType::String: PlacementDestroy(¶meter.value.stringVal); break; - case ParameterType_Userdata: + case ParameterType::Userdata: { Parameter::UserdataValue* userdata = parameter.value.userdataVal; if (--userdata->counter == 0) @@ -777,12 +777,12 @@ namespace Nz break; } - case ParameterType_Boolean: - case ParameterType_Color: - case ParameterType_Double: - case ParameterType_Integer: - case ParameterType_None: - case ParameterType_Pointer: + case ParameterType::Boolean: + case ParameterType::Color: + case ParameterType::Double: + case ParameterType::Integer: + case ParameterType::None: + case ParameterType::Pointer: break; } } diff --git a/src/Nazara/Core/PluginManager.cpp b/src/Nazara/Core/PluginManager.cpp index ffbbeda67..44d14d4c7 100644 --- a/src/Nazara/Core/PluginManager.cpp +++ b/src/Nazara/Core/PluginManager.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -15,9 +16,9 @@ namespace Nz using PluginLoad = int (*)(); using PluginUnload = void (*)(); - std::filesystem::path s_pluginFiles[] = + const char* s_pluginFiles[] = { - "PluginAssimp", // Plugin_Assimp + "PluginAssimp", // Plugin::Assimp }; } @@ -77,7 +78,7 @@ namespace Nz bool PluginManager::Mount(Plugin plugin) { - std::filesystem::path pluginName = s_pluginFiles[plugin]; + std::filesystem::path pluginName = s_pluginFiles[UnderlyingCast(plugin)]; #ifdef NAZARA_DEBUG std::filesystem::path debugPath = pluginName; @@ -195,7 +196,7 @@ namespace Nz void PluginManager::Unmount(Plugin plugin) { - Unmount(s_pluginFiles[plugin]); + Unmount(s_pluginFiles[UnderlyingCast(plugin)]); } /*! diff --git a/src/Nazara/Core/Posix/FileImpl.cpp b/src/Nazara/Core/Posix/FileImpl.cpp index b64370fbb..f994475c6 100644 --- a/src/Nazara/Core/Posix/FileImpl.cpp +++ b/src/Nazara/Core/Posix/FileImpl.cpp @@ -3,11 +3,12 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include -#include #include +#include #include #include @@ -61,20 +62,20 @@ namespace Nz if ((mode & OpenMode_ReadWrite) == OpenMode_ReadWrite) flags = O_CREAT | O_RDWR; - else if ((mode & OpenMode_ReadOnly) == OpenMode_ReadOnly) + else if ((mode & OpenMode::ReadOnly) == OpenMode::ReadOnly) flags = O_RDONLY; - else if ((mode & OpenMode_WriteOnly) == OpenMode_WriteOnly) + else if ((mode & OpenMode::WriteOnly) == OpenMode::WriteOnly) flags = O_CREAT | O_WRONLY; else return false; - if (mode & OpenMode_Append) + if (mode & OpenMode::Append) flags |= O_APPEND; - if (mode & OpenMode_MustExist) + if (mode & OpenMode::MustExist) flags &= ~O_CREAT; - if (mode & OpenMode_Truncate) + if (mode & OpenMode::Truncate) flags |= O_TRUNC; int fileDescriptor = Open_def(filePath.generic_u8string().data(), flags, permissions); @@ -111,7 +112,7 @@ namespace Nz return false; } - if (mode & OpenMode_Lock) + if (mode & OpenMode::Lock) { initialize_flock(lock); @@ -147,20 +148,20 @@ namespace Nz int moveMethod; switch (pos) { - case CursorPosition_AtBegin: + case CursorPosition::AtBegin: moveMethod = SEEK_SET; break; - case CursorPosition_AtCurrent: + case CursorPosition::AtCurrent: moveMethod = SEEK_CUR; break; - case CursorPosition_AtEnd: + case CursorPosition::AtEnd: moveMethod = SEEK_END; break; default: - NazaraInternalError("Cursor position not handled (0x" + NumberToString(pos, 16) + ')'); + NazaraInternalError("Cursor position not handled (0x" + NumberToString(UnderlyingCast(pos), 16) + ')'); return false; } diff --git a/src/Nazara/Core/StdLogger.cpp b/src/Nazara/Core/StdLogger.cpp index 92602393b..8e7225cb6 100644 --- a/src/Nazara/Core/StdLogger.cpp +++ b/src/Nazara/Core/StdLogger.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include @@ -11,13 +12,13 @@ namespace Nz namespace { const char* errorType[] = { - "Assert failed", // ErrorType_AssertFailed - "Internal error", // ErrorType_Internal - "Error", // ErrorType_Normal - "Warning" // ErrorType_Warning + "Assert failed", // ErrorType::AssertFailed + "Internal error", // ErrorType::Internal + "Error", // ErrorType::Normal + "Warning" // ErrorType::Warning }; - static_assert(sizeof(errorType) / sizeof(const char*) == ErrorType_Max + 1, "Error type array is incomplete"); + static_assert(sizeof(errorType) / sizeof(const char*) == ErrorTypeCount, "Error type array is incomplete"); } /*! @@ -80,7 +81,7 @@ namespace Nz void StdLogger::WriteError(ErrorType type, const std::string_view& error, unsigned int line, const char* file, const char* function) { - fprintf(stderr, "%s: ", errorType[type]); + fprintf(stderr, "%s: ", errorType[UnderlyingCast(type)]); fwrite(error.data(), sizeof(char), error.size(), stdout); if (line != 0 && file && function) diff --git a/src/Nazara/Core/Stream.cpp b/src/Nazara/Core/Stream.cpp index 9abc0a14a..1b4a6030b 100644 --- a/src/Nazara/Core/Stream.cpp +++ b/src/Nazara/Core/Stream.cpp @@ -78,7 +78,7 @@ namespace Nz std::ptrdiff_t pos = ptr - buffer; if (ptr != buffer) { - if (m_streamOptions & StreamOption_Text && buffer[pos - 1] == '\r') + if (m_streamOptions & StreamOption::Text && buffer[pos - 1] == '\r') line.append(buffer, pos - 1); else line.append(buffer, pos); @@ -92,7 +92,7 @@ namespace Nz else { std::size_t length = readSize; - if (m_streamOptions & StreamOption_Text && buffer[length - 1] == '\r') + if (m_streamOptions & StreamOption::Text && buffer[length - 1] == '\r') { if (!SetCursorPos(GetCursorPos() - 1)) NazaraWarning("Failed to reset cursor pos"); @@ -112,7 +112,7 @@ namespace Nz std::size_t pos = line.find('\n'); if (pos <= readSize) // False only if the character is not available (npos being the biggest integer) { - if (m_streamOptions & StreamOption_Text && pos > 0 && line[pos - 1] == '\r') + if (m_streamOptions & StreamOption::Text && pos > 0 && line[pos - 1] == '\r') line.resize(pos); else line.resize(pos + 1); @@ -149,7 +149,7 @@ namespace Nz bool Stream::Write(const std::string_view& string) { - if (m_streamOptions & StreamOption_Text) + if (m_streamOptions & StreamOption::Text) { #if defined(NAZARA_PLATFORM_WINDOWS) std::string temp(string); diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index 71274fc47..69f38ff9f 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -63,30 +63,30 @@ namespace Nz DWORD shareMode = FILE_SHARE_READ; DWORD openMode = 0; - if (mode & OpenMode_ReadOnly) + if (mode & OpenMode::ReadOnly) { access |= GENERIC_READ; - if (mode & OpenMode_MustExist || (mode & OpenMode_WriteOnly) == 0) + if (mode & OpenMode::MustExist || (mode & OpenMode::WriteOnly) == 0) openMode |= OPEN_EXISTING; } - if (mode & OpenMode_WriteOnly) + if (mode & OpenMode::WriteOnly) { - if (mode & OpenMode_Append) + if (mode & OpenMode::Append) access |= FILE_APPEND_DATA; else access |= GENERIC_WRITE; - if (mode & OpenMode_Truncate) + if (mode & OpenMode::Truncate) openMode |= CREATE_ALWAYS; - else if (mode & OpenMode_MustExist) + else if (mode & OpenMode::MustExist) openMode |= OPEN_EXISTING; else openMode |= OPEN_ALWAYS; } - if ((mode & OpenMode_Lock) == 0) + if ((mode & OpenMode::Lock) == 0) shareMode |= FILE_SHARE_WRITE; m_handle = CreateFileW(ToWideString(filePath.generic_u8string()).data(), access, shareMode, nullptr, openMode, 0, nullptr); @@ -136,20 +136,20 @@ namespace Nz DWORD moveMethod; switch (pos) { - case CursorPosition_AtBegin: + case CursorPosition::AtBegin: moveMethod = FILE_BEGIN; break; - case CursorPosition_AtCurrent: + case CursorPosition::AtCurrent: moveMethod = FILE_CURRENT; break; - case CursorPosition_AtEnd: + case CursorPosition::AtEnd: moveMethod = FILE_END; break; default: - NazaraInternalError("Cursor position not handled (0x" + NumberToString(pos, 16) + ')'); + NazaraInternalError("Cursor position not handled (0x" + NumberToString(UnderlyingCast(pos), 16) + ')'); return false; } @@ -167,11 +167,11 @@ namespace Nz CallOnExit resetCursor([this, cursorPos] () { - if (!SetCursorPos(CursorPosition_AtBegin, cursorPos)) + if (!SetCursorPos(CursorPosition::AtBegin, cursorPos)) NazaraWarning("Failed to reset cursor position to previous position: " + Error::GetLastSystemError()); }); - if (!SetCursorPos(CursorPosition_AtBegin, size)) + if (!SetCursorPos(CursorPosition::AtBegin, size)) { NazaraError("Failed to set file size: failed to move cursor position: " + Error::GetLastSystemError()); return false; diff --git a/src/Nazara/Network/AbstractSocket.cpp b/src/Nazara/Network/AbstractSocket.cpp index 205ead63e..af7ed396c 100644 --- a/src/Nazara/Network/AbstractSocket.cpp +++ b/src/Nazara/Network/AbstractSocket.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -32,9 +33,9 @@ namespace Nz */ AbstractSocket::AbstractSocket(SocketType type) : - m_lastError(SocketError_NoError), + m_lastError(SocketError::NoError), m_handle(SocketImpl::InvalidHandle), - m_state(SocketState_NotConnected), + m_state(SocketState::NotConnected), m_type(type), m_isBlockingEnabled(true) { @@ -165,7 +166,7 @@ namespace Nz void AbstractSocket::OnClose() { - UpdateState(SocketState_NotConnected); + UpdateState(SocketState::NotConnected); } /*! @@ -178,7 +179,7 @@ namespace Nz { SocketError errorCode; if (!SocketImpl::SetBlocking(m_handle, m_isBlockingEnabled, &errorCode)) - NazaraWarning("Failed to set socket blocking mode (0x" + NumberToString(errorCode, 16) + ')'); + NazaraWarning("Failed to set socket blocking mode (0x" + NumberToString(UnderlyingCast(errorCode), 16) + ')'); } /*! @@ -190,11 +191,11 @@ namespace Nz { if (m_handle == SocketImpl::InvalidHandle || m_protocol != protocol) { - SocketHandle handle = SocketImpl::Create((protocol == NetProtocol_Any) ? NetProtocol_IPv6 : protocol, m_type, &m_lastError); + SocketHandle handle = SocketImpl::Create((protocol == NetProtocol::Any) ? NetProtocol::IPv6 : protocol, m_type, &m_lastError); if (handle == SocketImpl::InvalidHandle) return false; - if (protocol == NetProtocol_Any) + if (protocol == NetProtocol::Any) { if (!SocketImpl::SetIPv6Only(handle, false, &m_lastError)) { @@ -204,7 +205,7 @@ namespace Nz return false; } - protocol = NetProtocol_IPv6; + protocol = NetProtocol::IPv6; } m_protocol = protocol; diff --git a/src/Nazara/Network/AlgorithmNetwork.cpp b/src/Nazara/Network/AlgorithmNetwork.cpp index bc9bbb811..4b3972aac 100644 --- a/src/Nazara/Network/AlgorithmNetwork.cpp +++ b/src/Nazara/Network/AlgorithmNetwork.cpp @@ -88,31 +88,31 @@ namespace Nz { switch (resolveError) { - case ResolveError_NoError: + case ResolveError::NoError: return "No error"; - case ResolveError_Internal: + case ResolveError::Internal: return "An internal error occurred"; - case ResolveError_ResourceError: + case ResolveError::ResourceError: return "The operating system lacks the resources to proceed"; - case ResolveError_NonRecoverable: + case ResolveError::NonRecoverable: return "A nonrecoverable error occurred"; - case ResolveError_NotFound: + case ResolveError::NotFound: return "No such host is known"; - case ResolveError_NotInitialized: + case ResolveError::NotInitialized: return "Nazara Network has not been initialized"; - case ResolveError_ProtocolNotSupported: + case ResolveError::ProtocolNotSupported: return "A specified protocol is not supported by the server"; - case ResolveError_TemporaryFailure: + case ResolveError::TemporaryFailure: return "A temporary failure occurred, try again"; - case ResolveError_Unknown: + case ResolveError::Unknown: return "An unknown error occurred"; default: @@ -131,52 +131,52 @@ namespace Nz { switch (socketError) { - case SocketError_NoError: + case SocketError::NoError: return "No error"; - case SocketError_AddressNotAvailable: + case SocketError::AddressNotAvailable: return "The address is already in use"; - case SocketError_ConnectionClosed: + case SocketError::ConnectionClosed: return "The connection has been closed"; - case SocketError_ConnectionRefused: + case SocketError::ConnectionRefused: return "The connection attempt was refused"; - case SocketError_DatagramSize: + case SocketError::DatagramSize: return "The datagram size is over the system limit"; - case SocketError_Internal: + case SocketError::Internal: return "An internal error occurred"; - case SocketError_Interrupted: + case SocketError::Interrupted: return "The operation was interrupted by a signal"; - case SocketError_Packet: + case SocketError::Packet: return "Packet encoding or decoding failed"; - case SocketError_NetworkError: + case SocketError::NetworkError: return "Networking subsystem failed"; - case SocketError_NotInitialized: + case SocketError::NotInitialized: return "Network module has not been initialized"; - case SocketError_NotSupported: + case SocketError::NotSupported: return "This operation is not supported"; - case SocketError_ResolveError: + case SocketError::ResolveError: return "The hostname couldn't be resolved"; - case SocketError_ResourceError: + case SocketError::ResourceError: return "The operating system lacks the resources to proceed"; - case SocketError_TimedOut: + case SocketError::TimedOut: return "The operation timed out"; - case SocketError_Unknown: + case SocketError::Unknown: return "An unknown error occurred"; - case SocketError_UnreachableHost: + case SocketError::UnreachableHost: return "The host is not reachable"; default: diff --git a/src/Nazara/Network/ENetHost.cpp b/src/Nazara/Network/ENetHost.cpp index 778fcdac0..92ddcdd49 100644 --- a/src/Nazara/Network/ENetHost.cpp +++ b/src/Nazara/Network/ENetHost.cpp @@ -89,9 +89,9 @@ namespace Nz UInt32 windowSize; if (m_outgoingBandwidth == 0) - windowSize = ENetProtocol_MaximumWindowSize; + windowSize = ENetConstants::ENetProtocol_MaximumWindowSize; else - windowSize = (m_outgoingBandwidth / ENetConstants::ENetPeer_WindowSizeScale) * ENetProtocol_MinimumWindowSize; + windowSize = (m_outgoingBandwidth / ENetConstants::ENetPeer_WindowSizeScale) * ENetConstants::ENetProtocol_MinimumWindowSize; ENetPeer& peer = m_peers[peerId]; peer.InitOutgoing(channelCount, remoteAddress, ++m_randomSeed, windowSize); @@ -134,7 +134,7 @@ namespace Nz if (!hostnameAddress.IsValid()) { if (error) - *error = ResolveError_NotFound; + *error = ResolveError::NotFound; return nullptr; } @@ -320,7 +320,7 @@ namespace Nz bool ENetHost::InitSocket(const IpAddress& address) { - if (!m_socket.Create((m_isUsingDualStack) ? NetProtocol_Any : address.GetProtocol())) + if (!m_socket.Create((m_isUsingDualStack) ? NetProtocol::Any : address.GetProtocol())) return false; m_socket.EnableBlocking(false); @@ -330,14 +330,14 @@ namespace Nz if (address.IsValid() && !address.IsLoopback()) { - if (m_socket.Bind(address) != SocketState_Bound) + if (m_socket.Bind(address) != SocketState::Bound) { NazaraError("Failed to bind address " + address.ToString()); return false; } } - m_poller.RegisterSocket(m_socket, SocketPollEvent_Read); + m_poller.RegisterSocket(m_socket, SocketPollEvent::Read); return true; } @@ -417,7 +417,7 @@ namespace Nz UInt32 channelCount = NetToHost(command->connect.channelCount); - if (channelCount < ENetProtocol_MinimumChannelCount || channelCount > ENetProtocol_MaximumChannelCount) + if (channelCount < ENetConstants::ENetProtocol_MinimumChannelCount || channelCount > ENetConstants::ENetProtocol_MaximumChannelCount) return nullptr; std::size_t duplicatePeers = 0; diff --git a/src/Nazara/Network/IpAddress.cpp b/src/Nazara/Network/IpAddress.cpp index fbb528488..e38584f51 100644 --- a/src/Nazara/Network/IpAddress.cpp +++ b/src/Nazara/Network/IpAddress.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -47,14 +48,14 @@ namespace Nz m_isValid = true; if (isIPv6) { - m_protocol = NetProtocol_IPv6; + m_protocol = NetProtocol::IPv6; for (unsigned int i = 0; i < 8; ++i) m_ipv6[i] = UInt32(result[i*2]) << 8 | result[i*2 + 1]; } else { - m_protocol = NetProtocol_IPv4; + m_protocol = NetProtocol::IPv4; for (unsigned int i = 0; i < 4; ++i) m_ipv4[i] = result[i]; @@ -75,21 +76,21 @@ namespace Nz if (!m_isValid) return false; - NazaraAssert(m_protocol <= NetProtocol_Max, "Protocol has value out of enum"); + NazaraAssert(m_protocol <= NetProtocol::Max, "Protocol has value out of enum"); switch (m_protocol) { - case NetProtocol_Any: - case NetProtocol_Unknown: + case NetProtocol::Any: + case NetProtocol::Unknown: break; - case NetProtocol_IPv4: + case NetProtocol::IPv4: return m_ipv4[0] == 127; - case NetProtocol_IPv6: + case NetProtocol::IPv6: return m_ipv6 == LoopbackIpV6.m_ipv6; // Only compare the ip value } - NazaraInternalError("Invalid protocol for IpAddress (0x" + NumberToString(m_protocol) + ')'); + NazaraInternalError("Invalid protocol for IpAddress (0x" + NumberToString(UnderlyingCast(m_protocol), 16) + ')'); return false; } @@ -106,14 +107,14 @@ namespace Nz if (m_isValid) { - NazaraAssert(m_protocol <= NetProtocol_Max, "Protocol has value out of enum"); + NazaraAssert(m_protocol <= NetProtocol::Max, "Protocol has value out of enum"); switch (m_protocol) { - case NetProtocol_Any: - case NetProtocol_Unknown: + case NetProtocol::Any: + case NetProtocol::Unknown: break; - case NetProtocol_IPv4: + case NetProtocol::IPv4: for (unsigned int i = 0; i < 4; ++i) { stream << int(m_ipv4[i]); @@ -122,7 +123,7 @@ namespace Nz } break; - case NetProtocol_IPv6: + case NetProtocol::IPv6: // Canonical representation of an IPv6 // https://tools.ietf.org/html/rfc5952 @@ -213,7 +214,7 @@ namespace Nz */ std::vector IpAddress::ResolveHostname(NetProtocol protocol, const std::string& hostname, const std::string& service, ResolveError* error) { - NazaraAssert(protocol != NetProtocol_Unknown, "Invalid protocol"); + NazaraAssert(protocol != NetProtocol::Unknown, "Invalid protocol"); return IpAddressImpl::ResolveHostname(protocol, hostname, service, error); } diff --git a/src/Nazara/Network/Linux/SocketPollerImpl.cpp b/src/Nazara/Network/Linux/SocketPollerImpl.cpp index be848deb1..fa1b39b16 100644 --- a/src/Nazara/Network/Linux/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Linux/SocketPollerImpl.cpp @@ -53,10 +53,10 @@ namespace Nz entry.data.fd = socket; - if (eventFlags & SocketPollEvent_Read) + if (eventFlags & SocketPollEvent::Read) entry.events |= EPOLLIN; - if (eventFlags & SocketPollEvent_Write) + if (eventFlags & SocketPollEvent::Write) entry.events |= EPOLLOUT; if (epoll_ctl(m_handle, EPOLL_CTL_ADD, socket, &entry) != 0) @@ -123,7 +123,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return activeSockets; } diff --git a/src/Nazara/Network/NetPacket.cpp b/src/Nazara/Network/NetPacket.cpp index 24db7be0c..dafeac959 100644 --- a/src/Nazara/Network/NetPacket.cpp +++ b/src/Nazara/Network/NetPacket.cpp @@ -41,7 +41,7 @@ namespace Nz const void* NetPacket::OnSend(std::size_t* newSize) const { NazaraAssert(newSize, "Invalid size pointer"); - NazaraAssert(m_netCode != NetCode_Invalid, "Invalid NetCode"); + NazaraAssert(m_netCode != 0, "Invalid NetCode"); std::size_t size = m_buffer->GetSize(); if (!EncodeHeader(m_buffer->GetBuffer(), static_cast(size), m_netCode)) diff --git a/src/Nazara/Network/Network.cpp b/src/Nazara/Network/Network.cpp index 6d5b6b076..78b28cd9b 100644 --- a/src/Nazara/Network/Network.cpp +++ b/src/Nazara/Network/Network.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #if defined(NAZARA_PLATFORM_WINDOWS) #include @@ -40,15 +39,11 @@ namespace Nz if (!NetPacket::Initialize()) throw std::runtime_error("failed to initialize packets"); - - if (!RUdpConnection::Initialize()) - throw std::runtime_error("failed to initialize RUDP protocol"); } Network::~Network() { // Uninitialize module here - RUdpConnection::Uninitialize(); NetPacket::Uninitialize(); SocketImpl::Uninitialize(); } diff --git a/src/Nazara/Network/Posix/IpAddressImpl.cpp b/src/Nazara/Network/Posix/IpAddressImpl.cpp index ac643896c..8a8cc87f9 100644 --- a/src/Nazara/Network/Posix/IpAddressImpl.cpp +++ b/src/Nazara/Network/Posix/IpAddressImpl.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -132,7 +133,7 @@ namespace Nz } if (error) - *error = ResolveError_NoError; + *error = ResolveError::NoError; return true; } @@ -174,7 +175,7 @@ namespace Nz } if (error) - *error = ResolveError_NoError; + *error = ResolveError::NoError; return results; } @@ -185,7 +186,7 @@ namespace Nz { switch (ipAddress.GetProtocol()) { - case NetProtocol_IPv4: + case NetProtocol::IPv4: { sockaddr_in* socketAddress = reinterpret_cast(buffer); @@ -197,7 +198,7 @@ namespace Nz return sizeof(sockaddr_in); } - case NetProtocol_IPv6: + case NetProtocol::IPv6: { sockaddr_in6* socketAddress = reinterpret_cast(buffer); @@ -217,7 +218,7 @@ namespace Nz } default: - NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(ipAddress.GetProtocol(), 16) + ')'); + NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(UnderlyingCast(ipAddress.GetProtocol()), 16) + ')'); break; } } @@ -231,13 +232,13 @@ namespace Nz switch (family) { case PF_INET: - return NetProtocol_IPv4; + return NetProtocol::IPv4; case PF_INET6: - return NetProtocol_IPv6; + return NetProtocol::IPv6; default: - return NetProtocol_Unknown; + return NetProtocol::Unknown; } } @@ -246,16 +247,16 @@ namespace Nz switch (socketType) { case SOCK_STREAM: - return SocketType_TCP; + return SocketType::TCP; case SOCK_DGRAM: - return SocketType_UDP; + return SocketType::UDP; case SOCK_RAW: - return SocketType_Raw; + return SocketType::Raw; default: - return SocketType_Unknown; + return SocketType::Unknown; } } @@ -265,35 +266,35 @@ namespace Nz switch (error) { case 0: - return ResolveError_NoError; + return ResolveError::NoError; // Engine error case EAI_BADFLAGS: case EAI_SYSTEM: - return ResolveError_Internal; + return ResolveError::Internal; case EAI_FAMILY: case EAI_SERVICE: case EAI_SOCKTYPE: - return ResolveError_ProtocolNotSupported; + return ResolveError::ProtocolNotSupported; case EAI_NONAME: - return ResolveError_NotFound; + return ResolveError::NotFound; case EAI_FAIL: - return ResolveError_NonRecoverable; + return ResolveError::NonRecoverable; case EAI_NODATA: - return ResolveError_NotInitialized; + return ResolveError::NotInitialized; case EAI_MEMORY: - return ResolveError_ResourceError; + return ResolveError::ResourceError; case EAI_AGAIN: - return ResolveError_TemporaryFailure; + return ResolveError::TemporaryFailure; } NazaraWarning("Unhandled EAI error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ") as " + gai_strerror(error)); - return ResolveError_Unknown; + return ResolveError::Unknown; } } diff --git a/src/Nazara/Network/Posix/SocketImpl.cpp b/src/Nazara/Network/Posix/SocketImpl.cpp index 0e826952b..efb08ea0c 100644 --- a/src/Nazara/Network/Posix/SocketImpl.cpp +++ b/src/Nazara/Network/Posix/SocketImpl.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -41,7 +42,7 @@ namespace Nz *address = IpAddressImpl::FromSockAddr(reinterpret_cast(&nameBuffer)); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; } else { @@ -65,19 +66,19 @@ namespace Nz if (error) *error = TranslateErrnoToSocketError(GetLastErrorCode()); - return SocketState_NotConnected; + return SocketState::NotConnected; } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; - return SocketState_Bound; + return SocketState::Bound; } SocketHandle SocketImpl::Create(NetProtocol protocol, SocketType type, SocketError* error) { - NazaraAssert(protocol != NetProtocol_Any, "Any protocol is not supported for socket creation"); - NazaraAssert(type <= SocketType_Max, "Type has value out of enum"); + NazaraAssert(protocol != NetProtocol::Any, "Any protocol is not supported for socket creation"); + NazaraAssert(type <= SocketType::Max, "Type has value out of enum"); SocketHandle handle = socket(TranslateNetProtocolToAF(protocol), TranslateSocketTypeToSock(type), 0); if (handle == InvalidHandle && error != nullptr) @@ -98,7 +99,7 @@ namespace Nz { NazaraAssert(handle != InvalidHandle, "Invalid handle"); - if (GetLastError(handle, nullptr) < 0) + if (GetLastError(handle, nullptr) != SocketError::Internal) NazaraWarning("Failed to clear socket error code: " + Error::GetLastSystemError(GetLastErrorCode())); } @@ -111,7 +112,7 @@ namespace Nz int bufferLength = IpAddressImpl::ToSockAddr(address, nameBuffer.data()); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; // Clear socket error status ClearErrorCode(handle); @@ -123,24 +124,24 @@ namespace Nz { case EALREADY: case EINPROGRESS: - return SocketState_Connecting; + return SocketState::Connecting; case EISCONN: - return SocketState_Connected; + return SocketState::Connected; } if (error) { if (errorCode == EADDRNOTAVAIL) - *error = SocketError_ConnectionRefused; //< ConnectionRefused seems more legit than AddressNotAvailable in connect case + *error = SocketError::ConnectionRefused; //< ConnectionRefused seems more legit than AddressNotAvailable in connect case else *error = TranslateErrnoToSocketError(errorCode); } - return SocketState_NotConnected; + return SocketState::NotConnected; } - return SocketState_Connected; + return SocketState::Connected; } bool SocketImpl::Initialize() @@ -152,7 +153,7 @@ namespace Nz { int code = GetLastErrorCode(handle, error); if (code < 0) - return SocketError_Internal; + return SocketError::Internal; return TranslateErrnoToSocketError(code); } @@ -176,7 +177,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -194,7 +195,7 @@ namespace Nz if (error) *error = TranslateErrnoToSocketError(GetLastErrorCode()); - return SocketState_NotConnected; + return SocketState::NotConnected; } if (listen(handle, queueSize) == SOCKET_ERROR) @@ -202,13 +203,13 @@ namespace Nz if (error) *error = TranslateErrnoToSocketError(GetLastErrorCode()); - return SocketState_NotConnected; + return SocketState::NotConnected; } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; - return SocketState_Bound; + return SocketState::Bound; } std::size_t SocketImpl::QueryAvailableBytes(SocketHandle handle, SocketError* error) @@ -225,7 +226,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return availableBytes; } @@ -244,7 +245,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -263,7 +264,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -286,7 +287,7 @@ namespace Nz #endif if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -305,7 +306,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -324,7 +325,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -347,7 +348,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return IpAddressImpl::FromSockAddr(reinterpret_cast(nameBuffer.data())); } @@ -366,7 +367,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -386,7 +387,7 @@ namespace Nz { int errorCode = GetLastErrorCode(); if (errorCode == EINVAL) - *error = SocketError_NoError; + *error = SocketError::NoError; else *error = TranslateErrnoToSocketError(errorCode); } @@ -395,7 +396,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return IpAddressImpl::FromSockAddr(reinterpret_cast(nameBuffer.data())); } @@ -432,7 +433,7 @@ namespace Nz if (error) *error = TranslateErrnoToSocketError(GetLastErrorCode()); - return SocketState_NotConnected; + return SocketState::NotConnected; } else if (ret > 0) { @@ -441,14 +442,14 @@ namespace Nz if (error) *error = GetLastError(handle); - return SocketState_NotConnected; + return SocketState::NotConnected; } else if (descriptor.revents & POLLOUT) - return SocketState_Connected; + return SocketState::Connected; else { NazaraWarning("Socket " + std::to_string(handle) + " was returned by poll without POLLOUT nor error events (events: 0x" + NumberToString(descriptor.revents, 16) + ')'); - return SocketState_NotConnected; + return SocketState::NotConnected; } } else @@ -457,12 +458,12 @@ namespace Nz if (error) { if (msTimeout > 0) - *error = SocketError_TimedOut; + *error = SocketError::TimedOut; else - *error = SocketError_NoError; + *error = SocketError::NoError; } - return SocketState_Connecting; + return SocketState::Connecting; } } @@ -499,7 +500,7 @@ namespace Nz else if (byteRead == 0) { if (error) - *error = SocketError_ConnectionClosed; + *error = SocketError::ConnectionClosed; return false; //< Connection has been closed } @@ -508,7 +509,7 @@ namespace Nz *read = byteRead; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -554,7 +555,7 @@ namespace Nz else if (byteRead == 0) { if (error) - *error = SocketError_ConnectionClosed; + *error = SocketError::ConnectionClosed; return false; //< Connection closed } @@ -568,7 +569,7 @@ namespace Nz *read = byteRead; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -634,7 +635,7 @@ namespace Nz else if (byteRead == 0) { if (error) - *error = SocketError_ConnectionClosed; + *error = SocketError::ConnectionClosed; return false; //< Connection closed } @@ -645,7 +646,7 @@ namespace Nz if (msgHdr.msg_flags & MSG_TRUNC) { if (error) - *error = SocketError_DatagramSize; + *error = SocketError::DatagramSize; return false; } @@ -658,7 +659,7 @@ namespace Nz *read = byteRead; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -695,7 +696,7 @@ namespace Nz *sent = byteSent; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -753,7 +754,7 @@ namespace Nz *sent = static_cast(byteSent); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -793,7 +794,7 @@ namespace Nz *sent = byteSent; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -812,7 +813,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -831,7 +832,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -850,7 +851,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -888,7 +889,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -907,7 +908,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; #if not defined(MSG_NOSIGNAL) // -> https://github.com/intel/parameter-framework/pull/133/files //There is no MSG_NOSIGNAL on macos @@ -938,7 +939,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -957,7 +958,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -967,7 +968,7 @@ namespace Nz switch (error) { case 0: - return SocketError_NoError; + return SocketError::NoError; // Engine error case EACCES: @@ -981,83 +982,83 @@ namespace Nz case EISCONN: case EWOULDBLOCK: NazaraWarning("Internal error occurred: " + Error::GetLastSystemError(error) + " (" + NumberToString(error)+')'); - return SocketError_Internal; + return SocketError::Internal; case EADDRNOTAVAIL: case EADDRINUSE: - return SocketError_AddressNotAvailable; + return SocketError::AddressNotAvailable; case EAFNOSUPPORT: case EPFNOSUPPORT: case EOPNOTSUPP: case EPROTONOSUPPORT: case ESOCKTNOSUPPORT: - return SocketError_NotSupported; + return SocketError::NotSupported; case ECONNREFUSED: - return SocketError_ConnectionRefused; + return SocketError::ConnectionRefused; case EINTR: - return SocketError_Interrupted; + return SocketError::Interrupted; case EMSGSIZE: - return SocketError_DatagramSize; + return SocketError::DatagramSize; case EMFILE: case ENOBUFS: case ENOMEM: - return SocketError_ResourceError; + return SocketError::ResourceError; case ENOTCONN: case ESHUTDOWN: - return SocketError_ConnectionClosed; + return SocketError::ConnectionClosed; case EHOSTUNREACH: - return SocketError_UnreachableHost; + return SocketError::UnreachableHost; case ENETDOWN: case ENETUNREACH: - return SocketError_NetworkError; + return SocketError::NetworkError; case ENODATA: - return SocketError_NotInitialized; + return SocketError::NotInitialized; case ETIMEDOUT: - return SocketError_TimedOut; + return SocketError::TimedOut; } NazaraWarning("Unhandled POSIX error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); - return SocketError_Unknown; + return SocketError::Unknown; } int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol) { - NazaraAssert(protocol <= NetProtocol_Max, "Protocol has value out of enum"); + NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum"); static int addressFamily[] = { - AF_UNSPEC, //< NetProtocol_Any - AF_INET, //< NetProtocol_IPv4 - AF_INET6, //< NetProtocol_IPv6 - -1 //< NetProtocol_Unknown + AF_UNSPEC, //< NetProtocol::Any + AF_INET, //< NetProtocol::IPv4 + AF_INET6, //< NetProtocol::IPv6 + -1 //< NetProtocol::Unknown }; - static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocol_Max + 1, "Address family array is incomplete"); + static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete"); - return addressFamily[protocol]; + return addressFamily[UnderlyingCast(protocol)]; } int SocketImpl::TranslateSocketTypeToSock(SocketType type) { - NazaraAssert(type <= SocketType_Max, "Socket type has value out of enum"); + NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum"); static int socketType[] = { - SOCK_RAW, //< SocketType_Raw - SOCK_STREAM, //< SocketType_TCP - SOCK_DGRAM, //< SocketType_UDP - -1 //< SocketType_Unknown + SOCK_RAW, //< SocketType::Raw + SOCK_STREAM, //< SocketType::TCP + SOCK_DGRAM, //< SocketType::UDP + -1 //< SocketType::Unknown }; - static_assert(sizeof(socketType) / sizeof(int) == SocketType_Max + 1, "Socket type array is incomplete"); + static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete"); - return socketType[type]; + return socketType[UnderlyingCast(type)]; } void SocketImpl::Uninitialize() diff --git a/src/Nazara/Network/Posix/SocketPollerImpl.cpp b/src/Nazara/Network/Posix/SocketPollerImpl.cpp index 2e1b03a44..39da759ee 100644 --- a/src/Nazara/Network/Posix/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Posix/SocketPollerImpl.cpp @@ -42,10 +42,10 @@ namespace Nz 0 }; - if (eventFlags & SocketPollEvent_Read) + if (eventFlags & SocketPollEvent::Read) entry.events |= POLLRDNORM; - if (eventFlags & SocketPollEvent_Write) + if (eventFlags & SocketPollEvent::Write) entry.events |= POLLWRNORM; m_allSockets[socket] = m_sockets.size(); diff --git a/src/Nazara/Network/RUdpConnection.cpp b/src/Nazara/Network/RUdpConnection.cpp deleted file mode 100644 index 2211c0705..000000000 --- a/src/Nazara/Network/RUdpConnection.cpp +++ /dev/null @@ -1,640 +0,0 @@ -// Copyright (C) 2020 Jérôme Leclercq -// This file is part of the "Nazara Engine - Utility module" -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -namespace Nz -{ - /*! - * \ingroup network - * \class Nz::RUdpConnection - * \brief Network class that represents a reliable UDP connection - */ - - /*! - * \brief Constructs a RUdpConnection object by default - */ - - RUdpConnection::RUdpConnection() : - m_peerIterator(0), - m_forceAckSendTime(10'000), //< 10ms - m_pingInterval(1'000'000), //< 1s - m_protocol(0x4E4E6574), //< "NNet" - m_timeBeforePing(500'000), //< 0.5s - m_timeBeforeTimeOut(10'000'000), //< 10s - m_currentTime(0), - m_isSimulationEnabled(false), - m_shouldAcceptConnections(true) - { - } - - /*! - * \brief Connects to the IpAddress - * \return true - * - * \param remoteAddress Address to connect to - * - * \remark Produces a NazaraAssert if socket is not bound - * \remark Produces a NazaraAssert if remote is invalid - * \remark Produces a NazaraAssert if port is not specified - */ - - bool RUdpConnection::Connect(const IpAddress& remoteAddress) - { - NazaraAssert(m_socket.GetState() == SocketState_Bound, "Socket must be bound first"); - NazaraAssert(remoteAddress.IsValid(), "Invalid remote address"); - NazaraAssert(remoteAddress.GetPort() != 0, "Remote address has no port"); - - PeerData& client = RegisterPeer(remoteAddress, PeerState_Connecting); - client.stateData1 = s_randomGenerator(); - - NetPacket connectionRequestPacket(NetCode_RequestConnection); - connectionRequestPacket << client.stateData1; - - EnqueuePacket(client, PacketPriority_Immediate, PacketReliability_Reliable, connectionRequestPacket); - return true; - } - - /*! - * \brief Connects to the hostname - * \return true If successful - * - * \param hostName Hostname of the remote - * \param protocol Net protocol to use - * \param service Specify the protocol used - * \param error Optional argument to get the error - */ - - bool RUdpConnection::Connect(const std::string& hostName, NetProtocol protocol, const std::string& service, ResolveError* error) - { - std::vector results = IpAddress::ResolveHostname(protocol, hostName, service, error); - if (results.empty()) - { - m_lastError = SocketError_ResolveError; - return false; - } - - IpAddress hostnameAddress; - for (const HostnameInfo& result : results) - { - if (!result.address) - continue; - - if (result.socketType != SocketType_UDP) - continue; - - hostnameAddress = result.address; - break; //< Take first valid address - } - - return Connect(hostnameAddress); - } - - /*! - * \brief Listens to a socket - * \return true If successfully bound - * - * \param remoteAddress Address to listen to - */ - - bool RUdpConnection::Listen(const IpAddress& address) - { - if (!InitSocket(address.GetProtocol())) - return false; - - return m_socket.Bind(address) == SocketState_Bound; - } - - /*! - * \brief Polls the message - * \return true If there is a message - * - * \param message Message to poll - * - * \remark Produces a NazaraAssert if message is invalid - */ - - bool RUdpConnection::PollMessage(RUdpMessage* message) - { - NazaraAssert(message, "Invalid message"); - - if (m_receivedMessages.empty()) - return false; - - *message = std::move(m_receivedMessages.front()); - m_receivedMessages.pop(); - return true; - } - - /*! - * \brief Sends the packet to a peer - * \return true If peer exists (false may result from disconnected client) - * - * \param peerIp IpAddress of the peer - * \param priority Priority of the packet - * \param reliability Policy of reliability of the packet - * \param packet Packet to send - */ - - bool RUdpConnection::Send(const IpAddress& peerIp, PacketPriority priority, PacketReliability reliability, const NetPacket& packet) - { - auto it = m_peerByIP.find(peerIp); - if (it == m_peerByIP.end()) - return false; /// Silently fail (probably a disconnected client) - - EnqueuePacket(m_peers[it->second], priority, reliability, packet); - return true; - } - - /*! - * \brief Updates the reliable connection - */ - - void RUdpConnection::Update() - { - m_currentTime = m_clock.GetMicroseconds(); - - NetPacket receivedPacket; - IpAddress senderIp; - while (m_socket.ReceivePacket(&receivedPacket, &senderIp)) - OnPacketReceived(senderIp, std::move(receivedPacket)); - - //for (unsigned int i = m_activeClients.FindFirst(); i != m_activeClients.npos; i = m_activeClients.FindNext(i)) - //{ - // PeerData& clientData = m_peers[i]; - - CallOnExit resetIterator([this] () { m_peerIterator = m_peers.size(); }); - - for (m_peerIterator = 0; m_peerIterator < m_peers.size(); ++m_peerIterator) - { - PeerData& peer = m_peers[m_peerIterator]; - - UInt32 timeSinceLastPacket = static_cast(m_currentTime - peer.lastPacketTime); - if (timeSinceLastPacket > m_timeBeforeTimeOut) - { - DisconnectPeer(peer.index); - continue; - } - else if (timeSinceLastPacket > m_timeBeforePing) - { - if (m_currentTime - peer.lastPingTime > m_pingInterval) - { - NetPacket pingPacket(NetCode_Ping); - EnqueuePacket(peer, PacketPriority_Low, PacketReliability_Unreliable, pingPacket); - } - } - - if (peer.state == PeerState_WillAck && m_currentTime - peer.stateData1 > m_forceAckSendTime) - { - NetPacket acknowledgePacket(NetCode_Acknowledge); - EnqueuePacket(peer, PacketPriority_Low, PacketReliability_Reliable, acknowledgePacket); - } - - for (unsigned int priority = PacketPriority_Highest; priority <= PacketPriority_Lowest; ++priority) - { - std::vector& pendingPackets = peer.pendingPackets[priority]; - for (PendingPacket& packetData : pendingPackets) - SendPacket(peer, std::move(packetData)); - - pendingPackets.clear(); - } - - auto it = peer.pendingAckQueue.begin(); - while (it != peer.pendingAckQueue.end()) - { - if (m_currentTime - it->timeSent > 2 * peer.roundTripTime) - { - OnPacketLost(peer, std::move(*it)); - it = peer.pendingAckQueue.erase(it); - } - else - ++it; - } - } - //m_activeClients.Reset(); - } - - /*! - * \brief Disconnects a peer - * - * \param peerIndex Index of the peer - * - * \remark Produces a NazaraNotice - */ - - void RUdpConnection::DisconnectPeer(std::size_t peerIndex) - { - PeerData& peer = m_peers[peerIndex]; - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": " + peer.address.ToString() + " has been disconnected due to time-out"); - - OnPeerDisconnected(this, peer.address); - - // Remove from IP lookup table - m_peerByIP.erase(peer.address); - - // Can we safely "remove" this slot? - if (m_peerIterator >= m_peers.size() - 1 || peerIndex > m_peerIterator) - { - // Yes we can - PeerData& newSlot = m_peers[peerIndex]; - newSlot = std::move(m_peers.back()); - newSlot.index = peerIndex; //< Update the moved slot index before resizing (in case it's the last one) - } - else - { - // Nope, let's be tricky - PeerData& current = m_peers[m_peerIterator]; - PeerData& newSlot = m_peers[peerIndex]; - - newSlot = std::move(current); - newSlot.index = peerIndex; //< Update the moved slot index - - current = std::move(m_peers.back()); - current.index = m_peerIterator; //< Update the moved slot index - - --m_peerIterator; - } - - // Pop the last entry (from where we moved our slot) - m_peers.pop_back(); - } - - /*! - * \brief Enqueues a packet in the sending list - * - * \param peer Data relative to the peer - * \param priority Priority of the packet - * \param reliability Policy of reliability of the packet - * \param packet Packet to send - */ - - void RUdpConnection::EnqueuePacket(PeerData& peer, PacketPriority priority, PacketReliability reliability, const NetPacket& packet) - { - UInt16 protocolBegin = static_cast(m_protocol & 0xFFFF); - UInt16 protocolEnd = static_cast((m_protocol & 0xFFFF0000) >> 16); - - NetPacket data(packet.GetNetCode(), MessageHeader + packet.GetDataSize() + MessageFooter); - data << protocolBegin; - - data.GetStream()->SetCursorPos(NetPacket::HeaderSize + MessageHeader); - data.Write(packet.GetConstData() + NetPacket::HeaderSize, packet.GetDataSize()); - - data << protocolEnd; - EnqueuePacketInternal(peer, priority, reliability, std::move(data)); - } - - /*! - * \brief Enqueues internally a packet in the sending list - * - * \param peer Data relative to the peer - * \param priority Priority of the packet - * \param reliability Policy of reliability of the packet - * \param packet Packet to send - */ - - void RUdpConnection::EnqueuePacketInternal(PeerData& peer, PacketPriority priority, PacketReliability reliability, NetPacket&& data) - { - PendingPacket pendingPacket; - pendingPacket.data = std::move(data); - pendingPacket.priority = priority; - pendingPacket.reliability = reliability; - - peer.pendingPackets[priority].emplace_back(std::move(pendingPacket)); - m_activeClients.UnboundedSet(peer.index); - } - - /*! - * \brief Inits the internal socket - * \return true If successful - * - * \param protocol Net protocol to use - */ - - bool RUdpConnection::InitSocket(NetProtocol protocol) - { - CallOnExit updateLastError([this] - { - m_lastError = m_socket.GetLastError(); - }); - - if (!m_socket.Create(protocol)) - return false; - - m_socket.EnableBlocking(false); - return true; - } - - /*! - * \brief Processes the acks - * - * \param peer Data relative to the peer - * \param lastAck Last index of the ack - * \param ackBits Bits for acking - */ - - void RUdpConnection::ProcessAcks(PeerData& peer, SequenceIndex lastAck, UInt32 ackBits) - { - auto it = peer.pendingAckQueue.begin(); - while (it != peer.pendingAckQueue.end()) - { - bool acked = false; - if (lastAck == it->sequenceId) - acked = true; - else if (!IsAckMoreRecent(it->sequenceId, lastAck)) - { - unsigned int difference = ComputeSequenceDifference(lastAck, it->sequenceId); - if (difference <= 32) - acked = (ackBits >> (difference - 1)) & 1; - } - - if (acked) - { - it = peer.pendingAckQueue.erase(it); - } - else - ++it; - } - } - - /*! - * \brief Registers a peer - * \return Data relative to the peer - * - * \param address Address of the peer - * \param state Status of the peer - */ - - RUdpConnection::PeerData& RUdpConnection::RegisterPeer(const IpAddress& address, PeerState state) - { - PeerData data; - data.address = address; - data.localSequence = 0; - data.remoteSequence = 0; - data.index = m_peers.size(); - data.lastPacketTime = m_currentTime; - data.lastPingTime = m_currentTime; - data.roundTripTime = 1'000'000; ///< Okay that's quite a lot - data.state = state; - - m_activeClients.UnboundedSet(data.index); - m_peerByIP[address] = data.index; - - m_peers.emplace_back(std::move(data)); - return m_peers.back(); - } - - /*! - * \brief Operation to do when client requests a connection - * - * \param address Address of the peer - * \param sequenceId Sequence index for the ack - * \param token Token for connection - */ - - void RUdpConnection::OnClientRequestingConnection(const IpAddress& address, SequenceIndex sequenceId, UInt64 token) - { - // Call hook to check if client should be accepted or not - OnPeerConnection(this, address); - - PeerData& client = RegisterPeer(address, PeerState_Aknowledged); - client.remoteSequence = sequenceId; - - /// Acknowledge connection - NetPacket connectionAcceptedPacket(NetCode_AcknowledgeConnection); - //connectionAcceptedPacket << address; - connectionAcceptedPacket << ~token; - - EnqueuePacket(client, PacketPriority_Immediate, PacketReliability_Reliable, connectionAcceptedPacket); - } - - /*! - * \brief Operation to do when a packet is lost - * - * \param peer Data relative to the peer - * \param packet Pending packet - */ - - void RUdpConnection::OnPacketLost(PeerData& peer, PendingAckPacket&& packet) - { - //NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + NumberToString(packet.sequenceId)); - - if (IsReliable(packet.reliability)) - EnqueuePacketInternal(peer, packet.priority, packet.reliability, std::move(packet.data)); - } - - /*! - * \brief Operation to do when receiving a packet - * - * \param peerIndex Index of the peer - * - * \remark Produces a NazaraNotice - */ - - void RUdpConnection::OnPacketReceived(const IpAddress& peerIp, NetPacket&& packet) - { - UInt16 protocolBegin; - UInt16 protocolEnd; - SequenceIndex sequenceId; - SequenceIndex lastAck; - UInt32 ackBits; - - packet.GetStream()->SetCursorPos(packet.GetSize() - MessageFooter); - packet >> protocolEnd; - - packet.GetStream()->SetCursorPos(NetPacket::HeaderSize); - packet >> protocolBegin; - - UInt32 protocolId = static_cast(protocolEnd) << 16 | protocolBegin; - if (protocolId != m_protocol) - return; ///< Ignore - - packet >> sequenceId >> lastAck >> ackBits; - - auto it = m_peerByIP.find(peerIp); - if (it == m_peerByIP.end()) - { - switch (packet.GetNetCode()) - { - case NetCode_RequestConnection: - { - UInt64 token; - packet >> token; - - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_RequestConnection from " + peerIp.ToString() + ": " + NumberToString(token)); - if (!m_shouldAcceptConnections) - return; //< Ignore - - OnClientRequestingConnection(peerIp, sequenceId, token); - break; - } - - default: - return; //< Ignore - } - } - else - { - PeerData& peer = m_peers[it->second]; - peer.lastPacketTime = m_currentTime; - - if (peer.receivedQueue.find(sequenceId) != peer.receivedQueue.end()) - return; //< Ignore - - if (m_isSimulationEnabled && m_packetLossProbability(s_randomGenerator)) - { - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Lost packet " + NumberToString(sequenceId) + " from " + peerIp.ToString() + " for simulation purpose"); - return; - } - - ///< Receiving a packet from an acknowledged client means the connection works in both ways - if (peer.state == PeerState_Aknowledged && packet.GetNetCode() != NetCode_RequestConnection) - { - peer.state = PeerState_Connected; - OnPeerAcknowledged(this, peerIp); - } - - if (IsAckMoreRecent(sequenceId, peer.remoteSequence)) - peer.remoteSequence = sequenceId; - - ProcessAcks(peer, lastAck, ackBits); - - peer.receivedQueue.insert(sequenceId); - - switch (packet.GetNetCode()) - { - case NetCode_Acknowledge: - return; //< Do not switch to will ack mode (to prevent infinite replies, just let's ping/pong do that) - - case NetCode_AcknowledgeConnection: - { - if (peer.state == PeerState_Connected) - break; - - IpAddress externalAddress; - UInt64 token; - packet /*>> externalAddress*/ >> token; - - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_AcknowledgeConnection from " + peerIp.ToString() + ": " + NumberToString(token)); - if (token == ~peer.stateData1) - { - peer.state = PeerState_Connected; - OnConnectedToPeer(this); - } - else - { - NazaraNotice("Received wrong token (" + NumberToString(token) + " instead of " + NumberToString(~peer.stateData1) + ") from client " + peer.address.ToString()); - return; //< Ignore - } - - break; - } - - case NetCode_RequestConnection: - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_RequestConnection from " + peerIp.ToString()); - return; //< Ignore - - case NetCode_Ping: - { - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_Ping from " + peerIp.ToString()); - - NetPacket pongPacket(NetCode_Pong); - EnqueuePacket(peer, PacketPriority_Low, PacketReliability_Unreliable, pongPacket); - break; - } - - case NetCode_Pong: - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received NetCode_Pong from " + peerIp.ToString()); - break; - - default: - { - NazaraNotice(m_socket.GetBoundAddress().ToString() + ": Received 0x" + NumberToString(packet.GetNetCode(), 16) + " from " + peerIp.ToString()); - RUdpMessage receivedMessage; - receivedMessage.from = peerIp; - receivedMessage.data = std::move(packet); - - m_receivedMessages.emplace(std::move(receivedMessage)); - break; - } - } - - if (!HasPendingPackets(peer)) - { - peer.state = PeerState_WillAck; - peer.stateData1 = m_currentTime; - } - } - } - - /*! - * \brief Sends a packet to a peer - * - * \param peer Data relative to the peer - * \param packet Pending packet - */ - - void RUdpConnection::SendPacket(PeerData& peer, PendingPacket&& packet) - { - if (peer.state == PeerState_WillAck) - peer.state = PeerState_Connected; - - SequenceIndex remoteSequence = peer.remoteSequence; - - UInt32 previousAcks = 0; - for (SequenceIndex ack : peer.receivedQueue) - { - if (ack == remoteSequence) - continue; - - unsigned int difference = ComputeSequenceDifference(remoteSequence, ack); - if (difference <= 32U) - previousAcks |= (1U << (difference - 1)); - } - - SequenceIndex sequenceId = ++peer.localSequence; - - packet.data.GetStream()->SetCursorPos(NetPacket::HeaderSize + sizeof(UInt16)); ///< Protocol begin has already been filled - packet.data << sequenceId; - packet.data << remoteSequence; - packet.data << previousAcks; - - m_socket.SendPacket(peer.address, packet.data); - - PendingAckPacket pendingAckPacket; - pendingAckPacket.data = std::move(packet.data); - pendingAckPacket.priority = packet.priority; - pendingAckPacket.reliability = packet.reliability; - pendingAckPacket.sequenceId = sequenceId; - pendingAckPacket.timeSent = m_currentTime; - - peer.pendingAckQueue.emplace_back(std::move(pendingAckPacket)); - } - - /*! - * \brief Initializes the RUdpConnection class - * \return true - */ - - bool RUdpConnection::Initialize() - { - std::random_device device; - s_randomGenerator.seed(device()); - - return true; - } - - /*! - * \brief Uninitializes the RUdpConnection class - */ - - void RUdpConnection::Uninitialize() - { - } - - std::mt19937_64 RUdpConnection::s_randomGenerator; -} diff --git a/src/Nazara/Network/SocketPoller.cpp b/src/Nazara/Network/SocketPoller.cpp index 93c6d21a1..4ff4235b2 100644 --- a/src/Nazara/Network/SocketPoller.cpp +++ b/src/Nazara/Network/SocketPoller.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -24,7 +25,7 @@ namespace Nz /*! * \ingroup network * \class Nz::SocketPoller - * \brief Network class allowing an application to wait on multiples sockets for them to become active (readable) + * \brief Network class allowing an application to wait on multiples sockets for them to become active (readable/writeable) */ /*! @@ -194,10 +195,10 @@ namespace Nz if (error) *error = waitError; - if (waitError != SocketError_NoError) + if (waitError != SocketError::NoError) { - if (waitError != SocketError_Interrupted) //< Do not log interrupted error - NazaraError("SocketPoller encountered an error (code: 0x" + NumberToString(waitError, 16) + "): " + ErrorToString(waitError)); + if (waitError != SocketError::Interrupted) //< Do not log interrupted error + NazaraError("SocketPoller encountered an error (code: 0x" + NumberToString(UnderlyingCast(waitError), 16) + "): " + ErrorToString(waitError)); return 0; } diff --git a/src/Nazara/Network/TcpClient.cpp b/src/Nazara/Network/TcpClient.cpp index ecff0e6e4..7b0265bd2 100644 --- a/src/Nazara/Network/TcpClient.cpp +++ b/src/Nazara/Network/TcpClient.cpp @@ -56,7 +56,7 @@ namespace Nz } SocketState state = SocketImpl::Connect(m_handle, remoteAddress, &m_lastError); - m_peerAddress = (state != SocketState_NotConnected) ? remoteAddress : IpAddress::Invalid; + m_peerAddress = (state != SocketState::NotConnected) ? remoteAddress : IpAddress::Invalid; UpdateState(state); return state; @@ -75,13 +75,13 @@ namespace Nz SocketState TcpClient::Connect(const std::string& hostName, NetProtocol protocol, const std::string& service, ResolveError* error) { - UpdateState(SocketState_Resolving); + UpdateState(SocketState::Resolving); std::vector results = IpAddress::ResolveHostname(protocol, hostName, service, error); if (results.empty()) { - m_lastError = SocketError_ResolveError; + m_lastError = SocketError::ResolveError; - UpdateState(SocketState_NotConnected); + UpdateState(SocketState::NotConnected); return m_state; } @@ -91,7 +91,7 @@ namespace Nz if (!result.address) continue; - if (result.socketType != SocketType_TCP) + if (result.socketType != SocketType::TCP) continue; hostnameAddress = result.address; @@ -176,7 +176,7 @@ namespace Nz /*! * \brief Polls the connection status of the currently connecting socket - * \return New socket state, which maybe unchanged (if connecting is still pending), SocketState_Connected if connection is successful or SocketState_NotConnected if connection failed + * \return New socket state, which maybe unchanged (if connecting is still pending), SocketState::Connected if connection is successful or SocketState::NotConnected if connection failed * * This functions checks if the pending connection has either succeeded, failed or is still processing at the time of the call. * @@ -188,16 +188,16 @@ namespace Nz { switch (m_state) { - case SocketState_Connecting: + case SocketState::Connecting: { NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle"); SocketState newState = SocketImpl::PollConnection(m_handle, m_peerAddress, waitDuration, &m_lastError); // Prevent valid peer address in non-connected state - if (newState == SocketState_NotConnected) + if (newState == SocketState::NotConnected) { - m_openMode = OpenMode_NotOpen; + m_openMode = OpenMode::NotOpen; m_peerAddress = IpAddress::Invalid; } @@ -205,16 +205,16 @@ namespace Nz return newState; } - case SocketState_Connected: - case SocketState_NotConnected: + case SocketState::Connected: + case SocketState::NotConnected: return m_state; - case SocketState_Bound: - case SocketState_Resolving: + case SocketState::Bound: + case SocketState::Resolving: break; } - NazaraInternalError("Unexpected socket state (0x" + NumberToString(m_state, 16) + ')'); + NazaraInternalError("Unexpected socket state (0x" + NumberToString(UnderlyingCast(m_state), 16) + ')'); return m_state; } @@ -240,9 +240,9 @@ namespace Nz { switch (m_lastError) { - case SocketError_ConnectionClosed: - case SocketError_ConnectionRefused: - UpdateState(SocketState_NotConnected); + case SocketError::ConnectionClosed: + case SocketError::ConnectionRefused: + UpdateState(SocketState::NotConnected); break; default: @@ -255,7 +255,7 @@ namespace Nz if (received) *received = read; - UpdateState(SocketState_Connected); + UpdateState(SocketState::Connected); return true; } @@ -292,7 +292,7 @@ namespace Nz UInt32 size; if (!NetPacket::DecodeHeader(m_pendingPacket.data.GetConstBuffer(), &size, &m_pendingPacket.netcode)) { - m_lastError = SocketError_Packet; + m_lastError = SocketError::Packet; NazaraWarning("Invalid header data"); return false; } @@ -379,9 +379,9 @@ namespace Nz { switch (m_lastError) { - case SocketError_ConnectionClosed: - case SocketError_ConnectionRefused: - UpdateState(SocketState_NotConnected); + case SocketError::ConnectionClosed: + case SocketError::ConnectionRefused: + UpdateState(SocketState::NotConnected); break; default: @@ -394,7 +394,7 @@ namespace Nz totalByteSent += sentSize; } - UpdateState(SocketState_Connected); + UpdateState(SocketState::Connected); return true; } @@ -415,9 +415,9 @@ namespace Nz { switch (m_lastError) { - case SocketError_ConnectionClosed: - case SocketError_ConnectionRefused: - UpdateState(SocketState_NotConnected); + case SocketError::ConnectionClosed: + case SocketError::ConnectionRefused: + UpdateState(SocketState::NotConnected); break; default: @@ -433,7 +433,7 @@ namespace Nz if (sent) *sent = byteSent; - UpdateState(SocketState_Connected); + UpdateState(SocketState::Connected); return true; } @@ -452,7 +452,7 @@ namespace Nz const UInt8* ptr = static_cast(packet.OnSend(&size)); if (!ptr) { - m_lastError = SocketError_Packet; + m_lastError = SocketError::Packet; NazaraError("Failed to prepare packet"); return false; } @@ -491,20 +491,20 @@ namespace Nz { switch (m_state) { - case SocketState_Connecting: + case SocketState::Connecting: { NazaraAssert(m_handle != SocketImpl::InvalidHandle, "Invalid handle"); SocketState newState = SocketImpl::PollConnection(m_handle, m_peerAddress, (msTimeout > 0) ? msTimeout : std::numeric_limits::max(), &m_lastError); // If connection is still pending after waiting, cancel it - if (newState == SocketState_Connecting) - newState = SocketState_NotConnected; + if (newState == SocketState::Connecting) + newState = SocketState::NotConnected; // Prevent valid stats in non-connected state - if (newState == SocketState_NotConnected) + if (newState == SocketState::NotConnected) { - m_openMode = OpenMode_NotOpen; + m_openMode = OpenMode::NotOpen; m_peerAddress = IpAddress::Invalid; } @@ -512,16 +512,16 @@ namespace Nz return newState; } - case SocketState_Connected: - case SocketState_NotConnected: + case SocketState::Connected: + case SocketState::NotConnected: return m_state; - case SocketState_Bound: - case SocketState_Resolving: + case SocketState::Bound: + case SocketState::Resolving: break; } - NazaraInternalError("Unhandled socket state (0x" + NumberToString(m_state, 16) + ')'); + NazaraInternalError("Unhandled socket state (0x" + NumberToString(UnderlyingCast(m_state), 16) + ')'); return m_state; } @@ -541,7 +541,7 @@ namespace Nz { AbstractSocket::OnClose(); - m_openMode = OpenMode_NotOpen; + m_openMode = OpenMode::NotOpen; m_peerAddress = IpAddress::Invalid; } @@ -558,10 +558,10 @@ namespace Nz SocketError errorCode; if (!SocketImpl::SetNoDelay(m_handle, m_isLowDelayEnabled, &errorCode)) - NazaraWarning("Failed to set socket no delay mode (0x" + NumberToString(errorCode, 16) + ')'); + NazaraWarning("Failed to set socket no delay mode (0x" + NumberToString(UnderlyingCast(errorCode), 16) + ')'); if (!SocketImpl::SetKeepAlive(m_handle, m_isKeepAliveEnabled, m_keepAliveTime, m_keepAliveInterval, &errorCode)) - NazaraWarning("Failed to set socket keep alive mode (0x" + NumberToString(errorCode, 16) + ')'); + NazaraWarning("Failed to set socket keep alive mode (0x" + NumberToString(UnderlyingCast(errorCode), 16) + ')'); m_peerAddress = IpAddress::Invalid; m_openMode = OpenMode_ReadWrite; @@ -610,7 +610,7 @@ namespace Nz Open(handle); m_peerAddress = peerAddress; m_openMode = OpenMode_ReadWrite; - UpdateState(SocketState_Connected); + UpdateState(SocketState::Connected); } /*! diff --git a/src/Nazara/Network/TcpServer.cpp b/src/Nazara/Network/TcpServer.cpp index e062d082a..7ff29b91b 100644 --- a/src/Nazara/Network/TcpServer.cpp +++ b/src/Nazara/Network/TcpServer.cpp @@ -66,7 +66,7 @@ namespace Nz Open(address.GetProtocol()); SocketState state = SocketImpl::Listen(m_handle, address, queueSize, &m_lastError); - if (state == SocketState_Bound) + if (state == SocketState::Bound) m_boundAddress = SocketImpl::QuerySocketAddress(m_handle); UpdateState(state); diff --git a/src/Nazara/Network/UdpSocket.cpp b/src/Nazara/Network/UdpSocket.cpp index e0209c427..0e521f879 100644 --- a/src/Nazara/Network/UdpSocket.cpp +++ b/src/Nazara/Network/UdpSocket.cpp @@ -41,7 +41,7 @@ namespace Nz NazaraAssert(address.IsValid(), "Invalid address"); SocketState state = SocketImpl::Bind(m_handle, address, &m_lastError); - if (state == SocketState_Bound) + if (state == SocketState::Bound) m_boundAddress = SocketImpl::QuerySocketAddress(m_handle); UpdateState(state); @@ -104,8 +104,8 @@ namespace Nz { switch (m_lastError) { - case SocketError_ConnectionClosed: - m_lastError = SocketError_NoError; + case SocketError::ConnectionClosed: + m_lastError = SocketError::NoError; read = 0; break; @@ -140,8 +140,8 @@ namespace Nz { switch (m_lastError) { - case SocketError_ConnectionClosed: - m_lastError = SocketError_NoError; + case SocketError::ConnectionClosed: + m_lastError = SocketError::NoError; read = 0; break; @@ -166,14 +166,13 @@ namespace Nz * \remark Produces a NazaraAssert if packet is invalid * \remark Produces a NazaraWarning if packet's header is invalid */ - bool UdpSocket::ReceivePacket(NetPacket* packet, IpAddress* from) { NazaraAssert(packet, "Invalid packet"); // I'm not sure what's the best between having a 65k bytes buffer ready for any datagram size // or querying the next datagram size every time, for now I'll leave it as is - packet->Reset(NetCode_Invalid, std::numeric_limits::max()); + packet->Reset(0, std::numeric_limits::max()); packet->Resize(std::numeric_limits::max()); std::size_t received; @@ -187,14 +186,14 @@ namespace Nz Nz::UInt32 packetSize; if (!NetPacket::DecodeHeader(packet->GetConstData(), &packetSize, &netCode)) { - m_lastError = SocketError_Packet; + m_lastError = SocketError::Packet; NazaraWarning("Invalid header data"); return false; } if (packetSize != received) { - m_lastError = SocketError_Packet; + m_lastError = SocketError::Packet; NazaraWarning("Invalid packet size (packet size is " + NumberToString(packetSize) + " bytes, received " + NumberToString(received) + " bytes)"); return false; } @@ -275,7 +274,7 @@ namespace Nz const UInt8* ptr = static_cast(packet.OnSend(&size)); if (!ptr) { - m_lastError = SocketError_Packet; + m_lastError = SocketError::Packet; NazaraError("Failed to prepare packet"); return false; } diff --git a/src/Nazara/Network/Win32/IpAddressImpl.cpp b/src/Nazara/Network/Win32/IpAddressImpl.cpp index 570cf8fe2..3f2913f69 100644 --- a/src/Nazara/Network/Win32/IpAddressImpl.cpp +++ b/src/Nazara/Network/Win32/IpAddressImpl.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -187,7 +188,7 @@ namespace Nz } if (error) - *error = ResolveError_NoError; + *error = ResolveError::NoError; return true; } @@ -228,7 +229,7 @@ namespace Nz } if (error) - *error = ResolveError_NoError; + *error = ResolveError::NoError; return results; } @@ -239,7 +240,7 @@ namespace Nz { switch (ipAddress.GetProtocol()) { - case NetProtocol_IPv4: + case NetProtocol::IPv4: { sockaddr_in* socketAddress = reinterpret_cast(buffer); @@ -251,7 +252,7 @@ namespace Nz return sizeof(sockaddr_in); } - case NetProtocol_IPv6: + case NetProtocol::IPv6: { sockaddr_in6* socketAddress = reinterpret_cast(buffer); @@ -271,7 +272,7 @@ namespace Nz } default: - NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(ipAddress.GetProtocol()) + ')'); + NazaraInternalError("Unhandled ip protocol (0x" + NumberToString(UnderlyingCast(ipAddress.GetProtocol())) + ')'); break; } } @@ -285,13 +286,13 @@ namespace Nz switch (family) { case PF_INET: - return NetProtocol_IPv4; + return NetProtocol::IPv4; case PF_INET6: - return NetProtocol_IPv6; + return NetProtocol::IPv6; default: - return NetProtocol_Unknown; + return NetProtocol::Unknown; } } @@ -300,16 +301,16 @@ namespace Nz switch (socketType) { case SOCK_STREAM: - return SocketType_TCP; + return SocketType::TCP; case SOCK_DGRAM: - return SocketType_UDP; + return SocketType::UDP; case SOCK_RAW: - return SocketType_Raw; + return SocketType::Raw; default: - return SocketType_Unknown; + return SocketType::Unknown; } } @@ -318,35 +319,35 @@ namespace Nz switch (error) { case 0: - return ResolveError_NoError; + return ResolveError::NoError; // Engine error case WSAEFAULT: case WSAEINVAL: - return ResolveError_Internal; + return ResolveError::Internal; case WSAEAFNOSUPPORT: case WSAESOCKTNOSUPPORT: case WSASERVICE_NOT_FOUND: - return ResolveError_ProtocolNotSupported; + return ResolveError::ProtocolNotSupported; case WSAHOST_NOT_FOUND: - return ResolveError_NotFound; + return ResolveError::NotFound; case WSANO_RECOVERY: - return ResolveError_NonRecoverable; + return ResolveError::NonRecoverable; case WSANOTINITIALISED: - return ResolveError_NotInitialized; + return ResolveError::NotInitialized; case WSA_NOT_ENOUGH_MEMORY: - return ResolveError_ResourceError; + return ResolveError::ResourceError; case WSATRY_AGAIN: - return ResolveError_TemporaryFailure; + return ResolveError::TemporaryFailure; } NazaraWarning("Unhandled WinSock error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); - return ResolveError_Unknown; + return ResolveError::Unknown; } } diff --git a/src/Nazara/Network/Win32/SocketImpl.cpp b/src/Nazara/Network/Win32/SocketImpl.cpp index 1cca2a32d..f68ef4a20 100644 --- a/src/Nazara/Network/Win32/SocketImpl.cpp +++ b/src/Nazara/Network/Win32/SocketImpl.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -52,7 +53,7 @@ namespace Nz *address = IpAddressImpl::FromSockAddr(reinterpret_cast(&nameBuffer)); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; } else { @@ -76,19 +77,19 @@ namespace Nz if (error) *error = TranslateWSAErrorToSocketError(WSAGetLastError()); - return SocketState_NotConnected; + return SocketState::NotConnected; } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; - return SocketState_Bound; + return SocketState::Bound; } SocketHandle SocketImpl::Create(NetProtocol protocol, SocketType type, SocketError* error) { - NazaraAssert(protocol != NetProtocol_Any, "Any protocol is not supported for socket creation"); - NazaraAssert(type <= SocketType_Max, "Type has value out of enum"); + NazaraAssert(protocol != NetProtocol::Any, "Any protocol is not supported for socket creation"); + NazaraAssert(type <= SocketType::Max, "Type has value out of enum"); SocketHandle handle = socket(TranslateNetProtocolToAF(protocol), TranslateSocketTypeToSock(type), 0); if (handle == InvalidHandle && error != nullptr) @@ -109,7 +110,7 @@ namespace Nz { NazaraAssert(handle != InvalidHandle, "Invalid handle"); - if (GetLastError(handle, nullptr) < 0) + if (GetLastError(handle, nullptr) != SocketError::Internal) NazaraWarning("Failed to clear socket error code: " + Error::GetLastSystemError(WSAGetLastError())); } @@ -122,7 +123,7 @@ namespace Nz int bufferLength = IpAddressImpl::ToSockAddr(address, nameBuffer.data()); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; // Clear socket error status ClearErrorCode(handle); @@ -135,24 +136,24 @@ namespace Nz case WSAEALREADY: case WSAEINVAL: //< In case of connect, WSAEINVAL may be returned instead of WSAEALREADY case WSAEWOULDBLOCK: - return SocketState_Connecting; + return SocketState::Connecting; case WSAEISCONN: - return SocketState_Connected; + return SocketState::Connected; } if (error) { if (errorCode == WSAEADDRNOTAVAIL) - *error = SocketError_ConnectionRefused; //< ConnectionRefused seems more legit than AddressNotAvailable in connect case + *error = SocketError::ConnectionRefused; //< ConnectionRefused seems more legit than AddressNotAvailable in connect case else *error = TranslateWSAErrorToSocketError(errorCode); } - return SocketState_NotConnected; + return SocketState::NotConnected; } - return SocketState_Connected; + return SocketState::Connected; } bool SocketImpl::Initialize() @@ -172,7 +173,7 @@ namespace Nz { int code = GetLastErrorCode(handle, error); if (code < 0) - return SocketError_Internal; + return SocketError::Internal; return TranslateWSAErrorToSocketError(code); } @@ -196,7 +197,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -214,7 +215,7 @@ namespace Nz if (error) *error = TranslateWSAErrorToSocketError(WSAGetLastError()); - return SocketState_NotConnected; + return SocketState::NotConnected; } if (listen(handle, queueSize) == SOCKET_ERROR) @@ -222,13 +223,13 @@ namespace Nz if (error) *error = TranslateWSAErrorToSocketError(WSAGetLastError()); - return SocketState_NotConnected; + return SocketState::NotConnected; } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; - return SocketState_Bound; + return SocketState::Bound; } std::size_t SocketImpl::QueryAvailableBytes(SocketHandle handle, SocketError* error) @@ -245,7 +246,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return availableBytes; } @@ -264,7 +265,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code == TRUE; } @@ -283,7 +284,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code == TRUE; } @@ -302,7 +303,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -321,7 +322,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code == TRUE; } @@ -340,7 +341,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -363,7 +364,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return IpAddressImpl::FromSockAddr(reinterpret_cast(nameBuffer.data())); } @@ -383,7 +384,7 @@ namespace Nz { int errorCode = WSAGetLastError(); if (errorCode == WSAEINVAL) - *error = SocketError_NoError; + *error = SocketError::NoError; else *error = TranslateWSAErrorToSocketError(errorCode); } @@ -392,7 +393,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return IpAddressImpl::FromSockAddr(reinterpret_cast(nameBuffer.data())); } @@ -411,7 +412,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return code; } @@ -436,7 +437,7 @@ namespace Nz assert(result >= 0); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return static_cast(result); #else @@ -445,7 +446,7 @@ namespace Nz NazaraUnused(timeout); if (error) - *error = SocketError_NotSupported; + *error = SocketError::NotSupported; return 0; #endif @@ -465,7 +466,7 @@ namespace Nz if (error) *error = TranslateWSAErrorToSocketError(WSAGetLastError()); - return SocketState_NotConnected; + return SocketState::NotConnected; } else if (ret > 0) { @@ -474,14 +475,14 @@ namespace Nz if (error) *error = GetLastError(handle); - return SocketState_NotConnected; + return SocketState::NotConnected; } else if (descriptor.revents & POLLWRNORM) - return SocketState_Connected; + return SocketState::Connected; else { NazaraWarning("Socket " + std::to_string(handle) + " was returned by poll without POLLOUT nor error events (events: 0x" + NumberToString(descriptor.revents, 16) + ')'); - return SocketState_NotConnected; + return SocketState::NotConnected; } } else @@ -490,12 +491,12 @@ namespace Nz if (error) { if (msTimeout > 0) - *error = SocketError_TimedOut; + *error = SocketError::TimedOut; else - *error = SocketError_NoError; + *error = SocketError::NoError; } - return SocketState_Connecting; + return SocketState::Connecting; } } @@ -529,7 +530,7 @@ namespace Nz else if (byteRead == 0) { if (error) - *error = SocketError_ConnectionClosed; + *error = SocketError::ConnectionClosed; return false; //< Connection has been closed } @@ -538,7 +539,7 @@ namespace Nz *read = byteRead; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -581,7 +582,7 @@ namespace Nz else if (byteRead == 0) { if (error) - *error = SocketError_ConnectionClosed; + *error = SocketError::ConnectionClosed; return false; //< Connection closed } @@ -595,7 +596,7 @@ namespace Nz *read = byteRead; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -650,7 +651,7 @@ namespace Nz if (flags & MSG_PARTIAL) { if (error) - *error = SocketError_DatagramSize; + *error = SocketError::DatagramSize; return false; } @@ -662,7 +663,7 @@ namespace Nz *read = byteRead; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -698,7 +699,7 @@ namespace Nz *sent = byteSent; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -744,7 +745,7 @@ namespace Nz *sent = static_cast(byteSent); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -783,7 +784,7 @@ namespace Nz *sent = byteSent; if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -802,7 +803,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -821,7 +822,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -841,12 +842,12 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; #else if (error) - *error = SocketError_NotSupported; + *error = SocketError::NotSupported; return false; #endif @@ -871,7 +872,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -890,7 +891,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -909,7 +910,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -928,7 +929,7 @@ namespace Nz } if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; return true; } @@ -938,7 +939,7 @@ namespace Nz switch (error) { case 0: - return SocketError_NoError; + return SocketError::NoError; // Engine error case WSAEACCES: @@ -953,82 +954,82 @@ namespace Nz case WSAEISCONN: case WSAEWOULDBLOCK: NazaraWarning("Internal error occurred: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); - return SocketError_Internal; + return SocketError::Internal; case WSAEADDRNOTAVAIL: case WSAEADDRINUSE: - return SocketError_AddressNotAvailable; + return SocketError::AddressNotAvailable; case WSAEAFNOSUPPORT: case WSAEPFNOSUPPORT: case WSAEOPNOTSUPP: case WSAEPROTONOSUPPORT: case WSAESOCKTNOSUPPORT: - return SocketError_NotSupported; + return SocketError::NotSupported; case WSAECONNREFUSED: - return SocketError_ConnectionRefused; + return SocketError::ConnectionRefused; case WSAECONNABORTED: case WSAECONNRESET: case WSAENOTCONN: case WSAESHUTDOWN: - return SocketError_ConnectionClosed; + return SocketError::ConnectionClosed; case WSAEMSGSIZE: - return SocketError_DatagramSize; + return SocketError::DatagramSize; case WSAEMFILE: case WSAENOBUFS: case WSA_NOT_ENOUGH_MEMORY: - return SocketError_ResourceError; + return SocketError::ResourceError; case WSAEHOSTUNREACH: - return SocketError_UnreachableHost; + return SocketError::UnreachableHost; case WSAENETDOWN: case WSAENETUNREACH: - return SocketError_NetworkError; + return SocketError::NetworkError; case WSANOTINITIALISED: - return SocketError_NotInitialized; + return SocketError::NotInitialized; case WSAETIMEDOUT: - return SocketError_TimedOut; + return SocketError::TimedOut; } NazaraWarning("Unhandled WinSock error: " + Error::GetLastSystemError(error) + " (" + NumberToString(error) + ')'); - return SocketError_Unknown; + return SocketError::Unknown; } int SocketImpl::TranslateNetProtocolToAF(NetProtocol protocol) { - NazaraAssert(protocol <= NetProtocol_Max, "Protocol has value out of enum"); + NazaraAssert(protocol <= NetProtocol::Max, "Protocol has value out of enum"); static int addressFamily[] = { - AF_UNSPEC, //< NetProtocol_Any - AF_INET, //< NetProtocol_IPv4 - AF_INET6, //< NetProtocol_IPv6 - -1 //< NetProtocol_Unknown + AF_UNSPEC, //< NetProtocol::Any + AF_INET, //< NetProtocol::IPv4 + AF_INET6, //< NetProtocol::IPv6 + -1 //< NetProtocol::Unknown }; - static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocol_Max + 1, "Address family array is incomplete"); + static_assert(sizeof(addressFamily) / sizeof(int) == NetProtocolCount, "Address family array is incomplete"); - return addressFamily[protocol]; + return addressFamily[UnderlyingCast(protocol)]; } int SocketImpl::TranslateSocketTypeToSock(SocketType type) { - NazaraAssert(type <= SocketType_Max, "Socket type has value out of enum"); + NazaraAssert(type <= SocketType::Max, "Socket type has value out of enum"); static int socketType[] = { - SOCK_RAW, //< SocketType_Raw - SOCK_STREAM, //< SocketType_TCP - SOCK_DGRAM, //< SocketType_UDP - -1 //< SocketType_Unknown + SOCK_RAW, //< SocketType::Raw + SOCK_STREAM, //< SocketType::TCP + SOCK_DGRAM, //< SocketType::UDP + -1 //< SocketType::Unknown }; - static_assert(sizeof(socketType) / sizeof(int) == SocketType_Max + 1, "Socket type array is incomplete"); + static_assert(sizeof(socketType) / sizeof(int) == SocketTypeCount, "Socket type array is incomplete"); - return socketType[type]; + return socketType[UnderlyingCast(type)]; } void SocketImpl::Uninitialize() diff --git a/src/Nazara/Network/Win32/SocketPollerImpl.cpp b/src/Nazara/Network/Win32/SocketPollerImpl.cpp index 927d0b447..6d56129dd 100644 --- a/src/Nazara/Network/Win32/SocketPollerImpl.cpp +++ b/src/Nazara/Network/Win32/SocketPollerImpl.cpp @@ -74,10 +74,10 @@ namespace Nz 0 }; - if (eventFlags & SocketPollEvent_Read) + if (eventFlags & SocketPollEvent::Read) entry.events |= POLLRDNORM; - if (eventFlags & SocketPollEvent_Write) + if (eventFlags & SocketPollEvent::Write) entry.events |= POLLWRNORM; m_allSockets[socket] = m_sockets.size(); @@ -85,7 +85,7 @@ namespace Nz #else for (std::size_t i = 0; i < 2; ++i) { - if ((eventFlags & ((i == 0) ? SocketPollEvent_Read : SocketPollEvent_Write)) == 0) + if ((eventFlags & ((i == 0) ? SocketPollEvent::Read : SocketPollEvent::Write)) == 0) continue; fd_set& targetSet = (i == 0) ? m_readSockets : m_writeSockets; @@ -202,7 +202,7 @@ namespace Nz activeSockets = static_cast(selectValue); if (error) - *error = SocketError_NoError; + *error = SocketError::NoError; #endif return activeSockets; diff --git a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp index 8e7820c2d..72a848613 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLContextBase.cpp @@ -51,7 +51,7 @@ namespace Nz::GL return CreateInternal(configs[configIndex], shareContext); } - bool EGLContextBase::Create(const ContextParams& params, WindowHandle window, const EGLContextBase* shareContext) + bool EGLContextBase::Create(const ContextParams& /*params*/, WindowHandle /*window*/, const EGLContextBase* /*shareContext*/) { NazaraError("Unexpected context creation call"); return false; @@ -140,7 +140,7 @@ namespace Nz::GL }; EGLint numConfig = 0; - if (m_loader.eglChooseConfig(m_display, configAttributes, configs, maxConfigCount, &numConfig) != GL_TRUE) + if (m_loader.eglChooseConfig(m_display, configAttributes, configs, EGLint(maxConfigCount), &numConfig) != GL_TRUE) { NazaraError(std::string("failed to retrieve compatible EGL configurations: ") + EGLLoader::TranslateError(m_loader.eglGetError())); return false; diff --git a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp index a63697e5c..3b66140cb 100644 --- a/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp +++ b/src/Nazara/OpenGLRenderer/Wrapper/EGL/EGLLoader.cpp @@ -202,7 +202,7 @@ namespace Nz::GL } } - bool EGLLoader::ImplementFallback(const std::string_view& function) + bool EGLLoader::ImplementFallback(const std::string_view& /*function*/) { return false; } diff --git a/src/Nazara/Physics2D/RigidBody2D.cpp b/src/Nazara/Physics2D/RigidBody2D.cpp index 1fe42df42..81214f859 100644 --- a/src/Nazara/Physics2D/RigidBody2D.cpp +++ b/src/Nazara/Physics2D/RigidBody2D.cpp @@ -101,11 +101,11 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: cpBodyApplyForceAtWorldPoint(m_handle, cpv(force.x, force.y), cpv(point.x, point.y)); break; - case CoordSys_Local: + case CoordSys::Local: cpBodyApplyForceAtLocalPoint(m_handle, cpv(force.x, force.y), cpv(point.x, point.y)); break; } @@ -120,11 +120,11 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: cpBodyApplyImpulseAtWorldPoint(m_handle, cpv(impulse.x, impulse.y), cpv(point.x, point.y)); break; - case CoordSys_Local: + case CoordSys::Local: cpBodyApplyImpulseAtLocalPoint(m_handle, cpv(impulse.x, impulse.y), cpv(point.x, point.y)); break; } @@ -254,11 +254,11 @@ namespace Nz switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: massCenter = cpBodyLocalToWorld(m_handle, massCenter); break; - case CoordSys_Local: + case CoordSys::Local: break; // Nothing to do } @@ -456,11 +456,11 @@ namespace Nz switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: massCenter = cpBodyWorldToLocal(m_handle, massCenter); break; - case CoordSys_Local: + case CoordSys::Local: break; // Nothing to do } diff --git a/src/Nazara/Physics3D/Collider3D.cpp b/src/Nazara/Physics3D/Collider3D.cpp index 24f435fc6..b1c9681cd 100644 --- a/src/Nazara/Physics3D/Collider3D.cpp +++ b/src/Nazara/Physics3D/Collider3D.cpp @@ -16,21 +16,21 @@ namespace Nz { switch (primitive.type) { - case PrimitiveType_Box: + case PrimitiveType::Box: return std::make_shared(primitive.box.lengths, primitive.matrix); - case PrimitiveType_Cone: + case PrimitiveType::Cone: return std::make_shared(primitive.cone.length, primitive.cone.radius, primitive.matrix); - case PrimitiveType_Plane: + case PrimitiveType::Plane: return std::make_shared(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y), primitive.matrix); ///TODO: PlaneGeom? - case PrimitiveType_Sphere: + case PrimitiveType::Sphere: return std::make_shared(primitive.sphere.size, primitive.matrix.GetTranslation()); } - NazaraError("Primitive type not handled (0x" + NumberToString(primitive.type, 16) + ')'); + NazaraError("Primitive type not handled (0x" + NumberToString(UnderlyingCast(primitive.type), 16) + ')'); return std::shared_ptr(); } } diff --git a/src/Nazara/Physics3D/RigidBody3D.cpp b/src/Nazara/Physics3D/RigidBody3D.cpp index 5aafcd1cf..40d6bd833 100644 --- a/src/Nazara/Physics3D/RigidBody3D.cpp +++ b/src/Nazara/Physics3D/RigidBody3D.cpp @@ -84,11 +84,11 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: m_forceAccumulator += force; break; - case CoordSys_Local: + case CoordSys::Local: m_forceAccumulator += GetRotation() * force; break; } @@ -101,13 +101,13 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: m_forceAccumulator += force; - m_torqueAccumulator += Vector3f::CrossProduct(point - GetMassCenter(CoordSys_Global), force); + m_torqueAccumulator += Vector3f::CrossProduct(point - GetMassCenter(CoordSys::Global), force); break; - case CoordSys_Local: - return AddForce(m_matrix.Transform(force, 0.f), m_matrix.Transform(point), CoordSys_Global); + case CoordSys::Local: + return AddForce(m_matrix.Transform(force, 0.f), m_matrix.Transform(point), CoordSys::Global); } // On réveille le corps pour que le callback soit appelé et que les forces soient appliquées @@ -118,11 +118,11 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: m_torqueAccumulator += torque; break; - case CoordSys_Local: + case CoordSys::Local: m_torqueAccumulator += m_matrix.Transform(torque, 0.f); break; } @@ -205,11 +205,11 @@ namespace Nz switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: center = m_matrix.Transform(center); break; - case CoordSys_Local: + case CoordSys::Local: break; // Aucune opération à effectuer sur le centre de rotation } diff --git a/src/Nazara/Platform/Cursor.cpp b/src/Nazara/Platform/Cursor.cpp index da52a62d9..b3aacb10a 100644 --- a/src/Nazara/Platform/Cursor.cpp +++ b/src/Nazara/Platform/Cursor.cpp @@ -13,13 +13,13 @@ namespace Nz Cursor::Cursor(const Image& cursor, const Vector2i& hotSpot, SystemCursor placeholder) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); Create(cursor, hotSpot, placeholder); } Cursor::Cursor(SystemCursor systemCursor) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); Create(systemCursor); } diff --git a/src/Nazara/Platform/Icon.cpp b/src/Nazara/Platform/Icon.cpp index 72cf081f3..0367a8341 100644 --- a/src/Nazara/Platform/Icon.cpp +++ b/src/Nazara/Platform/Icon.cpp @@ -12,7 +12,7 @@ namespace Nz Icon::Icon(const Image& icon) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); Create(icon); } diff --git a/src/Nazara/Platform/SDL2/CursorImpl.cpp b/src/Nazara/Platform/SDL2/CursorImpl.cpp index a6b07f7c4..78cc03019 100644 --- a/src/Nazara/Platform/SDL2/CursorImpl.cpp +++ b/src/Nazara/Platform/SDL2/CursorImpl.cpp @@ -39,7 +39,7 @@ namespace Nz CursorImpl::CursorImpl(const Image& cursor, const Vector2i& hotSpot) { - ErrorFlags errFlags(ErrorFlag_ThrowException); + ErrorFlags errFlags(ErrorMode::ThrowException); m_cursorImage = cursor; if (!m_cursorImage.Convert(PixelFormat::BGRA8)) @@ -69,7 +69,7 @@ namespace Nz CursorImpl::CursorImpl(SystemCursor cursor) { - ErrorFlags errFlags(ErrorFlag_ThrowException); + ErrorFlags errFlags(ErrorMode::ThrowException); if (cursor != SystemCursor::None) { diff --git a/src/Nazara/Platform/SDL2/IconImpl.cpp b/src/Nazara/Platform/SDL2/IconImpl.cpp index 290276de8..9fd730679 100644 --- a/src/Nazara/Platform/SDL2/IconImpl.cpp +++ b/src/Nazara/Platform/SDL2/IconImpl.cpp @@ -12,7 +12,7 @@ namespace Nz { IconImpl::IconImpl(const Image& icon) { - ErrorFlags errFlags(ErrorFlag_ThrowException); + ErrorFlags errFlags(ErrorMode::ThrowException); m_iconImage = icon; if (!m_iconImage.Convert(PixelFormat::BGRA8)) diff --git a/src/Nazara/Platform/SDL2/WindowImpl.cpp b/src/Nazara/Platform/SDL2/WindowImpl.cpp index 080405bd8..0ac8fb89e 100644 --- a/src/Nazara/Platform/SDL2/WindowImpl.cpp +++ b/src/Nazara/Platform/SDL2/WindowImpl.cpp @@ -198,7 +198,7 @@ namespace Nz if (SDL_GetWindowWMInfo(m_handle, &wmInfo) != SDL_TRUE) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); NazaraError(std::string("failed to retrieve window manager info: ") + SDL_GetError()); } @@ -235,7 +235,7 @@ namespace Nz #endif default: { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); NazaraError("unhandled window subsystem"); } } diff --git a/src/Nazara/Renderer/RenderDevice.cpp b/src/Nazara/Renderer/RenderDevice.cpp index 19582f718..826482736 100644 --- a/src/Nazara/Renderer/RenderDevice.cpp +++ b/src/Nazara/Renderer/RenderDevice.cpp @@ -14,7 +14,7 @@ namespace Nz std::shared_ptr RenderDevice::InstantiateShaderModule(ShaderStageTypeFlags shaderStages, ShaderLanguage lang, const std::filesystem::path& sourcePath, const ShaderWriter::States& states) { File file(sourcePath); - if (!file.Open(OpenMode_ReadOnly | OpenMode_Text)) + if (!file.Open(OpenMode::ReadOnly | OpenMode::Text)) { NazaraError("Failed to open \"" + sourcePath.generic_u8string() + '"'); return {}; diff --git a/src/Nazara/Shader/Ast/AstSerializer.cpp b/src/Nazara/Shader/Ast/AstSerializer.cpp index 637ff04c3..654e99ea8 100644 --- a/src/Nazara/Shader/Ast/AstSerializer.cpp +++ b/src/Nazara/Shader/Ast/AstSerializer.cpp @@ -753,7 +753,7 @@ namespace Nz::ShaderAst ByteArray SerializeShader(StatementPtr& shader) { ByteArray byteArray; - ByteStream stream(&byteArray, OpenModeFlags(OpenMode_WriteOnly)); + ByteStream stream(&byteArray, OpenModeFlags(OpenMode::WriteOnly)); ShaderAstSerializer serializer(stream); serializer.Serialize(shader); diff --git a/src/Nazara/Shader/ShaderLangParser.cpp b/src/Nazara/Shader/ShaderLangParser.cpp index fe57c48bb..fc09a3a13 100644 --- a/src/Nazara/Shader/ShaderLangParser.cpp +++ b/src/Nazara/Shader/ShaderLangParser.cpp @@ -1016,7 +1016,7 @@ namespace Nz::ShaderLang ShaderAst::StatementPtr Parse(const std::filesystem::path& sourcePath) { File file(sourcePath); - if (!file.Open(OpenMode_ReadOnly | OpenMode_Text)) + if (!file.Open(OpenMode::ReadOnly | OpenMode::Text)) { NazaraError("Failed to open \"" + sourcePath.generic_u8string() + '"'); return {}; diff --git a/src/Nazara/Utility/Buffer.cpp b/src/Nazara/Utility/Buffer.cpp index 390900160..a07e85e1d 100644 --- a/src/Nazara/Utility/Buffer.cpp +++ b/src/Nazara/Utility/Buffer.cpp @@ -25,7 +25,7 @@ namespace Nz Buffer::Buffer(BufferType type, UInt32 size, DataStorage storage, BufferUsageFlags usage) : Buffer(type) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); Create(size, storage, usage); } diff --git a/src/Nazara/Utility/Formats/DDSLoader.cpp b/src/Nazara/Utility/Formats/DDSLoader.cpp index f157889b8..8f8c8a174 100644 --- a/src/Nazara/Utility/Formats/DDSLoader.cpp +++ b/src/Nazara/Utility/Formats/DDSLoader.cpp @@ -30,7 +30,7 @@ namespace Nz return Ternary::False; ByteStream byteStream(&stream); - byteStream.SetDataEndianness(Endianness_LittleEndian); + byteStream.SetDataEndianness(Endianness::LittleEndian); UInt32 magic; byteStream >> magic; @@ -43,7 +43,7 @@ namespace Nz NazaraUnused(parameters); ByteStream byteStream(&stream); - byteStream.SetDataEndianness(Endianness_LittleEndian); + byteStream.SetDataEndianness(Endianness::LittleEndian); UInt32 magic; byteStream >> magic; diff --git a/src/Nazara/Utility/Formats/FreeTypeLoader.cpp b/src/Nazara/Utility/Formats/FreeTypeLoader.cpp index 09fe7b457..c6ce3b504 100644 --- a/src/Nazara/Utility/Formats/FreeTypeLoader.cpp +++ b/src/Nazara/Utility/Formats/FreeTypeLoader.cpp @@ -324,7 +324,7 @@ namespace Nz bool SetFile(const std::filesystem::path& filePath) { std::unique_ptr file = std::make_unique(); - if (!file->Open(filePath, OpenMode_ReadOnly)) + if (!file->Open(filePath, OpenMode::ReadOnly)) { NazaraError("Failed to open stream from file: " + Error::GetLastError()); return false; diff --git a/src/Nazara/Utility/Formats/MD5AnimParser.cpp b/src/Nazara/Utility/Formats/MD5AnimParser.cpp index d415f2c00..d0bb520ec 100644 --- a/src/Nazara/Utility/Formats/MD5AnimParser.cpp +++ b/src/Nazara/Utility/Formats/MD5AnimParser.cpp @@ -25,7 +25,7 @@ namespace Nz MD5AnimParser::~MD5AnimParser() { // Reset stream flags - if ((m_streamFlags & StreamOption_Text) == 0) + if ((m_streamFlags & StreamOption::Text) == 0) m_stream.EnableTextMode(false); } diff --git a/src/Nazara/Utility/Formats/MD5MeshParser.cpp b/src/Nazara/Utility/Formats/MD5MeshParser.cpp index dbc32e498..abd7bce4f 100644 --- a/src/Nazara/Utility/Formats/MD5MeshParser.cpp +++ b/src/Nazara/Utility/Formats/MD5MeshParser.cpp @@ -25,7 +25,7 @@ namespace Nz MD5MeshParser::~MD5MeshParser() { // Reset stream flags - if ((m_streamFlags & StreamOption_Text) == 0) + if ((m_streamFlags & StreamOption::Text) == 0) m_stream.EnableTextMode(false); } diff --git a/src/Nazara/Utility/Formats/MTLParser.cpp b/src/Nazara/Utility/Formats/MTLParser.cpp index 48150e082..8b9aa50c3 100644 --- a/src/Nazara/Utility/Formats/MTLParser.cpp +++ b/src/Nazara/Utility/Formats/MTLParser.cpp @@ -35,7 +35,7 @@ namespace Nz // Force stream in text mode, reset it at the end Nz::CallOnExit resetTextMode; - if ((stream.GetStreamOptions() & StreamOption_Text) == 0) + if ((stream.GetStreamOptions() & StreamOption::Text) == 0) { stream.EnableTextMode(true); @@ -490,7 +490,7 @@ namespace Nz // Force stream in text mode, reset it at the end Nz::CallOnExit resetTextMode; - if ((stream.GetStreamOptions() & StreamOption_Text) == 0) + if ((stream.GetStreamOptions() & StreamOption::Text) == 0) { stream.EnableTextMode(true); diff --git a/src/Nazara/Utility/Formats/OBJLoader.cpp b/src/Nazara/Utility/Formats/OBJLoader.cpp index 7641aa018..9b14409c9 100644 --- a/src/Nazara/Utility/Formats/OBJLoader.cpp +++ b/src/Nazara/Utility/Formats/OBJLoader.cpp @@ -45,7 +45,7 @@ namespace Nz bool ParseMTL(Mesh& mesh, const std::filesystem::path& filePath, const std::string* materials, const OBJParser::Mesh* meshes, std::size_t meshCount) { File file(filePath); - if (!file.Open(OpenMode_ReadOnly | OpenMode_Text)) + if (!file.Open(OpenMode::ReadOnly | OpenMode::Text)) { NazaraError("Failed to open MTL file (" + file.GetPath().generic_u8string() + ')'); return false; @@ -344,7 +344,7 @@ namespace Nz std::filesystem::path mtlLib = parser.GetMtlLib(); if (!mtlLib.empty()) { - ErrorFlags flags(ErrorFlag_ThrowExceptionDisabled); + ErrorFlags flags(ErrorMode::ThrowExceptionDisabled); ParseMTL(*mesh, stream.GetDirectory() / mtlLib, materials, meshes, meshCount); } diff --git a/src/Nazara/Utility/Formats/OBJParser.cpp b/src/Nazara/Utility/Formats/OBJParser.cpp index f5e7b4f76..fe63efe31 100644 --- a/src/Nazara/Utility/Formats/OBJParser.cpp +++ b/src/Nazara/Utility/Formats/OBJParser.cpp @@ -23,7 +23,7 @@ namespace Nz // Force stream in text mode, reset it at the end Nz::CallOnExit resetTextMode; - if ((stream.GetStreamOptions() & StreamOption_Text) == 0) + if ((stream.GetStreamOptions() & StreamOption::Text) == 0) { stream.EnableTextMode(true); @@ -95,7 +95,7 @@ namespace Nz // Force stream in text mode, reset it at the end Nz::CallOnExit resetTextMode; - if ((stream.GetStreamOptions() & StreamOption_Text) == 0) + if ((stream.GetStreamOptions() & StreamOption::Text) == 0) { stream.EnableTextMode(true); @@ -493,7 +493,7 @@ namespace Nz // Force stream in text mode, reset it at the end Nz::CallOnExit resetTextMode; - if ((stream.GetStreamOptions() & StreamOption_Text) == 0) + if ((stream.GetStreamOptions() & StreamOption::Text) == 0) { stream.EnableTextMode(true); diff --git a/src/Nazara/Utility/Formats/OBJSaver.cpp b/src/Nazara/Utility/Formats/OBJSaver.cpp index dc70ef7c1..c18ed1a8e 100644 --- a/src/Nazara/Utility/Formats/OBJSaver.cpp +++ b/src/Nazara/Utility/Formats/OBJSaver.cpp @@ -190,7 +190,7 @@ namespace Nz if (!mtlPath.empty()) { - File mtlFile(mtlPath, OpenMode_WriteOnly | OpenMode_Truncate); + File mtlFile(mtlPath, OpenMode::WriteOnly | OpenMode::Truncate); if (mtlFile.IsOpen()) mtlFormat.Save(mtlFile); } diff --git a/src/Nazara/Utility/Image.cpp b/src/Nazara/Utility/Image.cpp index ff8462f04..d81cdb9df 100644 --- a/src/Nazara/Utility/Image.cpp +++ b/src/Nazara/Utility/Image.cpp @@ -47,7 +47,7 @@ namespace Nz Image::Image(ImageType type, PixelFormat format, unsigned int width, unsigned int height, unsigned int depth, UInt8 levelCount) : m_sharedImage(&emptyImage) { - ErrorFlags flags(ErrorFlag_ThrowException); + ErrorFlags flags(ErrorMode::ThrowException); Create(type, format, width, height, depth, levelCount); } diff --git a/src/Nazara/Utility/IndexBuffer.cpp b/src/Nazara/Utility/IndexBuffer.cpp index fc07d1012..79cffaf2f 100644 --- a/src/Nazara/Utility/IndexBuffer.cpp +++ b/src/Nazara/Utility/IndexBuffer.cpp @@ -15,19 +15,19 @@ namespace Nz { IndexBuffer::IndexBuffer(bool largeIndices, std::shared_ptr buffer) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(largeIndices, std::move(buffer)); } IndexBuffer::IndexBuffer(bool largeIndices, std::shared_ptr buffer, std::size_t offset, std::size_t size) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(largeIndices, std::move(buffer), offset, size); } IndexBuffer::IndexBuffer(bool largeIndices, std::size_t length, DataStorage storage, BufferUsageFlags usage) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(largeIndices, length, storage, usage); } diff --git a/src/Nazara/Utility/Mesh.cpp b/src/Nazara/Utility/Mesh.cpp index 055bd4c86..93e5a08d9 100644 --- a/src/Nazara/Utility/Mesh.cpp +++ b/src/Nazara/Utility/Mesh.cpp @@ -106,7 +106,7 @@ namespace Nz switch (primitive.type) { - case PrimitiveType_Box: + case PrimitiveType::Box: { unsigned int indexCount; unsigned int vertexCount; @@ -128,7 +128,7 @@ namespace Nz break; } - case PrimitiveType_Cone: + case PrimitiveType::Cone: { unsigned int indexCount; unsigned int vertexCount; @@ -150,7 +150,7 @@ namespace Nz break; } - case PrimitiveType_Plane: + case PrimitiveType::Plane: { unsigned int indexCount; unsigned int vertexCount; @@ -172,11 +172,11 @@ namespace Nz break; } - case PrimitiveType_Sphere: + case PrimitiveType::Sphere: { switch (primitive.sphere.type) { - case SphereType_Cubic: + case SphereType::Cubic: { unsigned int indexCount; unsigned int vertexCount; @@ -198,7 +198,7 @@ namespace Nz break; } - case SphereType_Ico: + case SphereType::Ico: { unsigned int indexCount; unsigned int vertexCount; @@ -220,7 +220,7 @@ namespace Nz break; } - case SphereType_UV: + case SphereType::UV: { unsigned int indexCount; unsigned int vertexCount; diff --git a/src/Nazara/Utility/Node.cpp b/src/Nazara/Utility/Node.cpp index 72289447a..0b70e69f9 100644 --- a/src/Nazara/Utility/Node.cpp +++ b/src/Nazara/Utility/Node.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include namespace Nz @@ -148,17 +149,17 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (!m_derivedUpdated) UpdateDerived(); return m_derivedPosition; - case CoordSys_Local: + case CoordSys::Local: return m_position; } - NazaraError("Coordinate system out of enum (0x" + NumberToString(coordSys, 16) + ')'); + NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')'); return Vector3f(); } @@ -174,17 +175,17 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (!m_derivedUpdated) UpdateDerived(); return m_derivedRotation; - case CoordSys_Local: + case CoordSys::Local: return m_rotation; } - NazaraError("Coordinate system out of enum (0x" + NumberToString(coordSys, 16) + ')'); + NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')'); return Quaternionf(); } @@ -192,17 +193,17 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (!m_derivedUpdated) UpdateDerived(); return m_derivedScale; - case CoordSys_Local: + case CoordSys::Local: return m_scale; } - NazaraError("Coordinate system out of enum (0x" + NumberToString(coordSys, 16) + ')'); + NazaraError("Coordinate system out of enum (0x" + NumberToString(UnderlyingCast(coordSys), 16) + ')'); return Vector3f(); } @@ -231,7 +232,7 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (!nodeA.m_derivedUpdated) nodeA.UpdateDerived(); @@ -243,7 +244,7 @@ namespace Nz m_scale = ToLocalScale(Vector3f::Lerp(nodeA.m_derivedScale, nodeB.m_derivedScale, interpolation)); break; - case CoordSys_Local: + case CoordSys::Local: m_position = Vector3f::Lerp(nodeA.m_position, nodeB.m_position, interpolation); m_rotation = Quaternionf::Slerp(nodeA.m_rotation, nodeB.m_rotation, interpolation); m_scale = Vector3f::Lerp(nodeA.m_scale, nodeB.m_scale, interpolation); @@ -258,7 +259,7 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: { if (m_parent) { @@ -273,7 +274,7 @@ namespace Nz break; } - case CoordSys_Local: + case CoordSys::Local: m_position += m_rotation * movement; break; } @@ -295,7 +296,7 @@ namespace Nz switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: { if (!m_derivedUpdated) UpdateDerived(); @@ -304,7 +305,7 @@ namespace Nz break; } - case CoordSys_Local: + case CoordSys::Local: m_rotation *= q; break; } @@ -449,9 +450,9 @@ namespace Nz if (m_parent) m_parent->AddChild(this); - SetRotation(m_derivedRotation, CoordSys_Global); - SetScale(m_derivedScale, CoordSys_Global); - SetPosition(m_derivedPosition, CoordSys_Global); + SetRotation(m_derivedRotation, CoordSys::Global); + SetScale(m_derivedScale, CoordSys::Global); + SetPosition(m_derivedPosition, CoordSys::Global); } else { @@ -477,7 +478,7 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (m_parent && m_inheritPosition) { if (!m_parent->m_derivedUpdated) @@ -489,7 +490,7 @@ namespace Nz m_position = position - m_initialPosition; break; - case CoordSys_Local: + case CoordSys::Local: m_position = position; break; } @@ -510,7 +511,7 @@ namespace Nz switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (m_parent && m_inheritRotation) { Quaternionf rot(m_parent->GetRotation() * m_initialRotation); @@ -522,7 +523,7 @@ namespace Nz break; - case CoordSys_Local: + case CoordSys::Local: m_rotation = q; break; } @@ -540,14 +541,14 @@ namespace Nz { switch (coordSys) { - case CoordSys_Global: + case CoordSys::Global: if (m_parent && m_inheritScale) m_scale = scale / (m_initialScale * m_parent->GetScale()); else m_scale = scale / m_initialScale; break; - case CoordSys_Local: + case CoordSys::Local: m_scale = scale; break; } @@ -567,9 +568,9 @@ namespace Nz void Node::SetTransformMatrix(const Matrix4f& matrix) { - SetPosition(matrix.GetTranslation(), CoordSys_Global); - SetRotation(matrix.GetRotation(), CoordSys_Global); - SetScale(matrix.GetScale(), CoordSys_Global); + SetPosition(matrix.GetTranslation(), CoordSys::Global); + SetRotation(matrix.GetRotation(), CoordSys::Global); + SetScale(matrix.GetScale(), CoordSys::Global); m_transformMatrix = matrix; m_transformMatrixUpdated = true; diff --git a/src/Nazara/Utility/Skeleton.cpp b/src/Nazara/Utility/Skeleton.cpp index 7d2570830..0e48b1cc2 100644 --- a/src/Nazara/Utility/Skeleton.cpp +++ b/src/Nazara/Utility/Skeleton.cpp @@ -155,7 +155,7 @@ namespace Nz const Joint* jointsA = &skeletonA.m_impl->joints[0]; const Joint* jointsB = &skeletonB.m_impl->joints[0]; for (std::size_t i = 0; i < m_impl->joints.size(); ++i) - m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys_Local); + m_impl->joints[i].Interpolate(jointsA[i], jointsB[i], interpolation, CoordSys::Local); InvalidateJoints(); } @@ -174,7 +174,7 @@ namespace Nz std::size_t index = indices[i]; NazaraAssert(index < m_impl->joints.size(), "joint index out of range"); - m_impl->joints[index].Interpolate(jointsA[index], jointsB[index], interpolation, CoordSys_Local); + m_impl->joints[index].Interpolate(jointsA[index], jointsB[index], interpolation, CoordSys::Local); } InvalidateJoints(); diff --git a/src/Nazara/Utility/UniformBuffer.cpp b/src/Nazara/Utility/UniformBuffer.cpp index e5b69200e..6fe544f4e 100644 --- a/src/Nazara/Utility/UniformBuffer.cpp +++ b/src/Nazara/Utility/UniformBuffer.cpp @@ -12,19 +12,19 @@ namespace Nz { UniformBuffer::UniformBuffer(std::shared_ptr buffer) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(std::move(buffer)); } UniformBuffer::UniformBuffer(std::shared_ptr buffer, UInt32 offset, UInt32 size) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(std::move(buffer), offset, size); } UniformBuffer::UniformBuffer(UInt32 length, DataStorage storage, BufferUsageFlags usage) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(length, storage, usage); } diff --git a/src/Nazara/Utility/VertexBuffer.cpp b/src/Nazara/Utility/VertexBuffer.cpp index 9632539ac..edff32a2c 100644 --- a/src/Nazara/Utility/VertexBuffer.cpp +++ b/src/Nazara/Utility/VertexBuffer.cpp @@ -11,19 +11,19 @@ namespace Nz { VertexBuffer::VertexBuffer(std::shared_ptr vertexDeclaration, std::shared_ptr buffer) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(std::move(vertexDeclaration), std::move(buffer)); } VertexBuffer::VertexBuffer(std::shared_ptr vertexDeclaration, std::shared_ptr buffer, std::size_t offset, std::size_t size) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(std::move(vertexDeclaration), std::move(buffer), offset, size); } VertexBuffer::VertexBuffer(std::shared_ptr vertexDeclaration, std::size_t length, DataStorage storage, BufferUsageFlags usage) { - ErrorFlags(ErrorFlag_ThrowException, true); + ErrorFlags(ErrorMode::ThrowException, true); Reset(std::move(vertexDeclaration), length, storage, usage); } diff --git a/src/Nazara/Utility/VertexDeclaration.cpp b/src/Nazara/Utility/VertexDeclaration.cpp index 53e284e9c..9a2a3e837 100644 --- a/src/Nazara/Utility/VertexDeclaration.cpp +++ b/src/Nazara/Utility/VertexDeclaration.cpp @@ -37,7 +37,7 @@ namespace Nz VertexDeclaration::VertexDeclaration(VertexInputRate inputRate, std::initializer_list components) : m_inputRate(inputRate) { - ErrorFlags errFlags(ErrorFlag_ThrowException); + ErrorFlags errFlags(ErrorMode::ThrowException); std::size_t offset = 0; m_components.reserve(components.size()); @@ -99,7 +99,7 @@ namespace Nz { try { - ErrorFlags flags(ErrorFlag_Silent | ErrorFlag_ThrowException); + ErrorFlags flags(ErrorMode::Silent | ErrorMode::ThrowException); auto NewDeclaration = [](VertexInputRate inputRate, std::initializer_list components) { diff --git a/src/Nazara/Utility/VertexMapper.cpp b/src/Nazara/Utility/VertexMapper.cpp index dd9a25235..a863ae8fa 100644 --- a/src/Nazara/Utility/VertexMapper.cpp +++ b/src/Nazara/Utility/VertexMapper.cpp @@ -14,7 +14,7 @@ namespace Nz { VertexMapper::VertexMapper(SubMesh& subMesh, BufferAccess access) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); std::shared_ptr buffer = nullptr; switch (subMesh.GetAnimationType()) @@ -44,13 +44,13 @@ namespace Nz VertexMapper::VertexMapper(VertexBuffer& vertexBuffer, BufferAccess access) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); m_mapper.Map(vertexBuffer, access); } VertexMapper::VertexMapper(const SubMesh& subMesh, BufferAccess access) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); std::shared_ptr buffer = nullptr; switch (subMesh.GetAnimationType()) @@ -80,7 +80,7 @@ namespace Nz VertexMapper::VertexMapper(const VertexBuffer& vertexBuffer, BufferAccess access) { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); m_mapper.Map(vertexBuffer, access); } diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index d912828e5..cc4150d0c 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -372,7 +372,7 @@ namespace Nz std::shared_ptr Vulkan::CreateDevice(const Vk::PhysicalDevice& deviceInfo) { - Nz::ErrorFlags errFlags(ErrorFlag_ThrowException, true); + Nz::ErrorFlags errFlags(ErrorMode::ThrowException, true); // Find a queue that supports graphics operations UInt32 graphicsQueueNodeIndex = UINT32_MAX; @@ -409,7 +409,7 @@ namespace Nz std::shared_ptr Vulkan::CreateDevice(const Vk::PhysicalDevice& deviceInfo, const Vk::Surface& surface, UInt32* graphicsFamilyIndex, UInt32* presentableFamilyIndex, UInt32* transferFamilyIndex) { - Nz::ErrorFlags errFlags(ErrorFlag_ThrowException, true); + Nz::ErrorFlags errFlags(ErrorMode::ThrowException, true); // Find a queue that supports graphics operations UInt32 graphicsQueueNodeIndex = UINT32_MAX; diff --git a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp index 5877ef9c9..bdc9c7e20 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Device.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Device.cpp @@ -75,7 +75,7 @@ namespace Nz // Load all device-related functions try { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); UInt32 deviceVersion = deviceInfo.properties.apiVersion; diff --git a/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp b/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp index aa5f6f513..f75ae0af1 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp @@ -109,7 +109,7 @@ namespace Nz // And now load everything try { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); #define NAZARA_VULKANRENDERER_INSTANCE_EXT_BEGIN(ext) if (IsExtensionLoaded(#ext)) { #define NAZARA_VULKANRENDERER_INSTANCE_EXT_END() } diff --git a/src/Nazara/VulkanRenderer/Wrapper/Loader.cpp b/src/Nazara/VulkanRenderer/Wrapper/Loader.cpp index e0937675a..c41ca52c5 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Loader.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Loader.cpp @@ -99,7 +99,7 @@ namespace Nz #define NAZARA_VULKANRENDERER_LOAD_GLOBAL(func) func = reinterpret_cast(GetProcAddr(#func)) try { - ErrorFlags flags(ErrorFlag_ThrowException, true); + ErrorFlags flags(ErrorMode::ThrowException, true); #define NAZARA_VULKANRENDERER_GLOBAL_FUNCTION(func) func = reinterpret_cast(GetProcAddr(#func, false)); #define NAZARA_VULKANRENDERER_GLOBAL_FUNCTION_OPT(func) func = reinterpret_cast(GetProcAddr(#func, true)); diff --git a/src/NazaraSDK/ClientSdk.cpp b/src/NazaraSDK/ClientSdk.cpp index a0337e172..f9791d9c2 100644 --- a/src/NazaraSDK/ClientSdk.cpp +++ b/src/NazaraSDK/ClientSdk.cpp @@ -34,7 +34,7 @@ namespace Ndk ClientSdk::ClientSdk(Config /*config*/) : ModuleBase("ClientSDK", this) { - Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true); + Nz::ErrorFlags errFlags(Nz::ErrorMode::ThrowException, true); // Client components InitializeComponent("NdkList"); diff --git a/src/NazaraSDK/Sdk.cpp b/src/NazaraSDK/Sdk.cpp index 6ae2f16d2..c548da94f 100644 --- a/src/NazaraSDK/Sdk.cpp +++ b/src/NazaraSDK/Sdk.cpp @@ -30,7 +30,7 @@ namespace Ndk Sdk::Sdk(Config /*config*/) : ModuleBase("SDK", this) { - Nz::ErrorFlags errFlags(Nz::ErrorFlag_ThrowException, true); + Nz::ErrorFlags errFlags(Nz::ErrorMode::ThrowException, true); // SDK Initialization diff --git a/src/NazaraSDK/Systems/ListenerSystem.cpp b/src/NazaraSDK/Systems/ListenerSystem.cpp index 9fdb2147e..39a488220 100644 --- a/src/NazaraSDK/Systems/ListenerSystem.cpp +++ b/src/NazaraSDK/Systems/ListenerSystem.cpp @@ -52,10 +52,10 @@ namespace Ndk // We get the position and the rotation to affect these to the listener const NodeComponent& node = entity->GetComponent(); - Nz::Vector3f newPos = node.GetPosition(Nz::CoordSys_Global); + Nz::Vector3f newPos = node.GetPosition(Nz::CoordSys::Global); audio->SetListenerPosition(newPos); - audio->SetListenerRotation(node.GetRotation(Nz::CoordSys_Global)); + audio->SetListenerRotation(node.GetRotation(Nz::CoordSys::Global)); // Compute listener velocity based on their old/new position Nz::Vector3f velocity = (newPos - oldPos) / elapsedTime; diff --git a/src/NazaraSDK/Systems/PhysicsSystem2D.cpp b/src/NazaraSDK/Systems/PhysicsSystem2D.cpp index 60ff8e437..fab5be272 100644 --- a/src/NazaraSDK/Systems/PhysicsSystem2D.cpp +++ b/src/NazaraSDK/Systems/PhysicsSystem2D.cpp @@ -196,7 +196,7 @@ namespace Ndk auto& node = entity->GetComponent(); Nz::RigidBody2D* physObj = collision.GetStaticBody(); - physObj->SetPosition(Nz::Vector2f(node.GetPosition(Nz::CoordSys_Global))); + physObj->SetPosition(Nz::Vector2f(node.GetPosition(Nz::CoordSys::Global))); //physObj->SetRotation(node.GetRotation()); } } @@ -224,8 +224,8 @@ namespace Ndk PhysicsComponent2D& phys = entity->GetComponent(); Nz::RigidBody2D* body = phys.GetRigidBody(); - node.SetRotation(body->GetRotation(), Nz::CoordSys_Global); - node.SetPosition(Nz::Vector3f(body->GetPosition(), node.GetPosition(Nz::CoordSys_Global).z), Nz::CoordSys_Global); + node.SetRotation(body->GetRotation(), Nz::CoordSys::Global); + node.SetPosition(Nz::Vector3f(body->GetPosition(), node.GetPosition(Nz::CoordSys::Global).z), Nz::CoordSys::Global); } float invElapsedTime = 1.f / elapsedTime; @@ -237,7 +237,7 @@ namespace Ndk Nz::RigidBody2D* body = collision.GetStaticBody(); Nz::Vector2f oldPosition = body->GetPosition(); - Nz::Vector2f newPosition = Nz::Vector2f(node.GetPosition(Nz::CoordSys_Global)); + Nz::Vector2f newPosition = Nz::Vector2f(node.GetPosition(Nz::CoordSys::Global)); // To move static objects and ensure their collisions, we have to specify them a velocity // (/!\: the physical engine does not apply the speed on static objects) @@ -250,7 +250,7 @@ namespace Ndk body->SetVelocity(Nz::Vector2f::Zero()); Nz::RadianAnglef oldRotation = body->GetRotation(); - Nz::RadianAnglef newRotation = node.GetRotation(Nz::CoordSys_Global).To2DAngle(); + Nz::RadianAnglef newRotation = node.GetRotation(Nz::CoordSys::Global).To2DAngle(); if (newRotation != oldRotation) { diff --git a/src/NazaraSDK/Systems/PhysicsSystem3D.cpp b/src/NazaraSDK/Systems/PhysicsSystem3D.cpp index c83103048..66d94636b 100644 --- a/src/NazaraSDK/Systems/PhysicsSystem3D.cpp +++ b/src/NazaraSDK/Systems/PhysicsSystem3D.cpp @@ -69,8 +69,8 @@ namespace Ndk auto& node = entity->GetComponent(); Nz::RigidBody3D* physObj = collision.GetStaticBody(); - physObj->SetPosition(node.GetPosition(Nz::CoordSys_Global)); - physObj->SetRotation(node.GetRotation(Nz::CoordSys_Global)); + physObj->SetPosition(node.GetPosition(Nz::CoordSys::Global)); + physObj->SetRotation(node.GetRotation(Nz::CoordSys::Global)); } } @@ -97,8 +97,8 @@ namespace Ndk PhysicsComponent3D& phys = entity->GetComponent(); Nz::RigidBody3D* physObj = phys.GetRigidBody(); - node.SetRotation(physObj->GetRotation(), Nz::CoordSys_Global); - node.SetPosition(physObj->GetPosition(), Nz::CoordSys_Global); + node.SetRotation(physObj->GetRotation(), Nz::CoordSys::Global); + node.SetPosition(physObj->GetPosition(), Nz::CoordSys::Global); } float invElapsedTime = 1.f / elapsedTime; @@ -111,8 +111,8 @@ namespace Ndk Nz::Quaternionf oldRotation = physObj->GetRotation(); Nz::Vector3f oldPosition = physObj->GetPosition(); - Nz::Quaternionf newRotation = node.GetRotation(Nz::CoordSys_Global); - Nz::Vector3f newPosition = node.GetPosition(Nz::CoordSys_Global); + Nz::Quaternionf newRotation = node.GetRotation(Nz::CoordSys::Global); + Nz::Vector3f newPosition = node.GetPosition(Nz::CoordSys::Global); // To move static objects and ensure their collisions, we have to specify them a velocity // (/!\: the physical motor does not apply the speed on static objects) diff --git a/src/ShaderNode/Widgets/MainWindow.cpp b/src/ShaderNode/Widgets/MainWindow.cpp index 54678eb23..ed4055714 100644 --- a/src/ShaderNode/Widgets/MainWindow.cpp +++ b/src/ShaderNode/Widgets/MainWindow.cpp @@ -190,7 +190,7 @@ void MainWindow::OnCompile() if (!fileName.endsWith("shader", Qt::CaseInsensitive)) fileName += ".shader"; - Nz::File file(fileName.toStdString(), Nz::OpenMode_WriteOnly); + Nz::File file(fileName.toStdString(), Nz::OpenMode::WriteOnly); file.Write(Nz::ShaderAst::SerializeShader(shader)); } catch (const std::exception& e) diff --git a/tests/Engine/Core/AbstractHash.cpp b/tests/Engine/Core/AbstractHash.cpp index a2b4f49e1..44533fd6f 100644 --- a/tests/Engine/Core/AbstractHash.cpp +++ b/tests/Engine/Core/AbstractHash.cpp @@ -9,7 +9,7 @@ SCENARIO("AbstractHash", "[CORE][ABSTRACTHASH]") { GIVEN("The hash SHA512") { - std::unique_ptr SHA512 = Nz::AbstractHash::Get(Nz::HashType_SHA512); + std::unique_ptr SHA512 = Nz::AbstractHash::Get(Nz::HashType::SHA512); SHA512->Begin(); WHEN("We introduce data") diff --git a/tests/Engine/Core/AlgorithmCore.cpp b/tests/Engine/Core/AlgorithmCore.cpp index cdc07db90..249a46631 100644 --- a/tests/Engine/Core/AlgorithmCore.cpp +++ b/tests/Engine/Core/AlgorithmCore.cpp @@ -32,61 +32,61 @@ TEST_CASE("ComputeHash", "[CORE][ALGORITHM]") { /*SECTION("Compute CRC32 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_CRC32, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::CRC32, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "596A3B55"); } SECTION("Compute CRC64 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_CRC64, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::CRC64, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "33302B9FC23855A8"); } SECTION("Compute Fletcher16 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_Fletcher16, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::Fletcher16, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "F5CA"); }*/ SECTION("Compute MD5 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_MD5, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::MD5, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "81DC9BDB52D04DC20036DBD8313ED055"); } SECTION("Compute SHA1 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_SHA1, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::SHA1, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "7110EDA4D09E062AA5E4A390B0A572AC0D2C0220"); } SECTION("Compute SHA224 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_SHA224, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::SHA224, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "99FB2F48C6AF4761F904FC85F95EB56190E5D40B1F44EC3A9C1FA319"); } SECTION("Compute SHA256 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_SHA256, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::SHA256, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4"); } SECTION("Compute SHA384 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_SHA384, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::SHA384, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "504F008C8FCF8B2ED5DFCDE752FC5464AB8BA064215D9C5B5FC486AF3D9AB8C81B14785180D2AD7CEE1AB792AD44798C"); } SECTION("Compute SHA512 of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_SHA512, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::SHA512, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "D404559F602EAB6FD602AC7680DACBFAADD13630335E951F097AF3900E9DE176B6DB28512F2E000B9D04FBA5133E8B1C6E8DF59DB3A8AB9D60BE4B97CC9E81DB"); } SECTION("Compute Whirlpool of '1234'") { - auto result = Nz::ComputeHash(Nz::HashType_Whirlpool, "1234"); + auto result = Nz::ComputeHash(Nz::HashType::Whirlpool, "1234"); REQUIRE(Nz::ToUpper(result.ToHex()) == "2F9959B230A44678DD2DC29F037BA1159F233AA9AB183CE3A0678EAAE002E5AA6F27F47144A1A4365116D3DB1B58EC47896623B92D85CB2F191705DAF11858B8"); } } diff --git a/tests/Engine/Core/ByteStream.cpp b/tests/Engine/Core/ByteStream.cpp index c948a6ec5..744910cca 100644 --- a/tests/Engine/Core/ByteStream.cpp +++ b/tests/Engine/Core/ByteStream.cpp @@ -44,7 +44,7 @@ SCENARIO("ByteStream", "[CORE][BYTESTREAM]") Nz::ByteArray byteArray(numberOfBytes); Nz::ByteStream byteStream(&byteArray); - byteStream.SetDataEndianness(Nz::GetPlatformEndianness() == Nz::Endianness_BigEndian ? Nz::Endianness_LittleEndian : Nz::Endianness_BigEndian); + byteStream.SetDataEndianness(Nz::GetPlatformEndianness() == Nz::Endianness::BigEndian ? Nz::Endianness::LittleEndian : Nz::Endianness::BigEndian); WHEN("We write an integer") { diff --git a/tests/Engine/Core/Error.cpp b/tests/Engine/Core/Error.cpp index e95f6d990..5e042d7b4 100644 --- a/tests/Engine/Core/Error.cpp +++ b/tests/Engine/Core/Error.cpp @@ -3,7 +3,7 @@ SCENARIO("Error", "[CORE][ERROR]") { - Nz::UInt32 oldFlags = Nz::Error::GetFlags(); + Nz::ErrorModeFlags oldFlags = Nz::Error::GetFlags(); GIVEN("Multiple errors") { @@ -11,15 +11,15 @@ SCENARIO("Error", "[CORE][ERROR]") { THEN("These errors should be written in the log file") { - Nz::Error::Trigger(Nz::ErrorType_Internal, "ErrorType_Internal"); - Nz::Error::Trigger(Nz::ErrorType_Internal, "ErrorType_Internal", 2, "Error.cpp", "2nd place Internal"); - REQUIRE("ErrorType_Internal" == Nz::Error::GetLastError()); - Nz::Error::Trigger(Nz::ErrorType_Normal, "ErrorType_Normal"); - Nz::Error::Trigger(Nz::ErrorType_Normal, "ErrorType_Normal", 2, "Error.cpp", "2nd place Normal"); - REQUIRE("ErrorType_Normal" == Nz::Error::GetLastError()); - Nz::Error::Trigger(Nz::ErrorType_Warning, "ErrorType_Warning"); - Nz::Error::Trigger(Nz::ErrorType_Warning, "ErrorType_Warning", 2, "Error.cpp", "2nd place Warning"); - REQUIRE("ErrorType_Warning" == Nz::Error::GetLastError()); + Nz::Error::Trigger(Nz::ErrorType::Internal, "ErrorType::Internal"); + Nz::Error::Trigger(Nz::ErrorType::Internal, "ErrorType::Internal", 2, "Error.cpp", "2nd place Internal"); + REQUIRE("ErrorType::Internal" == Nz::Error::GetLastError()); + Nz::Error::Trigger(Nz::ErrorType::Normal, "ErrorType::Normal"); + Nz::Error::Trigger(Nz::ErrorType::Normal, "ErrorType::Normal", 2, "Error.cpp", "2nd place Normal"); + REQUIRE("ErrorType::Normal" == Nz::Error::GetLastError()); + Nz::Error::Trigger(Nz::ErrorType::Warning, "ErrorType::Warning"); + Nz::Error::Trigger(Nz::ErrorType::Warning, "ErrorType::Warning", 2, "Error.cpp", "2nd place Warning"); + REQUIRE("ErrorType::Warning" == Nz::Error::GetLastError()); } } } diff --git a/tests/Engine/Core/File.cpp b/tests/Engine/Core/File.cpp index 130166746..f3cc2714a 100644 --- a/tests/Engine/Core/File.cpp +++ b/tests/Engine/Core/File.cpp @@ -67,7 +67,7 @@ SCENARIO("File", "[CORE][FILE]") { REQUIRE(std::filesystem::exists(GetResourceDir() / "Engine/Core/FileTest.txt")); - Nz::File fileTest(GetResourceDir() / "Engine/Core/FileTest.txt", Nz::OpenMode_ReadOnly | Nz::OpenMode_Text); + Nz::File fileTest(GetResourceDir() / "Engine/Core/FileTest.txt", Nz::OpenMode::ReadOnly | Nz::OpenMode::Text); WHEN("We read the first line of the file") { diff --git a/tests/Engine/Core/PrimitiveList.cpp b/tests/Engine/Core/PrimitiveList.cpp index e0098a75e..4d6b7651f 100644 --- a/tests/Engine/Core/PrimitiveList.cpp +++ b/tests/Engine/Core/PrimitiveList.cpp @@ -25,19 +25,19 @@ SCENARIO("PrimitiveList", "[CORE][PRIMITIVELIST]") THEN("The first one is the cubic sphere") { - REQUIRE(primitiveList(0).type == Nz::PrimitiveType_Sphere); - REQUIRE(primitiveList(0).sphere.type == Nz::SphereType_Cubic); + REQUIRE(primitiveList(0).type == Nz::PrimitiveType::Sphere); + REQUIRE(primitiveList(0).sphere.type == Nz::SphereType::Cubic); } THEN("The second one is the box") { - REQUIRE(primitiveList(1).type == Nz::PrimitiveType_Box); + REQUIRE(primitiveList(1).type == Nz::PrimitiveType::Box); } THEN("The third one is the ico sphere") { - REQUIRE(primitiveList(2).type == Nz::PrimitiveType_Sphere); - REQUIRE(primitiveList(2).sphere.type == Nz::SphereType_Ico); + REQUIRE(primitiveList(2).type == Nz::PrimitiveType::Sphere); + REQUIRE(primitiveList(2).sphere.type == Nz::SphereType::Ico); } } } diff --git a/tests/Engine/Network/IpAddress.cpp b/tests/Engine/Network/IpAddress.cpp index 36fead7a2..1c1dd042c 100644 --- a/tests/Engine/Network/IpAddress.cpp +++ b/tests/Engine/Network/IpAddress.cpp @@ -27,7 +27,7 @@ SCENARIO("IpAddress", "[NETWORK][IPADDRESS]") { WHEN("We get the IP of Nazara") { - std::vector hostnameInfos = Nz::IpAddress::ResolveHostname(Nz::NetProtocol_IPv4, "nazara.digitalpulsesoftware.net"); + std::vector hostnameInfos = Nz::IpAddress::ResolveHostname(Nz::NetProtocol::IPv4, "nazara.digitalpulsesoftware.net"); THEN("Result is not null") { diff --git a/tests/Engine/Network/RUdpConnection.cpp b/tests/Engine/Network/RUdpConnection.cpp deleted file mode 100644 index cd30b3e1e..000000000 --- a/tests/Engine/Network/RUdpConnection.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include - -#include - -SCENARIO("RUdpConnection", "[NETWORK][RUDPCONNECTION]") -{ - GIVEN("Two RUdpConnection, one client, one server") - { - // Disabled for now - - /*Nz::UInt16 port = 64266; - Nz::RUdpConnection server; - REQUIRE(server.Listen(Nz::NetProtocol_IPv4, port)); - - Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port); - REQUIRE(serverIP.IsValid()); - - Nz::RUdpConnection client; - REQUIRE(client.Listen(Nz::NetProtocol_IPv4, port + 1)); - - Nz::IpAddress clientIP = client.GetBoundAddress(); - REQUIRE(client.Connect(serverIP)); - REQUIRE(clientIP.IsValid()); - - WHEN("We send data from client") - { - Nz::NetPacket packet(1); - Nz::Vector3f vector123(1.f, 2.f, 3.f); - packet << vector123; - REQUIRE(client.Send(serverIP, Nz::PacketPriority_Immediate, Nz::PacketReliability_Reliable, packet)); - client.Update(); - - THEN("We should get it on the server") - { - Nz::RUdpMessage rudpMessage; - server.Update(); - - REQUIRE(server.PollMessage(&rudpMessage)); - - Nz::Vector3f result; - rudpMessage.data >> result; - REQUIRE(result == vector123); - } - }*/ - } -} diff --git a/tests/Engine/Network/SocketPoller.cpp b/tests/Engine/Network/SocketPoller.cpp index 2e880cf5c..851e7d85f 100644 --- a/tests/Engine/Network/SocketPoller.cpp +++ b/tests/Engine/Network/SocketPoller.cpp @@ -17,7 +17,7 @@ SCENARIO("SocketPoller", "[NETWORK][SOCKETPOLLER]") Nz::TcpServer server; server.EnableBlocking(false); - REQUIRE(server.Listen(Nz::NetProtocol_IPv4, port) == Nz::SocketState_Bound); + REQUIRE(server.Listen(Nz::NetProtocol::IPv4, port) == Nz::SocketState::Bound); Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port); REQUIRE(serverIP.IsValid()); @@ -27,7 +27,7 @@ SCENARIO("SocketPoller", "[NETWORK][SOCKETPOLLER]") WHEN("We register the server socket to the poller") { - REQUIRE(serverPoller.RegisterSocket(server, Nz::SocketPollEvent_Read)); + REQUIRE(serverPoller.RegisterSocket(server, Nz::SocketPollEvent::Read)); THEN("The poller should have registered our socket") { @@ -37,7 +37,7 @@ SCENARIO("SocketPoller", "[NETWORK][SOCKETPOLLER]") { Nz::SocketState state = clientToServer.Connect(serverIP); - CHECK(state != Nz::SocketState_NotConnected); + CHECK(state != Nz::SocketState::NotConnected); AND_THEN("We wait on our selector, it should return true") { @@ -48,7 +48,7 @@ SCENARIO("SocketPoller", "[NETWORK][SOCKETPOLLER]") WHEN("We register the client socket to the poller") { - REQUIRE(serverPoller.RegisterSocket(serverToClient, Nz::SocketPollEvent_Read)); + REQUIRE(serverPoller.RegisterSocket(serverToClient, Nz::SocketPollEvent::Read)); THEN("The poller should have registered our socket") { diff --git a/tests/Engine/Network/TCP.cpp b/tests/Engine/Network/TCP.cpp index 0bc90483c..68ae6efc7 100644 --- a/tests/Engine/Network/TCP.cpp +++ b/tests/Engine/Network/TCP.cpp @@ -19,13 +19,13 @@ SCENARIO("TCP", "[NETWORK][TCP]") Nz::TcpServer server; server.EnableBlocking(false); - REQUIRE(server.Listen(Nz::NetProtocol_IPv4, port) == Nz::SocketState_Bound); + REQUIRE(server.Listen(Nz::NetProtocol::IPv4, port) == Nz::SocketState::Bound); Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port); REQUIRE(serverIP.IsValid()); Nz::TcpClient client; - REQUIRE(client.Connect(serverIP) == Nz::SocketState_Connecting); + REQUIRE(client.Connect(serverIP) == Nz::SocketState::Connecting); Nz::IpAddress clientIP = client.GetRemoteAddress(); CHECK(clientIP.IsValid()); diff --git a/tests/Engine/Network/UdpSocket.cpp b/tests/Engine/Network/UdpSocket.cpp index 00d793e7a..f4b8b8aa9 100644 --- a/tests/Engine/Network/UdpSocket.cpp +++ b/tests/Engine/Network/UdpSocket.cpp @@ -12,14 +12,14 @@ SCENARIO("UdpSocket", "[NETWORK][UDPSOCKET]") std::uniform_int_distribution dis(1025, 65535); Nz::UInt16 port = dis(rd); - Nz::UdpSocket server(Nz::NetProtocol_IPv4); - REQUIRE(server.Bind(port) == Nz::SocketState_Bound); + Nz::UdpSocket server(Nz::NetProtocol::IPv4); + REQUIRE(server.Bind(port) == Nz::SocketState::Bound); Nz::IpAddress serverIP(Nz::IpAddress::LoopbackIpV4.ToIPv4(), port); REQUIRE(serverIP.IsValid()); - Nz::UdpSocket client(Nz::NetProtocol_IPv4); - REQUIRE(client.Bind(port + 1) == Nz::SocketState_Bound); + Nz::UdpSocket client(Nz::NetProtocol::IPv4); + REQUIRE(client.Bind(port + 1) == Nz::SocketState::Bound); Nz::IpAddress clientIP = client.GetBoundAddress(); REQUIRE(clientIP.IsValid()); diff --git a/tests/Engine/Physics2D/RigidBody2D.cpp b/tests/Engine/Physics2D/RigidBody2D.cpp index cb128de64..c8448f4bf 100644 --- a/tests/Engine/Physics2D/RigidBody2D.cpp +++ b/tests/Engine/Physics2D/RigidBody2D.cpp @@ -131,7 +131,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") { CHECK(body.GetAABB() == aabb); CHECK(body.GetAngularVelocity() == 0.f); - CHECK(body.GetMassCenter(Nz::CoordSys_Global) == position); + CHECK(body.GetMassCenter(Nz::CoordSys::Global) == position); CHECK(body.GetGeom() == box); CHECK(body.GetMass() == Approx(mass)); CHECK(body.GetPosition() == position); @@ -155,7 +155,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") { aabb.Translate(velocity); CHECK(body.GetAABB() == aabb); - CHECK(body.GetMassCenter(Nz::CoordSys_Global) == position); + CHECK(body.GetMassCenter(Nz::CoordSys::Global) == position); CHECK(body.GetPosition() == position); CHECK(body.GetVelocity() == velocity); }