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_set_dt", sol::resolve<void(const double)>(&time::dt));
25 lua.set_function("time_get_dt", sol::resolve<double(void)>(&time::dt));
26
27 auto stopwatch_type = lua.new_usertype<Stopwatch>("Stopwatch", sol::constructors<Stopwatch()>());
28 // stopwatch_type["set"] = &Stopwatch::set;
29 stopwatch_type["repeat"] = &Stopwatch::repeat;
30 stopwatch_type["start"] = &Stopwatch::start;
31 stopwatch_type["stop"] = &Stopwatch::stop;
32 stopwatch_type["pause"] = &Stopwatch::pause;
33 stopwatch_type["unpause"] = &Stopwatch::unpause;
34 stopwatch_type["update"] = &Stopwatch::update;
35 stopwatch_type["stopped"] = &Stopwatch::stopped;
36 stopwatch_type["paused"] = &Stopwatch::paused;
37 stopwatch_type["get_time_passed"] = &Stopwatch::get_time_passed;
38
39 auto timer_type = lua.new_usertype<Timer>("Timer", sol::constructors<Timer()>());
40 // timer_type["set"] = &Timer::set;
41 timer_type["start"] = &Timer::start;
42 timer_type["stop"] = &Timer::stop;
43 timer_type["pause"] = &Timer::pause;
44 timer_type["stopped"] = &Timer::stopped;
45 timer_type["paused"] = &Timer::paused;
46 }
47} // 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:50
void pause()
Pause the Stopwatch.
Definition Stopwatch.cpp:59
void unpause()
Resume the Stopwatch.
Definition Stopwatch.cpp:70
void start()
Start Stopwatch.
Definition Stopwatch.cpp:41
void repeat(const bool repeat)
Make function repeat itself instead of running once.
Definition Stopwatch.cpp:36
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:81
std::uint64_t get_time_passed() const noexcept
Time passed in milliseconds.
bool stopped() const
Is the Stopwatch finished?
Definition Stopwatch.cpp:97
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
double dt() noexcept
Get galaxy delta time.
Definition Time.cpp:26
auto now() noexcept -> std::chrono::local_time< std::chrono::system_clock::duration >
Current local time.
Definition Time.cpp:16
Animated.cpp galaxy.
Definition Animated.cpp:16