From 091c2617a4f826cbd1f6ddeba904caa4e771e819 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Mon, 10 Nov 2025 09:06:13 +0100 Subject: [PATCH] =?UTF-8?q?VERSI=C3=93=201.3.10=20-=20[NEW]=20sys.delta()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua.cpp | 10 ++++++++++ version.h | 2 +- vscode/library.lua | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lua.cpp b/lua.cpp index d255cba..63f31a3 100644 --- a/lua.cpp +++ b/lua.cpp @@ -8,6 +8,8 @@ namespace fs = std::filesystem; extern "C" { + uint32_t last_update = 0; + float delta_time = 0.0f; // surface // =============================================== @@ -637,6 +639,11 @@ extern "C" { // sys // =============================================== + static int cpp_sys_delta(lua_State *L) { + lua_pushnumber(L, delta_time); + return 1; + } + static int cpp_sys_time(lua_State *L) { lua_pushnumber(L, time()); return 1; @@ -945,6 +952,7 @@ void push_lua_funcs() { lua_setglobal(L, "sound"); 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_beat); lua_setfield(L, -2, "beat"); lua_pushcfunction(L,cpp_sys_update); lua_setfield(L, -2, "update"); @@ -1211,6 +1219,8 @@ void lua_call_init() { void lua_call_update() { if (!update_exists) return; + delta_time = float(SDL_GetTicks() - last_update)/1000.0f; + last_update = SDL_GetTicks(); lua_getglobal(L, "mini"); lua_getfield(L, -1, "update"); if (lua_pcall(L, 0, 0, 0)) { diff --git a/version.h b/version.h index a649917..138716e 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.3.9" +#define MINI_VERSION "1.3.10" diff --git a/vscode/library.lua b/vscode/library.lua index a6a7fd3..6f0216c 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -372,6 +372,9 @@ function sound.enabled(value) end ---@class sys sys = {} +---Get delta time from last update in seconds (with decimals) +function sys.delta() end + ---Get current system timer in seconds (with decimals) function sys.time() end