From 8bcbd2729388edc63c82d77d314b583af1447c49 Mon Sep 17 00:00:00 2001 From: untodesu Date: Sun, 14 Sep 2025 19:16:44 +0500 Subject: Cleanup math with qfengine ports again --- core/config/number.hh | 20 ++-- core/io/CMakeLists.txt | 4 +- core/io/physfs.cc | 76 +++++++++++++ core/io/physfs.hh | 14 +++ core/math/CMakeLists.txt | 1 - core/math/aabb.hh | 18 +-- core/math/concepts.hh | 12 +- core/math/constexpr.hh | 210 +++++++---------------------------- core/math/crc64.cc | 5 + core/math/crc64.hh | 1 + core/math/randomizer.hh | 56 ---------- core/math/vectors.hh | 16 +-- core/resource/image.cc | 4 +- core/resource/resource.cc | 5 +- core/threading.cc | 4 +- core/utils/CMakeLists.txt | 2 - core/utils/physfs.cc | 76 ------------- core/utils/physfs.hh | 14 --- game/client/config/gamepad_axis.cc | 2 +- game/client/entity/interpolation.cc | 24 ++-- game/client/entity/listener.cc | 2 +- game/client/entity/player_look.cc | 2 +- game/client/entity/player_move.cc | 6 +- game/client/entity/sound_emitter.cc | 2 +- game/client/game.cc | 12 +- game/client/gui/crosshair.cc | 4 +- game/client/gui/direct_connection.cc | 2 +- game/client/gui/language.cc | 5 +- game/client/gui/main_menu.cc | 2 +- game/client/gui/play_menu.cc | 4 +- game/client/gui/progress_bar.cc | 8 +- game/client/gui/scoreboard.cc | 2 +- game/client/gui/splash.cc | 2 +- game/client/io/gamepad.cc | 8 +- game/client/main.cc | 4 +- game/client/program.cc | 6 +- game/client/resource/sound_effect.cc | 4 +- game/client/session.cc | 2 +- game/client/sound/sound.cc | 12 +- game/client/world/chunk_mesher.cc | 6 +- game/client/world/voxel_atlas.cc | 4 +- game/server/whitelist.cc | 3 +- game/server/world/overworld.cc | 4 +- game/server/world/universe.cc | 7 +- game/shared/entity/collision.cc | 14 +-- game/shared/game.cc | 11 +- game/shared/splash.cc | 4 +- game/shared/world/ray_dda.cc | 6 +- 48 files changed, 270 insertions(+), 442 deletions(-) create mode 100644 core/io/physfs.cc create mode 100644 core/io/physfs.hh delete mode 100644 core/math/randomizer.hh delete mode 100644 core/utils/physfs.cc delete mode 100644 core/utils/physfs.hh diff --git a/core/config/number.hh b/core/config/number.hh index 5533459..59d3f47 100644 --- a/core/config/number.hh +++ b/core/config/number.hh @@ -6,7 +6,7 @@ namespace config { -template +template class Number : public IValue { public: explicit Number(T default_value = T(0)); @@ -59,7 +59,7 @@ public: }; } // namespace config -template +template inline config::Number::Number(T default_value) { m_value = default_value; @@ -68,7 +68,7 @@ inline config::Number::Number(T default_value) m_string = std::to_string(default_value); } -template +template inline config::Number::Number(T default_value, T min_value, T max_value) { m_value = default_value; @@ -77,7 +77,7 @@ inline config::Number::Number(T default_value, T min_value, T max_value) m_string = std::to_string(default_value); } -template +template inline void config::Number::set(std::string_view value) { T parsed_value; @@ -89,38 +89,38 @@ inline void config::Number::set(std::string_view value) } } -template +template inline std::string_view config::Number::get(void) const { return m_string; } -template +template inline T config::Number::get_value(void) const { return m_value; } -template +template inline void config::Number::set_value(T value) { m_value = std::clamp(value, m_min_value, m_max_value); m_string = std::to_string(m_value); } -template +template inline T config::Number::get_min_value(void) const { return m_min_value; } -template +template inline T config::Number::get_max_value(void) const { return m_max_value; } -template +template inline void config::Number::set_limits(T min_value, T max_value) { m_min_value = min_value; diff --git a/core/io/CMakeLists.txt b/core/io/CMakeLists.txt index 0639d2c..3fe9fb1 100644 --- a/core/io/CMakeLists.txt +++ b/core/io/CMakeLists.txt @@ -4,4 +4,6 @@ target_sources(core PRIVATE "${CMAKE_CURRENT_LIST_DIR}/cmdline.cc" "${CMAKE_CURRENT_LIST_DIR}/cmdline.hh" "${CMAKE_CURRENT_LIST_DIR}/config_map.cc" - "${CMAKE_CURRENT_LIST_DIR}/config_map.hh") + "${CMAKE_CURRENT_LIST_DIR}/config_map.hh" + "${CMAKE_CURRENT_LIST_DIR}/physfs.cc" + "${CMAKE_CURRENT_LIST_DIR}/physfs.hh") diff --git a/core/io/physfs.cc b/core/io/physfs.cc new file mode 100644 index 0000000..1c36f88 --- /dev/null +++ b/core/io/physfs.cc @@ -0,0 +1,76 @@ +#include "core/pch.hh" + +#include "core/io/physfs.hh" + +bool io::read_file(std::string_view path, std::vector& buffer) +{ + auto file = PHYSFS_openRead(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, physfs_error()); + return false; + } + + PHYSFS_sint64 file_size = PHYSFS_fileLength(file); + buffer.resize(static_cast(file_size)); + + PHYSFS_readBytes(file, buffer.data(), file_size); + PHYSFS_close(file); + + return true; +} + +bool io::read_file(std::string_view path, std::string& buffer) +{ + auto file = PHYSFS_openRead(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, physfs_error()); + return false; + } + + PHYSFS_sint64 file_size = PHYSFS_fileLength(file); + buffer.resize(static_cast(file_size)); + + PHYSFS_readBytes(file, buffer.data(), file_size); + PHYSFS_close(file); + + return true; +} + +bool io::write_file(std::string_view path, const std::vector& buffer) +{ + auto file = PHYSFS_openWrite(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, physfs_error()); + return false; + } + + PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); + PHYSFS_close(file); + + return true; +} + +bool io::write_file(std::string_view path, const std::string& buffer) +{ + auto file = PHYSFS_openWrite(std::string(path).c_str()); + + if(file == nullptr) { + spdlog::error("physfs: {}: {}", path, physfs_error()); + return false; + } + + PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); + PHYSFS_close(file); + + return true; +} + +std::string_view io::physfs_error(void) +{ + auto error_code = PHYSFS_getLastErrorCode(); + auto error_string = PHYSFS_getErrorByCode(error_code); + return std::string_view(error_string, std::strlen(error_string)); +} diff --git a/core/io/physfs.hh b/core/io/physfs.hh new file mode 100644 index 0000000..01282ad --- /dev/null +++ b/core/io/physfs.hh @@ -0,0 +1,14 @@ +#pragma once + +namespace io +{ +bool read_file(std::string_view path, std::vector& buffer); +bool read_file(std::string_view path, std::string& buffer); +bool write_file(std::string_view path, const std::vector& buffer); +bool write_file(std::string_view path, const std::string& buffer); +} // namespace io + +namespace io +{ +std::string_view physfs_error(void); +} // namespace io diff --git a/core/math/CMakeLists.txt b/core/math/CMakeLists.txt index b994969..bcb45aa 100644 --- a/core/math/CMakeLists.txt +++ b/core/math/CMakeLists.txt @@ -5,5 +5,4 @@ target_sources(core PRIVATE "${CMAKE_CURRENT_LIST_DIR}/constexpr.hh" "${CMAKE_CURRENT_LIST_DIR}/crc64.cc" "${CMAKE_CURRENT_LIST_DIR}/crc64.hh" - "${CMAKE_CURRENT_LIST_DIR}/randomizer.hh" "${CMAKE_CURRENT_LIST_DIR}/vectors.hh") diff --git a/core/math/aabb.hh b/core/math/aabb.hh index ed3cf39..9a64aad 100644 --- a/core/math/aabb.hh +++ b/core/math/aabb.hh @@ -4,7 +4,7 @@ namespace math { -template +template class AABB { public: using value_type = T; @@ -35,27 +35,27 @@ namespace math using AABBf = AABB; } // namespace math -template +template constexpr math::AABB::AABB(const vector_type& start, const vector_type& end) { set_bounds(start, end); } -template +template constexpr void math::AABB::set_bounds(const vector_type& start, const vector_type& end) { min = start; max = end; } -template +template constexpr void math::AABB::set_offset(const vector_type& base, const vector_type& size) { min = base; max = base + size; } -template +template constexpr bool math::AABB::contains(const vector_type& point) const { auto result = true; @@ -65,7 +65,7 @@ constexpr bool math::AABB::contains(const vector_type& point) const return result; } -template +template constexpr bool math::AABB::intersect(const AABB& other_box) const { auto result = true; @@ -75,7 +75,7 @@ constexpr bool math::AABB::intersect(const AABB& other_box) const return result; } -template +template constexpr math::AABB math::AABB::combine(const AABB& other_box) const { AABB result; @@ -88,7 +88,7 @@ constexpr math::AABB math::AABB::combine(const AABB& other_box return result; } -template +template constexpr math::AABB math::AABB::multiply(const AABB& other_box) const { AABB result; @@ -101,7 +101,7 @@ constexpr math::AABB math::AABB::multiply(const AABB& other_bo return result; } -template +template constexpr math::AABB math::AABB::push(const vector_type& vector) const { AABB result; diff --git a/core/math/concepts.hh b/core/math/concepts.hh index 10cb74a..19d372c 100644 --- a/core/math/concepts.hh +++ b/core/math/concepts.hh @@ -2,10 +2,10 @@ namespace math { -template -concept Arithmetic = std::is_arithmetic_v; -template -concept Integer = std::is_integral_v; -template -concept FloatingPoint = std::is_floating_point_v; +template +concept arithmetic = std::is_arithmetic_v; +template +concept signed_arithmetic = std::is_arithmetic_v && std::is_signed_v; +template +concept unsigned_arithmetic = std::is_arithmetic_v && std::is_unsigned_v; } // namespace math diff --git a/core/math/constexpr.hh b/core/math/constexpr.hh index e6c4b6d..6641f23 100644 --- a/core/math/constexpr.hh +++ b/core/math/constexpr.hh @@ -4,195 +4,69 @@ namespace math { -template -constexpr static inline const T abs(const T x); -template -constexpr static inline const std::size_t array_size(const T (&)[L]); -template -constexpr static inline const T ceil(const F x); -template -constexpr static inline const T degrees(const T x); -template -constexpr static inline const T floor(const F x); -template -constexpr static inline const T clamp(const T x, const T min, const T max); -template -constexpr static inline const T lerp(const T x, const T y, const F a); -template -constexpr static inline const T log2(const T x); -template -constexpr static inline const T max(const T x, const T y); -template -constexpr static inline const T min(const T x, const T y); -template -requires std::is_signed_v -constexpr static inline const T mod_signed(const T x, const T m); -template -constexpr static inline const T pow2(const T x); -template -constexpr static inline const T radians(const T x); -template -constexpr static inline const bool range(const T x, const T min, const T max); -template -constexpr static inline const T sign(const F x); -template -constexpr static inline const T smoothstep(const T x, const T y, const F a); +template +constexpr std::size_t array_size(const type (&)[size]); } // namespace math -template -constexpr static inline const T math::abs(const T x) -{ - if(x < static_cast(0)) { - return -x; - } - else { - return x; - } -} - -template -constexpr static inline const std::size_t math::array_size(const T (&)[L]) -{ - return L; -} - -template -constexpr static inline const T math::ceil(const F x) -{ - const T ival = static_cast(x); - - if(ival < x) { - return ival + static_cast(1); - } - else { - return ival; - } -} - -template -constexpr static inline const T math::degrees(const T x) -{ - return x * static_cast(180.0) / static_cast(M_PI); -} - -template -constexpr static inline const T math::floor(const F x) -{ - const T ival = static_cast(x); - - if(ival > x) { - return ival - static_cast(1); - } - else { - return ival; - } -} - -template -constexpr static inline const T math::clamp(const T x, const T min, const T max) -{ - if(x < min) { - return min; - } - else if(x > max) { - return max; - } - else { - return x; - } -} - -template -constexpr static inline const T math::lerp(const T x, const T y, const F a) +namespace math { - return static_cast(static_cast(x) * (static_cast(1.0f) - a) + static_cast(y) * a); -} +template +constexpr scalar log2(const scalar x); +template +constexpr scalar mod_signed(const scalar x, const scalar m); +template +constexpr result_scalar sign(const scalar x); +} // namespace math -template -constexpr static inline const T math::log2(const T x) +namespace math { - if(x < 2) { - return 0; - } - else { - return math::log2((x + 1) >> 1) + 1; - } -} +template +constexpr scalar degrees(const scalar x); +template +constexpr scalar radians(const scalar x); +} // namespace math -template -constexpr static inline const T math::max(const T x, const T y) +template +constexpr std::size_t math::array_size(const type (&)[size]) { - if(x < y) { - return y; - } - else { - return x; - } + return size; } -template -constexpr static inline const T math::min(const T x, const T y) +template +constexpr scalar math::log2(const scalar x) { - if(x > y) { - return y; - } - else { - return x; - } + if(x < static_cast(2)) + return static_cast(0); + return math::log2((x + static_cast(1)) >> 1) + static_cast(1); } -template -requires std::is_signed_v -constexpr static inline const T math::mod_signed(const T x, const T m) +template +constexpr scalar math::mod_signed(const scalar x, const scalar m) { - auto result = static_cast(x % m); - - if(result < T(0)) { + auto result = static_cast(x % m); + if(result < static_cast(0)) return result + m; - } - else { - return result; - } -} - -template -constexpr static inline const T math::pow2(const T x) -{ - T value = static_cast(1); - while(value < x) - value *= static_cast(2); - return value; -} - -template -constexpr static inline const T math::radians(const T x) -{ - return x * static_cast(M_PI) / static_cast(180.0); + return result; } -template -constexpr static inline const bool math::range(const T x, const T min, const T max) +template +constexpr result_scalar math::sign(const scalar x) { - return ((x >= min) && (x <= max)); + if(x < static_cast(0)) + return static_cast(-1); + if(x > static_cast(0)) + return static_cast(+1); + return static_cast(0); } -template -constexpr static inline const T math::sign(const F x) +template +constexpr scalar math::degrees(const scalar x) { - if(x < F(0)) { - return T(-1); - } - else if(x > F(0)) { - return T(+1); - } - else { - return T(0); - } + return static_cast(static_cast(x) * 180.0 / M_PI); } -template -constexpr static inline const T math::smoothstep(const T x, const T y, const F a) +template +constexpr scalar math::radians(const scalar x) { - const F t = math::clamp((a - x) / (y - x), F(0), F(1)); - return static_cast(t * t * (F(3) - F(2) * t)); + return static_cast(static_cast(x) * M_PI / 180.0); } diff --git a/core/math/crc64.cc b/core/math/crc64.cc index 0b6a830..ea7841d 100644 --- a/core/math/crc64.cc +++ b/core/math/crc64.cc @@ -69,3 +69,8 @@ std::uint64_t math::crc64(const std::string& buffer, std::uint64_t combine) { return math::crc64(buffer.data(), buffer.size(), combine); } + +std::uint64_t math::crc64(std::string_view buffer, std::uint64_t combine) +{ + return math::crc64(buffer.data(), buffer.size(), combine); +} diff --git a/core/math/crc64.hh b/core/math/crc64.hh index f68c951..5a6fea4 100644 --- a/core/math/crc64.hh +++ b/core/math/crc64.hh @@ -5,4 +5,5 @@ namespace math std::uint64_t crc64(const void* buffer, std::size_t size, std::uint64_t combine = UINT64_C(0)); std::uint64_t crc64(const std::vector& buffer, std::uint64_t combine = UINT64_C(0)); std::uint64_t crc64(const std::string& buffer, std::uint64_t combine = UINT64_C(0)); +std::uint64_t crc64(std::string_view buffer, std::uint64_t combine = UINT64_C(0)); } // namespace math diff --git a/core/math/randomizer.hh b/core/math/randomizer.hh deleted file mode 100644 index db21c95..0000000 --- a/core/math/randomizer.hh +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once - -namespace math -{ -template -class Randomizer final { -public: - explicit Randomizer(void); - explicit Randomizer(std::uint64_t seed); - virtual ~Randomizer(void) = default; - void add(const T& value); - const T& get(void); - void clear(void); - -private: - std::vector m_vector; - std::mt19937_64 m_twister; - std::uniform_int_distribution m_dist; -}; -} // namespace math - -template -inline math::Randomizer::Randomizer(void) -{ - m_vector.clear(); - m_twister.seed(std::random_device()()); - m_dist = std::uniform_int_distribution(0, 0); -} - -template -inline math::Randomizer::Randomizer(std::uint64_t seed) -{ - m_vector.clear(); - m_twister.seed(seed); - m_dist = std::uniform_int_distribution(0, 0); -} - -template -inline void math::Randomizer::add(const T& value) -{ - m_vector.push_back(value); - m_dist = std::uniform_int_distribution(0, m_vector.size() - 1); -} - -template -inline const T& math::Randomizer::get(void) -{ - return m_vector.at(m_dist(m_twister)); -} - -template -inline void math::Randomizer::clear(void) -{ - m_vector.clear(); - m_dist = std::uniform_int_distribution(0, 0); -} diff --git a/core/math/vectors.hh b/core/math/vectors.hh index 9b9e762..ff2b8c9 100644 --- a/core/math/vectors.hh +++ b/core/math/vectors.hh @@ -8,35 +8,35 @@ namespace math { -template +template constexpr static inline const T length2(const glm::vec<2, T>& vector); -template +template constexpr static inline const T length2(const glm::vec<3, T>& vector); -template +template constexpr static inline const T distance2(const glm::vec<2, T>& vector_a, const glm::vec<2, T>& vector_b); -template +template constexpr static inline const T distance2(const glm::vec<3, T>& vector_a, const glm::vec<3, T>& vector_b); } // namespace math -template +template constexpr static inline const T math::length2(const glm::vec<2, T>& vector) { return (vector.x * vector.x) + (vector.y * vector.y); } -template +template constexpr static inline const T math::length2(const glm::vec<3, T>& vector) { return (vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z); } -template +template constexpr static inline const T math::distance2(const glm::vec<2, T>& vector_a, const glm::vec<2, T>& vector_b) { return math::length2(vector_a - vector_b); } -template +template constexpr static inline const T math::distance2(const glm::vec<3, T>& vector_a, const glm::vec<3, T>& vector_b) { return math::length2(vector_a - vector_b); diff --git a/core/resource/image.cc b/core/resource/image.cc index 45fe96e..8c83c55 100644 --- a/core/resource/image.cc +++ b/core/resource/image.cc @@ -4,7 +4,7 @@ #include "core/resource/resource.hh" -#include "core/utils/physfs.hh" +#include "core/io/physfs.hh" static int stbi_physfs_read(void* context, char* data, int size) { @@ -36,7 +36,7 @@ static const void* image_load_func(const char* name, std::uint32_t flags) auto file = PHYSFS_openRead(name); if(file == nullptr) { - spdlog::error("image: {}: {}", name, utils::physfs_error()); + spdlog::error("image: {}: {}", name, io::physfs_error()); return nullptr; } diff --git a/core/resource/resource.cc b/core/resource/resource.cc index 21d1e4e..7ca2ef9 100644 --- a/core/resource/resource.cc +++ b/core/resource/resource.cc @@ -10,10 +10,7 @@ struct ResourceLoader final { std::string class_name; }; -namespace -{ -emhash8::HashMap> loaders; -} // namespace +static emhash8::HashMap> loaders; void resource::detail::register_loader(const std::type_info& type, ResourceLoadFunc load_func, ResourceFreeFunc free_func) { diff --git a/core/threading.cc b/core/threading.cc index dcbdb9a..8514481 100644 --- a/core/threading.cc +++ b/core/threading.cc @@ -49,7 +49,7 @@ void threading::init(void) auto result = std::from_chars(argument.data(), argument.data() + argument.size(), thread_pool_size); if(result.ec == std::errc()) { - thread_pool_size = math::clamp(thread_pool_size, 1U, num_concurrent_threads); + thread_pool_size = glm::clamp(thread_pool_size, 1U, num_concurrent_threads); } else { thread_pool_size = 4U; @@ -59,7 +59,7 @@ void threading::init(void) auto result = std::from_chars(argument.data(), argument.data() + argument.size(), thread_pool_size); if(result.ec == std::errc()) { - thread_pool_size = math::max(thread_pool_size, 1U); + thread_pool_size = glm::max(thread_pool_size, 1U); } else { thread_pool_size = 4U; diff --git a/core/utils/CMakeLists.txt b/core/utils/CMakeLists.txt index 5d59e8d..4f96261 100644 --- a/core/utils/CMakeLists.txt +++ b/core/utils/CMakeLists.txt @@ -1,7 +1,5 @@ target_sources(core PRIVATE "${CMAKE_CURRENT_LIST_DIR}/epoch.cc" "${CMAKE_CURRENT_LIST_DIR}/epoch.hh" - "${CMAKE_CURRENT_LIST_DIR}/physfs.cc" - "${CMAKE_CURRENT_LIST_DIR}/physfs.hh" "${CMAKE_CURRENT_LIST_DIR}/string.cc" "${CMAKE_CURRENT_LIST_DIR}/string.hh") diff --git a/core/utils/physfs.cc b/core/utils/physfs.cc deleted file mode 100644 index b801963..0000000 --- a/core/utils/physfs.cc +++ /dev/null @@ -1,76 +0,0 @@ -#include "core/pch.hh" - -#include "core/utils/physfs.hh" - -bool utils::read_file(std::string_view path, std::vector& buffer) -{ - auto file = PHYSFS_openRead(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_sint64 file_size = PHYSFS_fileLength(file); - buffer.resize(static_cast(file_size)); - - PHYSFS_readBytes(file, buffer.data(), file_size); - PHYSFS_close(file); - - return true; -} - -bool utils::read_file(std::string_view path, std::string& buffer) -{ - auto file = PHYSFS_openRead(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_sint64 file_size = PHYSFS_fileLength(file); - buffer.resize(static_cast(file_size)); - - PHYSFS_readBytes(file, buffer.data(), file_size); - PHYSFS_close(file); - - return true; -} - -bool utils::write_file(std::string_view path, const std::vector& buffer) -{ - auto file = PHYSFS_openWrite(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); - PHYSFS_close(file); - - return true; -} - -bool utils::write_file(std::string_view path, const std::string& buffer) -{ - auto file = PHYSFS_openWrite(std::string(path).c_str()); - - if(file == nullptr) { - spdlog::error("physfs: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); - return false; - } - - PHYSFS_writeBytes(file, buffer.data(), static_cast(buffer.size())); - PHYSFS_close(file); - - return true; -} - -std::string_view utils::physfs_error(void) -{ - auto error_code = PHYSFS_getLastErrorCode(); - auto error_string = PHYSFS_getErrorByCode(error_code); - return std::string_view(error_string, std::strlen(error_string)); -} diff --git a/core/utils/physfs.hh b/core/utils/physfs.hh deleted file mode 100644 index 220954e..0000000 --- a/core/utils/physfs.hh +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -namespace utils -{ -bool read_file(std::string_view path, std::vector& buffer); -bool read_file(std::string_view path, std::string& buffer); -bool write_file(std::string_view path, const std::vector& buffer); -bool write_file(std::string_view path, const std::string& buffer); -} // namespace utils - -namespace utils -{ -std::string_view physfs_error(void); -} // namespace utils diff --git a/game/client/config/gamepad_axis.cc b/game/client/config/gamepad_axis.cc index c782c19..9cc731c 100644 --- a/game/client/config/gamepad_axis.cc +++ b/game/client/config/gamepad_axis.cc @@ -99,7 +99,7 @@ float config::GamepadAxis::get_value(const GLFWgamepadstate& state, float deadzo if(m_gamepad_axis <= math::array_size(state.axes)) { auto value = state.axes[m_gamepad_axis]; - if(math::abs(value) > deadzone) { + if(glm::abs(value) > deadzone) { return m_inverted ? -value : value; } diff --git a/game/client/entity/interpolation.cc b/game/client/entity/interpolation.cc index ef23a4c..c88fcf2 100644 --- a/game/client/entity/interpolation.cc +++ b/game/client/entity/interpolation.cc @@ -19,9 +19,9 @@ static void transform_interpolate(float alpha) entt::get); for(auto [entity, interp, current, previous] : group.each()) { - interp.angles[0] = math::lerp(previous.angles[0], current.angles[0], alpha); - interp.angles[1] = math::lerp(previous.angles[1], current.angles[1], alpha); - interp.angles[2] = math::lerp(previous.angles[2], current.angles[2], alpha); + interp.angles[0] = glm::mix(previous.angles[0], current.angles[0], alpha); + interp.angles[1] = glm::mix(previous.angles[1], current.angles[1], alpha); + interp.angles[2] = glm::mix(previous.angles[2], current.angles[2], alpha); // Figure out previous chunk-local floating-point coordinates transformed // to the current WorldCoord's chunk domain coordinates; we're interpolating @@ -33,9 +33,9 @@ static void transform_interpolate(float alpha) interp.chunk.y = current.chunk.y; interp.chunk.z = current.chunk.z; - interp.local.x = math::lerp(previous_local.x, current.local.x, alpha); - interp.local.y = math::lerp(previous_local.y, current.local.y, alpha); - interp.local.z = math::lerp(previous_local.z, current.local.z, alpha); + interp.local.x = glm::mix(previous_local.x, current.local.x, alpha); + interp.local.y = glm::mix(previous_local.y, current.local.y, alpha); + interp.local.z = glm::mix(previous_local.z, current.local.z, alpha); } } @@ -44,13 +44,13 @@ static void head_interpolate(float alpha) auto group = globals::dimension->entities.group(entt::get); for(auto [entity, interp, current, previous] : group.each()) { - interp.angles[0] = math::lerp(previous.angles[0], current.angles[0], alpha); - interp.angles[1] = math::lerp(previous.angles[1], current.angles[1], alpha); - interp.angles[2] = math::lerp(previous.angles[2], current.angles[2], alpha); + interp.angles[0] = glm::mix(previous.angles[0], current.angles[0], alpha); + interp.angles[1] = glm::mix(previous.angles[1], current.angles[1], alpha); + interp.angles[2] = glm::mix(previous.angles[2], current.angles[2], alpha); - interp.offset.x = math::lerp(previous.offset.x, current.offset.x, alpha); - interp.offset.y = math::lerp(previous.offset.y, current.offset.y, alpha); - interp.offset.z = math::lerp(previous.offset.z, current.offset.z, alpha); + interp.offset.x = glm::mix(previous.offset.x, current.offset.x, alpha); + interp.offset.y = glm::mix(previous.offset.y, current.offset.y, alpha); + interp.offset.z = glm::mix(previous.offset.z, current.offset.z, alpha); } } diff --git a/game/client/entity/listener.cc b/game/client/entity/listener.cc index 3d732ae..1223438 100644 --- a/game/client/entity/listener.cc +++ b/game/client/entity/listener.cc @@ -38,5 +38,5 @@ void entity::listener::update(void) alListenerfv(AL_ORIENTATION, orientation); } - alListenerf(AL_GAIN, math::clamp(sound::volume_master.get_value() * 0.01f, 0.0f, 1.0f)); + alListenerf(AL_GAIN, glm::clamp(sound::volume_master.get_value() * 0.01f, 0.0f, 1.0f)); } diff --git a/game/client/entity/player_look.cc b/game/client/entity/player_look.cc index caa367e..b6eaf16 100644 --- a/game/client/entity/player_look.cc +++ b/game/client/entity/player_look.cc @@ -55,7 +55,7 @@ static void add_angles(float pitch, float yaw) head.angles[0] += pitch; head.angles[1] += yaw; - head.angles[0] = math::clamp(head.angles[0], PITCH_MIN, PITCH_MAX); + head.angles[0] = glm::clamp(head.angles[0], PITCH_MIN, PITCH_MAX); head.angles = math::wrap_180(head.angles); // Client-side head angles are not interpolated; diff --git a/game/client/entity/player_move.cc b/game/client/entity/player_move.cc index 2570780..17aaadd 100644 --- a/game/client/entity/player_move.cc +++ b/game/client/entity/player_move.cc @@ -80,7 +80,7 @@ static glm::fvec3 pm_accelerate(const glm::fvec3& wishdir, const glm::fvec3& vel return velocity; } - auto accel_speed = math::min(add_speed, accel * globals::fixed_frametime * wishspeed); + auto accel_speed = glm::min(add_speed, accel * globals::fixed_frametime * wishspeed); auto result = glm::fvec3(velocity); result.x += accel_speed * wishdir.x; @@ -99,7 +99,7 @@ static glm::fvec3 pm_ground_move(const glm::fvec3& wishdir, const glm::fvec3& ve { if(auto speed = glm::length(velocity)) { auto speed_drop = speed * PMOVE_FRICTION_GROUND * globals::fixed_frametime; - auto speed_factor = math::max(speed - speed_drop, 0.0f) / speed; + auto speed_factor = glm::max(speed - speed_drop, 0.0f) / speed; return pm_accelerate(wishdir, velocity * speed_factor, PMOVE_ACCELERATION_GROUND, PMOVE_MAX_SPEED_GROUND); } @@ -225,7 +225,7 @@ void entity::player_move::fixed_update(void) next_jump_us = globals::curtime + PMOVE_JUMP_COOLDOWN; if(enable_speedometer.get_value()) { - if(math::abs(speed_change) < 0.01f) { + if(glm::abs(speed_change) < 0.01f) { // No considerable speed increase within // the precision we use to draw the speedometer gui::status_lines::set(gui::STATUS_DEBUG, new_speed_text, ImVec4(0.7f, 0.7f, 0.7f, 1.0f), 1.0f); diff --git a/game/client/entity/sound_emitter.cc b/game/client/entity/sound_emitter.cc index c2a93a1..84a66c0 100644 --- a/game/client/entity/sound_emitter.cc +++ b/game/client/entity/sound_emitter.cc @@ -37,7 +37,7 @@ void entity::SoundEmitter::update(void) const auto view = globals::dimension->entities.view(); const auto& pivot = entity::camera::position_chunk; - const auto gain = math::clamp(sound::volume_effects.get_value() * 0.01f, 0.0f, 1.0f); + const auto gain = glm::clamp(sound::volume_effects.get_value() * 0.01f, 0.0f, 1.0f); for(const auto [entity, emitter] : view.each()) { alSourcef(emitter.source, AL_GAIN, gain); diff --git a/game/client/game.cc b/game/client/game.cc index d61ce84..e772ff8 100644 --- a/game/client/game.cc +++ b/game/client/game.cc @@ -12,7 +12,7 @@ #include "core/resource/resource.hh" -#include "core/utils/physfs.hh" +#include "core/io/physfs.hh" #include "shared/entity/collision.hh" #include "shared/entity/gravity.hh" @@ -101,7 +101,7 @@ static ImFont* load_font(std::string_view path, float size, ImFontConfig& font_c bool font_load_success; std::vector font; - if(!utils::read_file(path, font)) { + if(!io::read_file(path, font)) { spdlog::error("{}: utils::read_file failed", path); std::terminate(); } @@ -549,10 +549,10 @@ void client_game::update(void) auto twice_scale_x = static_cast(globals::width) / half_base_width; auto twice_scale_y = static_cast(globals::height) / half_base_height; - auto scale_x = math::max(1.0f, 0.5f * glm::floor(twice_scale_x)); - auto scale_y = math::max(1.0f, 0.5f * glm::floor(twice_scale_y)); - auto scale_min = math::ceil(math::min(scale_x, scale_y)); - auto scale_int = math::max(1U, (scale_min / 2U) * 2U); + auto scale_x = glm::max(1.0f, 0.5f * glm::floor(twice_scale_x)); + auto scale_y = glm::max(1.0f, 0.5f * glm::floor(twice_scale_y)); + auto scale_min = static_cast(glm::ceil(glm::min(scale_x, scale_y))); + auto scale_int = glm::max(1U, (scale_min / 2U) * 2U); auto& io = ImGui::GetIO(); io.FontGlobalScale = scale_int; diff --git a/game/client/gui/crosshair.cc b/game/client/gui/crosshair.cc index b5650a9..2e6eeba 100644 --- a/game/client/gui/crosshair.cc +++ b/game/client/gui/crosshair.cc @@ -34,8 +34,8 @@ void gui::crosshair::layout(void) auto viewport = ImGui::GetMainViewport(); auto draw_list = ImGui::GetForegroundDrawList(); - auto scaled_width = math::max(texture->size.x, globals::gui_scale * texture->size.x / 2); - auto scaled_height = math::max(texture->size.y, globals::gui_scale * texture->size.y / 2); + auto scaled_width = glm::max(texture->size.x, globals::gui_scale * texture->size.x / 2); + auto scaled_height = glm::max(texture->size.y, globals::gui_scale * texture->size.y / 2); auto start = ImVec2(static_cast(0.5f * viewport->Size.x) - (scaled_width / 2), static_cast(0.5f * viewport->Size.y) - (scaled_height / 2)); auto end = ImVec2(start.x + scaled_width, start.y + scaled_height); diff --git a/game/client/gui/direct_connection.cc b/game/client/gui/direct_connection.cc index dfbd05b..c521232 100644 --- a/game/client/gui/direct_connection.cc +++ b/game/client/gui/direct_connection.cc @@ -63,7 +63,7 @@ static void connect_to_server(void) } if(parts.size() >= 2) { - parsed_port = math::clamp(strtoul(parts[1].c_str(), nullptr, 10), 1024, UINT16_MAX); + parsed_port = glm::clamp(strtoul(parts[1].c_str(), nullptr, 10), 1024, UINT16_MAX); } else { parsed_port = protocol::PORT; diff --git a/game/client/gui/language.cc b/game/client/gui/language.cc index 57a43fe..d10f88b 100644 --- a/game/client/gui/language.cc +++ b/game/client/gui/language.cc @@ -5,6 +5,7 @@ #include "core/config/string.hh" #include "core/io/config_map.hh" +#include "core/io/physfs.hh" #include "client/gui/settings.hh" @@ -40,7 +41,7 @@ void gui::language::init(void) auto file = PHYSFS_openRead(std::string(MANIFEST_PATH).c_str()); if(file == nullptr) { - spdlog::critical("language: {}: {}", MANIFEST_PATH, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("language: {}: {}", MANIFEST_PATH, io::physfs_error()); std::terminate(); } @@ -113,7 +114,7 @@ void gui::language::set(LanguageIterator new_language) auto file = PHYSFS_openRead(path.c_str()); if(file == nullptr) { - spdlog::warn("language: {}: {}", path, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::warn("language: {}: {}", path, io::physfs_error()); send_language_event(new_language); return; } diff --git a/game/client/gui/main_menu.cc b/game/client/gui/main_menu.cc index aa506d3..6c0ee37 100644 --- a/game/client/gui/main_menu.cc +++ b/game/client/gui/main_menu.cc @@ -96,7 +96,7 @@ void gui::main_menu::layout(void) } else { auto reference_height = 0.225f * window_size.y; - auto image_width = math::min(window_size.x, reference_height * title_aspect); + auto image_width = glm::min(window_size.x, reference_height * title_aspect); auto image_height = image_width / title_aspect; ImGui::SetCursorPosX(0.5f * (window_size.x - image_width)); ImGui::Image(title->handle, ImVec2(image_width, image_height)); diff --git a/game/client/gui/play_menu.cc b/game/client/gui/play_menu.cc index 0747e3a..cd7f730 100644 --- a/game/client/gui/play_menu.cc +++ b/game/client/gui/play_menu.cc @@ -95,7 +95,7 @@ static void parse_hostname(ServerStatusItem* item, const std::string& hostname) } if(parts.size() >= 2) { - item->port = math::clamp(strtoul(parts[1].c_str(), nullptr, 10), 1024, UINT16_MAX); + item->port = glm::clamp(strtoul(parts[1].c_str(), nullptr, 10), 1024, UINT16_MAX); } else { item->port = protocol::PORT; @@ -305,7 +305,7 @@ static void layout_server_item(ServerStatusItem* item) auto outline_pos = ImVec2(version_pos.x - 2U * globals::gui_scale, version_pos.y - 2U * globals::gui_scale); auto outline_end = ImVec2(version_end.x + 2U * globals::gui_scale, version_end.y + 2U * globals::gui_scale); - auto outline_thickness = math::max(1.0f, 0.5f * static_cast(globals::gui_scale)); + auto outline_thickness = glm::max(1.0f, 0.5f * static_cast(globals::gui_scale)); draw_list->AddRect(outline_pos, outline_end, version_color, 0.0f, 0, outline_thickness); draw_list->AddText(version_pos, version_color, version_toast.c_str(), version_toast.c_str() + version_toast.size()); diff --git a/game/client/gui/progress_bar.cc b/game/client/gui/progress_bar.cc index 9266ce1..46277b5 100644 --- a/game/client/gui/progress_bar.cc +++ b/game/client/gui/progress_bar.cc @@ -58,10 +58,10 @@ void gui::progress_bar::layout(void) const float modifier = std::exp(-8.0f * (0.5f + 0.5f * sinval)); ImVec4 color = {}; - color.x = math::lerp(background.x, foreground.x, modifier); - color.y = math::lerp(background.y, foreground.y, modifier); - color.z = math::lerp(background.z, foreground.z, modifier); - color.w = math::lerp(background.w, foreground.w, modifier); + color.x = glm::mix(background.x, foreground.x, modifier); + color.y = glm::mix(background.y, foreground.y, modifier); + color.z = glm::mix(background.z, foreground.z, modifier); + color.w = glm::mix(background.w, foreground.w, modifier); const ImVec2 start = ImVec2(base_xpos + bar_width * i, base_ypos); const ImVec2 end = ImVec2(start.x + bar_width, start.y + bar_height); diff --git a/game/client/gui/scoreboard.cc b/game/client/gui/scoreboard.cc index f875ef2..12a4f41 100644 --- a/game/client/gui/scoreboard.cc +++ b/game/client/gui/scoreboard.cc @@ -69,7 +69,7 @@ void gui::scoreboard::layout(void) // Having a minimum size allows for // generally better in-game visibility - const float true_size = math::max(0.25f * window_size.x, max_username_size); + const float true_size = glm::max(0.25f * window_size.x, max_username_size); // Figure out username rect dimensions const float rect_start_x = 0.5f * window_size.x - 0.5f * true_size; diff --git a/game/client/gui/splash.cc b/game/client/gui/splash.cc index 9990103..5eae0f2 100644 --- a/game/client/gui/splash.cc +++ b/game/client/gui/splash.cc @@ -99,7 +99,7 @@ void gui::client_splash::init_late(void) break; } - texture_alpha = math::smoothstep(0.25f, 0.6f, static_cast(remains) / static_cast(DELAY_MICROSECONDS)); + texture_alpha = glm::smoothstep(0.25f, 0.6f, static_cast(remains) / static_cast(DELAY_MICROSECONDS)); gui::client_splash::render(); } diff --git a/game/client/io/gamepad.cc b/game/client/io/gamepad.cc index 1407996..f19f04a 100644 --- a/game/client/io/gamepad.cc +++ b/game/client/io/gamepad.cc @@ -147,8 +147,8 @@ void io::gamepad::update_late(void) if(glfwGetGamepadState(active_gamepad_id, &io::gamepad::state)) { for(int i = 0; i < NUM_AXES; ++i) { - if((math::abs(io::gamepad::state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD) - && (math::abs(io::gamepad::last_state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD)) { + if((glm::abs(io::gamepad::state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD) + && (glm::abs(io::gamepad::last_state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD)) { GamepadAxisEvent event; event.action = GLFW_PRESS; event.axis = i; @@ -156,8 +156,8 @@ void io::gamepad::update_late(void) continue; } - if((math::abs(io::gamepad::state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD) - && (math::abs(io::gamepad::last_state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD)) { + if((glm::abs(io::gamepad::state.axes[i]) <= GAMEPAD_AXIS_EVENT_THRESHOLD) + && (glm::abs(io::gamepad::last_state.axes[i]) > GAMEPAD_AXIS_EVENT_THRESHOLD)) { GamepadAxisEvent event; event.action = GLFW_RELEASE; event.axis = i; diff --git a/game/client/main.cc b/game/client/main.cc index e20fd5c..b2a6a01 100644 --- a/game/client/main.cc +++ b/game/client/main.cc @@ -321,8 +321,8 @@ int main(int argc, char** argv) if(auto vmode = io::cmdline::get_cstr("mode")) { std::sscanf(vmode, "%dx%d", &vmode_width, &vmode_height); - vmode_height = math::max(vmode_height, MIN_HEIGHT); - vmode_width = math::max(vmode_width, MIN_WIDTH); + vmode_height = glm::max(vmode_height, MIN_HEIGHT); + vmode_width = glm::max(vmode_width, MIN_WIDTH); } glfwSetWindowSize(globals::window, vmode_width, vmode_height); diff --git a/game/client/program.cc b/game/client/program.cc index 9eba02f..6a2dfa0 100644 --- a/game/client/program.cc +++ b/game/client/program.cc @@ -2,6 +2,8 @@ #include "client/program.hh" +#include "core/io/physfs.hh" + #include "core/utils/string.hh" // This fills up the array of source lines and figures out @@ -76,7 +78,7 @@ bool GL_Program::setup(std::string_view vpath, std::string_view fpath) auto vfile = PHYSFS_openRead(vert_path.c_str()); if(vfile == nullptr) { - spdlog::warn("gl_program: {}: {}", vpath, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::warn("gl_program: {}: {}", vpath, io::physfs_error()); return false; } @@ -87,7 +89,7 @@ bool GL_Program::setup(std::string_view vpath, std::string_view fpath) auto ffile = PHYSFS_openRead(frag_path.c_str()); if(ffile == nullptr) { - spdlog::warn("gl_program: {}: {}", fpath, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::warn("gl_program: {}: {}", fpath, io::physfs_error()); return false; } diff --git a/game/client/resource/sound_effect.cc b/game/client/resource/sound_effect.cc index d6cc7c5..9d5d8a9 100644 --- a/game/client/resource/sound_effect.cc +++ b/game/client/resource/sound_effect.cc @@ -4,7 +4,7 @@ #include "core/resource/resource.hh" -#include "core/utils/physfs.hh" +#include "core/io/physfs.hh" #include "client/globals.hh" @@ -35,7 +35,7 @@ static const void* sound_effect_load_func(const char* name, std::uint32_t flags) auto file = PHYSFS_openRead(name); if(file == nullptr) { - spdlog::warn("sfx: {}: {}", name, utils::physfs_error()); + spdlog::warn("sfx: {}: {}", name, io::physfs_error()); return nullptr; } diff --git a/game/client/session.cc b/game/client/session.cc index ce3d616..d8666b9 100644 --- a/game/client/session.cc +++ b/game/client/session.cc @@ -41,7 +41,7 @@ static std::uint64_t server_password_hash = UINT64_MAX; static void set_fixed_tickrate(std::uint16_t tickrate) { - globals::fixed_frametime_us = 1000000U / math::clamp(tickrate, 10U, 300U); + globals::fixed_frametime_us = 1000000U / glm::clamp(tickrate, 10U, 300U); globals::fixed_frametime = static_cast(globals::fixed_frametime_us) / 1000000.0f; globals::fixed_accumulator = 0; } diff --git a/game/client/sound/sound.cc b/game/client/sound/sound.cc index 403bd3e..0eb0463 100644 --- a/game/client/sound/sound.cc +++ b/game/client/sound/sound.cc @@ -92,11 +92,11 @@ void sound::shutdown(void) void sound::update(void) { - auto effects_gain = math::clamp(0.01f * sound::volume_effects.get_value(), 0.0f, 1.0f); + auto effects_gain = glm::clamp(0.01f * sound::volume_effects.get_value(), 0.0f, 1.0f); alSourcef(generic_source, AL_GAIN, effects_gain); alSourcef(player_source, AL_GAIN, effects_gain); - auto ui_gain = math::clamp(0.01f * sound::volume_ui.get_value(), 0.0f, 1.0f); + auto ui_gain = glm::clamp(0.01f * sound::volume_ui.get_value(), 0.0f, 1.0f); alSourcef(ui_source, AL_GAIN, ui_gain); } @@ -149,7 +149,7 @@ void sound::play_generic(resource_ptr sound, bool looping, float pi if(sfx_generic) { alSourcei(generic_source, AL_BUFFER, sfx_generic->buffer); alSourcei(generic_source, AL_LOOPING, looping); - alSourcef(generic_source, AL_PITCH, math::clamp(pitch, MIN_PITCH, MAX_PITCH)); + alSourcef(generic_source, AL_PITCH, glm::clamp(pitch, MIN_PITCH, MAX_PITCH)); alSourcePlay(generic_source); } } @@ -165,7 +165,7 @@ void sound::play_entity(entt::entity entity, resource_ptr sound, bo if(emitter->sound) { alSourcei(emitter->source, AL_BUFFER, emitter->sound->buffer); alSourcei(emitter->source, AL_LOOPING, looping); - alSourcef(emitter->source, AL_PITCH, math::clamp(pitch, MIN_PITCH, MAX_PITCH)); + alSourcef(emitter->source, AL_PITCH, glm::clamp(pitch, MIN_PITCH, MAX_PITCH)); alSourcePlay(emitter->source); } } @@ -191,7 +191,7 @@ void sound::play_player(resource_ptr sound, bool looping, float pit if(sfx_player) { alSourcei(player_source, AL_BUFFER, sfx_player->buffer); alSourcei(player_source, AL_LOOPING, looping); - alSourcef(player_source, AL_PITCH, math::clamp(pitch, MIN_PITCH, MAX_PITCH)); + alSourcef(player_source, AL_PITCH, glm::clamp(pitch, MIN_PITCH, MAX_PITCH)); alSourcePlay(player_source); } } @@ -205,7 +205,7 @@ void sound::play_ui(resource_ptr sound, bool looping, float pitch) if(sfx_ui) { alSourcei(ui_source, AL_BUFFER, sfx_ui->buffer); alSourcei(ui_source, AL_LOOPING, looping); - alSourcef(ui_source, AL_PITCH, math::clamp(pitch, MIN_PITCH, MAX_PITCH)); + alSourcef(ui_source, AL_PITCH, glm::clamp(pitch, MIN_PITCH, MAX_PITCH)); alSourcePlay(ui_source); } } diff --git a/game/client/world/chunk_mesher.cc b/game/client/world/chunk_mesher.cc index bc90a03..da90d2e 100644 --- a/game/client/world/chunk_mesher.cc +++ b/game/client/world/chunk_mesher.cc @@ -39,9 +39,9 @@ static const CachedChunkCoord get_cached_cpos(const chunk_pos& pivot, const chun if(pivot != cpos) { chunk_pos delta = pivot - cpos; - delta[0] = math::clamp(delta[0], -1, 1); - delta[1] = math::clamp(delta[1], -1, 1); - delta[2] = math::clamp(delta[2], -1, 1); + delta[0] = glm::clamp(delta[0], -1, 1); + delta[1] = glm::clamp(delta[1], -1, 1); + delta[2] = glm::clamp(delta[2], -1, 1); if(delta[0]) { return nx[delta[0] + 1]; diff --git a/game/client/world/voxel_atlas.cc b/game/client/world/voxel_atlas.cc index a01db12..67832d3 100644 --- a/game/client/world/voxel_atlas.cc +++ b/game/client/world/voxel_atlas.cc @@ -96,12 +96,12 @@ void world::voxel_atlas::create(int width, int height, std::size_t count) // how voxel quad meshes are packed in memory: each texture index is // confined in 11 bits so having bigger atlas planes makes no sense; glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &max_plane_layers); - max_plane_layers = math::clamp(max_plane_layers, 256, 2048); + max_plane_layers = glm::clamp(max_plane_layers, 256, 2048); for(long i = count; i > 0L; i -= max_plane_layers) { AtlasPlane plane = {}; plane.plane_id = planes.size(); - plane.layer_count_max = math::min(max_plane_layers, i); + plane.layer_count_max = glm::min(max_plane_layers, i); plane.layer_count = 0; const std::size_t save_id = plane.plane_id; diff --git a/game/server/whitelist.cc b/game/server/whitelist.cc index 053809e..f2599b9 100644 --- a/game/server/whitelist.cc +++ b/game/server/whitelist.cc @@ -6,6 +6,7 @@ #include "core/config/string.hh" #include "core/io/config_map.hh" +#include "core/io/physfs.hh" #include "core/math/crc64.hh" @@ -47,7 +48,7 @@ void whitelist::init_late(void) PHYSFS_File* file = PHYSFS_openRead(whitelist::filename.c_str()); if(file == nullptr) { - spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::warn("whitelist: {}: {}", whitelist::filename.get(), io::physfs_error()); whitelist::enabled.set_value(false); return; } diff --git a/game/server/world/overworld.cc b/game/server/world/overworld.cc index 43059d8..b72a816 100644 --- a/game/server/world/overworld.cc +++ b/game/server/world/overworld.cc @@ -15,7 +15,7 @@ static void compute_tree_feature(unsigned int height, world::Feature& feature, c const world::Voxel* leaves_voxel) { // Ensure the tree height is too small - height = math::max(height, 4U); + height = glm::max(height, 4U); // Put down a single piece of dirt feature.push_back({ voxel_pos(0, -1, 0), game_voxels::dirt, true }); @@ -217,7 +217,7 @@ const world::Overworld_Metadata& world::Overworld::get_or_create_metadata(const } auto nvdi_value = 0.5f + 0.5f * fnlGetNoise2D(&m_fnl_nvdi, cpos.x, cpos.y); - auto tree_density = (nvdi_value >= 0.33f) ? math::floor(nvdi_value * 4.0f) : 0U; + auto tree_density = (nvdi_value >= 0.33f) ? static_cast(glm::floor(nvdi_value * 4.0f)) : 0U; for(unsigned int i = 0U; i < tree_density; ++i) { auto lpos = local_pos((twister() % CHUNK_SIZE), (twister() % OW_NUM_TREES), (twister() % CHUNK_SIZE)); diff --git a/game/server/world/universe.cc b/game/server/world/universe.cc index 2dd6053..b27a8de 100644 --- a/game/server/world/universe.cc +++ b/game/server/world/universe.cc @@ -7,6 +7,7 @@ #include "core/io/buffer.hh" #include "core/io/config_map.hh" +#include "core/io/physfs.hh" #include "core/utils/epoch.hh" @@ -51,7 +52,7 @@ static void add_new_dimension(world::Dimension* dimension) auto dimension_dir = std::format("{}/{}", universe_name.get(), dimension->get_name()); if(!PHYSFS_mkdir(dimension_dir.c_str())) { - spdlog::critical("universe: {}: {}", dimension_dir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("universe: {}: {}", dimension_dir, io::physfs_error()); std::terminate(); } @@ -60,7 +61,7 @@ static void add_new_dimension(world::Dimension* dimension) metadata->zvox_dir = std::format("{}/chunk", dimension_dir); if(!PHYSFS_mkdir(metadata->zvox_dir.c_str())) { - spdlog::critical("universe: {}: {}", metadata->zvox_dir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("universe: {}: {}", metadata->zvox_dir, io::physfs_error()); std::terminate(); } @@ -109,7 +110,7 @@ void world::universe::init_late(void) const auto universe_dir = std::string(universe_name.get()); if(!PHYSFS_mkdir(universe_dir.c_str())) { - spdlog::critical("universe: {}: {}", universe_dir, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("universe: {}: {}", universe_dir, io::physfs_error()); std::terminate(); } diff --git a/game/shared/entity/collision.cc b/game/shared/entity/collision.cc index 6b9f063..d2bc0a9 100644 --- a/game/shared/entity/collision.cc +++ b/game/shared/entity/collision.cc @@ -29,14 +29,14 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli next_aabb.max[d] += move; local_pos lpos_min; - lpos_min.x = math::floor(next_aabb.min.x); - lpos_min.y = math::floor(next_aabb.min.y); - lpos_min.z = math::floor(next_aabb.min.z); + lpos_min.x = static_cast(glm::floor(next_aabb.min.x)); + lpos_min.y = static_cast(glm::floor(next_aabb.min.y)); + lpos_min.z = static_cast(glm::floor(next_aabb.min.z)); local_pos lpos_max; - lpos_max.x = math::ceil(next_aabb.max.x); - lpos_max.y = math::ceil(next_aabb.max.y); - lpos_max.z = math::ceil(next_aabb.max.z); + lpos_max.x = static_cast(glm::ceil(next_aabb.max.x)); + lpos_max.y = static_cast(glm::ceil(next_aabb.max.y)); + lpos_max.z = static_cast(glm::ceil(next_aabb.max.z)); // Other axes const int u = (d + 1) % 3; @@ -110,7 +110,7 @@ static int vgrid_collide(const world::Dimension* dimension, int d, entity::Colli if(latch_touch != world::VTOUCH_NONE) { if(latch_touch == world::VTOUCH_BOUNCE) { - const auto move_distance = math::abs(current_aabb.min[d] - next_aabb.min[d]); + const auto move_distance = glm::abs(current_aabb.min[d] - next_aabb.min[d]); const auto threshold = 2.0f * globals::fixed_frametime; if(move_distance > threshold) { diff --git a/game/shared/game.cc b/game/shared/game.cc index f7b9da4..91bc3bc 100644 --- a/game/shared/game.cc +++ b/game/shared/game.cc @@ -3,6 +3,7 @@ #include "shared/game.hh" #include "core/io/cmdline.hh" +#include "core/io/physfs.hh" static std::filesystem::path get_gamepath(void) { @@ -77,7 +78,7 @@ void shared_game::init(int argc, char** argv) logger->flush(); if(!PHYSFS_init(argv[0])) { - spdlog::critical("physfs: init failed: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("physfs: init failed: {}", io::physfs_error()); std::terminate(); } @@ -92,17 +93,17 @@ void shared_game::init(int argc, char** argv) std::filesystem::create_directories(userpath, ignore_error); if(!PHYSFS_mount(gamepath.string().c_str(), nullptr, false)) { - spdlog::critical("physfs: mount {} failed: {}", gamepath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("physfs: mount {} failed: {}", gamepath.string(), io::physfs_error()); std::terminate(); } if(!PHYSFS_mount(userpath.string().c_str(), nullptr, false)) { - spdlog::critical("physfs: mount {} failed: {}", userpath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("physfs: mount {} failed: {}", userpath.string(), io::physfs_error()); std::terminate(); } if(!PHYSFS_setWriteDir(userpath.string().c_str())) { - spdlog::critical("physfs: setwritedir {} failed: {}", userpath.string(), PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("physfs: setwritedir {} failed: {}", userpath.string(), io::physfs_error()); std::terminate(); } @@ -117,7 +118,7 @@ void shared_game::shutdown(void) enet_deinitialize(); if(!PHYSFS_deinit()) { - spdlog::critical("physfs: deinit failed: {}", PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode())); + spdlog::critical("physfs: deinit failed: {}", io::physfs_error()); std::terminate(); } } diff --git a/game/shared/splash.cc b/game/shared/splash.cc index 7515358..9d74ba9 100644 --- a/game/shared/splash.cc +++ b/game/shared/splash.cc @@ -2,6 +2,8 @@ #include "shared/splash.hh" +#include "core/io/physfs.hh" + constexpr static std::string_view SPLASHES_FILENAME_CLIENT = "misc/splashes_client.txt"; constexpr static std::string_view SPLASHES_FILENAME_SERVER = "misc/splashes_server.txt"; constexpr static std::size_t SPLASH_SERVER_MAX_LENGTH = 32; @@ -37,7 +39,7 @@ static void splash_init_filename(std::string_view filename) splash_random.seed(std::random_device()()); } else { - splash_lines.push_back(std::format("{}: {}", filename, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()))); + splash_lines.push_back(std::format("{}: {}", filename, io::physfs_error())); splash_random.seed(std::random_device()()); } } diff --git a/game/shared/world/ray_dda.cc b/game/shared/world/ray_dda.cc index 7bb1068..af1ab3b 100644 --- a/game/shared/world/ray_dda.cc +++ b/game/shared/world/ray_dda.cc @@ -26,9 +26,9 @@ void world::RayDDA::reset(const world::Dimension* dimension, const chunk_pos& st this->start_fpos = start_fpos; this->direction = direction; - this->delta_dist.x = direction.x ? math::abs(1.0f / direction.x) : std::numeric_limits::max(); - this->delta_dist.y = direction.y ? math::abs(1.0f / direction.y) : std::numeric_limits::max(); - this->delta_dist.z = direction.z ? math::abs(1.0f / direction.z) : std::numeric_limits::max(); + this->delta_dist.x = direction.x ? glm::abs(1.0f / direction.x) : std::numeric_limits::max(); + this->delta_dist.y = direction.y ? glm::abs(1.0f / direction.y) : std::numeric_limits::max(); + this->delta_dist.z = direction.z ? glm::abs(1.0f / direction.z) : std::numeric_limits::max(); this->distance = 0.0f; this->vpos = coord::to_voxel(start_chunk, start_fpos); -- cgit