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

The Ubiquitousse Update

This commit is contained in:
Reuh 2016-12-23 17:22:38 +01:00
parent 8ccf3534bc
commit 07cc7216a1
9 changed files with 96 additions and 96 deletions

View file

@ -1,4 +1,4 @@
-- abstract.audio -- ubiquitousse.audio
--- Audio functions. --- Audio functions.
return { return {

View file

@ -7,7 +7,7 @@
local version = "0.0.1" local version = "0.0.1"
-- Require stuff -- Require stuff
local abstract = require((...):match("^(.-abstract)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
local ctr = require("ctr") local ctr = require("ctr")
local gfx = require("ctr.gfx") local gfx = require("ctr.gfx")
@ -18,7 +18,7 @@ do
local txt = ("Abstract ctrµLua backend version "..version.." was made for %s %s but %s is used!\nThings may not work as expected.") local txt = ("Abstract ctrµLua backend version "..version.." was made for %s %s but %s is used!\nThings may not work as expected.")
:format(stuffName, expectedVersion, actualVersion) :format(stuffName, expectedVersion, actualVersion)
print(txt) print(txt)
for i=0,300 do for _=0,300 do
gfx.start(gfx.TOP) gfx.start(gfx.TOP)
gfx.wrappedText(0, 0, txt, gfx.TOP_WIDTH) gfx.wrappedText(0, 0, txt, gfx.TOP_WIDTH)
gfx.stop() gfx.stop()
@ -27,7 +27,7 @@ do
end end
end end
-- checkCompat("ctrµLua", "", ("%s.%s.%s"):format(love.getVersion())) -- not really a version, just get the latest build -- checkCompat("ctrµLua", "", ("%s.%s.%s"):format(love.getVersion())) -- not really a version, just get the latest build
checkCompat("abstract", "0.0.1", abstract.version) checkCompat("abstract", "0.0.1", uqt.version)
end end
-- Redefine all functions in tbl which also are in toAdd, so when used they call the old function (in tbl) and then the new (in toAdd). -- Redefine all functions in tbl which also are in toAdd, so when used they call the old function (in tbl) and then the new (in toAdd).
@ -41,20 +41,20 @@ local function add(tbl, toAdd)
end end
end end
-- abstract -- uqt
abstract.backend = "ctrulua" uqt.backend = "ctrulua"
-- abstract.event: TODO -- uqt.event: TODO
-- abstract.draw: TODO -- uqt.draw: TODO
-- abstract.audio: TODO -- uqt.audio: TODO
-- abstract.time -- uqt.time
if abstract.time then if uqt.time then
add(abstract.time, { add(uqt.time, {
get = ctr.time get = ctr.time
}) })
end end
-- abstract.input: TODO -- uqt.input: TODO

View file

@ -13,7 +13,7 @@ local displayKeyConstant = true -- If using ScanCodes, sets this to true so the
local version = "0.0.1" local version = "0.0.1"
-- Require stuff -- Require stuff
local abstract = require((...):match("^(.-abstract)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
-- Version compatibility warning -- Version compatibility warning
do do
@ -26,7 +26,7 @@ do
end end
end end
checkCompat("Löve", "0.10.1", ("%s.%s.%s"):format(love.getVersion())) checkCompat("Löve", "0.10.1", ("%s.%s.%s"):format(love.getVersion()))
checkCompat("abstract", "0.0.1", abstract.version) checkCompat("abstract", "0.0.1", uqt.version)
end end
-- Redefine all functions in tbl which also are in toAdd, so when used they call the old function (in tbl) and then the new (in toAdd). -- Redefine all functions in tbl which also are in toAdd, so when used they call the old function (in tbl) and then the new (in toAdd).
@ -40,35 +40,35 @@ local function add(tbl, toAdd)
end end
end end
-- abstract -- uqt
abstract.backend = "love" uqt.backend = "love"
-- abstract.event -- uqt.event
if abstract.event then if uqt.event then
local updateDefault = abstract.event.update local updateDefault = uqt.event.update
abstract.event.update = function() end uqt.event.update = function() end
function love.update(dt) function love.update(dt)
-- Value update -- Value update
abstract.draw.fps = love.timer.getFPS() uqt.draw.fps = love.timer.getFPS()
-- Stuff defined in abstract.lua -- Stuff defined in abstract.lua
updateDefault(dt*1000) updateDefault(dt*1000)
-- Callback -- Callback
abstract.event.update(dt) uqt.event.update(dt)
end end
local drawDefault = abstract.event.draw local drawDefault = uqt.event.draw
abstract.event.draw = function() end uqt.event.draw = function() end
function love.draw() function love.draw()
love.graphics.push() love.graphics.push()
-- Resize type -- Resize type
local winW, winH = love.graphics.getWidth(), love.graphics.getHeight() local winW, winH = love.graphics.getWidth(), love.graphics.getHeight()
local gameW, gameH = abstract.draw.params.width, abstract.draw.params.height local gameW, gameH = uqt.draw.params.width, uqt.draw.params.height
if abstract.draw.params.resizeType == "auto" then if uqt.draw.params.resizeType == "auto" then
love.graphics.scale(winW/gameW, winH/gameH) love.graphics.scale(winW/gameW, winH/gameH)
elseif abstract.draw.params.resizeType == "center" then elseif uqt.draw.params.resizeType == "center" then
love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2)) love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2))
end end
@ -76,18 +76,18 @@ function love.draw()
drawDefault() drawDefault()
-- Callback -- Callback
abstract.event.draw() uqt.event.draw()
love.graphics.pop() love.graphics.pop()
end end
end end
-- abstract.draw -- uqt.draw
if abstract.draw then if uqt.draw then
local defaultFont = love.graphics.getFont() local defaultFont = love.graphics.getFont()
add(abstract.draw, { add(uqt.draw, {
init = function(params) init = function(params)
local p = abstract.draw.params local p = uqt.draw.params
love.window.setTitle(p.title) love.window.setTitle(p.title)
love.window.setMode(p.width, p.height, { love.window.setMode(p.width, p.height, {
resizable = p.resizable resizable = p.resizable
@ -134,16 +134,16 @@ add(abstract.draw, {
end, end,
}) })
function love.resize(width, height) function love.resize(width, height)
if abstract.draw.params.resizeType == "none" then if uqt.draw.params.resizeType == "none" then
abstract.draw.width = width uqt.draw.width = width
abstract.draw.height = height uqt.draw.height = height
end end
end end
end end
-- abstract.audio -- uqt.audio
if abstract.audio then if uqt.audio then
add(abstract.audio, { add(uqt.audio, {
-- TODO: doc -- TODO: doc
load = function(filepath) load = function(filepath)
local audio = love.audio.newSource(filepath) local audio = love.audio.newSource(filepath)
@ -156,17 +156,17 @@ add(abstract.audio, {
}) })
end end
-- abstract.time -- uqt.time
if abstract.time then if uqt.time then
add(abstract.time, { add(uqt.time, {
get = function() get = function()
return love.timer.getTime() return love.timer.getTime()
end end
}) })
end end
-- abstract.input -- uqt.input
if abstract.input then if uqt.input then
local buttonsInUse = {} local buttonsInUse = {}
local axesInUse = {} local axesInUse = {}
function love.keypressed(key, scancode, isrepeat) function love.keypressed(key, scancode, isrepeat)
@ -227,7 +227,7 @@ end
love.mouse.setVisible(false) love.mouse.setVisible(false)
add(abstract.input, { add(uqt.input, {
buttonDetector = function(...) buttonDetector = function(...)
local ret = {} local ret = {}
for _,id in ipairs({...}) do for _,id in ipairs({...}) do
@ -290,7 +290,7 @@ add(abstract.input, {
for _,id in ipairs({...}) do for _,id in ipairs({...}) do
-- Binary axis -- Binary axis
if id:match(".+%,.+") then if id:match(".+%,.+") then
local d1, d2 = abstract.input.buttonDetector(id:match("^(.+)%,(.+)$")) local d1, d2 = uqt.input.buttonDetector(id:match("^(.+)%,(.+)$"))
table.insert(ret, function() table.insert(ret, function()
local b1, b2 = d1(), d2() local b1, b2 = d1(), d2()
if b1 and b2 then return 0 if b1 and b2 then return 0
@ -427,7 +427,7 @@ add(abstract.input, {
for _,id in ipairs({...}) do for _,id in ipairs({...}) do
-- Binary axis -- Binary axis
if id:match(".+%,.+") then if id:match(".+%,.+") then
local b1, b2 = abstract.input.buttonName(id:match("^(.+)%,(.+)$")) local b1, b2 = uqt.input.buttonName(id:match("^(.+)%,(.+)$"))
table.insert(ret, b1.." / "..b2) table.insert(ret, b1.." / "..b2)
-- Mouse move -- Mouse move
elseif id:match("^mouse%.move%.") then elseif id:match("^mouse%.move%.") then
@ -466,31 +466,31 @@ add(abstract.input, {
}) })
-- Defaults -- Defaults
abstract.input.default.pointer:bind( uqt.input.default.pointer:bind(
{ "absolute", "keyboard.left,keyboard.right", "keyboard.up,keyboard.down" }, { "absolute", "keyboard.left,keyboard.right", "keyboard.up,keyboard.down" },
{ "absolute", "gamepad.axis.1.leftx", "gamepad.axis.1.lefty" } { "absolute", "gamepad.axis.1.leftx", "gamepad.axis.1.lefty" }
) )
abstract.input.default.up:bind( uqt.input.default.up:bind(
"keyboard.up", "keyboard.w", "keyboard.up", "keyboard.w",
"gamepad.button.1.dpup", "gamepad.axis.1.lefty%-0.5" "gamepad.button.1.dpup", "gamepad.axis.1.lefty%-0.5"
) )
abstract.input.default.down:bind( uqt.input.default.down:bind(
"keyboard.down", "keyboard.s", "keyboard.down", "keyboard.s",
"gamepad.button.1.dpdown", "gamepad.axis.1.lefty%0.5" "gamepad.button.1.dpdown", "gamepad.axis.1.lefty%0.5"
) )
abstract.input.default.right:bind( uqt.input.default.right:bind(
"keyboard.right", "keyboard.d", "keyboard.right", "keyboard.d",
"gamepad.button.1.dpright", "gamepad.axis.1.leftx%0.5" "gamepad.button.1.dpright", "gamepad.axis.1.leftx%0.5"
) )
abstract.input.default.left:bind( uqt.input.default.left:bind(
"keyboard.left", "keyboard.a", "keyboard.left", "keyboard.a",
"gamepad.button.1.dpleft", "gamepad.axis.1.leftx%-0.5" "gamepad.button.1.dpleft", "gamepad.axis.1.leftx%-0.5"
) )
abstract.input.default.confirm:bind( uqt.input.default.confirm:bind(
"keyboard.enter", "keyboard.space", "keyboard.lshift", "keyboard.e", "keyboard.enter", "keyboard.space", "keyboard.lshift", "keyboard.e",
"gamepad.button.1.a" "gamepad.button.1.a"
) )
abstract.input.default.cancel:bind( uqt.input.default.cancel:bind(
"keyboard.escape", "keyboard.backspace", "keyboard.escape", "keyboard.backspace",
"gamepad.button.1.b" "gamepad.button.1.b"
) )

View file

@ -1,5 +1,5 @@
-- abstract.draw -- ubiquitousse.draw
local abstract = require((...):match("^(.-abstract)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
--- The drawing functions: everything that affect the display/window. --- The drawing functions: everything that affect the display/window.
-- The coordinate system used is: -- The coordinate system used is:
@ -28,7 +28,7 @@ draw = {
-- This function is expected to be only called once, before doing any drawing operation. -- This function is expected to be only called once, before doing any drawing operation.
-- @tparam table params the game parameters -- @tparam table params the game parameters
-- @usage -- Default values: -- @usage -- Default values:
-- abstract.setup { -- ubiquitousse.init {
-- title = "Abstract Engine", -- usually window title -- title = "Abstract Engine", -- usually window title
-- width = 800, -- in px -- width = 800, -- in px
-- height = 600, -- in px -- height = 600, -- in px

View file

@ -1,14 +1,14 @@
-- abstract.event -- ubiquitousse.event
local input = require((...):match("^(.-abstract)%.")..".input") local input = require((...):match("^(.-ubiquitousse)%.")..".input")
local time = require((...):match("^(.-abstract)%.")..".time") local time = require((...):match("^(.-ubiquitousse)%.")..".time")
local scene = require((...):match("^(.-abstract)%.")..".scene") local scene = require((...):match("^(.-ubiquitousse)%.")..".scene")
--- The events: callback functions that will be called when something interesting occurs. --- The events: callback functions that will be called when something interesting occurs.
-- Theses are expected to be redefined in the game. -- Theses are expected to be redefined in the game.
-- For backend writers: if they already contain code, then this code has to be called on each call. -- For backend writers: if they already contain code, then this code has to be called on each call.
-- @usage -- in the game's code -- @usage -- in the game's code
-- abstract.event.draw = function() -- ubiquitousse.event.draw = function()
-- abstract.draw.text(5, 5, "Hello world") -- ubiquitousse.draw.text(5, 5, "Hello world")
-- 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.

View file

@ -1,4 +1,4 @@
-- abstract -- ubiquitousse
--- Abstract Engine. --- Abstract Engine.
-- Main module, containing the abstract things. -- Main module, containing the abstract things.
@ -50,9 +50,9 @@
-- @usage local abstract = require("abstract") -- @usage local abstract = require("abstract")
local p = ... -- require path local p = ... -- require path
local abstract local ubiquitousse
abstract = { ubiquitousse = {
--- Abstract version. --- Abstract version.
-- @impl abstract -- @impl abstract
version = "0.0.1", version = "0.0.1",
@ -64,12 +64,12 @@ abstract = {
} }
-- We're going to require modules requiring abstract, so to avoid stack overflows we already register the abstract package -- We're going to require modules requiring abstract, so to avoid stack overflows we already register the abstract package
package.loaded[p] = abstract package.loaded[p] = ubiquitousse
-- Require external submodules -- Require external submodules
for _, m in ipairs({"time", "draw", "audio", "input", "scene", "event"}) do for _, m in ipairs({"time", "draw", "audio", "input", "scene", "event"}) do
local s, t = pcall(require, p.."."..m) local s, t = pcall(require, p.."."..m)
if s then abstract[m] = t end if s then ubiquitousse[m] = t end
end end
-- Backend engine autodetect and load -- Backend engine autodetect and load
@ -79,4 +79,4 @@ elseif package.loaded["ctr"] then
require(p..".backend.ctrulua") require(p..".backend.ctrulua")
end end
return abstract return ubiquitousse

View file

@ -1,6 +1,6 @@
-- abstract.input -- ubiquitousse.input
local abstract = require((...):match("^(.-abstract)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
local draw = require((...):match("^(.-abstract)%.")..".draw") local draw = require((...):match("^(.-ubiquitousse)%.")..".draw")
--- Used to store inputs which were updated this frame --- Used to store inputs which were updated this frame
-- { Input: true, ... } -- { Input: true, ... }
@ -251,11 +251,11 @@ input = {
if mode == "relative" then if mode == "relative" then
local movX, movY = math.abs(xAxis:value()), math.abs(yAxis:value()) local movX, movY = math.abs(xAxis:value()), math.abs(yAxis:value())
if movX > maxMovX then if movX > maxMovX then
newX = x + (xSpeed and (xAxis:value() * xSpeed * abstract.time.dt) or xAxis:raw()) newX = x + (xSpeed and (xAxis:value() * xSpeed * uqt.time.dt) or xAxis:raw())
maxMovX = movX maxMovX = movX
end end
if movY > maxMovY then if movY > maxMovY then
newY = y + (ySpeed and (yAxis:value() * ySpeed * abstract.time.dt) or yAxis:raw()) newY = y + (ySpeed and (yAxis:value() * ySpeed * uqt.time.dt) or yAxis:raw())
maxMovY = movY maxMovY = movY
end end
elseif mode == "absolute" then elseif mode == "absolute" then
@ -365,7 +365,7 @@ input = {
}, },
--- Update all the Inputs. --- Update all the Inputs.
-- Supposed to be called in abstract.event.update. -- Supposed to be called in ubiquitousse.event.update.
-- @tparam numder dt the delta-time -- @tparam numder dt the delta-time
-- @impl abstract -- @impl abstract
update = function(dt) update = function(dt)

View file

@ -1,5 +1,5 @@
-- abstract.scene -- ubiquitousse.scene
local time = require((...):match("^(.-abstract)%.")..".time") local time = require((...):match("^(.-ubiquitousse)%.")..".time")
--- Returns the file path of the given module name. --- Returns the file path of the given module name.
local function getPath(modname) local function getPath(modname)
@ -18,10 +18,10 @@ 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.
-- This module is fully implemented in abstract and is mostly a "recommended way" of organising an abstract-based game. -- This module is fully implemented in abstract and is mostly a "recommended way" of organising an abstract-based game.
-- However, you don't have to use this if you don't want to. abstract.scene handles all the differents abstract-states and -- However, you don't have to use this if you don't want to. ubiquitousse.scene handles all the differents abstract-states and
-- make them scene-independent, for example by creating a scene-specific TimerRegistry (TimedFunctions that are keept accross -- make them scene-independent, for example by creating a scene-specific TimerRegistry (TimedFunctions that are keept accross
-- states are generally a bad idea). Theses scene-specific states should be created and available in the table returned by -- states are generally a bad idea). Theses scene-specific states should be created and available in the table returned by
-- abstract.scene.new. -- ubiquitousse.scene.new.
-- Currently, the implementation always execute a scene's file before setting it as current, but this may change in the future or -- Currently, the implementation always execute a scene's file before setting it as current, but this may change in the future or
-- for some implementations (e.g., on a computer where memory isn't a problem, the scene may be put in a cache). The result of this -- for some implementations (e.g., on a computer where memory isn't a problem, the scene may be put in a cache). The result of this
-- is that you can load assets, libraries, etc. outside of the enter callback, so they can be cached and not reloaded each time -- is that you can load assets, libraries, etc. outside of the enter callback, so they can be cached and not reloaded each time
@ -29,11 +29,11 @@ end
-- each enter otherwise. -- each enter otherwise.
-- The expected code-organisation is: -- The expected code-organisation is:
-- * each scene is in a file, identified by its module name (same identifier used by Lua's require) -- * each scene is in a file, identified by its module name (same identifier used by Lua's require)
-- * each scene file create a new scene table using abstract.scene.new and returns it at the end of the file -- * each scene file create a new scene table using ubiquitousse.scene.new and returns it at the end of the file
-- Order of callbacks: -- Order of callbacks:
-- * all scene exit callbacks are called before changing the stack or the current scene (ie, abstract.scene.current and the -- * all scene exit callbacks are called before changing the stack or the current scene (ie, ubiquitousse.scene.current and the
-- last stack element is the scene in which the exit or suspend function was called) -- last stack element is the scene in which the exit or suspend function was called)
-- * all scene enter callbacks are called before changing the stack or the current scene (ie, abstract.scene.current and the -- * all scene enter callbacks are called before changing the stack or the current scene (ie, ubiquitousse.scene.current and the
-- last stack element is the previous scene which was just exited, and not the new scene) -- last stack element is the previous scene which was just exited, and not the new scene)
local scene local scene
scene = { scene = {
@ -61,8 +61,8 @@ scene = {
suspend = function() end, -- Called when suspending a scene, and expecting to come back (scene won't be unloaded). suspend = function() end, -- Called when suspending a scene, and expecting to come back (scene won't be unloaded).
resume = function() end, -- Called when resuming a suspended scene (after calling suspend). resume = function() end, -- Called when resuming a suspended scene (after calling suspend).
update = function(dt, ...) end, -- Called on each abstract.event.update on the current scene. update = function(dt, ...) end, -- Called on each ubiquitousse.event.update on the current scene.
draw = function(...) end -- Called on each abstract.event.draw on the current scene. draw = function(...) end -- Called on each ubiquitousse.event.draw on the current scene.
} }
end, end,
@ -81,8 +81,8 @@ scene = {
end, end,
--- Push a new scene to the scene stack. --- Push a new scene to the scene stack.
-- Similar to abstract.scene.switch, except suspend is called on the current scene instead of exit, -- Similar to ubiquitousse.scene.switch, except suspend is called on the current scene instead of exit,
-- and the current scene is not replaced: when the new scene call abstract.scene.pop, the old scene -- and the current scene is not replaced: when the new scene call ubiquitousse.scene.pop, the old scene
-- will be reused. -- will be reused.
-- @tparam string scenePath the new scene module name -- @tparam string scenePath the new scene module name
-- @param ... arguments to pass to the scene's enter function -- @param ... arguments to pass to the scene's enter function
@ -107,7 +107,7 @@ scene = {
end, end,
--- Update the current scene. --- Update the current scene.
-- Should be called in abstract.event.update. -- Should be called in ubiquitousse.event.update.
-- @tparam number dt the delta-time (milisecond) -- @tparam number dt the delta-time (milisecond)
-- @param ... arguments to pass to the scene's update function after dt -- @param ... arguments to pass to the scene's update function after dt
-- @impl abstract -- @impl abstract
@ -119,7 +119,7 @@ scene = {
end, end,
--- Draw the current scene. --- Draw the current scene.
-- Should be called in abstract.event.draw. -- Should be called in ubiquitousse.event.draw.
-- @param ... arguments to pass to the scene's draw function -- @param ... arguments to pass to the scene's draw function
-- @impl abstract -- @impl abstract
draw = function(...) draw = function(...)

View file

@ -1,9 +1,9 @@
-- abstract.time -- ubiquitousse.time
local ease = require((...):match("^(.-abstract)%.")..".lib.easing") local ease = require((...):match("^(.-ubiquitousse)%.")..".lib.easing")
--- Time related functions --- Time related functions
local function newTimerRegistry() local function newTimerRegistry()
--- Used to store all the functions delayed with abstract.time.delay --- Used to store all the functions delayed with ubiquitousse.time.delay
-- The default implementation use the structure {<key: function> = <value: data table>, ...} -- The default implementation use the structure {<key: function> = <value: data table>, ...}
-- This table is for internal use and shouldn't be used from an external script. -- This table is for internal use and shouldn't be used from an external script.
local delayed = {} local delayed = {}
@ -14,9 +14,9 @@ local function newTimerRegistry()
local registry local registry
registry = { registry = {
--- Creates and return a new TimerRegistry. --- Creates and return a new TimerRegistry.
-- A TimerRegistry is a separate abstract.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 abstract.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
-- system, a scene-specific TimerRegistry is available at abstract.scene.current.time. -- system, a scene-specific TimerRegistry is available at ubiquitousse.scene.current.time.
-- @impl abstract -- @impl abstract
new = function() new = function()
local new = newTimerRegistry() local new = newTimerRegistry()
@ -31,7 +31,7 @@ local function newTimerRegistry()
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 ubiquitousse.event.update.
-- @tparam[opt=calculate here] numder dt the delta-time (time spent since last time the function was called) (miliseconds) -- @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)