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 --- game/shared/entity/collision.cc | 14 +++++++------- game/shared/game.cc | 11 ++++++----- game/shared/splash.cc | 4 +++- game/shared/world/ray_dda.cc | 6 +++--- 4 files changed, 19 insertions(+), 16 deletions(-) (limited to 'game/shared') 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