VERSIÓ 1.3.10

- [NEW] sys.delta()
This commit is contained in:
2025-11-10 09:06:13 +01:00
parent c7559f0d29
commit 091c2617a4
3 changed files with 14 additions and 1 deletions

10
lua.cpp
View File

@@ -8,6 +8,8 @@ namespace fs = std::filesystem;
extern "C" { extern "C" {
uint32_t last_update = 0;
float delta_time = 0.0f;
// surface // surface
// =============================================== // ===============================================
@@ -637,6 +639,11 @@ extern "C" {
// sys // sys
// =============================================== // ===============================================
static int cpp_sys_delta(lua_State *L) {
lua_pushnumber(L, delta_time);
return 1;
}
static int cpp_sys_time(lua_State *L) { static int cpp_sys_time(lua_State *L) {
lua_pushnumber(L, time()); lua_pushnumber(L, time());
return 1; return 1;
@@ -945,6 +952,7 @@ void push_lua_funcs() {
lua_setglobal(L, "sound"); lua_setglobal(L, "sound");
lua_newtable(L); lua_newtable(L);
lua_pushcfunction(L,cpp_sys_delta); lua_setfield(L, -2, "delta");
lua_pushcfunction(L,cpp_sys_time); lua_setfield(L, -2, "time"); lua_pushcfunction(L,cpp_sys_time); lua_setfield(L, -2, "time");
lua_pushcfunction(L,cpp_sys_beat); lua_setfield(L, -2, "beat"); lua_pushcfunction(L,cpp_sys_beat); lua_setfield(L, -2, "beat");
lua_pushcfunction(L,cpp_sys_update); lua_setfield(L, -2, "update"); lua_pushcfunction(L,cpp_sys_update); lua_setfield(L, -2, "update");
@@ -1211,6 +1219,8 @@ void lua_call_init() {
void lua_call_update() { void lua_call_update() {
if (!update_exists) return; if (!update_exists) return;
delta_time = float(SDL_GetTicks() - last_update)/1000.0f;
last_update = SDL_GetTicks();
lua_getglobal(L, "mini"); lua_getglobal(L, "mini");
lua_getfield(L, -1, "update"); lua_getfield(L, -1, "update");
if (lua_pcall(L, 0, 0, 0)) { if (lua_pcall(L, 0, 0, 0)) {

View File

@@ -1,3 +1,3 @@
#pragma once #pragma once
#define MINI_VERSION "1.3.9" #define MINI_VERSION "1.3.10"

View File

@@ -372,6 +372,9 @@ function sound.enabled(value) end
---@class sys ---@class sys
sys = {} sys = {}
---Get delta time from last update in seconds (with decimals)
function sys.delta() end
---Get current system timer in seconds (with decimals) ---Get current system timer in seconds (with decimals)
function sys.time() end function sys.time() end