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

Rename time to timer

This commit is contained in:
Étienne Fildadut 2019-12-25 16:15:40 +01:00
parent b5324faace
commit 82bc7268e6
9 changed files with 37 additions and 37 deletions

View file

@ -70,7 +70,7 @@ ubiquitousse = {
-- @tparam number dt time since last call, in miliseconds -- @tparam number dt time since last call, in miliseconds
-- @impl mixed -- @impl mixed
update = function(dt) update = function(dt)
if ubiquitousse.time then ubiquitousse.time.update(dt) end if ubiquitousse.timer then ubiquitousse.timer.update(dt) end
if ubiquitousse.scene then ubiquitousse.scene.update(dt) end if ubiquitousse.scene then ubiquitousse.scene.update(dt) end
if ubiquitousse.input then ubiquitousse.input.update(dt) end if ubiquitousse.input then ubiquitousse.input.update(dt) end
end, end,
@ -87,7 +87,7 @@ ubiquitousse = {
package.loaded[p] = ubiquitousse package.loaded[p] = ubiquitousse
-- Require external submodules -- Require external submodules
for _, m in ipairs{"asset", "ecs", "input", "scene", "time", "util"} do for _, m in ipairs{"asset", "ecs", "input", "scene", "timer", "util"} do
local s, t = pcall(require, p.."."..m) local s, t = pcall(require, p.."."..m)
if s then if s then
ubiquitousse[m] = t ubiquitousse[m] = t

View file

@ -1,7 +1,7 @@
--- ubiquitousse.scene --- ubiquitousse.scene
-- Optional dependencies: ubiquitousse.time (to provide each scene a time registry) -- Optional dependencies: ubiquitousse.timer (to provide each scene a timer registry)
local loaded, time = pcall(require, (...):match("^(.-)scene").."time") local loaded, timer = pcall(require, (...):match("^(.-)scene").."timer")
if not loaded then time = nil end if not loaded then timer = nil end
--- Scene management. --- Scene management.
-- You can use use scenes to seperate the different states of your game: for example, a menu scene and a game scene. -- You can use use scenes to seperate the different states of your game: for example, a menu scene and a game scene.
@ -28,9 +28,9 @@ scene = setmetatable({
-- @impl ubiquitousse -- @impl ubiquitousse
current = nil, current = nil,
--- Shortcut for scene.current.time. --- Shortcut for scene.current.timer.
-- @impl ubiquitousse -- @impl ubiquitousse
time = nil, timer = nil,
--- The scene stack: list of scene, from the farest one to the nearest. --- The scene stack: list of scene, from the farest one to the nearest.
-- @impl ubiquitousse -- @impl ubiquitousse
@ -73,7 +73,7 @@ scene = setmetatable({
return { return {
name = name or "unamed", -- The scene name. name = name or "unamed", -- The scene name.
time = time and time.new(), -- Scene-specific TimerRegistry, if uqt.time is available. timer = timer and timer.new(), -- Scene-specific TimerRegistry, if uqt.time is available.
enter = function(self, ...) end, -- Called when entering a scene. enter = function(self, ...) end, -- Called when entering a scene.
exit = function(self) end, -- Called when exiting a scene, and not expecting to come back (scene may be unloaded). exit = function(self) end, -- Called when exiting a scene, and not expecting to come back (scene may be unloaded).
@ -97,7 +97,7 @@ scene = setmetatable({
switch = function(scenePath, ...) switch = function(scenePath, ...)
local previous = scene.current local previous = scene.current
scene.current = type(scenePath) == "string" and scene.load(scene.prefix..scenePath) or scenePath scene.current = type(scenePath) == "string" and scene.load(scene.prefix..scenePath) or scenePath
scene.time = scene.current.time scene.timer = scene.current.timer
scene.current.name = scene.current.name or tostring(scenePath) scene.current.name = scene.current.name or tostring(scenePath)
if previous then previous:exit() end if previous then previous:exit() end
scene.current:enter(...) scene.current:enter(...)
@ -114,7 +114,7 @@ scene = setmetatable({
push = function(scenePath, ...) push = function(scenePath, ...)
local previous = scene.current local previous = scene.current
scene.current = type(scenePath) == "string" and scene.load(scene.prefix..scenePath) or scenePath scene.current = type(scenePath) == "string" and scene.load(scene.prefix..scenePath) or scenePath
scene.time = scene.current.time scene.timer = scene.current.timer
scene.current.name = scene.current.name or tostring(scenePath) scene.current.name = scene.current.name or tostring(scenePath)
if previous then previous:suspend() end if previous then previous:suspend() end
scene.current:enter(...) scene.current:enter(...)
@ -128,7 +128,7 @@ scene = setmetatable({
pop = function() pop = function()
local previous = scene.current local previous = scene.current
scene.current = scene.stack[#scene.stack-1] scene.current = scene.stack[#scene.stack-1]
scene.time = scene.current.time scene.timer = scene.current.timer
if previous then previous:exit() end if previous then previous:exit() end
if scene.current then scene.current:resume() end if scene.current then scene.current:resume() end
table.remove(scene.stack) table.remove(scene.stack)
@ -141,7 +141,7 @@ scene = setmetatable({
-- @impl ubiquitousse -- @impl ubiquitousse
update = function(dt, ...) update = function(dt, ...)
if scene.current then if scene.current then
if time then scene.current.time:update(dt) end if timer then scene.current.timer:update(dt) end
scene.current:update(dt, ...) scene.current:update(dt, ...)
end end
end, end,

View file

@ -1,6 +0,0 @@
local time = require((...):match("^(.-%.)backend").."time")
local ctr = require("ctr")
time.get = ctr.time
return time

View file

@ -1,7 +0,0 @@
local time = require((...):match("^(.-%.)backend").."time")
time.get = function()
return love.timer.getTime() * 1000
end
return time

View file

@ -0,0 +1,6 @@
local timer = require((...):match("^(.-%.)backend").."timer")
local ctr = require("ctr")
timer.get = ctr.time
return timer

7
timer/backend/love.lua Normal file
View file

@ -0,0 +1,7 @@
local timer = require((...):match("^(.-%.)backend").."timer")
timer.get = function()
return love.timer.getTime() * 1000
end
return timer

View file

@ -8,7 +8,7 @@ elseif package.loaded["ctr"] then
elseif package.loaded["libretro"] then elseif package.loaded["libretro"] then
error("NYI") error("NYI")
else else
error("no backend for ubiquitousse.time") error("no backend for ubiquitousse.timer")
end end
return time return time

View file

@ -1,7 +1,7 @@
--- ubiquitousse.time --- ubiquitousse.timer
-- Depends on a backend. -- Depends on a backend.
local ease = require((...):match("^.-time")..".easing") local ease = require((...):match("^.-timer")..".easing")
local time local timer
--- Returns true if all the values in the list are true ; functions in the list will be called and the test will be performed on their return value. --- Returns true if all the values in the list are true ; functions in the list will be called and the test will be performed on their return value.
-- Returns default if the list is empty. -- Returns default if the list is empty.
@ -28,7 +28,7 @@ local registry_mt = {
-- @tparam[opt=calculate here] number dt the delta-time (time spent since last time the function was called) (miliseconds) -- @tparam[opt=calculate here] number dt the delta-time (time spent since last time the function was called) (miliseconds)
-- @impl ubiquitousse -- @impl ubiquitousse
update = function(self, dt) update = function(self, dt)
local currentTime = time.get() local currentTime = timer.get()
if not dt then if not dt then
dt = currentTime - self.lastTime dt = currentTime - self.lastTime
@ -297,7 +297,7 @@ local registry_mt = {
registry_mt.__index = registry_mt registry_mt.__index = registry_mt
--- Time related functions --- Time related functions
time = { timer = {
--- Creates and return a new TimerRegistry. --- Creates and return a new TimerRegistry.
-- A TimerRegistry is a separate ubiquitousse.time instance: its TimedFunctions will be independant -- A TimerRegistry is a separate ubiquitousse.time instance: its TimedFunctions will be independant
-- from the one registered using ubiquitousse.time.run (the global TimerRegistry). If you use the scene -- from the one registered using ubiquitousse.time.run (the global TimerRegistry). If you use the scene
@ -311,7 +311,7 @@ time = {
delayed = {}, delayed = {},
-- Used to calculate the deltatime -- Used to calculate the deltatime
lastTime = time.get(), lastTime = timer.get(),
--- Time since last timer update (miliseconds). --- Time since last timer update (miliseconds).
dt = 0 dt = 0
@ -333,17 +333,17 @@ time = {
delayed = {}, delayed = {},
lastTime = 0, lastTime = 0,
update = function(...) update = function(...)
return registry_mt.update(time, ...) return registry_mt.update(timer, ...)
end, end,
run = function(...) run = function(...)
return registry_mt.run(time, ...) return registry_mt.run(timer, ...)
end, end,
tween = function(...) tween = function(...)
return registry_mt.tween(time, ...) return registry_mt.tween(timer, ...)
end, end,
clear = function(...) clear = function(...)
return registry_mt.clear(time, ...) return registry_mt.clear(timer, ...)
end end
} }
return time return timer