From 53e86aa9c572d1395d54ef8044875803afbabd86 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 6 Mar 2020 00:29:57 +0100 Subject: [PATCH] Clean up header usage. --- doc/samples/btphystest.cpp | 8 +- doc/tutorial/07_input.cpp | 6 +- doc/tutorial/09_sound.cpp | 4 +- doc/tutorial/11_fractal.cpp | 2 +- lol-core | 2 +- src/Makefile.am | 2 +- src/base/log.cpp | 2 +- src/easymesh/easymeshprimitive.cpp | 6 +- src/easymesh/easymeshtransform.cpp | 6 +- src/engine/tickable.cpp | 4 +- src/engine/ticker.cpp | 2 +- src/engine/ticker.h | 6 +- src/image/combine.cpp | 6 +- src/image/filter/convolution.cpp | 6 +- src/image/kernel.cpp | 6 +- src/light.h | 4 +- src/lol-core.vcxproj | 1 - src/lol-core.vcxproj.filters | 3 - src/lol/algorithm/all.h | 1 - src/lol/algorithm/portal.h | 6 +- src/lol/algorithm/sort.h | 130 ----------------------------- src/lol/base/log.h | 3 +- src/lol/engine/tickable.h | 5 +- src/lol/gpu/shader.h | 10 +-- src/lol/sys/file.h | 7 +- src/lol/sys/init.h | 25 +----- src/math/geometry.cpp | 30 +++---- src/scene.cpp | 2 +- src/scene.h | 2 +- src/utils.h | 1 + 30 files changed, 74 insertions(+), 224 deletions(-) delete mode 100644 src/lol/algorithm/sort.h diff --git a/doc/samples/btphystest.cpp b/doc/samples/btphystest.cpp index 3dbd9680..f9a8f01e 100644 --- a/doc/samples/btphystest.cpp +++ b/doc/samples/btphystest.cpp @@ -459,7 +459,7 @@ void BtPhysTest::tick_game(float seconds) //Jump handling //if (length(PhysObj->GetPhysic()->GetLinearVelocity()) < ZERO_SPEED) - if (lol::abs(PhysObj->GetPhysic()->GetLinearVelocity().y) < ZERO_SPEED) + if (lol::fabs(PhysObj->GetPhysic()->GetLinearVelocity().y) < ZERO_SPEED) obj_timer -= seconds; if (obj_timer < .0f) @@ -472,15 +472,15 @@ void BtPhysTest::tick_game(float seconds) } } - float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)), - max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y))); + float fov_ratio = max(max(lol::fabs(screen_min_max[0].x), lol::fabs(screen_min_max[0].y)), + max(lol::fabs(screen_min_max[1].x), lol::fabs(screen_min_max[1].y))); vec3 new_target = cam_center / cam_factor; float fov_dp = .0f; float loc_dp = .0f; //ideally fov is on the target - if (lol::abs(fov_ratio - 1.f) < .2f) + if (lol::fabs(fov_ratio - 1.f) < .2f) fov_dp = ((m_cam_target == -1)?(.7f):(.2f)); else fov_dp = ((m_cam_target == -1)?(1.7f):(.9f)); diff --git a/doc/tutorial/07_input.cpp b/doc/tutorial/07_input.cpp index 28d56caf..b19044f7 100644 --- a/doc/tutorial/07_input.cpp +++ b/doc/tutorial/07_input.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Input tutorial // -// Copyright © 2011—2019 Sam Hocevar +// Copyright © 2011—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -55,9 +55,9 @@ public: auto joystick = input::joystick(0); if ((bool)joystick) { - if (lol::abs(joystick->axis(input::axis::LeftY)) > 0.2f) + if (lol::fabs(joystick->axis(input::axis::LeftY)) > 0.2f) m_pitch_angle += joystick->axis(input::axis::LeftY) * seconds; - if (lol::abs(joystick->axis(input::axis::LeftX)) > 0.2f) + if (lol::fabs(joystick->axis(input::axis::LeftX)) > 0.2f) m_yaw_angle += joystick->axis(input::axis::LeftX) * seconds; } diff --git a/doc/tutorial/09_sound.cpp b/doc/tutorial/09_sound.cpp index 85ca0da9..c7f59292 100644 --- a/doc/tutorial/09_sound.cpp +++ b/doc/tutorial/09_sound.cpp @@ -1,7 +1,7 @@ // // Lol Engine — Sound tutorial // -// Copyright © 2011—2019 Sam Hocevar +// Copyright © 2011—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -35,7 +35,7 @@ public: } for (size_t i = 0; i < m_instrument.size(); ++i) - m_instrument[i] = (int16_t)(i % 80 * (10000 - lol::abs(i - 10000)) * 40 / 10000); + m_instrument[i] = (int16_t)(i % 80 * (10000 - lol::fabs(i - 10000)) * 40 / 10000); m_sample = sample::create(m_instrument.data(), 40000); m_text = new Text("SPACE for sine wave, Left Click for white noise", diff --git a/doc/tutorial/11_fractal.cpp b/doc/tutorial/11_fractal.cpp index 6bbdaed6..efd23439 100644 --- a/doc/tutorial/11_fractal.cpp +++ b/doc/tutorial/11_fractal.cpp @@ -216,7 +216,7 @@ public: else if (m_zoom_speed) { m_zoom_speed *= std::pow(2.0, -seconds * 5.0); - if (lol::abs(m_zoom_speed) < 1e-5 || m_drag) + if (lol::fabs(m_zoom_speed) < 1e-5 || m_drag) m_zoom_speed = 0.0; } diff --git a/lol-core b/lol-core index 4446947a..ec5f308b 160000 --- a/lol-core +++ b/lol-core @@ -1 +1 @@ -Subproject commit 4446947aec179186e165d36f36425ee568a71a34 +Subproject commit ec5f308bd3b69183359e6a16a151acca4fa69f46 diff --git a/src/Makefile.am b/src/Makefile.am index dec71a80..818751f9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,7 +35,7 @@ liblol_core_headers = \ lol/base/log.h \ \ lol/algorithm/all.h \ - lol/algorithm/sort.h lol/algorithm/portal.h \ + lol/algorithm/portal.h \ \ lol/audio/all.h \ lol/audio/audio.h lol/audio/sample.h \ diff --git a/src/base/log.cpp b/src/base/log.cpp index b9cdf7c4..68872b37 100644 --- a/src/base/log.cpp +++ b/src/base/log.cpp @@ -80,7 +80,7 @@ void msg::helper(message_type type, char const *fmt, va_list ap) #if !defined LOL_BUILD_DEBUG && !_DEBUG if (type == message_type::debug) { - static bool const disable_debug = sys::getenv("LOL_DEBUG").size() > 0; + static bool const disable_debug = os::getenv("LOL_DEBUG").size() > 0; if (disable_debug) return; } diff --git a/src/easymesh/easymeshprimitive.cpp b/src/easymesh/easymeshprimitive.cpp index ac1b25f0..c3587741 100644 --- a/src/easymesh/easymeshprimitive.cpp +++ b/src/easymesh/easymeshprimitive.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2010—2015 Sam Hocevar +// Copyright © 2010—2020 Sam Hocevar // © 2009—2015 Cédric Lecacheur // © 2009—2015 Benjamin “Touky” Huet // @@ -207,7 +207,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d) p[k] = normalize(p[k]); uv[k].x = (lol::atan2(p[k].z, p[k].x) + F_PI) / (F_PI * 2.f); - if (abs(p[k].y) >= 1.0f) + if (fabs(p[k].y) >= 1.0f) uv[k].x = -1.f; uv[k].y = lol::atan2(p[k].y, dot(p[k], normalize(p[k] * vec3(1.f,0.f,1.f)))) / F_PI + 0.5f; if (h) @@ -241,7 +241,7 @@ void EasyMesh::AppendCapsule(int ndivisions, float h, float d) int rid[] = { id[k + l], id[(k + 1) % 3 + l] }; if (uv[rid[0]].x >= .0f && uv[rid[1]].x >= .0f && - abs(uv[rid[0]].x - uv[rid[1]].x) > .5f) + fabs(uv[rid[0]].x - uv[rid[1]].x) > .5f) { if (uv[rid[0]].x < uv[rid[1]].x) uv[rid[0]].x += 1.0f; diff --git a/src/easymesh/easymeshtransform.cpp b/src/easymesh/easymeshtransform.cpp index f064d507..bf53d2dd 100644 --- a/src/easymesh/easymeshtransform.cpp +++ b/src/easymesh/easymeshtransform.cpp @@ -155,7 +155,7 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n case MeshTransform::Taper: { float value = m_vert[i].m_coord[axis0.ToScalar()]; - if (absolute) value = abs(value); + if (absolute) value = fabs(value); m_vert[i].m_coord[(axis0.ToScalar() + 1) % 3] *= max(0.f, 1.f + (n0 * value + noff)); m_vert[i].m_coord[(axis0.ToScalar() + 2) % 3] *= max(0.f, 1.f + (n1 * value + noff)); break; @@ -169,14 +169,14 @@ void EasyMesh::DoMeshTransform(MeshTransform ct, Axis axis0, Axis axis1, float n case MeshTransform::Shear: { float value = m_vert[i].m_coord[axis0.ToScalar()]; - if (absolute) value = abs(value); + if (absolute) value = fabs(value); m_vert[i].m_coord[(axis0.ToScalar() + 1) % 3] += (n0 * value + noff); m_vert[i].m_coord[(axis0.ToScalar() + 2) % 3] += (n1 * value + noff); break; } case MeshTransform::Stretch: { - //float value = abs(std::get<0>(m_vert[i])[axis0.ToScalar()]); + //float value = fabs(std::get<0>(m_vert[i])[axis0.ToScalar()]); //std::get<0>(m_vert[i])[(axis0.ToScalar() + 1) % 3] += (lol::pow(value, n0) + noff); //std::get<0>(m_vert[i])[(axis0.ToScalar() + 2) % 3] += (lol::pow(value, n1) + noff); break; diff --git a/src/engine/tickable.cpp b/src/engine/tickable.cpp index 4dfcaac1..049c03fb 100644 --- a/src/engine/tickable.cpp +++ b/src/engine/tickable.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 @@ -13,8 +13,8 @@ #include #include -#include #include +#include namespace lol { diff --git a/src/engine/ticker.cpp b/src/engine/ticker.cpp index 6e921408..8179f4a9 100644 --- a/src/engine/ticker.cpp +++ b/src/engine/ticker.cpp @@ -13,8 +13,8 @@ #include #include -#include #include +#include namespace lol { diff --git a/src/engine/ticker.h b/src/engine/ticker.h index 312e40f1..c10877bf 100644 --- a/src/engine/ticker.h +++ b/src/engine/ticker.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 @@ -20,8 +20,8 @@ #include -#include -#include +#include // uint32_t +#include // std::shared_ptr namespace lol { diff --git a/src/image/combine.cpp b/src/image/combine.cpp index d37fc832..b59e7514 100644 --- a/src/image/combine.cpp +++ b/src/image/combine.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2004—2017 Sam Hocevar +// Copyright © 2004—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,6 +37,8 @@ enum class MergeMode template static image generic_merge(image &src1, image &src2, float alpha) { + using std::min, std::max, std::fabs; + typedef typename PixelType::type pixel_t; ASSERT(src1.size() == src2.size()); @@ -70,7 +72,7 @@ static image generic_merge(image &src1, image &src2, float alpha) else if (MODE == MergeMode::Sub) dstp[n] = lol::max(src1p[n] - src2p[n], pixel_t(0.f)); else if (MODE == MergeMode::Difference) - dstp[n] = lol::abs(src1p[n] - src2p[n]); + dstp[n] = lol::fabs(src1p[n] - src2p[n]); } src1.unlock(src1p); diff --git a/src/image/filter/convolution.cpp b/src/image/filter/convolution.cpp index 08357e2c..4aae6d89 100644 --- a/src/image/filter/convolution.cpp +++ b/src/image/filter/convolution.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2004—2017 Sam Hocevar +// Copyright © 2004—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -57,7 +57,7 @@ image image::Convolution(array2d const &in_kernel) float p = in_kernel[dx][dy] * in_kernel[bestx][besty]; float q = in_kernel[dx][besty] * in_kernel[bestx][dy]; - if (lol::abs(p - q) > 1.0e-8f) + if (lol::fabs(p - q) > 1.0e-8f) separable = false; } } @@ -67,7 +67,7 @@ image image::Convolution(array2d const &in_kernel) /* Matrix rank is 1! Separate the filter. */ array hvec, vvec; - float norm = 1.0f / lol::sqrt(lol::abs(in_kernel[bestx][besty])); + float norm = 1.0f / lol::sqrt(lol::fabs(in_kernel[bestx][besty])); for (int dx = 0; dx < ksize.x; dx++) hvec << norm * in_kernel[dx][besty]; for (int dy = 0; dy < ksize.y; dy++) diff --git a/src/image/kernel.cpp b/src/image/kernel.cpp index 374db585..78bf5b7b 100644 --- a/src/image/kernel.cpp +++ b/src/image/kernel.cpp @@ -1,7 +1,7 @@ // // Lol Engine // -// Copyright © 2004—2019 Sam Hocevar +// Copyright © 2004—2020 Sam Hocevar // // Lol Engine is free software. It comes without any warranty, to // the extent permitted by applicable law. You can redistribute it @@ -290,8 +290,8 @@ array2d image::kernel::gaussian(vec2 radius, float angle, vec2 delta) /* FIXME: the kernel becomes far too big with large values of dx, because * we grow both left and right. Fix the growing direction. */ - int const krx = (int)(3.f * bbx + .99999f + lol::ceil(lol::abs(delta.x))); - int const kry = (int)(3.f * bby + .99999f + lol::ceil(lol::abs(delta.y))); + int const krx = (int)(3.f * bbx + .99999f + lol::ceil(lol::fabs(delta.x))); + int const kry = (int)(3.f * bby + .99999f + lol::ceil(lol::fabs(delta.y))); ivec2 size(2 * krx + 1, 2 * kry + 1); float const Kx = -1.f / (2.f * radius.x * radius.x); float const Ky = -1.f / (2.f * radius.y * radius.y); diff --git a/src/light.h b/src/light.h index 13707ad5..baffcc39 100644 --- a/src/light.h +++ b/src/light.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 @@ -57,7 +57,7 @@ struct LightType { LightType lv = LightType(i); float nv = lv.f(); - float ntop = lol::abs(nv - v); + float ntop = lol::fabs(nv - v); if (ntop < top) { top = ntop; diff --git a/src/lol-core.vcxproj b/src/lol-core.vcxproj index 29b1edfe..0cf0d650 100644 --- a/src/lol-core.vcxproj +++ b/src/lol-core.vcxproj @@ -237,7 +237,6 @@ - diff --git a/src/lol-core.vcxproj.filters b/src/lol-core.vcxproj.filters index d154b9f6..7f50f696 100644 --- a/src/lol-core.vcxproj.filters +++ b/src/lol-core.vcxproj.filters @@ -311,9 +311,6 @@ lol\algorithm - - lol\algorithm - lol\base diff --git a/src/lol/algorithm/all.h b/src/lol/algorithm/all.h index 1336e3c4..bb57e36e 100644 --- a/src/lol/algorithm/all.h +++ b/src/lol/algorithm/all.h @@ -12,7 +12,6 @@ #pragma once -#include #include <../legacy/lol/algorithm/aabb_tree.h> #include diff --git a/src/lol/algorithm/portal.h b/src/lol/algorithm/portal.h index fec27c5c..53895dd2 100644 --- a/src/lol/algorithm/portal.h +++ b/src/lol/algorithm/portal.h @@ -140,7 +140,7 @@ public: mat4 inv_proj_mx = inverse(proj); // First: Check normal dot - if (lol::abs(dot(mat3(inverse(view)) * vec3(0.f, 0.f, 1.f), m_normal)) < .00001f) + if (lol::fabs(dot(mat3(inverse(view)) * vec3(0.f, 0.f, 1.f), m_normal)) < .00001f) return false; // Second: convert to screen coordinates @@ -177,7 +177,7 @@ public: //world calculations proj_p[k] = inv_proj_mx * vec4(port_2d[j[k].x].x, port_2d[j[k].y].y, (i<4)?(port_2d[0].z):(1.f), 1.f); proj_p[k] /= proj_p[k].w; - proj_p[k].z = lol::abs(proj_p[k].z); + proj_p[k].z = lol::fabs(proj_p[k].z); for (int h = 0; h < 3; h++) { @@ -230,7 +230,7 @@ public: //Check if at least one point is not on the same side as the others for (int i = 0; i < 3; i++) - if (lol::abs(pos_test[i]) == 4) + if (lol::fabs(pos_test[i]) == 4) return false; return true; diff --git a/src/lol/algorithm/sort.h b/src/lol/algorithm/sort.h deleted file mode 100644 index 8c9c4b9a..00000000 --- a/src/lol/algorithm/sort.h +++ /dev/null @@ -1,130 +0,0 @@ -// -// Lol Engine -// -// Copyright © 2010—2015 Sam Hocevar -// © 2013—2015 Benjamin “Touky” Huet -// -// Lol Engine is free software. It comes without any warranty, to -// the extent permitted by applicable law. You can redistribute it -// and/or modify it under the terms of the Do What the Fuck You Want -// to Public License, Version 2, as published by the WTFPL Task Force. -// See http://www.wtfpl.net/ for more details. -// - -#pragma once - -#include -#include -#include <../legacy/lol/math/functions.h> // lol::max - -namespace lol -{ - -/* - * Shuffle an array. - */ - -template -void array_base::shuffle() -{ - auto n = count(); - auto ni = n; - while (n > 0) - { - ni = lol::rand(n--) | 0; - this->swap(ni, n); - } -} - -/* - * Sort an array - */ - -template -static void quick_swap_sort(array_base &a, - ptrdiff_t start, ptrdiff_t stop); - -template -void array_base::sort(SortAlgorithm algorithm) -{ -#if !SORT_WORKS // yeah cause it's shite. - algorithm = SortAlgorithm::Bubble; -#endif - - // Classic bubble - if (algorithm == SortAlgorithm::Bubble) - { - int d = 1; - for (ptrdiff_t i = 0; i < count_s() - 1; i = lol::max(i + d, (ptrdiff_t)0)) - { - if (i <= 0 || m_data[i] < m_data[i + 1]) - d = 1; - if (m_data[i + 1] < m_data[i]) - { - this->swap(i, i + 1); - d = -1; - } - } - } - // Quick sort with swap - else if (algorithm == SortAlgorithm::QuickSwap) - { - quick_swap_sort(*this, 0, count_s()); - } -} - -template -static void quick_swap_sort(array_base &a, - ptrdiff_t start, ptrdiff_t stop) -{ - ptrdiff_t m[3] = - { - rand(start, stop), - rand(start, stop), - rand(start, stop) - }; - - for (int i = 0; i < 2; ) - { - if (a[m[i+1]] < a[m[i]]) - { - ptrdiff_t mt = m[i+1]; - m[i+1] = m[i]; - m[i] = mt; - i = 0; - } - else - i++; - } - - // actual stuff - T median = a[m[1]]; - ptrdiff_t i0 = start, i1 = stop - 1; - bool b_swap = false; - while (i0 < i1) - { - if (!(a[i0] < median) && a[i1] < median) - { - a.swap(i0, i1); - i0++; - i1--; - b_swap = true; - } - else - { - if (a[i0] < median) - i0++; - if (!(a[i1] < median)) - i1--; - } - } - if (stop - start == 1 || !b_swap) - return; - if (start < i0) - quick_swap_sort(a, start, i0); - if (i0 < stop) - quick_swap_sort(a, i0, stop); -} - -} /* namespace lol */ - diff --git a/src/lol/base/log.h b/src/lol/base/log.h index c86a1dba..a370da8d 100644 --- a/src/lol/base/log.h +++ b/src/lol/base/log.h @@ -20,8 +20,7 @@ #include -#include -#include +#include // va_list namespace lol { diff --git a/src/lol/engine/tickable.h b/src/lol/engine/tickable.h index ec832764..c88c8532 100644 --- a/src/lol/engine/tickable.h +++ b/src/lol/engine/tickable.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 @@ -19,8 +19,7 @@ // loop. // -#include -#include +#include // std::shared_ptr namespace lol { diff --git a/src/lol/gpu/shader.h b/src/lol/gpu/shader.h index 8b136311..0bc8b548 100644 --- a/src/lol/gpu/shader.h +++ b/src/lol/gpu/shader.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 @@ -17,10 +17,10 @@ // ---------------- // -#include -#include -#include -#include +#include // std::string +#include // std::map +#include // std::shared_ptr +#include // int64_t #include "engine/entity.h" diff --git a/src/lol/sys/file.h b/src/lol/sys/file.h index 24989299..1948855d 100644 --- a/src/lol/sys/file.h +++ b/src/lol/sys/file.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 @@ -17,8 +17,9 @@ // ----------------------- // -#include -#include +#include // std::string +#include // std::map +#include // int64_t namespace lol { diff --git a/src/lol/sys/init.h b/src/lol/sys/init.h index 094389fe..53421f7c 100644 --- a/src/lol/sys/init.h +++ b/src/lol/sys/init.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 @@ -17,9 +17,8 @@ // ------------------------------- // -#include -#include -#include +#include // std::string +#include // std::getenv namespace lol { @@ -57,24 +56,6 @@ extern void init(int argc, char *argv[], extern void add_data_dir(std::string const &dir); extern array get_path_list(std::string const &file); -static inline std::string getenv(std::string const &var) -{ -#if _MSC_VER - char *buf = nullptr; - size_t count = 0; - if (_dupenv_s(&buf, &count, var.c_str()) == 0 && buf) - { - std::string ret(buf); - free(buf); - return ret; - } -#else - if (auto val = std::getenv(var.c_str())) - return std::string(val); -#endif - return std::string(); -} - } /* namespace sys */ } /* namespace lol */ diff --git a/src/math/geometry.cpp b/src/math/geometry.cpp index 2568328a..abe7a45b 100644 --- a/src/math/geometry.cpp +++ b/src/math/geometry.cpp @@ -1,27 +1,27 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2013 Sam Hocevar -// (c) 2010-2013 Benjamin "Touky" Huet -// 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. +// Copyright © 2010—2020 Sam Hocevar +// © 2010—2013 Benjamin “Touky” Huet +// +// 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 -#include /* free() */ -#include /* strdup() */ - -#include /* std::ostream */ +#include // std::min +#include // std::fabs namespace lol { //Test epsilon stuff TestEpsilon g_test_epsilon; float TestEpsilon::Get() { return g_test_epsilon.m_epsilon; } - void TestEpsilon::Set(float epsilon) { g_test_epsilon.m_epsilon = lol::max(epsilon, .0f); } + void TestEpsilon::Set(float epsilon) { using std::max; g_test_epsilon.m_epsilon = max(epsilon, .0f); } const TestEpsilon& TestEpsilon::F(float value) { g_test_epsilon.m_value = value; return g_test_epsilon; } float TestEpsilon::Minus()const { return m_value - m_epsilon; } float TestEpsilon::Plus() const { return m_value + m_epsilon; } @@ -102,7 +102,7 @@ namespace lol //Check the normal before doing any other calculations vec3 plane_norm[2] = { cross(normalize(triD[0]), normalize(triD[1])), cross(normalize(triD[3]), normalize(triD[4])) }; - if (abs(dot(plane_norm[0], plane_norm[1])) == 1.0f) + if (fabs(dot(plane_norm[0], plane_norm[1])) == 1.0f) return false; #if 0 @@ -256,13 +256,15 @@ namespace lol //-- bool TestPointVsFrustum(const vec3& point, const mat4& frustum, vec3* result_point) { + using std::fabs; + vec4 proj_point = frustum * vec4(point, 1.f); proj_point /= proj_point.w; if (result_point) *result_point = proj_point.xyz; for (int i = 0; i < 3; i++) - if (lol::abs(proj_point[i]) > 1.f) + if (fabs(proj_point[i]) > 1.f) return false; return true; } diff --git a/src/scene.cpp b/src/scene.cpp index 1bbc80ec..63fd8bc0 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -414,7 +414,7 @@ void Scene::AddLine(vec3 a, vec3 b, vec4 col) m_line_api.m_lines.push(l); } -void Scene::AddLine(vec3 a, vec3 b, vec4 col, float duration, int mask) +void Scene::AddLine(vec3 a, vec3 b, vec4 col, float duration, uint32_t mask) { struct line l { a, b, col, duration, mask, false, false }; m_line_api.m_lines.push(l); diff --git a/src/scene.h b/src/scene.h index b3ff34a2..afb36c56 100644 --- a/src/scene.h +++ b/src/scene.h @@ -245,7 +245,7 @@ public: public: void AddLine(vec3 a, vec3 b, vec4 color); - void AddLine(vec3 a, vec3 b, vec4 color, float duration, int mask); + void AddLine(vec3 a, vec3 b, vec4 color, float duration, uint32_t mask); void AddLight(Light *light); array const &GetLights(); diff --git a/src/utils.h b/src/utils.h index 9c8f6e01..26116c32 100644 --- a/src/utils.h +++ b/src/utils.h @@ -19,6 +19,7 @@ // #include +#include #include