From 8fe56fc27db2c03c75313800d7739741fda07034 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Mon, 2 Mar 2020 07:58:39 +0100 Subject: [PATCH] Clean up the features.h header. --- legacy/features.h | 191 ------------------------------- lol-core | 2 +- src/Makefile.am | 4 +- src/base/features.cpp | 30 ----- src/engine/ticker.cpp | 10 +- src/gpu/debug.cpp | 10 +- src/gpu/shader.cpp | 15 +-- src/image/codec/imlib2-image.cpp | 6 +- src/lol-core.vcxproj | 2 - src/lol-core.vcxproj.filters | 6 - src/lol/base/all.h | 7 +- src/lol/base/array.h | 4 +- src/lol/base/log.h | 14 ++- src/lol/image/image.h | 8 +- src/lol/math/arraynd.h | 4 +- src/lol/math/bigint.h | 4 +- src/lol/math/functions.h | 86 +++++++------- src/lol/math/geometry.h | 32 +++--- src/lol/math/half.h | 60 +++++----- src/ui/sdl-input.cpp | 4 +- src/utils.h | 4 +- 21 files changed, 137 insertions(+), 366 deletions(-) delete mode 100644 legacy/features.h delete mode 100644 src/base/features.cpp diff --git a/legacy/features.h b/legacy/features.h deleted file mode 100644 index 844f36b4..00000000 --- a/legacy/features.h +++ /dev/null @@ -1,191 +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 - -// -// The build-time features -// ----------------------- -// - -/* - * Check for C++11 and later features. - */ - -/* These features aren't necessarily supported by all compilers */ -#undef LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS -#undef LOL_FEATURE_CXX11_ISNAN /* FIXME: is this the right place? */ -#undef LOL_FEATURE_CXX11_NULLPTR -#undef LOL_FEATURE_CXX11_TEMPLATE_ALIASES -#undef LOL_FEATURE_CXX11_SFINAE_FOR_CTORS - -#undef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD -#undef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH - -/* Features detected through __has_cpp_attribute */ -#ifdef __has_cpp_attribute -# if __has_cpp_attribute(nodiscard) -# define LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD 1 -# endif -# if __has_cpp_attribute(fallthrough) -# define LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH 1 -# endif -#endif - -/* Features supported by GCC */ -#if defined __GNUC__ -# if !defined(__GXX_EXPERIMENTAL_CXX0X) && __cplusplus < 201103L -# error "sorry, this version of GCC does not support constexpr" -# endif -# define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1 -# define LOL_FEATURE_CXX11_ISNAN 1 -# define LOL_FEATURE_CXX11_NULLPTR 1 -# define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1 -# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 470 -# define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1 -# endif -#endif - -/* Features supported by Clang */ -#if !defined __GNUC__ && defined __has_feature -# define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1 -# if !__has_feature(cxx_constexpr) -# error "sorry, this version of clang does not support constexpr" -# endif -# define LOL_FEATURE_CXX11_ISNAN 1 -# if __has_feature(cxx_nullptr) -# define LOL_FEATURE_CXX11_NULLPTR 1 -# endif -# define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1 -# define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1 -#endif - -/* Features supported by Visual Studio */ -#if defined _MSC_VER -# if _MSC_VER < 1910 -# error "sorry, Visual Studio 2017 or later is needed" -# endif -# define LOL_FEATURE_CXX11_TEMPLATE_ALIASES 1 -# define LOL_FEATURE_CXX11_ISNAN 1 -# define LOL_FEATURE_CXX11_NULLPTR 1 -# define LOL_FEATURE_CXX11_SFINAE_FOR_CTORS 1 -# define LOL_FEATURE_CXX11_INHERIT_CONSTRUCTORS 1 -#endif - - -/* - * Define some attribute macros. - */ - -#ifdef __GNUC__ -# define LOL_ATTR_FORMAT(n, p) __attribute__((format(printf, n, p))) -#else -# define LOL_ATTR_FORMAT(n, p) -#endif - -#if defined(_WIN32) -# define LOL_ATTR_STDCALL __stdcall -#else -# define LOL_ATTR_STDCALL /* */ -#endif - -#ifdef LOL_FEATURE_CXX17_ATTRIBUTE_NODISCARD -# define LOL_ATTR_NODISCARD [[nodiscard]] -#else -# define LOL_ATTR_NODISCARD /* */ -#endif - -#ifdef LOL_FEATURE_CXX17_ATTRIBUTE_FALLTHROUGH -# define LOL_ATTR_FALLTHROUGH [[fallthrough]]; -#else -# define LOL_ATTR_FALLTHROUGH /* */ -#endif - - -/* - * Ensure we have ptrdiff_t. - */ - -#include - - -/* - * Ensure we have nullptr. - */ - -#if !LOL_FEATURE_CXX11_NULLPTR -# if defined nullptr - /* do nothing */ -# elif defined __GNUC__ -# define nullptr __null -# else -# include -# define nullptr NULL -# endif -#endif - - -/* - * Ensure isnan() is present even on systems that don't define it, or - * when -ffast-math is being used. - */ - -#include -#if defined __FAST_MATH__ -# undef isnan -#endif -#if !defined isnan && !LOL_FEATURE_CXX11_ISNAN -# define isnan isnan -# include -static inline int isnan(float f) -{ - union { float f; uint32_t x; } u = { f }; - return (u.x << 1) > 0xff000000u; -} -#endif - - -// -// Some feature test functions -// - -namespace lol -{ - extern bool has_threads(); - - // A handy endianness test function - static inline bool is_big_endian() - { - union { int i; char c; } u; - u.i = 1; - return u.c == 0; - } -} - - -// -// Ensure CreateFile2() is available on Mingw -// - -#if defined _WIN32 && !defined _MSC_VER && \ - (!defined _WIN32_WINNT || _WIN32_WINNT < 0x0602) -# undef _WIN32_WINNT -# define _WIN32_WINNT 0x0602 -#endif - - -/* XXX: workaround for X11 headers that try to #define these */ -#undef Always -#define Always Always -#undef None -#define None None - diff --git a/lol-core b/lol-core index e1ef913d..f0b8cfc6 160000 --- a/lol-core +++ b/lol-core @@ -1 +1 @@ -Subproject commit e1ef913daa492bc03b233824aae71f2ee351fb21 +Subproject commit f0b8cfc6f232b949c489f66479b7fc65c2c34891 diff --git a/src/Makefile.am b/src/Makefile.am index b21bf880..24c09b1c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,7 +31,7 @@ liblol_core_headers = \ lol/lua.h \ \ lol/base/all.h \ - lol/base/avl_tree.h ../legacy/features.h lol/base/tuple.h lol/base/types.h \ + lol/base/avl_tree.h lol/base/tuple.h lol/base/types.h \ lol/base/array.h lol/base/assert.h lol/base/map.h lol/base/enum.h \ lol/base/log.h \ \ @@ -89,7 +89,7 @@ liblol_core_sources = \ easymesh/shinydebuglighting.lolfx easymesh/shinydebugnormal.lolfx \ easymesh/shinydebugUV.lolfx easymesh/shiny_SK.lolfx \ \ - base/assert.cpp base/features.cpp base/log.cpp base/string.cpp \ + base/assert.cpp base/log.cpp base/string.cpp \ \ math/half.cpp \ math/geometry.cpp \ diff --git a/src/base/features.cpp b/src/base/features.cpp deleted file mode 100644 index f4b87d5c..00000000 --- a/src/base/features.cpp +++ /dev/null @@ -1,30 +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. -// - -#include - -namespace lol -{ - -bool has_threads() -{ - static bool const disable_threads = sys::getenv("LOL_NOTHREADS").size() > 0; -#if defined __EMSCRIPTEN__ && !defined __EMSCRIPTEN_PTHREADS__ - // For some reason hardware_concurrency() will return the actual number - // of threads/cores even though the system cannot spawn threads. - return false; -#endif - return !disable_threads && std::thread::hardware_concurrency() > 1; -} - -} // namespace lol - diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 02a9f543..6e921408 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -30,8 +30,8 @@ class ticker_data public: ticker_data() { - msg::debug("platform %s threads\n", has_threads() ? "has" : "has no"); - if (has_threads()) + msg::debug("platform %s threads\n", thread::has_threads() ? "has" : "has no"); + if (thread::has_threads()) { gamethread = std::make_unique(std::bind(&ticker_data::GameThreadMain, this)); drawtick.push(1); @@ -48,7 +48,7 @@ public: "still %d autoreleased entities\n", DEPRECATED_m_autolist.count()); msg::debug("%d frames required to quit\n", m_frame - m_quitframe); - if (has_threads()) + if (thread::has_threads()) { gametick.push(0); disktick.push(0); @@ -570,7 +570,7 @@ void ticker::teardown() void ticker::tick_draw() { - if (has_threads()) + if (thread::has_threads()) { int n = data->drawtick.pop(); if (n == 0) @@ -584,7 +584,7 @@ void ticker::tick_draw() Profiler::Start(Profiler::STAT_TICK_BLIT); /* Signal game thread that it can carry on */ - if (has_threads()) + if (thread::has_threads()) data->gametick.push(1); else ticker_data::DiskThreadTick(); diff --git a/src/gpu/debug.cpp b/src/gpu/debug.cpp index e3e176a9..7d8cbd92 100644 --- a/src/gpu/debug.cpp +++ b/src/gpu/debug.cpp @@ -14,6 +14,12 @@ #include "lolgl.h" +#if defined(_WIN32) +# define attr_stdcall __stdcall +#else +# define attr_stdcall /* */ +#endif + namespace lol { @@ -49,7 +55,7 @@ static std::map gl_dbg_severity_to_str { GL_DEBUG_SEVERITY_NOTIFICATION, "notification" }, }; -static void LOL_ATTR_STDCALL +static void attr_stdcall gl_debug(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *user_param) @@ -75,7 +81,7 @@ static void LOL_ATTR_STDCALL } #if defined LOL_USE_GLEW && !defined __APPLE__ -static void LOL_ATTR_STDCALL +static void attr_stdcall gl_debug_amd(GLuint id, GLenum category, GLenum severity, GLsizei length, const GLchar* message, GLvoid* user_param) diff --git a/src/gpu/shader.cpp b/src/gpu/shader.cpp index 11a774e0..5f0989d2 100644 --- a/src/gpu/shader.cpp +++ b/src/gpu/shader.cpp @@ -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 @@ -991,8 +991,8 @@ std::string ShaderBuilder::Build() //Added shader variables for (int var = 0; var < ShaderVariable::InOut; var++) { - array all_keys = keys(m_parameters[prog][var]); - if (all_keys.count()) + auto all_keys = keys(m_parameters[prog][var]); + if (all_keys.size()) { code += std::string("//- ") + Shader::GetVariableQualifier((ShaderVariable)var) + " ----\n"; for (auto const &key : all_keys) @@ -1028,14 +1028,9 @@ std::string ShaderBuilder::Build() //Add local variables int var = ShaderVariable::InOut; - array all_keys = keys(m_parameters[prog][var]); + auto all_keys = keys(m_parameters[prog][var]); for (auto const &key : all_keys) - { - if (all_keys.count()) - { - code += " " + m_parameters[prog][var][key] + " " + key + ";\n"; - } - } + code += " " + m_parameters[prog][var][key] + " " + key + ";\n"; code += "\n"; //Add calls diff --git a/src/image/codec/imlib2-image.cpp b/src/image/codec/imlib2-image.cpp index 437cd490..3caab984 100644 --- a/src/image/codec/imlib2-image.cpp +++ b/src/image/codec/imlib2-image.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 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 @@ -83,7 +83,7 @@ ResourceCodecData *Imlib2ImageCodec::Load(std::string const &path) for (int i = 0; i < size.x * size.y; i++) { - if (is_big_endian()) + if (os::is_big_endian()) dstdata[i] = srcdata[i].argb; else dstdata[i] = srcdata[i].bgra; @@ -113,7 +113,7 @@ bool Imlib2ImageCodec::Save(std::string const &path, ResourceCodecData *data) for (int i = 0; i < size.x * size.y; i++) { - if (is_big_endian()) + if (os::is_big_endian()) dstdata[i] = srcdata[i].argb; else dstdata[i] = srcdata[i].bgra; diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj index 2395ecf1..b9a52d91 100644 --- a/src/lol-core.vcxproj +++ b/src/lol-core.vcxproj @@ -106,7 +106,6 @@ - @@ -251,7 +250,6 @@ - diff --git a/src/lol-core.vcxproj.filters b/src/lol-core.vcxproj.filters index 45a7632b..394fc601 100644 --- a/src/lol-core.vcxproj.filters +++ b/src/lol-core.vcxproj.filters @@ -14,9 +14,6 @@ base - - base - base @@ -341,9 +338,6 @@ lol\base - - lol\base - lol\base diff --git a/src/lol/base/all.h b/src/lol/base/all.h index 2ae2adde..6f238b57 100644 --- a/src/lol/base/all.h +++ b/src/lol/base/all.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2013 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 @@ -12,15 +12,12 @@ #pragma once -#include - #include #include #include #include #include #include -#include -#include +#include #include diff --git a/src/lol/base/array.h b/src/lol/base/array.h index dc65ee32..2f6139b9 100644 --- a/src/lol/base/array.h +++ b/src/lol/base/array.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2013—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -50,7 +50,7 @@ enum class SortAlgorithm : uint8_t * m_count are allocated. The rest is uninitialised memory. */ -template class LOL_ATTR_NODISCARD array_base +template class [[nodiscard]] array_base { public: typedef T element_t; diff --git a/src/lol/base/log.h b/src/lol/base/log.h index f42d91cb..c86a1dba 100644 --- a/src/lol/base/log.h +++ b/src/lol/base/log.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 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 @@ -18,7 +18,9 @@ // The central logging system. // -#include +#include + +#include #include namespace lol @@ -27,10 +29,10 @@ namespace lol class msg { public: - static void debug(char const *format, ...) LOL_ATTR_FORMAT(1, 2); - static void info(char const *format, ...) LOL_ATTR_FORMAT(1, 2); - static void warn(char const *format, ...) LOL_ATTR_FORMAT(1, 2); - static void error(char const *format, ...) LOL_ATTR_FORMAT(1, 2); + static void debug(char const *format, ...) lol_attr_printf_format(1, 2); + static void info(char const *format, ...) lol_attr_printf_format(1, 2); + static void warn(char const *format, ...) lol_attr_printf_format(1, 2); + static void error(char const *format, ...) lol_attr_printf_format(1, 2); enum class message_type { diff --git a/src/lol/image/image.h b/src/lol/image/image.h index 275cdd6b..21772d58 100644 --- a/src/lol/image/image.h +++ b/src/lol/image/image.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 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 @@ -93,13 +93,13 @@ public: void SetWrap(WrapMode wrap_x, WrapMode wrap_y); /* Lock continuous arrays of pixels for writing */ - template LOL_ATTR_NODISCARD typename PixelType::type *lock(); - LOL_ATTR_NODISCARD void *lock(); + template [[nodiscard]] typename PixelType::type *lock(); + [[nodiscard]] void *lock(); void unlock(void const *pixels); /* Lock 2D arrays of pixels for writing */ template - LOL_ATTR_NODISCARD inline array2d::type> &lock2d() + [[nodiscard]] inline array2d::type> &lock2d() { /* Hack: this indirection is needed because of a Visual Studio ICE */ return *(array2d::type> *)lock2d_helper(T); diff --git a/src/lol/math/arraynd.h b/src/lol/math/arraynd.h index 61a31b63..d73142ce 100644 --- a/src/lol/math/arraynd.h +++ b/src/lol/math/arraynd.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2013—2014 Benjamin “Touky” Huet // © 2013—2014 Guillaume Bittoun // @@ -96,7 +96,7 @@ private: template -class LOL_ATTR_NODISCARD arraynd : protected array +class [[nodiscard]] arraynd : protected array { public: typedef array super; diff --git a/src/lol/math/bigint.h b/src/lol/math/bigint.h index d422f3c7..363721d3 100644 --- a/src/lol/math/bigint.h +++ b/src/lol/math/bigint.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 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 @@ -37,7 +37,7 @@ namespace lol */ template -class LOL_ATTR_NODISCARD bigint +class [[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/src/lol/math/functions.h b/src/lol/math/functions.h index 02b38914..acb0c24e 100644 --- a/src/lol/math/functions.h +++ b/src/lol/math/functions.h @@ -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 @@ -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); } + [[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); } + [[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); } + [[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) +[[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) +[[nodiscard]] static inline float degrees(float radians) { return radians * (180.0f / F_PI); } -LOL_ATTR_NODISCARD static inline double degrees(double radians) +[[nodiscard]] static inline double degrees(double radians) { return radians * (180.0 / D_PI); } -LOL_ATTR_NODISCARD static inline ldouble degrees(ldouble radians) +[[nodiscard]] static inline ldouble degrees(ldouble radians) { return radians * (180.0L / LD_PI); } -LOL_ATTR_NODISCARD static inline float radians(float degrees) +[[nodiscard]] static inline float radians(float degrees) { return degrees * (F_PI / 180.0f); } -LOL_ATTR_NODISCARD static inline double radians(double degrees) +[[nodiscard]] static inline double radians(double degrees) { return degrees * (D_PI / 180.0); } -LOL_ATTR_NODISCARD static inline ldouble radians(ldouble degrees) +[[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)); } +[[nodiscard]] static inline float degrees(int8_t x) { return degrees(float(x)); } +[[nodiscard]] static inline float degrees(uint8_t x) { return degrees(float(x)); } +[[nodiscard]] static inline float degrees(int16_t x) { return degrees(float(x)); } +[[nodiscard]] static inline float degrees(uint16_t x) { return degrees(float(x)); } +[[nodiscard]] static inline double degrees(int32_t x) { return degrees(double(x)); } +[[nodiscard]] static inline double degrees(uint32_t x) { return degrees(double(x)); } +[[nodiscard]] static inline ldouble degrees(int64_t x) { return degrees(ldouble(x)); } +[[nodiscard]] static inline ldouble degrees(uint64_t x) { return degrees(ldouble(x)); } + +[[nodiscard]] static inline float radians(int8_t x) { return radians(float(x)); } +[[nodiscard]] static inline float radians(uint8_t x) { return radians(float(x)); } +[[nodiscard]] static inline float radians(int16_t x) { return radians(float(x)); } +[[nodiscard]] static inline float radians(uint16_t x) { return radians(float(x)); } +[[nodiscard]] static inline double radians(int32_t x) { return radians(double(x)); } +[[nodiscard]] static inline double radians(uint32_t x) { return radians(double(x)); } +[[nodiscard]] static inline ldouble radians(int64_t x) { return radians(ldouble(x)); } +[[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) +[[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) +[[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); } +[[nodiscard]] static inline T2 abs(T x) { return std::abs(x); } template -LOL_ATTR_NODISCARD static inline T2 abs(T x) { return x; } +[[nodiscard]] static inline T2 abs(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 fmod(T x, T y) { return x % y; } +[[nodiscard]] static inline T2 fmod(T x, T y) { return x % y; } template -LOL_ATTR_NODISCARD static inline T2 floor(T x) { return x; } +[[nodiscard]] static inline T2 floor(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 ceil(T x) { return x; } +[[nodiscard]] static inline T2 ceil(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 round(T x) { return x; } +[[nodiscard]] static inline T2 round(T x) { return x; } template -LOL_ATTR_NODISCARD static inline T2 sq(T x) { return x * x; } +[[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); } +[[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); } +[[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); } +[[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)); } +[[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)); } +[[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); } +[[nodiscard]] static inline T2 sign(T x) { return (T)((T)0 < x); } } /* namespace lol */ diff --git a/src/lol/math/geometry.h b/src/lol/math/geometry.h index 7b37ce63..f110add5 100644 --- a/src/lol/math/geometry.h +++ b/src/lol/math/geometry.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2010—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -91,7 +91,7 @@ T_(box_t<, C_ 4>, box4) #undef T_ template -struct LOL_ATTR_NODISCARD box_t +struct [[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 + [[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 + [[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; + [[nodiscard]] bool operator==(float value) const; + [[nodiscard]] bool operator!=(float value) const; + [[nodiscard]] bool operator<(float value) const; + [[nodiscard]] bool operator<=(float value) const; + [[nodiscard]] bool operator>(float value) const; + [[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); +[[nodiscard]] bool operator==(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator!=(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator<(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator<=(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator>(float value, const TestEpsilon& epsilon); +[[nodiscard]] bool operator>=(float value, const TestEpsilon& epsilon); //-- static inline bool TestAABBVsAABB(box2 const &b1, box2 const &b2) diff --git a/src/lol/math/half.h b/src/lol/math/half.h index 667fa2b0..084d5aca 100644 --- a/src/lol/math/half.h +++ b/src/lol/math/half.h @@ -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 @@ -32,7 +32,7 @@ namespace lol namespace half_ops { struct base {}; } -class LOL_ATTR_NODISCARD half +class [[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 + [[nodiscard]] inline int is_nan() const { return ((bits & 0x7c00u) == 0x7c00u) && (bits & 0x03ffu); } - LOL_ATTR_NODISCARD inline int is_finite() const + [[nodiscard]] inline int is_finite() const { return (bits & 0x7c00u) != 0x7c00u; } - LOL_ATTR_NODISCARD inline int is_inf() const + [[nodiscard]] inline int is_inf() const { return (uint16_t)(bits << 1) == (0x7c00u << 1); } - LOL_ATTR_NODISCARD inline int is_normal() const + [[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); } + [[nodiscard]] inline operator int8_t() const { return (int8_t)(float)*this; } + [[nodiscard]] inline operator uint8_t() const { return (uint8_t)(float)*this; } + [[nodiscard]] inline operator int16_t() const { return (int16_t)(float)*this; } + [[nodiscard]] inline operator uint16_t() const { return (uint16_t)(float)*this; } + [[nodiscard]] inline operator int32_t() const { return (int32_t)(float)*this; } + [[nodiscard]] inline operator uint32_t() const { return (uint32_t)(float)*this; } + [[nodiscard]] inline operator int64_t() const { return (int64_t)(float)*this; } + [[nodiscard]] inline operator uint64_t() const { return (uint64_t)(float)*this; } + + [[nodiscard]] operator float() const; + [[nodiscard]] inline operator double() const { return (float)(*this); } + [[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; } + [[nodiscard]] bool operator ==(half x) const { return (float)*this == (float)x; } + [[nodiscard]] bool operator !=(half x) const { return (float)*this != (float)x; } + [[nodiscard]] bool operator <(half x) const { return (float)*this < (float)x; } + [[nodiscard]] bool operator >(half x) const { return (float)*this > (float)x; } + [[nodiscard]] bool operator <=(half x) const { return (float)*this <= (float)x; } + [[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; } + [[nodiscard]] bool operator !() const { return !(bits & 0x7fffu); } + [[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; } + [[nodiscard]] inline float operator +(half h) const { return (float)*this + (float)h; } + [[nodiscard]] inline float operator -(half h) const { return (float)*this - (float)h; } + [[nodiscard]] inline float operator *(half h) const { return (float)*this * (float)h; } + [[nodiscard]] inline float operator /(half h) const { return (float)*this / (float)h; } /* Factories */ static half makefast(float f); diff --git a/src/ui/sdl-input.cpp b/src/ui/sdl-input.cpp index 3415152d..ad6705a2 100644 --- a/src/ui/sdl-input.cpp +++ b/src/ui/sdl-input.cpp @@ -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 @@ -201,7 +201,7 @@ void SdlInput::tick(float seconds) sc2 = input::key::SC_NumLockClearStatus; keyboard->internal_set_key(sc2, !keyboard->key(sc2)); } - LOL_ATTR_FALLTHROUGH + [[fallthrough]]; default: // Set key updates the corresponding key keyboard->internal_set_key(sc, event.type == SDL_KEYDOWN); diff --git a/src/utils.h b/src/utils.h index 5113268e..9c8f6e01 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2018 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2012—2015 Benjamin “Touky” Huet // // Lol Engine is free software. It comes without any warranty, to @@ -18,7 +18,7 @@ // ----------------------------------- // -#include +#include #include