add more debug messages and checks

This commit is contained in:
MihailRis 2026-02-02 19:54:24 +03:00
parent f1d85000e4
commit a7ffbc9dec
3 changed files with 47 additions and 14 deletions

View file

@ -1,10 +1,13 @@
#include "Transform.hpp"
#include "data/dv_util.hpp"
#include "debug/Logger.hpp"
#include "maths/util.hpp"
#include <glm/gtc/matrix_transform.hpp>
static debug::Logger logger("entity-transform");
void Transform::refresh() {
combined = glm::mat4(1.0f);
combined = glm::translate(combined, pos);
@ -33,25 +36,31 @@ void Transform::deserialize(const dv::value& root) {
dv::get_mat(root, "rot", rot);
}
bool Transform::checkValue(const glm::vec3& vector) {
bool Transform::checkValue(const glm::vec3& vector, std::string_view name) {
if (util::is_nan_or_inf(vector)) {
auto message = "invalid vector attempted set to " + std::string(name) +
" : " + std::to_string(vector.x) + ", " +
std::to_string(vector.y) + ", " +
std::to_string(vector.z);
#ifndef NDEBUG
throw std::invalid_argument(
"invalid vector: " + std::to_string(vector.x) + ", " +
std::to_string(vector.y) + ", " + std::to_string(vector.z)
);
throw std::invalid_argument(message);
#else
logger.warning() << message;
return false;
#endif
}
return true;
}
bool Transform::checkValue(const glm::mat3& matrix) {
bool Transform::checkValue(const glm::mat3& matrix, std::string_view name) {
if (util::is_nan_or_inf(matrix)) {
auto message =
"invalid matrix (contains nan or inf) attempted set to " +
std::string(name);
#ifndef NDEBUG
throw std::invalid_argument("invalid matrix (contains nan or inf)");
throw std::invalid_argument(message);
#else
logger.warning() << message;
return false;
#endif
}