mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 13:31:49 +00:00
add more debug messages and checks
This commit is contained in:
parent
f1d85000e4
commit
a7ffbc9dec
3 changed files with 47 additions and 14 deletions
|
|
@ -1,5 +1,24 @@
|
||||||
#include "libentity.hpp"
|
#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) {
|
static int l_get_pos(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
return lua::pushvec3(L, entity->getTransform().pos);
|
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) {
|
static int l_set_pos(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
if (auto entity = get_entity(L, 1)) {
|
||||||
auto vec = lua::tovec3(L, 2);
|
auto vec = lua::tovec3(L, 2);
|
||||||
|
check_valid(vec);
|
||||||
entity->getTransform().setPos(vec);
|
entity->getTransform().setPos(vec);
|
||||||
entity->getRigidbody().hitbox.position = 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) {
|
static int l_set_size(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +61,9 @@ static int l_get_rot(lua::State* L) {
|
||||||
|
|
||||||
static int l_set_rot(lua::State* L) {
|
static int l_set_rot(lua::State* L) {
|
||||||
if (auto entity = get_entity(L, 1)) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
#include "Transform.hpp"
|
#include "Transform.hpp"
|
||||||
|
|
||||||
#include "data/dv_util.hpp"
|
#include "data/dv_util.hpp"
|
||||||
|
#include "debug/Logger.hpp"
|
||||||
#include "maths/util.hpp"
|
#include "maths/util.hpp"
|
||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
static debug::Logger logger("entity-transform");
|
||||||
|
|
||||||
void Transform::refresh() {
|
void Transform::refresh() {
|
||||||
combined = glm::mat4(1.0f);
|
combined = glm::mat4(1.0f);
|
||||||
combined = glm::translate(combined, pos);
|
combined = glm::translate(combined, pos);
|
||||||
|
|
@ -33,25 +36,31 @@ void Transform::deserialize(const dv::value& root) {
|
||||||
dv::get_mat(root, "rot", rot);
|
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)) {
|
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
|
#ifndef NDEBUG
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(message);
|
||||||
"invalid vector: " + std::to_string(vector.x) + ", " +
|
|
||||||
std::to_string(vector.y) + ", " + std::to_string(vector.z)
|
|
||||||
);
|
|
||||||
#else
|
#else
|
||||||
|
logger.warning() << message;
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return true;
|
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)) {
|
if (util::is_nan_or_inf(matrix)) {
|
||||||
|
auto message =
|
||||||
|
"invalid matrix (contains nan or inf) attempted set to " +
|
||||||
|
std::string(name);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
throw std::invalid_argument("invalid matrix (contains nan or inf)");
|
throw std::invalid_argument(message);
|
||||||
#else
|
#else
|
||||||
|
logger.warning() << message;
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ struct Transform {
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
inline void setRot(const glm::mat3& m) {
|
inline void setRot(const glm::mat3& m) {
|
||||||
if (!checkValue(m)) {
|
if (!checkValue(m, "rotation")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
rot = m;
|
rot = m;
|
||||||
|
|
@ -33,7 +33,7 @@ struct Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setSize(const glm::vec3& v) {
|
inline void setSize(const glm::vec3& v) {
|
||||||
if (!checkValue(v)) {
|
if (!checkValue(v, "size")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (glm::distance2(displaySize, v) >= EPSILON) {
|
if (glm::distance2(displaySize, v) >= EPSILON) {
|
||||||
|
|
@ -43,7 +43,7 @@ struct Transform {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setPos(const glm::vec3& v) {
|
inline void setPos(const glm::vec3& v) {
|
||||||
if (!checkValue(v)) {
|
if (!checkValue(v, "position")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (glm::distance2(displayPos, v) >= EPSILON) {
|
if (glm::distance2(displayPos, v) >= EPSILON) {
|
||||||
|
|
@ -52,6 +52,6 @@ struct Transform {
|
||||||
pos = v;
|
pos = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkValue(const glm::vec3& v);
|
static bool checkValue(const glm::vec3& v, std::string_view name);
|
||||||
static bool checkValue(const glm::mat3& v);
|
static bool checkValue(const glm::mat3& v, std::string_view name);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue