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
LuaPlatform.cpp
Go to the documentation of this file.
1
7
8#include <entt/locator/locator.hpp>
9#include <sol/sol.hpp>
10
15
16#include "../Lua.hpp"
17
18namespace galaxy
19{
20 void Lua::inject_platform() noexcept
21 {
22 auto& lua = entt::locator<sol::state>::value();
23
24 lua.set("GALAXY_DEBUG_BUILD", GALAXY_DEBUG_BUILD);
25
26#ifdef GALAXY_WIN_PLATFORM
27 lua.set("GALAXY_WIN_PLATFORM", true);
28 lua.set("GALAXY_UNIX_PLATFORM", false);
29#elif GALAXY_UNIX_PLATFORM
30 lua.set("GALAXY_WIN_PLATFORM", false);
31 lua.set("GALAXY_UNIX_PLATFORM", true);
32#endif
33
34 auto sub_type = lua.new_usertype<Subprocess>("Subprocess", sol::constructors<Subprocess(), Subprocess(std::string_view)>());
35 sub_type["create"] = &Subprocess::create;
36 sub_type["wait"] = &Subprocess::wait;
37 sub_type["kill"] = &Subprocess::kill;
38
39 lua.set_function("galaxy_seed_random", &platform::seed_random);
40 lua.set_function("galaxy_set_metadata", &platform::set_metadata);
41 lua.set_function("galaxy_set_hint", &platform::set_hint);
42 lua.set_function("galaxy_platform_as_string", &platform::as_string);
43
44 // clang-format off
45 lua.new_enum<SDL_PowerState>("SDL_PowerState",
46 {
47 {"SDL_POWERSTATE_ERROR", SDL_PowerState::SDL_POWERSTATE_ERROR},
48 {"SDL_POWERSTATE_UNKNOWN", SDL_PowerState::SDL_POWERSTATE_UNKNOWN},
49 {"SDL_POWERSTATE_ON_BATTERY", SDL_PowerState::SDL_POWERSTATE_ON_BATTERY},
50 {"SDL_POWERSTATE_NO_BATTERY", SDL_PowerState::SDL_POWERSTATE_NO_BATTERY},
51 {"SDL_POWERSTATE_CHARGING", SDL_PowerState::SDL_POWERSTATE_CHARGING},
52 {"SDL_POWERSTATE_CHARGED", SDL_PowerState::SDL_POWERSTATE_CHARGED}
53 });
54 // clang-format on
55
56 lua.set_function("galaxy_laptop_get_battery_remaining", &laptop::get_battery_remaining);
57 lua.set_function("galaxy_laptop_get_battery_status", &laptop::get_battery_status);
58
59 auto cpu_type = lua.new_usertype<CPUInfo>("CPUInfo", sol::constructors<CPUInfo()>());
60 cpu_type["cpu_cache_line_size"] = &CPUInfo::cpu_cache_line_size;
61 cpu_type["has_altivec"] = &CPUInfo::has_altivec;
62 cpu_type["has_arm_simd"] = &CPUInfo::has_arm_simd;
63 cpu_type["has_avx"] = &CPUInfo::has_avx;
64 cpu_type["has_avx2"] = &CPUInfo::has_avx2;
65 cpu_type["has_avx512f"] = &CPUInfo::has_avx512f;
66 cpu_type["has_lasx"] = &CPUInfo::has_lasx;
67 cpu_type["has_lsx"] = &CPUInfo::has_lsx;
68 cpu_type["has_mmx"] = &CPUInfo::has_mmx;
69 cpu_type["has_neon"] = &CPUInfo::has_neon;
70 cpu_type["has_sse"] = &CPUInfo::has_sse;
71 cpu_type["has_sse2"] = &CPUInfo::has_sse2;
72 cpu_type["has_sse3"] = &CPUInfo::has_sse3;
73 cpu_type["has_sse41"] = &CPUInfo::has_sse41;
74 cpu_type["has_sse42"] = &CPUInfo::has_sse42;
75 cpu_type["has_sve2"] = &CPUInfo::has_sve2;
76 cpu_type["logical_core_count"] = &CPUInfo::logical_core_count;
77 cpu_type["simd_alignment"] = &CPUInfo::simd_alignment;
78 cpu_type["system_page_size"] = &CPUInfo::system_page_size;
79 cpu_type["system_ram"] = &CPUInfo::system_ram;
80
81 lua.set_function("galaxy_get_cpu_info", &platform::get_cpu_info);
82 }
83} // namespace galaxy
static void inject_platform() noexcept
Inject platform stuff into Lua.
Manages a subprocess launched by galaxy.
void kill() noexcept
Terminates process.
void create(std::string_view process, std::span< std::string > args={})
Launch a subprocess.
bool wait(const bool block) noexcept
Wait for a process to finish execution.
SDL_PowerState get_battery_status() noexcept
Get battery status.
Definition Laptop.cpp:25
int get_battery_remaining(const bool percent) noexcept
Get remaining battery charge of a laptop.
Definition Laptop.cpp:16
void seed_random() noexcept
Seed the cstdlib rng algos.
Definition Platform.cpp:20
CPUInfo get_cpu_info() noexcept
Generates CPU info data.
Definition CPUInfo.cpp:14
void set_metadata(const char *type, const char *value) noexcept
Sets metadata.
Definition Platform.cpp:25
std::string as_string() noexcept
Gets the current platform name as a string.
Definition Platform.cpp:35
void set_hint(const char *hint, const char *value) noexcept
Sets SDL hints.
Definition Platform.cpp:30
Application.hpp galaxy.
Data structure containing info about the cpu, such as RAM, cache, SIMD, etc.
Definition CPUInfo.hpp:19
bool has_mmx
Determine whether the CPU has MMX features.
Definition CPUInfo.hpp:45
bool has_sse
Determine whether the CPU has SSE features.
Definition CPUInfo.hpp:49
bool has_avx
Determine whether the CPU has AVX features.
Definition CPUInfo.hpp:35
bool has_sse2
Determine whether the CPU has SSE2 features.
Definition CPUInfo.hpp:51
int system_ram
Returns the amount of RAM configured in the system in MiB.
Definition CPUInfo.hpp:29
std::size_t simd_alignment
This will return the minimum number of bytes to which a pointer must be aligned to be compatible with...
Definition CPUInfo.hpp:27
bool has_avx512f
Determine whether the CPU has AVX-512F (foundation) features.
Definition CPUInfo.hpp:39
bool has_sse41
Determine whether the CPU has SSE41 features.
Definition CPUInfo.hpp:55
bool has_sse3
Determine whether the CPU has SSE3 features.
Definition CPUInfo.hpp:53
bool has_avx2
Determine whether the CPU has AVX2 features.
Definition CPUInfo.hpp:37
int logical_core_count
Get the number of logical CPU cores available.
Definition CPUInfo.hpp:23
bool has_arm_simd
Determine whether the CPU has ARM SIMD (ARMv6) features.
Definition CPUInfo.hpp:33
int system_page_size
Report the size of a page of memory.
Definition CPUInfo.hpp:25
bool has_altivec
Returns true if the CPU has AltiVec features or false if not.
Definition CPUInfo.hpp:31
bool has_neon
Determine whether the CPU has NEON (ARM SIMD) features.
Definition CPUInfo.hpp:47
bool has_sse42
Determine whether the CPU has SSE42 features.
Definition CPUInfo.hpp:57
bool has_lasx
Determine whether the CPU has LASX (LOONGARCH SIMD) features.
Definition CPUInfo.hpp:41
int cpu_cache_line_size
Determine the L1 cache line size of the CPU.
Definition CPUInfo.hpp:21
bool has_lsx
Determine whether the CPU has LSX (LOONGARCH SIMD) features.
Definition CPUInfo.hpp:43
bool has_sve2
Determine whether the CPU has SVE2 (Scalable Vector Extension 2).
Definition CPUInfo.hpp:59