Browse Source

Minor header refactoring.

wip/core-clipp
Sam Hocevar 4 years ago
parent
commit
f579dbc881
22 changed files with 186 additions and 374 deletions
  1. +4
    -4
      include/lol/base/features.h
  2. +1
    -1
      include/lol/base/string.h
  3. +4
    -4
      include/lol/math/polynomial.h
  4. +14
    -14
      include/lol/math/rand.h
  5. +36
    -36
      include/lol/math/real.h
  6. +1
    -1
      include/lol/math/real.ipp
  7. +0
    -16
      legacy/lol/algorithm/all.h
  8. +0
    -25
      legacy/lol/base/all.h
  9. +0
    -20
      legacy/lol/image/all.h
  10. +0
    -31
      legacy/lol/math/all.h
  11. +1
    -1
      legacy/lol/math/arraynd.h
  12. +1
    -1
      legacy/lol/math/bigint.h
  13. +42
    -42
      legacy/lol/math/functions.h
  14. +15
    -15
      legacy/lol/math/geometry.h
  15. +29
    -29
      legacy/lol/math/half.h
  16. +9
    -9
      legacy/lol/math/matrix.h
  17. +4
    -4
      legacy/lol/math/ops.h
  18. +16
    -16
      legacy/lol/math/transform.h
  19. +9
    -9
      legacy/lol/math/vector.h
  20. +0
    -16
      legacy/lol/net/all.h
  21. +0
    -20
      legacy/lol/sys/all.h
  22. +0
    -60
      legacy/lol/sys/timer.h

+ 4
- 4
include/lol/base/features.h View File

@@ -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)


+ 1
- 1
include/lol/base/string.h View File

@@ -104,7 +104,7 @@ std::basic_string<T> toupper(std::basic_string<T> const &s)
}

// Format a string, printf-style
template<typename T = char> LOL_ATTR_FORMAT(1, 2)
template<typename T = char> lol_attr_printf_format(1, 2)
std::basic_string<T> format(T const *format, ...)
{
va_list ap;


+ 4
- 4
include/lol/math/polynomial.h View File

@@ -30,7 +30,7 @@ namespace lol
{

template<typename T>
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<typename U> LOL_ATTR_NODISCARD U eval(U x) const
template<typename U> 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()];
}


+ 14
- 14
include/lol/math/rand.h View File

@@ -27,50 +27,50 @@ namespace lol
{

/* Random number generators */
template<typename T> LOL_ATTR_NODISCARD static inline T rand();
template<typename T> LOL_ATTR_NODISCARD static inline T rand(T a);
template<typename T> LOL_ATTR_NODISCARD static inline T rand(T a, T b);
template<typename T> lol_attr_nodiscard static inline T rand();
template<typename T> lol_attr_nodiscard static inline T rand(T a);
template<typename T> lol_attr_nodiscard static inline T rand(T a, T b);

/* One-value random number generators */
template<typename T> LOL_ATTR_NODISCARD static inline T rand(T a)
template<typename T> lol_attr_nodiscard static inline T rand(T a)
{
return a ? rand<T>() % a : T(0);
}

#if 0
template<> LOL_ATTR_NODISCARD inline half rand<half>(half a)
template<> lol_attr_nodiscard inline half rand<half>(half a)
{
float f = (float)std::rand() / (float)RAND_MAX;
return (half)(a * f);
}
#endif

template<> LOL_ATTR_NODISCARD inline float rand<float>(float a)
template<> lol_attr_nodiscard inline float rand<float>(float a)
{
auto f = (float)std::rand() / (float)RAND_MAX;
return a * f;
}

template<> LOL_ATTR_NODISCARD inline double rand<double>(double a)
template<> lol_attr_nodiscard inline double rand<double>(double a)
{
auto f = (double)std::rand() / (double)RAND_MAX;
return a * f;
}

template<> LOL_ATTR_NODISCARD inline long double rand<long double>(long double a)
template<> lol_attr_nodiscard inline long double rand<long double>(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<typename T> LOL_ATTR_NODISCARD static inline T rand(T a, T b)
template<typename T> lol_attr_nodiscard static inline T rand(T a, T b)
{
return a + rand<T>(b - a);
}

/* Default random number generator */
template<typename T> LOL_ATTR_NODISCARD static inline T rand()
template<typename T> lol_attr_nodiscard static inline T rand()
{
switch (sizeof(T))
{
@@ -124,11 +124,11 @@ template<typename T> LOL_ATTR_NODISCARD static inline T rand()
}

#if 0
template<> LOL_ATTR_NODISCARD inline half rand<half>() { return rand<half>(1.f); }
template<> lol_attr_nodiscard inline half rand<half>() { return rand<half>(1.f); }
#endif
template<> LOL_ATTR_NODISCARD inline float rand<float>() { return rand<float>(1.f); }
template<> LOL_ATTR_NODISCARD inline double rand<double>() { return rand<double>(1.0); }
template<> LOL_ATTR_NODISCARD inline long double rand<long double>() { return rand<long double>(1.0); }
template<> lol_attr_nodiscard inline float rand<float>() { return rand<float>(1.f); }
template<> lol_attr_nodiscard inline double rand<double>() { return rand<double>(1.0); }
template<> lol_attr_nodiscard inline long double rand<long double>() { return rand<long double>(1.0); }

} /* namespace lol */


+ 36
- 36
include/lol/math/real.h View File

@@ -41,7 +41,7 @@ typedef Real<uint32_t> real;
* call real::sqrt).
*/
template<typename T>
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<T> operator +() const;
Real<T> operator -() const;
@@ -89,15 +89,15 @@ public:
Real<T> const &operator *=(Real<T> const &x);
Real<T> const &operator /=(Real<T> const &x);

LOL_ATTR_NODISCARD bool operator ==(Real<T> const &x) const;
LOL_ATTR_NODISCARD bool operator !=(Real<T> const &x) const;
LOL_ATTR_NODISCARD bool operator <(Real<T> const &x) const;
LOL_ATTR_NODISCARD bool operator >(Real<T> const &x) const;
LOL_ATTR_NODISCARD bool operator <=(Real<T> const &x) const;
LOL_ATTR_NODISCARD bool operator >=(Real<T> const &x) const;
lol_attr_nodiscard bool operator ==(Real<T> const &x) const;
lol_attr_nodiscard bool operator !=(Real<T> const &x) const;
lol_attr_nodiscard bool operator <(Real<T> const &x) const;
lol_attr_nodiscard bool operator >(Real<T> const &x) const;
lol_attr_nodiscard bool operator <=(Real<T> const &x) const;
lol_attr_nodiscard bool operator >=(Real<T> 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<typename U> friend Real<U> min(Real<U> const &a, Real<U> 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<typename U> Real<U> min(Real<U> const &a, Real<U> const &b);
template<typename U> Real<U> max(Real<U> const &a, Real<U> const &b);
@@ -376,5 +376,5 @@ template<> std::string real::xstr() const;

} /* namespace lol */

#include "../../../legacy/math/real.cpp"
#include "real.ipp"


legacy/math/real.cpp → include/lol/math/real.ipp View File

@@ -1,7 +1,7 @@
//
// Lol Engine
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it

+ 0
- 16
legacy/lol/algorithm/all.h View File

@@ -1,16 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2014 Sam Hocevar <sam@hocevar.net>
// 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 <lol/algorithm/sort.h>
#include <lol/algorithm/aabb_tree.h>
#include <lol/algorithm/portal.h>


+ 0
- 25
legacy/lol/base/all.h View File

@@ -1,25 +0,0 @@
//
// Lol Engine
//
// Copyright © 2010—2013 Sam Hocevar <sam@hocevar.net>
//
// 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 <lol/base/features.h>
#include <lol/base/types.h>
#include <lol/base/log.h>
#include <lol/base/assert.h>
#include <lol/base/tuple.h>
#include <lol/base/array.h>
#include <lol/base/avl_tree.h>
#include <lol/base/string.h>
#include <lol/base/map.h>
#include <lol/base/enum.h>


+ 0
- 20
legacy/lol/image/all.h View File

@@ -1,20 +0,0 @@
//
// Lol Engine
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
//
// 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 <lol/image/pixel.h>
#include <lol/image/color.h>
#include <lol/image/image.h>
#include <lol/image/resource.h>
#include <lol/image/movie.h>


+ 0
- 31
legacy/lol/math/all.h View File

@@ -1,31 +0,0 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
// 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 <lol/math/constants.h>
#include <lol/math/functions.h>
#include <lol/math/half.h>
#include <lol/math/bigint.h>
#include <lol/math/real.h>
#include <lol/math/ops.h>
#include <lol/math/vector.h>
#include <lol/math/matrix.h>
#include <lol/math/transform.h>
#include <lol/math/arraynd.h>
#include <lol/math/geometry.h>
#include <lol/math/interp.h>
#include <lol/math/rand.h>
#include <lol/math/polynomial.h>

#include <lol/math/noise/gradient.h>
#include <lol/math/noise/perlin.h>
#include <lol/math/noise/simplex.h>


+ 1
- 1
legacy/lol/math/arraynd.h View File

@@ -96,7 +96,7 @@ private:


template<int N, typename... T>
class LOL_ATTR_NODISCARD arraynd : protected array<T...>
class lol_attr_nodiscard arraynd : protected array<T...>
{
public:
typedef array<T...> super;


+ 1
- 1
legacy/lol/math/bigint.h View File

@@ -37,7 +37,7 @@ namespace lol
*/

template<unsigned int N = 16, typename T = uint32_t>
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);


+ 42
- 42
legacy/lol/math/functions.h View File

@@ -44,15 +44,15 @@ namespace lol
// Mechanism to import standard cmath functions
#define LOL_FORWARD_FP_1_ARG(f) \
template<typename T, typename T2 = T, typename DUMMY = LOL_T_FLOATING_POINT> \
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<typename T, typename T2 = T, typename DUMMY = LOL_T_ARITHMETIC> \
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<typename T, typename T2 = T, typename DUMMY = LOL_T_FLOATING_POINT> \
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<typename T, typename T2 = LOL_T_FLOATING_POINT>
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<typename T, typename T2 = LOL_T_FLOATING_POINT>
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<typename T, typename T2 = LOL_T_FLOATING_POINT>
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<typename T, typename T2 = LOL_T_SIGNED>
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<typename T, typename T2 = T, typename DUMMY = LOL_T_UNSIGNED>
LOL_ATTR_NODISCARD static inline T2 abs(T x) { return x; }
lol_attr_nodiscard static inline T2 abs(T x) { return x; }

template<typename T, typename T2 = LOL_T_INTEGRAL>
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<typename T, typename T2 = LOL_T_INTEGRAL>
LOL_ATTR_NODISCARD static inline T2 floor(T x) { return x; }
lol_attr_nodiscard static inline T2 floor(T x) { return x; }
template<typename T, typename T2 = LOL_T_INTEGRAL>
LOL_ATTR_NODISCARD static inline T2 ceil(T x) { return x; }
lol_attr_nodiscard static inline T2 ceil(T x) { return x; }
template<typename T, typename T2 = LOL_T_INTEGRAL>
LOL_ATTR_NODISCARD static inline T2 round(T x) { return x; }
lol_attr_nodiscard static inline T2 round(T x) { return x; }

template<typename T, typename T2 = LOL_T_ARITHMETIC>
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<typename T, typename T2 = LOL_T_ARITHMETIC>
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<typename T, typename T2 = LOL_T_ARITHMETIC>
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<typename T, typename T2 = LOL_T_ARITHMETIC>
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<typename T, typename T2 = LOL_T_ARITHMETIC>
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<typename T, typename T2 = LOL_T_SIGNED>
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<typename T, typename T2 = T, typename DUMMY = LOL_T_UNSIGNED>
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 */


+ 15
- 15
legacy/lol/math/geometry.h View File

@@ -91,7 +91,7 @@ T_(box_t<, C_ 4>, box4)
#undef T_

template<typename T, int N>
struct LOL_ATTR_NODISCARD box_t
struct lol_attr_nodiscard box_t
{
inline box_t()
: aa(vec_t<T, N>(T(0))),
@@ -154,12 +154,12 @@ struct LOL_ATTR_NODISCARD box_t
return *this = *this * s;
}

LOL_ATTR_NODISCARD bool operator ==(box_t<T,N> const &box) const
lol_attr_nodiscard bool operator ==(box_t<T,N> const &box) const
{
return aa == box.aa && bb == box.bb;
}

LOL_ATTR_NODISCARD bool operator !=(box_t<T,N> const &box) const
lol_attr_nodiscard bool operator !=(box_t<T,N> 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)


+ 29
- 29
legacy/lol/math/half.h View File

@@ -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);


+ 9
- 9
legacy/lol/math/matrix.h View File

@@ -37,7 +37,7 @@ namespace lol
*/

template<typename T, int COLS, int ROWS>
struct LOL_ATTR_NODISCARD mat_t
struct lol_attr_nodiscard mat_t
: public linear_ops::base<vec_t<T,ROWS>>
{
static int const count = COLS;
@@ -75,7 +75,7 @@ private:
*/

template <typename T>
struct LOL_ATTR_NODISCARD mat_t<T, 2, 2>
struct lol_attr_nodiscard mat_t<T, 2, 2>
: public linear_ops::base<vec_t<T,2>>
{
static int const count = 2;
@@ -128,7 +128,7 @@ static_assert(sizeof(dmat2) == 32, "sizeof(dmat2) == 32");
*/

template <typename T>
struct LOL_ATTR_NODISCARD mat_t<T, 3, 3>
struct lol_attr_nodiscard mat_t<T, 3, 3>
: public linear_ops::base<vec_t<T,3>>
{
static int const count = 3;
@@ -220,7 +220,7 @@ static_assert(sizeof(dmat3) == 72, "sizeof(dmat3) == 72");
*/

template <typename T>
struct LOL_ATTR_NODISCARD mat_t<T, 4, 4>
struct lol_attr_nodiscard mat_t<T, 4, 4>
: public linear_ops::base<vec_t<T,4>>
{
static int const count = 4;
@@ -403,7 +403,7 @@ mat_t<T, N - 1, N - 1> submatrix(mat_t<T, N, N> const &m, int i, int j)
* Compute square matrix cofactor
*/

template<typename T, int N> LOL_ATTR_NODISCARD
template<typename T, int N> lol_attr_nodiscard
T cofactor(mat_t<T, N, N> 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<T, N, N> const &m, int i, int j)
return ((i + j) & 1) ? -tmp : tmp;
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
T cofactor(mat_t<T, 2, 2> const &m, int i, int j)
{
/* This specialisation shouldn't be needed, but Visual Studio. */
@@ -421,7 +421,7 @@ T cofactor(mat_t<T, 2, 2> const &m, int i, int j)
}

// Lu decomposition with partial pivoting
template<typename T, int N> LOL_ATTR_NODISCARD
template<typename T, int N> lol_attr_nodiscard
std::tuple<mat_t<T, N, N>, vec_t<int, N>, int> lu_decomposition(mat_t<T, N, N> const &m)
{
mat_t<T, N, N> lu = m;
@@ -464,7 +464,7 @@ std::tuple<mat_t<T, N, N>, vec_t<int, N>, int> lu_decomposition(mat_t<T, N, N> c
* Compute square matrix determinant, with a specialisation for 1×1 matrices
*/

template<typename T, int N> LOL_ATTR_NODISCARD
template<typename T, int N> lol_attr_nodiscard
T determinant(mat_t<T, N, N> const &m)
{
auto lup = lu_decomposition(m);
@@ -476,7 +476,7 @@ T determinant(mat_t<T, N, N> const &m)
return det;
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
T const & determinant(mat_t<T, 1, 1> const &m)
{
return m[0][0];


+ 4
- 4
legacy/lol/math/ops.h View File

@@ -70,14 +70,14 @@ namespace swizzle_ops
namespace swizzle_ops
{

template<typename T, int N, int SWIZZLE1, int SWIZZLE2> LOL_ATTR_NODISCARD
template<typename T, int N, int SWIZZLE1, int SWIZZLE2> lol_attr_nodiscard
static inline typename std::enable_if<SWIZZLE1 != FULL_SWIZZLE || SWIZZLE2 != FULL_SWIZZLE, bool>::type
operator ==(vec_t<T,N,SWIZZLE1> const &a, vec_t<T,N,SWIZZLE2> const &b)
{
return vec_t<T,N>(a) == vec_t<T,N>(b);
}

template<typename T, int N, int SWIZZLE1, int SWIZZLE2> LOL_ATTR_NODISCARD
template<typename T, int N, int SWIZZLE1, int SWIZZLE2> lol_attr_nodiscard
static inline typename std::enable_if<SWIZZLE1 != FULL_SWIZZLE || SWIZZLE2 != FULL_SWIZZLE, bool>::type
operator !=(vec_t<T,N,SWIZZLE1> const &a, vec_t<T,N,SWIZZLE2> const &b)
{
@@ -135,7 +135,7 @@ namespace linear_ops
* Comparisons
*/

template<typename V> LOL_ATTR_NODISCARD
template<typename V> lol_attr_nodiscard
static inline typename std::enable_if<std::is_base_of<base<typename V::element>, 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<typename V> LOL_ATTR_NODISCARD
template<typename V> lol_attr_nodiscard
static inline typename std::enable_if<std::is_base_of<base<typename V::element>, V>::value, bool>::type
operator !=(V const &a, V const &b)
{


+ 16
- 16
legacy/lol/math/transform.h View File

@@ -29,7 +29,7 @@ namespace lol
*/

template<typename T>
struct LOL_ATTR_NODISCARD cmplx_t : public linear_ops::base<T>
struct lol_attr_nodiscard cmplx_t : public linear_ops::base<T>
{
static int const count = 2;
typedef T scalar_element;
@@ -77,7 +77,7 @@ static_assert(sizeof(dcmplx) == 16, "sizeof(dcmplx) == 16");
*/

template<typename T>
struct LOL_ATTR_NODISCARD quat_t : public linear_ops::base<T>
struct lol_attr_nodiscard quat_t : public linear_ops::base<T>
{
static int const count = 4;
typedef T scalar_element;
@@ -231,7 +231,7 @@ struct LOL_ATTR_NODISCARD quat_t : public linear_ops::base<T>
return normalize(v);
}

LOL_ATTR_NODISCARD inline T angle()
lol_attr_nodiscard inline T angle()
{
vec_t<T,3> v(x, y, z);
T n2 = sqlength(v);
@@ -256,7 +256,7 @@ static_assert(sizeof(dquat) == 32, "sizeof(dquat) == 32");
*/

template<typename T>
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<U> const &q)
* Common operations on transforms
*/

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T dot(cmplx_t<T> const &t1, cmplx_t<T> const &t2)
{
T ret(0);
@@ -349,20 +349,20 @@ static inline T dot(cmplx_t<T> const &t1, cmplx_t<T> const &t2)
return ret;
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T sqlength(cmplx_t<T> const &t)
{
return dot(t, t);
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T length(cmplx_t<T> const &t)
{
/* FIXME: this is not very nice */
return (T)sqrt((double)sqlength(t));
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T norm(cmplx_t<T> const &t)
{
return length(t);
@@ -377,7 +377,7 @@ static inline cmplx_t<T> normalize(cmplx_t<T> const &z)

/* XXX: duplicate */

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T dot(quat_t<T> const &t1, quat_t<T> const &t2)
{
T ret(0);
@@ -386,20 +386,20 @@ static inline T dot(quat_t<T> const &t1, quat_t<T> const &t2)
return ret;
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T sqlength(quat_t<T> const &t)
{
return dot(t, t);
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T length(quat_t<T> const &t)
{
/* FIXME: this is not very nice */
return (T)sqrt((double)sqlength(t));
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline T norm(quat_t<T> const &t)
{
return length(t);
@@ -434,22 +434,22 @@ static inline cmplx_t<T> operator /(cmplx_t<T> a, cmplx_t<T> const &b)
return a * inverse(b);
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline bool operator ==(cmplx_t<T> const &a, T b)
{
return (a.x == b) && !a.y;
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline bool operator !=(cmplx_t<T> const &a, T b)
{
return (a.x != b) || a.y;
}

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline bool operator ==(T a, cmplx_t<T> const &b) { return b == a; }

template<typename T> LOL_ATTR_NODISCARD
template<typename T> lol_attr_nodiscard
static inline bool operator !=(T a, cmplx_t<T> const &b) { return b != a; }

/*


+ 9
- 9
legacy/lol/math/vector.h View File

@@ -47,7 +47,7 @@ namespace lol
*/

template<typename T, int N, int SWIZZLE>
struct LOL_ATTR_NODISCARD vec_t
struct lol_attr_nodiscard vec_t
/* MUST have a different base than e.g. vec_t<T,2> otherwise the unions
* in vec_t<T,2> 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<typename T, int N>
struct LOL_ATTR_NODISCARD vec_t<T, N, FULL_SWIZZLE>
struct lol_attr_nodiscard vec_t<T, N, FULL_SWIZZLE>
: public componentwise_ops::base<T>
{
static int const count = N;
@@ -207,7 +207,7 @@ private:
*/

template <typename T>
struct LOL_ATTR_NODISCARD vec_t<T,2>
struct lol_attr_nodiscard vec_t<T,2>
: public swizzle_ops::base<T>
{
static int const count = 2;
@@ -318,7 +318,7 @@ static_assert(sizeof(dvec2) == 16, "sizeof(dvec2) == 16");
*/

template <typename T>
struct LOL_ATTR_NODISCARD vec_t<T,3>
struct lol_attr_nodiscard vec_t<T,3>
: public swizzle_ops::base<T>
{
static int const count = 3;
@@ -559,7 +559,7 @@ static_assert(sizeof(dvec3) == 24, "sizeof(dvec3) == 24");
*/

template <typename T>
struct LOL_ATTR_NODISCARD vec_t<T,4>
struct lol_attr_nodiscard vec_t<T,4>
: public swizzle_ops::base<T>
{
static int const count = 4;
@@ -1121,7 +1121,7 @@ static inline vec_t<T,N> mix(vec_t<T,N,SWIZZLE1> const &x,
* Some GLSL-like functions.
*/

template<typename T, int N, int SWIZZLE1, int SWIZZLE2> LOL_ATTR_NODISCARD
template<typename T, int N, int SWIZZLE1, int SWIZZLE2> lol_attr_nodiscard
static inline T dot(vec_t<T,N,SWIZZLE1> const &a,
vec_t<T,N,SWIZZLE2> const &b)
{
@@ -1131,13 +1131,13 @@ static inline T dot(vec_t<T,N,SWIZZLE1> const &a,
return ret;
}

template<typename T, int N, int SWIZZLE> LOL_ATTR_NODISCARD
template<typename T, int N, int SWIZZLE> lol_attr_nodiscard
static inline T sqlength(vec_t<T,N,SWIZZLE> const &a)
{
return dot(a, a);
}

template<typename T, int N, int SWIZZLE> LOL_ATTR_NODISCARD
template<typename T, int N, int SWIZZLE> lol_attr_nodiscard
static inline T length(vec_t<T,N,SWIZZLE> const &a)
{
/* FIXME: this is not very nice */
@@ -1155,7 +1155,7 @@ static inline vec_t<T,N> lerp(vec_t<T,N,SWIZZLE1> const &a,
return ret;
}

template<typename T, int N, int SWIZZLE1, int SWIZZLE2> LOL_ATTR_NODISCARD
template<typename T, int N, int SWIZZLE1, int SWIZZLE2> lol_attr_nodiscard
static inline T distance(vec_t<T,N,SWIZZLE1> const &a,
vec_t<T,N,SWIZZLE2> const &b)
{


+ 0
- 16
legacy/lol/net/all.h View File

@@ -1,16 +0,0 @@
//
// Lol Engine
//
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// 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 <lol/net/http.h>


+ 0
- 20
legacy/lol/sys/all.h View File

@@ -1,20 +0,0 @@
//
// Lol Engine
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
//
// 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 <lol/sys/thread.h>
#include <lol/sys/timer.h> /* requires thread.h */
#include <lol/sys/getopt.h>
#include <lol/sys/init.h>
#include <lol/sys/file.h>


+ 0
- 60
legacy/lol/sys/timer.h View File

@@ -1,60 +0,0 @@
//
// Lol Engine
//
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// © 2016 Guillaume Bittoun <guillaume.bittoun@gmail.com>
//
// 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 <chrono>
#include <thread>

//
// 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<float>(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<std::chrono::duration<float>>(tp - tp0).count();
}
};

} /* namespace lol */


Loading…
Cancel
Save