From 82bc7268e6d2cfc9826195031b1f109eead16d01 Mon Sep 17 00:00:00 2001 From: Reuh Date: Wed, 25 Dec 2019 16:15:40 +0100 Subject: [PATCH] Rename time to timer --- init.lua | 4 ++-- scene/scene.lua | 20 ++++++++++---------- time/backend/ctrulua.lua | 6 ------ time/backend/love.lua | 7 ------- timer/backend/ctrulua.lua | 6 ++++++ timer/backend/love.lua | 7 +++++++ {time => timer}/easing.lua | 0 {time => timer}/init.lua | 2 +- time/time.lua => timer/timer.lua | 22 +++++++++++----------- 9 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 time/backend/ctrulua.lua delete mode 100644 time/backend/love.lua create mode 100644 timer/backend/ctrulua.lua create mode 100644 timer/backend/love.lua rename {time => timer}/easing.lua (100%) rename {time => timer}/init.lua (83%) rename time/time.lua => timer/timer.lua (96%) diff --git a/init.lua b/init.lua index 46e354d..8f48c2b 100644 --- a/init.lua +++ b/init.lua @@ -70,7 +70,7 @@ ubiquitousse = { -- @tparam number dt time since last call, in miliseconds -- @impl mixed 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.input then ubiquitousse.input.update(dt) end end, @@ -87,7 +87,7 @@ ubiquitousse = { package.loaded[p] = ubiquitousse -- 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) if s then ubiquitousse[m] = t diff --git a/scene/scene.lua b/scene/scene.lua index b1aa458..5db7095 100644 --- a/scene/scene.lua +++ b/scene/scene.lua @@ -1,7 +1,7 @@ --- ubiquitousse.scene --- Optional dependencies: ubiquitousse.time (to provide each scene a time registry) -local loaded, time = pcall(require, (...):match("^(.-)scene").."time") -if not loaded then time = nil end +-- Optional dependencies: ubiquitousse.timer (to provide each scene a timer registry) +local loaded, timer = pcall(require, (...):match("^(.-)scene").."timer") +if not loaded then timer = nil end --- Scene management. -- 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 current = nil, - --- Shortcut for scene.current.time. + --- Shortcut for scene.current.timer. -- @impl ubiquitousse - time = nil, + timer = nil, --- The scene stack: list of scene, from the farest one to the nearest. -- @impl ubiquitousse @@ -73,7 +73,7 @@ scene = setmetatable({ return { 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. 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, ...) local previous = scene.current 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) if previous then previous:exit() end scene.current:enter(...) @@ -114,7 +114,7 @@ scene = setmetatable({ push = function(scenePath, ...) local previous = scene.current 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) if previous then previous:suspend() end scene.current:enter(...) @@ -128,7 +128,7 @@ scene = setmetatable({ pop = function() local previous = scene.current scene.current = scene.stack[#scene.stack-1] - scene.time = scene.current.time + scene.timer = scene.current.timer if previous then previous:exit() end if scene.current then scene.current:resume() end table.remove(scene.stack) @@ -141,7 +141,7 @@ scene = setmetatable({ -- @impl ubiquitousse update = function(dt, ...) 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, ...) end end, diff --git a/time/backend/ctrulua.lua b/time/backend/ctrulua.lua deleted file mode 100644 index 35e86e5..0000000 --- a/time/backend/ctrulua.lua +++ /dev/null @@ -1,6 +0,0 @@ -local time = require((...):match("^(.-%.)backend").."time") -local ctr = require("ctr") - -time.get = ctr.time - -return time \ No newline at end of file diff --git a/time/backend/love.lua b/time/backend/love.lua deleted file mode 100644 index 2d46124..0000000 --- a/time/backend/love.lua +++ /dev/null @@ -1,7 +0,0 @@ -local time = require((...):match("^(.-%.)backend").."time") - -time.get = function() - return love.timer.getTime() * 1000 -end - -return time \ No newline at end of file diff --git a/timer/backend/ctrulua.lua b/timer/backend/ctrulua.lua new file mode 100644 index 0000000..05143c1 --- /dev/null +++ b/timer/backend/ctrulua.lua @@ -0,0 +1,6 @@ +local timer = require((...):match("^(.-%.)backend").."timer") +local ctr = require("ctr") + +timer.get = ctr.time + +return timer \ No newline at end of file diff --git a/timer/backend/love.lua b/timer/backend/love.lua new file mode 100644 index 0000000..ea57669 --- /dev/null +++ b/timer/backend/love.lua @@ -0,0 +1,7 @@ +local timer = require((...):match("^(.-%.)backend").."timer") + +timer.get = function() + return love.timer.getTime() * 1000 +end + +return timer \ No newline at end of file diff --git a/time/easing.lua b/timer/easing.lua similarity index 100% rename from time/easing.lua rename to timer/easing.lua diff --git a/time/init.lua b/timer/init.lua similarity index 83% rename from time/init.lua rename to timer/init.lua index 291b3ef..2b758c4 100644 --- a/time/init.lua +++ b/timer/init.lua @@ -8,7 +8,7 @@ elseif package.loaded["ctr"] then elseif package.loaded["libretro"] then error("NYI") else - error("no backend for ubiquitousse.time") + error("no backend for ubiquitousse.timer") end return time diff --git a/time/time.lua b/timer/timer.lua similarity index 96% rename from time/time.lua rename to timer/timer.lua index fa90bb1..3f2840b 100644 --- a/time/time.lua +++ b/timer/timer.lua @@ -1,7 +1,7 @@ ---- ubiquitousse.time +--- ubiquitousse.timer -- Depends on a backend. -local ease = require((...):match("^.-time")..".easing") -local time +local ease = require((...):match("^.-timer")..".easing") +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 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) -- @impl ubiquitousse update = function(self, dt) - local currentTime = time.get() + local currentTime = timer.get() if not dt then dt = currentTime - self.lastTime @@ -297,7 +297,7 @@ local registry_mt = { registry_mt.__index = registry_mt --- Time related functions -time = { +timer = { --- Creates and return a new TimerRegistry. -- 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 @@ -311,7 +311,7 @@ time = { delayed = {}, -- Used to calculate the deltatime - lastTime = time.get(), + lastTime = timer.get(), --- Time since last timer update (miliseconds). dt = 0 @@ -333,17 +333,17 @@ time = { delayed = {}, lastTime = 0, update = function(...) - return registry_mt.update(time, ...) + return registry_mt.update(timer, ...) end, run = function(...) - return registry_mt.run(time, ...) + return registry_mt.run(timer, ...) end, tween = function(...) - return registry_mt.tween(time, ...) + return registry_mt.tween(timer, ...) end, clear = function(...) - return registry_mt.clear(time, ...) + return registry_mt.clear(timer, ...) end } -return time +return timer