mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-28 01:29: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
|
if abstract.time then
|
||||||
add(abstract.time, {
|
add(abstract.time, {
|
||||||
get = function()
|
get = function()
|
||||||
return ctr.time() / 1000
|
return ctr.time()
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ function love.update(dt)
|
||||||
abstract.draw.fps = love.timer.getFPS()
|
abstract.draw.fps = love.timer.getFPS()
|
||||||
|
|
||||||
-- Stuff defined in abstract.lua
|
-- Stuff defined in abstract.lua
|
||||||
updateDefault(dt)
|
updateDefault(dt*1000)
|
||||||
|
|
||||||
-- Callback
|
-- Callback
|
||||||
abstract.event.update(dt)
|
abstract.event.update(dt)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ local scene = require((...):match("^(.-abstract)%.")..".scene")
|
||||||
-- end
|
-- end
|
||||||
return {
|
return {
|
||||||
--- Called each time the game loop is ran. Don't draw here.
|
--- 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
|
-- @impl mixed
|
||||||
update = function(dt)
|
update = function(dt)
|
||||||
input.update(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
|
-- 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.
|
-- 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:
|
-- Style:
|
||||||
-- * tabs for indentation, spaces for esthetic whitespace (notably in comments)
|
-- * tabs for indentation, spaces for esthetic whitespace (notably in comments)
|
||||||
-- * no globals
|
-- * no globals
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,7 @@ input = {
|
||||||
local x, y = 0, 0 -- pointer position
|
local x, y = 0, 0 -- pointer position
|
||||||
local width, height = 1, 1 -- half-dimensions of the movement area
|
local width, height = 1, 1 -- half-dimensions of the movement area
|
||||||
local offsetX, offsetY = 0, 0 -- offsets
|
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 r -- object
|
||||||
local function update()
|
local function update()
|
||||||
if not updated[r] then
|
if not updated[r] then
|
||||||
|
|
@ -325,7 +325,7 @@ input = {
|
||||||
offsetX, offsetY = newOffX, newOffY
|
offsetX, offsetY = newOffX, newOffY
|
||||||
return self
|
return self
|
||||||
end,
|
end,
|
||||||
--- Set maximal speed (pixels-per-second)
|
--- Set maximal speed (pixels-per-milisecond)
|
||||||
-- Only used in relative mode.
|
-- Only used in relative mode.
|
||||||
-- Calls without argument to use the raw data and don't apply a speed modifier.
|
-- Calls without argument to use the raw data and don't apply a speed modifier.
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ scene = {
|
||||||
|
|
||||||
--- Update the current scene.
|
--- Update the current scene.
|
||||||
-- Should be called in abstract.event.update.
|
-- Should be called in abstract.event.update.
|
||||||
-- @tparam number dt the delta-time
|
-- @tparam number dt the delta-time (milisecond)
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
update = function(dt)
|
update = function(dt)
|
||||||
if scene.current then
|
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
|
-- 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
|
-- 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.
|
-- system, a scene-specific TimerRegistry is available at abstract.scene.current.time.
|
||||||
|
-- @impl abstract
|
||||||
new = function()
|
new = function()
|
||||||
local new = newTimerRegistry()
|
local new = newTimerRegistry()
|
||||||
new.get = registry.get
|
new.get = registry.get
|
||||||
return new
|
return new
|
||||||
end,
|
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.
|
-- 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
|
-- Should at least have millisecond-precision, but can be more precise if available.
|
||||||
-- non-global TimerRegistry.
|
|
||||||
-- @impl backend
|
-- @impl backend
|
||||||
get = function() end,
|
get = function() end,
|
||||||
|
|
||||||
--- Update all the TimedFunctions calls.
|
--- Update all the TimedFunctions calls.
|
||||||
-- Supposed to be called in abstract.event.update.
|
-- 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
|
-- @impl abstract
|
||||||
update = function(dt)
|
update = function(dt)
|
||||||
if dt then
|
if dt then
|
||||||
|
|
@ -83,9 +83,7 @@ local function newTimerRegistry()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Schedule a function to run.
|
--- 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 function will receive as first parameter the wait(time) function, which will pause the function execution for time miliseconds.
|
||||||
-- The second parameter is the delta-time.
|
|
||||||
-- @tparam[opt=0] number delay delay in seconds before first run
|
|
||||||
-- @tparam[opt] function func the function to schedule
|
-- @tparam[opt] function func the function to schedule
|
||||||
-- @treturn TimedFunction the object
|
-- @treturn TimedFunction the object
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
|
|
@ -111,27 +109,33 @@ local function newTimerRegistry()
|
||||||
local t = delayed[func] -- internal data
|
local t = delayed[func] -- internal data
|
||||||
local r -- external interface
|
local r -- external interface
|
||||||
r = {
|
r = {
|
||||||
|
--- Wait time milliseconds before running the function.
|
||||||
after = function(_, time)
|
after = function(_, time)
|
||||||
t.after = time
|
t.after = time
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
--- Run the function every time millisecond.
|
||||||
every = function(_, time)
|
every = function(_, time)
|
||||||
t.every = time
|
t.every = time
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
--- The function will not execute more than count times.
|
||||||
times = function(_, count)
|
times = function(_, count)
|
||||||
t.times = count
|
t.times = count
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
--- The TimedFunction will be active for a time duration.
|
||||||
during = function(_, time)
|
during = function(_, time)
|
||||||
t.during = time
|
t.during = time
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
--- Will execute func() when the function execution start.
|
||||||
onStart = function(_, func)
|
onStart = function(_, func)
|
||||||
t.onStart = func
|
t.onStart = func
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
--- Will execute func() when the function execution end.
|
||||||
onEnd = function(_, func)
|
onEnd = function(_, func)
|
||||||
t.onEnd = func
|
t.onEnd = func
|
||||||
return r
|
return r
|
||||||
|
|
@ -141,7 +145,7 @@ local function newTimerRegistry()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Tween some numeric values.
|
--- 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 tbl the table containing the values to tween
|
||||||
-- @tparam table to the new values
|
-- @tparam table to the new values
|
||||||
-- @tparam[opt="linear"] string/function method tweening method (string name or the actual function(time, start, change, duration))
|
-- @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 = {}
|
delayed = {}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
--- Time since last update (seconds).
|
--- Time since last update (miliseconds).
|
||||||
-- @impl abstract
|
-- @impl abstract
|
||||||
dt = 0
|
dt = 0
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue