From 0b9950270893bcd98e7bedd4d9d12c75952dd9bd Mon Sep 17 00:00:00 2001 From: Reuh Date: Thu, 28 Apr 2016 19:52:05 +0200 Subject: [PATCH] second -> millisecond. More adapt unit and avoid precision loss when working on float numbers. --- backend/ctrulua.lua | 2 +- backend/love.lua | 2 +- event.lua | 2 +- init.lua | 4 ++++ input.lua | 4 ++-- scene.lua | 2 +- time.lua | 22 +++++++++++++--------- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/backend/ctrulua.lua b/backend/ctrulua.lua index 581a3c4..afe9cfe 100644 --- a/backend/ctrulua.lua +++ b/backend/ctrulua.lua @@ -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 diff --git a/backend/love.lua b/backend/love.lua index 1cd8e69..a337a73 100644 --- a/backend/love.lua +++ b/backend/love.lua @@ -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) diff --git a/event.lua b/event.lua index 5dbd497..779752a 100644 --- a/event.lua +++ b/event.lua @@ -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) diff --git a/init.lua b/init.lua index ccac91b..5a9ef3c 100644 --- a/init.lua +++ b/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 diff --git a/input.lua b/input.lua index c2254a5..b75e3c4 100644 --- a/input.lua +++ b/input.lua @@ -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 diff --git a/scene.lua b/scene.lua index 89b5aef..e3b8cb1 100644 --- a/scene.lua +++ b/scene.lua @@ -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 diff --git a/time.lua b/time.lua index 970b5e9..525a324 100644 --- a/time.lua +++ b/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 }