Fix vector metamethods + add some debug funcs

This commit is contained in:
fed 2023-06-22 01:01:52 +02:00
parent 100ae9cd22
commit 5d85ea110b
3 changed files with 52 additions and 6 deletions

View File

@ -25,12 +25,14 @@ namespace gui::debug
float start[3];
float end[3];
float color[4];
bool deleted;
};
struct debug_square
{
float origin[3];
float color[4];
bool deleted;
};
std::vector<debug_line> debug_lines;
@ -683,12 +685,22 @@ namespace gui::debug
for (auto& line : debug_lines)
{
if (line.deleted)
{
continue;
}
draw_line(line.start, line.end, line.color, 1.f);
}
for (auto& square : debug_squares)
{
draw_square(square.origin, 100.f, square.color);
if (square.deleted)
{
continue;
}
draw_square(square.origin, 50.f, square.color);
}
}
@ -734,11 +746,22 @@ namespace gui::debug
std::memcpy(line.color, color, sizeof(float[4]));
std::lock_guard _0(debug_items_mutex);
const auto index = debug_squares.size();
const auto index = debug_lines.size();
debug_lines.emplace_back(line);
return index;
}
void remove_debug_line(const size_t line)
{
std::lock_guard _0(debug_items_mutex);
if (line >= debug_lines.size())
{
return;
}
debug_lines[line].deleted = true;
}
void set_debug_line_color(size_t line, const float* color)
{
std::lock_guard _0(debug_items_mutex);
@ -763,6 +786,17 @@ namespace gui::debug
return index;
}
void remove_debug_square(const size_t square)
{
std::lock_guard _0(debug_items_mutex);
if (square >= debug_squares.size())
{
return;
}
debug_squares[square].deleted = true;
}
void set_debug_square_color(size_t square, const float* color)
{
std::lock_guard _0(debug_items_mutex);

View File

@ -1,9 +1,11 @@
namespace gui::debug
{
size_t add_debug_line(const float* start, const float* end, const float* color);
void remove_debug_line(const size_t line);
void set_debug_line_color(size_t line, const float* color);
size_t add_debug_square(const float* origin, const float* color);
void remove_debug_square(const size_t line);
void set_debug_square_color(size_t square, const float* color);
void reset_debug_items();

View File

@ -101,7 +101,7 @@ namespace scripting::lua
a.get_z() + b.get_z()
);
},
[](const vector& a, const int value)
[](const vector& a, const float value)
{
return vector(
a.get_x() + value,
@ -120,7 +120,7 @@ namespace scripting::lua
a.get_z() - b.get_z()
);
},
[](const vector& a, const int value)
[](const vector& a, const float value)
{
return vector(
a.get_x() - value,
@ -139,7 +139,7 @@ namespace scripting::lua
a.get_z() * b.get_z()
);
},
[](const vector& a, const int value)
[](const vector& a, const float value)
{
return vector(
a.get_x() * value,
@ -158,7 +158,7 @@ namespace scripting::lua
a.get_z() / b.get_z()
);
},
[](const vector& a, const int value)
[](const vector& a, const float value)
{
return vector(
a.get_x() / value,
@ -504,6 +504,11 @@ namespace scripting::lua
return gui::debug::add_debug_line(start, end, color_);
};
debug_type["removeline"] = [](const debug&, const size_t line)
{
return gui::debug::remove_debug_line(line);
};
debug_type["addsquare"] = [](const debug&, const vector& origin, const vector& color)
{
float color_[4]{};
@ -515,6 +520,11 @@ namespace scripting::lua
return gui::debug::add_debug_square(origin, color_);
};
debug_type["removesquare"] = [](const debug&, const size_t square)
{
return gui::debug::remove_debug_square(square);
};
debug_type["setsquarecolor"] = [](const debug&, const size_t& square, const vector& color)
{
float color_[4]{};