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

abstract is ded

This commit is contained in:
Reuh 2016-12-24 21:15:27 +01:00
parent 07cc7216a1
commit 42738cc7c9
8 changed files with 219 additions and 135 deletions

View file

@ -1,7 +1,7 @@
--- ctrµLua backend 0.0.1 for Abstract. --- ctrµLua backend 0.0.1 for Ubiquitousse.
-- Provides a partial abstract API. Still a lot to implement. -- Provides a partial Ubiquitousse API. Still a lot to implement.
-- Made for some ctrµLua version and abstract 0.0.1. -- Made for some ctrµLua version and Ubiquitousse 0.0.1.
-- See `abstract` for Abstract API. -- See `ubiquitousse` for Ubiquitousse API.
-- General -- General
local version = "0.0.1" local version = "0.0.1"
@ -15,7 +15,7 @@ local gfx = require("ctr.gfx")
do do
local function checkCompat(stuffName, expectedVersion, actualVersion) local function checkCompat(stuffName, expectedVersion, actualVersion)
if actualVersion ~= expectedVersion then if actualVersion ~= expectedVersion then
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 = ("Ubiquitousse 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 _=0,300 do for _=0,300 do
@ -26,8 +26,8 @@ do
end end
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", "v1.0", ctr.version) -- not really a version, just get the latest build
checkCompat("abstract", "0.0.1", uqt.version) checkCompat("Ubiquitousse", "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).

View file

@ -1,7 +1,7 @@
--- Löve backend 0.0.1 for Abstract. --- Löve backend 0.0.1 for Ubiquitousse.
-- Provides all the Abstract API on a Löve environment. -- Provides all the Ubiquitousse API on a Löve environment.
-- Made for Löve 0.10.1 and abstract 0.0.1. -- Made for Löve 0.10.1 and Ubiquitousse 0.0.1.
-- See `abstract` for Abstract API. -- See `ubiquitousse` for Ubiquitousse API.
-- Config -- Config
local useScancodes = true -- Use ScanCodes (layout independant input) instead of KeyConstants (layout dependant) for keyboard input local useScancodes = true -- Use ScanCodes (layout independant input) instead of KeyConstants (layout dependant) for keyboard input
@ -19,14 +19,14 @@ local uqt = require((...):match("^(.-ubiquitousse)%."))
do do
local function checkCompat(stuffName, expectedVersion, actualVersion) local function checkCompat(stuffName, expectedVersion, actualVersion)
if actualVersion ~= expectedVersion then if actualVersion ~= expectedVersion then
local txt = ("Abstract Löve backend version "..version.." was made for %s %s but %s is used!\nThings may not work as expected.") local txt = ("Ubiquitousse Löve 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)
love.window.showMessageBox("Warning", txt, "warning") love.window.showMessageBox("Warning", txt, "warning")
end end
end end
checkCompat("Löve", "0.10.1", ("%s.%s.%s"):format(love.getVersion())) checkCompat("Löve", "0.10.2", ("%s.%s.%s"):format(love.getVersion()))
checkCompat("abstract", "0.0.1", uqt.version) checkCompat("Ubiquitousse", "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).
@ -51,7 +51,7 @@ function love.update(dt)
-- Value update -- Value update
uqt.draw.fps = love.timer.getFPS() uqt.draw.fps = love.timer.getFPS()
-- Stuff defined in abstract.lua -- Stuff defined in ubiquitousse.lua
updateDefault(dt*1000) updateDefault(dt*1000)
-- Callback -- Callback
@ -72,7 +72,7 @@ function love.draw()
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
-- Stuff defined in abstract.lua -- Stuff defined in ubiquitousse.lua
drawDefault() drawDefault()
-- Callback -- Callback
@ -468,23 +468,9 @@ add(uqt.input, {
-- Defaults -- Defaults
uqt.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", "keyboard.a,keyboard.d", "keyboard.w,keyboard.s" },
) { "absolute", "gamepad.axis.1.leftx", "gamepad.axis.1.lefty" },
uqt.input.default.up:bind( { "absolute", "gamepad.button.1.dpleft,gamepad.button.1.dpright", "gamepad.button.1.dpup,gamepad.button.1.dpdown"}
"keyboard.up", "keyboard.w",
"gamepad.button.1.dpup", "gamepad.axis.1.lefty%-0.5"
)
uqt.input.default.down:bind(
"keyboard.down", "keyboard.s",
"gamepad.button.1.dpdown", "gamepad.axis.1.lefty%0.5"
)
uqt.input.default.right:bind(
"keyboard.right", "keyboard.d",
"gamepad.button.1.dpright", "gamepad.axis.1.leftx%0.5"
)
uqt.input.default.left:bind(
"keyboard.left", "keyboard.a",
"gamepad.button.1.dpleft", "gamepad.axis.1.leftx%-0.5"
) )
uqt.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",

View file

@ -1,9 +1,9 @@
project = "Abstract" project = "Ubiquitousse"
description = "Abstract Game Engine" description = "Ubiquitousse Game Engine"
full_description = "A simple Lua game engine, made to run everywhere. See the abstract module for more information." full_description = "A simple Lua game engine, made to run everywhere. See the Ubiquitousse module for more information."
title = "Abstract Reference" title = "Ubiquitousse Reference"
package = "abstract" package = "ubiquitousse"
file = "./" file = "./"
format = "markdown" format = "markdown"

View file

@ -3,7 +3,7 @@ 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:
-- --
-- (0,0) +---> (x) -- (0,0) +---> (x)
-- | -- |
-- | -- |
@ -14,9 +14,9 @@ local uqt = require((...):match("^(.-ubiquitousse)%."))
local draw local draw
draw = { draw = {
--- Initial game view paramters (some defaults). --- Initial game view paramters (some defaults).
-- @impl abstract -- @impl ubiquitousse
params = { params = {
title = "Abstract Engine", title = "Ubiquitousse Game",
width = 800, width = 800,
height = 600, height = 600,
resizable = false, resizable = false,
@ -29,7 +29,7 @@ draw = {
-- @tparam table params the game parameters -- @tparam table params the game parameters
-- @usage -- Default values: -- @usage -- Default values:
-- ubiquitousse.init { -- ubiquitousse.init {
-- title = "Abstract Engine", -- usually window title -- title = "Ubiquitousse Game", -- usually window title
-- width = 800, -- in px -- width = 800, -- in px
-- height = 600, -- in px -- height = 600, -- in px
-- resizable = false, -- can the game be resized? -- resizable = false, -- can the game be resized?

View file

@ -1,33 +1,33 @@
-- ubiquitousse -- ubiquitousse
--- Abstract Engine. --- Ubiquitousse Game Engine.
-- Main module, containing the abstract things. -- Main module, containing the main things.
-- The API exposed here is the Abstract API. -- The API exposed here is the Ubiquitousse API.
-- It is as the name imply abstract, and must be implemented in a backend, such as abstract.love. -- It is as the name does not imply anymore abstract, and must be implemented in a backend, such as ubiquitousse.love.
-- When required, this file will try to autodetect the engine it is running on, and load a correct backend. -- When required, this file will try to autodetect the engine it is running on, and load a correct backend.
-- --
-- abstract may or may not be used as a full game engine. You can delete the modules files you don't need and abstract -- Ubiquitousse may or may not be used as a full game engine. You can delete the modules files you don't need and Ubiquitousse
-- should adapt accordingly. -- should adapt accordingly.
-- --
-- For backend writers: -- For backend writers:
-- If a function defined here already contains some code, this means this code is mandatory and you must put/call -- If a function defined here already contains some code, this means this code is mandatory and you must put/call
-- it in your implementation. -- it in your implementation.
-- Also, a backend file shouldn't redefine the abstract table itself but only redefine the backend-dependant fields. -- Also, a backend file shouldn't redefine the ubiquitousse table itself but only redefine the backend-dependant fields.
-- The API doesn't make the difference between numbers and integers, so convert to integers when needed. -- The API doesn't make the difference between numbers and integers, so convert to integers when needed.
-- --
-- Abstract's goal is to run everywhere with the least porting effort possible. -- Ubiquitousse's goal is to run everywhere with the least porting effort possible.
-- To achieve this, the engine needs to stay simple, and only provide features that are almost sure to be -- To achieve this, the engine needs to stay simple, and only provide features that are almost sure to be
-- available everywhere, so writing a backend should be straighforward. -- available everywhere, so writing a backend should be straighforward.
-- However, Abstract still make some small assumptions about the engine: -- However, Ubiquitousse still make some small assumptions about the engine:
-- * The engine has some kind of main loop, or at least a function called very often (may or may not be the -- * The engine has some kind of main loop, or at least a function called very often (may or may not be the
-- same as the redraw screen callback). -- same as the redraw screen callback).
-- * 32bit color depth. -- * 32bit color depth.
-- --
-- Regarding data formats, Abstract reference implemtations expect and recommend: -- Regarding data formats, Ubiquitousse reference implemtations expect and recommend:
-- * For images, PNG support is expected. -- * For images, PNG support is expected.
-- * For audio files, OGG Vorbis support is expected. -- * For audio files, OGG Vorbis support is expected.
-- * For fonts, TTF support is expected. -- * For fonts, TTF support is expected.
-- Theses formats are respected for the reference implementations, but Abstract may provide a script to -- Theses formats are respected for the reference implementations, but Ubiquitousse 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: -- Units used in the API:
@ -42,19 +42,19 @@
-- * lowerCamelCase is expected for everything else. -- * lowerCamelCase is expected for everything else.
-- --
-- Implementation levels: -- Implementation levels:
-- * backend: nothing defined in abstract, must be implemented in backend -- * backend: nothing defined in Ubiquitousse, must be implemented in backend
-- * mixed: partly implemented in abstract but must be complemeted in backend -- * mixed: partly implemented in Ubiquitousse but must be complemeted in backend
-- * abstract: fully-working version in abstract, may or may not be redefined in backend -- * ubiquitousse: fully-working version in Ubiquitousse, may or may not be redefined in backend
-- The implementation level is indicated using the "@impl level" annotation. -- The implementation level is indicated using the "@impl level" annotation.
-- --
-- @usage local abstract = require("abstract") -- @usage local ubiquitousse = require("ubiquitousse")
local p = ... -- require path local p = ... -- require path
local ubiquitousse local ubiquitousse
ubiquitousse = { ubiquitousse = {
--- Abstract version. --- Ubiquitousse version.
-- @impl abstract -- @impl ubiquitousse
version = "0.0.1", version = "0.0.1",
--- Backend name. --- Backend name.
@ -63,7 +63,7 @@ ubiquitousse = {
backend = "unknown" backend = "unknown"
} }
-- 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 Ubiquitousse, so to avoid stack overflows we already register the ubiquitousse package
package.loaded[p] = ubiquitousse package.loaded[p] = ubiquitousse
-- Require external submodules -- Require external submodules

214
input.lua
View file

@ -10,14 +10,17 @@ local updated = {}
--- Input stuff --- Input stuff
-- Inspired by Tactile by Andrew Minnich (https://github.com/tesselode/tactile). -- Inspired by Tactile by Andrew Minnich (https://github.com/tesselode/tactile).
-- I don't think I need to include the license since it's just inspiration, but for the sake of information, Tactile is under the MIT license. -- I don't think I need to include the license since it's just inspiration, but for the sake of information, Tactile is under the MIT license.
-- Abstract considers two input methods, called buttons (binary input) and axes (analog input). -- Ubiquitousse considers two input methods, called buttons (binary input) and axes (analog input).
local input local input
input = { input = {
---------------------------------
--- Detectors (input sources) --- --- Detectors (input sources) ---
---------------------------------
-- Buttons detectors -- -- Buttons detectors --
-- A button detector is a function which returns true (pressed) or false (unpressed). -- A button detector is a function which returns true (pressed) or false (unpressed).
-- Any fuction which returns a boolean can be used as a button detector, but you will probably want to get the data from an HID. -- Any fuction which returns a boolean can be used as a button detector, but you will probably want to get the data from an HID.
-- Abstract being abstract, it doesn't suppose there is a keyboard and mouse available for example, and all HID buttons are identified using -- Ubiquitousse being platform-agnostic, it doesn't suppose there is a keyboard and mouse available for example, and all HID buttons are identified using
-- an identifier string, which depends of the backend. Identifier strings should be of the format "source1.source2.[...].button", for example "keyboard.up" -- an identifier string, which depends of the backend. Identifier strings should be of the format "source1.source2.[...].button", for example "keyboard.up"
-- or "gamepad.button.1.a" for the A-button of the first gamepad. -- or "gamepad.button.1.a" for the A-button of the first gamepad.
-- If the button is actually an axis (ie, the button is pressed if the axis value passes a certain threshold), the threshold should be in the end of the -- If the button is actually an axis (ie, the button is pressed if the axis value passes a certain threshold), the threshold should be in the end of the
@ -27,7 +30,7 @@ input = {
--- Makes a new button detector(s) from the identifier(s) string. --- Makes a new button detector(s) from the identifier(s) string.
-- The function may error if the identifier is incorrect. -- The function may error if the identifier is incorrect.
-- @tparam string button identifier, depends on the platform abstract is running on (multiple parameters) -- @tparam string button identifier, depends on the platform Ubiquitousse is running on (multiple parameters)
-- @treturn each button detector (multiple-returns) -- @treturn each button detector (multiple-returns)
-- @impl backend -- @impl backend
buttonDetector = function(...) end, buttonDetector = function(...) end,
@ -37,20 +40,24 @@ input = {
-- Threshold value can be used similarly with %. -- Threshold value can be used similarly with %.
-- Axis detectors should support "binary axis", ie an axis defined by two buttons: if the 1rst button is pressed, value will be -1, if the 2nd is pressed it will be 1 -- Axis detectors should support "binary axis", ie an axis defined by two buttons: if the 1rst button is pressed, value will be -1, if the 2nd is pressed it will be 1
-- and if none or the both are pressed, the value will be 0. This kind of axis identifier should have an identifier like "button1,button2" (comma-separated). -- and if none or the both are pressed, the value will be 0. This kind of axis identifier should have an identifier like "button1,button2" (comma-separated).
-- Axis detectors may also optionally return after the number between -1 and 1 the raw value and max value. The raw value is between -max and +max.
--- Makes a new axis detector(s) from the identifier(s) string. --- Makes a new axis detector(s) from the identifier(s) string.
-- @tparam string axis identifier, depends on the platform abstract is running on (multiple parameters) -- @tparam string axis identifier, depends on the platform Ubiquitousse is running on (multiple parameters)
-- @treturn each axis detector (multiple-returns) -- @treturn each axis detector (multiple-returns)
-- @impl backend -- @impl backend
axisDetector = function(...) end, axisDetector = function(...) end,
------------------------------------------
--- Inputs (the thing you want to use) --- --- Inputs (the thing you want to use) ---
------------------------------------------
-- Buttons inputs -- -- Buttons inputs --
-- Button input is a container for buttons detector. A button will be pressed when one of its detectors returns true. -- Button input is a container for buttons detector. A button will be pressed when one of its detectors returns true.
-- Inputs also knows if the button was just pressed or released. -- Inputs also knows if the button was just pressed or released.
-- @tparam ButtonDetectors ... all the buttons detectors or buttons identifiers -- @tparam ButtonDetectors ... all the buttons detectors or buttons identifiers
-- @tretrun ButtonInput the object -- @tretrun ButtonInput the object
-- @impl abstract -- @impl ubiquitousse
button = function(...) button = function(...)
local r -- object local r -- object
local detectors = {} -- detectors list local detectors = {} -- detectors list
@ -82,6 +89,8 @@ input = {
end end
-- Object -- Object
r = { r = {
--- Returns a new ButtonInput with the same properties.
-- @treturn ButtonInput the cloned object
clone = function(self) clone = function(self)
local clone = input.button() local clone = input.button()
for name, detector in pairs(detectors) do for name, detector in pairs(detectors) do
@ -94,6 +103,9 @@ input = {
return clone return clone
end, end,
--- Bind new ButtonDetector(s) to this input.
-- @tparam ButtonDetectors ... buttons detectors or buttons identifiers to add
-- @treturn ButtonInput this ButtonInput object
bind = function(self, ...) bind = function(self, ...)
for _,d in ipairs({...}) do for _,d in ipairs({...}) do
if type(d) == "string" then if type(d) == "string" then
@ -106,6 +118,9 @@ input = {
end end
return self return self
end, end,
--- Unbind ButtonDetector(s).
-- @tparam ButtonDetectors ... buttons detectors or buttons identifiers to remove
-- @treturn ButtonInput this ButtonInput object
unbind = function(self, ...) unbind = function(self, ...)
for _,d in ipairs({...}) do for _,d in ipairs({...}) do
detectors[d] = nil detectors[d] = nil
@ -113,15 +128,21 @@ input = {
return self return self
end, end,
pressed = function(_) --- Returns true if the input was just pressed.
-- @treturn boolean true if the input was pressed, false otherwise
pressed = function(self)
update() update()
return state == "pressed" return state == "pressed"
end, end,
down = function(_) --- Returns true if the input is down.
-- @treturn boolean true if the input is currently down, false otherwise
down = function(self)
update() update()
return state == "down" or state == "pressed" return state == "down" or state == "pressed"
end, end,
released = function(_) --- Returns true if the input was just released.
-- @treturn boolean true if the input was released, false otherwise
released = function(self)
update() update()
return state == "released" return state == "released"
end, end,
@ -130,7 +151,12 @@ input = {
return r return r
end, end,
-- TODO: doc -- Axis inputs --
-- Axis input is a container for axes detector. An axis input will return the value of the axis detector the most far away from their center (0).
-- Axis input provide a threshold setting ; every axis which has a distance to the center below th threshold will be ignored.
-- @tparam AxisDetectors ... all the axis detectors or axis identifiers
-- @tretrun AxisInput the object
-- @impl ubiquitousse
axis = function(...) axis = function(...)
local r -- object local r -- object
local detectors = {} -- detectors list local detectors = {} -- detectors list
@ -150,6 +176,8 @@ input = {
end end
-- Object -- Object
r = { r = {
--- Returns a new AxisInput with the same properties.
-- @treturn AxisInput the cloned object
clone = function(self) clone = function(self)
local clone = input.axis() local clone = input.axis()
for name, detector in pairs(detectors) do for name, detector in pairs(detectors) do
@ -163,6 +191,9 @@ input = {
return clone return clone
end, end,
--- Bind new AxisDetector(s) to this input.
-- @tparam AxisDetectors ... axis detectors or axis identifiers to add
-- @treturn AxisInput this AxisInput object
bind = function(self, ...) bind = function(self, ...)
for _,d in ipairs({...}) do for _,d in ipairs({...}) do
if type(d) == "string" then if type(d) == "string" then
@ -175,6 +206,9 @@ input = {
end end
return self return self
end, end,
--- Unbind AxisDetector(s).
-- @tparam AxisDetectors ... axis detectors or axis identifiers to remove
-- @treturn AxisInput this AxisInput object
unbind = function(self, ...) unbind = function(self, ...)
for _,d in ipairs({...}) do for _,d in ipairs({...}) do
detectors[d] = nil detectors[d] = nil
@ -182,58 +216,52 @@ input = {
return self return self
end, end,
--- Sets the default detection threshold (deadzone).
-- @tparam number new the new detection threshold
-- @treturn AxisInput this AxisInput object
threshold = function(self, new) threshold = function(self, new)
threshold = tonumber(new) threshold = tonumber(new)
return self return self
end, end,
value = function(_, curThreshold) --- Returns the value of the input (between -1 and 1).
-- @tparam[opt=default threshold] number threshold value to use
-- @treturn number the input value
value = function(self, curThreshold)
update() update()
return math.abs(value) > math.abs(curThreshold or threshold) and value or 0 return math.abs(value) > math.abs(curThreshold or threshold) and value or 0
end, end,
raw = function(_, rawThreshold) --- Returns the raw value of the input (between -max and +max).
-- @tparam[opt=default threshold*max] number raw threshold value to use
-- @treturn number the input raw value
raw = function(self, rawThreshold)
update() update()
return math.abs(raw) > math.abs(rawThreshold or threshold*max) and raw or 0 return math.abs(raw) > math.abs(rawThreshold or threshold*max) and raw or 0
end, end,
max = function(_) --- Return the raw max of the input.
-- @treturn number the input raw max
max = function(self)
update() update()
return max return max
end end,
--- The associated button pressed when the axis reaches a positive value.
positive = input.button(function() return r:value() > 0 end),
--- The associated button pressed when the axis reaches a negative value.
negative = input.button(function() return r:value() < 0 end)
} }
r:bind(...) r:bind(...)
return r return r
end, end,
--- Returns a list of the buttons currently in use, identified by their string button identifier. -- Pointer inputs --
-- This may also returns "axis threshold" buttons if an axis passes the threshold. -- Pointer inputs are container for two axes input, in order to represent a two-dimensionnal pointing device, e.g. a mouse or a stick.
-- @treturn table<string> buttons identifiers list -- Each pointer detector is a table with 3 fields: mode(string), XAxis(axis), YAxis(axis). mode can either be "relative" or "absolute".
-- @treturn[opt=0.5] number threshold the threshold to detect axes as button -- In relative mode, the pointer will return the movement since last update (for example to move a mouse pointer with a stick).
-- @impl backend -- In absolute mode, the pointer will return the pointer position directly deduced of the current axes position.
buttonsInUse = function(threshold) end, -- @tparam table{mode,XAxis,YAxis} ... couples of axis detectors, axis identifiers or axis input to add and in which mode
-- @tretrun PointerInput the object
--- Returns a list of the axes currently in use, identified by their string axis identifier -- @impl ubiquitousse
-- @treturn table<string> axes identifiers list
-- @treturn[opt=0.5] number threshold the threshold to detect axes
-- @impl backend
axesInUse = function(threshold) end,
--- Returns a nice name for the button identifier.
-- Can be locale-depedant and stuff, it's only for display.
-- May returns the raw identifier if you're lazy.
-- @tparam string... button identifier string(s)
-- @treturn string... the displayable names
-- @impl backend
buttonName = function(...) end,
--- Returns a nice name for the axis identifier.
-- Can be locale-depedant and stuff, it's only for display.
-- May returns the raw identifier if you're lazy.
-- @tparam string... axis identifier string(s)
-- @treturn string... the displayable names
-- @impl backend
axisName = function(...) end,
-- TODO: doc
pointer = function(...) pointer = function(...)
local pointers = {} -- pointers list local pointers = {} -- pointers list
local x, y = 0, 0 -- pointer position local x, y = 0, 0 -- pointer position
@ -277,6 +305,8 @@ input = {
end end
end end
r = { r = {
--- Returns a new PointerInput with the same properties.
-- @treturn PointerInput the cloned object
clone = function(self) clone = function(self)
return input.pointer(unpack(pointers)) return input.pointer(unpack(pointers))
:dimensions(width, height) :dimensions(width, height)
@ -284,6 +314,9 @@ input = {
:speed(xSpeed, ySpeed) :speed(xSpeed, ySpeed)
end, end,
--- Bind new axis couples to this input.
-- @tparam table{mode,XAxis,YAxis} ... couples of axis detectors, axis identifiers or axis input to add and in which mode
-- @treturn PointerInput this PointerInput object
bind = function(self, ...) bind = function(self, ...)
for _,p in ipairs({...}) do for _,p in ipairs({...}) do
if type(p) == "table" then if type(p) == "table" then
@ -296,6 +329,9 @@ input = {
end end
return self return self
end, end,
--- Unbind axis couples.
-- @tparam table{mode,XAxis,YAxis} ... couples of axis detectors, axis identifiers or axis input to remove
-- @treturn PointerInput this PointerInput object
unbind = function(self, ...) unbind = function(self, ...)
for _,p in ipairs({...}) do for _,p in ipairs({...}) do
for i,pointer in ipairs(pointers) do for i,pointer in ipairs(pointers) do
@ -312,7 +348,9 @@ input = {
-- Call without argument to use half the window dimensions. -- Call without argument to use half the window dimensions.
-- It's the half dimensions because axes values goes from -1 to 1, so theses dimensions only -- It's the half dimensions because axes values goes from -1 to 1, so theses dimensions only
-- covers values from x=0,y=0 to x=1,y=1. The full moving area will be 4*newWidth*newHeight. -- covers values from x=0,y=0 to x=1,y=1. The full moving area will be 4*newWidth*newHeight.
-- @impl abstract -- @tparam number newWidth new width
-- @tparam number newHeight new height
-- @treturn PointerInput this PointerInput object
dimensions = function(self, newWidth, newHeight) dimensions = function(self, newWidth, newHeight)
width, height = newWidth, newHeight width, height = newWidth, newHeight
return self return self
@ -320,7 +358,9 @@ input = {
--- Set the moving area coordinates offset. --- Set the moving area coordinates offset.
-- The offset is a value automatically added to the x and y values when using the x() and y() methods. -- The offset is a value automatically added to the x and y values when using the x() and y() methods.
-- Call without argument to automatically offset so 0,0 <= x(),y() <= width,height, i.e. offset to width,height. -- Call without argument to automatically offset so 0,0 <= x(),y() <= width,height, i.e. offset to width,height.
-- @impl abstract -- @tparam number newOffX new X offset
-- @tparam number newOffY new Y offset
-- @treturn PointerInput this PointerInput object
offset = function(self, newOffX, newOffY) offset = function(self, newOffX, newOffY)
offsetX, offsetY = newOffX, newOffY offsetX, offsetY = newOffX, newOffY
return self return self
@ -328,46 +368,108 @@ input = {
--- Set maximal speed (pixels-per-milisecond) --- 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 -- @tparam number newXSpeed new X speed
-- @tparam number newYSpeed new Y speed
-- @treturn PointerInput this PointerInput object
speed = function(self, newXSpeed, newYSpeed) speed = function(self, newXSpeed, newYSpeed)
xSpeed, ySpeed = newXSpeed, newYSpeed or newXSpeed xSpeed, ySpeed = newXSpeed, newYSpeed or newXSpeed
return self return self
end, end,
--- Returns the current X value of the pointer.
-- @treturn number X value
x = function() x = function()
update() update()
return x + (offsetX or width or draw.width/2) return x + (offsetX or width or draw.width/2)
end, end,
--- Returns the current Y value of the pointer.
-- @treturn number Y value
y = function() y = function()
update() update()
return y + (offsetY or height or draw.height/2) return y + (offsetY or height or draw.height/2)
end end,
--- The associated horizontal axis.
horizontal = input.axis(function()
local h = r:x()
return h/width, h, width
end),
--- The associated vertical axis.
vertical = input.axis(function()
local v = r:y()
return v/height, v, height
end),
--- The associated button pressed when the pointer goes to the right.
right = nil,
--- The associated button pressed when the pointer goes to the left.
left = nil,
--- The associated button pressed when the pointer points up.
up = nil,
--- The associated button pressed when the pointer points down.
down = nil
} }
r.right, r.left = r.horizontal.positive, r.horizontal.negative
r.up, r.down = r.vertical.negative, r.vertical.positive
r:bind(...) r:bind(...)
return r return r
end, end,
------------------------------
--- Input detection helpers --
------------------------------
--- Returns a list of the buttons currently in use, identified by their string button identifier.
-- This may also returns "axis threshold" buttons if an axis passes the threshold.
-- @treturn table<string> buttons identifiers list
-- @treturn[opt=0.5] number threshold the threshold to detect axes as button
-- @impl backend
buttonsInUse = function(threshold) end,
--- Returns a list of the axes currently in use, identified by their string axis identifier
-- @treturn table<string> axes identifiers list
-- @treturn[opt=0.5] number threshold the threshold to detect axes
-- @impl backend
axesInUse = function(threshold) end,
--- Returns a nice name for the button identifier.
-- Can be locale-depedant and stuff, it's only for display.
-- May returns the raw identifier if you're lazy.
-- @tparam string... button identifier string(s)
-- @treturn string... the displayable names
-- @impl backend
buttonName = function(...) end,
--- Returns a nice name for the axis identifier.
-- Can be locale-depedant and stuff, it's only for display.
-- May returns the raw identifier if you're lazy.
-- @tparam string... axis identifier string(s)
-- @treturn string... the displayable names
-- @impl backend
axisName = function(...) end,
-------------------
--- Other stuff ---
-------------------
--- Some default inputs. --- Some default inputs.
-- The backend may bind detectors to thoses inputs. -- The backend should bind detectors to thoses inputs.
-- These are used to provide some common input default detectors to allow to start a game quickly on -- These are used to provide some common input default detectors to allow to start a game quickly on
-- any platform without having to configure the keys. -- any platform without having to configure the keys.
-- If some key function in your game match one of theses defaults, using it instead of creating a new -- If some key function in your game match one of theses defaults, using it instead of creating a new
-- input would be a good idea. -- input would be a good idea.
-- @impl mixed -- @impl mixed
default = { default = {
pointer = nil, -- A default Pointer: used to move. Example binds: arrow keys, stick. pointer = nil, -- Pointer: used to move and select. Example binds: arrow keys, WASD, stick.
up = nil, -- Button: similar to pointer, but only the up button.
down = nil, -- Button: similar to pointer, but only the down button.
right = nil, -- Button: similar to pointer, but only the right button.
left = nil, -- Button: similar to pointer, but only the left button.
confirm = nil, -- Button: used to confirm something. Example binds: Enter, A button. confirm = nil, -- Button: used to confirm something. Example binds: Enter, A button.
cancel = nil -- Button: used to cancel something. Example binds: Escape, B button. cancel = nil -- Button: used to cancel something. Example binds: Escape, B button.
}, },
--- Update all the Inputs. --- Update all the Inputs.
-- Supposed to be called in ubiquitousse.event.update. -- Supposed to be called in ubiquitousse.event.update.
-- The backend can hook into this function to to its input-related updates.
-- @tparam numder dt the delta-time -- @tparam numder dt the delta-time
-- @impl abstract -- @impl ubiquitousse
update = function(dt) update = function(dt)
updated = {} updated = {}
end end
@ -375,10 +477,6 @@ input = {
-- Create default inputs -- Create default inputs
input.default.pointer = input.pointer() input.default.pointer = input.pointer()
input.default.up = input.button()
input.default.down = input.button()
input.default.right = input.button()
input.default.left = input.button()
input.default.confirm = input.button() input.default.confirm = input.button()
input.default.cancel = input.button() input.default.cancel = input.button()

View file

@ -17,8 +17,8 @@ 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 Ubiquitousse and is mostly a "recommended way" of organising an Ubiquitousse-based game.
-- However, you don't have to use this if you don't want to. ubiquitousse.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 Ubiquitousse-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
-- ubiquitousse.scene.new. -- ubiquitousse.scene.new.
@ -38,19 +38,19 @@ end
local scene local scene
scene = { scene = {
--- The current scene table. --- The current scene table.
-- @impl abstract -- @impl ubiquitousse
current = nil, current = 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 abstract -- @impl ubiquitousse
stack = {}, stack = {},
--- A prefix for scene modules names --- A prefix for scene modules names
-- @impl abstract -- @impl ubiquitousse
prefix = "", prefix = "",
--- Creates and returns a new Scene object. --- Creates and returns a new Scene object.
-- @impl abstract -- @impl ubiquitousse
new = function() new = function()
return { return {
time = time.new(), -- Scene-specific TimerRegistry. time = time.new(), -- Scene-specific TimerRegistry.
@ -71,7 +71,7 @@ scene = {
-- the current scene will then be replaced by the new one, and then the enter callback is called. -- the current scene will then be replaced by the new one, and then the enter callback is called.
-- @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
-- @impl abstract -- @impl ubiquitousse
switch = function(scenePath, ...) switch = function(scenePath, ...)
if scene.current then scene.current.exit() end if scene.current then scene.current.exit() end
scene.current = dofile(getPath(scene.prefix..scenePath)) scene.current = dofile(getPath(scene.prefix..scenePath))
@ -86,7 +86,7 @@ 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
-- @impl abstract -- @impl ubiquitousse
push = function(scenePath, ...) push = function(scenePath, ...)
if scene.current then scene.current.suspend() end if scene.current then scene.current.suspend() end
scene.current = dofile(getPath(scene.prefix..scenePath)) scene.current = dofile(getPath(scene.prefix..scenePath))
@ -97,7 +97,7 @@ scene = {
--- Pop the current scene from the scene stack. --- Pop the current scene from the scene stack.
-- The current scene exit function will be called, then the previous scene resume function will be called. -- The current scene exit function will be called, then the previous scene resume function will be called.
-- Then the current scene will be removed from the stack, and the previous scene will be set as the current scene. -- Then the current scene will be removed from the stack, and the previous scene will be set as the current scene.
-- @impl abstract -- @impl ubiquitousse
pop = function() pop = function()
if scene.current then scene.current.exit() end if scene.current then scene.current.exit() end
local previous = scene.stack[#scene.stack-1] local previous = scene.stack[#scene.stack-1]
@ -110,7 +110,7 @@ scene = {
-- Should be called in ubiquitousse.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 ubiquitousse
update = function(dt, ...) update = function(dt, ...)
if scene.current then if scene.current then
scene.current.time.update(dt) scene.current.time.update(dt)
@ -121,7 +121,7 @@ scene = {
--- Draw the current scene. --- Draw the current scene.
-- Should be called in ubiquitousse.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 ubiquitousse
draw = function(...) draw = function(...)
if scene.current then scene.current.draw(...) end if scene.current then scene.current.draw(...) end
end end

View file

@ -17,7 +17,7 @@ local function newTimerRegistry()
-- 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
-- system, a scene-specific TimerRegistry is available at ubiquitousse.scene.current.time. -- system, a scene-specific TimerRegistry is available at ubiquitousse.scene.current.time.
-- @impl abstract -- @impl ubiquitousse
new = function() new = function()
local new = newTimerRegistry() local new = newTimerRegistry()
new.get = registry.get new.get = registry.get
@ -32,8 +32,8 @@ local function newTimerRegistry()
--- Update all the TimedFunctions calls. --- Update all the TimedFunctions calls.
-- Supposed to be called in ubiquitousse.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] number dt the delta-time (time spent since last time the function was called) (miliseconds)
-- @impl abstract -- @impl ubiquitousse
update = function(dt) update = function(dt)
if dt then if dt then
registry.dt = dt registry.dt = dt
@ -95,7 +95,7 @@ local function newTimerRegistry()
-- The function will receive as first parameter the wait(time) function, which will pause the function execution for time miliseconds. -- The function will receive as first parameter the wait(time) function, which will pause the function execution for time miliseconds.
-- @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 ubiquitousse
run = function(func) run = function(func)
-- Creates empty function (the TimedFunction may be used for time measure or stuff like that which doesn't need a specific function) -- Creates empty function (the TimedFunction may be used for time measure or stuff like that which doesn't need a specific function)
func = func or function() end func = func or function() end
@ -159,7 +159,7 @@ local function newTimerRegistry()
-- @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))
-- @treturn TimedFunction the object -- @treturn TimedFunction the object
-- @impl abstract -- @impl ubiquitousse
tween = function(duration, tbl, to, method) tween = function(duration, tbl, to, method)
method = method or "linear" method = method or "linear"
method = type(method) == "string" and ease[method] or method method = type(method) == "string" and ease[method] or method
@ -177,13 +177,13 @@ local function newTimerRegistry()
end, end,
--- Cancels all the running TimedFunctions. --- Cancels all the running TimedFunctions.
-- @impl abstract -- @impl ubiquitousse
clear = function() clear = function()
delayed = {} delayed = {}
end, end,
--- Time since last update (miliseconds). --- Time since last update (miliseconds).
-- @impl abstract -- @impl ubiquitousse
dt = 0 dt = 0
} }