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,5 +1,24 @@
#include "libentity.hpp"
#include "maths/util.hpp"
static void check_valid(const glm::vec3& vec) {
if (util::is_nan_or_inf(vec)) {
throw std::invalid_argument(
"invalid vector: " + std::to_string(vec.x) + ", " +
std::to_string(vec.y) + ", " + std::to_string(vec.z)
);
}
}
static void check_valid(const glm::mat3& vec) {
if (util::is_nan_or_inf(vec)) {
throw std::invalid_argument(
"invalid matrix (contains nan or inf values)"
);
}
}
static int l_get_pos(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
return lua::pushvec3(L, entity->getTransform().pos);
@ -10,6 +29,7 @@ static int l_get_pos(lua::State* L) {
static int l_set_pos(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
auto vec = lua::tovec3(L, 2);
check_valid(vec);
entity->getTransform().setPos(vec);
entity->getRigidbody().hitbox.position = vec;
}
@ -25,7 +45,9 @@ static int l_get_size(lua::State* L) {
static int l_set_size(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
entity->getTransform().setSize(lua::tovec3(L, 2));
auto vec = lua::tovec3(L, 2);
check_valid(vec);
entity->getTransform().setSize(vec);
}
return 0;
}
@ -39,7 +61,9 @@ static int l_get_rot(lua::State* L) {
static int l_set_rot(lua::State* L) {
if (auto entity = get_entity(L, 1)) {
entity->getTransform().setRot(lua::tomat4(L, 2));
auto matrix = lua::tomat4(L, 2);
check_valid(matrix);
entity->getTransform().setRot(matrix);
}
return 0;
}