mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 09:09:30 +00:00
Rename time to timer
This commit is contained in:
parent
b5324faace
commit
82bc7268e6
9 changed files with 37 additions and 37 deletions
4
init.lua
4
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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
local time = require((...):match("^(.-%.)backend").."time")
|
||||
local ctr = require("ctr")
|
||||
|
||||
time.get = ctr.time
|
||||
|
||||
return time
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
local time = require((...):match("^(.-%.)backend").."time")
|
||||
|
||||
time.get = function()
|
||||
return love.timer.getTime() * 1000
|
||||
end
|
||||
|
||||
return time
|
||||
6
timer/backend/ctrulua.lua
Normal file
6
timer/backend/ctrulua.lua
Normal 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
7
timer/backend/love.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
local timer = require((...):match("^(.-%.)backend").."timer")
|
||||
|
||||
timer.get = function()
|
||||
return love.timer.getTime() * 1000
|
||||
end
|
||||
|
||||
return timer
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue