163 lines
3.7 KiB
Lua
163 lines
3.7 KiB
Lua
|
|
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
||
|
|
require "lldebugger".start()
|
||
|
|
end
|
||
|
|
|
||
|
|
local util = require "util"
|
||
|
|
local launch = require "launch"
|
||
|
|
|
||
|
|
local iui = require "lib.iui"
|
||
|
|
local backend = require "lib.lovr-iui"
|
||
|
|
|
||
|
|
-- modify for nested lovr path for api
|
||
|
|
iui.resourcePath = "lovr/" .. iui.resourcePath
|
||
|
|
backend.resourcePath = "lovr/" .. backend.resourcePath
|
||
|
|
api.iui = iui
|
||
|
|
api.backend = backend
|
||
|
|
local ecs = api.ecs
|
||
|
|
|
||
|
|
--- @type Texture
|
||
|
|
local envTex
|
||
|
|
|
||
|
|
--- @type LovrIUIWorldWindow
|
||
|
|
local mainWindow
|
||
|
|
|
||
|
|
function lovr.load()
|
||
|
|
if launch.mode == "desktop" then
|
||
|
|
backend.mouse = require "lib.lovr-mouse"
|
||
|
|
|
||
|
|
lovr.system.setKeyRepeat(true)
|
||
|
|
end
|
||
|
|
|
||
|
|
iui.load(backend)
|
||
|
|
|
||
|
|
api.exec( api.ext, "load")
|
||
|
|
|
||
|
|
if iui.idiom == "vr" then
|
||
|
|
lovr.headset.setPassthrough("opaque")
|
||
|
|
|
||
|
|
mainWindow = backend.worldWindow.new()
|
||
|
|
api.mainWindow = mainWindow
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.update(dt)
|
||
|
|
if lovr.system.isKeyDown("escape") then
|
||
|
|
lovr.event.quit()
|
||
|
|
end
|
||
|
|
|
||
|
|
ecs.update( ecs.world, pass, ecs.filter('updatesystem') )
|
||
|
|
|
||
|
|
iui.beginFrame(dt)
|
||
|
|
|
||
|
|
if iui.idiom == "desktop" then
|
||
|
|
-- In desktop mode, we use IUI's standard window API to fill the screen.
|
||
|
|
iui.beginWindow(lovr.system.getWindowDimensions())
|
||
|
|
|
||
|
|
api.exec( api.ext, "update", dt)
|
||
|
|
|
||
|
|
iui.endWindow()
|
||
|
|
|
||
|
|
elseif iui.idiom == "vr" then
|
||
|
|
-- In VR mode, we have access to the backend's `LovrIUIWorldWindow`
|
||
|
|
-- class, which handles windowing in world-space.
|
||
|
|
if mainWindow:beginFrame() then
|
||
|
|
iui.beginWindow(mainWindow.w, mainWindow.h)
|
||
|
|
|
||
|
|
api.exec( api.ext, "update", dt)
|
||
|
|
|
||
|
|
iui.endWindow()
|
||
|
|
|
||
|
|
mainWindow:endFrame()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
iui.endFrame()
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.draw(pass)
|
||
|
|
if iui.idiom == "desktop" then
|
||
|
|
backend.graphics.pass = pass
|
||
|
|
|
||
|
|
iui.draw()
|
||
|
|
end
|
||
|
|
if api.iui.idiom == "vr" then
|
||
|
|
pass:setClear(0.5, 0.5, 0.5)
|
||
|
|
end
|
||
|
|
api.exec(api.ext, "draw",pass)
|
||
|
|
ecs.update( ecs.world, pass, ecs.filter('drawsystem') )
|
||
|
|
if api.mainWindow then
|
||
|
|
api.mainWindow:draw(pass)
|
||
|
|
end
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.recenter()
|
||
|
|
if iui.idiom == "vr" then
|
||
|
|
mainWindow:recenter()
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
if launch.mode == "desktop" then
|
||
|
|
function lovr.mousemoved(x, y, dx, dy)
|
||
|
|
backend.mousemoved(x, y, dx, dy)
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.mousepressed(x, y, button)
|
||
|
|
backend.mousepressed(x, y, button)
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.mousereleased(x, y, button)
|
||
|
|
backend.mousereleased(x, y, button)
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.wheelmoved(x, y)
|
||
|
|
backend.wheelmoved(x, y)
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.keypressed(key, scancode, isRepeat)
|
||
|
|
backend.keypressed(key, scancode, isRepeat)
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.keyreleased(key, scancode)
|
||
|
|
backend.keyreleased(key, scancode)
|
||
|
|
end
|
||
|
|
|
||
|
|
function lovr.textinput(text)
|
||
|
|
backend.textinput(text)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
local initECS = function(ecs)
|
||
|
|
ecs.world = ecs.world()
|
||
|
|
|
||
|
|
-- lovr.draw => ecs.drawsystem (render-logic thread)
|
||
|
|
local renderer = ecs.processingSystem()
|
||
|
|
renderer.filter = ecs.requireAny('model') -- add more types when needed
|
||
|
|
renderer.drawsystem = true
|
||
|
|
function renderer:process(obj, pass)
|
||
|
|
if obj['model'] ~= nil then
|
||
|
|
pass:setMaterial()
|
||
|
|
pass:setCullMode('none')
|
||
|
|
pass:draw(
|
||
|
|
obj['model'],
|
||
|
|
obj['x'] or 0,
|
||
|
|
obj['y'] or 0,
|
||
|
|
obj['z'] or 0,
|
||
|
|
1, 0, 1, 0, 0, 1)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
ecs.addSystem( ecs.world, renderer )
|
||
|
|
|
||
|
|
-- lovr.update => ecs updatesystem (game-logic thread)
|
||
|
|
local update = ecs.processingSystem()
|
||
|
|
update.updatesystem = true
|
||
|
|
update.filter = ecs.requireAll('update') -- *TODO* might need filter later
|
||
|
|
function update:process(obj, dt)
|
||
|
|
print_r(obj['data'])
|
||
|
|
end
|
||
|
|
ecs.addSystem( ecs.world, update )
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
initECS(api.ecs)
|