Remove Nz::String and Nz::StringStream
This commit is contained in:
parent
d665af1f9d
commit
2b6a463a45
|
|
@ -14,7 +14,7 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
void printCap(std::ostream& o, const Nz::String& cap, bool b);
|
||||
void printCap(std::ostream& o, const std::string& cap, bool b);
|
||||
|
||||
int main()
|
||||
{
|
||||
|
|
@ -65,7 +65,7 @@ int main()
|
|||
Nz::File reportFile("HardwareInfo.txt");
|
||||
if (reportFile.Open(Nz::OpenMode_Text | Nz::OpenMode_Truncate | Nz::OpenMode_WriteOnly))
|
||||
{
|
||||
reportFile.Write(oss.str()); // Conversion implicite en Nz::String
|
||||
reportFile.Write(oss.str()); // Conversion implicite en std::string
|
||||
reportFile.Close();
|
||||
|
||||
char accentAigu = static_cast<char>(130); // C'est crade, mais ça marche chez 95% des Windowsiens
|
||||
|
|
@ -79,7 +79,7 @@ int main()
|
|||
return 0;
|
||||
}
|
||||
|
||||
void printCap(std::ostream& o, const Nz::String& cap, bool b)
|
||||
void printCap(std::ostream& o, const std::string& cap, bool b)
|
||||
{
|
||||
if (b)
|
||||
o << cap << ": Oui" << std::endl;
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ int main()
|
|||
{
|
||||
const Nz::ParameterList& matData = mesh->GetMaterialData(i);
|
||||
|
||||
Nz::String data;
|
||||
std::string data;
|
||||
if (!matData.GetStringParameter(Nz::MaterialData::FilePath, &data))
|
||||
data = "<Custom>";
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ int main()
|
|||
meshParams.matrix = Nz::Matrix4f::Rotate(Nz::EulerAnglesf(0.f, 90.f, 180.f)) * Nz::Matrix4f::Scale(Nz::Vector3f(0.002f));
|
||||
meshParams.vertexDeclaration = Nz::VertexDeclaration::Get(Nz::VertexLayout_XYZ_Normal_UV);
|
||||
|
||||
Nz::String windowTitle = "Render Test";
|
||||
std::string windowTitle = "Render Test";
|
||||
if (!window.Create(Nz::VideoMode(800, 600, 32), windowTitle))
|
||||
{
|
||||
std::cout << "Failed to create Window" << std::endl;
|
||||
|
|
@ -341,7 +341,7 @@ int main()
|
|||
if (secondClock.GetMilliseconds() >= 1000) // Toutes les secondes
|
||||
{
|
||||
// Et on insère ces données dans le titre de la fenêtre
|
||||
window.SetTitle(windowTitle + " - " + Nz::String::Number(fps) + " FPS");
|
||||
window.SetTitle(windowTitle + " - " + Nz::NumberToString(fps) + " FPS");
|
||||
|
||||
/*
|
||||
Note: En C++11 il est possible d'insérer de l'Unicode de façon standard, quel que soit l'encodage du fichier,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Audio/Config.hpp>
|
||||
#include <Nazara/Audio/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// Inclusion of OpenAL headers
|
||||
|
|
@ -64,19 +64,19 @@ namespace Nz
|
|||
class NAZARA_AUDIO_API OpenAL
|
||||
{
|
||||
public:
|
||||
static OpenALFunc GetEntry(const String& entryPoint);
|
||||
static String GetRendererName();
|
||||
static String GetVendorName();
|
||||
static OpenALFunc GetEntry(const std::string& entryPoint);
|
||||
static std::string GetRendererName();
|
||||
static std::string GetVendorName();
|
||||
static unsigned int GetVersion();
|
||||
|
||||
static bool Initialize(bool openDevice = true);
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static std::size_t QueryInputDevices(std::vector<String>& devices);
|
||||
static std::size_t QueryOutputDevices(std::vector<String>& devices);
|
||||
static std::size_t QueryInputDevices(std::vector<std::string>& devices);
|
||||
static std::size_t QueryOutputDevices(std::vector<std::string>& devices);
|
||||
|
||||
static bool SetDevice(const String& deviceName);
|
||||
static bool SetDevice(const std::string& deviceName);
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
|
|
|
|||
|
|
@ -87,9 +87,7 @@
|
|||
#include <Nazara/Core/StackVector.hpp>
|
||||
#include <Nazara/Core/StdLogger.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/TaskScheduler.hpp>
|
||||
#include <Nazara/Core/TypeList.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
#define NAZARA_ABSTRACTLOGGER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -22,8 +23,8 @@ namespace Nz
|
|||
|
||||
virtual bool IsStdReplicationEnabled() const = 0;
|
||||
|
||||
virtual void Write(const String& string) = 0;
|
||||
virtual void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
|
||||
virtual void Write(const std::string_view& string) = 0;
|
||||
virtual void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#define NAZARA_ALGORITHM_CORE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/SerializationContext.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
|
|
@ -18,7 +19,6 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
class AbstractHash;
|
||||
class ByteArray;
|
||||
|
||||
template<typename T> constexpr T Align(T offset, T alignment);
|
||||
|
|
@ -30,6 +30,7 @@ namespace Nz
|
|||
template<typename T> ByteArray ComputeHash(AbstractHash* hash, const T& v);
|
||||
template<typename T, std::size_t N> constexpr std::size_t CountOf(T(&name)[N]) noexcept;
|
||||
template<typename T> std::size_t CountOf(const T& c);
|
||||
inline bool HashAppend(AbstractHash* hash, const std::string_view& v);
|
||||
template<typename T> void HashCombine(std::size_t& seed, const T& v);
|
||||
template<typename T> bool IsPowerOfTwo(T value);
|
||||
template<typename T> T ReverseBits(T integer);
|
||||
|
|
|
|||
|
|
@ -192,6 +192,12 @@ namespace Nz
|
|||
return c.size();
|
||||
}
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const std::string_view& v)
|
||||
{
|
||||
hash->Append(reinterpret_cast<const UInt8*>(v.data()), v.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup core
|
||||
* \brief Combines two hash in one
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -32,7 +32,8 @@ namespace Nz
|
|||
explicit Bitset(const char* bits);
|
||||
Bitset(const char* bits, std::size_t bitCount);
|
||||
Bitset(const Bitset& bitset) = default;
|
||||
explicit Bitset(const String& bits);
|
||||
explicit Bitset(const std::string_view& bits);
|
||||
explicit Bitset(const std::string& bits);
|
||||
template<typename T> Bitset(T value);
|
||||
Bitset(Bitset&& bitset) noexcept = default;
|
||||
~Bitset() noexcept = default;
|
||||
|
|
@ -81,7 +82,7 @@ namespace Nz
|
|||
bool TestNone() const;
|
||||
|
||||
template<typename T> T To() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
void UnboundedReset(std::size_t bit);
|
||||
void UnboundedSet(std::size_t bit, bool val = true);
|
||||
|
|
@ -96,7 +97,7 @@ namespace Nz
|
|||
Bitset operator~() const;
|
||||
|
||||
Bitset& operator=(const Bitset& bitset) = default;
|
||||
Bitset& operator=(const String& bits);
|
||||
Bitset& operator=(const std::string_view& bits);
|
||||
template<typename T> Bitset& operator=(T value);
|
||||
Bitset& operator=(Bitset&& bitset) noexcept = default;
|
||||
|
||||
|
|
|
|||
|
|
@ -98,14 +98,24 @@ namespace Nz
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Bitset object from a Nz::String
|
||||
* \brief Constructs a Bitset object from a std::string_view
|
||||
*
|
||||
* \param bits String containing only '0' and '1'
|
||||
*/
|
||||
|
||||
template<typename Block, class Allocator>
|
||||
Bitset<Block, Allocator>::Bitset(const String& bits) :
|
||||
Bitset(bits.GetConstBuffer(), bits.GetSize())
|
||||
Bitset<Block, Allocator>::Bitset(const std::string_view& bits) :
|
||||
Bitset(bits.data(), bits.size())
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a Bitset object from a std::string
|
||||
*
|
||||
* \param bits String containing only '0' and '1'
|
||||
*/
|
||||
template<typename Block, class Allocator>
|
||||
Bitset<Block, Allocator>::Bitset(const std::string& bits) :
|
||||
Bitset(bits.data(), bits.size())
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -883,9 +893,9 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename Block, class Allocator>
|
||||
String Bitset<Block, Allocator>::ToString() const
|
||||
std::string Bitset<Block, Allocator>::ToString() const
|
||||
{
|
||||
String str(m_bitCount, '0');
|
||||
std::string str(m_bitCount, '0');
|
||||
|
||||
for (std::size_t i = 0; i < m_bitCount; ++i)
|
||||
{
|
||||
|
|
@ -991,14 +1001,14 @@ namespace Nz
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets this bitset from a Nz::String
|
||||
* \brief Sets this bitset from a std::string
|
||||
* \return A reference to this
|
||||
*
|
||||
* \param bits String containing only '0' and '1'
|
||||
*/
|
||||
|
||||
template<typename Block, class Allocator>
|
||||
Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator=(const String& bits)
|
||||
Bitset<Block, Allocator>& Bitset<Block, Allocator>::operator=(const std::string_view& bits)
|
||||
{
|
||||
Bitset bitset(bits);
|
||||
std::swap(*this, bitset);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
#define NAZARA_BYTEARRAY_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -88,8 +89,8 @@ namespace Nz
|
|||
inline void ShrinkToFit();
|
||||
inline void Swap(ByteArray& other);
|
||||
|
||||
String ToHex() const;
|
||||
inline String ToString() const;
|
||||
std::string ToHex() const;
|
||||
inline std::string ToString() const;
|
||||
|
||||
// STL interface
|
||||
inline iterator begin() noexcept;
|
||||
|
|
|
|||
|
|
@ -464,12 +464,12 @@ namespace Nz
|
|||
|
||||
/*!
|
||||
* \brief Gives a string representation
|
||||
* \return String where each byte is converted to char
|
||||
* \return std::string where each byte is converted to char
|
||||
*/
|
||||
|
||||
inline String ByteArray::ToString() const
|
||||
inline std::string ByteArray::ToString() const
|
||||
{
|
||||
return String(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
|
||||
return std::string(reinterpret_cast<const char*>(GetConstBuffer()), GetSize());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/ByteArray.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
#define NAZARA_COLOR_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -28,7 +28,7 @@ namespace Nz
|
|||
|
||||
inline bool IsOpaque() const;
|
||||
|
||||
inline String ToString() const;
|
||||
inline std::string ToString() const;
|
||||
|
||||
inline Color operator+(const Color& angles) const;
|
||||
inline Color operator*(const Color& angles) const;
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@
|
|||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -83,9 +84,9 @@ namespace Nz
|
|||
* \return String representation of the object "Color(r, g, b[, a])"
|
||||
*/
|
||||
|
||||
inline String Color::ToString() const
|
||||
inline std::string Color::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << "Color(" << static_cast<int>(r) << ", " << static_cast<int>(g) << ", " << static_cast<int>(b);
|
||||
|
||||
if (a != 255)
|
||||
|
|
@ -93,7 +94,7 @@ namespace Nz
|
|||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Config.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#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)
|
||||
|
|
@ -31,20 +31,20 @@ namespace Nz
|
|||
~Error() = delete;
|
||||
|
||||
static UInt32 GetFlags();
|
||||
static String GetLastError(const char** file = nullptr, unsigned int* line = nullptr, const char** function = nullptr);
|
||||
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 Trigger(ErrorType type, const String& error);
|
||||
static void Trigger(ErrorType type, const String& error, unsigned int line, const char* file, const char* function);
|
||||
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);
|
||||
|
||||
private:
|
||||
static const char* GetCurrentFileRelativeToEngine(const char* file);
|
||||
|
||||
static UInt32 s_flags;
|
||||
static String s_lastError;
|
||||
static std::string s_lastError;
|
||||
static const char* s_lastErrorFunction;
|
||||
static const char* s_lastErrorFile;
|
||||
static unsigned int s_lastErrorLine;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/Stream.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Nz
|
|||
class NAZARA_CORE_API FileLogger : public AbstractLogger
|
||||
{
|
||||
public:
|
||||
FileLogger(const String& logPath = "NazaraLog.log");
|
||||
FileLogger(std::filesystem::path logPath = "NazaraLog.log");
|
||||
FileLogger(const FileLogger&) = default;
|
||||
FileLogger(FileLogger&&) = default;
|
||||
~FileLogger();
|
||||
|
|
@ -29,8 +29,8 @@ namespace Nz
|
|||
bool IsStdReplicationEnabled() const override;
|
||||
bool IsTimeLoggingEnabled() const;
|
||||
|
||||
void Write(const String& string) override;
|
||||
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
|
||||
void Write(const std::string_view& string) override;
|
||||
void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
|
||||
|
||||
FileLogger& operator=(const FileLogger&) = default;
|
||||
FileLogger& operator=(FileLogger&&) = default;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -21,10 +21,10 @@ namespace Nz
|
|||
|
||||
static void Cpuid(UInt32 functionId, UInt32 subFunctionId, UInt32 result[4]);
|
||||
|
||||
static String GetProcessorBrandString();
|
||||
static std::string_view GetProcessorBrandString();
|
||||
static unsigned int GetProcessorCount();
|
||||
static ProcessorVendor GetProcessorVendor();
|
||||
static String GetProcessorVendorName();
|
||||
static std::string_view GetProcessorVendorName();
|
||||
static UInt64 GetTotalMemory();
|
||||
|
||||
static bool HasCapability(ProcessorCap capability);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
|
||||
#ifdef NAZARA_DEBUG
|
||||
#define NazaraDebug(txt) NazaraNotice(txt)
|
||||
|
|
@ -36,11 +36,11 @@ namespace Nz
|
|||
|
||||
static void SetLogger(AbstractLogger* logger);
|
||||
|
||||
static void Write(const String& string);
|
||||
static void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
|
||||
static void Write(const std::string_view& string);
|
||||
static void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
|
||||
|
||||
NazaraStaticSignal(OnLogWrite, const String& /*string*/);
|
||||
NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, const String& /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/);
|
||||
NazaraStaticSignal(OnLogWrite, const std::string_view& /*string*/);
|
||||
NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, const std::string_view& /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#include <Nazara/Core/HandledObject.hpp>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -36,7 +37,7 @@ namespace Nz
|
|||
|
||||
ObjectHandle& Swap(ObjectHandle& handle);
|
||||
|
||||
Nz::String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
explicit operator bool() const;
|
||||
operator T*() const;
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/ObjectHandle.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -135,18 +135,12 @@ namespace Nz
|
|||
* \return A string representation of the object "ObjectHandle(object representation) or Null"
|
||||
*/
|
||||
template<typename T>
|
||||
Nz::String ObjectHandle<T>::ToString() const
|
||||
std::string ObjectHandle<T>::ToString() const
|
||||
{
|
||||
Nz::StringStream ss;
|
||||
ss << "ObjectHandle(";
|
||||
if (IsValid())
|
||||
ss << GetObject()->ToString();
|
||||
else
|
||||
ss << "Null";
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
ss << ')';
|
||||
|
||||
return ss;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -219,7 +213,14 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const ObjectHandle<T>& handle)
|
||||
{
|
||||
out << handle.ToString();
|
||||
out << "ObjectHandle(";
|
||||
if (handle.IsValid())
|
||||
out << handle->ToString();
|
||||
else
|
||||
out << "Null";
|
||||
|
||||
out << ')';
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/RefCounted.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -25,18 +25,18 @@ namespace Nz
|
|||
|
||||
static void Clear();
|
||||
|
||||
static ObjectRef<Type> Get(const String& name);
|
||||
static bool Has(const String& name);
|
||||
static ObjectRef<Type> Get(const std::string& name);
|
||||
static bool Has(const std::string& name);
|
||||
|
||||
static void Register(const String& name, ObjectRef<Type> object);
|
||||
static ObjectRef<Type> Query(const String& name);
|
||||
static void Unregister(const String& name);
|
||||
static void Register(const std::string& name, ObjectRef<Type> object);
|
||||
static ObjectRef<Type> Query(const std::string& name);
|
||||
static void Unregister(const std::string& name);
|
||||
|
||||
private:
|
||||
static bool Initialize();
|
||||
static void Uninitialize();
|
||||
|
||||
using LibraryMap = std::unordered_map<String, ObjectRef<Type>>;
|
||||
using LibraryMap = std::unordered_map<std::string, ObjectRef<Type>>;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Nz
|
|||
* \remark Produces a NazaraError if object not found
|
||||
*/
|
||||
template<typename Type>
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Get(const String& name)
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Get(const std::string& name)
|
||||
{
|
||||
ObjectRef<Type> ref = Query(name);
|
||||
if (!ref)
|
||||
|
|
@ -46,7 +46,7 @@ namespace Nz
|
|||
* \return true if it the case
|
||||
*/
|
||||
template<typename Type>
|
||||
bool ObjectLibrary<Type>::Has(const String& name)
|
||||
bool ObjectLibrary<Type>::Has(const std::string& name)
|
||||
{
|
||||
return Type::s_library.find(name) != Type::s_library.end();
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ namespace Nz
|
|||
* \param object Object to stock
|
||||
*/
|
||||
template<typename Type>
|
||||
void ObjectLibrary<Type>::Register(const String& name, ObjectRef<Type> object)
|
||||
void ObjectLibrary<Type>::Register(const std::string& name, ObjectRef<Type> object)
|
||||
{
|
||||
Type::s_library.emplace(name, object);
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ namespace Nz
|
|||
* \param name Name of the object
|
||||
*/
|
||||
template<typename Type>
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Query(const String& name)
|
||||
ObjectRef<Type> ObjectLibrary<Type>::Query(const std::string& name)
|
||||
{
|
||||
auto it = Type::s_library.find(name);
|
||||
if (it != Type::s_library.end())
|
||||
|
|
@ -85,7 +85,7 @@ namespace Nz
|
|||
* \param name Name of the object
|
||||
*/
|
||||
template<typename Type>
|
||||
void ObjectLibrary<Type>::Unregister(const String& name)
|
||||
void ObjectLibrary<Type>::Unregister(const std::string& name)
|
||||
{
|
||||
Type::s_library.erase(name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Color.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -28,33 +28,33 @@ namespace Nz
|
|||
|
||||
void Clear();
|
||||
|
||||
inline void ForEach(const std::function<bool(const ParameterList& list, const String& name)>& callback);
|
||||
inline void ForEach(const std::function<void(const ParameterList& list, const String& name)>& callback) const;
|
||||
inline void ForEach(const std::function<bool(const ParameterList& list, const std::string& name)>& callback);
|
||||
inline void ForEach(const std::function<void(const ParameterList& list, const std::string& name)>& callback) const;
|
||||
|
||||
bool GetBooleanParameter(const String& name, bool* value) const;
|
||||
bool GetColorParameter(const String& name, Color* value) const;
|
||||
bool GetDoubleParameter(const String& name, double* value) const;
|
||||
bool GetIntegerParameter(const String& name, long long* value) const;
|
||||
bool GetParameterType(const String& name, ParameterType* type) const;
|
||||
bool GetPointerParameter(const String& name, void** value) const;
|
||||
bool GetStringParameter(const String& name, String* value) const;
|
||||
bool GetUserdataParameter(const String& name, void** value) const;
|
||||
bool GetBooleanParameter(const std::string& name, bool* value) const;
|
||||
bool GetColorParameter(const std::string& name, Color* value) const;
|
||||
bool GetDoubleParameter(const std::string& name, double* value) const;
|
||||
bool GetIntegerParameter(const std::string& name, long long* value) const;
|
||||
bool GetParameterType(const std::string& name, ParameterType* type) const;
|
||||
bool GetPointerParameter(const std::string& name, void** value) const;
|
||||
bool GetStringParameter(const std::string& name, std::string* value) const;
|
||||
bool GetUserdataParameter(const std::string& name, void** value) const;
|
||||
|
||||
bool HasParameter(const String& name) const;
|
||||
bool HasParameter(const std::string& name) const;
|
||||
|
||||
void RemoveParameter(const String& name);
|
||||
void RemoveParameter(const std::string& name);
|
||||
|
||||
void SetParameter(const String& name);
|
||||
void SetParameter(const String& name, const Color& value);
|
||||
void SetParameter(const String& name, const String& value);
|
||||
void SetParameter(const String& name, const char* value);
|
||||
void SetParameter(const String& name, bool value);
|
||||
void SetParameter(const String& name, double value);
|
||||
void SetParameter(const String& name, long long value);
|
||||
void SetParameter(const String& name, void* value);
|
||||
void SetParameter(const String& name, void* value, Destructor destructor);
|
||||
void SetParameter(const std::string& name);
|
||||
void SetParameter(const std::string& name, const Color& value);
|
||||
void SetParameter(const std::string& name, const std::string& value);
|
||||
void SetParameter(const std::string& name, const char* value);
|
||||
void SetParameter(const std::string& name, bool value);
|
||||
void SetParameter(const std::string& name, double value);
|
||||
void SetParameter(const std::string& name, long long value);
|
||||
void SetParameter(const std::string& name, void* value);
|
||||
void SetParameter(const std::string& name, void* value, Destructor destructor);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
ParameterList& operator=(const ParameterList& list);
|
||||
ParameterList& operator=(ParameterList&&) = default;
|
||||
|
|
@ -90,17 +90,17 @@ namespace Nz
|
|||
long long intVal;
|
||||
void* ptrVal;
|
||||
Color colorVal;
|
||||
String stringVal;
|
||||
std::string stringVal;
|
||||
UserdataValue* userdataVal;
|
||||
};
|
||||
|
||||
Value value;
|
||||
};
|
||||
|
||||
Parameter& CreateValue(const String& name);
|
||||
Parameter& CreateValue(const std::string& name);
|
||||
void DestroyValue(Parameter& parameter);
|
||||
|
||||
using ParameterMap = std::unordered_map<String, Parameter>;
|
||||
using ParameterMap = std::unordered_map<std::string, Parameter>;
|
||||
ParameterMap m_parameters;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Nz
|
|||
*
|
||||
* \remark Changing the ParameterList while iterating on it may cause bugs, but querying data is safe.
|
||||
*/
|
||||
inline void ParameterList::ForEach(const std::function<bool(const ParameterList& list, const String& name)>& callback)
|
||||
inline void ParameterList::ForEach(const std::function<bool(const ParameterList& list, const std::string& name)>& callback)
|
||||
{
|
||||
for (auto it = m_parameters.begin(); it != m_parameters.end();)
|
||||
{
|
||||
|
|
@ -31,7 +31,7 @@ namespace Nz
|
|||
*
|
||||
* \remark Changing the ParameterList while iterating on it may cause bugs, but querying data is safe.
|
||||
*/
|
||||
inline void ParameterList::ForEach(const std::function<void(const ParameterList& list, const String& name)>& callback) const
|
||||
inline void ParameterList::ForEach(const std::function<void(const ParameterList& list, const std::string& name)>& callback) const
|
||||
{
|
||||
for (auto& pair : m_parameters)
|
||||
callback(*this, pair.first);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <Nazara/Core/ObjectRef.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Nz
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@
|
|||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/Resource.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ namespace Nz
|
|||
|
||||
bool IsStdReplicationEnabled() const override;
|
||||
|
||||
void Write(const String& string) override;
|
||||
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
|
||||
void Write(const std::string_view& error) override;
|
||||
void WriteError(ErrorType type, const std::string_view& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;
|
||||
|
||||
StdLogger& operator=(const StdLogger&) = default;
|
||||
StdLogger& operator=(StdLogger&&) noexcept = default;
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/Enums.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -49,7 +49,7 @@ namespace Nz
|
|||
virtual bool SetCursorPos(UInt64 offset) = 0;
|
||||
|
||||
bool Write(const ByteArray& byteArray);
|
||||
bool Write(const String& string);
|
||||
bool Write(const std::string_view& string);
|
||||
inline std::size_t Write(const void* buffer, std::size_t size);
|
||||
|
||||
Stream& operator=(const Stream&) = default;
|
||||
|
|
|
|||
|
|
@ -1,348 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_STRING_HPP
|
||||
#define NAZARA_STRING_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Endianness.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <cstdarg>
|
||||
#include <iosfwd>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct SerializationContext;
|
||||
|
||||
class NAZARA_CORE_API String
|
||||
{
|
||||
public:
|
||||
enum Flags
|
||||
{
|
||||
None = 0x00, // Default mode
|
||||
CaseInsensitive = 0x01, // Case insensitive
|
||||
HandleUtf8 = 0x02, // Considers bytes as a list of UTF-8 characters
|
||||
TrimOnlyLeft = 0x04, // Trim(med), only cut the left part of the string
|
||||
TrimOnlyRight = 0x08 // Trim(med), only cut the right part of the string
|
||||
};
|
||||
|
||||
String();
|
||||
explicit String(char character);
|
||||
String(std::size_t rep, char character);
|
||||
String(std::size_t rep, const char* string);
|
||||
String(std::size_t rep, const char* string, std::size_t length);
|
||||
String(std::size_t rep, const String& string);
|
||||
String(const char* string);
|
||||
String(const char* string, std::size_t length);
|
||||
String(const std::string& string);
|
||||
String(const String& string) = default;
|
||||
inline String(String&& string) noexcept;
|
||||
~String() = default;
|
||||
|
||||
String& Append(char character);
|
||||
String& Append(const char* string);
|
||||
String& Append(const char* string, std::size_t length);
|
||||
String& Append(const String& string);
|
||||
|
||||
void Clear(bool keepBuffer = false);
|
||||
|
||||
bool Contains(char character, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
bool Contains(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
bool Contains(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
|
||||
unsigned int Count(char character, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Count(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Count(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int CountAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int CountAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
|
||||
bool EndsWith(char character, UInt32 flags = None) const;
|
||||
bool EndsWith(const char* string, UInt32 flags = None) const;
|
||||
bool EndsWith(const char* string, std::size_t length, UInt32 flags = None) const;
|
||||
bool EndsWith(const String& string, UInt32 flags = None) const;
|
||||
|
||||
std::size_t Find(char character, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t Find(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t Find(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t FindAny(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t FindAny(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t FindLast(char character, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLast(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLast(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLastAny(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLastAny(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLastWord(const char* string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindLastWord(const String& string, std::intmax_t start = -1, UInt32 flags = None) const;
|
||||
std::size_t FindWord(const char* string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
std::size_t FindWord(const String& string, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
|
||||
char* GetBuffer();
|
||||
std::size_t GetCapacity() const;
|
||||
std::size_t GetCharacterPosition(std::size_t characterIndex) const;
|
||||
const char* GetConstBuffer() const;
|
||||
std::size_t GetLength() const;
|
||||
std::size_t GetSize() const;
|
||||
std::string GetUtf8String() const;
|
||||
std::u16string GetUtf16String() const;
|
||||
std::u32string GetUtf32String() const;
|
||||
std::wstring GetWideString() const;
|
||||
String GetWord(unsigned int index, UInt32 flags = None) const;
|
||||
std::size_t GetWordPosition(unsigned int index, UInt32 flags = None) const;
|
||||
|
||||
String& Insert(std::intmax_t pos, char character);
|
||||
String& Insert(std::intmax_t pos, const char* string);
|
||||
String& Insert(std::intmax_t pos, const char* string, std::size_t length);
|
||||
String& Insert(std::intmax_t pos, const String& string);
|
||||
|
||||
bool IsEmpty() const;
|
||||
bool IsNull() const;
|
||||
bool IsNumber(UInt8 radix = 10, UInt32 flags = CaseInsensitive) const;
|
||||
|
||||
bool Match(const char* pattern) const;
|
||||
bool Match(const String& pattern) const;
|
||||
|
||||
String& Prepend(char character);
|
||||
String& Prepend(const char* string);
|
||||
String& Prepend(const char* string, std::size_t length);
|
||||
String& Prepend(const String& string);
|
||||
|
||||
unsigned int Replace(char oldCharacter, char newCharacter, std::intmax_t start = 0, UInt32 flags = None);
|
||||
unsigned int Replace(const char* oldString, const char* replaceString, std::intmax_t start = 0, UInt32 flags = None);
|
||||
unsigned int Replace(const char* oldString, std::size_t oldLength, const char* replaceString, std::size_t replaceLength, std::intmax_t start = 0, UInt32 flags = None);
|
||||
unsigned int Replace(const String& oldString, const String& replaceString, std::intmax_t start = 0, UInt32 flags = None);
|
||||
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, std::intmax_t start = 0, UInt32 flags = None);
|
||||
//unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, std::intmax_t start = 0, UInt32 flags = None);
|
||||
//unsigned int ReplaceAny(const String& oldCharacters, const String& replaceString, std::intmax_t start = 0, UInt32 flags = None);
|
||||
|
||||
void Reserve(std::size_t bufferSize);
|
||||
|
||||
String& Resize(std::intmax_t size, UInt32 flags = None);
|
||||
String Resized(std::intmax_t size, UInt32 flags = None) const;
|
||||
|
||||
String& Reverse();
|
||||
String Reversed() const;
|
||||
|
||||
String& Set(char character);
|
||||
String& Set(std::size_t rep, char character);
|
||||
String& Set(std::size_t rep, const char* string);
|
||||
String& Set(std::size_t rep, const char* string, std::size_t length);
|
||||
String& Set(std::size_t rep, const String& string);
|
||||
String& Set(const char* string);
|
||||
String& Set(const char* string, std::size_t length);
|
||||
String& Set(const std::string& string);
|
||||
String& Set(const String& string);
|
||||
String& Set(String&& string) noexcept;
|
||||
|
||||
String Simplified(UInt32 flags = None) const;
|
||||
String& Simplify(UInt32 flags = None);
|
||||
|
||||
unsigned int Split(std::vector<String>& result, char separation = ' ', std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<String>& result, const char* separation, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<String>& result, const char* separation, std::size_t length, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int Split(std::vector<String>& result, const String& separation, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int SplitAny(std::vector<String>& result, const char* separations, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
unsigned int SplitAny(std::vector<String>& result, const String& separations, std::intmax_t start = 0, UInt32 flags = None) const;
|
||||
|
||||
bool StartsWith(char character, UInt32 flags = None) const;
|
||||
bool StartsWith(const char* string, UInt32 flags = None) const;
|
||||
bool StartsWith(const String& string, UInt32 flags = None) const;
|
||||
|
||||
String SubString(std::intmax_t startPos, std::intmax_t endPos = -1) const;
|
||||
String SubStringFrom(char character, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringFrom(const char* string, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringFrom(const char* string, std::size_t length, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringFrom(const String& string, std::intmax_t startPos = 0, bool fromLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringTo(char character, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringTo(const char* string, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringTo(const char* string, std::size_t length, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
|
||||
String SubStringTo(const String& string, std::intmax_t startPos = 0, bool toLast = false, bool include = false, UInt32 flags = None) const;
|
||||
|
||||
void Swap(String& str);
|
||||
|
||||
bool ToBool(bool* value, UInt32 flags = None) const;
|
||||
bool ToDouble(double* value) const;
|
||||
bool ToInteger(long long* value, UInt8 radix = 10) const;
|
||||
String ToLower(UInt32 flags = None) const;
|
||||
std::string ToStdString() const;
|
||||
String ToUpper(UInt32 flags = None) const;
|
||||
|
||||
String& Trim(UInt32 flags = None);
|
||||
String& Trim(char character, UInt32 flags = None);
|
||||
String Trimmed(UInt32 flags = None) const;
|
||||
String Trimmed(char character, UInt32 flags = None) const;
|
||||
|
||||
// Méthodes STD
|
||||
char* begin();
|
||||
const char* begin() const;
|
||||
char* end();
|
||||
const char* end() const;
|
||||
void push_front(char c);
|
||||
void push_back(char c);
|
||||
//char* rbegin();
|
||||
//const char* rbegin() const;
|
||||
//char* rend();
|
||||
//const char* rend() const;
|
||||
|
||||
using const_reference = const char&;
|
||||
using iterator = char*;
|
||||
//using reverse_iterator = char*;
|
||||
using value_type = char;
|
||||
// Méthodes STD
|
||||
|
||||
char& operator[](std::size_t pos);
|
||||
char operator[](std::size_t pos) const;
|
||||
|
||||
String& operator=(char character);
|
||||
String& operator=(const char* string);
|
||||
String& operator=(const std::string& string);
|
||||
String& operator=(const String& string);
|
||||
String& operator=(String&& string) noexcept;
|
||||
|
||||
String operator+(char character) const;
|
||||
String operator+(const char* string) const;
|
||||
String operator+(const std::string& string) const;
|
||||
String operator+(const String& string) const;
|
||||
|
||||
String& operator+=(char character);
|
||||
String& operator+=(const char* string);
|
||||
String& operator+=(const std::string& string);
|
||||
String& operator+=(const String& string);
|
||||
|
||||
bool operator==(char character) const;
|
||||
bool operator==(const char* string) const;
|
||||
bool operator==(const std::string& string) const;
|
||||
|
||||
bool operator!=(char character) const;
|
||||
bool operator!=(const char* string) const;
|
||||
bool operator!=(const std::string& string) const;
|
||||
|
||||
bool operator<(char character) const;
|
||||
bool operator<(const char* string) const;
|
||||
bool operator<(const std::string& string) const;
|
||||
|
||||
bool operator<=(char character) const;
|
||||
bool operator<=(const char* string) const;
|
||||
bool operator<=(const std::string& string) const;
|
||||
|
||||
bool operator>(char character) const;
|
||||
bool operator>(const char* string) const;
|
||||
bool operator>(const std::string& string) const;
|
||||
|
||||
bool operator>=(char character) const;
|
||||
bool operator>=(const char* string) const;
|
||||
bool operator>=(const std::string& string) const;
|
||||
|
||||
static String Boolean(bool boolean);
|
||||
static int Compare(const String& first, const String& second);
|
||||
static inline String Format(const char* format, ...);
|
||||
static String FormatVA(const char* format, va_list arg);
|
||||
static String Number(float number);
|
||||
static String Number(double number);
|
||||
static String Number(long double number);
|
||||
static String Number(signed char number, UInt8 radix = 10);
|
||||
static String Number(unsigned char number, UInt8 radix = 10);
|
||||
static String Number(short number, UInt8 radix = 10);
|
||||
static String Number(unsigned short number, UInt8 radix = 10);
|
||||
static String Number(int number, UInt8 radix = 10);
|
||||
static String Number(unsigned int number, UInt8 radix = 10);
|
||||
static String Number(long number, UInt8 radix = 10);
|
||||
static String Number(unsigned long number, UInt8 radix = 10);
|
||||
static String Number(long long number, UInt8 radix = 10);
|
||||
static String Number(unsigned long long number, UInt8 radix = 10);
|
||||
static String Pointer(const void* ptr);
|
||||
static String Unicode(char32_t character);
|
||||
static String Unicode(const char* u8String);
|
||||
static String Unicode(const char16_t* u16String);
|
||||
static String Unicode(const char32_t* u32String);
|
||||
static String Unicode(const wchar_t* wString);
|
||||
|
||||
NAZARA_CORE_API friend std::istream& operator>>(std::istream& in, String& string);
|
||||
NAZARA_CORE_API friend std::ostream& operator<<(std::ostream& out, const String& string);
|
||||
|
||||
NAZARA_CORE_API friend String operator+(char character, const String& string);
|
||||
NAZARA_CORE_API friend String operator+(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend String operator+(const std::string& string, const String& nstring);
|
||||
|
||||
NAZARA_CORE_API friend bool operator==(const String& first, const String& second);
|
||||
NAZARA_CORE_API friend bool operator!=(const String& first, const String& second);
|
||||
NAZARA_CORE_API friend bool operator<(const String& first, const String& second);
|
||||
NAZARA_CORE_API friend bool operator<=(const String& first, const String& second);
|
||||
NAZARA_CORE_API friend bool operator>(const String& first, const String& second);
|
||||
NAZARA_CORE_API friend bool operator>=(const String& first, const String& second);
|
||||
|
||||
NAZARA_CORE_API friend bool operator==(char character, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator==(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator==(const std::string& string, const String& nstring);
|
||||
|
||||
NAZARA_CORE_API friend bool operator!=(char character, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator!=(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator!=(const std::string& string, const String& nstring);
|
||||
|
||||
NAZARA_CORE_API friend bool operator<(char character, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator<(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator<(const std::string& string, const String& nstring);
|
||||
|
||||
NAZARA_CORE_API friend bool operator<=(char character, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator<=(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator<=(const std::string& string, const String& nstring);
|
||||
|
||||
NAZARA_CORE_API friend bool operator>(char character, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator>(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator>(const std::string& string, const String& nstring);
|
||||
|
||||
NAZARA_CORE_API friend bool operator>=(char character, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator>=(const char* string, const String& nstring);
|
||||
NAZARA_CORE_API friend bool operator>=(const std::string& string, const String& nstring);
|
||||
|
||||
static const std::size_t npos;
|
||||
|
||||
private:
|
||||
struct SharedString;
|
||||
|
||||
String(std::shared_ptr<SharedString>&& sharedString);
|
||||
|
||||
void EnsureOwnership(bool discardContent = false);
|
||||
inline void ReleaseString();
|
||||
|
||||
static const std::shared_ptr<SharedString>& GetEmptyString();
|
||||
|
||||
std::shared_ptr<SharedString> m_sharedString;
|
||||
|
||||
struct SharedString
|
||||
{
|
||||
inline SharedString();
|
||||
inline SharedString(std::size_t strSize);
|
||||
inline SharedString(std::size_t strSize, std::size_t strCapacity);
|
||||
|
||||
std::size_t capacity;
|
||||
std::size_t size;
|
||||
std::unique_ptr<char[]> string;
|
||||
};
|
||||
};
|
||||
|
||||
class AbstractHash;
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const String& string);
|
||||
NAZARA_CORE_API bool Serialize(SerializationContext& context, const String& string, TypeTag<String>);
|
||||
NAZARA_CORE_API bool Unserialize(SerializationContext& context, String* string, TypeTag<String>);
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
NAZARA_CORE_API istream& getline(istream& is, Nz::String& str);
|
||||
NAZARA_CORE_API istream& getline(istream& is, Nz::String& str, char delim);
|
||||
NAZARA_CORE_API void swap(Nz::String& lhs, Nz::String& rhs);
|
||||
|
||||
template<>
|
||||
struct hash<Nz::String>;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/String.inl>
|
||||
|
||||
#endif // NAZARA_STRING_HPP
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/AbstractHash.hpp>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
inline Nz::String::String(String&& string) noexcept :
|
||||
m_sharedString(std::move(string.m_sharedString))
|
||||
{
|
||||
string.m_sharedString = GetEmptyString();
|
||||
}
|
||||
|
||||
inline String::String(std::shared_ptr<SharedString>&& sharedString) :
|
||||
m_sharedString(std::move(sharedString))
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Build a string using a format and returns it
|
||||
* \return Formatted string
|
||||
*
|
||||
* \param format String format
|
||||
* \param ... Format arguments
|
||||
*/
|
||||
String String::Format(const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
String result = FormatVA(format, args);
|
||||
va_end(args);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Releases the content to the string
|
||||
*/
|
||||
|
||||
inline void String::ReleaseString()
|
||||
{
|
||||
m_sharedString = GetEmptyString();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SharedString object by default
|
||||
*/
|
||||
|
||||
inline String::SharedString::SharedString() : // Special case: empty string
|
||||
capacity(0),
|
||||
size(0)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SharedString object with a size
|
||||
*
|
||||
* \param strSize Number of characters in the string
|
||||
*/
|
||||
|
||||
inline String::SharedString::SharedString(std::size_t strSize) :
|
||||
capacity(strSize),
|
||||
size(strSize),
|
||||
string(new char[strSize + 1])
|
||||
{
|
||||
string[strSize] = '\0';
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a SharedString object with a size and a capacity
|
||||
*
|
||||
* \param strSize Number of characters in the string
|
||||
* \param strCapacity Capacity in characters in the string
|
||||
*/
|
||||
|
||||
inline String::SharedString::SharedString(std::size_t strSize, std::size_t strCapacity) :
|
||||
capacity(strCapacity),
|
||||
size(strSize),
|
||||
string(new char[strCapacity + 1])
|
||||
{
|
||||
string[strSize] = '\0';
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Appends the string to the hash
|
||||
* \return true if hash is successful
|
||||
*
|
||||
* \param hash Hash to append data of the file
|
||||
* \param string String to hash
|
||||
*/
|
||||
|
||||
inline bool HashAppend(AbstractHash* hash, const String& string)
|
||||
{
|
||||
hash->Append(reinterpret_cast<const UInt8*>(string.GetConstBuffer()), string.GetSize());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
template<>
|
||||
struct hash<Nz::String>
|
||||
{
|
||||
/*!
|
||||
* \brief Specialisation of std to hash
|
||||
* \return Result of the hash
|
||||
*
|
||||
* \param str String to hash
|
||||
*/
|
||||
size_t operator()(const Nz::String& str) const
|
||||
{
|
||||
// Algorithme DJB2
|
||||
// http://www.cse.yorku.ca/~oz/hash.html
|
||||
|
||||
size_t h = 5381;
|
||||
if (!str.IsEmpty())
|
||||
{
|
||||
const char* ptr = str.GetConstBuffer();
|
||||
|
||||
do
|
||||
h = ((h << 5) + h) + static_cast<size_t>(*ptr);
|
||||
while (*++ptr);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Unicode.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp> //< FIXME
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -17,49 +18,70 @@ namespace Nz
|
|||
struct UnicodeAware {};
|
||||
|
||||
// std::string is assumed to contains UTF-8
|
||||
NAZARA_CORE_API std::string FromUtf16String(const char16_t* u16str);
|
||||
NAZARA_CORE_API std::string FromUtf16String(const std::u16string_view& u16str);
|
||||
|
||||
NAZARA_CORE_API std::string FromUtf32String(const char32_t* u32str);
|
||||
NAZARA_CORE_API std::string FromUtf32String(const std::u32string_view& u32str);
|
||||
|
||||
NAZARA_CORE_API std::string FromWideString(const wchar_t* wstr);
|
||||
NAZARA_CORE_API std::string FromWideString(const std::wstring_view& str);
|
||||
|
||||
inline bool IsNumber(const char* str);
|
||||
inline bool IsNumber(const std::string_view& str);
|
||||
NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex);
|
||||
NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex, UnicodeAware);
|
||||
|
||||
inline bool IsNumber(std::string_view str);
|
||||
|
||||
inline bool MatchPattern(const std::string_view& str, const char* pattern);
|
||||
NAZARA_CORE_API bool MatchPattern(const std::string_view& str, const std::string_view& pattern);
|
||||
|
||||
template<typename... Args> bool StartsWith(const std::string_view& str, const char* s, Args&&... args);
|
||||
NAZARA_CORE_API std::string PointerToString(const void* ptr);
|
||||
|
||||
inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to);
|
||||
|
||||
inline bool StartsWith(const std::string_view& str, const std::string_view& s);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& str, const std::string_view& s, CaseIndependent, UnicodeAware);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
|
||||
|
||||
template<typename F> bool SplitString(const std::string_view& str, const std::string_view& token, F&& func);
|
||||
template<typename F> bool SplitStringAny(const std::string_view& str, const std::string_view& token, F&& func);
|
||||
|
||||
inline std::string ToLower(const char* str);
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str);
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs);
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
|
||||
NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
|
||||
NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
|
||||
|
||||
inline std::string ToLower(const char* str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str);
|
||||
NAZARA_CORE_API std::string ToLower(const std::string_view& str, UnicodeAware);
|
||||
|
||||
inline std::string ToUpper(const char* str);
|
||||
NAZARA_CORE_API std::string ToUpper(const std::string_view& str);
|
||||
|
||||
inline std::string ToUpper(const char* str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string ToUpper(const std::string_view& str, UnicodeAware);
|
||||
|
||||
inline std::u16string ToUtf16String(const char* str);
|
||||
NAZARA_CORE_API std::u16string ToUtf16String(const std::string_view& str);
|
||||
|
||||
inline std::u32string ToUtf32String(const char* str);
|
||||
NAZARA_CORE_API std::u32string ToUtf32String(const std::string_view& str);
|
||||
|
||||
inline std::wstring ToWideString(const char* str);
|
||||
NAZARA_CORE_API std::wstring ToWideString(const std::string_view& str);
|
||||
|
||||
inline std::string_view Trim(std::string_view str);
|
||||
inline std::string_view Trim(std::string_view str, char c);
|
||||
inline std::string_view Trim(std::string_view str, char c, CaseIndependent);
|
||||
inline std::string_view Trim(std::string_view str, Unicode::Category category);
|
||||
inline std::string_view Trim(std::string_view str, UnicodeAware);
|
||||
inline std::string_view Trim(std::string_view str, char32_t c, UnicodeAware);
|
||||
inline std::string_view Trim(std::string_view str, char32_t c, CaseIndependent, UnicodeAware);
|
||||
inline std::string_view Trim(std::string_view str, Unicode::Category category, UnicodeAware);
|
||||
|
||||
NAZARA_CORE_API std::string_view TrimLeft(std::string_view str);
|
||||
inline std::string_view TrimLeft(std::string_view str, char c);
|
||||
inline std::string_view TrimLeft(std::string_view str, char c, CaseIndependent);
|
||||
inline std::string_view TrimLeft(std::string_view str, Unicode::Category category);
|
||||
NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, char32_t c, UnicodeAware);
|
||||
NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, char32_t c, CaseIndependent, UnicodeAware);
|
||||
NAZARA_CORE_API std::string_view TrimLeft(std::string_view str, Unicode::Category category, UnicodeAware);
|
||||
|
||||
NAZARA_CORE_API std::string_view TrimRight(std::string_view str);
|
||||
inline std::string_view TrimRight(std::string_view str, char c);
|
||||
inline std::string_view TrimRight(std::string_view str, char c, CaseIndependent);
|
||||
inline std::string_view TrimRight(std::string_view str, Unicode::Category category);
|
||||
NAZARA_CORE_API std::string_view TrimRight(std::string_view str, UnicodeAware);
|
||||
NAZARA_CORE_API std::string_view TrimRight(std::string_view str, char32_t c, UnicodeAware);
|
||||
NAZARA_CORE_API std::string_view TrimRight(std::string_view str, char32_t c, CaseIndependent, UnicodeAware);
|
||||
NAZARA_CORE_API std::string_view TrimRight(std::string_view str, Unicode::Category category, UnicodeAware);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/StringExt.inl>
|
||||
|
|
|
|||
|
|
@ -10,32 +10,33 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
bool IsNumber(const char* str)
|
||||
inline bool IsNumber(std::string_view str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return IsNumber(std::string_view(str, size));
|
||||
}
|
||||
|
||||
bool IsNumber(const std::string_view& str)
|
||||
{
|
||||
return !str.empty() && std::find_if(str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c); }) == str.end();
|
||||
}
|
||||
|
||||
bool MatchPattern(const std::string_view& str, const char* pattern)
|
||||
{
|
||||
if (!pattern)
|
||||
if (str.empty())
|
||||
return false;
|
||||
|
||||
return MatchPattern(str, std::string_view(pattern, std::strlen(pattern)));
|
||||
if (str.front() == '-')
|
||||
str.remove_prefix(1);
|
||||
|
||||
return std::find_if(str.begin(), str.end(), [](unsigned char c) { return !std::isdigit(c); }) == str.end();
|
||||
}
|
||||
|
||||
template<typename... Args> bool StartsWith(const std::string_view& str, const char* s, Args&&... args)
|
||||
inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to)
|
||||
{
|
||||
std::size_t size = std::strlen(s);
|
||||
return StartsWith(str, std::string_view(s, size), std::forward<Args>(args)...);
|
||||
if (str.empty())
|
||||
return str;
|
||||
|
||||
std::size_t startPos = 0;
|
||||
while ((startPos = str.find(from, startPos)) != std::string::npos)
|
||||
{
|
||||
str.replace(startPos, from.length(), to);
|
||||
startPos += to.length();
|
||||
}
|
||||
|
||||
bool StartsWith(const std::string_view& str, const std::string_view& s)
|
||||
return str;
|
||||
}
|
||||
|
||||
inline bool StartsWith(const std::string_view& str, const std::string_view& s)
|
||||
{
|
||||
//FIXME: Replace with proper C++20 value once it's available
|
||||
#if __cplusplus > 201703L
|
||||
|
|
@ -83,48 +84,116 @@ namespace Nz
|
|||
return func(str.substr(previousPos));
|
||||
}
|
||||
|
||||
inline std::string ToLower(const char* str)
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToLower(std::string_view(str, size));
|
||||
return lhs == rhs;
|
||||
}
|
||||
|
||||
inline std::string ToLower(const char* str, UnicodeAware)
|
||||
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToLower(std::string_view(str, size), UnicodeAware{});
|
||||
if (lhs.size() != rhs.size())
|
||||
return false;
|
||||
|
||||
for (std::size_t i = 0; i < lhs.size(); ++i)
|
||||
{
|
||||
if (std::tolower(lhs[i]) != std::tolower(rhs[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
inline std::string ToUpper(const char* str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUpper(std::string_view(str, size));
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::string ToUpper(const char* str, UnicodeAware)
|
||||
inline std::string_view Trim(std::string_view str)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUpper(std::string_view(str, size), UnicodeAware{});
|
||||
return TrimRight(TrimLeft(str));
|
||||
}
|
||||
|
||||
inline std::u16string ToUtf16String(const char* str)
|
||||
inline std::string_view Trim(std::string_view str, char c)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUtf16String(std::string_view(str, size));
|
||||
return TrimRight(TrimLeft(str, c), c);
|
||||
}
|
||||
|
||||
inline std::u32string ToUtf32String(const char* str)
|
||||
inline std::string_view Trim(std::string_view str, char c, CaseIndependent)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToUtf32String(std::string_view(str, size));
|
||||
return TrimRight(TrimLeft(str, c, CaseIndependent{}), c, CaseIndependent{});
|
||||
}
|
||||
|
||||
inline std::wstring ToWideString(const char* str)
|
||||
inline std::string_view Trim(std::string_view str, Unicode::Category category)
|
||||
{
|
||||
std::size_t size = std::strlen(str);
|
||||
return ToWideString(std::string_view(str, size));
|
||||
return TrimRight(TrimLeft(str, category), category);
|
||||
}
|
||||
|
||||
inline std::string_view Trim(std::string_view str, UnicodeAware)
|
||||
{
|
||||
return TrimRight(TrimLeft(str, UnicodeAware{}), UnicodeAware{});
|
||||
}
|
||||
|
||||
inline std::string_view Trim(std::string_view str, char32_t c, UnicodeAware)
|
||||
{
|
||||
return TrimRight(TrimLeft(str, c, UnicodeAware{}), c, UnicodeAware{});
|
||||
}
|
||||
|
||||
inline std::string_view Trim(std::string_view str, char32_t c, CaseIndependent, UnicodeAware)
|
||||
{
|
||||
return TrimRight(TrimLeft(str, c, CaseIndependent{}, UnicodeAware{}), c, CaseIndependent{}, UnicodeAware{});
|
||||
}
|
||||
|
||||
inline std::string_view Trim(std::string_view str, Unicode::Category category, UnicodeAware)
|
||||
{
|
||||
return TrimRight(TrimLeft(str, category, UnicodeAware{}), category, UnicodeAware{});
|
||||
}
|
||||
|
||||
inline std::string_view TrimLeft(std::string_view str, char c)
|
||||
{
|
||||
while (!str.empty() && str.front() == c)
|
||||
str.remove_prefix(1);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
inline std::string_view TrimLeft(std::string_view str, char c, CaseIndependent)
|
||||
{
|
||||
c = char(std::tolower(c));
|
||||
|
||||
while (!str.empty() && std::tolower(str.front()) == c)
|
||||
str.remove_prefix(1);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
inline std::string_view TrimLeft(std::string_view str, Unicode::Category category)
|
||||
{
|
||||
while (!str.empty() && (Unicode::GetCategory(str.front()) & category) == category)
|
||||
str.remove_prefix(1);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
inline std::string_view TrimRight(std::string_view str, char c)
|
||||
{
|
||||
while (!str.empty() && str.back() == c)
|
||||
str.remove_suffix(1);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
inline std::string_view TrimRight(std::string_view str, char c, CaseIndependent)
|
||||
{
|
||||
c = char(std::tolower(c));
|
||||
|
||||
while (!str.empty() && std::tolower(str.back()) == c)
|
||||
str.remove_suffix(1);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
inline std::string_view TrimRight(std::string_view str, Unicode::Category category)
|
||||
{
|
||||
while (!str.empty() && (Unicode::GetCategory(str.back()) & category) == category)
|
||||
str.remove_suffix(1);
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
// Copyright (C) 2020 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Core module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_STRINGSTREAM_HPP
|
||||
#define NAZARA_STRINGSTREAM_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
class NAZARA_CORE_API StringStream
|
||||
{
|
||||
public:
|
||||
StringStream() = default;
|
||||
StringStream(String str);
|
||||
StringStream(const StringStream&) = default;
|
||||
StringStream(StringStream&&) noexcept = default;
|
||||
|
||||
void Clear();
|
||||
|
||||
std::size_t GetBufferSize() const;
|
||||
|
||||
String ToString() const;
|
||||
|
||||
StringStream& operator=(const StringStream&) = default;
|
||||
StringStream& operator=(StringStream&&) noexcept = default;
|
||||
|
||||
StringStream& operator<<(bool boolean);
|
||||
StringStream& operator<<(short number);
|
||||
StringStream& operator<<(unsigned short number);
|
||||
StringStream& operator<<(int number);
|
||||
StringStream& operator<<(unsigned int number);
|
||||
StringStream& operator<<(long number);
|
||||
StringStream& operator<<(unsigned long number);
|
||||
StringStream& operator<<(long long number);
|
||||
StringStream& operator<<(unsigned long long number);
|
||||
StringStream& operator<<(float number);
|
||||
StringStream& operator<<(double number);
|
||||
StringStream& operator<<(long double number);
|
||||
StringStream& operator<<(char character);
|
||||
StringStream& operator<<(unsigned char character);
|
||||
StringStream& operator<<(const char* string);
|
||||
StringStream& operator<<(const std::string& string);
|
||||
StringStream& operator<<(const String& string);
|
||||
StringStream& operator<<(const void* ptr);
|
||||
|
||||
operator String() const;
|
||||
|
||||
private:
|
||||
String m_result;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // NAZARA_STRINGSTREAM_HPP
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// This file was automatically generated
|
||||
|
||||
/*
|
||||
Nazara Engine - Graphics module
|
||||
|
||||
Copyright (C) 2020 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_GLOBAL_GRAPHICS_HPP
|
||||
#define NAZARA_GLOBAL_GRAPHICS_HPP
|
||||
|
||||
#include <Nazara/Graphics/Config.hpp>
|
||||
#include <Nazara/Graphics/Enums.hpp>
|
||||
#include <Nazara/Graphics/Graphics.hpp>
|
||||
|
||||
#endif // NAZARA_GLOBAL_GRAPHICS_HPP
|
||||
|
|
@ -9,9 +9,9 @@
|
|||
#define NAZARA_ALGORITHM_MATH_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653589793238462643
|
||||
|
|
@ -59,9 +59,9 @@ namespace Nz
|
|||
template<typename T> constexpr T NormalizeAngle(T angle);
|
||||
template<typename T> constexpr bool NumberEquals(T a, T b);
|
||||
template<typename T> constexpr bool NumberEquals(T a, T b, T maxDifference);
|
||||
String NumberToString(long long number, UInt8 radix = 10);
|
||||
inline std::string NumberToString(long long number, UInt8 radix = 10);
|
||||
template<typename T> constexpr T RadianToDegree(T radians);
|
||||
long long StringToNumber(String str, UInt8 radix = 10, bool* ok = nullptr);
|
||||
inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr);
|
||||
template<typename T> constexpr T ToDegrees(T angle);
|
||||
template<typename T> constexpr T ToRadians(T angle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
|
|
@ -571,20 +570,18 @@ namespace Nz
|
|||
* \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior
|
||||
* \remark With NAZARA_MATH_SAFE, a NazaraError is produced and String() is returned
|
||||
*/
|
||||
inline String NumberToString(long long number, UInt8 radix)
|
||||
inline std::string NumberToString(long long number, UInt8 radix)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (radix < 2 || radix > 36)
|
||||
{
|
||||
NazaraError("Base must be between 2 and 36");
|
||||
return String();
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
|
||||
if (number == 0)
|
||||
return String('0');
|
||||
|
||||
static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
return "0";
|
||||
|
||||
bool negative;
|
||||
if (number < 0)
|
||||
|
|
@ -595,20 +592,23 @@ namespace Nz
|
|||
else
|
||||
negative = false;
|
||||
|
||||
String str;
|
||||
str.Reserve(GetNumberLength(number)); // Prends en compte le signe négatif
|
||||
std::string str;
|
||||
|
||||
const char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
do
|
||||
{
|
||||
str.Append(symbols[number % radix]);
|
||||
str.push_back(symbols[number % radix]);
|
||||
number /= radix;
|
||||
}
|
||||
while (number > 0);
|
||||
|
||||
if (negative)
|
||||
str.Append('-');
|
||||
str.push_back('-');
|
||||
|
||||
return str.Reverse();
|
||||
std::reverse(str.begin(), str.end());
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -636,7 +636,7 @@ namespace Nz
|
|||
* \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior
|
||||
* \remark With NAZARA_MATH_SAFE, a NazaraError is produced and 0 is returned
|
||||
*/
|
||||
inline long long StringToNumber(String str, UInt8 radix, bool* ok)
|
||||
inline long long StringToNumber(const std::string_view& str, UInt8 radix, bool* ok)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (radix < 2 || radix > 36)
|
||||
|
|
@ -650,15 +650,19 @@ namespace Nz
|
|||
}
|
||||
#endif
|
||||
|
||||
static const char* symbols = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
if (str.empty())
|
||||
{
|
||||
if (ok)
|
||||
*ok = false;
|
||||
|
||||
str.Simplify();
|
||||
if (radix > 10)
|
||||
str = str.ToUpper();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool negative = str.StartsWith('-');
|
||||
const char symbols[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
char* digit = &str[(negative) ? 1 : 0];
|
||||
bool negative = (str.front() == '-');
|
||||
|
||||
const char* digit = &str[(negative) ? 1 : 0];
|
||||
unsigned long long total = 0;
|
||||
do
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@
|
|||
#ifndef NAZARA_ANGLE_HPP
|
||||
#define NAZARA_ANGLE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ namespace Nz
|
|||
Quaternion<T> ToQuaternion() const;
|
||||
T ToRadians() const;
|
||||
Angle<AngleUnit::Radian, T> ToRadianAngle() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Angle& operator=(const Angle&) = default;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#ifdef NAZARA_PLATFORM_POSIX
|
||||
#include <math.h> //< sincos
|
||||
|
|
@ -51,11 +52,6 @@ namespace Nz
|
|||
return DegreeToRadian(degrees);
|
||||
}
|
||||
|
||||
template<typename T> static String ToString(T value)
|
||||
{
|
||||
return "Angle(" + String::Number(value) + "deg)";
|
||||
}
|
||||
|
||||
template<typename T> static std::ostream& ToString(std::ostream& out, T value)
|
||||
{
|
||||
return out << "Angle(" << value << "deg)";
|
||||
|
|
@ -95,11 +91,6 @@ namespace Nz
|
|||
return radians;
|
||||
}
|
||||
|
||||
template<typename T> static String ToString(T value)
|
||||
{
|
||||
return "Angle(" + String::Number(value) + "rad)";
|
||||
}
|
||||
|
||||
template<typename T> static std::ostream& ToString(std::ostream& out, T value)
|
||||
{
|
||||
return out << "Angle(" << value << "rad)";
|
||||
|
|
@ -358,9 +349,12 @@ namespace Nz
|
|||
* \return String representation of the angle
|
||||
*/
|
||||
template<AngleUnit Unit, typename T>
|
||||
String Angle<Unit, T>::ToString() const
|
||||
std::string Angle<Unit, T>::ToString() const
|
||||
{
|
||||
return Detail::AngleUtils<Unit>::ToString(value);
|
||||
std::ostringstream oss;
|
||||
Detail::AngleUtils<Unit>::ToString(oss, value);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
#ifndef NAZARA_BOUNDINGVOLUME_HPP
|
||||
#define NAZARA_BOUNDINGVOLUME_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/OrientedBox.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -47,7 +47,7 @@ namespace Nz
|
|||
BoundingVolume& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
|
||||
template<typename U> BoundingVolume& Set(const BoundingVolume<U>& volume);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
void Update(const Matrix4<T>& transformMatrix);
|
||||
void Update(const Vector3<T>& translation);
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
|
|
@ -361,23 +359,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String BoundingVolume<T>::ToString() const
|
||||
std::string BoundingVolume<T>::ToString() const
|
||||
{
|
||||
switch (extend)
|
||||
{
|
||||
case Extend_Finite:
|
||||
return "BoundingVolume(localBox=" + obb.localBox.ToString() + ')';
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
case Extend_Infinite:
|
||||
return "BoundingVolume(Infinite)";
|
||||
|
||||
case Extend_Null:
|
||||
return "BoundingVolume(Null)";
|
||||
}
|
||||
|
||||
// Si nous arrivons ici c'est que l'extend est invalide
|
||||
NazaraError("Invalid extend type (0x" + String::Number(extend, 16) + ')');
|
||||
return "BoundingVolume(ERROR)";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -510,17 +497,17 @@ namespace Nz
|
|||
BoundingVolume<T> BoundingVolume<T>::Lerp(const BoundingVolume& from, const BoundingVolume& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Null();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NumberEquals(interpolation, F(0.0)))
|
||||
if (NumberEquals(interpolation, T(0.0)))
|
||||
return from;
|
||||
|
||||
if (NumberEquals(interpolation, F(1.0)))
|
||||
if (NumberEquals(interpolation, T(1.0)))
|
||||
return to;
|
||||
|
||||
switch (to.extend)
|
||||
|
|
@ -545,7 +532,7 @@ namespace Nz
|
|||
}
|
||||
|
||||
// If we arrive here, the extend is invalid
|
||||
NazaraError("Invalid extend type (From) (0x" + String::Number(from.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (From) (0x" + NumberToString(from.extend, 16) + ')');
|
||||
return Null();
|
||||
}
|
||||
|
||||
|
|
@ -557,7 +544,7 @@ namespace Nz
|
|||
switch (from.extend)
|
||||
{
|
||||
case Extend_Finite:
|
||||
return from.obb * (F(1.0) - interpolation);
|
||||
return from.obb * (T(1.0) - interpolation);
|
||||
|
||||
case Extend_Infinite:
|
||||
return Infinite();
|
||||
|
|
@ -567,13 +554,13 @@ namespace Nz
|
|||
}
|
||||
|
||||
// If we arrive here, the extend is invalid
|
||||
NazaraError("Invalid extend type (From) (0x" + String::Number(from.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (From) (0x" + NumberToString(from.extend, 16) + ')');
|
||||
return Null();
|
||||
}
|
||||
}
|
||||
|
||||
// If we arrive here, the extend is invalid
|
||||
NazaraError("Invalid extend type (To) (0x" + String::Number(to.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (To) (0x" + NumberToString(to.extend, 16) + ')');
|
||||
return Null();
|
||||
}
|
||||
|
||||
|
|
@ -659,10 +646,22 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::BoundingVolume<T>& volume)
|
||||
{
|
||||
out << volume.ToString();
|
||||
switch (volume.extend)
|
||||
{
|
||||
case Nz::Extend_Finite:
|
||||
out << "BoundingVolume(localBox=" << volume.obb.localBox << ')';
|
||||
break;
|
||||
|
||||
case Nz::Extend_Infinite:
|
||||
out << "BoundingVolume(Infinite)";
|
||||
break;
|
||||
|
||||
case Nz::Extend_Null:
|
||||
out << "BoundingVolume(Null)";
|
||||
break;
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,12 +7,12 @@
|
|||
#ifndef NAZARA_BOX_HPP
|
||||
#define NAZARA_BOX_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -68,7 +68,7 @@ namespace Nz
|
|||
Box& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
|
||||
template<typename U> Box& Set(const Box<U>& box);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Box& Transform(const Matrix4<T>& matrix, bool applyTranslation = true);
|
||||
Box& Translate(const Vector3<T>& translation);
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -261,7 +259,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T> Box<T>::GetCenter() const
|
||||
{
|
||||
return GetPosition() + GetLengths() / F(2.0);
|
||||
return GetPosition() + GetLengths() / T(2.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -303,7 +301,7 @@ namespace Nz
|
|||
return Vector3<T>(x + width, y + height, z + depth);
|
||||
}
|
||||
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
return Vector3<T>();
|
||||
}
|
||||
|
||||
|
|
@ -358,13 +356,13 @@ namespace Nz
|
|||
{
|
||||
Vector3<T> neg(GetPosition());
|
||||
|
||||
if (normal.x < F(0.0))
|
||||
if (normal.x < T(0.0))
|
||||
neg.x += width;
|
||||
|
||||
if (normal.y < F(0.0))
|
||||
if (normal.y < T(0.0))
|
||||
neg.y += height;
|
||||
|
||||
if (normal.z < F(0.0))
|
||||
if (normal.z < T(0.0))
|
||||
neg.z += depth;
|
||||
|
||||
return neg;
|
||||
|
|
@ -397,13 +395,13 @@ namespace Nz
|
|||
{
|
||||
Vector3<T> pos(GetPosition());
|
||||
|
||||
if (normal.x > F(0.0))
|
||||
if (normal.x > T(0.0))
|
||||
pos.x += width;
|
||||
|
||||
if (normal.y > F(0.0))
|
||||
if (normal.y > T(0.0))
|
||||
pos.y += height;
|
||||
|
||||
if (normal.z > F(0.0))
|
||||
if (normal.z > T(0.0))
|
||||
pos.z += depth;
|
||||
|
||||
return pos;
|
||||
|
|
@ -442,7 +440,7 @@ namespace Nz
|
|||
T Box<T>::GetSquaredRadius() const
|
||||
{
|
||||
Vector3<T> size(GetLengths());
|
||||
size /= F(2.0); // The size only depends on the lengths and not the center
|
||||
size /= T(2.0); // The size only depends on the lengths and not the center
|
||||
|
||||
return size.GetSquaredLength();
|
||||
}
|
||||
|
|
@ -494,7 +492,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Box<T>::IsValid() const
|
||||
{
|
||||
return width > F(0.0) && height > F(0.0) && depth > F(0.0);
|
||||
return width > T(0.0) && height > T(0.0) && depth > T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -507,12 +505,12 @@ namespace Nz
|
|||
template<typename T>
|
||||
Box<T>& Box<T>::MakeZero()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
width = F(0.0);
|
||||
height = F(0.0);
|
||||
depth = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
width = T(0.0);
|
||||
height = T(0.0);
|
||||
depth = T(0.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -531,9 +529,9 @@ namespace Nz
|
|||
template<typename T>
|
||||
Box<T>& Box<T>::Set(T Width, T Height, T Depth)
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
width = Width;
|
||||
height = Height;
|
||||
depth = Depth;
|
||||
|
|
@ -599,10 +597,10 @@ namespace Nz
|
|||
{
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
z = F(0.0);
|
||||
z = T(0.0);
|
||||
width = rect.width;
|
||||
height = rect.height;
|
||||
depth = F(1.0);
|
||||
depth = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -655,12 +653,12 @@ namespace Nz
|
|||
template<typename U>
|
||||
Box<T>& Box<T>::Set(const Box<U>& box)
|
||||
{
|
||||
x = F(box.x);
|
||||
y = F(box.y);
|
||||
z = F(box.z);
|
||||
width = F(box.width);
|
||||
height = F(box.height);
|
||||
depth = F(box.depth);
|
||||
x = T(box.x);
|
||||
y = T(box.y);
|
||||
z = T(box.z);
|
||||
width = T(box.width);
|
||||
height = T(box.height);
|
||||
depth = T(box.depth);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -671,11 +669,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Box<T>::ToString() const
|
||||
std::string Box<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Box(" << x << ", " << y << ", " << z << ", " << width << ", " << height << ", " << depth << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -689,8 +688,8 @@ namespace Nz
|
|||
template<typename T>
|
||||
Box<T>& Box<T>::Transform(const Matrix4<T>& matrix, bool applyTranslation)
|
||||
{
|
||||
Vector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? F(1.0) : F(0.0)); // Value multiplying the translation
|
||||
Vector3<T> halfSize = GetLengths() / F(2.0);
|
||||
Vector3<T> center = matrix.Transform(GetCenter(), (applyTranslation) ? T(1.0) : T(0.0)); // Value multiplying the translation
|
||||
Vector3<T> halfSize = GetLengths() / T(2.0);
|
||||
|
||||
halfSize.Set(std::abs(matrix(0,0)) * halfSize.x + std::abs(matrix(1,0)) * halfSize.y + std::abs(matrix(2,0)) * halfSize.z,
|
||||
std::abs(matrix(0,1)) * halfSize.x + std::abs(matrix(1,1)) * halfSize.y + std::abs(matrix(2,1)) * halfSize.z,
|
||||
|
|
@ -855,9 +854,9 @@ namespace Nz
|
|||
Box<T> Box<T>::Lerp(const Box& from, const Box& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -963,9 +962,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Box<T>& box)
|
||||
{
|
||||
return out << box.ToString();
|
||||
return out << "Box(" << box.x << ", " << box.y << ", " << box.z << ", " << box.width << ", " << box.height << ", " << box.depth << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
#ifndef NAZARA_EULERANGLES_HPP
|
||||
#define NAZARA_EULERANGLES_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
|||
|
||||
//Matrix3<T> ToRotationMatrix() const;
|
||||
Quaternion<T> ToQuaternion() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
EulerAngles operator+(const EulerAngles& angles) const;
|
||||
EulerAngles operator-(const EulerAngles& angles) const;
|
||||
|
|
|
|||
|
|
@ -4,16 +4,14 @@
|
|||
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
|
|
@ -96,7 +94,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
void EulerAngles<T>::MakeZero()
|
||||
{
|
||||
Set(F(0.0), F(0.0), F(0.0));
|
||||
Set(T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -194,9 +192,9 @@ namespace Nz
|
|||
template<typename U>
|
||||
EulerAngles<T>& EulerAngles<T>::Set(const EulerAngles<U>& angles)
|
||||
{
|
||||
pitch = F(angles.pitch);
|
||||
yaw = F(angles.yaw);
|
||||
roll = F(angles.roll);
|
||||
pitch = T(angles.pitch);
|
||||
yaw = T(angles.yaw);
|
||||
roll = T(angles.roll);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -210,13 +208,13 @@ namespace Nz
|
|||
Quaternion<T> EulerAngles<T>::ToQuaternion() const
|
||||
{
|
||||
// XYZ
|
||||
T c1 = std::cos(ToRadians(yaw) / F(2.0));
|
||||
T c2 = std::cos(ToRadians(roll) / F(2.0));
|
||||
T c3 = std::cos(ToRadians(pitch) / F(2.0));
|
||||
T c1 = std::cos(ToRadians(yaw) / T(2.0));
|
||||
T c2 = std::cos(ToRadians(roll) / T(2.0));
|
||||
T c3 = std::cos(ToRadians(pitch) / T(2.0));
|
||||
|
||||
T s1 = std::sin(ToRadians(yaw) / F(2.0));
|
||||
T s2 = std::sin(ToRadians(roll) / F(2.0));
|
||||
T s3 = std::sin(ToRadians(pitch) / F(2.0));
|
||||
T s1 = std::sin(ToRadians(yaw) / T(2.0));
|
||||
T s2 = std::sin(ToRadians(roll) / T(2.0));
|
||||
T s3 = std::sin(ToRadians(pitch) / T(2.0));
|
||||
|
||||
return Quaternion<T>(c1 * c2 * c3 - s1 * s2 * s3,
|
||||
s1 * s2 * c3 + c1 * c2 * s3,
|
||||
|
|
@ -230,11 +228,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String EulerAngles<T>::ToString() const
|
||||
std::string EulerAngles<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -401,9 +400,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles<T>& angles)
|
||||
{
|
||||
return out << angles.ToString();
|
||||
return out << "EulerAngles(" << angles.pitch << ", " << angles.yaw << ", " << angles.roll << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef NAZARA_FRUSTUM_HPP
|
||||
#define NAZARA_FRUSTUM_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/BoundingVolume.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
|
@ -15,6 +14,7 @@
|
|||
#include <Nazara/Math/Plane.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ namespace Nz
|
|||
|
||||
template<typename U> Frustum& Set(const Frustum<U>& frustum);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
template<typename U>
|
||||
friend bool Serialize(SerializationContext& context, const Frustum<U>& frustum, TypeTag<Frustum<U>>);
|
||||
|
|
|
|||
|
|
@ -7,13 +7,11 @@
|
|||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
|
|
@ -55,9 +53,9 @@ namespace Nz
|
|||
Frustum<T>& Frustum<T>::Build(T angle, T ratio, T zNear, T zFar, const Vector3<T>& eye, const Vector3<T>& target, const Vector3<T>& up)
|
||||
{
|
||||
#if NAZARA_MATH_ANGLE_RADIAN
|
||||
angle /= F(2.0);
|
||||
angle /= T(2.0);
|
||||
#else
|
||||
angle = DegreeToRadian(angle/F(2.0));
|
||||
angle = DegreeToRadian(angle / T(2.0));
|
||||
#endif
|
||||
|
||||
T tangent = std::tan(angle);
|
||||
|
|
@ -128,7 +126,7 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid intersection side (0x" + String::Number(side, 16) + ')');
|
||||
NazaraError("Invalid intersection side (0x" + NumberToString(side, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +137,7 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +154,7 @@ namespace Nz
|
|||
// http://www.lighthouse3d.com/tutorials/view-frustum-culling/geometric-approach-testing-boxes-ii/
|
||||
for (unsigned int i = 0; i <= FrustumPlane_Max; i++)
|
||||
{
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0))
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +171,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Frustum<T>::Contains(const OrientedBox<T>& orientedbox) const
|
||||
{
|
||||
return Contains(&orientedbox[0], 8);
|
||||
return Contains(orientedbox.GetCorners(), 8);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -207,7 +205,7 @@ namespace Nz
|
|||
{
|
||||
for (unsigned int i = 0; i <= FrustumPlane_Max; ++i)
|
||||
{
|
||||
if (m_planes[i].Distance(point) < F(0.0))
|
||||
if (m_planes[i].Distance(point) < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -230,7 +228,7 @@ namespace Nz
|
|||
unsigned int j;
|
||||
for (j = 0; j < pointCount; j++ )
|
||||
{
|
||||
if (m_planes[i].Distance(points[j]) > F(0.0))
|
||||
if (m_planes[i].Distance(points[j]) > T(0.0))
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +262,7 @@ namespace Nz
|
|||
plane[3] = clipMatrix[15] - clipMatrix[12];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
|
|
@ -279,7 +277,7 @@ namespace Nz
|
|||
plane[3] = clipMatrix[15] + clipMatrix[12];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
|
|
@ -294,7 +292,7 @@ namespace Nz
|
|||
plane[3] = clipMatrix[15] + clipMatrix[13];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
|
|
@ -309,7 +307,7 @@ namespace Nz
|
|||
plane[3] = clipMatrix[15] - clipMatrix[13];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
|
|
@ -324,7 +322,7 @@ namespace Nz
|
|||
plane[3] = clipMatrix[15] - clipMatrix[14];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
|
|
@ -339,7 +337,7 @@ namespace Nz
|
|||
plane[3] = clipMatrix[15] + clipMatrix[14];
|
||||
|
||||
// Normalize the result
|
||||
invLength = F(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
invLength = T(1.0) / std::sqrt(plane[0] * plane[0] + plane[1] * plane[1] + plane[2] * plane[2]);
|
||||
plane[0] *= invLength;
|
||||
plane[1] *= invLength;
|
||||
plane[2] *= invLength;
|
||||
|
|
@ -356,56 +354,56 @@ namespace Nz
|
|||
Vector4<T> corner;
|
||||
|
||||
// FarLeftBottom
|
||||
corner.Set(F(-1.0), F(-1.0), F(1.0));
|
||||
corner.Set(T(-1.0), T(-1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarLeftBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// FarLeftTop
|
||||
corner.Set(F(-1.0), F(1.0), F(1.0));
|
||||
corner.Set(T(-1.0), T(1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarLeftTop] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// FarRightBottom
|
||||
corner.Set(F(1.0), F(-1.0), F(1.0));
|
||||
corner.Set(T(1.0), T(-1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarRightBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// FarRightTop
|
||||
corner.Set(F(1.0), F(1.0), F(1.0));
|
||||
corner.Set(T(1.0), T(1.0), T(1.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_FarRightTop] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearLeftBottom
|
||||
corner.Set(F(-1.0), F(-1.0), F(0.0));
|
||||
corner.Set(T(-1.0), T(-1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_NearLeftBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearLeftTop
|
||||
corner.Set(F(-1.0), F(1.0), F(0.0));
|
||||
corner.Set(T(-1.0), T(1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_NearLeftTop] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearRightBottom
|
||||
corner.Set(F(1.0), F(-1.0), F(0.0));
|
||||
corner.Set(T(1.0), T(-1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
m_corners[BoxCorner_NearRightBottom] = Vector3<T>(corner.x, corner.y, corner.z);
|
||||
|
||||
// NearRightTop
|
||||
corner.Set(F(1.0), F(1.0), F(0.0));
|
||||
corner.Set(T(1.0), T(1.0), T(0.0));
|
||||
corner = invClipMatrix.Transform(corner);
|
||||
corner.Normalize();
|
||||
|
||||
|
|
@ -448,7 +446,7 @@ namespace Nz
|
|||
#ifdef NAZARA_DEBUG
|
||||
if (corner > BoxCorner_Max)
|
||||
{
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
|
||||
static Vector3<T> dummy;
|
||||
return dummy;
|
||||
|
|
@ -473,7 +471,7 @@ namespace Nz
|
|||
#ifdef NAZARA_DEBUG
|
||||
if (plane > FrustumPlane_Max)
|
||||
{
|
||||
NazaraError("Frustum plane not handled (0x" + String::Number(plane, 16) + ')');
|
||||
NazaraError("Frustum plane not handled (0x" + NumberToString(plane, 16) + ')');
|
||||
|
||||
static Plane<T> dummy;
|
||||
return dummy;
|
||||
|
|
@ -515,7 +513,7 @@ namespace Nz
|
|||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
NazaraError("Invalid intersection side (0x" + String::Number(side, 16) + ')');
|
||||
NazaraError("Invalid intersection side (0x" + NumberToString(side, 16) + ')');
|
||||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +524,7 @@ namespace Nz
|
|||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')');
|
||||
return IntersectionSide_Outside;
|
||||
}
|
||||
|
||||
|
|
@ -545,9 +543,9 @@ namespace Nz
|
|||
|
||||
for (unsigned int i = 0; i <= FrustumPlane_Max; i++)
|
||||
{
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < F(0.0))
|
||||
if (m_planes[i].Distance(box.GetPositiveVertex(m_planes[i].normal)) < T(0.0))
|
||||
return IntersectionSide_Outside;
|
||||
else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < F(0.0))
|
||||
else if (m_planes[i].Distance(box.GetNegativeVertex(m_planes[i].normal)) < T(0.0))
|
||||
side = IntersectionSide_Intersecting;
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +562,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
IntersectionSide Frustum<T>::Intersect(const OrientedBox<T>& orientedbox) const
|
||||
{
|
||||
return Intersect(&orientedbox[0], 8);
|
||||
return Intersect(orientedbox.GetCorners(), 8);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -610,7 +608,7 @@ namespace Nz
|
|||
unsigned int j;
|
||||
for (j = 0; j < pointCount; j++ )
|
||||
{
|
||||
if (m_planes[i].Distance(points[j]) > F(0.0))
|
||||
if (m_planes[i].Distance(points[j]) > T(0.0))
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -649,16 +647,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Frustum<T>::ToString() const
|
||||
std::string Frustum<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Frustum(Bottom: " << m_planes[FrustumPlane_Bottom].ToString() << "\n"
|
||||
<< " Far: " << m_planes[FrustumPlane_Far].ToString() << "\n"
|
||||
<< " Left: " << m_planes[FrustumPlane_Left].ToString() << "\n"
|
||||
<< " Near: " << m_planes[FrustumPlane_Near].ToString() << "\n"
|
||||
<< " Right: " << m_planes[FrustumPlane_Right].ToString() << "\n"
|
||||
<< " Top: " << m_planes[FrustumPlane_Top].ToString() << ")\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -723,9 +717,12 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Frustum<T>& frustum)
|
||||
{
|
||||
return out << frustum.ToString();
|
||||
return out << "Frustum(Bottom: " << frustum.GetPlane(Nz::FrustumPlane_Bottom) << ",\n"
|
||||
<< " Far: " << frustum.GetPlane(Nz::FrustumPlane_Far) << ",\n"
|
||||
<< " Left: " << frustum.GetPlane(Nz::FrustumPlane_Left) << ",\n"
|
||||
<< " Near: " << frustum.GetPlane(Nz::FrustumPlane_Near) << ",\n"
|
||||
<< " Right: " << frustum.GetPlane(Nz::FrustumPlane_Right) << ",\n"
|
||||
<< " Top: " << frustum.GetPlane(Nz::FrustumPlane_Top) << ")\n";
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@
|
|||
|
||||
///FIXME: Matrices column-major, difficile de bosser avec (Tout passer en row-major et transposer dans les shaders ?)
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -90,7 +91,7 @@ namespace Nz
|
|||
Matrix4& SetScale(const Vector3<T>& scale);
|
||||
Matrix4& SetTranslation(const Vector3<T>& translation);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Vector2<T> Transform(const Vector2<T>& vector, T z = 0.0, T w = 1.0) const;
|
||||
Vector3<T> Transform(const Vector3<T>& vector, T w = 1.0) const;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
|
|
@ -14,11 +13,10 @@
|
|||
#include <Nazara/Math/Vector4.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
|
|
@ -202,22 +200,22 @@ namespace Nz
|
|||
return Set(m11*matrix.m11 + m12*matrix.m21 + m13*matrix.m31,
|
||||
m11*matrix.m12 + m12*matrix.m22 + m13*matrix.m32,
|
||||
m11*matrix.m13 + m12*matrix.m23 + m13*matrix.m33,
|
||||
F(0.0),
|
||||
T(0.0),
|
||||
|
||||
m21*matrix.m11 + m22*matrix.m21 + m23*matrix.m31,
|
||||
m21*matrix.m12 + m22*matrix.m22 + m23*matrix.m32,
|
||||
m21*matrix.m13 + m22*matrix.m23 + m23*matrix.m33,
|
||||
F(0.0),
|
||||
T(0.0),
|
||||
|
||||
m31*matrix.m11 + m32*matrix.m21 + m33*matrix.m31,
|
||||
m31*matrix.m12 + m32*matrix.m22 + m33*matrix.m32,
|
||||
m31*matrix.m13 + m32*matrix.m23 + m33*matrix.m33,
|
||||
F(0.0),
|
||||
T(0.0),
|
||||
|
||||
m41*matrix.m11 + m42*matrix.m21 + m43*matrix.m31 + matrix.m41,
|
||||
m41*matrix.m12 + m42*matrix.m22 + m43*matrix.m32 + matrix.m42,
|
||||
m41*matrix.m13 + m42*matrix.m23 + m43*matrix.m33 + matrix.m43,
|
||||
F(1.0));
|
||||
T(1.0));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
@ -257,10 +255,10 @@ namespace Nz
|
|||
#if NAZARA_MATH_SAFE
|
||||
if (column > 3)
|
||||
{
|
||||
String error("Column out of range: (" + String::Number(column) + ") > 3");
|
||||
std::string error("Column out of range: (" + std::to_string(column) + ") > 3");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -466,7 +464,7 @@ namespace Nz
|
|||
m31 * m12 * m23 -
|
||||
m31 * m13 * m22;
|
||||
|
||||
T invDet = F(1.0) / det;
|
||||
T invDet = T(1.0) / det;
|
||||
for (unsigned int i = 0; i < 16; ++i)
|
||||
inv[i] *= invDet;
|
||||
|
||||
|
|
@ -508,7 +506,7 @@ namespace Nz
|
|||
#endif
|
||||
|
||||
T det = GetDeterminantAffine();
|
||||
if (det != F(0.0))
|
||||
if (det != T(0.0))
|
||||
{
|
||||
// http://stackoverflow.com/questions/1148309/inverting-a-4x4-matrix
|
||||
T inv[16];
|
||||
|
|
@ -521,7 +519,7 @@ namespace Nz
|
|||
inv[2] = m12 * m23 -
|
||||
m22 * m13;
|
||||
|
||||
inv[3] = F(0.0);
|
||||
inv[3] = T(0.0);
|
||||
|
||||
inv[4] = -m21 * m33 +
|
||||
m31 * m23;
|
||||
|
|
@ -532,7 +530,7 @@ namespace Nz
|
|||
inv[6] = -m11 * m23 +
|
||||
m21 * m13;
|
||||
|
||||
inv[7] = F(0.0);
|
||||
inv[7] = T(0.0);
|
||||
|
||||
inv[8] = m21 * m32 -
|
||||
m31 * m22;
|
||||
|
|
@ -543,7 +541,7 @@ namespace Nz
|
|||
inv[10] = m11 * m22 -
|
||||
m21 * m12;
|
||||
|
||||
inv[11] = F(0.0);
|
||||
inv[11] = T(0.0);
|
||||
|
||||
inv[12] = -m21 * m32 * m43 +
|
||||
m21 * m33 * m42 +
|
||||
|
|
@ -566,11 +564,11 @@ namespace Nz
|
|||
m41 * m12 * m23 +
|
||||
m41 * m13 * m22;
|
||||
|
||||
T invDet = F(1.0) / det;
|
||||
T invDet = T(1.0) / det;
|
||||
for (unsigned int i = 0; i < 16; ++i)
|
||||
inv[i] *= invDet;
|
||||
|
||||
inv[15] = F(1.0);
|
||||
inv[15] = T(1.0);
|
||||
|
||||
*dest = inv;
|
||||
return true;
|
||||
|
|
@ -591,10 +589,10 @@ namespace Nz
|
|||
Quaternion<T> quat;
|
||||
|
||||
T trace = m11 + m22 + m33;
|
||||
if (trace > F(0.0))
|
||||
if (trace > T(0.0))
|
||||
{
|
||||
T s = F(0.5) / std::sqrt(trace + F(1.0));
|
||||
quat.w = F(0.25) / s;
|
||||
T s = T(0.5) / std::sqrt(trace + T(1.0));
|
||||
quat.w = T(0.25) / s;
|
||||
quat.x = (m23 - m32) * s;
|
||||
quat.y = (m31 - m13) * s;
|
||||
quat.z = (m12 - m21) * s;
|
||||
|
|
@ -603,30 +601,30 @@ namespace Nz
|
|||
{
|
||||
if (m11 > m22 && m11 > m33)
|
||||
{
|
||||
T s = F(2.0) * std::sqrt(F(1.0) + m11 - m22 - m33);
|
||||
T s = T(2.0) * std::sqrt(T(1.0) + m11 - m22 - m33);
|
||||
|
||||
quat.w = (m23 - m32) / s;
|
||||
quat.x = F(0.25) * s;
|
||||
quat.x = T(0.25) * s;
|
||||
quat.y = (m21 + m12) / s;
|
||||
quat.z = (m31 + m13) / s;
|
||||
}
|
||||
else if (m22 > m33)
|
||||
{
|
||||
T s = F(2.0) * std::sqrt(F(1.0) + m22 - m11 - m33);
|
||||
T s = T(2.0) * std::sqrt(T(1.0) + m22 - m11 - m33);
|
||||
|
||||
quat.w = (m31 - m13) / s;
|
||||
quat.x = (m21 + m12) / s;
|
||||
quat.y = F(0.25) * s;
|
||||
quat.y = T(0.25) * s;
|
||||
quat.z = (m32 + m23) / s;
|
||||
}
|
||||
else
|
||||
{
|
||||
T s = F(2.0) * std::sqrt(F(1.0) + m33 - m11 - m22);
|
||||
T s = T(2.0) * std::sqrt(T(1.0) + m33 - m11 - m22);
|
||||
|
||||
quat.w = (m12 - m21) / s;
|
||||
quat.x = (m31 + m13) / s;
|
||||
quat.y = (m32 + m23) / s;
|
||||
quat.z = F(0.25) * s;
|
||||
quat.z = T(0.25) * s;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -651,10 +649,10 @@ namespace Nz
|
|||
#if NAZARA_MATH_SAFE
|
||||
if (row > 3)
|
||||
{
|
||||
String error("Row out of range: (" + String::Number(row) + ") > 3");
|
||||
std::string error("Row out of range: (" + NumberToString(row) + ") > 3");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -740,7 +738,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Matrix4<T>::HasNegativeScale() const
|
||||
{
|
||||
return GetDeterminant() < F(0.0);
|
||||
return GetDeterminant() < T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -754,15 +752,15 @@ namespace Nz
|
|||
bool Matrix4<T>::HasScale() const
|
||||
{
|
||||
T t = m11*m11 + m21*m21 + m31*m31;
|
||||
if (!NumberEquals(t, F(1.0)))
|
||||
if (!NumberEquals(t, T(1.0)))
|
||||
return true;
|
||||
|
||||
t = m12*m12 + m22*m22 + m32*m32;
|
||||
if (!NumberEquals(t, F(1.0)))
|
||||
if (!NumberEquals(t, T(1.0)))
|
||||
return true;
|
||||
|
||||
t = m13*m13 + m23*m23 + m33*m33;
|
||||
if (!NumberEquals(t, F(1.0)))
|
||||
if (!NumberEquals(t, T(1.0)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
@ -814,7 +812,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Matrix4<T>::IsAffine() const
|
||||
{
|
||||
return NumberEquals(m14, F(0.0)) && NumberEquals(m24, F(0.0)) && NumberEquals(m34, F(0.0)) && NumberEquals(m44, F(1.0));
|
||||
return NumberEquals(m14, T(0.0)) && NumberEquals(m24, T(0.0)) && NumberEquals(m34, T(0.0)) && NumberEquals(m44, T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -825,10 +823,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Matrix4<T>::IsIdentity() const
|
||||
{
|
||||
return (NumberEquals(m11, F(1.0)) && NumberEquals(m12, F(0.0)) && NumberEquals(m13, F(0.0)) && NumberEquals(m14, F(0.0)) &&
|
||||
NumberEquals(m21, F(0.0)) && NumberEquals(m22, F(1.0)) && NumberEquals(m23, F(0.0)) && NumberEquals(m24, F(0.0)) &&
|
||||
NumberEquals(m31, F(0.0)) && NumberEquals(m32, F(0.0)) && NumberEquals(m33, F(1.0)) && NumberEquals(m34, F(0.0)) &&
|
||||
NumberEquals(m41, F(0.0)) && NumberEquals(m42, F(0.0)) && NumberEquals(m43, F(0.0)) && NumberEquals(m44, F(1.0)));
|
||||
return (NumberEquals(m11, T(1.0)) && NumberEquals(m12, T(0.0)) && NumberEquals(m13, T(0.0)) && NumberEquals(m14, T(0.0)) &&
|
||||
NumberEquals(m21, T(0.0)) && NumberEquals(m22, T(1.0)) && NumberEquals(m23, T(0.0)) && NumberEquals(m24, T(0.0)) &&
|
||||
NumberEquals(m31, T(0.0)) && NumberEquals(m32, T(0.0)) && NumberEquals(m33, T(1.0)) && NumberEquals(m34, T(0.0)) &&
|
||||
NumberEquals(m41, T(0.0)) && NumberEquals(m42, T(0.0)) && NumberEquals(m43, T(0.0)) && NumberEquals(m44, T(1.0)));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -841,10 +839,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeIdentity()
|
||||
{
|
||||
Set(F(1.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(1.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(1.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
Set(T(1.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(1.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(1.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -893,10 +891,10 @@ namespace Nz
|
|||
Matrix4<T>& Matrix4<T>::MakeOrtho(T left, T right, T top, T bottom, T zNear, T zFar)
|
||||
{
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb204942(v=vs.85).aspx
|
||||
Set(F(2.0) / (right - left), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(2.0) / (top - bottom), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(1.0) / (zNear - zFar), F(0.0),
|
||||
(left + right) / (left - right), (top + bottom) / (bottom - top), zNear/(zNear - zFar), F(1.0));
|
||||
Set(T(2.0) / (right - left), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(2.0) / (top - bottom), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(1.0) / (zNear - zFar), T(0.0),
|
||||
(left + right) / (left - right), (top + bottom) / (bottom - top), zNear/(zNear - zFar), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -918,17 +916,17 @@ namespace Nz
|
|||
{
|
||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb204945(v=vs.85).aspx
|
||||
#if NAZARA_MATH_ANGLE_RADIAN
|
||||
angle /= F(2.0);
|
||||
angle /= T(2.0);
|
||||
#else
|
||||
angle = DegreeToRadian(angle/F(2.0));
|
||||
angle = DegreeToRadian(angle / T(2.0));
|
||||
#endif
|
||||
|
||||
T yScale = std::tan(static_cast<T>(M_PI_2) - angle);
|
||||
|
||||
Set(yScale / ratio, F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), yScale, F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), - (zFar + zNear) / (zFar - zNear), F(-1.0),
|
||||
F(0.0), F(0.0), F(-2.0) * (zNear * zFar) / (zFar - zNear), F(0.0));
|
||||
Set(yScale / ratio, T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), yScale, T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), - (zFar + zNear) / (zFar - zNear), T(-1.0),
|
||||
T(0.0), T(0.0), T(-2.0) * (zNear * zFar) / (zFar - zNear), T(0.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -948,13 +946,13 @@ namespace Nz
|
|||
SetRotation(rotation);
|
||||
|
||||
// We complete the matrix
|
||||
m14 = F(0.0);
|
||||
m24 = F(0.0);
|
||||
m34 = F(0.0);
|
||||
m41 = F(0.0);
|
||||
m42 = F(0.0);
|
||||
m43 = F(0.0);
|
||||
m44 = F(1.0);
|
||||
m14 = T(0.0);
|
||||
m24 = T(0.0);
|
||||
m34 = T(0.0);
|
||||
m41 = T(0.0);
|
||||
m42 = T(0.0);
|
||||
m43 = T(0.0);
|
||||
m44 = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -971,10 +969,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeScale(const Vector3<T>& scale)
|
||||
{
|
||||
Set(scale.x, F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), scale.y, F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), scale.z, F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
Set(scale.x, T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), scale.y, T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), scale.z, T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -991,10 +989,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeTranslation(const Vector3<T>& translation)
|
||||
{
|
||||
Set(F(1.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(1.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(1.0), F(0.0),
|
||||
translation.x, translation.y, translation.z, F(1.0));
|
||||
Set(T(1.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(1.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(1.0), T(0.0),
|
||||
translation.x, translation.y, translation.z, T(1.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -1019,10 +1017,10 @@ namespace Nz
|
|||
SetTranslation(translation);
|
||||
|
||||
// We complete the matrix (the transformations are affine)
|
||||
m14 = F(0.0);
|
||||
m24 = F(0.0);
|
||||
m34 = F(0.0);
|
||||
m44 = F(1.0);
|
||||
m14 = T(0.0);
|
||||
m24 = T(0.0);
|
||||
m34 = T(0.0);
|
||||
m44 = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -1078,10 +1076,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Matrix4<T>& Matrix4<T>::MakeZero()
|
||||
{
|
||||
Set(F(0.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(0.0),
|
||||
F(0.0), F(0.0), F(0.0), F(0.0));
|
||||
Set(T(0.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(0.0),
|
||||
T(0.0), T(0.0), T(0.0), T(0.0));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -1130,10 +1128,10 @@ namespace Nz
|
|||
template<typename U>
|
||||
Matrix4<T>& Matrix4<T>::Set(const Matrix4<U>& matrix)
|
||||
{
|
||||
Set(F(matrix[ 0]), F(matrix[ 1]), F(matrix[ 2]), F(matrix[ 3]),
|
||||
F(matrix[ 4]), F(matrix[ 5]), F(matrix[ 6]), F(matrix[ 7]),
|
||||
F(matrix[ 8]), F(matrix[ 9]), F(matrix[10]), F(matrix[11]),
|
||||
F(matrix[12]), F(matrix[13]), F(matrix[14]), F(matrix[15]));
|
||||
Set(T(matrix[ 0]), T(matrix[ 1]), T(matrix[ 2]), T(matrix[ 3]),
|
||||
T(matrix[ 4]), T(matrix[ 5]), T(matrix[ 6]), T(matrix[ 7]),
|
||||
T(matrix[ 8]), T(matrix[ 9]), T(matrix[10]), T(matrix[11]),
|
||||
T(matrix[12]), T(matrix[13]), T(matrix[14]), T(matrix[15]));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -1159,17 +1157,17 @@ namespace Nz
|
|||
T qy2 = qy * qy;
|
||||
T qz2 = qz * qz;
|
||||
|
||||
m11 = F(1.0) - F(2.0) * qy2 - F(2.0) * qz2;
|
||||
m21 = F(2.0) * qx * qy - F(2.0) * qz * qw;
|
||||
m31 = F(2.0) * qx * qz + F(2.0) * qy * qw;
|
||||
m11 = T(1.0) - T(2.0) * qy2 - T(2.0) * qz2;
|
||||
m21 = T(2.0) * qx * qy - T(2.0) * qz * qw;
|
||||
m31 = T(2.0) * qx * qz + T(2.0) * qy * qw;
|
||||
|
||||
m12 = F(2.0) * qx * qy + F(2.0) * qz * qw;
|
||||
m22 = F(1.0) - F(2.0) * qx2 - F(2.0) * qz2;
|
||||
m32 = F(2.0) * qy * qz - F(2.0) * qx * qw;
|
||||
m12 = T(2.0) * qx * qy + T(2.0) * qz * qw;
|
||||
m22 = T(1.0) - T(2.0) * qx2 - T(2.0) * qz2;
|
||||
m32 = T(2.0) * qy * qz - T(2.0) * qx * qw;
|
||||
|
||||
m13 = F(2.0) * qx * qz - F(2.0) * qy * qw;
|
||||
m23 = F(2.0) * qy * qz + F(2.0) * qx * qw;
|
||||
m33 = F(1.0) - F(2.0) * qx2 - F(2.0) * qy2;
|
||||
m13 = T(2.0) * qx * qz - T(2.0) * qy * qw;
|
||||
m23 = T(2.0) * qy * qz + T(2.0) * qx * qw;
|
||||
m33 = T(1.0) - T(2.0) * qx2 - T(2.0) * qy2;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -1218,13 +1216,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Matrix4<T>::ToString() const
|
||||
std::string Matrix4<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
return ss << "Matrix4(" << m11 << ", " << m12 << ", " << m13 << ", " << m14 << ",\n"
|
||||
<< " " << m21 << ", " << m22 << ", " << m23 << ", " << m24 << ",\n"
|
||||
<< " " << m31 << ", " << m32 << ", " << m33 << ", " << m34 << ",\n"
|
||||
<< " " << m41 << ", " << m42 << ", " << m43 << ", " << m44 << ')';
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -1335,10 +1332,10 @@ namespace Nz
|
|||
#if NAZARA_MATH_SAFE
|
||||
if (x > 3 || y > 3)
|
||||
{
|
||||
String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)");
|
||||
std::string error("Index out of range: (" + NumberToString(x) + ", " + NumberToString(y) +") > (3, 3)");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1359,10 +1356,10 @@ namespace Nz
|
|||
#if NAZARA_MATH_SAFE
|
||||
if (x > 3 || y > 3)
|
||||
{
|
||||
String error("Index out of range: (" + String::Number(x) + ", " + String::Number(y) +") > (3, 3)");
|
||||
std::string error("Index out of range: (" + NumberToString(x) + ", " + NumberToString(y) +") > (3, 3)");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::out_of_range(error.ToStdString());
|
||||
throw std::out_of_range(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1801,7 +1798,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Matrix4<T>& matrix)
|
||||
{
|
||||
return out << matrix.ToString();
|
||||
return out << "Matrix4(" << matrix.m11 << ", " << matrix.m12 << ", " << matrix.m13 << ", " << matrix.m14 << ",\n"
|
||||
<< " " << matrix.m21 << ", " << matrix.m22 << ", " << matrix.m23 << ", " << matrix.m24 << ",\n"
|
||||
<< " " << matrix.m31 << ", " << matrix.m32 << ", " << matrix.m33 << ", " << matrix.m34 << ",\n"
|
||||
<< " " << matrix.m41 << ", " << matrix.m42 << ", " << matrix.m43 << ", " << matrix.m44 << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -1818,6 +1818,4 @@ Nz::Matrix4<T> operator*(T scale, const Nz::Matrix4<T>& matrix)
|
|||
return matrix * scale;
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,10 +7,11 @@
|
|||
#ifndef NAZARA_ORIENTEDBOX_HPP
|
||||
#define NAZARA_ORIENTEDBOX_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -29,6 +30,7 @@ namespace Nz
|
|||
~OrientedBox() = default;
|
||||
|
||||
const Vector3<T>& GetCorner(BoxCorner corner) const;
|
||||
const Vector3<T>* GetCorners() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
|
|
@ -39,14 +41,11 @@ namespace Nz
|
|||
OrientedBox& Set(const Vector3<T>& vec1, const Vector3<T>& vec2);
|
||||
template<typename U> OrientedBox& Set(const OrientedBox<U>& orientedBox);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
void Update(const Matrix4<T>& transformMatrix);
|
||||
void Update(const Vector3<T>& transformMatrix);
|
||||
|
||||
operator Vector3<T>* ();
|
||||
operator const Vector3<T>* () const;
|
||||
|
||||
Vector3<T>& operator()(unsigned int i);
|
||||
Vector3<T> operator()(unsigned int i) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
///DOC: Pour que les coins soient valides, la méthode Update doit être appelée
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -93,7 +91,7 @@ namespace Nz
|
|||
#ifdef NAZARA_DEBUG
|
||||
if (corner > BoxCorner_Max)
|
||||
{
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
|
||||
static Vector3<T> dummy;
|
||||
return dummy;
|
||||
|
|
@ -103,6 +101,12 @@ namespace Nz
|
|||
return m_corners[corner];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const Vector3<T>* OrientedBox<T>::GetCorners() const
|
||||
{
|
||||
return &m_corners[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Checks whether this oriented box is valid
|
||||
* \return true if the oriented box has a strictly positive width, height and depth
|
||||
|
|
@ -205,18 +209,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String OrientedBox<T>::ToString() const
|
||||
std::string OrientedBox<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "OrientedBox(FLB: " << m_corners[BoxCorner_FarLeftBottom].ToString() << "\n"
|
||||
<< " FLT: " << m_corners[BoxCorner_FarLeftTop].ToString() << "\n"
|
||||
<< " FRB: " << m_corners[BoxCorner_FarRightBottom].ToString() << "\n"
|
||||
<< " FRT: " << m_corners[BoxCorner_FarRightTop].ToString() << "\n"
|
||||
<< " NLB: " << m_corners[BoxCorner_NearLeftBottom].ToString() << "\n"
|
||||
<< " NLT: " << m_corners[BoxCorner_NearLeftTop].ToString() << "\n"
|
||||
<< " NRB: " << m_corners[BoxCorner_NearRightBottom].ToString() << "\n"
|
||||
<< " NRT: " << m_corners[BoxCorner_NearRightTop].ToString() << ")\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -245,32 +243,6 @@ namespace Nz
|
|||
m_corners[i] = localBox.GetCorner(static_cast<BoxCorner>(i)) + translation;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts oriented box to pointer of Vector3 to its own corners
|
||||
* \return A pointer to the own corners
|
||||
*
|
||||
* \remark Access to index greather than BoxCorner_Max is undefined behavior
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
OrientedBox<T>::operator Vector3<T>* ()
|
||||
{
|
||||
return &m_corners[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts oriented box to pointer of Vector3 to its own corners
|
||||
* \return A const pointer to the own corners
|
||||
*
|
||||
* \remark Access to index greather than BoxCorner_Max is undefined behavior
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
OrientedBox<T>::operator const Vector3<T>* () const
|
||||
{
|
||||
return &m_corners[0];
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith corner of the oriented box
|
||||
* \return A reference to this corner
|
||||
|
|
@ -285,11 +257,11 @@ namespace Nz
|
|||
#if NAZARA_MATH_SAFE
|
||||
if (i > BoxCorner_Max)
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")";
|
||||
|
||||
NazaraError(ss);
|
||||
throw std::out_of_range(ss.ToString().ToStdString());
|
||||
NazaraError(ss.str());
|
||||
throw std::out_of_range(ss.str());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -310,11 +282,11 @@ namespace Nz
|
|||
#if NAZARA_MATH_SAFE
|
||||
if (i > BoxCorner_Max)
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << "Index out of range: (" << i << " >= " << BoxCorner_Max << ")";
|
||||
|
||||
NazaraError(ss);
|
||||
throw std::out_of_range(ss.ToString().ToStdString());
|
||||
NazaraError(ss.str());
|
||||
throw std::out_of_range(ss.str());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -465,9 +437,15 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::OrientedBox<T>& orientedBox)
|
||||
{
|
||||
return out << orientedBox.ToString();
|
||||
return out << "OrientedBox(FLB: " << orientedBox.GetCorner(Nz::BoxCorner_FarLeftBottom) << ",\n"
|
||||
<< " FLT: " << orientedBox.GetCorner(Nz::BoxCorner_FarLeftTop) << ",\n"
|
||||
<< " FRB: " << orientedBox.GetCorner(Nz::BoxCorner_FarRightBottom) << ",\n"
|
||||
<< " FRT: " << orientedBox.GetCorner(Nz::BoxCorner_FarRightTop) << ",\n"
|
||||
<< " NLB: " << orientedBox.GetCorner(Nz::BoxCorner_NearLeftBottom) << ",\n"
|
||||
<< " NLT: " << orientedBox.GetCorner(Nz::BoxCorner_NearLeftTop) << ",\n"
|
||||
<< " NRB: " << orientedBox.GetCorner(Nz::BoxCorner_NearRightBottom) << ",\n"
|
||||
<< " NRT: " << orientedBox.GetCorner(Nz::BoxCorner_NearRightTop) << ")\n";
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
#include "OrientedBox.hpp"
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
#ifndef NAZARA_PLANE_HPP
|
||||
#define NAZARA_PLANE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
|||
Plane& Set(const Vector3<T>& point1, const Vector3<T>& point2, const Vector3<T>& point3);
|
||||
template<typename U> Plane& Set(const Plane<U>& plane);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Plane& operator=(const Plane& other) = default;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,11 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -148,7 +146,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Plane<T>& Plane<T>::MakeXY()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -161,7 +159,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Plane<T>& Plane<T>::MakeXZ()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -174,7 +172,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Plane<T>& Plane<T>::MakeYZ()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -282,7 +280,7 @@ namespace Nz
|
|||
Plane<T>& Plane<T>::Set(const Plane<U>& plane)
|
||||
{
|
||||
normal.Set(plane.normal);
|
||||
distance = F(plane.distance);
|
||||
distance = T(plane.distance);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -293,11 +291,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Plane<T>::ToString() const
|
||||
std::string Plane<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Plane(Normal: " << normal.ToString() << "; Distance: " << distance << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -348,9 +347,9 @@ namespace Nz
|
|||
Plane<T> Plane<T>::Lerp(const Plane& from, const Plane& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Plane();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -461,9 +460,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Plane<T>& plane)
|
||||
{
|
||||
return out << plane.ToString();
|
||||
return out << "Plane(Normal: " << plane.normal << "; Distance: " << plane.distance << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
#ifndef NAZARA_QUATERNION_HPP
|
||||
#define NAZARA_QUATERNION_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Angle.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -63,7 +63,7 @@ namespace Nz
|
|||
RadianAngle<T> To2DAngle() const;
|
||||
EulerAngles<T> ToEulerAngles() const;
|
||||
//Matrix3<T> ToRotationMatrix() const;
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Quaternion& operator=(const Quaternion& quat) = default;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,17 +4,15 @@
|
|||
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Config.hpp>
|
||||
#include <Nazara/Math/EulerAngles.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -119,10 +117,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Quaternion<T>& Quaternion<T>::ComputeW()
|
||||
{
|
||||
T t = F(1.0) - SquaredMagnitude();
|
||||
T t = T(1.0) - SquaredMagnitude();
|
||||
|
||||
if (t < F(0.0))
|
||||
w = F(0.0);
|
||||
if (t < T(0.0))
|
||||
w = T(0.0);
|
||||
else
|
||||
w = -std::sqrt(t);
|
||||
|
||||
|
|
@ -230,9 +228,9 @@ namespace Nz
|
|||
Quaternion<T>& Quaternion<T>::Inverse()
|
||||
{
|
||||
T norm = SquaredMagnitude();
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / std::sqrt(norm);
|
||||
T invNorm = T(1.0) / std::sqrt(norm);
|
||||
|
||||
w *= invNorm;
|
||||
x *= -invNorm;
|
||||
|
|
@ -253,7 +251,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Quaternion<T>& Quaternion<T>::MakeIdentity()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -288,7 +286,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Quaternion<T>& Quaternion<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -319,9 +317,9 @@ namespace Nz
|
|||
Quaternion<T>& Quaternion<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = std::sqrt(SquaredMagnitude());
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
T invNorm = T(1.0) / norm;
|
||||
w *= invNorm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
|
|
@ -399,7 +397,7 @@ namespace Nz
|
|||
angle = DegreeToRadian(angle);
|
||||
#endif
|
||||
|
||||
angle /= F(2.0);
|
||||
angle /= T(2.0);
|
||||
|
||||
Vector3<T> normalizedAxis = axis.GetNormal();
|
||||
|
||||
|
|
@ -442,10 +440,10 @@ namespace Nz
|
|||
template<typename U>
|
||||
Quaternion<T>& Quaternion<T>::Set(const Quaternion<U>& quat)
|
||||
{
|
||||
w = F(quat.w);
|
||||
x = F(quat.x);
|
||||
y = F(quat.y);
|
||||
z = F(quat.z);
|
||||
w = T(quat.w);
|
||||
x = T(quat.x);
|
||||
y = T(quat.y);
|
||||
z = T(quat.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -488,17 +486,17 @@ namespace Nz
|
|||
EulerAngles<T> Quaternion<T>::ToEulerAngles() const
|
||||
{
|
||||
T test = x * y + z * w;
|
||||
if (test > F(0.499))
|
||||
if (test > T(0.499))
|
||||
// singularity at north pole
|
||||
return EulerAngles<T>(F(0.0), FromRadians(F(2.0) * std::atan2(x, w)), FromDegrees(F(90.0)));
|
||||
return EulerAngles<T>(T(0.0), FromRadians(T(2.0) * std::atan2(x, w)), FromDegrees(T(90.0)));
|
||||
|
||||
if (test < F(-0.499))
|
||||
if (test < T(-0.499))
|
||||
// singularity at south pole
|
||||
return EulerAngles<T>(F(0.0), FromRadians(F(-2.0) * std::atan2(x, w)), FromDegrees(F(-90.0)));
|
||||
return EulerAngles<T>(T(0.0), FromRadians(T(-2.0) * std::atan2(x, w)), FromDegrees(T(-90.0)));
|
||||
|
||||
return EulerAngles<T>(FromRadians(std::atan2(F(2.0) * x * w - F(2.0) * y * z, F(1.0) - F(2.0) * x * x - F(2.0) * z * z)),
|
||||
FromRadians(std::atan2(F(2.0) * y * w - F(2.0) * x * z, F(1.0) - F(2.0) * y * y - F(2.0) * z * z)),
|
||||
FromRadians(std::asin(F(2.0) * test)));
|
||||
return EulerAngles<T>(FromRadians(std::atan2(T(2.0) * x * w - T(2.0) * y * z, T(1.0) - T(2.0) * x * x - T(2.0) * z * z)),
|
||||
FromRadians(std::atan2(T(2.0) * y * w - T(2.0) * x * z, T(1.0) - T(2.0) * y * y - T(2.0) * z * z)),
|
||||
FromRadians(std::asin(T(2.0) * test)));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -507,11 +505,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Quaternion<T>::ToString() const
|
||||
std::string Quaternion<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -565,8 +564,8 @@ namespace Nz
|
|||
Vector3<T> quatVec(x, y, z);
|
||||
Vector3<T> uv = quatVec.CrossProduct(vec);
|
||||
Vector3<T> uuv = quatVec.CrossProduct(uv);
|
||||
uv *= F(2.0) * w;
|
||||
uuv *= F(2.0);
|
||||
uv *= T(2.0) * w;
|
||||
uuv *= T(2.0);
|
||||
|
||||
return vec + uv + uuv;
|
||||
}
|
||||
|
|
@ -715,9 +714,9 @@ namespace Nz
|
|||
Quaternion<T> Quaternion<T>::Lerp(const Quaternion& from, const Quaternion& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -784,9 +783,9 @@ namespace Nz
|
|||
Quaternion<T> Quaternion<T>::Slerp(const Quaternion& from, const Quaternion& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -794,7 +793,7 @@ namespace Nz
|
|||
Quaternion q;
|
||||
|
||||
T cosOmega = from.DotProduct(to);
|
||||
if (cosOmega < F(0.0))
|
||||
if (cosOmega < T(0.0))
|
||||
{
|
||||
// We invert everything
|
||||
q.Set(-to.w, -to.x, -to.y, -to.z);
|
||||
|
|
@ -804,21 +803,21 @@ namespace Nz
|
|||
q.Set(to);
|
||||
|
||||
T k0, k1;
|
||||
if (cosOmega > F(0.9999))
|
||||
if (cosOmega > T(0.9999))
|
||||
{
|
||||
// Linear interpolation to avoid division by zero
|
||||
k0 = F(1.0) - interpolation;
|
||||
k0 = T(1.0) - interpolation;
|
||||
k1 = interpolation;
|
||||
}
|
||||
else
|
||||
{
|
||||
T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega);
|
||||
T sinOmega = std::sqrt(T(1.0) - cosOmega*cosOmega);
|
||||
T omega = std::atan2(sinOmega, cosOmega);
|
||||
|
||||
// To avoid two divisions
|
||||
sinOmega = F(1.0)/sinOmega;
|
||||
sinOmega = T(1.0)/sinOmega;
|
||||
|
||||
k0 = std::sin((F(1.0) - interpolation) * omega) * sinOmega;
|
||||
k0 = std::sin((T(1.0) - interpolation) * omega) * sinOmega;
|
||||
k1 = std::sin(interpolation*omega) * sinOmega;
|
||||
}
|
||||
|
||||
|
|
@ -905,9 +904,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Quaternion<T>& quat)
|
||||
{
|
||||
return out << quat.ToString();
|
||||
return out << "Quaternion(" << quat.w << " | " << quat.x << ", " << quat.y << ", " << quat.z << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#ifndef NAZARA_RAY_HPP
|
||||
#define NAZARA_RAY_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Frustum.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
|
|
@ -15,6 +14,7 @@
|
|||
#include <Nazara/Math/Plane.hpp>
|
||||
#include <Nazara/Math/Sphere.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -57,7 +57,7 @@ namespace Nz
|
|||
template<typename U> Ray& Set(const Ray<U>& ray);
|
||||
template<typename U> Ray& Set(const Vector3<U>& origin, const Vector3<U>& direction);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Vector3<T> operator*(T lambda) const;
|
||||
Ray& operator=(const Ray& other) = default;
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -166,7 +164,7 @@ namespace Nz
|
|||
case Extend_Infinite:
|
||||
{
|
||||
if (closestHit)
|
||||
*closestHit = F(0.0);
|
||||
*closestHit = T(0.0);
|
||||
|
||||
if (furthestHit)
|
||||
*furthestHit = std::numeric_limits<T>::infinity();
|
||||
|
|
@ -178,7 +176,7 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
NazaraError("Invalid extend type (0x" + String::Number(volume.extend, 16) + ')');
|
||||
NazaraError("Invalid extend type (0x" + NumberToString(volume.extend, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +195,7 @@ namespace Nz
|
|||
bool Ray<T>::Intersect(const Box<T>& box, T* closestHit, T* furthestHit) const
|
||||
{
|
||||
// http://www.gamedev.net/topic/429443-obb-ray-and-obb-plane-intersection/
|
||||
T tfirst = F(0.0);
|
||||
T tfirst = T(0.0);
|
||||
T tlast = std::numeric_limits<T>::infinity();
|
||||
|
||||
Vector3<T> boxMin = box.GetMinimum();
|
||||
|
|
@ -210,7 +208,7 @@ namespace Nz
|
|||
T max = boxMax[i];
|
||||
T min = boxMin[i];
|
||||
|
||||
if (NumberEquals(dir, F(0.0)))
|
||||
if (NumberEquals(dir, T(0.0)))
|
||||
{
|
||||
if (ori < max && ori > min)
|
||||
continue;
|
||||
|
|
@ -256,7 +254,7 @@ namespace Nz
|
|||
{
|
||||
// http://www.opengl-tutorial.org/miscellaneous/clicking-on-objects/picking-with-custom-ray-obb-function/
|
||||
// Intersection method from Real-Time Rendering and Essential Mathematics for Games
|
||||
T tMin = F(0.0);
|
||||
T tMin = T(0.0);
|
||||
T tMax = std::numeric_limits<T>::infinity();
|
||||
|
||||
Vector3<T> boxMin = box.GetMinimum();
|
||||
|
|
@ -270,7 +268,7 @@ namespace Nz
|
|||
T e = axis.DotProduct(delta);
|
||||
T f = direction.DotProduct(axis);
|
||||
|
||||
if (!NumberEquals(f, F(0.0)))
|
||||
if (!NumberEquals(f, T(0.0)))
|
||||
{
|
||||
T t1 = (e + boxMin[i]) / f; // Intersection with the "left" plane
|
||||
T t2 = (e + boxMax[i]) / f; // Intersection with the "right" plane
|
||||
|
|
@ -296,7 +294,7 @@ namespace Nz
|
|||
}
|
||||
else
|
||||
// Rare case : the ray is almost parallel to the planes, so they don't have any "intersection"
|
||||
if (-e + boxMin[i] > F(0.0) || -e + boxMax[i] < F(0.0))
|
||||
if (-e + boxMin[i] > T(0.0) || -e + boxMax[i] < T(0.0))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -334,7 +332,7 @@ namespace Nz
|
|||
Matrix4<T> matrix(width.x, height.x, depth.x, corner.x,
|
||||
width.y, height.y, depth.y, corner.y,
|
||||
width.z, height.z, depth.z, corner.z,
|
||||
F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
|
||||
matrix.InverseAffine();
|
||||
|
||||
|
|
@ -361,11 +359,11 @@ namespace Nz
|
|||
bool Ray<T>::Intersect(const Plane<T>& plane, T* hit) const
|
||||
{
|
||||
T divisor = plane.normal.DotProduct(direction);
|
||||
if (NumberEquals(divisor, F(0.0)))
|
||||
if (NumberEquals(divisor, T(0.0)))
|
||||
return false; // Perpendicular
|
||||
|
||||
T lambda = -(plane.normal.DotProduct(origin) - plane.distance) / divisor; // The plane is ax + by + cz = d
|
||||
if (lambda < F(0.0))
|
||||
if (lambda < T(0.0))
|
||||
return false; // The plane is 'behind' the ray.
|
||||
|
||||
if (hit)
|
||||
|
|
@ -391,7 +389,7 @@ namespace Nz
|
|||
Vector3<T> sphereRay = sphere.GetPosition() - origin;
|
||||
T length = sphereRay.DotProduct(direction);
|
||||
|
||||
if (length < F(0.0))
|
||||
if (length < T(0.0))
|
||||
return false; // ray is perpendicular to the vector origin - center
|
||||
|
||||
T squaredDistance = sphereRay.GetSquaredLength() - length * length;
|
||||
|
|
@ -436,21 +434,21 @@ namespace Nz
|
|||
|
||||
Vector3<T> P = Vector3<T>::CrossProduct(direction, secondEdge);
|
||||
const T divisor = firstEdge.DotProduct(P);
|
||||
if (NumberEquals(divisor, F(0.0)))
|
||||
if (NumberEquals(divisor, T(0.0)))
|
||||
return false; // Ray lies in plane of triangle
|
||||
|
||||
Vector3<T> directionToPoint = origin - firstPoint;
|
||||
T u = directionToPoint.DotProduct(P) / divisor;
|
||||
if (u < F(0.0) || u > F(1.0))
|
||||
if (u < T(0.0) || u > T(1.0))
|
||||
return 0; // The intersection lies outside of the triangle
|
||||
|
||||
Vector3<T> Q = Vector3<T>::CrossProduct(directionToPoint, firstEdge);
|
||||
T v = directionToPoint.DotProduct(Q) / divisor;
|
||||
if (v < F(0.0) || u + v > F(1.0))
|
||||
if (v < T(0.0) || u + v > T(1.0))
|
||||
return 0; // The intersection lies outside of the triangle
|
||||
|
||||
T t = secondEdge.DotProduct(Q) / divisor;
|
||||
if (t > F(0.0))
|
||||
if (t > T(0.0))
|
||||
{
|
||||
if (hit)
|
||||
*hit = t;
|
||||
|
|
@ -574,16 +572,16 @@ namespace Nz
|
|||
T det = termOne * termFour - termTwo * termTwo;
|
||||
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(det, F(0.0)))
|
||||
if (NumberEquals(det, T(0.0)))
|
||||
{
|
||||
String error("Planes are parallel");
|
||||
std::string error("Planes are parallel");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
throw std::domain_error(error);
|
||||
}
|
||||
#endif
|
||||
|
||||
T invdet = F(1.0) / det;
|
||||
T invdet = T(1.0) / det;
|
||||
T fc0 = (termFour * -planeOne.distance + termTwo * planeTwo.distance) * invdet;
|
||||
T fc1 = (termOne * -planeTwo.distance + termTwo * planeOne.distance) * invdet;
|
||||
|
||||
|
|
@ -634,11 +632,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Ray<T>::ToString() const
|
||||
std::string Ray<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Ray(origin: " << origin.ToString() << ", direction: " << direction.ToString() << ")";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -799,9 +798,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Ray<T>& ray)
|
||||
{
|
||||
return out << ray.ToString();
|
||||
return out << "Ray(origin: " << ray.origin << ", direction: " << ray.direction << ")";
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@
|
|||
#ifndef NAZARA_RECT_HPP
|
||||
#define NAZARA_RECT_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Enums.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -59,7 +59,7 @@ namespace Nz
|
|||
Rect& Set(const Vector2<T>& vec1, const Vector2<T>& vec2);
|
||||
template<typename U> Rect& Set(const Rect<U>& rect);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
Rect& Translate(const Vector2<T>& translation);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -224,7 +222,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector2<T> Rect<T>::GetCenter() const
|
||||
{
|
||||
return GetPosition() + GetLengths() / F(2.0);
|
||||
return GetPosition() + GetLengths() / T(2.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -254,7 +252,7 @@ namespace Nz
|
|||
return Vector2<T>(x + width, y);
|
||||
}
|
||||
|
||||
NazaraError("Corner not handled (0x" + String::Number(corner, 16) + ')');
|
||||
NazaraError("Corner not handled (0x" + NumberToString(corner, 16) + ')');
|
||||
return Vector2<T>();
|
||||
}
|
||||
|
||||
|
|
@ -309,10 +307,10 @@ namespace Nz
|
|||
{
|
||||
Vector2<T> neg(GetPosition());
|
||||
|
||||
if (normal.x < F(0.0))
|
||||
if (normal.x < T(0.0))
|
||||
neg.x += width;
|
||||
|
||||
if (normal.y < F(0.0))
|
||||
if (normal.y < T(0.0))
|
||||
neg.y += height;
|
||||
|
||||
return neg;
|
||||
|
|
@ -345,10 +343,10 @@ namespace Nz
|
|||
{
|
||||
Vector2<T> pos(GetPosition());
|
||||
|
||||
if (normal.x > F(0.0))
|
||||
if (normal.x > T(0.0))
|
||||
pos.x += width;
|
||||
|
||||
if (normal.y > F(0.0))
|
||||
if (normal.y > T(0.0))
|
||||
pos.y += height;
|
||||
|
||||
return pos;
|
||||
|
|
@ -394,7 +392,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Rect<T>::IsValid() const
|
||||
{
|
||||
return width > F(0.0) && height > F(0.0);
|
||||
return width > T(0.0) && height > T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -407,10 +405,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Rect<T>& Rect<T>::MakeZero()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
width = F(0.0);
|
||||
height = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
width = T(0.0);
|
||||
height = T(0.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -428,8 +426,8 @@ namespace Nz
|
|||
template<typename T>
|
||||
Rect<T>& Rect<T>::Set(T Width, T Height)
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
width = Width;
|
||||
height = Height;
|
||||
|
||||
|
|
@ -521,10 +519,10 @@ namespace Nz
|
|||
template<typename U>
|
||||
Rect<T>& Rect<T>::Set(const Rect<U>& rect)
|
||||
{
|
||||
x = F(rect.x);
|
||||
y = F(rect.y);
|
||||
width = F(rect.width);
|
||||
height = F(rect.height);
|
||||
x = T(rect.x);
|
||||
y = T(rect.y);
|
||||
width = T(rect.width);
|
||||
height = T(rect.height);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -535,11 +533,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Rect<T>::ToString() const
|
||||
std::string Rect<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Rect(" << x << ", " << y << ", " << width << ", " << height << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -753,9 +752,9 @@ namespace Nz
|
|||
Rect<T> Rect<T>::Lerp(const Rect& from, const Rect& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -847,9 +846,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Rect<T>& rect)
|
||||
{
|
||||
return out << rect.ToString();
|
||||
return out << "Rect(" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
#ifndef NAZARA_SPHERE_HPP
|
||||
#define NAZARA_SPHERE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -57,7 +57,7 @@ namespace Nz
|
|||
Sphere& Set(const T sphere[4]);
|
||||
template<typename U> Sphere& Set(const Sphere<U>& sphere);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -306,7 +304,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
bool Sphere<T>::IsValid() const
|
||||
{
|
||||
return radius > F(0.0);
|
||||
return radius > T(0.0);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -319,10 +317,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Sphere<T>& Sphere<T>::MakeUnit()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
radius = F(1.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
radius = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -337,10 +335,10 @@ namespace Nz
|
|||
template<typename T>
|
||||
Sphere<T>& Sphere<T>::MakeZero()
|
||||
{
|
||||
x = F(0.0);
|
||||
y = F(0.0);
|
||||
z = F(0.0);
|
||||
radius = F(0.0);
|
||||
x = T(0.0);
|
||||
y = T(0.0);
|
||||
z = T(0.0);
|
||||
radius = T(0.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -390,7 +388,7 @@ namespace Nz
|
|||
{
|
||||
x = circle.x;
|
||||
y = circle.y;
|
||||
z = F(0.0);
|
||||
z = T(0.0);
|
||||
radius = circle.radius;
|
||||
|
||||
return *this;
|
||||
|
|
@ -426,10 +424,10 @@ namespace Nz
|
|||
template<typename U>
|
||||
Sphere<T>& Sphere<T>::Set(const Sphere<U>& sphere)
|
||||
{
|
||||
x = F(sphere.x);
|
||||
y = F(sphere.y);
|
||||
z = F(sphere.z);
|
||||
radius = F(sphere.radius);
|
||||
x = T(sphere.x);
|
||||
y = T(sphere.y);
|
||||
z = T(sphere.z);
|
||||
radius = T(sphere.radius);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -440,11 +438,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Sphere<T>::ToString() const
|
||||
std::string Sphere<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Sphere(" << x << ", " << y << ", " << z << "; " << radius << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -568,9 +567,9 @@ namespace Nz
|
|||
Sphere<T> Sphere<T>::Lerp(const Sphere& from, const Sphere& to, T interpolation)
|
||||
{
|
||||
#ifdef NAZARA_DEBUG
|
||||
if (interpolation < F(0.0) || interpolation > F(1.0))
|
||||
if (interpolation < T(0.0) || interpolation > T(1.0))
|
||||
{
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + String::Number(interpolation) + ')');
|
||||
NazaraError("Interpolation must be in range [0..1] (Got " + NumberToString(interpolation) + ')');
|
||||
return Zero();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -662,9 +661,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Sphere<T>& sphere)
|
||||
{
|
||||
return out << sphere.ToString();
|
||||
return out << "Sphere(" << sphere.x << ", " << sphere.y << ", " << sphere.z << "; " << sphere.radius << ')';
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@
|
|||
#ifndef NAZARA_VECTOR2_HPP
|
||||
#define NAZARA_VECTOR2_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -61,7 +63,7 @@ namespace Nz
|
|||
|
||||
T SquaredDistance(const Vector2& vec) const;
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -212,7 +210,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeUnit()
|
||||
{
|
||||
return Set(F(1.0), F(1.0));
|
||||
return Set(T(1.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -225,7 +223,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeUnitX()
|
||||
{
|
||||
return Set(F(1.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -238,7 +236,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeUnitY()
|
||||
{
|
||||
return Set(F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -251,7 +249,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -311,9 +309,9 @@ namespace Nz
|
|||
Vector2<T>& Vector2<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = GetLength();
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
T invNorm = T(1.0) / norm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
}
|
||||
|
|
@ -383,8 +381,8 @@ namespace Nz
|
|||
template<typename U>
|
||||
Vector2<T>& Vector2<T>::Set(const Vector2<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
x = T(vec.x);
|
||||
y = T(vec.y);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -442,11 +440,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Vector2<T>::ToString() const
|
||||
std::string Vector2<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Vector2(" << x << ", " << y << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -550,24 +549,11 @@ namespace Nz
|
|||
* \return A vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T> Vector2<T>::operator/(const Vector2& vec) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector2(x / vec.x, y / vec.y);
|
||||
}
|
||||
|
||||
|
|
@ -576,24 +562,11 @@ namespace Nz
|
|||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T> Vector2<T>::operator/(T scale) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector2(x / scale, y / scale);
|
||||
}
|
||||
|
||||
|
|
@ -666,24 +639,11 @@ namespace Nz
|
|||
* \return A reference to this vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to multiply components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::operator/=(const Vector2& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
|
||||
|
|
@ -695,24 +655,11 @@ namespace Nz
|
|||
* \return A reference to this vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector2<T>& Vector2<T>::operator/=(T scale)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
|
||||
|
|
@ -990,7 +937,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Vector2<T>& vec)
|
||||
{
|
||||
return out << vec.ToString();
|
||||
return out << "Vector2(" << vec.x << ", " << vec.y << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -1011,24 +958,11 @@ Nz::Vector2<T> operator*(T scale, const Nz::Vector2<T>& vec)
|
|||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0)))
|
||||
{
|
||||
Nz::String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Nz::Vector2<T>(scale / vec.x, scale / vec.y);
|
||||
}
|
||||
|
||||
|
|
@ -1055,6 +989,4 @@ namespace std
|
|||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@
|
|||
#ifndef NAZARA_VECTOR3_HPP
|
||||
#define NAZARA_VECTOR3_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -72,7 +74,7 @@ namespace Nz
|
|||
|
||||
T SquaredDistance(const Vector3& vec) const;
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
|
|
|||
|
|
@ -3,15 +3,13 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
/*!
|
||||
|
|
@ -126,17 +124,17 @@ namespace Nz
|
|||
T divisor = std::sqrt(GetSquaredLength() * vec.GetSquaredLength());
|
||||
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(divisor, F(0.0)))
|
||||
if (NumberEquals(divisor, T(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
std::string error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
throw std::domain_error(std::move(error));
|
||||
}
|
||||
#endif
|
||||
|
||||
T alpha = DotProduct(vec) / divisor;
|
||||
return FromRadians(std::acos(Clamp(alpha, F(-1.0), F(1.0))));
|
||||
return FromRadians(std::acos(Clamp(alpha, T(-1.0), T(1.0))));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -244,7 +242,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeBackward()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -256,7 +254,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeDown()
|
||||
{
|
||||
return Set(F(0.0), F(-1.0), F(0.0));
|
||||
return Set(T(0.0), T(-1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -268,7 +266,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeForward()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(-1.0));
|
||||
return Set(T(0.0), T(0.0), T(-1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -280,7 +278,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeLeft()
|
||||
{
|
||||
return Set(F(-1.0), F(0.0), F(0.0));
|
||||
return Set(T(-1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -292,7 +290,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeRight()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -304,7 +302,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnit()
|
||||
{
|
||||
return Set(F(1.0), F(1.0), F(1.0));
|
||||
return Set(T(1.0), T(1.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -316,7 +314,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnitX()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -328,7 +326,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnitY()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -340,7 +338,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUnitZ()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -352,7 +350,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeUp()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -364,7 +362,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(0.0));
|
||||
return Set(T(0.0), T(0.0), T(0.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -427,9 +425,9 @@ namespace Nz
|
|||
Vector3<T>& Vector3<T>::Normalize(T* length)
|
||||
{
|
||||
T norm = GetLength();
|
||||
if (norm > F(0.0))
|
||||
if (norm > T(0.0))
|
||||
{
|
||||
T invNorm = F(1.0) / norm;
|
||||
T invNorm = T(1.0) / norm;
|
||||
x *= invNorm;
|
||||
y *= invNorm;
|
||||
z *= invNorm;
|
||||
|
|
@ -533,9 +531,9 @@ namespace Nz
|
|||
template<typename U>
|
||||
Vector3<T>& Vector3<T>::Set(const Vector3<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
z = F(vec.z);
|
||||
x = T(vec.x);
|
||||
y = T(vec.y);
|
||||
z = T(vec.z);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -575,11 +573,12 @@ namespace Nz
|
|||
* \return A string representation of the object: "Vector3(x, y, z)"
|
||||
*/
|
||||
template<typename T>
|
||||
String Vector3<T>::ToString() const
|
||||
std::string Vector3<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Vector3(" << x << ", " << y << ", " << z <<')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -677,23 +676,10 @@ namespace Nz
|
|||
* \return A vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T> Vector3<T>::operator/(const Vector3& vec) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector3(x / vec.x, y / vec.y, z / vec.z);
|
||||
}
|
||||
|
||||
|
|
@ -702,23 +688,10 @@ namespace Nz
|
|||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T> Vector3<T>::operator/(T scale) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector3(x / scale, y / scale, z / scale);
|
||||
}
|
||||
|
||||
|
|
@ -791,21 +764,10 @@ namespace Nz
|
|||
* \return A reference to this vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to multiply components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::operator/=(const Vector3& vec)
|
||||
{
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
z /= vec.z;
|
||||
|
|
@ -818,21 +780,10 @@ namespace Nz
|
|||
* \return A reference to this vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
template<typename T>
|
||||
Vector3<T>& Vector3<T>::operator/=(T scale)
|
||||
{
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
z /= scale;
|
||||
|
|
@ -1253,7 +1204,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Vector3<T>& vec)
|
||||
{
|
||||
return out << vec.ToString();
|
||||
return out << "Vector3(" << vec.x << ", " << vec.y << ", " << vec.z << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -1274,24 +1225,11 @@ Nz::Vector3<T> operator*(T scale, const Nz::Vector3<T>& vec)
|
|||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (Nz::NumberEquals(vec.x, F(0.0)) || Nz::NumberEquals(vec.y, F(0.0)) || Nz::NumberEquals(vec.z, F(0.0)))
|
||||
{
|
||||
Nz::String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Nz::Vector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
|
||||
}
|
||||
|
||||
|
|
@ -1320,6 +1258,4 @@ namespace std
|
|||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@
|
|||
#ifndef NAZARA_VECTOR4_HPP
|
||||
#define NAZARA_VECTOR4_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/TypeTag.hpp>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -59,7 +61,7 @@ namespace Nz
|
|||
Vector4& Set(const Vector3<T>& vec, T W = 1.0);
|
||||
template<typename U> Vector4& Set(const Vector4<U>& vec);
|
||||
|
||||
String ToString() const;
|
||||
std::string ToString() const;
|
||||
|
||||
T& operator[](std::size_t i);
|
||||
T operator[](std::size_t i) const;
|
||||
|
|
|
|||
|
|
@ -3,16 +3,14 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/StringStream.hpp>
|
||||
#include <Nazara/Math/Algorithm.hpp>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D
|
||||
|
||||
#define F(a) static_cast<T>(a)
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
||||
|
|
@ -188,7 +186,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeUnitX()
|
||||
{
|
||||
return Set(F(1.0), F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(1.0), T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -201,7 +199,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeUnitY()
|
||||
{
|
||||
return Set(F(0.0), F(1.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(1.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -214,7 +212,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeUnitZ()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(1.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(1.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -227,7 +225,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::MakeZero()
|
||||
{
|
||||
return Set(F(0.0), F(0.0), F(0.0), F(1.0));
|
||||
return Set(T(0.0), T(0.0), T(0.0), T(1.0));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -296,7 +294,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::Normalize(T* length)
|
||||
{
|
||||
T invLength = F(1.0)/w;
|
||||
T invLength = T(1.0)/w;
|
||||
x *= invLength; // Warning, change this logic will break Frustum::Extract
|
||||
y *= invLength;
|
||||
z *= invLength;
|
||||
|
|
@ -304,7 +302,7 @@ namespace Nz
|
|||
if (length)
|
||||
*length = w;
|
||||
|
||||
w = F(1.0);
|
||||
w = T(1.0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -472,10 +470,10 @@ namespace Nz
|
|||
template<typename U>
|
||||
Vector4<T>& Vector4<T>::Set(const Vector4<U>& vec)
|
||||
{
|
||||
x = F(vec.x);
|
||||
y = F(vec.y);
|
||||
z = F(vec.z);
|
||||
w = F(vec.w);
|
||||
x = T(vec.x);
|
||||
y = T(vec.y);
|
||||
z = T(vec.z);
|
||||
w = T(vec.w);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -486,11 +484,12 @@ namespace Nz
|
|||
*/
|
||||
|
||||
template<typename T>
|
||||
String Vector4<T>::ToString() const
|
||||
std::string Vector4<T>::ToString() const
|
||||
{
|
||||
StringStream ss;
|
||||
std::ostringstream ss;
|
||||
ss << *this;
|
||||
|
||||
return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')';
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -594,24 +593,11 @@ namespace Nz
|
|||
* \return A vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T> Vector4<T>::operator/(const Vector4& vec) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w);
|
||||
}
|
||||
|
||||
|
|
@ -620,24 +606,11 @@ namespace Nz
|
|||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T> Vector4<T>::operator/(T scale) const
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Vector4(x / scale, y / scale, z / scale, w / scale);
|
||||
}
|
||||
|
||||
|
|
@ -718,24 +691,11 @@ namespace Nz
|
|||
* \return A reference to this vector where components are the quotient of this vector and the other one
|
||||
*
|
||||
* \param vec The other vector to multiply components with
|
||||
*
|
||||
* \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::operator/=(const Vector4& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= vec.x;
|
||||
y /= vec.y;
|
||||
z /= vec.z;
|
||||
|
|
@ -749,24 +709,11 @@ namespace Nz
|
|||
* \return A reference to this vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Vector4<T>& Vector4<T>::operator/=(T scale)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(scale, F(0.0)))
|
||||
{
|
||||
String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
x /= scale;
|
||||
y /= scale;
|
||||
z /= scale;
|
||||
|
|
@ -1062,7 +1009,7 @@ namespace Nz
|
|||
template<typename T>
|
||||
std::ostream& operator<<(std::ostream& out, const Nz::Vector4<T>& vec)
|
||||
{
|
||||
return out << vec.ToString();
|
||||
return out << "Vector4(" << vec.x << ", " << vec.y << ", " << vec.z << ", " << vec.w << ')';
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -1084,24 +1031,11 @@ Nz::Vector4<T> operator*(T scale, const Nz::Vector4<T>& vec)
|
|||
* \return A vector where components are the quotient of this vector and the scalar
|
||||
*
|
||||
* \param scale The scalar to divide components with
|
||||
*
|
||||
* \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined
|
||||
* \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec)
|
||||
{
|
||||
#if NAZARA_MATH_SAFE
|
||||
if (NumberEquals(vec.x, F(0.0)) || NumberEquals(vec.y, F(0.0)) || NumberEquals(vec.z, F(0.0)) || NumberEquals(vec.w, F(0.0)))
|
||||
{
|
||||
Nz::String error("Division by zero");
|
||||
|
||||
NazaraError(error);
|
||||
throw std::domain_error(error.ToStdString());
|
||||
}
|
||||
#endif
|
||||
|
||||
return Nz::Vector4<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
|
||||
}
|
||||
|
||||
|
|
@ -1130,6 +1064,4 @@ namespace std
|
|||
};
|
||||
}
|
||||
|
||||
#undef F
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@
|
|||
#define NAZARA_IPADDRESS_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Network/Config.hpp>
|
||||
#include <Nazara/Network/Enums.hpp>
|
||||
#include <array>
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -30,12 +31,13 @@ namespace Nz
|
|||
inline IpAddress(const UInt8& a, const UInt8& b, const UInt8& c, const UInt8& d, UInt16 port = 0);
|
||||
inline IpAddress(const UInt16& a, const UInt16& b, const UInt16& c, const UInt16& d, const UInt16& e, const UInt16& f, const UInt16& g, const UInt16& h, UInt16 port = 0);
|
||||
inline explicit IpAddress(const char* address);
|
||||
inline explicit IpAddress(const String& address);
|
||||
inline explicit IpAddress(const std::string& address);
|
||||
IpAddress(const IpAddress&) = default;
|
||||
IpAddress(IpAddress&&) noexcept = default;
|
||||
~IpAddress() = default;
|
||||
|
||||
bool BuildFromAddress(const char* address);
|
||||
inline bool BuildFromAddress(const std::string& address);
|
||||
|
||||
inline UInt16 GetPort() const;
|
||||
inline NetProtocol GetProtocol() const;
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ namespace Nz
|
|||
* \param address Hostname or textual IP address
|
||||
*/
|
||||
|
||||
inline IpAddress::IpAddress(const char* address)
|
||||
inline IpAddress::IpAddress(const char* address) :
|
||||
IpAddress()
|
||||
{
|
||||
BuildFromAddress(address);
|
||||
}
|
||||
|
|
@ -88,17 +89,21 @@ namespace Nz
|
|||
*
|
||||
* \param address Hostname or textual IP address
|
||||
*/
|
||||
|
||||
inline IpAddress::IpAddress(const String& address)
|
||||
inline IpAddress::IpAddress(const std::string& address) :
|
||||
IpAddress()
|
||||
{
|
||||
BuildFromAddress(address.GetConstBuffer());
|
||||
BuildFromAddress(address);
|
||||
}
|
||||
|
||||
inline bool IpAddress::BuildFromAddress(const std::string& address)
|
||||
{
|
||||
return BuildFromAddress(address.c_str());
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the port
|
||||
* \return Port attached to the IP address
|
||||
*/
|
||||
|
||||
inline UInt16 IpAddress::GetPort() const
|
||||
{
|
||||
return m_port;
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ namespace Nz
|
|||
return false;
|
||||
}
|
||||
|
||||
NazaraError("PacketReliability not handled (0x" + String::Number(reliability, 16) + ')');
|
||||
NazaraError("PacketReliability not handled (0x" + NumberToString(reliability, 16) + ')');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#define NAZARA_UTILS_OPENGL_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Wrapper/Loader.hpp>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include <Nazara/OpenGLRenderer/Utils.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Core/StringExt.hpp>
|
||||
#include <Nazara/OpenGLRenderer/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -20,7 +20,7 @@ namespace Nz
|
|||
default: break;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled PixelFormat 0x" + String::Number(UnderlyingCast(pixelFormat), 16));
|
||||
NazaraError("Unhandled PixelFormat 0x" + NumberToString(UnderlyingCast(pixelFormat), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ namespace Nz
|
|||
case BlendFunc_Zero: return GL_ZERO;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled BlendFunc 0x" + String::Number(UnderlyingCast(blendFunc), 16));
|
||||
NazaraError("Unhandled BlendFunc 0x" + NumberToString(UnderlyingCast(blendFunc), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ namespace Nz
|
|||
case FaceSide_FrontAndBack: return GL_FRONT_AND_BACK;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled FaceSide 0x" + String::Number(UnderlyingCast(filter), 16));
|
||||
NazaraError("Unhandled FaceSide 0x" + NumberToString(UnderlyingCast(filter), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ namespace Nz
|
|||
case RendererComparison_NotEqual: return GL_NOTEQUAL;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled RendererComparison 0x" + String::Number(UnderlyingCast(comparison), 16));
|
||||
NazaraError("Unhandled RendererComparison 0x" + NumberToString(UnderlyingCast(comparison), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ namespace Nz
|
|||
case SamplerFilter::SamplerFilter_Nearest: return GL_NEAREST;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(filter), 16));
|
||||
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(filter), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -102,7 +102,7 @@ namespace Nz
|
|||
case SamplerMipmapMode_Nearest: return GL_LINEAR_MIPMAP_NEAREST;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(mipmapFilter), 16));
|
||||
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -114,12 +114,12 @@ namespace Nz
|
|||
case SamplerMipmapMode_Nearest: return GL_NEAREST_MIPMAP_NEAREST;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(mipmapFilter), 16));
|
||||
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(mipmapFilter), 16));
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
NazaraError("Unhandled SamplerFilter 0x" + String::Number(UnderlyingCast(minFilter), 16));
|
||||
NazaraError("Unhandled SamplerFilter 0x" + NumberToString(UnderlyingCast(minFilter), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +132,7 @@ namespace Nz
|
|||
case SamplerWrap::SamplerWrap_Repeat: return GL_REPEAT;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled SamplerWrap 0x" + String::Number(UnderlyingCast(wrapMode), 16));
|
||||
NazaraError("Unhandled SamplerWrap 0x" + NumberToString(UnderlyingCast(wrapMode), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +144,7 @@ namespace Nz
|
|||
case ShaderStageType::Vertex: return GL_VERTEX_SHADER;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled ShaderStageType 0x" + String::Number(UnderlyingCast(stageType), 16));
|
||||
NazaraError("Unhandled ShaderStageType 0x" + NumberToString(UnderlyingCast(stageType), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ namespace Nz
|
|||
case StencilOperation_Zero: return GL_ZERO;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled StencilOperation 0x" + String::Number(UnderlyingCast(stencilOp), 16));
|
||||
NazaraError("Unhandled StencilOperation 0x" + NumberToString(UnderlyingCast(stencilOp), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ namespace Nz
|
|||
case GL::BufferTarget::Uniform: return GL_UNIFORM_BUFFER;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled GL::BufferTarget 0x" + String::Number(UnderlyingCast(bufferTarget), 16));
|
||||
NazaraError("Unhandled GL::BufferTarget 0x" + NumberToString(UnderlyingCast(bufferTarget), 16));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +194,7 @@ namespace Nz
|
|||
case GL::TextureTarget::Target3D: return GL_TEXTURE_3D;
|
||||
}
|
||||
|
||||
NazaraError("Unhandled GL::TextureTarget 0x" + String::Number(UnderlyingCast(textureTarget), 16));
|
||||
NazaraError("Unhandled GL::TextureTarget 0x" + NumberToString(UnderlyingCast(textureTarget), 16));
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Physics3D/Config.hpp>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class NewtonBody;
|
||||
|
|
@ -36,13 +36,13 @@ namespace Nz
|
|||
PhysWorld3D(PhysWorld3D&&) noexcept = default;
|
||||
~PhysWorld3D();
|
||||
|
||||
int CreateMaterial(String name = String());
|
||||
int CreateMaterial(std::string name = {});
|
||||
|
||||
void ForEachBodyInAABB(const Boxf& box, const BodyIterator& iterator);
|
||||
|
||||
Vector3f GetGravity() const;
|
||||
NewtonWorld* GetHandle() const;
|
||||
int GetMaterial(const String& name);
|
||||
int GetMaterial(const std::string& name);
|
||||
std::size_t GetMaxStepCount() const;
|
||||
float GetStepSize() const;
|
||||
unsigned int GetThreadCount() const;
|
||||
|
|
@ -75,7 +75,7 @@ namespace Nz
|
|||
static void ProcessContact(const NewtonJoint* const contact, float timestep, int threadIndex);
|
||||
|
||||
std::unordered_map<Nz::UInt64, std::unique_ptr<Callback>> m_callbacks;
|
||||
std::unordered_map<Nz::String, int> m_materialIds;
|
||||
std::unordered_map<std::string, int> m_materialIds;
|
||||
std::size_t m_maxStepCount;
|
||||
MovablePtr<NewtonWorld> m_world;
|
||||
Vector3f m_gravity;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace Nz
|
|||
void SetLinearVelocity(const Vector3f& velocity);
|
||||
void SetMass(float mass);
|
||||
void SetMassCenter(const Vector3f& center);
|
||||
void SetMaterial(const String& materialName);
|
||||
void SetMaterial(const std::string& materialName);
|
||||
void SetMaterial(int materialIndex);
|
||||
void SetPosition(const Vector3f& position);
|
||||
void SetRotation(const Quaternionf& rotation);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#define NAZARA_JOYSTICK_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
#define NAZARA_KEYBOARD_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Platform/Config.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -319,8 +319,8 @@ namespace Nz
|
|||
Keyboard() = delete;
|
||||
~Keyboard() = delete;
|
||||
|
||||
static String GetKeyName(Scancode scancode);
|
||||
static String GetKeyName(VKey key);
|
||||
static std::string GetKeyName(Scancode scancode);
|
||||
static std::string GetKeyName(VKey key);
|
||||
static bool IsKeyPressed(Scancode scancode);
|
||||
static bool IsKeyPressed(VKey key);
|
||||
static void StartTextInput();
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Platform/Config.hpp>
|
||||
#include <Nazara/Platform/Cursor.hpp>
|
||||
|
|
@ -38,7 +37,7 @@ namespace Nz
|
|||
|
||||
public:
|
||||
Window();
|
||||
inline Window(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||
inline Window(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default);
|
||||
inline explicit Window(void* handle);
|
||||
Window(const Window&) = delete;
|
||||
Window(Window&& window);
|
||||
|
|
@ -46,7 +45,7 @@ namespace Nz
|
|||
|
||||
inline void Close();
|
||||
|
||||
bool Create(VideoMode mode, const String& title, WindowStyleFlags style = WindowStyle_Default);
|
||||
bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default);
|
||||
bool Create(void* handle);
|
||||
|
||||
void Destroy();
|
||||
|
|
@ -66,7 +65,7 @@ namespace Nz
|
|||
Vector2ui GetSize() const;
|
||||
WindowStyleFlags GetStyle() const;
|
||||
WindowHandle GetSystemHandle() const;
|
||||
String GetTitle() const;
|
||||
std::string GetTitle() const;
|
||||
|
||||
bool HasFocus() const;
|
||||
|
||||
|
|
@ -97,7 +96,7 @@ namespace Nz
|
|||
void SetSize(const Vector2i& size);
|
||||
void SetSize(unsigned int width, unsigned int height);
|
||||
void SetStayOnTop(bool stayOnTop);
|
||||
void SetTitle(const String& title);
|
||||
void SetTitle(const std::string& title);
|
||||
void SetVisible(bool visible);
|
||||
|
||||
NAZARA_DEPRECATED("Event pooling/waiting is deprecated, please use the EventHandler system")
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Nz
|
|||
* \class Nz::Window
|
||||
*/
|
||||
|
||||
inline Window::Window(VideoMode mode, const String& title, WindowStyleFlags style) :
|
||||
inline Window::Window(VideoMode mode, const std::string& title, WindowStyleFlags style) :
|
||||
Window()
|
||||
{
|
||||
ErrorFlags flags(ErrorFlag_ThrowException, true);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#define NAZARA_RENDERDEVICE_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Renderer/Enums.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -16,7 +15,7 @@ namespace Nz
|
|||
struct RenderDeviceInfo
|
||||
{
|
||||
RenderDeviceType type;
|
||||
String name;
|
||||
std::string name;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ namespace Nz
|
|||
{
|
||||
public:
|
||||
inline RenderWindow();
|
||||
inline RenderWindow(VideoMode mode, const String &title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters ¶meters = RenderWindowParameters());
|
||||
inline RenderWindow(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
|
||||
inline explicit RenderWindow(void* handle, const RenderWindowParameters ¶meters = RenderWindowParameters());
|
||||
inline ~RenderWindow();
|
||||
|
||||
inline bool Create(VideoMode mode, const String &title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters ¶meters = RenderWindowParameters());
|
||||
inline bool Create(VideoMode mode, const std::string& title, WindowStyleFlags style = WindowStyle_Default, const RenderWindowParameters& parameters = RenderWindowParameters());
|
||||
inline bool Create(void* handle, const RenderWindowParameters ¶meters = RenderWindowParameters());
|
||||
|
||||
void Display();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Nz
|
|||
{
|
||||
}
|
||||
|
||||
inline RenderWindow::RenderWindow(VideoMode mode, const String& title, WindowStyleFlags style, const RenderWindowParameters& parameters) :
|
||||
inline RenderWindow::RenderWindow(VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters) :
|
||||
RenderWindow()
|
||||
{
|
||||
ErrorFlags errFlags(ErrorFlag_ThrowException, true);
|
||||
|
|
@ -32,7 +32,7 @@ namespace Nz
|
|||
Destroy();
|
||||
}
|
||||
|
||||
inline bool RenderWindow::Create(VideoMode mode, const String& title, WindowStyleFlags style, const RenderWindowParameters& parameters)
|
||||
inline bool RenderWindow::Create(VideoMode mode, const std::string& title, WindowStyleFlags style, const RenderWindowParameters& parameters)
|
||||
{
|
||||
m_parameters = parameters;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Shader/ShaderExpressionType.hpp>
|
||||
#include <Nazara/Core/Algorithm.hpp>
|
||||
#include <Nazara/Shader/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -17,7 +18,7 @@ namespace Nz
|
|||
else if constexpr (std::is_same_v<T, std::string>)
|
||||
return false;
|
||||
else
|
||||
static_assert(AlwaysFalse<U>::value, "non-exhaustive visitor");
|
||||
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
|
||||
|
||||
}, type);
|
||||
}
|
||||
|
|
@ -98,7 +99,7 @@ namespace Nz
|
|||
else if constexpr (std::is_same_v<T, std::string>)
|
||||
return true;
|
||||
else
|
||||
static_assert(AlwaysFalse<U>::value, "non-exhaustive visitor");
|
||||
static_assert(AlwaysFalse<T>::value, "non-exhaustive visitor");
|
||||
|
||||
}, type);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@
|
|||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/Signal.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -67,23 +67,23 @@ namespace Nz
|
|||
|
||||
std::size_t GetFrameCount() const;
|
||||
std::size_t GetJointCount() const;
|
||||
Sequence* GetSequence(const String& sequenceName);
|
||||
Sequence* GetSequence(const std::string& sequenceName);
|
||||
Sequence* GetSequence(std::size_t index);
|
||||
const Sequence* GetSequence(const String& sequenceName) const;
|
||||
const Sequence* GetSequence(const std::string& sequenceName) const;
|
||||
const Sequence* GetSequence(std::size_t index) const;
|
||||
std::size_t GetSequenceCount() const;
|
||||
std::size_t GetSequenceIndex(const String& sequenceName) const;
|
||||
std::size_t GetSequenceIndex(const std::string& sequenceName) const;
|
||||
SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0);
|
||||
const SequenceJoint* GetSequenceJoints(std::size_t frameIndex = 0) const;
|
||||
AnimationType GetType() const;
|
||||
|
||||
bool HasSequence(const String& sequenceName) const;
|
||||
bool HasSequence(const std::string& sequenceName) const;
|
||||
bool HasSequence(std::size_t index = 0) const;
|
||||
|
||||
bool IsLoopPointInterpolationEnabled() const;
|
||||
bool IsValid() const;
|
||||
|
||||
void RemoveSequence(const String& sequenceName);
|
||||
void RemoveSequence(const std::string& sequenceName);
|
||||
void RemoveSequence(std::size_t index);
|
||||
|
||||
template<typename... Args> static AnimationRef New(Args&&... args);
|
||||
|
|
|
|||
|
|
@ -64,18 +64,18 @@ namespace Nz
|
|||
const std::shared_ptr<AbstractAtlas>& GetAtlas() const;
|
||||
std::size_t GetCachedGlyphCount(unsigned int characterSize, TextStyleFlags style, float outlineThickness) const;
|
||||
std::size_t GetCachedGlyphCount() const;
|
||||
String GetFamilyName() const;
|
||||
std::string GetFamilyName() const;
|
||||
int GetKerning(unsigned int characterSize, char32_t first, char32_t second) const;
|
||||
const Glyph& GetGlyph(unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const;
|
||||
unsigned int GetGlyphBorder() const;
|
||||
unsigned int GetMinimumStepSize() const;
|
||||
const SizeInfo& GetSizeInfo(unsigned int characterSize) const;
|
||||
String GetStyleName() const;
|
||||
std::string GetStyleName() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, char32_t character) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const String& characterSet) const;
|
||||
bool Precache(unsigned int characterSize, TextStyleFlags style, float outlineThickness, const std::string& characterSet) const;
|
||||
|
||||
void SetAtlas(const std::shared_ptr<AbstractAtlas>& atlas);
|
||||
void SetGlyphBorder(unsigned int borderSize);
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
#define NAZARA_FONTDATA_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -24,8 +24,8 @@ namespace Nz
|
|||
|
||||
virtual bool ExtractGlyph(unsigned int characterSize, char32_t character, TextStyleFlags style, float outlineThickness, FontGlyph* dst) = 0;
|
||||
|
||||
virtual String GetFamilyName() const = 0;
|
||||
virtual String GetStyleName() const = 0;
|
||||
virtual std::string GetFamilyName() const = 0;
|
||||
virtual std::string GetStyleName() const = 0;
|
||||
|
||||
virtual bool HasKerning() const = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Nz
|
|||
{
|
||||
Int32 parent;
|
||||
Quaternionf bindOrient;
|
||||
String name;
|
||||
std::string name;
|
||||
Vector3f bindPos;
|
||||
UInt32 flags;
|
||||
UInt32 index;
|
||||
|
|
@ -57,12 +57,12 @@ namespace Nz
|
|||
|
||||
private:
|
||||
bool Advance(bool required = true);
|
||||
void Error(const String& message);
|
||||
void Error(const std::string& message);
|
||||
bool ParseBaseframe();
|
||||
bool ParseBounds();
|
||||
bool ParseFrame();
|
||||
bool ParseHierarchy();
|
||||
void Warning(const String& message);
|
||||
void Warning(const std::string& message);
|
||||
void UnrecognizedLine(bool error = false);
|
||||
|
||||
std::vector<float> m_animatedComponents;
|
||||
|
|
@ -70,7 +70,7 @@ namespace Nz
|
|||
std::vector<Joint> m_joints;
|
||||
Stream& m_stream;
|
||||
StreamOptionFlags m_streamFlags;
|
||||
String m_currentLine;
|
||||
std::string m_currentLine;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_frameIndex;
|
||||
unsigned int m_frameRate;
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@
|
|||
#define NAZARA_FORMATS_MD5MESHPARSER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -22,9 +22,9 @@ namespace Nz
|
|||
public:
|
||||
struct Joint
|
||||
{
|
||||
std::string name;
|
||||
Int32 parent;
|
||||
Quaternionf bindOrient;
|
||||
String name;
|
||||
Vector3f bindPos;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ namespace Nz
|
|||
std::unordered_map<std::string, Material> m_materials;
|
||||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
mutable StringStream m_outputStream;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ namespace Nz
|
|||
void MTLParser::Emit(const T& text) const
|
||||
{
|
||||
m_outputStream << text;
|
||||
if (m_outputStream.GetBufferSize() > 1024 * 1024)
|
||||
if (m_outputStream.rdbuf()->str().size() > 1024 * 1024)
|
||||
Flush();
|
||||
}
|
||||
|
||||
|
|
@ -58,8 +58,8 @@ namespace Nz
|
|||
|
||||
inline void MTLParser::Flush() const
|
||||
{
|
||||
m_currentStream->Write(m_outputStream);
|
||||
m_outputStream.Clear();
|
||||
m_currentStream->Write(std::move(m_outputStream).str());
|
||||
m_outputStream.str({});
|
||||
}
|
||||
|
||||
inline void MTLParser::Warning(const std::string& message)
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace Nz
|
|||
mutable Stream* m_currentStream;
|
||||
std::string m_currentLine;
|
||||
std::filesystem::path m_mtlLib;
|
||||
mutable StringStream m_outputStream;
|
||||
mutable std::ostringstream m_outputStream;
|
||||
bool m_keepLastLine;
|
||||
unsigned int m_lineCount;
|
||||
unsigned int m_errorCount;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Formats/OBJParser.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
|
|
@ -135,7 +136,7 @@ namespace Nz
|
|||
void OBJParser::Emit(const T& text) const
|
||||
{
|
||||
m_outputStream << text;
|
||||
if (m_outputStream.GetBufferSize() > 1024 * 1024)
|
||||
if (m_outputStream.rdbuf()->str().size() > 1024 * 1024)
|
||||
Flush();
|
||||
}
|
||||
|
||||
|
|
@ -158,8 +159,8 @@ namespace Nz
|
|||
|
||||
inline void OBJParser::Flush() const
|
||||
{
|
||||
m_currentStream->Write(m_outputStream);
|
||||
m_outputStream.Clear();
|
||||
m_currentStream->Write(std::move(m_outputStream).str());
|
||||
m_outputStream.str({});
|
||||
}
|
||||
|
||||
inline void OBJParser::Warning(const std::string& message)
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@
|
|||
#define NAZARA_JOINT_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Utility/Node.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -26,13 +26,13 @@ namespace Nz
|
|||
void EnsureSkinningMatrixUpdate() const;
|
||||
|
||||
const Matrix4f& GetInverseBindMatrix() const;
|
||||
String GetName() const;
|
||||
const std::string& GetName() const;
|
||||
Skeleton* GetSkeleton();
|
||||
const Skeleton* GetSkeleton() const;
|
||||
const Matrix4f& GetSkinningMatrix() const;
|
||||
|
||||
void SetInverseBindMatrix(const Matrix4f& matrix);
|
||||
void SetName(const String& name);
|
||||
void SetName(std::string name);
|
||||
|
||||
private:
|
||||
void InvalidateNode() override;
|
||||
|
|
@ -40,7 +40,7 @@ namespace Nz
|
|||
|
||||
Matrix4f m_inverseBindMatrix;
|
||||
mutable Matrix4f m_skinningMatrix;
|
||||
String m_name;
|
||||
std::string m_name;
|
||||
Skeleton* m_skeleton;
|
||||
mutable bool m_skinningMatrixUpdated;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
#include <Nazara/Core/ResourceManager.hpp>
|
||||
#include <Nazara/Core/ResourceParameters.hpp>
|
||||
#include <Nazara/Core/ResourceSaver.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/Bitset.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/Config.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <functional>
|
||||
|
|
@ -25,9 +24,9 @@ namespace Nz
|
|||
{
|
||||
inline PixelFormatDescription();
|
||||
inline PixelFormatDescription(PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0);
|
||||
inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType);
|
||||
inline PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp = 0);
|
||||
|
||||
inline void Clear();
|
||||
|
||||
|
|
@ -38,6 +37,7 @@ namespace Nz
|
|||
|
||||
inline bool Validate() const;
|
||||
|
||||
std::string name;
|
||||
// Warning: Masks bit order is reversed
|
||||
Bitset<> redMask;
|
||||
Bitset<> greenMask;
|
||||
|
|
@ -48,7 +48,6 @@ namespace Nz
|
|||
PixelFormatSubType greenType;
|
||||
PixelFormatSubType blueType;
|
||||
PixelFormatSubType alphaType;
|
||||
String name;
|
||||
UInt8 bitsPerPixel;
|
||||
};
|
||||
|
||||
|
|
@ -71,7 +70,7 @@ namespace Nz
|
|||
static inline PixelFormatContent GetContent(PixelFormat format);
|
||||
static inline UInt8 GetBytesPerPixel(PixelFormat format);
|
||||
static inline const PixelFormatDescription& GetInfo(PixelFormat format);
|
||||
static inline const String& GetName(PixelFormat format);
|
||||
static inline const std::string& GetName(PixelFormat format);
|
||||
|
||||
static inline bool HasAlpha(PixelFormat format);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,23 +25,24 @@ namespace Nz
|
|||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) :
|
||||
inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, UInt8 bpp, PixelFormatSubType subType) :
|
||||
name(formatName),
|
||||
content(formatContent),
|
||||
redType(subType),
|
||||
greenType(subType),
|
||||
blueType(subType),
|
||||
alphaType(subType),
|
||||
name(formatName),
|
||||
bitsPerPixel(bpp)
|
||||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) :
|
||||
inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, Bitset<> rMask, Bitset<> gMask, Bitset<> bMask, Bitset<> aMask, PixelFormatSubType subType) :
|
||||
PixelFormatDescription(formatName, formatContent, subType, rMask, subType, gMask, subType, bMask, subType, aMask)
|
||||
{
|
||||
}
|
||||
|
||||
inline PixelFormatDescription::PixelFormatDescription(const String& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) :
|
||||
inline PixelFormatDescription::PixelFormatDescription(const std::string& formatName, PixelFormatContent formatContent, PixelFormatSubType rType, Bitset<> rMask, PixelFormatSubType gType, Bitset<> gMask, PixelFormatSubType bType, Bitset<> bMask, PixelFormatSubType aType, Bitset<> aMask, UInt8 bpp) :
|
||||
name(formatName),
|
||||
redMask(rMask),
|
||||
greenMask(gMask),
|
||||
blueMask(bMask),
|
||||
|
|
@ -50,8 +51,7 @@ namespace Nz
|
|||
redType(rType),
|
||||
greenType(gType),
|
||||
blueType(bType),
|
||||
alphaType(aType),
|
||||
name(formatName)
|
||||
alphaType(aType)
|
||||
{
|
||||
redMask.Reverse();
|
||||
greenMask.Reverse();
|
||||
|
|
@ -69,7 +69,7 @@ namespace Nz
|
|||
blueMask.Clear();
|
||||
greenMask.Clear();
|
||||
redMask.Clear();
|
||||
name.Clear();
|
||||
name.clear();
|
||||
}
|
||||
|
||||
inline bool PixelFormatDescription::IsCompressed() const
|
||||
|
|
@ -245,7 +245,7 @@ namespace Nz
|
|||
return s_pixelFormatInfos[format];
|
||||
}
|
||||
|
||||
inline const String& PixelFormatInfo::GetName(PixelFormat format)
|
||||
inline const std::string& PixelFormatInfo::GetName(PixelFormat format)
|
||||
{
|
||||
return s_pixelFormatInfos[format].name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
#define NAZARA_RICHTEXTDRAWER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Nz
|
||||
|
|
@ -26,7 +26,7 @@ namespace Nz
|
|||
RichTextDrawer(RichTextDrawer&& drawer);
|
||||
~RichTextDrawer();
|
||||
|
||||
BlockRef AppendText(const String& str, bool forceNewBlock = false);
|
||||
BlockRef AppendText(const std::string& str, bool forceNewBlock = false);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ namespace Nz
|
|||
inline const Color& GetBlockOutlineColor(std::size_t index) const;
|
||||
inline float GetBlockOutlineThickness(std::size_t index) const;
|
||||
inline TextStyleFlags GetBlockStyle(std::size_t index) const;
|
||||
inline const String& GetBlockText(std::size_t index) const;
|
||||
inline const std::string& GetBlockText(std::size_t index) const;
|
||||
|
||||
inline BlockRef GetBlock(std::size_t index);
|
||||
const Rectf& GetBounds() const override;
|
||||
|
|
@ -77,7 +77,7 @@ namespace Nz
|
|||
inline void SetBlockOutlineColor(std::size_t index, const Color& color);
|
||||
inline void SetBlockOutlineThickness(std::size_t index, float thickness);
|
||||
inline void SetBlockStyle(std::size_t index, TextStyleFlags style);
|
||||
inline void SetBlockText(std::size_t index, String str);
|
||||
inline void SetBlockText(std::size_t index, std::string str);
|
||||
|
||||
inline void SetDefaultCharacterSize(unsigned int characterSize);
|
||||
inline void SetDefaultCharacterSpacingOffset(float offset);
|
||||
|
|
@ -104,7 +104,7 @@ namespace Nz
|
|||
inline void ConnectFontSlots();
|
||||
inline void DisconnectFontSlots();
|
||||
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, const Font* font, const Color& color, TextStyleFlags style, float lineSpacingOffset, unsigned int characterSize, int renderOrder, int* advance) const;
|
||||
void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const String& text) const;
|
||||
void GenerateGlyphs(const Font* font, const Color& color, TextStyleFlags style, unsigned int characterSize, const Color& outlineColor, float characterSpacingOffset, float lineSpacingOffset, float outlineThickness, const std::string& text) const;
|
||||
inline float GetLineHeight(const Block& block) const;
|
||||
inline float GetLineHeight(float lineSpacingOffset, const Font::SizeInfo& sizeInfo) const;
|
||||
inline std::size_t HandleFontAddition(const FontRef& font);
|
||||
|
|
@ -124,9 +124,9 @@ namespace Nz
|
|||
{
|
||||
std::size_t fontIndex;
|
||||
std::size_t glyphIndex;
|
||||
std::string text;
|
||||
Color color;
|
||||
Color outlineColor;
|
||||
String text;
|
||||
TextStyleFlags style;
|
||||
float characterSpacingOffset;
|
||||
float lineSpacingOffset;
|
||||
|
|
@ -184,7 +184,7 @@ namespace Nz
|
|||
inline Color GetOutlineColor() const;
|
||||
inline float GetOutlineThickness() const;
|
||||
inline TextStyleFlags GetStyle() const;
|
||||
inline const String& GetText() const;
|
||||
inline const std::string& GetText() const;
|
||||
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetCharacterSize(unsigned int size);
|
||||
|
|
@ -194,7 +194,7 @@ namespace Nz
|
|||
inline void SetOutlineColor(Color color);
|
||||
inline void SetOutlineThickness(float thickness);
|
||||
inline void SetStyle(TextStyleFlags style);
|
||||
inline void SetText(const String& text);
|
||||
inline void SetText(std::string text);
|
||||
|
||||
BlockRef& operator=(const BlockRef&) = default;
|
||||
BlockRef& operator=(BlockRef&&) = default;
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ namespace Nz
|
|||
return m_blocks[index].style;
|
||||
}
|
||||
|
||||
inline const String& RichTextDrawer::GetBlockText(std::size_t index) const
|
||||
inline const std::string& RichTextDrawer::GetBlockText(std::size_t index) const
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
return m_blocks[index].text;
|
||||
|
|
@ -341,15 +341,15 @@ namespace Nz
|
|||
InvalidateGlyphs();
|
||||
}
|
||||
|
||||
inline void RichTextDrawer::SetBlockText(std::size_t index, String str)
|
||||
inline void RichTextDrawer::SetBlockText(std::size_t index, std::string str)
|
||||
{
|
||||
NazaraAssert(index < m_blocks.size(), "Invalid block index");
|
||||
|
||||
std::size_t previousLength = m_blocks[index].text.GetLength();
|
||||
std::size_t previousLength = m_blocks[index].text.size(); //< FIXME: Count Unicode glyphs
|
||||
|
||||
m_blocks[index].text = std::move(str);
|
||||
|
||||
std::size_t newLength = m_blocks[index].text.GetLength();
|
||||
std::size_t newLength = m_blocks[index].text.size(); //< FIXME: Count Unicode glyphs
|
||||
if (newLength != previousLength)
|
||||
{
|
||||
std::size_t delta = newLength - previousLength; //< Underflow allowed
|
||||
|
|
@ -523,7 +523,7 @@ namespace Nz
|
|||
*
|
||||
* \see GetCharacterSize, GetColor, GetFont, GetStyle, SetText
|
||||
*/
|
||||
inline const String& RichTextDrawer::BlockRef::GetText() const
|
||||
inline const std::string& RichTextDrawer::BlockRef::GetText() const
|
||||
{
|
||||
return m_drawer.GetBlockText(m_blockIndex);
|
||||
}
|
||||
|
|
@ -622,9 +622,9 @@ namespace Nz
|
|||
*
|
||||
* \see GetText, SetCharacterSize, SetColor, SetFont, SetStyle
|
||||
*/
|
||||
inline void RichTextDrawer::BlockRef::SetText(const String& text)
|
||||
inline void RichTextDrawer::BlockRef::SetText(std::string text)
|
||||
{
|
||||
m_drawer.SetBlockText(m_blockIndex, text);
|
||||
m_drawer.SetBlockText(m_blockIndex, std::move(text));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@
|
|||
#ifndef NAZARA_SEQUENCE_HPP
|
||||
#define NAZARA_SEQUENCE_HPP
|
||||
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Math/Quaternion.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
struct Sequence
|
||||
{
|
||||
String name;
|
||||
std::string name;
|
||||
UInt32 firstFrame;
|
||||
UInt32 frameCount;
|
||||
UInt32 frameRate;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#define NAZARA_SIMPLETEXTDRAWER_HPP
|
||||
|
||||
#include <Nazara/Prerequisites.hpp>
|
||||
#include <Nazara/Core/String.hpp>
|
||||
#include <Nazara/Utility/AbstractTextDrawer.hpp>
|
||||
#include <Nazara/Utility/Enums.hpp>
|
||||
#include <Nazara/Utility/Font.hpp>
|
||||
|
|
@ -24,7 +23,7 @@ namespace Nz
|
|||
inline SimpleTextDrawer(SimpleTextDrawer&& drawer);
|
||||
~SimpleTextDrawer() = default;
|
||||
|
||||
inline void AppendText(const String& str);
|
||||
inline void AppendText(const std::string_view& str);
|
||||
|
||||
void Clear() override;
|
||||
|
||||
|
|
@ -45,7 +44,7 @@ namespace Nz
|
|||
inline const Color& GetOutlineColor() const;
|
||||
inline float GetOutlineThickness() const;
|
||||
inline TextStyleFlags GetStyle() const;
|
||||
inline const String& GetText() const;
|
||||
inline const std::string& GetText() const;
|
||||
|
||||
inline void SetCharacterSpacingOffset(float offset);
|
||||
inline void SetCharacterSize(unsigned int characterSize);
|
||||
|
|
@ -56,15 +55,15 @@ namespace Nz
|
|||
inline void SetOutlineColor(const Color& color);
|
||||
inline void SetOutlineThickness(float thickness);
|
||||
inline void SetStyle(TextStyleFlags style);
|
||||
inline void SetText(const String& str);
|
||||
inline void SetText(std::string str);
|
||||
|
||||
inline SimpleTextDrawer& operator=(const SimpleTextDrawer& drawer);
|
||||
inline SimpleTextDrawer& operator=(SimpleTextDrawer&& drawer);
|
||||
|
||||
static inline SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static inline SimpleTextDrawer Draw(const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
static inline SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static inline SimpleTextDrawer Draw(Font* font, const String& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static inline SimpleTextDrawer Draw(const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
static inline SimpleTextDrawer Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style = TextStyle_Regular, const Color& color = Color::White);
|
||||
static inline SimpleTextDrawer Draw(Font* font, const std::string& str, unsigned int characterSize, TextStyleFlags style, const Color& color, float outlineThickness, const Color& outlineColor);
|
||||
|
||||
private:
|
||||
inline void AppendNewLine() const;
|
||||
|
|
@ -76,7 +75,7 @@ namespace Nz
|
|||
inline void DisconnectFontSlots();
|
||||
|
||||
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, Nz::Color color, int renderOrder, int* advance) const;
|
||||
void GenerateGlyphs(const String& text) const;
|
||||
void GenerateGlyphs(const std::string_view& text) const;
|
||||
|
||||
inline float GetLineHeight(const Font::SizeInfo& sizeInfo) const;
|
||||
|
||||
|
|
@ -102,11 +101,11 @@ namespace Nz
|
|||
mutable std::size_t m_lastSeparatorGlyph;
|
||||
mutable std::vector<Glyph> m_glyphs;
|
||||
mutable std::vector<Line> m_lines;
|
||||
std::string m_text;
|
||||
Color m_color;
|
||||
Color m_outlineColor;
|
||||
FontRef m_font;
|
||||
mutable Rectf m_bounds;
|
||||
String m_text;
|
||||
TextStyleFlags m_style;
|
||||
mutable UInt32 m_previousCharacter;
|
||||
mutable Vector2f m_drawPos;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue