From f579dbc8816e587ff01a12de02cd8c017731bfb2 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 25 Feb 2020 12:53:35 +0100 Subject: [PATCH] Minor header refactoring. --- include/lol/base/features.h | 8 +- include/lol/base/string.h | 2 +- include/lol/math/polynomial.h | 8 +- include/lol/math/rand.h | 28 +++---- include/lol/math/real.h | 72 ++++++++-------- .../real.cpp => include/lol/math/real.ipp | 2 +- legacy/lol/algorithm/all.h | 16 ---- legacy/lol/base/all.h | 25 ------ legacy/lol/image/all.h | 20 ----- legacy/lol/math/all.h | 31 ------- legacy/lol/math/arraynd.h | 2 +- legacy/lol/math/bigint.h | 2 +- legacy/lol/math/functions.h | 84 +++++++++---------- legacy/lol/math/geometry.h | 30 +++---- legacy/lol/math/half.h | 58 ++++++------- legacy/lol/math/matrix.h | 18 ++-- legacy/lol/math/ops.h | 8 +- legacy/lol/math/transform.h | 32 +++---- legacy/lol/math/vector.h | 18 ++-- legacy/lol/net/all.h | 16 ---- legacy/lol/sys/all.h | 20 ----- legacy/lol/sys/timer.h | 60 ------------- 22 files changed, 186 insertions(+), 374 deletions(-) rename legacy/math/real.cpp => include/lol/math/real.ipp (99%) delete mode 100644 legacy/lol/algorithm/all.h delete mode 100644 legacy/lol/base/all.h delete mode 100644 legacy/lol/image/all.h delete mode 100644 legacy/lol/math/all.h delete mode 100644 legacy/lol/net/all.h delete mode 100644 legacy/lol/sys/all.h delete mode 100644 legacy/lol/sys/timer.h diff --git a/include/lol/base/features.h b/include/lol/base/features.h index ee0c0ec1..de0c4d29 100644 --- a/include/lol/base/features.h +++ b/include/lol/base/features.h @@ -20,9 +20,9 @@ // C++ compiler features detected through __has_cpp_attribute #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) -# define LOL_ATTR_NODISCARD [[nodiscard]] +# define lol_attr_nodiscard [[nodiscard]] #else -# define LOL_ATTR_NODISCARD /* */ +# define lol_attr_nodiscard /* */ #endif #if defined(__has_cpp_attribute) && __has_cpp_attribute(fallthrough) @@ -34,9 +34,9 @@ // Define some attribute macros. #ifdef __GNUC__ -# define LOL_ATTR_FORMAT(n, p) __attribute__((format(printf, n, p))) +# define lol_attr_printf_format(n, p) __attribute__((format(printf, n, p))) #else -# define LOL_ATTR_FORMAT(n, p) +# define lol_attr_printf_format(n, p) #endif #if defined(_WIN32) diff --git a/include/lol/base/string.h b/include/lol/base/string.h index 51428493..7a653974 100644 --- a/include/lol/base/string.h +++ b/include/lol/base/string.h @@ -104,7 +104,7 @@ std::basic_string toupper(std::basic_string const &s) } // Format a string, printf-style -template LOL_ATTR_FORMAT(1, 2) +template lol_attr_printf_format(1, 2) std::basic_string format(T const *format, ...) { va_list ap; diff --git a/include/lol/math/polynomial.h b/include/lol/math/polynomial.h index df64a0ad..73c25be9 100644 --- a/include/lol/math/polynomial.h +++ b/include/lol/math/polynomial.h @@ -30,7 +30,7 @@ namespace lol { template -struct LOL_ATTR_NODISCARD polynomial +struct lol_attr_nodiscard polynomial { /* The zero polynomial */ explicit inline polynomial() {} @@ -95,7 +95,7 @@ struct LOL_ATTR_NODISCARD polynomial /* Evaluate polynomial at a given value. This method can also * be used to compose polynomials, i.e. using another polynomial * as the value instead of a scalar. */ - template LOL_ATTR_NODISCARD U eval(U x) const + template lol_attr_nodiscard U eval(U x) const { U ret(leading()); for (int i = degree() - 1; i >= 0; --i) @@ -264,7 +264,7 @@ struct LOL_ATTR_NODISCARD polynomial * copy because we cannot let the user mess with the integrity of * the structure (i.e. the guarantee that the leading coefficient * remains non-zero). */ - LOL_ATTR_NODISCARD inline T operator[](ptrdiff_t n) const + lol_attr_nodiscard inline T operator[](ptrdiff_t n) const { if (n < 0 || n > degree()) return T(0); @@ -273,7 +273,7 @@ struct LOL_ATTR_NODISCARD polynomial } /* Return the leading coefficient */ - LOL_ATTR_NODISCARD inline T leading() const + lol_attr_nodiscard inline T leading() const { return (*this)[degree()]; } diff --git a/include/lol/math/rand.h b/include/lol/math/rand.h index 286e030c..5e8580d0 100644 --- a/include/lol/math/rand.h +++ b/include/lol/math/rand.h @@ -27,50 +27,50 @@ namespace lol { /* Random number generators */ -template LOL_ATTR_NODISCARD static inline T rand(); -template LOL_ATTR_NODISCARD static inline T rand(T a); -template LOL_ATTR_NODISCARD static inline T rand(T a, T b); +template lol_attr_nodiscard static inline T rand(); +template lol_attr_nodiscard static inline T rand(T a); +template lol_attr_nodiscard static inline T rand(T a, T b); /* One-value random number generators */ -template LOL_ATTR_NODISCARD static inline T rand(T a) +template lol_attr_nodiscard static inline T rand(T a) { return a ? rand() % a : T(0); } #if 0 -template<> LOL_ATTR_NODISCARD inline half rand(half a) +template<> lol_attr_nodiscard inline half rand(half a) { float f = (float)std::rand() / (float)RAND_MAX; return (half)(a * f); } #endif -template<> LOL_ATTR_NODISCARD inline float rand(float a) +template<> lol_attr_nodiscard inline float rand(float a) { auto f = (float)std::rand() / (float)RAND_MAX; return a * f; } -template<> LOL_ATTR_NODISCARD inline double rand(double a) +template<> lol_attr_nodiscard inline double rand(double a) { auto f = (double)std::rand() / (double)RAND_MAX; return a * f; } -template<> LOL_ATTR_NODISCARD inline long double rand(long double a) +template<> lol_attr_nodiscard inline long double rand(long double a) { auto f = (long double)std::rand() / (long double)RAND_MAX; return a * f; } /* Two-value random number generator -- no need for specialisation */ -template LOL_ATTR_NODISCARD static inline T rand(T a, T b) +template lol_attr_nodiscard static inline T rand(T a, T b) { return a + rand(b - a); } /* Default random number generator */ -template LOL_ATTR_NODISCARD static inline T rand() +template lol_attr_nodiscard static inline T rand() { switch (sizeof(T)) { @@ -124,11 +124,11 @@ template LOL_ATTR_NODISCARD static inline T rand() } #if 0 -template<> LOL_ATTR_NODISCARD inline half rand() { return rand(1.f); } +template<> lol_attr_nodiscard inline half rand() { return rand(1.f); } #endif -template<> LOL_ATTR_NODISCARD inline float rand() { return rand(1.f); } -template<> LOL_ATTR_NODISCARD inline double rand() { return rand(1.0); } -template<> LOL_ATTR_NODISCARD inline long double rand() { return rand(1.0); } +template<> lol_attr_nodiscard inline float rand() { return rand(1.f); } +template<> lol_attr_nodiscard inline double rand() { return rand(1.0); } +template<> lol_attr_nodiscard inline long double rand() { return rand(1.0); } } /* namespace lol */ diff --git a/include/lol/math/real.h b/include/lol/math/real.h index 72330dec..21542f10 100644 --- a/include/lol/math/real.h +++ b/include/lol/math/real.h @@ -41,7 +41,7 @@ typedef Real real; * call real::sqrt). */ template -class LOL_ATTR_NODISCARD Real +class lol_attr_nodiscard Real { public: typedef T bigit_t; @@ -65,18 +65,18 @@ public: return n <= 0 ? count : (count = n); } - LOL_ATTR_NODISCARD bool is_zero() const { return m_mantissa.size() == 0; } - LOL_ATTR_NODISCARD bool is_negative() const { return m_sign; } - LOL_ATTR_NODISCARD bool is_nan() const { return m_nan; } - LOL_ATTR_NODISCARD bool is_inf() const { return m_inf; } + lol_attr_nodiscard bool is_zero() const { return m_mantissa.size() == 0; } + lol_attr_nodiscard bool is_negative() const { return m_sign; } + lol_attr_nodiscard bool is_nan() const { return m_nan; } + lol_attr_nodiscard bool is_inf() const { return m_inf; } - LOL_ATTR_NODISCARD operator float() const; - LOL_ATTR_NODISCARD operator double() const; - LOL_ATTR_NODISCARD operator long double() const; - LOL_ATTR_NODISCARD operator int32_t() const; - LOL_ATTR_NODISCARD operator uint32_t() const; - LOL_ATTR_NODISCARD operator int64_t() const; - LOL_ATTR_NODISCARD operator uint64_t() const; + lol_attr_nodiscard operator float() const; + lol_attr_nodiscard operator double() const; + lol_attr_nodiscard operator long double() const; + lol_attr_nodiscard operator int32_t() const; + lol_attr_nodiscard operator uint32_t() const; + lol_attr_nodiscard operator int64_t() const; + lol_attr_nodiscard operator uint64_t() const; Real operator +() const; Real operator -() const; @@ -89,15 +89,15 @@ public: Real const &operator *=(Real const &x); Real const &operator /=(Real const &x); - LOL_ATTR_NODISCARD bool operator ==(Real const &x) const; - LOL_ATTR_NODISCARD bool operator !=(Real const &x) const; - LOL_ATTR_NODISCARD bool operator <(Real const &x) const; - LOL_ATTR_NODISCARD bool operator >(Real const &x) const; - LOL_ATTR_NODISCARD bool operator <=(Real const &x) const; - LOL_ATTR_NODISCARD bool operator >=(Real const &x) const; + lol_attr_nodiscard bool operator ==(Real const &x) const; + lol_attr_nodiscard bool operator !=(Real const &x) const; + lol_attr_nodiscard bool operator <(Real const &x) const; + lol_attr_nodiscard bool operator >(Real const &x) const; + lol_attr_nodiscard bool operator <=(Real const &x) const; + lol_attr_nodiscard bool operator >=(Real const &x) const; - LOL_ATTR_NODISCARD bool operator !() const; - LOL_ATTR_NODISCARD operator bool() const; + lol_attr_nodiscard bool operator !() const; + lol_attr_nodiscard operator bool() const; /* Comparison functions */ template friend Real min(Real const &a, Real const &b); @@ -260,13 +260,13 @@ template<> real::Real(int64_t i); template<> real::Real(uint64_t i); template<> real::Real(char const *str); -template<> LOL_ATTR_NODISCARD real::operator float() const; -template<> LOL_ATTR_NODISCARD real::operator double() const; -template<> LOL_ATTR_NODISCARD real::operator long double() const; -template<> LOL_ATTR_NODISCARD real::operator int32_t() const; -template<> LOL_ATTR_NODISCARD real::operator uint32_t() const; -template<> LOL_ATTR_NODISCARD real::operator int64_t() const; -template<> LOL_ATTR_NODISCARD real::operator uint64_t() const; +template<> lol_attr_nodiscard real::operator float() const; +template<> lol_attr_nodiscard real::operator double() const; +template<> lol_attr_nodiscard real::operator long double() const; +template<> lol_attr_nodiscard real::operator int32_t() const; +template<> lol_attr_nodiscard real::operator uint32_t() const; +template<> lol_attr_nodiscard real::operator int64_t() const; +template<> lol_attr_nodiscard real::operator uint64_t() const; template<> real real::operator +() const; template<> real real::operator -() const; template<> real real::operator +(real const &x) const; @@ -277,14 +277,14 @@ template<> real const &real::operator +=(real const &x); template<> real const &real::operator -=(real const &x); template<> real const &real::operator *=(real const &x); template<> real const &real::operator /=(real const &x); -template<> LOL_ATTR_NODISCARD bool real::operator ==(real const &x) const; -template<> LOL_ATTR_NODISCARD bool real::operator !=(real const &x) const; -template<> LOL_ATTR_NODISCARD bool real::operator <(real const &x) const; -template<> LOL_ATTR_NODISCARD bool real::operator >(real const &x) const; -template<> LOL_ATTR_NODISCARD bool real::operator <=(real const &x) const; -template<> LOL_ATTR_NODISCARD bool real::operator >=(real const &x) const; -template<> LOL_ATTR_NODISCARD bool real::operator !() const; -template<> LOL_ATTR_NODISCARD real::operator bool() const; +template<> lol_attr_nodiscard bool real::operator ==(real const &x) const; +template<> lol_attr_nodiscard bool real::operator !=(real const &x) const; +template<> lol_attr_nodiscard bool real::operator <(real const &x) const; +template<> lol_attr_nodiscard bool real::operator >(real const &x) const; +template<> lol_attr_nodiscard bool real::operator <=(real const &x) const; +template<> lol_attr_nodiscard bool real::operator >=(real const &x) const; +template<> lol_attr_nodiscard bool real::operator !() const; +template<> lol_attr_nodiscard real::operator bool() const; template Real min(Real const &a, Real const &b); template Real max(Real const &a, Real const &b); @@ -376,5 +376,5 @@ template<> std::string real::xstr() const; } /* namespace lol */ -#include "../../../legacy/math/real.cpp" +#include "real.ipp" diff --git a/legacy/math/real.cpp b/include/lol/math/real.ipp similarity index 99% rename from legacy/math/real.cpp rename to include/lol/math/real.ipp index 4c3e49bd..7dc9a667 100644 --- a/legacy/math/real.cpp +++ b/include/lol/math/real.ipp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2019 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it diff --git a/legacy/lol/algorithm/all.h b/legacy/lol/algorithm/all.h deleted file mode 100644 index dec445fc..00000000 --- a/legacy/lol/algorithm/all.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2014 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include -#include - diff --git a/legacy/lol/base/all.h b/legacy/lol/base/all.h deleted file mode 100644 index a395de71..00000000 --- a/legacy/lol/base/all.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2013 Sam Hocevar -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - diff --git a/legacy/lol/image/all.h b/legacy/lol/image/all.h deleted file mode 100644 index 3375d56c..00000000 --- a/legacy/lol/image/all.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2015 Sam Hocevar -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include -#include -#include -#include - diff --git a/legacy/lol/math/all.h b/legacy/lol/math/all.h deleted file mode 100644 index 417d419c..00000000 --- a/legacy/lol/math/all.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Lol Engine -// -// Copyright: (c) 2010-2013 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - diff --git a/legacy/lol/math/arraynd.h b/legacy/lol/math/arraynd.h index 61a31b63..b141baf2 100644 --- a/legacy/lol/math/arraynd.h +++ b/legacy/lol/math/arraynd.h @@ -96,7 +96,7 @@ private: template -class LOL_ATTR_NODISCARD arraynd : protected array +class lol_attr_nodiscard arraynd : protected array { public: typedef array super; diff --git a/legacy/lol/math/bigint.h b/legacy/lol/math/bigint.h index d422f3c7..a914b420 100644 --- a/legacy/lol/math/bigint.h +++ b/legacy/lol/math/bigint.h @@ -37,7 +37,7 @@ namespace lol */ template -class LOL_ATTR_NODISCARD bigint +class lol_attr_nodiscard bigint { static int const bits_per_digit = sizeof(T) * 8 - 1; static T const digit_mask = ~((T)1 << bits_per_digit); diff --git a/legacy/lol/math/functions.h b/legacy/lol/math/functions.h index 02b38914..442eb717 100644 --- a/legacy/lol/math/functions.h +++ b/legacy/lol/math/functions.h @@ -44,15 +44,15 @@ namespace lol // Mechanism to import standard cmath functions #define LOL_FORWARD_FP_1_ARG(f) \ template \ - LOL_ATTR_NODISCARD static inline T2 f(T x) { return std::f(x); } + lol_attr_nodiscard static inline T2 f(T x) { return std::f(x); } #define LOL_FORWARD_ARITH_2_ARGS(f) \ template \ - LOL_ATTR_NODISCARD static inline T2 f(T x, T y) { return std::f(x, y); } + lol_attr_nodiscard static inline T2 f(T x, T y) { return std::f(x, y); } #define LOL_FORWARD_FP_2_ARGS(f) \ template \ - LOL_ATTR_NODISCARD static inline T2 f(T x, T y) { return std::f(x, y); } + lol_attr_nodiscard static inline T2 f(T x, T y) { return std::f(x, y); } LOL_FORWARD_FP_1_ARG(sqrt) LOL_FORWARD_FP_1_ARG(cbrt) @@ -78,72 +78,72 @@ LOL_FORWARD_FP_1_ARG(round) // Our extensions template -LOL_ATTR_NODISCARD static inline T2 sincos(T x, T *s, T *c) +lol_attr_nodiscard static inline T2 sincos(T x, T *s, T *c) { *s = std::sin(x); *c = std::cos(x); } // Inherited from GLSL -LOL_ATTR_NODISCARD static inline float degrees(float radians) +lol_attr_nodiscard static inline float degrees(float radians) { return radians * (180.0f / F_PI); } -LOL_ATTR_NODISCARD static inline double degrees(double radians) +lol_attr_nodiscard static inline double degrees(double radians) { return radians * (180.0 / D_PI); } -LOL_ATTR_NODISCARD static inline ldouble degrees(ldouble radians) +lol_attr_nodiscard static inline ldouble degrees(ldouble radians) { return radians * (180.0L / LD_PI); } -LOL_ATTR_NODISCARD static inline float radians(float degrees) +lol_attr_nodiscard static inline float radians(float degrees) { return degrees * (F_PI / 180.0f); } -LOL_ATTR_NODISCARD static inline double radians(double degrees) +lol_attr_nodiscard static inline double radians(double degrees) { return degrees * (D_PI / 180.0); } -LOL_ATTR_NODISCARD static inline ldouble radians(ldouble degrees) +lol_attr_nodiscard static inline ldouble radians(ldouble degrees) { return degrees * (LD_PI / 180.0L); } // The integer versions return floating point values. This avoids nasty // surprises when calling radians(180) instead of radians(180.0). -LOL_ATTR_NODISCARD static inline float degrees(int8_t x) { return degrees(float(x)); } -LOL_ATTR_NODISCARD static inline float degrees(uint8_t x) { return degrees(float(x)); } -LOL_ATTR_NODISCARD static inline float degrees(int16_t x) { return degrees(float(x)); } -LOL_ATTR_NODISCARD static inline float degrees(uint16_t x) { return degrees(float(x)); } -LOL_ATTR_NODISCARD static inline double degrees(int32_t x) { return degrees(double(x)); } -LOL_ATTR_NODISCARD static inline double degrees(uint32_t x) { return degrees(double(x)); } -LOL_ATTR_NODISCARD static inline ldouble degrees(int64_t x) { return degrees(ldouble(x)); } -LOL_ATTR_NODISCARD static inline ldouble degrees(uint64_t x) { return degrees(ldouble(x)); } - -LOL_ATTR_NODISCARD static inline float radians(int8_t x) { return radians(float(x)); } -LOL_ATTR_NODISCARD static inline float radians(uint8_t x) { return radians(float(x)); } -LOL_ATTR_NODISCARD static inline float radians(int16_t x) { return radians(float(x)); } -LOL_ATTR_NODISCARD static inline float radians(uint16_t x) { return radians(float(x)); } -LOL_ATTR_NODISCARD static inline double radians(int32_t x) { return radians(double(x)); } -LOL_ATTR_NODISCARD static inline double radians(uint32_t x) { return radians(double(x)); } -LOL_ATTR_NODISCARD static inline ldouble radians(int64_t x) { return radians(ldouble(x)); } -LOL_ATTR_NODISCARD static inline ldouble radians(uint64_t x) { return radians(ldouble(x)); } +lol_attr_nodiscard static inline float degrees(int8_t x) { return degrees(float(x)); } +lol_attr_nodiscard static inline float degrees(uint8_t x) { return degrees(float(x)); } +lol_attr_nodiscard static inline float degrees(int16_t x) { return degrees(float(x)); } +lol_attr_nodiscard static inline float degrees(uint16_t x) { return degrees(float(x)); } +lol_attr_nodiscard static inline double degrees(int32_t x) { return degrees(double(x)); } +lol_attr_nodiscard static inline double degrees(uint32_t x) { return degrees(double(x)); } +lol_attr_nodiscard static inline ldouble degrees(int64_t x) { return degrees(ldouble(x)); } +lol_attr_nodiscard static inline ldouble degrees(uint64_t x) { return degrees(ldouble(x)); } + +lol_attr_nodiscard static inline float radians(int8_t x) { return radians(float(x)); } +lol_attr_nodiscard static inline float radians(uint8_t x) { return radians(float(x)); } +lol_attr_nodiscard static inline float radians(int16_t x) { return radians(float(x)); } +lol_attr_nodiscard static inline float radians(uint16_t x) { return radians(float(x)); } +lol_attr_nodiscard static inline double radians(int32_t x) { return radians(double(x)); } +lol_attr_nodiscard static inline double radians(uint32_t x) { return radians(double(x)); } +lol_attr_nodiscard static inline ldouble radians(int64_t x) { return radians(ldouble(x)); } +lol_attr_nodiscard static inline ldouble radians(uint64_t x) { return radians(ldouble(x)); } template -LOL_ATTR_NODISCARD static inline T2 mix(T a, T b, T x) +lol_attr_nodiscard static inline T2 mix(T a, T b, T x) { return a + (b - a) * x; } // Inherited from HLSL template -LOL_ATTR_NODISCARD static inline T2 lerp(T a, T b, T x) +lol_attr_nodiscard static inline T2 lerp(T a, T b, T x) { return mix(a, b, x); } @@ -151,35 +151,35 @@ LOL_ATTR_NODISCARD static inline T2 lerp(T a, T b, T x) // C++ doesn't define abs() or fmod() for all types; we add these for // convenience to avoid adding complexity to vector.h. template -LOL_ATTR_NODISCARD static inline T2 abs(T x) { return std::abs(x); } +lol_attr_nodiscard static inline T2 abs(T x) { return std::abs(x); } template -LOL_ATTR_NODISCARD static inline T2 abs(T x) { return x; } +lol_attr_nodiscard static inline T2 abs(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 fmod(T x, T y) { return x % y; } +lol_attr_nodiscard static inline T2 fmod(T x, T y) { return x % y; } template -LOL_ATTR_NODISCARD static inline T2 floor(T x) { return x; } +lol_attr_nodiscard static inline T2 floor(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 ceil(T x) { return x; } +lol_attr_nodiscard static inline T2 ceil(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 round(T x) { return x; } +lol_attr_nodiscard static inline T2 round(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 sq(T x) { return x * x; } +lol_attr_nodiscard static inline T2 sq(T x) { return x * x; } template -LOL_ATTR_NODISCARD static inline T2 fract(T x) { return x - lol::floor(x); } +lol_attr_nodiscard static inline T2 fract(T x) { return x - lol::floor(x); } template -LOL_ATTR_NODISCARD static inline T2 clamp(T x, T y, T z) { return min(max(x, y), z); } +lol_attr_nodiscard static inline T2 clamp(T x, T y, T z) { return min(max(x, y), z); } template -LOL_ATTR_NODISCARD static inline T2 saturate(T x) { return clamp(x, (T)0, (T)1); } +lol_attr_nodiscard static inline T2 saturate(T x) { return clamp(x, (T)0, (T)1); } template -LOL_ATTR_NODISCARD static inline T2 gcd(T x, T y) { return y == (T)0 ? lol::abs(x) : lol::gcd(y, lol::fmod(x, y)); } +lol_attr_nodiscard static inline T2 gcd(T x, T y) { return y == (T)0 ? lol::abs(x) : lol::gcd(y, lol::fmod(x, y)); } template -LOL_ATTR_NODISCARD static inline T2 sign(T x) { return (T)(((T)0 < x) - (x < (T)0)); } +lol_attr_nodiscard static inline T2 sign(T x) { return (T)(((T)0 < x) - (x < (T)0)); } template -LOL_ATTR_NODISCARD static inline T2 sign(T x) { return (T)((T)0 < x); } +lol_attr_nodiscard static inline T2 sign(T x) { return (T)((T)0 < x); } } /* namespace lol */ diff --git a/legacy/lol/math/geometry.h b/legacy/lol/math/geometry.h index 7b37ce63..fef2023c 100644 --- a/legacy/lol/math/geometry.h +++ b/legacy/lol/math/geometry.h @@ -91,7 +91,7 @@ T_(box_t<, C_ 4>, box4) #undef T_ template -struct LOL_ATTR_NODISCARD box_t +struct lol_attr_nodiscard box_t { inline box_t() : aa(vec_t(T(0))), @@ -154,12 +154,12 @@ struct LOL_ATTR_NODISCARD box_t return *this = *this * s; } - LOL_ATTR_NODISCARD bool operator ==(box_t const &box) const + lol_attr_nodiscard bool operator ==(box_t const &box) const { return aa == box.aa && bb == box.bb; } - LOL_ATTR_NODISCARD bool operator !=(box_t const &box) const + lol_attr_nodiscard bool operator !=(box_t const &box) const { return aa != box.aa || bb != box.bb; } @@ -193,19 +193,19 @@ private: float Minus() const; float Plus() const; public: - LOL_ATTR_NODISCARD bool operator==(float value) const; - LOL_ATTR_NODISCARD bool operator!=(float value) const; - LOL_ATTR_NODISCARD bool operator<(float value) const; - LOL_ATTR_NODISCARD bool operator<=(float value) const; - LOL_ATTR_NODISCARD bool operator>(float value) const; - LOL_ATTR_NODISCARD bool operator>=(float value) const; + lol_attr_nodiscard bool operator==(float value) const; + lol_attr_nodiscard bool operator!=(float value) const; + lol_attr_nodiscard bool operator<(float value) const; + lol_attr_nodiscard bool operator<=(float value) const; + lol_attr_nodiscard bool operator>(float value) const; + lol_attr_nodiscard bool operator>=(float value) const; }; -LOL_ATTR_NODISCARD bool operator==(float value, const TestEpsilon& epsilon); -LOL_ATTR_NODISCARD bool operator!=(float value, const TestEpsilon& epsilon); -LOL_ATTR_NODISCARD bool operator<(float value, const TestEpsilon& epsilon); -LOL_ATTR_NODISCARD bool operator<=(float value, const TestEpsilon& epsilon); -LOL_ATTR_NODISCARD bool operator>(float value, const TestEpsilon& epsilon); -LOL_ATTR_NODISCARD bool operator>=(float value, const TestEpsilon& epsilon); +lol_attr_nodiscard bool operator==(float value, const TestEpsilon& epsilon); +lol_attr_nodiscard bool operator!=(float value, const TestEpsilon& epsilon); +lol_attr_nodiscard bool operator<(float value, const TestEpsilon& epsilon); +lol_attr_nodiscard bool operator<=(float value, const TestEpsilon& epsilon); +lol_attr_nodiscard bool operator>(float value, const TestEpsilon& epsilon); +lol_attr_nodiscard bool operator>=(float value, const TestEpsilon& epsilon); //-- static inline bool TestAABBVsAABB(box2 const &b1, box2 const &b2) diff --git a/legacy/lol/math/half.h b/legacy/lol/math/half.h index 667fa2b0..93335565 100644 --- a/legacy/lol/math/half.h +++ b/legacy/lol/math/half.h @@ -32,7 +32,7 @@ namespace lol namespace half_ops { struct base {}; } -class LOL_ATTR_NODISCARD half +class lol_attr_nodiscard half : half_ops::base { public: @@ -44,22 +44,22 @@ public: inline half(double f) { *this = makefast((float)f); } inline half(ldouble f) { *this = makefast((float)f); } - LOL_ATTR_NODISCARD inline int is_nan() const + lol_attr_nodiscard inline int is_nan() const { return ((bits & 0x7c00u) == 0x7c00u) && (bits & 0x03ffu); } - LOL_ATTR_NODISCARD inline int is_finite() const + lol_attr_nodiscard inline int is_finite() const { return (bits & 0x7c00u) != 0x7c00u; } - LOL_ATTR_NODISCARD inline int is_inf() const + lol_attr_nodiscard inline int is_inf() const { return (uint16_t)(bits << 1) == (0x7c00u << 1); } - LOL_ATTR_NODISCARD inline int is_normal() const + lol_attr_nodiscard inline int is_normal() const { return (is_finite() && (bits & 0x7c00u)) || ((bits & 0x7fffu) == 0); } @@ -69,33 +69,33 @@ public: inline half &operator =(float f) { return *this = makefast(f); } inline half &operator =(double f) { return *this = makefast((float)f); } inline half &operator =(ldouble f) { return *this = makefast((float)f); } - LOL_ATTR_NODISCARD inline operator int8_t() const { return (int8_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator uint8_t() const { return (uint8_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator int16_t() const { return (int16_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator uint16_t() const { return (uint16_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator int32_t() const { return (int32_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator uint32_t() const { return (uint32_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator int64_t() const { return (int64_t)(float)*this; } - LOL_ATTR_NODISCARD inline operator uint64_t() const { return (uint64_t)(float)*this; } - - LOL_ATTR_NODISCARD operator float() const; - LOL_ATTR_NODISCARD inline operator double() const { return (float)(*this); } - LOL_ATTR_NODISCARD inline operator ldouble() const { return (float)(*this); } + lol_attr_nodiscard inline operator int8_t() const { return (int8_t)(float)*this; } + lol_attr_nodiscard inline operator uint8_t() const { return (uint8_t)(float)*this; } + lol_attr_nodiscard inline operator int16_t() const { return (int16_t)(float)*this; } + lol_attr_nodiscard inline operator uint16_t() const { return (uint16_t)(float)*this; } + lol_attr_nodiscard inline operator int32_t() const { return (int32_t)(float)*this; } + lol_attr_nodiscard inline operator uint32_t() const { return (uint32_t)(float)*this; } + lol_attr_nodiscard inline operator int64_t() const { return (int64_t)(float)*this; } + lol_attr_nodiscard inline operator uint64_t() const { return (uint64_t)(float)*this; } + + lol_attr_nodiscard operator float() const; + lol_attr_nodiscard inline operator double() const { return (float)(*this); } + lol_attr_nodiscard inline operator ldouble() const { return (float)(*this); } /* Array conversions */ static void convert(half *dst, float const *src, size_t nelem); static void convert(float *dst, half const *src, size_t nelem); /* Operations */ - LOL_ATTR_NODISCARD bool operator ==(half x) const { return (float)*this == (float)x; } - LOL_ATTR_NODISCARD bool operator !=(half x) const { return (float)*this != (float)x; } - LOL_ATTR_NODISCARD bool operator <(half x) const { return (float)*this < (float)x; } - LOL_ATTR_NODISCARD bool operator >(half x) const { return (float)*this > (float)x; } - LOL_ATTR_NODISCARD bool operator <=(half x) const { return (float)*this <= (float)x; } - LOL_ATTR_NODISCARD bool operator >=(half x) const { return (float)*this >= (float)x; } + lol_attr_nodiscard bool operator ==(half x) const { return (float)*this == (float)x; } + lol_attr_nodiscard bool operator !=(half x) const { return (float)*this != (float)x; } + lol_attr_nodiscard bool operator <(half x) const { return (float)*this < (float)x; } + lol_attr_nodiscard bool operator >(half x) const { return (float)*this > (float)x; } + lol_attr_nodiscard bool operator <=(half x) const { return (float)*this <= (float)x; } + lol_attr_nodiscard bool operator >=(half x) const { return (float)*this >= (float)x; } - LOL_ATTR_NODISCARD bool operator !() const { return !(bits & 0x7fffu); } - LOL_ATTR_NODISCARD operator bool() const { return !!*this; } + lol_attr_nodiscard bool operator !() const { return !(bits & 0x7fffu); } + lol_attr_nodiscard operator bool() const { return !!*this; } inline half operator -() const { return makebits(bits ^ 0x8000u); } inline half operator +() const { return *this; } @@ -104,10 +104,10 @@ public: inline half &operator *=(half h) { return (*this = (half)(*this * h)); } inline half &operator /=(half h) { return (*this = (half)(*this / h)); } - LOL_ATTR_NODISCARD inline float operator +(half h) const { return (float)*this + (float)h; } - LOL_ATTR_NODISCARD inline float operator -(half h) const { return (float)*this - (float)h; } - LOL_ATTR_NODISCARD inline float operator *(half h) const { return (float)*this * (float)h; } - LOL_ATTR_NODISCARD inline float operator /(half h) const { return (float)*this / (float)h; } + lol_attr_nodiscard inline float operator +(half h) const { return (float)*this + (float)h; } + lol_attr_nodiscard inline float operator -(half h) const { return (float)*this - (float)h; } + lol_attr_nodiscard inline float operator *(half h) const { return (float)*this * (float)h; } + lol_attr_nodiscard inline float operator /(half h) const { return (float)*this / (float)h; } /* Factories */ static half makefast(float f); diff --git a/legacy/lol/math/matrix.h b/legacy/lol/math/matrix.h index ffb3e59d..8634ec31 100644 --- a/legacy/lol/math/matrix.h +++ b/legacy/lol/math/matrix.h @@ -37,7 +37,7 @@ namespace lol */ template -struct LOL_ATTR_NODISCARD mat_t +struct lol_attr_nodiscard mat_t : public linear_ops::base> { static int const count = COLS; @@ -75,7 +75,7 @@ private: */ template -struct LOL_ATTR_NODISCARD mat_t +struct lol_attr_nodiscard mat_t : public linear_ops::base> { static int const count = 2; @@ -128,7 +128,7 @@ static_assert(sizeof(dmat2) == 32, "sizeof(dmat2) == 32"); */ template -struct LOL_ATTR_NODISCARD mat_t +struct lol_attr_nodiscard mat_t : public linear_ops::base> { static int const count = 3; @@ -220,7 +220,7 @@ static_assert(sizeof(dmat3) == 72, "sizeof(dmat3) == 72"); */ template -struct LOL_ATTR_NODISCARD mat_t +struct lol_attr_nodiscard mat_t : public linear_ops::base> { static int const count = 4; @@ -403,7 +403,7 @@ mat_t submatrix(mat_t const &m, int i, int j) * Compute square matrix cofactor */ -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard T cofactor(mat_t const &m, int i, int j) { ASSERT(i >= 0); ASSERT(j >= 0); ASSERT(i < N); ASSERT(j < N); @@ -411,7 +411,7 @@ T cofactor(mat_t const &m, int i, int j) return ((i + j) & 1) ? -tmp : tmp; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard T cofactor(mat_t const &m, int i, int j) { /* This specialisation shouldn't be needed, but Visual Studio. */ @@ -421,7 +421,7 @@ T cofactor(mat_t const &m, int i, int j) } // Lu decomposition with partial pivoting -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard std::tuple, vec_t, int> lu_decomposition(mat_t const &m) { mat_t lu = m; @@ -464,7 +464,7 @@ std::tuple, vec_t, int> lu_decomposition(mat_t c * Compute square matrix determinant, with a specialisation for 1×1 matrices */ -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard T determinant(mat_t const &m) { auto lup = lu_decomposition(m); @@ -476,7 +476,7 @@ T determinant(mat_t const &m) return det; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard T const & determinant(mat_t const &m) { return m[0][0]; diff --git a/legacy/lol/math/ops.h b/legacy/lol/math/ops.h index 11bc364d..e25f4504 100644 --- a/legacy/lol/math/ops.h +++ b/legacy/lol/math/ops.h @@ -70,14 +70,14 @@ namespace swizzle_ops namespace swizzle_ops { -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline typename std::enable_if::type operator ==(vec_t const &a, vec_t const &b) { return vec_t(a) == vec_t(b); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline typename std::enable_if::type operator !=(vec_t const &a, vec_t const &b) { @@ -135,7 +135,7 @@ namespace linear_ops * Comparisons */ -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline typename std::enable_if, V>::value, bool>::type operator ==(V const &a, V const &b) { @@ -145,7 +145,7 @@ operator ==(V const &a, V const &b) return true; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline typename std::enable_if, V>::value, bool>::type operator !=(V const &a, V const &b) { diff --git a/legacy/lol/math/transform.h b/legacy/lol/math/transform.h index b456a117..d599784a 100644 --- a/legacy/lol/math/transform.h +++ b/legacy/lol/math/transform.h @@ -29,7 +29,7 @@ namespace lol */ template -struct LOL_ATTR_NODISCARD cmplx_t : public linear_ops::base +struct lol_attr_nodiscard cmplx_t : public linear_ops::base { static int const count = 2; typedef T scalar_element; @@ -77,7 +77,7 @@ static_assert(sizeof(dcmplx) == 16, "sizeof(dcmplx) == 16"); */ template -struct LOL_ATTR_NODISCARD quat_t : public linear_ops::base +struct lol_attr_nodiscard quat_t : public linear_ops::base { static int const count = 4; typedef T scalar_element; @@ -231,7 +231,7 @@ struct LOL_ATTR_NODISCARD quat_t : public linear_ops::base return normalize(v); } - LOL_ATTR_NODISCARD inline T angle() + lol_attr_nodiscard inline T angle() { vec_t v(x, y, z); T n2 = sqlength(v); @@ -256,7 +256,7 @@ static_assert(sizeof(dquat) == 32, "sizeof(dquat) == 32"); */ template -struct LOL_ATTR_NODISCARD sqt_t +struct lol_attr_nodiscard sqt_t { /* Default constructor and copy constructor */ inline constexpr sqt_t() = default; @@ -340,7 +340,7 @@ std::ostream &operator<<(std::ostream &stream, quat_t const &q) * Common operations on transforms */ -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T dot(cmplx_t const &t1, cmplx_t const &t2) { T ret(0); @@ -349,20 +349,20 @@ static inline T dot(cmplx_t const &t1, cmplx_t const &t2) return ret; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T sqlength(cmplx_t const &t) { return dot(t, t); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T length(cmplx_t const &t) { /* FIXME: this is not very nice */ return (T)sqrt((double)sqlength(t)); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T norm(cmplx_t const &t) { return length(t); @@ -377,7 +377,7 @@ static inline cmplx_t normalize(cmplx_t const &z) /* XXX: duplicate */ -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T dot(quat_t const &t1, quat_t const &t2) { T ret(0); @@ -386,20 +386,20 @@ static inline T dot(quat_t const &t1, quat_t const &t2) return ret; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T sqlength(quat_t const &t) { return dot(t, t); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T length(quat_t const &t) { /* FIXME: this is not very nice */ return (T)sqrt((double)sqlength(t)); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T norm(quat_t const &t) { return length(t); @@ -434,22 +434,22 @@ static inline cmplx_t operator /(cmplx_t a, cmplx_t const &b) return a * inverse(b); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline bool operator ==(cmplx_t const &a, T b) { return (a.x == b) && !a.y; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline bool operator !=(cmplx_t const &a, T b) { return (a.x != b) || a.y; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline bool operator ==(T a, cmplx_t const &b) { return b == a; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline bool operator !=(T a, cmplx_t const &b) { return b != a; } /* diff --git a/legacy/lol/math/vector.h b/legacy/lol/math/vector.h index bfc85850..ef704100 100644 --- a/legacy/lol/math/vector.h +++ b/legacy/lol/math/vector.h @@ -47,7 +47,7 @@ namespace lol */ template -struct LOL_ATTR_NODISCARD vec_t +struct lol_attr_nodiscard vec_t /* MUST have a different base than e.g. vec_t otherwise the unions * in vec_t with the same base will cause empty base optimisation * failures. */ @@ -118,7 +118,7 @@ private: /* The generic “vec_t” type, which is a fixed-size vector with no * swizzling. There's an override for N=2, N=3, N=4 that has swizzling. */ template -struct LOL_ATTR_NODISCARD vec_t +struct lol_attr_nodiscard vec_t : public componentwise_ops::base { static int const count = N; @@ -207,7 +207,7 @@ private: */ template -struct LOL_ATTR_NODISCARD vec_t +struct lol_attr_nodiscard vec_t : public swizzle_ops::base { static int const count = 2; @@ -318,7 +318,7 @@ static_assert(sizeof(dvec2) == 16, "sizeof(dvec2) == 16"); */ template -struct LOL_ATTR_NODISCARD vec_t +struct lol_attr_nodiscard vec_t : public swizzle_ops::base { static int const count = 3; @@ -559,7 +559,7 @@ static_assert(sizeof(dvec3) == 24, "sizeof(dvec3) == 24"); */ template -struct LOL_ATTR_NODISCARD vec_t +struct lol_attr_nodiscard vec_t : public swizzle_ops::base { static int const count = 4; @@ -1121,7 +1121,7 @@ static inline vec_t mix(vec_t const &x, * Some GLSL-like functions. */ -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T dot(vec_t const &a, vec_t const &b) { @@ -1131,13 +1131,13 @@ static inline T dot(vec_t const &a, return ret; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T sqlength(vec_t const &a) { return dot(a, a); } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T length(vec_t const &a) { /* FIXME: this is not very nice */ @@ -1155,7 +1155,7 @@ static inline vec_t lerp(vec_t const &a, return ret; } -template LOL_ATTR_NODISCARD +template lol_attr_nodiscard static inline T distance(vec_t const &a, vec_t const &b) { diff --git a/legacy/lol/net/all.h b/legacy/lol/net/all.h deleted file mode 100644 index 922f3b4d..00000000 --- a/legacy/lol/net/all.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2020 Sam Hocevar -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include - diff --git a/legacy/lol/sys/all.h b/legacy/lol/sys/all.h deleted file mode 100644 index 765c54d3..00000000 --- a/legacy/lol/sys/all.h +++ /dev/null @@ -1,20 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2019 Sam Hocevar -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include /* requires thread.h */ -#include -#include -#include - diff --git a/legacy/lol/sys/timer.h b/legacy/lol/sys/timer.h deleted file mode 100644 index ed96452c..00000000 --- a/legacy/lol/sys/timer.h +++ /dev/null @@ -1,60 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2018 Sam Hocevar -// © 2016 Guillaume Bittoun -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include - -// -// The timer class -// --------------- -// - -namespace lol -{ - -class timer -{ -public: - inline timer() { (void)get_seconds(true); } - - inline void reset() { (void)get_seconds(true); } - inline float get() { return get_seconds(true); } - inline float poll() { return get_seconds(false); } - - void wait(float seconds) - { - if (seconds > 0.0f) - { - float secs_elapsed = get_seconds(false); - std::this_thread::sleep_for(std::chrono::duration(seconds - secs_elapsed)); - } - } - -private: - std::chrono::steady_clock::time_point m_tp; - - float get_seconds(bool do_reset) - { - auto tp = std::chrono::steady_clock::now(), tp0 = m_tp; - - if (do_reset) - m_tp = tp; - - return std::chrono::duration_cast>(tp - tp0).count(); - } -}; - -} /* namespace lol */ -