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

Moved stuff

This commit is contained in:
Reuh 2016-04-26 17:01:45 +02:00
parent 8694400105
commit 005f0a51b7
5 changed files with 94 additions and 75 deletions

View file

@ -42,15 +42,6 @@ end
-- abstract -- abstract
abstract.backend = "love" abstract.backend = "love"
add(abstract, {
setup = function(params)
local p = abstract.params
love.window.setTitle(p.title)
love.window.setMode(p.width, p.height, {
resizable = p.resizable
})
end
})
-- abstract.event -- abstract.event
do do
@ -58,8 +49,7 @@ local updateDefault = abstract.event.update
abstract.event.update = function() end abstract.event.update = function() end
function love.update(dt) function love.update(dt)
-- Value update -- Value update
abstract.fps = love.timer.getFPS() abstract.draw.fps = love.timer.getFPS()
abstract.dt = love.timer.getDelta()
-- Stuff defined in abstract.lua -- Stuff defined in abstract.lua
updateDefault(dt) updateDefault(dt)
@ -95,6 +85,13 @@ end
-- abstract.draw -- abstract.draw
local defaultFont = love.graphics.getFont() local defaultFont = love.graphics.getFont()
add(abstract.draw, { add(abstract.draw, {
init = function(params)
local p = abstract.draw.params
love.window.setTitle(p.title)
love.window.setMode(p.width, p.height, {
resizable = p.resizable
})
end,
color = function(r, g, b, a) color = function(r, g, b, a)
love.graphics.setColor(r, g, b, a) love.graphics.setColor(r, g, b, a)
end, end,

View file

@ -11,7 +11,45 @@ local abstract = require((...):match("^(.-abstract)%."))
-- --
-- x and y values can be float, so make sure to perform math.floor if your engine only support -- x and y values can be float, so make sure to perform math.floor if your engine only support
-- integer coordinates. -- integer coordinates.
return { local draw
draw = {
--- Initial game view paramters (some defaults).
-- @impl abstract
params = {
title = "Abstract Engine",
width = 800,
height = 600,
resizable = false,
resizeType = "auto"
},
--- Setup the intial game view parameters.
-- If a parmeter is not set, a default value will be used.
-- This function is expected to be only called once, before doing any drawing operation.
-- @tparam table params the game parameters
-- @usage -- Default values:
-- abstract.setup {
-- title = "Abstract Engine", -- usually window title
-- width = 800, -- in px
-- height = 600, -- in px
-- resizable = false, -- can the game be resized?
-- resizeType = "auto" -- how to act on resize: "none" to do nothing (0,0 will be top-left)
-- "center" to autocenter (0,0 will be at windowWidth/2-gameWidth/2,windowHeight/2-gameHeight/2)
-- "auto" to automatically resize to the window size (coordinate system won't change)
-- }
-- @impl mixed
init = function(params)
for k, v in pairs(params) do
draw.params[k] = v
end
draw.width = params.width
draw.height = params.height
end,
--- Frames per second (the backend should update this value).
-- @impl backend
fps = 60,
--- Sets the drawing color --- Sets the drawing color
-- @tparam number r the red component (0-255) -- @tparam number r the red component (0-255)
-- @tparam number g the green component (0-255) -- @tparam number g the green component (0-255)
@ -55,11 +93,11 @@ return {
--- The drawing area width, in pixels. --- The drawing area width, in pixels.
-- @impl backend -- @impl backend
width = abstract.params.width, width = 800,
--- The drawing area height, in pixels. --- The drawing area height, in pixels.
-- @impl backend -- @impl backend
height = abstract.params.height, height = 600,
-- TODO: doc & api -- TODO: doc & api
push = function() end, push = function() end,
@ -70,3 +108,5 @@ return {
font = function(filename) end, font = function(filename) end,
image = function(filename) end, image = function(filename) end,
} }
return draw

View file

@ -6,6 +6,9 @@
-- It is as the name imply abstract, and must be implemented in a backend, such as abstract.love. -- It is as the name imply abstract, and must be implemented in a backend, such as abstract.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
-- 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.
@ -53,60 +56,17 @@ abstract = {
--- Backend name. --- Backend name.
-- For consistency, only use lowercase letters [a-z] (no special char) -- For consistency, only use lowercase letters [a-z] (no special char)
-- @impl backend -- @impl backend
backend = "unknown", backend = "unknown"
--- General game paramters (some defaults).
-- @impl abstract
params = {
title = "Abstract Engine",
width = 800,
height = 600,
resizable = false,
resizeType = "auto"
},
--- Setup general game parameters.
-- If a parmeter is not set, a default value will be used.
-- This function is expected to be only called once, before doing any drawing operation.
-- @tparam table params the game parameters
-- @usage -- Default values:
-- abstract.setup {
-- title = "Abstract Engine", -- usually window title
-- width = 800, -- in px
-- height = 600, -- in px
-- resizable = false, -- can the game be resized?
-- resizeType = "auto" -- how to act on resize: "none" to do nothing (0,0 will be top-left)
-- "center" to autocenter (0,0 will be at windowWidth/2-gameWidth/2,windowHeight/2-gameHeight/2)
-- "auto" to automatically resize to the window size (coordinate system won't change)
-- }
-- @impl mixed
setup = function(params)
for k, v in pairs(params) do
abstract.params[k] = v
end
abstract.draw.width = params.width
abstract.draw.height = params.height
end,
--- Frames per second (the backend should update this value).
-- @impl backend
fps = 60,
--- Time since last frame (seconds)
-- @impl backend
dt = 0
} }
-- 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] = abstract
-- External submodules -- Require external submodules
abstract.time = require(p..".time") for _, m in ipairs({"time", "draw", "audio", "input", "scene", "event"}) do
abstract.draw = require(p..".draw") local s, t = pcall(require, p.."."..m)
abstract.audio = require(p..".audio") if s then abstract[m] = t end
abstract.input = require(p..".input") end
abstract.scene = require(p..".scene")
abstract.event = require(p..".event")
-- Backend engine autodetect and load -- Backend engine autodetect and load
if love then if love then

View file

@ -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.dt) or xAxis:raw()) newX = x + (xSpeed and (xAxis:value() * xSpeed * abstract.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.dt) or yAxis:raw()) newY = y + (ySpeed and (yAxis:value() * ySpeed * abstract.time.dt) or yAxis:raw())
maxMovY = movY maxMovY = movY
end end
elseif mode == "absolute" then elseif mode == "absolute" then

View file

@ -2,20 +2,25 @@
local ease = require((...):match("^(.-abstract)%.")..".lib.easing") local ease = require((...):match("^(.-abstract)%.")..".lib.easing")
--- Time related functions --- Time related functions
local time
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 abstract.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 = {}
return { -- Used to calculate the deltatime
local lastTime
local 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 abstract.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 abstract.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 abstract.scene.current.time.
new = function() new = function()
return newTimerRegistry() local new = newTimerRegistry()
new.get = registry.get
return new
end, end,
--- Returns the number of seconds elapsed since some point in time. --- Returns the number of seconds elapsed since some point in time.
@ -27,9 +32,21 @@ local function newTimerRegistry()
--- Update all the TimedFunctions calls. --- Update all the TimedFunctions calls.
-- Supposed to be called in abstract.event.update. -- Supposed to be called in abstract.event.update.
-- @tparam numder dt the delta-time -- @tparam[opt=calculate here] numder dt the delta-time (time spent since last time the function was called) (seconds)
-- @impl abstract -- @impl abstract
update = function(dt) update = function(dt)
if dt then
registry.dt = dt
else
if lastTime then
local newTime = registry.get()
registry.dt = newTime - lastTime
lastTime = newTime
else
lastTime = registry.get()
end
end
local d = delayed local d = delayed
for func, t in pairs(d) do for func, t in pairs(d) do
local co = t.coroutine local co = t.coroutine
@ -39,7 +56,7 @@ local function newTimerRegistry()
if not co then if not co then
co = coroutine.create(func) co = coroutine.create(func)
t.coroutine = co t.coroutine = co
t.started = time.get() t.started = registry.get()
if t.times > 0 then t.times = t.times - 1 end if t.times > 0 then t.times = t.times - 1 end
t.onStart() t.onStart()
end end
@ -49,7 +66,7 @@ local function newTimerRegistry()
coroutine.yield() coroutine.yield()
end, dt)) end, dt))
if coroutine.status(co) == "dead" then if coroutine.status(co) == "dead" then
if (t.during >= 0 and t.started + t.during < time.get()) if (t.during >= 0 and t.started + t.during < registry.get())
or (t.times == 0) or (t.times == 0)
or (t.every == -1 and t.times == -1 and t.during == -1) -- no repeat or (t.every == -1 and t.times == -1 and t.during == -1) -- no repeat
then then
@ -138,7 +155,7 @@ local function newTimerRegistry()
local from = {} local from = {}
for k in pairs(to) do from[k] = tbl[k] end for k in pairs(to) do from[k] = tbl[k] end
return time.run(function(wait, dt) return registry.run(function(wait, dt)
time = time + dt time = time + dt
for k, v in pairs(to) do for k, v in pairs(to) do
tbl[k] = method(time, from[k], to[k] - from[k], duration) tbl[k] = method(time, from[k], to[k] - from[k], duration)
@ -150,9 +167,14 @@ local function newTimerRegistry()
-- @impl abstract -- @impl abstract
clear = function() clear = function()
delayed = {} delayed = {}
end end,
--- Time since last update (seconds).
-- @impl abstract
dt = 0
} }
return registry
end end
time = newTimerRegistry() return newTimerRegistry()
return time