Convert all remaining enums to enum classes (!)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ErrorMode>
|
||||
{
|
||||
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<ErrorMode>;
|
||||
|
||||
HashType_Max = HashType_Whirlpool
|
||||
enum class ErrorType
|
||||
{
|
||||
AssertFailed,
|
||||
Internal,
|
||||
Normal,
|
||||
Warning,
|
||||
|
||||
Max = Warning
|
||||
};
|
||||
|
||||
enum OpenMode
|
||||
constexpr std::size_t ErrorTypeCount = static_cast<std::size_t>(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<std::size_t>(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<OpenMode>
|
||||
{
|
||||
static constexpr OpenMode max = OpenMode_Max;
|
||||
static constexpr OpenMode max = OpenMode::Max;
|
||||
};
|
||||
|
||||
using OpenModeFlags = Flags<OpenMode>;
|
||||
|
||||
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<std::size_t>(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<std::size_t>(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<std::size_t>(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<std::size_t>(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<StreamOption>
|
||||
{
|
||||
static constexpr StreamOption max = StreamOption_Max;
|
||||
static constexpr StreamOption max = StreamOption::Max;
|
||||
};
|
||||
|
||||
using StreamOptionFlags = Flags<StreamOption>;
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
|
||||
@@ -8,26 +8,27 @@
|
||||
#define NAZARA_ERRORFLAGS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Nz
|
||||
struct NAZARA_CORE_API SerializationContext
|
||||
{
|
||||
MovablePtr<Stream> 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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<std::size_t>(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<std::size_t>(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<std::size_t>(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<std::size_t>(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<std::size_t>(SocketPollEvent::Max) + 1;
|
||||
|
||||
template<>
|
||||
struct EnumAsFlags<SocketPollEvent>
|
||||
{
|
||||
static constexpr SocketPollEvent max = SocketPollEvent_Max;
|
||||
static constexpr SocketPollEvent max = SocketPollEvent::Max;
|
||||
};
|
||||
|
||||
using SocketPollEventFlags = Flags<SocketPollEvent>;
|
||||
|
||||
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<std::size_t>(SocketState::Max) + 1;
|
||||
|
||||
SocketType_Max = SocketType_Unknown
|
||||
enum class SocketType
|
||||
{
|
||||
Raw,
|
||||
TCP,
|
||||
UDP,
|
||||
Unknown,
|
||||
|
||||
Max = Unknown
|
||||
};
|
||||
|
||||
constexpr std::size_t SocketTypeCount = static_cast<std::size_t>(SocketType::Max) + 1;
|
||||
}
|
||||
|
||||
#endif // NAZARA_ENUMS_NETWORK_HPP
|
||||
|
||||
@@ -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<size_t>::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++)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/Clock.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
#include <Nazara/Network/RUdpMessage.hpp>
|
||||
#include <Nazara/Network/UdpSocket.hpp>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <random>
|
||||
#include <set>
|
||||
#include <unordered_map>
|
||||
|
||||
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<std::vector<PendingPacket>, PacketPriority_Max + 1> pendingPackets;
|
||||
std::deque<PendingAckPacket> pendingAckQueue;
|
||||
std::set<UInt16> 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<RUdpMessage> m_receivedMessages;
|
||||
std::size_t m_peerIterator;
|
||||
std::unordered_map<IpAddress, std::size_t> m_peerByIP;
|
||||
std::vector<PeerData> m_peers;
|
||||
Bitset<UInt64> 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 <Nazara/Network/RUdpConnection.inl>
|
||||
|
||||
#endif // NAZARA_RUDPSERVER_HPP
|
||||
@@ -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 <Nazara/Network/Debug.hpp>
|
||||
|
||||
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<SequenceIndex>::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<PendingPacket>& 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<SequenceIndex>::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 <Nazara/Network/DebugOff.hpp>
|
||||
@@ -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 <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <Nazara/Network/NetPacket.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct RUdpMessage
|
||||
{
|
||||
IpAddress from;
|
||||
NetPacket data;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_RUDMESSAGE_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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<Collider2D>& 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<Collider2D> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ namespace Nz
|
||||
inline RenderWindow::RenderWindow(std::shared_ptr<RenderDevice> 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> renderDevice, void* handle, const RenderWindowParameters& parameters)
|
||||
{
|
||||
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
|
||||
ErrorFlags errFlags(ErrorMode::ThrowException, true);
|
||||
|
||||
Create(std::move(renderDevice), handle, parameters);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Ndk
|
||||
class NDK_API VelocityComponent : public Component<VelocityComponent>
|
||||
{
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user