1
0
Fork 0
mirror of https://github.com/Reuh/ubiquitousse.git synced 2025-10-27 09:09:30 +00:00

second -> millisecond. More adapt unit and avoid precision loss when working on float numbers.

This commit is contained in:
Reuh 2016-04-28 19:52:05 +02:00
parent 39198a3bd3
commit 0b99502708
7 changed files with 23 additions and 15 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}