mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 17:19:31 +00:00
second -> millisecond. More adapt unit and avoid precision loss when working on float numbers.
This commit is contained in:
parent
39198a3bd3
commit
0b99502708
7 changed files with 23 additions and 15 deletions
|
|
@ -54,7 +54,7 @@ abstract.backend = "ctrulua"
|
|||
if abstract.time then
|
||||
add(abstract.time, {
|
||||
get = function()
|
||||
return ctr.time() / 1000
|
||||
return ctr.time()
|
||||
end
|
||||
})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ function love.update(dt)
|
|||
abstract.draw.fps = love.timer.getFPS()
|
||||
|
||||
-- Stuff defined in abstract.lua
|
||||
updateDefault(dt)
|
||||
updateDefault(dt*1000)
|
||||
|
||||
-- Callback
|
||||
abstract.event.update(dt)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ local scene = require((...):match("^(.-abstract)%.")..".scene")
|
|||
-- end
|
||||
return {
|
||||
--- Called each time the game loop is ran. Don't draw here.
|
||||
-- @tparam number dt time since last call, in seconds
|
||||
-- @tparam number dt time since last call, in miliseconds
|
||||
-- @impl mixed
|
||||
update = function(dt)
|
||||
input.update(dt)
|
||||
|
|
|
|||
4
init.lua
4
init.lua
|
|
@ -30,6 +30,10 @@
|
|||
-- Theses formats are respected for the reference implementations, but Abstract may provide a script to
|
||||
-- automatically convert data formats from a project at some point.
|
||||
--
|
||||
-- Units used in the API:
|
||||
-- * All distances are expressed in pixels (px)
|
||||
-- * All durations are expressed in milliseconds (ms)
|
||||
--
|
||||
-- Style:
|
||||
-- * tabs for indentation, spaces for esthetic whitespace (notably in comments)
|
||||
-- * no globals
|
||||
|
|
|
|||
|
|
@ -239,7 +239,7 @@ input = {
|
|||
local x, y = 0, 0 -- pointer position
|
||||
local width, height = 1, 1 -- half-dimensions of the movement area
|
||||
local offsetX, offsetY = 0, 0 -- offsets
|
||||
local xSpeed, ySpeed = 1, 1 -- speed (pixels/second); for relative mode
|
||||
local xSpeed, ySpeed = 1, 1 -- speed (pixels/milisecond); for relative mode
|
||||
local r -- object
|
||||
local function update()
|
||||
if not updated[r] then
|
||||
|
|
@ -325,7 +325,7 @@ input = {
|
|||
offsetX, offsetY = newOffX, newOffY
|
||||
return self
|
||||
end,
|
||||
--- Set maximal speed (pixels-per-second)
|
||||
--- Set maximal speed (pixels-per-milisecond)
|
||||
-- Only used in relative mode.
|
||||
-- Calls without argument to use the raw data and don't apply a speed modifier.
|
||||
-- @impl abstract
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ scene = {
|
|||
|
||||
--- Update the current scene.
|
||||
-- Should be called in abstract.event.update.
|
||||
-- @tparam number dt the delta-time
|
||||
-- @tparam number dt the delta-time (milisecond)
|
||||
-- @impl abstract
|
||||
update = function(dt)
|
||||
if scene.current then
|
||||
|
|
|
|||
22
time.lua
22
time.lua
|
|
@ -17,22 +17,22 @@ local function newTimerRegistry()
|
|||
-- A TimerRegistry is a separate abstract.time instance: its TimedFunctions will be independant
|
||||
-- from the one registered using abstract.time.run (the global TimerRegistry). If you use the scene
|
||||
-- system, a scene-specific TimerRegistry is available at abstract.scene.current.time.
|
||||
-- @impl abstract
|
||||
new = function()
|
||||
local new = newTimerRegistry()
|
||||
new.get = registry.get
|
||||
return new
|
||||
end,
|
||||
|
||||
--- Returns the number of seconds elapsed since some point in time.
|
||||
--- Returns the number of miliseconds elapsed since some point in time.
|
||||
-- This point is fixed but undetermined, so this function should only be used to calculate durations.
|
||||
-- Should at least have millisecond-precision. Should be called using abstract.time.get and not in
|
||||
-- non-global TimerRegistry.
|
||||
-- Should at least have millisecond-precision, but can be more precise if available.
|
||||
-- @impl backend
|
||||
get = function() end,
|
||||
|
||||
--- Update all the TimedFunctions calls.
|
||||
-- Supposed to be called in abstract.event.update.
|
||||
-- @tparam[opt=calculate here] numder dt the delta-time (time spent since last time the function was called) (seconds)
|
||||
-- @tparam[opt=calculate here] numder dt the delta-time (time spent since last time the function was called) (miliseconds)
|
||||
-- @impl abstract
|
||||
update = function(dt)
|
||||
if dt then
|
||||
|
|
@ -83,9 +83,7 @@ local function newTimerRegistry()
|
|||
end,
|
||||
|
||||
--- Schedule a function to run.
|
||||
-- The function will receive as first parameter the wait(time) function, which will pause the function execution for time seconds.
|
||||
-- The second parameter is the delta-time.
|
||||
-- @tparam[opt=0] number delay delay in seconds before first run
|
||||
-- The function will receive as first parameter the wait(time) function, which will pause the function execution for time miliseconds.
|
||||
-- @tparam[opt] function func the function to schedule
|
||||
-- @treturn TimedFunction the object
|
||||
-- @impl abstract
|
||||
|
|
@ -111,27 +109,33 @@ local function newTimerRegistry()
|
|||
local t = delayed[func] -- internal data
|
||||
local r -- external interface
|
||||
r = {
|
||||
--- Wait time milliseconds before running the function.
|
||||
after = function(_, time)
|
||||
t.after = time
|
||||
return r
|
||||
end,
|
||||
--- Run the function every time millisecond.
|
||||
every = function(_, time)
|
||||
t.every = time
|
||||
return r
|
||||
end,
|
||||
--- The function will not execute more than count times.
|
||||
times = function(_, count)
|
||||
t.times = count
|
||||
return r
|
||||
end,
|
||||
--- The TimedFunction will be active for a time duration.
|
||||
during = function(_, time)
|
||||
t.during = time
|
||||
return r
|
||||
end,
|
||||
|
||||
--- Will execute func() when the function execution start.
|
||||
onStart = function(_, func)
|
||||
t.onStart = func
|
||||
return r
|
||||
end,
|
||||
--- Will execute func() when the function execution end.
|
||||
onEnd = function(_, func)
|
||||
t.onEnd = func
|
||||
return r
|
||||
|
|
@ -141,7 +145,7 @@ local function newTimerRegistry()
|
|||
end,
|
||||
|
||||
--- Tween some numeric values.
|
||||
-- @tparam number duration tween duration (seconds)
|
||||
-- @tparam number duration tween duration (miliseconds)
|
||||
-- @tparam table tbl the table containing the values to tween
|
||||
-- @tparam table to the new values
|
||||
-- @tparam[opt="linear"] string/function method tweening method (string name or the actual function(time, start, change, duration))
|
||||
|
|
@ -169,7 +173,7 @@ local function newTimerRegistry()
|
|||
delayed = {}
|
||||
end,
|
||||
|
||||
--- Time since last update (seconds).
|
||||
--- Time since last update (miliseconds).
|
||||
-- @impl abstract
|
||||
dt = 0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue