2017-12-19 00:01:12 +00:00
|
|
|
local conf = {
|
|
|
|
modules = {
|
|
|
|
audio = true,
|
2018-01-16 07:13:26 +00:00
|
|
|
data = true,
|
2017-12-19 00:01:12 +00:00
|
|
|
event = true,
|
|
|
|
graphics = true,
|
|
|
|
headset = true,
|
|
|
|
math = true,
|
|
|
|
physics = true,
|
2018-02-12 04:34:32 +00:00
|
|
|
thread = true,
|
2017-12-19 00:01:12 +00:00
|
|
|
timer = true
|
|
|
|
},
|
|
|
|
gammacorrect = false,
|
|
|
|
headset = {
|
|
|
|
drivers = { 'openvr', 'webvr', 'fake' },
|
|
|
|
mirror = true,
|
|
|
|
offset = 1.7
|
|
|
|
},
|
|
|
|
window = {
|
2018-03-04 23:07:44 +00:00
|
|
|
width = 1080,
|
2017-12-19 00:01:12 +00:00
|
|
|
height = 600,
|
|
|
|
fullscreen = false,
|
|
|
|
msaa = 0,
|
|
|
|
title = 'LÖVR',
|
|
|
|
icon = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function lovr.errhand(message)
|
|
|
|
message = 'Error:\n' .. message:gsub('\n[^\n]+$', ''):gsub('\t', ''):gsub('stack traceback', '\nStack')
|
|
|
|
print(message)
|
|
|
|
if not lovr.graphics then return end
|
|
|
|
lovr.graphics.reset()
|
|
|
|
lovr.graphics.setBackgroundColor(.105, .098, .137)
|
|
|
|
lovr.graphics.setColor(.863, .863, .863)
|
|
|
|
if lovr.headset then
|
|
|
|
lovr.headset.setMirrored(false)
|
|
|
|
end
|
|
|
|
local font = lovr.graphics.getFont()
|
|
|
|
local pixelDensity = font:getPixelDensity()
|
|
|
|
local width = font:getWidth(message, .55 * pixelDensity)
|
|
|
|
local function render()
|
2018-03-18 17:56:12 +00:00
|
|
|
lovr.graphics.print(message, -width / 2, 0, -20, 1, 0, 0, 0, 0, .55 * pixelDensity, 'left')
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
while true do
|
|
|
|
lovr.event.pump()
|
|
|
|
for name in lovr.event.poll() do
|
|
|
|
if name == 'quit' then return end
|
|
|
|
end
|
|
|
|
lovr.graphics.clear()
|
|
|
|
lovr.graphics.origin()
|
2018-02-26 00:40:48 +00:00
|
|
|
if lovr.headset and lovr.getOS() ~= 'Web' then
|
2018-03-18 17:56:12 +00:00
|
|
|
lovr.graphics.push()
|
|
|
|
lovr.graphics.translate(0, conf.headset.offset, 0)
|
2018-03-05 04:43:42 +00:00
|
|
|
lovr.headset.renderTo(render)
|
2018-03-18 17:56:12 +00:00
|
|
|
lovr.graphics.pop()
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
render()
|
|
|
|
lovr.graphics.present()
|
2018-02-26 00:40:48 +00:00
|
|
|
lovr.timer.sleep(lovr.headset and .001 or .1)
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
lovr.filesystem = require('lovr.filesystem')
|
|
|
|
|
|
|
|
local runnable = lovr.filesystem.isFile('conf.lua') or lovr.filesystem.isFile('main.lua')
|
|
|
|
if not lovr.filesystem.getSource() or not runnable then
|
|
|
|
function lovr.conf(t)
|
|
|
|
t.modules.audio = false
|
|
|
|
t.modules.math = false
|
|
|
|
t.modules.physics = false
|
|
|
|
end
|
|
|
|
|
|
|
|
local logo, controllers
|
|
|
|
|
|
|
|
function lovr.load()
|
2018-02-20 05:04:53 +00:00
|
|
|
local texture = lovr.graphics.newTexture(lovr.data.newBlob(lovr._logo, 'logo.png'))
|
2017-12-19 00:01:12 +00:00
|
|
|
logo = lovr.graphics.newMaterial(texture)
|
|
|
|
lovr.graphics.setBackgroundColor(.960, .988, 1.0)
|
|
|
|
refreshControllers()
|
|
|
|
end
|
|
|
|
|
|
|
|
function lovr.draw()
|
|
|
|
lovr.graphics.setColor(1.0, 1.0, 1.0)
|
|
|
|
|
|
|
|
for controller, model in pairs(controllers) do
|
|
|
|
local x, y, z = controller:getPosition()
|
|
|
|
model:draw(x, y, z, 1, controller:getOrientation())
|
|
|
|
end
|
|
|
|
|
|
|
|
local padding = .1
|
|
|
|
local font = lovr.graphics.getFont()
|
|
|
|
local fade = .315 + .685 * math.abs(math.sin(lovr.timer.getTime() * 2))
|
2018-03-05 05:46:37 +00:00
|
|
|
local titlePosition = 1.4 - padding
|
2017-12-19 00:01:12 +00:00
|
|
|
local subtitlePosition = titlePosition - font:getHeight() * .25 - padding
|
|
|
|
|
2018-03-05 05:46:37 +00:00
|
|
|
lovr.graphics.plane(logo, 0, 1.9, -3, 1, 1, 0, 0, 1)
|
2017-12-19 00:01:12 +00:00
|
|
|
lovr.graphics.setColor(.059, .059, .059)
|
|
|
|
lovr.graphics.print('LÖVR', -.01, titlePosition, -3, .25, 0, 0, 1, 0, nil, 'center', 'top')
|
|
|
|
lovr.graphics.setColor(.059, .059, .059, fade)
|
|
|
|
lovr.graphics.print('No game :(', -.01, subtitlePosition, -3, .15, 0, 0, 1, 0, nil, 'center', 'top')
|
|
|
|
end
|
|
|
|
|
|
|
|
function refreshControllers()
|
|
|
|
controllers = {}
|
|
|
|
|
|
|
|
if not lovr.headset then return end
|
|
|
|
|
|
|
|
for _, controller in pairs(lovr.headset.getControllers()) do
|
|
|
|
controllers[controller] = controller:newModel()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
lovr.controlleradded = refreshControllers
|
|
|
|
lovr.controllerremoved = refreshControllers
|
|
|
|
end
|
|
|
|
|
2018-01-06 07:04:47 +00:00
|
|
|
local confOk, confError
|
|
|
|
if lovr.filesystem.isFile('conf.lua') then
|
|
|
|
confOk, confError = pcall(require, 'conf')
|
|
|
|
if lovr.conf then
|
|
|
|
confOk, confError = pcall(lovr.conf, conf)
|
|
|
|
end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
lovr._setConf(conf)
|
|
|
|
|
|
|
|
lovr.filesystem.setIdentity(conf.identity)
|
|
|
|
|
2018-02-12 04:34:32 +00:00
|
|
|
local modules = { 'audio', 'data', 'event', 'graphics', 'headset', 'math', 'physics', 'thread', 'timer' }
|
2017-12-19 00:01:12 +00:00
|
|
|
for _, module in ipairs(modules) do
|
|
|
|
if conf.modules[module] then
|
|
|
|
lovr[module] = require('lovr.' .. module)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Error after window is created
|
2018-01-06 07:04:47 +00:00
|
|
|
if confError then
|
|
|
|
error(confError)
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
|
2018-02-26 00:40:48 +00:00
|
|
|
lovr.handlers = setmetatable({}, { __index = lovr })
|
2017-12-19 00:01:12 +00:00
|
|
|
|
|
|
|
function lovr.step()
|
|
|
|
lovr.event.pump()
|
|
|
|
for name, a, b, c, d in lovr.event.poll() do
|
|
|
|
if name == 'quit' and (not lovr.quit or not lovr.quit()) then
|
|
|
|
return a
|
|
|
|
end
|
2018-02-26 00:40:48 +00:00
|
|
|
if lovr.handlers[name] then lovr.handlers[name](a, b, c, d) end
|
2017-12-19 00:01:12 +00:00
|
|
|
end
|
|
|
|
local dt = lovr.timer.step()
|
|
|
|
if lovr.headset then
|
|
|
|
lovr.headset.update(dt)
|
|
|
|
end
|
|
|
|
if lovr.audio then
|
|
|
|
lovr.audio.update()
|
2018-02-26 00:40:48 +00:00
|
|
|
if lovr.headset then
|
2017-12-19 00:01:12 +00:00
|
|
|
lovr.audio.setOrientation(lovr.headset.getOrientation())
|
|
|
|
lovr.audio.setPosition(lovr.headset.getPosition())
|
|
|
|
lovr.audio.setVelocity(lovr.headset.getVelocity())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if lovr.update then lovr.update(dt) end
|
|
|
|
if lovr.graphics then
|
|
|
|
lovr.graphics.clear()
|
|
|
|
lovr.graphics.origin()
|
|
|
|
if lovr.draw then
|
2018-02-26 00:40:48 +00:00
|
|
|
if lovr.headset then
|
2018-03-05 04:43:42 +00:00
|
|
|
lovr.headset.renderTo(lovr.draw)
|
2017-12-19 00:01:12 +00:00
|
|
|
else
|
|
|
|
lovr.draw()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
lovr.graphics.present()
|
|
|
|
end
|
|
|
|
lovr.timer.sleep(.001)
|
|
|
|
end
|
|
|
|
|
|
|
|
function lovr.run()
|
2018-01-14 00:00:47 +00:00
|
|
|
lovr.timer.step()
|
2018-03-31 01:48:20 +00:00
|
|
|
if lovr.load then lovr.load(arg) end
|
2017-12-19 00:01:12 +00:00
|
|
|
while true do
|
|
|
|
local exit = lovr.step()
|
|
|
|
if exit then return exit end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-12 17:37:45 +00:00
|
|
|
function lovr.threaderror(thread, err)
|
|
|
|
error('Thread error\n\n' .. err)
|
|
|
|
end
|
|
|
|
|
2017-12-19 00:01:12 +00:00
|
|
|
if lovr.filesystem.isFile('main.lua') then
|
|
|
|
require('main')
|
|
|
|
end
|