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"
16#include "galaxy/math/ZLib.hpp"
17
18namespace galaxy
19{
20 namespace lua
21 {
23 {
24 auto& lua = entt::locator<sol::state>::value();
25
26 lua.set_function("encode_base64", &math::encode_base64);
27 lua.set_function("decode_base64", &math::decode_base64);
28 lua.set_function("fnv1a_32", &math::fnv1a<std::uint32_t>);
29 lua.set_function("fnv1a_64", &math::fnv1a<std::uint64_t>);
30 lua.set_function("normalize_f", &math::normalize<float>);
31 lua.set_function("normalize_d", &math::normalize<double>);
32
33 auto random_type = lua.new_usertype<math::Random>("Random", sol::constructors<math::Random()>());
34 random_type["gen_int"] = &math::Random::gen<int>;
35 random_type["gen_float"] = &math::Random::gen<float>;
36 random_type["gen_vec2f"] = &math::Random::gen_vec2<float>;
37 random_type["gen_vec3f"] = &math::Random::gen_vec3<float>;
38 random_type["gen_vec2i"] = &math::Random::gen_vec2<int>;
39 random_type["gen_vec3i"] = &math::Random::gen_vec3<int>;
40
41 auto rectpack_type = lua.new_usertype<math::RectPack>("RectPack", sol::constructors<math::RectPack()>());
42 rectpack_type["init"] = &math::RectPack::init;
43 rectpack_type["pack"] = &math::RectPack::pack;
44 rectpack_type["clear"] = &math::RectPack::clear;
45 rectpack_type["get_width"] = &math::RectPack::get_width;
46 rectpack_type["get_height"] = &math::RectPack::get_height;
47 rectpack_type["get_free_space"] = &math::RectPack::get_free_space;
48
49 lua.set_function("encode_zlib", &math::encode_zlib);
50 lua.set_function("decode_zlib", &math::decode_zlib);
51 }
52 } // namespace lua
53} // namespace galaxy
Generates random numbers.
Definition Random.hpp:37
T gen(const T min, const T max) noexcept
Generate a random number of type T.
Definition Random.hpp:105
sf::Vector2< T > gen_vec2(const sf::Vector2< T > &min, const sf::Vector2< T > &max) noexcept
Generate a random vec2.
Definition Random.hpp:112
sf::Vector3< T > gen_vec3(const sf::Vector3< T > &min, const sf::Vector3< T > &max) noexcept
Generate a random vec3.
Definition Random.hpp:118
Rectangle 2D bin packing class.
Definition RectPack.hpp:24
void init(const int width, const int height) noexcept
Set starting width and height of rectangle.
Definition RectPack.cpp:25
std::optional< sf::IntRect > pack(const int width, const int height) noexcept
Pack a rectangle into the master rectangle.
Definition RectPack.cpp:33
int get_width() const noexcept
Get total width.
Definition RectPack.cpp:96
void clear() noexcept
Clear all data.
Definition RectPack.cpp:90
const std::vector< sf::IntRect > & get_free_space() const noexcept
Get free rectangles.
Definition RectPack.cpp:106
int get_height() const noexcept
Get total height.
Definition RectPack.cpp:101
void inject_math()
Injects math stuff into Lua.
Definition LuaMath.cpp:22
std::string encode_base64(const std::string &input)
Compresses string into Base64.
Definition Base64.cpp:51
std::string decode_base64(const std::string &input)
Decompresses string into Base64.
Definition Base64.cpp:105
constexpr bits fnv1a(const char *const str, const bits value=fnv_1a_params< bits >::offset) noexcept
Convert string to hash.
Definition FNV1a.hpp:64
float normalize(const Type val, const Type max) noexcept
Calc normalized value from range.
Definition Generic.hpp:32
std::string encode_zlib(const std::string &input)
Compresses string into ZLib.
Definition ZLib.cpp:234
std::string decode_zlib(const std::string &input)
Decompresses string into ZLib.
Definition ZLib.cpp:276
Timer.hpp galaxy.
Definition Async.hpp:17