galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
LuaMath.cpp
Go to the documentation of this file.
1
7
8#include <entt/locator/locator.hpp>
9#include <sol/sol.hpp>
10
12#include "galaxy/math/FNV1a.hpp"
13#include "galaxy/math/Math.hpp"
15#include "galaxy/math/Rect.hpp"
17#include "galaxy/math/ZLib.hpp"
18
19namespace galaxy
20{
21 namespace lua
22 {
24 {
25 auto& lua = entt::locator<sol::state>::value();
26
27 lua.set_function("encode_base64", &math::encode_base64);
28 lua.set_function("decode_base64", &math::decode_base64);
29
30 lua.set_function("fnv1a_32", &math::fnv1a_32);
31 lua.set_function("fnv1a_64", &math::fnv1a_64);
32
33 lua.set_function("normalize_f", &math::normalize<float>);
34 lua.set_function("normalize_i", &math::normalize<int>);
35
36 lua.set_function("random_int", &math::random<int>);
37 lua.set_function("random_float", &math::random<float>);
38 lua.set_function("random_vec2", &math::random_vec2);
39 lua.set_function("random_vec3", &math::random_vec3);
40 lua.set_function("random_vec4", &math::random_vec4);
41
42 lua.set_function("encode_zlib", &ZLib::encode);
43 lua.set_function("decode_zlib", &ZLib::decode);
44
45 auto frect_type = lua.new_usertype<fRect>("fRect", sol::constructors<fRect(), fRect(const float, const float, const float, const float)>());
46 frect_type["x"] = &fRect::x;
47 frect_type["y"] = &fRect::y;
48 frect_type["width"] = &fRect::width;
49 frect_type["height"] = &fRect::height;
50 frect_type["contains_point"] = sol::resolve<bool(const float, const float) const>(&fRect::contains);
51 frect_type["contains"] = sol::resolve<bool(const fRect&) const>(&fRect::contains);
52 frect_type["overlaps"] = &fRect::overlaps;
53 frect_type["intersects"] = &fRect::intersects;
54 frect_type["set_top_left"] = &fRect::set_top_left;
55 frect_type["get_right"] = &fRect::get_right;
56 frect_type["get_bottom"] = &fRect::get_bottom;
57 frect_type["get_top_left"] = &fRect::get_top_left;
58 frect_type["get_center"] = &fRect::get_center;
59 frect_type["get_size"] = &fRect::get_size;
60
61 auto irect_type = lua.new_usertype<iRect>("iRect", sol::constructors<iRect(), iRect(const int, const int, const int, const int)>());
62 irect_type["x"] = &iRect::x;
63 irect_type["y"] = &iRect::y;
64 irect_type["width"] = &iRect::width;
65 irect_type["height"] = &iRect::height;
66 irect_type["contains_point"] = sol::resolve<bool(const int, const int) const>(&iRect::contains);
67 irect_type["contains"] = sol::resolve<bool(const iRect&) const>(&iRect::contains);
68 irect_type["overlaps"] = &iRect::overlaps;
69 irect_type["intersects"] = &iRect::intersects;
70 irect_type["set_top_left"] = &iRect::set_top_left;
71 irect_type["get_right"] = &iRect::get_right;
72 irect_type["get_bottom"] = &iRect::get_bottom;
73 irect_type["get_top_left"] = &iRect::get_top_left;
74 irect_type["get_center"] = &iRect::get_center;
75 irect_type["get_size"] = &iRect::get_size;
76
77 auto rectpack_type = lua.new_usertype<RectPack>("RectPack", sol::constructors<RectPack()>());
78 rectpack_type["init"] = &RectPack::init;
79 rectpack_type["pack"] = &RectPack::pack;
80 rectpack_type["clear"] = &RectPack::clear;
81 rectpack_type["get_width"] = &RectPack::get_width;
82 rectpack_type["get_height"] = &RectPack::get_height;
83 rectpack_type["get_free_space"] = &RectPack::get_free_space;
84 }
85 } // namespace lua
86} // namespace galaxy
Rectangle 2D bin packing class.
Definition RectPack.hpp:22
const std::vector< iRect > & get_free_space() const noexcept
Get free rectangles.
Definition RectPack.cpp:106
std::optional< iRect > pack(const int width, const int height)
Pack a rectangle into the master rectangle.
Definition RectPack.cpp:31
void clear() noexcept
Clear all data.
Definition RectPack.cpp:90
int get_height() const noexcept
Get total height.
Definition RectPack.cpp:101
void init(const int width, const int height) noexcept
Set starting width and height of rectangle.
Definition RectPack.cpp:23
int get_width() const noexcept
Get total width.
Definition RectPack.cpp:96
bool intersects(const Rect< Type > &b) const noexcept
Definition Rect.hpp:235
bool contains(const Type _x, const Type _y) const noexcept
Definition Rect.hpp:212
bool overlaps(const Rect< Type > &b) noexcept
Definition Rect.hpp:225
void set_top_left(const glm::vec< 2, Type, glm::defaultp > &pos) noexcept
Definition Rect.hpp:241
Type get_right() const noexcept
Definition Rect.hpp:248
glm::vec< 2, Type, glm::defaultp > get_size() const noexcept
Definition Rect.hpp:272
glm::vec< 2, Type, glm::defaultp > get_top_left() const noexcept
Definition Rect.hpp:260
Type get_bottom() const noexcept
Definition Rect.hpp:254
glm::vec< 2, Type, glm::defaultp > get_center() const noexcept
Definition Rect.hpp:266
static std::string decode(const std::string &input)
Decompresses string into ZLib.
Definition ZLib.cpp:124
static std::string encode(const std::string &input)
Compresses string into ZLib.
Definition ZLib.cpp:81
void inject_math()
Injects math stuff into Lua.
Definition LuaMath.cpp:23
constexpr std::uint64_t fnv1a_64(const char *const str) noexcept
Convert string to 64bit hash.
Definition FNV1a.hpp:92
std::string encode_base64(const std::string &input)
Compresses string into Base64.
Definition Base64.cpp:51
glm::vec3 random_vec3(const glm::vec3 &min, const glm::vec3 &max) noexcept
Generate a random vec3.
Definition Random.cpp:19
float constexpr normalize(const Arithmetic val, const Arithmetic max) noexcept
Calc normalized value from range.
Definition Math.hpp:29
std::string decode_base64(const std::string &input)
Decompresses string into Base64.
Definition Base64.cpp:105
glm::vec2 random_vec2(const glm::vec2 &min, const glm::vec2 &max) noexcept
Generate a random vec2.
Definition Random.cpp:14
glm::vec4 random_vec4(const glm::vec4 &min, const glm::vec4 &max) noexcept
Generate a random vec4.
Definition Random.cpp:24
constexpr std::uint32_t fnv1a_32(const char *const str) noexcept
Convert string to 32bit hash.
Definition FNV1a.hpp:78
T random(const T min, const T max) noexcept
Generate a random number of type T.
Definition Random.hpp:44
Timer.hpp galaxy.
Definition Timer.cpp:18