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
LuaTime.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/time/Time.hpp"
13#include "galaxy/time/Timer.hpp"
14
15#include "../Lua.hpp"
16
17namespace galaxy
18{
19 void Lua::inject_time() noexcept
20 {
21 auto& lua = entt::locator<sol::state>::value();
22
23 lua.set_function("time_now", &time::now);
24 lua.set_function("time_since_epoch", &time::time_since_epoch);
25 lua.set_function("time_set_dt", sol::resolve<void(const double)>(&time::dt));
26 lua.set_function("time_get_dt", sol::resolve<double(void)>(&time::dt));
27
28 auto stopwatch_type = lua.new_usertype<Stopwatch>("Stopwatch", sol::constructors<Stopwatch()>());
29 // stopwatch_type["set"] = &Stopwatch::set;
30 stopwatch_type["repeat"] = &Stopwatch::repeat;
31 stopwatch_type["start"] = &Stopwatch::start;
32 stopwatch_type["stop"] = &Stopwatch::stop;
33 stopwatch_type["pause"] = &Stopwatch::pause;
34 stopwatch_type["unpause"] = &Stopwatch::unpause;
35 stopwatch_type["update"] = &Stopwatch::update;
36 stopwatch_type["stopped"] = &Stopwatch::stopped;
37 stopwatch_type["paused"] = &Stopwatch::paused;
38 stopwatch_type["get_time_passed"] = &Stopwatch::get_time_passed;
39
40 auto timer_type = lua.new_usertype<Timer>("Timer", sol::constructors<Timer()>());
41 // timer_type["set"] = &Timer::set;
42 timer_type["start"] = &Timer::start;
43 timer_type["stop"] = &Timer::stop;
44 timer_type["pause"] = &Timer::pause;
45 timer_type["stopped"] = &Timer::stopped;
46 timer_type["paused"] = &Timer::paused;
47 }
48} // namespace galaxy
static void inject_time() noexcept
Register galaxy time support functions into Lua.
Definition LuaTime.cpp:19
Synchronous stopwatch.
Definition Stopwatch.hpp:19
void stop()
Stop Stopwatch.
Definition Stopwatch.cpp:52
void pause()
Pause the Stopwatch.
Definition Stopwatch.cpp:61
void unpause()
Resume the Stopwatch.
Definition Stopwatch.cpp:72
void start()
Start Stopwatch.
Definition Stopwatch.cpp:43
void repeat(const bool repeat)
Make function repeat itself instead of running once.
Definition Stopwatch.cpp:38
bool paused() const
Is the Stopwatch paused?
void update()
Call this if you want to trigger the callback after delay has passed.
Definition Stopwatch.cpp:83
std::uint64_t get_time_passed() const noexcept
Time passed in milliseconds.
bool stopped() const
Is the Stopwatch finished?
Definition Stopwatch.cpp:99
Asynchronous timer class.
Definition Timer.hpp:19
void stop() noexcept
Stop timer.
Definition Timer.cpp:67
void pause(const bool pause) noexcept
Pause the timer.
Definition Timer.cpp:79
void start(const bool repeat=false)
Start timer.
Definition Timer.cpp:40
bool paused() const noexcept
Is the timer paused?
Definition Timer.cpp:89
bool stopped() const noexcept
Is the timer finished?
Definition Timer.cpp:84
void dt(const double dt) noexcept
Set galaxy delta time.
Definition Time.cpp:27
auto now() noexcept -> std::chrono::local_time< std::chrono::system_clock::duration >
Current local time.
Definition Time.cpp:16
std::uint64_t time_since_epoch() noexcept
Time since epoch.
Definition Time.cpp:21
Application.hpp galaxy.