| @@ -1,191 +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 | |||
| // | |||
| // 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 <cstddef> | |||
| /* | |||
| * Ensure we have nullptr. | |||
| */ | |||
| #if !LOL_FEATURE_CXX11_NULLPTR | |||
| # if defined nullptr | |||
| /* do nothing */ | |||
| # elif defined __GNUC__ | |||
| # define nullptr __null | |||
| # else | |||
| # include <cstddef> | |||
| # 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 <cmath> | |||
| #if defined __FAST_MATH__ | |||
| # undef isnan | |||
| #endif | |||
| #if !defined isnan && !LOL_FEATURE_CXX11_ISNAN | |||
| # define isnan isnan | |||
| # include <stdint.h> | |||
| 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 | |||
| @@ -1 +1 @@ | |||
| Subproject commit e1ef913daa492bc03b233824aae71f2ee351fb21 | |||
| Subproject commit f0b8cfc6f232b949c489f66479b7fc65c2c34891 | |||
| @@ -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 \ | |||
| @@ -1,30 +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. | |||
| // | |||
| #include <lol/engine-internal.h> | |||
| 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 | |||
| @@ -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<thread>(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(); | |||
| @@ -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<GLenum, char const *> 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) | |||
| @@ -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 | |||
| @@ -991,8 +991,8 @@ std::string ShaderBuilder::Build() | |||
| //Added shader variables | |||
| for (int var = 0; var < ShaderVariable::InOut; var++) | |||
| { | |||
| array<std::string> 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<std::string> 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 | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 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 | |||
| @@ -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; | |||
| @@ -106,7 +106,6 @@ | |||
| <ClCompile Include="audio\sample.cpp" /> | |||
| <ClCompile Include="camera.cpp" /> | |||
| <ClCompile Include="base\assert.cpp" /> | |||
| <ClCompile Include="base\features.cpp" /> | |||
| <ClCompile Include="base\log.cpp" /> | |||
| <ClCompile Include="base\string.cpp" /> | |||
| <ClCompile Include="debug\fps.cpp" /> | |||
| @@ -251,7 +250,6 @@ | |||
| <ClInclude Include="lol\base\array.h" /> | |||
| <ClInclude Include="lol\base\assert.h" /> | |||
| <ClInclude Include="lol\base\enum.h" /> | |||
| <ClInclude Include="..\legacy\features.h" /> | |||
| <ClInclude Include="lol\base\log.h" /> | |||
| <ClInclude Include="lol\base\map.h" /> | |||
| <ClInclude Include="lol\base\types.h" /> | |||
| @@ -14,9 +14,6 @@ | |||
| <ClCompile Include="base\assert.cpp"> | |||
| <Filter>base</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="base\features.cpp"> | |||
| <Filter>base</Filter> | |||
| </ClCompile> | |||
| <ClCompile Include="base\log.cpp"> | |||
| <Filter>base</Filter> | |||
| </ClCompile> | |||
| @@ -341,9 +338,6 @@ | |||
| <ClInclude Include="lol\base\enum.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="..\legacy\features.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| <ClInclude Include="lol\base\log.h"> | |||
| <Filter>lol\base</Filter> | |||
| </ClInclude> | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2013 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 | |||
| @@ -12,15 +12,12 @@ | |||
| #pragma once | |||
| #include <lol/../../legacy/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/utils.h> | |||
| #include <lol/base/enum.h> | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // 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<typename T, typename ARRAY> class LOL_ATTR_NODISCARD array_base | |||
| template<typename T, typename ARRAY> class [[nodiscard]] array_base | |||
| { | |||
| public: | |||
| typedef T element_t; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2015 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 | |||
| @@ -18,7 +18,9 @@ | |||
| // The central logging system. | |||
| // | |||
| #include <stdint.h> | |||
| #include <lol/base/private/features.h> | |||
| #include <cstdint> | |||
| #include <cstdarg> | |||
| 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 | |||
| { | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 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 | |||
| @@ -93,13 +93,13 @@ public: | |||
| void SetWrap(WrapMode wrap_x, WrapMode wrap_y); | |||
| /* Lock continuous arrays of pixels for writing */ | |||
| template<PixelFormat T> LOL_ATTR_NODISCARD typename PixelType<T>::type *lock(); | |||
| LOL_ATTR_NODISCARD void *lock(); | |||
| template<PixelFormat T> [[nodiscard]] typename PixelType<T>::type *lock(); | |||
| [[nodiscard]] void *lock(); | |||
| void unlock(void const *pixels); | |||
| /* Lock 2D arrays of pixels for writing */ | |||
| template<PixelFormat T> | |||
| LOL_ATTR_NODISCARD inline array2d<typename PixelType<T>::type> &lock2d() | |||
| [[nodiscard]] inline array2d<typename PixelType<T>::type> &lock2d() | |||
| { | |||
| /* Hack: this indirection is needed because of a Visual Studio ICE */ | |||
| return *(array2d<typename PixelType<T>::type> *)lock2d_helper(T); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2013—2014 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // © 2013—2014 Guillaume Bittoun <guillaume.bittoun@gmail.com> | |||
| // | |||
| @@ -96,7 +96,7 @@ private: | |||
| template<int N, typename... T> | |||
| class LOL_ATTR_NODISCARD arraynd : protected array<T...> | |||
| class [[nodiscard]] arraynd : protected array<T...> | |||
| { | |||
| public: | |||
| typedef array<T...> super; | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2015 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 | |||
| @@ -37,7 +37,7 @@ namespace lol | |||
| */ | |||
| template<unsigned int N = 16, typename T = uint32_t> | |||
| 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); | |||
| @@ -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 | |||
| @@ -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); } | |||
| [[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); } | |||
| [[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); } | |||
| [[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) | |||
| [[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<typename T, typename T2 = LOL_T_FLOATING_POINT> | |||
| 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<typename T, typename T2 = LOL_T_FLOATING_POINT> | |||
| 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<typename T, typename T2 = LOL_T_SIGNED> | |||
| 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<typename T, typename T2 = T, typename DUMMY = LOL_T_UNSIGNED> | |||
| LOL_ATTR_NODISCARD static inline T2 abs(T x) { return x; } | |||
| [[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; } | |||
| [[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; } | |||
| [[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; } | |||
| [[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; } | |||
| [[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; } | |||
| [[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); } | |||
| [[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); } | |||
| [[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); } | |||
| [[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)); } | |||
| [[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)); } | |||
| [[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); } | |||
| [[nodiscard]] static inline T2 sign(T x) { return (T)((T)0 < x); } | |||
| } /* namespace lol */ | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2010—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -91,7 +91,7 @@ T_(box_t<, C_ 4>, box4) | |||
| #undef T_ | |||
| template<typename T, int N> | |||
| struct LOL_ATTR_NODISCARD box_t | |||
| struct [[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 | |||
| [[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 | |||
| [[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; | |||
| [[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) | |||
| @@ -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 | |||
| @@ -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); | |||
| @@ -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 | |||
| @@ -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); | |||
| @@ -1,7 +1,7 @@ | |||
| // | |||
| // Lol Engine | |||
| // | |||
| // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net> | |||
| // Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net> | |||
| // © 2012—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com> | |||
| // | |||
| // Lol Engine is free software. It comes without any warranty, to | |||
| @@ -18,7 +18,7 @@ | |||
| // ----------------------------------- | |||
| // | |||
| #include <lol/base/string.h> | |||
| #include <lol/base/utils.h> | |||
| #include <string> | |||