mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
Merge pull request #839 from MihailRis/precise-time-in-lua
Precise time in lua
This commit is contained in:
commit
a06d5433a2
3 changed files with 31 additions and 11 deletions
|
|
@ -1,13 +1,21 @@
|
|||
# *time* library
|
||||
# *time* Library
|
||||
|
||||
```python
|
||||
time.uptime() -> float
|
||||
```lua
|
||||
-- Returns the time since engine startup in seconds and milliseconds.
|
||||
time.uptime() -> number
|
||||
|
||||
-- Returns the time delta in seconds and milliseconds (time elapsed since the previous frame)
|
||||
time.delta() -> number
|
||||
|
||||
-- Returns UTC time in seconds
|
||||
time.utc_time() -> int
|
||||
|
||||
-- Returns local (system) time in seconds
|
||||
time.local_time() -> int
|
||||
|
||||
-- Returns the local time offset from UTC in seconds
|
||||
time.utc_offset() -> int
|
||||
|
||||
-- Returns high-precision time in seconds (elapsed since the engine startup).
|
||||
time.precise_time() -> number
|
||||
```
|
||||
|
||||
Returns time elapsed since the engine started.
|
||||
|
||||
```python
|
||||
time.delta() -> float
|
||||
```
|
||||
|
||||
Returns time elapsed since the last frame.
|
||||
|
|
|
|||
|
|
@ -15,4 +15,7 @@ time.local_time() -> int
|
|||
|
||||
-- Возвращает смещение локального времени от UTC в секундах
|
||||
time.utc_offset() -> int
|
||||
|
||||
-- Возвращает время высокой точности в секундах. За точку отсчёта берётся запуск движка.
|
||||
time.precise_time() -> number
|
||||
```
|
||||
|
|
|
|||
|
|
@ -62,11 +62,20 @@ static int l_utc_offset(lua::State* L) {
|
|||
return lua::pushnumber(L, offset);
|
||||
}
|
||||
|
||||
static auto start_time = std::chrono::steady_clock::now();
|
||||
|
||||
static int l_precise_time(lua::State* L) {
|
||||
auto time = std::chrono::steady_clock::now();
|
||||
std::chrono::duration<double> delta = time - start_time;
|
||||
return lua::pushnumber(L, delta.count());
|
||||
}
|
||||
|
||||
const luaL_Reg timelib[] = {
|
||||
{"uptime", lua::wrap<l_uptime>},
|
||||
{"delta", lua::wrap<l_delta>},
|
||||
{"utc_time", lua::wrap<l_utc_time>},
|
||||
{"utc_offset", lua::wrap<l_utc_offset>},
|
||||
{"local_time", lua::wrap<l_local_time>},
|
||||
{"precise_time", lua::wrap<l_precise_time>},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue